description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for _ in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] if n == 1: if a[0] == 1: a = [1, 1] else: a = [1, 1, a[0] - 1] elif n == 2: if a[0] == 1: a = [a[0], a[1] + 1] else: a = [1, a[1] + 1, a[0]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR LIST VAR...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
class Solution(object): def one(self, nums): if nums[0] - 1 == 0: return 2, [1, 1] else: return 3, [1, 1, nums[0] - 1] def two(self, nums): if nums[0] - 1 == 0: return 2, [1, nums[1] + 1] else: return 3, [1, nums[1] + 1, nums[0] -...
CLASS_DEF VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER NUMBER RETURN NUMBER LIST NUMBER NUMBER RETURN NUMBER LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF IF BIN_OP VAR NUMBER NUMBER NUMBER RETURN NUMBER LIST NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER LIST NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) l = [1000] + l if n % 2: l = l[:-2] + [l[-2] - 1, 1, 1, l[-1] - 1] else: l = l[:-3] + [l[-3] - 1, 1, l[-1] + 1, l[-2] - 1] while 1: for i in range(1, len(l)): if l[i] == 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR ...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def findC(ar): N = len(ar) if N == 1: if ar[0] > 1: return [1, 1, ar[0] - 1] else: return [1, 1] if N == 2: if ar[0] > 1: return [1, ar[1] + 1, ar[0] - 1] else: return [ar[0], ar[1] + 1] if N % 2 == 1: zeros = ar[-2]...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER NUMBER RETURN LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN LIST NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER RETURN LIST NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN LIST VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMB...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for _ in range(int(input().strip())): input() integers = list(map(int, input().strip().split())) if len(integers) > 2: if len(integers) % 2 != 0: a = integers[-3] b = integers[-2] c = integers[-1] if b > 1 and c > 1: integers.pop() ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXP...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
t = int(input()) while t > 0: t -= 1 n = int(input()) a = list(map(int, input().split())) if n == 1: if a[0] == 1: a.append(1) else: a[0] -= 1 a = [1, 1] + a print(len(a)) print(" ".join(map(str, a))) continue if n == 2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CAL...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
cases = int(input().strip()) while cases: n = int(input().strip()) a = list(map(int, input().strip().split())) offset = 0 if n == 1: m = 3 c = [1, 1, a[0] - 1] elif n == 2: m = 3 c = [1, a[1] + 1, a[0] - 1] else: while n - offset > 4: offset +=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBE...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
t = int(input().strip()) for i in range(t): n = int(input().strip()) arr = [int(n) for n in input().split()] if len(arr) % 2 == 0: arr[n - 1] += 1 temp = arr[n - 2] - 1 if temp != 0: arr[n - 2] = 1 if n > 3: arr[n - 3] -= 1 arr.exte...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN ...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
import sys def solve(aa): print("aa=%s" % aa, file=sys.stderr) i = len(aa) - 1 if i % 2 == 1: i -= 1 print("i=%d" % i, file=sys.stderr) if i == 0: cache = [1, 1] + [aa[i] - 1] + aa[i + 1 :] else: cache = aa[: i - 1] + [aa[i - 1] - 1] + [1, 1] + [aa[i] - 1] + aa[i + 1 :]...
IMPORT FUNC_DEF EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER LIST BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP B...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split(" "))) if len(a) == 1: a = [1] + [1] + [a[0] - 1] elif len(a) == 2: a = [1] + [a[1] + 1] + [a[0] - 1] elif len(a) == 3: a = [a[0]] + [a[1] - 1] + [1] + [1] + [a[2] - 1] elif len(a) == 4: ...
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 STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER LIST NUMBER LIST BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN ...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for t in range(int(input())): n = int(input()) a = list(map(int, input().split()[:n])) ones = 0 if n == 1: a[0] -= 1 if a[0] == 0: a.pop() a.insert(0, 1) a.insert(0, 1) elif n == 2: a[0] -= 1 a[1] += 1 a[0], a[1] = a[1], a[0] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF V...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
T = int(input().strip()) N = [] S = [] for t in range(0, T): n = int(input().strip()) seq = list(map(lambda x: int(x), input().strip().split(" "))) N.append(n) S.append(seq) def extzero(seq_): ones = 0 n = len(seq_) for j in range(0, n, 2): ones += seq_[j] zeros = 0 for j i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSI...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for _ in range(int(input())): n = int(input()) A = [int(i) for i in input().strip().split()] if n == 1: A.append(1) A.append(A[0] - 1) A[0] = 1 elif n == 2: A.append(A[0] - 1) A[1] += 1 A[0] = 1 else: if n % 2: A.append(0) i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMB...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
T = int(input()) for _ in range(T): N = int(input()) A = [0, 1] + list(map(int, input().split())) l1 = N + 1 & -2 XL = A[: l1 - 1] X = [A[l1 - 1] - 1, 1, 1, A[l1] - 1] XR = A[l1 + 1 :] if len(XR) and X[3]: X[2] += XR[0] XR = [] elif len(XR): XR[0] += X[2] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST BIN_OP VAR BIN_OP VAR NUMBER NU...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
t = int(input()) for _ in range(t): n = int(input()) L = [int(x) for x in input().strip().split()] if len(L) == 1: if L[-1] == 1: C = [1, 1] else: C = [1, 1, L[-1] - 1] elif len(L) % 2: if L[-2] == 1: if L[-1] == 1: C = L[:-3] +...
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 FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP FUNC_...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
t = int(input().strip()) for _ in range(t): n = int(input()) a = [int(num) for num in input().strip().split()] if n % 2 == 1: if n == 1: c = [1, 1] elif a[n - 2] > 1: c = a[: max(0, n - 2)] c += [a[n - 2] - 1, 1, 1] else: c = a[: max(0,...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
T = int(input()) def compact(A): result = [] i = 1 while A[i] == 0: i += 1 j = len(A) - 1 while B[j] == 0: j -= 1 while i <= j: if A[i] == 0: result[-1] += A[i + 1] i += 2 else: result.append(A[i]) i += 1 retur...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR FOR VA...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def pp(A, *b): for a in A: print(a, end=" ") for x in b: print(x, end=" ") print() T = int(input()) for t in range(T): n = int(input()) A = list(map(int, input().split())) if len(A) % 2: if len(A) == 1: if A[0] == 1: print(2) ...
FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL 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 IF BIN_OP FUNC_CALL VAR VAR NUMBER IF...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def whats_next(number_list): number_list = list(number_list) length = len(number_list) if length == 1: number_list.insert(0, 1) number_list.insert(0, 1) number_list[2] -= 1 if number_list[-1] == 0: number_list.pop() elif length == 2: if number_list[0] ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUM...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for T in range(int(input())): n, A = int(input()), list(map(int, input().split())) if n & 1: A.append(0) if len(A) < 4: A = [0, 1] + A C = A[:-4] if A[-3] > 1: C.extend([A[-4], A[-3] - 1, 1]) else: C.extend([A[-4] + 1]) C.append(A[-1] + 1) if A[-2] > 1: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CA...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def is_odd(x): return int(x) % 2 def print_list(a): s = "" for x in a: s = s + str(x) + " " s = s[:-1] print(s) n = int(input().strip()) for i in range(0, n): k = int(input().strip()) a = list(map(int, input().strip().split(" "))) l = k if l == 1: if a[0] - 1 > 0:...
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASS...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
T = int(input()) for t in range(T): N = int(input()) A = [int(x) for x in input().split()] if N == 1: A = [1, 1, A[0] - 1] elif N == 2: A = [1, A[1] + 1, A[0] - 1] elif N & 1: A.append(1) A.append(A[-2] - 1) A[-4] -= 1 A[-3] = 1 else: A.app...
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 IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF ...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
t = int(input().strip()) while t > 0: t -= 1 n = int(input().strip()) vals = [int(x) for x in input().strip().split()] if n == 1: if vals[0] == 1: print(2) print(1, vals[0]) else: print(3) print(1, 1, vals[0] - 1) continue if n ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXP...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x in input().split(" ")] if n == 1: a = [1, 1, a[-1] - 1] elif n == 2: a = [1, a[-1] + 1, a[-2] - 1] elif len(a) % 2 == 1: a = a[:-2] + [a[-2] - 1, 1, 1, a[-1] - 1] if a[-4] == 0 and len(a) >= 5: ...
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 STRING IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUM...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
num1 = input() list = [] def output(list): len1 = len(list) if len1 is 1: list.insert(-1, 1) if int(list[1]) != int(1): list.insert(-1, 1) list[2] = str(int(list[2]) - 1) elif len1 is 2: list.insert(2, str(int(list[0]) - 1)) list[0] = str(1) ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER F...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
from itertools import cycle for test in range(int(input())): size = int(input()) ar = [(int(a) * b) for a, b in zip(("1 " + input()).split(), cycle((-1, 1)))] if size % 2: ar = ar[:-2] + [ar[-2] + 1, 1, -1, ar[-1] - 1] else: ar = ar[:-3] + [ar[-3] + 1, 1, -1, ar[-1], ar[-2] - 1] dig...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER NUMBER NUMBER NUMBER BIN_OP VA...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def get_near(A): if len(A) == 2: return [n for n in [1, A[1] + 1, A[0] - 1] if n] if len(A) == 1: return [n for n in [1, 1, A[0] - 1] if n] if len(A) % 2 == 0: zero = -3 else: zero = -2 count_list = [[int(not n % 2), A[n]] for n in range(len(A))] count_list[zero][...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR VAR LIST NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR BIN...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
T = int(input("")) for t in range(T): n = int(input("")) A = input("") A = [int(a) for a in A.split(" ")] C = A[:] if len(C) == 1: C[0] -= 1 C.insert(0, 1) C.insert(0, 1) if C[2] == 0: C = C[:2] print(len(C)) print(" ".join([str(c) for c in...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUM...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for _ in range(int(input())): n = int(input()) arr = [int(x) for x in input().split()] if n % 2 == 1: if n == 1: arr = [1, 1, arr[0] - 1] elif arr[-2] == 1: arr = arr[:-3] + [arr[-3] + 1, 1, arr[-1] - 1] else: arr = arr[:-2] + [arr[-2] - 1, 1, 1, a...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER NUMB...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def _remove_zeros(array): j = max(0, len(array) - 5) while j < len(array): if array[j] != 0: j += 1 continue if j == 0: array = array[2:] continue if j == len(array) - 1: array.pop() continue array[j - 1 : j ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR ...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) if n == 1: c = [1, 1] if a[0] > 1: c.append(a[0] - 1) elif n == 2: if a[0] > 1: c = [1, a[1] + 1, a[0] - 1] else: c = [1, 1 + a[1]] elif n % 2 == 1: ...
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 IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR LIST NUMB...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
import sys T = int(input().strip()) for t in range(T): N = int(input().strip()) A = [int(a) for a in input().strip().split(" ")] if N > 2 and N % 2 == 1: if A[-2] > 1: new_N = N + 2 C = A[:-2] + [A[-2] - 1, 1, 1, A[-1] - 1] if A[-1] == 1: new_N -=...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMB...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def test(B): if B[-3] > 1: if B[-2] > 1: return 1, B[:-3] + [B[-3] - 1, 1, B[-1] + 1, B[-2] - 1] else: return 0, B[:-3] + [B[-3] - 1, 1, B[-1] + 1] elif B[-2] > 1: return -1, B[:-4] + [B[-4] + 1, B[-1] + 1, B[-2] - 1] else: return -2, B[:-4] + [B[-4] +...
FUNC_DEF IF VAR NUMBER NUMBER IF VAR NUMBER NUMBER RETURN NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER RETURN NUMBER BIN_OP VAR NUMBER LIS...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def next(l): if len(l) % 2: if len(l) == 1: return [1, 1] + ([l[0] - 1] if l[0] > 1 else []) if l[-2] == 1: return l[:-3] + [l[-3] + 1, 1] + ([l[-1] - 1] if l[-1] > 1 else []) return l[:-2] + [l[-2] - 1, 1, 1] + ([l[-1] - 1] if l[-1] > 1 else []) else: if ...
FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP LIST NUMBER NUMBER VAR NUMBER NUMBER LIST BIN_OP VAR NUMBER NUMBER LIST IF VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER LIST BIN_OP VAR NUMBER NUMBER LIST RETURN BIN_OP BIN_O...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def next_list(n1, n0): if n1 > 1: return [1, n0, n1 - 1] return [1, n0] def merge(l1, l2): if len(l1) % 2: l1[-1] += l2[0] l1.extend(l2[1:]) else: l1.extend(l2) def main(l): n = len(l) if n == 1: return [1, 1, l[0] - 1] if l[0] > 1 else [1, 1] elif...
FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER VAR BIN_OP VAR NUMBER RETURN LIST NUMBER VAR FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR NUMBER NUMBER LIST NUMBER NUMBER BIN_OP VAR NUMBER ...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
import sys def solucao(arr): for arrA in arr: n = len(arrA) if n % 2 == 0: pos1 = n - 2 final0 = True else: pos1 = n - 1 final0 = False if pos1 > 0: arrA[pos1 - 1] -= 1 arrA[pos1] -= 1 arrA.insert(pos1, 1) ...
IMPORT FUNC_DEF FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR B...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for _ in range(int(input())): n, data = int(input()), [int(x) for x in input().split(" ")] if n == 1: print("2\n1 1" if data[0] == 1 else "3\n1 1 %d" % (data[0] - 1)) elif n == 2: print( "2\n1 %d" % (data[1] + 1) if data[0] == 1 else "3\n1 %d %d" % (data[1...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER STRING BIN_OP STRING BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP STRING BIN_OP VAR N...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for _ in range(int(input())): n, arr = int(input()), list(map(int, input().split())) if n == 1: barr = [1, 1, arr[0] - 1] elif n == 2: barr = [1, arr[1] + 1, arr[0] - 1] elif n % 2 == 1: barr = [arr[i] for i in range(n - 2)] if arr[-2] == 1: barr[-1] += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR N...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
t = int(input().strip()) for tt in range(t): n = int(input().strip()) a = [int(_) for _ in input().strip().split()] if n == 1: r = [1] + [1] if a[0] > 1: r += [a[0] - 1] elif n == 2: r = [1] + [1 + a[1]] if a[0] > 1: r += [a[0] - 1] else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER LIST NUMBER IF VAR NUMBER NUMBER VAR LIST BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSI...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def solve(n, A): if n == 0: A.append(1) elif n == 1: if A[0] == 1: A.append(1) else: A[:] = [1, 1, A[0] - 1] elif n == 2: if A[0] == 1: A[1] += 1 else: A[:] = [1, A[1] + 1, A[0] - 1] else: x = (n - 1) // 2 * ...
FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def zlfill(arr): zeros = sum(arr[::2]) ones = sum(arr[1::2]) return [zeros, ones] def zstrip(arr): if not arr: return [] elif 0 in arr: idx = arr.index(0) if idx == len(arr) - 1: return arr[:-1] mod_arr = arr[:idx] + zstrip(arr[idx + 2 :]) mod_ar...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER RETURN LIST VAR VAR FUNC_DEF IF VAR RETURN LIST IF NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMB...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
t = int(input()) for ti in range(t): n = int(input()) a = [int(s) for s in input().split()] if n == 1: if a[0] == 1: n1 = n + 1 a1 = [1, 1] else: a1 = [1, 1, a[0] - 1] n1 = n + 2 elif n == 2: if a[0] == 1: n1 = n ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
n = int(input()) for i in range(n): n1 = int(input()) arr = list(map(int, input().split())) if n1 == 1: arr.insert(1, 1) if arr[0] > 1: arr.insert(2, arr[0] - 1) arr[0] = 1 elif n1 == 2: if arr[0] > 1: arr.insert(2, arr[0] - 1) arr[...
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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VA...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def f(a): n = len(a) w = n - 2 + n % 2 if w == n - 1: a.append(1) else: a[n - 1] += 1 if a[w] != 1: a.append(a[w] - 1) a[w] = 1 if w: a[w - 1] -= 1 if a[w - 1] == 0: a[w - 2] += 1 a[w] = a.pop() a[w - 1] = a.pop() ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for xx in range(int(input())): n = int(input()) l = list(map(int, input().split())) ans = [] if len(l) % 2 == 0: if len(l) == 2: if l[0] > 1: ans.append(1) ans.append(l[1] + 1) ans.append(l[0] - 1) else: l[1]...
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 LIST IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR N...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def foo(lst): m = len(lst) i = m - 1 i -= i % 2 if i > 0: if lst[i - 1] == 1: ris = lst[: i - 2] + [lst[i - 2] + 1] else: ris = lst[: i - 1] + [lst[i - 1] - 1, 1] else: ris = [1] if i < m - 1: ris.append(lst[-1] + 1) else: ris.a...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER LIST BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER LIST BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST ...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = a[:] if n & 1: b.append(1) if n > 1: b[n - 2] -= 1 b.append(b[n - 1] - 1) b[n - 1] = 1 else: b.append(b[n - 2] - 1) b[n - 2] = 1 b[n - 1] += 1 ...
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 VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSI...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
import sys def main(): num_test_cases = 0 start_test_case = False size_test_case = 0 test_case = [] for line in sys.stdin.readlines(): line = line.rstrip() if num_test_cases == 0: num_test_cases = line elif not start_test_case: size_test_case = int(l...
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def next_equal_count(a): if len(a) == 1: if a[0] == 1: return [1, 1] return [1, 1, a[0] - 1] n = len(a) last_zero_idx = n // 2 * 2 - 1 if last_zero_idx < n - 1: if a[last_zero_idx] > 1: a[last_zero_idx] -= 1 tmp = a[last_zero_idx + 1] ...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER RETURN LIST NUMBER NUMBER RETURN LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUN...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
import sys from itertools import groupby _debug = False _debug = True def dprint(*args): global _debug if _debug: print(" ".join([str(x) for x in args])) def findSmallest(A): i = -1 B = A.copy() if len(A) % 2: i = sum(A[:-1]) if len(B) == 1: B.insert(0, 1) ...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL ...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
n = int(input().strip()) for i in range(n): x = input().strip() a = [int(a_temp) for a_temp in input().strip().split(" ")] if len(a) == 1: b = [1, 1, a[0] - 1] elif len(a) == 2: b = [1, 1 + a[-1], a[0] - 1] elif len(a) % 2 == 0: b = a[:-3] + [a[-3] - 1, 1, a[-1] + 1, a[-2] - ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER BI...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for _ in range(int(input())): len_A = int(input()) A = [int(ai) for ai in input().split()] code = [A.pop(), A.pop() - 1, 1] if len_A & 1 == 0 else [0, A.pop() - 1, 1] code += [1, 0, 0] if len_A <= 2 else [1, A.pop() - 1, A.pop()] code.reverse() if code[1] == 0: code[0] += code[2] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER LIST FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER LIST NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER VAR VAR NUMBER LIST NUMBER NUMBER NUM...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
t = [] for q in range(int(input())): n = int(input()) l = [int(x) for x in input().split()] if n % 2 == 0: nl = [] if n > 3: nl = l[0 : n - 3] if l[n - 3] - 1 == 0: nl[len(nl) - 1] += 1 else: if l[n - 3] - 1 != 0: ...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP FUN...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
T = int(input()) for i in range(T): n = int(input()) vals = list(int(x) for x in input().split(" ")) if n == 1: if vals[0] == 1: vals = [1, 1] else: vals = [1, 1, vals[0] - 1] elif n == 2: if vals[0] == 1: vals[1] += 1 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 VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF V...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
t = int(input()) while t > 0: n = int(input()) a = list(map(int, input().split())) if n == 1: ones = a[0] - 1 if ones >= 1: a[0] -= 1 a.insert(0, 1) a.insert(0, 1) else: a.append(1) elif n == 2: ones = a[0] if ones >...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def clean(a): i = 0 while i < len(a): if a[i][0] == 0: del a[i] else: i += 1 i = 0 while i < len(a) - 1: if a[i][1] == a[i + 1][1]: a[i][0] += a[i + 1][0] del a[i + 1] else: i += 1 return a nTestCases = int...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR F...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def solve(n, arr): n1 = arr[n - 1] if (n - 1) % 2 == 0: if n - 2 < 0: arr = [1, 1, n1 - 1] else: n2 = arr[n - 2] del arr[n - 1] del arr[n - 2] arr += [n2 - 1, 1, 1, n1 - 1] else: n2 = arr[n - 2] if n - 3 < 0: ...
FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR LIST BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VA...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
test_cases = int(input()) for _ in range(test_cases): n, A = int(input()), list(map(int, input().split())) last_ones_set = -1 - int(n % 2 == 0) A[last_ones_set] -= 1 if n + last_ones_set - 1 >= 0: A[last_ones_set - 1] -= 1 if A[last_ones_set] >= 1 and last_ones_set == -2: A[last_ones...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VA...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
t = int(input()) for i in range(t): n = int(input()) l = [int(temp) for temp in input().split()] if n % 2 != 0: if n == 1: if l[0] - 1 != 0: print(3, end="\n") print(1, 1, l[0] - 1, end="\n") else: print(2, end="\n") ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER NUMBER BIN_OP VAR NUMBE...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
import sys T = int(input().strip()) for _ in range(T): binary_A = [] n = int(input().strip()) A = list(map(int, input().strip().split())) if n > 1: if n % 2 == 0: if n >= 4: if A[n - 3] == 1: if A[n - 2] != 1: A[n - 2] -= 1...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR B...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
T = int(input()) for i in range(T): n = int(input()) A = list(map(lambda x: int(x), input().split())) if n % 2 == 1 and n > 2: if A[-1] == 1 and A[-2] == 1: A = A[:-3] + [A[-3] + 1] + [1] elif A[-1] > 1 and A[-2] == 1: A = A[:-3] + [A[-3] + 1] + [1] + [A[-1] - 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBE...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def main(): t = int(input()) for xx in range(0, t): n = int(input()) a = [int(x) for x in input().split()] if n == 1: if a[0] == 1: print("2\n1 1") else: print("3\n1 1 {}".format(a[0] - 1)) elif n == 2: if a[-2] ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR ...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
import sys def tidy_up(arr): n = len(arr) result = [arr[0]] pos = 1 while pos < n: if arr[pos]: result.append(arr[pos]) elif pos + 1 < n: result[-1] += arr[pos + 1] pos += 1 pos += 1 return result t = int(input().strip()) for _ in range...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR F...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
class RLE_list: def __init__(self, n, l): self.n = n self.l = l self.incremet() def reduce_cell(self, ind): self.l[ind] -= 1 def clear_zeros(self): l = [0] + self.l n = self.n + 1 ind = 1 while ind < n - 1: if l[ind] == 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_DEF VAR VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUM...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
def whatsNext(arr): parts = [(("0" if i % 2 else "1") * length) for i, length in enumerate(arr)] printBinArrRes(nextbin(list("".join(parts)))) def printBinArrRes(bin_i): bin_i = "".join(bin_i).lstrip("0") one_group = [len(x) for x in bin_i.split("0") if x] zero_group = [len(x) for x in bin_i.split...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER STRING STRING VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
for _ in range(int(input().strip())): n = int(input()) A = [int(x) for x in input().strip().split()] if len(A) % 2 == 1: if len(A) > 1: A[-2] -= 1 A.append(1) A.append(A[-2] - 1) A[-3] = 1 else: if len(A) > 2: A[-3] -= 1 A[-1] += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUM...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
tests = int(input()) for test in range(tests): n = int(input()) A = [int(s) for s in input().split()] last3 = A[-3:] if n % 2 == 0: if n == 2: if A[0] == 1: print(2) print(1, A[1] + 1) else: print(3) print(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 VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMB...
Johnny is playing with a large binary number, $\mbox{B}$. The number is so large that it needs to be compressed into an array of integers, $\mbox{A}$, where the values in even indices ($0,2,4,\ldots$) represent some number of consecutive $1$ bits and the values in odd indices ($1,3,5,\ldots$) represent some number of c...
num_cases = int(input()) for i in range(num_cases): num_elems = input() elems = list(map(int, input().split())) if len(elems) == 1: if elems[0] == 1: print("2") print("1 1") else: print("3") print("1 1 " + str(elems[0] - 1)) continue ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING FUN...
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receive...
n = int(input()) L = [] for i in range(n): l, r = list(map(int, input().split(" "))) L.append([l, r]) for i in range(n, 5): L.append([0, 0]) ans = 0.0 for s in range(1, 10001): P = [0] * 5 for i in range(5): P[i] = max(min((L[i][1] - s + 1) / (L[i][1] - L[i][0] + 1), 1.0), 0.0) P0 = 1.0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSI...
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receive...
d = [list(map(int, input().split())) for i in range(int(input()))] s = 0 for k in range(1, 10001): p = [min(max((k - l) / (r - l + 1), 1e-20), 1) for l, r in d] u = v = 1 for r in p: u *= r for r in p: v *= r s += (u - v) * (r - 1) / r print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR...
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receive...
import itertools n = int(input()) pairs = [] for i in range(n): pairs.append([int(x) for x in input().split()]) allPairs = [ x for x in itertools.product((0, 1, 2), repeat=len(pairs)) if x.count(0) == 1 and x.count(1) >= 1 or x.count(0) == 0 and x.count(1) >= 2 ] def analyze_sec_price_prob(companiesP...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL V...
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receive...
n = int(input()) l = [] r = [] for _ in range(n): x, y = map(int, input().split()) l.append(x) r.append(y) big = 1 for i in range(n): big *= r[i] - l[i] + 1 out = 0 for amt in range(10000): for x in range(n): for y in range(n): if x == y: continue loca...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL...
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receive...
import sys MaxV = int(10000.0) data = [] readIdx = 0 for line in sys.stdin.readlines(): data += line.split() def read(): global readIdx readIdx += 1 return data[readIdx - 1] n, average, power, mul = int(read()), 0, 1, 1 froms, tos, r = [], [], [] def generate(i, maxIdx, secondMax, equal, ways): ...
IMPORT ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF VAR NUMBER RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR LIST LIST LIST FUNC_DEF IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF ...
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receive...
def p2pl(p1, p2, p3, p4, p5): prob0 = (1 - p1) * (1 - p2) * (1 - p3) * (1 - p4) * (1 - p5) prob1 = ( p1 * (1 - p2) * (1 - p3) * (1 - p4) * (1 - p5) + p2 * (1 - p1) * (1 - p3) * (1 - p4) * (1 - p5) + p3 * (1 - p1) * (1 - p2) * (1 - p4) * (1 - p5) + p4 * (1 - p1) * (1 - p2) * (1 - ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP ...
Let's call a non-empty sequence of positive integers a_1, a_2... a_{k} coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 10^9 + 7. N...
n = int(input()) r = list(map(int, input().split())) dp = [0] * (10**5 + 1) cnt = [0] * (10**5 + 1) tmp = [0] * (10**5 + 1) mod = 10**9 + 7 for i in range(n): cnt[r[i]] += 1 for i in range(1, 10**5 + 1): for j in range(2 * i, 10**5 + 1, i): cnt[i] += cnt[j] tmp[i] = pow(2, cnt[i], mod) - 1 for i in ...
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 BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP B...
Let's call a non-empty sequence of positive integers a_1, a_2... a_{k} coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 10^9 + 7. N...
fact = [1] temp = 1 MOD = 10**9 + 7 for i in range(1, 10**5 + 5): temp *= i temp %= MOD fact += [temp] def bino(a, b): up = fact[a] down = pow(fact[b] * fact[a - b], MOD - 2, MOD) return up * down % MOD def find(A): MOD = 10**9 + 7 dp = [0] * (10**5 + 2) for x in A: dp[x]...
ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR VAR VAR VAR LIST VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR VAR VA...
Let's call a non-empty sequence of positive integers a_1, a_2... a_{k} coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 10^9 + 7. N...
import sys mod = 10**9 + 7 def solve(): n = int(input()) a = [int(i) for i in input().split()] cnt = [0] * (10**5 + 1) for ai in a: for d in range(1, ai + 1): if d * d > ai: break if ai % d == 0: if d != ai // d: cnt[...
IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR IF BIN_OP VAR VA...
Let's call a non-empty sequence of positive integers a_1, a_2... a_{k} coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 10^9 + 7. N...
N = 10**5 + 5 MOD = 10**9 + 7 freq = [(0) for i in range(N)] p2 = [(0) for i in range(N)] p2[0] = 1 for i in range(1, N): p2[i] = p2[i - 1] * 2 p2[i] %= MOD def Calculate_Mobius(N): arr = [(1) for i in range(N + 1)] prime_count = [(0) for i in range(N + 1)] mobius_value = [(0) for i in range(N + 1...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ...
Let's call a non-empty sequence of positive integers a_1, a_2... a_{k} coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 10^9 + 7. N...
mod = int(1000000000.0 + 7) n = int(input()) a = [int(_) for _ in input().split()] freq = {i: (0) for i in range(100001)} power = {(0): 1} for i in range(1, 100001): power[i] = 2 * power[i - 1] % mod for v in a: freq[v] += 1 dp = {i: (0) for i in range(100001)} for gcd in range(100000, 0, -1): mult = 2 ...
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR FOR...
Let's call a non-empty sequence of positive integers a_1, a_2... a_{k} coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 10^9 + 7. N...
MOD = int(1000000000.0) + 7 N = int(input()) A = list(map(int, input().split())) pow2 = [pow(2, i, MOD) for i in range(N + 1)] maxa = max(A) mcnt = [(0) for i in range(maxa + 1)] mans = [(0) for i in range(maxa + 1)] for i in range(N): mcnt[A[i]] += 1 for i in range(1, maxa + 1): for j in range(i + i, maxa + 1,...
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VA...
Let's call a non-empty sequence of positive integers a_1, a_2... a_{k} coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 10^9 + 7. N...
n = int(input()) L = list(map(int, input().split(" "))) D = [0] * 101000 mod = 10**9 + 7 itt = [0] * 101000 p = [0] * 100010 D[0] = 1 for i in range(100010): D[i + 1] = D[i] * 2 % mod for i in range(n): itt[L[i]] += 1 for i in range(1, 100001): for j in range(i * 2, 100001, i): itt[i] += itt[j] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUM...
Let's call a non-empty sequence of positive integers a_1, a_2... a_{k} coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 10^9 + 7. N...
import sys mod = 10**9 + 7 def solve(): n = int(input()) a = [int(i) for i in input().split()] cnt = [0] * (10**5 + 1) pat = [0] * (10**5 + 1) p2 = [1] * (n + 1) for i in range(1, n + 1): p2[i] = 2 * p2[i - 1] % mod for ai in a: cnt[ai] += 1 for i in range(1, 10**5 + 1...
IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BI...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
M = 10**9 + 7 t = int(input()) for _ in range(t): n = int(input()) if n <= 2: print(n) else: s = bin(n) num = len(s) - 2 out = pow(2, num, M) if s.count("1") == 1: out -= 1 print(out % M)
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 FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR IF FUNC_CALL VAR STRI...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
t = int(input()) for i in range(t): n = int(input()) l = 1 mod = 1000000000.0 + 7 if n <= 2: print(n) continue i = 0 j = 40 while j > i: m = (i + j) // 2 if 2**m <= n: l = m i = m + 1 else: j = m l = 2**l % mod ...
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 BIN_OP NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR VAR...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
m = 1000000007 for i in range(int(input())): n = int(input()) if n == 1: print(1) continue if n == 2: print(2) continue j = 2 while n > j: j *= 2 if j == n: print((j * 2 - 1) % m) else: print(j % m)
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VA...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
for _ in range(int(input())): n = int(input()) b = bin(n).replace("0b", "") l = len(b) if n == 2: print(2) elif n == 2 ** (l - 1) and n <= 10**12: print((2**l - 1) % (10**9 + 7)) else: print(2**l % (10**9 + 7))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBE...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
for _ in range(int(input())): n = int(input()) mod = int(1000000000.0 + 7) if n == 1 or n == 2: print(n) elif n & n - 1 == 0: print((2 * n - 1) % mod) else: print(2 ** len(bin(n)[2:]) % mod)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUM...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
mod = 10**9 + 7 def exp(x): n = 1 base = 0 while n < x: n *= 2 base += 1 return base def power(x, n): ans = 1 x = x % mod while n: if n & 1: ans = ans * x % mod n = n >> 1 x = x * x % mod return ans for u in range(int(input())): ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
for _t in range(int(input())): n = int(input()) ans = 1 if n == 2: print("2") continue while ans < n: ans *= 2 if n == ans: ans *= 2 ans -= 1 print(int(ans % (1000000000.0 + 7)))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING WHILE VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
from sys import stdin, stdout t = int(stdin.readline()) for i in range(t): n = int(stdin.readline()) my_dict = {(1): 1, (2): 2, (3): 4, (4): 7} if n in my_dict: print(my_dict[n]) else: m = 2 while 1 << m < n: m += 1 if 1 << m == n: print(((1 << m ...
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 IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_O...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
l = 10**9 + 7 for i in range(int(input())): n = int(input()) if n == 1: print(1) elif n == 2: print(2) elif n & n - 1 == 0: print((n * 2 - 1) % l) else: j = 2 while j < n: j = j * 2 print(j % l)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSI...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
try: p = int(input()) while p > 0: p = p - 1 n = int(input()) t = 0 while pow(2, t) <= n: t = t + 1 if n == 2: print(2) elif n == pow(2, t - 1): k = pow(2, t) - 1 print(k % 1000000007) else: d = p...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL ...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
def main(): mod = 10**9 + 7 for _ in range(int(input())): n = int(input()) if n <= 2: print(n) elif n & n - 1: print(pow(2, len(bin(n)) - 2, mod)) else: print((2 * n - 1) % mod) main()
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VA...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
T = int(input()) for _ in range(T): n = int(input()) if n == 1 or n == 2: print(n) else: i = 2 while i <= n: if 2**i == n: print((2 ** (i + 1) - 1) % 1000000007) break elif 2**i > n: print(2**i % 1000000007) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP NUMBER VAR VAR EXPR FU...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
for jkfd in range(int(input())): n = int(input()) if n == 1: print(1) continue elif n == 2: print(2) continue elif n == 3: print(4) continue p = False x = 4 asdf = [(2**i) for i in range(2, 100)] if n in asdf: p = True while x <...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASS...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
def nextPowerOf2(n): count = 0 if n and not n & n - 1: return n while n != 0: n >>= 1 count += 1 return 1 << count t = int(input()) for i in range(t): modulo = 10**9 + 7 n = int(input()) if n == 1: print(1) elif n == 2: print(2) else: ...
FUNC_DEF ASSIGN VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
def bin_exp(n, p): mod = int(10**9) + 7 pwrs = [n] for i in range(60): pwrs.append(pwrs[-1] * pwrs[-1] % mod) i = 0 prod = 1 while p: if p & 1 == 1: prod = prod * pwrs[i] % mod i += 1 p = p // 2 return prod t = int(input()) for _ in range(t): ...
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
def setbits(a): c = 0 while a > 0: c += 1 a &= a - 1 return c for tc in range(int(input())): n = int(input()) mod = 1000000007 if n <= 3: if n == 1: print(1) elif n == 2: print(2) elif n == 3: print(4) else: ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR BIN_OP 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 NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VA...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
for _ in range(int(input())): n = int(input()) if n == 1: print(1) elif n == 2: print(2) else: for i in range(1, n): if n < 2**i: break if n == 2 ** (i - 1): ans = 2 * n - 1 print(ans % 1000000007) else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP NUMBER VAR IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_C...
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N. Formally, let S be the set S = \{x\oplus y \mid 1 ≤ x, y ≤ N\} where \oplus denotes the [bitwise XOR] operation. Find |S| (where |S| denotes the size of set S. Note that a set, by defini...
mod = int(1000000000.0 + 7) for _ in range(int(input())): n = int(input()) print( n if n < 3 else pow(2, len(bin(n)) - 2, mod) if n & n - 1 else (2 * n - 1) % mod )
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR