message
stringlengths
2
44.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
42
109k
cluster
float64
5
5
__index_level_0__
int64
84
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30 Submitted Solution: ``` n=int(input()) *a,=map(int, input().split()) def gcd(a,b): while b: a,b=b,a%b return a def lcm(a,b): return a*b//gcd(a,b) ans = 1 for ai in a: ans = lcm(ans, ai) print(ans) ```
instruction
0
87,518
5
175,036
Yes
output
1
87,518
5
175,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30 Submitted Solution: ``` import math def LCM(x, y): return (x * y) // math.gcd(x, y) n = int(input()) a = list(map(int,input().split())) lcm = 1 for ai in a: lcm =LCM(ai,lcm) print(lcm) ```
instruction
0
87,519
5
175,038
Yes
output
1
87,519
5
175,039
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30 Submitted Solution: ``` from functools import reduce def gcd(a, b): while b: a, b = b, a % b return a def lcm(x, y): # saisyou koubaisuu return (x * y) // gcd(x, y) def lcm_list(numbers): return reduce(lcm, numbers) n = int(input()) a = list(map(int, input().split())) print(lcm_list(a)) ```
instruction
0
87,520
5
175,040
Yes
output
1
87,520
5
175,041
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30 Submitted Solution: ``` #!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 4 1 2 3 5 output: 30 """ import sys import math from functools import reduce def gcd(x, y): if x < y: x, y = y, x while y > 0: r = x % y x = y y = r return x def lcm(a, b): return a * b // math.gcd(a, b) def solve(_n_list): return reduce(lcm, _n_list) if __name__ == '__main__': _input = sys.stdin.readlines() cnt = int(_input[0]) n_list = tuple(map(int, _input[1].split())) print(solve(n_list)) ```
instruction
0
87,521
5
175,042
No
output
1
87,521
5
175,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30 Submitted Solution: ``` def GCD(x,y): r = x%y if r == 0: return y else: return GCD(y,r) n = int(input()) list1 = list(map(int,input().split())) result = list1[0] for i in list1[1:]: result = result*i/GCD(i,result) print(result) ```
instruction
0
87,522
5
175,044
No
output
1
87,522
5
175,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30 Submitted Solution: ``` import numpy ```
instruction
0
87,523
5
175,046
No
output
1
87,523
5
175,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of the given integers in a line. Examples Input 3 3 4 6 Output 12 Input 4 1 2 3 5 Output 30 Submitted Solution: ``` from math import sqrt, floor from collections import deque from functools import reduce from operator import mul def divide(p): global a, lcm, limit c, d, f = a.copy(), set(), False while True: b = set(i for i in c if not (i % p)) d |= c - b b = set(i // p for i in b) if not b: a = d break lcm.append(p) c = b f = True if f: limit = floor(sqrt(max(c))) n, a = int(input()), set(map(int, input().split())) p, lcm, limit = 3, deque(), floor(sqrt(max(a))) divide(2) while p <= limit: divide(p) p += 2 print(reduce(mul, lcm, 1) * reduce(mul, a, 1)) ```
instruction
0
87,524
5
175,048
No
output
1
87,524
5
175,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two matrices A and B. Each matrix contains exactly n rows and m columns. Each element of A is either 0 or 1; each element of B is initially 0. You may perform some operations with matrix B. During each operation, you choose any submatrix of B having size 2 × 2, and replace every element in the chosen submatrix with 1. In other words, you choose two integers x and y such that 1 ≤ x < n and 1 ≤ y < m, and then set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1. Your goal is to make matrix B equal to matrix A. Two matrices A and B are equal if and only if every element of matrix A is equal to the corresponding element of matrix B. Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes B equal to A. Note that you don't have to minimize the number of operations. Input The first line contains two integers n and m (2 ≤ n, m ≤ 50). Then n lines follow, each containing m integers. The j-th integer in the i-th line is A_{i, j}. Each integer is either 0 or 1. Output If it is impossible to make B equal to A, print one integer -1. Otherwise, print any sequence of operations that transforms B into A in the following format: the first line should contain one integer k — the number of operations, and then k lines should follow, each line containing two integers x and y for the corresponding operation (set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1). The condition 0 ≤ k ≤ 2500 should hold. Examples Input 3 3 1 1 1 1 1 1 0 1 1 Output 3 1 1 1 2 2 2 Input 3 3 1 0 1 1 0 1 0 0 0 Output -1 Input 3 2 0 0 0 0 0 0 Output 0 Note The sequence of operations in the first example: \begin{matrix} 0 & 0 & 0 & & 1 & 1 & 0 & & 1 & 1 & 1 & & 1 & 1 & 1 \\\ 0 & 0 & 0 & → & 1 & 1 & 0 & → & 1 & 1 & 1 & → & 1 & 1 & 1 \\\ 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 1 & 1 \end{matrix} Submitted Solution: ``` import sys input = sys.stdin.readline n, m = map(int, input().split()) mat = [] for _ in range(n): mat.append([int(i) for i in input().split()]) b = [[0 for _ in range(m)] for _ in range(n)] ans = [] for i in range(n - 1): for j in range(m - 1): if mat[i][j] == mat[i+1][j] == mat[i][j+1] == mat[i+1][j+1] == 1: b[i][j] = b[i+1][j] = b[i][j+1] = b[i+1][j+1] = 1 ans.append((i, j)) if mat == b: print(len(ans)) for (i,j) in ans: print(i+1, j+1) else: print(-1) ```
instruction
0
87,645
5
175,290
Yes
output
1
87,645
5
175,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two matrices A and B. Each matrix contains exactly n rows and m columns. Each element of A is either 0 or 1; each element of B is initially 0. You may perform some operations with matrix B. During each operation, you choose any submatrix of B having size 2 × 2, and replace every element in the chosen submatrix with 1. In other words, you choose two integers x and y such that 1 ≤ x < n and 1 ≤ y < m, and then set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1. Your goal is to make matrix B equal to matrix A. Two matrices A and B are equal if and only if every element of matrix A is equal to the corresponding element of matrix B. Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes B equal to A. Note that you don't have to minimize the number of operations. Input The first line contains two integers n and m (2 ≤ n, m ≤ 50). Then n lines follow, each containing m integers. The j-th integer in the i-th line is A_{i, j}. Each integer is either 0 or 1. Output If it is impossible to make B equal to A, print one integer -1. Otherwise, print any sequence of operations that transforms B into A in the following format: the first line should contain one integer k — the number of operations, and then k lines should follow, each line containing two integers x and y for the corresponding operation (set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1). The condition 0 ≤ k ≤ 2500 should hold. Examples Input 3 3 1 1 1 1 1 1 0 1 1 Output 3 1 1 1 2 2 2 Input 3 3 1 0 1 1 0 1 0 0 0 Output -1 Input 3 2 0 0 0 0 0 0 Output 0 Note The sequence of operations in the first example: \begin{matrix} 0 & 0 & 0 & & 1 & 1 & 0 & & 1 & 1 & 1 & & 1 & 1 & 1 \\\ 0 & 0 & 0 & → & 1 & 1 & 0 & → & 1 & 1 & 1 & → & 1 & 1 & 1 \\\ 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 1 & 1 \end{matrix} Submitted Solution: ``` from copy import copy, deepcopy def operation(B, i, j): B[i][j] = 1 B[i+1][j] = 1 B[i][j+1] = 1 B[i+1][j+1] = 1 def compare(A, i, j): if (A[i][j] == 1 and A[i+1][j] == 1 and A[i][j+1] == 1 and A[i+1][j+1] == 1): return True else: return False n, m = input().split(' ') n, m = int(n), int(m) A = [] B = [[0 for _ in range(m)] for _ in range(n)] n2 = n while(n2): A.append([int(x) for x in input().split(' ')]) n2 -= 1 op = 0 res = [] i = 0 j = 0 while(i < n-1): j = 0 while(j < m-1): if compare(A, i, j): operation(B, i, j) op += 1 res.append([i+1, j+1]) j += 1 i += 1 if A == B: print(op) for i in res: print(*i) else: print(-1) ```
instruction
0
87,646
5
175,292
Yes
output
1
87,646
5
175,293
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two matrices A and B. Each matrix contains exactly n rows and m columns. Each element of A is either 0 or 1; each element of B is initially 0. You may perform some operations with matrix B. During each operation, you choose any submatrix of B having size 2 × 2, and replace every element in the chosen submatrix with 1. In other words, you choose two integers x and y such that 1 ≤ x < n and 1 ≤ y < m, and then set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1. Your goal is to make matrix B equal to matrix A. Two matrices A and B are equal if and only if every element of matrix A is equal to the corresponding element of matrix B. Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes B equal to A. Note that you don't have to minimize the number of operations. Input The first line contains two integers n and m (2 ≤ n, m ≤ 50). Then n lines follow, each containing m integers. The j-th integer in the i-th line is A_{i, j}. Each integer is either 0 or 1. Output If it is impossible to make B equal to A, print one integer -1. Otherwise, print any sequence of operations that transforms B into A in the following format: the first line should contain one integer k — the number of operations, and then k lines should follow, each line containing two integers x and y for the corresponding operation (set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1). The condition 0 ≤ k ≤ 2500 should hold. Examples Input 3 3 1 1 1 1 1 1 0 1 1 Output 3 1 1 1 2 2 2 Input 3 3 1 0 1 1 0 1 0 0 0 Output -1 Input 3 2 0 0 0 0 0 0 Output 0 Note The sequence of operations in the first example: \begin{matrix} 0 & 0 & 0 & & 1 & 1 & 0 & & 1 & 1 & 1 & & 1 & 1 & 1 \\\ 0 & 0 & 0 & → & 1 & 1 & 0 & → & 1 & 1 & 1 & → & 1 & 1 & 1 \\\ 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 1 & 1 \end{matrix} Submitted Solution: ``` rd = lambda: [int(x) for x in input().split()] n, m = rd() A = [[0] for _ in range(n)] B = [[0 for _ in range(m)] for __ in range(n)] for i in range(n): A[i] = rd() ans = [] for i in range(n - 1): for j in range(m - 1): if A[i][j] and A[i][j + 1] and A[i + 1][j] and A[i + 1][j + 1]: ans += [(i + 1, j + 1)] B[i][j] = B[i][j + 1] = B[i + 1][j] = B[i + 1][j + 1] = 1 if A != B: print(-1) else: print(len(ans)) for i, j in ans: print(i, j) ```
instruction
0
87,647
5
175,294
Yes
output
1
87,647
5
175,295
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two matrices A and B. Each matrix contains exactly n rows and m columns. Each element of A is either 0 or 1; each element of B is initially 0. You may perform some operations with matrix B. During each operation, you choose any submatrix of B having size 2 × 2, and replace every element in the chosen submatrix with 1. In other words, you choose two integers x and y such that 1 ≤ x < n and 1 ≤ y < m, and then set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1. Your goal is to make matrix B equal to matrix A. Two matrices A and B are equal if and only if every element of matrix A is equal to the corresponding element of matrix B. Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes B equal to A. Note that you don't have to minimize the number of operations. Input The first line contains two integers n and m (2 ≤ n, m ≤ 50). Then n lines follow, each containing m integers. The j-th integer in the i-th line is A_{i, j}. Each integer is either 0 or 1. Output If it is impossible to make B equal to A, print one integer -1. Otherwise, print any sequence of operations that transforms B into A in the following format: the first line should contain one integer k — the number of operations, and then k lines should follow, each line containing two integers x and y for the corresponding operation (set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1). The condition 0 ≤ k ≤ 2500 should hold. Examples Input 3 3 1 1 1 1 1 1 0 1 1 Output 3 1 1 1 2 2 2 Input 3 3 1 0 1 1 0 1 0 0 0 Output -1 Input 3 2 0 0 0 0 0 0 Output 0 Note The sequence of operations in the first example: \begin{matrix} 0 & 0 & 0 & & 1 & 1 & 0 & & 1 & 1 & 1 & & 1 & 1 & 1 \\\ 0 & 0 & 0 & → & 1 & 1 & 0 & → & 1 & 1 & 1 & → & 1 & 1 & 1 \\\ 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 1 & 1 \end{matrix} Submitted Solution: ``` n,m=map(int,input().split(" ")) y=[] for i in range(n): c=list(map(int,input().split())) y.append(c) count=[] y1=[[0 for i in range(m)] for j in range(n)] for i in range(1,n): for j in range(1,m): if y[i][j]==1: if y[i-1][j-1]==y[i-1][j]==y[i][j-1]==1: y1[i-1][j-1]=y1[i-1][j]=y1[i][j-1]=y1[i][j]=1 count.append([i,j]) if y==y1: print(len(count)) for i in count: print(i[0],i[1]) else: print(-1) ```
instruction
0
87,648
5
175,296
Yes
output
1
87,648
5
175,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two matrices A and B. Each matrix contains exactly n rows and m columns. Each element of A is either 0 or 1; each element of B is initially 0. You may perform some operations with matrix B. During each operation, you choose any submatrix of B having size 2 × 2, and replace every element in the chosen submatrix with 1. In other words, you choose two integers x and y such that 1 ≤ x < n and 1 ≤ y < m, and then set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1. Your goal is to make matrix B equal to matrix A. Two matrices A and B are equal if and only if every element of matrix A is equal to the corresponding element of matrix B. Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes B equal to A. Note that you don't have to minimize the number of operations. Input The first line contains two integers n and m (2 ≤ n, m ≤ 50). Then n lines follow, each containing m integers. The j-th integer in the i-th line is A_{i, j}. Each integer is either 0 or 1. Output If it is impossible to make B equal to A, print one integer -1. Otherwise, print any sequence of operations that transforms B into A in the following format: the first line should contain one integer k — the number of operations, and then k lines should follow, each line containing two integers x and y for the corresponding operation (set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1). The condition 0 ≤ k ≤ 2500 should hold. Examples Input 3 3 1 1 1 1 1 1 0 1 1 Output 3 1 1 1 2 2 2 Input 3 3 1 0 1 1 0 1 0 0 0 Output -1 Input 3 2 0 0 0 0 0 0 Output 0 Note The sequence of operations in the first example: \begin{matrix} 0 & 0 & 0 & & 1 & 1 & 0 & & 1 & 1 & 1 & & 1 & 1 & 1 \\\ 0 & 0 & 0 & → & 1 & 1 & 0 & → & 1 & 1 & 1 & → & 1 & 1 & 1 \\\ 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 1 & 1 \end{matrix} Submitted Solution: ``` if __name__ == "__main__": dims = input().split(" ") n = int(dims[0]) m = int(dims[1]) matr = [] for i in range(n): row = [] line = input().split(" ") for j in range(m): row.append(int(line[j])) matr.append(row) for index in range(n): matr[index] = [0] + matr[index] + [0] up_down_border = (m + 2) * [0] matr = [up_down_border] + matr + [up_down_border] k = 0 indexes = [] for i in range(1, n): for j in range(1, m): if matr[i][j] == 1: if matr[i + 1][j] == 1 and matr[i][j + 1] == 1 and matr[i + 1][j + 1] == 1: k += 1 indexes.append((i, j)) elif matr[i - 1][j] == 1 and matr[i - 1][j + 1] == 1 and matr[i][j + 1] == 1: continue else: k = -1 break if k == -1: print(-1) else: print(k) for i in range(k): print(indexes[i][0], indexes[i][1]) ```
instruction
0
87,649
5
175,298
No
output
1
87,649
5
175,299
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two matrices A and B. Each matrix contains exactly n rows and m columns. Each element of A is either 0 or 1; each element of B is initially 0. You may perform some operations with matrix B. During each operation, you choose any submatrix of B having size 2 × 2, and replace every element in the chosen submatrix with 1. In other words, you choose two integers x and y such that 1 ≤ x < n and 1 ≤ y < m, and then set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1. Your goal is to make matrix B equal to matrix A. Two matrices A and B are equal if and only if every element of matrix A is equal to the corresponding element of matrix B. Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes B equal to A. Note that you don't have to minimize the number of operations. Input The first line contains two integers n and m (2 ≤ n, m ≤ 50). Then n lines follow, each containing m integers. The j-th integer in the i-th line is A_{i, j}. Each integer is either 0 or 1. Output If it is impossible to make B equal to A, print one integer -1. Otherwise, print any sequence of operations that transforms B into A in the following format: the first line should contain one integer k — the number of operations, and then k lines should follow, each line containing two integers x and y for the corresponding operation (set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1). The condition 0 ≤ k ≤ 2500 should hold. Examples Input 3 3 1 1 1 1 1 1 0 1 1 Output 3 1 1 1 2 2 2 Input 3 3 1 0 1 1 0 1 0 0 0 Output -1 Input 3 2 0 0 0 0 0 0 Output 0 Note The sequence of operations in the first example: \begin{matrix} 0 & 0 & 0 & & 1 & 1 & 0 & & 1 & 1 & 1 & & 1 & 1 & 1 \\\ 0 & 0 & 0 & → & 1 & 1 & 0 & → & 1 & 1 & 1 & → & 1 & 1 & 1 \\\ 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 1 & 1 \end{matrix} Submitted Solution: ``` n, m = map(int, input().split()) ans = [] a = [] count = 0 for gk in range(n): k = list(map(int, input().split())) a.append(k) #b.append(zero) for i in range(n-1): for j in range(m-1): if a[i][j]==1 and a[i][j+1]==1 and a[i+1][j]==1 and a[i+1][j+1]==1: ans.append([i+1, j+1]) if a[i][j]==1: count += 1 if count==0: print(0) elif len(ans)==0: print('-1') else: print(len(ans)) for x in ans: print(" ".join(str(elem) for elem in x)) ```
instruction
0
87,650
5
175,300
No
output
1
87,650
5
175,301
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two matrices A and B. Each matrix contains exactly n rows and m columns. Each element of A is either 0 or 1; each element of B is initially 0. You may perform some operations with matrix B. During each operation, you choose any submatrix of B having size 2 × 2, and replace every element in the chosen submatrix with 1. In other words, you choose two integers x and y such that 1 ≤ x < n and 1 ≤ y < m, and then set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1. Your goal is to make matrix B equal to matrix A. Two matrices A and B are equal if and only if every element of matrix A is equal to the corresponding element of matrix B. Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes B equal to A. Note that you don't have to minimize the number of operations. Input The first line contains two integers n and m (2 ≤ n, m ≤ 50). Then n lines follow, each containing m integers. The j-th integer in the i-th line is A_{i, j}. Each integer is either 0 or 1. Output If it is impossible to make B equal to A, print one integer -1. Otherwise, print any sequence of operations that transforms B into A in the following format: the first line should contain one integer k — the number of operations, and then k lines should follow, each line containing two integers x and y for the corresponding operation (set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1). The condition 0 ≤ k ≤ 2500 should hold. Examples Input 3 3 1 1 1 1 1 1 0 1 1 Output 3 1 1 1 2 2 2 Input 3 3 1 0 1 1 0 1 0 0 0 Output -1 Input 3 2 0 0 0 0 0 0 Output 0 Note The sequence of operations in the first example: \begin{matrix} 0 & 0 & 0 & & 1 & 1 & 0 & & 1 & 1 & 1 & & 1 & 1 & 1 \\\ 0 & 0 & 0 & → & 1 & 1 & 0 & → & 1 & 1 & 1 & → & 1 & 1 & 1 \\\ 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 1 & 1 \end{matrix} Submitted Solution: ``` n, m = map(int, input().split()) arr = list(list(map(int, input().split())) for _ in range(n)) def valid_idx(i, j): return i >= 0 and j >=0 and i < n and j < m def is_full_square(i, j): return valid_idx(i, j) and valid_idx(i+1, j)and valid_idx(i, j+1) and valid_idx(i+1, j+1) and \ arr[i][j] + arr[i+1][j] + arr[i][j+1] + arr[i+1][j+1] == 4 or \ valid_idx(i, j) and valid_idx(i-1, j)and valid_idx(i, j-1) and valid_idx(i-1, j-1) and \ arr[i][j] + arr[i-1][j] + arr[i][j-1] + arr[i-1][j-1] == 4 or \ valid_idx(i, j) and valid_idx(i-1, j)and valid_idx(i, j+1) and valid_idx(i-1, j+1) and \ arr[i][j] + arr[i-1][j] + arr[i][j+1] + arr[i-1][j+1] == 4 or \ valid_idx(i, j) and valid_idx(i+1, j)and valid_idx(i, j-1) and valid_idx(i+1, j-1) and \ arr[i][j] + arr[i+1][j] + arr[i][j-1] + arr[i+1][j-1] == 4 def is_valid(): for i in range(n): for j in range(m): if arr[i][j] == 0: if arr[i][j] == 1 and not is_full_square(i, j): return False return True if not is_valid(): print(-1) exit() vis = list([0] * m for _ in range(n)) res = [] for i in range(n-1): for j in range(m-1): if arr[i][j] == arr[i+1][j] == arr[i][j+1] == arr[i+1][j+1] == 1: res.append((i+1, j+1)) vis[i][j] = vis[i+1][j] = vis[i][j+1] = vis[i+1][j+1] = 1 print(len(res)) for i in res: print(*i) ```
instruction
0
87,651
5
175,302
No
output
1
87,651
5
175,303
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two matrices A and B. Each matrix contains exactly n rows and m columns. Each element of A is either 0 or 1; each element of B is initially 0. You may perform some operations with matrix B. During each operation, you choose any submatrix of B having size 2 × 2, and replace every element in the chosen submatrix with 1. In other words, you choose two integers x and y such that 1 ≤ x < n and 1 ≤ y < m, and then set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1. Your goal is to make matrix B equal to matrix A. Two matrices A and B are equal if and only if every element of matrix A is equal to the corresponding element of matrix B. Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes B equal to A. Note that you don't have to minimize the number of operations. Input The first line contains two integers n and m (2 ≤ n, m ≤ 50). Then n lines follow, each containing m integers. The j-th integer in the i-th line is A_{i, j}. Each integer is either 0 or 1. Output If it is impossible to make B equal to A, print one integer -1. Otherwise, print any sequence of operations that transforms B into A in the following format: the first line should contain one integer k — the number of operations, and then k lines should follow, each line containing two integers x and y for the corresponding operation (set B_{x, y}, B_{x, y + 1}, B_{x + 1, y} and B_{x + 1, y + 1} to 1). The condition 0 ≤ k ≤ 2500 should hold. Examples Input 3 3 1 1 1 1 1 1 0 1 1 Output 3 1 1 1 2 2 2 Input 3 3 1 0 1 1 0 1 0 0 0 Output -1 Input 3 2 0 0 0 0 0 0 Output 0 Note The sequence of operations in the first example: \begin{matrix} 0 & 0 & 0 & & 1 & 1 & 0 & & 1 & 1 & 1 & & 1 & 1 & 1 \\\ 0 & 0 & 0 & → & 1 & 1 & 0 & → & 1 & 1 & 1 & → & 1 & 1 & 1 \\\ 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 1 & 1 \end{matrix} Submitted Solution: ``` m,n = map(int,input().split()) lines_list = [] for i in range(m): lines_list.append(list(map(int, input().split()))) mod_list = [] nummods = 0 for j in range(m-1): for k in range(n-1): if lines_list[j][k]==1: if lines_list[j][k+1]==1 and lines_list[j+1][k]==1 and lines_list[j+1][k+1]==1: lines_list[j][k],lines_list[j+1][k],lines_list[j][k+1],lines_list[j+1][k+1] = 0,0,0,0 nummods +=1 mod_list.append(str(j+1)+' '+str(k+1)) else: print('-1') quit() else: pass for i in range(m): if lines_list[n-1][i]==1: print('-1') quit() for i in range(n): if lines_list[i][m-1]==1: print('-1') quit() print(str(nummods)) for item in mod_list: print(item) ```
instruction
0
87,652
5
175,304
No
output
1
87,652
5
175,305
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2v - 1 for some integer v (v ≥ 0). Help Ivan, find the required quantity of numbers. Input The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. Output Print a single integer — the answer to the problem. Examples Input 4 0 1 1 1 Output 0 Input 1 3 Output 3 Note In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7. In the second sample you need to add numbers 20, 21, 22. Submitted Solution: ``` n = int(input()) s = list(map(int, input().split())) def ins(_set, n): if n in _set: _set.remove(n) ins(_set, n+1) else: _set.add(n) ss = set() for i in s: ins(ss, i) m = max(ss) print(m - len(ss) + 1) ```
instruction
0
87,891
5
175,782
Yes
output
1
87,891
5
175,783
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2v - 1 for some integer v (v ≥ 0). Help Ivan, find the required quantity of numbers. Input The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. Output Print a single integer — the answer to the problem. Examples Input 4 0 1 1 1 Output 0 Input 1 3 Output 3 Note In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7. In the second sample you need to add numbers 20, 21, 22. Submitted Solution: ``` input() a = list(map(int, input().split())) b = [] i = j = 0 while i < len(a): while j < len(a) and a[j] == a[i]: j += 1 if (j - i) % 2 == 1: b += [a[i]] i = j - (j - i) // 2 for k in range(i, j): a[k] += 1 print(b[-1] - len(b) + 1) ```
instruction
0
87,892
5
175,784
Yes
output
1
87,892
5
175,785
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2v - 1 for some integer v (v ≥ 0). Help Ivan, find the required quantity of numbers. Input The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. Output Print a single integer — the answer to the problem. Examples Input 4 0 1 1 1 Output 0 Input 1 3 Output 3 Note In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7. In the second sample you need to add numbers 20, 21, 22. Submitted Solution: ``` n = int(input()) I = map(int, input().split()) a = []; for val in I: a.append(val); la = len(a); b = []; c = []; d = -1; for i in range (0, la): if i == 0 or a[i] != a[i-1]: b.append(a[i]); c.append(1); d = d + 1; else: c[d] = c[d] + 1; d = d + 1; tot = 0; idx = 0; for i in range(0, d): while idx < b[i]: if tot < 2: break; else: tot = int(tot / 2); idx = idx + 1; if idx < b[i]: idx = b[i]; tot = c[i]; else: tot = tot + c[i]; while tot >= 2: tot = int(tot / 2); idx = idx + 1; idx = idx + 1; res = idx; #print (idx) st = []; tot = 0; idx = 0; for i in range (0, d): while idx < b[i]: if tot == 0: break; else: if tot == 1: st.append(idx); tot = 0; idx = idx + 1; else: if tot % 2 == 1: st.append(idx); tot = int(tot / 2); idx = idx + 1; if idx < b[i]: idx = b[i]; tot = c[i]; if tot % 2 == 1: st.append(idx); tot = int(tot / 2); idx = idx + 1; else: idx = b[i]; tot = tot + c[i]; if tot % 2 == 1: st.append(idx); tot = int(tot / 2); idx = idx + 1; while tot > 0: if tot % 2 == 1: st.append(idx); tot = int(tot / 2); idx = idx + 1; lst = len(st); print (res- lst) ```
instruction
0
87,893
5
175,786
Yes
output
1
87,893
5
175,787
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2v - 1 for some integer v (v ≥ 0). Help Ivan, find the required quantity of numbers. Input The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. Output Print a single integer — the answer to the problem. Examples Input 4 0 1 1 1 Output 0 Input 1 3 Output 3 Note In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7. In the second sample you need to add numbers 20, 21, 22. Submitted Solution: ``` n=int(input()) st=set() for e in map(int,input().split()): while(e in st): st.remove(e) e+=1 st.add(e) print(max(st)-len(st)+1) # Made By Mostafa_Khaled ```
instruction
0
87,894
5
175,788
Yes
output
1
87,894
5
175,789
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2v - 1 for some integer v (v ≥ 0). Help Ivan, find the required quantity of numbers. Input The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. Output Print a single integer — the answer to the problem. Examples Input 4 0 1 1 1 Output 0 Input 1 3 Output 3 Note In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7. In the second sample you need to add numbers 20, 21, 22. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) c=1 v=0 p=a[0] for i in range(1,n): if c<=1 and p<a[i]: p=a[i] v+=c c=1 continue if a[i]==a[i-1]: c+=1 else: while (c>0) and p!=a[i]: v+=(c%2) c//=2 p+=1 c+=1 while (c>1): v+=(c%2) c//=2 p+=1 print(p-v) ```
instruction
0
87,895
5
175,790
No
output
1
87,895
5
175,791
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2v - 1 for some integer v (v ≥ 0). Help Ivan, find the required quantity of numbers. Input The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. Output Print a single integer — the answer to the problem. Examples Input 4 0 1 1 1 Output 0 Input 1 3 Output 3 Note In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7. In the second sample you need to add numbers 20, 21, 22. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) a.append(int(1e10)) c=1 v=0 p=a[0] for i in range(n): if c<=1 and p<a[i]: p=a[i] v+=c if a[i]==a[i-1]: c+=1 else: while (c>0) and (i==n-1 or p!=a[i]): if c%2: v+=1 c//=2 p+=1 c=1 while (c>0): if c%2: v+=1 c//=2 p+=1 print(p-v) ```
instruction
0
87,896
5
175,792
No
output
1
87,896
5
175,793
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2v - 1 for some integer v (v ≥ 0). Help Ivan, find the required quantity of numbers. Input The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. Output Print a single integer — the answer to the problem. Examples Input 4 0 1 1 1 Output 0 Input 1 3 Output 3 Note In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7. In the second sample you need to add numbers 20, 21, 22. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) s=set() mx=0 cnt=0 for i in a: k=int(i) if k in s: while k+1 in s : s.remove(int(k)) cnt=cnt-1 k=k+1 if k+1>mx: mx=k+1 else: cnt=cnt+1 if int(i)>mx: mx=int(i) s.add(k) print(mx-cnt+1) ```
instruction
0
87,897
5
175,794
No
output
1
87,897
5
175,795
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2v - 1 for some integer v (v ≥ 0). Help Ivan, find the required quantity of numbers. Input The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an. Output Print a single integer — the answer to the problem. Examples Input 4 0 1 1 1 Output 0 Input 1 3 Output 3 Note In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7. In the second sample you need to add numbers 20, 21, 22. Submitted Solution: ``` from sys import stdin, stdout inputIdx = 0; input = stdin.read().strip().split(); def nextToken(): global inputIdx, input; token = input[inputIdx]; inputIdx += 1; return token; def main(): global inputIdx, input; while inputIdx < len(input): n = int( nextToken() ); fr = 0; cur = 0; ans = 0; for i in range(n): a = int( nextToken() ); if a <= cur: cur -= a; if cur == 0: fr += 1; cur = fr; else: to = max( fr, a ); ans += (to-fr); fr = to+1; cur = fr; if cur != fr: ans += 1; print( int(ans) ); main(); ```
instruction
0
87,898
5
175,796
No
output
1
87,898
5
175,797
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square. A number x is said to be a perfect square if there exists an integer y such that x = y2. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. Output Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. Examples Input 2 4 2 Output 2 Input 8 1 2 4 8 16 32 64 576 Output 32 Note In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) a=sorted(a,reverse=True) for i in a: if i>=0: b=int(i**0.5) if b*b!=i: print(i) break else: print(i) break ```
instruction
0
88,091
5
176,182
Yes
output
1
88,091
5
176,183
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square. A number x is said to be a perfect square if there exists an integer y such that x = y2. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. Output Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. Examples Input 2 4 2 Output 2 Input 8 1 2 4 8 16 32 64 576 Output 32 Note In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. Submitted Solution: ``` n = list(map(int, input().strip().split())) arr = list(map(int, input().strip().split())) answer = -9999999 for i in arr: if i < 0: answer = max(answer, i) continue temp = int(i ** (1 / 2)) if (temp - 1) ** 2 == i or temp ** 2 == i or (temp + 1) ** 2 == i: continue answer = max(answer, i) print(answer) ```
instruction
0
88,093
5
176,186
Yes
output
1
88,093
5
176,187
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square. A number x is said to be a perfect square if there exists an integer y such that x = y2. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. Output Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. Examples Input 2 4 2 Output 2 Input 8 1 2 4 8 16 32 64 576 Output 32 Note In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. Submitted Solution: ``` sq = {i*i for i in range(0,10000)} n = int(input()) A = [int(x) for x in input().split()] B = [a for a in A if a not in sq] print(max(B)) ```
instruction
0
88,094
5
176,188
Yes
output
1
88,094
5
176,189
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square. A number x is said to be a perfect square if there exists an integer y such that x = y2. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. Output Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. Examples Input 2 4 2 Output 2 Input 8 1 2 4 8 16 32 64 576 Output 32 Note In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. Submitted Solution: ``` from math import sqrt def dig_sum(num): while num >= 10: num = sum(list(map(int,list(str(num))))) return num n = int(input()) nums = list(map(int,input().strip().split(' '))) nums.sort(reverse=True) for num in nums: if num % 10 not in [0,1,4,5,6,9] and dig_sum(num) not in [0,1,4,7]: print(num) break ```
instruction
0
88,095
5
176,190
No
output
1
88,095
5
176,191
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square. A number x is said to be a perfect square if there exists an integer y such that x = y2. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. Output Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. Examples Input 2 4 2 Output 2 Input 8 1 2 4 8 16 32 64 576 Output 32 Note In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. Submitted Solution: ``` input() prnt=-10000000 for x in list(map(int,input().split())): print(prnt, x) if x>0: prnt=max(prnt, x) if int(abs(x)**0.5)**2 != abs(x) else prnt else: prnt = max(prnt,x) print(prnt) ```
instruction
0
88,096
5
176,192
No
output
1
88,096
5
176,193
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square. A number x is said to be a perfect square if there exists an integer y such that x = y2. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. Output Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. Examples Input 2 4 2 Output 2 Input 8 1 2 4 8 16 32 64 576 Output 32 Note In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. Submitted Solution: ``` import math mp = 0 mo = 0 n = int(input()) a = input().split() a = [int (i) for i in a] ot = [] a = sorted(a) for j in range(len(a)): if a[j] < 0: ot.append(a[j]) else: break a.reverse() if len(ot) > 0: mo = max(ot) for i in range(len(a)): if a[i] == 1 or a[i] == -1: print(a[i]) break s = math.sqrt(abs(a[i])) k = int (s) if s != abs(k): mp = a[i] break if mp != 0: print(mp) else: print(mo) ```
instruction
0
88,097
5
176,194
No
output
1
88,097
5
176,195
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square. A number x is said to be a perfect square if there exists an integer y such that x = y2. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. Output Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. Examples Input 2 4 2 Output 2 Input 8 1 2 4 8 16 32 64 576 Output 32 Note In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. Submitted Solution: ``` from math import sqrt n = int(input()) s = [int(i) for i in input().split()] c = -10**6 for i in range(n): if s[i]<0: pass elif sqrt(s[i]).is_integer()==False: c=max(c,s[i]) print(c) ```
instruction
0
88,098
5
176,196
No
output
1
88,098
5
176,197
Provide a correct Python 3 solution for this coding contest problem. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0
instruction
0
88,159
5
176,318
"Correct Solution: ``` n=int(input()) arr=list(input()) arr=[int(arr[i]) for i in range(n)] if n==1: print(arr[0]) if n==2: print(abs(arr[0]-arr[1])) else: tmp=[] for i in range(n-2): tmp.append(abs(abs(arr[i]-arr[i+1])-abs(arr[i+1]-arr[i+2]))) arr=tmp while len(arr)>3: tmp=[] if len(arr)%2==0: for i in range(len(arr)//2): tmp.append(abs(arr[2*i]-arr[2*i+1])) else: for i in range(len(arr)-1): tmp.append(abs(arr[i]-arr[i+1])) arr=tmp if len(arr)==1: print(arr[0]) elif len(arr)==2: print(abs(arr[0]-arr[1])) elif len(arr)==3: print(abs(abs(arr[0]-arr[1])-abs(arr[1]-arr[2]))) ```
output
1
88,159
5
176,319
Provide a correct Python 3 solution for this coding contest problem. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0
instruction
0
88,160
5
176,320
"Correct Solution: ``` import sys N = int(input()) - 1 two = False S = 0 for i in range(N+1): a = int(sys.stdin.read(1)) if not two: two = a == 2 if i & N == i: S ^= a-1 if two: S &= ~2 print(S) ```
output
1
88,160
5
176,321
Provide a correct Python 3 solution for this coding contest problem. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0
instruction
0
88,161
5
176,322
"Correct Solution: ``` #!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list(map(lambda x: int(x)-1, input().split())) def II(): return int(input()) def IF(): return float(input()) def LS(): return list(map(list, input().split())) def S(): return list(input().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = 1e10 #solve def solve(): n = II() a = list(map(lambda x: int(x) - 1, S())) ans = 1 if not 1 in a: ans *= 2 for i in range(n): a[i] >>= 1 res = 0 for i in range(n): # ~ Lucas の定理から ~ # n C k において # k の bitが立っているところについて # n の bitが立っていない場合 n C k が 2の倍数になる # これを超簡単にする方法 (Touristの提出を見た) if ((n - 1) & i == i): res ^= a[i] & 1 print(res * ans) return #main if __name__ == '__main__': solve() ```
output
1
88,161
5
176,323
Provide a correct Python 3 solution for this coding contest problem. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0
instruction
0
88,162
5
176,324
"Correct Solution: ``` N = int(input()) a = input() def myc(n): ret = 0 while n % 2 == 0: ret += 1 n //= 2 return ret def func(c): odd = 0 count = 0 if a[0] == c: count += 1 if a[-1] == c: count += 1 for i in range(1, N // 2): odd += myc(N-i) - myc(i) if a[i] == c and odd == 0: count += 1 if a[-i-1] == c and odd == 0: count += 1 if N % 2 == 1: if a[N // 2] == c and odd + myc(N // 2 + 1) - myc(N // 2) == 0: count += 1 return count % 2 == 0 if '2' in a: if func('2'): print(0) else: print(1) else: if func('3'): print(0) else: print(2) ```
output
1
88,162
5
176,325
Provide a correct Python 3 solution for this coding contest problem. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0
instruction
0
88,163
5
176,326
"Correct Solution: ``` n = int(input()) s = input() a = [] for i in range(n - 1): a.append(abs(int(s[i]) - int(s[i + 1]))) ans = [] for r in range(n - 1): if (n - 2)^ r ^ (n - 2 - r) == 0: ans.append(int(a[r])) res = 0 for i in ans: res = abs(res - i) if 1 in a: print(res % 2) else: print(res) ```
output
1
88,163
5
176,327
Provide a correct Python 3 solution for this coding contest problem. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0
instruction
0
88,164
5
176,328
"Correct Solution: ``` import sys N = int(input()) - 1 two = False S = 0 for i in range(N+1): a = int(sys.stdin.read(1)) two |= (a == 2) if i & N == i: S ^= a-1 if two: S &= ~2 print(S) ```
output
1
88,164
5
176,329
Provide a correct Python 3 solution for this coding contest problem. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0
instruction
0
88,165
5
176,330
"Correct Solution: ``` # -*- coding: utf-8 -*- """ Created on Sun Mar 22 13:54:24 2020 @author: naoki """ import sys #f = open("C:/Users/naoki/Desktop/Atcoder/input.txt") N = int(input()) a = list(map(lambda x:int(x)-1,list(input()))) all_odd = 0 kai = [0] * N if (0 not in a) and (1 not in a): print(0) sys.exit() if (1 not in a) and (2 not in a): print(0) sys.exit() if (0 not in a) and (2 not in a): print(0) sys.exit() for k in range(1,N): count = 0 p = k for _ in range(N): if p % 2 == 1: kai[k] = kai[k-1] + count break p = p/2 count += 1 all_num = 0 for k in range(N): if kai[-1] == kai[k] + kai[N-1-k] and a[k] == 1: all_num += 1 if all_num % 2 == 1: print(1) elif 1 in a: print(0) else: for i in range(N): a[i] = a[i]/2 for k in range(N): if kai[-1] <= kai[k] + kai[N-1-k] and a[k] == 1: all_num += 1 if all_num % 2 == 1: print(2) else: print(0) ```
output
1
88,165
5
176,331
Provide a correct Python 3 solution for this coding contest problem. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0
instruction
0
88,166
5
176,332
"Correct Solution: ``` import sys n=int(input()) s=input() frac=[0]*(n+1) for i in range(1,n+1): k=i frac[i]=frac[i-1] while k%2==0: k//=2 frac[i]+=1 ans=0 for i in range(n): if int(s[i])==2 and frac[n-1]-frac[i]-frac[n-1-i]==0: ans^=1 if ans==1: print(1) elif "2" in s: print(0) else: ans=0 for i in range(n): if int(s[i])==3 and frac[n-1]-frac[i]-frac[n-1-i]==0: ans^=1 print(ans*2) ```
output
1
88,166
5
176,333
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0 Submitted Solution: ``` N = int(input()) A = list(map(int, input())) num = 0 for i in range(N): num += (N - 1 == (i | N - 1 - i)) * ((-1)**i) * A[i] if num % 2 == 1: print(1) else: for i in range(N - 1): if abs(A[i]-A[i+1]) == 1: print(0) break else: B = [] for i in range(N-1): if A[i] == A[i+1]: B.append(0) else: B.append(1) for i in range(N-1): num += (N - 2 == (i | N - 2 - i)) * ((-1)**i) * B[i] if num % 2 == 1: print(2) else: print(0) ```
instruction
0
88,167
5
176,334
Yes
output
1
88,167
5
176,335
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0 Submitted Solution: ``` import sys N = int(input()) S = input().strip() ss = [] for c in S: ss.append(int(c)) if N == 2: print(abs(ss[0]-ss[1])) sys.exit() X = [] X2 = [] fff = 0 for i in range(N-1): c = abs(ss[i] - ss[i+1]) X.append(c%2) X2.append((c//2)%2) if c == 1: fff = 1 N=N-2 i = 0 Y = [] while N: if N%2: Y.append(i) i += 1 N=N//2 C = [0] for y in Y[::-1]: y = 2**y # print(y) tmp = [] for c in C: tmp.append(c+y) for t in tmp: C.append(t) r = 0 r2 = 0 for c in C: r = r^X[c] r2 = r2^X2[c] if fff: print(r) else: print(r2*2) ```
instruction
0
88,168
5
176,336
Yes
output
1
88,168
5
176,337
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0 Submitted Solution: ``` import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) A = list(map(int, read().decode().rstrip())) U = N + 10 fact_ord = [0] * U for n in range(1,U): fact_ord[n] = fact_ord[n//2] + (n//2) def solve_01(A): ret = 0 N = len(A) - 1 comb_ord = [fact_ord[N] - fact_ord[i] - fact_ord[N-i] for i in range(N+1)] return sum(x * (y==0) for x,y in zip(A, comb_ord)) % 2 def solve(A): if len(A) == 1: return A[0] A = [abs(x - y) for x,y in zip(A, A[1:])] if all(x != 1 for x in A): B = [x // 2 for x in A] return 2 * solve_01(B) # 1 が存在 A = [x % 2 for x in A] return solve_01(A) print(solve(A)) ```
instruction
0
88,169
5
176,338
Yes
output
1
88,169
5
176,339
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0 Submitted Solution: ``` N = int(input()) A = [int(c)-1 for c in input()] x = 0 b = 1 if any(a==1 for a in A) else 2 for k,a in enumerate(A): p = int(((N-1)&k)==k) if p and a^b==0: x ^= b print(x) ```
instruction
0
88,170
5
176,340
Yes
output
1
88,170
5
176,341
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0 Submitted Solution: ``` print(1) ```
instruction
0
88,171
5
176,342
No
output
1
88,171
5
176,343
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0 Submitted Solution: ``` N = int(input()) a = input() sp = len(''.join(set(a))) if sp == 1: print(0) elif sp == 2: if a[0] == '1': add = 1 else: add = 0 if a[-1] == '1': add = add+1 else: add = add a = a.replace('1', '') if not "3" in a: if (len(a)+add) % 2 == 1: print(1) else: print(0) elif not "2" in a: if (len(a)+add) % 2 == 1: print(2) else: print(0) else: if len(a) % 2 == 1: print(1) else: print(0) else: a = a.replace('1', '') if a[0] == '2': add = 1 else: add = 0 a = a.replace('2', '') if (len(a)+add) % 2 == 1: print(1) else: print(0) ```
instruction
0
88,172
5
176,344
No
output
1
88,172
5
176,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0 Submitted Solution: ``` n=int(input()) a_=input() a=[] for i in range(n): a.append(int(a_[i])) while n!=0: for i in range(n-1): a[i]=abs(a[i]-a[i+1]) n-=1 print(a[0]) ```
instruction
0
88,173
5
176,346
No
output
1
88,173
5
176,347
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. Constraints * 2 \leq N \leq 10^6 * a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N Output Print x_{N,1}. Examples Input 4 1231 Output 1 Input 10 2311312312 Output 0 Submitted Solution: ``` n = int(input()) a = input() a1 = 0 a2 = 0 a3 = 0 for i in range(n): if a[i] == "1": a1 += 1 elif a[i] == "3": a3 += 1 if n == 2 and a1 == 1 and a3 == 1: print(2) elif a == "213" or a == "132" or a == "231" or a == "312": print(1) elif a1 == 1 and a3 == 0: print(1) elif a1 == 0 and a3 == 1: print(1) else: print(0) ```
instruction
0
88,174
5
176,348
No
output
1
88,174
5
176,349
Provide a correct Python 3 solution for this coding contest problem. Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls? Constraints * 1 \leq K \leq N \leq 100 * All values in input are integers. Input Input is given from Standard Input in the following format: N K Output Print the maximum possible difference in the number of balls received. Examples Input 3 2 Output 1 Input 3 1 Output 0 Input 8 5 Output 3
instruction
0
88,177
5
176,354
"Correct Solution: ``` n, k = map(int, input().split()) print((n - k) if k > 1 else 0) ```
output
1
88,177
5
176,355
Provide a correct Python 3 solution for this coding contest problem. Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls? Constraints * 1 \leq K \leq N \leq 100 * All values in input are integers. Input Input is given from Standard Input in the following format: N K Output Print the maximum possible difference in the number of balls received. Examples Input 3 2 Output 1 Input 3 1 Output 0 Input 8 5 Output 3
instruction
0
88,178
5
176,356
"Correct Solution: ``` W = list(map(int,input().split())) print(W[0]%W[1]) ```
output
1
88,178
5
176,357
Provide a correct Python 3 solution for this coding contest problem. Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls? Constraints * 1 \leq K \leq N \leq 100 * All values in input are integers. Input Input is given from Standard Input in the following format: N K Output Print the maximum possible difference in the number of balls received. Examples Input 3 2 Output 1 Input 3 1 Output 0 Input 8 5 Output 3
instruction
0
88,179
5
176,358
"Correct Solution: ``` (lambda n,k: print(0 if k==1 else n-k))(*list(map(int,input().split()))) ```
output
1
88,179
5
176,359
Provide a correct Python 3 solution for this coding contest problem. Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls? Constraints * 1 \leq K \leq N \leq 100 * All values in input are integers. Input Input is given from Standard Input in the following format: N K Output Print the maximum possible difference in the number of balls received. Examples Input 3 2 Output 1 Input 3 1 Output 0 Input 8 5 Output 3
instruction
0
88,180
5
176,360
"Correct Solution: ``` n,k = map(int,input().split()) print(max((n % k - n // k + 1),0)) ```
output
1
88,180
5
176,361