description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
t = int(input()) for _ in range(t): n = int(input()) dig = 0 ones = 0 while n: if n & 1 == 1: ones += 1 dig += 1 n = n // 2 sol = 2**dig % 1000000007 if ones == 1: sol -= 1 if dig == 2: sol -= 1 print(sol)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBE...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
for _ in range(int(input())): n = int(input()) mod = int(1000000000.0 + 7) if n == 1 or n == 2: print(n) else: binn = bin(n)[2:] ans = 2 ** len(binn) % mod if binn.count("1") == 1: ans -= 1 print(ans % mod)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR STRING NUMBER VAR NUMBER EXPR ...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
t = int(input()) for _ in range(t): n = int(input()) digits = 0 x = n while x != 0: x >>= 1 digits += 1 largest = (1 << digits) - 1 check = 1 << digits - 1 if check != n: largest += 1 if n == 2: print(2) else: divider = pow(10, 9) + 7 a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUM...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
for _ in range(int(input())): n = int(input()) mod = int(1000000000.0 + 7) if n == 1 or n == 2: print(n) else: ans = 1 while ans < n: ans *= 2 if n & n - 1 == 0: ans = ans * 2 - 1 print(ans % mod)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CA...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
M = 1000000007 t = int(input()) for _ in range(t): n = int(input()) num = len(bin(n)) - 2 if n <= 2: print(n) elif bin(n).count("1") == 1: print((2**num - 1) % M) else: print(2**num % M)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER V...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
import sys input = sys.stdin.readline def inp(): return int(input()) def st(): return input().rstrip("\n") def lis(): return list(map(int, input().split())) def ma(): return map(int, input().split()) t = inp() p = 10**9 + 7 while t: t -= 1 n = inp() if n <= 2: print(n) ...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE ...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
mod = 10**9 + 7 for _ in range(int(input())): n = int(input()) if n == 1: print(1) continue if n == 2: print(2) continue if n & n + 1 == 0: print((n + 1) % mod) elif n & n - 1 == 0: print((n * 2 - 1) % mod) else: print(int("1" + "0" * len(b...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR BIN_...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
t = int(input()) for _ in range(t): n = int(input()) temp = n c = 0 ans = 0 mo = int(1000000000.0) + 7 count = 0 while n > 0: if n % 2 != 0: count += 1 n //= 2 c += 1 for po in range(c): ans += 2**po ans = (ans + 1) % mo if temp == 2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR V...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
def nextPowerOf2(n): count = 0 if n and not n & n - 1: return n while n != 0: n >>= 1 count += 1 return 1 << count for _ in range(int(input())): n = int(input()) if n == 1 or n == 2: print(n) elif n & n - 1 == 0: print((2 * n - 1) % (10**9 + 7)) ...
FUNC_DEF ASSIGN VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR F...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
MOD = 10**9 + 7 def solve(): n = int(input()) if n == 1: return print(1) if n == 2: return print(2) bit = 1 while bit <= n: bit <<= 1 if bit == n * 2: bit = bit - 1 print(bit % MOD) t = int(input()) for _ in range(t): solve()
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR ...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
for i in range(int(input())): n, x = map(int, input().split()) a, b, p = n, n, False while a > 0: if a == x: p = True print(b) break b += b & -b a &= b if x == 0: print(b) elif p == False: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
def get_bigger_pow_2(n): p = 1 i = 0 while p <= n: p *= 2 i += 1 return p, i def main(): t = int(input()) for _ in range(t): n, x = list(map(int, input().split(" "))) if n | x != n: print(-1) continue xor = n ^ x p, i = ge...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VA...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
def mapped_read(cast): return map(cast, input().split()) def read_list(cast): return list(mapped_read(cast)) def count(a): ans = 0 while a > 0: a //= 2 ans += 1 return ans def f(x): cnt = 0 while x % 4 == 0: x //= 2 cnt += 1 return cnt def solve():...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR IF V...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
import sys input = sys.stdin.readline for _ in range(int(input())): n, x = map(int, input().split()) nn, xx = n, x flag = 0 if n < x: print(-1) elif n == x: print(n) else: cnt = 0 a, b = str(bin(n))[2:], str(bin(x))[2:] b = "0" * (len(a) - len(b)) + b ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CA...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
t = int(input()) for _ in range(t): n, goal = map(int, input().split()) bin_n = bin(n) length_n = len(bin_n) - 2 bin_goal = bin(goal) length_goal = len(bin_goal) - 2 if n == goal: print(n) elif goal == 0: print(2**length_n) elif n < goal or length_goal != length_n: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR F...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
t = int(input()) def solve(): s = input() n = int(s.split(" ")[0]) x = int(s.split(" ")[1]) if n == x: print(n) return for i in range(70, -1, -1): if n >> i & 1 != x >> i & 1: if n >> i & 1 == 0: print(-1) return else:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUM...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
t = int(input()) for i in range(t): n, x = map(int, input().split(" ")) if n < x: print(-1) continue m = n current_bit = 0 current_num = n while current_num != x and m < 1e19: m += 1 << current_bit if (m >> current_bit) % 2 == 0: current_bit += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR I...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
def read_test(): nums = input().split(" ") return int(nums[0]), int(nums[1]) def read_input(): test_num = int(input()) tests = [] for _ in range(test_num): tests.append(read_test()) return tests def solve(test): n = test[0] x = test[1] if n == x: return n n_bi...
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR RETURN VAR ASS...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
for _ in range(int(input())): n, x = map(int, input().split()) if len(bin(x)) > len(bin(n)): print(-1) continue bin_n = bin(n) bin_x = bin(x) if len(bin_x) < len(bin_n): if x: print(-1) continue bin_x = "0b" + "0" * (len(bin_n) - len(bin_x)) + ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL V...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
for j in range(int(input())): b, c = [int(j) for j in input().split()] bc = bin(b)[2:] cc = bin(c)[2:] y = b z = b found = False while y > 0: if y == c: found = True print(z) break z += z & -z y &= z if c == 0: print(z) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR V...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
for _ in range(int(input())): a, b = input().split() a = int(a) b = int(b) if b > a: print(-1) continue if b == a: print(a) continue n = str(bin(a))[2:] c = str(bin(b))[2:] if b == 0: print(2 ** len(n)) continue if len(c) != len(n): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
for _ in range(int(input())): m, x = map(int, input().split()) dicM = {} dicX = {} ok = True pos = -1 A = -1 ans = 0 for i in range(63): if 1 << i & x != 0: dicX[i] = 1 else: dicX[i] = 0 if 1 << i & m != 0: dicM[i] = 1 e...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMB...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
t = int(input()) for _ in range(t): n, x = [int(i) for i in input().split()] if n == x: print(n) continue if x > n: print(-1) else: x_b = bin(x)[2:] n_b = bin(n)[2:] le = max(len(x_b), len(n_b)) x_b = "0" * (le - len(x_b)) + x_b n_b = "0" *...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CAL...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
def bin_to_dec(x): y = 0 for i in x: y *= 2 y += int(i) return y t = int(input()) for _ in range(t): n, x = map(int, input().split()) a = bin(n) b = bin(x) if n == x: print(n) continue if x == 0: print(1 << len(a) - 2) continue if n <...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
t = int(input()) for tc in range(t): n, x = map(int, input().split()) if n == x: print(x) continue sn = bin(n)[2:] ln = len(sn) sx = bin(x)[2:] lx = len(sx) if x == 0: print(1 << ln) continue if ln != lx: print(-1) continue i = 0 wh...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR B...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
def ii(num=False): i = input().split() if num: return int(i[0]) try: return list(map(int, i)) except Exception: return i def gcd(a, b): if a == 0: return b return gcd(b % a, a) for _ in range(ii(1)): max_bit = 63 n, x = ii() if n == x: prin...
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR RETURN FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR IF VAR V...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
def solve(): n, x = map(int, input().split()) if x > n: print(-1) return n = bin(n)[2:] x = bin(x)[2:] ln = len(n) lx = len(x) ans = [] if x == "0": if n == "0": print(0) return myans = "1" + "0" * ln print(int(myans, 2)) ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR STRING IF VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN ASS...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
for _ in range(int(input())): n, x = map(int, input().split()) f = 0 for i in range(64): if n >> i & 1 and x >> i & 1: f = 1 if f == 1 and n >> i & 1 and x >> i & 1 == 0: f = 2 break if n >> i & 1 == 0 and x >> i & 1: f = 2 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN V...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
def find_m(n, x): f = [0] * 60 for i in range(60): if ~n >> i & 1: f[i] = n else: f[i] = (n & ~((1 << i) - 1)) + (1 << i) m = n for i in range(60): if ~x >> i & 1: m = max(m, f[i]) for i in range(60): if x >> i & 1: if m...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VA...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
t = int(input()) for _ in range(t): n, x = map(int, input().split()) N = [0] * 62 X = [0] * 62 f = True for i in range(62): if n & 1 << i: N[i] += 1 if x & 1 << i: X[i] += 1 if X[i] and not N[i]: f = False break if not f: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VA...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
T = int(input()) def b(a, b): return a >> b & 1 for t in range(T): n, x = map(int, input().split()) low, high = n, 10**20 ac = 0 for i in range(max(x.bit_length(), n.bit_length())): if not b(n, i) and not b(x, i): pass elif not b(n, i) and b(x, i): low = -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR FUNC_C...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
for _ in range(int(input())): [n, x] = list(map(int, input().split())) orin, orix = n, x if n == x: print(n) continue if n < x: print(-1) continue maxi = 0 power = 0 yes = 1 while n or x: if x % 2 == 1 and n % 2 == 0: print(-1) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
t = int(input()) for i in range(t): n, x = map(int, input().split()) st, st1 = bin(n)[2:], bin(x)[2:] if n & x != x: print(-1) elif n == x: print(x) else: while len(st) != 64: st = "0" + st while len(st1) != 64: st1 = "0" + st1 vsp = [0...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP ST...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
for j in range(int(input())): n, x = map(int, input().split()) if n == x: print(n) continue if x > n: print("-1") continue a = list(bin(n)[2:]) b = list(bin(x)[2:]) t = len(b) s = len(a) - t b1 = ["0"] * s b = b1 + b f = 0 r = len(a) j = r ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BI...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
def solve(n, x): if n < x: print(-1) return if n == x: print(n) return bn = bin(n)[2:][::-1] bx = bin(x)[2:][::-1] bm = bn[:] if x == 0: print(2 ** len(bn)) return if len(bx) != len(bn): print(-1) return last1 = -1 no_mo...
FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR RETURN IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
def func(): a, b = map(int, input().split()) if b > a: print(-1) return if b == a: print(a) return c = a - b d = a ld = [] lc = [] cnt = 0 while d != 0: if d % 2 != 0: ld.append(cnt) d = d // 2 cnt = cnt + 1 cnt ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
def ii(num=False): i = input().split() if num: return int(i[0]) try: return list(map(int, i)) except Exception: return i def gcd(a, b): if a == 0: return b return gcd(b % a, a) for _ in range(ii(1)): max_bit = 63 n, x = ii() xor = n ^ x left = ...
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR RETURN FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN V...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
t = int(input()) for i in range(t): arr = list(map(int, input().split())) n = arr[0] x = arr[1] t1 = n temp = n fnd = 0 while t1 > 0: if t1 == x: fnd = 1 break temp = temp + (temp & -temp) t1 = t1 & temp if fnd != 0 or x == 0: print...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BI...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
import sys input = sys.stdin.readline MAX = int(1e18) def solve(): N, X = list(map(int, input().split())) if N == X: print(N) elif X == 0: A = 1 while A <= N: A <<= 1 print(A) else: A = list(bin(N)[2:]) N1 = len(A) D = {} for...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL V...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
t = int(input("")) for _ in range(t): n, x = [int(x) for x in input("").split(" ")] if x > n: print(-1) continue if x & n != x: print(-1) continue if x == n: print(n) continue s1 = bin(n)[2:] s2 = bin(x)[2:] s2 = "0" * (len(s1) - len(s2)) + s2 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CA...
Petya and his friend, robot Petya++, like to solve exciting math problems. One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m...
def solve(): n, x = map(int, input().split()) if n == x: print(n) return for bitOff in range(70): bit = 1 << bitOff if not n & bit: continue tmpN = n for smallOff in range(bitOff - 1, -1, -1): smallBit = 1 << smallOff if tmp...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR VAR ASSIG...
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2." Same with some writers, she wants to make an example with some certain output...
k = int(input()) edges = [["N" for i in range(1010)] for j in range(1010)] vertices = 2 def add_edge(a, b): nonlocal edges edges[a][b] = edges[b][a] = "Y" for i in range(1, 29 + 1): vertices += 3 add_edge(i * 3, i * 3 - 1) add_edge(i * 3, i * 3 + 2) add_edge(i * 3 + 1, i * 3 - 1) add_edg...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
a, b = map(lambda s: bin(int(s))[2:], input().split()) a0, a1 = a + "1", a.rstrip("0") if a == b or __import__("re").fullmatch(f"1*({a0}|{a1}|{a0[::-1]}|{a1[::-1]})1*", b): print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR STRING FUNC_CALL VAR STRING IF VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING VAR STRING VAR STRING VAR NUMBER STRING VAR NUMBER STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def check(a, b): if a not in b: return False left = b[: b.find(a)] right = b[b.find(a) + len(a) :] if "0" in left or "0" in right: return False return True x, y = map(int, input().split()) a = bin(x)[2:] b = bin(y)[2:] if a == b: print("YES") exit() if check(a + "1", b) or ...
FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF STRING VAR STRING VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EX...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
x, y = [int(i) for i in input().split(" ")] ans = "NO" if x == y: print("YES") exit(0) bin_x, bin_y = str(bin(x))[2:], str(bin(y))[2:] try: i1 = bin_y.index(bin_x + "1") re = set(bin_y[:i1] + bin_y[i1 + len(bin_x) + 1 :]) if len(re) == 0 or len(re) == 1 and "1" in re: ans = "YES" except: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def reverse(string): string = string[::-1] return string def b(n): return bin(n).replace("0b", "") def z(a): zeroes = 0 for i in a: if i == "0": zeroes += 1 return zeroes x, y = map(int, input().split()) x, y = b(x), b(y) if len(x) == len(y) and x in y: print("YES")...
FUNC_DEF ASSIGN VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VA...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
a, b = map(int, input().split()) s = bin(b)[2:] t = bin(a)[2:] if s == t: print("YES") exit(0) for q in [t + "1", t.strip("0")]: for l in range(len(s) - len(q) + 1): r = len(s) - len(q) - l if "1" * l + q + "1" * r == s or "1" * l + q[::-1] + "1" * r == s: print("YES") ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR LIST BIN_OP VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMB...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def debin(s): ret = 0 mn = 1 for i in range(len(s) - 1, -1, -1): ret += int(s[i]) * mn mn *= 2 return ret st = set() def ch(x, y, deep): if x in st: return 0 st.add(x) if x == y: return 1 if deep == 150: return 0 s = bin(x)[2:] if ch(de...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FU...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
x, y = [str(bin(int(i)))[2:] for i in input().split()] if x == y: print("YES") elif y[-1] == "0": print("NO") else: x += "1" if (y.find(x) != -1 or y.find(x[::-1]) != -1) and y.count("1") - x.count( "1" ) == len(y) - len(x): print("YES") else: x = x[:-1] while x[-...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
import sys v = set() def bfs(n): if n in v: return v.add(n) if len(n) == len(bb): if n == bb: print("YES") sys.exit(0) elif n[0] == "1" and n[-1] == "1": bfs(n[::-1]) return elif len(n) > len(bb): if n[0] == "1" and n[-1]...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER RETURN IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def check(s, t): idx = t.find(s) if idx != -1: lft = t[:idx] rght = t[idx + len(s) :] if lft.count("0") + rght.count("0") == 0: return True else: return False else: return False n, m = map(int, input().split()) sn = bin(n)[2:] sm = bin(m)[2:]...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR ...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
x, y = [int(i) for i in input().split(" ")] def solve(): if x == y: return True a = bin(x)[2:] b = bin(y)[2:] if x == 0: if b.count("0") == 1 and b[-1] != 0: return True else: return False n = len(a) for i in range(n - 1, -1, -1): if a[i]...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR STRING NUMBER VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
import sys inpu = sys.stdin.readline prin = sys.stdout.write x, y = map(int, inpu().split()) if y == x: print("YES") exit() x = bin(x)[2:] y = bin(y)[2:] ind = 0 for i in range(len(x)): if x[i] == "1": ind = i use = x[: ind + 1] if use in y: ind = y.index(use) if "0" not in y[:ind] and "0" ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN ...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def work(a, b, l, r): for i in range(max(0, r - len(a)), min(l + 1, len(b) - len(a)) + 1): if a == b[i : i + len(a)]: print("YES") exit(0) [x, y] = map(int, input().split()) a, b, c = [1], [], [] while x: a.append(x % 2) c.append(x % 2) x //= 2 while y: b.append(y %...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_C...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
L = input().split(" ") s1 = str(bin(int(L[0])))[2:] s2 = str(bin(int(L[1])))[2:] n1 = 0 n2 = 0 for i in range(len(s1)): if s1[i] == "0": n1 += 1 for i in range(len(s2)): if s2[i] == "0": n2 += 1 if s1 == s2: print("YES") else: if s1[-1] == "0": if n1 == n2: s1 += "1" ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
a, b = map(int, input().split()) sus = bin(int(bin(a)[2:][::-1], 2))[2:] sussy = (bin(a)[2:] + "1")[::-1] bb = bin(b)[2:] realsus = sus[::-1] realsussy = sussy[::-1] amogus = bin(b)[2:] great = True pos = -1 leng = 0 for i in [sus, sussy, realsus, realsussy]: lmao = False pos = amogus.find(i) leng = len(i) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIG...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def contain(a, b): if not "0" in b: if not "0" in a: if len(a) <= len(b): return True return False return False if not "0" in a: return False listA = list(a) listB = list(b) Aleft = 0 Aright = 0 Bleft = 0 Bright = 0 whil...
FUNC_DEF IF STRING VAR IF STRING VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER IF STRING VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER STRING EXPR FUNC_CALL VAR S...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
x, y = map(int, input().split()) used = set() s = [x] f = False for _ in range(10000): if len(s) == 0: break a = s[0] del s[0] if a == y: f = True break b = bin(a).lstrip("0b") y1 = int("0b" + (b + "0")[::-1], 2) y2 = int("0b" + (b + "1")[::-1], 2) if y1 == y or y...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP STR...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
import sys input = sys.stdin.readline x, y = map(int, input().split()) if x == y: ans = "YES" print(ans) exit() x = list(bin(x)[2:]) y = list(bin(y)[2:]) x.append("1") lx, ly = len(x), len(y) ans = "NO" for _ in range(2): for i in range(max(0, ly - lx + 1)): ok = 1 for j in range(lx): ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL V...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
from sys import stdin, stdout x, y = [int(z) for z in stdin.readline().split()] answer = "NO" if x == y: answer = "YES" x_reduced = x while x_reduced % 2 == 0: x_reduced = x_reduced // 2 y_bin = str(bin(y))[2:] x_reduced_bin = str(bin(x_reduced))[2:] if len(x_reduced_bin) <= len(y_bin): delta = len(y_bin) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING IF VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VA...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
a, b = [int(i) for i in input().split(" ")] a = bin(a)[2:] b = bin(b)[2:] good = lambda a, b: b.replace(a, "", 1) == (len(b) - len(a)) * "1" check = a == b check = check or good(a + "1", b) check = check or good((a + "1")[::-1], b) while a[-1] == "0": a = a[:-1] check = check or good(a, b) check = check or good(a[:...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR STRING VAR ASSIGN VAR...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
a, b = map(int, input().split()) st = bin(a)[2:] ed = bin(b)[2:] if st == ed: print("YES") exit(0) s1 = st + "1" s2 = st.strip("0") for s in [s1, s2, s1[::-1], s2[::-1]]: for l in range(len(ed)): r = len(ed) - len(s) - l if r < 0: continue if "1" * l + s + "1" * r == ed: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR LIST VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FU...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
x, y = map(int, input().split()) if x == y: print("YES") exit(0) s1, s2 = list(bin(x)[2:]), bin(y)[2:] s3 = bin(x)[2:] r_s3 = s3[::-1] while s1[-1] == "0": s1.pop() s1 = "".join(s1) r_s1 = s1[::-1] for i in range(len(s2) - len(s1) + 1): if ( s2[i : i + len(s1)] == s1 and s2[:i].count("0"...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
x, y = map(int, input().split()) def check(x, y): b1, b2 = bin(x)[2:], bin(y)[2:] n = len(b2) if y == x: return True c1 = (b1 + "1")[::-1] c2 = b1[::-1].lstrip("0") c3 = c1[::-1] c4 = c2[::-1] for cand in [c1, c2, c3, c4]: m = len(cand) if m > n: con...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR LIST VAR...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
x, y = map(int, input().split()) s = set() s.add(x) a = [x] for u in a: if u > 10**20: continue k = 2 * u + 0 b = bin(k)[2:][::-1] v = int(b, 2) if v not in s: s.add(v) a.append(v) k = 2 * u + 1 b = bin(k)[2:][::-1] v = int(b, 2) if v not in s: s.add(v...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FOR VAR VAR IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def solver(): first_num, second_num = map(int, input().split()) if first_num == second_num: print("YES") return 0 base_2_first_num_rev = "" base_2_second_num_rev = "" def div_mod2(a): return a // 2, a % 2 while first_num > 0: first_num, coef = div_mod2(first_num...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF RETURN BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL V...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
a, b = list(map(int, input().strip().split())) a_str = "{0:b}".format(a) b_str = "{0:b}".format(b) a_str_1 = a_str + "1" a_str_rev = a_str[::-1].strip("0") a_str_rev_1 = a_str_1[::-1].strip("0") a_strs = [a_str.strip("0"), a_str_1, a_str_rev, a_str_rev_1] ans = a_str == b_str for string in a_strs: pos = b_str.find(...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR LIST FUNC_CALL VAR STRING VAR VAR VAR ASSIGN VAR VAR VAR ...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
import sys input = sys.stdin.readline def removeLeadingZeors(x): index = len(x) for i in range(len(x)): if x[i] == "1": index = i break return x[index:] def reverse(x): return x[::-1] def sumString(x): ans = 0 for i in x: ans += int(i) return an...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def check_candidate(y, candidate): if candidate in y: a = set(list(y.replace(candidate, "", 1))) if len(a) == 1 and "1" in a: return True return False def slv(x, y): if x == y: return "YES" candidates = set() candidates.add(x + "1") candidates.add(x.rstrip("...
FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING NUMBER IF FUNC_CALL VAR VAR NUMBER STRING VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING IF VAR VAR VAR NUMBER VAR ...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def solve(current, target): queue = [current] visited = set() while len(queue): currentNode = queue.pop(0) currentIdx = 0 while currentNode[currentIdx] == "0": currentIdx += 1 currentNode = currentNode[currentIdx:] if currentNode in visited: co...
FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR RETURN STRING ASSIGN VAR VAR VAR BIN_OP VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR F...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def check(s1, s2): index = s2.find(s1) return ( False if index == -1 else s2 == "1" * index + s1 + "1" * (len(s2) - index - len(s1)) ) x, y = map(int, input().split()) if y % 2 == 0: print("YES" if y == x else "NO") elif x % 2: print( "YES" if check(bin(x)[2...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING STRING IF BIN_OP VAR NUMBER EX...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
x, y = [int(x) for x in input().split()] if x == y: print("YES") exit() a, b = bin(x), bin(y) a = a.replace("0b", "") b = b.replace("0b", "") if b[-1] == "0": print("NO") exit() if a in b and a.count("0") == b.count("0"): print("YES") exit() b = b[::-1] if a in b and a.count("0") == b.count("0")...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR V...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def sol(t, s): pos = t.find(s) while pos != -1: x = t[:pos] y = t[pos + len(s) :] if "0" not in x and "0" not in y: return True pos = t.find(s, pos + 1) return False def solve(): [x, y] = [int(a) for a in input().split()] if x == y: print("YES") ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF STRING VAR STRING VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL V...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def check(a, b): if a[-1] == "0": return False rev = a[::-1] for i in range(len(b) - len(a) + 1): if rev == b[i : i + len(a)] or a == b[i : i + len(a)]: j, k, valid = i, i + len(a), True while j >= 0: if b[j] == "0": valid = False ...
FUNC_DEF IF VAR NUMBER STRING RETURN NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR STR...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def f(s, y): if s in y: i = y.index(s) for j in range(0, i): if y[j] != "1": return False for j in range(i + len(s), len(y)): if y[j] != "1": return False return True return False x, y = map(int, input().split()) x = bin(x...
FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING RETURN NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
x, y = map(int, input().split()) x = str(bin(x))[2:] y = str(bin(y))[2:] x1, x2 = x.rstrip("0"), x + "1" if x == y or __import__("re").fullmatch(f"1*({x1}|{x2}|{x1[::-1]}|{x2[::-1]})1*", y): print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING BIN_OP VAR STRING IF VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING VAR STRING VAR STRING VAR NUMBER STRING VAR NUMBER STRING VA...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def check(first, second): idx = second.find(first) if idx == -1: return False return "0" not in second[:idx] and "0" not in second[idx + len(first) :] def solve(x, y): if x == y: return True x_bin = bin(x)[2:] y_bin = bin(y)[2:] first = "1" + x_bin[::-1] second = x_bin[...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER RETURN STRING VAR VAR STRING VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER ...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
a, b = map(int, input().split()) a = str(bin(a)[2:]) b = str(bin(b)[2:]) if b[-1] == "0" and a != b: print("NO") exit() elif a == b: print("YES") exit() x1 = "" flag = False for el in a[::-1]: if el == "1": flag = True x1 += el if el == "0": if flag: x1 += el ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMB...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
a, b = map(int, input().split()) x = bin(a)[2:] y = bin(b)[2:] def add0(s): while s[-1] == "0": s = s[0 : len(s) - 1] return s[::-1] def add1(s): s += "1" return s[::-1] v = [] check = [] v.append(x) check.append(x) ans = False while len(v) > 0: t = v[0] del v[0] if t == y: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF WHILE VAR NUMBER STRING ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER FUNC_DEF VAR STRING RETURN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL V...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def check(s: str, t: str): index = s.find(t) return ( False if index == -1 else s == "1" * index + t + "1" * (len(s) - index - len(t)) ) def CF_760(x, y): if x == y: return True if y % 2 == 0: return False binX = bin(x)[2:] binY = bin(y)[2:] if x % 2: re...
FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ...
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$. For example: $34$ can be turned ...
def prov(z, x): l = len(x) m = len(z) e = 0 for i in range(l - m + 1): if z == x[i : m + i]: e = 1 x = x[:i] + x[m + i :] break if e == 1: for i in x: if i == "0": e = -1 break return e a = [] x, y ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
N, Q = [int(x) for x in input().strip().split(" ")] A = int(input(), 2) B = int(input(), 2) s = "" for q in range(0, Q): a = input().split(" ") if a[0] == "set_a": mask = 1 << int(a[1]) if a[2] == "1": A |= mask else: A &= ~mask elif a[0] == "set_b": m...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER STRING ASSIGN VAR BIN_OP NUMBER FUNC_CALL V...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
length, queries = input().strip().split(" ") length = int(length) a = int(input().strip(), 2) b = int(input().strip(), 2) output = "" for i in range(int(queries)): line = input().split(" ") q = line[0] index = int(line[1]) if q == "set_a": bit = int(line[2]) val = 1 << index a = ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER A...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
n, q = input().split() n, q = int(n), int(q) result = "" if n >= 1 and n <= 100000 and q >= 1 and q <= 500000: a = input() if len(a) == n: b = input() if len(b) == n: a = int(a, 2) b = int(b, 2) for i in range(q): command = input().split() ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
import sys def main(): parameters = input().split() bitLength = int(parameters[0]) numQueries = int(parameters[1]) numA = int(input(), 2) numB = int(input(), 2) for queryNum in range(numQueries): query = input().split() command = query[0] index = int(query[1]) i...
IMPORT 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 FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL V...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
n, q = [int(x) for x in input().strip().split(" ")] a = int(input().strip(), 2) b = int(input().strip(), 2) def set_bit(num, idx, val): mask = 1 << idx return num | mask if val else num & ~mask for i in range(q): line = input().strip().split(" ") idx = int(line[1]) if len(line) == 2: pri...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
N, Q = list(map(int, input().split())) A = int(input(), 2) B = int(input(), 2) result = [] all_ones = 2**N - 1 def get_c(x): C = A + B return ["0", "1"][C >> int(x) & 1] temp = "" for i in range(Q): s = input().split() if s[0] == "set_a": idx, bit = int(s[1]), int(s[2]) if bit: ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR RETURN LIST STRING STRING BIN_OP BIN_OP VAR FUNC_CALL VAR VAR N...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
import sys n, q = list(map(int, input().split())) a = input() b = input() c = int(a, 2) + int(b, 2) a = list(reversed(a)) b = list(reversed(b)) for i in range(q): s = input().split() idx = int(s[1]) if len(s) == 2: bl = 1 << idx sys.stdout.write(c & bl and "1" or "0") else: p = ...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR F...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
def setbit(val, i, bit): num = 1 << i if bit: return val | num return val & ~num n, q = map(int, input().strip().split(" ")) a = int(input().strip(), 2) b = int(input().strip(), 2) out = "" for i in range(q): cmd = input().strip().split(" ") inx = int(cmd[1]) cmd.append(7) bit = in...
FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR IF VAR RETURN BIN_OP VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR A...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
test = tuple(map(int, input().strip().split(" "))) def setbit(a, b, c): n = 1 << int(b) if c == "1": return a | n return a & ~n a = int(input().strip(), 2) b = int(input().strip(), 2) s = "" for t in range(test[1]): r = input().strip().split(" ") if r[0] == "set_a": a = setbit(a,...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR STRING RETURN BIN_OP VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR STR...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
n, q = map(int, input().split()) a = int(input(), 2) b = int(input(), 2) def set_bit(v, index, on): b = 1 << index return v | b if on else v & ~b for _ in range(q): k, *args = input().split() args = list(map(int, args)) if k == "set_a": a = set_bit(a, *args) elif k == "set_b": ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FU...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
def set_bit(n, offset): mask = 1 << offset return n | mask def clear_bit(n, offset): mask = ~(1 << offset) return n & mask def get_bit(n, i): mask = 1 << i return 1 if n & mask else 0 line = input("").split(" ") N, Q = int(line[0]), int(line[1]) A = int(input(""), 2) B = int(input(""), 2) ...
FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR F...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
n_bit, line_count = [int(i) for i in input().split()] a = int(input(), 2) b = int(input(), 2) for i in range(line_count): inp = input().split() x = int(inp[1]) if inp[0] == "get_c": print((a + b & 1 << x) >> x, end="") elif inp[0] == "set_a": if inp[2] == "1": a = a | 1 << x ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR B...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
N, Q = [int(s) for s in input().split(" ")] A = int(input(), 2) B = int(input(), 2) C = None for _ in range(Q): line = input().split() if line[0] == "get_c": if C is None: C = A + B idx = int(line[1]) print(C >> idx & 1, end="") else: C = None idx, x = [in...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NONE ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
N, Q = [int(x) for x in input().strip().split()] A = int(input().strip(), 2) B = int(input().strip(), 2) Output = [] for dummyQ in range(Q): QueryFields = input().strip().split() if QueryFields[0] == "set_a": idx, x = [int(x) for x in QueryFields[1:]] Target = A >> idx & 1 if Target != x...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR ...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
def find_base(N): M = 2 while M < N: M <<= 1 return M def build(X): XC = ["0"] * (2 * M) MM = M >> 1 XC[M : M + N] = X for i in range(M - 1, 0, -1): if i < M and i >= MM: XC[i] = int(XC[i << 1]) + int(XC[i << 1 | 1]) else: XC[i] = XC[i << 1] ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST STRING BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_C...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
import sys n = [int(number) for number in input().split()] a = int(input(), 2) b = int(input(), 2) for i in range(n[1]): query = input().split() if query[0] == "set_a": if query[2] == "0": a &= ~(1 << int(query[1])) elif query[2] == "1": a |= 1 << int(query[1]) elif ...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NUMBER STRING VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMB...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
raw = input().split() n = int(raw[0]) q = int(raw[1]) a = int(input(), 2) b = int(input(), 2) c = a + b for i in range(q): qraw = input().split() if qraw[0] == "set_a": idx = int(qraw[1]) x = int(qraw[2]) if a >> idx & 1 != x: if x == 1: a = a | 1 << idx ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FU...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
def clearBit(n, pos): return n & ~(1 << pos) def setBit(n, pos): return n | 1 << pos def getBit(n, pos): return 0 if n & 1 << pos == 0 else 1 n, q = input().split() n, q = int(n), int(q) a = int(input(), 2) b = int(input(), 2) buf = [] for _ in range(q): cmd = input().split() pos = int(cmd[1])...
FUNC_DEF RETURN BIN_OP VAR BIN_OP NUMBER VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP NUMBER VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUN...
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$. set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b...
T = list(map(int, input().split())) A = int(input(), 2) B = int(input(), 2) for _ in range(T[1]): temp = input() if temp[4] == "a": if temp[-1] == "1": A = A | 1 << int(temp[5:-2]) else: A = A & ~(1 << int(temp[5:-2])) elif temp[4] == "b": if temp[-1] == "1": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ...