문제
There is a line of cows, initially (i.e. at time ) containing only cow at position (here, a cow is at position if there are cows in front of it). At time for , the cow at position 0 moves to position , every cow in positions moves forward one position, and cow joins the line at the end of the line (position ).
Answer () independent queries each of the following form:
Out of cows , how many are located at positions immediately after time ? ()
입력
The first line contains , the number of queries.
The next lines each contain five integers specifying a query of the form " ."
출력
Output the answer to each query on a separate line.
예제 입력 1
4
0 9 0 9 9
3 5 4 5 9
4 5 3 5 9
1 1 3 3 9
예제 출력 1
10
2
1
1
예제 입력 2
1
0 1000000000000000000 0 1000000000000000000 1000000000000000000
예제 출력 2
1000000000000000001
점수
Input 3: Inputs 4-7: for all queriesInputs 8-14: for all queriesInputs 15-21: No additional constraints
코드를 제출하려면 로그인이 필요합니다.
로그인