description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
a, b, k = map(int, input().split()) if a == 0 or b == 1: if k != 0: print("No") elif a == 0 and b == 1: print("Yes\n1 1") elif a == 0: print(f"Yes\n{'1' * b} {'1' * b}") elif b == 1: print("Yes\n1" + "0" * a + " " + "1" + "0" * a) elif a + b - 2 < k: print("No") else:...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP STRING VAR STRING BIN_OP STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
a, b, k = map(int, input().split()) if k == 0: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) quit() if k >= a + b - 1: print("No") else: if b == 1 or a == 0: print("No") quit() first = "1" * b + "0" * a second = [c for c in first] take = min(a, k) ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER ...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
a, b, k = map(int, input().split()) if b == 1 or a == 0: if k == 0: print("YES") y = [1] * b + [0] * a print(*y, sep="") print(*y, sep="") else: print("NO") elif k > a: if b >= 3 and k <= a + b - 2: x = [1] * b + [0] * a v = a + b - 2 - k + 1 y...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP V...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
a, b, k = map(int, input().split()) if a == 0 or b == 1: if k == 0: print("Yes") print("{}{}".format("1" * b, "0" * a)) print("{}{}".format("1" * b, "0" * a)) else: print("No") elif k > a + b - 2: print("No") elif k <= a: print("Yes") print("{}{}".format("1" * b, "0" ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP BIN_OP VAR...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
a, b, k = map(int, input().split()) if a == 0: if k == 0: s = b * "1" print("Yes") print(s) print(s) else: print("No") exit() if b == 1: if k == 0: s = "1" + a * "0" print("Yes") print(s) print(s) else: print("No") e...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR STRING EXPR FUNC_CALL...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
import sys input = lambda: sys.stdin.readline().rstrip("\r\n") z1, o1, o2 = map(int, input().split()) z2 = z1 + o1 - o2 f = "1" * o1 + "0" * z1 ans = "YES" if not z1 or o1 == 1: if o2: ans = "NO" else: s = "1" * o1 + "0" * z1 elif o2 <= z1: s = "1" * (o1 - 1) + "0" * o2 + "1" + "0" * (z1 - ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR STRING IF VAR VAR NUMBER IF VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF V...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
import sys input = sys.stdin.readline a, b, k = map(int, input().split()) if b == 1: if k == 0: print("Yes") x = "1" + "0" * a y = "1" + "0" * a print(x) print(y) else: print("No") elif k > a: if a == 0: print("No") elif k > a + b - 2: pri...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP STRING BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR NUMBER ...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
from sys import stdin input = stdin.readline def main(): a, b, k = map(int, input().split()) if b == 1 or a == 0: if k != 0: print("No") return else: x = ["1"] * b + ["0"] * a y = x.copy() elif k > a + b - 2: print("No") retu...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP BIN_OP LIST STRING VAR BIN_OP LIST STRING VAR ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VA...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
from sys import stdin, stdout input = stdin.readline a, b, k = map(int, input().split()) if k == 0: s1 = "1" * b + "0" * a s2 = "1" * b + "0" * a a = 0 b = 0 else: s1 = "1" s2 = "1" b -= 1 if a < k and a > 0: s = "1" * (k - a) + "0" * (a - 1) s1 += "1" + s + "0" ...
ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
a, b, k = map(int, input().split()) if a == k == 0 and b == 1: print("Yes") print(1) print(1) elif k > a + b - 2 or b == 1 and k > 0 or a == 0 and k > 0: print("No") elif k == 0: sa = "1" sb = "1" b -= 1 while b: sa += "1" sb += "1" b -= 1 while a: sa ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STR...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
import sys input = sys.stdin.readline def get_ret_1(a, b, k): if b == 1 and k == 0: x = y = "1" + "0" * a return "Yes\n" + x + "\n" + y x = "1" * (b - 1) + "0" * (a + b - k - (b - 1) - 1) + "1" + "0" * k y = "1" * (b - 1) + "0" * (a + b - (b - 1) - 1) + "1" return "Yes\n" + x + "\n" +...
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP STRING BIN_OP STRING VAR RETURN BIN_OP BIN_OP BIN_OP STRING VAR STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER STRING BIN_OP STRING VAR...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
a, b, k = map(int, input().split()) a, b = b, a if k == 0: print("Yes") print("1" * a + "0" * b) print("1" * a + "0" * b) exit() if a <= 1 or b == 0: print("No") exit() if a + b - 1 <= k: print("No") exit() zero = b - 1 xl = [0] yl = [1] for i in range(k - 1): if zero > 0: xl...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EX...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
from sys import stdin, stdout def yes(x, y): stdout.write("Yes\n") stdout.write("".join(map(str, x))) stdout.write("\n") stdout.write("".join(map(str, y))) stdout.write("\n") def no(): stdout.write("No\n") def check(x, y): x = int(f"0b{''.join(map(str, x))}", base=2) y = int(f"0b{'...
FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR NU...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
import sys from sys import stdin tt = 1 for loop in range(tt): a, b, k = map(int, stdin.readline().split()) if k == 0: print("Yes") print("1" * b + "0" * a) print("1" * b + "0" * a) elif a == 0: if k > 0: print("No") else: print("Yes") ...
IMPORT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL V...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
import sys input = sys.stdin.readline Z, O, k = map(int, input().split()) if O == 1: if k == 0: print("Yes") print("1" + "0" * Z) print("1" + "0" * Z) else: print("No") sys.exit() if Z == 0: if k == 0: print("Yes") print("1" * O) print("1" * O) ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUN...
You are given three integers a, b, k. Find two binary integers x and y (x β‰₯ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
a, b, k = map(int, input().split()) if a >= k and b > 1: print("YES") for i in range(b - 1): print(1, end="") for i in range(a - k): print(0, end="") print(1, end="") for i in range(k): print(0, end="") print() for i in range(b - 1): print(1, end="") for i...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC...
Harasees has an array A of size N containing non-negative integers. He starts at the index 1 of A and wants to reach the index N. In one move, he can do the following: If he is currently at index i, then he can move to any index j such that i ≀ j ≀ \min(i + A_{i}, N). The cost of a path is defined as the [bitwise OR]...
def canJump(nums): n = len(nums) i = 0 while i < n: p = i if p == n - 1: return True if nums[p] == 0 and p != n - 1: return False i += 1 nxt = i m = nums[i] while i <= p + nums[p]: if i >= n: return T...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR WHILE VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR...
Harasees has an array A of size N containing non-negative integers. He starts at the index 1 of A and wants to reach the index N. In one move, he can do the following: If he is currently at index i, then he can move to any index j such that i ≀ j ≀ \min(i + A_{i}, N). The cost of a path is defined as the [bitwise OR]...
def check(arr, mask): if arr[0] & mask != arr[0]: return False if arr[-1] & mask != arr[-1]: return False i = 1 max_reach = arr[0] while i < len(arr): if i > max_reach: return False if arr[i] & mask == arr[i]: max_reach = max(max_reach, i + arr...
FUNC_DEF IF BIN_OP VAR NUMBER VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC...
Harasees has an array A of size N containing non-negative integers. He starts at the index 1 of A and wants to reach the index N. In one move, he can do the following: If he is currently at index i, then he can move to any index j such that i ≀ j ≀ \min(i + A_{i}, N). The cost of a path is defined as the [bitwise OR]...
def decToBin(num): out = [(0) for _ in range(32)] idx = 31 maxBitPos = 31 while num > 0: out[idx] = num % 2 if num % 2 == 1: maxBitPos = idx num //= 2 idx -= 1 return out, max(0, maxBitPos - 2) def binToDec(arr): num, base = 0, 1 for bit in arr[:...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER VAR BIN_OP...
Harasees has an array A of size N containing non-negative integers. He starts at the index 1 of A and wants to reach the index N. In one move, he can do the following: If he is currently at index i, then he can move to any index j such that i ≀ j ≀ \min(i + A_{i}, N). The cost of a path is defined as the [bitwise OR]...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) def check(mask): if arr[0] | mask != mask: return False if arr[-1] | mask != mask: return False dp = [False] * n dp[0] = True j = 0 for i in range(n):...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR NUMBER VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR...
Harasees has an array A of size N containing non-negative integers. He starts at the index 1 of A and wants to reach the index N. In one move, he can do the following: If he is currently at index i, then he can move to any index j such that i ≀ j ≀ \min(i + A_{i}, N). The cost of a path is defined as the [bitwise OR]...
def works(vec, mask): if vec[-1] & mask != vec[-1]: return False mx = 0 for i, v in zip(range(len(vec)), vec): if i > mx: break if v & mask == v and v + i > mx: mx = v + i return mx >= len(vec) - 1 t = int(input()) for _ in range(t): __ = input() ...
FUNC_DEF IF BIN_OP VAR NUMBER VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR...
Harasees has an array A of size N containing non-negative integers. He starts at the index 1 of A and wants to reach the index N. In one move, he can do the following: If he is currently at index i, then he can move to any index j such that i ≀ j ≀ \min(i + A_{i}, N). The cost of a path is defined as the [bitwise OR]...
from sys import stdin input = stdin.readline BIT = 20 def solve(N, A): if N == 1: return A[0] maximum = 1 i = 1 while i <= maximum <= N: maximum = max(maximum, i + A[i]) i += 1 if maximum < N: return -1 answer = 0 for b in reversed(range(BIT + 1)): ...
ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP ...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
def sz(n): if n == 0: return -1 else: count = 0 while n != 1: count += 1 n = int(n / 2) return count for _ in range(int(input())): A, B, N = [int(x) for x in input().split()] if A == 0 and B == 0: print(0) continue sza = sz(A)...
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
t = int(input()) for _ in range(t): a, b, n = map(int, input().split()) if a == b: print(0) else: z = 1 while z < n: z *= 2 if a ^ b < n: print(1) elif a ^ b < z: print(2) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
for _ in range(int(input())): a, b, n = (int(i) for i in input().split()) c = a ^ b if a == b: print(0) continue if c < n: print(1) elif 2 ** (len(bin(c)) - 3) < n: print(2) else: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CA...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
t = int(input()) def fun(a, b, n): diff = bin(b ^ a)[2:] pr = pow(2, len(diff) - 1) if n >= pr: vl = a ^ b if vl <= n: return 1 else: return 2 else: return -1 for _ in range(t): a, b, n = map(int, input().split()) dif = b - a if dif...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CAL...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
ans = [] for _ in range(int(input())): A, B, N = [int(x) for x in input().split()] AexorB = A ^ B binAexorB, binN = bin(AexorB)[2:], bin(N - 1)[2:] if A == B: an = 0 elif AexorB < N: an = 1 elif N != 1 and len(binAexorB) == len(binN): an = 2 else: an = -1 ...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FUNC_CALL VA...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
def answer(a, b, n): if a == b: return 0 xor = a ^ b if xor < n: return 1 z = 1 while z < n: z *= 2 if xor < z: return 2 return -1 for T in range(int(input())): a, b, n = map(int, input().split()) print(answer(a, b, n))
FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR V...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
T = int(input()) def algo(): x, y, N = map(int, input().split()) d = x ^ y if d == 0: print(0) elif d in range(1, N): print(1) elif 2 ** (len(bin(d)) - 3) >= N: print(-1) else: print(2) for i in range(T): algo()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR N...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
for _ in range(int(input())): a, b, n = list(map(int, input().split())) s = 1 while s < n: s *= 2 if a == b: print(0) elif a ^ b < n: print(1) elif a ^ b < s: print(2) else: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
t = int(input()) for i in range(0, t): abn = input() abn = abn.split(" ") a = int(abn[0]) b = int(abn[1]) n = int(abn[2]) ai = bin(a) ai = ai.replace("0b", "") bi = bin(b) bi = bi.replace("0b", "") mi = bin(n - 1) mi = mi.replace("0b", "") l = max(len(ai), len(bi), len(mi...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER 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 STRING STRING ASSIGN VAR FUNC...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
for _ in range(int(input())): a, b, n = map(int, input().split()) if a == b: print(0) continue val = a ^ b if val < n: print(1) continue while val >= n: val = val - (val & -val) if val: print(2) else: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
for _ in range(int(input())): A, B, N = map(int, input().split()) X = A ^ B if X == 0: print(0) elif 1 <= X < N: print(1) elif N != 1 and len(str(bin(X))) == len(str(bin(N - 1))): print(2) else: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL V...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
def solve(a, b, n): if a == b: print(0) return x = a ^ b if x < n: print(1) elif 2 ** (len(bin(x)) - 3) < n: print(2) else: print(-1) t = int(input()) for _ in range(t): a, b, n = list(map(int, input().split())) solve(a, b, n)
FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR F...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
n = int(input()) while n: n -= 1 a, b, N = map(int, input().split()) if a == b: print(0) continue x = a ^ b b = len(bin(x)[2:]) - 1 if x < N: print(1) elif N <= x and N >= 2**b + 1: print(2) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP NUMBER...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
for t in range(int(input())): a, b, n = map(int, input().split()) if a == b: print(0) continue bina, binb = bin(a)[:1:-1], bin(b)[:1:-1] la, lb = len(bina), len(binb) diff = "" for i in range(min(la, lb)): if bina[i] == binb[i]: diff += "0" else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FU...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
T = int(input()) def check(N): l = len(bin(N)) - 2 temp = 2 ** (l - 1) if temp == N: return False return True for i in range(0, T): A, B, N = map(int, input().split()) C = A ^ B if A == B: print(0) elif C < N: print(1) elif C > N and len(bin(C)) == len(bin...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EX...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
def function(A, B, N): if A == B: return 0 val = A ^ B if val < N: return 1 else: c1 = 0 c2 = 0 N = N - 1 while val: if N: c1 += 1 N = N >> 1 c2 += 1 val = val >> 1 if c1 == c2: ...
FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
def op(a, b, n): arra = [(0) for i in range(30)] arrb = [(0) for i in range(30)] j = 29 while a > 0 or b > 0: arra[j] = a & 1 arrb[j] = b & 1 a >>= 1 b >>= 1 j -= 1 j = 29 val = 0 res = 0 countbits = 0 while j >= 0: if arra[j] == arrb[j...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VA...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
def countbit(n): count = 0 while n > 0: n >>= 1 count += 1 return count T = int(input()) while T > 0: a, b, n = map(int, input().split()) t = a ^ b if t == 0: print(0) elif 0 < t < n: print(1) elif countbit(t) == countbit(n - 1): print(2) els...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
ans = "" for _ in range(int(input())): a, b, n = list(map(int, input().split())) count = 0 poss = True if a == b: count = 0 elif a ^ b < n: count = 1 else: for i in range(31, -1, -1): if (a ^ b) & 1 << i >= n: poss = False break...
ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR BIN_...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
t = int(input()) def fun(a, b, n): if a == b: return 0 x = a ^ b if x < n: return 1 c = 0 while x > 0: x = x >> 1 c = c + 1 if 2 ** (c - 1) < n: return 2 return -1 while t > 0: a, b, n = [int(i) for i in input().split()] print(fun(a, b, n))...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR ...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
t = int(input()) for i in range(t): li = list(map(int, input().split())) a = li[0] b = li[1] n = li[2] n -= 1 if a == b: print(0) continue q = a ^ b temp = q res = 0 while temp: if res: res *= 2 else: res = 1 temp = ...
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 NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR IF VA...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
t = int(input()) while t: a, b, n = map(int, input().split(" ")) num = 0 count = 0 flag = False for i in range(29, -1, -1): val = 1 << i if a & val and not b & val: if val >= n: print(-1) break else: if num + val...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_...
JJ has three integers A, B, and N. He can apply the following operation on A: Select an integer X such that 1 ≀ X < N and set A := A \oplus X. (Here, \oplus denotes the [bitwise XOR operation].) JJ wants to make A equal to B. Determine the minimum number of operations required to do so. Print -1 if it is not possib...
t = int(input()) while t: li = [int(x) for x in input().split()] a = li[0] b = li[1] n = li[2] c = a ^ b z = 1 while z < n: z *= 2 if c == 0: print(0) elif c < n: print(1) elif c < z: print(2) else: print(-1) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
n = int(input()) E = [[(int(x) - 1) for x in input().split()] for i in range(n - 1)] G = [[] for i in range(n)] for u, v in E: G[u].append(v) G[v].append(u) root = next(i for i in range(n) if len(G[i]) > 1) pa = [None] * n d = [None] * n useless = [0] * n q = [(root, 0, root)] while q: parent, depth, i = q....
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR V...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
n = int(input()) graph = [[] for i in range(n + 1)] deg = [0] * (n + 1) for i in range(n - 1): x, y = map(int, input().split()) graph[x].append(y) graph[y].append(x) deg[x] += 1 deg[y] += 1 root = -1 leavs = [] for i in range(n + 1): if deg[i] == 1: root = i break for i in range(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
n = int(input()) g = [[] for i in range(n)] for i in range(n - 1): a, b = [(int(s) - 1) for s in input().split()] g[a].append(b) g[b].append(a) ls = [] for i in range(n): if len(g[i]) == 1: ls.append(i) maxans = n - 1 ls_set = set(ls) for i in range(n): ints = len(ls_set.intersection(g[i])) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
import sys n = int(sys.stdin.readline().strip()) N = [[] for i in range(0, n)] C = [(-1) for i in range(0, n)] for i in range(0, n - 1): a, b = list(map(int, sys.stdin.readline().strip().split())) a, b = a - 1, b - 1 N[a].append(b) N[b].append(a) C[0] = 0 L0 = [0] L1 = [] while len(L0) + len(L1) > 0: ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR ...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
import sys readline = sys.stdin.readline def parorder(Edge, p): N = len(Edge) par = [0] * N par[p] = -1 stack = [p] order = [] visited = set([p]) ast = stack.append apo = order.append while stack: vn = stack.pop() apo(vn) for vf in Edge[vn]: if ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR ...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
import sys n = int(input()) adj = [[] for _ in range(n)] for _ in range(n - 1): a, b = [int(x) for x in sys.stdin.readline().split()] a -= 1 b -= 1 adj[a].append(b) adj[b].append(a) mx = n - 1 for i in range(n): num_adj_leaves = sum([(1) for b in adj[i] if len(adj[b]) == 1]) if num_adj_leav...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSI...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
n = int(input()) G = {} for i in range(n - 1): a, b = map(int, input().split()) try: G[a].append(b) except: G[a] = [b] try: G[b].append(a) except: G[b] = [a] leaves = [] for i in G.keys(): if len(G[i]) == 1: leaves.append(i) else: sv = i val = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUM...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
n = int(input()) g = [[] for i in range(n)] for i in range(n - 1): u, v = [(int(i) - 1) for i in input().split()] g[u].append(v) g[v].append(u) leaf = [(len(i) == 1) for i in g] root = -1 mx = n - 1 for i in range(n): if leaf[i]: root = i leafs = 0 for j in g[i]: if leaf[j]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR B...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
n = int(input()) l = [[] for i in range(n)] for i in range(n - 1): a, b = map(int, input().split()) a -= 1 b -= 1 l[a].append(b) l[b].append(a) maxans = n - 1 v = [0] * n leaf = [] for i in range(len(l)): k = l[i] if len(k) == 1: if v[k[0]] == 1: maxans -= 1 else:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN ...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI1(): return map(int1, sys.stdin.readline().split()) def LI(): return list(map(int, sys...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
n = int(input()) gs = [[] for _ in range(n)] for _ in range(n - 1): u, v = map(int, input().split()) u -= 1 v -= 1 gs[u].append(v) gs[v].append(u) for root, u in enumerate(gs): if len(u) > 1: break leaves = [] q = [root] ds = [None] * n ds[root] = 0 par = [None] * n while q: u = q.po...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR L...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
import sys input = sys.stdin.readline n = int(input()) E = [[] for i in range(n + 1)] for i in range(n - 1): a, b = list(map(int, input().split())) E[a].append(b) E[b].append(a) LEAF = [] for i in range(n + 1): if len(E[i]) == 1: LEAF.append(i) Q = [1] USE = [-1] * (n + 1) USE[1] = 0 while Q: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
n = int(input()) dic = {} dicle = {} for i in range(n): dic[i + 1] = [] dicle[i + 1] = 0 for i in range(n - 1): x, y = map(int, input().split()) dic[x].append(y) dic[y].append(x) dicle[x] += 1 dicle[y] += 1 root = 0 leafcount = 0 se = set({}) for i in dicle: if dicle[i] == 1: lea...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER LIST ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VA...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
I = lambda: list(map(int, input().split())) (n,) = I() g = [[] for i in range(n + 1)] for i in range(n - 1): x, y = I() g[x].append(y) g[y].append(x) leaf = [] for i in range(1, n + 1): if len(g[i]) == 1: leaf.append(i) st = [1] visi = [-1] * (n + 1) visi[1] = 0 while st: x = st.pop() fo...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP V...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
def solveAll(): case = readCase() print(*solve(case)) def readCase(): treeSize = int(input()) graph = [[] for i in range(treeSize)] for _ in range(1, treeSize): a, b = (int(x) for x in input().split()) a -= 1 b -= 1 graph[a] += [b] graph[b] += [a] return...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR LIST VAR VAR VAR LIST VAR RETURN VAR FU...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
import sys n, *ab = map(int, sys.stdin.read().split()) graph = [[] for _ in range(n)] for a, b in zip(*([iter(ab)] * 2)): a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) def main(): rank = [None] * n rank[0] = 0 parent = [None] * n leaves = [] stack = [0] while stack: ...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR BIN_OP LIST FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BI...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
from sys import stdin input = stdin.readline class N: def __init__(self, v) -> None: self.v = v self.c = set() self.l = False n = int(input()) arr = [N(i) for i in range(n)] es = set() for _ in range(n - 1): x, y = map(int, input().split()) x -= 1 y -= 1 x, y = min(x, y...
ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
import sys sys.setrecursionlimit(10**6) n = int(input().strip()) conns = [set() for i in range(n + 1)] for i in range(n - 1): a, b = [int(d) for d in input().strip().split()] conns[a].add(b) conns[b].add(a) even = False odd = False for i in range(1, n + 1): if len(conns[i]) > 1: first = i ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VA...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
n = int(input()) g = [[] for i in range(n)] L = [-1] * n for i in range(n - 1): a, b = map(int, input().split(" ")) a -= 1 b -= 1 g[a] += [b] g[b] += [a] L[0] = 0 q = [0] i = 0 odd = 0 even = 0 x = 0 while i < len(q): a = q[i] if len(g[a]) == 1: if L[a]: odd += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER VAR VAR LIST VAR VAR VAR LIST VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER A...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
import sys sys.setrecursionlimit(11000) _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ def go(): n = int(input()) if n == 2: return "1 1" e = {i: set() for i in range(1, n + 1)} rank = [0] * (n + 1) root = -1 for _ in range(n - 1): a, b = map(...
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR F...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
import sys lines = sys.stdin.readlines() n = int(lines[0].strip()) edges = {} for i in range(1, n): u, v = map(int, lines[i].strip().split(" ")) if u not in edges: edges[u] = [] if v not in edges: edges[v] = [] edges[u].append(v) edges[v].append(u) leaves = [] parLeave = {} for u in...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF VAR VAR ASSIGN VAR VAR LIST IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VA...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
from sys import stderr, stdin def rl(): return [int(w) for w in stdin.readline().split()] (n,) = rl() a = [[] for _ in range(n)] for _ in range(n - 1): ai, bi = rl() a[ai - 1].append(bi - 1) a[bi - 1].append(ai - 1) for v in range(n): if len(a[v]) == 1: f = [(v, a[v][0])] break d...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CAL...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
import sys input = sys.stdin.readline def DFS(i): visited = {i: True} stack = [(i, 0)] while len(stack) != 0: tail, depth = stack.pop(-1) flag = True for each in neigh[tail]: if each not in visited: visited[each] = True flag = False ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR DICT VAR NUMBER ASSIGN VAR LIST VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR F...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
size = int(input()) graph = [[] for i in range(size)] for _ in range(1, size): a, b = (int(x) for x in input().split()) a -= 1 b -= 1 graph[a] += [b] graph[b] += [a] leafs = [node for node in range(0, len(graph)) if len(graph[node]) == 1] color = [None] * len(graph) queue = [0] color[0] = "a" head =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR LIST VAR VAR VAR LIST VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
from sys import stdin, stdout def main(): n = int(stdin.readline()) g = [[] for _ in range(n + 1)] k = [[] for _ in range(n + 1)] already = [0] * (n + 1) already1 = [0] * (n + 1) even = [False] * (n + 1) odd = [False] * (n + 1) for _ in range(n - 1): a, b = list(map(int, stdin....
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST N...
You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. Note th...
import sys input = sys.stdin.readline n = int(input()) edge = [[] for _ in range(n)] for _ in range(n - 1): u, v = map(int, input().split()) u -= 1 v -= 1 edge[u].append(v) edge[v].append(u) is_leaf = [False] * n for i in range(n): if len(edge[i]) == 1: is_leaf[i] = True else: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_C...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) state = [-1] * n bit = 1 << 29 while bit > 0: poss = True for j in range(n): if state[j] == 0 and not a[j] & bit: poss = False ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR NUM...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
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() while t: t -= 1 n = inp() a = lis() b = lis() bits = [0] * 30 ...
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 WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
T = int(input()) def check(bit, setBits, array): for i in range(N): here = 0 if front[i] == float("inf") or front[i] & 1 << bit == 0: here = here + 1 if back[i] == float("inf") or back[i] & 1 << bit == 0: here = here + 1 if here == 2: return Fals...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR FUNC_CALL VAR STRING BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR STRING BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBE...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for i in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) st = [-1] * n ans = 0 for i in range(29, -1, -1): ps = 1 bit = 1 << i for i in range(n): if st[i] == 0 and a[i] & bit == 0: p...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER AS...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for _ in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] res = [(-1) for i in range(n)] bcount = 0 abin = [bin(i) for i in a] bbin = [bin(i) for i in b] for i in reversed(range(30)): currentrow = [(-1) for k in ran...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR 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 ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL V...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
t = int(input()) while t > 0: n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 state = [-1] * n for i in range(30, -1, -1): bit = 2**i is_bit_set = True for j in range(n): if a[j] & bit == 0 and b[j] & bit == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUM...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
t = int(input()) for xyz in range(t): n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) m = max(max(A), max(B)) b = 0 while m > 1: m = m // 2 b += 1 ans = 0 flips = 0 while b >= 0: f = True for i in range(n): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHI...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for tc in range(int(input())): n = int(input()) ls = list(map(int, input().split())) lk = list(map(int, input().split())) comb = [-1] * len(ls) res = [] for r in range(30, -1, -1): pos = True for x in range(len(ls)): if comb[x] == 0 and ls[x] >> r & 1 == 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMB...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) totaland = 2**32 flag = 0 overallflip = [] maxi = 0 while totaland > 0: localflip = [] j = 0 while j < n: x = a[j] & totaland ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBE...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
t = int(input()) def log(n): x = str(bin(n))[2:] return len(x) - 1 def check(n, m): x = str(bin(n))[2:] if m < len(x): return x[-m - 1] == "1" return False for _ in range(t): n = int(input()) f = list(map(int, input().split())) b = list(map(int, input().split())) mix = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER STRING RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VA...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
def gcd(a, b): if b == 0: return a return gcd(b, a % b) def check(arr, lex, size): j = 0 ans = 0 k = 0 rem = 0 while j < len(arr): if k == 0: rem = j if k < size: ans = gcd(ans, arr[j]) if ans < lex: j = rem + 1 ...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER AS...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for i in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 st = [-1] * n for k in range(29, -1, -1): poss = 1 for i in range(n): if st[i] == 0: if not 1 << k & a[i]: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER AS...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) flip = [-1] * N for i in range(30, -1, -1): pos = True for j in range(N): if flip[j] == 0 and not A[j] & 1 << i: pos = False ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FO...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for _ in range(int(input())): n = int(input()) ai = list(map(int, input().split())) bi = list(map(int, input().split())) fi = [1] * n for i in range(n): x = str(bin(ai[i])[2:]) ai[i] = "0" * (32 - len(x)) + x x = str(bin(bi[i])[2:]) bi[i] = "0" * (32 - len(x)) + x ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VA...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) mx = max(max(a), max(b)) l = len(bin(mx).replace("0b", "")) count = [3] * n flag = False for i in range(l, -1, -1): if not flag: count = [3] * n ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL F...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
from sys import stdin, stdout mod = 1000000007 def srt(n, l, r): m = (l + r) // 2 if l > r: return m if m * m > n: r = m - 1 return srt(n, l, r) elif m * m < n: l = m + 1 return srt(n, l, r) else: return m for _ in range(int(stdin.readline())): ...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR AS...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) pos = [-1] * n x = 1 << 29 while x: poss = True for y in range(n): if pos[y] == 0 and not a[y] & x: poss = False elif pos...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR ASSIGN VAR NUMBER FOR...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) flip = set() band = 0 mbits = 0 for i in range(N): mbits = max(mbits, len(bin(A[i])[2:]), len(bin(B[i])[2:])) for bit in range(mbits, 0, -1): tbt = 2 ** ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
t = int(input()) for z in range(t): n = int(input()) state = [-1] * n a = list(map(int, input().split())) b = list(map(int, input().split())) x = 1 << 29 while x > 0: chng = True x = x // 2 for i in range(n): if state[i] == 0 and not a[i] & x: ...
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 LIST NUMBER 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 WHILE VAR NUMBER...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for tcase in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) p2, flip, canflip = 2**29, [0] * n, [True] * n result = 0 while p2 > 0: i, x = 0, p2 while x == p2 and i < n: if canflip[i]: x = ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR ...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
INF = pow(2, 31) - 1 for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) state = [-1] * n for i in range(31, -1, -1): temp = 1 << i possible = True for i in range(n): if state[i] == 0 and a[i] & te...
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 VAR FOR VAR FU...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) vis = set() ans = 0 for i in range(30, -1, -1): f = 1 h = [] for j in range(n): if j in vis: if 1 << i & b[j] == 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR ...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
def main(): n = int(input()) a1 = list(map(int, input().split())) b1 = list(map(int, input().split())) m = len(bin(max(max(a1), max(b1)))[2:]) arr = [3] * n ans = 0 for j in range(m - 1, -1, -1): b2 = pow(2, j) f = True for i in range(n): if arr[i] == 3 an...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN V...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 flips = 0 decided = [-1] * n for j in range(29, -1, -1): possible = True make_decided = [-1] * n for i in range(n): if decided[i]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBE...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
T = int(input()) for t in range(T): n = int(input()) arr1 = [bin(int(i))[2:] for i in input().split()] arr1 = [("0" * (31 - len(i)) + i) for i in arr1] arr2 = [bin(int(i))[2:] for i in input().split()] arr2 = [("0" * (31 - len(i)) + i) for i in arr2] count = [-1] * n answer = [0] * 31 fo...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CAL...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
def intinp(): return int(input()) def mapinp(): return map(int, list(input().split())) T = intinp() for _ in range(T): N = intinp() A = list(mapinp()) B = list(mapinp()) state = [0] * N flipped = [0] * N for i in range(29, -1, -1): flip = True for j in range(N): ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_O...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
def func(): turn = [(-1) for x in range(n)] for req in range(31, -1, -1): flag = False changed = [(False) for x in range(n)] swapped = [(False) for x in range(n)] curr = 1 << req for j in range(n): if turn[j] != -1: if curr & a[j] == 0: ...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP ...
Chef found N magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner. Chef denotes the numbers on the front face by A_{1}, A_{2},..., A_{N} and on the back face by B_{1}, B_{2},..., B_{N}. Chef can choose some (possibly zero or al...
T = int(input()) while T != 0: n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) m = max(max(A), max(B)) index = 0 while m != 1: index += 1 m //= 2 ans = (1 << index + 1) - 1 state = [(-1) for t in range(n)] i = 1 << index wh...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NU...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
def recur(n): if n == 0: return 0 return recur(n // 2) + n t = int(input()) for hh in range(0, t): n = int(input()) ans = recur(n) print(ans)
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR