message
stringlengths
2
39.6k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
219
108k
cluster
float64
11
11
__index_level_0__
int64
438
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A university student, Takahashi, has to take N examinations and pass all of them. Currently, his readiness for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * 1 \leq B_i \leq 10^9 * A_i and B_i are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_{N} B_1 B_2 ... B_{N} Output Print the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the conditions. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1. Examples Input 3 2 3 5 3 4 1 Output 3 Input 3 2 3 3 2 2 1 Output 0 Input 3 17 7 1 25 6 14 Output -1 Input 12 757232153 372327760 440075441 195848680 354974235 458054863 463477172 740174259 615762794 632963102 529866931 64991604 74164189 98239366 465611891 362739947 147060907 118867039 63189252 78303147 501410831 110823640 122948912 572905212 Output 5 Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=sorted([a[i]-b[i] for i in range(n)],reverse=True) if sum(c)<0: print(-1) else: d=[i for i in c if i<0] cnt=len(d) d=abs(sum(d)) i=0 while d>0: d-=c[i] cnt+=1 print(cnt) ```
instruction
0
65,471
11
130,942
No
output
1
65,471
11
130,943
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A university student, Takahashi, has to take N examinations and pass all of them. Currently, his readiness for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * 1 \leq B_i \leq 10^9 * A_i and B_i are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_{N} B_1 B_2 ... B_{N} Output Print the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the conditions. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1. Examples Input 3 2 3 5 3 4 1 Output 3 Input 3 2 3 3 2 2 1 Output 0 Input 3 17 7 1 25 6 14 Output -1 Input 12 757232153 372327760 440075441 195848680 354974235 458054863 463477172 740174259 615762794 632963102 529866931 64991604 74164189 98239366 465611891 362739947 147060907 118867039 63189252 78303147 501410831 110823640 122948912 572905212 Output 5 Submitted Solution: ``` N=int(input()) A=list(map(int,input().split(' '))) B=list(map(int,input().split(' '))) plus=[] minus = 0 ans = 0 if sum(A)<sum(B): print(-1) exit() for a,b in zip(A,B): if a-b >=0: plus.append(a-b) elif a-b<0: minus += a-b ans += 1 if minus==0: print(0) exit() sorted(plus,reverse=True) for i in sorted(plus,reverse=True): print(i) minus += i ans += 1 if minus >=0: print(ans) break ```
instruction
0
65,472
11
130,944
No
output
1
65,472
11
130,945
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A university student, Takahashi, has to take N examinations and pass all of them. Currently, his readiness for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * 1 \leq B_i \leq 10^9 * A_i and B_i are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_{N} B_1 B_2 ... B_{N} Output Print the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the conditions. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1. Examples Input 3 2 3 5 3 4 1 Output 3 Input 3 2 3 3 2 2 1 Output 0 Input 3 17 7 1 25 6 14 Output -1 Input 12 757232153 372327760 440075441 195848680 354974235 458054863 463477172 740174259 615762794 632963102 529866931 64991604 74164189 98239366 465611891 362739947 147060907 118867039 63189252 78303147 501410831 110823640 122948912 572905212 Output 5 Submitted Solution: ``` N = int(input()) taka = list(map(int,input().split())) exam = list(map(int,input().split())) sa = list() for t,e in zip(taka,exam): sa.append(t-e) sa = sorted(sa) minus = list(filter(lambda x:x<0,sa)) plus = list(filter(lambda x:x>0,sa)) sum_plus = 0 sum_minus = sum(minus) for idx,p in enumerate(plus[::-1]): sum_plus += p if sum_plus>=-sum_minus: print(idx+1+len(minus)) break else: if all([s==0 for s in sa]): print(0) else: print(-1) ```
instruction
0
65,473
11
130,946
No
output
1
65,473
11
130,947
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A university student, Takahashi, has to take N examinations and pass all of them. Currently, his readiness for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1. Constraints * 1 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * 1 \leq B_i \leq 10^9 * A_i and B_i are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_{N} B_1 B_2 ... B_{N} Output Print the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the conditions. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1. Examples Input 3 2 3 5 3 4 1 Output 3 Input 3 2 3 3 2 2 1 Output 0 Input 3 17 7 1 25 6 14 Output -1 Input 12 757232153 372327760 440075441 195848680 354974235 458054863 463477172 740174259 615762794 632963102 529866931 64991604 74164189 98239366 465611891 362739947 147060907 118867039 63189252 78303147 501410831 110823640 122948912 572905212 Output 5 Submitted Solution: ``` import numpy as np from collections import deque import sys N=int(input()) A=np.array([int(i) for i in input().split()]) B=np.array([int(i) for i in input().split()]) C = A-B minus_idx=np.where(C<0) plus_idx=np.where(C>0) minus = np.sum(C[minus_idx]) plus = deque(np.sort(C[plus_idx])) len_plus = len(plus) if len_plus == 0: print(-1) sys.exit() count = 0 while minus<0: minus += plus.pop() count += 1 len_plus -= 1 if len_plus == 0: print(-1) sys.exit() print(len(minus_idx[0])+count) ```
instruction
0
65,474
11
130,948
No
output
1
65,474
11
130,949
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; } Constraints * 3 ≤ n ≤ 10000 Input An integer n is given in a line. Output Print the output result of the above program for given integer n. Example Input 30 Output 3 6 9 12 13 15 18 21 23 24 27 30 Submitted Solution: ``` n=input() n=int(n) s="" for i in range(1,n+1): if i%3==0: s+=" "+str(i) elif "3" in list(str(i)): s+=" "+str(i) print(s) ```
instruction
0
65,602
11
131,204
Yes
output
1
65,602
11
131,205
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; } Constraints * 3 ≤ n ≤ 10000 Input An integer n is given in a line. Output Print the output result of the above program for given integer n. Example Input 30 Output 3 6 9 12 13 15 18 21 23 24 27 30 Submitted Solution: ``` N = int(input()) result = ' '.join([str(c) for c in range(1, N + 1) if c % 3 == 0 or '3' in str(c)]) print(' ' + result) ```
instruction
0
65,603
11
131,206
Yes
output
1
65,603
11
131,207
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; } Constraints * 3 ≤ n ≤ 10000 Input An integer n is given in a line. Output Print the output result of the above program for given integer n. Example Input 30 Output 3 6 9 12 13 15 18 21 23 24 27 30 Submitted Solution: ``` #1から入力数までで3で割り切れる数と3が入ってるかずを出力する for i in range(1,int(input()) + 1): if "3" in str(i) or i % 3 == 0:print(" " + str(i),end="") print() ```
instruction
0
65,604
11
131,208
Yes
output
1
65,604
11
131,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; } Constraints * 3 ≤ n ≤ 10000 Input An integer n is given in a line. Output Print the output result of the above program for given integer n. Example Input 30 Output 3 6 9 12 13 15 18 21 23 24 27 30 Submitted Solution: ``` n = int(input()) for i in range(3, n+1): if i % 3 == 0 or "3" in str(i): print("", i, end="") print() ```
instruction
0
65,605
11
131,210
Yes
output
1
65,605
11
131,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; } Constraints * 3 ≤ n ≤ 10000 Input An integer n is given in a line. Output Print the output result of the above program for given integer n. Example Input 30 Output 3 6 9 12 13 15 18 21 23 24 27 30 Submitted Solution: ``` # coding: utf-8 num = int(input()) i = 0 print(" ",end="") while (i != num): i+=1 if i % 3 == 0: print(i, end="") if i != num: print(" ", end="") elif "3" in str(i): print(i, end="") if i != num: print(" ",end="") ```
instruction
0
65,606
11
131,212
No
output
1
65,606
11
131,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; } Constraints * 3 ≤ n ≤ 10000 Input An integer n is given in a line. Output Print the output result of the above program for given integer n. Example Input 30 Output 3 6 9 12 13 15 18 21 23 24 27 30 Submitted Solution: ``` def call(n): i = 1 while i <= n: if i % 3 == 0: print(' {}'.format(i),end='') elif i % 10 == 3: print(' {}'.format(i),end='') i += 1 call(int(input())) ```
instruction
0
65,607
11
131,214
No
output
1
65,607
11
131,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; } Constraints * 3 ≤ n ≤ 10000 Input An integer n is given in a line. Output Print the output result of the above program for given integer n. Example Input 30 Output 3 6 9 12 13 15 18 21 23 24 27 30 Submitted Solution: ``` n=int(input()) for i in range(1,n): if i%3==0: print(i,end=" ") elif str(i).find("3")>-1: print(i,end=" ") ```
instruction
0
65,608
11
131,216
No
output
1
65,608
11
131,217
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; } Constraints * 3 ≤ n ≤ 10000 Input An integer n is given in a line. Output Print the output result of the above program for given integer n. Example Input 30 Output 3 6 9 12 13 15 18 21 23 24 27 30 Submitted Solution: ``` input("") print(3 6 9 12 13 15 18 21 23 24 27 30) ```
instruction
0
65,609
11
131,218
No
output
1
65,609
11
131,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy. Input The only line contains three integers n, a and b (0 ≤ a, b < n ≤ 100). Output Print the single number — the number of the sought positions. Examples Input 3 1 1 Output 2 Input 5 2 3 Output 3 Note The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5. Submitted Solution: ``` import sys,os,io,time,copy if os.path.exists('input.txt'): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') import math def main(): # start=time.time() n,a,b=map(int,input().split()) res=0 for i in range(1,n+1): if n-i>=a and i-1<=b: res+=1 print(res) # end=time.time() main() ```
instruction
0
65,717
11
131,434
Yes
output
1
65,717
11
131,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` import sys input = sys.stdin.readline for _ in range(int(input())): n,m = map(int,input().split()) a = [input() for i in range(n)] a = [[a[i][j] for j in range(m)] for i in range(n)] res = [] for x in range(0,n,2): for y in range(0,m,2): if x<n-1: if y<m-1: i,j = x,y else: i,j = x,y-1 else: if y<m-1: i,j = x-1,y else: i,j = x-1,y-1 tmp = int(a[i][j]) + int(a[i+1][j]) + int(a[i][j+1]) + int(a[i+1][j+1]) if tmp==1: if a[i][j] == "1": res.append((i,j,i,j)) res.append((i+1,j,i,j)) res.append((i,j+1,i,j)) elif a[i+1][j] == "1": res.append((i+1,j,i,j)) res.append((i,j,i,j)) res.append((i+1,j+1,i,j)) elif a[i][j+1] == "1": res.append((i,j+1,i,j)) res.append((i,j,i,j)) res.append((i+1,j+1,i,j)) elif a[i+1][j+1] == "1": res.append((i+1,j+1,i,j)) res.append((i+1,j,i,j)) res.append((i,j+1,i,j)) elif tmp==2: if a[i][j]=="1" and a[i+1][j]=="1": res.append((i,j+1,i,j)) res.append((i+1,j+1,i,j)) elif a[i][j]=="1" and a[i][j+1]=="1": res.append((i+1,j,i,j)) res.append((i+1,j+1,i,j)) elif a[i][j]=="1" and a[i+1][j+1]=="1": res.append((i,j,i,j)) res.append((i+1,j+1,i,j)) elif a[i+1][j]=="1" and a[i][j+1]=="1": res.append((i+1,j,i,j)) res.append((i,j+1,i,j)) elif a[i+1][j]=="1" and a[i+1][j+1]=="1": res.append((i,j,i,j)) res.append((i,j+1,i,j)) elif a[i][j+1]=="1" and a[i+1][j+1]=="1": res.append((i,j,i,j)) res.append((i+1,j,i,j)) elif tmp==3: if a[i][j]=="0": res.append((i+1,j+1,i,j)) elif a[i+1][j]=="0": res.append((i,j+1,i,j)) elif a[i][j+1]=="0": res.append((i+1,j,i,j)) else: res.append((i,j,i,j)) elif tmp==4: res.append((i,j,i,j)) res.append((i+1,j,i,j)) res.append((i,j+1,i,j)) res.append((i+1,j+1,i,j)) a[i][j],a[i+1][j],a[i][j+1],a[i+1][j+1]="0","0","0","0" print(len(res)) assert len(res)<=3*n*m for x,y,bx,by in res: #print(x,y,bx,by) tmp = [] d_x = bx + (1-((x-bx)%2)) d_y = by + (1-((y-by)%2)) for i in range(2): for j in range(2): if bx+i!=d_x or by+j!=d_y: tmp.append(bx+i+1) tmp.append(by+j+1) print(*tmp) ```
instruction
0
65,794
11
131,588
Yes
output
1
65,794
11
131,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` def multiLineArrayOfArraysPrint(arr): print('\n'.join([' '.join([str(x) for x in y]) for y in arr])) def fix2by2(x,y): #x,y are the coordinates of the bottom left corner cnt=0 for i in range(x,x+2): for j in range(y,y+2): if arr[i][j]==1: cnt+=1 if cnt==0: return [] if cnt==1: return fixOne(x,y) if cnt==2: return fixTwo(x,y) if cnt==3: return fixThree(x,y) if cnt==4: return fixFour(x,y) def getOneTwoThreeFour(x,y): blx=x+1 bly=y+1 one=[blx+1,bly,blx,bly,blx,bly+1] two=[blx,bly,blx,bly+1,blx+1,bly+1] three=[blx,bly+1,blx+1,bly+1,blx+1,bly] four=[blx,bly,blx+1,bly,blx+1,bly+1] return [one,two,three,four] def fixOne(x,y): one,two,three,four=getOneTwoThreeFour(x,y) if arr[x][y]==1:return [one,two,four] if arr[x+1][y]==1:return [one,three,four] if arr[x+1][y+1]==1:return[two,three,four] if arr[x][y+1]==1:return[one,two,three] def fixTwo(x,y): one,two,three,four=getOneTwoThreeFour(x,y) if arr[x][y]==arr[x][y+1]==1:return [three,four] if arr[x][y]==arr[x+1][y]==1:return [two,three] if arr[x][y]==arr[x+1][y+1]==1:return [one,three] if arr[x+1][y]==arr[x+1][y+1]==1:return [one,two] if arr[x][y+1]==arr[x+1][y+1]==1:return [one,four] if arr[x+1][y]==arr[x][y+1]==1:return [two,four] def fixThree(x,y): one,two,three,four=getOneTwoThreeFour(x,y) if arr[x][y]==0:return [three] if arr[x+1][y]==0:return [two] if arr[x][y+1]==0:return [four] if arr[x+1][y+1]==0:return [one] def fixFour(x,y): one,two,three,four=getOneTwoThreeFour(x,y) return [one,two,three,four] import sys input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS. t=int(input()) for _ in range(t): n,m=[int(x) for x in input().split()] arr=[] for _ in range(n): arr.append([int(x) for x in list(input())]) # arrTest=[x.copy() for x in arr] ans=[] starti=0 if n%2==0 else 1 startj=0 if m%2==0 else 1 if n%2==1 and m%2==1: starti=1 startj=1 if arr[0][0]==1: ans.append([1,1,1,2,2,1]) arr[0][0]=0 arr[0][1]=1-arr[0][1] arr[1][0]=1-arr[1][0] if n%2==1: i=0 for j in range(startj,m): if arr[i][j]==1: if j==0: ans.append([i+1,j+1,i+2,j+1,i+2,j+2]) arr[i][j]=0 arr[i+1][j]=1-arr[i+1][j] arr[i+1][j+1]=1-arr[i+1][j+1] else: ans.append([i+1,j+1,i+2,j,i+2,j+1]) arr[i][j]=0 arr[i+1][j]=1-arr[i+1][j] arr[i+1][j-1]=1-arr[i+1][j-1] if m%2==1: j=0 for i in range(starti,n): if arr[i][j]==1: if i!=n-1: ans.append([i+1,j+1,i+1,j+2,i+2,j+2]) arr[i][j]=0 arr[i][j+1]=1-arr[i][j+1] arr[i+1][j+1]=1-arr[i+1][j+1] else: ans.append([i+1,j+1,i+1,j+2,i,j+2]) arr[i][j]=0 arr[i][j+1]=1-arr[i][j+1] arr[i-1][j+1]=1-arr[i-1][j+1] for i in range(starti,n,2): for j in range(startj,m,2): for res in fix2by2(i,j): ans.append(res) print(len(ans)) multiLineArrayOfArraysPrint(ans) # arr=arrTest # print('\n') # for a in ans: # for i in range(len(a)): # a[i]-=1 # for x1,y1,x2,y2,x3,y3 in ans: # arr[x1][y1]=1-arr[x1][y1] # arr[x2][y2]=1-arr[x2][y2] # arr[x3][y3]=1-arr[x3][y3] # # multiLineArrayOfArraysPrint(arr) # print('') ```
instruction
0
65,795
11
131,590
Yes
output
1
65,795
11
131,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` for _ in range(int(input())): r, c = map(int, input().split()) a = [] b = [] [a.append(list(input())) for i in range(r)] for i in range(r - 1): for j in range(c): if j == 0 and int(a[i][j]): a[i][j] = (int(a[i][j]) + 1) % 2 a[i + 1][j] = (int(a[i + 1][j]) + 1) % 2 a[i + 1][j + 1] = (int(a[i + 1][j + 1]) + 1) % 2 b.append([i + 1, j + 1, i + 2, j + 1, i + 2, j + 2]) elif int(a[i][j]): a[i][j] = (int(a[i][j]) + 1) % 2 a[i + 1][j] = (int(a[i + 1][j]) + 1) % 2 a[i + 1][j - 1] = (int(a[i + 1][j - 1]) + 1) % 2 b.append([i + 1, j + 1, i + 2, j + 1, i + 2, j]) for j in range(c - 1): i = r - 1 if int(a[-1][j]): b.append([i, j + 1, i + 1, j + 1, i + 1, j + 2]) b.append([i, j + 1, i, j + 2, i + 1, j + 1]) b.append([i + 1, j + 2, i + 1, j + 1, i, j + 2]) if int(a[-1][-1]): i = r - 1 j = c - 1 b.append([i + 1, j + 1, i, j + 1, i + 1, j]) b.append([i, j + 1, i + 1, j + 1, i, j]) b.append([i + 1, j, i + 1, j + 1, i, j]) print(len(b)) for i in b: print(*i) ```
instruction
0
65,796
11
131,592
Yes
output
1
65,796
11
131,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` read = lambda: map(int, input().split()) t = int(input()) for _ in range(t): n, m = read() a = [list(map(int, input())) for i in range(n)] def add(x, y, z): a[x[0]][x[1]] ^= 1 a[y[0]][y[1]] ^= 1 a[z[0]][z[1]] ^= 1 ans.append(' '.join(map(lambda x: str(x + 1), (x[0], x[1], y[0], y[1], z[0], z[1])))) ans = [] for i in range(n - 1, 1, -1): for j in range(m): if a[i][j]: add((i, j), (i - 1, j), (i - 1, j + (1 if j < m - 1 else -1))) for j in range(m - 1, 1, -1): for i in (0, 1): if a[i][j]: add((i, j), (0, j - 1), (1, j - 1)) for i in (0, 1): for j in (0, 1): s = a[0][0] + a[0][1] + a[1][0] + a[1][1] if (s + a[i][j]) % 2: add((i ^ 1, j), (i, j ^ 1), (i ^ 1, j ^ 1)) print(len(ans)) print('\n'.join(ans)) ```
instruction
0
65,797
11
131,594
Yes
output
1
65,797
11
131,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` import sys input = sys.stdin.readline for _ in range(int(input())): n,m = map(int,input().split()) a = [input() for i in range(n)] a = [[a[i][j] for j in range(m)] for i in range(n)] res = [] for x in range(0,n,2): for y in range(0,m,2): if x<n-1: if y<m-1: i,j = x,y else: i,j = x,y-1 else: if y<m-1: i,j = x-1,y else: i,j = x-1,y-1 tmp = int(a[i][j]) + int(a[i+1][j]) + int(a[i][j+1]) + int(a[i+1][j+1]) if tmp==1: if a[i][j] == "1": res.append((i,j,i,j)) res.append((i+1,j,i,j)) res.append((j+1,i,i,j)) elif a[i+1][j] == "1": res.append((i+1,j,i,j)) res.append((i,j,i,j)) res.append((i+1,j+1,i,j)) elif a[i][j+1] == "1": res.append((i,j+1,i,j)) res.append((i,j,i,j)) res.append((i+1,j+1,i,j)) elif a[i+1][j+1] == "1": res.append((i+1,j+1,i,j)) res.append((i+1,j,i,j)) res.append((j+1,i,i,j)) elif tmp==2: if a[i][j]=="1" and a[i+1][j]=="1": res.append((i,j+1,i,j)) res.append((i+1,j+1,i,j)) elif a[i][j]=="1" and a[i][j+1]=="1": res.append((i+1,j,i,j)) res.append((i+1,j+1,i,j)) elif a[i][j]=="1" and a[i+1][j+1]=="1": res.append((i,j,i,j)) res.append((i+1,j+1,i,j)) elif a[i+1][j]=="1" and a[i][j+1]=="1": res.append((i+1,j,i,j)) res.append((i,j+1,i,j)) elif a[i+1][j]=="1" and a[i+1][j+1]=="1": res.append((i,j,i,j)) res.append((i,j+1,i,j)) elif a[i][j+1]=="1" and a[i+1][j+1]=="1": res.append((i,j,i,j)) res.append((i+1,j,i,j)) elif tmp==3: if a[i][j]=="0": res.append((i+1,j+1,i,j)) elif a[i+1][j]=="0": res.append((i,j+1,i,j)) elif a[i][j+1]=="0": res.append((i+1,j,i,j)) else: res.append((i,j,i,j)) elif tmp==4: res.append((i,j,i,j)) res.append((i+1,j,i,j)) res.append((i,j+1,i,j)) res.append((i+1,j+1,i,j)) a[i][j],a[i+1][j],a[i][j+1],a[i+1][j+1]="0","0","0","0" print(len(res)) for x,y,bx,by in res: #print(x,y,bx,by) tmp = [] d_x = bx + (1-((x-bx)%2)) d_y = by + (1-((y-by)%2)) for i in range(2): for j in range(2): if bx+i!=d_x or by+j!=d_y: tmp.append(bx+i+1) tmp.append(by+j+1) print(*tmp) ```
instruction
0
65,798
11
131,596
No
output
1
65,798
11
131,597
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` def fun3(): x = [] for i1 in range(i,i+2): for j1 in range(j,j+2): if l[i1][j1]==1: x.append(i1+1) x.append(j1+1) ans.append(x) def fun2(): #10 #01 if (l[i][j]==1 and l[i+1][j+1]==1): x = [i+1,j+1,i+1+1,j+1,i+1,j+1+1] ans.append(x) x = [i+1+1,j,i+1,j+1+1,i+1+1,j+1+1] ans.append(x) return if (l[i+1][j]==1 and l[i][j+1]==1): x = [i+1+1,j+1+1,i+1+1,j+1,i+1,j+1] ans.append(x) x = [i+1,j+1,i+1,j+1+1,i+1+1,j+1+1] ans.append(x) return #01 #10 if (l[i][j]==1 and l[i+1][j]==1): x = [i+1+1,j+1+1,i+1+1,j+1,i+1,j+1+1] ans.append(x) x = [i+1,j+1,i+2,j+1,i+1,j+2] ans.append(x) #10 #10 return if (l[i][j+1]==1 and l[i+1][j+1]==1): x = [i+1,j+1,i+1+1,j+1+1,i+1+1,j+1] ans.append(x) x = [i+1,j+1,i+1,j+2,i+2,j+1] ans.append(x) #01 #01 return if (l[i][j]==1 and l[i][j+1]==1): #11 #00 x = [i+1,j+1+1,i+1+1,j+1+1,i+1+1,j+1] ans.append(x) x = [i+1,j+1,i+1+1,j+1+1,i+1+1,j+1] ans.append(x) return if (l[i+1][j]==1 and l[i+1][j]==1): #00 #11 x = [i+1,j+1,i+1,j+1+1,i+1+1,j+1] ans.append(x) x = [i+1,j+1,i+1,j+1+1,i+1+1,j+1+1] ans.append(x) return def fun1(): if (l[i][j]==1): x = [i+1,j+1,i+1,j+1+1,i+1+1,j+1+1] l[i][j]=0 l[i+1][j]=1 l[i+1][j+1]=1 if (l[i][j+1]==1): x = [i+1,j+1,i+1,j+1+1,i+1+1,j+1+1] l[i][j]=1 l[i+1][j]=0 l[i+1][j+1]=1 if (l[i+1][j]==1): x = [i+1,j+1,i+1,j+1+1,i+1+1,j+1] l[i][j]=1 l[i][j+1]=1 l[i+1][j]=0 if (l[i+1][j+1]==1): x = [i+1,j+1,i+1,j+1+1,i+1+1,j+1+1] l[i][j]=1 l[i][j+1]=1 l[i+1][j+1]=0 ans.append(x) fun2() count=0 def fun4(): x = [i+1,j+1,i+1,j+1,i+1,j+2,i+2,j+2] ans.append(x) def fun(block,b): if (b.count(1)==0): return if (b.count(1)==1): fun1() return if (b.count(1)==2): fun2() return if (b.count(1)==3): fun3() return if (b.count(1)==4): fun4() return t = int(input()) for _ in range(t): n,m = [int(x) for x in input().split()] l = [] for i in range(n): a = list(input()) l.append(a) for i in range(n): for j in range(m): l[i][j]=int(l[i][j]) count = 0 ans = [] for i in range(n-1): for j in range(n-1): block = l[i:i+2][j:j+2] b = [] block1 = [] block1.append(l[i][j:j+2]) block1.append(l[i+1][j:j+2]) block = block1[:] for element in block: for ele1 in element: b.append(ele1) fun(block,b) l[i][j]=0 l[i+1][j]=0 l[i][j+1]=0 l[i+1][j+1]=0 print(len(ans)) for i in ans: print(*i) #print(l) ```
instruction
0
65,799
11
131,598
No
output
1
65,799
11
131,599
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() def flip(i,j): res=[] if j==w-1:j-=1 cnt=3 if aa[i][j]: aa[i][j]=0 cnt-=1 res+=[i+1,j+1] if aa[i][j+1]: aa[i][j+1]=0 cnt-=1 res+=[i+1,j+2] if cnt==2 or aa[i+1][j+1]: aa[i+1][j]=0 cnt-=1 res+=[i+2,j+1] if cnt: aa[i+1][j+1]=0 cnt-=1 res+=[i+2,j+2] return res def zero(sj): ij1=[] ij0=[] res=[] for i in range(h-2,h): for j in range(sj,sj+2): if aa[i][j]:ij1.append((i,j)) else:ij0.append((i,j)) if len(ij1)==3: for i,j in ij1: aa[i][j]=0 res+=[i+1,j+1] elif len(ij1)==2: i,j=ij1[0] aa[i][j] = 0 res += [i+1, j+1] for i,j in ij0: aa[i][j]=0 res+=[i+1,j+1] else: i,j=ij1[0] aa[i][j] = 0 res += [i+1, j+1] for i,j in ij0[:2]: aa[i][j]=0 res+=[i+1,j+1] return res for _ in range(II()): h,w=MI() aa=[[int(c) for c in SI()] for _ in range(h)] ans=[] for i in range(h-1): for j in range(w): if aa[i][j]: ans.append(flip(i,j)) for j in range(w-1): while aa[h-2][j]+aa[h-2][j+1]+aa[h-1][j]+aa[h-1][j+1]: ans.append(zero(j)) # p2D(aa) print(len(ans)) for row in ans: print(*row) ```
instruction
0
65,800
11
131,600
No
output
1
65,800
11
131,601
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0). Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations. It can be proved that it is always possible. Input The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100). Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table. It is guaranteed that the sum of nm for all test cases does not exceed 20000. Output For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations. In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square. Example Input 5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101 Output 1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2 Note In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0. In the second test case: * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 011 001 000 * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 000 000 000 In the fifth test case: * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 010 110 * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 000 000 Submitted Solution: ``` import sys input = sys.stdin.readline for _ in range(int(input())): n,m = map(int,input().split()) l = [[ i for i in input()] for _ in range(n)] r = [] for i in range(n): for j in range(m): if l[i][j]=='1': #print(i,j) if i+1>=n or j+1>=m: l[i][j]='0' r.append([i-1+1,j-1+1,i+1,j-1+1,i+1,j+1]) r.append([i+1,j-1+1,i+1,j+1,i-1+1,j+1]) r.append([i+1,j+1,i-1+1,j+1,i-1+1,j-1+1]) else: l[i][j]='0' r.append([i+1+1,j+1+1,i+1+1,j+1,i+1,j+1]) r.append([i+1+1,j+1,i+1,j+1,i+1,j+1+1]) r.append([i+1,j+1,i+1,j+1+1,i+1+1,j+1+1]) print(len(r)) for i in r: print(*i) ```
instruction
0
65,801
11
131,602
No
output
1
65,801
11
131,603
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a number n and an array b_1, b_2, …, b_{n+2}, obtained according to the following algorithm: * some array a_1, a_2, …, a_n was guessed; * array a was written to array b, i.e. b_i = a_i (1 ≤ i ≤ n); * The (n+1)-th element of the array b is the sum of the numbers in the array a, i.e. b_{n+1} = a_1+a_2+…+a_n; * The (n+2)-th element of the array b was written some number x (1 ≤ x ≤ 10^9), i.e. b_{n+2} = x; The * array b was shuffled. For example, the array b=[2, 3, 7, 12 ,2] it could be obtained in the following ways: * a=[2, 2, 3] and x=12; * a=[3, 2, 7] and x=2. For the given array b, find any array a that could have been guessed initially. Input The first line contains a single integer t (1 ≤ t ≤ 10^4). Then t test cases follow. The first line of each test case contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5). The second row of each test case contains n+2 integers b_1, b_2, …, b_{n+2} (1 ≤ b_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output: * "-1", if the array b could not be obtained from any array a; * n integers a_1, a_2, …, a_n, otherwise. If there are several arrays of a, you can output any. Example Input 4 3 2 3 7 12 2 4 9 1 7 1 6 5 5 18 2 2 3 2 9 2 3 2 6 9 2 1 Output 2 3 7 -1 2 2 2 3 9 1 2 6 Submitted Solution: ``` t=int(input()) for i in range(t): n=int(input()) b=[int(x) for x in input().split()] b.sort() temp=sum(b[:n]) if b[n]==temp or b[n+1]==temp: b=[str(x) for x in b] print(" ".join(b[:n])) continue temp=sum(b[:n+1]) flag=False for i in range(n): temp1=temp-b[i] if temp1==b[n+1]: flag=True b.pop(i) break if flag: b=[str(x) for x in b] print(" ".join(b[:n])) else: print(-1) ```
instruction
0
65,827
11
131,654
Yes
output
1
65,827
11
131,655
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a number n and an array b_1, b_2, …, b_{n+2}, obtained according to the following algorithm: * some array a_1, a_2, …, a_n was guessed; * array a was written to array b, i.e. b_i = a_i (1 ≤ i ≤ n); * The (n+1)-th element of the array b is the sum of the numbers in the array a, i.e. b_{n+1} = a_1+a_2+…+a_n; * The (n+2)-th element of the array b was written some number x (1 ≤ x ≤ 10^9), i.e. b_{n+2} = x; The * array b was shuffled. For example, the array b=[2, 3, 7, 12 ,2] it could be obtained in the following ways: * a=[2, 2, 3] and x=12; * a=[3, 2, 7] and x=2. For the given array b, find any array a that could have been guessed initially. Input The first line contains a single integer t (1 ≤ t ≤ 10^4). Then t test cases follow. The first line of each test case contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5). The second row of each test case contains n+2 integers b_1, b_2, …, b_{n+2} (1 ≤ b_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output: * "-1", if the array b could not be obtained from any array a; * n integers a_1, a_2, …, a_n, otherwise. If there are several arrays of a, you can output any. Example Input 4 3 2 3 7 12 2 4 9 1 7 1 6 5 5 18 2 2 3 2 9 2 3 2 6 9 2 1 Output 2 3 7 -1 2 2 2 3 9 1 2 6 Submitted Solution: ``` import sys import math as mt import collections as cc import itertools as it input = sys.stdin.readline I = lambda:list(map(int,input().split())) for tc in range(int(input())): n , = I() ar = I() ar.sort() ans = [] su = sum(ar) #print(ar) #print(su) for i in [len(ar)-1,len(ar)-2]: tar = ar[i] now = su - tar #print(tar,now) for j in range(len(ar)): if j!=i: if now - ar[j] == tar: ans.append([i,j]) if ans: #print(ans[0],ar) for i in range(len(ar)): if i not in ans[0]: print(ar[i],end=" ") print() else: print(-1) ```
instruction
0
65,828
11
131,656
Yes
output
1
65,828
11
131,657
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a number n and an array b_1, b_2, …, b_{n+2}, obtained according to the following algorithm: * some array a_1, a_2, …, a_n was guessed; * array a was written to array b, i.e. b_i = a_i (1 ≤ i ≤ n); * The (n+1)-th element of the array b is the sum of the numbers in the array a, i.e. b_{n+1} = a_1+a_2+…+a_n; * The (n+2)-th element of the array b was written some number x (1 ≤ x ≤ 10^9), i.e. b_{n+2} = x; The * array b was shuffled. For example, the array b=[2, 3, 7, 12 ,2] it could be obtained in the following ways: * a=[2, 2, 3] and x=12; * a=[3, 2, 7] and x=2. For the given array b, find any array a that could have been guessed initially. Input The first line contains a single integer t (1 ≤ t ≤ 10^4). Then t test cases follow. The first line of each test case contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5). The second row of each test case contains n+2 integers b_1, b_2, …, b_{n+2} (1 ≤ b_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output: * "-1", if the array b could not be obtained from any array a; * n integers a_1, a_2, …, a_n, otherwise. If there are several arrays of a, you can output any. Example Input 4 3 2 3 7 12 2 4 9 1 7 1 6 5 5 18 2 2 3 2 9 2 3 2 6 9 2 1 Output 2 3 7 -1 2 2 2 3 9 1 2 6 Submitted Solution: ``` for _ in range(int(input())): n = int(input()) arrB = list(map(int, input().split())) arrB.sort() sumB = sum(arrB) for i in range(n+2): if i != n+1: if sumB-arrB[i] == 2*arrB[n+1]: print(*arrB[:i]+arrB[i+1:n+1]) break else: if sumB-arrB[n+1] == 2*arrB[n]: print(*arrB[:n]) break else: print(-1) ```
instruction
0
65,829
11
131,658
Yes
output
1
65,829
11
131,659
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a number n and an array b_1, b_2, …, b_{n+2}, obtained according to the following algorithm: * some array a_1, a_2, …, a_n was guessed; * array a was written to array b, i.e. b_i = a_i (1 ≤ i ≤ n); * The (n+1)-th element of the array b is the sum of the numbers in the array a, i.e. b_{n+1} = a_1+a_2+…+a_n; * The (n+2)-th element of the array b was written some number x (1 ≤ x ≤ 10^9), i.e. b_{n+2} = x; The * array b was shuffled. For example, the array b=[2, 3, 7, 12 ,2] it could be obtained in the following ways: * a=[2, 2, 3] and x=12; * a=[3, 2, 7] and x=2. For the given array b, find any array a that could have been guessed initially. Input The first line contains a single integer t (1 ≤ t ≤ 10^4). Then t test cases follow. The first line of each test case contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5). The second row of each test case contains n+2 integers b_1, b_2, …, b_{n+2} (1 ≤ b_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output: * "-1", if the array b could not be obtained from any array a; * n integers a_1, a_2, …, a_n, otherwise. If there are several arrays of a, you can output any. Example Input 4 3 2 3 7 12 2 4 9 1 7 1 6 5 5 18 2 2 3 2 9 2 3 2 6 9 2 1 Output 2 3 7 -1 2 2 2 3 9 1 2 6 Submitted Solution: ``` import sys read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip() import bisect,string,math,time,functools,random,fractions from bisect import* from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby rep=range;R=range def I():return int(input()) def LI():return [int(i) for i in input().split()] def LI_():return [int(i)-1 for i in input().split()] def AI():return map(int,open(0).read().split()) def S_():return input() def IS():return input().split() def LS():return [i for i in input().split()] def NI(n):return [int(input()) for i in range(n)] def NI_(n):return [int(input())-1 for i in range(n)] def NLI(n):return [[int(i) for i in input().split()] for i in range(n)] def NLI_(n):return [[int(i)-1 for i in input().split()] for i in range(n)] def StoLI():return [ord(i)-97 for i in input()] def ItoS(n):return chr(n+97) def LtoS(ls):return ''.join([chr(i+97) for i in ls]) def RLI(n=8,a=1,b=10):return [random.randint(a,b)for i in range(n)] def RI(a=1,b=10):return random.randint(a,b) def INP(): N=10 n=random.randint(1,N) a=RLI(n,0,n-1) return n,a def Rtest(T): case,err=0,0 for i in range(T): inp=INP() a1=naive(*inp) a2=solve(*inp) if a1!=a2: print(inp) print('naive',a1) print('solve',a2) err+=1 case+=1 print('Tested',case,'case with',err,'errors') def GI(V,E,ls=None,Directed=False,index=1): org_inp=[];g=[[] for i in range(V)] FromStdin=True if ls==None else False for i in range(E): if FromStdin: inp=LI() org_inp.append(inp) else: inp=ls[i] if len(inp)==2:a,b=inp;c=1 else:a,b,c=inp if index==1:a-=1;b-=1 aa=(a,c);bb=(b,c);g[a].append(bb) if not Directed:g[b].append(aa) return g,org_inp def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1): #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage mp=[boundary]*(w+2);found={} for i in R(h): s=input() for char in search: if char in s: found[char]=((i+1)*(w+2)+s.index(char)+1) mp_def[char]=mp_def[replacement_of_found] mp+=[boundary]+[mp_def[j] for j in s]+[boundary] mp+=[boundary]*(w+2) return h+2,w+2,mp,found def TI(n):return GI(n,n-1) def accum(ls): rt=[0] for i in ls:rt+=[rt[-1]+i] return rt def bit_combination(n,base=2): rt=[] for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s] return rt def gcd(x,y): if y==0:return x if x%y==0:return y while x%y!=0:x,y=y,x%y return y def YN(x):print(['NO','YES'][x]) def Yn(x):print(['No','Yes'][x]) def show(*inp,end='\n'): if show_flg:print(*inp,end=end) mo=10**9+7 #mo=998244353 inf=float('inf') FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb)) alp=[chr(ord('a')+i)for i in range(26)] #sys.setrecursionlimit(10**7) def gcj(c,x): print("Case #{0}:".format(c+1),x) ######################################################################################################################################################################## # Verified by # https://yukicoder.me/problems/no/979 # https://atcoder.jp/contests/abc152/tasks/abc152_e ## return prime factors of N as dictionary {prime p:power of p} ## within 2 sec for N = 2*10**20+7 def primeFactor(N): i,n=2,N ret={} d,sq=2,99 while i<=sq: k=0 while n%i==0: n,k,ret[i]=n//i,k+1,k+1 if k>0 or i==97: sq=int(n**(1/2)+0.5) if i<4: i=i*2-1 else: i,d=i+d,d^6 if n>1: ret[n]=1 return ret ## return divisors of n as list def divisor(n): div=[1] for i,j in primeFactor(n).items(): div=[(i**k)*d for d in div for k in range(j+1)] return div ## return the list of prime numbers in [2,N], using eratosthenes sieve ## around 800 ms for N = 10**6 by PyPy3 (7.3.0) @ AtCoder def PrimeNumSet(N): M=int(N**0.5) seachList=[i for i in range(2,N+1)] primes=[] while seachList: if seachList[0]>M: break primes.append(seachList[0]) tmp=seachList[0] seachList=[i for i in seachList if i%tmp!=0] return primes+seachList ## retrun LCM of numbers in list b ## within 2sec for no of B = 10*5 and Bi < 10**6 def LCM(b,mo=10**9+7): prs=PrimeNumSet(max(b)) M=dict(zip(prs,[0]*len(prs))) for i in b: dc=primeFactor(i) for j,k in dc.items(): M[j]=max(M[j],k) r=1 for j,k in M.items(): if k!=0: r*=pow(j,k,mo) r%=mo return r ## return (a,b,gcd(x,y)) s.t. a*x+b*y=gcd(x,y) def extgcd(x,y): if y==0: return 1,0 r0,r1,s0,s1 = x,y,1,0 while r1!= 0: r0,r1,s0,s1=r1,r0%r1,s1,s0-r0//r1*s1 return s0,(r0-s0*x)//y,x*s0+y*(r0-s0*x)//y ## return x,LCM(mods) s.t. x = rem_i (mod_i), x = -1 if such x doesn't exist ## verified by ABC193E ## https://atcoder.jp/contests/abc193/tasks/abc193_e def crt(rems,mods): n=len(rems) if n!=len(mods): return NotImplemented x,d=0,1 for r,m in zip(rems,mods): a,b,g=extgcd(d,m) x,d=(m*b*x+d*a*r)//g,d*(m//g) x%=d for r,m in zip(rems,mods): if r!=x%m: return -1,d return x,d ## returns the maximum integer rt s.t. rt*rt<=x ## verified by ABC191D ## https://atcoder.jp/contests/abc191/tasks/abc191_d def intsqrt(x): if x<0: return NotImplemented rt=int(x**0.5)-1 while (rt+1)**2<=x: rt+=1 return rt class Comb: def __init__(self,n,mo=10**9+7): self.fac=[0]*(n+1) self.inv=[1]*(n+1) self.fac[0]=1 self.fact(n) for i in range(1,n+1): self.fac[i]=i*self.fac[i-1]%mo self.inv[n]*=i self.inv[n]%=mo self.inv[n]=pow(self.inv[n],mo-2,mo) for i in range(1,n): self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo return def fact(self,n): return self.fac[n] def invf(self,n): return self.inv[n] def comb(self,x,y): if y<0 or y>x: return 0 return self.fac[x]*self.inv[x-y]*self.inv[y]%mo def cat(self,x): if x<0: return 0 return self.fac[2*x]*self.inv[x]*self.inv[x+1]%mo show_flg=False show_flg=True ans=0 for _ in range(I()): n=I() b=sorted(LI())[::-1] orb=b[:] s=sum(b[1:]) x,y=b[:2] if s-x in b[1:]: b.remove(s-x) print(*b[1:]) elif y==s-y: print(*b[2:]) else: print(-1) ```
instruction
0
65,830
11
131,660
Yes
output
1
65,830
11
131,661
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a number n and an array b_1, b_2, …, b_{n+2}, obtained according to the following algorithm: * some array a_1, a_2, …, a_n was guessed; * array a was written to array b, i.e. b_i = a_i (1 ≤ i ≤ n); * The (n+1)-th element of the array b is the sum of the numbers in the array a, i.e. b_{n+1} = a_1+a_2+…+a_n; * The (n+2)-th element of the array b was written some number x (1 ≤ x ≤ 10^9), i.e. b_{n+2} = x; The * array b was shuffled. For example, the array b=[2, 3, 7, 12 ,2] it could be obtained in the following ways: * a=[2, 2, 3] and x=12; * a=[3, 2, 7] and x=2. For the given array b, find any array a that could have been guessed initially. Input The first line contains a single integer t (1 ≤ t ≤ 10^4). Then t test cases follow. The first line of each test case contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5). The second row of each test case contains n+2 integers b_1, b_2, …, b_{n+2} (1 ≤ b_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output: * "-1", if the array b could not be obtained from any array a; * n integers a_1, a_2, …, a_n, otherwise. If there are several arrays of a, you can output any. Example Input 4 3 2 3 7 12 2 4 9 1 7 1 6 5 5 18 2 2 3 2 9 2 3 2 6 9 2 1 Output 2 3 7 -1 2 2 2 3 9 1 2 6 Submitted Solution: ``` def isSum(a,sumy,val): for i in range(len(a)): if val == sumy-a[i]: return (True,i) return (False,0) for _ in range(int(input())): n = int(input()) arr = list(map(int,input().split())) arr = sorted(arr) # print(arr) cond,ind = isSum(arr[:-1],sum(arr[:-1]),arr[-1]) # print(cond,ind) if cond: for i in range(n+1): if i != ind: print(arr[i],end=' ') print() elif sum(arr[::-2]) == arr[-2] : for i in range(n+1): print(arr[i],end=' ') print() # print(arr[::-1]) else: print(-1) # print(sum(arr)) ```
instruction
0
65,833
11
131,666
No
output
1
65,833
11
131,667
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a number n and an array b_1, b_2, …, b_{n+2}, obtained according to the following algorithm: * some array a_1, a_2, …, a_n was guessed; * array a was written to array b, i.e. b_i = a_i (1 ≤ i ≤ n); * The (n+1)-th element of the array b is the sum of the numbers in the array a, i.e. b_{n+1} = a_1+a_2+…+a_n; * The (n+2)-th element of the array b was written some number x (1 ≤ x ≤ 10^9), i.e. b_{n+2} = x; The * array b was shuffled. For example, the array b=[2, 3, 7, 12 ,2] it could be obtained in the following ways: * a=[2, 2, 3] and x=12; * a=[3, 2, 7] and x=2. For the given array b, find any array a that could have been guessed initially. Input The first line contains a single integer t (1 ≤ t ≤ 10^4). Then t test cases follow. The first line of each test case contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5). The second row of each test case contains n+2 integers b_1, b_2, …, b_{n+2} (1 ≤ b_i ≤ 10^9). It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case, output: * "-1", if the array b could not be obtained from any array a; * n integers a_1, a_2, …, a_n, otherwise. If there are several arrays of a, you can output any. Example Input 4 3 2 3 7 12 2 4 9 1 7 1 6 5 5 18 2 2 3 2 9 2 3 2 6 9 2 1 Output 2 3 7 -1 2 2 2 3 9 1 2 6 Submitted Solution: ``` import sys input=sys.stdin.buffer.readline for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) a.sort() if sum(a[:n])==a[n+1]: for i in range(n): print(a[i],end=' ') continue sum_a=sum(a[:n+1]) b=[] flag=0 for i in range(n+1): if sum_a-a[i]==max(a): b=a[:i]+a[i+1:n+2] flag=1 break if flag==1: for i in range(n): print(b[i],end=' ') else: print(-1) print() ```
instruction
0
65,834
11
131,668
No
output
1
65,834
11
131,669
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness. Input The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Examples Input 5 2 4 7 8 10 Output 3 Input 4 1 2 1 1 Output 2 Submitted Solution: ``` a=int(input()) n=list(map(int,input().split())) chet=0 nechet=0 for i in n: if i%2==0: chet+=1 else: nechet+=1 if chet>nechet: for i in n: if i%2!=0: print(n.index(i)+1) else: for i in n: if i%2==0: print(n.index(i)+1) ```
instruction
0
65,879
11
131,758
Yes
output
1
65,879
11
131,759
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness. Input The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Examples Input 5 2 4 7 8 10 Output 3 Input 4 1 2 1 1 Output 2 Submitted Solution: ``` n=int(input()) l=[int(x) for x in input().split()] e=0 o=0 for x in l: if x%2==0: e+=1 else: o+=1 if e==1: for x in l: if x%2==0: print(l.index(x)+1) break else: for x in l: if x%2!=0: print(l.index(x)+1) break ```
instruction
0
65,880
11
131,760
Yes
output
1
65,880
11
131,761
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness. Input The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Examples Input 5 2 4 7 8 10 Output 3 Input 4 1 2 1 1 Output 2 Submitted Solution: ``` def _25A(numbers): modulus = list(map(lambda x: x % 2, numbers)) if modulus.count(1) >1: return(modulus.index(0) + 1) else: return(modulus.index(1) + 1) input() print(_25A(list(map(lambda x: int(x), input().split())))) ```
instruction
0
65,881
11
131,762
Yes
output
1
65,881
11
131,763
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness. Input The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Examples Input 5 2 4 7 8 10 Output 3 Input 4 1 2 1 1 Output 2 Submitted Solution: ``` n=int(input()) number=list(map(int,input().split())) even=0;odd=0 for i in range(n): if int(number[i]/2)*2==number[i]: even+=1 else: odd+=1 if odd==1: for i in range(n): if int(number[i]/2)*2!=number[i]: print(i+1) elif even==1: for i in range(n): if int(number[i]/2)*2==number[i]: print(i+1) ```
instruction
0
65,882
11
131,764
Yes
output
1
65,882
11
131,765
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness. Input The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Examples Input 5 2 4 7 8 10 Output 3 Input 4 1 2 1 1 Output 2 Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) for i in range(n): if i==0 and a[i]%2!=a[i+1]%2 and a[i]%2!=a[i+2]%2: print(1) elif i==n-1 and a[i]%2!=a[i-1]%2 and a[i]%2!=a[i-2]%2: print(n) elif i!=0 and i!=2 and a[i]%2!=a[i-1]%2 and a[i]%2!=a[i+1]%2: print(i+1) ```
instruction
0
65,883
11
131,766
No
output
1
65,883
11
131,767
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness. Input The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Examples Input 5 2 4 7 8 10 Output 3 Input 4 1 2 1 1 Output 2 Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) o,e=[],[] for i in range(n): if a[i]%2==0: e.append(i) else: o.append(i) if len(o)==1: print(o[0]) else: print(e[0]) ```
instruction
0
65,884
11
131,768
No
output
1
65,884
11
131,769
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness. Input The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Examples Input 5 2 4 7 8 10 Output 3 Input 4 1 2 1 1 Output 2 Submitted Solution: ``` input() l = list(map(int,input().split())) e,o=0,0 b = False for pos,i in enumerate(l): if i % 2 == 0: e += 1 else: o += 1 if e > 0 and o > 0: if e > o or o > e: print(pos) b = True if b: break ```
instruction
0
65,885
11
131,770
No
output
1
65,885
11
131,771
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness. Input The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Examples Input 5 2 4 7 8 10 Output 3 Input 4 1 2 1 1 Output 2 Submitted Solution: ``` n=int(input()) l=list(map(int,input().split())) v=-1 for i in range(1,n): for j in range(1,n): if i!=j and abs(l[0]-l[i])==abs(l[0]-l[j]): v=0 break for i in range(n-1): for j in range(n-1): if i!=j and abs(l[-1]-l[i])==abs(l[-1]-l[j]): v=n-1 break for k in range(1,n-1): for i in range(n): for j in range(n): if i!=j and k!=i and k!=j and abs(l[k]-l[i])==abs(l[k]-l[j]): v=k break print(k) ```
instruction
0
65,886
11
131,772
No
output
1
65,886
11
131,773
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Please be sure to use the stream flushing operation after each query's output in order not to leave part of your output in some buffer. For example, in C++ you've got to use the fflush(stdout) function, in Java — call System.out.flush(), and in Pascal — flush(output). Bulls and Cows (also known as Cows and Bulls or Pigs and Bulls or Bulls and Cleots) is an old code-breaking paper and pencil game for two players, predating the similar commercially marketed board game Mastermind. On a sheet of paper, the first player thinks a secret string. This string consists only of digits and has the length 4. The digits in the string must be all different, no two or more equal digits are allowed. Then the second player tries to guess his opponent's string. For every guess the first player gives the number of matches. If the matching digits are on their right positions, they are "bulls", if on different positions, they are "cows". Thus a response is a pair of numbers — the number of "bulls" and the number of "cows". A try can contain equal digits. More formally, let's the secret string is s and the second player are trying to guess it with a string x. The number of "bulls" is a number of such positions i (1 ≤ i ≤ 4) where s[i] = x[i]. The number of "cows" is a number of such digits c that s contains c in the position i (i.e. s[i] = c), x contains c, but x[i] ≠ c. For example, the secret string is "0427", the opponent's try is "0724", then the answer is 2 bulls and 2 cows (the bulls are "0" and "2", the cows are "4" and "7"). If the secret string is "0123", the opponent's try is "0330", then the answer is 1 bull and 1 cow. In this problem you are to guess the string s that the system has chosen. You only know that the chosen string consists of 4 distinct digits. You can make queries to the testing system, each query is the output of a single 4-digit string. The answer to the query is the number of bulls and number of cows. If the system's response equals "4 0", that means the interaction with your problem is over and the program must terminate. That is possible for two reasons — the program either guessed the number x or made an invalid action (for example, printed letters instead of digits). Your program is allowed to do at most 50 queries. You can hack solutions of other participants providing a 4-digit string containing distinct digits — the secret string. Input To read answers to the queries, the program must use the standard input. The program will receive pairs of non-negative integers in the input, one pair per line. The first number in a pair is a number of bulls and the second one is a number of cows of the string s and the string xi printed by your program. If the system response equals "4 0", then your solution should terminate. The testing system will let your program read the i-th pair of integers from the input only after your program displays the corresponding system query in the output: prints value xi in a single line and executes operation flush. Output The program must use the standard output to print queries. Your program must output requests — 4-digit strings x1, x2, ..., one per line. After the output of each line the program must execute flush operation. The program should read the answer to the query from the standard input. Your program is allowed to do at most 50 queries. Examples Input 0 1 2 0 1 1 0 4 2 1 4 0 Output 8000 0179 3159 3210 0112 0123 Note The secret string s in the example is "0123". Submitted Solution: ``` import itertools def get_all_possibilities(nums): return [x for x in itertools.permutations(nums)] def guess_dec(): """ We can bruteforce this game by trying out all the possible guesses. In the worst case, there will be 26 guesses. In the best case, there will be 11 guesses. First, we make use of the secret digits being "distinct" digis. We can use identical digits per guess(e.g. "0000", "1111", etc) to identify all four distict digits. Once we have all the "cows", we can try out all the possible combinations of four digits which is 16. So in total, we can guess the correct combination in 11 guesses if lucky. If unlucky, we have to consume all 16 possibilities of combinations. """ secret_numbers = [] try_outs = [] counter = 0 first_time = True def inner(bulls, cows): nonlocal counter, try_outs, secret_numbers, first_time if bulls > 0: secret_numbers.append(counter - 1) if counter < 10: guess = str(counter) * 4 counter += 1 return guess # now we have all four digits if first_time: try_outs = get_all_possibilities(secret_numbers) first_time = False if len(try_outs) > 0: return try_outs.pop() return inner def main(): bulls = 0 cows = 0 guess = guess_dec() for _ in range(50): print(guess(bulls, cows)) answer = input() b, c = answer.split() bulls = int(b) cows = int(c) if bulls == 4 and cows == 0: break if __name__ == '__main__': main() ```
instruction
0
66,083
11
132,166
No
output
1
66,083
11
132,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Please be sure to use the stream flushing operation after each query's output in order not to leave part of your output in some buffer. For example, in C++ you've got to use the fflush(stdout) function, in Java — call System.out.flush(), and in Pascal — flush(output). Bulls and Cows (also known as Cows and Bulls or Pigs and Bulls or Bulls and Cleots) is an old code-breaking paper and pencil game for two players, predating the similar commercially marketed board game Mastermind. On a sheet of paper, the first player thinks a secret string. This string consists only of digits and has the length 4. The digits in the string must be all different, no two or more equal digits are allowed. Then the second player tries to guess his opponent's string. For every guess the first player gives the number of matches. If the matching digits are on their right positions, they are "bulls", if on different positions, they are "cows". Thus a response is a pair of numbers — the number of "bulls" and the number of "cows". A try can contain equal digits. More formally, let's the secret string is s and the second player are trying to guess it with a string x. The number of "bulls" is a number of such positions i (1 ≤ i ≤ 4) where s[i] = x[i]. The number of "cows" is a number of such digits c that s contains c in the position i (i.e. s[i] = c), x contains c, but x[i] ≠ c. For example, the secret string is "0427", the opponent's try is "0724", then the answer is 2 bulls and 2 cows (the bulls are "0" and "2", the cows are "4" and "7"). If the secret string is "0123", the opponent's try is "0330", then the answer is 1 bull and 1 cow. In this problem you are to guess the string s that the system has chosen. You only know that the chosen string consists of 4 distinct digits. You can make queries to the testing system, each query is the output of a single 4-digit string. The answer to the query is the number of bulls and number of cows. If the system's response equals "4 0", that means the interaction with your problem is over and the program must terminate. That is possible for two reasons — the program either guessed the number x or made an invalid action (for example, printed letters instead of digits). Your program is allowed to do at most 50 queries. You can hack solutions of other participants providing a 4-digit string containing distinct digits — the secret string. Input To read answers to the queries, the program must use the standard input. The program will receive pairs of non-negative integers in the input, one pair per line. The first number in a pair is a number of bulls and the second one is a number of cows of the string s and the string xi printed by your program. If the system response equals "4 0", then your solution should terminate. The testing system will let your program read the i-th pair of integers from the input only after your program displays the corresponding system query in the output: prints value xi in a single line and executes operation flush. Output The program must use the standard output to print queries. Your program must output requests — 4-digit strings x1, x2, ..., one per line. After the output of each line the program must execute flush operation. The program should read the answer to the query from the standard input. Your program is allowed to do at most 50 queries. Examples Input 0 1 2 0 1 1 0 4 2 1 4 0 Output 8000 0179 3159 3210 0112 0123 Note The secret string s in the example is "0123". Submitted Solution: ``` while True: print('abcd') ```
instruction
0
66,084
11
132,168
No
output
1
66,084
11
132,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Please be sure to use the stream flushing operation after each query's output in order not to leave part of your output in some buffer. For example, in C++ you've got to use the fflush(stdout) function, in Java — call System.out.flush(), and in Pascal — flush(output). Bulls and Cows (also known as Cows and Bulls or Pigs and Bulls or Bulls and Cleots) is an old code-breaking paper and pencil game for two players, predating the similar commercially marketed board game Mastermind. On a sheet of paper, the first player thinks a secret string. This string consists only of digits and has the length 4. The digits in the string must be all different, no two or more equal digits are allowed. Then the second player tries to guess his opponent's string. For every guess the first player gives the number of matches. If the matching digits are on their right positions, they are "bulls", if on different positions, they are "cows". Thus a response is a pair of numbers — the number of "bulls" and the number of "cows". A try can contain equal digits. More formally, let's the secret string is s and the second player are trying to guess it with a string x. The number of "bulls" is a number of such positions i (1 ≤ i ≤ 4) where s[i] = x[i]. The number of "cows" is a number of such digits c that s contains c in the position i (i.e. s[i] = c), x contains c, but x[i] ≠ c. For example, the secret string is "0427", the opponent's try is "0724", then the answer is 2 bulls and 2 cows (the bulls are "0" and "2", the cows are "4" and "7"). If the secret string is "0123", the opponent's try is "0330", then the answer is 1 bull and 1 cow. In this problem you are to guess the string s that the system has chosen. You only know that the chosen string consists of 4 distinct digits. You can make queries to the testing system, each query is the output of a single 4-digit string. The answer to the query is the number of bulls and number of cows. If the system's response equals "4 0", that means the interaction with your problem is over and the program must terminate. That is possible for two reasons — the program either guessed the number x or made an invalid action (for example, printed letters instead of digits). Your program is allowed to do at most 50 queries. You can hack solutions of other participants providing a 4-digit string containing distinct digits — the secret string. Input To read answers to the queries, the program must use the standard input. The program will receive pairs of non-negative integers in the input, one pair per line. The first number in a pair is a number of bulls and the second one is a number of cows of the string s and the string xi printed by your program. If the system response equals "4 0", then your solution should terminate. The testing system will let your program read the i-th pair of integers from the input only after your program displays the corresponding system query in the output: prints value xi in a single line and executes operation flush. Output The program must use the standard output to print queries. Your program must output requests — 4-digit strings x1, x2, ..., one per line. After the output of each line the program must execute flush operation. The program should read the answer to the query from the standard input. Your program is allowed to do at most 50 queries. Examples Input 0 1 2 0 1 1 0 4 2 1 4 0 Output 8000 0179 3159 3210 0112 0123 Note The secret string s in the example is "0123". Submitted Solution: ``` from itertools import permutations from random import shuffle try: raw_input except: raw_input = input try: from itertools import izip except: izip = zip digits = '0123456789' size = 4 def parse_score(score): score = score.strip().split() return tuple(int(s.strip()) for s in score) def scorecalc(guess, chosen): bulls = cows = 0 for g,c in izip(guess, chosen): if g == c: bulls += 1 elif g in chosen: cows += 1 return bulls, cows choices = list(permutations(digits, size)) shuffle(choices) answers = [] scores = [] while True: ans = choices[0] answers.append(ans) #print ("(Narrowed to %i possibilities)" % len(choices)) score = raw_input("%*s\n" % (size, ''.join(ans))) score = parse_score(score) scores.append(score) #print("Bulls: %i, Cows: %i" % score) found = score == (size, 0) if found: break choices = [c for c in choices if scorecalc(c, ans) == score] if not choices: print ("Bad scoring? nothing fits those scores you gave:") print (' ' + '\n '.join("%s -> %s" % (''.join(an),sc) for an,sc in izip(answers, scores))) break ```
instruction
0
66,085
11
132,170
No
output
1
66,085
11
132,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Please be sure to use the stream flushing operation after each query's output in order not to leave part of your output in some buffer. For example, in C++ you've got to use the fflush(stdout) function, in Java — call System.out.flush(), and in Pascal — flush(output). Bulls and Cows (also known as Cows and Bulls or Pigs and Bulls or Bulls and Cleots) is an old code-breaking paper and pencil game for two players, predating the similar commercially marketed board game Mastermind. On a sheet of paper, the first player thinks a secret string. This string consists only of digits and has the length 4. The digits in the string must be all different, no two or more equal digits are allowed. Then the second player tries to guess his opponent's string. For every guess the first player gives the number of matches. If the matching digits are on their right positions, they are "bulls", if on different positions, they are "cows". Thus a response is a pair of numbers — the number of "bulls" and the number of "cows". A try can contain equal digits. More formally, let's the secret string is s and the second player are trying to guess it with a string x. The number of "bulls" is a number of such positions i (1 ≤ i ≤ 4) where s[i] = x[i]. The number of "cows" is a number of such digits c that s contains c in the position i (i.e. s[i] = c), x contains c, but x[i] ≠ c. For example, the secret string is "0427", the opponent's try is "0724", then the answer is 2 bulls and 2 cows (the bulls are "0" and "2", the cows are "4" and "7"). If the secret string is "0123", the opponent's try is "0330", then the answer is 1 bull and 1 cow. In this problem you are to guess the string s that the system has chosen. You only know that the chosen string consists of 4 distinct digits. You can make queries to the testing system, each query is the output of a single 4-digit string. The answer to the query is the number of bulls and number of cows. If the system's response equals "4 0", that means the interaction with your problem is over and the program must terminate. That is possible for two reasons — the program either guessed the number x or made an invalid action (for example, printed letters instead of digits). Your program is allowed to do at most 50 queries. You can hack solutions of other participants providing a 4-digit string containing distinct digits — the secret string. Input To read answers to the queries, the program must use the standard input. The program will receive pairs of non-negative integers in the input, one pair per line. The first number in a pair is a number of bulls and the second one is a number of cows of the string s and the string xi printed by your program. If the system response equals "4 0", then your solution should terminate. The testing system will let your program read the i-th pair of integers from the input only after your program displays the corresponding system query in the output: prints value xi in a single line and executes operation flush. Output The program must use the standard output to print queries. Your program must output requests — 4-digit strings x1, x2, ..., one per line. After the output of each line the program must execute flush operation. The program should read the answer to the query from the standard input. Your program is allowed to do at most 50 queries. Examples Input 0 1 2 0 1 1 0 4 2 1 4 0 Output 8000 0179 3159 3210 0112 0123 Note The secret string s in the example is "0123". Submitted Solution: ``` s="0123" from itertools import permutations perm = permutations(s) for i in perm: s="" for j in i: s+=j print(s) a,b=input().split() a=int(a) if(a==4): print(s) break # print(i) ```
instruction
0
66,086
11
132,172
No
output
1
66,086
11
132,173
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game? Constraints * 1≤N≤100000 * 1≤A_i≤1000000000(=10^9) * All input values are integers. Input Input is given from Standard Input in the following format: N A_1 : A_N Output Print how many numbers will be written on the sheet at the end of the game. Examples Input 3 6 2 6 Output 1 Input 4 2 5 5 2 Output 0 Input 6 12 22 16 22 18 12 Output 2 Submitted Solution: ``` dic={} for _ in range(int(input())): a=int(input()) if a in dic: dic[a]=1-dic[a] else: dic[a]=1 print(sum(dic.values())) ```
instruction
0
66,330
11
132,660
Yes
output
1
66,330
11
132,661
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game? Constraints * 1≤N≤100000 * 1≤A_i≤1000000000(=10^9) * All input values are integers. Input Input is given from Standard Input in the following format: N A_1 : A_N Output Print how many numbers will be written on the sheet at the end of the game. Examples Input 3 6 2 6 Output 1 Input 4 2 5 5 2 Output 0 Input 6 12 22 16 22 18 12 Output 2 Submitted Solution: ``` n=int(input()) se=set() for _ in range(n): a=int(input()) if a in se:se.discard(a) else:se.add(a) print(len(se)) ```
instruction
0
66,331
11
132,662
Yes
output
1
66,331
11
132,663
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game? Constraints * 1≤N≤100000 * 1≤A_i≤1000000000(=10^9) * All input values are integers. Input Input is given from Standard Input in the following format: N A_1 : A_N Output Print how many numbers will be written on the sheet at the end of the game. Examples Input 3 6 2 6 Output 1 Input 4 2 5 5 2 Output 0 Input 6 12 22 16 22 18 12 Output 2 Submitted Solution: ``` x=int(input()) a=[] B={-1} for i in range(x): Y=int(input()) if Y not in B: B.add(Y) else: B.discard(Y) print(len(B)-1) ```
instruction
0
66,332
11
132,664
Yes
output
1
66,332
11
132,665
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game? Constraints * 1≤N≤100000 * 1≤A_i≤1000000000(=10^9) * All input values are integers. Input Input is given from Standard Input in the following format: N A_1 : A_N Output Print how many numbers will be written on the sheet at the end of the game. Examples Input 3 6 2 6 Output 1 Input 4 2 5 5 2 Output 0 Input 6 12 22 16 22 18 12 Output 2 Submitted Solution: ``` from collections import Counter N = int(input()) A = [int(input()) for _ in range(N)] print(sum([vi % 2 for vi in Counter(A).values()])) ```
instruction
0
66,333
11
132,666
Yes
output
1
66,333
11
132,667
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game? Constraints * 1≤N≤100000 * 1≤A_i≤1000000000(=10^9) * All input values are integers. Input Input is given from Standard Input in the following format: N A_1 : A_N Output Print how many numbers will be written on the sheet at the end of the game. Examples Input 3 6 2 6 Output 1 Input 4 2 5 5 2 Output 0 Input 6 12 22 16 22 18 12 Output 2 Submitted Solution: ``` n=int(input()) list=[] ans=0 for i in range(n): a=int(input()) list.append(a) for i in range(n): if list.count(list[i])%2!=0: ans+=1 print(ans) ```
instruction
0
66,334
11
132,668
No
output
1
66,334
11
132,669
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game? Constraints * 1≤N≤100000 * 1≤A_i≤1000000000(=10^9) * All input values are integers. Input Input is given from Standard Input in the following format: N A_1 : A_N Output Print how many numbers will be written on the sheet at the end of the game. Examples Input 3 6 2 6 Output 1 Input 4 2 5 5 2 Output 0 Input 6 12 22 16 22 18 12 Output 2 Submitted Solution: ``` n=int(input()) S=set() for i in range(n): S=S^set([int(input())]) print(len(S)) ```
instruction
0
66,335
11
132,670
No
output
1
66,335
11
132,671
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game? Constraints * 1≤N≤100000 * 1≤A_i≤1000000000(=10^9) * All input values are integers. Input Input is given from Standard Input in the following format: N A_1 : A_N Output Print how many numbers will be written on the sheet at the end of the game. Examples Input 3 6 2 6 Output 1 Input 4 2 5 5 2 Output 0 Input 6 12 22 16 22 18 12 Output 2 Submitted Solution: ``` import sys input = sys.stdin.readline N=int(input()) count=0 for _ in range(n): a=[int(input())] for x in a: if a.count(x)%2==1: count+=1 print(count) ```
instruction
0
66,336
11
132,672
No
output
1
66,336
11
132,673
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game? Constraints * 1≤N≤100000 * 1≤A_i≤1000000000(=10^9) * All input values are integers. Input Input is given from Standard Input in the following format: N A_1 : A_N Output Print how many numbers will be written on the sheet at the end of the game. Examples Input 3 6 2 6 Output 1 Input 4 2 5 5 2 Output 0 Input 6 12 22 16 22 18 12 Output 2 Submitted Solution: ``` import numpy as np n = int(input()) num = np.zeros(10 ** 9, dtype = bool) for i in range(n): a = int(input()) num[a] = not(num[a]) sum = np.where(num == True) print(len(sum[0])) ```
instruction
0
66,337
11
132,674
No
output
1
66,337
11
132,675
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Example Input 0 3 1 7 5 9 8 6 4 2 7 0 9 2 1 5 4 8 6 3 4 2 0 6 8 7 1 3 5 9 1 7 5 0 9 8 3 4 2 6 6 1 2 3 0 4 5 9 7 8 3 6 7 4 2 0 9 5 8 1 5 8 6 9 7 2 0 1 3 4 8 9 4 5 3 6 2 0 1 7 9 4 3 8 6 1 7 2 0 5 2 5 8 1 4 3 6 7 9 0 Output 0 Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] while True: a = [LI() for _ in range(10)] sm = {} for i in range(10**4): c = 0 t = 10**3 while t > 0: k = i // t % 10 c = a[c][k] t //= 10 sm[i] = c e = collections.defaultdict(set) for i in range(10): for j in range(10): for k in range(10): for l in range(10): t = i * 1000 + j * 100 + k * 10 + l for m in range(10): if i != m: u = m * 1000 + j * 100 + k * 10 + l e[t].add(u) if j != m: u = i * 1000 + m * 100 + k * 10 + l e[t].add(u) if k != m: u = i * 1000 + j * 100 + m * 10 + l e[t].add(u) if l != m: u = i * 1000 + j * 100 + k * 10 + m e[t].add(u) if i != j: u = j * 1000 + i * 100 + k * 10 + l e[t].add(u) if j != k: u = i * 1000 + k * 100 + j * 10 + l e[t].add(u) if k != l: u = i * 1000 + j * 100 + l * 10 + k e[t].add(u) r = 0 for i in range(10**4): t = sm[i] if i % 10 != t and sm[i - i % 10 + t] == i % 10: r += 1 continue for k in e[i]: if sm[k] == t: r += 1 break rr.append(r) break return '\n'.join(map(str, rr)) print(main()) ```
instruction
0
66,409
11
132,818
No
output
1
66,409
11
132,819
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Example Input 0 3 1 7 5 9 8 6 4 2 7 0 9 2 1 5 4 8 6 3 4 2 0 6 8 7 1 3 5 9 1 7 5 0 9 8 3 4 2 6 6 1 2 3 0 4 5 9 7 8 3 6 7 4 2 0 9 5 8 1 5 8 6 9 7 2 0 1 3 4 8 9 4 5 3 6 2 0 1 7 9 4 3 8 6 1 7 2 0 5 2 5 8 1 4 3 6 7 9 0 Output 0 Submitted Solution: ``` import copy T = [[int(x) for x in input().split()] for i in range(10)] def E(ID): if len(ID)!=4: print(len(ID)) ret = 0 for d in ID: d =int(d) ret = T[ret][d] return ret def solve(ID): e = E(ID) for i in range(4): for j in range(10): kari = copy.deepcopy(ID) if kari[i] == str(j): continue kari[i] = str(j) if E(kari) == e: # print(kari,ID) return 1 for i in range(3): kari = copy.deepcopy(ID) if kari[i] == kari[i+1]: continue kari[i],kari[i+1] =kari[i+1],kari[i] if E(kari) == e: # print(kari,ID) return 1 if E(ID[:3]+[str(e)]) == int(ID[3]) and int(ID[3])!=e: return 1 return 0 ans = 0 for i in range(10000): ID =[j for j in str(i)] ID = ['0']*(4-len(ID)) + ID ans += solve(ID) print(ans) ```
instruction
0
66,410
11
132,820
No
output
1
66,410
11
132,821
Provide tags and a correct Python 3 solution for this coding contest problem. An online contest will soon be held on ForceCoders, a large competitive programming platform. The authors have prepared n problems; and since the platform is very popular, 998244351 coder from all over the world is going to solve them. For each problem, the authors estimated the number of people who would solve it: for the i-th problem, the number of accepted solutions will be between l_i and r_i, inclusive. The creator of ForceCoders uses different criteria to determine if the contest is good or bad. One of these criteria is the number of inversions in the problem order. An inversion is a pair of problems (x, y) such that x is located earlier in the contest (x < y), but the number of accepted solutions for y is strictly greater. Obviously, both the creator of ForceCoders and the authors of the contest want the contest to be good. Now they want to calculate the probability that there will be no inversions in the problem order, assuming that for each problem i, any integral number of accepted solutions for it (between l_i and r_i) is equally probable, and all these numbers are independent. Input The first line contains one integer n (2 ≤ n ≤ 50) — the number of problems in the contest. Then n lines follow, the i-th line contains two integers l_i and r_i (0 ≤ l_i ≤ r_i ≤ 998244351) — the minimum and maximum number of accepted solutions for the i-th problem, respectively. Output The probability that there will be no inversions in the contest can be expressed as an irreducible fraction x/y, where y is coprime with 998244353. Print one integer — the value of xy^{-1}, taken modulo 998244353, where y^{-1} is an integer such that yy^{-1} ≡ 1 (mod 998244353). Examples Input 3 1 2 1 2 1 2 Output 499122177 Input 2 42 1337 13 420 Output 578894053 Input 2 1 1 0 0 Output 1 Input 2 1 1 1 1 Output 1 Note The real answer in the first test is 1/2.
instruction
0
66,564
11
133,128
Tags: combinatorics, dp, probabilities Correct Solution: ``` import sys input = sys.stdin.readline mod=998244353 n=int(input()) LR=[list(map(int,input().split())) for i in range(n)] RMIN=1<<31 ALL=1 for l,r in LR: ALL=ALL*pow(r-l+1,mod-2,mod)%mod for i in range(n): if LR[i][1]>RMIN: LR[i][1]=RMIN RMIN=min(RMIN,LR[i][1]) LMAX=-1 for i in range(n-1,-1,-1): if LR[i][0]<LMAX: LR[i][0]=LMAX LMAX=max(LMAX,LR[i][0]) compression=[] for l,r in LR: compression.append(l) compression.append(r+1) compression=sorted(set(compression)) co_dict={a:ind for ind,a in enumerate(compression)} LEN=len(compression)-1 if LEN==0: print(0) sys.exit() DP=[[0]*LEN for i in range(n)] for i in range(co_dict[LR[0][0]],co_dict[LR[0][1]+1]): x=compression[i+1]-compression[i] now=x #print(i,x) for j in range(n): if LR[j][0]<=compression[i] and LR[j][1]+1>=compression[i+1]: DP[j][i]=now else: break now=now*(x+j+1)*pow(j+2,mod-2,mod)%mod #print(DP) for i in range(1,n): SUM=DP[i-1][LEN-1] #print(DP) for j in range(LEN-2,-1,-1): if LR[i][0]<=compression[j] and LR[i][1]+1>=compression[j+1]: x=SUM*(compression[j+1]-compression[j])%mod now=x t=compression[j+1]-compression[j] #print(x,t) for k in range(i,n): if LR[k][0]<=compression[j] and LR[k][1]+1>=compression[j+1]: DP[k][j]=(DP[k][j]+now)%mod else: break now=now*(t+k-i+1)*pow(k-i+2,mod-2,mod)%mod SUM+=DP[i-1][j] print(sum(DP[-1])*ALL%mod) ```
output
1
66,564
11
133,129