description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
for _ in range(int(input())): n1, m = map(int, input().split()) sum = 0 p = 1 for i in range(31): n = n1 z = max(m % (1 << i + 1) - (1 << i) + 1, 0) + (m // (1 << i + 1) << i) p = 1 while n: if n % 2: p = p * z % 998244353 z = z * z...
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 NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER NUMBER BIN_OP BIN_O...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
MOD = 998244353 for _ in range(int(input())): n, m = [int(s) for s in input().split()] m += 1 ans = 0 cur = 1 while cur <= m: cur = cur << 1 w = m // cur * (cur // 2) + max(0, m % cur - cur // 2) ans = (ans + cur // 2 * pow(w, n, MOD) % MOD) % MOD print(ans)
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR ...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
MODULE = 998244353 for _ in range(int(input())): N, M = list(map(int, input().split())) ans = 0 for i in range(M.bit_length()): suma = M // 2 ** (i + 1) * 2**i + max(M % 2 ** (i + 1) - 2**i + 1, 0) ans += 2**i * pow(suma, N, MODULE) print(ans % MODULE)
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BI...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
mod = 998244353 for i in range(int(input())): n, m = map(int, input().split()) ans = 0 mult = 1 for k in range(31): block = m // (2 * mult) cnt = block * mult cnt += max(0, m % (2 * mult) - mult + 1) ans += pow(cnt, n, mod) * mult ans %= mod mult *= 2 ...
ASSIGN 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER ...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
def Sets(n: int, m: int): if m == 1: return [[n]] ans = [] for i in range(n + 1): ans += [([i] + e) for e in Sets(n - i, m - 1)] return ans def lpow(e: int, i: int): if i == 0: return 2**31 - 1 return e def relu(x): return max(0, x) def nCr2(n: int, r: int): ...
FUNC_DEF VAR VAR IF VAR NUMBER RETURN LIST LIST VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP LIST VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF VAR VAR IF VAR NUMBER RETURN BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER VAR F...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
for k in range(int(input())): n, i = list(map(int, input().split())) s = 0 for j in range(0, 32): q = (i // (1 << j + 1) << j) + max(0, i % (1 << j + 1) - (1 << j) + 1) s += pow(q, n, 998244353) << j print(s % 998244353)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NU...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
mod = 998244353 def power(x, y): a = 1 while y: if y & 1: a = a * x % mod x = x * x % mod y >>= 1 return a def func(m, j): upper = m >> j + 1 ans = upper * 2**j if m & 1 << j: ans += m - (upper << j + 1) - 2**j + 1 return ans for _ in range(i...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VA...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
mod = 998244353 for _ in range(int(input())): n, m = list(map(int, input().split())) l = [(0) for i in range(31)] bi = str(bin(m))[2:][::-1] l1 = [] for i in range(len(bi)): x = m >> i + 1 x = x << i if bi[i] == "1": x = x + (m - (m >> i << i) + 1) l1.appe...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
for i in range(int(input())): n, m = map(int, input().split()) def array(a, n): c = 1 while n: if n % 2 == 1: c = c * a % 998244353 a = a * a % 998244353 n = n // 2 return c def sol(q, w): return (q // (1 << w + 1) << w) +...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP BIN_O...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
MOD = 998244353 def modpow(base, exp, mod): result = 1 while exp: if exp & 1: result = result * base % mod base = base * base % mod exp >>= 1 return result def cardinalBitX1toM(M, bit): if M < bit: return 0 elif M < bit << 1: return M - bit + 1...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
def getcount(n, k): res = n >> k + 1 << k if n >> k & 1: res += n & (1 << k) - 1 return res for _ in range(int(input())): n, m = map(int, input().split()) ans = 0 mod = 998244353 new = [0] * 32 for i in range(31): new[i] = getcount(m + 1, i) for i in range(32): ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMB...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
inf = 998244353 def an(n, a): z = 1 while n: if n % 2: z = z * a % inf a = a * a % inf n //= 2 return z for _ in range(int(input())): n, m = map(int, input().split()) ans = 0 for i in range(31): c = (m // (1 << i + 1) << i) + max(0, m % (1 << i + 1...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR N...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
mod = 998244353 def counts(m, i): count = m >> i + 1 << i if m >> i & 1: count += m & (1 << i) - 1 return count def solve(n, m): ans = 0 for i in range(32): count = counts(m + 1, i) if count: ans = (ans + pow(count, n, mod) * pow(2, i, mod) % mod) % mod ...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
def solve(n, m): m += 1 ans = 0 mod = 998244353 for bit in range(30): cnt = m // (2 << bit) cnt = cnt * (1 << bit) cnt += max(0, m % (2 << bit) - (1 << bit)) ans += pow(cnt, n, mod) * (1 << bit) print(ans % mod) testCase = int(input()) for _ in range(testCase): ...
FUNC_DEF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BI...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
from itertools import product output = [] for _ in range(int(input())): N, M = map(int, input().split(" ")) ways = 0 two_power = 1 while two_power <= M: c = M // (two_power << 1) * two_power r = (M & (two_power << 1) - 1) - (two_power - 1) if r > 0: c += r wa...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF VAR NUM...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
mod = 998244353 t = int(input()) for _ in range(t): n, m = map(int, input().split()) res = 0 for bit in range(31): b2 = 2 << bit count = m // b2 * (b2 >> 1) + max(0, m % b2 - (b2 >> 1) + 1) res += pow(count, n, mod) << bit print(res % mod)
ASSIGN 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR ...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
md = 998244353 t = int(input()) for _ in range(t): n, m = input().split() n = int(n) m = int(m) ans = 0 for i in range(0, 32): ans += ( pow( (m // pow(2, i + 1) << i) + max(0, m % pow(2, i + 1) - pow(2, i) + 1), n, md, )...
ASSIGN VAR NUMBER 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMB...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
def mi(): return map(int, input().split()) def li(): return list(mi()) def si(): return str(input()) def ni(): return int(input()) def find(m, k): sk = 1 << k c1 = m >> k + 1 << k c0 = c1 << 1 return c1 + max(0, m + 1 - c0 - sk) for t in range(int(input())): n, m = mi() ...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_O...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
mod = 998244353 def arrctr(n, m): ans = 0 for bit in range(30): ct = m // (2 << bit) * (1 << bit) ct += max(0, m % (2 << bit) - (1 << bit) + 1) ans += pow(ct, n, mod) << bit return ans % mod t = int(input()) for _ in range(t): n, m = [int(x) for x in input().split()] prin...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ...
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elements of the i^{th} array in the set, where 1 ≤ i ≤ M^{N}. Find t...
MOD = 998244353 def getex(till, exp): ex = till >> exp + 1 << exp powxp = 1 << exp if till & powxp: ex += till % powxp return ex def main(N, M): summation = 0 for exp in range(M.bit_length()): expenses = getex(M + 1, exp) expbitsum = (pow(expenses, N, MOD) << exp) % M...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ...
In Conway's Game of Life, cells in a grid are used to simulate biological cells. Each cell is considered to be either alive or dead. At each step of the simulation each cell's current status and number of living neighbors is used to determine the status of the cell during the following step of the simulation. In this o...
def check(s): p = ["00", "01", "10", "11"] for val in s[1:-1]: for i in range(4): p[i] = p[i] + str(int(p[i][-2]) ^ int(p[i][-1]) ^ int(val)) count = 0 for x in p: if convert(x) == s: count += 1 r = x if count == 1: return r elif count ...
FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING FOR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR V...
In Conway's Game of Life, cells in a grid are used to simulate biological cells. Each cell is considered to be either alive or dead. At each step of the simulation each cell's current status and number of living neighbors is used to determine the status of the cell during the following step of the simulation. In this o...
t = int(input()) zero_list = ["000", "101", "110", "011"] one_list = ["100", "001", "010", "111"] for iter in range(t): cells = list(input()) if cells[-1] == "0": possibles = zero_list[:] else: possibles = one_list[:] possibles.sort() for i in range(len(cells) - 2, -1, -1): f...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMB...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
m = [] onesarr = [] for i in range(128): a = [] ones = 0 for j in range(7): l = i % 2 ** (7 - j) // 2 ** (6 - j) a.append(l) ones += l onesarr.append(7 - ones) m.append(a) t = int(input()) for _ in range(t): poslag = True n = int(input()) maxd = 0 mind = 8 ...
ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR F...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
seg = [ [True, True, True, True, True, True, False], [False, False, False, True, True, False, False], [False, True, True, False, True, True, True], [False, False, True, True, True, True, True], [True, False, False, True, True, False, True], [True, False, True, True, False, True, True], [True...
ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER N...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
digits = [119, 18, 93, 91, 58, 107, 111, 82, 127, 123] t = int(input()) for ti in range(t): n = int(input()) x, y = [None for _ in range(n)], [None for _ in range(n)] for i in range(n): x[i], y[i] = map(int, input().split()) any_ok = False min_dead, max_dead = 7, 0 for mask in range(1 <<...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER 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 VAR NONE VAR FUNC_CALL VAR VAR NONE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VA...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
def count_alive(num): return bin(num).count("1") for _ in range(int(input())): li = [] for i in range(int(input())): xx, yy = map(int, input().split()) li.append((xx, yy)) ideal = [119, 18, 93, 91, 58, 107, 111, 82, 127, 123] comb = list(range(128)) valid = 1 for x, y in li...
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST 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 VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMB...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
mask = [119, 36, 93, 109, 46, 107, 123, 37, 127, 111] def NumOn(x): i = 1 ans = 0 while i < 128: if x & i > 0: ans += 1 i = i << 1 return ans def NumOff(x): return 7 - NumOn(x) t = int(input()) while t: t -= 1 n = int(input()) inp = [list(map(int, input(...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
def solve(i): for k in range(n): a, b = arr[k][0], arr[k][1] count = 0 for j in range(7): if mask[a] & 1 << j and i & 1 << j: count += 1 if count != b: return False return True mask = [119, 36, 93, 109, 46, 107, 123, 37, 127, 111] tests =...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
from itertools import combinations def solve(tests): for i in tests: if len(i[0]) < i[1]: print("invalid") return i = 0 mini, maxi = -1, 8 flag = True while mini <= i <= maxi: for s in combinations(range(7), i): for j in tests: if...
FUNC_DEF FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR ASSIGN VAR NUM...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
num_dic = { (0): "1110111", (1): "0010010", (2): "1011101", (3): "1011011", (4): "0111010", (5): "1101011", (6): "1101111", (7): "1010010", (8): "1111111", (9): "1111011", } for z in range(int(input())): n = int(input()) tuples = [tuple(map(int, input().split())) for i in...
ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING 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 VAR FUNC...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
def n1(n): s = bin(n) if s[2] == "0": return 0 else: return s.count("1") conf = [119, 18, 93, 91, 58, 107, 111, 82, 127, 123] for z in range(int(input())): n = int(input()) bf = [] for i in range(128): bf.append(i) li = [] for i in range(n): li.append(tu...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING RETURN NUMBER RETURN FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
d = [ [0, 3, 4, 2, 6, 5], [5, 6], [0, 5, 1, 4, 2], [0, 5, 1, 6, 2], [3, 1, 5, 6], [0, 3, 1, 6, 2], [0, 3, 4, 2, 6, 1], [0, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 3, 1, 5, 6, 2], ] def check(ar, b): for i in ar: c = 0 for j in d[i[0]]: if b[j]: ...
ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER ...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
def invalid(n, l, list1, list5, max_dead): list2 = [] for i in range(n): if len(list1[l[i][0]]) < l[i][1]: print("invalid") return for i in range(127): list3 = list5[i].copy() list4 = list({0, 1, 2, 3, 4, 5, 6} - set(list3)) list4.sort() flag =...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VA...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
def countSetBits(n): count = 0 while n: count += n & 1 n >>= 1 return count for _ in range(int(input())): la = [] lb = [] masks = [63, 6, 91, 79, 102, 109, 125, 7, 127, 111] conf = [] for o in range(int(input())): n, k = list(map(int, input().split())) l...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIG...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
t = int(input()) d = { (0): (1, 2, 3, 5, 6, 7), (1): (3, 7), (2): (2, 3, 4, 5, 6), (3): (2, 3, 4, 6, 7), (4): (1, 3, 4, 7), (5): (1, 2, 4, 6, 7), (6): (1, 2, 4, 5, 6, 7), (7): (2, 3, 7), (8): (1, 2, 3, 4, 5, 6, 7), (9): (1, 2, 3, 4, 6, 7), } ll = [] for i in range(128): ll.ap...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
sevseg = [126, 48, 109, 121, 51, 91, 95, 112, 127, 123] for _ in range(int(input())): n = int(input()) x, y = [None] * n, [None] * n mini = 8 maxi = -1 for i in range(n): x[i], y[i] = map(int, input().rstrip().split()) badaflag = 0 for check in range(128): flag = 1 fo...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NONE VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUN...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
t = int(input()) for _ in range(t): n = int(input()) f = { (0): [0, {1, 2, 3, 5, 6, 7}], (1): [2, {3, 7}], (2): [5, {2, 3, 4, 5, 6}], (3): [5, {2, 3, 4, 7, 6}], (4): [4, {1, 4, 3, 7}], (5): [5, {2, 1, 4, 7, 6}], (6): [6, {1, 2, 4, 5, 6, 7}], (7): [...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIS...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
dicti = { (1): "0110000", (2): "1101101", (3): "1111001", (4): "0110011", (5): "1011011", (6): "1011111", (7): "1110000", (8): "1111111", (9): "1111011", (0): "1111110", } Arr = [] for i in range(2**7): to_Append = str(bin(i))[2:] Arr.append("0" * (7 - len(to_Append)) + t...
ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP NUMBER F...
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Consider a seven-segment display, which can be used to show a decimal digit ($0$ through $9$). When a digit is shown on a working display, specific segments of the display turn on, as depicted in the following image (for di...
t = int(input()) segment_map = [ (True, True, True, False, True, True, True), (False, False, True, False, False, True, False), (True, False, True, True, True, False, True), (True, False, True, True, False, True, True), (False, True, True, True, False, True, False), (True, True, False, True, Fals...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
def main(): n, m = read() m -= 1 perm = [0] * n lf = 0 rt = n - 1 for i in range(n): if m >= 2 ** (n - i - 2): perm[rt] = i + 1 rt -= 1 else: perm[lf] = i + 1 lf += 1 m %= 2 ** (n - i - 2) write(perm) def read(mode=2):...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER BIN_OP B...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split()) arr = [(0) for i in range(0, n + 1)] fac = [1] for i in range(1, n + 1): fac.append(2 * fac[i - 1]) def dfs(x, lft, rgt, m): if lft == rgt: arr[lft] = x return elif m <= fac[n - x - 1]: arr[lft] = x dfs(x + 1, lft + 1, rgt, m) else: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR RETURN IF VAR VAR BIN_OP BIN_OP VAR VA...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = input().split() n, m = int(n), int(m) - 1 pow2 = [] u = 1 for i in range(n): pow2.append(u) u *= 2 r = [] k = 1 while k < n: if m < pow2[n - k - 1]: r.append(k) else: m -= pow2[n - k - 1] k += 1 z = [] for i in range(n): if not n - i in r: z.append(n - i) r += z r ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
import itertools __author__ = "yushchenko" def countf(f): sum = 0 for i in range(len(f)): for j in range(len(f))[i:]: sum += min(f[i : j + 1]) return sum n, m = input().split() n = int(n) m = int(m) if n == 1: print(1) exit() maxcount = pow(2, n - 2) t = 1 saved = [] result ...
IMPORT ASSIGN VAR STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split()) t = [n] for i in range(1, n): t = t + [n - i] if m - 1 & 1 << i - 1 else [n - i] + t for q in t: print(q)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR LIST BIN_OP VAR VAR BIN_OP LIST BIN_OP VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split()) def ans(elems, m): n = len(elems) pow = 2 ** (n - 1) if m >= pow: return elems[::-1] pow //= 2 j = 0 while m > pow: j += 1 m -= pow pow //= 2 return [elems[j]] + ans(elems[j + 1 :], m) + elems[:j][::-1] elems = [(i + 1) for...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR RETURN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP LIST VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VA...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
ii = lambda: int(input()) kk = lambda: map(int, input().split()) ll = lambda: list(kk()) n, k = kk() pre, post = [], [] k -= 1 v = 1 for i in range(n - 2, -1, -1): if k & 2**i: post.append(v) else: pre.append(v) v += 1 print(*pre, n, *reversed(post))
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 LIST LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR V...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split()) s = 1 c = n - 1 arr = [0] * n i = 0 while i <= c: r = 0 j = s while j <= n and r < m: if j < n: r += 2 ** (n - j - 1) j += 1 if j > s and j != n + 1: r -= 2 ** (n - j) m -= r j -= 1 arr[i] = j while s < j: arr[c...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR ...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = [int(i) for i in input().split()] big = 1 << n - 1 def r(i, m, half): half >>= 1 if half == 0: print(i, end=" ") return 0 if m <= half: print(i, end=" ") r(i + 1, m, half) else: r(i + 1, m - half, half) print(i, end=" ") r(1, m, big)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_DEF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING RETURN NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split()) a = [(0) for i in range(n)] l, r = 0, n - 1 m -= 1 for i in range(1, n + 1): cur = 2 ** (n - i - 1) if m >= cur: m -= cur a[r] = i r -= 1 else: a[l] = i l += 1 print(*a)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split()) s = 0 flag = False k = 0 myset = set() flag1 = True for j in range(n): if n in myset: for i in range(n, 0, -1): if i not in myset: print(i, end=" ") flag1 = False if flag1 == False: break flag = False s = 0 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBE...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
def gen(n, start, t): if n == 1: return [start] if t <= 2 ** (n - 2): return [start] + gen(n - 1, start + 1, t) else: return gen(n - 1, start + 1, t - 2 ** (n - 2)) + [start] n, t = map(int, input().split()) print(" ".join(map(str, gen(n, 1, t))))
FUNC_DEF IF VAR NUMBER RETURN LIST VAR IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN BIN_OP LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER LIST VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_C...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
def func(n, a, b): if a > n: return val = 2 ** (n - a - 1) if b >= val: func(n, a + 1, b - val) print(a, end=" ") else: print(a, end=" ") func(n, a + 1, b) def main(): n, m = map(int, input().split()) func(n, 1, m - 1) main()
FUNC_DEF IF VAR VAR RETURN ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR E...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split()) seq = [i for i in range(1, n + 1)] m -= 1 dig = [] digs = 0 while m > 0: dig.append(m % 2) m //= 2 digs += 1 swap = 0 sw = [0] * digs for i in range(digs - 1, -1, -1): if swap == 1: sw[i] = 1 - dig[i] else: sw[i] = dig[i] swap = (swap + sw[i]) % 2...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
from itertools import permutations as p n, m = map(int, input().split()) def f(p): ret = 0 for i in range(len(p)): for j in range(i, len(p)): ret += min(p[i : j + 1]) return ret def get(n, last, avail, rank): if rank == n: return sorted(avail, reverse=True) n //= 2 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER I...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split()) lst = [0] * n l, r = 0, n - 1 i = 1 while r > l: if m > 2 ** (r - l - 1): lst[r] = i m -= 2 ** (r - l - 1) r -= 1 else: lst[l] = i l += 1 i += 1 lst[l] = i print(" ".join(map(str, lst)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
ip = [int(i) for i in input().split()] n, m = ip[0], ip[1] - 1 per = "0" * (n + 1 - len(bin(m))) + bin(m)[2 : len(bin(m))] p = str(n) for i in range(n - 1, 0, -1): if per[i - 1] == "0": p = str(i) + " " + p else: p = p + " " + str(i) print(p)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMB...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split()) def gen(n, m, now): if n == 1: return [now] if m <= 2 ** (n - 2): return [now] + gen(n - 1, m, now + 1) else: return gen(n - 1, m - 2 ** (n - 2), now + 1) + [now] p = 2 ** (n - 2) print(" ".join(map(str, gen(n, m, 1))))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN LIST VAR IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN BIN_OP LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER L...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split()) res = [] num = 0 x = n for i in range(1, n): if i not in res: if pow(2, x - len(res) - 2) + num >= m: res.append(i) else: num += pow(2, x - len(res) - 2) x -= 1 i = n while i > 0: if i not in res: res.append(i) i -=...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR IF BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMB...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
def find_kth(i, j, p, n, k, a): d = j - i if d == 1: a[i] = p return a if k < 1 << d - 2: a[i] = p return find_kth(i + 1, j, p + 1, n, k, a) else: a[j - 1] = p return find_kth(i, j - 1, p + 1, n, k - (1 << d - 2), a) n, m = map(int, input().split()) ans ...
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR B...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
arc = [] def sv(a, b, c, n, v): if n < c // 2: arc[a] = v if b - a > 1: sv(a + 1, b, c // 2, n, v + 1) else: arc[b - 1] = v if b - a > 1: sv(a, b - 1, c // 2, n - c // 2, v + 1) n, m = map(int, input().split()) arc = [0] * n ssc = 1 << n - 1 sv(0, n, s...
ASSIGN VAR LIST FUNC_DEF IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
import sys def read_input(input_path=None): if input_path is None: f = sys.stdin else: f = open(input_path, "r") n, m = map(int, f.readline().split()) return n, m def sol(n, m): v = [(0) for _ in range(n + 1)] left, right = 1, n for i in range(1, n + 1): if n - i ...
IMPORT FUNC_DEF NONE IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUM...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split()) out = [n] i = n - 1 m -= 1 for _ in range(n - 1): if m % 2: out.append(i) else: out = [i] + out m //= 2 i -= 1 for i in out: print(i, end=" ") print()
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split(" ")) cnt = 2 ** (n - 1) L = [-1] * n left = 0 right = n - 1 for x in range(1, n + 1): if m <= cnt // 2: L[left] = x left += 1 else: L[right] = x right -= 1 m -= cnt // 2 cnt //= 2 for i in L: print(i, end=" ") print()
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
inp = input().split(" ") n = int(inp[0]) m = bin(int(inp[1]) - 1)[2:] lenbin = n - 1 while len(m) < lenbin: m = "0" + m start = [] end = [] for x in range(n - 1): if m[x] == "0": start = start + [x + 1] else: end = [x + 1] + end final = start + [n] + end for x in final: print(x, end=" ")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ST...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
def main(): n, m = map(int, input().split()) m -= 1 aa = [0] * n lo, hi = 0, n - 1 t = 2 ** (n - 2) for i in range(1, n + 1): if m < t: aa[lo] = i lo += 1 else: aa[hi] = i hi -= 1 m -= t t //= 2 print(*aa) ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR ...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
def fun(n, m): m -= 1 solu = [0] * n l = n - 1 po = l - 1 o = 0 for i in range(n): if m >= pow(2, po): solu[l] = i + 1 m -= pow(2, po) l -= 1 else: solu[o] = i + 1 o += 1 po -= 1 print(*solu) def fun2(n, m)...
FUNC_DEF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR...
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum: <image> Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn...
n, m = map(int, input().split()) if n == 1: print(1) exit() m -= 1 perm = [0] * n k = 2 ** (n - 2) cleft = 0 cright = n - 1 for i in range(1, n + 1): if m & k: perm[cright] = i cright -= 1 else: perm[cleft] = i cleft += 1 k //= 2 print(" ".join(map(str, perm)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR ASSI...
After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number x to the basket, Misha should answer the quest...
m = int(input()) b = [] k = [] for i in range(m): x = int(input()) c = 0 for j in range(len(b)): v = b[j] d = k[j] if x ^ v < x: x ^= v c ^= d if x != 0: print(0) c ^= 2**i b.append(x) k.append(c) else: a = [] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP...
After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number x to the basket, Misha should answer the quest...
n = int(input()) t = [(0) for i in range(2000)] c = [(0) for i in range(2000)] for i in range(n): x = int(input()) r = 0 ok = False for j in range(2000): if x >> j & 1: if t[j] != 0: x ^= t[j] r ^= c[j] else: t[j] = x ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR...
After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number x to the basket, Misha should answer the quest...
m = int(input()) values = [] idx = [] for i in range(m): x = int(input()) ans = 0 for j, xx in enumerate(values): if xx ^ x < x: x ^= xx ans ^= idx[j] if x == 0: anss = [] for j in range(i): if ans & 1 != 0: anss.append(j) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_...
After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number x to the basket, Misha should answer the quest...
n = int(input()) b = [] bb = [] for i in range(n): x = int(input()) idx = 0 for j in range(len(b)): nxt = b[j] ^ x if nxt < x: x = nxt idx ^= bb[j] if x == 0: cnt = 0 v = [] for k in range(2000): if idx & 1 << k: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FU...
After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number x to the basket, Misha should answer the quest...
buck = [[0, 0] for i in range(2201)] m = int(input()) for i in range(m): a = int(input()) ok = True br = 0 for j in range(2200, -1, -1): if a & 1 << j: if buck[j][0]: a ^= buck[j][0] br ^= buck[j][1] else: ok = False ...
ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR N...
You are given an array A, consisting of N distinct integers. Calculate number of pairs (i,j) (1 ≤ i < j ≤ N), such that 2 \cdot (A_{i} \oplus A_{j}) = A_{i} + A_{j}, where \oplus denotes [bitwise XOR]. ------ Input Format ------ - The first line contains two integers N - the size of the array. - The second line c...
def do_bitwise_xor(x, y): return (x | y) & (~x | ~y) def split_list_to_even_odd(A: list): A_EVEN = [] A_ODD = [] for item in A: if item % 2 == 0: A_EVEN.append(item) else: A_ODD.append(item) return A_EVEN, A_ODD def get_xor_times_two_is_sum_count(A: list):...
FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FU...
You are given an array A, consisting of N distinct integers. Calculate number of pairs (i,j) (1 ≤ i < j ≤ N), such that 2 \cdot (A_{i} \oplus A_{j}) = A_{i} + A_{j}, where \oplus denotes [bitwise XOR]. ------ Input Format ------ - The first line contains two integers N - the size of the array. - The second line c...
def patt(n): s = format(n, "b")[1:] i = len(s) - 1 while i >= 0: if s[i] == "1": if i - 1 < 0: return False i -= 2 else: i -= 1 return True def rev(n): s = format(n, "b")[1:] ans = "" i = len(s) - 1 while i >= 0: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
M = int(1000000000.0 + 7) T = int(input()) for i in range(T): L, R = map(int, input().split()) ans = 0 if L == R: ans = L % M else: b1 = bin(L)[2:] b2 = bin(R)[2:] val = -1 if len(b2) == len(b1): for j in range(len(b1)): if b1[j] != b2[...
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER 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 NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
mod = 10**9 + 7 for i in range(int(input())): l, r = [int(i) for i in input().split()] if l == r: print(l % mod) continue res = 0 diff = r - l + 1 i = 1 j = 1 temp = l while temp: if temp & 1: temp2 = l & i k = min(r + 1 - l, i + 1 - temp2)...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
for _ in range(int(input())): l, r = map(int, input().split()) binary = bin(l)[2:] a, b, s = 1, 0, 0 for i in range(len(binary) - 1, -1, -1): if binary[i] == "1": s += a * min(a - b, r - l + 1) s %= 1000000007 b += a a *= 2 print(s)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER 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 VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP ...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
m = [1] mod = 10**9 + 7 for i in range(60): a = m[-1] a *= 2 a %= mod m.append(a) for i in range(int(input())): L, R = map(int, input().split()) tmp = 0 l = bin(L)[2:] r = bin(R)[2:] a = 1 ans = L % mod for i in range(1, len(l) + 1): if l[-i] == "0": if tm...
ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMB...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
for _ in range(int(input())): l, r = map(int, input().split()) a = 1 b = 0 s = 0 x = l binary = "" while l > 0: binary += str(l % 2) l //= 2 for i in binary: if i == "1": s += a * min(a - b, r - x + 1) % 1000000007 s %= 1000000007 ...
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR STRING VAR BIN_OP BIN_OP VAR FUNC_CALL VAR ...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
MOD = 10**9 + 7 for _ in range(int(input())): l, r = map(int, input().split()) max_no_elm = r - l + 1 ans, multi, l_p, r_p = 0, 1, l, 0 while l_p != 0: curr_bit = l_p & 1 if curr_bit == 1: no_elm = multi - r_p ans = (ans + multi * min(no_elm, max_no_elm)) % MOD ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER 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 BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP V...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
l = [] for i in range(62): l.append(2**i) T = int(input()) flag = 0 for t in range(T): L, R = [int(i) for i in input().split()] bL = bin(L) lL = len(bL) - 2 index = 1 ans = 0 temp = 0 while index <= lL: temp = L % l[index] if temp >= l[index - 1]: if l[index] ...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSI...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
t = int(input()) while t > 0: a, b = list(map(int, input().split())) k = 1 m = a n = b sum = 0 x = 0 y = 1 while a > 0: a = a // 2 l = m // k if l % 2 != 0: p = k * l q = k * (l + 1) else: p = k * (l + 1) q =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBE...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
MVAL = 1000000007 def rangeand(low, hi): odf = hi - low + 1 ra = 0 p2 = 1 lmd = 0 while low & p2 == 0: p2 *= 2 pmdf = p2 if pmdf >= odf: return odf * low % MVAL while p2 <= low: if low & p2: lmd += p2 ra += pmdf * p2 % MVAL else: ...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP B...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
for i in range(int(input())): l, r = map(int, input().split()) binl = bin(l)[2:] diff = r - l + 1 ans, ans1, ans2 = 0, 0, 0 for j in range(len(binl)): if diff <= 0: break if binl[len(binl) - j - 1] == "1": x = 2**j ans += ( (l - 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 FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR ...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
t = int(input()) m = 10**9 + 7 while t: p = 0 res = 0 l, r = map(int, input().split()) d = r - l + 1 br = bin(r)[2:] lbr = len(br) l = bin(l)[2:] k = -1 lol = 0 ll = len(l) ind = ll - 1 if 2**ll > r: for i in range(ll): if l[i] == "0" and br[i] == "1":...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VA...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
mod = 10**9 + 7 for _ in range(int(input())): l, r = map(int, input().split()) a1 = bin(l)[2:] if l == 1: print(1) else: k = [] k1 = [] su = 0 if a1[-1] == "1": k.append(1) k1.append(1) su = 1 p = len(a1) ca = 2 ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER 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 VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR N...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
mod = 1000000007 t = int(input()) while t: l, r = map(int, input().split()) ans = 0 if l == r: print(l % mod) else: temp = l i = 1 j = 1 while temp: if temp & 1: tp2 = l & i k = min(r - l + 1, i - tp2 + 1) ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
modulo = int(1000000000.0) + 7 for t in range(int(input())): l, r = map(int, input().split()) curr = 1 ans = 0 for i in range(61): q = l // curr if q & 1: end = min(r, (q + 1) * curr - 1) ans = (ans + curr * (end - l + 1) % modulo % modulo) % modulo curr *...
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR N...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
t = int(input()) mod = 10**9 + 7 for i in range(t): a, b = (int(x) for x in input().split()) sum = a check = 2 while check <= a: rem = a // check to = (rem + 1) * check - a - 1 if to > b - a: to = b - a if rem % 2 != 0: sum = sum + to * (check % mo...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
mod = 10**9 + 7 t = int(input()) while t > 0: l, r = map(int, input().split()) ans = 0 for i in range(63): if l & 1 << i: x = (1 << i) - (l & (1 << i) - 1) x = min(x, r - l + 1) ans += x * (1 << i) print(ans % mod) t = t - 1
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASS...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
e = 10**9 + 7 t = int(input()) for _ in range(t): a, b = map(int, input().split()) ans = 0 s = "{0:0b}".format(a) s = s[-1::-1] for i in range(len(s)): if s[i] == "1": d = pow(2, i) x = a % d m = d - x n = b - a + 1 ans = (ans + d *...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER 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 NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
MOD = 1000000007 a = int(input()) for i in range(a): x, y = map(int, input().split()) start = x end = y ans = x prev = x z = x j = -1 while start != 0: j += 1 if z & 1 != 0: add = 1 << j next = start + add if next > end: ...
ASSIGN 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 VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR AS...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
MOD = 10**9 + 7 II = lambda: [int(x) for x in input().split()] I2 = lambda: int(input()) T = int(input()) for _ in range(T): L, R = (int(x) for x in input().split()) sum = 0 max_R1 = 1 while max_R1 <= L: max_R1 *= 2 val = int(max_R1 / 2) max_R1 -= 1 while val >= 1: if L & val...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VA...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
MOD = int(10**9) + 7 for _ in range(int(input())): L, R = map(int, input().split()) ans = 0 for i in range(0, 61): pw = 1 << i if L & pw == 0: continue diff = pw - 1 - (L & pw - 1) + 1 ans += min(diff, R - L + 1) % MOD * (pw % MOD) % MOD ans %= MOD ans...
ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BI...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
for t in range(int(input())): c, c1, summ = 0, 0, 0 M = 1000000007 l, r = list(map(int, input().split())) for i in range(60): if l & 1 << i: summ += min(r - l + 1, c1 - c + 1) % M * (1 << i) % M % M c += 1 << i c1 += 1 << i print(summ % M)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_O...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
t = int(input()) p = pow(10, 9) + 7 p = int(p) while t: t -= 1 l, r = map(int, input().split()) f = bin(l)[2:] po = 1 s = 0 res = 0 for i in range(len(f) - 1, -1, -1): if f[i] == "1": res += po * min(po - s, r - l + 1) res = res % p s += po ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FU...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
MOD = 10**9 + 7 T = int(input()) for _ in range(T): l, r = map(int, input().split()) bl = bin(l)[2:] sum = 0 val = 1 s = 0 for i in range(len(bl) - 1, -1, -1): if bl[i] == "1": sum += val * min(val - s, r - l + 1) sum = sum % MOD s += val val *...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER N...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
t = int(input()) while t: t -= 1 l, r = [int(i) for i in input().split()] bl = bin(l)[2:] bl = bl[::-1] sub = 0 val = 1 ans = 0 mod = 10**9 + 7 for i in range(len(bl)): if bl[i] == "1": ans += val * min(val - sub, r - l + 1) % mod sub += val va...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR I...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
MVAL = 1000000007 def rangeand(low, hi): ra = 0 p2 = 1 while p2 <= low: ld, lm = divmod(low, p2 * 2) hd, hm = divmod(hi, p2 * 2) if ld == hd: ra += (hm - lm + 1) * (p2 & lm) % MVAL else: ra += (p2 * 2 - lm) * (p2 & lm) % MVAL p2 *= 2 retu...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VA...
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first...
mod = int(1000000000.0) + 7 t = int(input()) while t: t -= 1 l, r = map(int, input().split()) binl = bin(l)[:1:-1] f, cnt, ans = 1, 0, 0 for i in binl: if i == "1": ans = (ans + f * min(f - cnt, r - l + 1)) % mod cnt += f f *= 2 print(ans)
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR FUNC_CAL...