Repovive
  • Dashboard
  • Ranking
  • Submissions
  • Discussion
  1. Contests
  2. Starter Round 8Rated: < 1700
  3. 23A
Sponsor
Abhishek Choudhary

My submissions

/
/
/
/

Announcements

My submissions

/
/
/
/

Announcements

Solve
Author

23A. The Untouched Die

500 pts·1s·256 MB

Constraints

Input

Output

Samples

Input
3 11 15
Explanation
Output
6
Input
1 4 4
Explanation
Output
4
Input
4 17 8
Explanation
Output
2

There are nnn standard dice on a table. Each die has faces numbered from 111 to 666, and the numbers on opposite faces sum to 777.

Initially, the sum of the numbers on the top faces is aaa.

You leave exactly one die untouched and turn every other die upside down, exchanging its top and bottom faces. The sum of the numbers on the top faces becomes bbb.

Find the number on the top face of the untouched die.

  • 1≤n≤1001 \le n \le 1001≤n≤100
  • n≤a,b≤6nn \le a,b \le 6nn≤a,b≤6n
  • The input is guaranteed to describe a possible situation.
nabn \quad a \quad bnab

The input consists of three integers nnn, aaa, and bbb: the number of dice, the initial sum of their top faces, and the sum after turning all but one die upside down.

xxx

Print the number xxx on the top face of the untouched die.

The top faces can initially be (2,3,6)(2,3,6)(2,3,6). Turning the first two dice upside down changes them to (5,4,6)(5,4,6)(5,4,6). The sums are 111111 and 151515, and the untouched die shows 666.

There is only one die, so it remains untouched. Its top face shows 444 both before and after the operation.

The top faces can initially be (5,5,5,2)(5,5,5,2)(5,5,5,2). Turning the first three dice upside down changes them to (2,2,2,2)(2,2,2,2)(2,2,2,2). The sums are 171717 and 888, and the untouched die shows 222.