description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\...
query = int(input()) for q in range(query): num = bin(int(input()))[2:][::-1] length = len(num) ans = 0 for cnt, x in enumerate(num): if x == "0": ans += 2**cnt print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Given a long integer $\boldsymbol{x}$, count the number of values of $\class{ML__boldsymbol}{\boldsymbol{a}}$ satisfying the following conditions: $a\oplus x>x$ $0<a<x$ where $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{x}$ are long integers and $\oplus$ is the bitwise XOR operator. You are given $\...
import sys q = int(input().strip()) for a0 in range(q): x = int(input().strip()) answer = 0 for i in range(0, 33): if 1 << i >= x: break if 0 == x & 1 << i: answer = answer + (1 << i) print(answer)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER VAR VAR IF NUMBER BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation...
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: flips = 0 print(bin(a)) print(bin(b)) print(bin(c)) while a or b or c: if c % 2: if not (a % 2 or b % 2): flips += 1 else: flips += ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VA...
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation...
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: res = 0 for i in range(32): mask = 1 << i ai = a & mask bi = b & mask ci = c & mask if ci == 0: if ai and bi: res += 2 e...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation...
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: a = bin(a)[2:].zfill(32) b = bin(b)[2:].zfill(32) c = bin(c)[2:].zfill(32) count = 0 for i in range(32): temp_a = int(a[i]) temp_b = int(b[i]) temp_c = int(c[i]) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_C...
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation...
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: flips = 0 while a or b or c: if c & 1 == 0: if a & 1: flips += 1 if b & 1: flips += 1 elif a & 1 == 0 and b & 1 == 0: fl...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation...
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: i, j, k = bin(a)[2:], bin(b)[2:], bin(c)[2:] maxL = max(len(i), len(j), len(k)) i, j, k = ( "0" * (maxL - len(i)) + i, "0" * (maxL - len(j)) + j, "0" * (maxL - len(k)) + k, ) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL V...
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation...
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: stra = "{0:b}".format(a) strb = "{0:b}".format(b) strc = "{0:b}".format(c) n = max(len(stra), len(strb), len(strc)) stra = "0" * (n - len(stra)) + stra strb = "0" * (n - len(strb)) + strb strc...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_C...
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.   Example 1: Input: a = 2, b = 6, c = 5 Output: 3 Explanation...
class Solution: def minFlips(self, a: int, b: int, c: int) -> int: count = 0 while a or b or c: temp = a & 1 | b & 1 if temp != c & 1: if c & 1: count += 1 else: if a & 1: count +...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VA...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) i = 0 while i < t: l1, l2, l3, N = input().strip().split(" ") N = int(N) if (l1.count("0") == 0 and l2.count("0") == 0) and l3.count("0") == 0: print("1") elif l3.count("0") == 0 and l2.count("0") == 0: s1 = bin(int(l1, 2) + 1) s1 = s1[2 : len(s1)] print(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VA...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
import sys def ones(x): return sum(1 for c in list(x) if c == "1") def trailones(x): ret = 0 for c in reversed(list(x)): if c == "0": break ret += 1 return ret def solve(a, b, c, d): oc = ones(c) tc = trailones(c) if tc < len(c): return ones(a) + one...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
def inc(b): for i, c in reversed(list(enumerate(b))): if c == "0": b[i] = "1" break b[i] = "0" else: return 1 return 0 for _ in range(int(input())): a, b, c, n = input().split() a, b, c = (list(x) for x in (a, b, c)) n = int(n) r = 0 if i...
FUNC_DEF FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_C...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
import sys sys.setrecursionlimit(10**9) def pad(s): if s == "": return s if s[0] == "0": return pad(s[1:]) return s def pad1(s): if s == "": return s if s[0] == "1": return pad1(s[1:]) return s t = int(input()) while t > 0: t -= 1 s1, s2, s3, n = ma...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR STRING RETURN VAR IF VAR NUMBER STRING RETURN FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR STRING RETURN VAR IF VAR NUMBER STRING RETURN FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
for t in range(int(input())): l = list(input().strip().split()) l[3] = int(l[3]) str2 = l[2] str2 = str2[::-1] flag = [False] * 3 count = 1 i = 0 while i < len(str2) and str2[i] == "1": i += 1 if i == len(str2): flag[2] = True if not flag[2]: count = count...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMB...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) for i in range(0, t): count = 0 l1, l2, l3, n = map(str, input().split()) N = int(n) L = int(l3, 2) if len(l3) == l3.count("1"): if len(l2) == l2.count("1"): l = int(l1, 2) + 1 l1 = bin(l) L1 = l1.count("1") else: l4 = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_O...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
for _ in range(int(input())): a, b, c, n = map(str, input().split()) n = int(n) s = a + b + c c1 = a.count("1") + n * b.count("1") + c.count("1") l = len(s) i = l - 1 while i >= 0: if s[i] == "0": break i -= 1 if i == l - 1: print(c1 + 1) elif i ==...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR ...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
for i in range(0, int(input())): lst = [i for i in input().split()] s1, s2, s3, n = lst[0], lst[1], lst[2], int(lst[3]) o = 0 for i in s1: if i == "1": o += 1 for i in s2: if i == "1": o += n for i in s3: if i == "1": o += 1 o += 1 ...
FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER FOR VAR VAR IF VAR STRING VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER AS...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
for _ in range(int(input())): l = input().split() cnt = 0 for c in l[1]: cnt += c == "1" cnt *= int(l[3]) for c in l[0]: cnt += c == "1" for c in l[2]: cnt += c == "1" i = len(l[2]) - 1 while i >= 0 and l[2][i] == "1": cnt -= 1 i -= 1 if l[2] =...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER VAR VAR STRING VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER VAR VAR STRING FOR VAR VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER VAR STRI...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
for z in range(int(input())): li = [i for i in input().split()] ans, temp = 0, 0 if li[2][-1] == "0": ans = 1 for i in li[0]: if i == "1": ans += 1 for i in li[1]: if i == "1": temp += 1 temp *= int(li[3]) ans +=...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR FOR VAR VAR NUMBER IF VAR S...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) for i in range(t): l1, l2, l3, n = input().split() n = int(n) c = l1.count("1") + l2.count("1") * n + l3.count("1") len1, len2, len3 = len(l1), len(l2), len(l3) if l3[-1] == "0": print(c + 1) elif l3[-1] == "1": r = l3.rindex("0") if "0" in l3 else -1 if ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR ...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) for i in range(t): l1, l2, l3, n = map(lambda x: x.strip(), list(input().split())) n = int(n) x = l3.rfind("0") if x == -1: y = l2.rfind("0") if y == -1: z = l1.rfind("0") if z == -1: print(1) else: prin...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) for i in range(t): l1, l2, l3, n = map(str, input().split()) len1 = l1.count("1") len2 = l2.count("1") len3 = l3.count("1") if len3 == len(l3): if len2 == len(l2): if len1 == len(l1): print(1) else: ind = -1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) for t0 in range(t): l1, l2, l3, n = [i for i in input().strip().split()] n = int(n) s = 0 s1 = 0 if "0" in l3: r1 = l3.rindex("0") s = l1.count("1") + l2.count("1") * n + l3[0:r1].count("1") + 1 elif "0" in l2: r1 = l2.rindex("0") ct = l2[r1:].cou...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRIN...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
for t in range(eval(input())): lis = input().split() c3 = 0 flag = False for i in reversed(lis[2]): if flag and i == "1": c3 += 1 elif i == "0": flag = True c2 = 0 c21 = 0 for i in reversed(lis[1]): if i == "1": c21 += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR NUMBER IF VAR VAR ...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
def fdown(i): return i & i + 1 def actual_answer(value): count = 0 while value > 0: value = fdown(value) - 1 count += 1 return count t = int(input()) while t > 0: t -= 1 l1, l2, l3, n = input().split() n = int(n) case1 = int(l1 + l2 + l3, base=2) case2 = int(l1 + ...
FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VA...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
def check(s): size = len(s) end, total, found = 0, 0, True for i in range(len(s) - 1, -1, -1): if s[i] == "0": found = False if found: end += 1 if s[i] == "1": total += 1 return total, end, size for i in range(int(input())): l = list(map(...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL V...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) while t: t -= 1 inp = input().split() n = int(inp[3]) inp_1 = inp[0] inp_2 = inp[1] inp_3 = inp[2] len1 = len(inp_1) len2 = len(inp_2) len3 = len(inp_3) count = 1 c = len3 - 1 found_zero = 0 while c >= 0: if inp_3[c] == "0": found_...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP ...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
tes = int(input()) for _ in range(tes): a, b, c, n = [x for x in input().split()] n = int(n) ans = switch = 0 for i in range(len(c) - 1, -1, -1): if switch == 0: if c[i] == "0": switch = 1 ans += 1 if switch == 1: if c[i] == "1": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) ans = [] for i in range(t): ip = list(input().split(" ")) l1 = ip[0] l2 = ip[1] l3 = ip[2] n = int(ip[3]) zero_flag = 0 count = 0 rep_count = 0 for j in range(len(l3) - 1, -1, -1): if l3[j] == "1": count += 1 if zero_flag == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_O...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
def add_one(n, add_carry=False): n = list(n) l = len(n) carry = 1 for i in range(l - 1, -1, -1): if carry == 1: if n[i] == "1": n[i] = "0" else: n[i] = "1" carry = 0 if add_carry and carry == 1: n.insert(0, "1") ...
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING RETURN FUNC_CALL STRING VAR V...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) for i in range(t): l1, l2, l3, n = input().strip().split(" ") n = int(n) cnt = 0 if l3.count("0") == 0: if l2.count("0") == 0: ll1 = bin(int(l1, 2) + 1) ll1 = ll1[2 : len(ll1)] cnt = ll1.count("1") else: ll2 = bin(int(l2, 2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUM...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
T = int(input()) for _t in range(T): a, b, c, n = input().strip().split(" ") n = int(n) ans = 0 if "0" not in a + b + c: ans = 1 elif "1" not in a + b + c: ans = 0 else: if "0" in c: ans = 0 elif "0" in b: c = b n -= 1 e...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF STRING BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF STRING BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF STRING VAR ASSIGN VAR NUMBER IF S...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
def plusone(s): for i in range(len(s) - 1, -1, -1): if s[i] == "0": s[i] = "1" return i else: s[i] = "0" return -1 def countones(s): cnt = 0 for c in s: if c == "1": cnt += 1 return cnt T = int(input()) for t in range(T): ...
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING RETURN VAR ASSIGN VAR VAR STRING RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = input() t = int(t) while t: l1, l2, l3, n = input().split() n = int(n) counter = 0 t = t - 1 if l3.count("1") == len(l3): if l2.count("1") == len(l2): if l1.count("1") == len(l1): counter = 1 print(counter) continue ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN ...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
import sys t = int(input()) for i in range(t): s = input().strip().split() n = int(s[3]) l1 = "" l2 = "" l3 = "" if s[2][-1] == "0": print(1 + s[0].count("1") + n * s[1].count("1") + s[2].count("1")) else: l3 = bin(int(s[2], 2) + 1)[2:] if len(l3) <= len(s[2]): ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR NUMBER STRING BIN_OP VAR...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
for _ in range(int(input())): l1, l2, l3, n = [i for i in input().split()] n = int(n) if l3.find("0") == -1: if l2.find("0") == -1: if l1.find("0") == -1: print(1) else: s = l1[::-1] for i in range(len(s)): i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VA...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
for _ in range(int(input())): l1, l2, l3, n = [x for x in input().split()] allOne = 0 count = 0 last = len(l3) - 1 countl3 = l3.count("1") countl2 = l2.count("1") countl1 = l1.count("1") totalOne = countl1 + countl2 * int(n) + countl3 if len(l3) == countl3: count += countl3 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR ...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
for t in range(int(input())): s, s1, s2, n = [i for i in input().split()] sf = s co = 0 l = len(s) l1 = len(s1) l2 = len(s2) ns = s.count("1") ns1 = s1.count("1") ns2 = s2.count("1") co = ns + ns1 * int(n) + ns2 if s2[l2 - 1] == "0": co += 1 elif co == l + l1 * in...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) while t > 0: l = ["", "", ""] c = 1 l1, l2, l3, n = input().split(" ") n = int(n) a1, b1, c1 = l1.count("1"), l2.count("1"), l3.count("1") a0, b0, c0 = l1.count("0"), l2.count("0"), l3.count("0") if c0 == 0: if b0 == 0: if a0 == 0: print(1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FUNC...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) count = [] for i in range(t): s = input() a, b, c, n = s.split() n = int(n) d = int(a + b * n + c, 2) count.append(0) while d > 0: d = (d & d + 1) - 1 count[i] += 1 for i in range(t): print(count[i])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP ...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
def returnIndexAfterContinuousOnes(s): l = len(s) i = l - 1 while i >= 0 and s[i] == "1": i -= 1 return i def returnCountOfOnes(s, j): i = j sum = 0 while i >= 0: if s[i] == "1": sum += 1 i -= 1 return sum t = int(input()) for xyz in range(t): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUN...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) while t: a, b, c, d = input().split() d = int(d) an = a.count("1") + b.count("1") * d + c.count("1") lc = len(c) lb = len(b) la = len(a) cc = 0 cb = 0 ca = 0 for i in range(lc - 1, -1, -1): if c[i] == "0": break else: cc +=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VA...
Chef has just learned a new data structure - Fenwick tree. This data structure holds information about array of N elements and can process two types of operations: - Add some value to ith element of the array - Calculate sum of all elements on any prefix of the array Both operations take O(log N) time. This data stru...
t = int(input()) while t > 0: l1, l2, l3, n = map(str, input().split()) n = int(n) a = bin(int(l3, 2) + 1) if len(a) > len(l3) + 2: a = bin(int(l2, 2) + 1) if len(a) > len(l2) + 2: a = bin(int(l1, 2) + 1) if len(a) > len(l1) + 2: print(1) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUM...
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
t = int(input()) for _ in range(t): n, A = map(int, input().split()) if n == 1: if A & 1: print("Odd") else: print("Even") continue if A & 1 == 0: print("Impossible") continue if n & 1: print("Odd") else: print("Even")
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 BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_...
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
for _ in range(int(input())): n, a = map(int, input().split()) if a % 2: if n % 2: print("Odd") else: print("Even") elif n == 1: print("Even") else: print("Impossible")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
for a0 in range(int(input())): n, k = list(map(int, input().split())) if n == 1: if k % 2 == 0: print("Even") else: print("Odd") elif k % 2 == 1: if n % 2 == 0: print("Even") else: print("Odd") else: print("Impossibl...
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 IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRI...
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
num = int(input()) def answer(integer): if integer % 2 == 0: print("Even") else: print("Odd") while num: num -= 1 a1 = input().split() n, a = int(a1[0]), int(a1[1]) if n == 1: answer(a) continue if a % 2 == 0: print("Impossible") else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR F...
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
T = int(input()) for i in range(T): N, A = input().split() N = eval(N) A = eval(A) if A % 2 != 0: if N % 2 == 0: print("Even") else: print("Odd") elif N == 1: print("Even") else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_...
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
t = input() for c in range(0, int(t)): n, a = map(int, input().split()) if n == 1: if a % 2 == 1: print("Odd") elif a % 2 == 0: print("Even") elif n % 2 == 0: if a % 2 == 1: print("Even") else: print("Impossible") elif a % 2...
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CAL...
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
t = int(input()) for _ in range(t): n, a = list(map(int, input().split())) if n == 1: print("Odd" if a % 2 else "Even") else: x = a % 10 if x == 0 or x % 2 == 0: print("Impossible") else: print("Odd" if n % 2 else "Even")
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 NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP...
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
for _ in range(int(input())): n, a = [int(i) for i in input().split()] if n % 2 == 0 and a & 1 == 1 or n == 1 and a & 1 == 0: print("Even") elif n % 2 != 0 and a & 1 == 1: print("Odd") else: print("Impossible")
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 BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL ...
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
for i in range(int(input())): N, A = map(int, input().split()) BinS = bin(A)[2:] if BinS[len(BinS) - 1] == "1": if N % 2 == 0: print("Even") else: print("Odd") elif N == 1: if A % 2 == 0: print("Even") else: print("Odd") ...
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 NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC...
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
for _ in range(int(input())): d = {(1): "Odd", (0): "Even"} n, a = map(int, input().split()) if a % 2 != 0 or n <= 2: if n <= 2: print(d[a % 2]) else: print(d[n % 2]) else: print("Impossible")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER STRING STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
t = int(input()) for i in range(t): n, a = [int(x) for x in input().split()] if a & 1 == 1: if n & 1 == 1: result = "Odd" else: result = "Even" elif n == 1: result = "Even" else: result = "Impossible" print(result)
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 BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
t = int(input()) while t: n, a = map(int, input().split()) if a % 2 == 1: if n % 2 == 0: print("Even") else: print("Odd") elif a % 2 == 0: if n == 1: print("Even ") else: print("Impossible") t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined. ------ Input Format ------ - The first line of each input contains T - the number of test cases. The test cases then follow. - The only ...
def solve(n, a): if n == 1: if a & 1: return "Odd" else: return "Even" val = a & 1 if val == 1: return "Even" if n % 2 == 0 else "Odd" else: return "Impossible" for _ in range(int(input())): n, a = map(int, input().split()) print(solve(n,...
FUNC_DEF IF VAR NUMBER IF BIN_OP VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN BIN_OP VAR NUMBER NUMBER STRING STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR V...
Consider an array, $\mbox{A}$, of $n$ integers ($A=a_0,a_1,...,a_{n-1}$). We take all consecutive subsequences of integers from the array that satisfy the following: $\{a_i,a_{i+1},\ldots,a_{j-1},aj\},\text{where}\ 0\leq i\leq j<n$ For example, if $n=3$ our subsequences will be: $\boldsymbol{a_0}$ $a_1$ $a_2$ ...
def fwht(a): h = 1 while h < len(a): for i in range(0, len(a), h << 1): for j in range(i, i + h): k = j + h x = a[j] y = a[k] a[j] = x + y a[k] = x - y h <<= 1 n = int(input()) bits = 16 a = [0] * (1 <<...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR...
Consider an array, $\mbox{A}$, of $n$ integers ($A=a_0,a_1,...,a_{n-1}$). We take all consecutive subsequences of integers from the array that satisfy the following: $\{a_i,a_{i+1},\ldots,a_{j-1},aj\},\text{where}\ 0\leq i\leq j<n$ For example, if $n=3$ our subsequences will be: $\boldsymbol{a_0}$ $a_1$ $a_2$ ...
M = 1 << 16 def FWHT(V, inv=False): H = 1 while H < M: for L in range(0, M, 2 * H): for I in range(H): X = V[L + I] Y = V[L + H + I] V[L + H + I] = X - Y V[L + I] = X + Y if inv: V[L + H + I...
ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
T = int(input()) for _ in range(T): A, B = map(int, input().split()) i = 0 while 2**i < B - A: i += 1 ans = A & B & (4294967295 ^ 2**i - 1) print(ans)
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 WHILE BIN_OP NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
import sys __author__ = "mtadmk" def pr(a): if db: print(a) def process(a, b): act = a & b num = 1 while a + num < b: act &= a + num num *= 2 return act db = False if not db: n = int(input()) for i in range(0, n): a, b = list(map(int, input().split())) ...
IMPORT ASSIGN VAR STRING FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL V...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def and_product(fst, secnd): fst = list(bin(fst))[2:] secnd = list(bin(secnd))[2:] if len(fst) != len(secnd): return 0 num = 0 same = True for ind in range(len(fst)): num *= 2 same &= fst[ind] == secnd[ind] if same: num += int(fst[ind]) return num ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN ...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def main(): for _ in range(int(input())): A, B = map(int, input().split()) A = bin(A)[2:] B = bin(B)[2:] answer = "" A = "0" * (32 - len(A)) + A B = "0" * (32 - len(B)) + B for i in range(32): if A[i] != B[i]: break answ...
FUNC_DEF 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER ...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
for _ in range(int(input())): a, b = (int(f) for f in input().split()) result = 0 bit = 1 while bit <= b: if bit & a & b: result |= bit elif bit & a != bit & b: result = 0 bit <<= 1 print(result)
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 NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
t = int(input()) for i in range(t): a, b = [int(x) for x in input().split()] x = a ^ b s = x >> 1 while s != 0: x = x | s s >>= 1 print(a & b & ~x)
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 BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
a = 0 b = 0 c = 0 result = 0 current = 0 for i in range(0, int(input())): a, b = input().split() c = 0 while int(a) | c < int(b): c = c << 1 | 1 result = int(a) & ~c print(result)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FU...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def calc_and(a, b): result = 0 distance = b - a + 1 for i in range(0, 32): if distance <= 1 << i: mask = 1 << i if a & mask == b & mask: result = result | a & mask return result def main(): T = int(input()) for t in range(0, T): var = inp...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR A...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def bitLen(int_type): length = 0 while int_type: int_type >>= 1 length += 1 return length T = int(input()) for j in range(T): A, B = input().split(" ") A = int(A) B = int(B) result = 0 lengthA = bitLen(A) lengthB = bitLen(B) while lengthA == lengthB: tem...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR 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 FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
T = int(input()) for _ in range(T): A, B = (bin(int(i))[2:] for i in input().split()) max_length = max(len(A), len(B)) A, B = (x.zfill(max_length) for x in (A, B)) i = 0 result = "" while i < max_length and A[i] == B[i]: result += A[i] i += 1 result += "0" * (max_length - i) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR VAR VAR VAR VAR VAR V...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
for _ in range(int(input())): A, B = [int(i) for i in input().split()] v = A ^ B v |= v >> 1 v |= v >> 2 v |= v >> 4 v |= v >> 8 v |= v >> 16 print(A & ~v)
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 BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def run(a, b): if len(bin(b)) > len(bin(a)): return 0 d = len(bin(b - a)) - 2 a_, b_ = int(bin(a)[:-d], 2), int(bin(b)[:-d], 2) s = a_ for x in range(a_ + 1, b_ + 1): s &= x return s * 2**d for _ in range(int(input())): a, b = [int(x) for x in input().split()] print(run...
FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
t = int(input()) for uuhhhj in range(t): a = [int(i) for i in input().split()] p = bin(a[0]) q = bin(a[1]) m = min(len(p), len(q)) - 2 p = p[-m:] q = q[-m:] s = "0b" t = 0 for i in range(m): if p[i] != q[i] or t == 1: t = 1 s += "0" else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN 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 BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR ST...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
t = int(input().strip()) while t > 0: a, b = [int(i) for i in input().strip().split(" ")] count = 1 while a != b: a = int(a / 2) b = int(b / 2) count *= 2 t -= 1 print(int(count * a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def reduce_and(a, b): bits_to_ignore = (a - b).bit_length() - 1 mask = 2**bits_to_ignore - 1 a |= mask a ^= mask interval = 2**bits_to_ignore result = a for val in range(a, b + 1, interval): result &= val return result count = int(input()) for i in range(count): a, b = [int...
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL V...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def my_bin(n, length=32): t = str(bin(n))[2:] ans = "0" * (length - len(t)) + t return ans for t in range(int(input())): a, b = [int(i) for i in input().split()] a = my_bin(a) b = my_bin(b) ans = [0] * 32 for i in range(32): if a[i] == b[i]: ans[i] = a[i] el...
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN VAR 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VA...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def solve(A, B): if A == B: return A a, b, i, j = A, B, 0, 0 while a > 0 or b > 0: if (a ^ b) & 1: j = i a >>= 1 b >>= 1 i += 1 return A & -(2**j) T = int(input()) for _ in range(T): A, B = (int(_) for _ in input().split()) print(solve(A, B))
FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VA...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
for T in range(int(input())): A, B = map(int, input().split()) ans = 0 for i in range(32): k = A + (1 << i) >> i if k << i >= B + 1 and k & 1 == 0: ans |= 1 << i print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def min_and(a, b): for i in range(a.bit_length(), -1, -1): mask = 2**i if a & mask != b & mask: return sum(a & 2**j for j in range(i + 1, a.bit_length())) return a & a + 1 test_cases = int(input().strip()) for _ in range(test_cases): a, b = [int(n) for n in input().strip().spli...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_C...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
import sys n = int(sys.stdin.readline().strip()) for i in range(n): cl = [int(num) for num in sys.stdin.readline().strip().split(" ")] x = 0 while cl[0] | x < cl[1]: x = x << 1 | 1 print(cl[0] & ~x)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
t = int(input()) for w in range(t): start, end = list(int(i) for i in input().split()) testLow = int.bit_length(start) testHigh = int.bit_length(end) if testHigh > testLow: print(0) else: result = start shift = 0 while start <= end: while start & 1 == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR 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 ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUM...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
for _ in range(int(input())): a, b = [int(i) for i in input().strip().split()] diff = b - a n = 0 while diff: diff >>= 1 n += 1 res = (a & b) >> n << n print(res)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def and_product(a, b): l1 = len(a) l2 = len(b) b = b[l2 - l1 :] i = 0 res = "" while a[i] == b[i]: res += a[i] i += 1 res += "0" * (l1 - i) return btd(res) def dtb(n): ans = "" while n != 0: ans += str(n % 2) n = n // 2 return ans[::-1] def...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP STRING BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR STRING WHILE VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSI...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
T = int(input()) for _ in range(T): A, B = map(lambda x: bin(int(x)), input().split()) ans = "" for ind, digit in enumerate(A): if ind < 2: continue if digit == B[ind]: ans += digit else: ans += "0" * (len(B) - ind) break print(int(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR VAR VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR N...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
author = "Ashu" tc = int(input()) for _ in range(tc): x = input().split() a = int(x[0]) b = int(x[1]) r = 0 while a | r < b: r = r << 1 | 1 print(a & ~r)
ASSIGN VAR STRING 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 ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def and_product(start, end): result = start steps = end - start i = 0 while start >> i > 0: if lmask(start, i + 1) + steps > lmask(-1, i + 1): result = bitmask(result, i) i += 1 return result def lmask(n, k): return n & (1 << k) - 1 def bitmask(n, k): return n...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF RETURN BIN_O...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
T = int(input()) for _ in range(T): l, r = [int(i) for i in input().split()] x1 = x2 = l ^ r while x1: x1 >>= 1 l >>= 1 while x2: x2 >>= 1 l <<= 1 print(l)
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 VAR BIN_OP VAR VAR WHILE VAR VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def calc(a, b): if a == 0 and b == 0: return 0 if a == 1 and b == 1: return 1 res = "0" for i in range(1, 32): if 2**i & a > 0: if b >= a + 2**i: res = "0" + res else: res = "1" + res else: res = "0" + re...
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR RETURN FUNC_CALL ...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
t = int(input()) for _ in range(t): a, b = map(int, input().split()) result = 1 aBinary, bBinary = bin(a)[2:], bin(b)[2:] aBinary = "0" * (len(bBinary) - len(aBinary)) + aBinary result = "" for i in range(len(aBinary)): if aBinary[i] == bBinary[i]: result += aBinary[i] ...
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 ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL ...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
t = int(input()) for i in range(0, t): s = input() ss = s.split(" ") a = int(ss[0]) b = int(ss[1]) pow = 0 while 1: if 2**pow > a: break else: pow = pow + 1 if 2**pow > b and 2 ** (pow - 1) < b: aa = "{0:b}".format(a) bb = "{0:b}".forma...
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 NUMBER WHILE NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP NU...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
T = int(input()) for _ in range(T): A, B = [int(x) for x in input().split()] a = bin(A)[2:] b = bin(B)[2:] if len(a) != len(b): print(0) else: i = 0 while i < len(a): if a[i] != b[i]: break i += 1 c = a[:i] while len(c) ...
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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR ...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
T = int(input()) for _ in range(T): A, B = (int(_) for _ in input().split()) i, C = -1, A ^ B while C > 0: C >>= 1 i += 1 print(A & 2**32 - 2**i)
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 VAR NUMBER BIN_OP VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
for _ in range(int(input())): a, b = list(map(int, input().split())) a, b = bin(a)[2:], bin(b)[2:] if len(a) != len(b): print(0) else: res = 0 for i in range(len(a)): if a[i] == b[i] == "1": res |= 1 << len(a) - i - 1 elif a[i] == "0" and b...
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 VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
for t in range(int(input())): a, b = map(int, input().split()) answer = a for i in range(32): d = 1 << i if a & d and (not b & d or b - a >= d): answer ^= d print(answer)
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 FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
n = int(input()) while n > 0: n -= 1 numbers = input().split() numbers = [int(x) for x in numbers] a = numbers[0] b = numbers[1] ans = 0 i = 31 while i >= 0: temp = 1 temp = temp << i i -= 1 if a & temp != 0 and b & temp == 0: break eli...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
T = int(input()) for _ in range(T): A, B = tuple([int(token) for token in input().split()]) diff = A ^ B diff = diff | diff >> 1 diff = diff | diff >> 2 diff = diff | diff >> 4 diff = diff | diff >> 8 diff = diff | diff >> 16 R = A & B & ~diff print(R)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR N...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
for _ in range(int(input())): l, h = [bin(int(x))[2:] for x in input().split()] if len(l) != len(h): print(0) elif l == h: print(int(l, 2)) else: for i in range(1, len(l)): if l[i] != h[i]: print(int(l[:i] + "0" * (len(l) - i), 2)) brea...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR EX...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
t = int(input()) for k in range(t): a, b = map(int, input().split(" ")) x = 0 while a | x < b: x <<= 1 x |= 1 print(a & ~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 STRING ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def and_product(a, b): b_str = bin(b)[2:] a_str = bin(a)[2:].zfill(len(b_str)) result = [] for i in range(len(b_str)): if a_str[i] == b_str[i]: result.append(b_str[i]) else: break while len(result) != len(b_str): result.append("0") return int("".jo...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN FUNC_CALL VAR FUNC_CALL STRING VAR...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def andpro(A, B): lenA = len("{0:b}".format(A)) lenB = len("{0:b}".format(B)) if lenA == lenB: i = 0 strA = "{0:b}".format(A) strB = "{0:b}".format(B) curr = "" for i in range(lenA): if strA[i] == strB[i]: curr += strA[i] else: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR FUNC...
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
def andProduct(A, B): shift_amount = 0 while A != B: A = A >> 1 B = B >> 1 shift_amount += 1 return A << shift_amount T = int(input()) for _ in range(T): A, B = map(int, input().split(" ")) print(andProduct(A, B))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR 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 STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Consider two non-negative long integers, $a$ and $\boldsymbol{b}$, where $a\leq b$. The bitwise AND of all long integers in the inclusive range between $a$ and $\boldsymbol{b}$ can be expressed as $a\ \text{&}\ (a+1)\ \text{&}\ \ldots\ \text{&}\ (b-1)\ \text{&}\ b$, where $\text{&}$ is the bitwise AND operator. Given...
T = int(input()) while T: A, B = map(int, input().split()) if A == B: print(A) T -= 1 continue a, b = map(bin, (A, B)) dif = len(bin(B - A)[2:]) a, b = a[2:], b[2:] x, y = len(a), len(b) if y > x: print(0) T -= 1 continue ret = "0" * dif ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR V...