description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
def read():
line = sys.stdin.readline().strip()
return map(int, line.split())
def dfs(l, r, dpt):
if dpt == 0:
return [0]
lst = []
for i in range(l, r):
for j in dfs(i + 1, r, dpt - 1):
lst.append(arr[i] + j)
return lst
def solver(N):
if 0 in arr or len(set(arr)) != N:
return "YES"
lst = []
for i in range(1, N + 1):
lst.extend(dfs(0, N, i))
if len(set(lst)) != (1 << N) - 1:
return "YES"
return "NO"
(T,) = read()
for t in range(T):
(N,) = read()
arr = sorted(list(map(lambda x: abs(x), list(read()))))
print(solver(N))
sys.exit() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF IF NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
input = sys.stdin.readline
def main():
n = int(input())
alst = list(map(int, input().split()))
for bit in range(1, 3**n):
tot = 0
for b in alst:
if bit % 3 == 1:
tot += b
elif bit % 3 == 2:
tot -= b
bit //= 3
if tot == 0:
print("YES")
return
print("NO")
for _ in range(int(input())):
main() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
n = int(input())
A = list(map(int, input().split()))
if n == 1:
if A[0] == 0:
print("YES")
else:
print("NO")
continue
if 0 in A:
print("YES")
continue
X = [A[0]]
for i in range(1, n):
a = A[i]
Y = [a]
for x in X:
Y.append(x + a)
Y.append(x - a)
X += Y
if 0 in X:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
print("YES")
else:
for i in range(n):
c = [0]
for j in range(n):
if i != j:
for k in range(len(c)):
c.append(c[k] - a[j])
c.append(c[k] + a[j])
if a[i] in c or -a[i] in c:
print("YES")
break
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | def find(i, total, k):
if i == n:
if total == 0 and k > 0:
return True
return False
return (
find(i + 1, total + a[i], k + 1)
or find(i + 1, total - a[i], k + 1)
or find(i + 1, total, k)
)
def sex(n, a):
if n == 1:
if a[0] == 0:
return "YES"
return "NO"
a = [abs(a[i]) for i in range(n)]
a.sort()
for i in range(n - 1):
if a[i] == a[i + 1]:
return "YES"
if find(0, 0, 0):
return "YES"
return "NO"
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
print(sex(n, a)) | FUNC_DEF IF VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF IF VAR NUMBER IF VAR NUMBER NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN STRING IF FUNC_CALL VAR NUMBER NUMBER NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
zai = [0] * n
ans = 0
for i in range(1 << n):
t = []
if ans == 1:
break
ind = 0
while i > 0:
if i & 1 == 1:
t.append(a[ind])
ind += 1
i = i >> 1
res = 0
if sum(t) % 2 == 1 or len(t) == 0:
continue
else:
mb = sum(t) // 2
m = len(t)
for j in range(1 << m):
r = 0
ind = 0
while j > 0:
if j & 1 == 1:
r += t[ind]
ind += 1
j = j >> 1
if r == mb:
ans = 1
break
if ans == 1:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | def readline():
return map(int, input().split())
def sums(values):
sums_ = [0]
for v in values:
new = list()
for s in sums_:
new.extend((s + v, s - v))
yield from new
sums_.extend(new)
def solve():
input()
a = readline()
print("YES" if 0 in sums(a) else "NO")
t = int(input())
for __ in range(t):
solve() | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | def possible(a):
sums = [0]
for v in a:
cands = []
for sum_ in sums:
cands_ = [sum_ + v, sum_ - v]
if 0 in cands_:
return True
cands.extend(cands_)
sums.extend(cands)
return False
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
if possible(a):
print("YES")
else:
print("NO") | FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST BIN_OP VAR VAR BIN_OP VAR VAR IF NUMBER VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | for i in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
z = int(3**n)
an = "NO"
for i in range(1, z):
temp = 0
i1 = i
for j in range(n):
x = i1 % 3
if x == 1:
temp += l[j]
elif x == 2:
temp -= l[j]
i1 //= 3
if temp == 0:
an = "YES"
break
print(an) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | def process(A):
n = len(A)
A = [abs(x) for x in A]
A = sorted(set(A))
if len(A) < n:
return "YES"
if n == 1:
if A == [0]:
return "YES"
return "NO"
if n == 2:
if A[0] == 0:
return "YES"
return "NO"
sums = set([0])
for i in range(n):
if A[i] in sums:
return "YES"
sums2 = set([])
for x in sums:
sums2.add(x)
sums2.add(x + A[i])
sums = sums2
if len(sums) == 2**n:
return "NO"
return "YES"
t = int(input())
for i in range(t):
n = int(input())
A = [int(x) for x in input().split()]
print(process(A)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN STRING IF VAR NUMBER IF VAR LIST NUMBER RETURN STRING RETURN STRING IF VAR NUMBER IF VAR NUMBER NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
sums = set([a[0], -a[0]])
for i in range(1, n):
current_sums = sums.copy()
sums.add(a[i])
for s in current_sums:
sums.add(s + a[i])
sums.add(s - a[i])
print("YES" if 0 in sums else "NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR STRING STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | from sys import stdin, stdout
def arrin():
return list(map(int, stdin.readline().split()))
def num1in():
return int(stdin.readline())
def num2in():
a, b = map(int, stdin.readline().split())
return a, b
def num3in():
a, b, c = map(int, stdin.readline().split())
return a, b, c
def num4in():
a, b, c, d = map(int, stdin.readline().split())
return a, b, c, d
def num5in():
a, b, c, d, e = map(int, stdin.readline().split())
return a, b, c, d, e
def recur(i, arr, visited, s, f):
if s == f:
return True
if i == len(arr):
return False
if visited[i]:
return recur(i + 1, arr, visited, s, f)
return (
recur(i + 1, arr, visited, s, f)
or recur(i + 1, arr, visited, s + arr[i], f)
or recur(i + 1, arr, visited, s - arr[i], f)
)
t = num1in()
for test in range(t):
n = num1in()
arr = arrin()
visited = [(False) for x in range(n)]
flag = 0
for i in range(n):
visited[i] = True
ans = recur(0, arr, visited, 0, arr[i])
if ans == True:
print("YES")
flag = 1
break
visited[i] = False
if flag == 0:
print("NO") | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR VAR VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
for i in range(n):
a[i] = abs(a[i])
a.sort()
aset = set(a)
ans = "NO"
if 0 in a or len(aset) != n:
ans = "YES"
print(ans)
continue
for i in range(n):
ts = set([0])
for j in range(n):
newlis = []
if j != i:
for v in ts:
newlis.append(v + a[j])
newlis.append(v - a[j])
for x in newlis:
ts.add(x)
if a[i] in ts:
ans = "YES"
break
print(ans) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
from itertools import combinations
input = sys.stdin.readline
t = int(input())
for j in range(t):
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
flag = False
for i in range(n):
if a[i] == 0:
flag = True
break
temp = a.copy()
temp.pop(i)
if a[i] in temp or -a[i] in temp:
flag = True
break
if flag:
print("YES")
continue
for x in range(3, n + 1):
temp = list(combinations(a, x))
for y in temp:
y = list(y)
t_sum = sum(y)
sums = [t_sum]
suml = 1
for z in range(x):
ty = suml
for w in range(ty):
sums.append(sums[w] - 2 * y[z])
suml += 1
if 0 in sums:
flag = True
break
if flag == True:
break
if flag:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR NUMBER IF NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | mod = 10**9 + 7
def gcd(a, b):
return a if b == 0 else gcd(b, a % b)
def lcm(a, b):
return a * b // gcd(a, b)
def solve(t_id):
n = int(input())
a = list(map(int, input().split()))
ok = False
for i in range(1, 3**n):
sm = 0
k = i
for j in range(n):
if k % 3 == 1:
sm += a[j]
elif k % 3 == 2:
sm -= a[j]
k //= 3
if sm == 0:
ok = True
print("YES" if ok else "NO")
t = 1
t = int(input())
for i in range(t):
solve(i + 1) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
input = sys.stdin.readline
for nt in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
curr = [0]
for i in range(n):
b = []
for j in curr:
b.append(a[i] + j)
for j in curr:
b.append(j - a[i])
curr.extend(b)
if curr.count(0) > 1:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | from itertools import chain, combinations
T = int(input())
for _ in range(T):
N = int(input())
arr = [int(x) for x in input().split()]
powerSet = chain.from_iterable(combinations(arr, r) for r in range(N + 1))
powerSetSums = set([sum(i) for i in powerSet])
if len(powerSetSums) < 2**N:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
(N,) = map(int, input().split())
X = list(map(int, input().split()))
if 0 in X:
print("YES")
continue
for k in range(N):
ff = 0
for j in range(3 ** (N - 1)):
l = []
for _ in range(N - 1):
j, m = divmod(j, 3)
l.append(m)
r = 0
f = 0
for i in range(N - 1):
if i == k:
f = 1
continue
if l[i] == 1:
r += X[i + f]
elif l[i] == 2:
r -= X[i + f]
if r == X[k]:
ff = 1
print("YES")
break
if ff:
break
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | from itertools import *
for s in [*open(0)][2::2]:
(*a,) = map(int, s.split())
n = len(a)
print("YNEOS"[len({*map(sum, combinations(a + [0] * n, n))}) >> n :: 2]) | FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP LIST NUMBER VAR VAR VAR NUMBER |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | from sys import setrecursionlimit, stdin
input = stdin.readline
setrecursionlimit(10**8)
def solve(i, value, took):
if i == n:
if took and value == 0:
return True
return False
return (
solve(i + 1, value, took)
| solve(i + 1, value + a[i], took + 1)
| solve(i + 1, value - a[i], took + 1)
)
def answer():
if solve(0, 0, 0) == True:
return "YES"
else:
return "NO"
for T in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
print(answer()) | ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR VAR IF VAR VAR NUMBER RETURN NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
input = sys.stdin.readline
def inp():
return int(input())
def inara():
return list(map(int, input().split()))
def insr():
s = input()
return list(s[: len(s) - 1])
def invr():
return map(int, input().split())
for _ in range(inp()):
n = inp()
a = inara()
for i in range(n):
a[i] = abs(a[i])
a.sort()
flag = False
for i in range(1, n):
if a[i] == a[i - 1]:
flag = True
for i in range(n):
if a[i] == 0:
flag = True
subset = []
for mask in range(1, 1 << n):
tot = 0
for bit in range(n):
if mask & 1 << bit:
tot += a[bit]
subset.append(tot)
subset.sort()
for i in range(1, len(subset)):
if subset[i] == subset[i - 1]:
flag = True
print("YES" if flag else "NO") | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | def readline():
return map(int, input().split())
def sums(values):
ret = [(0, 0)]
for v in values:
plus = [(v + x, cnt + 1) for x, cnt in ret]
minus = [(v - x, cnt + 1) for x, cnt in ret]
ret.extend(plus)
ret.extend(minus)
return ret
def solve():
n = int(input())
a = readline()
return any(v == 0 for v, cnt in sums(a) if cnt)
t = int(input())
for __ in range(t):
print("YES" if solve() else "NO") | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | def get_power_set(s):
power_set = [[]]
for elem in s:
for sub_set in power_set:
power_set = power_set + [list(sub_set) + [elem]]
return power_set
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
y = 0
if 0 in a:
print("YES")
y = 1
else:
for i in range(n):
if -a[i] in a:
print("YES")
y = 1
break
if y == 0:
li = get_power_set(a)
li.pop(0)
for i in range(2**n - 1):
li[i] = sum(li[i])
se = set(li)
if len(se) == len(li):
print("NO")
else:
print("YES") | FUNC_DEF ASSIGN VAR LIST LIST FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR LIST BIN_OP FUNC_CALL VAR VAR LIST VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
input = iter(sys.stdin.read().splitlines()).__next__
def solve():
n = int(input())
a = list(map(int, input().split()))
a = set(map(abs, a))
a.discard(0)
if len(a) < n:
return "YES"
elements = sorted(a)
elements_minus_i = [(elements[:i] + elements[i + 1 :]) for i in range(n)]
for q in range(3 ** (n - 1)):
sum_elements_minus_i = [0] * n
for j in range(n - 1):
q, r = divmod(q, 3)
if r == 1:
for i in range(n):
sum_elements_minus_i[i] += elements_minus_i[i][j]
elif r == 2:
for i in range(n):
sum_elements_minus_i[i] -= elements_minus_i[i][j]
for element, other_combo in zip(elements, sum_elements_minus_i):
if element == other_combo:
return "YES"
return "NO"
t = int(input())
output = []
for _ in range(t):
output.append(solve())
print(*output, sep="\n") | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | def find_common(a1, a2):
list_len = len(a1)
list_len2 = len(a2)
a3 = []
iz = jz = 0
while iz < list_len and jz < list_len2:
if a1[iz] < a2[jz]:
iz += 1
elif a2[jz] < a1[iz]:
jz += 1
else:
a3.append(a1[iz])
iz += 1
jz += 1
return a3
t = int(input())
for i in range(t):
y = 0
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
print("YES")
elif n <= 5:
for j in range(1, 3**n):
tz = 0
for k in range(n):
if j // 3**k % 3 == 1:
tz += a[k]
elif j // 3**k % 3 == 2:
tz -= a[k]
if tz == 0:
y = 1
break
if y == 0:
print("NO")
else:
print("YES")
else:
l = []
for j in range(1, 3**5):
tz = 0
for k in range(5):
if j // 3**k % 3 == 1:
tz += a[k]
elif j // 3**k % 3 == 2:
tz -= a[k]
l.append(abs(tz))
l = list(set(l))
l.sort()
a = a[5:]
ln = []
for j in range(1, 3 ** len(a)):
tz = 0
for k in range(len(a)):
if j // 3**k % 3 == 1:
tz += a[k]
elif j // 3**k % 3 == 2:
tz -= a[k]
ln.append(tz)
ln = list(set(ln))
ln.sort()
if find_common(l, ln):
print("YES")
elif 0 in ln:
print("YES")
elif 0 in l:
print("YES")
else:
print("NO") | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER VAR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER VAR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER VAR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING IF NUMBER VAR EXPR FUNC_CALL VAR STRING IF NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | from itertools import combinations
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split(" ")))
if 0 in arr:
print("yes")
continue
if n == 1:
print("no")
continue
b = set(arr)
if len(b) != len(arr):
print("yes")
else:
tp = set()
for x in arr:
tp.add(abs(x))
if len(tp) != n:
print("yes")
continue
smr = set()
for x in range(1, n + 1):
b = combinations(arr, x)
for y in list(b):
smr.add(sum(y))
if len(smr) != 2**n - 1:
print("yes")
else:
print("no") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | from itertools import product
from sys import gettrace, stdin
if gettrace():
def inputi():
return input()
else:
def input():
return next(stdin)[:-1]
def inputi():
return stdin.buffer.readline()
def solve():
n = int(input())
aa = [int(a) for a in input().split()]
if 0 in aa:
print("YES")
return
bbb = [[-a, 0, a] for a in aa]
ppp = product(*bbb)
for pp in ppp:
if sum(pp) == 0 and pp != (0,) * n:
print("YES")
return
print("NO")
def main():
t = int(input())
for _ in range(t):
solve()
main() | IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR LIST VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | from itertools import combinations
T = int(input())
for i in range(T):
n = int(input())
arr = list(map(int, input().split()))
if n == 1:
if arr[0] != 0:
print("NO")
else:
print("YES")
continue
h = dict()
t = 0
for j in range(1, n + 1):
for k in combinations(arr, j):
l = sum(k)
if l == 0:
t = 1
print("YES")
break
elif l in h:
t = 1
print("YES")
break
else:
h[l] = 1
if t == 1:
break
if t != 1:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | from itertools import chain, combinations
from sys import stdin, stdout
def powerset(s):
return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1))
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
a = [abs(int(x)) for x in stdin.readline().split()]
check_0 = False
for i in range(n):
if a[i] == 0:
check_0 = True
check_repeat = False
for i in range(n):
for j in range(i + 1, n):
if a[i] == a[j]:
check_repeat = True
if check_0 or check_repeat:
stdout.write("YES\n")
else:
answer = "NO"
check = set()
for s in powerset(a):
s1 = sum(s)
if s1 in check:
answer = "YES"
break
else:
check.add(s1)
stdout.write(answer + "\n") | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
x = 2**n - 1
d = []
an = "NO"
for i in range(x + 1):
c = sum([a[j] for j in range(n) if i & 1 << j])
if c in d:
an = "YES"
break
else:
d.append(c)
print(an)
num_inp = lambda: int(input())
arr_inp = lambda: list(map(int, input().split()))
sp_inp = lambda: map(int, input().split())
str_inp = lambda: input() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | def tern_az(x, n):
z = []
for _ in range(n):
z.append([0, 1, -1][x % 3])
x //= 3
return z
t = int(input())
for _ in range(t):
n = int(input())
s = [int(i) for i in input().split()]
x = False
for i in range(1, 3**n):
_i = tern_az(i, n)
q = [(s[j] * _i[j]) for j in range(n)]
if sum(q) == 0:
x = True
break
print(["Yes", "No"][x - 1]) | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING BIN_OP VAR NUMBER |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | t = int(input())
while t:
t -= 1
n = int(input())
arr = [abs(int(x)) for x in input().split()]
if 0 in arr:
print("YES")
continue
look = set()
found = False
for i in range(1, 2**n):
s = bin(i)[2:]
s = "0" * (n - len(s)) + s
curr = 0
for i in range(n):
if s[i] == "1":
curr += arr[i]
if curr not in look:
look.add(curr)
else:
found = True
break
print("YES" if found else "NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
input = sys.stdin.readline
def solve():
n = int(input())
a = list(map(int, input().split()))
def possible(j, target):
ans = set([0])
for k in range(j, n):
to = set()
for x in ans:
to.add(x - a[k])
to.add(x + a[k])
ans |= to
return target in ans
for i in range(n):
target = a[i]
if possible(i + 1, target):
print("YES")
return
print("NO")
return
for nt in range(int(input())):
solve() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
f = False
for i in range(1, 3**n):
m = i
s = []
while m > 0 or len(s) < n:
r = m % 3
if r == 0:
s.append(0)
elif r == 1:
s.append(-1)
else:
s.append(1)
m //= 3
val = 0
for j in range(n):
val += a[j] * s[j]
if val == 0:
f = True
if f:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | def su(uni):
result = [[]]
for i in range(len(uni)):
for j in range(len(result)):
result.append(result[j] + [uni[i]])
return result
def summ(a):
S = 0
for i in a:
S += i
return S
def fun(x):
return abs(int(x))
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(fun, input().split()))
starry = su(a)
sumarry = set()
flag = 0
for i in range(len(starry)):
x = summ(starry[i])
if x in sumarry:
flag = 1
break
sumarry.add(x)
if flag == 0:
print("NO")
else:
print("YES") | FUNC_DEF ASSIGN VAR LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR LIST VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
from itertools import product
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return map(int, sys.stdin.readline().rstrip().split())
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LI2():
return list(map(int, sys.stdin.readline().rstrip()))
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split())
def LS2():
return list(sys.stdin.readline().rstrip())
t = I()
for _ in range(t):
n = I()
A = LI()
Y = set()
for X in product([0, 1], repeat=n):
b = 0
for i in range(n):
a = A[i]
if X[i] == 0:
continue
else:
b += a
if b in Y:
print("YES")
break
Y.add(b)
else:
print("NO") | IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(2 * 10**5 + 10)
write = lambda x: sys.stdout.write(x + "\n")
debug = lambda x: sys.stderr.write(x + "\n")
writef = lambda x: print("{:.12f}".format(x))
t = int(input())
ans = []
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
res = 1
else:
for b in range(3**n):
l0 = []
l1 = []
for i in range(n):
b, v = divmod(b, 3)
if v == 1:
l0.append(a[i])
elif v == 2:
l1.append(a[i])
if not l0:
continue
if sum(l0) == sum(l1, 0):
res = 1
break
else:
res = 0
if res:
ans.append("Yes")
else:
ans.append("No")
write("\n".join(ans)) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | from sys import stdin, stdout
T = int(stdin.readline())
for _ in range(T):
n = int(stdin.readline())
A = list(map(int, stdin.readline().split()))
B = set()
B.add(0)
found = False
for i in range(n):
added = set()
for k in B:
c = k + A[i]
if c in B:
found = True
break
elif c in added:
found = True
break
else:
added.add(c)
if found:
break
B = B.union(added)
if found:
break
if found:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
m = 1
for i in range(n):
m *= 3
for i in range(1, m):
x = i
s = 0
for j in range(n):
if x % 3 == 1:
s += l[j]
elif x % 3 == 2:
s += -l[j]
x //= 3
if s == 0:
print("YES")
break
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | def su(uni):
result = [[]]
for i in range(len(uni)):
for j in range(len(result)):
result.append(result[j] + [uni[i]])
return result
def summ(a):
S = 0
for i in a:
S += i
return S
t = int(input())
for _ in range(t):
n = int(input())
num = list(map(int, input().split()))
a = []
for temp1 in num:
a.append(abs(temp1))
starry = su(a)
sumarry = []
for i in range(len(starry)):
sumarry.append(summ(starry[i]))
flag = 0
sumarry.sort()
N = len(sumarry)
count = 0
while count < N - 1:
if sumarry[count] == sumarry[count + 1]:
flag = 1
break
count += 1
if flag == 0:
print("NO")
else:
print("YES") | FUNC_DEF ASSIGN VAR LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR LIST VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
t = int(input())
while t > 0:
t -= 1
n = int(input())
a = list(map(int, input().split()))
cur = [0]
for i in range(n):
cur = cur + [(x + a[i]) for x in cur] + [(x - a[i]) for x in cur]
print("YES" if sum(x == 0 for x in cur) > 1 else "NO") | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER STRING STRING |
You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$.
Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds?
For each $1 \le i \le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1 \le j, \, k \le n$) such that $a_i = b_j - b_k$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 20$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains one integer $n$ ($1 \le n \le 10$).
The second line of each test case contains the $n$ integers $a_1, \, \dots, \, a_n$ ($-10^5 \le a_i \le 10^5$).
-----Output-----
For each test case, output a line containing YES if a sequence $b_1, \, \dots, \, b_n$ satisfying the required property exists, and NO otherwise.
-----Examples-----
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
-----Note-----
In the first test case, the sequence $b = [-9, \, 2, \, 1, \, 3, \, -2]$ satisfies the property. Indeed, the following holds:
$a_1 = 4 = 2 - (-2) = b_2 - b_5$;
$a_2 = -7 = -9 - (-2) = b_1 - b_5$;
$a_3 = -1 = 1 - 2 = b_3 - b_2$;
$a_4 = 5 = 3 - (-2) = b_4 - b_5$;
$a_5 = 10 = 1 - (-9) = b_3 - b_1$.
In the second test case, it is sufficient to choose $b = [0]$, since $a_1 = 0 = 0 - 0 = b_1 - b_1$.
In the third test case, it is possible to show that no sequence $b$ of length $3$ satisfies the property. | def r(arr, pos=0, sum_=0):
if arr[pos] == sum_:
return True
if pos == len(arr) - 1:
return False
return any(r(arr, pos + 1, sum_ + x) for x in [0, arr[pos], -arr[pos]])
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
print("YES" if r(a) else "NO") | FUNC_DEF NUMBER NUMBER IF VAR VAR VAR RETURN NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR LIST NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | lm = int(1000000000000.0)
f = [1]
for i in range(2, 17):
if f[-1] * i < lm:
f.append(f[-1] * i)
d = []
def t(i, nb, s):
if i == 12:
if s < lm and bin(s).count("1") - nb > 0:
d.append([s, nb])
else:
t(i + 1, nb, s)
t(i + 1, nb + 1, s + f[i])
f = f[2:]
t(0, 0, 0)
d = sorted(d, key=lambda x: x[0])
for _ in range(int(input())):
n = int(input())
ans = bin(n).count("1")
for e in d:
if e[0] <= n:
ans = min(ans, e[1] + bin(n - e[0]).count("1"))
else:
break
print(ans) | ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | from itertools import combinations
def bit_count(value: int) -> int:
return f"{value:b}".count("1")
factorial = [1]
for _ in range(int(input())):
n = int(input())
while factorial[-1] <= n:
factorial.append(factorial[-1] * len(factorial))
factorial.pop()
result = float("inf")
for i in range(len(factorial) - 2):
for combination in combinations(factorial[2:], i):
if "1" in combination or "2" in combination:
continue
value = n - sum(combination)
if value < 0:
continue
result = min(result, i + bit_count(value))
if result == float("inf"):
result = 1
print(result) | FUNC_DEF VAR RETURN FUNC_CALL VAR STRING STRING VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR IF STRING VAR STRING VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | def get(good):
n = int(input())
ans = 10000.0
for x in good:
if n >= x[0]:
rem = n - x[0]
ans = min(ans, x[1] + bin(rem).count("1"))
print(ans)
good = [(0, 0)]
fact = []
c = 2
for i in range(3, 15):
c *= i
fact.append(c)
for f in fact:
good_no = []
for num in good:
good_no.append((num[0] + f, num[1] + 1))
good.extend(good_no)
for _ in range(int(input())):
get(good) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | from itertools import combinations
from sys import stdin
input = stdin.readline
l = []
a = 1
for i in range(1, 15):
a *= i
l.append(a)
for _ in range(int(input())):
n = int(input())
r = 100
for i in range(15):
for j in combinations(l, i):
s = n - sum(j)
if s >= 0:
r = min(r, i + bin(s).count("1"))
print(r) | ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | def factorials(n):
factorials_list = []
prod = 6
i = 4
while prod <= n:
factorials_list.append(prod)
prod *= i
i += 1
return factorials_list
def count(a):
ans = 9223372036854775807
for mask in range(1 << len(a)):
s = n
for i in range(len(a)):
s -= [0, a[i]][mask & 1 << i != 0]
if s < 0:
continue
ans = min(bin(mask).count("1") + bin(s).count("1"), ans)
return ans
for _ in range(int(input())):
n = int(input())
a = factorials(n)
print(count(a)) | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR LIST NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | def main_tc(good_numbers):
n = int(input())
answer = 10000
for good_number in good_numbers:
if n >= good_number[0]:
remaining = n - good_number[0]
answer = min(answer, good_number[1] + get_bit_count(remaining))
print(answer)
def get_bit_count(n):
answer = 0
while n > 0:
answer += n & 1
n >>= 1
return answer
def main():
tc = int(input())
good_numbers = [(0, 0)]
factorials = []
cur = 2
for i in range(3, 15):
cur *= i
factorials.append(cur)
for f in factorials:
extension_good_numbers = []
for number in good_numbers:
extension_good_numbers.append((number[0] + f, number[1] + 1))
good_numbers.extend(extension_good_numbers)
for _ in range(tc):
main_tc(good_numbers)
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | k, idx = 2, 3
fact = []
while k <= 1000000000000.0:
k *= idx
fact.append(k)
idx += 1
def fac(x):
for i in range(len(fact)):
if fact[i] > x:
return i
for _ in range(int(input())):
n = int(input())
i = fac(n)
ans = min(1000000000000000.0, bin(n).count("1"))
for j in range(1 << i):
s = 0
a1 = 0
for k in range(i):
if 1 << k & j:
s += fact[k]
a1 += 1
dif = n - s
if dif >= 0:
ans = min(ans, a1 + bin(dif).count("1"))
print(ans) | ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | fact = [1] * 15
subs = []
for i in range(1, 15):
fact[i] = fact[i - 1] * (i + 1)
for i in range(1 << 15):
sub, s = 0, 0
for j in range(15):
if i & 1 << j:
sub += 1
s += fact[j]
subs.append((sub, s))
for _ in range(int(input())):
n = int(input())
ans = bin(n).count("1")
for i in subs:
if i[1] <= n:
ans = min(ans, i[0] + bin(n - i[1]).count("1"))
print(ans) | ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | a = []
p = 1
for i in range(1, 15):
p *= i
if bin(p).count("1") > 1:
a.append(p)
T = int(input())
for t in range(T):
n = int(input())
ans = 10000000000
if n & n - 1 == 0 or n in a:
print(1)
continue
for i in range(1 << 12):
s = 0
for j in range(12):
if i & 1 << j:
s += a[j]
if s > n:
break
ans = min(ans, bin(i).count("1") + bin(n - s).count("1"))
print(ans) | ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR IF FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | import itertools
import sys
input = sys.stdin.readline
factorials = [
1,
2,
6,
24,
120,
720,
5040,
40320,
362880,
3628800,
39916800,
479001600,
6227020800,
87178291200,
]
powers = [
4,
8,
16,
32,
64,
128,
256,
512,
1024,
2048,
4096,
8192,
16384,
32768,
65536,
131072,
262144,
524288,
1048576,
2097152,
4194304,
8388608,
16777216,
33554432,
67108864,
134217728,
268435456,
536870912,
1073741824,
2147483648,
4294967296,
8589934592,
17179869184,
34359738368,
68719476736,
137438953472,
274877906944,
549755813888,
]
for i in range(int(input())):
num = int(input())
minn = bin(num).count("1")
if num in powers:
print(1)
else:
list1 = []
for i in range(1, 15):
list1.append(list(itertools.combinations(factorials, i)))
for i in list1:
for j in i:
imp = num - sum(j)
if imp == 0:
output = len(j)
if output < minn:
minn = output
elif imp > 0:
s = bin(imp)[2:]
output = len(j) + s.count("1")
if output < minn:
minn = output
print(minn) | IMPORT IMPORT ASSIGN VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | n = [0]
p = 1
for x in range(2, 16):
n.append(p)
p *= x
j = {}
for y in range(1, 2**15):
l = format(y, "015b")
s = 0
ll = 0
for z in range(14, -1, -1):
if l[z] == "1":
s += n[14 - z]
ll += 1
j[s] = ll
a = int(input())
for x in range(a):
b = int(input())
t = {}
ans = 999999999999999999
for y in j:
if y <= b:
t[format(b - y, "050b")] = j[y]
for y in t:
ans = min(ans, y.count("1") + t[y] - 1)
print(ans) | ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR STRING VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR STRING VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | def count(n, id):
if n == 0:
return 0
min_ = bin(n).count("1")
i = 0
while f[i] <= n and i < id:
min_ = min(min_, count(n - f[i], i) + 1)
i += 1
return min_
f = [1]
i = 2
while f[-1] < 10**12:
f.append(f[-1] * i)
i += 1
for t in range(int(input())):
print(count(int(input()), 20)) | FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | def fact(n):
p = 1
for j in range(1, n + 1):
p = p * j
return p
lst2 = []
lstfac = []
for k in range(1, 16):
lstfac.append(fact(k))
class py_solution:
def sub_sets(self, sset):
return self.subsetsRecur([], sorted(sset))
def subsetsRecur(self, current, sset):
if sset:
return self.subsetsRecur(current, sset[1:]) + self.subsetsRecur(
current + [sset[0]], sset[1:]
)
return [current]
lst1 = py_solution().sub_sets(lstfac)
lst2 = []
for h in lst1:
lst2.append((sum(h), len(h)))
def decimalToBinary(n):
return bin(n).replace("0b", "")
t = int(input())
for i in range(t):
n = int(input())
lstf = []
for f in lst2:
dif = n - f[0]
if dif >= 0:
s = decimalToBinary(dif)
c = s.count("1")
lstf.append(c + f[1])
print(min(lstf)) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_DEF IF VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR LIST VAR NUMBER VAR NUMBER RETURN LIST VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | from itertools import *
a = (1,)
r = range(14)
for i in r:
a += (a[-1] * (i + 1),)
b = [(i, sum(c)) for i in r for c in combinations(a, i)]
for n in [*map(int, open(0))][1:]:
print(min(m + bin(n - s).count("1") for m, s in b if s <= n))
lst = [] | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR STRING VAR VAR VAR VAR VAR ASSIGN VAR LIST |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline
facs = []
def fac(n):
if n <= 1:
return 1
else:
return n * fac(n - 1)
for i in range(14):
facs.append(fac(i + 1))
def answer(n, leftfacs):
if n == 0:
return 0
default = bin(n).count("1")
aux = [default]
for i in range(len(leftfacs)):
if leftfacs[i] > n:
break
newleftfacs = leftfacs[i + 1 :]
aux.append(answer(n - leftfacs[i], newleftfacs) + 1)
return min(aux)
for _ in range(int(input())):
n = int(input())
print(answer(n, facs)) | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | test = int(input())
factorial = []
subsets = [[]]
fact = 1
for i in range(1, 15):
fact *= i
factorial.append(fact)
for i in factorial:
l = len(subsets)
for j in range(l):
k = subsets[j].copy()
k.append(i)
subsets.append(k)
while test:
n = int(input())
ans = float("inf")
for i in subsets:
s = sum(i)
if s > n:
continue
ct = len(i)
b = bin(n - s)
if 1 in i and b[-1] == "1":
continue
elif 2 in i and b[-2] == "1":
continue
else:
ct += b.count("1")
ans = min(ans, ct)
print(ans)
test -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF NUMBER VAR VAR NUMBER STRING IF NUMBER VAR VAR NUMBER STRING VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For example $1$, $4$, and $6$ are powerful numbers, because $1=1!$, $4=2^2$, and $6=3!$ but $7$, $10$, or $18$ are not.
You are given a positive integer $n$. Find the minimum number $k$ such that $n$ can be represented as the sum of $k$ distinct powerful numbers, or say that there is no such $k$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
A test case consists of only one line, containing one integer $n$ ($1\le n\le 10^{12}$).
-----Output-----
For each test case print the answer on a separate line.
If $n$ can not be represented as the sum of distinct powerful numbers, print $-1$.
Otherwise, print a single positive integer β the minimum possible value of $k$.
-----Examples-----
Input
4
7
11
240
17179869184
Output
2
3
4
1
-----Note-----
In the first test case, $7$ can be represented as $7=1+6$, where $1$ and $6$ are powerful numbers. Because $7$ is not a powerful number, we know that the minimum possible value of $k$ in this case is $k=2$.
In the second test case, a possible way to represent $11$ as the sum of three powerful numbers is $11=1+4+6$. We can show that there is no way to represent $11$ as the sum of two or less powerful numbers.
In the third test case, $240$ can be represented as $240=24+32+64+120$. Observe that $240=120+120$ is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, $17179869184=2^{34}$, so $17179869184$ is a powerful number and the minimum $k$ in this case is $k=1$. | import sys
def input():
return sys.stdin.readline().rstrip()
def solution(n: int) -> int:
INF = 53
def backtrack(pos, cnt, cur_sum):
if cur_sum == n:
return cnt
elif cur_sum > n:
return INF
elif suffix_sum[pos] < n - cur_sum:
return INF
if pos == len(num_list):
return INF
return min(
backtrack(pos + 1, cnt + 1, cur_sum + num_list[pos]),
backtrack(pos + 1, cnt, cur_sum),
)
power_nums = set()
num = 2
while num <= n:
power_nums.add(num)
num *= 2
num = 1
i = 2
while num <= n:
power_nums.add(num)
num *= i
i += 1
num_list = sorted(list(power_nums))
suffix_sum = [0]
for num in num_list:
suffix_sum.append(suffix_sum[-1] + num)
suffix_sum.reverse()
num_list.reverse()
min_k = backtrack(0, 0, 0)
if min_k == INF:
return -1
else:
return min_k
def main():
t = int(input())
for tc in range(t):
n = int(input())
print(solution(n))
main() | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN VAR IF VAR VAR RETURN VAR IF VAR VAR BIN_OP VAR VAR RETURN VAR IF VAR FUNC_CALL VAR VAR RETURN VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR RETURN NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You are given n strings s_1, s_2, ..., s_{n} consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation s_{a}_{i}s_{b}_{i} is saved into a new string s_{n} + i (the operations are numbered starting from 1). After each operation you need to find the maximum positive integer k such that all possible strings consisting of 0 and 1 of length k (there are 2^{k} such strings) are substrings of the new string. If there is no such k, print 0.
-----Input-----
The first line contains single integer n (1 β€ n β€ 100)Β β the number of strings. The next n lines contain strings s_1, s_2, ..., s_{n} (1 β€ |s_{i}| β€ 100), one per line. The total length of strings is not greater than 100.
The next line contains single integer m (1 β€ m β€ 100)Β β the number of operations. m lines follow, each of them contains two integers a_{i} abd b_{i} (1 β€ a_{i}, b_{i} β€ n + i - 1)Β β the number of strings that are concatenated to form s_{n} + i.
-----Output-----
Print m lines, each should contain one integerΒ β the answer to the question after the corresponding operation.
-----Example-----
Input
5
01
10
101
11111
0
3
1 2
6 5
4 4
Output
1
2
0
-----Note-----
On the first operation, a new string "0110" is created. For k = 1 the two possible binary strings of length k are "0" and "1", they are substrings of the new string. For k = 2 and greater there exist strings of length k that do not appear in this string (for k = 2 such string is "00"). So the answer is 1.
On the second operation the string "01100" is created. Now all strings of length k = 2 are present.
On the third operation the string "1111111111" is created. There is no zero, so the answer is 0. | from sys import stdin, stdout
K = 20
def findAllStrings(s):
n = len(s)
sDict = {}
for i in range(1, K + 1):
sDict[i] = set()
for x in range(n - i + 1):
sDict[i].add(s[x : x + i])
return sDict
n = int(stdin.readline().rstrip())
stringDicts = []
stringEnd = []
stringBegin = []
for i in range(n):
s = stdin.readline().rstrip()
stringDicts.append(findAllStrings(s))
if len(s) < K:
stringEnd.append(s)
stringBegin.append(s)
else:
stringEnd.append(s[-20:])
stringBegin.append(s[:20])
m = int(stdin.readline().rstrip())
for _ in range(m):
a, b = map(int, stdin.readline().rstrip().split())
a -= 1
b -= 1
sDict1 = findAllStrings(stringEnd[a] + stringBegin[b])
sDict2 = stringDicts[a]
sDict3 = stringDicts[b]
sDict = {}
for i in range(1, K + 1):
sDict[i] = sDict1[i] | sDict2[i] | sDict3[i]
stringDicts.append(sDict)
for i in range(1, K + 1):
if len(sDict[i]) != 2**i:
print(i - 1)
break
if len(stringBegin[a]) < K and len(stringBegin[a]) + len(stringBegin[b]) < K:
stringBegin.append(stringBegin[a] + stringBegin[b])
elif len(stringBegin[a]) < K:
s = stringBegin[a] + stringBegin[b]
stringBegin.append(s[:K])
else:
stringBegin.append(stringBegin[a])
if len(stringEnd[b]) < K and len(stringEnd[a]) + len(stringEnd[b]) < K:
stringEnd.append(stringEnd[a] + stringEnd[b])
elif len(stringEnd[b]) < K:
s = stringEnd[a] + stringEnd[b]
stringEnd.append(s[-K:])
else:
stringEnd.append(stringEnd[b]) | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints:
You can move to the right or to the bottom only. Formally, from the cell ($i, j$) you may move to the cell ($i, j + 1$) or to the cell ($i + 1, j$). The target cell can't be outside of the grid. The xor of all the numbers on the path from the cell ($1, 1$) to the cell ($n, m$) must be equal to $k$ (xor operation is the bitwise exclusive OR, it is represented as '^' in Java or C++ and "xor" in Pascal).
Find the number of such paths in the given grid.
-----Input-----
The first line of the input contains three integers $n$, $m$ and $k$ ($1 \le n, m \le 20$, $0 \le k \le 10^{18}$) β the height and the width of the grid, and the number $k$.
The next $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line is $a_{i, j}$ ($0 \le a_{i, j} \le 10^{18}$).
-----Output-----
Print one integer β the number of paths from ($1, 1$) to ($n, m$) with xor sum equal to $k$.
-----Examples-----
Input
3 3 11
2 1 5
7 10 0
12 6 4
Output
3
Input
3 4 2
1 3 3 3
0 3 3 2
3 0 1 1
Output
5
Input
3 4 1000000000000000000
1 3 3 3
0 3 3 2
3 0 1 1
Output
0
-----Note-----
All the paths from the first example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$.
All the paths from the second example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$. | n, m, k = list(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(n)]
t = [[None for i in range(m)] for j in range(n)]
t2 = [[None for i in range(m)] for j in range(n)]
t[0][0] = {b[0][0]: 1}
for i in range(1, m):
t[0][i] = {(list(t[0][i - 1].keys())[0] ^ b[0][i]): 1}
for i in range(1, n):
t[i][0] = {(list(t[i - 1][0].keys())[0] ^ b[i][0]): 1}
limit = (n + m - 2) // 2
for i in range(1, n):
for j in range(1, m):
if i + j > limit:
continue
t[i][j] = {}
for num, cnt in t[i - 1][j].items():
t[i][j][num ^ b[i][j]] = cnt
for num, cnt in t[i][j - 1].items():
if num ^ b[i][j] in t[i][j].keys():
t[i][j][num ^ b[i][j]] += cnt
else:
t[i][j][num ^ b[i][j]] = cnt
for i in range(n):
for j in range(m):
if i + j == limit:
b[i][j] = 0
t2[n - 1][m - 1] = {b[n - 1][m - 1]: 1}
for i in range(m - 2, -1, -1):
t2[n - 1][i] = {(list(t2[n - 1][i + 1].keys())[0] ^ b[n - 1][i]): 1}
for i in range(n - 2, -1, -1):
t2[i][m - 1] = {(list(t2[i + 1][m - 1].keys())[0] ^ b[i][m - 1]): 1}
for i in range(n - 2, -1, -1):
for j in range(m - 2, -1, -1):
if i + j < limit:
continue
t2[i][j] = {}
for num, cnt in t2[i + 1][j].items():
t2[i][j][num ^ b[i][j]] = cnt
for num, cnt in t2[i][j + 1].items():
if num ^ b[i][j] in t2[i][j].keys():
t2[i][j][num ^ b[i][j]] += cnt
else:
t2[i][j][num ^ b[i][j]] = cnt
res = 0
for i in range(n):
for j in range(m):
if i + j != limit:
continue
tk = set(t[i][j].keys())
for k2 in t2[i][j].keys():
if k2 ^ k in tk:
res += t2[i][j][k2] * t[i][j][k2 ^ k]
print(res) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER DICT VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR DICT BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER DICT BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR DICT FOR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER DICT VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR DICT BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER DICT BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR DICT FOR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints:
You can move to the right or to the bottom only. Formally, from the cell ($i, j$) you may move to the cell ($i, j + 1$) or to the cell ($i + 1, j$). The target cell can't be outside of the grid. The xor of all the numbers on the path from the cell ($1, 1$) to the cell ($n, m$) must be equal to $k$ (xor operation is the bitwise exclusive OR, it is represented as '^' in Java or C++ and "xor" in Pascal).
Find the number of such paths in the given grid.
-----Input-----
The first line of the input contains three integers $n$, $m$ and $k$ ($1 \le n, m \le 20$, $0 \le k \le 10^{18}$) β the height and the width of the grid, and the number $k$.
The next $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line is $a_{i, j}$ ($0 \le a_{i, j} \le 10^{18}$).
-----Output-----
Print one integer β the number of paths from ($1, 1$) to ($n, m$) with xor sum equal to $k$.
-----Examples-----
Input
3 3 11
2 1 5
7 10 0
12 6 4
Output
3
Input
3 4 2
1 3 3 3
0 3 3 2
3 0 1 1
Output
5
Input
3 4 1000000000000000000
1 3 3 3
0 3 3 2
3 0 1 1
Output
0
-----Note-----
All the paths from the first example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$.
All the paths from the second example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$. | n, m, k = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
re = 0
half = (m + n - 2) // 2
d = [dict() for _ in range(22)]
def forward(i, j, value):
if i >= n or j >= m:
return
value ^= l[i][j]
if i + j == half:
if value in d[i]:
d[i][value] += 1
else:
d[i][value] = 1
return None
forward(i + 1, j, value)
forward(i, j + 1, value)
def backward(i, j, value):
if i < 0 or j < 0:
return
if i + j == half:
tmp = k ^ value
if tmp in d[i]:
nonlocal re
re += d[i][tmp]
return None
value ^= l[i][j]
backward(i - 1, j, value)
backward(i, j - 1, value)
forward(0, 0, 0)
backward(n - 1, m - 1, 0)
print(re) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR IF BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NONE EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR RETURN NONE VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints:
You can move to the right or to the bottom only. Formally, from the cell ($i, j$) you may move to the cell ($i, j + 1$) or to the cell ($i + 1, j$). The target cell can't be outside of the grid. The xor of all the numbers on the path from the cell ($1, 1$) to the cell ($n, m$) must be equal to $k$ (xor operation is the bitwise exclusive OR, it is represented as '^' in Java or C++ and "xor" in Pascal).
Find the number of such paths in the given grid.
-----Input-----
The first line of the input contains three integers $n$, $m$ and $k$ ($1 \le n, m \le 20$, $0 \le k \le 10^{18}$) β the height and the width of the grid, and the number $k$.
The next $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line is $a_{i, j}$ ($0 \le a_{i, j} \le 10^{18}$).
-----Output-----
Print one integer β the number of paths from ($1, 1$) to ($n, m$) with xor sum equal to $k$.
-----Examples-----
Input
3 3 11
2 1 5
7 10 0
12 6 4
Output
3
Input
3 4 2
1 3 3 3
0 3 3 2
3 0 1 1
Output
5
Input
3 4 1000000000000000000
1 3 3 3
0 3 3 2
3 0 1 1
Output
0
-----Note-----
All the paths from the first example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$.
All the paths from the second example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$. | d = {}
ans = 0
for i in range(22):
d[i] = {}
n, m, k = list(map(int, input().split()))
arr = [list(map(int, input().split())) for i in range(n)]
def check(x, y):
if x < 0 or x >= n or y < 0 or y >= m:
return False
else:
return True
def go(x, y, now):
if check(x, y) == False:
return
now ^= arr[x][y]
if x + y == m - 1:
if now in d[x]:
d[x][now] += 1
else:
d[x][now] = 1
return
go(x + 1, y, now)
go(x, y + 1, now)
def goRev(i, j, now):
if check(i, j) == False:
return
if i + j == m - 1:
cur = k ^ now
if cur in d[i]:
global ans
ans += d[i][cur]
return
now ^= arr[i][j]
goRev(i - 1, j, now)
goRev(i, j - 1, now)
go(0, 0, 0)
goRev(n - 1, m - 1, 0)
print(ans) | ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR NUMBER RETURN IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR RETURN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints:
You can move to the right or to the bottom only. Formally, from the cell ($i, j$) you may move to the cell ($i, j + 1$) or to the cell ($i + 1, j$). The target cell can't be outside of the grid. The xor of all the numbers on the path from the cell ($1, 1$) to the cell ($n, m$) must be equal to $k$ (xor operation is the bitwise exclusive OR, it is represented as '^' in Java or C++ and "xor" in Pascal).
Find the number of such paths in the given grid.
-----Input-----
The first line of the input contains three integers $n$, $m$ and $k$ ($1 \le n, m \le 20$, $0 \le k \le 10^{18}$) β the height and the width of the grid, and the number $k$.
The next $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line is $a_{i, j}$ ($0 \le a_{i, j} \le 10^{18}$).
-----Output-----
Print one integer β the number of paths from ($1, 1$) to ($n, m$) with xor sum equal to $k$.
-----Examples-----
Input
3 3 11
2 1 5
7 10 0
12 6 4
Output
3
Input
3 4 2
1 3 3 3
0 3 3 2
3 0 1 1
Output
5
Input
3 4 1000000000000000000
1 3 3 3
0 3 3 2
3 0 1 1
Output
0
-----Note-----
All the paths from the first example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$.
All the paths from the second example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$. | n, m, k = list(map(int, input().split()))
matrix = []
for _ in range(n):
row = list(map(int, input().split()))
matrix.append(row)
d = [[{} for _ in range(m)] for _ in range(n)]
middle = (n + m - 2) // 2
answer = 0
def upleft(x, y, acc, count):
val = matrix[y][x] ^ acc
if count == middle:
if d[y][x].get(val) == None:
d[y][x][val] = 1
return
else:
d[y][x][val] += 1
return
else:
if x + 1 < m:
upleft(x + 1, y, val, count + 1)
if y + 1 < n:
upleft(x, y + 1, val, count + 1)
def downright(x, y, acc, count):
nonlocal answer
if count == n + m - 2 - middle:
complement = k ^ acc
if d[y][x].get(complement) != None:
answer += d[y][x][complement]
return
else:
val = matrix[y][x] ^ acc
if x - 1 >= 0:
downright(x - 1, y, val, count + 1)
if y - 1 >= 0:
downright(x, y - 1, val, count + 1)
upleft(0, 0, 0, 0)
downright(m - 1, n - 1, 0, 0)
print(answer) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR VAR NONE ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR NUMBER RETURN IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR NONE VAR VAR VAR VAR VAR RETURN ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints:
You can move to the right or to the bottom only. Formally, from the cell ($i, j$) you may move to the cell ($i, j + 1$) or to the cell ($i + 1, j$). The target cell can't be outside of the grid. The xor of all the numbers on the path from the cell ($1, 1$) to the cell ($n, m$) must be equal to $k$ (xor operation is the bitwise exclusive OR, it is represented as '^' in Java or C++ and "xor" in Pascal).
Find the number of such paths in the given grid.
-----Input-----
The first line of the input contains three integers $n$, $m$ and $k$ ($1 \le n, m \le 20$, $0 \le k \le 10^{18}$) β the height and the width of the grid, and the number $k$.
The next $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line is $a_{i, j}$ ($0 \le a_{i, j} \le 10^{18}$).
-----Output-----
Print one integer β the number of paths from ($1, 1$) to ($n, m$) with xor sum equal to $k$.
-----Examples-----
Input
3 3 11
2 1 5
7 10 0
12 6 4
Output
3
Input
3 4 2
1 3 3 3
0 3 3 2
3 0 1 1
Output
5
Input
3 4 1000000000000000000
1 3 3 3
0 3 3 2
3 0 1 1
Output
0
-----Note-----
All the paths from the first example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$.
All the paths from the second example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$. | n, m, k = map(int, input().split())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
if n > m:
d = []
for i in range(m):
d.append([])
for j in range(n):
d[i].append(a[j][i])
a = d
n, m = m, n
b = []
for i in range(n):
temp = []
for j in range(m):
temp.append([])
b.append(temp)
for i in range((n + m) // 2):
for j in range(min(i + 1, m, n)):
if i == 0:
b[j][i - j].append(a[j][i - j])
elif j == 0:
b[j][i - j].append(b[j][i - j - 1][0] ^ a[j][i - j])
elif j == i:
b[j][i - j].append(b[j - 1][i - j][0] ^ a[j][i - j])
else:
for x in b[j][i - j - 1] + b[j - 1][i - j]:
b[j][i - j].append(x ^ a[j][i - j])
c = []
for i in range(n):
temp = []
for j in range(m):
temp.append([])
c.append(temp)
for i in range((n + m + 1) // 2):
for j in range(min(i + 1, m, n)):
if i == 0:
c[n - 1 - j][m - 1 - (i - j)].append(k)
elif j == 0:
c[n - 1 - j][m - 1 - (i - j)].append(
c[n - 1 - j][m - 1 - (i - j - 1)][0] ^ a[n - 1 - j][m - 1 - (i - j - 1)]
)
elif j == i:
c[n - 1 - j][m - 1 - (i - j)].append(
c[n - 1 - (j - 1)][m - 1 - (i - j)][0]
^ a[n - 1 - (j - 1)][m - 1 - (i - j)]
)
else:
for x in c[n - 1 - j][m - 1 - (i - j - 1)]:
c[n - 1 - j][m - 1 - (i - j)].append(
x ^ a[n - 1 - j][m - 1 - (i - j - 1)]
)
for x in c[n - 1 - (j - 1)][m - 1 - (i - j)]:
c[n - 1 - j][m - 1 - (i - j)].append(
x ^ a[n - 1 - (j - 1)][m - 1 - (i - j)]
)
wae = 0
i = (n + m) // 2 - 1
for j in range(min(m, n)):
d = {}
e = {}
for l1 in b[j][i - j]:
if not l1 in d:
d[l1] = 0
d[l1] += 1
for l2 in c[j][i - j]:
if not l2 in e:
e[l2] = 0
e[l2] += 1
for key in d.keys():
if key in d and key in e:
wae += d[key] * e[key]
print(wae) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR FOR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR FOR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints:
You can move to the right or to the bottom only. Formally, from the cell ($i, j$) you may move to the cell ($i, j + 1$) or to the cell ($i + 1, j$). The target cell can't be outside of the grid. The xor of all the numbers on the path from the cell ($1, 1$) to the cell ($n, m$) must be equal to $k$ (xor operation is the bitwise exclusive OR, it is represented as '^' in Java or C++ and "xor" in Pascal).
Find the number of such paths in the given grid.
-----Input-----
The first line of the input contains three integers $n$, $m$ and $k$ ($1 \le n, m \le 20$, $0 \le k \le 10^{18}$) β the height and the width of the grid, and the number $k$.
The next $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line is $a_{i, j}$ ($0 \le a_{i, j} \le 10^{18}$).
-----Output-----
Print one integer β the number of paths from ($1, 1$) to ($n, m$) with xor sum equal to $k$.
-----Examples-----
Input
3 3 11
2 1 5
7 10 0
12 6 4
Output
3
Input
3 4 2
1 3 3 3
0 3 3 2
3 0 1 1
Output
5
Input
3 4 1000000000000000000
1 3 3 3
0 3 3 2
3 0 1 1
Output
0
-----Note-----
All the paths from the first example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$.
All the paths from the second example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$. | def go_up_to_down(w, h, value, steps):
value ^= matrix[h][w]
if steps == half_steps:
if value not in counts[h][w]:
counts[h][w][value] = 0
counts[h][w][value] += 1
return
if w < width - 1:
go_up_to_down(w + 1, h, value, steps + 1)
if h < height - 1:
go_up_to_down(w, h + 1, value, steps + 1)
def go_down_to_up(w, h, value, steps, count_ways):
if steps == width + height - 2 - half_steps:
if value ^ res_find in counts[h][w]:
count_ways += counts[h][w][value ^ res_find]
return count_ways
delta = 0
if w > 0:
delta += go_down_to_up(w - 1, h, value ^ matrix[h][w], steps + 1, count_ways)
if h > 0:
delta += go_down_to_up(w, h - 1, value ^ matrix[h][w], steps + 1, count_ways)
return count_ways + delta
height, width, res_find = [int(num) for num in input().split()]
matrix = []
for h in range(height):
row = [int(num) for num in input().split()]
matrix.append(row)
counts = [([dict()] * width) for h in range(height)]
half_steps = (width + height - 2) // 2
go_up_to_down(0, 0, 0, 0)
count_ways = go_down_to_up(width - 1, height - 1, 0, 0, 0)
print(count_ways) | FUNC_DEF VAR VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
matrix = []
for i in range(n):
matrix.append([int(x) for x in input().split()])
all_1 = True
for row in matrix:
if len(set(row)) > 1:
all_1 = False
print("TAK")
break
if all_1:
v = 0
for row in matrix:
v ^= row[0]
if v == 0:
print("NIE")
else:
print("TAK")
print(*([1] * n))
else:
ans = [0] * n
v = 0
for row in matrix:
v ^= row[0]
if v == 0:
j = 0
for i in range(n):
row = matrix[i]
if len(set(row)) > 1:
j = i
break
for i in range(m):
if v ^ matrix[j][0] ^ matrix[j][i] != 0:
ans[j] = i
break
for a in ans:
print(a + 1, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
tab = []
for i in range(n):
a = map(int, input().split())
tab.append(list(a))
k = -1
for i in range(n):
s = set()
for j in range(m):
s.add(tab[i][j])
if len(s) > 1:
k = i
break
res = [1] * n
t = 0
for i in range(n):
if i != k:
t = t ^ tab[i][0]
if k == -1:
if t == 0:
print("NIE")
else:
print("TAK")
print(*res)
else:
for i in range(m):
if t ^ tab[k][i] != 0:
res[k] = i + 1
print("TAK")
print(*res)
break
else:
print("NIE") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
l = []
for i in range(n):
l += [list(map(int, input().split()))]
l1 = len(set(l[-1][:]))
s = []
for i in range(n):
s += [set(l[i])]
save = -1
for i in range(n):
if len(s[i]) > 1:
save = i
break
if save != -1:
print("TAK")
for j in range(m - 1):
if l[save][j] != l[save][j + 1]:
save1 = j
break
t = 0
for i in range(n):
if i != save:
t = (t | l[i][0]) & (~t | ~l[i][0])
else:
t = (t | l[i][save1]) & (~t | ~l[i][j])
if t != 0:
for i in range(n):
if i != save:
print("1", end=" ")
else:
print(j + 1, end=" ")
else:
for i in range(n):
if i != save:
print("1", end=" ")
else:
print(j + 1 + 1, end=" ")
else:
t = 0
for i in range(n):
t = (t | l[i][0]) & (~t | ~l[i][0])
if t == 0:
print("NIE")
exit()
print("TAK")
for i in range(n):
print("1", end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | import sys
n, m = [int(x) for x in input().split()]
a = [[] for i in range(n)]
for i in range(n):
a[i] = [int(x) for x in input().split()]
mask = 1
while mask <= 1024:
z, nz, both = 0, 0, 0
cur = [[] for i in range(n)]
for i in range(n):
j0, j1 = m, m
for j in range(m):
if a[i][j] & mask > 0:
j1 = j
else:
j0 = j
if j0 != m and j1 == m:
z += 1
elif j0 == m and j1 != m:
nz += 1
else:
both += 1
cur[i] = [j0, j1]
if nz % 2 == 1:
print("TAK")
ans = [0] * n
for i in range(n):
if cur[i][0] == m and cur[i][1] != m:
ans[i] = cur[i][1] + 1
else:
ans[i] = cur[i][0] + 1
print(*ans, sep=" ")
sys.exit()
if both > 0:
need = True
print("TAK")
ans = [0] * n
for i in range(n):
if cur[i][0] == m and cur[i][1] != m:
ans[i] = cur[i][1] + 1
elif cur[i][1] != m and need:
ans[i] = cur[i][1] + 1
need = False
else:
ans[i] = cur[i][0] + 1
print(*ans, sep=" ")
sys.exit()
mask *= 2
print("NIE") | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR LIST VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
flag = False
for sft in range(10):
b = [[(a[i][j] >> sft & 1) for j in range(m)] for i in range(n)]
must1 = 0
must0 = 0
for i in range(n):
for j in range(m):
if b[i][j] == 0:
break
else:
must1 += 1
for i in range(n):
for j in range(m):
if b[i][j] == 1:
break
else:
must0 += 1
if must1 == n and n % 2 == 1:
c = [(1) for i in range(n)]
print("TAK")
print(*c)
exit()
elif must1 == n and n % 2 == 0:
continue
elif must0 == n:
continue
elif must1 < n and must0 < n:
if must1 % 2 == 1:
c = []
for i in range(n):
flag = True
idx = -1
for j in range(m):
if b[i][j] == 0:
flag = False
idx = j
if flag:
c.append(1)
else:
c.append(idx + 1)
print("TAK")
print(*c)
exit()
elif must1 + must0 != n:
c = []
flag2 = True
for i in range(n):
flag = True
idx = -1
z = -1
for j in range(m):
if b[i][j] == 0:
flag = False
idx = j
elif z == -1:
z = j
if flag:
c.append(1)
elif z >= 0 and flag2:
c.append(z + 1)
flag2 = False
else:
c.append(idx + 1)
print("TAK")
print(*c)
exit()
print("NIE") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR IF VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF BIN_OP VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | import sys
n, m = list(map(int, input().split()))
A = []
for i in range(n):
A.append(list(map(int, input().split())))
initial = [0] * n
xx = 0
for i in range(len(initial)):
idx = initial[i]
xx = xx ^ A[i][idx]
if xx > 0:
print("TAK")
print(" ".join(list(map(lambda x: str(x + 1), initial))))
sys.exit(0)
else:
for i in range(0, n):
for j in range(1, m):
if A[i][j] != A[i][0]:
initial[i] = j
print("TAK")
print(" ".join(list(map(lambda x: str(x + 1), initial))))
sys.exit(0)
print("NIE") | IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
output = [1] * n
Xor = 0
lis = []
for i in range(n):
lis2 = list(map(int, input().split()))
Xor = Xor ^ lis2[0]
lis.append(lis2)
if Xor != 0:
print("TAK")
for i in output:
print(i, end=" ")
exit()
for i in range(n):
element = lis[i][0]
for j in range(1, m):
if lis[i][j] != element:
output[i] = j + 1
print("TAK")
for i in output:
print(i, end=" ")
exit()
print("NIE") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = list(map(int, input().split()))
res = 0
pair = None
row = -1
column = -1
for i in range(n):
tmp = list(map(int, input().split()))
if pair is None:
has_pair = False
for j in range(len(tmp) - 1):
if tmp[j] != tmp[j + 1]:
has_pair = True
pair = tmp[j], tmp[j + 1]
row = i
column = j
break
if not has_pair:
res ^= tmp[0]
else:
res ^= tmp[0]
if pair is None and res == 0:
print("NIE")
else:
selection = [1] * n
if pair is not None:
if pair[0] != res:
selection[row] = column + 1
else:
selection[row] = column + 2
print("TAK")
print(" ".join(list(map(str, selection)))) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NONE VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NONE IF VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | arr = input()
row, col = [int(x) for x in arr.split(" ")]
data = [([0] * col) for _ in range(row)]
for i in range(row):
arr = input()
arr = [int(x) for x in arr.split(" ")]
for j in range(col):
data[i][j] = arr[j]
res = 0
ans = [1] * row
for i in range(row):
res = res ^ data[i][0]
flag = 0
if res == 0:
for i in range(row):
for j in range(1, col):
if data[i][j] != data[i][0]:
flag = 1
ans[i] = j + 1
break
if flag == 1:
break
else:
flag = 1
if flag == 1:
print("TAK")
for num in ans:
print(num, end=" ")
else:
print("NIE") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = [int(t) for t in input().split()]
def xor(arr):
t = 0
for a in arr:
t = t ^ a
return t
a = []
win = False
j = 0
for i in range(n):
tmp = [int(t) for t in input().split()]
if len(set(tmp)) > 1:
win = True
j = i
a.append(tmp)
if not win:
if xor([t[0] for t in a]) == 0:
print("NIE")
else:
print("TAK")
print(" ".join(["1"] * n))
else:
print("TAK")
if xor([t[0] for t in a]) != 0:
print(" ".join(["1"] * n))
else:
ans = ["1"] * n
k = 1
while a[j][k] == a[j][0]:
k += 1
ans[j] = str(k + 1)
print(" ".join(ans)) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IF VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP LIST STRING VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | import sys
n, m = list(map(int, sys.stdin.readline().strip().split()))
L = [0] * n
ans = 0
for i in range(0, n):
row = list(map(int, sys.stdin.readline().strip().split()))
j = row[0]
l = -1
for k in range(0, m):
if row[k] != j:
l = k
L[i] = l
ans = ans ^ j
if ans != 0:
print("TAK")
print(("1 " * n).strip())
elif max(L) == -1:
print("NIE")
else:
for i in range(0, n):
if L[i] != -1:
j = i
print("TAK")
print("1 " * j + str(L[j] + 1) + (n - j - 1) * " 1") | IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL BIN_OP STRING VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
arr = [[] for _ in range(n)]
ans = [-1] * n
for i in range(n):
vis = set()
for j, c in enumerate(list(map(int, input().split()))):
if c not in vis:
arr[i].append([c, i, j + 1])
vis.add(c)
arr.sort(key=lambda x: len(x))
def dfs(cur, p):
if cur == n:
if p > 0:
return True
return False
for v, row, col in arr[cur]:
ans[row] = col
if dfs(cur + 1, p ^ v):
return True
ans[row] = -1
return False
if dfs(0, 0):
print("TAK")
print(*ans)
else:
print("NIE") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR LIST VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | def fun():
n, m = (int(x) for x in input().split())
matrix = []
answer = 0
for i in range(n):
line = [int(x) for x in input().split()]
answer ^= line[0]
matrix.append(line)
if answer > 0:
print("TAK")
values = n * [1]
print(*values)
return
else:
for i in range(n):
j = 1
while j < m:
if matrix[i][j] != matrix[i][0]:
print("TAK")
values = []
for k in range(n):
if k != i:
values.append(1)
else:
values.append(j + 1)
print(*values)
return
j += 1
print("NIE")
fun() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR LIST NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
a, xor, b = [], 0, [1] * n
for i in range(n):
a.append(list(map(int, input().split())))
xor = xor ^ a[i][0]
for i in range(n):
for j in range(m):
if xor ^ a[i][0] ^ a[i][j] != 0:
b[i] = j + 1
print("TAK")
exit(print(*b))
print("NIE") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | x = input().split()
n = int(x[0])
m = int(x[1])
can = 0
lines = []
for i in range(n):
lines.append(input().split())
for i in range(n):
l = set(lines[i])
if len(l) > 1:
can = 1
break
result = 0
first_zero = 0
for i in range(n):
result = result ^ int(lines[i][0])
if result == 0:
first_zero = 1
if can == 0:
if first_zero == 1:
print("NIE")
else:
print("TAK")
x = ""
for i in range(n - 1):
x = x + "1" + " "
x += "1"
print(x)
else:
print("TAK")
if first_zero == 0:
x = ""
for i in range(n - 1):
x = x + "1" + " "
x += "1"
print(x)
else:
alright = 0
x = ""
for i in range(n):
for j in range(m - 1):
if lines[i][j] != lines[i][j + 1]:
x += str(j + 2) + " "
alright = 1
break
if alright == 1:
for j in range(n - i - 1):
x += "1 "
break
else:
x += "1" + " "
print(x[: len(x) - 1]) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING STRING VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING STRING VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING VAR BIN_OP STRING STRING EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | x = []
n, m = list(map(int, input().strip().split()))
def find(i, p):
if i == n:
return p, []
for j in x[i]:
v, path = find(i + 1, p ^ j)
if v:
path.append(x[i][j])
return v, path
return 0, []
for i in range(n):
p = map(int, input().strip().split())
p = {v: i for i, v in enumerate(p)}
x.append(p)
v, ans = find(0, 0)
if v != 0:
ans = " ".join(map(lambda x: str(x + 1), reversed(ans)))
print("TAK")
print(ans)
else:
print("NIE") | ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN VAR LIST FOR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR RETURN NUMBER LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | sizeI, sizeJ = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(sizeI)]
ret = [0] * sizeI
xor = 0
for i in range(sizeI):
xor ^= a[i][0]
for i in range(sizeI):
if xor > 0:
break
for j in range(sizeJ):
if xor ^ a[i][0] ^ a[i][j] > 0:
ret[i] = j
xor ^= a[i][0] ^ a[i][j]
break
if xor == 0:
print("NIE")
else:
print("TAK")
print(*map(lambda x: x + 1, ret)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
a = []
k = 0
ans = 0
for i in range(n):
a.append(list(map(int, input().split())))
ans ^= a[i][0]
if len(set(a[i])) > len(set(a[k])):
k = i
b = 0
for i in range(m):
if ans ^ a[k][b] ^ a[k][i] != 0:
ans ^= a[k][b] ^ a[k][i]
b = i
if ans == 0:
print("NIE")
else:
print("TAK")
for i in range(n):
if i == k:
print(b + 1, end=" ")
else:
print(1, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
a = [[int(s) for s in input().split()] for i in range(n)]
ans = [1] * n
x = a[0][0]
for i in range(1, n):
x ^= a[i][0]
if x:
print("TAK")
print(*ans)
else:
flag = False
for i in range(n):
if len(set(a[i])) > 1:
flag = True
for j in range(m):
if a[i][j] != a[i][0]:
ans[i] = j + 1
break
break
if not flag:
print("NIE")
else:
print("TAK")
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
g = []
r_mult = -1
for i in range(n):
r = [int(s) for s in input().split()]
dist = {}
for j, v in enumerate(r):
if v not in dist:
dist[v] = j + 1
r = [(v, dist[v]) for v in dist]
if len(r) > 1 and r_mult == -1:
r_mult = i
g.append(r)
sum0 = 0
has_ans = False
for i in range(n):
sum0 ^= g[i][0][0]
if sum0 > 0 or r_mult != -1:
has_ans = True
if has_ans:
ans = []
for i in range(n):
to_app = g[i][0][1]
if sum0 == 0 and r_mult != -1 and i == r_mult:
to_app = g[i][1][1]
ans.append(to_app)
print("TAK")
print(*ans)
else:
print("NIE") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
dp = [[int(i) for i in input().split()] for j in range(n)]
res = 0
for i in range(n):
res ^= dp[i][0]
if res:
print("TAK")
print(*([1] * n))
else:
resa = [1] * n
for i in range(n):
for j in range(m):
if dp[i][0] != dp[i][j]:
resa[i] = j + 1
print("TAK")
print(*resa)
exit()
print("NIE") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
mat = []
lis = []
ans = []
k = 0
cur = 0
for i in range(n):
temp = list(map(int, input().split()))
mat.append(temp)
for i in range(n):
cur ^= mat[i][0]
ans.append(1)
for i in range(n):
if cur > 0:
break
for j in range(1, m):
if cur ^ mat[i][0] ^ mat[i][j] > 0:
ans[i] = j + 1
cur ^= mat[i][0] ^ mat[i][j]
break
if cur == 0:
print("NIE")
else:
print("TAK")
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | r, c = list(map(int, input().split()))
arr = []
for i in range(r):
lista = list(map(int, input().split()))
arr.append(lista)
a = 0
ans = [(1) for i in range(r)]
for i in range(r):
a = a ^ arr[i][0]
flag = 0
if a > 0:
print("TAK")
print(*ans)
elif a == 0:
for i in range(r):
for j in range(1, c):
if arr[i][0] != arr[i][j]:
flag = 1
ans[i] = j + 1
break
if flag == 1:
break
if flag == 0:
print("NIE")
else:
print("TAK")
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
a = [(0) for j in range(n)]
for i in range(n):
a[i] = list(map(int, input().split()))
c = [1] * n
xor = 0
for i in range(n):
xor = xor ^ a[i][c[i] - 1]
for i in range(n):
flag = False
for j in range(1, m + 1):
cold = c[i]
c[i] = j
xor = xor ^ a[i][cold - 1]
xor = xor ^ a[i][c[i] - 1]
if xor != 0:
print("TAK")
print(*c)
flag = True
break
if flag:
break
else:
print("NIE") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | import sys
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
x = 0
for r in a:
x ^= r[0]
ans = [1] * n
for i in range(n):
for j in range(m):
if x ^ a[i][0] ^ a[i][j]:
ans[i] = j + 1
print("TAK")
print(*ans)
sys.exit(0)
print("NIE") | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = (int(x) for x in input().split())
matrix = [[int(x) for x in input().split()] for _ in range(n)]
my_xor = 0
ans = [(1) for _ in range(n)]
for i in range(n):
my_xor ^= matrix[i][0]
if my_xor > 0:
print("TAK")
print(*ans)
quit()
for i in range(n):
s = set(matrix[i])
if len(s) > 1:
my_xor ^= matrix[i][0]
s.remove(matrix[i][0])
for j in range(1, m):
if matrix[i][j] in s:
s.remove(matrix[i][j])
my_xor ^= matrix[i][j]
if my_xor > 0:
ans[i] = j + 1
print("TAK")
print(*ans)
quit()
my_xor ^= matrix[i][j]
print("NIE") | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
A = []
T = False
ind = -1
for i in range(n):
B = list(map(int, input().split()))
if len(set(B)) > 1:
T = True
ind = i
A.append(B)
if T:
print("TAK")
ans = 0
for i in range(n):
if i != ind:
ans ^= A[i][0]
for j in range(m):
if ans ^ A[ind][j] > 0:
for i in range(n):
if i == ind:
print(j + 1, end=" ")
else:
print(1, end=" ")
break
else:
ans = 0
for i in range(n):
ans ^= A[i][0]
if ans != 0:
print("TAK")
for i in range(n):
print(1, end=" ")
else:
print("NIE") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = list(map(int, input().split()))
x = []
d = []
for i in range(n):
y = list(map(int, input().split()))
x.append(y)
d.append(set(y))
ans = [1] * n
s = x[0][0]
for i in range(1, n):
s = s ^ x[i][0]
if s == 0:
j = -1
for i in range(n):
if len(d[i]) != 1:
j = i
break
if j == -1:
print("NIE")
else:
print("TAK")
z = 1
for i in range(m):
if x[j][i] != x[j][0]:
z = i + 1
ans[j] = z
break
print(*ans)
else:
print("TAK")
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = map(int, input().split())
t = [list(map(int, input().split())) for _ in range(n)]
for i in range(10):
m = 1 << i
is_zero = [all(i & m == 0 for i in row) for row in t]
is_one = [all(i & m != 0 for i in row) for row in t]
zero = is_zero.count(True)
one = is_one.count(True)
needed = 1 - one % 2
ok = n - zero - one >= needed
if not ok:
continue
print("TAK")
for y, row in enumerate(t):
if is_zero[y] or is_one[y]:
print(1, end=" ")
continue
for i, e in enumerate(row):
if needed and e & m != 0:
print(i + 1, end=" ")
needed -= 1
break
elif not needed and e & m == 0:
print(i + 1, end=" ")
break
break
else:
print("NIE") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | n, m = [int(i) for i in input().split()]
l = [[] for i in range(n)]
for i in range(n):
l[i] = [int(j) for j in input().split()]
l1 = []
for i in range(n):
l1.append(l[i][0])
xv = 0
for i in range(n):
xv = xv ^ l1[i]
if xv > 0:
print("TAK")
for k in range(n):
print(1, end=" ")
exit(0)
t1 = 0
t2 = 0
for i in range(n):
t1 = xv
t1 = t1 ^ l[i][0]
for j in range(m):
t2 = t1
t2 = t2 ^ l[i][j]
if t2 > 0:
print("TAK")
for k in range(n):
if i == k:
print(j + 1, end=" ")
else:
print(1, end=" ")
exit(0)
print("NIE") | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | def main():
n, m = map(int, input().split())
l = []
for i in range(n):
l.append(list(map(int, input().split())))
xor = 0
for i in range(n):
xor ^= l[i][0]
pos = [0] * n
if xor == 0:
for i in range(n):
for j in range(m):
if l[i][j] != l[i][0]:
pos[i] = j
print("TAK" + "\n" + " ".join([str(ch + 1) for ch in pos]))
return
if xor == 0:
print("NIE")
else:
print("TAK" + "\n" + " ".join([str(ch + 1) for ch in pos]))
main() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING STRING FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING STRING FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | import sys
input = sys.stdin.readline
for _ in range(1):
n, m = map(int, input().split())
mat = []
available = [0] * 11
filled = [0] * 11
sep = [0] * 11
for i in range(n):
l = list(map(int, input().split()))
mat.append(l)
cnt = [0] * 11
for x in l:
w = bin(x)[2:][::-1]
for e in range(len(w)):
if w[e] == "1":
available[e] = 1
cnt[e] += 1
for r in range(len(cnt)):
w = cnt[r]
if w == m:
filled[r] += 1
continue
if w > 0:
sep[r] = 1
flag = 0
ans = []
for i in range(len(available)):
x = available[i]
if x == 0:
continue
if filled[i] % 2 == 0 and sep[i] == 0:
continue
if filled[i] == 0:
v = 0
for r in range(n):
z = 0
q = 0
for c in range(m):
g = mat[r][c]
w = bin(g)[2:]
toadd = 11 - len(w)
w = "0" * toadd + w
w = w[::-1]
if w[i] == "0":
z = c + 1
else:
q = c + 1
if v == 0 and q != 0:
v = 1
ans.append(q)
else:
ans.append(z)
flag = 1
break
if filled[i] % 2 == 1:
for r in range(n):
f = 1
z = 0
for c in range(m):
g = mat[r][c]
w = bin(g)[2:]
toadd = 11 - len(w)
w = "0" * toadd + w
w = w[::-1]
if w[i] == "0":
f = 0
z = c + 1
if f == 1:
ans.append(1)
else:
ans.append(z)
else:
v = 0
for r in range(n):
f = 1
z = 0
q = 0
for c in range(m):
g = mat[r][c]
w = bin(g)[2:]
toadd = 11 - len(w)
w = "0" * toadd + w
w = w[::-1]
if w[i] == "0":
f = 0
z = c + 1
else:
q = c + 1
if f == 1:
ans.append(1)
elif v == 0 and q != 0:
v = 1
ans.append(q)
else:
ans.append(z)
flag = 1
break
if flag == 0:
print("NIE")
else:
print("TAK")
print(*ans) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ans = [1] * n
res = 0
for i in range(n):
res ^= a[i][0]
if res != 0:
print("TAK")
print(*ans)
exit()
for i in range(n):
res ^= a[i][0]
for j in range(m):
res ^= a[i][j]
if res != 0:
ans[i] = j + 1
print("TAK")
print(*ans)
exit()
res ^= a[i][j]
res ^= a[i][0]
print("NIE") | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING |
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$)Β β the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found. | X = list(map(int, input().split()))
Answer = [1] * X[0]
Check = False
Index = 0
SequenceNumber = 0
SUMXOR = 0
for _ in range(X[0]):
Temp = list(map(int, input().split()))
SUMXOR ^= Temp[0]
if not Check:
if Temp.count(Temp[0]) != X[1]:
Check = True
SequenceNumber = _
for i in range(X[1]):
if Temp[i] != Temp[0]:
Index = i + 1
break
if SUMXOR == 0 and not Check:
print("NIE")
exit()
if SUMXOR != 0:
print("TAK")
print(*Answer)
exit()
print("TAK")
Answer[SequenceNumber] = Index
print(*Answer) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER IF VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.