description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
After defeating a Blacklist Rival, you get a chance to draw $1$ reward slip out of $x$ hidden valid slips. Initially, $x=3$ and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are $c$, $m$, and $p$, respect...
t = int(input()) ex = 0 def dfs(c, m, p, v, count, curr): global ex if p: ex += curr * count * p if c > 10**-6: if c > v: if m > 10**-6: dfs(c - v, m + v / 2, p + v / 2, v, count + 1, curr * c) else: dfs(c - v, 0, p + v, v, count + 1,...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER IF VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BI...
After defeating a Blacklist Rival, you get a chance to draw $1$ reward slip out of $x$ hidden valid slips. Initially, $x=3$ and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are $c$, $m$, and $p$, respect...
import sys input = sys.stdin.readline def dfs(c, m, p, Prob, Try): Ex = Try * Prob * p if c < 1e-07: c = 0 if m < 1e-07: m = 0 if c and m: Ex += dfs( max(0, c - V), m + min(c, V) / 2, p + min(c, V) / 2, Prob * c, Try + 1 ) Ex += dfs( c +...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUM...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
nums = input().split() numPeople = int(nums[0]) numPairs = int(nums[1]) names = [] for i in range(numPeople): names.append(input()) pair1 = [] pair2 = [] for i in range(numPairs): pair = input().split() pair1.append(pair[0]) pair2.append(pair[1]) numSets = pow(2, numPeople) bestSet = [] for i in range(1...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL ...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
def do(): n, m = map(int, input().split(" ")) ban = [] names = [] res = [] for _ in range(n): names.append(input()) d = {name: i for i, name in enumerate(names)} for _ in range(m): x, y = input().split(" ") ban.append(1 << d[x] | 1 << d[y]) for state in range(1 <<...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
n, m = map(int, input().split()) ID = {} name_from_ID = {} for i in range(n): name = input() ID[name] = i name_from_ID[i] = name people_I_hate = [set() for i in range(n)] for j in range(m): name1, name2 = input().split() people_I_hate[ID[name1]].add(ID[name2]) people_I_hate[ID[name2]].add(ID[nam...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
def get_subsets(elements): if not elements: yield tuple() else: for subset_rec in get_subsets(elements[1:]): yield subset_rec yield (elements[0],) + subset_rec def is_valid_set(subset, pairs): subset = set(subset) ok = True for pair in pairs: ok = ok...
FUNC_DEF IF VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER EXPR VAR EXPR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL ...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
global res, maxi res = [] maxi = 0 def check(op): global maxi, res flag = 1 if len(op) > maxi: d = {} for i in op: d[i] = None for i in range(m): if v[i][0] in d and v[i][1] in d: flag = 0 break if flag: ma...
ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NONE FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CAL...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
import itertools as it n, m = map(int, input().split()) edges = set() friends_M = {} for i in range(n): friends_M[input()] = i for _ in range(m): a, b = input().split() a, b = friends_M[a], friends_M[b] edges.add((a, b)) edges.add((b, a)) best = 0 best_vals = [] for subset in it.product([0, 1], rep...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
def GSB(x): counter = 0 while x != 0: counter += 1 x = x >> 1 return counter def friends(checker, enemy): for i in range(len(enemy)): if enemy[i][0] in checker and enemy[i][1] in checker: return 0 return 1 people, conflict = [int(x) for x in input().split()] p...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUM...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
n, m = map(int, input().split()) N = [n] Names = {} Numbers = {} Enemies = [] for i in range(n): s = input() Names[s] = i Enemies.append([]) Numbers[i] = str(s) for i in range(m): a, b = input().split() Enemies[Names[a]].append(Names[b]) Enemies[Names[b]].append(Names[a]) Ans = [[]] def dp...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXP...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
n, m = map(int, input().split()) names = dict() ind = dict() enemies = list() for i in range(n): cur = input() names[i] = cur ind[cur] = i enemies.append(set()) for i in range(m): nm1, nm2 = input().split() enemies[ind[nm1]].add(ind[nm2]) enemies[ind[nm2]].add(ind[nm1]) ans = 0 for i in rang...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR E...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
def s(): [n, m] = list(map(int, input().split())) a = [input() for _ in range(n)] b = {input() for _ in range(m)} res = [[]] aa = len(a) * [False] def r(x=0): if x == n: p = [a[i] for i in range(n) if aa[i]] if len(p) <= len(res[0]): return ...
FUNC_DEF ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR LIST NUMBER FUNC_DEF NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
from itertools import combinations def solve(): n, m = map(int, input().split()) name = sorted([input().strip() for i in range(n)]) bad = sorted([sorted(input().strip().split()) for i in range(m)]) for i in range(n, -1, -1): temp = sorted(map(sorted, combinations(name, i))) for k in te...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
n, m = map(int, input().split()) names = [] mp = {} for i in range(n): name = input() mp[name] = i names.append(name) mask = [0] * n for i in range(m): a, b = map(mp.get, input().split()) mask[a] |= 1 << b mask[b] |= 1 << a ans = 0 result = 0 def bcnt(x): return 0 if x == 0 else bcnt(x >> ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR BIN_OP NUMBER...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
n_m = input() n, m = [int(s) for s in n_m.split()] names = [] reverse = dict() entente = [([True] * n) for _ in range(n)] for i in range(n): name = input() names.append(name) reverse[name] = i entente[i][i] = False for i in range(m): i1, i2 = [reverse[s] for s in input().split()] entente[i2][i1]...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR AS...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
f_in = input() f_in = f_in.split(" ") num_members = int(f_in[0]) num_bad_pairs = int(f_in[1]) members = [] bad_pair = [] bad_pair_dic = {} for i in range(num_members): members.append(input()) for i in range(num_bad_pairs): bad_pair = input().split(" ") if bad_pair[0] not in bad_pair_dic: bad_pair_di...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VA...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
n, m = map(int, input().split()) p = {} for i in range(n): p[input()] = [] for i in range(m): a, b = input().split() p[a].append(b) p[b].append(a) t, r, k = [], [], 0 for a in p: d = set(p[a]) for i in range(k): if a in t[i]: continue q = t[i] | d if len(q) ==...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR LIST LIST NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
ii = lambda: int(input()) kk = lambda: map(int, input().split()) ll = lambda: list(kk()) n, m = kk() ppl = [input() for _ in range(n)] others = [set() for _ in range(n)] for _ in range(m): a, b = input().split() a = ppl.index(a) b = ppl.index(b) others[a].add(b) others[b].add(a) largest = set() for ...
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 FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR A...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
tmp = input().split(" ") N_ppl = int(tmp[0]) N_cstrt = int(tmp[1]) ppl_to_id = {} id_ppl = [0] * N_ppl cstrt = [0] * N_ppl for i in range(N_ppl): tmp = input() id_ppl[i] = tmp ppl_to_id[tmp] = i cstrt[i] = [] for i in range(N_cstrt): tmp = input().split() cstrt[ppl_to_id[tmp[0]]].append(ppl_to_i...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR LIST FOR VAR FUNC_...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
cant_integrantes, cant_lleva_mal = map(int, input().split(" ")) integrantes = [] lleva_mal = [] for i in range(cant_integrantes): integrantes.append(input()) for i in range(cant_lleva_mal): n1, n2 = map(str, input().split(" ")) lista = [n1, n2] lista.sort() lleva_mal.append(lista) if cant_lleva_mal ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NU...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
from itertools import product n, m = map(int, input().split()) vl = sorted([input() for i in range(n)]) cm = {vl[i]: i for i in range(n)} cl = [] for i in range(m): a, b = input().split() cl += [[cm[a], cm[b]]] ans = [(), 0] for x in list(product([1, 0], repeat=n)): flag = 0 for c in cl: if x[c...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST LIST VAR VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR F...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
def good(a, bad): for i in bad: if i[0] in a and i[1] in a: return False return True def f(arr, bad, d): n = len(arr) mask = 0 ans = [] while mask < 1 << n: temp = [] for i in range(len(arr)): if mask & 1 << i: temp.append(i) ...
FUNC_DEF FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EX...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
def moins(M, N): L = [] for i in M: if i not in N: L += [i] return L S = str(input()) l = S.split(" ") n, m = int(l[0]), int(l[1]) d = {} S = str(input()) L = [S] for i in range(n - 1): S = str(input()) j, f = 0, 0 while f == 0: if j == len(L): L += [S] ...
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR LIST VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMB...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
n, m = map(int, input().split()) names = [] for i in range(n): names.append(input()) hate = [] for i in range(m): hate.append(list(input().split())) ans = set() for x in range(1, (1 << n) + 1): a = set() for i in range(n): if x & 1 << i: a.add(names[i]) flag = True for b in h...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASS...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
def bitmask(m, array): return [array[i] for i in range(len(array)) if m & 1 << i] n, k = map(int, input().split()) names = [input() for _ in range(n)] names.sort() bads = [input().split() for _ in range(k)] m_count, bb = -1, [] for m in range(2**n): if bin(m).count("1") < m_count: continue b = bit...
FUNC_DEF RETURN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER LIST FOR VAR FUNC_CALL VAR BI...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
n, m = map(int, input().split()) l = [] for i in range(n): l.append(input()) c = [] for i in range(m): s1, s2 = input().split() c.append([1 << l.index(s1), 1 << l.index(s2)]) ans = [] for i in range(1, 2**n): flag = 0 for k in c: if i & k[0] and i & k[1]: flag = 1 bre...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR...
When little Petya grew up and entered the university, he started to take part in АБМ contests. Later he realized that he doesn't like how the АБМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff...
def check(b): for i in b: for j in b: if (a[i], a[j]) in pair or (a[j], a[i]) in pair: return False return True n, m = map(int, input().split()) a = [] ind = {} for i in range(n): a.append(input()) ind[a[-1]] = i graph = [[] for i in range(n)] pair = {} for i in ran...
FUNC_DEF FOR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSI...
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps: Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation. $a$, $b$, $c$ are not in $s$. Here triple of intege...
import sys input = sys.stdin.readline out = [] t = int(input()) for _ in range(t): n = int(input()) n -= 1 rem = n % 3 n //= 3 s = [] if n: n -= 1 while n >= 0: s.append( [ ["00", "00", "00"], ["01", "10", "11"]...
IMPORT ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST IF VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR LIST LIST STRING STRING STRING LIST STRING STRING STRING ...
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps: Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation. $a$, $b$, $c$ are not in $s$. Here triple of intege...
import sys input = sys.stdin.readline t = int(input()) s = [int(input()) for i in range(t)] res = [] for num in s: num -= 1 mod = num % 3 num = num // 3 div = 1 while True: if num // div != 0: num -= div div *= 4 else: break a = div + num ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ...
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps: Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation. $a$, $b$, $c$ are not in $s$. Here triple of intege...
import sys from itertools import combinations input = sys.stdin.readline t = int(input()) for tt in range(t): n = int(input()) - 1 mod3 = n % 3 n = n // 3 i = 0 while n >= 4**i: n -= 4**i i += 1 if i == 0: a = 1 b = 2 c = 3 else: a = 4**i + n ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR ...
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps: Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation. $a$, $b$, $c$ are not in $s$. Here triple of intege...
from sys import stdin input = stdin.readline pot = [1] * 40 for i in range(1, 40): pot[i] = 4 * pot[i - 1] poczatki = [1, 2] for i in range(38): os = poczatki[-1] poczatki.append(os + pot[i + 1]) tab = [[0, 1, 2, 3], [0, 2, 3, 1], [0, 3, 1, 2]] def odp(ind, m3): if ind == 1: return m3 + 1 ...
ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER...
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps: Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation. $a$, $b$, $c$ are not in $s$. Here triple of intege...
import sys def new_find_pair(n): stack = [] while n: N = n.bit_length() - 1 if N % 2 == 0: i = N // 2 stack.append((n, 1, i)) n -= 4**i else: i = N // 2 if n >> 2 * i & 1 == 0: stack.append((n, 2, i)) ...
IMPORT FUNC_DEF ASSIGN VAR LIST WHILE VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP...
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps: Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation. $a$, $b$, $c$ are not in $s$. Here triple of intege...
def find_answer(n): trio_num, trio_place = n // 3, n % 3 digit = 1 while trio_num >= 0: trio_num -= digit digit *= 4 digit //= 4 trio_num += digit t1 = digit + trio_num if trio_place == 0: return t1 t2, t3 = digit * 2, digit * 3 new_digit = 1 while new_dig...
FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
n = int(input()) curr = list([i for i in range(1, 100)]) curr = set(curr) def isvalid(x): if x < 1 or x > 10**9: return 0 if len(set(str(x))) <= 2: return 1 cnt = 0 while cnt <= 10**5: curr1 = set() for i in curr: for j in range(10): if isvalid(i * 10 + j): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR BIN_OP NUMBER NUMBER RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER NUMBER ASSIGN VAR...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
def p(k): if 0 < k <= n: s.add(k) k *= 10 p(k + x) p(k + y) n = int(input()) s = set() for x in range(10): for y in range(10): p(x) print(len(s))
FUNC_DEF IF NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
num = int(input()) cou = 0 def traverse(x): if x > num: return nonlocal cou if len(set([int(j) for j in str(x)])) <= 2: cou += 1 for i in range(0, 10): traverse(10 * x + i) for i in range(1, 10): traverse(i) print(cou)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
n = int(input()) use = set() def calc(x, a, b): global cnt if int(x) <= n and not int(x) in use: use.add(int(x)) elif int(x) > n: return calc(x + a, a, b) calc(x + b, a, b) def calc2(x, a): global cnt if int(x) <= n and not int(x) in use: use.add(int(x)) elif ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
ii = lambda: int(input()) kk = lambda: map(int, input().split()) ll = lambda: list(kk()) q = [] s = set() n = ii() for x in range(10): for y in range(10): q.append(x) while q: q2 = [] for item in q: if item > 0 and item <= n: s.add(item) ...
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 LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR LIST FOR VAR VAR IF V...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
import sys dp = [[[(-1) for j in range(3)] for i in range(1 << 10)] for k in range(11)] In = sys.stdin n = In.readline().strip() def go(idx, mask, equal): if dp[idx][mask][equal] != -1: return dp[idx][mask][equal] if bin(mask).count("1") > 2: return 0 if idx == len(n): return 1 ...
IMPORT ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR IF FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER ...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
n = int(input()) array = set() array.add(10**9) for x in range(10): for y in range(10): for l in range(1, 10): for m in range(1, 2**l + 1): s = [(str(x) if m & 1 << i else str(y)) for i in range(l)] u = int("".join(s)) if u <= n: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR FUN...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
n = int(input()) def bruteforce(number): res = 0 liste = [] while number > 0: integer = number % 10 if integer not in liste: liste.append(integer) number = number // 10 return len(liste) <= 2 answer = [0] def dfs(num): if num > 0 and num <= n: answer...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUM...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
s = set() def DFS(x, y, num): s.add(num) num_x = 10 * num + x num_y = 10 * num + y if num_x and num_x <= n: DFS(x, y, num_x) if num_y and num_y <= n: DFS(x, y, num_y) n = int(input()) for i in range(10): for j in range(i, 10): DFS(i, j, 0) print(len(s) - 1)
ASSIGN VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR V...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
n = int(input()) res = set() def solve(p, l): if p > n or l > 10: return if p > 0: res.add(p) solve(p * 10 + a, l + 1) solve(p * 10 + b, l + 1) for a in range(0, 10): for b in range(0, a): solve(0, 0) print(len(res))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
from itertools import product n = int(input().strip()) if n < 102: print(n) else: from itertools import product res = set() combination = (str(i) + str(j) for i in range(10) for j in range(i + 1, 10)) for it in ( product(comb, repeat=l) for comb in combination for l in rang...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUN...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
def gen(digit, x, length, S): S.append(x) if length == 10: return if len(digit) == 1: for i in range(0, 10): next_x = x * 10 + i if i == digit[0]: gen(digit, next_x, length + 1, S) else: gen(digit + [i], next_x, length + 1, ...
FUNC_DEF EXPR FUNC_CALL VAR VAR IF VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NU...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
n = int(input()) a = [] def foo(x, i, j): if x > n: return if x: a.append(x) if 10 * x + i != x: foo(10 * x + i, i, j) foo(10 * x + j, i, j) for i in range(10): for j in range(i + 1, 10): foo(0, i, j) print(len(set(a)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF IF VAR VAR RETURN IF VAR EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VA...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
nset = set() n = int(input()) def reslove(x, y, num, flag): if num > n or flag and num == 0: return if num > 0: nset.add(num) reslove(x, y, num * 10 + x, True) reslove(x, y, num * 10 + y, True) for i in range(10): for j in range(i + 1, 10): reslove(i, j, 0, False) print(l...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR ...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
n = str(int(input()) + 1) a = int(n[0]) l = len(n) d = 1 << l - 1 def f(a, i): global n, l if i == l: return 0 b = int(n[i]) i += 1 d = 1 << l - i if a > b: return b * d + g(b, a, i) if a == b: return b * d + f(a, i) return (b - 1) * d + g(a, b, i) + 9 * d - 8 ...
ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR RETURN BIN_OP BI...
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
def cnt(s, p): ans = 0 if p > s: ans = 0 elif len(p) == len(s): ans = 1 if len(set(p.lstrip("0"))) <= 2 else 0 elif len(set(p.lstrip("0"))) > 2: ans = 0 elif s[: len(p)] > p: if len(set(p.lstrip("0"))) == 2: ans = 2 ** (len(s) - len(p)) elif len(se...
FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CA...
Consider the infinite sequence s of positive integers, created by repeating the following steps: 1. Find the lexicographically smallest triple of positive integers (a, b, c) such that * a βŠ• b βŠ• c = 0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). * a, b, ...
import sys for _ in range(int(sys.stdin.readline())): n = int(sys.stdin.readline()) q, r = (n - 1) // 3, n % 3 i = 0 while q >= 1 << (i << 1): q -= 1 << (i << 1) i += 1 quad = [0] * i if r == 1: s = 0 while q > 0: quad[s] += q % 4 q >>= 2 ...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER ASSI...
Consider the infinite sequence s of positive integers, created by repeating the following steps: 1. Find the lexicographically smallest triple of positive integers (a, b, c) such that * a βŠ• b βŠ• c = 0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). * a, b, ...
def level(m): l = 0 while m - (1 << l * 2) >= 0: m -= 1 << l * 2 l += 1 return l, m def to_bin(l, r): ls = [] for __ in range(l): ls.append(r % 4) r //= 4 return ls def off(b, t): magic = [[0, 1, 2, 3], [0, 2, 3, 1], [0, 3, 1, 2]] base = 1 ans = 0 ...
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER LIST NU...
Consider the infinite sequence s of positive integers, created by repeating the following steps: 1. Find the lexicographically smallest triple of positive integers (a, b, c) such that * a βŠ• b βŠ• c = 0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). * a, b, ...
import sys lines = sys.stdin.readlines() t = int(lines[0].strip()) pows = [(4**i) for i in range(64)] vals = (0, 1, 2, 3), (0, 2, 3, 1), (0, 3, 1, 2) prt = [] for iter in range(t): n = int(lines[iter + 1].strip()) pow = 0 for i in range(64): if pows[i + 1] > n: pow = i break...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR N...
Consider the infinite sequence s of positive integers, created by repeating the following steps: 1. Find the lexicographically smallest triple of positive integers (a, b, c) such that * a βŠ• b βŠ• c = 0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). * a, b, ...
tail = [["00", "00", "00"], ["01", "10", "11"], ["10", "11", "01"], ["11", "01", "10"]] top = ["01", "10", "11"] S = [] E = [] cur = 1 for i in range(32): S.append(cur) E.append(4 * cur - 1) cur *= 4 def convert(s): cur = 1 ans = 0 for x in s[::-1]: if x == "1": ans |= cur ...
ASSIGN VAR LIST LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER...
Consider the infinite sequence s of positive integers, created by repeating the following steps: 1. Find the lexicographically smallest triple of positive integers (a, b, c) such that * a βŠ• b βŠ• c = 0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). * a, b, ...
import sys def input(): return sys.stdin.readline()[:-1] t = int(input()) rep = [[0, 1, 2, 3], [0, 2, 3, 1], [0, 3, 1, 2]] pows = [(1) for _ in range(30)] for i in range(1, 30): pows[i] = pows[i - 1] * 4 for _ in range(t): n = int(input()) n -= 1 quo, mod = n // 3, n % 3 stage, cum = 0, 0 ...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER...
Consider the infinite sequence s of positive integers, created by repeating the following steps: 1. Find the lexicographically smallest triple of positive integers (a, b, c) such that * a βŠ• b βŠ• c = 0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). * a, b, ...
import sys mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline for _ in range(int(input())): N = int(input()) if N <= 3: print(N) continue if N % 3 == 1: k = N.bit_length() - 1 if k & 1: ...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR 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 NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER EXPR FU...
Consider the infinite sequence s of positive integers, created by repeating the following steps: 1. Find the lexicographically smallest triple of positive integers (a, b, c) such that * a βŠ• b βŠ• c = 0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). * a, b, ...
import sys lines = sys.stdin.readlines() T = int(lines[0].strip()) partial = [ 1, 2, 3, 4, 8, 12, 5, 10, 15, 6, 11, 13, 7, 9, 14, 16, 32, 48, 17, 34, 51, 18, 35, 49, 19, 33, 50, 20, 40, 60, 21, ...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER 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 NU...
Consider the infinite sequence s of positive integers, created by repeating the following steps: 1. Find the lexicographically smallest triple of positive integers (a, b, c) such that * a βŠ• b βŠ• c = 0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). * a, b, ...
import sys memo = [(0, 0, 0)] def new_find_pair(n): stack = [] while n >= len(memo): N = n.bit_length() - 1 if N % 2 == 0: i = N // 2 stack.append((n, 1, i)) n -= 4**i else: i = N // 2 if n >> 2 * i & 1 == 0: ...
IMPORT ASSIGN VAR LIST NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUM...
Consider the infinite sequence s of positive integers, created by repeating the following steps: 1. Find the lexicographically smallest triple of positive integers (a, b, c) such that * a βŠ• b βŠ• c = 0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). * a, b, ...
import sys def log4(n): k = 0 while n > 3: n //= 4 k += 1 return k def manual_test(n): a = 0 s = [] forbidden = set() while len(s) < n: a = a + 1 while a in forbidden: a += 1 b = a + 1 while b in forbidden or a ^ b in forbidden ...
IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR N...
Consider the infinite sequence s of positive integers, created by repeating the following steps: 1. Find the lexicographically smallest triple of positive integers (a, b, c) such that * a βŠ• b βŠ• c = 0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). * a, b, ...
import sys input = sys.stdin.readline Q = int(input()) Query = [int(input()) for _ in range(Q)] for N in Query: N -= 1 seq = N // 3 where = N % 3 T = 0 for l in range(100): a = 4**l if T + a > seq: start = seq - T + a break T += a if where == 0: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP B...
Consider the infinite sequence s of positive integers, created by repeating the following steps: 1. Find the lexicographically smallest triple of positive integers (a, b, c) such that * a βŠ• b βŠ• c = 0, where βŠ• denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). * a, b, ...
import sys input = sys.stdin.buffer.readline for f in range(int(input())): n = int(input()) size = 2 ma = 4 while n >= ma: ma *= 4 size += 2 pr = ma // 4 ind = n - pr ind //= 3 first = [0] * size first[1] = 1 i = size - 1 while ind > 0: if ind % 2 == ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR B...
A company of $n$ friends wants to order exactly two pizzas. It is known that in total there are $9$ pizza ingredients in nature, which are denoted by integers from $1$ to $9$. Each of the $n$ friends has one or more favorite ingredients: the $i$-th of friends has the number of favorite ingredients equal to $f_i$ ($1 \...
import itertools from sys import stdin, stdout n, m = map(int, stdin.readline().split()) friends = [0] * 512 exists = [0] * 512 costs_min = [0] * 512 costs_2 = [0] * 512 index_min = [0] * 512 index_2 = [0] * 512 count_friends = [0] * 512 def top_to_idx(top): ans = 0 for t in top: ans += 1 << t - 1 ...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMB...
A company of $n$ friends wants to order exactly two pizzas. It is known that in total there are $9$ pizza ingredients in nature, which are denoted by integers from $1$ to $9$. Each of the $n$ friends has one or more favorite ingredients: the $i$-th of friends has the number of favorite ingredients equal to $f_i$ ($1 \...
import sys def popcount(i): assert 0 <= i < 4294967296 i = i - (i >> 1 & 1431655765) i = (i & 858993459) + (i >> 2 & 858993459) return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24 N, M = map(int, sys.stdin.readline().split()) table = [0] * 2**9 for _ in range(N): S = tuple(map(int,...
IMPORT FUNC_DEF NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_...
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Example 1: Input:Β 2 Output:Β [0,1,3,2] Explanation: 00 - 0 01 - 1 11 ...
class Solution: def grayCode(self, n): ans = [0] mask = 1 for l in range(n): for c in ans[::-1]: ans.append(mask | c) mask <<= 1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Example 1: Input:Β 2 Output:Β [0,1,3,2] Explanation: 00 - 0 01 - 1 11 ...
class Solution: def grayCode(self, n): if n == 0: return [0] result = [0, 1] for i in range(2, n + 1): mask = 1 << i - 1 temp = [] for j in range(len(result)): temp.append(result[-j - 1] | mask) result += temp ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Example 1: Input:Β 2 Output:Β [0,1,3,2] Explanation: 00 - 0 01 - 1 11 ...
class Solution: def grayCode(self, n): if n == 0: return [0] concat = "" res = [0, 1] for i in range(1, n): newRes = [] for j in res: newRes.append(j) for j in reversed(res): newRes.append(j + 2**i) ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR STRING ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR RETURN VAR
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Example 1: Input:Β 2 Output:Β [0,1,3,2] Explanation: 00 - 0 01 - 1 11 ...
class Solution: def grayCode(self, n): if n < 0: return [] elif n == 0: return [0] elif n == 1: return [0, 1] result = [0, 1] res_len = 2**n cnt = 1 while len(result) != res_len: cnt *= 2 result.exte...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST IF VAR NUMBER RETURN LIST NUMBER IF VAR NUMBER RETURN LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VA...
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Example 1: Input:Β 2 Output:Β [0,1,3,2] Explanation: 00 - 0 01 - 1 11 ...
class Solution: def helper(self, n): if n == 0: return ["0"] if n == 1: return ["0", "1"] ret = [] for code in self.helper(n - 1): ret.append("0" + code) for code in reversed(self.helper(n - 1)): ret.append("1" + code) ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST STRING IF VAR NUMBER RETURN LIST STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN LIS...
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Example 1: Input:Β 2 Output:Β [0,1,3,2] Explanation: 00 - 0 01 - 1 11 ...
class Solution: def grayCode(self, n): result = [0] for i in range(n): temp = [] for num in result: temp.append(num + 2**i) result += temp[::-1] return result
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER RETURN VAR
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Example 1: Input:Β 2 Output:Β [0,1,3,2] Explanation: 00 - 0 01 - 1 11 ...
class Solution: def grayCode(self, n): if n == 0: return [0] q = [0, -1] for i in range(n): tag = 0 while q[0] != -1: item = q.pop(0) q.append(item * 2 + tag) q.append(item * 2 + (1 - tag)) t...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR...
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Example 1: Input:Β 2 Output:Β [0,1,3,2] Explanation: 00 - 0 01 - 1 11 ...
class Solution: def grayCode(self, n): result = [0, 1] if n <= 1: return result[: n + 1] res_len = 2**n cnt = 1 while len(result) != res_len: cnt *= 2 result.extend(result[::-1]) start = len(result) // 2 for i in ra...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER IF VAR NUMBER RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR
2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase). When a team loses a g...
from itertools import product M = 998244353 k, A, h = map(int, input().split()) def play_half(os, lo, lo_win): j = 0 teams = list(range(2 ** (k - 1))) places = [(0) for _ in teams] for i in range(k - 1): tt = [] z = 2 ** (k - 2 - i) for r in range(z): o = os[j] ...
ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR FOR VAR...
2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase). When a team loses a g...
MOD = 998244353 k, A, H = map(int, input().split()) sgames = 2 ** (k - 1) - 1 steams = 2 ** (k - 1) def build(wp: int, offset: int): pos = {} for outcomes in range(2**sgames): i = 0 res = 0 teams = [i for i in range(steams)] place = [-1] * steams for p in range(k - 1, 0...
ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_DEF VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR...
2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase). When a team loses a g...
k, A, h = map(int, input().split()) team = 1 << k mod = 998244353 POW = [1] for i in range(100): POW.append(POW[-1] * A % mod) ANS = [(1 << k - 1) + 1] * (team // 2) X = tuple([i for i in range(team // 2)]) ALLLIST = [] def half_all(ANS, X, Y, i): if i == 0: ALLLIST.append(tuple(ANS)) return A...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL ...
2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase). When a team loses a g...
import sys def pr(x): sys.stdout.write(str(x) + "\n") def inp(): return sys.stdin.readline() M = 998244353 k, a, h = [int(i) for i in inp().split()] pp = [[], [2], [3, 2], [5, 3, 2], [9, 5, 3, 2], [17, 9, 5, 3, 2]] pa = [(a**i % M) for i in pp[k]] rgs = [ [], [[1, 3]], [[4, 7], [1, 5]], [[...
IMPORT FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST LIST NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUM...
2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase). When a team loses a g...
import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline...
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CAL...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
memo = dict() def knpsk(c, w, index, k): if index in memo.keys(): if k in memo[index].keys(): return memo[index][k] if k == 0 or index == -1: return 0 if c[index] > k: return knpsk(c, w, index - 1, k) if index not in memo: memo[index] = dict() memo[index...
ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
def make_set(arr, l): ans = [] for i in range(2**l): bits = bin(i)[2:] bits = "0" * (l - len(bits)) + bits temp = [] for x in range(l): if bits[x] == "1": temp += [arr[x]] ans += [temp] return ans t = int(input()) for i in range(t): n...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR LIST VAR VAR VAR LIST VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_C...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
import itertools import sys T = int(sys.stdin.readline()) for _ in range(T): n, k = list(map(int, sys.stdin.readline().split())) cost, weight = zip( *[list(map(int, sys.stdin.readline().split())) for _ in range(n)] ) weights = [] for seq in itertools.product([0, 1], repeat=n): if su...
IMPORT IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER VAR IF...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
def bitmask(cost, wt, W, n): s = "" for i in range(n): s += "1" s = int(s, 2) ans = 0 for i in range(1, s + 1): curr = i curr_val, j = 0, n - 1 curr_cost = W while curr != 0: if curr & 1: if curr_cost - cost[j] >= 0: ...
FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR VA...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
T = int(input()) for t in range(T): n, k = [int(i) for i in input().split(" ")] C = [] W = [] for X in range(n): c, w = [int(i) for i in input().split(" ")] C.append(c) W.append(w) maxwt = 0 for i in range(1 << n): curwt = 0 curcost = 0 for j in ra...
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 STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMB...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
import sys from itertools import combinations as combn stdin = sys.stdin for i, line in enumerate(stdin): if i == 0: T = int(line.strip()) N = -1 oranges = [] cur_i = 0 elif cur_i > N: N, K = [int(s) for s in line.strip().split(" ")] oranges = [] cur_i = ...
IMPORT ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
from itertools import combinations for _ in range(int(input())): toranges, trubles = list(map(int, input().split())) ocost_oweight = [] for i in range(toranges): ocost_oweight.append(list(map(int, input().split()))) pos_choices = [] for i in range(1, toranges + 1): pos_choices.appen...
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
def knapsack(k, c, w, n): if n == 0 or k == 0: return 0 if c[n - 1] > k: return knapsack(k, c, w, n - 1) else: return max( w[n - 1] + knapsack(k - c[n - 1], c, w, n - 1), knapsack(k, c, w, n - 1) ) t = int(input()) for _ in range(t): n, k = map(int, input()....
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
def snek(l, a, k, s, b): if a == len(l): return s if b == 0: return max(snek(l, a + 1, k, s, 0), snek(l, a + 1, k, s, 1)) if b == 1: if l[a][0] <= k: k -= l[a][0] s += l[a][1] return max(snek(l, a + 1, k, s, 0), snek(l, a + 1, k, s, 1)) els...
FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
import itertools t = int(input().strip()) for i in range(t): [n, k] = map(int, input().strip().split(" ")) l = [] for j in range(n): s = list(map(int, input().strip().split(" "))) l.append(s) l1 = [] for L in range(0, n + 1): for i in itertools.combinations(l, L): ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
def solve(C, W, K): n = len(C) max_ = 0 for i in range(1 << n): weight = 0 ans = [] k = K for j in range(n): if i & 1 << j: ans.append(W[j]) if C[j] <= k: k -= C[j] weight += W[j] max_...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN ...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
ans = [] def solve(id, remW): if remW <= 0 or id == n: return 0 marker = id, remW if marker in memo: return memo[marker] ans = solve(id + 1, remW) if remW >= pairs[id][0]: ans = max(ans, solve(id + 1, remW - pairs[id][0]) + pairs[id][1]) memo[marker] = ans return an...
ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FOR VA...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
def knapsack(W, cost, wt, n): if n < 0 or W == 0: return 0 if cost[n] > W: return knapsack(W, cost, wt, n - 1) else: inc = wt[n] + knapsack(W - cost[n], cost, wt, n - 1) exc = knapsack(W, cost, wt, n - 1) return max(inc, exc) for _ in range(int(input())): n, W =...
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR F...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
def solve(costs, weights, k, n): limit = 2**n ans = float("-inf") for i in range(1, limit): rep = "{:0" + str(n) + "b}" rep = [int(x) for x in rep.format(i)] curr_sum = sum([(x * y) for x, y in zip(weights, rep)]) curr_cost = sum([(x * y) for x, y in zip(costs, rep)]) ...
FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
for _ in range(int(input())): n, k = map(int, input().split()) app = [] for i in range(n): cost, weight = map(int, input().split()) app.append([cost, weight]) maxi = 0 def calc(curr): sm = 0 ans = 0 for i in curr: sm += app[i][0] 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
def search(n, k, c, w): if k == 0: return 0 elif n == 0: return 0 elif k < c[n - 1]: return search(n - 1, k, c, w) else: return max(search(n - 1, k, c, w), w[n - 1] + search(n - 1, k - c[n - 1], c, w)) t = int(input()) for i in range(t): n, k = map(int, input().spli...
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN V...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
from itertools import combinations for _ in range(int(input())): n, k = map(int, input().split()) a = [] b = [] c = list(range(n)) for _ in range(n): d, e = map(int, input().split()) a.append(d) b.append(e) ans = 0 for r in range(1, n + 1): x = combinations(c...
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 LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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 VA...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
def mainstuff(k, cost, weight): global a m = -1 for i in range(2 ** len(cost)): t = list(map(int, list(str(format(i, "0" + str(n) + "b"))))) t1 = sum([(a * b) for a, b in zip(cost, t)]) t2 = sum([(a * b) for a, b in zip(weight, t)]) if t1 <= k: if t2 > m: ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VA...
Read problems statements in Russian also. Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weigh...
from itertools import combinations try: t = int(input()) for _ in range(t): n, k = map(int, input().split()) weight = [] cost = [] ind = [] res = 0 for i in range(n): c, w = map(int, input().split()) weight.append(w) cost.appen...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER 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 EXP...
[Image] -----Input----- The input contains a single integer $a$ ($0 \le a \le 15$). -----Output----- Output a single integer. -----Example----- Input 3 Output 13
n = int(input()) d = [] for i in range(4): d.append(n % 2) n //= 2 x = 1 for i in range(3, -1, -1): d[i] ^= x x &= d[i] r = 0 for v in d[::-1]: r = 2 * r + v print(r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
[Image] -----Input----- The input contains a single integer $a$ ($0 \le a \le 15$). -----Output----- Output a single integer. -----Example----- Input 3 Output 13
n = int(input()) bits = bin(n + 16)[3:] bits = [int(x) for x in bits] bits[0] ^= 1 if bits[0]: bits[1] ^= 1 if bits[0] and bits[1]: bits[2] ^= 1 if bits[0] and bits[1] and bits[2]: bits[3] ^= 1 print(int("".join(str(x) for x in bits), 2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRI...
[Image] -----Input----- The input contains a single integer $a$ ($0 \le a \le 15$). -----Output----- Output a single integer. -----Example----- Input 3 Output 13
N = int(input()) if N: S = bin(N)[2:] S = "0" * (4 - len(S)) + S Z = 0 for I in range(4): if S[I] == "1": Z += 2**I S = bin(Z - 1)[2:] S = "0" * (4 - len(S)) + S Z = 0 for I in range(4): if S[I] == "1": Z += 2**I print(Z) else: print(15)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING B...
[Image] -----Input----- The input contains a single integer $a$ ($0 \le a \le 15$). -----Output----- Output a single integer. -----Example----- Input 3 Output 13
a = int(input()) if a == 0 or a == 6 or a == 9 or a == 15: c = a if a == 2 or a == 5 or a == 7: c = a * 2 if a == 4 or a == 10 or a == 14: c = a // 2 if a == 1: c = 8 if a == 8: c = 1 if a == 3: c = 12 if a == 12: c = 3 if a == 11: c = 13 if a == 13: c = 11 if a != 0: e = c - 1 e...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR ...
[Image] -----Input----- The input contains a single integer $a$ ($0 \le a \le 15$). -----Output----- Output a single integer. -----Example----- Input 3 Output 13
n = int(input("")) a = [0, 0, 0, 0] a[0] = n % 2 n = n // 2 a[1] = n % 2 n = n // 2 a[2] = n % 2 n = n // 2 a[3] = n % 2 def intnot(x): return 0 if x == 1 else 1 a[3] = intnot(a[3]) if a[3] == 1: a[2] = intnot(a[2]) if a[3] + a[2] == 2: a[1] = intnot(a[1]) if a[3] + a[2] + a[1] == 3: a[0] = intnot(a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER...
[Image] -----Input----- The input contains a single integer $a$ ($0 \le a \le 15$). -----Output----- Output a single integer. -----Example----- Input 3 Output 13
def run(): a = eval(input()) def get_bin(num): result = "" for i in [8, 4, 2, 1]: if num >= i: result = result + "1" num -= i else: result = result + "0" return result def get_dec(s): result = 0 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING FOR VAR LIST NUMBER NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP NUMBER BIN_OP NUMBER...