#K96147. Total Coins Calculation

    ID: 39022 Type: Default 1000ms 256MiB

Total Coins Calculation

Total Coins Calculation

You are given a series of tasks numbered from 1 to n. Completing the ith task grants you i coins. Given three integers n, i, and j (where tasks are 1-indexed), calculate the total number of coins earned when completing tasks from the ith task to the jth task inclusive.

You can calculate the sum of consecutive natural numbers using the formula:

$$S = \frac{j(j+1)}{2} - \frac{(i-1)i}{2}$$

Note that the input n represents the total number of tasks but it is not directly used in the calculation, other than to indicate the upper bound of tasks.

inputFormat

The input is read from standard input and consists of a single line containing three space-separated integers:

  • n - the total number of tasks (1-indexed)
  • i - the starting task index
  • j - the ending task index

outputFormat

Output a single integer representing the total number of coins earned by completing tasks from the ith task to the jth task. The result should be printed to standard output.

## sample
5 2 4
9