description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
from sys import stdin input = stdin.readline for ti in range(int(input().strip())): n, l, r = [int(x) for x in input().strip().split()] cs, tc, cc = 1, 0, n - 1 ans = [] while tc + 2 * cc < l and cs <= n: tc += 2 * cc cs += 1 cc -= 1 while tc <= r and cs <= n: for cc...
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER WHILE VAR VA...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
def solve(): n, l, r = map(int, input().split()) def where(x): if x == n * (n - 1) + 1: return 1 else: l = 0 r = n + 1 while r - l > 1: m = (l + r) // 2 if (2 * n - 1 - m) * m < x: l = m ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR A...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
def find(a): global k, tot if a > n * (n - 1): return 1 while a > tot + (n - k) * 2: tot += (n - k) * 2 k += 1 if a & 1: return k return (a - tot) // 2 + k for _ in range(int(input())): n, l, r = map(int, input().split()) global k, tot k = 1 tot = 0 ...
FUNC_DEF IF VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN NUMBER WHILE VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER RETURN VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR F...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
for f in range(int(input())): n, l, r = map(int, input().split()) s = [0] * (r - l + 1) i = 1 p = 1 t = 2 * n - ((2 * n) ** 2 - 4 * l) ** 0.5 t = t / 2 t = int(t) t -= 1 if t > 0: p = 2 * (t * n - t * (t + 1) // 2) p += 1 i += t while p + 2 * (n - i) <= l ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN ...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
import sys def binsearch(i, n): last = n * (n - 1) ip = n * (n - 1) - i jprev = 0 j = n - 1 while True: step = max(1, abs(jprev - j) // 2) jprev = j if j * (j - 1) < ip: j += step elif j > 1 and (j - 1) * (j - 2) >= ip: j -= step else...
IMPORT FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER BIN_O...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
for _ in range(int(input())): n, l, r = map(int, input().split()) z = 0 idx = 0 sd = (n - 1) * 2 lst = n * (n - 1) + 1 while z < l: if sd <= 0: z += 1 break idx += 1 z += sd sd -= 2 m = idx - 1 c = (n - 1) * 2 sm = 0 for t i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN ...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
def f(n, k): return n * k - k + n * k - k * k def af(n, p): if p == n * (n - 1): return 1 l = 0 r = n + 1 while r - l > 1: m = (l + r) // 2 if f(n, m) <= p: l = m else: r = m if (p - f(n, l)) % 2 == 0: return r return (p - f(n...
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF IF VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR I...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
import sys input = sys.stdin.buffer.readline for t in range(int(input())): n, l, r = map(int, input().split()) for i in range(l, min(2 * (n - 2) + 1, r) + 1): print("1" if i & 1 else i // 2 + 1, end=" ") n_set = n set_idx = 2 * (n - 2) + 2 while n_set > 2: ls = l - set_idx + 1 ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING BIN_OP BIN_OP VAR NUMBER NUMBER STRING ...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
for _ in range(int(input())): n, l, r = map(int, input().split()) x = 0 off = 0 for i in range(1, n + 1): if x + 2 * (n - i) >= l: off = l - x - 1 break x += 2 * (n - i) series = [] while len(series) < r - l + 1 + off: for j in range(i + 1, n + 1):...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
t = int(input()) for ii in range(t): n, l, r = map(int, input().split()) s = [] count = 1 ans = count * (2 * (n - 1) + 1 - count) while n - count > 0 and ans < l: count += 1 ans = count * (2 * (n - 1) + 1 - count) count -= 1 remain = l - count * (2 * (n - 1) + 1 - count) - 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_O...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
CASES = int(input()) answers = [] while CASES: CASES -= 1 num, begin, end = [int(x) for x in input().split(" ")] sequence = [] index = 1 tempB = begin tempE = end temp = 2 * (num - index) while tempB > temp and index < num: tempB -= temp tempE -= temp index += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP N...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
def main(): t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) if l == n * n - n + 1: print(1) continue if r == n * n - n + 1: r_g = n for i in range(n - 1): if l > 2 * n - 2 - 2 * i: l -= 2 * n ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
import sys input = sys.stdin.buffer.readline def prog(): for _ in range(int(input())): n, l, r = map(int, input().split()) l -= 1 r -= 1 a = 1 new = 2 * (n - a) while new < l: l -= new r -= new a += 1 new = 2 * (n - a...
IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) num = r - l + 1 init_num = 1 index = 0 for i in range(1, n): init_num = i if l <= (n - i) * 2: index = l l = 0 break else: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR V...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
import sys input = sys.stdin.readline def li(): return [int(i) for i in input().rstrip("\n").split()] def val(): return int(input().rstrip("\n")) for _ in range(val()): n, l, r = li() orig = r l -= 1 r -= l currleft = 0 curs = n - 1 while curs and currleft + 2 * curs <= l: ...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VA...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
n_tests = int(input()) for _ in range(n_tests): n_vertices, l, r = list(map(int, input().split())) index = 0 i_v = None for i_v in range(1, n_vertices): n_indexes_here = (n_vertices - i_v) * 2 if l <= index + n_indexes_here: break else: index += (n_vertice...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
cases = int(input()) def ecycle(n, l, r): l -= 1 cnt = r - l p = n - 1 start = 1 while l >= 2 * p and p > 0: l -= 2 * p p -= 1 start += 1 if start == n: start = 1 flag = (l + 1) % 2 nextn = start + 1 + l // 2 while cnt > 0: cnt -= 1 i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMB...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
import sys input = sys.stdin.readline for t in range(int(input())): n, l, r = map(int, input().split(" ")) startSection = 2 * (n - 1) startCount = 1 while l > startSection: startCount = startCount + 1 if startCount < n: startSection = startSection + 2 * (n - startCount) ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) l -= 1 r -= 1 start_i = 1 pos = 0 while start_i < n: cur_i_len = 2 * (n - start_i) if pos + cur_i_len > l: break pos += cur_i_len start_i += 1 wanted_len = r - l + 1 s = []...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER A...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
def ss(a, d, n): return n * (2 * a + (n - 1) * d) // 2 T = int(input()) for loop in range(T): n, l, r = map(int, input().split()) ans = [] lb = 0 rb = n - 1 while rb - lb != 1: m = (lb + rb) // 2 if ss(2 * n - 2, -2, m) >= l: rb = m else: lb = m ...
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN V...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
for t in range(int(input())): n, l, r = map(int, input().split()) b = 1 for i in range(1, n): a = b b += 2 * (n - i) if l < b: break x, y = i, (l - a) // 2 + i + 1 b = (l - a) % 2 for _ in range(r - l): if b: print(y, end=" ") y...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP V...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
t = int(input()) for y in range(t): n, l, r = list(map(int, input().split())) if l == n * (n - 1) + 1: print(1) continue ind = 1 ct = 1 while 1: if l < ct: break ct += (n - ind) * 2 ind += 1 ind -= 1 if (ct - l) % 2 == 0: st = ind ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) cycle_size = 2 * (n - 1) cycle_start = 1 cycle_number = 1 while cycle_start + cycle_size <= l and cycle_number != n: cycle_start += cycle_size cycle_number += 1 cycle_size -= 2 ans = [] while l <=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF BIN_OP BIN_OP VAR V...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
for _ in range(int(input())): n, l, r = map(int, input().split()) cursum = 0 curn = n - 1 while curn > 0 and cursum + (curn << 1) < l: cursum += curn << 1 curn -= 1 fix = n - curn d = False i = fix nexti = fix + 1 for _ in range(cursum + 1, l): if d: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VA...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
def slv(n, l, r): l -= 1 r -= 1 c = 0 ans = [] for i in range(1, n): nl, nr = c, c + 2 * (n - i) - 1 c = nr + 1 if l > nr: continue for j in range(max(l, nl), min(r, nr) + 1): if j % 2 == 0: ans.append(i) else: ...
FUNC_DEF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER E...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) L = [0] tt = 2 * (n - 1) for i in range(n): L.append(tt) tt -= 2 L[-1] = 1 temp = 0 ct = r - l + 1 c = 0 tot = 0 for i in range(1, len(L)): if tot + L[i] < l: tot += L[i] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP ...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
from sys import stdin input = stdin.readline q = int(input()) for _ in range(q): n, l, r = map(int, input().split()) tab = [-1, 1] cyk = 0 for i in range(n): cyk += 2 * (n - i - 1) tab.append(cyk + 1) tab.append(1012809128301279797787789798789798798) i = 0 start = i whil...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NU...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
import sys d = [] def bins(k, n): l = 0 r = n - 2 while l != r: mid = (l + r + 1) // 2 if d[mid] <= k: l = mid else: r = mid - 1 ex = k - d[l] if ex & 1: f = ex // 2 return f + l + 2 else: return l + 1 for q in range(in...
IMPORT ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBE...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
import sys input = sys.stdin.readline (t,) = map(int, input().split()) def gen(k): return [(k + (i + 1) // 2 if i % 2 else k) for i in range(2 * (n - k))] for _ in range(t): n, s, e = map(int, input().split()) k, sm = 0, 0 while sm < s and k < n - 1: k += 1 sm += 2 * (n - k) if ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER W...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
t = int(input()) for case_num in range(t): n, l, r = map(int, input().split(" ")) if l == n * (n - 1) + 1: print(1) continue total = 0 unvisited = n - 1 while total < l: total += unvisited * 2 unvisited -= 1 unvisited += 1 total -= unvisited * 2 current = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR BI...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
t = int(input()) for i in range(t): n, l, r = map(int, input().split()) if l == n * (n - 1) + 1: print(1) else: x = 1 summa = x * 2 * n rasn = x * (x + 1) while summa - rasn < l: summa += 2 * n rasn = rasn // x * (x + 2) x += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
import sys from itertools import accumulate def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
test = int(input()) for _ in range(test): n, l, r = [int(x) for x in input().split()] start = 1 it = 1 if l == n * (n - 1) + 1: print("1") continue while start < l: start += (n - it) * 2 it += 1 if start != l: it -= 1 start -= (n - it) * 2 a = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING WHILE VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBE...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
R = lambda: map(int, input().split()) t = int(input()) def block(b, pos, n): if pos % 2 == 0: return b return b + (pos + 1) // 2 def binary(k, n): left, right = 1, n + 1 while left <= right: m = (left + right) // 2 if m * (m + 1) >= k > m * (m - 1): return m ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NU...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
import sys def data(): return sys.stdin.buffer.readline().strip() out = sys.stdout.write def mdata(): return map(int, data().split()) for t in range(int(data())): n, l, r = mdata() a = l for i in range(1, n + 1): if 2 * (n - i) <= a: a -= 2 * (n - i) else: ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP NUMBER BIN_OP VAR VAR VAR VAR BIN_OP NUMBER B...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
for nt in range(int(input())): w, a, b = map(int, input().split()) if w == 2: l = [1, 2, 1] print(*l[a - 1 : b]) continue k = w prev = 0 for j in range(a, b + 1): i = j - prev while k > 1: if i <= 2 * (k - 1): if i % 2: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR ...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
def calc(N, index): if index == 1 or index == N * (N - 1) + 1: return 1 else: wave_l = 1 wave_r = N while wave_r - wave_l > 1: M = (wave_l + wave_r) // 2 if (2 * N - M) * (M - 1) < index: wave_l = M else: wave_r ...
FUNC_DEF IF VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP ...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
T = int(input()) for _ in range(T): n, left, right = map(int, input().split()) l = [0] * n l[1] = 2 * n - 2 for i in range(2, n): l[i] = l[i - 1] - 2 l[-1] += 1 left_n = -1 right_n = -1 acc = 0 for i in range(1, n): if acc + 1 <= left: left_n = i a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN V...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
from sys import stdin def allWays(start, verts, done, stack, n): global valid if not valid: return stack.append(start) if len(done) == len(verts): print(stack) stack.pop() valid = False return for x in range(1, n + 1): if start != x and not (start, x...
FUNC_DEF IF VAR RETURN EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR ...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
for _ in range(int(input())): n, l, r = map(int, input().split()) s = 0 ans = [] for i in range(1, n): gap2 = i t = i if s + (n - i) * 2 >= l: for j in range(l, r + 1): gg = (j - s) // 2 if j % 2 == 1: ans.append(gap...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
import sys def calcStartIndex(vertex, n): i = vertex return 1 + 2 * (i - 1) * n - i * i + i def main(): t = int(input()) allans = [] for _ in range(t): n, l, r = readIntArr() startVertex = 1 b = n while b > 0: while startVertex + b <= n and calcStartIn...
IMPORT FUNC_DEF ASSIGN VAR VAR RETURN BIN_OP BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER WHILE BIN_OP VAR VA...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
from sys import gettrace, stdin def input(): return stdin.buffer.readline() t = int(input()) for _ in range(t): n, l, r = list(map(int, input().split())) count = 0 i = 1 while count < l: if i == n: i = 1 count += (n - i) * 2 i += 1 i -= 1 count -= (n -...
FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_O...
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such c...
t = int(input()) for i in range(t): n, l, r = map(int, input().split()) if l == n * (n - 1) + 1: print(1) continue left, right, summ = 0, n, 0 while left != right - 1: mid = (left + right) // 2 tmp = n * mid - mid * (mid + 1) // 2 if 2 * tmp < l: left ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BI...
Chef loves problems about digits and he came up with an interesting one. Chef has given you two integers N and K. You should find the minimum non-negative integer X, such that N + X has at most K distinct digits in its decimal representation. For example, 1231 has three distinct digits and 100 has two distinct digits...
from sys import stdin, stdout input = stdin.readline r_int = lambda: int(input()) m_int = lambda: map(int, input().split()) l_int = lambda: list(map(int, input().split())) def solve(): n_int, k = m_int() n = list(map(int, str(n_int))) if len(set(n)) <= k: print(0) return for i, d in e...
ASSIGN VAR VAR 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 VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUN...
Chef loves problems about digits and he came up with an interesting one. Chef has given you two integers N and K. You should find the minimum non-negative integer X, such that N + X has at most K distinct digits in its decimal representation. For example, 1231 has three distinct digits and 100 has two distinct digits...
for _ in range(int(input())): s, k = input().split() n, k = int(s), int(k) mark = [0] * 10 ans = "9" * len(s) for i in range(len(s)): d = ord(s[i]) - ord("0") d1, d2 = d + 1, 0 if sum(mark) < k: if sum(mark) == k - 1 and d1 < 10 and mark[d1] == 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING...
Chef loves problems about digits and he came up with an interesting one. Chef has given you two integers N and K. You should find the minimum non-negative integer X, such that N + X has at most K distinct digits in its decimal representation. For example, 1231 has three distinct digits and 100 has two distinct digits...
for _ in range(int(input())): n, k = [int(x) for x in input().split()] n_str = str(n) n_len = len(n_str) pfx_set = set() min_pfx_set = ":" min_big = "1" * (n_len + 1) ok_already = True for i in range(n_len): c = n_str[i] if len(pfx_set) == k: cc = ":" ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF...
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of...
from sys import stdin input = stdin.buffer.readline n = int(input()) board = [list(map(int, input().split())) for i in range(n)] d1 = [0] * (2 * n - 1) d2 = [0] * (2 * n - 1) for r in range(n): for c in range(n): d1[n - 1 + r - c] += board[r][c] d2[r + c] += board[r][c] best = [-1] * 2 bestv = [Non...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR V...
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of...
import sys input = sys.stdin.buffer.readline t = 1 for __ in range(t): a = [] n = int(input()) for i in range(n): b = list(map(int, input().split())) a.append(b) dr = {} di = {} for i in range(n): for j in range(n): dr[i + j] = dr.get(i + j, 0) + a[i][j] ...
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL 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 FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR...
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of...
from sys import stdin input = stdin.buffer.readline n = int(input()) l = [[*map(int, input().split())] for _ in range(n)] d = {} su = {} s = 0 an = [1, 1, 2, 1] for i in range(n): for j in range(n): d[i - j] = d.get(i - j, 0) + l[i][j] su[i + j] = su.get(i + j, 0) + l[i][j] position = [2, 1, 1, 1] ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CA...
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of...
from sys import stdin input = stdin.buffer.readline I = lambda: list(map(int, input().split())) n = int(input()) ans = [] for _ in range(n): arr = I() ans.append(arr) topLeft, bottomLeft = {}, {} for i in range(n): for j in range(n): topLeft[i - j] = topLeft.get(i - j, 0) + ans[i][j] bottom...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP...
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of...
from sys import stdin input = stdin.buffer.readline I = lambda: list(map(int, input().split())) mat = [] for _ in range(int(input())): mat.append(I()) n = len(mat) def sumDiag(mat): diag_sum = [] diag_sum2 = [] n = len(mat) for i in range(n): s = 0 for j in range(0, n - i): ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUM...
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of...
from sys import stdin input = stdin.buffer.readline I = lambda: list(map(int, input().split())) (n,) = I() l = [] for i in range(n): l.append(I()) d = {} su = {} s = 0 an = [1, 1, 2, 1] for i in range(n): for j in range(n): d[i - j] = d.get(i - j, 0) + l[i][j] su[i + j] = su.get(i + j, 0) + l[i...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL ...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
from sys import stdin def printVal(x): if x <= 9: return x elif x <= 35: return chr(x - 10 + ord("A")) else: return chr(x - 36 + ord("a")) for t in range(int(input())): r, c, k = map(int, input().split()) s = [0] * r for i in range(r): s[i] = stdin.readline() ...
FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR STRING RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMB...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
chk = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" for _ in range(int(input())): r, c, k = map(int, input().split()) grid = [] ans = [([""] * c) for i in range(r)] ric = 0 for i in range(r): a = input() grid.append(a) ric += a.count("R") s = ric // k ...
ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING AS...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
import sys def distribute(n, person): q, m = divmod(n, person) if m == 0: return [q] * person else: return [q] * (person - m) + [q + 1] * m input = sys.stdin.readline T = int(input()) CHAR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" for _ in range(T): R, C, K =...
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN BIN_OP LIST VAR VAR RETURN BIN_OP BIN_OP LIST VAR BIN_OP VAR VAR BIN_OP LIST BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FU...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
mp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" imp = 0 t = int(input()) while t > 0: imp = 0 z = input().split() r = int(z[0]) c = int(z[1]) k = int(z[2]) i = 0 j = 0 inp = [] rice = 0 while i < r: a = input() for j in a: if j ==...
ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMB...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
C = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" T = int(input()) for t in range(T): r, c, k = map(int, input().split()) A = [] for i in range(r): A.append(list(input())) tot = 0 for i in range(r): tot += A[i].count("R") target = [(tot // k + 1 if i < tot % k ...
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
t = int(input()) for _ in range(t): r, c, k = map(int, input().split()) arr = [[(0) for j in range(c)] for i in range(r)] chararr = [[(0) for j in range(c)] for i in range(r)] R = 0 for i in range(r): string = input() for j in range(c): arr[i][j] = string[j] i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR F...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
import sys input = sys.stdin.readline C = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" T = int(input()) for testcases in range(T): r, c, k = map(int, input().split()) MAP = [input().strip() for i in range(r)] ANS = [([None] * c) for i in range(r)] RICE = 0 for ma in MAP: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
def sym(a): if a <= 10: return str(a - 1) elif a >= 11 and a <= 36: return chr(54 + a) else: return chr(60 + a) t = int(input()) for i in range(t): n, m, k = map(int, input().split()) symbol = "0" num = 1 d = [] t = [["" for j in range(m)] for o in range(n)] ...
FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR BIN_OP NUMBER VAR RETURN FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR ...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
t = int(input()) for _ in range(t): r, c, k = map(int, input().split()) farm = [] rice = 0 chk = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" for i in range(r): f = input() rice += f.count("R") farm.append(f) n = rice // k rest = rice % k start...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
import sys def count_rice(grid): count = 0 r, c = len(grid), len(grid[0]) for i in range(r): for j in range(c): if grid[i][j] == "R": count += 1 return count t = int(sys.stdin.readline()) l = [] start = 65 for i in range(26): l.append(chr(start + i)) start = 9...
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL V...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
import sys input = sys.stdin.readline t = int(input()) string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" for _ in range(t): r, c, k = map(int, input().split()) info = [list(input()) for i in range(r)] ans = [([None] * c) for i in range(r)] cnt_r = 0 for i in range(r): ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 BIN_OP LIST NONE VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
chars = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", ...
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STR...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
from sys import stdin input = stdin.readline can = [] for i in range(26): can.append(chr(ord("a") + i)) can.append(chr(ord("A") + i)) for i in range(10): can.append(i) t = int(input()) for _ in range(t): mp = [] r, c, k = map(int, input().split()) ans = [(["0"] * c) for _ in range(r)] tot =...
ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LI...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
import sys input = sys.stdin.readline Q = int(input()) Query = [] for _ in range(Q): R, C, K = map(int, input().split()) state = [list(input().rstrip()) for _ in range(R)] Query.append((R, C, K, state)) Alp = ( [chr(i) for i in range(97, 97 + 26)] + [chr(i) for i in range(65, 65 + 26)] + [str(i...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUN...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
def codechickens(m, n, c, r): k = 0 for i in range(r): for j in range(c): if m[i][j] == "R": k += 1 v1 = k // n v2 = k % n s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" numchick = 0 numriceforchick = 0 for i in range(r): ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
dic = [] for i in range(26): dic.append(chr(ord("a") + i)) for i in range(26): dic.append(chr(ord("A") + i)) for i in range(10): dic.append(str(i)) t = int(input()) while t: li = [] l = [] r, c, k = map(int, input().split()) cr = 0 for i in range(r): li = list(input().strip()) ...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR A...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
import sys input = sys.stdin.readline initChickens = [chr(i) for i in range(ord("a"), ord("a") + 26)] initChickens.extend([chr(i) for i in range(ord("A"), ord("A") + 26)]) initChickens.extend([str(i) for i in range(10)]) t = int(input()) for _ in range(t): chickens = initChickens.copy() r, c, k = map(int, inpu...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL V...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
q = int(input()) for rw in range(q): r, c, k = list(map(int, input().split())) mat = [list(input()) for i in range(r)] dupa = "qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0123456789" rice = 0 for i in range(r): for j in range(c): if mat[i][j] == "R": rice ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL 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 STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBE...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
char_list = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") def pr(ans): S = "" for R in ans: S += "".join(R) + "\n" print(S[:-1]) T = int(input()) for _ in range(T): r, c, k = map(int, input().split()) cnt = 0 arr = [] for _ in range(r): s = input(...
ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL STRING VAR STRING EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VA...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
import sys input = sys.stdin.readline I = lambda: list(map(int, input().split())) (t,) = I() bl = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING S...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
def next(i, j, r, c): if i & 1: if j == 0: i += 1 else: j -= 1 elif j == c - 1: i += 1 else: j += 1 return i, j def printMatrix(matrix): s = [[str(e) for e in row] for row in matrix] lens = [max(map(len, col)) for col in zip(*s)] fmt ...
FUNC_DEF IF BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL STRING VAR VAR VAR ASSIGN VAR F...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
ls = [] for i in range(48, 58): ls.append(chr(i)) for i in range(65, 91): ls.append(chr(i)) for i in range(97, 123): ls.append(chr(i)) T = int(input()) while T: r, c, k = map(int, input().split()) a = [[(0) for j in range(c)] for i in range(r)] count = 0 for i in range(r): b = input(...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in ran...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
t = int(input()) alp = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM" for _ in range(t): count = 0 R, C, k = list(map(int, input().split())) arr = [] for i in range(R): arr.append(input()) final = [["0" for _ in range(C)] for _ in range(R)] total = 0 for i in range(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR 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 ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN ...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
import sys input = lambda: sys.stdin.readline().rstrip() I = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" T = int(input()) for _ in range(T): R, C, K = map(int, input().split()) X = [[(1 if a == "R" else 0) for a in input()] for _ in range(R)] s = sum([sum(x) for x in X]) a = s // K...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING NUMBER NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN ...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
import sys chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" for _ in range(int(input())): r, c, k = map(int, input().split()) total = 0 s = [] for l in (sys.stdin.readline() for _ in range(r)): s.append(l.rstrip()) total += l.count("R") ans = [(["*"] * c) for...
IMPORT ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL ...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
t = int(input()) ans = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] i = 65 while i < 91: ans.append(chr(i)) i += 1 i = 97 while i < 123: ans.append(chr(i)) i += 1 for z in range(t): r, c, k = map(int, input().split()) ri = 0 arr = [input() for x in range(r)] i = 0 while i < r: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASS...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
from sys import stdin, stdout T = int(stdin.readline().strip()) def fill(x, y, k, dr, let): while True: if dr == 1: for i in range(y, m): if mt[x][i] == "R": if k == 0: return [x, i, dr] k -= 1 ans...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF WHILE NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING IF VAR NUMBER RETURN LIST VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR STRING IF VAR NUMBER RETURN LIST VAR VAR VAR VAR NUMBER ...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
t = int(input()) mas = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" for asd in range(t): r, c, k = map(int, input().split()) matr = [] suma = 0 for i in range(r): s = input() matr.append([]) for j in range(c): if s[j] == ".": matr[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
t = int(input()) for ti in range(t): r, c, k = list(map(int, input().split())) rc = 0 field = [] for i in range(r): s = input() field.append(s) for j in range(c): if s[j] == "R": rc += 1 res = [[(0) for x in range(c)] for y in range(r)] sr = [c...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
import sys def zip_sorted(a, b): a, b = zip(*sorted(zip(a, b))) sorted(zip(a, b), key=lambda x: x[1]) return a, b input = sys.stdin.readline I = lambda: list(map(int, input().split())) S = lambda: list(map(str, input())) w = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") (t,) = I...
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING A...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
for _ in range(int(input())): row, col, k = map(int, input().split()) arr = [] for i in range(row): s = input() if i % 2 == 0: temp = [x for x in s] else: temp = [x for x in s[::-1]] arr.extend(temp) ric = arr.count("R") ans = [] c = 65 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
arid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" for _ in range(int(input())): r, c, k = map(int, input().split()) ar = [] count = 0 for i in range(r): ar.append(input()) for j in ar[-1]: if j == "R": count += 1 each = count // k ...
ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR AS...
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chicken...
import sys def main(): global chickens print = out.append r, c, k = get_list() mat = [list(input()) for _ in range(r)] res = [["a" for _ in range(c)] for _ in range(r)] def next(i, j): if i % 2 == 0 and j + 1 < c: return i, j + 1 elif i % 2 != 0 and j > 0: ...
IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR RETURN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN...
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
N = int(1000000.0) + 20 n = int(input()) m = [0] * N k = 1000000.0 + 1 for x in map(int, input().split()): m[x] += 1 k = min(k, x) result = 0 while k < N - 1: v = m[k] m[k + 1] += v >> 1 result += v & 1 k += 1 print(result + m[-1])
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BI...
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
n = int(input()) l = [0] * (10**6 + 100) for i in map(int, input().split()): l[i] += 1 cur = ans = 0 for i in l: cur += i if cur % 2: ans += 1 cur //= 2 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
n = int(input()) a = [(0) for i in range(10**6 + 1)] for x in input().split(): a[int(x)] += 1 c = 0 prev = 0 for el in a: prev += el if prev % 2 == 1: c += 1 prev //= 2 while prev > 0: c += prev % 2 prev //= 2 print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR ...
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
def main(): n = int(input()) w = list(map(int, input().split())) bits = [0] * (10**6 + 100) for e in w: bits[e] += 1 cur, res = 0, 0 for e in bits: cur += e if cur % 2: res += 1 cur //= 2 print(res) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VA...
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
n = int(input()) weights = list(map(int, input().split())) counter = [0] * (10**6 + 21) for weight in weights: counter[weight] += 1 ans = 0 for i in range(10**6 + 21): weight, count = i, counter[i] if count > 0 and count // 2 > 0: counter[weight + 1] += count // 2 count -= count // 2 * 2 ...
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 FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER BIN_OP...
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
n = int(input()) l = list(map(int, input().split())) bit = [0] * (10**6 + 101) for i in l: bit[i] = bit[i] + 1 ans = 0 s = 0 for i in bit: s = s + i ans = ans + s % 2 s = s // 2 print(ans)
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 FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_...
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
n = int(input()) lis = sorted(map(int, input().split())) ans = c = 0 c = 1 for i in range(1, n): if lis[i] == lis[i - 1]: c += 1 else: while lis[i] != lis[i - 1] and c > 0: if c % 2: ans += 1 c = c // 2 lis[i - 1] += 1 c += 1 while c > ...
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP ...
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
def main(): input() l = [0] * 1000001 for w in map(int, input().split()): l[w] += 1 t = rest = 0 for x in l: t += x if t & 1: rest += 1 t >>= 1 print(bin(t).count("1") + rest) main()
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING VAR EXPR FUNC_CALL VAR
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
def inc(a, w): n = len(a) i = w while i < n and a[i] == 1: a[i] = 0 i += 1 if i < n: a[i] = 1 else: a.append(1) n = int(input()) x = input().split(" ") w = [int(y) for y in x] a = [0] * 1000024 for t in w: inc(a, t) print(sum(a))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBE...
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are n stations in the subway. It was built according to the Bertown Transport Law: For each station i there exists exactly one train that goes from this station. Its ...
n = int(input()) p = list(map(int, input().split())) ls = [] visited = [(False) for _ in range(n)] cnt = 0 for i in range(n): j = i cnt = 0 while not visited[j]: visited[j] = True cnt += 1 j = p[j] - 1 if 0 < cnt: ls.append(cnt) ls.sort() if 1 < len(ls): ls[-2] += ls[...
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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER I...
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are n stations in the subway. It was built according to the Bertown Transport Law: For each station i there exists exactly one train that goes from this station. Its ...
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = s...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ...
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are n stations in the subway. It was built according to the Bertown Transport Law: For each station i there exists exactly one train that goes from this station. Its ...
import sys n = int(input()) dest = [0] + list(map(int, input().split())) edge = [1] * (n + 1) for i, x in enumerate(dest): if i != x: edge[x] = 0 visit_time = [0] * (n + 1) def solve(i): t = visit_time[i] = 1 while 1: t += 1 i = dest[i] if visit_time[i]: return...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR N...
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are n stations in the subway. It was built according to the Bertown Transport Law: For each station i there exists exactly one train that goes from this station. Its ...
n = int(input()) a = list(map(int, input().split())) if n == 1: print("1"), exit() if n == 2: print("4"), exit() b = [i for i in range(0, n + 1)] r = [(1) for i in range(0, n + 1)] def find(x): if b[x] == x: return x else: b[x] = find(b[x]) return b[x] for i in range(1, n + 1...
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 STRING FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_O...
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are n stations in the subway. It was built according to the Bertown Transport Law: For each station i there exists exactly one train that goes from this station. Its ...
def dfs(v): cnt = 0 while not vis[v]: vis[v] = True cnt += 1 v = town[v] return cnt n = int(input()) town = list(map(int, input().split())) for i in range(n): town[i] -= 1 cur = [(0) for _ in range(n)] vis = [(False) for _ in range(n)] answer = [0] for i in range(n): answer...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CA...