message stringlengths 2 48.6k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 318 108k | cluster float64 8 8 | __index_level_0__ int64 636 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then the descriptions of t test cases follow.
The first line of a test case contains three integers n, s and k (2 ≤ n ≤ 10^9, 1 ≤ s ≤ n, 1 ≤ k ≤ min(n-1, 1000)) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains k distinct integers a_1, a_2, …, a_k (1 ≤ a_i ≤ n) — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of k over all test cases does not exceed 1000.
Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.
Example
Input
5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
Output
2
0
4
0
2
Note
In the first example test case, the nearest floor with an open restaurant would be the floor 4.
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the 6-th floor. | instruction | 0 | 41,370 | 8 | 82,740 |
Tags: binary search, brute force, implementation
Correct Solution:
```
n = int(input())
for i in range(n):
ans = 0
a, r, c = list(map(int, input().strip().split()))
renewing = set(list(map(int, input().strip().split())))
down = up = r
if r not in renewing:
print(ans)
else:
while True:
ans += 1
if down > 1:
down -= 1
if up < a:
up += 1
if down not in renewing or up not in renewing:
print(ans)
break
``` | output | 1 | 41,370 | 8 | 82,741 |
Provide tags and a correct Python 3 solution for this coding contest problem.
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then the descriptions of t test cases follow.
The first line of a test case contains three integers n, s and k (2 ≤ n ≤ 10^9, 1 ≤ s ≤ n, 1 ≤ k ≤ min(n-1, 1000)) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains k distinct integers a_1, a_2, …, a_k (1 ≤ a_i ≤ n) — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of k over all test cases does not exceed 1000.
Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.
Example
Input
5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
Output
2
0
4
0
2
Note
In the first example test case, the nearest floor with an open restaurant would be the floor 4.
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the 6-th floor. | instruction | 0 | 41,371 | 8 | 82,742 |
Tags: binary search, brute force, implementation
Correct Solution:
```
def solve(f, n, s, k):
for i in range(n):
if s - i >= 0 and s - i + 1 not in f:
return i
if s + i < n and s + i + 1 not in f:
return i
for _ in range(int(input())):
n, s, k = map(int, input().split())
a = list(map(int, input().split()))
print(' ', solve(set(a), n, s - 1, k))
``` | output | 1 | 41,371 | 8 | 82,743 |
Provide tags and a correct Python 3 solution for this coding contest problem.
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then the descriptions of t test cases follow.
The first line of a test case contains three integers n, s and k (2 ≤ n ≤ 10^9, 1 ≤ s ≤ n, 1 ≤ k ≤ min(n-1, 1000)) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains k distinct integers a_1, a_2, …, a_k (1 ≤ a_i ≤ n) — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of k over all test cases does not exceed 1000.
Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.
Example
Input
5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
Output
2
0
4
0
2
Note
In the first example test case, the nearest floor with an open restaurant would be the floor 4.
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the 6-th floor. | instruction | 0 | 41,372 | 8 | 82,744 |
Tags: binary search, brute force, implementation
Correct Solution:
```
# cook your dish here
for _ in range(int(input())):
n, s, k = map(int, input().split())
rs = list(map(int, input().split()))
d = {}
for i in range(k):
d[rs[i]] = 1
i = 0
while 1:
if ((s+i <= n and s+i not in d) or (s-i >= 1 and s-i not in d)):
print(i)
break
i += 1
``` | output | 1 | 41,372 | 8 | 82,745 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then the descriptions of t test cases follow.
The first line of a test case contains three integers n, s and k (2 ≤ n ≤ 10^9, 1 ≤ s ≤ n, 1 ≤ k ≤ min(n-1, 1000)) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains k distinct integers a_1, a_2, …, a_k (1 ≤ a_i ≤ n) — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of k over all test cases does not exceed 1000.
Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.
Example
Input
5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
Output
2
0
4
0
2
Note
In the first example test case, the nearest floor with an open restaurant would be the floor 4.
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the 6-th floor.
Submitted Solution:
```
def solve(n,s,closed):
min_moves = float('inf')
floor = s
time = 0
while floor > 0:
if floor not in closed:
min_moves = min(min_moves,time)
break
floor -= 1
time += 1
floor = s
time = 0
while floor <= n:
if floor not in closed:
min_moves = min(min_moves,time)
break
floor += 1
time += 1
print(min_moves)
def main():
t = int(input())
for i in range(t):
n,s,k = map(int,input().split())
closed = set(map(int,input().split()))
solve(n,s,closed)
main()
``` | instruction | 0 | 41,373 | 8 | 82,746 |
Yes | output | 1 | 41,373 | 8 | 82,747 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then the descriptions of t test cases follow.
The first line of a test case contains three integers n, s and k (2 ≤ n ≤ 10^9, 1 ≤ s ≤ n, 1 ≤ k ≤ min(n-1, 1000)) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains k distinct integers a_1, a_2, …, a_k (1 ≤ a_i ≤ n) — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of k over all test cases does not exceed 1000.
Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.
Example
Input
5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
Output
2
0
4
0
2
Note
In the first example test case, the nearest floor with an open restaurant would be the floor 4.
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the 6-th floor.
Submitted Solution:
```
def solve_case():
global N, S, K
N, S, K = map(int, input().split())
A = set(map(int, input().split()))
best = N
low = max(S - K, 1)
high = min(S + K, N)
for floor in range(low, high + 1):
if floor not in A:
best = min(best, abs(S - floor))
print(best)
tests = int(input())
for test in range(tests):
solve_case()
``` | instruction | 0 | 41,374 | 8 | 82,748 |
Yes | output | 1 | 41,374 | 8 | 82,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then the descriptions of t test cases follow.
The first line of a test case contains three integers n, s and k (2 ≤ n ≤ 10^9, 1 ≤ s ≤ n, 1 ≤ k ≤ min(n-1, 1000)) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains k distinct integers a_1, a_2, …, a_k (1 ≤ a_i ≤ n) — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of k over all test cases does not exceed 1000.
Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.
Example
Input
5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
Output
2
0
4
0
2
Note
In the first example test case, the nearest floor with an open restaurant would be the floor 4.
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the 6-th floor.
Submitted Solution:
```
import sys
input = lambda: sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
n, s, k = map(int, input().split())
a = set(map(int, input().split()))
for i in range(1010):
if (s+i<=n and s+i not in a) or (s-i>0 and s-i not in a):
print(i)
break
``` | instruction | 0 | 41,375 | 8 | 82,750 |
Yes | output | 1 | 41,375 | 8 | 82,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then the descriptions of t test cases follow.
The first line of a test case contains three integers n, s and k (2 ≤ n ≤ 10^9, 1 ≤ s ≤ n, 1 ≤ k ≤ min(n-1, 1000)) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains k distinct integers a_1, a_2, …, a_k (1 ≤ a_i ≤ n) — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of k over all test cases does not exceed 1000.
Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.
Example
Input
5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
Output
2
0
4
0
2
Note
In the first example test case, the nearest floor with an open restaurant would be the floor 4.
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the 6-th floor.
Submitted Solution:
```
''' Hey stalker :) '''
INF = 10**10
def main():
#print = out.append
''' Cook your dish here! '''
n, s, k = get_list()
li = set(get_list())
i = 0
while i<n:
if s+i<=n and s+i not in li:
print(i)
break
elif s-i>0 and s-i not in li:
print(i)
break
i += 1
''' Pythonista fLite 1.1 '''
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
#from functools import reduce
import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
#main()
[main() for _ in range(int(input()))]
print(*out, sep='\n')
``` | instruction | 0 | 41,376 | 8 | 82,752 |
Yes | output | 1 | 41,376 | 8 | 82,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then the descriptions of t test cases follow.
The first line of a test case contains three integers n, s and k (2 ≤ n ≤ 10^9, 1 ≤ s ≤ n, 1 ≤ k ≤ min(n-1, 1000)) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains k distinct integers a_1, a_2, …, a_k (1 ≤ a_i ≤ n) — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of k over all test cases does not exceed 1000.
Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.
Example
Input
5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
Output
2
0
4
0
2
Note
In the first example test case, the nearest floor with an open restaurant would be the floor 4.
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the 6-th floor.
Submitted Solution:
```
t = int(input())
for _ in range(t):
n, s, k = map(int, input().split())
closed = [int(c) for c in input().split()]
closed.sort()
if s not in closed:
print(0)
else:
i = s + 1
j = s - 1
if s < n:
while(i <= n and i in closed):
i += 1
if i == n and i in closed:
i = j
else:
i = j
if s > 1:
while(j >= 1 and j in closed):
j -= 1
if j == 0 and 1 in closed:
j = i
else:
j = i
print(min(abs(i - s), abs(s - j)))
``` | instruction | 0 | 41,377 | 8 | 82,754 |
No | output | 1 | 41,377 | 8 | 82,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then the descriptions of t test cases follow.
The first line of a test case contains three integers n, s and k (2 ≤ n ≤ 10^9, 1 ≤ s ≤ n, 1 ≤ k ≤ min(n-1, 1000)) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains k distinct integers a_1, a_2, …, a_k (1 ≤ a_i ≤ n) — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of k over all test cases does not exceed 1000.
Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.
Example
Input
5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
Output
2
0
4
0
2
Note
In the first example test case, the nearest floor with an open restaurant would be the floor 4.
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the 6-th floor.
Submitted Solution:
```
t = int(input())
for i in range(t):
n, s, k = map(int, input().split())
a = list(map(int, input().split()))
if s not in a:
print(0)
else:
a.sort()
m = a.index(s)
d = 1
mx = 10 ** 9
for r in range(m + 1, len(a)):
if s + d != a[r]:
mx = d
break
else:
d += 1
if mx == 10 ** 9 and a[-1] < n:
mx = d
else:
mx = 10 ** 9
for r in range(m - 1, -1, -1):
if s - d != a[r]:
mx = min(mx, d)
f = 0
break
else:
d -= 1
print(mx)
``` | instruction | 0 | 41,378 | 8 | 82,756 |
No | output | 1 | 41,378 | 8 | 82,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then the descriptions of t test cases follow.
The first line of a test case contains three integers n, s and k (2 ≤ n ≤ 10^9, 1 ≤ s ≤ n, 1 ≤ k ≤ min(n-1, 1000)) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains k distinct integers a_1, a_2, …, a_k (1 ≤ a_i ≤ n) — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of k over all test cases does not exceed 1000.
Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.
Example
Input
5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
Output
2
0
4
0
2
Note
In the first example test case, the nearest floor with an open restaurant would be the floor 4.
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the 6-th floor.
Submitted Solution:
```
t = int(input())
for _ in range(t):
n,s,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
m = 0
M = 0
if(s not in a):
print(0)
else:
for i in range(1,s):
if(i not in a):
m = min(m,abs(s-i)) if m !=0 else abs(s-i)
for i in range(s+1,max(a)+2):
if(i not in a):
M = min(M,abs(s-i)) if M !=0 else abs(s-i)
if m == 0:
print(M)
elif M == 0:
print(m)
else:
print(min(m,M))
``` | instruction | 0 | 41,379 | 8 | 82,758 |
No | output | 1 | 41,379 | 8 | 82,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
[Sakuzyo - Imprinting](https://www.youtube.com/watch?v=55Ca6av1kAY)
A.R.C. Markland-N is a tall building with n floors numbered from 1 to n. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he's planning for a location to enjoy his meal.
ConneR's office is at floor s of the building. On each floor (including floor s, of course), there is a restaurant offering meals. However, due to renovations being in progress, k of the restaurants are currently closed, and as a result, ConneR can't enjoy his lunch there.
CooneR wants to reach a restaurant as quickly as possible to save time. What is the minimum number of staircases he needs to walk to reach a closest currently open restaurant.
Please answer him quickly, and you might earn his praise and even enjoy the lunch with him in the elegant Neumanns' way!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then the descriptions of t test cases follow.
The first line of a test case contains three integers n, s and k (2 ≤ n ≤ 10^9, 1 ≤ s ≤ n, 1 ≤ k ≤ min(n-1, 1000)) — respectively the number of floors of A.R.C. Markland-N, the floor where ConneR is in, and the number of closed restaurants.
The second line of a test case contains k distinct integers a_1, a_2, …, a_k (1 ≤ a_i ≤ n) — the floor numbers of the currently closed restaurants.
It is guaranteed that the sum of k over all test cases does not exceed 1000.
Output
For each test case print a single integer — the minimum number of staircases required for ConneR to walk from the floor s to a floor with an open restaurant.
Example
Input
5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
Output
2
0
4
0
2
Note
In the first example test case, the nearest floor with an open restaurant would be the floor 4.
In the second example test case, the floor with ConneR's office still has an open restaurant, so Sensei won't have to go anywhere.
In the third example test case, the closest open restaurant is on the 6-th floor.
Submitted Solution:
```
import math
def main():
n,s,k = map(int, input().split())
lst = list(map(int, input().split()))
dif = 0
max_dif = []
for i in range(0, 502):
if not (s+i) in lst and (s + i) <= n:
print(i)
return 0
if not (s - i) in lst and (s - i) > 0:
print(i)
return 0
if __name__ == "__main__":
t = int(input())
for i in range(t):
main()
``` | instruction | 0 | 41,380 | 8 | 82,760 |
No | output | 1 | 41,380 | 8 | 82,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
Baby Ehab loves crawling around his apartment. It has n rooms numbered from 0 to n-1. For every pair of rooms, a and b, there's either a direct passage from room a to room b, or from room b to room a, but never both.
Baby Ehab wants to go play with Baby Badawy. He wants to know if he could get to him. However, he doesn't know anything about his apartment except the number of rooms. He can ask the baby sitter two types of questions:
* is the passage between room a and room b directed from a to b or the other way around?
* does room x have a passage towards any of the rooms s_1, s_2, ..., s_k?
He can ask at most 9n queries of the first type and at most 2n queries of the second type.
After asking some questions, he wants to know for every pair of rooms a and b whether there's a path from a to b or not. A path from a to b is a sequence of passages that starts from room a and ends at room b.
Input
The first line contains an integer t (1 ≤ t ≤ 30) — the number of test cases you need to solve.
Then each test case starts with an integer n (4 ≤ n ≤ 100) — the number of rooms.
The sum of n across the test cases doesn't exceed 500.
Output
To print the answer for a test case, print a line containing "3", followed by n lines, each containing a binary string of length n. The j-th character of the i-th string should be 1 if there's a path from room i to room j, and 0 if there isn't. The i-th character of the i-th string should be 1 for each valid i.
After printing the answer, we will respond with a single integer. If it's 1, you printed a correct answer and should keep solving the test cases (or exit if it is the last one). If it's -1, you printed a wrong answer and should terminate to get Wrong answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
Interaction
To ask a question of the first type, use the format:
* 1 a b (0 ≤ a,b ≤ n-1, a ≠b).
* we will answer with 1 if the passage is from a to b, and 0 if it is from b to a.
* you can ask at most 9n questions of this type in each test case.
To ask a question of the second type, use the format:
* 2 x k s_1 s_2 ... s_k (0 ≤ x,s_i ≤ n-1, 0 ≤ k < n, x ≠s_i, elements of s are pairwise distinct).
* we will answer with 1 if there's a passage from x to any of the rooms in s, and 0 otherwise.
* you can ask at most 2n questions of this type in each test case.
If we answer with -1 instead of a valid answer, that means you exceeded the number of queries or made an invalid query. Exit immediately after receiving -1 and you will see Wrong answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query, do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see the documentation for other languages.
Hacks:
The first line should contain an integer t — the number of test cases.
The first line of each test case should contain an integer n (4 ≤ n ≤ 100) — the number of rooms.
Each of the next n lines should contain a binary string of length n. The j-th character of the i-th string should be 1 if there's a passage from room i to room j, 0 otherwise. The i-th character of the i-th string should be 0.
Example
Input
1
4
0
0
1
1
1
Output
2 3 3 0 1 2
1 0 1
1 0 2
2 2 1 1
3
1111
1111
1111
0001
Note
In the given example:
<image>
The first query asks whether there's a passage from room 3 to any of the other rooms.
The second query asks about the direction of the passage between rooms 0 and 1.
After a couple other queries, we concluded that you can go from any room to any other room except if you start at room 3, and you can't get out of this room, so we printed the matrix:
1111
1111
1111
0001
The interactor answered with 1, telling us the answer is correct.
Submitted Solution:
```
import sys
def query_1(a, b):
print(f'1 {a} {b}')
sys.stdout.flush()
return int(input())
def query_2(a, *b):
print(f'2 {a} {len(b)}', ' '.join(map(str, b)))
sys.stdout.flush()
return int(input())
def solve(g):
print('3')
for row in g:
print(''.join(map(str, row)))
sys.stdout.flush()
return int(input())
T = int(input())
for _ in range(T):
N = int(input())
path = [0]
while len(path) < N:
node = len(path)
for i in range(len(path)):
r = query_1(node, path[i])
if r == 1:
path.insert(i, node)
break
else:
path.append(node)
graph = [[1 for _ in range(N)] for _ in range(N)]
p = N - 2
for n in range(N - 1, -1, -1):
if p == n:
for j in range(0, n + 1):
for k in range(n + 1, N):
graph[path[k]][path[j]] = 0
p -= 1
while query_2(path[n], *path[:p + 1]):
p -= 1
if solve(graph) < 0:
break
``` | instruction | 0 | 41,492 | 8 | 82,984 |
No | output | 1 | 41,492 | 8 | 82,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
Baby Ehab loves crawling around his apartment. It has n rooms numbered from 0 to n-1. For every pair of rooms, a and b, there's either a direct passage from room a to room b, or from room b to room a, but never both.
Baby Ehab wants to go play with Baby Badawy. He wants to know if he could get to him. However, he doesn't know anything about his apartment except the number of rooms. He can ask the baby sitter two types of questions:
* is the passage between room a and room b directed from a to b or the other way around?
* does room x have a passage towards any of the rooms s_1, s_2, ..., s_k?
He can ask at most 9n queries of the first type and at most 2n queries of the second type.
After asking some questions, he wants to know for every pair of rooms a and b whether there's a path from a to b or not. A path from a to b is a sequence of passages that starts from room a and ends at room b.
Input
The first line contains an integer t (1 ≤ t ≤ 30) — the number of test cases you need to solve.
Then each test case starts with an integer n (4 ≤ n ≤ 100) — the number of rooms.
The sum of n across the test cases doesn't exceed 500.
Output
To print the answer for a test case, print a line containing "3", followed by n lines, each containing a binary string of length n. The j-th character of the i-th string should be 1 if there's a path from room i to room j, and 0 if there isn't. The i-th character of the i-th string should be 1 for each valid i.
After printing the answer, we will respond with a single integer. If it's 1, you printed a correct answer and should keep solving the test cases (or exit if it is the last one). If it's -1, you printed a wrong answer and should terminate to get Wrong answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
Interaction
To ask a question of the first type, use the format:
* 1 a b (0 ≤ a,b ≤ n-1, a ≠b).
* we will answer with 1 if the passage is from a to b, and 0 if it is from b to a.
* you can ask at most 9n questions of this type in each test case.
To ask a question of the second type, use the format:
* 2 x k s_1 s_2 ... s_k (0 ≤ x,s_i ≤ n-1, 0 ≤ k < n, x ≠s_i, elements of s are pairwise distinct).
* we will answer with 1 if there's a passage from x to any of the rooms in s, and 0 otherwise.
* you can ask at most 2n questions of this type in each test case.
If we answer with -1 instead of a valid answer, that means you exceeded the number of queries or made an invalid query. Exit immediately after receiving -1 and you will see Wrong answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query, do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see the documentation for other languages.
Hacks:
The first line should contain an integer t — the number of test cases.
The first line of each test case should contain an integer n (4 ≤ n ≤ 100) — the number of rooms.
Each of the next n lines should contain a binary string of length n. The j-th character of the i-th string should be 1 if there's a passage from room i to room j, 0 otherwise. The i-th character of the i-th string should be 0.
Example
Input
1
4
0
0
1
1
1
Output
2 3 3 0 1 2
1 0 1
1 0 2
2 2 1 1
3
1111
1111
1111
0001
Note
In the given example:
<image>
The first query asks whether there's a passage from room 3 to any of the other rooms.
The second query asks about the direction of the passage between rooms 0 and 1.
After a couple other queries, we concluded that you can go from any room to any other room except if you start at room 3, and you can't get out of this room, so we printed the matrix:
1111
1111
1111
0001
The interactor answered with 1, telling us the answer is correct.
Submitted Solution:
```
def ask1(i, j):
print('1', i, j)
x = int(input())
return x != 0
def ask2(i, a):
print('2', i, len(a), *a)
x = int(input())
return x != 0
def answer(a):
print('3')
for x in a:
print(*x, sep = '')
x = int(input())
assert(x != -1)
def solve_case():
n = int(input())
ans = [[0] * n for i in range(n)]
path = []
for i in range(n):
l, r = -1, i
while r - l > 1:
m = (l + r) >> 1
if ask1(path[m], i):
l = m
else:
r = m
path = path[:r] + [i] + path[r:]
for i in range(n):
for j in range(i, n):
ans[path[i]][path[j]] = 1
l, r = n - 1, n - 1
for i in range(n - 1, -1, -1):
while l > 0 and ask2(path[i], path[:l]):
l -= 1
if i == l:
for x in range(l, r + 1):
for y in range(x, r + 1):
ans[path[x]][path[y]] = 1
l, r = i - 1, i - 1
answer(ans)
def main():
for _ in range(int(input())):
solve_case()
main()
``` | instruction | 0 | 41,493 | 8 | 82,986 |
No | output | 1 | 41,493 | 8 | 82,987 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
Baby Ehab loves crawling around his apartment. It has n rooms numbered from 0 to n-1. For every pair of rooms, a and b, there's either a direct passage from room a to room b, or from room b to room a, but never both.
Baby Ehab wants to go play with Baby Badawy. He wants to know if he could get to him. However, he doesn't know anything about his apartment except the number of rooms. He can ask the baby sitter two types of questions:
* is the passage between room a and room b directed from a to b or the other way around?
* does room x have a passage towards any of the rooms s_1, s_2, ..., s_k?
He can ask at most 9n queries of the first type and at most 2n queries of the second type.
After asking some questions, he wants to know for every pair of rooms a and b whether there's a path from a to b or not. A path from a to b is a sequence of passages that starts from room a and ends at room b.
Input
The first line contains an integer t (1 ≤ t ≤ 30) — the number of test cases you need to solve.
Then each test case starts with an integer n (4 ≤ n ≤ 100) — the number of rooms.
The sum of n across the test cases doesn't exceed 500.
Output
To print the answer for a test case, print a line containing "3", followed by n lines, each containing a binary string of length n. The j-th character of the i-th string should be 1 if there's a path from room i to room j, and 0 if there isn't. The i-th character of the i-th string should be 1 for each valid i.
After printing the answer, we will respond with a single integer. If it's 1, you printed a correct answer and should keep solving the test cases (or exit if it is the last one). If it's -1, you printed a wrong answer and should terminate to get Wrong answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
Interaction
To ask a question of the first type, use the format:
* 1 a b (0 ≤ a,b ≤ n-1, a ≠b).
* we will answer with 1 if the passage is from a to b, and 0 if it is from b to a.
* you can ask at most 9n questions of this type in each test case.
To ask a question of the second type, use the format:
* 2 x k s_1 s_2 ... s_k (0 ≤ x,s_i ≤ n-1, 0 ≤ k < n, x ≠s_i, elements of s are pairwise distinct).
* we will answer with 1 if there's a passage from x to any of the rooms in s, and 0 otherwise.
* you can ask at most 2n questions of this type in each test case.
If we answer with -1 instead of a valid answer, that means you exceeded the number of queries or made an invalid query. Exit immediately after receiving -1 and you will see Wrong answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query, do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see the documentation for other languages.
Hacks:
The first line should contain an integer t — the number of test cases.
The first line of each test case should contain an integer n (4 ≤ n ≤ 100) — the number of rooms.
Each of the next n lines should contain a binary string of length n. The j-th character of the i-th string should be 1 if there's a passage from room i to room j, 0 otherwise. The i-th character of the i-th string should be 0.
Example
Input
1
4
0
0
1
1
1
Output
2 3 3 0 1 2
1 0 1
1 0 2
2 2 1 1
3
1111
1111
1111
0001
Note
In the given example:
<image>
The first query asks whether there's a passage from room 3 to any of the other rooms.
The second query asks about the direction of the passage between rooms 0 and 1.
After a couple other queries, we concluded that you can go from any room to any other room except if you start at room 3, and you can't get out of this room, so we printed the matrix:
1111
1111
1111
0001
The interactor answered with 1, telling us the answer is correct.
Submitted Solution:
```
import sys
input = sys.stdin.readline
import random
def q1(a, b):
print(1,a,b)
sys.stdout.flush()
return int(input())
def order(l):
if l == []:
return l
left = []
right = []
v = l.pop()
for v2 in l:
res = q1(v, v2)
assert res != -1
if res == 0:
left.append(v2)
else:
right.append(v2)
return order(left) + [v] + order(right)
t = int(input())
for _ in range(t):
n = int(input())
p = list(range(n))
random.shuffle(p)
path = order(p)
left = [-1] * n
curr = n
for i in range(n-1, -1, -1):
while curr > 0:
if curr > i:
curr = i
else:
print(2, path[i], curr, *path[:curr])
sys.stdout.flush()
res = int(input())
assert res != -1
if res == 1:
curr -= 1
else:
break
left[i] = curr
tl = []
for i in range(n):
if left[i] == i:
tl.append(i)
else:
tl.append(tl[left[i]])
out = [''] * n
for i in range(n):
curr = ['0']*n
for j in range(tl[i],n):
curr[path[j]] = '1'
out[i] = ''.join(curr)
print(3)
print('\n'.join(out))
sys.stdout.flush()
assert int(input()) == 1
``` | instruction | 0 | 41,494 | 8 | 82,988 |
No | output | 1 | 41,494 | 8 | 82,989 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
Baby Ehab loves crawling around his apartment. It has n rooms numbered from 0 to n-1. For every pair of rooms, a and b, there's either a direct passage from room a to room b, or from room b to room a, but never both.
Baby Ehab wants to go play with Baby Badawy. He wants to know if he could get to him. However, he doesn't know anything about his apartment except the number of rooms. He can ask the baby sitter two types of questions:
* is the passage between room a and room b directed from a to b or the other way around?
* does room x have a passage towards any of the rooms s_1, s_2, ..., s_k?
He can ask at most 9n queries of the first type and at most 2n queries of the second type.
After asking some questions, he wants to know for every pair of rooms a and b whether there's a path from a to b or not. A path from a to b is a sequence of passages that starts from room a and ends at room b.
Input
The first line contains an integer t (1 ≤ t ≤ 30) — the number of test cases you need to solve.
Then each test case starts with an integer n (4 ≤ n ≤ 100) — the number of rooms.
The sum of n across the test cases doesn't exceed 500.
Output
To print the answer for a test case, print a line containing "3", followed by n lines, each containing a binary string of length n. The j-th character of the i-th string should be 1 if there's a path from room i to room j, and 0 if there isn't. The i-th character of the i-th string should be 1 for each valid i.
After printing the answer, we will respond with a single integer. If it's 1, you printed a correct answer and should keep solving the test cases (or exit if it is the last one). If it's -1, you printed a wrong answer and should terminate to get Wrong answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
Interaction
To ask a question of the first type, use the format:
* 1 a b (0 ≤ a,b ≤ n-1, a ≠b).
* we will answer with 1 if the passage is from a to b, and 0 if it is from b to a.
* you can ask at most 9n questions of this type in each test case.
To ask a question of the second type, use the format:
* 2 x k s_1 s_2 ... s_k (0 ≤ x,s_i ≤ n-1, 0 ≤ k < n, x ≠s_i, elements of s are pairwise distinct).
* we will answer with 1 if there's a passage from x to any of the rooms in s, and 0 otherwise.
* you can ask at most 2n questions of this type in each test case.
If we answer with -1 instead of a valid answer, that means you exceeded the number of queries or made an invalid query. Exit immediately after receiving -1 and you will see Wrong answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query, do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see the documentation for other languages.
Hacks:
The first line should contain an integer t — the number of test cases.
The first line of each test case should contain an integer n (4 ≤ n ≤ 100) — the number of rooms.
Each of the next n lines should contain a binary string of length n. The j-th character of the i-th string should be 1 if there's a passage from room i to room j, 0 otherwise. The i-th character of the i-th string should be 0.
Example
Input
1
4
0
0
1
1
1
Output
2 3 3 0 1 2
1 0 1
1 0 2
2 2 1 1
3
1111
1111
1111
0001
Note
In the given example:
<image>
The first query asks whether there's a passage from room 3 to any of the other rooms.
The second query asks about the direction of the passage between rooms 0 and 1.
After a couple other queries, we concluded that you can go from any room to any other room except if you start at room 3, and you can't get out of this room, so we printed the matrix:
1111
1111
1111
0001
The interactor answered with 1, telling us the answer is correct.
Submitted Solution:
```
import sys
input = sys.stdin.readline
for f in range(int(input())):
n=int(input())
order=[0]
for i in range(1,n):
mn=0
mx=len(order)
while mx>mn:
md=(mx+mn)//2
print(1,i,order[md],flush=True)
ans=int(input())
if ans:
mn=md+1
else:
mx=md
order.insert(mn,i)
cur=[]
ans=[0]*n
for i in range(n):
ans[i]=[0]*n
ans[order[-1]]=[1]*n
for i in range(n-1):
print(2,order[i],1,order[i+1],flush=True)
res=int(input())
if res:
cur+=[order[i]]
else:
cur+=[order[i]]
for x in cur:
for j in range(i+1):
ans[x][order[j]]=1
cur=[]
for x in cur:
for j in range(n):
ans[x][j]=1
for i in range(n):
print(*ans[i])
``` | instruction | 0 | 41,495 | 8 | 82,990 |
No | output | 1 | 41,495 | 8 | 82,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
* The chosen c prisoners has to form a contiguous segment of prisoners.
* Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the c prisoners.
Input
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Output
Print a single integer — the number of ways you can choose the c prisoners.
Examples
Input
4 3 3
2 3 1 1
Output
2
Input
1 1 1
2
Output
0
Input
11 4 2
2 2 0 7 3 2 2 4 9 1 4
Output
6
Submitted Solution:
```
row = input().split()
row2 = input().split()
n = int(row[0])
t = int(row[1])
c = int(row[2])
aux = 0
cn = 0
for i in range(n):
if int(row2[i]) <= t:
cn += 1
else:
if cn >= c:
aux = aux + cn - (c-1)
cn = 0
if cn >= c:
aux = aux + cn - (c-1)
print(aux)
``` | instruction | 0 | 41,586 | 8 | 83,172 |
Yes | output | 1 | 41,586 | 8 | 83,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
* The chosen c prisoners has to form a contiguous segment of prisoners.
* Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the c prisoners.
Input
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Output
Print a single integer — the number of ways you can choose the c prisoners.
Examples
Input
4 3 3
2 3 1 1
Output
2
Input
1 1 1
2
Output
0
Input
11 4 2
2 2 0 7 3 2 2 4 9 1 4
Output
6
Submitted Solution:
```
a=list(map(int,input().split()[1:]))
b=list(map(int,input().split()))
m=0
c=0
for i in b:
if i>a[0]:
if not c<a[1]:
m+=c-a[1]+1
c=0
else:c+=1
print(m+c-a[1]+1 if c>=a[1]else m)
``` | instruction | 0 | 41,587 | 8 | 83,174 |
Yes | output | 1 | 41,587 | 8 | 83,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
* The chosen c prisoners has to form a contiguous segment of prisoners.
* Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the c prisoners.
Input
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Output
Print a single integer — the number of ways you can choose the c prisoners.
Examples
Input
4 3 3
2 3 1 1
Output
2
Input
1 1 1
2
Output
0
Input
11 4 2
2 2 0 7 3 2 2 4 9 1 4
Output
6
Submitted Solution:
```
number, limit, chosen = map(int, input().split())
prisioners = list(map(int, input().split()))
sequences = 0
aux = 0
for p in prisioners:
if p > limit:
aux = 0
else:
aux += 1
if aux >= chosen:
sequences += 1
print(sequences)
``` | instruction | 0 | 41,588 | 8 | 83,176 |
Yes | output | 1 | 41,588 | 8 | 83,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
* The chosen c prisoners has to form a contiguous segment of prisoners.
* Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the c prisoners.
Input
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Output
Print a single integer — the number of ways you can choose the c prisoners.
Examples
Input
4 3 3
2 3 1 1
Output
2
Input
1 1 1
2
Output
0
Input
11 4 2
2 2 0 7 3 2 2 4 9 1 4
Output
6
Submitted Solution:
```
n, t, c = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
res = 0
cnt = 0
for i in h:
if i > t:
cnt = 0
else:
cnt += 1
if cnt >= c:
res += 1
print(res)
``` | instruction | 0 | 41,589 | 8 | 83,178 |
Yes | output | 1 | 41,589 | 8 | 83,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
* The chosen c prisoners has to form a contiguous segment of prisoners.
* Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the c prisoners.
Input
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Output
Print a single integer — the number of ways you can choose the c prisoners.
Examples
Input
4 3 3
2 3 1 1
Output
2
Input
1 1 1
2
Output
0
Input
11 4 2
2 2 0 7 3 2 2 4 9 1 4
Output
6
Submitted Solution:
```
def nchoosek(n, k):
ans = 1
for i in range(n-k + 1, n+1):
ans *= i
for i in range(2, k+1):
ans //= i
return ans
def main():
n, t, c = map(int, input().split())
crime_level = list(map(int, input().split()))
lengths = []
seg_len = 0
for e in crime_level:
if e <= t:
seg_len += 1
else:
if seg_len >= c:
lengths.append(seg_len)
seg_len = 0
if seg_len >= c:
lengths.append(seg_len)
ans = 0
for e in lengths:
ans += nchoosek(e, c)
print(ans)
``` | instruction | 0 | 41,590 | 8 | 83,180 |
No | output | 1 | 41,590 | 8 | 83,181 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
* The chosen c prisoners has to form a contiguous segment of prisoners.
* Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the c prisoners.
Input
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Output
Print a single integer — the number of ways you can choose the c prisoners.
Examples
Input
4 3 3
2 3 1 1
Output
2
Input
1 1 1
2
Output
0
Input
11 4 2
2 2 0 7 3 2 2 4 9 1 4
Output
6
Submitted Solution:
```
n,t,c=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
l=0
a.sort()
for i in range(n-c):
p=[]
h=i
for j in range(c):
p.append(a[h])
h+=1
if p[-1]<t:
l+=1
else:
break
print(l)
``` | instruction | 0 | 41,591 | 8 | 83,182 |
No | output | 1 | 41,591 | 8 | 83,183 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
* The chosen c prisoners has to form a contiguous segment of prisoners.
* Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the c prisoners.
Input
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Output
Print a single integer — the number of ways you can choose the c prisoners.
Examples
Input
4 3 3
2 3 1 1
Output
2
Input
1 1 1
2
Output
0
Input
11 4 2
2 2 0 7 3 2 2 4 9 1 4
Output
6
Submitted Solution:
```
n, t, c = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
res = 0
cnt = 0
for i in h:
if i > t:
cnt = 0
cnt += 1
if cnt >= c:
res += 1
print(res)
``` | instruction | 0 | 41,592 | 8 | 83,184 |
No | output | 1 | 41,592 | 8 | 83,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
* The chosen c prisoners has to form a contiguous segment of prisoners.
* Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the c prisoners.
Input
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Output
Print a single integer — the number of ways you can choose the c prisoners.
Examples
Input
4 3 3
2 3 1 1
Output
2
Input
1 1 1
2
Output
0
Input
11 4 2
2 2 0 7 3 2 2 4 9 1 4
Output
6
Submitted Solution:
```
n, t, c = list(map(int, input().split()))
presos = list(map(int, input().split()))
temp = 0
temp2 = 0
for e in presos:
if e <= t:
temp += 1
else:
temp2 += (temp - c + 1)
temp = 0
else:
temp2 += (temp - c + 1)
print(temp2)
``` | instruction | 0 | 41,593 | 8 | 83,186 |
No | output | 1 | 41,593 | 8 | 83,187 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.
<image>
So, if height of Xaniar is h1 and height of Abol is h2, after one second height of Xaniar will become <image> and height of Abol will become <image> where x1, y1, x2 and y2 are some integer numbers and <image> denotes the remainder of a modulo b.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a1 and height of Abol is a2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
Input
The first line of input contains integer m (2 ≤ m ≤ 106).
The second line of input contains integers h1 and a1 (0 ≤ h1, a1 < m).
The third line of input contains integers x1 and y1 (0 ≤ x1, y1 < m).
The fourth line of input contains integers h2 and a2 (0 ≤ h2, a2 < m).
The fifth line of input contains integers x2 and y2 (0 ≤ x2, y2 < m).
It is guaranteed that h1 ≠a1 and h2 ≠a2.
Output
Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise.
Examples
Input
5
4 2
1 1
0 1
2 3
Output
3
Input
1023
1 2
1 0
1 2
1 1
Output
-1
Note
In the first sample, heights sequences are following:
Xaniar: <image>
Abol: <image> | instruction | 0 | 41,626 | 8 | 83,252 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
mod = int(input())
h1, a1 = map(int, input().split())
x1, y1 = map(int, input().split())
h2, a2 = map(int, input().split())
x2, y2 = map(int, input().split())
q1 = 0
while h1 != a1:
h1 = (h1 * x1 + y1) % mod
q1 += 1
if q1 > 2 * mod:
print(-1)
exit()
q2, t2 = 0, h2
while t2 != a2:
t2 = (t2 * x2 + y2) % mod
q2 += 1
if q2 > 2 * mod:
print(-1)
exit()
if q1 == q2:
print(q1)
exit()
c1, h1 = 1, (a1 * x1 + y1) % mod
while h1 != a1:
h1 = (h1 * x1 + y1) % mod
c1 += 1
if c1 > 2 * mod:
print(-1)
exit()
c2, nx2, ny2 = 0, 1, 0
for i in range(c1):
nx2 = (nx2 * x2) % mod
ny2 = (ny2 * x2 + y2) % mod
for i in range(q1):
h2 = (h2 * x2 + y2) % mod
while h2 != a2:
h2 = (h2 * nx2 + ny2) % mod
c2 += 1
if c2 > 2 * mod:
print(-1)
exit()
print(q1 + c1 * c2)
``` | output | 1 | 41,626 | 8 | 83,253 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.
<image>
So, if height of Xaniar is h1 and height of Abol is h2, after one second height of Xaniar will become <image> and height of Abol will become <image> where x1, y1, x2 and y2 are some integer numbers and <image> denotes the remainder of a modulo b.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a1 and height of Abol is a2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
Input
The first line of input contains integer m (2 ≤ m ≤ 106).
The second line of input contains integers h1 and a1 (0 ≤ h1, a1 < m).
The third line of input contains integers x1 and y1 (0 ≤ x1, y1 < m).
The fourth line of input contains integers h2 and a2 (0 ≤ h2, a2 < m).
The fifth line of input contains integers x2 and y2 (0 ≤ x2, y2 < m).
It is guaranteed that h1 ≠a1 and h2 ≠a2.
Output
Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise.
Examples
Input
5
4 2
1 1
0 1
2 3
Output
3
Input
1023
1 2
1 0
1 2
1 1
Output
-1
Note
In the first sample, heights sequences are following:
Xaniar: <image>
Abol: <image> | instruction | 0 | 41,627 | 8 | 83,254 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
from fractions import *
f = lambda: map(int, input().split())
m = int(input())
def g(u, v):
h, a = u
x, y = v
s = 0
while h != a:
h = (h * x + y) % m
s += 1
if s > m: break
h = (a * x + y) % m
d = 1
while h != a:
h = (h * x + y) % m
d += 1
if d > m: break
return s, d
(u, x), (v, y) = g(f(), f()), g(f(), f())
if u > m or v > m: q = -1
elif u == v: q = u
elif x > m: q = -1 if u < v or (v - u) % y else u
elif y > m: q = -1 if v < u or (v - u) % x else v
elif (v - u) % gcd(x, y): q = -1
else:
while u != v:
if u < v: u += x
else: v += y
q = u
print(q)
``` | output | 1 | 41,627 | 8 | 83,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.
<image>
So, if height of Xaniar is h1 and height of Abol is h2, after one second height of Xaniar will become <image> and height of Abol will become <image> where x1, y1, x2 and y2 are some integer numbers and <image> denotes the remainder of a modulo b.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a1 and height of Abol is a2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
Input
The first line of input contains integer m (2 ≤ m ≤ 106).
The second line of input contains integers h1 and a1 (0 ≤ h1, a1 < m).
The third line of input contains integers x1 and y1 (0 ≤ x1, y1 < m).
The fourth line of input contains integers h2 and a2 (0 ≤ h2, a2 < m).
The fifth line of input contains integers x2 and y2 (0 ≤ x2, y2 < m).
It is guaranteed that h1 ≠a1 and h2 ≠a2.
Output
Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise.
Examples
Input
5
4 2
1 1
0 1
2 3
Output
3
Input
1023
1 2
1 0
1 2
1 1
Output
-1
Note
In the first sample, heights sequences are following:
Xaniar: <image>
Abol: <image> | instruction | 0 | 41,629 | 8 | 83,258 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
__author__ = 'kitkat'
import sys
def GetNext(h, x, y):
global m
return (x * h + y) % m
try:
while True:
m = int(input())
h1, a1 = map(int, input().split(" "))
x1, y1 = map(int, input().split(" "))
h2, a2 = map(int, input().split(" "))
x2, y2 = map(int, input().split(" "))
t1 = []
t2 = []
T = 0
for i in range (2 * m + 1):
if h1 == a1:
t1.append(T)
if h2 == a2:
t2.append(T)
T += 1
h1 = GetNext(h1, x1, y1)
h2 = GetNext(h2, x2, y2)
if len(t1) == 0 or len(t2) == 0:
print("-1")
continue
if t1[0] == t2[0]:
print(t1[0])
continue
elif len(t1) < 2 or len(t2) < 2:
if len(t1) == 1 and len(t2) == 1:
print(t1[0] if t1[0] == t2[0] else "-1")
elif len(t1) == 1:
if t1[0] in t2:
print(t1[0])
else:
print("-1")
elif len(t2) == 1:
if t2[0] in t1:
print(t2[0])
else:
print("-1")
continue
res1 = t1[0]
res2 = t2[0]
flag = False
for i in range (5000000):
if res1 == res2:
flag = True
print(res1)
break
elif res1 <= res2:
res1 += t1[1] - t1[0]
else:
res2 += t2[1] - t2[0]
if not flag:
print("-1")
except EOFError:
pass
``` | output | 1 | 41,629 | 8 | 83,259 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.
<image>
So, if height of Xaniar is h1 and height of Abol is h2, after one second height of Xaniar will become <image> and height of Abol will become <image> where x1, y1, x2 and y2 are some integer numbers and <image> denotes the remainder of a modulo b.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a1 and height of Abol is a2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
Input
The first line of input contains integer m (2 ≤ m ≤ 106).
The second line of input contains integers h1 and a1 (0 ≤ h1, a1 < m).
The third line of input contains integers x1 and y1 (0 ≤ x1, y1 < m).
The fourth line of input contains integers h2 and a2 (0 ≤ h2, a2 < m).
The fifth line of input contains integers x2 and y2 (0 ≤ x2, y2 < m).
It is guaranteed that h1 ≠a1 and h2 ≠a2.
Output
Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise.
Examples
Input
5
4 2
1 1
0 1
2 3
Output
3
Input
1023
1 2
1 0
1 2
1 1
Output
-1
Note
In the first sample, heights sequences are following:
Xaniar: <image>
Abol: <image> | instruction | 0 | 41,630 | 8 | 83,260 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
f = lambda: map(int, input().split())
m = int(input())
def g():
h, a = f()
x, y = f()
t = lambda: (h * x + y) % m
s, d = 0, 1
while h != a:
h = t()
s += 1
if s > m:
print(-1)
exit()
h = t()
while h != a:
h = t()
d += 1
if d > m: return s, 0
return s, d
def h():
u, x = g()
v, y = g()
k = 0
while u != v:
if u < v:
u += x
else:
v += y
k += 1
if k > 2 * m: return -1
return u
print(h())
``` | output | 1 | 41,630 | 8 | 83,261 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.
<image>
So, if height of Xaniar is h1 and height of Abol is h2, after one second height of Xaniar will become <image> and height of Abol will become <image> where x1, y1, x2 and y2 are some integer numbers and <image> denotes the remainder of a modulo b.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a1 and height of Abol is a2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
Input
The first line of input contains integer m (2 ≤ m ≤ 106).
The second line of input contains integers h1 and a1 (0 ≤ h1, a1 < m).
The third line of input contains integers x1 and y1 (0 ≤ x1, y1 < m).
The fourth line of input contains integers h2 and a2 (0 ≤ h2, a2 < m).
The fifth line of input contains integers x2 and y2 (0 ≤ x2, y2 < m).
It is guaranteed that h1 ≠a1 and h2 ≠a2.
Output
Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise.
Examples
Input
5
4 2
1 1
0 1
2 3
Output
3
Input
1023
1 2
1 0
1 2
1 1
Output
-1
Note
In the first sample, heights sequences are following:
Xaniar: <image>
Abol: <image> | instruction | 0 | 41,631 | 8 | 83,262 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
mod = int(input())
h1, a1 = map(int, input().split())
x1, y1 = map(int, input().split())
h2, a2 = map(int, input().split())
x2, y2 = map(int, input().split())
q1 = 0
while h1 != a1:
h1 = (h1 * x1 + y1) % mod
q1 += 1
if q1 > 2 * mod:
print(-1)
exit()
q2 = 0
t2 = h2
while t2 != a2:
t2 = (t2 * x2 + y2) % mod
q2 += 1
if q2 > 2 * mod:
print(-1)
exit()
if q1 == q2:
print(q1)
exit()
c1 = 1
h1 = (a1 * x1 + y1) % mod
while h1 != a1:
h1 = (h1 * x1 + y1) % mod
c1 += 1
if c1 > 2 * mod:
print(-1)
exit()
c2 = 0
nx2 = 1
ny2 = 0
for i in range(c1):
nx2 = (nx2 * x2) % mod
ny2 = (ny2 * x2 + y2) % mod
for i in range(q1):
h2 = (h2 * x2 + y2) % mod
while h2 != a2:
h2 = (h2 * nx2 + ny2) % mod
c2 += 1
if c2 > 2 * mod:
print(-1)
exit()
print(q1 + c1 * c2)
``` | output | 1 | 41,631 | 8 | 83,263 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.
<image>
So, if height of Xaniar is h1 and height of Abol is h2, after one second height of Xaniar will become <image> and height of Abol will become <image> where x1, y1, x2 and y2 are some integer numbers and <image> denotes the remainder of a modulo b.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a1 and height of Abol is a2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
Input
The first line of input contains integer m (2 ≤ m ≤ 106).
The second line of input contains integers h1 and a1 (0 ≤ h1, a1 < m).
The third line of input contains integers x1 and y1 (0 ≤ x1, y1 < m).
The fourth line of input contains integers h2 and a2 (0 ≤ h2, a2 < m).
The fifth line of input contains integers x2 and y2 (0 ≤ x2, y2 < m).
It is guaranteed that h1 ≠a1 and h2 ≠a2.
Output
Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise.
Examples
Input
5
4 2
1 1
0 1
2 3
Output
3
Input
1023
1 2
1 0
1 2
1 1
Output
-1
Note
In the first sample, heights sequences are following:
Xaniar: <image>
Abol: <image> | instruction | 0 | 41,632 | 8 | 83,264 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
import fractions
def read_data():
m = int(input())
h1, a1 = map(int, input().split())
x1, y1 = map(int, input().split())
h2, a2 = map(int, input().split())
x2, y2 = map(int, input().split())
return m, h1, a1, x1, y1, h2, a2, x2, y2
def solve(m, h1, a1, x1, y1, h2, a2, x2, y2):
t = 0
h1s = [-1] * m
h2s = [-1] * m
h1s[h1] = 0
h2s[h2] = 0
t1 = -1
t2 = -1
while h1 != a1 or h2 != a2:
t += 1
h1 = (x1 * h1 + y1) % m
h2 = (x2 * h2 + y2) % m
if h1s[h1] >= 0 and t1 == -1:
t1 = h1s[h1]
s1 = t - t1
if t2 >= 0:
break
else:
h1s[h1] = t
if h2s[h2] >= 0 and t2 == -1:
t2 = h2s[h2]
s2 = t - t2
if t1 >= 0:
break
else:
h2s[h2] = t
if h1 == a1 and h2 == a2:
return t
return retrieve(a1, a2, t1, s1, t2, s2, h1s, h2s)
def retrieve(a1, a2, t1, s1, t2, s2, h1s, h2s):
u1 = h1s[a1]
u2 = h2s[a2]
if u1 == -1 or u2 == -1:
return -1
if u1 < t1:
if guess(h2s, u1, t2, s2, a2):
return u1
else:
return -1
if u2 < t2:
if guess(h1s, u2, t1, s1, a1):
return u2
else:
return -1
return find_time(u1, s1, u2, s2)
def guess(hs, u, t, s, a):
if u <= t:
return hs[a] == u
tt = t + (u - t) % s
return hs[a] == tt
def find_time(u1, s1, u2, s2):
g = fractions.gcd(s1, s2)
if abs(u1 - u2) % g:
return -1
k1, k2 = extended_euclid(s1, s2, u2-u1, g)
b = s2 // g
return (k1 % b) * s1 + u1
def egcd(a, b):
x, lastx = 0, 1
y, lasty = 1, 0
while b:
q = a // b
a, b = b, a % b
x, lastx = lastx - q * x, x
y, lasty = lasty - q * y, y
return lastx, lasty
def extended_euclid(a, b, c, g):
x, y = egcd(a, b)
return (c // g) * x, (x // g) * y
param = read_data()
print(solve(*param))
``` | output | 1 | 41,632 | 8 | 83,265 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | instruction | 0 | 41,641 | 8 | 83,282 |
Tags: constructive algorithms, implementation
Correct Solution:
```
#n = int(input())
n, m = map(int, input().split())
#s = input()
#c = list(map(int, input().split()))
l = 0
for j in range(n):
c = list(map(int, input().split()))
for i in range(0, 2 * m, 2):
if c[i] or c[i + 1]:
l += 1
print(l)
``` | output | 1 | 41,641 | 8 | 83,283 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | instruction | 0 | 41,642 | 8 | 83,284 |
Tags: constructive algorithms, implementation
Correct Solution:
```
r, c = map(int, input().split())
t = 0
for _ in range(r):
l_w = list(map(int, input().split()))
for i in range(len(l_w) // 2):
if l_w[i * 2] == 1 or l_w[i * 2 + 1] == 1:
t += 1
print(t)
``` | output | 1 | 41,642 | 8 | 83,285 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | instruction | 0 | 41,643 | 8 | 83,286 |
Tags: constructive algorithms, implementation
Correct Solution:
```
(n, m) = [int(i) for i in input().strip().split(' ')]
count = 0
for i in range(n):
l = [int(j) for j in input().strip().split(' ')]
for k in range(0, 2*m, 2):
if l[k] == 1 or l[k+1] == 1:
count += 1
print(count)
``` | output | 1 | 41,643 | 8 | 83,287 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | instruction | 0 | 41,644 | 8 | 83,288 |
Tags: constructive algorithms, implementation
Correct Solution:
```
"""
IIIIIIIIII OOOOOOOOOOO IIIIIIIIII
II OO OO II
II OO OO II
II OO OO II
II OO OO II
II OO OO II
II OO OO II
IIIIIIIIII OOOOOOOOOOO IIIIIIIIII
"""
n, m = map(int, input().split())
cnt = 0
for i in range(n):
a = list(map(int ,input().split()))
for j in range(0, 2 * m, 2):
if a[j] == 1 or a[j + 1] == 1:
cnt += 1
print(cnt)
``` | output | 1 | 41,644 | 8 | 83,289 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | instruction | 0 | 41,645 | 8 | 83,290 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n,m = map(int, input().split())
ans=0
for i in range(n):
flat=list(map(int,input().split()))
for j in range(m):
if flat[2*j]+flat[2*j+1]>0:
ans+=1
print(ans)
``` | output | 1 | 41,645 | 8 | 83,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | instruction | 0 | 41,646 | 8 | 83,292 |
Tags: constructive algorithms, implementation
Correct Solution:
```
line1 = (input().split(" "))
floors = int(line1[0])
flats_every_floor = int(line1[1])
all_flats = int(line1[0])*int(line1[1])
awake_flats = 0
counter = 0
for floor in range(floors):
line = (input().split(" "))
for flat in range(flats_every_floor):
if(int(line[flat+counter]) or int(line[flat+counter+1]) == 1):
awake_flats +=1
counter+=1
counter = 0
print(awake_flats)
``` | output | 1 | 41,646 | 8 | 83,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | instruction | 0 | 41,647 | 8 | 83,294 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n, m = map(int, input().split())
m2 = 2*m
count = 0
for i in range(n):
floor = list(map(int, input().split()))
for j in range(0,m2,2):
if floor[j] == 1 or floor[j+1] == 1:
count += 1
print(count)
``` | output | 1 | 41,647 | 8 | 83,295 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | instruction | 0 | 41,648 | 8 | 83,296 |
Tags: constructive algorithms, implementation
Correct Solution:
```
'''
Author: Sofen Hoque Anonta
'''
import re
import sys
import math
import itertools
import collections
def inputArray(TYPE= int):
return [TYPE(x) for x in input().split()]
def solve():
n, m = inputArray()
cc = 0
for x in range(n):
a = inputArray()
i = 0
while i <2*m:
cc+= 1 if a[i]+a[i+1] > 0 else 0
i+= 2
print(cc)
if __name__ == '__main__':
# sys.stdin= open('F:/input.txt')
solve()
``` | output | 1 | 41,648 | 8 | 83,297 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
Submitted Solution:
```
n, m = [int(s) for s in input().split()]
c = 0
for j in range(n):
s = input().split()
for i in range(0, 2*m, 2):
if s[i] == '1' or s[i+1] == '1':
c+=1
print(c)
``` | instruction | 0 | 41,649 | 8 | 83,298 |
Yes | output | 1 | 41,649 | 8 | 83,299 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
Submitted Solution:
```
floors, flats = list(map(int, (input().split())))
cheking_windows = []
for _ in range(floors):
windows = input().replace(' ', '')
while windows:
cheking_windows.append(windows[:2])
windows = windows[2:]
sleeping = cheking_windows.count('00')
print(floors * flats - sleeping)
``` | instruction | 0 | 41,650 | 8 | 83,300 |
Yes | output | 1 | 41,650 | 8 | 83,301 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
Submitted Solution:
```
g = list(map(int, input().split()))
k = 2
result = []
b = 0
l = 0
k = 2
for i in range(g[0]):
h = [int(t) for t in input().split()]
for j in range(g[1]):
for t in range(l, k):
b += h[t]
if b >= 1:
result.append(True)
b = 0
(l, k) = (k, k + 2)
(l, k) = (0, 2)
print(result.count(True))
``` | instruction | 0 | 41,651 | 8 | 83,302 |
Yes | output | 1 | 41,651 | 8 | 83,303 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
Submitted Solution:
```
n, m = (int(x) for x in input().split())
ans = 0
for i in range(n):
a = [int(x) for x in input().split()]
ans += sum([max(a[x], a[x + 1]) for x in range(0, m * 2, 2)])
print(ans)
``` | instruction | 0 | 41,652 | 8 | 83,304 |
Yes | output | 1 | 41,652 | 8 | 83,305 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
Submitted Solution:
```
n=list(map(int,input().split()))
sum=0
for i in range(n[0]):
x=list(map(int,input().split()))
f=0
for i in range(2*n[1]):
if x[i]==1:
f=1
if (i+1)%n[1]==0:
if f==1:
sum+=1
f=0
print(sum)
``` | instruction | 0 | 41,653 | 8 | 83,306 |
No | output | 1 | 41,653 | 8 | 83,307 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
Submitted Solution:
```
n, m = map(int, input().split())
arr = []
tf = m * n
for i in range(n):
arr.append(list(map(int, input().split())))
for i in range(n):
j = 0
while j < m:
if arr[i][j] == arr[i][j + 1] == 0:
tf -= 1
j += 2
print(tf)
``` | instruction | 0 | 41,654 | 8 | 83,308 |
No | output | 1 | 41,654 | 8 | 83,309 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
Submitted Solution:
```
''' Design by Dinh Viet Anh(JOKER)
//_____________________________________$$$$$__
//___________________________________$$$$$$$$$
//___________________________________$$$___$
//___________________________$$$____$$$$
//_________________________$$$$$$$__$$$$$$$$$$$
//_______________________$$$$$$$$$___$$$$$$$$$$$
//_______________________$$$___$______$$$$$$$$$$
//________________$$$$__$$$$_________________$$$
//_____________$__$$$$__$$$$$$$$$$$_____$____$$$
//__________$$$___$$$$___$$$$$$$$$$$__$$$$__$$$$
//_________$$$$___$$$$$___$$$$$$$$$$__$$$$$$$$$
//____$____$$$_____$$$$__________$$$___$$$$$$$
//__$$$$__$$$$_____$$$$_____$____$$$_____$
//__$$$$__$$$_______$$$$__$$$$$$$$$$
//___$$$$$$$$$______$$$$__$$$$$$$$$
//___$$$$$$$$$$_____$$$$___$$$$$$
//___$$$$$$$$$$$_____$$$
//____$$$$$$$$$$$____$$$$
//____$$$$$__$$$$$___$$$
//____$$$$$___$$$$$$
//____$$$$$____$$$
//_____$$$$
//_____$$$$
//_____$$$$
'''
from math import *
from cmath import *
from itertools import *
from decimal import * # su dung voi so thuc
from fractions import * # su dung voi phan so
from sys import *
from types import CodeType, new_class
#from numpy import *
'''getcontext().prec = x # lay x-1 chu so sau giay phay (thuoc decimal)
Decimal('12.3') la 12.3 nhung Decimal(12.3) la 12.30000000012
Fraction(a) # tra ra phan so bang a (Fraction('1.23') la 123/100 Fraction(1.23) la so khac (thuoc Fraction)
a = complex(c, d) a = c + d(i) (c = a.real, d = a.imag)
a.capitalize() bien ki tu dau cua a(string) thanh chu hoa, a.lower() bien a thanh chu thuong, tuong tu voi a.upper()
a.swapcase() doi nguoc hoa thuong, a.title() bien chu hoa sau dau cach, a.replace('a', 'b', slg)
chr(i) ki tu ma i ord(c) ma ki tu c
a.join['a', 'b', 'c'] = 'a'a'b'a'c, a.strip('a') bo dau va cuoi ki tu 'a'(rstrip, lstrip)
a.split('a', slg = -1) cat theo ki tu 'a' slg lan(rsplit(), lsplit()), a.count('aa', dau = 0, cuoi= len(a)) dem slg
a.startswith('a', dau = 0, cuoi = len(a)) co bat dau bang 'a' ko(tuong tu endswith())
a.index("aa") vi tri dau tien xuat hien (rfind())
input = open(".inp", mode='r') a = input.readline()
out = open(".out", mode='w') a.index(val) '''
#inn = open(".inp", "r")
n, m = map(int, input().split())
ans = 0
for x in range(n):
a = input().split()
for y in range(0, m, 2):
if a[y] == '1' or a[y+1] == '1':
ans += 1
print(ans)
``` | instruction | 0 | 41,655 | 8 | 83,310 |
No | output | 1 | 41,655 | 8 | 83,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.
Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.
Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Examples
Input
2 2
0 0 0 1
1 0 1 1
Output
3
Input
1 3
1 1 0 1 0 0
Output
2
Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
Submitted Solution:
```
n,m = map(int, input().split())
f = [list(map(int, input().split())) for _ in range(n)]
c = 0
s = len(f[0])//m
for i in f:
for j in range(s+1):
if sum(i[j*s:(j+1)*s]) >= 1:
c+=1
print(c)
``` | instruction | 0 | 41,656 | 8 | 83,312 |
No | output | 1 | 41,656 | 8 | 83,313 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches <image>.
Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.
In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible.
Input
The only line contains two integers p and y (2 ≤ p ≤ y ≤ 109).
Output
Output the number of the highest suitable branch. If there are none, print -1 instead.
Examples
Input
3 6
Output
5
Input
3 4
Output
-1
Note
In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case. | instruction | 0 | 42,615 | 8 | 85,230 |
Tags: brute force, math, number theory
Correct Solution:
```
def is_prime(n,p):
if n%2==0:
return False
r=int(n**0.5)
f=3
while f<=r and f<=p:
if n%f == 0:
return False
f+=2
return True
p,y=map(int,input().split())
for i in range(y,p,-1):
if is_prime(i,p):
print(i)
break
else:
print(-1)
``` | output | 1 | 42,615 | 8 | 85,231 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches <image>.
Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.
In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible.
Input
The only line contains two integers p and y (2 ≤ p ≤ y ≤ 109).
Output
Output the number of the highest suitable branch. If there are none, print -1 instead.
Examples
Input
3 6
Output
5
Input
3 4
Output
-1
Note
In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case. | instruction | 0 | 42,616 | 8 | 85,232 |
Tags: brute force, math, number theory
Correct Solution:
```
p, y = map(int, input().split())
for i in range(y, p, -1):
if all(i % j != 0 for j in range(2, min(p, int(i ** .5)) + 1)):
print(i)
exit()
print(-1)
``` | output | 1 | 42,616 | 8 | 85,233 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches <image>.
Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.
In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible.
Input
The only line contains two integers p and y (2 ≤ p ≤ y ≤ 109).
Output
Output the number of the highest suitable branch. If there are none, print -1 instead.
Examples
Input
3 6
Output
5
Input
3 4
Output
-1
Note
In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case. | instruction | 0 | 42,617 | 8 | 85,234 |
Tags: brute force, math, number theory
Correct Solution:
```
p,y=list(map(int,input().split()))
t=min(p,int(y**.5)+2)
for i in range(y,p,-1):
while t*t>i:t-=1
if not any(i%x==0 for x in range(2,t+1)):
print(i)
exit(0)
print(-1)
``` | output | 1 | 42,617 | 8 | 85,235 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches <image>.
Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.
In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible.
Input
The only line contains two integers p and y (2 ≤ p ≤ y ≤ 109).
Output
Output the number of the highest suitable branch. If there are none, print -1 instead.
Examples
Input
3 6
Output
5
Input
3 4
Output
-1
Note
In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case. | instruction | 0 | 42,618 | 8 | 85,236 |
Tags: brute force, math, number theory
Correct Solution:
```
import math
p,y=map(int,input().split())
def check(a):
for i in range(2,min(int(math.sqrt(a)),p)+1):
if a%i==0:
return False
return True
while y>p:
if check(y):
print(y)
exit(0)
y=y-1
print(-1)
``` | output | 1 | 42,618 | 8 | 85,237 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches <image>.
Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.
In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible.
Input
The only line contains two integers p and y (2 ≤ p ≤ y ≤ 109).
Output
Output the number of the highest suitable branch. If there are none, print -1 instead.
Examples
Input
3 6
Output
5
Input
3 4
Output
-1
Note
In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case. | instruction | 0 | 42,619 | 8 | 85,238 |
Tags: brute force, math, number theory
Correct Solution:
```
import math
import sys
import math
def div(p,n) :
list = []
for i in range(1, int(math.sqrt(n) + 1)) :
if (n % i == 0) :
if (n / i == i) :
list.append(i)
else :
list.append(i)
list.append(int(n / i))
list.sort()
if list[1]>p:
return list[1]
else:
return 0
p,y=map(int,input().split())
ctr=0
while(y>p and ctr<=300):
a=div(p,y)
if a!=0:
print(y)
sys.exit(0)
y-=1
ctr+=1
print(-1)
``` | output | 1 | 42,619 | 8 | 85,239 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.