message stringlengths 2 45.8k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 254 108k | cluster float64 3 3 | __index_level_0__ int64 508 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL | instruction | 0 | 93,378 | 3 | 186,756 |
"Correct Solution:
```
a,b,c,d = map(int,input().split())
x=c-a
y=d-b
print('R'*x+'U'*(y+1)+'L'*(x+1)+'D'*(y+1)+'R'+'U'*y+'R'*(x+1)+'D'*(y+1)+'L'*(x+1)+'U')
``` | output | 1 | 93,378 | 3 | 186,757 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL | instruction | 0 | 93,379 | 3 | 186,758 |
"Correct Solution:
```
sx,sy,tx,ty=[int(x) for x in input().split()]
dx=tx-sx
dy=ty-sy
print("R"*dx+"U"*dy+"L"*dx+"D"*(dy+1)+"R"*(dx+1)+"U"*(dy+1)+"LU"+"L"*(dx+1)+"D"*(dy+1)+"R")
``` | output | 1 | 93,379 | 3 | 186,759 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL | instruction | 0 | 93,380 | 3 | 186,760 |
"Correct Solution:
```
SX,SY,TX,TY=map(int,input().split())
x=TX-SX
y=TY-SY
print(''.join(['U'*y,'R'*x,'D'*y,'L'*x,'L','U'*(y+1),'R'*(x+1),'D','R','D'*(y+1),'L'*(x+1),'U']))
``` | output | 1 | 93,380 | 3 | 186,761 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL | instruction | 0 | 93,381 | 3 | 186,762 |
"Correct Solution:
```
sx, sy, tx, ty = [int(x) for x in input().split()]
dx=tx-sx
dy=ty-sy
print('R'*dx+'U'*dy+'L'*dx+'D'*(dy+1)+'R'*(dx+1)+'U'*(dy+1)+'L'+'U'+'L'*(dx+1)+'D'*(dy+1)+'R')
``` | output | 1 | 93,381 | 3 | 186,763 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL | instruction | 0 | 93,382 | 3 | 186,764 |
"Correct Solution:
```
a,b,c,d = list(map(int,input().split()))
a = c-a
b = d-b
print('R'*a+'U'*b+'L'*a+'D'*(b+1)+'R'*(a+1)+'U'*(b+1)
+'L'+'U'+'L'*(a+1)+'D'*(b+1)+'R')
``` | output | 1 | 93,382 | 3 | 186,765 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
sx,sy,tx,ty = map(int,input().split())
x,y = tx-sx,ty-sy
ans = "R"*x + "U"*y + "L"*x + "D"*y + "D" +"R"*(x+1) + "U"*(y+1) + "LU" + "L"*(x+1) + "D"*(y+1) + "R"
print(ans)
``` | instruction | 0 | 93,383 | 3 | 186,766 |
Yes | output | 1 | 93,383 | 3 | 186,767 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
a,b,c,d = map(int,input().split())
dx = c-a
dy = d-b
print('U'*dy+'R'*dx+'D'*dy+'L'*(dx+1)+'U'*(dy+1)+'R'*(dx+1)+'D'+'R'+'D'*(dy+1)+'L'*(dx+1)+'U')
``` | instruction | 0 | 93,384 | 3 | 186,768 |
Yes | output | 1 | 93,384 | 3 | 186,769 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
sx,sy,tx,ty=map(int, input().split()) #a1 a2 a3
m1=(tx-sx)*"R"+(ty-sy)*"U"
m2=(tx-sx)*"L"+(ty-sy)*"D"
print(m1+m2+"DR"+m1+"ULUL"+m2+"DR")
``` | instruction | 0 | 93,385 | 3 | 186,770 |
Yes | output | 1 | 93,385 | 3 | 186,771 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
a,b,c,d=map(int,input().split())
X=c-a
Y=d-b
ans1='R'*X+'U'*Y
ans2='L'*X+'D'*Y
ans3='D'+'R'*(X+1)+'U'*(Y+1)+'L'
ans4='U'+'L'*(X+1)+'D'*(Y+1)+'R'
print(ans1+ans2+ans3+ans4)
``` | instruction | 0 | 93,386 | 3 | 186,772 |
Yes | output | 1 | 93,386 | 3 | 186,773 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
X=list(map(int,input().split()))
#X軸に並行
if X[2]-X[0]==0:
if X[3]-X[1]>0:
q=X[3]-X[1]
U="U"
D="D"
else:
q=X[1]-X[3]
U="U"
D="D"
print(U*(q+1)+R*2+D*(q+2)+L*2+U+L+U*q+R*2+D*q+L)
#Y軸に並行
if X[3]-X[1]==0:
if X[2]-X[0]>0:
p=X[2]-X[0]
R="R"
L="L"
else:
p=X[0]-X[2]
R="L"
L="R"
print(R*(p+1)+U*2+L*(p+2)+D*2+R+D+R*p+U*2+L*p+D)
if (X[2]-X[0]!=0 and X[3]-X[1]!=0):
if X[2]-X[0]>0:
p=X[2]-X[0]
R="R"
L="L"
else:
p=X[0]-X[2]
R="L"
L="R"
if X[3]-X[1]>0:
q=X[3]-X[1]
U="U"
D="D"
else:
q=X[1]-X[3]
U="D"
D="U"
print(U*p+R*(q+1)+D*(p+1)+L*(q+1)+U+L+U*(p+1)+R*(q+1)+D*(p+1)+L*q)
``` | instruction | 0 | 93,387 | 3 | 186,774 |
No | output | 1 | 93,387 | 3 | 186,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
sx,sy,tx,ty=map(int,input().split())
nx=tx-sx
ny=ty-sy
ans=""
R1="U"*ny + "R"*nx + "D"*ny + "L"*nx
R2="D" + "R"*(nx + 1) + "U"*(ny + 1) +"R" + "U" + "L"*(nx + 1) +"D"*(ny + 1) + "R"
print(R1+R2)
``` | instruction | 0 | 93,388 | 3 | 186,776 |
No | output | 1 | 93,388 | 3 | 186,777 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
ret=''
for i in range(tx-sx):
ret=ret+'U'
for i in range(ty-sy):
ret=ret+'R'
for i in range(tx-sx):
ret=ret+'D'
import sys
inp=sys.stdin.readline()
sx,sy,tx,ty=map(lambda x: int(x), inp.split(' '))
for i in range(ty-sy+1):
ret=ret+'L'
for i in range(tx-sx+1):
ret=ret+'U'
for i in range(ty-sy+1):
ret=ret+'R'
ret=ret+'DR'
for i in range(tx-sx+1):
ret=ret+'D'
for i in range(ty-sy+1):
ret=ret+'L'
ret=ret+'U'
``` | instruction | 0 | 93,389 | 3 | 186,778 |
No | output | 1 | 93,389 | 3 | 186,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
sx, sy, tx, ty = map(int, input().split())
ans = 'R'*(tx-sx) + 'U'*(ty-sy) + 'L'*(tx-sx) + 'D'*(ty-sy)
ans += 'D'*1 + 'R'*(tx-sx+1) + 'U'*(ty-sy+1) + 'L' * 1 + 'U' * 1 + 'L' * (tx-sy+1) + 'D'*(ty-sy+1) + 'R'*1
print(ans)
``` | instruction | 0 | 93,390 | 3 | 186,780 |
No | output | 1 | 93,390 | 3 | 186,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors. | instruction | 0 | 93,819 | 3 | 187,638 |
Tags: math, number theory
Correct Solution:
```
######### ## ## ## #### ##### ## # ## # ##
# # # # # # # # # # # # # # # # # # #
# # # # ### # # # # # # # # # # # #
# ##### # # # # ### # # # # # # # # #####
# # # # # # # # # # # # # # # # # #
######### # # # # ##### # ##### # ## # ## # #
"""
PPPPPPP RRRRRRR OOOO VV VV EEEEEEEEEE
PPPPPPPP RRRRRRRR OOOOOO VV VV EE
PPPPPPPPP RRRRRRRRR OOOOOOOO VV VV EE
PPPPPPPP RRRRRRRR OOOOOOOO VV VV EEEEEE
PPPPPPP RRRRRRR OOOOOOOO VV VV EEEEEEE
PP RRRR OOOOOOOO VV VV EEEEEE
PP RR RR OOOOOOOO VV VV EE
PP RR RR OOOOOO VV VV EE
PP RR RR OOOO VVVV EEEEEEEEEE
"""
"""
Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
import sys
input = sys.stdin.readline
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;
def ceil(x):
if x != int(x):
x = int(x) + 1
return x
def factorial(x, m):
val = 1
while x>0:
val = (val * x) % m
x -= 1
return val
def fact(x):
val = 1
while x > 0:
val *= x
x -= 1
return val
# swap_array function
def swaparr(arr, a,b):
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
## gcd function
def gcd(a,b):
if b == 0:
return a;
return gcd(b, a % b);
## lcm function
def lcm(a, b):
return (a * b) // gcd(a, b)
## nCr function efficient using Binomial Cofficient
def nCr(n, k):
if k > n:
return 0
if(k > n - k):
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return int(res)
## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0, hi = None):
if hi == None:
hi = len(a);
while lo < hi:
mid = (lo+hi)//2;
if a[mid] < x:
lo = mid+1;
else:
hi = mid;
return lo;
## prime factorization
def primefs(n):
## if n == 1 ## calculating primes
primes = {}
while(n%2 == 0 and n > 0):
primes[2] = primes.get(2, 0) + 1
n = n//2
for i in range(3, int(n**0.5)+2, 2):
while(n%i == 0 and n > 0):
primes[i] = primes.get(i, 0) + 1
n = n//i
if n > 2:
primes[n] = primes.get(n, 0) + 1
## prime factoriazation of n is stored in dictionary
## primes and can be accesed. O(sqrt n)
return primes
## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
res = 1
x = x % p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) :
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
temp = a
a = b
b = temp
return a,b;
# find function with path compression included (recursive)
# def find(x, link):
# if link[x] == x:
# return x
# link[x] = find(link[x], link);
# return link[x];
# find function with path compression (ITERATIVE)
def find(x, link):
p = x;
while( p != link[p]):
p = link[p];
while( x != p):
nex = link[x];
link[x] = p;
x = nex;
return p;
# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x,y = swap(x,y)
if x != y:
size[x] += size[y]
link[y] = x
## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
prime = [True for i in range(n+1)]
prime[0], prime[1] = False, False
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
# Euler's Toitent Function phi
def phi(n) :
result = n
p = 2
while(p * p<= n) :
if (n % p == 0) :
while (n % p == 0) :
n = n // p
result = result * (1.0 - (1.0 / (float) (p)))
p = p + 1
if (n > 1) :
result = result * (1.0 - (1.0 / (float)(n)))
return (int)(result)
def is_prime(n):
if n == 0:
return False
if n == 1:
return True
for i in range(2, int(n ** (1 / 2)) + 1):
if not n % i:
return False
return True
#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
spf[1] = 1;
for i in range(2, MAXN):
spf[i] = i;
for i in range(4, MAXN, 2):
spf[i] = 2;
for i in range(3, ceil(MAXN ** 0.5), 2):
if spf[i] == i:
for j in range(i*i, MAXN, i):
if spf[j] == j:
spf[j] = i;
## function for storing smallest prime factors (spf) in the array
################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
res = []
for i in range(2, int(x ** 0.5) + 1):
while x % i == 0:
res.append(i)
x //= i
if x != 1:
res.append(x)
return res
## this function is useful for multiple queries only, o/w use
## primefs function above. complexity O(log n)
def factors(n):
res = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
res.append(n // i)
return list(set(res))
## taking integer array input
def int_array():
return list(map(int, input().strip().split()));
def float_array():
return list(map(float, input().strip().split()));
## taking string array input
def str_array():
return input().strip().split();
#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
################### ---------------- TEMPLATE ENDS HERE ---------------- ###################
from itertools import permutations
import math
from bisect import bisect_left
def solve():
a, b = map(int, input().split())
a, b = min(a, b), max(a, b)
c = 0
while a > 0:
c += b // a
b = b % a
a, b = min(a, b), max(a, b)
print(c)
if __name__ == '__main__':
for _ in range(1):
solve()
# fin_time = datetime.now()
# print("Execution time (for loop): ", (fin_time-init_time))
``` | output | 1 | 93,819 | 3 | 187,639 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors. | instruction | 0 | 93,820 | 3 | 187,640 |
Tags: math, number theory
Correct Solution:
```
a,b=map(int,input().split())
c=0
while (a>0 and b>0):
c+=(a//b)
a,b=b,a%b
print(c)
``` | output | 1 | 93,820 | 3 | 187,641 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors. | instruction | 0 | 93,821 | 3 | 187,642 |
Tags: math, number theory
Correct Solution:
```
## don't understand why this works yet
c=0
a,b=map(int,input().split())
while a!=0 and b!=0:
c+=a//b
a=a%b
a,b=b,a
print(c)
``` | output | 1 | 93,821 | 3 | 187,643 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors. | instruction | 0 | 93,822 | 3 | 187,644 |
Tags: math, number theory
Correct Solution:
```
import math
import sys
import collections
import bisect
import string
import time
def get_ints():return map(int, sys.stdin.readline().strip().split())
def get_list():return list(map(int, sys.stdin.readline().strip().split()))
def get_string():return sys.stdin.readline().strip()
def SieveOfEratosthenes(n):
prime = [True for i in range(n + 1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 1
prime[0] = False
prime[1] = False
ans=[]
for p in range(n + 1):
if prime[p]:
ans.append(p)
return ans
primes=SieveOfEratosthenes(2*(10**5))
set_primes=set(primes)
for t in range(1):
a,b=get_ints()
ans = 0
while a > 0 and b > 0:
ans += max(a, b) // min(a, b)
a, b = max(a, b) % min(a, b), min(a, b)
print(ans)
``` | output | 1 | 93,822 | 3 | 187,645 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors. | instruction | 0 | 93,823 | 3 | 187,646 |
Tags: math, number theory
Correct Solution:
```
a, b = map(int, input().split())
k = 1
while a != b:
if a > b:
x = a // b - (b == 1)
k += x
a -= b * x
else:
x = b // a - (a == 1)
k += x
b -= a * x
print(k)
``` | output | 1 | 93,823 | 3 | 187,647 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors. | instruction | 0 | 93,824 | 3 | 187,648 |
Tags: math, number theory
Correct Solution:
```
n,m=map(int,input().split())
a=0
while m:a+=n//m;n,m=m,n%m
print(a)
# Made By Mostafa_Khaled
``` | output | 1 | 93,824 | 3 | 187,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors. | instruction | 0 | 93,825 | 3 | 187,650 |
Tags: math, number theory
Correct Solution:
```
def check(x, y):
integer = x // y
if x == integer * y:
return integer
elif x > y:
result = integer
x = x % y
if x == 1:
result += y
return result
elif x != 1:
result += check(y, x)
return result
return check(y, x)
a, b = [int(i) for i in input().split()]
print(check(a, b))
``` | output | 1 | 93,825 | 3 | 187,651 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors. | instruction | 0 | 93,826 | 3 | 187,652 |
Tags: math, number theory
Correct Solution:
```
a,b = map(int,input().split())
ans=0
c=1
while a!=1:
ans+=a//b
a,b = b , a%b
c+=1
if c>100:
break
ans+=b
print(ans)
``` | output | 1 | 93,826 | 3 | 187,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors.
Submitted Solution:
```
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353
# from sys import stdin
# input = stdin.readline
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
try:
# sys.setrecursionlimit(int(pow(10,7)))
sys.stdin = open("input.txt", "r")
# sys.stdout = open("../output.txt", "w")
except:
pass
def pmat(A):
for ele in A:
print(*ele,end="\n")
def seive():
prime=[1 for i in range(10**6+1)]
prime[0]=0
prime[1]=0
for i in range(10**6+1):
if(prime[i]):
for j in range(2*i,10**6+1,i):
prime[j]=0
return prime
a,b=L()
def rec(a,b):
if b==1:
return a
if a>b:
return a//b+rec(b,a%b)
else:
return rec(b,a)
print(rec(a,b))
endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")
``` | instruction | 0 | 93,827 | 3 | 187,654 |
Yes | output | 1 | 93,827 | 3 | 187,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors.
Submitted Solution:
```
a, b = map(int, input().split())
def rec(a, b):
if ((a // b) * b == a):
return a // b
if (a > b):
t = a // b
return t + rec(a - t * b, b)
else:
t = b // a
if (a * t == b):
t -= 1
return t + rec(a, b - t * a)
print(rec(a, b))
``` | instruction | 0 | 93,828 | 3 | 187,656 |
Yes | output | 1 | 93,828 | 3 | 187,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors.
Submitted Solution:
```
def euclid(a, b, num_iterations = 0):
return (euclid(b, a % b, num_iterations + a // b) if b else num_iterations)
a, b = map(int, input().split())
print(euclid(a, b))
``` | instruction | 0 | 93,829 | 3 | 187,658 |
Yes | output | 1 | 93,829 | 3 | 187,659 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors.
Submitted Solution:
```
c=0
a,b=map(int,input().split())
while a!=0 and b!=0:
c+=a//b
a=a%b
a,b=b,a
print(c)
``` | instruction | 0 | 93,830 | 3 | 187,660 |
Yes | output | 1 | 93,830 | 3 | 187,661 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors.
Submitted Solution:
```
from math import gcd
def main():
a, b = map(int, input().split())
r = a // b
ans = r
a = a % b
if a > 0:
a, b = b, a
r = a // b
ans += r
a = a % b
ans += b * a
print(ans)
if __name__ == "__main__":
main()
``` | instruction | 0 | 93,831 | 3 | 187,662 |
No | output | 1 | 93,831 | 3 | 187,663 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors.
Submitted Solution:
```
a,b = map(int, input().split())
count = 0
if a > b:
count = a//b
a = a%b
r0 = ((b**2 - 4*a) + b)//2
r1 = b - r0
print(count + r0+r1)
``` | instruction | 0 | 93,832 | 3 | 187,664 |
No | output | 1 | 93,832 | 3 | 187,665 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors.
Submitted Solution:
```
a, b = map(int, input().strip().split())
ans = a // b
a %= b
if (b != 1):
ans += (b % a) * a + b // a
print(ans)
``` | instruction | 0 | 93,833 | 3 | 187,666 |
No | output | 1 | 93,833 | 3 | 187,667 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
1. one resistor;
2. an element and one resistor plugged in sequence;
3. an element and one resistor plugged in parallel.
<image>
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.
Input
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.
Output
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Examples
Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200
Note
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors.
Submitted Solution:
```
def fun(a,b):
if a==1:
return b
if b==1:
return a
return 1+fun(b%a,a)
a,b=list(map(int,input().split()))
if a<=b:
print(fun(a,b))
else:
print(a//b + fun(a%b,b))
``` | instruction | 0 | 93,834 | 3 | 187,668 |
No | output | 1 | 93,834 | 3 | 187,669 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7. | instruction | 0 | 93,925 | 3 | 187,850 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
hacked = 0
pos = 0
changes = 0
right = True
while hacked < n:
if right:
r = range(pos, n)
else:
r = range(pos, -1, -1)
for i in r:
if a[i] <= hacked:
a[i] = n + 1
hacked += 1
pos = i
if hacked < n:
changes += 1
right = not right
print(changes)
``` | output | 1 | 93,925 | 3 | 187,851 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7. | instruction | 0 | 93,926 | 3 | 187,852 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
sum = 0
ans = 0
f = True
while sum != n:
for i in range(n):
if a[i] <= sum:
a[i] = 100000000000000000000000
sum += 1
if sum == n:
f = False
break
if not f:
break
ans += 1
for i in range(n - 1, -1, -1):
if a[i] <= sum:
a[i] = 1000000000000000000000000000
sum += 1
if sum == n:
f = False
break
if not f:
break
ans += 1
print(ans)
``` | output | 1 | 93,926 | 3 | 187,853 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7. | instruction | 0 | 93,927 | 3 | 187,854 |
Tags: greedy, implementation
Correct Solution:
```
from sys import stdin
live = True
if not live: stdin = open("data.in", "r")
n = int(stdin.readline().strip())
c = list(map(int, stdin.readline().strip().split()))
g = dir = 0
ans = -1
while g != n:
ans += 1
if dir == 0:
for it in range(n):
if c[it] <= g and c[it] != - 1:
g += 1
c[it] = -1
else:
for it in range(n - 1, -1, -1):
if c[it] <= g and c[it] != - 1:
g += 1
c[it] = -1
dir = 1 - dir
print(ans)
if not live: stdin.close()
``` | output | 1 | 93,927 | 3 | 187,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7. | instruction | 0 | 93,928 | 3 | 187,856 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
visited = [False]*n
c = 0
cycles = 0
order = 1
while not all(visited):
for idx,i in enumerate(a[::order]):
if order == -1:
idx = n - idx - 1
if not visited[idx] and i <= c:
c += 1
visited[idx] = True
if all(visited):
break
order = 1 if order < 0 else -1
cycles += 1
print(cycles)
``` | output | 1 | 93,928 | 3 | 187,857 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7. | instruction | 0 | 93,929 | 3 | 187,858 |
Tags: greedy, implementation
Correct Solution:
```
# 583B
# θ(n*log(n)) time
# θ(n) space
from queue import PriorityQueue
__author__ = 'artyom'
# SOLUTION
def main():
n = read()
a = read(3)
if n == 1:
return 0
ix = []
for i in range(n):
ix.append(i)
ix.sort(key=lambda x: a[x])
l = PriorityQueue()
r = PriorityQueue()
i = pos = eg = flag = count = 0
while eg < n:
while i < n and a[ix[i]] <= eg:
if ix[i] > pos:
r.put(ix[i])
elif ix[i] < pos:
l.put(-ix[i])
else:
eg += 1
i += 1
if flag:
if l.empty():
flag = 0
count += 1
pos = r.get()
else:
pos = -l.get()
else:
if r.empty():
flag = 1
count += 1
pos = -l.get()
else:
pos = r.get()
eg += 1
return count
# HELPERS
def read(mode=1, size=None):
# 0: String
# 1: Integer
# 2: List of strings
# 3: List of integers
# 4: Matrix of integers
if mode == 0: return input().strip()
if mode == 1: return int(input().strip())
if mode == 2: return input().strip().split()
if mode == 3: return list(map(int, input().strip().split()))
a = []
for _ in range(size):
a.append(read(3))
return a
def write(s="\n"):
if s is None: s = ''
if isinstance(s, tuple) or isinstance(s, list): s = ' '.join(map(str, s))
s = str(s)
print(s, end="\n")
write(main())
``` | output | 1 | 93,929 | 3 | 187,859 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7. | instruction | 0 | 93,930 | 3 | 187,860 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
arr = list(map(int,input().split()))
info = 0
num =0
count = -1
while num != n:
count += 1
for i in range(n):
if arr[i]<=info:
arr[i] = 2000
info += 1
num += 1
arr.reverse()
print(count)
``` | output | 1 | 93,930 | 3 | 187,861 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7. | instruction | 0 | 93,931 | 3 | 187,862 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
direct = 1
pos = 0
now = 0
res = 0
checked = [0] * n
count = 0
while now < n:
if count < 10:
#print(checked)
count += 1
if direct == 1:
good = 0
for i in range(pos, n):
if checked[i]: continue
if a[i] <= now:
checked[i] = 1
now += 1
pos = i
good = 1
break
if not good:
res += 1
direct = 0
if now == n:
break
if count < 10:
#print(now, direct)
count += 1
if direct == 0:
good = 0
for i in range(pos-1, -1, -1):
if checked[i]: continue
if a[i] <= now:
checked[i] = 1
now += 1
pos = i
good = 1
break
if not good:
direct = 1
res += 1
print(res)
``` | output | 1 | 93,931 | 3 | 187,863 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7. | instruction | 0 | 93,932 | 3 | 187,864 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
cnt = 0
res = 0
while len(a):
b = []
for i in range(len(a)):
if a[i] <= cnt:
cnt += 1
else:
b.append(a[i])
a = b[::-1]
res += 1
print(res - 1)
``` | output | 1 | 93,932 | 3 | 187,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
info=0; i=0; di=0
while 1:
for i in range(n):
if a[i]==-69: continue
if a[i]<=info:
info+=1
a[i]=-69
if info==n: break
a.reverse()
di+=1
print(di)
``` | instruction | 0 | 93,933 | 3 | 187,866 |
Yes | output | 1 | 93,933 | 3 | 187,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
Submitted Solution:
```
n = int(input())
list = [int(x) for x in input().split()]
count = 0 #answer
x = 0 #count level
i = 0 #index
while list!=[]:
count += 1
i = 0
while i < len(list):
if list[i] <= x:
del list[i]
x += 1
else:
i += 1
if list!=[]:
count += 1
i = len(list)-1
while i >= 0:
if list[i] <= x:
x += 1
del list[i]
i -= 1
count -= 1
print(count)
``` | instruction | 0 | 93,934 | 3 | 187,868 |
Yes | output | 1 | 93,934 | 3 | 187,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
Submitted Solution:
```
n = int(input())
lst = [int(x) for x in input().split()]
power = 0
answer = 0
while power != len(lst):
for i in range(len(lst)):
if lst[i] <= power:
power += 1
lst[i] = float('inf')
if power == len(lst):
break
answer += 1
for i in range(len(lst)-1, -1, -1):
if lst[i] <= power:
power += 1
lst[i] = float('inf')
if power == len(lst):
break
answer += 1
print(answer)
``` | instruction | 0 | 93,935 | 3 | 187,870 |
Yes | output | 1 | 93,935 | 3 | 187,871 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
Submitted Solution:
```
n=int(input())
s=list(map(int,input().split()))
c=[0]*n
i=0
o=1
p=-1
d=0
while(i!=n):
if(p+o<0) or (p+o>=n):
o*=-1
d+=1
p+=o
if(c[p]==0 and s[p]<=i):
c[p]=1
i+=1
print(d)
``` | instruction | 0 | 93,936 | 3 | 187,872 |
Yes | output | 1 | 93,936 | 3 | 187,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
co=0
an=-1
while True:
if len(set(a))==1:
break
for i in range(n):
if a[i]<=co:
co+=1
a[i]=10**5
an+=1
if len(set(a))==1:
break
j=n-1
while j>=0:
if a[j]<=co:
co+=1
a[j]=10**5
j-=1
an+=1
print(an)
``` | instruction | 0 | 93,937 | 3 | 187,874 |
No | output | 1 | 93,937 | 3 | 187,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
Submitted Solution:
```
#!/usr/bin/env python3
import copy
def solveLeft(elems, acum=0):
changed = False
for i in range(len(elems)):
if elems[i] is not None and elems[i] <= acum:
acum += 1
elems[i] = None
changed = True
if not changed:
return 0
return 1 + solveRight(elems, acum)
def solveRight(elems, acum=0):
changed = False
for i in reversed(range(len(elems))):
if elems[i] is not None and elems[i] <= acum:
acum += 1
elems[i] = None
changed = True
if not changed:
return 0
return 1 + solveLeft(elems, acum)
def solve(elems):
return min(solveLeft(copy.copy(elems)),
solveRight(copy.copy(elems))) - 1
if __name__ == '__main__':
n = int(input())
elems = list(map(int, input().split()))
print(solve(elems))
``` | instruction | 0 | 93,938 | 3 | 187,876 |
No | output | 1 | 93,938 | 3 | 187,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
Submitted Solution:
```
#!/usr/bin/env python3.4
import time
COL, ROW, LEN = 1000, 1000, 26
matrix = [[0] * COL for i in range(ROW)]
arr = [0] * LEN
direction = ((0, -1), (-1, 0), (0, 1), (1, 0))
class Pair:
def __init__(self, x, y):
self.x = x
self.y = y
def timer(func, *pargs, **kargs):
start = time.time()
func(*pargs, **kargs)
return time.time() - start
def test(a):
answer = 0
for value in a:
if value >= 0:
answer += value
return answer
if __name__ == "__main__":
n = int(input())
arr = list(map(int, input().split()))
ans = -1
volume = 0
direct = 0;
while test(arr):
ans += 1
if direct == 0:
for ind, val in enumerate(arr):
if val <= volume and val != -1:
arr[ind] = -1
volume += 1
else:
for ind in range(len(arr), 0, -1):
if arr[val] <= volume and arr[val] != -1:
arr[ind] = -1
volume += 1
direct += 1
direct %= 2
print(ans)
``` | instruction | 0 | 93,939 | 3 | 187,878 |
No | output | 1 | 93,939 | 3 | 187,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
Examples
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
used = [False for i in range(n)]
k = 0
for i in range(n):
flag = False
for j in range(n):
if a[j] <= k and used[j] == False:
used[j] = True
k += 1
for j in range(n):
if used[j] == False:
flag = True
if flag == False:
print(i + 1)
break
for j in range(n - 1, -1, -1):
if a[j] <= k and used[j] == False:
used[j] = True
k += 1
``` | instruction | 0 | 93,940 | 3 | 187,880 |
No | output | 1 | 93,940 | 3 | 187,881 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances. | instruction | 0 | 93,962 | 3 | 187,924 |
Tags: data structures, geometry, math
Correct Solution:
```
n = int(input())
d = {}
d2 = {}
d3 = {}
ans = 0
for i in range(n):
x,y = map(int,input().split())
if (x,y) not in d:
d[(x,y)] = 0
d[(x,y)] += 1
if x not in d2:
d2[x] = 0
d2[x] += 1
if y not in d3:
d3[y] = 0
d3[y] += 1
for i in d2:
ans += d2[i]*(d2[i]-1)//2
for i in d3:
ans += d3[i]*(d3[i]-1)//2
for i in d:
ans -= d[i]*(d[i]-1)//2
print(ans)
``` | output | 1 | 93,962 | 3 | 187,925 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances. | instruction | 0 | 93,963 | 3 | 187,926 |
Tags: data structures, geometry, math
Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def inc_val_of_dict(dictionary, key):
if key not in dictionary:
dictionary[key] = 0
dictionary[key] += 1
def main():
n = int(input())
p_ctr = dict()
x_ctr = dict()
y_ctr = dict()
for _ in range(n):
x, y = map(int, input().split())
inc_val_of_dict(p_ctr, (x, y))
inc_val_of_dict(x_ctr, x)
inc_val_of_dict(y_ctr, y)
answer = 0
for (x, y), num in p_ctr.items():
answer += num * (x_ctr[x] + y_ctr[y] - p_ctr[(x, y)] - 1)
answer //= 2
print(answer)
if __name__ == '__main__':
main()
``` | output | 1 | 93,963 | 3 | 187,927 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances. | instruction | 0 | 93,964 | 3 | 187,928 |
Tags: data structures, geometry, math
Correct Solution:
```
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
def summa_maksonchik_top_potomu_chto_pishet_cod_na_scretche(n_maksonchik_top_potomu_chto_pishet_cod_na_scretche):
ans_maksonchik_top_potomu_chto_pishet_cod_na_scretche = 0
while n_maksonchik_top_potomu_chto_pishet_cod_na_scretche > 0:
ans_maksonchik_top_potomu_chto_pishet_cod_na_scretche += n_maksonchik_top_potomu_chto_pishet_cod_na_scretche
n_maksonchik_top_potomu_chto_pishet_cod_na_scretche -= 1
return ans_maksonchik_top_potomu_chto_pishet_cod_na_scretche
import sys
n_maksonchik_top_potomu_chto_pishet_cod_na_scretche = int(sys.stdin.readline())
a_maksonchik_top_potomu_chto_pishet_cod_na_scretche = []
ans_maksonchik_top_potomu_chto_pishet_cod_na_scretche = 0
for i_maksonchik_top_potomu_chto_pishet_cod_na_scretche in range(n_maksonchik_top_potomu_chto_pishet_cod_na_scretche):
a_maksonchik_top_potomu_chto_pishet_cod_na_scretche.append(tuple(map(int, sys.stdin.readline().split())))
b_maksonchik_top_potomu_chto_pishet_cod_na_scretche = {}
x_maksonchik_top_potomu_chto_pishet_cod_na_scretche = {}
for i_maksonchik_top_potomu_chto_pishet_cod_na_scretche in a_maksonchik_top_potomu_chto_pishet_cod_na_scretche:
if i_maksonchik_top_potomu_chto_pishet_cod_na_scretche [0] not in x_maksonchik_top_potomu_chto_pishet_cod_na_scretche :
x_maksonchik_top_potomu_chto_pishet_cod_na_scretche[i_maksonchik_top_potomu_chto_pishet_cod_na_scretche[0]] = [1, 0]
b_maksonchik_top_potomu_chto_pishet_cod_na_scretche[i_maksonchik_top_potomu_chto_pishet_cod_na_scretche] = 1
else:
if i_maksonchik_top_potomu_chto_pishet_cod_na_scretche not in b_maksonchik_top_potomu_chto_pishet_cod_na_scretche:
b_maksonchik_top_potomu_chto_pishet_cod_na_scretche[i_maksonchik_top_potomu_chto_pishet_cod_na_scretche] = 1
else:
b_maksonchik_top_potomu_chto_pishet_cod_na_scretche[i_maksonchik_top_potomu_chto_pishet_cod_na_scretche] += 1
x_maksonchik_top_potomu_chto_pishet_cod_na_scretche[i_maksonchik_top_potomu_chto_pishet_cod_na_scretche[0]][0] += 1
x_maksonchik_top_potomu_chto_pishet_cod_na_scretche[i_maksonchik_top_potomu_chto_pishet_cod_na_scretche[0]][1] += x_maksonchik_top_potomu_chto_pishet_cod_na_scretche[i_maksonchik_top_potomu_chto_pishet_cod_na_scretche[0]][0]-1
for i_maksonchik_top_potomu_chto_pishet_cod_na_scretche in x_maksonchik_top_potomu_chto_pishet_cod_na_scretche.values():
ans_maksonchik_top_potomu_chto_pishet_cod_na_scretche += i_maksonchik_top_potomu_chto_pishet_cod_na_scretche[1]
y_maksonchik_top_potomu_chto_pishet_cod_na_scretche = {}
for i_maksonchik_top_potomu_chto_pishet_cod_na_scretche in a_maksonchik_top_potomu_chto_pishet_cod_na_scretche:
if i_maksonchik_top_potomu_chto_pishet_cod_na_scretche[1] not in y_maksonchik_top_potomu_chto_pishet_cod_na_scretche:
y_maksonchik_top_potomu_chto_pishet_cod_na_scretche[i_maksonchik_top_potomu_chto_pishet_cod_na_scretche[1]] = [1, 0]
else:
y_maksonchik_top_potomu_chto_pishet_cod_na_scretche[i_maksonchik_top_potomu_chto_pishet_cod_na_scretche[1]][0] += 1
y_maksonchik_top_potomu_chto_pishet_cod_na_scretche[i_maksonchik_top_potomu_chto_pishet_cod_na_scretche[1]][1] += y_maksonchik_top_potomu_chto_pishet_cod_na_scretche[i_maksonchik_top_potomu_chto_pishet_cod_na_scretche[1]][0]-1
for i_maksonchik_top_potomu_chto_pishet_cod_na_scretche in y_maksonchik_top_potomu_chto_pishet_cod_na_scretche.values():
ans_maksonchik_top_potomu_chto_pishet_cod_na_scretche += i_maksonchik_top_potomu_chto_pishet_cod_na_scretche[1]
for i_maksonchik_top_potomu_chto_pishet_cod_na_scretche in b_maksonchik_top_potomu_chto_pishet_cod_na_scretche.values():
if i_maksonchik_top_potomu_chto_pishet_cod_na_scretche > 1:
ans_maksonchik_top_potomu_chto_pishet_cod_na_scretche -= summa_maksonchik_top_potomu_chto_pishet_cod_na_scretche(i_maksonchik_top_potomu_chto_pishet_cod_na_scretche-1)
print(ans_maksonchik_top_potomu_chto_pishet_cod_na_scretche)
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
#maksonchiktoppotomuchtopishetcodnascretche
``` | output | 1 | 93,964 | 3 | 187,929 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances. | instruction | 0 | 93,965 | 3 | 187,930 |
Tags: data structures, geometry, math
Correct Solution:
```
n=int(input())
a =0
b =0
s1 = {}
s2 = {}
s3 = {}
for i in range(n):
a,b = map(int, input().split())
s1[a]=s1.get(a,0)+1
s2[b]=s2.get(b,0)+1
tmp = (a,b)
s3[tmp] = s3.get(tmp,0)+1
sum=0
for i in s1.values():
sum+=(i-1)*(i)//2
for i in s2.values():
sum+=(i-1)*(i)//2
for i in s3.values():
sum-=(i-1)*(i)//2
print(sum)
``` | output | 1 | 93,965 | 3 | 187,931 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.
The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input
The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen.
Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109).
Some positions may coincide.
Output
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
Note
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances. | instruction | 0 | 93,966 | 3 | 187,932 |
Tags: data structures, geometry, math
Correct Solution:
```
n=int(input())
d1={}
d2={}
same={}
for i in range(n):
a,b=map(int,input().split())
if a in d1.keys():
d1[a]+=1
else:
d1[a]=1
if b in d2.keys():
d2[b]+=1
else:
d2[b]=1
#print(a,b)
if (a,b) in same.keys():
same[(a,b)]+=1
else:
same[(a,b)]=1
#print(d1,d2,same)
ans=0
for i in d1.keys():
if d1[i]>1:
ans+=(d1[i]*(d1[i]-1))//2
for i in d2.keys():
if d2[i]>1:
ans+=(d2[i]*(d2[i]-1))//2
#print(ans)
for i in same.keys():
if same[i]>1:
ans-=(same[i]*(same[i]-1))//2
print(ans)
``` | output | 1 | 93,966 | 3 | 187,933 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.