message
stringlengths
2
43.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
853
107k
cluster
float64
24
24
__index_level_0__
int64
1.71k
214k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a lot of work to do. Recently he has learned a new time management rule: "if a task takes five minutes or less, do it immediately". Polycarp likes the new rule, however he is not sure that five minutes is the optimal value. He supposes that this value d should be chosen based on existing task list. Polycarp has a list of n tasks to complete. The i-th task has difficulty p_i, i.e. it requires exactly p_i minutes to be done. Polycarp reads the tasks one by one from the first to the n-th. If a task difficulty is d or less, Polycarp starts the work on the task immediately. If a task difficulty is strictly greater than d, he will not do the task at all. It is not allowed to rearrange tasks in the list. Polycarp doesn't spend any time for reading a task or skipping it. Polycarp has t minutes in total to complete maximum number of tasks. But he does not want to work all the time. He decides to make a break after each group of m consecutive tasks he was working on. The break should take the same amount of time as it was spent in total on completion of these m tasks. For example, if n=7, p=[3, 1, 4, 1, 5, 9, 2], d=3 and m=2 Polycarp works by the following schedule: * Polycarp reads the first task, its difficulty is not greater than d (p_1=3 ≀ d=3) and works for 3 minutes (i.e. the minutes 1, 2, 3); * Polycarp reads the second task, its difficulty is not greater than d (p_2=1 ≀ d=3) and works for 1 minute (i.e. the minute 4); * Polycarp notices that he has finished m=2 tasks and takes a break for 3+1=4 minutes (i.e. on the minutes 5, 6, 7, 8); * Polycarp reads the third task, its difficulty is greater than d (p_3=4 > d=3) and skips it without spending any time; * Polycarp reads the fourth task, its difficulty is not greater than d (p_4=1 ≀ d=3) and works for 1 minute (i.e. the minute 9); * Polycarp reads the tasks 5 and 6, skips both of them (p_5>d and p_6>d); * Polycarp reads the 7-th task, its difficulty is not greater than d (p_7=2 ≀ d=3) and works for 2 minutes (i.e. the minutes 10, 11); * Polycarp notices that he has finished m=2 tasks and takes a break for 1+2=3 minutes (i.e. on the minutes 12, 13, 14). Polycarp stops exactly after t minutes. If Polycarp started a task but has not finished it by that time, the task is not considered as completed. It is allowed to complete less than m tasks in the last group. Also Polycarp considers acceptable to have shorter break than needed after the last group of tasks or even not to have this break at all β€” his working day is over and he will have enough time to rest anyway. Please help Polycarp to find such value d, which would allow him to complete maximum possible number of tasks in t minutes. Input The first line of the input contains single integer c (1 ≀ c ≀ 5 β‹… 10^4) β€” number of test cases. Then description of c test cases follows. Solve test cases separately, test cases are completely independent and do not affect each other. Each test case is described by two lines. The first of these lines contains three space-separated integers n, m and t (1 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m ≀ 2 β‹… 10^5, 1 ≀ t ≀ 4 β‹… 10^{10}) β€” the number of tasks in Polycarp's list, the number of tasks he can do without a break and the total amount of time Polycarp can work on tasks. The second line of the test case contains n space separated integers p_1, p_2, ..., p_n (1 ≀ p_i ≀ 2 β‹… 10^5) β€” difficulties of the tasks. The sum of values n for all test cases in the input does not exceed 2 β‹… 10^5. Output Print c lines, each line should contain answer for the corresponding test case β€” the maximum possible number of tasks Polycarp can complete and the integer value d (1 ≀ d ≀ t) Polycarp should use in time management rule, separated by space. If there are several possible values d for a test case, output any of them. Examples Input 4 5 2 16 5 6 1 4 7 5 3 30 5 6 1 4 7 6 4 15 12 5 15 7 20 17 1 1 50 100 Output 3 5 4 7 2 10 0 25 Input 3 11 1 29 6 4 3 7 5 3 4 7 3 5 3 7 1 5 1 1 1 1 1 1 1 5 2 18 2 3 3 7 5 Output 4 3 3 1 4 5 Note In the first test case of the first example n=5, m=2 and t=16. The sequence of difficulties is [5, 6, 1, 4, 7]. If Polycarp chooses d=5 then he will complete 3 tasks. Polycarp will work by the following schedule: * Polycarp reads the first task, its difficulty is not greater than d (p_1=5 ≀ d=5) and works for 5 minutes (i.e. the minutes 1, 2, ..., 5); * Polycarp reads the second task, its difficulty is greater than d (p_2=6 > d=5) and skips it without spending any time; * Polycarp reads the third task, its difficulty is not greater than d (p_3=1 ≀ d=5) and works for 1 minute (i.e. the minute 6); * Polycarp notices that he has finished m=2 tasks and takes a break for 5+1=6 minutes (i.e. on the minutes 7, 8, ..., 12); * Polycarp reads the fourth task, its difficulty is not greater than d (p_4=4 ≀ d=5) and works for 4 minutes (i.e. the minutes 13, 14, 15, 16); * Polycarp stops work because of t=16. In total in the first test case Polycarp will complete 3 tasks for d=5. He can't choose other value for d to increase the number of completed tasks. Submitted Solution: ``` import io, os input = io.StringIO(os.read(0, os.fstat(0).st_size).decode()).readline ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) out = [] for _ in range(ii()): n, m, t = mi() p = li() def check(d): cur = tim = tot = totim = 0 for i in range(n): x = p[i] if x > d: continue totim += x tim += x if totim > t: break cur += 1 tot += 1 if cur == m: totim += tim if totim > t: break cur = tim = 0 return all(x > d for x in p[i+1:]), tot lo, hi = 1, t while lo < hi: mid = (lo + hi + 1) >> 1 if check(mid)[0]: lo = mid else: hi = mid - 1 out.append('%d %d' % (check(lo)[1], lo)) print(*out, sep='\n') ```
instruction
0
97,856
24
195,712
No
output
1
97,856
24
195,713
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a lot of work to do. Recently he has learned a new time management rule: "if a task takes five minutes or less, do it immediately". Polycarp likes the new rule, however he is not sure that five minutes is the optimal value. He supposes that this value d should be chosen based on existing task list. Polycarp has a list of n tasks to complete. The i-th task has difficulty p_i, i.e. it requires exactly p_i minutes to be done. Polycarp reads the tasks one by one from the first to the n-th. If a task difficulty is d or less, Polycarp starts the work on the task immediately. If a task difficulty is strictly greater than d, he will not do the task at all. It is not allowed to rearrange tasks in the list. Polycarp doesn't spend any time for reading a task or skipping it. Polycarp has t minutes in total to complete maximum number of tasks. But he does not want to work all the time. He decides to make a break after each group of m consecutive tasks he was working on. The break should take the same amount of time as it was spent in total on completion of these m tasks. For example, if n=7, p=[3, 1, 4, 1, 5, 9, 2], d=3 and m=2 Polycarp works by the following schedule: * Polycarp reads the first task, its difficulty is not greater than d (p_1=3 ≀ d=3) and works for 3 minutes (i.e. the minutes 1, 2, 3); * Polycarp reads the second task, its difficulty is not greater than d (p_2=1 ≀ d=3) and works for 1 minute (i.e. the minute 4); * Polycarp notices that he has finished m=2 tasks and takes a break for 3+1=4 minutes (i.e. on the minutes 5, 6, 7, 8); * Polycarp reads the third task, its difficulty is greater than d (p_3=4 > d=3) and skips it without spending any time; * Polycarp reads the fourth task, its difficulty is not greater than d (p_4=1 ≀ d=3) and works for 1 minute (i.e. the minute 9); * Polycarp reads the tasks 5 and 6, skips both of them (p_5>d and p_6>d); * Polycarp reads the 7-th task, its difficulty is not greater than d (p_7=2 ≀ d=3) and works for 2 minutes (i.e. the minutes 10, 11); * Polycarp notices that he has finished m=2 tasks and takes a break for 1+2=3 minutes (i.e. on the minutes 12, 13, 14). Polycarp stops exactly after t minutes. If Polycarp started a task but has not finished it by that time, the task is not considered as completed. It is allowed to complete less than m tasks in the last group. Also Polycarp considers acceptable to have shorter break than needed after the last group of tasks or even not to have this break at all β€” his working day is over and he will have enough time to rest anyway. Please help Polycarp to find such value d, which would allow him to complete maximum possible number of tasks in t minutes. Input The first line of the input contains single integer c (1 ≀ c ≀ 5 β‹… 10^4) β€” number of test cases. Then description of c test cases follows. Solve test cases separately, test cases are completely independent and do not affect each other. Each test case is described by two lines. The first of these lines contains three space-separated integers n, m and t (1 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m ≀ 2 β‹… 10^5, 1 ≀ t ≀ 4 β‹… 10^{10}) β€” the number of tasks in Polycarp's list, the number of tasks he can do without a break and the total amount of time Polycarp can work on tasks. The second line of the test case contains n space separated integers p_1, p_2, ..., p_n (1 ≀ p_i ≀ 2 β‹… 10^5) β€” difficulties of the tasks. The sum of values n for all test cases in the input does not exceed 2 β‹… 10^5. Output Print c lines, each line should contain answer for the corresponding test case β€” the maximum possible number of tasks Polycarp can complete and the integer value d (1 ≀ d ≀ t) Polycarp should use in time management rule, separated by space. If there are several possible values d for a test case, output any of them. Examples Input 4 5 2 16 5 6 1 4 7 5 3 30 5 6 1 4 7 6 4 15 12 5 15 7 20 17 1 1 50 100 Output 3 5 4 7 2 10 0 25 Input 3 11 1 29 6 4 3 7 5 3 4 7 3 5 3 7 1 5 1 1 1 1 1 1 1 5 2 18 2 3 3 7 5 Output 4 3 3 1 4 5 Note In the first test case of the first example n=5, m=2 and t=16. The sequence of difficulties is [5, 6, 1, 4, 7]. If Polycarp chooses d=5 then he will complete 3 tasks. Polycarp will work by the following schedule: * Polycarp reads the first task, its difficulty is not greater than d (p_1=5 ≀ d=5) and works for 5 minutes (i.e. the minutes 1, 2, ..., 5); * Polycarp reads the second task, its difficulty is greater than d (p_2=6 > d=5) and skips it without spending any time; * Polycarp reads the third task, its difficulty is not greater than d (p_3=1 ≀ d=5) and works for 1 minute (i.e. the minute 6); * Polycarp notices that he has finished m=2 tasks and takes a break for 5+1=6 minutes (i.e. on the minutes 7, 8, ..., 12); * Polycarp reads the fourth task, its difficulty is not greater than d (p_4=4 ≀ d=5) and works for 4 minutes (i.e. the minutes 13, 14, 15, 16); * Polycarp stops work because of t=16. In total in the first test case Polycarp will complete 3 tasks for d=5. He can't choose other value for d to increase the number of completed tasks. Submitted Solution: ``` import io, os input = io.StringIO(os.read(0, os.fstat(0).st_size).decode()).readline ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) out = [] for _ in range(ii()): n, m, t = mi() p = li() def check(d): cur = tim = tot = totim = 0 for i in range(n): x = p[i] if x > d: continue totim += x tim += x if totim > t: break cur += 1 tot += 1 if cur == m: totim += tim if totim > t: break cur = tim = 0 return all(x > d for x in p[i+1:]), tot lo, hi = 0, max(p) while lo < hi: mid = (lo + hi + 1) >> 1 if check(mid)[0]: lo = mid else: hi = mid - 1 out.append('%d %d' % (check(lo)[1], lo)) print(*out, sep='\n') ```
instruction
0
97,857
24
195,714
No
output
1
97,857
24
195,715
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3
instruction
0
98,912
24
197,824
Tags: greedy, math Correct Solution: ``` n=int(input()) arr=list(map(int,input().split())) s=0 for i in range(n): s+=arr[i] if s%n==0: print(n) else: print(n-1) ```
output
1
98,912
24
197,825
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3
instruction
0
98,913
24
197,826
Tags: greedy, math Correct Solution: ``` # It's all about what U BELIEVE def gint(): return int(input()) def gint_arr(): return list(map(int, input().split())) def gfloat(): return float(input()) def gfloat_arr(): return list(map(float, input().split())) def pair_int(): return map(int, input().split()) ############################################################################### INF = (1 << 31) dx = [-1, 0, 1, 0] dy = [ 0, 1, 0, -1] ############################################################################### ############################ SOLUTION IS COMING ############################### ############################################################################### n = gint() a = gint_arr() print(n if sum(a) % n == 0 else n - 1) ```
output
1
98,913
24
197,827
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3
instruction
0
98,914
24
197,828
Tags: greedy, math Correct Solution: ``` def IC(): n=int(input()) a=[int(x) for x in input().split()] shave=sum(a) if shave % n == 0: print(n) return else: print(n-1) return IC() ```
output
1
98,914
24
197,829
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3
instruction
0
98,915
24
197,830
Tags: greedy, math Correct Solution: ``` from math import pi def main(): n = int(input()) s = sum(map(int, input().split())) if s % n: n -= 1 print(n) if __name__ == '__main__': main() ```
output
1
98,915
24
197,831
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3
instruction
0
98,916
24
197,832
Tags: greedy, math Correct Solution: ``` def fun (x,l): if(len(set(x))==1): print(l) return if(sum(x)%l==0): print(l) else: print(l-1) return l = int(input()) x=list(map(int,input().split())) x.sort() fun(x,l) ```
output
1
98,916
24
197,833
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3
instruction
0
98,917
24
197,834
Tags: greedy, math Correct Solution: ``` n=int(input()) summ=sum(map(int,input().split())) if summ%n==0: print(n) else: print(n-1) ```
output
1
98,917
24
197,835
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3
instruction
0
98,918
24
197,836
Tags: greedy, math Correct Solution: ``` '''input 6 -1 1 0 0 -1 -1 ''' n = int(input()) a = list(map(int, input().split())) print(n if sum(a) % n == 0 else n - 1) ```
output
1
98,918
24
197,837
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3
instruction
0
98,919
24
197,838
Tags: greedy, math Correct Solution: ``` n=int(input()) print( n if sum((map(int,input().split())))%n==0 else n-1) ```
output
1
98,919
24
197,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3 Submitted Solution: ``` x=int(input()) sm=sum(list(map(int,input().split())))%x if sm==0: print(x) else: print(x-1) ```
instruction
0
98,920
24
197,840
Yes
output
1
98,920
24
197,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3 Submitted Solution: ``` n = int(input()) array = [int(c) for c in input().split()] array.sort() avg = sum(array) // n low, hi = 0, n - 1 while low < hi: amount = min(abs(array[hi] - avg), abs(avg - array[low])) array[low] += amount array[hi] -= amount if array[low] == avg: low += 1 if array[hi] == avg: hi -= 1 ans = sum(1 for x in array if x == avg) print(ans) ```
instruction
0
98,921
24
197,842
Yes
output
1
98,921
24
197,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3 Submitted Solution: ``` n=int(input()) arr = list(map(int, input().split())) arr.sort() if sum(arr)%n==0: print(n) else: print(n-1) ```
instruction
0
98,922
24
197,844
Yes
output
1
98,922
24
197,845
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3 Submitted Solution: ``` n = int(input()) print(n - 1 if sum(map(int, input().split())) % n else n) ```
instruction
0
98,923
24
197,846
Yes
output
1
98,923
24
197,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3 Submitted Solution: ``` import sys INF = 10**20 MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) from math import gcd from math import ceil from collections import defaultdict as dd, Counter from bisect import bisect_left as bl, bisect_right as br """ Facts and Data representation Constructive? Top bottom up down """ n, = I() a = I() fix = a[0] for i in range(1, n): if a[i] < 0: fix += -a[i] else: fix += a[i] if fix % n == 0: print(n) else: print(n - 1, fix) ```
instruction
0
98,924
24
197,848
No
output
1
98,924
24
197,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3 Submitted Solution: ``` n = int(input()) arr = input().split() arr = [int(i) for i in arr] sum_arr = sum(arr) ans = 1 for i in range(2, len(arr)+1): if(int(sum_arr/i) == sum_arr/i): ans = i print(ans) ```
instruction
0
98,925
24
197,850
No
output
1
98,925
24
197,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3 Submitted Solution: ``` l = int(input()) x = list(map(int, input().split())) d={} for i in range (len(x)): try: d[x[i]]+=1 except: d[x[i]]=1 m = max(d) m,s = d[m],0 for i in d: if(i!=m): s += abs(i-m) print(s) ```
instruction
0
98,926
24
197,852
No
output
1
98,926
24
197,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); * he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≀ 104) β€” the original array. Output Print a single integer β€” the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3 Submitted Solution: ``` n=int(input()) nums=list(map(int,input().split())) i=n maxx=-float('inf') while i: nums.sort() nums[-1]-=1 nums[0]+=1 count=len(nums)-len(set(nums)) maxx=max(count,maxx) i-=1 print(maxx+1) ```
instruction
0
98,927
24
197,854
No
output
1
98,927
24
197,855
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers.
instruction
0
99,695
24
199,390
Tags: *special, greedy, sortings Correct Solution: ``` from functools import cmp_to_key def main(): n, m = map(int, input().split()) markers = [] caps = [] for _ in range(n): x, y = map(int, input().split()) markers.append((x, y)) for _ in range(m): x, y = map(int, input().split()) caps.append((x, y)) marker_sizes = dict() cap_sizes = dict() marker_dict = dict() cap_dict = dict() for m in markers: if marker_sizes.get(m[1]): marker_sizes[m[1]] += 1 else: marker_sizes[m[1]] = 1 if marker_dict.get(m): marker_dict[m]+=1 else: marker_dict[m]=1 for c in caps: if cap_sizes.get(c[1]): cap_sizes[c[1]] += 1 else: cap_sizes[c[1]] = 1 if cap_dict.get(c): cap_dict[c]+=1 else: cap_dict[c]=1 ans1 = 0 for s, c1 in marker_sizes.items(): c2 = cap_sizes.get(s) if c2: ans1 += min(c1, c2) ans2 = 0 for val, freq in marker_dict.items(): x = cap_dict.get(val) if x: ans2+=min(freq, x) return '{} {}'.format(ans1, ans2) if __name__ == '__main__': print(main()) ```
output
1
99,695
24
199,391
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers.
instruction
0
99,696
24
199,392
Tags: *special, greedy, sortings Correct Solution: ``` import sys import time import math from collections import defaultdict from functools import lru_cache INF = 10 ** 18 + 3 EPS = 1e-10 MAX_CACHE = 10 ** 9 def time_it(function, output=sys.stderr): def wrapped(*args, **kwargs): start = time.time() res = function(*args, **kwargs) elapsed_time = time.time() - start print('"%s" took %f ms' % (function.__name__, elapsed_time * 1000), file=output) return res return wrapped @time_it def main(): n, m = map(int, input().split()) closed_count = 0 nice_closed_count = 0 markers = defaultdict(lambda: defaultdict(lambda: 0)) caps = defaultdict(lambda: defaultdict(lambda: 0)) for _ in range(n): color, size = map(int, input().split()) markers[size][color] += 1 for _ in range(m): color, size = map(int, input().split()) if markers[size][color] > 0: markers[size][color] -= 1 closed_count += 1 nice_closed_count += 1 else: caps[size][color] += 1 for size in caps.keys(): closed_count += min(sum(markers[size].values()), sum(caps[size].values())) print(closed_count, nice_closed_count) def set_input(file): global input input = lambda: file.readline().strip() def set_output(file): global print local_print = print def print(*args, **kwargs): kwargs["file"] = kwargs.get("file", file) return local_print(*args, **kwargs) if __name__ == '__main__': set_input(open("input.txt", "r") if "MINE" in sys.argv else sys.stdin) set_output(sys.stdout) main() ```
output
1
99,696
24
199,393
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers.
instruction
0
99,697
24
199,394
Tags: *special, greedy, sortings Correct Solution: ``` n, m = map(int, input().split()) x, y, u, v = {}, {}, 0, 0 for i in range(n): a, b = input().split() if b in x: x[b][a] = x[b].get(a, 0) + 1 else: x[b] = {a: 1} for i in range(m): a, b = input().split() if b in y: y[b][a] = y[b].get(a, 0) + 1 else: y[b] = {a: 1} for b in x.keys() & y.keys(): u += min(sum(x[b].values()), sum(y[b].values())) v += sum(min(x[b][a], y[b][a]) for a in x[b].keys() & y[b].keys()) print(u, v) # Made By Mostafa_Khaled ```
output
1
99,697
24
199,395
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers.
instruction
0
99,698
24
199,396
Tags: *special, greedy, sortings Correct Solution: ``` n,m=map(int,input().split()) m1={} m2={} c1={} c2={} for i in range(n): x,y=(map(int,input().split())) m1[y]=m1.get(y,0)+1 m2[(x,y)]=m2.get((x,y),0)+1 for i in range(m): x,y=(map(int,input().split())) c1[y]=c1.get(y,0)+1 c2[(x,y)]=c2.get((x,y),0)+1 r1=0 r2=0 for i in m1.keys(): if i in c1.keys(): t1=m1[i] t2=c1[i] r1=r1+(min(t1,t2)) for i in m2.keys(): if i in c2.keys(): t1=m2[i] t2=c2[i] r2=r2+(min(t1,t2)) print(r1,r2) ```
output
1
99,698
24
199,397
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers.
instruction
0
99,699
24
199,398
Tags: *special, greedy, sortings Correct Solution: ``` # n=int(input()) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) #ls=list(map(int,input().split())) #for i in range(m): # for _ in range(int(input())): #from collections import Counter #from fractions import Fraction #s=iter(input()) #from collections import deque from collections import Counter import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ########################################################## from collections import defaultdict m=defaultdict(list) c=defaultdict(list) n,k=map(int, input().split()) for i in range(n): u,v=map(int,input().split()) m[v].append(u) for i in range(k): u, v = map(int, input().split()) c[v].append(u) #print(m) #print(c) t=0 b=0 for j in sorted(m.keys()): if j in c: t += min(len(c[j]), len(m[j])) var = Counter(c[j]) ans=Counter(m[j]) for k in (ans.keys()): if k in var: b+=min(var[k],ans[k]) print(t ,b) ```
output
1
99,699
24
199,399
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers.
instruction
0
99,700
24
199,400
Tags: *special, greedy, sortings Correct Solution: ``` n,m=map(int,input().split()) p=[list(map(int,input().split())) for i in range(n)] dic1={} dic2={} for i in range(m): x,y=map(int,input().split()) dic1[(x,y)]=dic1.get((x,y),0)+1 dic2[y]=dic2.get(y,0)+1 c1=0 c2=0 for x in p: if dic1.get((x[0],x[1])): c1=c1+1 dic1[(x[0],x[1])]=dic1[(x[0],x[1])]-1 if dic2.get(x[1]): c2=c2+1 dic2[x[1]]=dic2[x[1]]-1 print(c2,c1) ```
output
1
99,700
24
199,401
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers.
instruction
0
99,701
24
199,402
Tags: *special, greedy, sortings Correct Solution: ``` def main(): from sys import stdin l = list(map(int, stdin.read().split())) n, yx = l[0] * 2, [[0] * 1001 for _ in range(1001)] cnt = yx[0] u = v = 0 for y, x in zip(l[3:n + 3:2], l[2:n + 2:2]): cnt[y] += 1 yx[y][x] += 1 ba, l = list(zip(l[n + 3::2], l[n + 2::2])), [] for y, x in ba: if yx[y][x]: yx[y][x] -= 1 cnt[y] -= 1 v += 1 else: l.append(y) for y in l: if cnt[y]: cnt[y] -= 1 u += 1 print(u + v, v) if __name__ == '__main__': main() ```
output
1
99,701
24
199,403
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers.
instruction
0
99,702
24
199,404
Tags: *special, greedy, sortings Correct Solution: ``` from collections import Counter def read_ints(): return tuple(int(x) for x in input().split()) def parse_input(size): data = [read_ints() for _ in range(size)] by_diam = Counter(size for diam, size in data) by_color = Counter(data) return by_diam, by_color n, m = read_ints() pens_by_diam, pens_by_color = parse_input(n) caps_by_diam, caps_by_color = parse_input(m) closed = sum((pens_by_diam & caps_by_diam).values()) beautiful = sum((pens_by_color & caps_by_color).values()) print(closed, beautiful) ```
output
1
99,702
24
199,405
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers. Submitted Solution: ``` __author__ = 'asmn' n,m=tuple(map(int,input().split())) cap1=[0]*1001 cap2=[0]*1001 cnt=[[0]*1001 for y in range(1001)] for k in range(n): x,y=tuple(map(int,input().split())) cap1[y]+=1 cnt[x][y]+=1 ans=0 for k in range(m): x,y=tuple(map(int,input().split())) cap2[y]+=1 if cnt[x][y] > 0: cnt[x][y]-=1 ans +=1 print(sum(min(cap1[y],cap2[y]) for y in range(1001)),ans) ```
instruction
0
99,703
24
199,406
Yes
output
1
99,703
24
199,407
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers. Submitted Solution: ``` n,m=map(int,input().split()) inp=[list(map(int,input().split())) for i in range(n)] dict1={} dict2={} count1=0 count2=0 for i in range(m): a,b=map(int,input().split()) dict1[(a,b)]=dict1.get((a,b),0)+1 dict2[b]=dict2.get(b,0)+1 for i in inp: if dict2.get(i[1]): count1=count1+1 dict2[i[1]]=dict2[i[1]]-1 if dict1.get((i[0],i[1])): count2=count2+1 dict1[(i[0],i[1])]=dict1[(i[0],i[1])]-1 print(count1,count2) ```
instruction
0
99,704
24
199,408
Yes
output
1
99,704
24
199,409
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers. Submitted Solution: ``` n,m = list(map(int,input().split())) buck1,buck2,cb,c = {},{}, 0, 0 for i in range(n): k1,k2 = list(map(int,input().split())) if k2 in buck1: buck1[k2][k1] = buck1[k2].get(k1,0) + 1 # get - The method get() returns a value for the given key else: buck1[k2] = {k1:1} for i in range(m): k1,k2 = list(map(int,input().split())) if k2 in buck2: buck2[k2][k1] = buck2[k2].get(k1,0) + 1 elif k2 in buck1: buck2[k2] = {k1:1} for i in buck1.keys() & buck2.keys(): c += min(sum(buck1[i].values()), sum(buck2[i].values())) cb += sum(min(buck1[i][k], buck2[i][k]) for k in buck1[i].keys() & buck2[i].keys()) print(c,cb) ```
instruction
0
99,705
24
199,410
Yes
output
1
99,705
24
199,411
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers. Submitted Solution: ``` n, m = map(int, input().split()) a = dict() l = list() u = 0 v = 0 for i in range(n): c, d = map(int, input().split()) if a.get(d, -1) == -1: a[d] = dict() a[d][c] = 1 elif a[d].get(c, -1) == -1: a[d][c] = 1 else: a[d][c] += 1 for i in range(m): c, d = map(int, input().split()) if a.get(d, -1) != -1: if a[d].get(c, -1) == -1: l.append((c, d)) else: a[d][c] -= 1 u += 1 if a[d][c] == 0: del a[d][c] if a[d] == {}: del a[d] for c, d in l: if a.get(d, -1) != -1: for i in a[d]: c = i break a[d][i] -= 1 v += 1 if a[d][i] == 0: del a[d][i] if a[d] == {}: del a[d] print(u + v, u) ```
instruction
0
99,706
24
199,412
Yes
output
1
99,706
24
199,413
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers. Submitted Solution: ``` n,m=map(int,input().split()) d,c,p,q={},{},{},{} for i in range(n): x,y=map(int,input().split()) if (x,y) in d: d[(x,y)]=+1 else: d[(x,y)]=1 if y in p: p[y]+=1 else: p[y]=1 u,v=0,0 for j in range(m): x,y=map(int,input().split()) if (x,y) in d and d[(x,y)]>0: d[(x,y)]=-1 u,v=u+1,v+1 p[y]=p[y]-1 else: if y in q: q[y]=+1 else: q[y]=1 for i in p: if i in q: u=u+min(p[i],q[i]) print(u,v) ```
instruction
0
99,707
24
199,414
No
output
1
99,707
24
199,415
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers. Submitted Solution: ``` n,m=map(int,input().split()) m1={} m2={} c1={} c2={} for i in range(n): x,y=(map(int,input().split())) m1[y]=m1.get(y,0)+1 m2[(x,y)]=m2.get((x,y),0)+1 for i in range(m): x,y=(map(int,input().split())) c1[y]=c1.get(y,0)+1 c2[(x,y)]=c2.get((x,y),0)+1 r1=0 r2=0 for i in m1.keys(): if i in c1.keys(): t1=m1[i] t2=c1[i] r1=r1+(min(t1,t2)) for i in m2.keys(): if i in c2.keys(): t1=m2[i] t2=m2[i] r2=r2+(min(t1,t2)) print(r1,r2) ```
instruction
0
99,708
24
199,416
No
output
1
99,708
24
199,417
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers. Submitted Solution: ``` from operator import itemgetter line = input().split() n, m = int(line[0]), int(line[1]) mk,c=[],[] for i in range(n): line = input().split() mk.append((int(line[1]), int(line[0]))) for i in range(m): line = input().split() c.append([int(line[1]), int(line[0])]) mk = sorted(mk,key=itemgetter(0,1)) c = sorted(c,key=itemgetter(0,1)) i, j, ic, jc, count, countp = 0, 0, 0, 0, 0, 0 while i < n and j < m: if mk[i][0] < c[j][0]: i += 1 elif mk[i][0] > c[j][0]: j +=1 else: count += 1 ic, jc = i, j while ic < n and jc < m: if mk[ic][1] < c[jc][1]: ic += 1 elif mk[ic][1] > c[jc][1]: jc += 1 else: countp += 1 break i += 1 j += 1 print(count,countp ) ```
instruction
0
99,709
24
199,418
No
output
1
99,709
24
199,419
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi. Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers. Input The first input line contains two space-separated integers n and m (1 ≀ n, m ≀ 105) β€” the number of markers and the number of caps, correspondingly. Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≀ xi, yi ≀ 1000) β€” the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≀ aj, bj ≀ 1000) β€” the color and diameter of the j-th cap, correspondingly. Output Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum. Examples Input 3 4 1 2 3 4 2 4 5 4 2 4 1 1 1 2 Output 3 2 Input 2 2 1 2 2 1 3 4 5 1 Output 1 0 Note In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed β€” the first and the third markers. Submitted Solution: ``` def main(): from sys import stdin l = list(map(int, stdin.read().split())) n, b, y, u, v = l[0] * 2, -1, -2, 0, 0 xy = iter(sorted(zip(l[3:n + 3:2], l[2:n + 2:2]))) ab = iter(sorted(zip(l[n + 3::2], l[n + 2::2]))) try: while True: while b > y: y, x = next(xy) while b < y: b, a = next(ab) u += 1 if x == a: v += 1 y, x = next(xy) b, a = next(ab) except StopIteration: print(u, v) if __name__ == '__main__': main() ```
instruction
0
99,710
24
199,420
No
output
1
99,710
24
199,421
Provide tags and a correct Python 3 solution for this coding contest problem. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
instruction
0
99,997
24
199,994
Tags: brute force, implementation Correct Solution: ``` n, m = [int(i) for i in input().split()] mn = 10 ** 5 mx = 1 n -= 1 for i in range(m): x, y = [int(i) for i in input().split()] x -= 1 y -= 1 if y != 0: mn = min(mn, x // y) mx = max(mx, [(x + y) // (y + 1), x // (y + 1) + 1][x % (y + 1) == 0]) a = n // mx for i in range(mx + 1, mn + 1): if a != n // i: print(-1) exit() print(a + 1) ```
output
1
99,997
24
199,995
Provide tags and a correct Python 3 solution for this coding contest problem. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
instruction
0
99,998
24
199,996
Tags: brute force, implementation Correct Solution: ``` import math from sys import stdin from math import ceil if __name__ == '__main__': numbers = list(map(int, input().split())) n = numbers[0] m = numbers[1] floors = [] for i in range(m): floors.append(tuple(map(int, input().split()))) rez = set() for i in range(1,100 + 1): ok = True for ki, fi in floors: if (ki + i - 1) // i != fi: ok = False break if ok: rez.add((n + i - 1) // i) if len(rez) == 1: x = rez.pop() print(x) else: print("-1") ```
output
1
99,998
24
199,997
Provide tags and a correct Python 3 solution for this coding contest problem. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
instruction
0
99,999
24
199,998
Tags: brute force, implementation Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now----------------------------------------------------- n, m = map(int, input().split()) l = set() s = {i for i in range(1, 101)} b = False for i in range(m): k, f = map(int, input().split()) if k == n: print(f) b = True break j = 1 if f == 1: l = {i for i in range(k, 101)} else: while j <= (k-j)//(f-1): if (k-j)%(f-1) == 0: l.add((k-j)//(f-1)) j += f-1 else: j += 1 s &= l l.clear() a = -1 if b == False: t = True for j in s: if a == -1: a = (n-1)//j else: if (n-1)//j != a: print(-1) t = False break if t == True: print(a+1) ```
output
1
99,999
24
199,999
Provide tags and a correct Python 3 solution for this coding contest problem. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
instruction
0
100,000
24
200,000
Tags: brute force, implementation Correct Solution: ``` import sys, os n, m = map(int, input().split()) mi = [] ma = [] if m == 0: if n == 1: print(1) else: print(-1) exit(0) sys.exit() os.abort() for i in range(m): a, b = map(int, input().split()) if b == 1: ma.append(1000000000) mi.append(a) if n <= a: print(1) exit(0) sys.exit() os.abort() else: mak = (a - 1) // (b - 1) ma.append(mak) if a % b == 0: mi.append(a // b) else: mi.append((a // b ) + 1) #print(mi, ma) mik = min(ma) mak = max(mi) if n % mik == 0: a = n // mik else: a = (n // mik) + 1 if n % mak == 0: b = n // mak else: b = (n // mak) + 1 if a == b: print(b) else: print(-1) ```
output
1
100,000
24
200,001
Provide tags and a correct Python 3 solution for this coding contest problem. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
instruction
0
100,001
24
200,002
Tags: brute force, implementation Correct Solution: ``` def rec(i): global a return i import sys from collections import Counter sys.setrecursionlimit(10**6) #n=int(input()) n,m=list(map(int,input().split())) a=[[] for i in range(100)] b=[i for i in range(1,101)] for i in range(m): x,y=list(map(int,input().split())) z=b.copy() for i0 in z: if not(((x-1)>=(y-1)*i0)and((x-1)<y*i0)): b.remove(i0) a=set() for i0 in b: a.add((n-1)//i0) if len(a)==1: print(a.pop()+1) else: print(-1) ```
output
1
100,001
24
200,003
Provide tags and a correct Python 3 solution for this coding contest problem. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
instruction
0
100,002
24
200,004
Tags: brute force, implementation Correct Solution: ``` n,m=map(int,input().split()) n-=1 k=[] f=[] p=0 for i in range(m): q=list(map(int,input().split())) k.append(q[0]) f.append(q[1]) for i in range(1,101): for j in range(m): if ((k[j]-1)//i)+1!=f[j]: break else: if not p: p=n//i+1 else: q=n//i+1 if p!=q: print(-1) exit() print(p) ```
output
1
100,002
24
200,005
Provide tags and a correct Python 3 solution for this coding contest problem. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
instruction
0
100,003
24
200,006
Tags: brute force, implementation Correct Solution: ``` from math import ceil n, m = map(int, input().split()) k = [0 for i in range(m)] f = [0 for i in range(m)] x = -1 for i in range(m): k[i], f[i] = map(int, input().split()) i = 0 while i < m: j = i while j < m: if abs(k[i] - k[j]) == 1 and abs(f[i] - f[j]) == 1: if f[i] < f[j]: x = ceil(n / ceil(k[i] / f[i])) else: x = ceil(n / ceil(k[j] / f[j])) i = m - 1 j = i j += 1 i += 1 if x > 0: print(x) else: c = [] for i in range(1, 101): j = 0 b = True while j < m and b: if not (ceil(k[j] / i) == f[j]): b = False j += 1 if b: c.append(i) x = ceil(n / c[0]) for i in range(len(c)): if ceil(n / c[i]) != x: x = -1 break print(x) ```
output
1
100,003
24
200,007
Provide tags and a correct Python 3 solution for this coding contest problem. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
instruction
0
100,004
24
200,008
Tags: brute force, implementation Correct Solution: ``` def xor(a,b,i): if (((a-1)//i)==(b-1)): return True elif(a<i) and (b==1): return True else: return False dannie = input() dannie = dannie.split(' ') level = int(dannie[0]) n = int(dannie[1]) levels = [] if level == 1: print(1) elif n == 0: print(-1) else: for i in range(0,n): info = input() info = info.split(' ') levels.append(info) fl = True i = 1 count = 0 while (i<=100) and (fl): for etaz in levels: fl2 = True flat = int(etaz[0]) floor = int(etaz[1]) if xor(flat, floor, i): continue else: fl2 = False if not(fl2): break if not(fl2): i = i + 1 elif (count==0) and fl2: count += 1 if level%i==0: answer = int(level/i) i = i + 1 else: answer = int((level//i) + 1) i = i + 1 elif fl2 and count!=0: if level%i==0: answer1 = level/i else: answer1 = level//i + 1 if answer1 == answer: i = i + 1 continue else: print(-1) fl = False else: i +=1 if fl : try: print(answer) except NameError: print(-1) ```
output
1
100,004
24
200,009
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat. Submitted Solution: ``` import math n,q = map(int,input().split()) lst = [ ] for i in range(q): x,y = map(int,input().split()) lst.append((x,y)) ans = set() for no_of_floors in range(1,101): flag = 1 for k,f in lst: temp_floor = math.ceil(k/no_of_floors) if(temp_floor!=f): flag = 0 if(flag): temp = math.ceil(n/no_of_floors) ans.add(temp) if(len(ans)!=1): print(-1) else: print(*ans) ```
instruction
0
100,005
24
200,010
Yes
output
1
100,005
24
200,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat. Submitted Solution: ``` import math def find_3(): etazh = [] for p in range(1, 101): if all((memory[0] + p - 1) // p == memory[1] for memory in mass): etazh.append(p) return etazh def find_2(): etazh = [] p = 1 while p < 100: for i in range (m): if math.ceil(mass[i][0]/p) != mass[i][1]: p += 1 break elif i==(m-1): etazh.append(p) p += 1 return etazh def find_1(): etazh = [] for p in range(100): suit = True for i in range(m): if math.ceil(mass[i][0]/p) != mass[i][1]: suit = False break if suit: etazh.append(p) return etazh n, m = map(int, input().split()) mass = [] for i in range (m): mass.append(list(map(int, input().split()))) etazh = find_3() if all((n+x-1)//x == (n+etazh[0]-1)//etazh[0] for x in etazh): print((n+etazh[0]-1)//etazh[0]) else: print(-1) ```
instruction
0
100,006
24
200,012
Yes
output
1
100,006
24
200,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat. Submitted Solution: ``` n, m = map(int, input().split()) k = [0] * 500 f = [0] * 500 for i in range(m): k[i], f[i] = map(int, input().split()) vars = set() for cnt in range(1, 201): flag = 1 for i in range(m): if (k[i] - 1) // cnt != f[i] - 1: flag = 0 break if flag: vars.add((n - 1) // cnt + 1) if n == 1: ans = 1 else: ans = -1 if len(vars) > 1 else max(vars) print(ans) ```
instruction
0
100,007
24
200,014
Yes
output
1
100,007
24
200,015
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat. Submitted Solution: ``` n, m = map(int, input().split()) ans = -1 k = [] f = [] for i in range(m): flat, level = map(int, input().split()) k.append(flat) f.append(level) mainflag = True for count in range(1, 101): flag = True for i in range(m): if (k[i] + count - 1) // count != f[i]: flag = False break if flag and ans != -1 and (n + count - 1) // count != (n + ans - 1) // ans: mainflag = False elif flag: ans = count if mainflag: print((n + ans - 1) // ans) else: print(-1) ```
instruction
0
100,008
24
200,016
Yes
output
1
100,008
24
200,017
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat. Submitted Solution: ``` n, m = map(int, input().split()) a = [] for i in range(m): k, f = map(int, input().split()) a.append((k, f)) cnt = 0 num = 0 for e in range(1, 101): can = True for k, f in a: if f != (k + e - 1) // e: can = False break if can: cnt += 1 num = e if cnt == 1: print((n + num - 1) // num) else: print(-1) ```
instruction
0
100,009
24
200,018
No
output
1
100,009
24
200,019
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat. Submitted Solution: ``` n, m = map(int, input().split()) k, f = map(int, input().split()) omin=(k-1)//f+1 omax = -1 if f > 1: omax=(k-1)//(f-1) for i in range(m-1): k, f = map(int, input().split()) localmin = (k-1) // f + 1 if f > 1: localmax = (k-1) // (f - 1) else: localmax = -1 omin = max(localmin, omin) if localmax != -1 and (localmax < omax or omax == -1): omax = localmax if omax == omin: print((n - 1) // omin + 1) elif omax == -1: print(1) else: print(-1) ```
instruction
0
100,010
24
200,020
No
output
1
100,010
24
200,021
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat. Submitted Solution: ``` from sys import stdout from sys import stdin def get(): return stdin.readline().strip() def getf(): return [int(i) for i in get().split()] def put(a, end = "\n"): stdout.write(str(a) + end) def putf(a, sep = " ", end = "\n"): stdout.write(sep.join(map(str, a)) + end) from math import ceil def main(): n, m = getf() fl = [[] for i in range(101)] for i in range(m): k, f = getf() fl[f] += [k] ans = -1 fl1 = -1 for i in range(1, 101): if(min(fl[i] or [-1]) <= n <= max(fl[i] or [-1])): ans = i for i in range(1, 100): f1, f2 = fl[i], fl[i + 1] if not(f1 and f2): continue k1, k2 = max(f1), min(f2) if(k2 - k1 == 1): fl1 = k1 // i if(ans == -1): if(fl1 != -1): put(int(ceil(n / fl1))) else: put(-1) else: put(ans) main() ```
instruction
0
100,011
24
200,022
No
output
1
100,011
24
200,023
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat n? Input The first line contains two integers n and m (1 ≀ n ≀ 100, 0 ≀ m ≀ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≀ ki ≀ 100, 1 ≀ fi ≀ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct. It is guaranteed that the given information is not self-contradictory. Output Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Examples Input 10 3 6 2 2 1 7 3 Output 4 Input 8 4 3 1 6 2 5 2 2 1 Output -1 Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat. Submitted Solution: ``` from math import ceil def check(flats_on_level): for fl in flats: after = ceil(fl[0] / flats_on_level) if fl[1] != after: return False return True n, m = map(int, input().split()) flats = [] for _ in range(m): ki, fi = map(int, input().split()) flats.append((ki, fi)) answer = -1 cf = -1 if m == 0 and n == 1: print(1) exit(0) for i in range(1, 101): if check(i): if answer == -1: answer = i else: cf == i if ceil(n / answer) != ceil(n / cf): print(-1) else: print(ceil(n / answer)) ```
instruction
0
100,012
24
200,024
No
output
1
100,012
24
200,025