description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
t = int(input()) ans = [1] n = 10 for i in range(2, n + 1): c = ans[:] ans.append(i) ans += c for _ in range(t): n = int(input()) print(*ans[:n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
t = int(input()) def lsb(num): idx = 0 while num % 2 == 0: num = num // 2 idx = idx + 1 return idx + 1 while t > 0: n = int(input()) ans = [] for i in range(1, n + 1): ans.append(lsb(i)) print(*ans) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FU...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
s = [1] mx = 1 while len(s) <= 1000: temp = s.copy() mx += 1 s.append(mx) s.extend(temp) for _ in range(int(input())): n = int(input()) for i in range(n): print(s[i], end=" ") print()
ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VA...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
millors = [[1]] for i in range(1000): p = millors[-1] for v in range(1, max(p) + 2): imp = {v} for r in p[::-1]: if r not in imp: imp.add(r) else: imp.remove(r) if not imp: break if imp: ...
ASSIGN VAR LIST LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
ans = [0] * 1000 def solution(n): def recur(l, r, ele): nonlocal n if l > r: return m = (l + r) // 2 ans[m] = ele recur(l, m - 1, ele + 1) recur(m + 1, r, ele + 1) recur(0, n - 1, 1) return ans for _ in range(int(input())): n = int(input(...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF FUNC_DEF IF VAR VAR RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR FOR VAR ...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
t = int(input()) mylist = [1] current = 2 while len(mylist) < 1000: newlist = [current] newlist += mylist mylist += newlist current += 1 for _ in range(t): n = int(input()) for i in range(n): print(mylist[i], end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
T = int(input()) for t in range(T): N = int(input()) i = 0 j = -1 A = [] curr = 1 while i < N: if j == -1: A.append(curr) curr += 1 j = i - 1 i += 1 else: A.append(A[j]) i += 1 j -= 1 for a in...
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 ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NU...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
t = int(input()) while t: n = int(input()) if n == 1: ans = [1] else: ans = [1] for i in range(2, 100): ans += ans ans = ans[: len(ans) - 1] ans = ans + [i] if len(ans) >= n: break ans = ans[:n] for f in ans: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FOR VA...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
final = [1] incr = 1 while len(final) <= 1000: temp = final.copy() incr += 1 final.append(incr) final += temp def prog_name(): n = int(input()) if n == 1: print(1) elif n == 2: print(1, 2) elif n == 3: print(1, 2, 1) else: for x in range(n): ...
ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
def solveG(N): n = len(bin(N)) - 2 A = [] l = 0 for mx in range(1, n + 1): A.append(mx) l += 1 if l == N: return A for i in range(2 ** (mx - 1) - 1): A.append(A[i]) l += 1 if l == N: return A for _ in range...
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR ...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
def arr(left, right, res, n, m): if left > right: return mid = (left + right) // 2 res[mid] = m arr(left, mid - 1, res, n, m + 1) arr(mid + 1, right, res, n, m + 1) def main(): for _ in range(int(input())): n = int(input()) res = [0] * n arr(0, n - 1, res, n, 1)...
FUNC_DEF IF VAR VAR RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR AS...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
def give(a, k): return a[0:-1] + [k] a = [1, 2] k = 3 for i in range(9): a += give(a, k) k += 1 for _ in range(int(input())): n = int(input()) print(*a[0:n])
FUNC_DEF RETURN BIN_OP VAR NUMBER NUMBER LIST VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
dp = [1] x = 2 while len(dp) < 1000: dp = dp + [x] + dp x += 1 def solve(): n = int(input()) print(*dp[:n]) for _ in range(int(input())): solve()
ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR LIST VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
t = int(input()) for i in range(t): n = int(input()) m = 1 l = [] p = 1 s = [] c = 0 for j in range(n): if c: l1 = list(reversed(s)) l += l1[0 : n - len(l)] c = 0 if len(l) == n: break if len(l) + 1 == 2**p: ...
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 LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
from sys import stdin input = stdin.readline def answer(): ans = [0] * n skip, value = 2, 1 for i in range(n): if ans[i] == 0: for j in range(i, n, skip): ans[j] = value value += 1 skip *= 2 return ans for T in range(int(input())): n =...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
from sys import stdin, stdout input = stdin.readline pows = set() for i in range(11): pows.add(1 << i) t = int(input()) for _ in range(t): n = int(input()) vals = [] arr = [] curr = 0 ind = -1 for i in range(n): if i + 1 in pows: curr += 1 vals.append(curr) ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NU...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
import sys import time start_time = time.time() try: sys.stdin = open("5.txt", "r") except: pass input = sys.stdin.readline T = int(input()) a = "1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1...
IMPORT IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP STRING FUN...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
l = [1, 2, 1] for x in range(1000): l.append(x + 3) l = l + l[: len(l) - 1] if len(l) > 1000: break t = int(input()) while t: n = int(input()) print(" ".join([str(l[x]) for x in range(n)])) t = t - 1
ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CA...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
for _ in range(int(input())): n = int(input()) a = [1] i = 2 while len(a) < n: a = a + [i] + a i += 1 print(*a[:n])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR LIST VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
print( *[ " ".join([str(bin(i ^ i + 1).count("1")) for i in range(int(input()))]) for _ in range(int(input())) ], sep="\n" )
EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
def construct(N): arr = [] top = 1 while len(arr) < N: arr = arr + [top] + arr top += 1 return arr A = [str(x) for x in construct(1000)] T = int(input()) for t in range(T): N = int(input()) print(" ".join(A[:N]))
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR LIST VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CAL...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
import sys def input(): return sys.stdin.readline().rstrip("\r\n") def maps(): return [int(i) for i in input().split()] a = "1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
t = int(input()) for _ in range(t): n = int(input()) l = [] i = 1 p = 0 while len(l) < n: l.append(i) for j in range(p): l.append(l[j]) i += 1 p = 2 * p + 1 for i in range(n): print(l[i], end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VA...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case...
T = int(input()) for test in range(T): N = int(input()) if N == 1: print(1) continue elif N == 2: print(1, 2) continue res = [1] N -= 1 l = 0 max_el = 2 while N > 0: res.append(max_el) N -= 1 r = len(res) - 1 max_el += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR LIST NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN V...
Consider an array of $n$ binary integers (i.e., $1$'s and $1$'s) defined as $A=[a_0,a_1,...,a_{n-1}]$. Let $f(i,j)$ be the bitwise XOR of all elements in the inclusive range between index $\boldsymbol{i}$ and index $j$ in array $\mbox{A}$. In other words, $f(i,j)=a_i\oplus a_{i+1}\oplus\ldots\oplus a_j$. Next, we'll d...
def init(A, n): retA = [0] * (n + 1) B = [0] * (n + 1) tmp = 0 for i in range(n): tmp ^= A[i] B[i + 1] = tmp retA[i + 1] += retA[i] + tmp return retA, B n, q = list(map(int, input().rstrip().split())) A = list(map(int, input().rstrip().split())) newA, B = init(A, n) while q...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUN...
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be. Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons ar...
class Solution(object): def flipLights(self, lightNum, performTime): if lightNum == 0: return 0 if performTime == 0: return 1 if lightNum == 1: return 2 statuNumToStatu = dict() statuNumToStatu[0] = (False,) * lightNum statuNumToSt...
CLASS_DEF VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER AS...
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be. Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons ar...
class Solution(object): def flipLights(self, n, m): if not n: return 0 n, b = min(6, n), set() b.add(tuple([1] * n)) for j in range(m): c = set() for x in b: for t in ( tuple([((x[i] + 1) % 2) for i in range(n)]...
CLASS_DEF VAR FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VA...
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be. Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons ar...
class Solution: def flipLights(self, n, m): n = min(n, 3) if n == 0: return 0 if n == 1: return 2 if m > 0 else 1 if n == 2: if m == 0: return 1 elif m == 1: return 3 else: re...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NU...
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be. Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons ar...
class Solution: def flipLights(self, n, m): states = set() for op_odd in [0, 1]: for op_even in [0, 1]: for op_third in [0, 1]: op_all = m - op_odd - op_even - op_third if op_all >= 0: one = (op_odd + op_all...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR LIST NUMBER NUMBER FOR VAR LIST NUMBER NUMBER FOR VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BI...
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be. Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons ar...
class Solution: def flipLights(self, n, m): if n == 0: return 0 if m == 0: return 1 if n == 1: return 2 if n == 2: if m >= 2: return 4 if m == 1: return 3 if n >= 3: if m ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be. Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons ar...
class Solution: def flipLights(self, n, m): if m == 0: return 1 lights = [True] * min(n, 3) if m > 4: if m & 1: m = 3 else: m = 4 return self.final(m, lights) def operate(self, num, array): if num == 1:...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMB...
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an...
a, b = 0, 1023 for i in range(int(input())): cmd = input() c, x = cmd.split() x = int(x) if c == "|": a, b = a | x, b | x elif c == "&": a, b = a & x, b & x else: a, b = a ^ x, b ^ x x = 0 y = 1023 z = 0 for i in range(10): a_i = a >> i & 1 b_i = b >> i & 1 if...
ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR...
You are a member of a bomb-disposal squad. Each bomb is identified by a unique serial id X, which is a positive integer. To disarm the bomb, a positive integral key Y needs to be entered such that X + Y = X ⊕ Y (here "⊕" denotes the bit-wise XOR operator and "+" denotes the arithmetic sum operator). However, there ar...
t = 0 for _ in range(int(input())): x, y = list(map(int, input().split())) t += 1 c = 0 k = 1 while True: if x + k == x ^ k: c += 1 if c == y: break k += 1 print("Case #%d:" % t, k, end="") print("")
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR STRING EXPR FU...
You are a member of a bomb-disposal squad. Each bomb is identified by a unique serial id X, which is a positive integer. To disarm the bomb, a positive integral key Y needs to be entered such that X + Y = X ⊕ Y (here "⊕" denotes the bit-wise XOR operator and "+" denotes the arithmetic sum operator). However, there ar...
for i in range(eval(input())): a, k = list(map(int, input().split())) cnt = 0 start = 1 while True: if (a & start) << 1 > 0: start += 1 continue else: cnt += 1 start += 1 if cnt == k: break print("Case #%d: %...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBE...
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero. Example 1: Input: dividend = 10, divisor = 3 Output: 3 Example 2: Input: dividend = 7, d...
class Solution: def get_half(self, dividend, divisor): abs_dividend = abs(dividend) abs_divisor = abs(divisor) num = divisor num_temp = 0 result = 1 result_temp = 0 while num <= dividend: num_temp = num num += num result_te...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CA...
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero. Example 1: Input: dividend = 10, divisor = 3 Output: 3 Example 2: Input: dividend = 7, d...
class Solution: def divide(self, dividend, divisor): flag = (dividend < 0) is (divisor < 0) dividend, divisor = abs(dividend), abs(divisor) result = 0 while dividend >= divisor: newDivisor, rate = divisor, 1 while dividend >= newDivisor: divid...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR BIN_OP NUMBER VAR RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero. Example 1: Input: dividend = 10, divisor = 3 Output: 3 Example 2: Input: dividend = 7, d...
import sys class Solution: import sys def divide(self, dividend, divisor): maxint = 2**31 - 1 minint = -(2**31) sign = (2 * (dividend > 0) - 1) * (2 * (divisor > 0) - 1) quotient = 0 dividend *= 2 * (dividend > 0) - 1 divisor *= 2 * (divisor > 0) - 1 re...
IMPORT CLASS_DEF IMPORT FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VA...
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero. Example 1: Input: dividend = 10, divisor = 3 Output: 3 Example 2: Input: dividend = 7, d...
class Solution: def divide(self, dividend, divisor): tag = 1 if (dividend < 0) is (divisor < 0) else -1 dividend, divisor = abs(dividend), abs(divisor) if divisor == 0: return float("inf") count = 0 while dividend >= divisor: mul = 1 t = d...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL...
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero. Example 1: Input: dividend = 10, divisor = 3 Output: 3 Example 2: Input: dividend = 7, d...
class Solution: def divide(self, dividend, divisor): if abs(dividend) < abs(divisor): return 0 sum, count, result = 0, 0, 0 a, b = abs(dividend), abs(divisor) while a >= b: sum = b count = 1 while sum + sum < a: sum += ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN...
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero. Example 1: Input: dividend = 10, divisor = 3 Output: 3 Example 2: Input: dividend = 7, d...
class Solution: def divide(self, dividend, divisor): MIN_INT = -(2**31) MAX_INT = -MIN_INT - 1 if divisor == 0 or dividend == MIN_INT and divisor == -1: return MAX_INT sign = 1 if dividend < 0: sign = -sign dividend = -dividend if ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER WHILE VAR NUMBER I...
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero. Example 1: Input: dividend = 10, divisor = 3 Output: 3 Example 2: Input: dividend = 7, d...
class Solution: def divide(self, dividend, divisor): if dividend < 0 and divisor > 0 or dividend > 0 and divisor < 0: if abs(dividend) < abs(divisor): return 0 summ = 0 count = 0 res = 0 a = abs(dividend) b = abs(divisor) while a >...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR V...
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero. Example 1: Input: dividend = 10, divisor = 3 Output: 3 Example 2: Input: dividend = 7, d...
class Solution: def divide(self, dividend, divisor): positive = (dividend < 0) is (divisor < 0) dividend, divisor, div = abs(dividend), abs(divisor), abs(divisor) res = 0 q = 1 while dividend >= divisor: dividend -= div res += q q += q ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR N...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) for z in range(t): [a, b] = [int(j) for j in input().split()] if a == b: print(0) elif a == b - 1: print(1) elif b == 0: print(-1) elif b == 1 and a != 0: print(-1) else: b = b - 1 n1 = bin(a)[2:].count("1") n2 = bin(b)[2:]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) for i in range(t): a, b = list(map(int, input().split())) if a == b: print(0) elif b == 0 or not a == 0 and b == 2 // 2: print(-1) else: if a - b + 1 == 0: print(1) continue b -= 1 count = 0 bina = bin(a)[2:] ...
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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NU...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
for z in range(int(input())): a, b = (int(x) for x in input().split()) if a == b: print("0") elif b == 1 and a == 0: print("1") elif b == 1 or b == 0: print("-1") else: c1 = b - 1 q = bin(c1)[2:] p = bin(a)[2:] s = p.count("1") t = q.co...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIG...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
test_case = int(input()) def count_zero_one(num): arr = [0, 0] for n in num: if n == 0: arr[0] += 1 elif n == 1: arr[1] += 1 return arr while test_case: a, b = input().split() a = int(a) b = int(b) if a == b: print(0) elif a == 0 and b ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER RETURN VAR WHILE 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 NUMB...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
T = int(input()) for i in range(T): a, b = map(int, input().split(" ")) to_get = b - 1 counter_get = bin(to_get).count("1") counter_a = bin(a).count("1") counter_b = bin(a).count("1") if a == b: result = 0 elif b == 0: if a == 0: result = 0 else: ...
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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF VAR VAR ASSIGN VAR NU...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def main(): for _ in range(int(input())): a, b = [int(x) for x in input().split()] bina = bin(a)[2:] binb = bin(b)[2:] binac = bina.count("1") binbc = binb.count("1") extra = binac - binbc revidx = binb[::-1].index("1") if b != 0 else 0 ans = 0 ...
FUNC_DEF 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 FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR NU...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
cnt = lambda x: bin(x).count("1") def solve(a, b): b_orig = b ans = 0 if a == b: ans = 0 elif a == b - 1: ans = 1 elif b <= 1: ans = -1 else: ans = abs(cnt(a) - cnt(b - 1)) + 1 if cnt(a) > cnt(b - 1): ans = min(ans, 2) return ans for _ in range...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL V...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) for i in range(t): a, b = [int(x) for x in input().split()] if a == b: print(0) elif b == 0: print(-1) elif b == 1: if a == 0: print(1) else: print(-1) else: aa = bin(a) bb = bin(b - 1) oa = aa.count("1"...
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 NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN V...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def StringListToNumList(L): for i in range(0, len(L), 1): L[i] = int(L[i]) return L def NumberOfOnesInBinary(N): NumOfOnes = 0 if N == 0: pass else: while N > 0: if N % 2 == 1: NumOfOnes += 1 N = N // 2 return NumOfOnes T = int(...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMB...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) for i in range(t): inp = input().split() a = int(inp[0]) b = int(inp[1]) if a == b: print(0) elif a == b - 1: print(1) elif b <= 1: print(-1) else: count1 = bin(a).count("1") count2 = bin(b - 1).count("1") if count1 == count2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN 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 NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) for j in range(t): a, b = [int(x) for x in input().split()] cnta1 = 0 a1 = bin(a)[2:] b1 = bin(b)[2:] cntb1 = 0 for i in a1: if i == "1": cnta1 += 1 for i in b1: if i == "1": cntb1 += 1 fap = 0 for i in range(1, len(b1) + 1, 1)...
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 ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR N...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def set_bits(n): return bin(n).count("1") t = int(input()) for test in range(t): a, b = map(int, input().split()) if a == b: ans = 0 elif b == 0 or a > 0 and b == 1: ans = -1 else: set_bits_a = set_bits(a) set_bits_b_less_1 = set_bits(b - 1) if set_bits_a <=...
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING 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 ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def val(a, b): if a == b: return 0 elif b == 0 and a != 0: return -1 elif b == 1: if a == 0: return 1 else: return -1 numb = bin(b - 1).count("1") numa = bin(a).count("1") if numb - numa + 1 >= 1: return numb - numa + 1 else: ...
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN NUM...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
for i in range(int(input())): a, b = (int(s) for s in input().split()) s1 = bin(a)[2:] if a == b: print(0) elif b == 0: print(-1) elif b == 1: if a == 0: print(1) else: print(-1) else: s3 = bin(b - 1)[2:] c1 = s1.count("1") ...
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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def ones(a): res = 0 while a: res += a % 2 a = a // 2 return res def counting(a, b): if a == b: return 0 elif b == 0: return -1 elif b == 1: return 1 if a == 0 else -1 ops = ones(b - 1) - ones(a) + 1 return ops if ops > 0 else 2 for i in range(...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER VAR NUMBER FO...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
for t in range(int(input())): a, b = list(map(int, input().split())) bin_a, bin_b = "{0:b}".format(a), "{0:b}".format(b) a_one, b_one = list(bin_a).count("1"), list(bin_b).count("1") len_a, len_b = len(bin_a), len(bin_b) tr_zero = 0 pos = -1 while pos > -1 * len(bin_b): if bin_b[pos]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) for test in range(t): a, b = map(int, input().split()) if a == b: print(0) continue if a == 0 and b == 1: print(1) continue if b == 0 or b == 1: print("-1") continue b = b - 1 aones = 0 bones = 0 x = a y = b while x...
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 NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR N...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def calc(a, b): s1 = bin(a)[2:] s2 = bin(b - 1)[2:] if s1.count("1") > s2.count("1"): return 2 elif s1.count("1") <= s2.count("1"): return s2.count("1") - s1.count("1") + 1 for _ in range(int(input())): a, b = map(int, input().split()) if a == b: print(0) elif b - a...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING RETURN NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING RETURN BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR A...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) for test in range(t): a, b = map(int, input().split()) ans = -1 if a == b: ans = 0 elif a == 0 and b == 1: ans = 1 elif b > 1: counta = 0 while a > 0: if a & 1: counta += 1 a >>= 1 countb = 0 ind...
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 NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBE...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def no_of_ending_zeros(r): z = 0 for i in range(len(r) - 1, -1, -1): if r[i] == "0": z = z + 1 if r[i] == "1": break return z for _ in range(int(input())): N1, N2 = map(int, input().split()) A = format(N1, "b") B = format(N2, "b") p = -1 nez = no...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING RETURN 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 FUNC_CALL VAR VAR STRING ASSIGN...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
T = int(input()) for i in range(T): A, B = list(map(int, input().strip().split(" "))) C = B - 1 D = "{0:08b}".format(A) C = "{0:08b}".format(C) a1 = D.count("1") b1 = C.count("1") if B == 1 and A > 1: print(-1) elif a1 > b1 and A != B and A != 0 and B != 0: print(2) e...
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 FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUM...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
T = int(input()) for t in range(T): A, B = map(int, input().split()) if B == 0: if A == 0: print(0) else: print(-1) elif B == 1: if A == 0: print(1) elif A == 1: print(0) else: print(-1) elif A == B: ...
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 NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBE...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def bin1(x): res = 0 while x > 0: res += x % 2 x = x // 2 return res for t in range(int(input())): a, b = map(int, input().split()) if b == a: print(0) elif b == 0: print(-1) else: cta = bin1(a) ctb = bin1(b - 1) if cta > ctb: ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR 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 NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR A...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def convert(n): if n == 0: return 0 else: return (n & 1) + convert(n >> 1) t = int(input()) for i in range(0, t): s = input().split() a = int(s[0]) b = int(s[1]) if a == b: print("0") elif a > 0 and b == 1: print("-1") elif b == 0: print("-1") ...
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN 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 IF ...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) for i in range(t): a, b = [int(i) for i in input().split()] if a == b: count = 0 elif b == 0 and a != 0: count = -1 elif b == 1 and a != 0: count = -1 else: p1 = bin(a).count("1") p2 = bin(b - 1).count("1") if p1 > p2: coun...
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 ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VA...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) i = 0 while i < t: a, b = [int(j) for j in input().split()] if a == b: print("0") elif b == 0: print("-1") elif b == 1: if a != 0: print("-1") else: print("1") else: a1 = 0 b1 = 0 while a > 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NU...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
for i in range(int(input())): a, b = map(int, input().split()) c1 = bin(a).count("1") c2 = bin(b - 1).count("1") ans = c2 - c1 + 1 if a == b: print(0) elif a == 0 and b == 1: print(1) elif b == 0 or b == 1: print(-1) elif ans <= 0: print(2) else: ...
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 FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR ...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
for _ in range(int(input())): A, B = map(int, input().split()) a = format(A, "b") b = format(B, "b") if A == B: print(0) elif B == 1 and A >= 1 or B == 0: print(-1) else: t = True s = 0 i = -1 while t: if b[i] == "0": s ...
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 FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
n = int(input()) for i in range(0, n): arr = [int(x) for x in input().split(" ")] if arr[0] == arr[1]: print(0) continue if arr[1] == 0 or arr[1] == 1 and arr[0] > 0: print(-1) continue nb = bin(arr[1] - 1).count("1") na = bin(arr[0]).count("1") if nb < na: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMB...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def sb(num): binary = bin(num) setBits = [ones for ones in binary[2:] if ones == "1"] return len(setBits) def doIt(x, y): if x == y: return 0 if y == 0: return -1 if y == 1: if x == 0: return 1 return -1 kachra = sb(y - 1) - sb(x) + 1 if kach...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR STRING RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RE...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) for i in range(t): a, b = [int(i) for i in input().split()] if a == b: print("0") elif b == 1 and a > 1 or b == 0 and a != 0: print("-1") else: na, nb = 0, 0 res = 0 j = a while j != 0: j = j & j - 1 na += 1 ...
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 STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIG...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def countone(num): count = 0 while num > 0: num = num & num - 1 count += 1 return count T = int(input()) for t in range(T): A, B = map(int, input().split()) a = "{0:b}".format(A) b = "{0:b}".format(B) x = len(a) y = len(b) anum1 = countone(A) bnum1 = countone(B)...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER 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 STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def dbin(x): return int(bin(x)[2:]) def dbin1(x): return bin(x)[2:] def print1(x): if x > 0: print(x) else: x = 1 print(x + 1) def zero(x): flag = 0 count = 0 while flag == 0 and x > 0: if x % 10 != 0: flag = 1 else: count...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSI...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) for cnt in range(t): a, b = input().split() a, b = [int(a), int(b)] if a == b: print(0) elif b <= 1 and a != 0: print(-1) else: binary = bin(a) setBits = [ones for ones in binary[2:] if ones == "1"] countA = len(setBits) binary = bin(b...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR STRING AS...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def ones(n): o = 0 while n: if n % 2: o += 1 n //= 2 return o t = int(input()) while t: t -= 1 a, b = input().split() if a == b: print(0) continue elif b == "0": print(-1) continue elif b == "1": if a == "0": ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING IF VAR STRING EXPR FUNC_CALL VAR NUMBER...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
T = int(input()) for f in range(T): inp = list(map(int, input().split())) a = inp[0] b = inp[1] if a == b: ans = 0 elif b == 1 and a > 0: ans = -1 elif b == 0: ans = -1 else: b = b - 1 bbin = bin(b) abin = bin(a) b1 = bbin.count("1") ...
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 IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR ...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
for t in range(int(input())): A, B = map(int, input().split()) if A == B: print(0) elif B == 0: print(-1) elif B == 1: if A == 0: print(1) else: print(-1) else: a, b = bin(A).count("1"), bin(B - 1).count("1") if a == b: ...
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 NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_C...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def cnt(n): count = 0 while n > 0: if n % 2 == 1: count += 1 n = n // 2 return count t = int(input()) while t > 0: a, b = map(int, input().split()) c = cnt(a) d = cnt(b - 1) if a == b: print(0) elif b == 0 or b == 1 and a != 0: print(-1) ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR E...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def dtb(n): g = bin(n) k = len(g) m = g[2:k] return int(m) def jkl(p): c = 0 while p != 0: if p % 10 == 1: c = c + 1 p = p // 10 return c t = int(input()) for i in range(0, t): a, b = map(int, input().split()) if b == a: print(0) elif b == ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR ...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
a = int(input()) for i in range(a): qq = list(map(int, input().split())) a = qq[0] b = qq[1] if a == b: print(0) elif b == 0 or b == 1 and a != 0: print(-1) elif b == 1 and a == 1: print(1) else: b = b - 1 a = a q1 = bin(b)[2:].count("1") - bin...
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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR N...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
import itertools def bruteForceMethod(A, B): if B == 0: return -1 if A != 0 and B == 1: return -1 if A == B: return 0 if A + 1 == B: return 1 A_ = bin(A)[2:] B_ = bin(B)[2:] digitsToCheck, newDigitsFormed = {A}, set() iterationsMade = 0 while True: ...
IMPORT FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR F...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) while t: a, b = map(int, input().split(" ")) f = 0 if a == b: print(0) elif a == 0 and b == 1: print(1) elif b == 0 or b == 1: print(-1) else: f = f + 1 b = b - 1 x = 0 y = 0 while a: if a % 2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def countSetBits(num): binary = bin(num) setBits = [ones for ones in binary[2:] if ones == "1"] return len(setBits) t = int(input()) for _ in range(t): A, B = [int(x) for x in input().split()] set_A = countSetBits(A) set_B = countSetBits(B - 1) if A == B: print("0") elif A > 1 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR STRING RETURN FUNC_CALL VAR VAR 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FU...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
for i in range(int(input())): a, b = [int(x) for x in input().split()] if a == b: print(0) continue if b == 0 or b == 1 and a != 0: print(-1) continue one_a = bin(a)[2:].count("1") one_b = bin(b - 1)[2:].count("1") if one_a > one_b: print(2) elif one_a...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER NUMB...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
for t in range(int(input())): a, b = input().split() a, b = int(a), int(b) if a == b: print("0") elif b == 0: print(-1) elif b == 1: if a == 0: print(1) else: print(-1) else: a1 = bin(a) b1 = bin(b - 1) a1 = a1.count...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VA...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) while t: t = t - 1 s = input().split() a = int(s[0]) b = int(s[1]) if a == b: print(0) continue if b == 0 or b == 1 and a != 0: print(-1) continue x = bin(a).count("1") k = bin(b).count("1") + list(reversed(bin(b))).index("1") - 1 if k...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN 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 NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR V...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def setBits(n): cnt = 0 while n > 0: rsbm = n & -n n -= rsbm cnt += 1 return cnt t = int(input()) for i in range(t): a, b = list(map(int, input().split())) if a == b: print(0) continue elif b == 0: print(-1) continue elif b == 1: ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR 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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR ...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def count1(n): count = 0 while n > 0: count += n % 2 n = n // 2 return count for t in range(int(input())): a, b = map(int, input().split()) oa, ob = count1(a), count1(b - 1) ans = 0 if a == b: ans = 0 elif b == 0: ans = -1 elif b == 1: if a !...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN 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 FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NU...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
for T in range(int(input())): A, B = input().split() A = bin(int(A))[2:] B = bin(int(B))[2:] A1 = A.count("1") B1 = B.count("1") if A == B: print(0) continue if B == "1" or B == "0": print([-1, 1][B == "1" and A == "0"]) continue B1 = B1 + (len(B) - B.rind...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR STRING VAR STRING EXPR ...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
for t in range(int(input())): A, B = map(int, input().split(" ")) countA, countB = str(bin(A)).count("1"), str(bin(B - 1)).count("1") if A == B: print("0") elif A != 0 and (B == 0 or B == 1): print("-1") pass elif countA > countB: print("2") pass else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR F...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def bcnt(x): res = 0 for i in range(0, 64): if x >> i & 1 == 1: res = res + 1 return res for _ in range(0, int(input())): a, b = map(int, input().split()) if a == b: print(0) elif b == 0 and a > 0 or b == 1 and a > 1: print(-1) elif bcnt(a) > bcnt(b - 1)...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER 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 NUMBER IF VAR NUMBER VAR NUMBER VA...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
for _ in range(int(input())): a, b = [int(x) for x in input().split()] if a == b: print(0) elif a == 0 and b == 1: print(1) elif b <= 1: print(-1) else: b -= 1 x, y = bin(a)[2:], bin(b)[2:] c1, c2 = x.count("1"), y.count("1") if c1 == c2: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIG...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
for testc in range(int(input())): aa, bb = map(int, input().split()) b = "{0:b}".format(bb) a = "{0:b}".format(aa) na = a.count("1") nb = b.count("1") b = "0" * 60 + b l = len(b) odd = False if bb % 2 != 0: odd = True if nb == 0 and na != 0: print("-1") elif b...
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 FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NU...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input()) def f(A, B): str_A = bin(A)[2:] str_B = bin(B - 1)[2:] lhs = str_A.count("1") rhs = str_B.count("1") if A == B: return 0 if B == 0: return -1 if B == 1: if A == 0: return 1 else: return -1 if lhs == rhs: r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR VAR RE...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def count_ones(a): return bin(a)[2:].count("1") def count_opts(a, b): if a == b: return 0 elif b == 0: return -1 elif b == 1: if a == 0: return 1 else: return -1 opts = count_ones(b - 1) - count_ones(a) + 1 if opts > 0: return opt...
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN VAR RETURN NUMBER FOR VAR FUNC_CALL VAR F...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = int(input().strip()) for _ in range(t): a, b = map(int, input().strip().split()) d = b - a b_a = bin(a) b_b = bin(b) b_a = b_a[2:] b_b = b_b[2:] one_a = b_a.count("1") one_b = b_b.count("1") if d == 0: print("0") elif d == 1: print("1") elif b == 0 or b ==...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CA...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
t = input() t = int(t) for i in range(0, t): cnt = 0 a, b = map(int, input().split()) if a == b: print(0) continue if a == 0 and b == 1: print(1) continue if b <= 1: print(-1) continue b = b - 1 ba = list(map(int, list(bin(b))[2:])) aa = li...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER A...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero): write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any) shuffle the binar...
def num(A): cnt = 0 while A > 0: if A % 2 == 1: cnt += 1 A = A // 2 return cnt t = int(input()) for kk in range(t): A, B = list(map(int, input().split())) if A == B: print(0) elif B == 0 and A > 0: print(-1) elif B == 1 and A > 1: print(-...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR 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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER...