message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
<image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2.
Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1).
Given Bolek's final picture, restore the initial one.
Input
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.
Output
Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.
Examples
Input
3 2
0 5 3 5 1 5 2
Output
0 5 3 4 1 4 2
Input
1 1
0 2 0
Output
0 1 0
Submitted Solution:
```
n,k=input().split()
n=int(n)
k=int(k)
arr=list(map(int,input().split()))
count=0
for index in range(1,(2*n)+1,2):
if arr[index]-1>arr[index-1] and arr[index]-1>arr[index+1] and count<k:
arr[index]=arr[index]-1
count=count+1
print(*arr)
``` | instruction | 0 | 105,550 | 23 | 211,100 |
Yes | output | 1 | 105,550 | 23 | 211,101 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
<image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2.
Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1).
Given Bolek's final picture, restore the initial one.
Input
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.
Output
Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.
Examples
Input
3 2
0 5 3 5 1 5 2
Output
0 5 3 4 1 4 2
Input
1 1
0 2 0
Output
0 1 0
Submitted Solution:
```
nk = input().strip().split(' ')
n = int(nk[0])
k = int(nk[1])
pks = input().strip().split(' ')
pks = [int(p) for p in pks]
for i in range(1, 2*n, 2):
if pks[i]-1>pks[i-1] and pks[i]-1>pks[i+1]:
pks[i]-= 1
k -= 1
if k==0:
break
for i in range(2*n+1):
print(pks[i], end=' ')
``` | instruction | 0 | 105,551 | 23 | 211,102 |
Yes | output | 1 | 105,551 | 23 | 211,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
<image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2.
Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1).
Given Bolek's final picture, restore the initial one.
Input
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.
Output
Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.
Examples
Input
3 2
0 5 3 5 1 5 2
Output
0 5 3 4 1 4 2
Input
1 1
0 2 0
Output
0 1 0
Submitted Solution:
```
def main():
n, k = map(int, input().split())
r = list(map(int, input().split()))
for i in range(1, n * 2, 2):
if k and r[i - 1] < r[i] - 1 > r[i + 1]:
r[i] -= 1
k -= 1
print(*r)
if __name__ == '__main__':
main()
``` | instruction | 0 | 105,552 | 23 | 211,104 |
Yes | output | 1 | 105,552 | 23 | 211,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
<image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2.
Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1).
Given Bolek's final picture, restore the initial one.
Input
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.
Output
Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.
Examples
Input
3 2
0 5 3 5 1 5 2
Output
0 5 3 4 1 4 2
Input
1 1
0 2 0
Output
0 1 0
Submitted Solution:
```
n, k = [int(i) for i in input().split()]
points = [int(i) for i in input().split()]
peaks = {}
for i in range(2 * n - 1):
if points[i] < points[i + 1] and points[i + 1] > points[i + 2]:
if points[i] < points[i + 1] - 1 and points[i + 1] - 1 > points[i + 2]:
peaks[i + 1] = points[i + 1] - 1
high = list(peaks.keys())
selected = high[:k]
for i in range(len(points)):
if i in selected:
print(peaks[i], end=" ")
else:
print(points[i], end=" ")
``` | instruction | 0 | 105,553 | 23 | 211,106 |
Yes | output | 1 | 105,553 | 23 | 211,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
<image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2.
Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1).
Given Bolek's final picture, restore the initial one.
Input
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.
Output
Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.
Examples
Input
3 2
0 5 3 5 1 5 2
Output
0 5 3 4 1 4 2
Input
1 1
0 2 0
Output
0 1 0
Submitted Solution:
```
n , k = map(int , input().split())
l = list(map (int , input().split()))
i = 1
while k:
if l[i-1] < l[i]-1 and l[i+1] < l[i]-1 :
l[i]-=1
k-=1
i+=2
print(*l)
``` | instruction | 0 | 105,554 | 23 | 211,108 |
No | output | 1 | 105,554 | 23 | 211,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
<image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2.
Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1).
Given Bolek's final picture, restore the initial one.
Input
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.
Output
Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.
Examples
Input
3 2
0 5 3 5 1 5 2
Output
0 5 3 4 1 4 2
Input
1 1
0 2 0
Output
0 1 0
Submitted Solution:
```
_, k = map(int, input().strip().split())
ys = [*map(int, input().strip().split())]
new_ys = [y - 1 if k and i >= 2 and not i % 2 and ys[i-1] < y - 1 and (k := k - 1) else y for i, y in enumerate(ys, 1) ]
print(' '.join(str(y) for y in new_ys))
``` | instruction | 0 | 105,555 | 23 | 211,110 |
No | output | 1 | 105,555 | 23 | 211,111 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
<image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2.
Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1).
Given Bolek's final picture, restore the initial one.
Input
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.
Output
Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.
Examples
Input
3 2
0 5 3 5 1 5 2
Output
0 5 3 4 1 4 2
Input
1 1
0 2 0
Output
0 1 0
Submitted Solution:
```
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(2,2*n):
if (i+1)%2!=0:
continue
if k==0:
break
if a[i]>a[i-1] and a[i]>a[i+1]:
a[i]-=1
k-=1
print(*a)
``` | instruction | 0 | 105,556 | 23 | 211,112 |
No | output | 1 | 105,556 | 23 | 211,113 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
<image> The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2.
Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1).
Given Bolek's final picture, restore the initial one.
Input
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.
Output
Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.
Examples
Input
3 2
0 5 3 5 1 5 2
Output
0 5 3 4 1 4 2
Input
1 1
0 2 0
Output
0 1 0
Submitted Solution:
```
def capitalization(inpu):
m=inpu[0].upper()
return m+inpu[1:len(inpu)]
u=input()
print(capitalization(u))
``` | instruction | 0 | 105,557 | 23 | 211,114 |
No | output | 1 | 105,557 | 23 | 211,115 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.
Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.
Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Input
The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.
Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.
Output
Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Examples
Input
5
1 10
2 9
3 9
2 3
2 9
Output
2 1
Input
3
1 5
2 6
6 20
Output
-1 -1
Note
In the first example the following pairs are considered correct:
* (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;
* (3, 2), (4, 2), (3, 5), (4, 5) — touch one border;
* (5, 2), (2, 5) — match exactly.
Submitted Solution:
```
import sys
n = int(sys.stdin.readline())
intervals = list(map(lambda x : (int(x[0]), int(x[1])), map(str.split, sys.stdin.readlines())))
intervals = list(enumerate(intervals))
intervals.sort(key=lambda x : 1000000009 * x[1][0] - x[1][1])
r = 0
ans1 = -1
ans2 = -1
for interval in intervals:
if interval[1][1] <= r:
ans1 = interval[0]
break
else:
ans2 = interval[0]
r = interval[1][1]
if ans1 == -1:
print('-1 -1')
else:
print(ans1 +1, ans2 +1)
``` | instruction | 0 | 105,875 | 23 | 211,750 |
Yes | output | 1 | 105,875 | 23 | 211,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.
Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.
Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Input
The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.
Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.
Output
Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Examples
Input
5
1 10
2 9
3 9
2 3
2 9
Output
2 1
Input
3
1 5
2 6
6 20
Output
-1 -1
Note
In the first example the following pairs are considered correct:
* (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;
* (3, 2), (4, 2), (3, 5), (4, 5) — touch one border;
* (5, 2), (2, 5) — match exactly.
Submitted Solution:
```
def main():
n = int(input())
arr = []
for i in range(n):
arr.append(list(map(int, input().split())) + [i + 1])
arr.sort(key=lambda x:[x[0], -x[1]])
ind = 0
for i in range(1, len(arr)):
if arr[ind][1] >= arr[i][1]:
print(arr[i][2], arr[ind][2])
return
else:
ind = i
print(-1, -1)
main()
``` | instruction | 0 | 105,876 | 23 | 211,752 |
Yes | output | 1 | 105,876 | 23 | 211,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.
Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.
Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Input
The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.
Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.
Output
Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Examples
Input
5
1 10
2 9
3 9
2 3
2 9
Output
2 1
Input
3
1 5
2 6
6 20
Output
-1 -1
Note
In the first example the following pairs are considered correct:
* (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;
* (3, 2), (4, 2), (3, 5), (4, 5) — touch one border;
* (5, 2), (2, 5) — match exactly.
Submitted Solution:
```
n = int(input())
L = []
for i in range(n):
l,r = map(int,input().split())
L.append((l,-r,i+1))
L = sorted(L)
f = 0
for i in range(1,n):
if L[i-1][1] <= L[i][1]:
f = 1
print(L[i][2],L[i-1][2])
break
if f == 0:
print(-1,-1)
``` | instruction | 0 | 105,877 | 23 | 211,754 |
Yes | output | 1 | 105,877 | 23 | 211,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.
Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.
Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Input
The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.
Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.
Output
Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Examples
Input
5
1 10
2 9
3 9
2 3
2 9
Output
2 1
Input
3
1 5
2 6
6 20
Output
-1 -1
Note
In the first example the following pairs are considered correct:
* (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;
* (3, 2), (4, 2), (3, 5), (4, 5) — touch one border;
* (5, 2), (2, 5) — match exactly.
Submitted Solution:
```
n = int(input())
segments = []
for _ in range(n):
x, y = map(int, input().split())
segments.append((x,y))
segments = sorted(segments, key=lambda seg: seg[1], reverse=True)
segments = sorted(segments, key=lambda seg: seg[0], reverse=False)
max_seg = (-1,-1)
output = (-1, -1)
# print(segments)
for i in range(n):
if segments[i][1] > max_seg[0]:
max_seg = (segments[i][1], i)
else:
fst = segments.index(segments[i]) + 1
snd = segments.index(segments[max_seg[1]]) + 1
# print(str(max_seg[1]) + ' ' + str(i))
print(str(fst) + ' ' + str(snd))
break
if max_seg == (-1, -1):
print('-1 -1')
``` | instruction | 0 | 105,878 | 23 | 211,756 |
No | output | 1 | 105,878 | 23 | 211,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.
Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.
Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Input
The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.
Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.
Output
Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Examples
Input
5
1 10
2 9
3 9
2 3
2 9
Output
2 1
Input
3
1 5
2 6
6 20
Output
-1 -1
Note
In the first example the following pairs are considered correct:
* (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;
* (3, 2), (4, 2), (3, 5), (4, 5) — touch one border;
* (5, 2), (2, 5) — match exactly.
Submitted Solution:
```
#Failed
n = int(input())
def divconq(seq):
if(len(seq) <= 1):
return False
eraser = seq[len(seq)//2]
skip_index = len(seq)//2
left = []
left_out = False
right_out = False
left_border = False
right_border = False
# l_c = 0
right = []
#r_c = 0
for i in range(len(seq)):
if not i == skip_index:
if seq[i][0] < eraser[0]:
left_out = True
if seq[i][1] > eraser[1]:
right_out = True
if seq[i][0] == eraser[0]:
left_border = True
if seq[i][1] == eraser[1]:
right_border = True
if ((left_out or left_border) and (right_border or right_out)) or ((not left_out) and (not right_out)):
if eraser[1]-eraser[0] >= seq[i][1] - seq[i][0]:
print(eraser[2],seq[i][2])
else:
print(seq[i][2],eraser[2])
return True
elif left_out:
left.append(seq[i])
else:
right.append(seq[i])
left_out = False
right_out = False
left_border = False
right_border = False
return divconq(left) or divconq(right)
seq = []
for i in range(n):
seq.append(list(map(int,input().split())))
seq[i].append(i+1)
seq = sorted(seq,key = lambda x : (x[0],-x[1],x[2]))
if not divconq(seq):
print(-1,-1)
``` | instruction | 0 | 105,879 | 23 | 211,758 |
No | output | 1 | 105,879 | 23 | 211,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.
Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.
Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Input
The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.
Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.
Output
Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Examples
Input
5
1 10
2 9
3 9
2 3
2 9
Output
2 1
Input
3
1 5
2 6
6 20
Output
-1 -1
Note
In the first example the following pairs are considered correct:
* (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;
* (3, 2), (4, 2), (3, 5), (4, 5) — touch one border;
* (5, 2), (2, 5) — match exactly.
Submitted Solution:
```
n=int(input())
segs=[]
for i in range(n):
a,b=map(int,input().split())
segs.append([a,b,i])
segs.sort(key=lambda x:x[0])
for i in range(1,n):
if segs[i][1]<=segs[0][1]:
print(segs[i][2]+1,segs[0][2]+1)
exit()
segs.sort(key=lambda x:-x[1])
for i in range(1,n):
if segs[i][0]>=segs[0][0]:
print(segs[i][2]+1,segs[0][2]+1)
print('-1 -1')
``` | instruction | 0 | 105,880 | 23 | 211,760 |
No | output | 1 | 105,880 | 23 | 211,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.
Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.
Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Input
The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.
Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.
Output
Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Examples
Input
5
1 10
2 9
3 9
2 3
2 9
Output
2 1
Input
3
1 5
2 6
6 20
Output
-1 -1
Note
In the first example the following pairs are considered correct:
* (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;
* (3, 2), (4, 2), (3, 5), (4, 5) — touch one border;
* (5, 2), (2, 5) — match exactly.
Submitted Solution:
```
N = int(input())
A = []
for i in range(1, N+1):
l, r = map(int, input().split())
A.append([l, r, i])
A.sort(key=lambda x:x[0])
if N == 1:
print(-1, -1)
quit()
a = A[0][1]
for i in range(1, N):
if i == 1 and A[1][0] == A[0][0] and A[0][1] > A[1][1]:
print(A[0][2], A[1][2])
elif A[i][1] <= a:
print(A[i][2], A[i-1][2])
quit()
else:
if i == N-1:
print(-1, -1)
quit()
else:
a = A[i][1]
``` | instruction | 0 | 105,881 | 23 | 211,762 |
No | output | 1 | 105,881 | 23 | 211,763 |
Provide a correct Python 3 solution for this coding contest problem.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9 | instruction | 0 | 106,038 | 23 | 212,076 |
"Correct Solution:
```
print((lambda x : int(x[0]) + int(x[1]) + 1 - (lambda *x, f=lambda f, x, y: f(f, y, x % y) if y else x: f(f, *x))(int(x[0]),int(x[1])))(input().split()))
``` | output | 1 | 106,038 | 23 | 212,077 |
Provide a correct Python 3 solution for this coding contest problem.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9 | instruction | 0 | 106,039 | 23 | 212,078 |
"Correct Solution:
```
import math
x,y=map(int,input().split())
k=math.gcd(x,y)
if k==1:
print(x+y)
else:
m=2*x//k
print(x+y+1-2*x//m)
``` | output | 1 | 106,039 | 23 | 212,079 |
Provide a correct Python 3 solution for this coding contest problem.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9 | instruction | 0 | 106,040 | 23 | 212,080 |
"Correct Solution:
```
def GCD(M, N) :
while True :
if N < M :
N, M = M, N
amari = N % M
if amari == 0 :
break
else :
N, M = M, amari
return M
x, y = map(int, input().split())
gcd = GCD(x, y)
x = x / gcd
y = y / gcd
print(int(x-1 + y-1 + 1) * gcd + 1)
``` | output | 1 | 106,040 | 23 | 212,081 |
Provide a correct Python 3 solution for this coding contest problem.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9 | instruction | 0 | 106,041 | 23 | 212,082 |
"Correct Solution:
```
import math
x, y = map(int, input().split())
g = math.gcd(x, y)
print(x+y-g+1)
``` | output | 1 | 106,041 | 23 | 212,083 |
Provide a correct Python 3 solution for this coding contest problem.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9 | instruction | 0 | 106,042 | 23 | 212,084 |
"Correct Solution:
```
x, y = map(int, input().split())
def eu(x, y):
p, q = max(x, y), min(x, y)
while p % q != 0:p, q = q, p % q
return q
print(x + y - eu(x, y) + 1)
``` | output | 1 | 106,042 | 23 | 212,085 |
Provide a correct Python 3 solution for this coding contest problem.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9 | instruction | 0 | 106,043 | 23 | 212,086 |
"Correct Solution:
```
il = lambda: list(map(int, input().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]
def gcd(a, b):
if a < b: return gcd(b, a)
if b == 0: return a
return gcd(b, a%b)
x, y = il()
a = gcd(x, y)
print(x+y-a+1)
``` | output | 1 | 106,043 | 23 | 212,087 |
Provide a correct Python 3 solution for this coding contest problem.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9 | instruction | 0 | 106,044 | 23 | 212,088 |
"Correct Solution:
```
from math import gcd
x,y=map(int,input().split())
print(x+y-gcd(x,y)+1)
``` | output | 1 | 106,044 | 23 | 212,089 |
Provide a correct Python 3 solution for this coding contest problem.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9 | instruction | 0 | 106,045 | 23 | 212,090 |
"Correct Solution:
```
import math
x,y=list(map(int,input().split()))
print(x+y-math.gcd(x,y)+1)
``` | output | 1 | 106,045 | 23 | 212,091 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9
Submitted Solution:
```
def gcd(m, n):
r = m % n
return gcd(n, r) if r else n
x, y = map(int, input().split())
g = gcd(x, y)
print(((x // g - 1) + (y // g - 1) + 1) * g + 1)
``` | instruction | 0 | 106,046 | 23 | 212,092 |
Yes | output | 1 | 106,046 | 23 | 212,093 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9
Submitted Solution:
```
from math import gcd
x, y = map(int, input().split())
print(x + 1 + y + 1 - gcd(x, y) - 1)
``` | instruction | 0 | 106,047 | 23 | 212,094 |
Yes | output | 1 | 106,047 | 23 | 212,095 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9
Submitted Solution:
```
def gcd(p,q):
if p<q:
return gcd(q,p)
if p%q==0:
return q
else:
return gcd(q,p%q)
x,y = map(int,list(input().split(" ")))
print(x+y+1-gcd(x,y))
``` | instruction | 0 | 106,048 | 23 | 212,096 |
Yes | output | 1 | 106,048 | 23 | 212,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9
Submitted Solution:
```
import math
a,b = map(int,input().split())
print(a+b-(math.gcd(a,b))+1)
``` | instruction | 0 | 106,049 | 23 | 212,098 |
Yes | output | 1 | 106,049 | 23 | 212,099 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9
Submitted Solution:
```
print((lambda x,y : x + y + 1 - (lambda *x, f=lambda f, x, y: f(f, y, x % y) if y else x: f(f, *x))(x,y))(int(input()),int(input())))
``` | instruction | 0 | 106,050 | 23 | 212,100 |
No | output | 1 | 106,050 | 23 | 212,101 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)
Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
Input
The input is given in the following format.
x y
A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
Output
Output the number of points where the wire intersects with the panel boundaries.
Examples
Input
4 4
Output
5
Input
4 6
Output
9
Submitted Solution:
```
x, y = map(int, input().split())
if x == y:
print(x+1)
else:
print(min(x, y ) + 1 + abs(x - y) * 2)
``` | instruction | 0 | 106,051 | 23 | 212,102 |
No | output | 1 | 106,051 | 23 | 212,103 |
Provide a correct Python 3 solution for this coding contest problem.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0 | instruction | 0 | 106,085 | 23 | 212,170 |
"Correct Solution:
```
from itertools import starmap
q = int(input())
while q:
q -= 1
p0, p1, p2, p3 = starmap(complex, zip(*[map(int, input().split())] * 2))
prod = (p1 - p0).conjugate() * (p3 - p2)
print(2 if abs(prod.imag) < 1e-6 else 1 if abs(prod.real) < 1e-6 else 0)
``` | output | 1 | 106,085 | 23 | 212,171 |
Provide a correct Python 3 solution for this coding contest problem.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0 | instruction | 0 | 106,086 | 23 | 212,172 |
"Correct Solution:
```
q = int(input())
for _ in range(q):
x0, y0, x1, y1, x2, y2, x3, y3 = map(int, input().split())
dot = (x1 - x0)*(x3 - x2) + (y1 - y0)*(y3 - y2)
if dot == 0:
print(1)
elif ((x1 - x0)**2 + (y1 - y0)**2)*((x3 - x2)**2 + (y3 - y2)**2) == dot**2:
print(2)
else:
print(0)
``` | output | 1 | 106,086 | 23 | 212,173 |
Provide a correct Python 3 solution for this coding contest problem.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0 | instruction | 0 | 106,087 | 23 | 212,174 |
"Correct Solution:
```
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __repr__(self):
return f"({self.x},{self.y})"
class Segment:
def __init__(self, x: Point, y: Point):
self.pt1 = x
self.pt2 = y
self.vector = self.pt2 - self.pt1
def dot(self, other):
return self.vector.x * other.vector.x + self.vector.y * other.vector.y
def cross(self, other):
return self.vector.x * other.vector.y - self.vector.y * other.vector.x
def __repr__(self):
return f"{self.pt1},{self.pt2},{self.vector}"
def main():
n = int(input())
for i in range(n):
p0_x, p0_y, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y = map(int, input().split())
seg_1 = Segment(Point(p0_x, p0_y), Point(p1_x, p1_y))
seg_2 = Segment(Point(p2_x, p2_y), Point(p3_x, p3_y))
if seg_1.dot(seg_2) == 0:
print('1')
elif seg_1.cross(seg_2) == 0:
print('2')
else:
print('0')
return
main()
``` | output | 1 | 106,087 | 23 | 212,175 |
Provide a correct Python 3 solution for this coding contest problem.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0 | instruction | 0 | 106,088 | 23 | 212,176 |
"Correct Solution:
```
#内積0の場合直行している
#外積0の場合平行
def main():
q = int(input())
for i in range(q):
print(parallel_orthogonal())
def parallel_orthogonal():
xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(int, input().split())
l1_start = complex(xp0, yp0)
l1_end = complex(xp1, yp1)
l2_start = complex(xp2, yp2)
l2_end = complex(xp3, yp3)
if 0 == dot(l1_end - l1_start, l2_end - l2_start):
return 1
if 0 == cross(l1_end - l1_start, l2_end - l2_start):
return 2
return 0
# p0..p3がそれぞれ座標になっている
#内積
def dot(a, b):
return a.real * b.real + a.imag * b.imag
#外積
def cross(a, b):
return a.real * b.imag - a.imag * b.real
main()
``` | output | 1 | 106,088 | 23 | 212,177 |
Provide a correct Python 3 solution for this coding contest problem.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0 | instruction | 0 | 106,089 | 23 | 212,178 |
"Correct Solution:
```
import sys
def get_line(line_info):
for line_pair in line_info:
line_axis = tuple(map(int, line_pair))
p0, p1, p2, p3 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
# print(p0, p1, p2, p3)
if dot(p1 - p0, p3 - p2) == 0:
print('1')
elif cross(p1 - p0, p3 - p2) == 0:
print('2')
else:
print('0')
return line_info
def cross(a, b):
return a.real * b.imag - a.imag * b.real
def dot(a, b):
return a.real * b.real + a.imag * b.imag
if __name__ == '__main__':
_input = sys.stdin.readlines()
questions = int(_input[0])
lines = map(lambda x: x.split(), _input[1:])
ans = get_line(lines)
``` | output | 1 | 106,089 | 23 | 212,179 |
Provide a correct Python 3 solution for this coding contest problem.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0 | instruction | 0 | 106,090 | 23 | 212,180 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A&lang=jp
"""
import sys
from sys import stdin
input = stdin.readline
class Point(object):
epsilon = 1e-10
def __init__(self, x=0.0, y=0.0):
if isinstance(x, tuple):
self.x = x[0]
self.y = x[1]
else:
self.x = x
self.y = y
# ????????????
def __add__(self, other):
return (self.x + other.x, self.y + other.y)
def __sub__(self, other):
return (self.x - other.x, self.y - other.y)
def __mul__(self, other):
return (other * self.x, other * self.y)
def __truediv__(self, other):
return (other / self.x, other / self.y)
def __lt__(self, other):
if self.x == other.x:
return self.y < other.y
else:
return self.x < other.x
def __eq__(self, other):
from math import fabs
if fabs(self.x - other.x) < Point.epsilon and fabs(self.y - other.y) < Point.epsilon:
return True
else:
return False
def norm(self):
return self.x * self.x + self.y * self.y
def abs(self):
from math import sqrt
return sqrt(self.norm())
class Vector(Point):
@classmethod
def dot(cls, a, b):
return a.x * b.x + a.y * b.y
@classmethod
def cross(cls, a, b):
return a.x * b.y - a.y * b.x
@classmethod
def is_orthogonal(cls, a, b):
return Vector.dot(a, b) == 0.0
@classmethod
def is_parallel(cls, a, b):
return Vector.cross(a, b) == 0.0
class Segment(object):
def __init__(self, p1=Point(), p2=Point()):
if isinstance(p1, Point):
self.p1 = p1
self.p2 = p2
elif isinstance(p1, tuple):
self.p1 = Point(p1[0], p1[1])
self.p2 = Point(p2[0], p2[1])
@classmethod
def is_orthogonal(cls, s1, s2):
a = Vector(s1.p2 - s1.p1)
b = Vector(s2.p2 - s2.p1)
return Vector.is_orthogonal(a, b)
@classmethod
def is_parallel(cls, s1, s2):
a = Vector(s1.p2 - s1.p1)
b = Vector(s2.p2 - s2.p1)
return Vector.is_parallel(a, b)
class Line(Segment):
pass
class Cirle(object):
def __init__(self, c=Point(), r=0.0):
self.c = c
self.r = r
def solve(data):
x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = data
a = Segment((x_p0, y_p0), (x_p1, y_p1))
b = Segment((x_p2, y_p2), (x_p3, y_p3))
if Segment.is_orthogonal(a, b):
return 1
elif Segment.is_parallel(a, b):
return 2
else:
return 0
def main(args):
q = int(input())
for _ in range(q):
result = solve([int(x) for x in input().split()])
print(result)
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 106,090 | 23 | 212,181 |
Provide a correct Python 3 solution for this coding contest problem.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0 | instruction | 0 | 106,091 | 23 | 212,182 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')
# ベクトルの内積
def dot(a, b):
x1,y1=a
x2,y2=b
return x1*x2+y1*y2
# ベクトルの外積
def cross(a, b):
x1,y1=a
x2,y2=b
return x1*y2-y1*x2
Q=INT()
for _ in range(Q):
x1,y1,x2,y2,x3,y3,x4,y4=MAP()
# 2直線のベクトルを出しておく
# (今回は方向だけ分かればよくて向きはどっちでもいいので、x1-x2かx2-x1かはどっちでもいい。
# ただしxとyでどっちにするかは揃える。)
v1=(x1-x2, y1-y2)
v2=(x3-x4, y3-y4)
# 直交判定(内積が0)
if dot(v1, v2)==0:
print(1)
# 平行判定(外積が0)
elif cross(v1, v2)==0:
print(2)
else:
print(0)
``` | output | 1 | 106,091 | 23 | 212,183 |
Provide a correct Python 3 solution for this coding contest problem.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0 | instruction | 0 | 106,092 | 23 | 212,184 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
import os
import pprint
#fd = os.open('CGL_2_A.txt', os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())
def judge(lst):
x0, y0, x1, y1, x2, y2, x3, y3 = lst
v0 = (x1 - x0, y1 - y0)
v1 = (x3 - x2, y3 - y2)
dot = v0[0] * v1[0] + v0[1] * v1[1]
cross = v0[0] * v1[1] - v0[1] * v1[0]
if dot == 0:
print(1)
elif cross == 0:
print(2)
else:
print(0)
N = int(input())
for i in range(N):
lst = list(map(int, input().split()))
judge(lst)
``` | output | 1 | 106,092 | 23 | 212,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0
Submitted Solution:
```
import sys
readline = sys.stdin.readline
n = int(readline())
def cross(a, b):
return a.real * b.imag - a.imag * b.real
def dot(a, b):
return a.real * b.real + a.imag * b.imag
for _ in [0] * n:
line_axis = tuple(map(int, readline().split()))
p0, p1, p2, p3 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
if dot(p1 - p0, p3 - p2) == 0:
print('1')
elif cross(p1 - p0, p3 - p2) == 0:
print('2')
else:
print('0')
``` | instruction | 0 | 106,093 | 23 | 212,186 |
Yes | output | 1 | 106,093 | 23 | 212,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0
Submitted Solution:
```
import sys
readline = sys.stdin.readline
n = int(readline())
def cross(a, b):
return a.real * b.imag - a.imag * b.real
def dot(a, b):
return a.real * b.real + a.imag * b.imag
for _ in [0] * n:
line_axis = tuple(map(int, readline().split()))
p0, p1, p2, p3 = (complex(x, y) for x, y in zip(line_axis[::2], line_axis[1::2]))
if dot(p1 - p0, p3 - p2) == 0:
print('1')
elif cross(p1 - p0, p3 - p2) == 0:
print('2')
else:
print('0')
``` | instruction | 0 | 106,094 | 23 | 212,188 |
Yes | output | 1 | 106,094 | 23 | 212,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0
Submitted Solution:
```
# coding=utf-8
def vector_product(vect1, vect2):
return [el1 * el2 for el1, el2 in zip(vect1, vect2)]
def inner_product(vect1, vect2):
return sum(vector_product(vect1, vect2))
def cross_product(vect1, vect2):
return vect1[0]*vect2[1] - vect1[1]*vect2[0]
def vector_minus(vect1, vect2):
return [el1 - el2 for el1, el2 in zip(vect1, vect2)]
def line_slope(line_from, line_to):
try:
slope = (line_to[1] - line_from[1])/(line_to[0] - line_from[0])
except ZeroDivisionError:
slope = "未定義"
return slope
"""
def is_parallel(l_from1, l_to1, l_from2, l_to2):
slope1 = line_slope(l_from1, l_to1)
slope2 = line_slope(l_from2, l_to2)
if slope1 == slope2:
return 1
return 0
"""
def is_parallel(l_from1, l_to1, l_from2, l_to2):
line1 = vector_minus(l_to1, l_from1)
line2 = vector_minus(l_to2, l_from2)
if cross_product(line1, line2) == 0:
return 1
return 0
def is_orthogonal(l_from1, l_to1, l_from2, l_to2):
line1 = vector_minus(l_to1, l_from1)
line2 = vector_minus(l_to2, l_from2)
if inner_product(line1, line2) == 0:
return 1
return 0
if __name__ == '__main__':
Q = int(input())
for i in range(Q):
all_list = list(map(int, input().split()))
p0_list = all_list[:2]
p1_list = all_list[2:4]
p2_list = all_list[4:6]
p3_list = all_list[6:]
if is_parallel(p0_list, p1_list, p2_list, p3_list):
print("2")
elif is_orthogonal(p0_list, p1_list, p2_list, p3_list):
print("1")
else:
print("0")
``` | instruction | 0 | 106,095 | 23 | 212,190 |
Yes | output | 1 | 106,095 | 23 | 212,191 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0
Submitted Solution:
```
from math import sqrt
class Vector:
def __init__(self, ls):
"""ls = list"""
self.vec = ls
def __len__(self):
return len(self.vec)
def __getitem__(self, idx):
return self.vec[idx]
def __repr__(self):
return f'Vector({self.vec})'
def add(self, vec):
"""vec: Vector class"""
assert len(self) == len(vec)
ret = [a + b for a, b in zip(self.vec, vec.vec)]
return Vector(ret)
def sub(self, vec):
"""vec: Vector class"""
assert len(self) == len(vec)
ret = [a - b for a, b in zip(self.vec, vec.vec)]
return Vector(ret)
def mul(self, vec):
"""vec: Vector class"""
assert len(self) == len(vec)
ret = [a * b for a, b in zip(self.vec, vec.vec)]
return Vector(ret)
def norm(self):
tmp = sum([x * x for x in self.vec])
return sqrt(tmp)
def norm(vec):
"""
vec ... Vector class
"""
return vec.norm()
def cross(a, b):
"""
Outer product for 2d
a,b ... Vector class
"""
assert len(a) == 2 and len(b) == 2
first = a[0] * b[1]
second = a[1] * b[0]
return first - second
def dot(a, b):
return sum(a.mul(b))
def resolve():
Q = int(input())
for i in range(Q):
s, t, a, b, x, y, c, d = map(int, input().split())
P0 = Vector([s, t])
P1 = Vector([a, b])
P2 = Vector([x, y])
P3 = Vector([c, d])
line_a = P1.sub(P0)
line_b = P3.sub(P2)
if cross(line_a, line_b) == 0:
print(2)
elif dot(line_a, line_b) == 0:
print(1)
else:
print(0)
if __name__ == '__main__':
resolve()
``` | instruction | 0 | 106,096 | 23 | 212,192 |
Yes | output | 1 | 106,096 | 23 | 212,193 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0
Submitted Solution:
```
n = int(input())
for i in range(n):
x0,y0,x1,y1,x2,y2,x3,y3 = map(float,input().split())
if x1 - x0 == 0:
if x3 -x2 == 0:
print('2')
elif y3 - y2 == 0:
print('1')
else:
print('0')
elif x3 - x2 == 0:
if y1 - y0 == 0:
print('1')
else:
print('0')
elif y1 - y0 == 0:
if y3 - y2 == 0:
print('2')
elif x3 - x2 == 0:
print('1')
else:
print('0')
elif y3 - y2 == 0:
if x1 - x0 == 0:
print('1')
else:
print('0')
else:
a1 = (y1-y0)/(x1-x0)
a2 = (y3-y2)/(x3-x2)
if a1 * a2 == -1:
print('1')
elif a1 == a2 or a1 == -a2:
print('2')
else:
print('0')
``` | instruction | 0 | 106,097 | 23 | 212,194 |
No | output | 1 | 106,097 | 23 | 212,195 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0
Submitted Solution:
```
n = int(input())
def judge():
x0,y0,x1,y1,x2,y2,x3,y3 = map(float,input().split())
if x1 - x0 == 0:
if x3 -x2 == 0:
print('2')
elif y3 - y2 == 0:
print('1')
else:
print('0')
elif x3 - x2 == 0:
if y1 - y0 == 0:
print('1')
else:
print('0')
elif y1 - y0 == 0:
if y3 - y2 == 0:
print('2')
elif x3 - x2 == 0:
print('1')
else:
print('0')
elif y3 - y2 == 0:
if x1 - x0 == 0:
print('1')
else:
print('0')
else:
a1 = (y1-y0)/(x1-x0)
a2 = (y3-y2)/(x3-x2)
if a1 * a2 == -1:
print('1')
elif a1 == a2 or a1 == -a2:
print('2')
else:
print('0')
for i in range(n):
judge()
``` | instruction | 0 | 106,098 | 23 | 212,196 |
No | output | 1 | 106,098 | 23 | 212,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0
Submitted Solution:
```
# coding=utf-8
def line_slope(line_from, line_to):
try:
slope = (line_to[1] - line_from[1])/(line_to[0] - line_from[1])
except ZeroDivisionError:
slope = "未定義"
return slope
def is_parallel(l_from1, l_to1, l_from2, l_to2):
slope1 = line_slope(l_from1, l_to1)
slope2 = line_slope(l_from2, l_to2)
if slope1 == slope2:
return 1
return 0
def is_orthogonal(l_from1, l_to1, l_from2, l_to2):
slope1 = line_slope(l_from1, l_to1)
slope2 = line_slope(l_from2, l_to2)
if slope1 == "未定義":
if slope2 == 0:
return 1
return 0
if slope2 == "未定義":
if slope1 == 0:
return 1
return 0
if slope1 * slope2 == -1:
return 1
return 0
if __name__ == '__main__':
Q = int(input())
for i in range(Q):
all_list = list(map(int, input().split()))
p0_list = all_list[:2]
p1_list = all_list[2:4]
p2_list = all_list[4:6]
p3_list = all_list[6:]
if is_parallel(p0_list, p1_list, p2_list, p3_list):
print("2")
elif is_orthogonal(p0_list, p1_list, p2_list, p3_list):
print("1")
else:
print("0")
``` | instruction | 0 | 106,099 | 23 | 212,198 |
No | output | 1 | 106,099 | 23 | 212,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.
s1 crosses points p0 and p1, and s2 crosses points p2 and p3.
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
Input
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
Output
For each query, print "2", "1" or "0".
Example
Input
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2
Output
2
1
0
Submitted Solution:
```
n = int(input())
for i in range(n):
x0,y0,x1,y1,x2,y2,x3,y3 = map(float,input().split())
if x1 - x0 == 0:
if x3 -x2 == 0:
print('2')
elif y3 - y2 == 0:
print('1')
else:
print('0')
elif x3 - x2 == 0:
if y1 - y0 == 0:
print('1')
else:
print('0')
elif y1 - y0 == 0:
if y3 - y2 == 0:
print('2')
elif x3 - x2 == 0:
print('1')
else:
print('0')
else:
a1 = (y1-y0)/(x1-x0)
a2 = (y3-y2)/(x3-x2)
if a1 * a2 == -1:
print('1')
elif a1 == a2 or a1 == -a2:
print('2')
else:
print('0')
``` | instruction | 0 | 106,100 | 23 | 212,200 |
No | output | 1 | 106,100 | 23 | 212,201 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4 | instruction | 0 | 106,152 | 23 | 212,304 |
Tags: binary search, constructive algorithms, math
Correct Solution:
```
ans=10**9
n=int(input())
i=1
while i*i<=n:
ans=min(ans, i+(n-1)//i+1)
i+=1
print(ans)
``` | output | 1 | 106,152 | 23 | 212,305 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4 | instruction | 0 | 106,153 | 23 | 212,306 |
Tags: binary search, constructive algorithms, math
Correct Solution:
```
from math import sqrt
n = int(input())
l = 1
r = 1
while (l+r)/2 < sqrt(n) :
if (l+r) % 2 == 0:
r+=1
else:
l+=1
print(r+l)
``` | output | 1 | 106,153 | 23 | 212,307 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4 | instruction | 0 | 106,154 | 23 | 212,308 |
Tags: binary search, constructive algorithms, math
Correct Solution:
```
import math
a = int(input())
lb = int(math.sqrt(a))
if lb == math.sqrt(a):
print(lb * 2)
else:
if lb + (lb*lb) >= a:
print((lb * 2) + 1 )
else:
print((lb * 2) + 2 )
``` | output | 1 | 106,154 | 23 | 212,309 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4 | instruction | 0 | 106,155 | 23 | 212,310 |
Tags: binary search, constructive algorithms, math
Correct Solution:
```
import math
n=int(input())
val=int(math.sqrt(n))
if val*val==n:
print(2*val)
elif n-(val*val)<=val:
print(1+(2*val))
else:
print(2+(2*val))
``` | output | 1 | 106,155 | 23 | 212,311 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends (x, y) and (x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x', y) and (x', y+1) for some x'. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates x, x+1 and the differing coordinate y.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:
<image>
After that, she can draw the remaining two segments, using the first two as a guide:
<image>
If Sofia needs to draw two squares, she will have to draw three segments using a ruler:
<image>
After that, she can draw the remaining four segments, using the first three as a guide:
<image>
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
Input
The only line of input contains a single integer n (1 ≤ n ≤ 10^{9}), the number of squares that Sofia wants to draw.
Output
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw n squares in the manner described above.
Examples
Input
1
Output
2
Input
2
Output
3
Input
4
Output
4 | instruction | 0 | 106,156 | 23 | 212,312 |
Tags: binary search, constructive algorithms, math
Correct Solution:
```
import math
def main():
n = int(input())
print(int(math.ceil(math.sqrt(n) * 2)))
if __name__ == "__main__":
main()
``` | output | 1 | 106,156 | 23 | 212,313 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.