description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
t = int(input()) while t > 0: n, p = map(int, input().split()) temp = 2 * n + p l = 1 r = l + 1 while temp > 0: if r == n + 1: l += 1 r = l + 1 print(l, r) r += 1 temp -= 1 t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
import sys input = sys.stdin.readline read_tuple = lambda _type: map(_type, input().split(" ")) def solve(): t = int(input()) for _ in range(t): n, p = read_tuple(int) n_vertices = 2 * n + p for i in range(1, n + 1): for j in range(i + 1, n + 1): if not n_v...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
t = int(input()) for tt in range(t): n, p = map(int, input().split()) now = 1 ans = 0 while ans != 2 * n + p: for i in range(now + 1, n + 1): if ans == 2 * n + p: break print(now, i) ans += 1 now += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VA...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
N = int(input()) for i in range(N): a = list(map(int, input().split())) c = 0 for i in range(a[0]): if c == 2 * a[0] + a[1]: break for j in range(i + 1, a[0]): if c == 2 * a[0] + a[1]: break print(i + 1, j + 1) c = c + 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMB...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
for t in range(int(input())): n, p = (int(x) for x in input().split()) g = [([0] * n) for i in range(n)] for i in range(n): g[i][(i + 1) % n] = g[(i + 1) % n][i] = 1 g[i][(i + 2) % n] = g[(i + 2) % n][i] = 1 for i in range(n): for j in range(i + 1, n): if g[i][j] == 0...
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 BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
def graph(n, p): threshold = 2 * n + p cache = {} for i in range(1, n): for j in range(0, n): node1 = j + 1 node2 = (j + i) % n + 1 if (node1, node2) not in cache: print(node1, node2) threshold -= 1 cache[node1, node...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF V...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
a = int(input()) l = [] for j in range(a): start = 1 end = 1 h = list(map(int, input().split())) n = h[0] p = h[1] for i in range(2 * n + p): if end + 1 > n: start += 1 end = start + 1 else: end += 1 print(start, end)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIG...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
t = int(input()) while t > 0: [n, p] = map(int, input().split(" ")) count = int(0) for i in range(n): j = i + 2 while j <= n: count = count + 1 print(str(i + 1) + " " + str(j)) if count == 2 * n + p: break j = j + 1 if j...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER ...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
t = int(input()) for k in range(t): n, p = map(int, input().split()) c = 0 e = 2 * n + p for i in range(1, n + 1): for j in range(i + 1, n + 1): if c < e: print(i, j) c += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR V...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
t = int(input()) def readints(): return map(int, input().split(" ")) def solve(): n, p = readints() viz = [([0] * n) for _ in range(n)] for j in range(n): viz[0][j] = viz[j][0] = 1 for j in range(n): viz[1][j] = viz[j][1] = 1 leftover = p + 3 done = False for i in ran...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR ...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
import sys t = int(sys.stdin.readline().strip()) for test_case in range(t): n, p = map(int, sys.stdin.readline().strip().split()) s = set() for i in range(0, n): j = (i + 1) % n k = (i + 2) % n s.add(tuple(sorted((i, j)))) s.add(tuple(sorted((i, k)))) for i in range(0, n...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
t = int(input()) for z in range(t): n, p = [int(x) for x in input().split()] cur = 0 for i in range(1, n): j = i + 1 while j <= n and cur < n * 2 + p: print(i, j) j += 1 cur += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
import sys def compute(n, p): count = 0 for i in range(1, n + 1, 1): for j in range(i + 1, n + 1, 1): print("{0} {1}".format(i, j)) count += 1 if count >= 2 * n + p: return t = int(input()) for case in range(t): n, p = list(map(int, input().spl...
IMPORT FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSI...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
def solve(n, p): cnt = 2 * n + p for i in range(1, n + 1): for j in range(i + 1, n + 1): print(i, j) cnt -= 1 if cnt == 0: return def main(): t = int(input()) for _ in range(t): n, p = map(int, input().split()) solve(n, p) m...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
T = int(input()) while T > 0: T -= 1 n, p = map(int, input().split()) node = range(1, n + 1) e = [(a, b) for a in node for b in node if a < b] for a, b in e: if min(b - a, a + n - b) <= 2: print(a, b) elif p > 0: p -= 1 print(a, b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
t = int(input()) while t > 0: t -= 1 n, p = map(int, input().split()) num = 0 for i in range(1, n): for j in range(i + 1, n + 1): num += 1 if num <= 2 * n + p: print(i, j)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
for _ in range(int(input())): n, p = map(int, input().split()) p += 2 * n for i in range(n): for j in range(i + 1, n): if p == 0: break print(i + 1, j + 1) p -= 1
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def result(x, y, numbers): numbers.reverse() a, b = 1, 0 for number in numbers: b, a = a, number * a + b return a * y == b * x x, y = [int(item) for item in input().split()] n = int(input()) numbers = [int(item) for item in input().split()] if result(x, y, numbers): print("YES") else: ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def solve(p, q, a, st, n): if st == n - 1: return p == q * a[st] return solve(q, p - a[st] * q, a, st + 1, n) p, q = map(int, input().split()) n = int(input()) a = list(map(int, input().split())) if solve(p, q, a, 0, n): print("YES") else: print("NO")
FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
s = input().split(" ") p = int(s[0]) q = int(s[1]) s = input() n = int(s) s = input().split(" ") ok = True for i in range(n): x = int(s[i]) p = p - q * x if ok == False: continue if p == 0 and i != n - 1: ok = False elif p < 0: ok = False t = p p = q q = t if ok a...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR ...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
import sys p, q = list(map(int, input().split())) n = int(input()) num = list(map(int, input().split())) l1, l2 = [], [] i = 0 if q == 1: if num == [p] or num == [p - 1, 1]: print("YES") else: print("NO") else: while q > 0: l1.append(p // q) p, q = q, p % q if len(l1) > ...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER IF VAR NUMBER IF VAR LIST VAR VAR LIST BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXP...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
P, Q = [int(x) for x in input().split()] N = int(input()) A = [int(x) for x in input().split()] U, V = 1, 0 for x in A[::-1]: U, V = V, U U, V = V * x + U, V if U * Q == P * V: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def gcd(x, y): if y == 0: return x else: return gcd(y, x % y) p, q = [int(i) for i in input().split()] n = int(input()) a = [int(i) for i in input().split()] x, y = 1, 0 for i in a[::-1]: x, y = y + i * x, x a, b = gcd(p, q), gcd(x, y) p = p // a q = q // a x = x // b y = y // b if x == p ...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR ...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
p, q = map(int, input().split()) n = int(input()) a = list(map(int, input().split())) g = 0 for i in range(n): if p <= 0: print("NO\n") exit(0) b = q * a[i] p -= b g = p p = q q = g if q == 0: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VA...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) p, q = map(int, input().split()) n = int(input()) A = list(map(int, input().split())) g = gcd(p, q) p = p // g q = q // g k = A[n - 1] l = 1 for i in range(n - 2, -1, -1): k, l = l, k k += A[i] * l g = gcd(k, l) k = ...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VA...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
p, q = map(int, input().split()) n = int(input()) a = list(map(int, input().split())) x, y = a[n - 1], 1 for i in range(n - 1)[::-1]: x, y = a[i] * x + y, x print(["NO", "YES"][p * y == q * x])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VA...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
from sys import stdin p, q = map(int, input().split()) n = int(input()) l = list(stdin.read().split()) for i in l: if q == 0: print("NO") exit() p, q = q, p - int(i) * q print("YES" if q == 0 else "NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING STRING
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
p, q = map(int, input().split()) n, t = int(input()), list(map(int, input().split())) t.reverse() a, b = 1, t[0] for c in t[1:]: a, b = b, c * b + a print("YNEOS"[a * p != b * q :: 2])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR VAR BIN_OP ...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
l = input() p = int(l.split()[0]) q = int(l.split()[1]) n = int(input()) v = [int(x) for x in input().split()] def calc(f, n): if n <= 0: return f aux = f[1] f[1] = f[1] * v[n] + f[0] f[0] = aux return calc(f, n - 1) equal = False if n > 1: f = calc([1, v[n - 1]], n - 2) f[0] = v...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR ...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
s = input() a = s.split() p = int(a[0]) q = int(a[1]) n = input() s = input() se = s.split() for c in se: e = int(c) t1 = p - e * q t2 = q p = t2 q = t1 if q == 0: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
p, q = tuple(map(int, input().split())) n1 = input().split() n = int(n1[0]) a = list(map(int, input().split())) x = 1 y = a[n - 1] for i in range(n - 2, -1, -1): x1 = a[i] * y + x x = y y = x1 if p * x == q * y: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
p, q = list(map(int, input().split())) n = int(input()) a = list(map(int, input().split())) fract1 = [] x, y = p, q while y > 0: if y == 1: fract1 += [x - 1, 1] else: fract1 += [x // y] x, y = y, x % y fract2 = [] x, y = p, q while y > 0: fract2 += [x // y] x, y = y, x % y if fract1 ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER IF VAR NUMBER VAR LIST BIN_OP VAR NUMBER NUMBER VAR LIST BIN_OP VAR VAR ASSIGN VAR VAR ...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
p, q = map(int, input().split()) n = int(input()) A = list(map(int, input().split())) for i in range(n): p, q = q, p - A[i] * q if p != 0 and q == 0: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
num, den = [int(x) for x in input().split()] n = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] for i in range(n[0] - 1): num -= den * arr[i] num, den = den, num if den and num % den == 0: num = num // den den = 1 if num == arr[n[0] - 1] and den == 1: print("YES") else: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR V...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
from sys import stdin def read(): return map(int, stdin.readline().split()) def gcd(a, b): return a if b == 0 else gcd(b, a % b) def simp(a, b): g = gcd(a, b) return a // g, b // g def calc(a): if len(a) == 1: return a[0], 1 y, x = calc(a[1:]) return simp(a[0] * y + x, y) n...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL ...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
P, Q = map(int, input().split()) n = int(input()) a = [int(i) for i in input().split()] p = [] q = [] p.append(a[0]) q.append(1) if n == 1: if p[0] * Q == q[0] * P: print("YES") else: print("NO") else: p.append(a[1] * a[0] + 1) q.append(a[1]) for i in range(2, n): p.append(a[...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def gcd(x, y): while x > 0 and y > 0: if x > y: x %= y else: y %= x return x + y p, q = map(int, input().split()) n = int(input()) a = list(map(int, input().split())) p1 = 1 q1 = a[n - 1] for i in range(n - 2, -1, -1): p1 += a[i] * q1 z = p1 p1 = q1 q1 =...
FUNC_DEF WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VA...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
p, q = map(int, input().split()) n = int(input()) w = [int(x) for x in input().split()] if n >= 2: if p % q != 0: r = [0] * n i = 0 while i + 1 <= n: if q != 0: r[i] = int(p / q) p, q = q, p - int(p / q) * q i += 1 else:...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_O...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
import sys def gcd(a, b): return a if b == 0 else gcd(b, a % b) def main(): p, q = map(lambda x: int(x), sys.stdin.readline().split()) n = int(sys.stdin.readline()) a = list(map(lambda x: int(x), sys.stdin.readline().split())) b = [1] * n gg = gcd(p, q) p = p // gg q = q // gg wh...
IMPORT FUNC_DEF RETURN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def s(): def gcd(a, b): if a < b: a, b = b, a if b: return gcd(b, a % b) else: return a pq = list(map(int, input().split())) g = gcd(*pq) pq[0] //= g pq[1] //= g input() a = list(map(int, input().split())) r = [1, 0] for i...
FUNC_DEF FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VA...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
3 p, q = tuple(map(int, input().strip().split())) n = int(input().strip()) a = list(map(int, input().strip().split())) a.reverse() def gcd(a, b): while a: a, b = b % a, a return b g = gcd(p, q) p, q = p // g, q // g u, v = 0, 1 for i in a: v, u = v * i + u, v g = gcd(u, v) u, v = u // g,...
EXPR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF WHILE VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CA...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
p, q = map(int, input().split()) n = int(input()) a = list(map(int, input().split())) def dfs(i): if i == n - 1: return 1, a[i] x = dfs(i + 1) return x[1], a[i] * x[1] + x[0] x = dfs(0) if x[0] * p == x[1] * q: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUM...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
import sys def gcd(a, b): if b == 0: return a return gcd(b, a % b) def red(frac): gcdfrac = gcd(frac[0], frac[1]) return frac[0] // gcdfrac, frac[1] // gcdfrac def add(i, frac): a, b = frac a += b * i return red((a, b)) args = list(map(int, sys.stdin.read().split())) p, q = a...
IMPORT FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUN...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def gcd(a, b): if b > a: q = a a = b b = q if b == 0: return a else: return gcd(b, a % b) def sokrat(p, q): d = gcd(p, q) return p / d, q / d p, q = map(int, input().split()) n = int(input()) a = list(map(int, input().split())) g, h = a[n - 1], 1 for i in ...
FUNC_DEF IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
p, q = map(int, input().split()) n = int(input()) l = list(map(int, input().split())) for i in l: if q == 0 or i > p // q: print("NO") exit() p -= i * q p, q = q, p print("YES" if q == 0 else "NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NU...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def main(): var_input = input() my_list = list(var_input.split(" ")) p = int(my_list[0]) q = int(my_list[1]) n = int(input()) var_input = input() a = list(var_input.split(" ")) for index in range(len(a)): p -= q * int(a[index]) if index != len(a) - 1 and p == 0: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR FUN...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
x = input("").split(" ") a = int(x[0]) b = int(x[1]) c = int(input("")) bad = input("").split(" ") bad = [int(x) for x in bad] num = 0 denom = 0 if c == 1: if bad[0] * b == a: print("YES") else: print("NO") elif c == 2: e = bad[0] f = bad[1] if a * f == b * (e * f + 1): print...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUM...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
p, q = input().split() p = int(p) q = int(q) n = int(input()) A = input().split() a = 1 b = int(A[n - 1]) i = n - 2 while i >= 0: aux = b b = a + b * int(A[i]) a = aux i = i - 1 print("YES" if p * a == q * b else "NO")
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR B...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
arr = [(0) for i in range(100)] def gcd(a, b): if b == 0: return a return gcd(b, a % b) def compute(a, b, c): ret = [a * c[0] + b * c[1], c[0]] return tuple(ret) def dfs(idx): if idx == n - 2: return compute(arr[idx], 1, tuple([arr[idx + 1], 1])) return compute(arr[idx], 1,...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR LIST BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR LIST VA...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def gcd(a, b): if b == 0: return a return gcd(b, a % b) p, q = list(map(int, input().split())) N = int(input()) A = list(map(int, input().split())) znam = 1 chisl = A[N - 1] for i in range(N - 1, 0, -1): chisl, znam = znam, chisl chisl += znam * A[i - 1] if p * znam == q * chisl: print("YE...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL ...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def gcd(a, b): while b != 0: a, b = b, a % b return a def solve(p, q, a): if len(a) == 1: return q * a[0] == p pp = q qq = p - q * a[0] aa = a[1:] g = gcd(pp, qq) pp //= g qq //= g return solve(pp, qq, aa) p, q = map(int, input().split()) n = int(input()) a = ...
FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR F...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def ratios(p, q, n, lst): for i in range(n): if p <= 0: return "NO" b = q * lst[i] p -= b g = p p = q q = g if q == 0: return "YES" return "NO" P, Q = [int(j) for j in input().split()] m = int(input()) a = [int(x) for x in input().split()...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def foo(x, y, z): I = [] I.append(z) I.append(x * z + y) return I p, q = map(int, input().split()) n = int(input()) da = map(int, input().split()) a = [] for val in da: a.append(val) a.reverse() la = len(a) if la == 1: if p == q * a[0]: print("YES") else: print("NO") else: ...
FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL V...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
import sys try: file = open("input.txt", "r") sys.stdin = file file = open("output.txt", "w") sys.stdout = file except: ... s = input().split() p, q = int(s[0]), int(s[1]) n = int(input()) s = input().split() arr = [int(i) for i in s] if n == 1: if p / q == arr[0]: print("YES") else...
IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR EXPR UNKNOWN ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CA...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) p, q = map(int, input().split()) n = int(input()) data = list(map(int, input().split())) a = 1 b = data[-1] for i in range(2, n + 1): a = b * data[n - i] + a a, b = b, a a, b = b, a nod = gcd(p, q) p = p // nod q = q // nod ...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUM...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
p, q = map(int, input().split()) n = int(input()) try: for v in map(int, input().split()): if q and p // q == v: p, q = q, p % q elif q and p // q == v + 1: p, q = q, p - q * v else: raise Exception print("NO" if q else "YES") except: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ST...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
import sys def gcd(a, b): if b == 0: return a return gcd(b, a % b) def red(pr): a, b = pr g = gcd(a, b) return a // g, b // g def rev(pr): a, b = pr return b, a def add(pr, i): a, b = pr a += b * i return red((a, b)) args = list(map(int, sys.stdin.read().split()...
IMPORT FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL V...
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal. -----Input----- The first line contains ...
p, q = map(int, input().split()) height = int(input()) fraction = list(map(int, input().split())) def maxFraction(firstNum, firstDem, secNum, secDem): a = firstNum b = firstDem c = secNum d = secDem Y = a * d X = b * c return X == Y if height == 1 and fraction[0] == p // q and p % q == 0...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR VAR IF VAR NUMBER VAR NUM...
After a hard-working week Polycarp prefers to have fun. Polycarp's favorite entertainment is drawing snakes. He takes a rectangular checkered sheet of paper of size $n \times m$ (where $n$ is the number of rows, $m$ is the number of columns) and starts to draw snakes in cells. Polycarp draws snakes with lowercase Lati...
import sys input = sys.stdin.readline testcases = int(input()) for testcase in range(testcases): n, m = list(map(int, input().split())) MAP = [input().strip() for i in range(n)] STR = [[] for i in range(26)] for i in range(n): for j in range(m): if MAP[i][j] != ".": ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR V...
After a hard-working week Polycarp prefers to have fun. Polycarp's favorite entertainment is drawing snakes. He takes a rectangular checkered sheet of paper of size $n \times m$ (where $n$ is the number of rows, $m$ is the number of columns) and starts to draw snakes in cells. Polycarp draws snakes with lowercase Lati...
import sys input = sys.stdin.readline T = int(input()) for _ in range(T): n, m = map(int, input().split()) minx = {} maxx = {} miny = {} maxy = {} matrix = [] for i in range(n): matrix.append(list(input().strip())) for i in range(n): for j in range(m): if mat...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_...
After a hard-working week Polycarp prefers to have fun. Polycarp's favorite entertainment is drawing snakes. He takes a rectangular checkered sheet of paper of size $n \times m$ (where $n$ is the number of rows, $m$ is the number of columns) and starts to draw snakes in cells. Polycarp draws snakes with lowercase Lati...
import sys input = sys.stdin.readline def solve(): H, W = map(int, input().split()) G = [[(ord(s) - 46) for s in input().strip()] for _ in range(H)] Gy = list(map(list, zip(*G))) k = 0 St = [None] * 77 for h, G1 in enumerate(G, 1): k = max(k, max(G1)) for w, g in enumerate(G1,...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE NUMBER FOR VAR VAR FUNC_CALL VAR...
After a hard-working week Polycarp prefers to have fun. Polycarp's favorite entertainment is drawing snakes. He takes a rectangular checkered sheet of paper of size $n \times m$ (where $n$ is the number of rows, $m$ is the number of columns) and starts to draw snakes in cells. Polycarp draws snakes with lowercase Lati...
import sys input = sys.stdin.readline T = int(input()) for _ in range(T): N, M = map(int, input().split()) mar = [-1] * 26 mir = [2000] * 26 mac = [-1] * 26 mic = [2000] * 26 X = [[(-1 if a == "." else ord(a) - 97) for a in input()] for i in range(N)] R = [[(a + 1) for a in range(M)] for _ ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 VAR STRING NUMBER...
After a hard-working week Polycarp prefers to have fun. Polycarp's favorite entertainment is drawing snakes. He takes a rectangular checkered sheet of paper of size $n \times m$ (where $n$ is the number of rows, $m$ is the number of columns) and starts to draw snakes in cells. Polycarp draws snakes with lowercase Lati...
import sys t = int(input()) for ti in range(t): n, m = list(map(int, input().split())) a = [] for i in range(n): a.append(input()) top = {} bot = {} l = {} r = {} res = True for y in range(n): for x in range(m): c = a[y][x] if c != ".": ...
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VA...
After a hard-working week Polycarp prefers to have fun. Polycarp's favorite entertainment is drawing snakes. He takes a rectangular checkered sheet of paper of size $n \times m$ (where $n$ is the number of rows, $m$ is the number of columns) and starts to draw snakes in cells. Polycarp draws snakes with lowercase Lati...
import sys def solve(): H, W = map(int, sys.stdin.readline().split()) G = [[(ord(s) - 46) for s in sys.stdin.readline().strip()] for _ in range(H)] k = 0 inf = 10**9 Stbw = [-inf] * 77 Stsw = [inf] * 77 Stbh = [-inf] * 77 Stsh = [inf] * 77 for h, G1 in enumerate(G, 1): k = ...
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER AS...
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple...
n = int(input()) L = [] i = 1 while i * i * i <= n: if n % i != 0: i += 1 continue x = n // i j = i while j * j <= x: if x % j != 0: j += 1 continue L.append((i, j, x // j)) j += 1 i += 1 maxx = 0 minn = 10**20 E = [[1, 2, 2], [2, 1, 2]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VA...
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple...
n = int(input()) min1 = 10000000000000000000000 max1 = 0 i = 1 while i * i * i <= n: if n % i == 0: j = 1 while j * j <= int(n / i): if n % (i * j) == 0: a = i + 1 b = j + 2 c = int(n / (i * j)) + 2 min1 = min(min1, a * b * ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSI...
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple...
n = int(input()) a, mi = 1, 999999999999 while a**3 <= n: if n % a == 0: b = 1 while b**2 <= n // a: if n // a % b == 0: c = n // a // b mi = min(mi, (a + 1) * (b + 2) * (c + 2)) b += 1 a += 1 print(mi - n, 9 * n + 9 - n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP V...
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple...
n = int(input()) mn = 999999999999 for i in range(1, int(n ** (1 / 3)) + 1): if n % i == 0: for j in range(1, int((n // i) ** (1 / 2)) + 1): if n / i % j == 0: k = n // i // j mn = min(mn, (i + 1) * (k + 2) * (j + 2)) print(mn - n, 9 * n + 9 - n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BI...
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple...
def main(): n = int(input()) m1 = float("inf") m2 = float("-inf") i = 1 while i * i * i <= n: if n % i != 0: i += 1 continue j = 1 while j * j <= n // i: if n // i % j != 0: j += 1 continue k = n ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
from itertools import product def main(): n = int(input()) m = [] beg = [] for _ in range(n): x = list(map(int, input().split())) m.append(x) beg.append(x[0]) ans = 0 cur = [] for j in m: if j[1] not in cur and j[1] in beg and j[1] != j[0]: ans +...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR ...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) res = [[0, False, 0] for k in range(1000)] for i in range(n): a, b = list(map(int, input().split())) res[a - 1][0] += 1 if a != b: res[b - 1][1] = True else: res[b - 1][2] += 1 ans = 0 for el in res: if not el[1]: if el[2] == 0: ans += el[0] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUM...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) a = [0] * n b = [0] * n s = [0] * n ans = 0 for i in range(n): a[i], b[i] = map(int, input().split()) for p in range(n): for j in range(n): if p != j and a[j] == b[p]: if s[j] == 0: s[j] = 1 for t in range(n): ans += s[t] print(n - ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) a = [] b = [] for i in range(n): ai, bi = [int(x) for x in input().split()] a.append(ai) b.append(bi) count = 0 index = 0 for item in a: counter = b.count(item) if counter == 0 or counter == 1 and b[index] == item: count += 1 index += 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR VA...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) a, b = zip(*[map(int, input().split()) for _ in range(n)]) print(sum([(b.count(a[i]) <= (a[i] == b[i])) for i in range(n)]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) t = [[int(x) for x in input().split(" ")] for _ in range(n)] a = [] b = [] a = [t[i][0] for i in range(n)] b = [t[i][1] for i in range(n)] c = [(0) for i in range(n)] for i in range(len(b)): for j in range(len(c)): if b[i] == a[j] and i != j: c[j] = 1 h = 0 for i in c: if i ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
a = int(input()) arr = [] brr = [] for i in range(0, a): x, y = map(int, input().split()) arr.append(x) brr.append(y) flag = False counter = 0 for i in range(0, a): flag = False for j in range(0, a): if i == j: continue if arr[i] == brr[j]: flag = True ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMB...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
t = int(input()) ans = 0 lst = [] lst2 = [] while t: t -= 1 a, b = map(int, input().split()) lst.append(a) lst2.append(b) for i in range(len(lst)): if lst[i] not in lst2[i + 1 :] and lst[i] not in lst2[:i]: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER EXPR FU...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
t = int(input()) a = list() b = list() for i in range(t): c = list(map(int, input().strip().split(" "))) a.append(c[0]) b.append(c[1]) flag = 0 count = 0 for i in range(t): for j in range(t): if a[i] == b[j] and i != j: flag = 1 break if flag == 0: count += 1 ...
ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) count = 0 a = [0] * n b = [0] * n for i in range(n): a[i], b[i] = map(int, input().split()) for i in range(n): for j in range(n): if a[i] == b[j] and j != i: count += 1 break print(n - count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
get = lambda: list(map(int, input().split())) n = int(input()) a = [] b = [] for i in range(n): x, y = get() a.append(x) b.append(y) d = n for i in range(n): for j in range(n): if a[i] == b[j] and i != j: d -= 1 break print(d)
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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) arr = [False] * n des = [] for i in range(n): a, b = map(int, input().split()) des.append([a, b, False]) for i in range(n): open = des[i][1] for j in range(n): if j != i: if des[j][0] == open: des[j][2] = True count = 0 for i in des: if not i[2]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER VA...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) l = [] for i in range(n): l.append(list(map(int, input().split()))) c = 0 for i in range(n): flag = False for j in range(n): if l[i][0] == l[j][1] and i != j: flag = True break if not flag: c += 1 print(c)
ASSIGN VAR FUNC_CALL VAR 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) a = [list(map(int, input().split())) for i in range(n)] t = set() for i in range(n): for j in range(n): if i != j and a[i][1] == a[j][0]: t.add(j) print(n - len(t))
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 FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) b, a = [], [] for i in range(n): x, y = map(int, input().split()) b.append(y) a.append(x) c = a[:] for i in range(n): if b[i] in a and a[i] != b[i]: for j in range(a.count(b[i])): try: c.remove(b[i]) except: pass elif a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_C...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) list1 = [] list2 = [] openedBottles = [] for i in range(0, n + 1): list1.append(0) list2.append(0) openedBottles.append(0) for i in range(1, n + 1): input1 = list(map(int, input().split(" "))) list1[i] = input1[0] list2[i] = input1[1] for i in range(1, n + 1): for j in range...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CAL...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) a = [] b = [] for i in range(n): x, y = map(int, input().split()) a.append(x) b.append(y) ok = [False] * n for i in range(n): for j in range(n): if b[i] == a[j] and i != j: ok[j] = True print(ok.count(False))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN ...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) l = [] t = [0] * 1001 for i in range(n): l += [list(map(int, input().split()))] t = [i[1] for i in l] c = 0 for i in range(n): if t.count(l[i][0]) > 1: c += 1 elif t.count(l[i][0]) == 1 and t.index(l[i][0]) != i: c += 1 else: pass print(n - c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL ...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) a = [] b = [] freq = {} for i in range(n): ai, bi = [int(x) for x in input().split()] a.append(ai) b.append(bi) if bi not in freq: freq[bi] = 0 freq[bi] += 1 ans = n for i in range(n): if a[i] not in freq or freq[a[i]] == 0: continue if freq[a[i]] == 1 and b[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) m, p = [], [] for i in " " * n: a, b = list(map(int, input().split())) m.append(a) p.append(b) for i, j in zip(m, p): if i != j and i in p or i == j and p.count(i) > 1: n = n - 1 print(n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR BIN_OP STRING VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBE...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
import sys num = int(sys.stdin.readline()) arr_a, arr_b = [], [] cnt = 0 for i in range(num): a, b = map(int, sys.stdin.readline().split()) arr_a.append(a) arr_b.append(b) for i in range(num): for j in range(num): if i != j and arr_a[i] == arr_b[j]: cnt += 1 break sys.st...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST 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 FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CA...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) O = [0] * n B = list(O) for i in range(n): a, b = map(int, input().split()) O[i] = b B[i] = a ans = n for i in range(n): for j in range(n): if j == i: continue if O[j] == B[i]: ans -= 1 break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR ...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
l1 = [] l2 = [] n = int(input()) for _ in range(n): x, y = list(map(int, input().split())) l1.append(x) l2.append(y) ans = [1] * n for i in range(len(l1)): for j in range(len(l2)): if i == j: continue if l2[i] == l1[j]: ans[j] = 0 print(sum(ans))
ASSIGN VAR LIST ASSIGN VAR LIST 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 EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL ...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) a = [] for _ in range(n): x, y = [int(x) for x in input().split()] a.append((x, y)) openable = 0 for x, (i, j) in enumerate(a): for y, (l, m) in enumerate(a): if i == m and x != y: openable += 1 break print(n - openable)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) d = {} A = [(0) for i in range(n)] B = [(0) for i in range(n)] for i in range(n): a, b = map(int, input().split()) if b not in d: d[b] = 0 d[b] += 1 A[i] = a B[i] = b count = 0 for i in range(n): if A[i] not in d or d[A[i]] == 1 and A[i] == B[i]: count += 1 print...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBE...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) a = [] b = [] x = [] for i in range(n): c, d = map(int, input().split()) a.append(c) b.append(d) for i in range(n): if a[i] in b: if b[i] == a[i]: if b.count(a[i]) > 1: n -= 1 else: n -= 1 print(n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER V...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
from sys import stdin n = int(stdin.readline()) a = [-1] * n b = [-1] * n opened = [0] * n for i in range(n): a_, b_ = [int(v) for v in stdin.readline().split()] a[i] = a_ b[i] = b_ o1 = [-1] * 1001 o2 = [-1] * 1001 for i in range(n): if o1[b[i]] != -1: o2[b[i]] = i else: o1[b[i]] =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
def main(): n = int(input()) a = [] b = [] opened = [0] * 1001 for i in range(n): ai, bi = map(int, input().split()) a.append(ai) b.append(bi) answer = 0 for i in range(n): opened[b[i]] += 1 for i in range(n): opened[b[i]] -= 1 if opened[a[...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUN...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) count = 0 a = [] b = [] for i in range(n): x, y = map(int, input().split()) a.append(x) b.append(y) v = b.copy() for i in range(n): del v[i] if not a[i] in v: count += 1 v = b.copy() print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_C...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
n = int(input()) arr = [None] for i in range(n): a, b = [int(x) for x in input().split()] ans = [i, a, b] arr.append(ans) result = 0 ans = [(False) for x in range(n + 1)] for i in range(1, n + 1): for j in range(1, n + 1): if j != i: if arr[i][1] == arr[j][2]: ans[i] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one b...
def main(): n = int(input()) a = [None] * n b = [None] * n for i in range(n): a[i], b[i] = map(int, input().split()) for i in range(n): for j in range(n): if i == j: continue if a[j] == b[i]: a[j] = -1 ans = 0 for item i...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NU...