Biluta de la RMI

Time limit: 0.1s Memory limit: 4MB Input: biluta.in Output: biluta.out

Task

Luci has a small ball. This ball has an interesting property: it can move along the axis of integers! More precisely, it can only move within the interval [X,X][-X, X]. Luci noticed that the ball moves in the first minute by one position, in the second minute by two positions, \dots, in the NN-th minute it moves NN positions. If it reaches one end of the interval [X,X][-X, X], it changes direction and continues with the remaining number of positions.

If initially, the ball is at position 00 and moves towards XX, what position will it be in after NN minutes?

Input data

The first line will contain the numbers XX and NN.

Output data

The first line will contain the position of the ball after NN minutes.

Constraints and clarifications

  • 1X1091 \leq X \leq 10^9;
  • 1N1091 \leq N \leq 10^9;
# Points Constraints
1 20 1X1041 \leq X \leq 10^4, 1N10001 \leq N \leq 1000
2 20 1X1061 \leq X \leq 10^6, 1N5×1051 \leq N \leq 5 \times 10^5
3 60 No additional constraints

Example 1

biluta.in

4 3

biluta.out

2

Explicație

The ball moves as follows:

01320 \rightarrow 1 \rightarrow 3 \rightarrow 2

Example 2

biluta.in

3 7

biluta.out

2

`

Log in or sign up to be able to send submissions!