description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator . $\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For e...
t = int(input()) for i in range(t): n, m = map(int, input().split()) s1 = [] s2 = [] for j in range(33): u = n >> j v = m >> j s1.append(u & 1) s2.append(v & 1) ans = 0 for j in range(33): if s2[j] == 1: v = j for j in range(v + 1): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR ...
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator . $\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For e...
from sys import * ws = lambda: map(int, stdin.readline().strip().split()) li = lambda: list(map(int, stdin.readline().strip().split())) mod = 1000000007 def ncr(n, r, p): num = den = 1 for i in range(r): num = num * (n - i) % p den = den * (i + 1) % p return num * pow(den, p - 2, p) % p ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
T = int(input()) for i in range(T): Nlen, Query = map(int, input().split()) Alist = list(map(int, input().split())) prefixlist = [([0] * 60) for i in range(Nlen + 1)] for i in range(1, Nlen + 1): for k in range(60): prefixlist[i][-k - 1] = prefixlist[i - 1][-k - 1] + Alist[i - 1] % 2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUN...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
for _ in range(int(input())): a = list(map(int, input().split())) l = list(map(int, input().split())) re = [] for i in range(62): r = [] d = 0 for j in l: if j & 1 << i: d += 1 r.append(d) re.append(r) for i in range(a[1]): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER EX...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
for i in range(int(input())): n, q = map(int, input().split()) a = list(map(int, input().split())) bits = [0] * 60 f = [] for s in a: for j in range(60): if s & 2**j == 2**j: bits[j] += 1 k = bits.copy() f.append(k) for j in range(q): k...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR VA...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
for t in range(int(input())): n, q = map(int, input().split()) a = list(map(int, input().split())) check = [[(0) for i in range(60)] for j in range(n + 1)] for i in range(n): for j in range(60): check[i + 1][j] = check[i][j] + (a[i] >> j & 1) for x in range(q): k, l1, r1,...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR B...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
def KthBit(n, k): if n < 2**k: return 0 else: k += 1 return (n & 1 << k - 1) >> k - 1 for _ in range(int(input())): n, q = map(int, input().split()) z = lambda x: bin(int(x))[2:] arr = list(map(int, input().split())) pre = [] for i in range(60): temp = [0] ...
FUNC_DEF IF VAR BIN_OP NUMBER VAR RETURN NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER 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 FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
BITS = 60 class Numbers: def __init__(self, numbers): self.numbers = numbers self.ac = [([0] * BITS) for _ in range(len(numbers))] previous = [0] * BITS for i, number in enumerate(numbers): for k in range(BITS): self.ac[i][k] = previous[k] + (1 if numbe...
ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
for i in range(int(input())): n, q = map(int, input().split()) l = list(map(int, input().split())) b = [0] * 60 d = {} d[0] = [0] * 60 j = 1 for i in l: b1 = bin(i)[2:][::-1] for i in range(len(b1)): if b1[i] == "1": b[i] += 1 b2 = b.copy()...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CAL...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
R = lambda: map(int, input().split()) (t,) = R() for _ in range(t): n, q = R() a = [([0] * (n + 1)) for _ in range(60)] for i, x in enumerate(R()): for j, b in enumerate(a): b[i + 1] = b[i] + (x >> j & 1) for _ in range(q): k, l1, r1, l2, r2 = R() l1 -= 1 l2 -...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
for _ in range(int(input())): n, q = map(int, input().split()) m = [int(i) for i in input().split()] l = [] lx = [] for i in range(n): z = [0] * 60 l.append(z) z1 = [0] * 60 lx.append(z1) for i in range(n): k = 0 j = m[i] while j: ...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER E...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
t = int(input()) for _ in range(t): n, q = map(int, input().split()) arr = list(map(int, input().split())) prefik = dict() for k in range(60): setk = 0 prefik[0, k] = 0 for i in range(n): setk += (arr[i] >> k) % 2 prefik[i + 1, k] = setk for _ in range...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
def toBin(n): return bin(n).replace("0b", "") def isValid(num, k): st = toBin(num) st = list(st) st = st[::-1] if k < len(st) and st[k] == "1": return True return False for _ in range(int(input())): n, q = map(int, input().split()) nums = list(map(int, input().split())) a...
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR STRING RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VA...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
for t in range(int(input())): n, q = [int(i) for i in input().split(" ")] a = [int(i) for i in input().split(" ")] pre = [] for i in range(n + 1): pre.append([]) pre[i] = [(0) for i in range(64)] for i in range(1, n + 1): for j in range(64): pre[i][j] += pre[i - 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 STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUN...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
def main(): t = int(input()) for _ in range(t): n, q = map(int, input().split()) l = [int(x) for x in input().split()] a = [[(0) for i in range(n + 1)] for j in range(61)] for i in range(61): for j in range(1, n + 1): if (l[j - 1] >> i) % 2 == 1: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NU...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
for i in range(int(input())): n, q = map(int, input().split()) a = list(map(int, input().split())) c = a.copy() mp = [] for f in range(61): c[0] = c[0] >> f & 1 for j in range(1, n): c[j] = (c[j] >> f & 1) + c[j - 1] mp.append(c) c = a.copy() for j in ...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR ...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
t = int(input()) for _ in range(t): n, q = map(int, input().split()) arr = list(map(int, input().split())) pf = [[0] for _ in range(60)] for i in range(n): for b in range(60): if arr[i] & 1 << b: pf[b].append(pf[b][-1] + 1) else: pf[b].appe...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUM...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
power = [pow(2, i) for i in range(60)] t = int(input()) for T in range(t): n, q = map(int, input().split()) a = list(map(int, input().split())) pre = [[(0) for j in range(n)] for i in range(60)] for i in range(n): for j in range(60): if a[i] & power[j] > 0: pre[j][i] ...
ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR V...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
def soln(n, q, arr, queries): n = len(arr) dp = [([0] * (n + 1)) for _ in range(60)] for i in range(60): prev = 0 mask = 1 << i for j in range(n): if mask & arr[j]: prev += 1 dp[i][j + 1] = prev else: dp[i][j + 1...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
def solve(): n, q = map(int, input().split()) a = list(map(int, input().split())) p = [] for i in range(60): p.append([0] * (n + 1)) d = 1 for j in range(60): for i in range(n): p[j][i + 1] = p[j][i] + (1 if a[i] & d > 0 else 0) d *= 2 for _q in range(q): ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VA...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
for _ in range(int(input())): n, q = map(int, input().split()) a = list(map(int, input().split())) d = {} for i in range(60): t0 = [0] t1 = [0] for j in a: if j & 2**i == 0: t0.append(t0[-1] + 1) t1.append(t1[-1] + 0) 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
t = int(input()) while t > 0: n, q = input().split() q = int(q) Arr = [int(x) for x in input().split()] m = max(Arr) msb = 0 for i in range(31, 0, -1): if m >> i & 1 == 1: msb = i break temp = [[(0) for _ in range(60)]] for i in Arr: te = [(0) for ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
for _ in range(int(input())): msn, msq = map(int, input().split()) msl = list(map(int, input().split())) bit_count = [([0] * 60) for __ in range(msn + 1)] for i in range(1, msn + 1): num = msl[i - 1] for j in range(60): bit_count[i][j] = bit_count[i - 1][j] + (num >> j & 1) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR ...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
def solution(n, q, a, queries): dp = [[(0) for j in range(n + 1)] for i in range(60)] for i in range(n): num = a[i] k = 0 while num >> k: dp[k][i + 1] = num >> k & 1 k += 1 for k in range(60): for i in range(n): dp[k][i + 1] += dp[k][i] ...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR N...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
def prefix(a, n): pref = [] for i in range(61): pref.append([]) for j in range(n): tst = a[j] & 1 << i if tst: pref[i].append(1) else: pref[i].append(0) for i in range(61): for j in range(1, n): pref[i][j...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR IF VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETUR...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
t = int(input()) for i in range(t): n, q = map(int, input().split()) a = list(map(int, input().split())) zeros = [[(0) for di in range(n + 1)] for dj in range(60)] ones = [[(0) for ci in range(n + 1)] for cj in range(60)] for bi in range(1, n + 1): bf = bin(a[bi - 1])[::-1] for bj in...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBE...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
def isKthSet(n: int, k: int): return int(bool(n & 1 << k)) t = int(input()) for _ in range(t): n, q = map(int, input().split()) arr = list(map(int, input().split())) c1 = [] for i in range(60): l = [0] for j in range(n): l.append(l[-1] + isKthSet(arr[j], i)) c1....
FUNC_DEF VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIG...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): return input().strip() def invr(): return map(int, input().split()) def outp(n): sys.stdout.write(str(n) + "\n") def outlt(lst): sys.stdout.write(" ".j...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL ...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
def binary(n): ans = "" count = 0 while n > 0: ans += str(n % 2) count += 1 n = n // 2 return (64 - count) * "0" + ans[::-1] for _ in range(int(input())): n, q = map(int, input().split()) lst = list(map(int, input().split())) binary_lst = [0] * n grand_count_zer...
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP NUMBER VAR STRING VAR NUMBER 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_CA...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
import sys input = sys.stdin.readline def main(): for testcases in range(int(input())): n, q = map(int, input().split()) array = list(map(int, input().split())) prefk = [[] for _ in range(60)] for k in range(60): for i in range(n): bitset = array[i] >> ...
IMPORT ASSIGN VAR VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP B...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
for i in range(int(input())): n, q = input().split() n = int(n) q = int(q) arr = [int(x) for x in input().split()] matrix = [[(0) for i in range(60)] for j in range(len(arr))] for i in range(len(arr)): j = 0 for j in range(60): if arr[i] & 1 == 1: matr...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR V...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
def ans(l): n = len(l) z = [[(0) for i in range(61)] for j in range(len(l) + 1)] for i in range(len(l)): for j in range(61): z[i + 1][j] = z[i][j] + (l[i] >> j) % 2 return z t = int(input()) for _ in range(t): a, b = map(int, input().split()) l = list(map(int, input().split...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
def preprocess(n): prep = [([0] * 60) for _ in range(len(n) + 1)] for i in range(len(n)): for j in range(60): prep[i + 1][j] = prep[i][j] if n[i] >> j & 1 == 1: prep[i + 1][j] += 1 return prep def solve(prep, q): toti = q[2] - q[1] + 1 totj = q[4] - ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
def checkbit(n, i): if n >> i & 1 == 1: return True return False t = int(input()) for _ in range(t): n, q = map(int, input().split()) l = [] arr = list(map(int, input().split())) for i in range(60): l1 = [] l1.append(0) s = 0 for j in range(n): ...
FUNC_DEF IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER 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 LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
for _ in range(int(input())): n, q = map(int, input().split()) l = [int(x) for x in input().split()] ans = [] for i in range(60): x = [] s = 0 for j in range(n): if 1 << i & l[j]: s += 1 x.append(s) ans.append(x) for i in range(...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR NUMBER EXPR...
*A Binod is a person who is very good with bitwise operations. Help Alice solve the following problem and become a Binod.* You are given an array A of N elements. Process Q queries on this array, of the following form: Each query contains 5 integers k, L_{1}, R_{1}, L_{2}, R_{2}. It is guaranteed that L_{1} ≀ R_{1} < ...
import sys input = sys.stdin.readline T = int(input()) for _ in range(T): n, q = map(int, input().split()) A = list(map(int, input().split())) DP = [[(0) for i in range(n)] for j in range(61)] for i in range(n): val = A[i] for j in range(61): if val & 1 << j: ...
IMPORT ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
t = int(input()) for _ in range(t): n = int(input()) d = [[(0) for i in range(33)] for j in range(n + 1)] l = list(map(int, input().strip().split(" "))) for i in range(n): t = l[i] c = 0 while t != 0: t = t // 2 c = c + 1 for j in range(33): ...
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 VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN V...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) q = int(input()) o = {x: [(1) for _ in range(n)] for x in range(1, 33)} for i, item in enumerate(a): e = bin(item)[2:] index = None for j, digit in enumerate(e[::-1]): if digit == "...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CAL...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
import sys sys.setrecursionlimit(10**5) def hsb(x): for i in range(31, -1, -1): if x & 1 << i: return i return 32 def pro(arr, q): n = len(arr) lst = [[0] * 33] for i in range(n): if i: lst.append(lst[i - 1].copy()) lst[i][hsb(arr[i])] += 1 fo...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) sett = [[(0) for i in range(32)] for j in range(n + 1)] for i in range(n): ele = arr[i] msb = 0 while ele > 0: msb += 1 ele = ele // 2 for k in range(32): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE V...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
def calculateMSB(number): if number == 0: return 0 block = 0 while number >> block: block += 1 return block def solution(): N = int(input()) array = list(map(int, input().split())) p = [[(0) for i in range(32)] for i in range(N + 1)] for i in range(N): b = calcu...
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR AS...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) res = [] for k in range(32): L = [] c = 0 for l in range(n): if k == 0: if arr[l] == 0: c += 1 L.append(c) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR NUMBER E...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
def top_set_bit(x): if x == 0: return int(0) return 1 + int(top_set_bit(x >> 1)) T = int(input()) for i in range(T): N = int(input()) values = [int(i) for i in input().split()] for i in range(N): values[i] = top_set_bit(values[i]) dp = [] for j in range(32): dp.appe...
FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
LIM = 2 * 10**5 + 10 def HBIT(n): bit = -1 while n: bit += 1 n >>= 1 return bit hbitCount = [([0] * LIM) for i in range(32)] totalPos = [0] * LIM def prep(A, N): for ind in range(N + 1): totalPos[ind] = 0 for bit in range(32): hbitCount[bit][ind] = 0 ...
ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMB...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x in input().split()] q = int(input()) pre = [] for i in a: if i == 0: pre.append(0) else: pre.append(len(bin(i)) - 2) mat = [] k = [0] * 32 mat.append([0] * 32) for i in pre:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VA...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
T = int(input()) for t in range(T): N = int(input()) A = [int(a) for a in input().split()] B = [] for a in A: if a == 0: B.append(0) elif a == 1: B.append(1) else: i = 0 b = a while b > 0: b = b >> 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER A...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
t = int(input()) for i in range(0, t): n = int(input()) myList = list(map(int, input().strip().split()))[:n] myProcessedData = [] for i in range(0, 33): temp = [] for j in range(0, n + 1): temp.append(0) myProcessedData.append(temp) for j in range(1, n + 1): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CAL...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
def msb(n): ans = 1 count = 0 while n: n = n >> 1 count += 1 return count t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) dp = [[(0) for j in range(32)] for i in range(n + 1)] for i in range(n): res = msb(arr[i]) ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN 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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
def readInt(): return int(input()) def readInts(): return [int(x) for x in input().split()] def readString(): return input().rstrip() def readStrings(): return input().split() def readCase(): n = readInt() numbers = readInts() q = readInt() queries = [readInts() for _ in range(q)...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RET...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
def log(x, y): coun = 0 while x >= y: coun += 1 x //= y return coun for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) q = int(input()) lst = [([0] * (n + 1)) for i in range(32)] for i in range(1, n + 1): for j in range(32): ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FU...
A number M is said to be a *Mystical Number* with respect to a number X if (M \oplus X) > (M \& X). You are given an array A of size N. You are also given Q queries. Each query consists of three integers L, R, and X. For each query, find the count of *Mystical Numbers* in the subarray A[L:R] with respect to the numbe...
def msb(n): ans = 0 while n > 0: n >>= 1 ans += 1 return ans for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) arr1 = [([0] * 32) for _ in range(n)] arr1[0][msb(arr[0])] += 1 for i in range(1, n): temp = msb(arr[i]) for...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
c, d = map(int, input().split()) a = min(c, d) b = max(c, d) w = b - a c = b * a e = 0 for i in range(1, int(w**0.5) + 1): if w % i == 0: if b % i == 0: q1 = b // i q2 = a // i else: q1 = b // i + 1 q2 = a // i + 1 if i * q1 * q2 < c: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER AS...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = map(int, input().split()) if a < b: a, b = b, a if a == b: print(0) exit() def update(g): global ans if a % g != b % g: return n = g - a % g if a % g else 0 lcm = (a + n) * (b + n) // g ans = min(ans, (lcm, n)) d = a - b ans = 10**31, 10**31 for gcd in range(1, int(d**...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR VAR BIN_OP VAR VAR RETURN ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = map(int, input().split()) if a < b: a, b = b, a d = [] ab = a - b for i in range(1, int(ab**0.5) + 1): if ab % i == 0: d.append(i) if i != ab // i: d.append(ab // i) mink = 0 minlcm = float("inf") for i in d: if b % i == 0: k = 0 else: k = (b // i + 1) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN V...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
def gcd(a, b): return a if b == 0 else gcd(b, a % b) def lcm(a, b): return a / gcd(a, b) * b def main(): a, b = [int(x) for x in input().split()] d = 1 if a == b: print("%d" % 0) return if a > b: a, b = b, a ans = lcm(a, b) kans = 0 while d * d <= b - a: ...
FUNC_DEF RETURN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING NUMBER RETURN IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
def mp(): return map(int, input().split()) def gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return a * b // gcd(a, b) a, b = mp() a, b = min(a, b), max(a, b) x = [] w = b - a dl = 1 while dl**2 <= w: if w % dl == 0: x.append(dl) x.append(w // dl) ...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR VA...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
def gcd(a, b): if b == 0: return a return gcd(b, a % b) a1, b1 = map(int, input().split()) a = min(a1, b1) b = max(a1, b1) diff = b - a div = [] if a == b: print(0) exit() for i in range(1, int(diff**0.5) + 1): if diff % i == 0: zz = diff // i div.append(i) if i != ...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUM...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
def gcd(p, q): while p: p, q = q % p, p return q I = lambda: map(int, input().split()) a, b = I() a, b = min(a, b), max(a, b) if b % a == 0: exit(print("0")) k1 = 0 t = b - a ans = 100 minn = 10**31 k = 100 for i in range(1, int(t**0.5) + 1): if t % i == 0: g = i k = (g - a % g...
FUNC_DEF WHILE VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
def gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return a * b / gcd(a, b) arr = input() A, B = [int(x) for x in arr.split(" ")] d = abs(A - B) divisiors = [] for i in range(1, 100000): if i * i > d: break elif d % i == 0: divisiors.append(i) ...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP V...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = sorted(list(map(int, input().split()))) if a == b: print(0) elif a > b - a: if a % (b - a) == 0: print(0) else: print(b - a - a % (b - a)) elif (b - a) % a == 0: print(0) else: ans = float("inf") for q in range(1, int((b - a) ** (1 / 2)) + 2): if (b - a) % q == 0: ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_C...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
def solve(a, b): if a > b: a, b = b, a d = b - a if d <= 1: return 0 if d > a: if d % a == 0: return 0 i = a q = [] while i * i <= d: if d % i == 0: return i - a i += 1 if a * a > d: i...
FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR N...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = map(int, input().split()) a, b = min(a, b), max(a, b) if a == b: print(0) else: M, u = 2 * a * b, 0 D = 1 while D * D <= b - a: if (b - a) % D == 0: for d in (D, (b - a) // D): k = 0 if a % d != 0: k = d - a % d ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR VAR BIN_OP BIN_OP ...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = list(map(int, input().split())) a, b = min(a, b), max(a, b) if b < 2 * a: if a == b: print(0) exit() print(-a % (b - a)) exit() s = [1] q = b - a for i in range(2, int((b - a) ** (1 / 2) + 2)): while q % i == 0: t = [(j * i) for j in s] for aa in t: s.a...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP VAR ...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
A, B = map(int, input().split()) def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) def lcm(a, b): return a * b // gcd(a, b) def primeFactor(N): i = 2 ret = {} n = N if n < 0: ret[-1] = 1 n = -n if n == 0: ret[0] = 1 d = 2 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR NUMBER ASS...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
def euc(x, y): x, y = max(x, y), min(x, y) if x % y == 0: return y while x % y != 0: x, y = y, x % y return y def lcm(x, y): return x * y // euc(x, y) a, b = map(int, input().split()) a, b = max(a, b), min(a, b) if a == b: ans = 0 else: s = a - b c, d = a + (1 + b // ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL V...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
def hcf(a, b): while a: temp = a a = b % a b = temp return b def lcm(a, b): return a * b // hcf(a, b) def check(a, b, ko, kn, min_lcm): val = lcm(a + kn, b + kn) if min_lcm == -2: min_lcm = val elif val < min_lcm: min_lcm = val ko = min(ko, kn)...
FUNC_DEF WHILE VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR ...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = input().split() a, b = int(a), int(b) a, b = min(a, b), max(a, b) def eu(a, b): if a == 0: return b if b == 0: return a if a > b: return eu(a % b, b) return eu(a, b % a) opt = b - a factor = [] i = 1 while i**2 < opt + 1: if opt % i == 0: factor.append(i) ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
n = list(map(int, list(input().split()))) v = [n[0], n[1]] x = max(v) y = min(v) def gcd(x, y): while y != 0: x, y = y, x % y return x def lcm2(x, y): return x * y / gcd(x, y) def getFactors(n): factors1 = [] factors = [] for i in range(1, n + 1): if n % i == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASS...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = map(int, input().split()) a, b = min(a, b), max(a, b) def divisors(n): div = [] for i in range(1, int(n ** (1 / 2)) + 1): if n % i == 0: div.append(i) if i * i != n: div.append(n // i) return sorted(div) div = divisors(b - a) ans = res = 1e50 for i ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR B...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = list(map(int, input().split())) def gcd(a, b): if b == 0: return a return gcd(b, a % b) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR ...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
are, bre = list(map(int, input().split())) def plottt(xre, yre): if xre == 0: return yre if yre == 0: return xre if yre > xre: yre, xre = xre, yre return plottt(xre % yre, yre) if are > bre: are, bre = bre, are kre = bre - are plkiyer = [] ire = 1 while ire**2 <= kre: ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR IF VAR VAR ASSIGN VAR VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBE...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = map(int, input().split()) q = abs(a - b) if q == 0: print(0) else: dq = [] dq2 = [] for i in range(1, int(q**0.5) + 1): if not q % i: dq.append(i) if i != q // i: dq2 = [q // i] + dq2 dq = dq + dq2 dq = dq[::-1] if a < b: a, b = ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BI...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = list(map(int, input().split())) a, b = min(a, b), max(a, b) gap = b - a arr = [] i = 1 while i * i < gap: if gap % i == 0: arr.append(i) arr.append(gap // i) i += 1 if i * i == gap: arr.append(i) arr.sort() answer = 0 value = 10**20 for i in arr: plus = 0 if a % i: plu...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VA...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = list(map(int, input().split())) a, b = min(a, b), max(a, b) if b % a == 0: print(0) return x = b - a dels = set() for i in range(1, int(x**0.5) + 1): if x % i == 0: dels.add(i) dels.add(x // i) dels = list(dels) j = 10**20 for i in dels: if i >= a: j = min(j, i - a) print(...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = [int(x) for x in input().split()] lcm = K = 10**100 def gcd(a, b): if b > a: a, b = b, a if b == 0: return a return gcd(a % b, b) delit = [] if a == b: print(0) else: if a > b: a, b = b, a for i in range(1, int((b - a) ** 0.5) + 1): if (b - a) % i == 0:...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
def divisor(n): n2 = int(n**0.5 + 1) ret = set() for i in range(1, n2 + 1): if n % i == 0: ret.add(i) ret.add(n // i) ret = list(ret) ret.sort() return ret def gcd(a, b): while b != 0: a, b = b, a % b return a def lcm(a, b): return a // gcd...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR ...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
import sys __version__ = "1.1" __date__ = "2019-04-24" def gcd(a, b): if b == 0: return a return gcd(b, a % b) def solve(a, b): a, b = min(a, b), max(a, b) if b % a == 0: return 0 diff = b - a k, lcm = 0, a * b factors = [1, diff] fact = 2 while fact * fact <= di...
IMPORT ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR LIST NUMBER VAR ASSIGN...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
def gcd(a, b): while b > 0: a, b = b, a % b return a def lcm(a, b): return a * b / gcd(a, b) ans = 0 ans_lcm = 100000000000000000000 a = 0 b = 0 def update(d): global ans, a, b, ans_lcm k = d - a % d lcm_ = lcm(a + k, b + k) if lcm_ < ans_lcm or lcm_ == ans_lcm and d < ans: ...
FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR VAR V...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) a, b = mi() a, b = min(a, b), max(a, b) X = b - a def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) def lcm(a, b): return a * b // gcd(a, b) def prime_factor(x): pf = [] for i i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR F...
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
a, b = map(int, input().split()) d = abs(a - b) def factor(x): S = set() i = 1 while i * i <= x: if x % i == 0: S.add(i) S.add(x // i) i += 1 return S def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): if a == 0 or b =...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN F...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) while t: n, k = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] num = [[(0) for i in range(n)] for j in range(n)] i = 0 j = 0 count = 0 while i < n: while j < n: num[i][j] = arr[i] + arr[j] j = j + 1 i = i + 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR ASSIGN VA...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
for _ in range(int(input())): N, K = map(int, input().split()) array = list(map(int, input().split())) count = 0 mn = float("inf") for i in range(N): for j in range(i + 1, N): if abs(array[i] + array[j] - K) < mn: mn = abs(array[i] + array[j] - K) ...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP BI...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
from sys import stdin T = int(stdin.readline().strip()) while T > 0: [N, K] = [int(n) for n in stdin.readline().strip().split()] arr = [int(n) for n in stdin.readline().strip().split()] minAbs = abs(arr[0] + arr[1] - K) count = 0 for i in range(0, N - 1): for j in range(i + 1, N): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
T = int(input()) for i in range(T): n, k = [int(s) for s in input().split()] l = [int(s) for s in input().split()] m = [] for j in range(n): for a in range(j + 1, n): m.append(abs(l[a] + l[j] - k)) print(min(m), m.count(min(m)))
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR ...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) for I in range(t): n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = [] for i in range(len(a)): for j in range(i + 1, len(a)): b.append(abs(a[i] + a[j] - k)) count = 0 p = min(b) for i in b: if i == p: ...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
from itertools import combinations for _ in range(int(input())): n, k = map(int, input().split()) l = list(map(int, input().split())) l = list(combinations(l, 2)) x = [] for i in l: x.append(abs(sum(i) - k)) print(min(x), x.count(min(x)))
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR F...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
def solution(): N, K = map(int, input().split()) A = list(map(int, input().split())) min_val = 10000000000.0 count = 0 for i in range(N): for j in range(i + 1, N): dif = abs(A[i] + A[j] - K) if min_val > dif: min_val = dif count = 1 ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR ...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
for _ in range(int(input())): n, k = map(int, input().split()) mini = 10000000000000000000 l = [int(i) for i in input().split()] cmaxi = 0 for i in range(n): for j in range(i + 1, n): curr = abs(l[i] + l[j] - k) if curr < mini: mini = curr ...
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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
n1 = int(input()) for i in range(n1): n, b = map(int, input().split(" ")) l = list(map(int, input().split(" "))) s = [] for j in range(0, n - 1): for k in range(j + 1, n): s.append(abs(l[j] + l[k] - b)) p = min(s) c = 0 for j in s: if j == p: c = c + 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) for i in range(t): n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() minimum_diff = k num_of_pairs = 0 sum_of_two_list = [] for j in range(n): for l in range(j + 1, n): sum_value = a[j] + a[l] sum_of_two_list.append...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMB...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) while t > 0: n, k = map(int, input().split()) t -= 1 l = list(map(int, input().split())) sum = 0 a = [] for i in range(0, n): for j in range(i + 1, n): x = l[i] + l[j] - k x = abs(x) a.append(x) q = min(a) z = a.count(q) pr...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP ...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
T = int(input()) for i in range(T): n, k = map(int, input().split()) d = list(map(int, input().split())) f = 0 l = [] for i in range(n + 1): for j in range(i + 1, n): f = abs(d[i] + d[j] - k) l.append(f) print(min(l), l.count(min(l)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FU...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) for i in range(t): l = [] mi = 99999999999 n, m = map(int, input().split()) a = list(map(int, input().split())) for j in range(n - 1): for k in range(j + 1, n): a1 = a[j] a2 = a[k] b1 = a1 + a2 - m b2 = abs(b1) l.ap...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VA...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
for _ in range(int(input())): n, k = map(int, input().split()) l = list(map(int, input().split())) l.sort() c = 0 m = 100 d = [] for i in range(n - 1): for j in range(i + 1, n): m = abs(l[i] + l[j] - k) d.append(m) m = min(d) c = d.count(m) print(m...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NU...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
from itertools import combinations for t in range(int(input())): n, k = map(int, input().split()) li = list(map(int, input().split())) li2 = list(combinations(li, 2)) mn, ct = 10000000000, 0 for x in li2: if abs(x[0] + x[1] - k) < mn: mn = abs(x[0] + x[1] - k) for x in li2: ...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VA...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) for i in range(t): B = list(map(eval, input().split())) A = list(map(eval, input().split())) count = 0 minimum = 10000000000 for j in range(len(A) - 1): for m in range(j + 1, len(A)): if abs(A[j] + A[m] - B[1]) < minimum: count = 0 ...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VA...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) while t >= 1: n = input() arr = n.split() a = int(arr[0]) k = int(arr[1]) c = input() c = c.split() arr1 = [] sum = [] for i in range(len(c)): arr1.append(int(c[i])) arr1.sort() numberofpairs = 0 min_value = 10000000000 count = 0 assist = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR F...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
for t in range(int(input())): temp = list(map(int, input().split())) n = temp[0] k = temp[1] a = list(map(int, input().split())) count = 0 minn = -1 for i in range(n): for j in range(i + 1, n): if minn == -1: count += 1 minn = abs(a[i] + a[...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP V...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) for z in range(t): n, k = map(int, input().split()) l = input().split() for i in range(n): l[i] = int(l[i]) i = 0 m = [] while i < n - 1: s = i + 1 while s < n: x, y = l[i], l[s] tot = x + y - k if tot < 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. -----Input-----...
for _ in range(int(input())): N, K = map(int, input().split()) A = list(map(int, input().split())) m = abs(A[0] + A[1] - K) c = 0 for i in range(N - 1): for j in range(i + 1, N): m = min(abs(A[i] + A[j] - K), m) for i in range(N - 1): for j in range(i + 1, N): ...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR B...