description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
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.
s = input() cuv = "" for c in s: if c != " ": cuv += c else: n = int(cuv) cuv = "" m = int(cuv) mat = [[]] ok = False row = 0 col = 0 for i in range(n): mat.append([]) cnt = -1 cuv = "" s = input() for c in s: if c != " ": cuv += c else: mat[i].append(int(cuv)) cuv = "" cnt += 1 if mat[i][cnt] != mat[i][0]: row = i col = cnt ok = True mat[i].append(int(cuv)) cnt += 1 if mat[i][cnt] != mat[i][0]: row = i col = cnt ok = True if ok: print("TAK\n") result1 = 0 result2 = 0 r1 = "" r2 = "" for i in range(n): result1 = result1 ^ mat[i][0] r1 += str(1) + " " if i == row: result2 = result2 ^ mat[i][col] r2 += str(col + 1) + " " else: result2 = result2 ^ mat[i][0] r2 += str(1) + " " if result1 > 0: print(r1) else: print(r2) else: result1 = 0 r1 = "" for i in range(n): result1 = result1 ^ mat[i][0] r1 += str(1) + " " if result1 > 0: print("TAK\n") print(r1) else: print("NIE")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER STRING IF 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.
def put(): return map(int, input().split()) n, m = put() l = [] xor = 0 for i in range(n): l.append(list(put())) xor ^= l[-1][0] ans = [1] * n if xor == 0: found = False for i in range(n): for j in range(1, m): if xor ^ l[i][0] ^ l[i][j] != 0: ans[i] = j + 1 found = True xor = xor ^ l[i][0] ^ l[i][j] break if found: break if xor == 0: print("NIE") else: print("TAK") print(*ans)
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR 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 ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR IF 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.
n, m = list(map(int, input().split())) arr = [] xor = 0 for i in range(n): d = list(map(int, input().split())) if i == 0: xor = d[0] else: xor ^= d[0] arr.append(d) if xor != 0: print("TAK") print("1 " * n) else: ans = [1] * n fl = False for i in range(n): for g in range(1, m): if arr[i][g] != arr[i][0]: ans[i] = g + 1 fl = True break if fl: break if fl: print("TAK") print(*ans) else: print("NIE")
ASSIGN VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR IF 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.
import sys n, m = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(n)] kek = False for x in arr: for i in range(m - 1): if x[i] != x[i + 1]: kek = True val = 0 for i in range(n): val ^= arr[i][0] if val > 0: print("TAK") print("1 " * n) sys.exit(0) if not kek and val == 0: print("NIE") sys.exit(0) for i in range(n): for j in range(m - 1): if arr[i][j] != arr[i][j + 1]: print("TAK") print("1 " * i + str(j + 2) + " " + "1 " * (n - i - 1)) sys.exit(0)
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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER 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 BIN_OP STRING VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER 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 EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL 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.
def in_int(): return int(input()) def in_list(): return [int(x) for x in input().split()] n, m = in_list() mat = [] first = -1 for i in range(n): mat.append(in_list()) if first == -1: for j in range(m - 1): if mat[-1][j] != mat[-1][j + 1]: first = i, j break if first == -1: ans = 0 for i in range(n): ans = ans ^ mat[i][0] if ans > 0: print("TAK") print(" ".join(["1"] * n)) else: print("NIE") else: r, c = first print("TAK") ans = 0 for i in range(n): if i != r: ans = ans ^ mat[i][0] else: ans = ans ^ mat[i][c] if ans > 0: for i in range(n): if i != r: print(0 + 1, end=" ") else: print(c + 1, end=" ") else: for i in range(n): if i != r: print(0 + 1, end=" ") else: print(c + 2, end=" ")
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP LIST STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER STRING 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.
import sys input = sys.stdin.readline n, m = list(map(int, input().strip().split())) mat = [] for i in range(n): mat.append(list(map(int, input().strip().split()))) se = set() for x in mat: for y in x: se.add(y) if n == 1: val = False ans = None for x in range(m): if mat[0][x] != 0: ans = x + 1 val = True break if val: print("TAK") print(ans) else: print("NIE") elif len(se) == 1: print("NIE") else: ans = set() an = [] for i in range(n): if len(ans) < 2: found = False for j in range(m): if mat[i][j] not in ans: found = True ans.add(mat[i][j]) an.append(j + 1) break if not found: ans.add(mat[i][0]) an.append(1) else: an.append(1) xr = 0 for i in range(n): xr ^= mat[i][an[i] - 1] if xr != 0: print("TAK") print(" ".join(map(str, an))) else: ex = False for i in range(n): cur = an[i] for j in range(m): if j != cur - 1: if ex ^ mat[i][cur - 1] ^ mat[i][j] != 0: an[i] = j + 1 ex = True break if ex: break if ex: print("TAK") print(" ".join(map(str, an))) else: print("NIE")
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL 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.
import sys input = sys.stdin.readline def ceil(x): if x != int(x): x = int(x) + 1 return x def swaparr(arr, a, b): temp = arr[a] arr[a] = arr[b] arr[b] = temp def gcd(a, b): if b == 0: return a return gcd(b, a % b) def nCr(n, k): if k > n - k: k = n - k res = 1 for i in range(k): res = res * (n - i) res = res / (i + 1) return int(res) def upper_bound(a, x, lo=0, hi=None): if hi == None: hi = len(a) while lo < hi: mid = (lo + hi) // 2 if a[mid] < x: lo = mid + 1 else: hi = mid return lo def primefs(n): primes = {} while n % 2 == 0 and n > 0: primes[2] = primes.get(2, 0) + 1 n = n // 2 for i in range(3, int(n**0.5) + 2, 2): while n % i == 0 and n > 0: primes[i] = primes.get(i, 0) + 1 n = n // i if n > 2: primes[n] = primes.get(n, 0) + 1 return primes def power(x, y, p): res = 1 x = x % p if x == 0: return 0 while y > 0: if y & 1 == 1: res = res * x % p y = y >> 1 x = x * x % p return res def swap(a, b): temp = a a = b b = temp return a, b def find(x, link): p = x while p != link[p]: p = link[p] while x != p: nex = link[x] link[x] = p x = nex return p def union(x, y, link, size): x = find(x, link) y = find(y, link) if size[x] < size[y]: x, y = swap(x, y) if x != y: size[x] += size[y] link[y] = x def sieve(n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 return prime MAXN = int(100000.0 + 5) def spf_sieve(): spf[1] = 1 for i in range(2, MAXN): spf[i] = i for i in range(4, MAXN, 2): spf[i] = 2 for i in range(3, ceil(MAXN**0.5), 2): if spf[i] == i: for j in range(i * i, MAXN, i): if spf[j] == j: spf[j] = i def factoriazation(x): ret = {} while x != 1: ret[spf[x]] = ret.get(spf[x], 0) + 1 x = x // spf[x] return ret def int_array(): return list(map(int, input().strip().split())) def float_array(): return list(map(float, input().strip().split())) def str_array(): return input().strip().split() MOD = int(1000000000.0) + 7 CMOD = 998244353 INF = float("inf") NINF = -float("inf") def xor(nums): x = 0 for i in nums: x ^= i return x n, m = int_array() a = [] for _ in range(n): a.append(int_array()) ans = [0] * n nums = [None] * n for i in range(n): nums[i] = a[i][ans[i]] if xor(nums) != 0: for i in range(n): ans[i] += 1 print("TAK") print(*ans) exit() f = 0 for i in range(n): if f: break x = a[i][0] for j in range(1, m): if a[i][j] != x: f = 1 ans[i] = j break if f: for i in range(n): ans[i] += 1 print("TAK") print(*ans) else: print("NIE")
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF NUMBER NONE IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR DICT WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN 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 FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR FOR VAR FUNC_CALL VAR VAR VAR 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.
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) a = [None] * n d = [None] * n for i in range(n): a[i] = input().split() d[i] = list(map(int, set(a[i]))) a[i] = list(map(int, a[i])) def func(x, c, b): if len(c) == 0: if x != 0: print("TAK") print(*[(a[i].index(d[i][b[i]]) + 1) for i in range(len(b))]) return True else: return False for i, y in enumerate(c[0]): if func(x ^ y, c[1:], b + [i]): return True return False if not func(0, d, []): print("NIE")
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR LIST VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR NUMBER VAR LIST 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()) alt_i = 0 alt = 0 res = [] srt = True xr = 0 for _ in range(n): inp = {} j = 1 for inp1 in map(int, input().split()): inp[inp1] = j j += 1 inp1 = next(iter(inp.keys())) res.append(inp[inp1]) del inp[inp1] xr ^= inp1 if srt: if inp: alt = inp[next(iter(inp.keys()))] srt = False else: alt_i += 1 if not (srt or xr): res[alt_i] = alt xr = 1 if xr: print("TAK") print(*res) else: print("NIE")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR IF VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF 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.
R = lambda: map(int, input().split()) n, m = R() a = [[*R()] for _ in [0] * n] s = i = 0 for r in a: s ^= r[0] t = [1] * n for r in a: j = 0 for x in r: if s ^ r[0] ^ x: t[i] = j + 1 print("TAK", *t) exit() j += 1 i += 1 print("NIE")
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR VAR NUMBER 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.
answer = False path = list() def recur(num, list1, height, n): global answer global path global lists if answer: return if height == n: if num != 0: path = list1 answer = True return s = list(lists[height]) for x in s: recur(num ^ x, list1 + [x], height + 1, n) n, m = map(int, input().split()) lists = [0] * n lists2 = [0] * n for i in range(0, n): b = list(map(int, input().split())) g = set(b) lists[i] = g lists2[i] = b answer = False recur(0, list(), 0, n) print("NIE" if not answer else "TAK") x = "" if answer: for i in range(0, len(path)): x += str(lists2[i].index(path[i]) + 1) + " " print(x.strip(), end="")
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR RETURN IF VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR LIST VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR STRING STRING ASSIGN VAR STRING IF VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR 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())) T = [[] for i in range(n)] x = 0 d = [1] * n for i in range(n): a = list(map(int, input().split())) T[i] = a x ^= a[0] for i in range(n): for j in range(m): if x ^ T[i][0] ^ T[i][j] != 0: print("TAK") d[i] = j + 1 print(*d) exit() print("NIE")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR 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 EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER 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()) a = [[*map(int, input().split())] for _ in range(n)] for b in range(10): inds = [] for r in range(n): i = [-1, -1] for c in range(m): i[a[r][c] >> b & 1] = c inds.append(i) tot = 0 opt = -1 for r in range(n): if -1 not in inds[r]: opt = r tot += inds[r][0] == -1 tot &= 1 if tot == 0 and opt == -1: continue print("TAK") ans = [] for r in range(n): if opt == r and tot == 0: ans.append(inds[r][1] + 1) else: ans.append(inds[r][inds[r][0] == -1] + 1) print(*ans) break else: print("NIE")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER NUMBER 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 groupxor(l): result = 0 for item in l: result = result ^ item return result r, c = [int(x) for x in input().split()] rows = [] for _ in range(r): rows.append([int(x) for x in input().split()]) starts = [rows[j][0] for j in range(r)] result = [1] * r if groupxor(starts) == 0: notfixed = True for j in range(r): for k in range(1, c): if notfixed: if rows[j][0] != rows[j][k]: notfixed = False result[j] = k + 1 if notfixed == True: print("NIE") else: print("TAK") print(" ".join([str(x) for x in result])) else: print("TAK") print(" ".join([str(x) for x in result]))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR 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.
n, m = map(int, input().split()) c = [] for i in range(n): c.append(list(map(int, input().split()))) nieflag = 1 for a in range(11): bit0row = 0 bit1row = 0 bit0rowlist = [] bit1rowlist = [] for i in range(n): bit1 = 0 bit0 = 0 for j in range(m): if c[i][j] % 2 == 1: bit1 += 1 else: bit0 += 1 if bit1 == m: bit1row += 1 bit1rowlist.append(i) elif bit0 == m: bit0row += 1 bit0rowlist.append(i) if bit1row == n and n % 2 == 0: for i in range(n): for j in range(m): c[i][j] //= 2 continue elif bit0row == n: for i in range(n): for j in range(m): c[i][j] //= 2 continue elif bit1row + bit0row == n and bit1row % 2 == 0: for i in range(n): for j in range(m): c[i][j] //= 2 continue else: nieflag = 0 break if nieflag == 1: print("NIE") else: print("TAK") ans = [] if bit1row % 2 == 1: for i in range(n): if i in bit1rowlist: ans.append(1) elif i in bit0rowlist: ans.append(1) else: for j in range(m): if c[i][j] % 2 == 0: ans.append(j + 1) break else: flag = 0 for i in range(n): if i in bit1rowlist: ans.append(1) elif i in bit0rowlist: ans.append(1) elif flag == 1: for j in range(m): if c[i][j] % 2 == 0: ans.append(j + 1) break else: for j in range(m): if c[i][j] % 2 == 1: ans.append(j + 1) flag = 1 break print(" ".join(map(str, ans)))
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING 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.
n, m = [int(i) for i in input().split()] a = [[int(i) for i in input().split()] for _ in range(n)] def test(a, n, m): for i in range(n): _or, _and = a[i][0], a[i][0] for j in range(m): _or |= a[i][j] _and &= a[i][j] if _or != _and: return i return -1 t = test(a, n, m) if t == -1: _xor = 0 for i in range(n): _xor ^= a[i][0] if _xor > 0: print("TAK") print(" ".join("1" for _ in range(n))) exit() else: _xor = 0 for i in range(n): if i == t: continue _xor ^= a[i][0] for j in range(m): if _xor ^ a[t][j] > 0: print("TAK") print(" ".join([("1" if k != t else str(j + 1)) for k in range(n)])) exit() 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 FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER 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 FUNC_CALL STRING STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR 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.
def goDeep(index, currvals): if index == n: v = 0 for i in range(n): v ^= currvals[i] if v != 0: print("TAK") tbp = [-1] * n for i in range(n): tbp[i] = str(grid[i].index(currvals[i]) + 1) print(*tbp) exit() return for val in sets[index]: currvals[index] = val goDeep(index + 1, currvals) kk = lambda: map(int, input().split()) ll = lambda: list(kk()) n, m = kk() grid, sets = [None] * n, [None] * n for i in range(n): ls = ll() grid[i] = ls sets[i] = set(ls) goDeep(0, [0] * n) print("NIE")
FUNC_DEF IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN FOR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NONE VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP LIST NUMBER 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 = [int(i) for i in input().split()] a = [] for i in range(n): a.append([int(j) for j in input().split()]) arr = [] xor = 0 for i in range(n): xor ^= a[i][0] arr.append(1) if xor: print("TAK") print(*arr) else: flag = 0 for i in range(n): val = xor val ^= a[i][0] for j in range(1, m): if val ^ a[i][j] > 0: flag = 1 arr[i] = j + 1 break if flag: break if flag: print("TAK") print(*arr) else: print("NIE")
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR IF 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.
H, W = map(int, input().split()) A = [] As = [] for h in range(H): A.append(list(map(int, input().split()))) As.append(set(A[h])) def dfs(h, xor1, hist): if h == H: if xor1 > 0: return hist else: return None for a in As[h]: ret = dfs(h + 1, xor1 ^ a, hist + [a]) if ret is not None: return ret return None hist = dfs(0, 0, []) if hist is not None: print("TAK") print(*[(A[h].index(hist[h]) + 1) for h in range(H)]) else: print("NIE")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR IF VAR NUMBER RETURN VAR RETURN NONE FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR LIST VAR IF VAR NONE RETURN VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER LIST IF VAR NONE EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER 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.
n, m = map(int, input().strip().split()) arr = [] for i in range(n): arr.append(list(map(int, input().strip().split()))) xor = 0 flag = 0 ele = [] for i in range(n): seti = set(arr[i]) if len(seti) > 1 and flag == 0: flag = 1 ele = [seti.pop(), seti.pop(), i] else: xor ^= arr[i][0] if flag == 0 and xor == 0: print("NIE") else: print("TAK") ans = [(1) for i in range(n)] if flag == 1: ans[ele[2]] = ( arr[ele[2]].index(ele[0]) + 1 if xor ^ ele[0] is not 0 else arr[ele[2]].index(ele[1]) + 1 ) print(*ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR 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.
col, row = [int(i) for i in input().split()] array = list() for i in range(col): array.append([int(i) for i in input().split()]) choice = list() xor = int() for i in range(col): choice.append(str(1)) xor = xor ^ array[i][0] if xor == 0: for i in range(col): current = array[i][0] check = False for j in range(row): if array[i][j] != current: choice[i] = str(j + 1) print("TAK") print(" ".join(choice)) check = True break if check: break if check == False: print("NIE") else: print("TAK") print(" ".join(choice))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER IF VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING 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.
n, m = map(int, input().split()) sr = n bl = [] for i in range(n): a = list(map(int, input().split())) bl.append(a) if sr == n and len(set(a)) > 1: sr = i s = set(a) if sr != n: print("TAK") ans = [] x = 0 for i in range(n): if i != sr: ans.append(1) x ^= bl[i][0] for i in s: if i == x: continue ind = bl[sr].index(i) ans = ans[:sr] + [ind + 1] + ans[sr:] break print(*ans) else: x = 0 for i in range(n): x ^= bl[i][0] if x: print("TAK") ans = [1] * n print(*ans) else: print("NIE")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 IF VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR LIST BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR 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()) mat = [] for i in range(n): l = [int(i) for i in input().split()] mat.append(l) ans = [] xor = 0 for i in mat: xor ^= i[0] ans.append(1) if xor: print("TAK") print(*ans) exit() else: for i in range(n): for j in range(m): if mat[i][j] ^ mat[i][0] > 0: ans[i] = j + 1 print("TAK") print(*ans) exit() 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 VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER 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.
import sys n, m = map(int, input().split()) s = [list(map(int, input().split())) for _ in range(n)] x = 0 b = False ans = 0 a = [] for i in range(n): for j in range(m): if s[i][j] != s[i][0]: b = True x = i if b: for i in range(n): if x == i: continue ans ^= s[i][0] for i in range(m): if ans != s[x][i]: print("TAK") for j in range(n): a.append(i + 1 if x == j else 1) print(*a) sys.exit() for i in range(n): ans ^= s[i][0] a.append(1) if ans == 0: print("NIE") else: print("TAK") print(*a)
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL 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 n, m = [int(x) for x in input().split()] lines = [] for i in range(n): lines.append([bin(int(x))[2:].zfill(10) for x in input().split()]) odds = [(-1) for _ in range(n)] evens = [(-1) for _ in range(n)] for i in range(10): pos_even = True pos_odd = False for c in range(n): pos_even_temp = False pos_odd_temp = False for cur in range(m): if lines[c][cur][i] == "1": if pos_even: pos_odd_temp = True odds[c] = cur if pos_odd: pos_even_temp = True evens[c] = cur else: if pos_even: pos_even_temp = True evens[c] = cur if pos_odd: pos_odd_temp = True odds[c] = cur pos_even = pos_even_temp pos_odd = pos_odd_temp if pos_odd: print("TAK") res = [] last_even = lines[n - 1][odds[n - 1]][i] != "1" res.append(odds[n - 1]) for s in reversed(range(n - 1)): if last_even: res.append(odds[s]) last_even = lines[s][odds[s]][i] != "1" else: res.append(evens[s]) last_even = lines[s][evens[s]][i] == "1" res = reversed(res) for s in res: print(s + 1, end=" ") sys.exit() print("NIE")
IMPORT 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 FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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 = map(int, input().split()) Matrix = [] for i in range(N): temp = [int(x) for x in input().split()] Matrix.append(temp) index = -1 for i in range(N): if len(set(Matrix[i])) > 1: index = i break if index == -1: Xor = 0 for i in range(N): Xor ^= Matrix[i][0] if Xor: print("TAK") Ans = [1] * N print(*Ans) else: print("NIE") else: Xor = 0 for i in range(N): if i != index: Xor ^= Matrix[i][0] Value = list(set(Matrix[index])) Hit = -1 for i in Value: if Xor ^ i: Hit = i break for i in range(M): if Matrix[index][i] == Hit: ii = i + 1 break Ans = [1] * N Ans[index] = ii print("TAK") print(*Ans)
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 VAR FUNC_CALL FUNC_CALL VAR 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 VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR 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()) a = [] for i in range(n): a.append(list(map(int, input().split()))) fl = -1 k = 0 for i in range(n): if len(set(a[i])) > 1: fl = i break x = a[0][0] for i in range(n): for j in range(m): if a[i][j] != x: k = 1 break if k == 0 and n % 2 == 0 or k == 0 and a[0][0] == 0: exit(print("NIE")) else: ans = [1] * n x = 0 if fl != -1: for i in range(n): if i != fl: x ^= a[i][0] for i in range(m): if x ^ a[fl][i] > 0: ans[fl] = i + 1 break x = 0 for i in range(n): x ^= a[i][ans[i] - 1] if x > 0: print("TAK") print(*ans) else: print("NIE")
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER IF 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 ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF 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.
import sys N, M = map(int, input().split()) mat = [list(map(int, input().split())) for i in range(N)] def db(*arg): print(*arg) for i in range(10): column_1 = [-1] * N column_0 = [-1] * N flag_double = [0] * N count_only_1 = 0 count_only_0 = 0 count_double = 0 for r in range(N): found1, found0 = False, False for c in range(M): if mat[r][c] >> i & 1: column_1[r] = c found1 = True else: column_0[r] = c found0 = True if found0 and found1: flag_double[r] = 1 count_double += 1 elif found0: count_only_0 += 1 else: count_only_1 += 1 if not (count_double > 0 or count_only_1 % 2 == 1): continue ans_ls = [0] * N if count_only_1 % 2 == 1: for r in range(N): if flag_double[r] == 1: ans_ls[r] = column_0[r] + 1 elif column_0[r] != -1: ans_ls[r] = column_0[r] + 1 else: ans_ls[r] = column_1[r] + 1 else: done = False for r in range(N): if flag_double[r] == 1: if not done: ans_ls[r] = column_1[r] + 1 done = True else: ans_ls[r] = column_0[r] + 1 elif column_0[r] != -1: ans_ls[r] = column_0[r] + 1 else: ans_ls[r] = column_1[r] + 1 print("TAK") print(*ans_ls) xor = mat[0][ans_ls[0] - 1] for i in range(1, N): xor ^= mat[i][ans_ls[i] - 1] assert xor > 0 sys.exit() 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 FUNC_DEF EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER 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 = map(int, input().split()) M = [] for i in range(n): M.append(list(map(int, input().split()))) result = 0 for i in range(n): result = result ^ M[i][0] if result > 0: print("TAK") print(*[(1) for _ in range(n)]) return is_solution_exist = False row = None col = None for i in range(n): for j in range(m): if M[i][j] != M[i][0]: is_solution_exist = True row = i col = j break if is_solution_exist: break if is_solution_exist: print("TAK") result = [(1) for _ in range(n)] result[row] = col + 1 print(*result) else: print("NIE")
IMPORT 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 ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR RETURN ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER 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 matrixNdxor(n, m): matrix = [] firstXor = 0 for i in range(n): row = [] values = input() values = values.split() for j in range(m): row.append(int(values[j])) matrix.append(row) firstXor ^= int(values[0]) return [matrix, firstXor] def finder(n, m, matrix, firstXor): ans = "" for i in range(n): for j in range(1, m): if matrix[i][j] != matrix[i][0]: for a in range(n): if a == i: ans += str(j + 1) + " " else: ans += "1 " return ans return False values = input() n, m = values.split() n = int(n) m = int(m) matrix, firstXor = matrixNdxor(n, m) if firstXor > 0: print("TAK") ans = "" for i in range(n): ans += "1 " print(ans) else: res = finder(n, m, matrix, firstXor) if res != False: print("TAK") print(res) else: print("NIE")
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER RETURN LIST VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR STRING RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF 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.
def mp(): return map(int, input().split()) def f(): global j, n r = 0 for i in range(n): r ^= a[i][j[i]] return r n, m = mp() a = [list(mp()) for i in range(n)] j = [0] * n if f() == 0: for i in range(n): ac = 0 for q in range(m): if a[i][q] != a[i][0]: j[i] = q ac = 1 break if ac: break if f() == 0: print("NIE") else: print("TAK") print(" ".join([str(i + 1) for i in j]))
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER 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.
def solve(): entrada = input().split() n = int(entrada[0]) m = int(entrada[1]) temp = 0 arr_c = [ [(0) for x in range(5 * pow(10, 2) + 4)] for y in range(5 * pow(10, 2) + 4) ] for i in range(0, n): entrada = input().split() for j in range(0, m): arr_c[i][j] = int(entrada[j]) for i in range(n): temp ^= arr_c[i][0] if temp != 0: print("TAK") for i in range(n): print("1", end=" ") print() return else: for i in range(n): for j in range(1, m): if arr_c[i][j] != arr_c[i][0]: print("TAK") for k in range(n): if k != i: print("1", end=" ") else: print(j + 1, end=" ") print() return print("NIE") return solve()
FUNC_DEF 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 NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR 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 STRING STRING EXPR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR RETURN EXPR FUNC_CALL VAR STRING RETURN 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.
def taknie(n, m): v = [0] for i in range(n): l = [int(x) for x in input().split()] l.insert(0, 0) v.append(l) resp = 0 for i in range(1, n + 1): resp ^= v[i][1] if resp: print("TAK") for i in range(1, n + 1): print("1") else: for i in range(1, n + 1): for j in range(2, m + 1): if v[i][j] != v[i][1]: print("TAK") for k in range(1, n + 1): if k != i: print("1") else: print(j) return print("NIE") arr = [int(x) for x in input().split()] n = arr[0] m = arr[1] taknie(n, m)
FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given $n$ blocks, each of them is of the form [color$_1$|value|color$_2$], where the block can also be flipped to get [color$_2$|value|color$_1$]. A sequence of blocks is called valid if the touching endpoints of neighboring blocks have the same color. For example, the sequence of three blocks A, B and C is valid if the left color of the B is the same as the right color of the A and the right color of the B is the same as the left color of C. The value of the sequence is defined as the sum of the values of the blocks in this sequence. Find the maximum possible value of the valid sequence that can be constructed from the subset of the given blocks. The blocks from the subset can be reordered and flipped if necessary. Each block can be used at most once in the sequence. -----Input----- The first line of input contains a single integer $n$ ($1 \le n \le 100$) — the number of given blocks. Each of the following $n$ lines describes corresponding block and consists of $\mathrm{color}_{1,i}$, $\mathrm{value}_i$ and $\mathrm{color}_{2,i}$ ($1 \le \mathrm{color}_{1,i}, \mathrm{color}_{2,i} \le 4$, $1 \le \mathrm{value}_i \le 100\,000$). -----Output----- Print exactly one integer — the maximum total value of the subset of blocks, which makes a valid sequence. -----Examples----- Input 6 2 1 4 1 2 4 3 4 4 2 8 3 3 16 3 1 32 2 Output 63 Input 7 1 100000 1 1 100000 2 1 100000 2 4 50000 3 3 50000 4 4 50000 4 3 50000 3 Output 300000 Input 4 1 1000 1 2 500 2 3 250 3 4 125 4 Output 1000 -----Note----- In the first example, it is possible to form a valid sequence from all blocks. One of the valid sequences is the following: [4|2|1] [1|32|2] [2|8|3] [3|16|3] [3|4|4] [4|1|2] The first block from the input ([2|1|4] $\to$ [4|1|2]) and second ([1|2|4] $\to$ [4|2|1]) are flipped. In the second example, the optimal answers can be formed from the first three blocks as in the following (the second or the third block from the input is flipped): [2|100000|1] [1|100000|1] [1|100000|2] In the third example, it is not possible to form a valid sequence of two or more blocks, so the answer is a sequence consisting only of the first block since it is the block with the largest value.
class UnionFind: def __init__(self, size): self.table = [(-1) for _ in range(size)] def find(self, x): if self.table[x] < 0: return x else: self.table[x] = self.find(self.table[x]) return self.table[x] def union(self, x, y): s1 = self.find(x) s2 = self.find(y) if s1 != s2: if self.table[s1] > self.table[s2]: self.table[s2] = s1 elif self.table[s1] < self.table[s2]: self.table[s1] = s2 else: self.table[s1] = s2 self.table[s2] -= 1 return n = int(input()) d = [[] for _ in range(4)] uf = UnionFind(4) CVC = [list(map(int, input().split())) for _ in range(n)] vals = [] min_not_auto = float("inf") for i in range(n): cvc = CVC[i] vals.append(cvc[1]) d[cvc[0] - 1].append(cvc[1]) d[cvc[2] - 1].append(cvc[1]) if cvc[0] != cvc[2] and cvc[1] < min_not_auto: min_not_auto = cvc[1] uf.union(cvc[0] - 1, cvc[2] - 1) root_num = 0 for i in range(4): if uf.table[i] < 0: root_num += 1 if root_num == 1: odd = True for i in range(4): if len(d[i]) % 2 == 0: odd = False break if odd: print(sum(vals) - min_not_auto) else: answers = [0] * 4 for i in range(4): answers[uf.find(i)] += sum(d[i]) print(max(answers) // 2) else: answers = [0] * 4 for i in range(4): answers[uf.find(i)] += sum(d[i]) print(max(answers) // 2)
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
You are given $n$ blocks, each of them is of the form [color$_1$|value|color$_2$], where the block can also be flipped to get [color$_2$|value|color$_1$]. A sequence of blocks is called valid if the touching endpoints of neighboring blocks have the same color. For example, the sequence of three blocks A, B and C is valid if the left color of the B is the same as the right color of the A and the right color of the B is the same as the left color of C. The value of the sequence is defined as the sum of the values of the blocks in this sequence. Find the maximum possible value of the valid sequence that can be constructed from the subset of the given blocks. The blocks from the subset can be reordered and flipped if necessary. Each block can be used at most once in the sequence. -----Input----- The first line of input contains a single integer $n$ ($1 \le n \le 100$) — the number of given blocks. Each of the following $n$ lines describes corresponding block and consists of $\mathrm{color}_{1,i}$, $\mathrm{value}_i$ and $\mathrm{color}_{2,i}$ ($1 \le \mathrm{color}_{1,i}, \mathrm{color}_{2,i} \le 4$, $1 \le \mathrm{value}_i \le 100\,000$). -----Output----- Print exactly one integer — the maximum total value of the subset of blocks, which makes a valid sequence. -----Examples----- Input 6 2 1 4 1 2 4 3 4 4 2 8 3 3 16 3 1 32 2 Output 63 Input 7 1 100000 1 1 100000 2 1 100000 2 4 50000 3 3 50000 4 4 50000 4 3 50000 3 Output 300000 Input 4 1 1000 1 2 500 2 3 250 3 4 125 4 Output 1000 -----Note----- In the first example, it is possible to form a valid sequence from all blocks. One of the valid sequences is the following: [4|2|1] [1|32|2] [2|8|3] [3|16|3] [3|4|4] [4|1|2] The first block from the input ([2|1|4] $\to$ [4|1|2]) and second ([1|2|4] $\to$ [4|2|1]) are flipped. In the second example, the optimal answers can be formed from the first three blocks as in the following (the second or the third block from the input is flipped): [2|100000|1] [1|100000|1] [1|100000|2] In the third example, it is not possible to form a valid sequence of two or more blocks, so the answer is a sequence consisting only of the first block since it is the block with the largest value.
def min(a, b): if a < b: return a return b def max(a, b): return abs(min(-a, -b)) been = [(0) for i in range(4)] ans = 0 minw = 10**18 degpar = [(0) for i in range(4)] w = [(0) for i in range(4)] gr = [list() for i in range(4)] rem = [[(0) for i in range(4)] for j in range(4)] def dfs(x, l): l.append(w[x]) if been[x]: return been[x] = 1 for i in gr[x]: if been[i] == 0 and rem[x][i] > 0: dfs(i, l) n = int(input()) blocks = [] for i in range(n): a, v, b = map(int, input().split()) a -= 1 b -= 1 if a != b: blocks.append([a, v, b]) w[b] += v if a != b: minw = min(minw, v) degpar[a] += 1 degpar[a] %= 2 degpar[b] += 1 degpar[b] %= 2 gr[a].append(b) gr[b].append(a) rem[a][b] += 1 rem[b][a] += 1 ok = True for i in range(4): l = [] if been[i] == 0: dfs(i, l) if i == 0 and all(been) and all(degpar): ok = False break ans = max(ans, sum(l)) if ok: print(ans) exit() for p in blocks: i = p[0] j = p[2] w[j] -= p[1] been = [(0) for i in range(4)] rem[i][j] -= 1 rem[j][i] -= 1 for x in range(4): l = [] if been[x] == 0: dfs(x, l) ans = max(ans, sum(l)) w[j] += p[1] rem[i][j] += 1 rem[j][i] += 1 print(ans)
FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given $n$ blocks, each of them is of the form [color$_1$|value|color$_2$], where the block can also be flipped to get [color$_2$|value|color$_1$]. A sequence of blocks is called valid if the touching endpoints of neighboring blocks have the same color. For example, the sequence of three blocks A, B and C is valid if the left color of the B is the same as the right color of the A and the right color of the B is the same as the left color of C. The value of the sequence is defined as the sum of the values of the blocks in this sequence. Find the maximum possible value of the valid sequence that can be constructed from the subset of the given blocks. The blocks from the subset can be reordered and flipped if necessary. Each block can be used at most once in the sequence. -----Input----- The first line of input contains a single integer $n$ ($1 \le n \le 100$) — the number of given blocks. Each of the following $n$ lines describes corresponding block and consists of $\mathrm{color}_{1,i}$, $\mathrm{value}_i$ and $\mathrm{color}_{2,i}$ ($1 \le \mathrm{color}_{1,i}, \mathrm{color}_{2,i} \le 4$, $1 \le \mathrm{value}_i \le 100\,000$). -----Output----- Print exactly one integer — the maximum total value of the subset of blocks, which makes a valid sequence. -----Examples----- Input 6 2 1 4 1 2 4 3 4 4 2 8 3 3 16 3 1 32 2 Output 63 Input 7 1 100000 1 1 100000 2 1 100000 2 4 50000 3 3 50000 4 4 50000 4 3 50000 3 Output 300000 Input 4 1 1000 1 2 500 2 3 250 3 4 125 4 Output 1000 -----Note----- In the first example, it is possible to form a valid sequence from all blocks. One of the valid sequences is the following: [4|2|1] [1|32|2] [2|8|3] [3|16|3] [3|4|4] [4|1|2] The first block from the input ([2|1|4] $\to$ [4|1|2]) and second ([1|2|4] $\to$ [4|2|1]) are flipped. In the second example, the optimal answers can be formed from the first three blocks as in the following (the second or the third block from the input is flipped): [2|100000|1] [1|100000|1] [1|100000|2] In the third example, it is not possible to form a valid sequence of two or more blocks, so the answer is a sequence consisting only of the first block since it is the block with the largest value.
n = int(input()) mv = 10**9 f = [(0) for i in range(4)] adj = [[(i == j) for j in range(4)] for i in range(4)] w = [(0) for i in range(4)] for _ in range(n): a, v, b = map(int, input().split()) a -= 1 b -= 1 if a != b: mv = min(mv, v) f[a] ^= 1 f[b] ^= 1 w[a] += v adj[a][b] = adj[b][a] = True for k in range(4): for i in range(4): for j in range(4): if adj[i][k] and adj[k][j]: adj[i][j] = True if all(adj[0]) and all(f): print(sum(w) - mv) else: print(max(sum(w[j] for j in range(4) if adj[i][j]) for i in range(4)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR NUMBER
You are given $n$ blocks, each of them is of the form [color$_1$|value|color$_2$], where the block can also be flipped to get [color$_2$|value|color$_1$]. A sequence of blocks is called valid if the touching endpoints of neighboring blocks have the same color. For example, the sequence of three blocks A, B and C is valid if the left color of the B is the same as the right color of the A and the right color of the B is the same as the left color of C. The value of the sequence is defined as the sum of the values of the blocks in this sequence. Find the maximum possible value of the valid sequence that can be constructed from the subset of the given blocks. The blocks from the subset can be reordered and flipped if necessary. Each block can be used at most once in the sequence. -----Input----- The first line of input contains a single integer $n$ ($1 \le n \le 100$) — the number of given blocks. Each of the following $n$ lines describes corresponding block and consists of $\mathrm{color}_{1,i}$, $\mathrm{value}_i$ and $\mathrm{color}_{2,i}$ ($1 \le \mathrm{color}_{1,i}, \mathrm{color}_{2,i} \le 4$, $1 \le \mathrm{value}_i \le 100\,000$). -----Output----- Print exactly one integer — the maximum total value of the subset of blocks, which makes a valid sequence. -----Examples----- Input 6 2 1 4 1 2 4 3 4 4 2 8 3 3 16 3 1 32 2 Output 63 Input 7 1 100000 1 1 100000 2 1 100000 2 4 50000 3 3 50000 4 4 50000 4 3 50000 3 Output 300000 Input 4 1 1000 1 2 500 2 3 250 3 4 125 4 Output 1000 -----Note----- In the first example, it is possible to form a valid sequence from all blocks. One of the valid sequences is the following: [4|2|1] [1|32|2] [2|8|3] [3|16|3] [3|4|4] [4|1|2] The first block from the input ([2|1|4] $\to$ [4|1|2]) and second ([1|2|4] $\to$ [4|2|1]) are flipped. In the second example, the optimal answers can be formed from the first three blocks as in the following (the second or the third block from the input is flipped): [2|100000|1] [1|100000|1] [1|100000|2] In the third example, it is not possible to form a valid sequence of two or more blocks, so the answer is a sequence consisting only of the first block since it is the block with the largest value.
n = int(input()) score00 = [0] * 4 grid = [] for i in range(4): grid.append([]) for j in range(4): grid[-1].append([]) for i in range(n): a, x, b = map(int, input().split()) if a == b: score00[a - 1] += x continue if b < a: tmp = a a = b b = tmp grid[a - 1][b - 1].append(x) for i in range(4): for j in range(4): grid[i][j].sort() ans1 = 0 for i in range(2**16): tmp = 0 score = [] fail = 0 for j in range(4): score.append([0] * 4) degrees = [0] * 4 for j in range(4): for k in range(j + 1, 4): if i & 1 << j * 4 + k: if not grid[j][k]: fail = 1 break score[j][k] = sum(grid[j][k]) - grid[j][k][0] degrees[j] += len(grid[j][k]) - 1 degrees[k] += len(grid[j][k]) - 1 else: if grid[j][k]: score[j][k] = sum(grid[j][k]) degrees[j] += len(grid[j][k]) degrees[k] += len(grid[j][k]) if fail: break if fail: continue count = 0 for j in range(4): if degrees[j] % 2 == 1: count += 1 if count == 4: continue totalscore = 0 for j in range(4): for k in range(4): totalscore += score[j][k] if score[0][1] + score[2][3] == totalscore: if score[0][1] == 0: l = max(score00[0], score00[1]) else: l = score[0][1] + score00[0] + score00[1] if score[2][3] == 0: r = max(score00[2], score00[3]) else: r = score[2][3] + score00[2] + score00[3] ans = max(l, r) elif score[0][2] + score[1][3] == totalscore: if score[0][2] == 0: l = max(score00[0], score00[2]) else: l = score[0][2] + score00[0] + score00[2] if score[1][3] == 0: r = max(score00[1], score00[3]) else: r = score[1][3] + score00[1] + score00[3] ans = max(l, r) elif score[0][3] + score[1][2] == totalscore: if score[0][3] == 0: l = max(score00[0], score00[3]) else: l = score[0][3] + score00[0] + score00[3] if score[1][2] == 0: r = max(score00[1], score00[2]) else: r = score[1][2] + score00[1] + score00[2] ans = max(l, r) else: tmp = [0] * 4 for j in range(4): for k in range(4): if score[j][k] != 0: tmp[j] = 1 tmp[k] = 1 ans = totalscore for j in range(4): if tmp[j]: ans += score00[j] ans1 = max(ans1, ans) print(ans1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR IF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR IF VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR IF VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR IF VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p_{i}. We'll call number n the size or the length of permutation p_1, p_2, ..., p_{n}. Petya decided to introduce the sum operation on the set of permutations of length n. Let's assume that we are given two permutations of length n: a_1, a_2, ..., a_{n} and b_1, b_2, ..., b_{n}. Petya calls the sum of permutations a and b such permutation c of length n, where c_{i} = ((a_{i} - 1 + b_{i} - 1) mod n) + 1 (1 ≤ i ≤ n). Operation $x \text{mod} y$ means taking the remainder after dividing number x by number y. Obviously, not for all permutations a and b exists permutation c that is sum of a and b. That's why Petya got sad and asked you to do the following: given n, count the number of such pairs of permutations a and b of length n, that exists permutation c that is sum of a and b. The pair of permutations x, y (x ≠ y) and the pair of permutations y, x are considered distinct pairs. As the answer can be rather large, print the remainder after dividing it by 1000000007 (10^9 + 7). -----Input----- The single line contains integer n (1 ≤ n ≤ 16). -----Output----- In the single line print a single non-negative integer — the number of such pairs of permutations a and b, that exists permutation c that is sum of a and b, modulo 1000000007 (10^9 + 7). -----Examples----- Input 3 Output 18 Input 5 Output 1800
n = int(input()) ans = [1, 3, 5, 7, 9, 11, 13, 15] dct = { (1): 1, (3): 18, (5): 1800, (7): 670320, (9): 734832000, (11): 890786230, (13): 695720788, (15): 150347555, } if n in ans: print(dct[n]) else: print(0)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] pairs = [[(True) for i in range(m)] for j in range(n)] ans = 0 for i in range(8, -1, -1): const = 2**i prob = False for j in range(n): act_prob = True for l in range(m): if pairs[j][l] and a[j] & b[l] & const == 0: act_prob = False if act_prob: prob = True if prob: ans += const else: for j in range(n): for l in range(m): if pairs[j][l] and a[j] & b[l] & const > 0: pairs[j][l] = False print(ans)
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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) ln = list(map(int, input().split())) lm = list(map(int, input().split())) for ans in range(512): poss = True for i in ln: curr = False for j in lm: if i & j | ans == ans: curr = True if curr == False: poss = False if poss == True: print(ans) break
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(513): x = 0 for j in range(n): for k in range(m): if a[j] & b[k] | i == i: x += 1 break if x == n: print(i) exit()
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] mins = [0] * n for j in range(n): mins[j] = min([(a[j] & i) for i in b]) lb = max(mins) for j in range(n): lb = min([(lb | a[j] & i) for i in b]) print(lb)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
def check(x): for i in range(n): done = False for j in range(m): if p[i] & q[j] | x == x: done = True break if not done: return 0 return 1 n, m = map(int, input().split()) p = list(map(int, input().split())) q = list(map(int, input().split())) for i in range(1 << 9): if check(i): print(i) break
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = [int(x) for x in input().split(" ")] al = [int(x) for x in input().split(" ")] bl = [int(x) for x in input().split(" ")] def binn(x): y = bin(x) z = "0" * (11 - len(y)) + y[2 : len(y)] zz = [] for x in z: zz.append(int(x)) return zz def rev(x): q = 0 for i in range(9): q += x[8 - i] * 2**i return q def And(p, q): aaa = [-1] * 9 for i in range(9): aaa[i] = p[i] & q[i] return aaa def Or(p, q): aaa = [-1] * 9 for i in range(9): aaa[i] = p[i] | q[i] return aaa a = [] for i in range(n): a.append(binn(al[i])) b = [] for i in range(m): b.append(binn(bl[i])) c = [] a.sort() b.sort() poss = [] for i in range(n): poss.append(set([x for x in range(0, m)])) ans = [-1] * 9 for j in range(9): pd = [] for x in poss: pd.append(set(x)) for i in range(n): tbremoved = set() for x in pd[i]: if a[i][j] & b[x][j]: tbremoved.add(x) for x in tbremoved: pd[i].remove(x) fl = 1 for i in range(n): if len(pd[i]) == 0: fl = 0 break if fl: for i in range(len(poss)): poss[i] = set(pd[i]) ans[j] = 0 else: ans[j] = 1 print(rev(ans))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) moves = [] for i in range(n): curr = [] for j in range(m): curr.append(a[i] & b[j]) moves.append(curr) bits = 0 for i in range(n): if min(moves[i]) > bits: bits = min(moves[i]) for i in range(n): best = -1 for j in range(m): moves[i][j] = moves[i][j] - (moves[i][j] & bits) if best == -1: best = moves[i][j] elif moves[i][j] < best: best = moves[i][j] bits = bits | best print(bits)
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
from sys import stdin input = stdin.readline n, m = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] for x in range(512): flag = 0 r = "0" * 9 + bin(x)[2:] for y in a: flag = 0 for z in b: s = "0" * 9 + bin(y & z)[2:] flag = 0 for i in range(-9, 0, 1): if s[i] == "1" and r[i] == "0": flag = 1 break if flag == 0: break if flag == 0: continue else: break if flag == 0: print(x) break
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] for x in range(2**9): count = 0 for i in a: for j in b: if i & j | x == x: count += 1 break if count == n: break if count == n: print(x) break
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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
input() good = [False] * 512 a = [*map(int, input().split())] for v in map(int, input().split()): good[v] = True for i in range(9): for j in range(512): good[1 << i | j] |= good[j] for i in range(512): for v in a: if not good[(~v | i) % 512]: break else: print(i) break
EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
import sys input = sys.stdin.buffer.readline n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] pa = [[(-1) for __ in range(m)] for _ in range(n)] for i in range(n): for j in range(m): pa[i][j] = a[i] & b[j] memo = [set() for _ in range(n)] def dp(i): if i == -1: return [0] if memo[i] == set(): res = set() for j in range(m): for xx in dp(i - 1): res.add(xx | pa[i][j]) memo[i] = res return memo[i] for i in range(n): dp(i) print(min(dp(n - 1)))
IMPORT ASSIGN VAR VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER IF VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
import sys input = sys.stdin.readline n, m = map(int, input().split()) a = [int(i) for i in input().split() if i != "\n"] b = [int(i) for i in input().split() if i != "\n"] ok = False for i in range(513): count = 0 for j in range(n): for k in range(m): if a[j] & b[k] | i == i: count += 1 break if count == n: print(i) ok = True break if ok: break
IMPORT ASSIGN VAR VAR 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 STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) x = [int(a) for a in input().split()] y = [int(b) for b in input().split()] x.sort() y.sort() fil = [] and_list = [] for i in x: poss = [] for j in y: poss.append(i & j) and_list.append(poss) fil.append(min(poss)) ma = max(fil) for arr in and_list: or_list = [] for num in arr: or_list.append(ma | num) ma = min(or_list) print(ma)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) n, m = inm() a = inl() b = inl() for x in range(512): outt = True for i in a: out = False for j in set(b): if i & j | x == x: out = True break if out == False: outt = False if outt: print(x) break
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL 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 ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
def check(mat, x): n = len(mat) m = len(mat[0]) for i in range(n): t = 0 for j in range(m): t |= mat[i][j] | x == x if t == 0: return 0 return 1 n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 mat = [([0] * m) for i in range(n)] for i in range(n): for j in range(m): mat[i][j] = a[i] & b[j] for i in range(512): if check(mat, i): print(i) break
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
def gt(): return list(map(int, input().split())) n, m = gt() a = gt() b = gt() def gtmx(): return max([min([(a[i] & b[j]).bit_length() for j in range(m)]) for i in range(n)]) ret = 0 while 1: high = gtmx() if high == 0: break val = 1 << high - 1 ret |= val for i in range(n): if a[i] & val > 0: a[i] ^= val print(ret)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
a, b = map(int, input().split()) r1 = list(map(int, input().split())) r2 = list(map(int, input().split())) for target in range(2**9): ans = 0 g = True for i in range(a): f = False for j in range(b): t = r1[i] & r2[j] if t & target == t: f = True break if not f: g = False break if g: print(target) exit(0)
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
def gns(): return list(map(int, input().split())) n, m = gns() ns = gns() ms = gns() ans = [set(ms) for i in range(n)] def gt(x, i): return x >> i & 1 == 1 def check(loc, i): rt = set() for x in ans[loc]: if not gt(x, i): rt.add(x) return rt def check_bit(i): for loc in range(n): if not gt(ns[loc], i): continue rt = check(loc, i) if len(rt) == 0: return False return True for i in reversed(range(11)): if not check_bit(i): continue for loc in range(n): if not gt(ns[loc], i): continue ans[loc] = check(loc, i) for c in ans[0]: x = ns[0] & c break for i in range(1, n): for c in ans[i]: c = c & ns[i] x = x | c break print(x)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) if 0 in b: print(0) else: alle = [[(i & j) for j in b] for i in a] ans = 0 for i in range(513): cnt = 0 for j in range(n): for k in range(m): if alle[j][k] | i <= i: cnt += 1 break if cnt >= n: ans = i break print(ans)
ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) def possible(x): for i in range(n): ok = False for j in range(m): x1 = a[i] & b[j] f = 0 for k in range(mx): if x1 & 1 << k and x[k] == 0: f = 1 break if f == 0: ok = True break if ok == False: return 0 return 1 mx = len(bin(max(a))[2:]) for i in range(1 << mx): x = [0] * mx for j in range(mx): if i & 1 << j: x[j] = 1 if possible(x): print(i) exit(0)
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(int(pow(2, 9))): ans = i flag = True hold = [0] * n for j in range(n): for k in range(m): temp = a[j] & b[k] if temp & ~ans == 0: hold[j] = 1 break for j in range(n): if hold[j] == 0: flag = False break if flag: print(ans) break
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 flag = 0 well = 0 good = 0 while flag == 0: for i in range(n): well = 0 for j in range(m): c = a[i] & b[j] if c | ans == ans: well = 1 good += 1 break if well == 0: ans += 1 good = 0 break if good == n: flag = 1 print(ans)
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) l1 = list(map(int, input().split())) l2 = list(map(int, input().split())) m2 = 0 for i in range(len(l1)): m1 = 1000000 for j in range(len(l2)): m1 = min(m1, l1[i] & l2[j]) m2 = max(m1, m2) for i in range(len(l1)): ans = 100000000 for j in range(len(l2)): ans = min(ans, m2 | l1[i] & l2[j]) m2 = max(m2, ans) print(m2)
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
def check(a, b, x): for i in a: flg = False for j in b: if i & j | x == x: flg = True break if not flg: return False return True def proC(a, b): for i in range(1 << 9): if check(a, b, i): return i arr = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) print(proC(a, b))
FUNC_DEF FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
def func(i): global n, m ans = -1 for A in range(513): count = 0 for i in range(n): for j in range(m): if a[i] & b[j] | A == A: count += 1 break if count == n: ans = A break print(ans) n, m = tuple(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) func(0)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
def to_bits(x): ans = [] for _ in range(9): ans.append(x % 2) x //= 2 return tuple(ans[::-1]) def bigger(x): ans = set(x) while True: prev = len(ans) new = set(ans) for x in ans: for i in range(len(x)): if x[i] == 0: y = list(x) y[i] = 1 y = tuple(y) new.add(y) ans = new if len(ans) == prev: break return ans def main(): n, m = list(map(int, input().split())) a = list(map(lambda x: to_bits(int(x)), input().split())) b = list(map(lambda x: to_bits(int(x)), input().split())) valid = bigger(b) for i in range(2**9): bits = to_bits(i) for x in a: t = tuple(0 if i == 1 and j == 0 else 1 for i, j in zip(x, bits)) if t not in valid: break else: print(i) break main()
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) good = [False] * 512 a = list(map(int, input().split())) for v in map(int, input().split()): good[v] = True for i in range(9): for j in range(512): good[1 << i | j] |= good[j] for i in range(512): works = True for v in a: test = (~v | i) % 512 if good[test]: pass else: works = False break if works: print(i) break
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = [0] + list(map(int, input().split())) b = [0] + list(map(int, input().split())) maxmin = 0 for i in range(1, n + 1): temp = 2**9 for j in range(1, m + 1): temp = min(temp, a[i] & b[j]) maxmin = max(maxmin, temp) for i in range(1, n + 1): temp = a[i] & b[1] | maxmin for j in range(1, m + 1): temp = min(temp, a[i] & b[j] | maxmin) maxmin = temp print(maxmin)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [] p = 0 for i in a: min = 512 for j in b: y = i & j if y < min: min = y c.append([min, i]) p = min c.sort() final = c[-1][0] for i in range(len(c) - 1, -1, -1): min = 512 for j in b: y = c[i][1] & j | final if y < min: min = y final = min print(final)
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
import sys input = sys.stdin.buffer.readline def main(): n, m = map(int, input().split()) alst = list(map(int, input().split())) blst = list(map(int, input().split())) clst = [[] for _ in range(n)] for i, a in enumerate(alst): for b in blst: clst[i].append(a & b) ans = set(clst[0]) for lst in clst[1:]: ans2 = set() for num in ans: for num2 in lst: ans2.add(num | num2) ans = ans2.copy() print(min(ans)) main()
IMPORT ASSIGN VAR VAR FUNC_DEF 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] for k in range(2**9): solved = False for i in range(n): found = False for j in range(m): if a[i] & b[j] | k == k: found = True break if not found: break elif found and i == n - 1: print(k) solved = True break if solved: break
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = list(map(int, input().split())) a_nums = list(map(int, input().split())) b_nums = list(map(int, input().split())) cand = set([0]) for a in a_nums: new_cand = set([]) for b in b_nums: for c in cand: new_cand.add(c | a & b) cand = new_cand print(min(cand))
ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
data = [*open(0)] dt = lambda x: map(int, data[x].split()) a = (*dt(1),) b = (*dt(2),) for k in range(512): for ai in a: flag = False for bi in b: if k | ai & bi == k: flag = True break if not flag: break else: break print(k)
ASSIGN VAR LIST FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) alist = list(map(int, input().split())) blist = list(map(int, input().split())) ma = max(alist) num = 0 while 1 << num < ma: num += 1 f = {} for i in range(0, n): f[i] = blist res = 0 while num >= 0: flag = True tmp = 1 << num for i in range(0, n): if alist[i] & tmp == 0: continue if len([j for j in f[i] if j & tmp == 0]) == 0: flag = False break if not flag: res += 1 << num else: for i in range(0, n): if alist[i] & tmp == 0: continue f[i] = [j for j in f[i] if j & tmp == 0] num -= 1 print(res)
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
def format_bin(b): z = 12 - len(b) return "0" * z + b[2:] def main(): n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = 0 T = [] M = 0 for i in a: T.append([]) for j in b: r = format_bin(bin(i & j)) T[-1].append(r) M = max(M, len(r)) c = "" cut = False for k in range(M): k_done = False for i in range(n): necessary = True for j in range(m): cell = T[i][j] if not cell: continue if cut and cell[k - 1] == "1": T[i][j] = None continue if not k_done and necessary: if cell[k] == "0": necessary = False if not cut: break if necessary: k_done = True if not cut: break if k_done: c += "1" cut = False else: c += "0" cut = True print(int(c, 2)) main()
FUNC_DEF ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP STRING VAR VAR NUMBER FUNC_DEF 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR NONE IF VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR IF VAR ASSIGN VAR NUMBER IF VAR IF VAR VAR STRING ASSIGN VAR NUMBER VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
from sys import stdin n, m = map(int, stdin.readline().split()) a = list(map(int, stdin.readline().split())) b = list(map(int, stdin.readline().split())) c = [] for i in a: d = [] for j in b: d.append(i & j) c.append(d) d = [False] * 515 d[0] = True e = [False] * 515 for i in c: for j in range(515): if d[j]: for k in i: e[j | k] = True for j in range(515): d[j] = e[j] for j in range(515): e[j] = False for i in range(515): if d[i]: print(i) break
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
from sys import stdin input = stdin.buffer.readline n, m = map(int, input().split()) (*a,) = map(int, input().split()) (*b,) = map(int, input().split()) d = [set(b) for i in range(n)] ans = 0 for bit in range(9, -1, -1): s = set() for i in b: if not i >> bit & 1: s.add(i) for i in range(n): if a[i] >> bit & 1 and not d[i] & s: ans += 1 << bit break else: for i in range(n): if a[i] >> bit & 1: d[i] &= s print(ans)
ASSIGN VAR VAR ASSIGN VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
from sys import stdin n, m = map(int, stdin.readline().rstrip().split(" ")) l1 = list(map(int, stdin.readline().rstrip().split(" "))) l2 = sorted(list(map(int, stdin.readline().rstrip().split(" ")))) for x in range(0, 512): r = True for i in range(n): inside = False for j in range(m): y = x | l1[i] & l2[j] if y == x: inside = True break if not inside: r = False break if r: print(x) break
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = [*map(int, input().split())] b = [*map(int, input().split())] t = [[] for i in range(n)] for i in range(n): for j in range(m): t[i].append(a[i] & b[j]) for j in range(2**9): f = 1 for i in range(n): flag = 0 for x in t[i]: if j | x == j: flag = 1 break if flag == 0: f = 0 break if f == 1: print(j) break
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
import sys input = sys.stdin.buffer.readline n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] pa = [[(-1) for __ in range(m)] for _ in range(n)] for i in range(n): for j in range(m): pa[i][j] = a[i] & b[j] memo = [[(False) for __ in range(2**9)] for _ in range(n)] for i in range(n): for j in range(m): if i == 0: memo[i][pa[i][j]] = True else: for k in range(2**9): if memo[i - 1][k]: ans = k | pa[i][j] memo[i][ans] = True for k in range(2**9): if memo[n - 1][k]: print(k) break
IMPORT ASSIGN VAR VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
temp = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) dp = [([False] * 2**9) for i in range(len(a))] for i in range(len(a)): for j in range(len(b)): if i == 0: dp[i][a[i] & b[j]] = True else: for k in range(2**9): if dp[i - 1][k]: dp[i][k | a[i] & b[j]] = True for i in range(2**9): if dp[len(a) - 1][i]: print(i) break
ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = input().split() n = int(n) m = int(m) a1 = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(513): for j in range(len(a1)): a = 0 for k in range(len(b)): ans1 = a1[j] & b[k] ans = ans1 | i if ans == i: a = 1 break if a == 1: continue else: break if a == 1: print(i) break
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN 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 FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = set(map(int, input().split())) b = set(map(int, input().split())) z = 1 << 7 R = {x: b.copy() for x in a} for i in range(8, -1, -1): t = {x: set() for x in a} flag = True for p in a: for q in R[p]: if not p & q & 1 << i: t[p].add(q) if not t[p]: flag = False if flag: R = t c = 0 z = 0 for x in a: for i in R[x]: z = i c |= x & z print(c)
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
def found(i, j): for k in j: if k | i <= i: return True return False n, m = map(int, input().split()) a = list(set(list(map(int, input().split())))) b = list(set(list(map(int, input().split())))) c = [] for i in a: c.append([]) for j in b: c[-1].append(i & j) for i in range(1024): flag = 0 for j in c: if not found(i, j): flag = 1 break if not flag: ans = i break print(ans)
FUNC_DEF FOR VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) def is_possible(candidate, a, b): for ai in a: found = False for bi in b: ci = ai & bi if ci | candidate == candidate: found = True if not found: return False return True answer = 0 for candidate in range(0, 2**10): if is_possible(candidate, a, b): answer = candidate break print(answer)
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = (int(i) for i in input().split()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = (1 << 9) - 1 b_for = {a_i: b.copy() for a_i in a} for bit in (1 << i for i in reversed(range(9))): b_for_zero = dict() for a_i, b in b_for.items(): b_zero = [b_i for b_i in b if a_i & b_i & bit == 0] if b_zero: b_for_zero[a_i] = b_zero else: break else: b_for = b_for_zero c ^= bit print(c)
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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
def check(n, m, x): for i in range(n): flag = False for j in range(m): res = a[i] & b[j] if res | x == x: flag = True break if flag is False: return False return True def solve(n, m, a, b): for x in range(0, 1 << 9): if check(n, m, x): print(x) return else: continue return n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) solve(n, m, a, b)
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN RETURN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) pref = [b for i in range(n)] c = [] for q in range(9): k = 8 - q s = 0 for i in range(n): if a[i] >> k & 1 == 1: t = pref[i][0] >> k & 1 for v in pref[i]: t = t & (v >> k & 1) s = s | t if s == 0: for i in range(n): if a[i] >> k & 1 == 1: pref1 = [] for v in pref[i]: if v >> k & 1 == 0: pref1.append(v) pref[i] = pref1 for i in range(n): c.append(a[i] & pref[i][0]) t = c[0] for i in c: t = t | i print(t)
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] c = [] for i in range(n): mini = 2**10 for j in range(m): mini = min(mini, a[i] & b[j]) c.append(mini) index = -1 ans = 0 for i in range(n): if c[i] > ans: index = i ans = c[i] for i in range(n): if i != index: mini = 10**9 for j in range(m): mini = min(mini, ans | a[i] & b[j]) ans |= mini 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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = tuple(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [] for i in a: c.append([(i & j) for j in b]) left, right = -1, 512 while right - left > 1: middle = (left + right) // 2 err = False for i in c: err = True for j in i: if j | middle == middle: err = False break if err: break if err: left = middle else: right = middle print(left + 1)
ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
m, n = map(int, input().strip().split()) a = list(map(int, input().strip().split())) b = list(map(int, input().strip().split())) ands = [] for i in range(len(a)): curAnds = [] for j in range(len(b)): curAnds.append(a[i] & b[j]) ands.append(curAnds) for i in range(2**9): end = False for j in range(len(ands)): found = False for k in range(len(ands[j])): if ands[j][k] & i == ands[j][k]: found = True if found and j == len(ands) - 1: end = True elif found == False: break if end: print(i) break
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) (*a,) = map(int, input().split()) (*b,) = map(int, input().split()) for ans in range(2**9): for i, aa in enumerate(a): for j, bb in enumerate(b): if ans | aa & bb == ans: break else: break else: print(ans) break
ASSIGN VAR 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 VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) r = [] for i in a: r.append([(i & j) for j in b]) d = dict() l = r[0].copy() for i in range(1, n): d = {} for j in range(m): for k in l: d[k | r[i][j]] = 1 l = list(d.keys()) print(min(l))
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
input() A = list(map(int, input().split())) B = list(map(int, input().split())) candidates = [] for a in A: candidates += [set(a & b for b in B)] def has(cs, i): for c in cs: if c & 1 << i == 0: return True return False def could_az(candidates, i): return all(has(cs, i) for cs in candidates) def weeded(cs, i): ret = set(cs) for c in cs: if c & 1 << i != 0: ret.remove(c) assert len(ret) > 0 return ret ret = [1] * 11 for pos in range(10, -1, -1): if could_az(candidates, pos): ret[pos] = 0 for i in range(len(candidates)): candidates[i] = weeded(candidates[i], pos) ret = map(str, ret[::-1]) ret = "".join(ret) ret = int(ret, 2) print(ret)
EXPR 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR VAR LIST FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_DEF FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
import sys read = lambda: sys.stdin.readline().rstrip("\r\n") m, n = map(int, read().split()) arr_a = list(map(int, read().split())) arr_b = list(map(int, read().split())) def solution(arr_a, arr_b): mask = 0 while mask <= 2**9: for a in arr_a: for b in arr_b: if ~mask & (a & b) == 0: break else: break else: return mask mask += 1 print(solution(arr_a, arr_b))
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
mem = [[(-1) for j in range(201)] for i in range(1 << 10)] def dp(i, j, n, m, a, b): if j == n: return 0 if mem[i][j] != -1: return mem[i][j] ans = 1 << 10 for k in range(m): ans = min(ans, i | a[j] & b[k] | dp(i | a[j] & b[k], j + 1, n, m, a, b)) mem[i][j] = ans return ans n, m = map(int, input().split()) a = [*map(int, input().split())] ans = 0 b = [*map(int, input().split())] print(dp(0, 0, n, m, a, b))
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) (*a,) = map(int, input().split()) (*b,) = map(int, input().split()) mm = 0 for i in range(n): tt = 2**10 for j in range(m): t = a[i] & b[j] if t < tt: tt = t if tt > mm: mm = tt ans = mm for i in range(n): c = 2**10 for j in range(m): t = ans | a[i] & b[j] if t < c: c = t ans = c print(ans)
ASSIGN VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) l = [int(j) for j in input().split()] l1 = [int(j) for j in input().split()] c = 0 for t in range(2**9 + 1): c = 1 for i in range(len(l)): a = 0 for j in range(len(l1)): if t | l[i] & l1[j] == t: a = 1 break if a == 0: c = 0 break if c == 1: print(t) break
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) change = [[(a[i] & b[j]) for j in range(m)] for i in range(n)] dp = [([0] * 2**9) for i in range(n)] for i in range(n): if i == 0: for k in range(m): dp[0][change[i][k]] = 1 continue for j in range(2**9): if dp[i - 1][j] == 1: for k in range(m): dp[i][j | change[i][k]] = 1 for j in range(2**9): if dp[-1][j] == 1: print(j) break
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = [int(i) for i in input().split(" ")] a = [int(i) for i in input().split(" ")] b = [int(i) for i in input().split(" ")] ab = [b.copy() for i in a] result = 1023 def isTrue(a, s): return a >> s & 1 for s in range(9, -1, -1): new_ab = [None for i in ab] possible = True for i, ca in enumerate(a): if isTrue(ca, s): res = [cb for cb in ab[i] if not isTrue(cb, s)] if len(res) != 0: new_ab[i] = res else: possible = False break else: new_ab[i] = ab[i] if possible: result ^= 1 << s ab = new_ab print(result)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NONE VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
def readGenerator(): while True: tokens = input().split(" ") for t in tokens: yield t reader = readGenerator() def readWord(): return next(reader) def readInt(): return int(next(reader)) def readFloat(): return float(next(reader)) def readLine(): return input() def solve(n): return n n = readInt() m = readInt() a = [readInt() for _ in range(0, n)] b = [readInt() for _ in range(0, m)] for res in range(0, 2**10): f = False for va in a: f = False for vb in b: if res | va & vb == res: f = True break if not f: break if f: print(res) break
FUNC_DEF WHILE NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR EXPR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR VAR
Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s. Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation. -----Input----- The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$). The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$). The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$). -----Output----- Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$. -----Examples----- Input 4 2 2 6 4 0 2 4 Output 2 Input 7 6 1 9 1 9 8 1 0 1 1 4 5 1 4 Output 0 Input 8 5 179 261 432 162 82 43 10 38 379 357 202 184 197 Output 147 -----Note----- For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.
n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) cur = (1 << 10) - 1 bit = [] for i in range(9, -1, -1): for el1 in a: isThere = False for el2 in b: el = el1 & el2 if el <= cur and el & 1 << i == 0 and cur | el == cur: isThere = True break if not isThere: break if isThere: cur = cur - (1 << i) print(cur)
ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR