description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
from itertools import dropwhile n = [int(i) for i in input()] l = len(n) if len(n) == 1: print(-1) exit() if n in [[2, 5], [7, 5], [5, 0]]: print(0) exit() if n in [[5, 2], [5, 7]]: print(1) exit() inf = 10**12 def calc1(x, y): global n, l, inf m = n[::-1] if x not in n or y not i...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER EXPR FU...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
l = [int(e) for e in input().strip()] def lei00(l): result = [] for i in range(len(l) - 1, -1, -1): if l[i] == 0: result.append(i) if len(result) == 2: break if len(result) < 2: return None return 2 * len(l) - result[0] - result[1] - 3 def lei(l, x, y)...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NONE RETURN BIN_OP BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR V...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
s = list(input()) n = len(s) if n == 1: print(-1) exit(0) ans = 2000000000.0 for i in range(n): for j in range(i + 1, n): s1 = s[:] cnt = 0 i1, j1 = i + 1, j + 1 while j1 < n: s1[j1 - 1], s1[j1] = s1[j1], s1[j1 - 1] j1 += 1 cnt += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
a = input()[::-1] d = ["52", "05", "57"] if len(a) < 2: print(-1) elif a[:2] in d: print(0) else: ans = 99999999 if len([i for i in a if i == "0"]) >= 2: x, y = -1, -1 for i in range(len(a)): if a[i] == "0": if x < 0: x = i ...
ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST STRING STRING STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR STRING NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING I...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
s = input() globans = 10**9 for i_ in range(len(s)): for j_ in range(len(s)): i = i_ j = j_ if j == i: continue if i == len(s) - 1: ans = abs(len(s) - j - 1) else: ans = abs(len(s) - i - 2) + abs(len(s) - j - 1) + int(j < i) if i > ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL ...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
n = list(input())[::-1] INF = 10**9 if "".join(n) in ["52", "05", "57"]: print(0) exit(0) if "".join(n) in ["25", "75"]: print(1) exit(0) def solve(a, b): if a not in n or b not in n: return INF nn = n[:] ia = nn.index(a) nn = [a] + nn[:ia] + nn[ia + 1 :] ib = nn.index(b) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER IF FUNC_CALL STRING VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL STRING VAR LIST STRING STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR RETURN VAR ASSIGN...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
s = input() if int(s) % 25 == 0: print(0) else: sols = [] d = {} n = list(s) nr = s[::-1] for c in ("0", "2", "5", "7"): p = nr.find(c) d[c] = p for c1, c2 in (("2", "5"), ("5", "0"), ("7", "5")): if c1 not in n or c2 not in n: continue dc1 = d[c1]...
ASSIGN VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR STRING STRING STRING STRING STRING STRING IF VAR...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
a = input() k = 0 if a.rfind("5") == 0 and a[1] == "0" and len(a) > 2: a = a[0] + a[2] + a[1] + a[3:] k = a.count("0") if a.count("0") >= 2: a00 = -1 + len(a) - 1 - a.rfind("0") + (len(a) - 1 - a.rfind("0", 0, a.rfind("0"))) else: a00 = 1000 if a.rfind("2") > a.rfind("5") and a.rfind("2") != -1 and a.rf...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING NUMBER VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR ...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
n = list(input())[::-1] INF = 10**9 def solve(b, a): a, b = str(a), str(b) if a not in n or b not in n: return INF nn = n[:] ia = nn.index(a) nn = [a] + nn[:ia] + nn[ia + 1 :] ib = nn.index(b) nn = [a, b] + nn[1:ib] + nn[ib + 1 :] if len(n) == 2: return ia + ib - 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
s = input() arr = [] for i in s: arr.append(i) ans = 100000000000 for i in range(len(s)): for j in range(len(s)): if i == j: continue t = arr[:] curr = 0 for k in range(i, len(s) - 1): tt = t[k] t[k] = t[k + 1] t[k + 1] = tt ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
import sys k = input() n = len(k) Min = sys.maxsize ck = ["50", "25", "75"] for c in ck: if c[0] in k and c[1] in k: temp = 2 * n - 3 - k.rfind(c[0]) - k.rfind(c[1]) if c[1] == "5": if k.rfind("5") == 0 and k[1] == "0" and n > 3: add = 0 i = 1 ...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST STRING STRING STRING FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF FUNC_CALL VAR STRING NUMBER VAR...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
def is_valid(a): i = len(a) - 1 cnt = 0 while i >= 0 and a[i] == 0: cnt += 1 i -= 1 if i == -1 and cnt > 0: return False, cnt return True, cnt def create(a): b = [x for x in a] return b def solve(d, a): min_ = float("inf") for x, y in [[2, 5], [7, 5], [5, ...
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER VAR RETURN NUMBER VAR FUNC_DEF ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR LIST LIST NUMBER NUMBER LIST NUMBER NUM...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
def solve(n): if int(n) % 25 == 0: return 0 if n in {"52", "57"}: return 1 ans = float("inf") for x, y in ["00", "25", "50", "75"]: for i in range(len(n)): if n[i] == "0": continue for j in range(len(n)): if i == j or n[j] !...
FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER IF VAR STRING STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR LIST STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR ...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
y = input() fives = y.count("5") zeroes = y.count("0") twos = y.count("2") sevens = y.count("7") if fives == 0: if zeroes < 2: print(-1) exit(0) elif zeroes == 0 and twos == 0 and sevens == 0: print(-1) exit(0) best = 5 * len(y) y = y[::-1] for xx in [["5", "2"], ["0", "0"], ["5", "7"], ["0"...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
num = str(input()) n = len(num) num_r = num[::-1] s0, s5 = num_r.find("0"), num_r.find("5") if s0 != -1: newnum_r = num_r[:s0] + num_r[s0 + 1 :] c = [] for a in ["0", "5"]: if newnum_r.find(a) != -1: c.append(newnum_r.find(a)) if c != []: s = min(c) s0 = s0 + s el...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR LIST STRING STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF ...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
def idx(s, c, start=0): try: return s[::-1].index(c, start) except: return -1 def main(): s = input() zero_cnt = 0 while zero_cnt < len(s) - 1 and s[zero_cnt + 1] == "0": zero_cnt += 1 i01 = idx(s, "0") i02 = idx(s, "0", i01 + 1) i2 = idx(s, "2") i5 = idx(s,...
FUNC_DEF NUMBER RETURN FUNC_CALL VAR NUMBER VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR S...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
n = input() if "2" not in n or "5" not in n: a = 10**18 else: a = 0 i = len(n) - 1 while n[i] != "5": i -= 1 a += 1 updated_n = n[0:i] + n[i + 1 :] i = len(n) - 2 while updated_n[i] != "2": i -= 1 a += 1 updated_n = updated_n[0:i] + updated_n[i + 1 :] ...
ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR STRING VAR NUMBER VAR ...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
n = input() n = list(n) if not "5" in n and not "0" in n and not "7" in n and not "2" in n: print(-1) quit() wkn = [] wkn[:] = n ans = -1 for i in reversed(list(range(len(n)))): if n[i] == "0": wk1 = n[:i] + n[i + 1 :] + [n[i]] ans = len(n) - i - 1 if wk1[0] != "0": n[:] ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BI...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
import sys def sol(a, s): s1 = s[::-1] try: ai = s1.index(a) if a == "0": s2 = a + s1[0:ai] + s1[ai + 1 :] return [True, ai, s2[::-1]] except: return [False] x = len(s) - 2 while x > -1 and s1[x] == "0" and ai == len(s) - 1 and len(s) != 1: x...
IMPORT FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN LIST NUMBER VAR VAR NUMBER RETURN LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
s = input()[::-1] ans = 10**9 mp = {"0": "05", "5": "27"} for i in range(len(s)): if s[i] not in mp: continue rem = s[:i] + s[i + 1 :] for j in range(len(rem)): if rem[j] not in mp[s[i]]: continue rem2 = rem[:j] + rem[j + 1 :] if rem2: lastnz = -1 ...
ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBE...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
def swap(ar, ind1, ind2): if ind2 > ind1: for i in range(ind1, ind2): temp = ar[i] ar[i] = ar[i + 1] ar[i + 1] = temp else: for i in range(ind1, ind2, -1): temp = ar[i] ar[i] = ar[i - 1] ar[i - 1] = temp n = list(input()) ...
FUNC_DEF IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
n = [int(x) for x in input()] var = [[0, 0], [5, 2], [5, 7], [0, 5]] res = 1000 ln = len(n) for c in var: num = n[:] i1 = -1 i2 = -1 i0 = -1 for i in range(ln - 1, -1, -1): if num[i] == c[0]: i1 = i break if i1 == -1: continue tres = 0 idx = i1 + 1...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
import sys n = int(input()) if n % 25 == 0: print(0) else: tmp = n digits = [0] * 10 while tmp: digits[tmp % 10] += 1 tmp //= 10 s = str(n) length = len(s) leading_zero_inc = 0 for i in range(1, length): if s[i] != "0": leading_zero_inc = i ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER WHILE VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VA...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
s = input()[::-1] t = len(s) def g(c, i=0): return s.find(str(c), i) + 1 or 50 i, f = g(0), g(5) j = min(g(0, i), f) m = i + j + (j < i) j = min(g(2), g(7)) l = f + j + (j < f) if f == t: i = t - 1 while s[i - 1] == "0": l += 1 i -= 1 m = min(m, l) print((-1, m - 3)[m < 40])
ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FU...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
def digits(n): return len(str(n)) def digit(n, i): if i < digits(n): return int(str(n)[digits(n) - i - 1]) return 0 def swap_digits(n, i, j): return n + digit(n, i) * (10**j - 10**i) + digit(n, j) * (10**i - 10**j) n = int(input()) if n % 25 == 0: print(0) exit() ans = [] for i in ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP ...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
n = int(input()) l = list(str(n))[::-1] g = [] def verif(l): if l[-1] != "0": return 0 else: return 1 + verif(l[:-1]) def permut(l, c, c1): i = l.copy() k = 0 while True: if i.index(c) == 0: break else: j = i.index(c) i[j], i[j ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER STRING RETURN NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASS...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
A_str = input() A = list(A_str) B = [["2", "5"], ["5", "0"], ["7", "5"]] result = 10**9 if int(A_str) % 100 == 0: print(0) else: for a, b in B: if a not in A or b not in A: continue cresult = 0 tmp_str = A_str[:] i = tmp_str.rfind(b) cresult += len(tmp_str) - ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST STRING STRING LIST STRING STRING LIST STRING STRING ASSIGN VAR BIN_OP NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
def swipe(s, i): return s[:i] + s[i + 1] + s[i] + (s[i + 2 :] if i + 2 < len(s) else "") def nazis(s): m = float("inf") for i in range(9): if s.find(str(i + 1)) > -1: m = min(s.find(str(i + 1)), m) return m n = input() c = float("inf") if ( n.count("0") >= 2 or "5" in n ...
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR B...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
def permutate(s): answer = 1000 n = len(s) z = 0 if s.count("2") >= 1 and s.count("5") >= 1: k1 = s.rfind("2") k2 = s.rfind("5") s1 = s[:k1] + s[k1 + 1 :] m = s1.rfind("5") s2 = s1[:m] + s1[m + 1 :] if len(s2) > 0 and s2[0] == "0": for i in ran...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NU...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
from sys import stdin def f(n, x, y): ans = 0 cur = n.rfind(y) if cur < 0: return 10**18 ans += len(n) - 1 - cur n = n[:cur] + n[cur + 1 :] + y cur = n[:-1].rfind(x) if cur < 0: return 10**18 ans += len(n) - 2 - cur n = n[:-1][:cur] + n[:-1][cur + 1 :] + x + y c...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN BIN_OP NUMBER NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER RETURN BIN_OP NUMBER NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NU...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
k = input() zeroes = [-1, -1] five = -1 two = -1 seven = -1 for i in range(len(k)): if k[i] == "0": zeroes[zeroes.index(min(zeroes))] = i elif k[i] == "2": two = i elif k[i] == "5": five = i elif k[i] == "7": seven = i if len(k) == 3 and k[:2] == "50" and k[-1] != "5" and...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF FUNC...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
INF = 10000 n = input() ans = INF k = len(n) for i in range(k): for j in range(k): if i == j: continue s = n tmp = 0 for p in range(i, k - 1): s = s[:p] + s[p + 1] + s[p] + s[p + 2 :] tmp += 1 for p in range(j - (j > i), k - 2): ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER V...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
s = input() n = len(s) c = dict() ans = 1e18 c["2"], c["5"], c["7"], c["0"] = 0, 0, 0, 0 for i in s: if i not in c: c[i] = 0 c[i] += 1 if c["0"] >= 2: res = -1 for i in range(n - 1, -1, -1): if s[i] == "0": if res == -1: res = n - 1 - i else: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING VAR STRING VAR STRING VAR STRING NUMBER NUMBER NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBE...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
import sys input = sys.stdin.readline n = list(input().rstrip()) m = len(n) inf = 114514 if m == 1: ans = -1 elif m == 2: x = 10 * int(n[0]) + int(n[1]) if x % 25 == 0: ans = 0 elif x == 52 or x == 57: ans = 1 else: ans = -1 else: ans = inf for i in range(m): ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASS...
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
class Problem: def solve(self, s): ans = -1 n = len(s) for i in range(n): for j in range(n): if i != j: c1 = c2 = 0 t, c1 = self.move_end(s, i, j) if t[0] == "0": k = self.find_no...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
def gcd(a, b): c = 0 while b > 0: c = a % b a = b b = c return a arr = list(map(int, input().split())) n = arr[0] m = arr[1] if m < n - 1: print("Impossible") exit() vec = [] for i in range(n): for j in range(i + 1, n): if gcd(int(i + 1), int(j + 1)) == 1: ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
import sys def make_prime_factors(n: int) -> list: prime_factors = [] for k in range(2, int(n**0.5) + 1): while n % k == 0: prime_factors.append(k) n = n // k if n != 1: prime_factors.append(n) return set(prime_factors) input = sys.stdin.readline def solve(n...
IMPORT FUNC_DEF VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMB...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
n, m = map(int, input().split()) def gcd(p, q): if q == 0: return p else: return gcd(q, p % q) rec = [] num = 0 for i in range(1, n + 1): if num == m: break for j in range(i, n + 1): if num == m: break if j == i: continue if i =...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VA...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
def gcd(a, b): return a if not b else gcd(b, a % b) n, m = map(int, input().split()) ans, cnt = "Possible", 0 for i in range(1, n + 1): for j in range(i + 1, n + 1): if gcd(i, j) == 1: cnt += 1 ans += "\n%d %d" % (i, j) if cnt == m: break if cnt ...
FUNC_DEF RETURN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP STRING VAR VAR IF ...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
def gcd_recursive(a, b): if b == 0: return a else: return gcd_recursive(b, a % b) out = [] inp = [int(x) for x in input().split(" ")] if inp[1] < inp[0] - 1: print("Impossible") else: for a in range(1, inp[0]): if len(out) == inp[1] - inp[0] + 1: print("Possible") ...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMB...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
from itertools import islice def get_all(n): q = [(0, 1, 1, 1)] while q: a, b, c, d = q.pop() e, f = a + c, b + d if f <= n: yield e, f q.append((a, b, e, f)) q.append((e, f, c, d)) def solve(n, m): x = list(islice(get_all(n), m)) if len(x)...
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER WHILE VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CAL...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
def gcd(a, b): while b != 0: t = a a = b b = t % b return a n, m = map(int, input().split()) c = 0 ans = "Possible " + chr(10) for i in range(1, n + 1): for j in range(i + 1, n + 1): if gcd(i, j) == 1: ans += str(i) + " " + str(j) + chr(10) c += 1 ...
FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER I...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
def gcd(a, b): if b == 0: return a return gcd(b, a % b) nm = input().split() n = int(nm[0]) m = int(nm[1]) if m < n - 1: print("Impossible") else: l = [] cnt = 0 f = 0 for i in range(1, n): for j in range(i + 1, n + 1): if gcd(i, j) == 1: l.appen...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
def gcd(x, y): while y: x, y = y, x % y return x n, m = [int(i) for i in input().split()] mi = n - 1 mx = n * (n - 1) // 2 if m < mi: print("Impossible") else: l = [] c = 0 for i in range(1, n): for j in range(i + 1, n + 1): if gcd(i, j) == 1: l.appe...
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR ...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
[n, m] = [int(i) for i in input().split()] gcd = lambda x, y: x if not y else gcd(y, x % y) if m < n - 1: print("Impossible") else: pairs = [] flag = 0 i = 0 while i < n and not flag: j = i + 1 while j < n and not flag: if len(pairs) == m: flag = 1 ...
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VA...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
def gcd(a, b): while b: a, b = b, a % b return a n, m = map(int, input().split()) if n - 1 > m: exit(print("Impossible")) ans = [] co = m for i in range(1, n): ans.append((i, i + 1)) co -= 1 for i in range(1, n + 1): for j in range(i + 2, n + 1): if co == 0: break ...
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL ...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
def gcd(a, b): return b if a % b == 0 else gcd(b, a % b) n, m = [int(x) for x in input().split()] if m < n - 1: print("Impossible") elif m == n - 1: print("Possible") for i in range(1, n): print(i, i + 1) else: ct = 0 pairs = [] done = False for i in range(1, n): if don...
FUNC_DEF RETURN BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN V...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
def gcd(a, b): if a % b == 0: return b else: return gcd(b, a % b) n, m = list(map(int, input().split())) b = [] c = 0 e = 0 for i in range(1, n): for j in range(i + 1, n + 1): if gcd(i, j) == 1: b.append([i, j]) c = c + 1 if c == m: e = 1...
FUNC_DEF IF BIN_OP VAR 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 LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
def gcd(a, b): while b: a, b = b, a % b return a n, m = [int(_) for _ in input().split()] edges = [] for i in range(1, n + 1): for j in range(i + 1, n + 1): if gcd(i, j) == 1: edges.append((i, j)) if len(edges) == m: break if len(edges) == m: bre...
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VA...
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
def gcd(n1, n2): if n2 > n1: return gcd(n2, n1) if n2 == 0: return n1 return gcd(n2, n1 % n2) def main(): n, m = map(int, input().split()) if m < n - 1: print("Impossible") return ans = [] for i in range(1, n): j = 2 curr = set() whil...
FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
def find(): n, m = map(int, input().split()) g = [list(input()) for _ in range(n)] if m % 2 != 0: ans = " ".join([str(j % 2 + 1) for j in range(m + 1)]) return "Yes\n" + ans for j in range(n): for k in range(j + 1, n): if g[k][j] == g[j][k]: res = j + ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP STRING VAR FOR VAR FUNC_CALL VAR VAR FOR ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
def arrIn(): return list(map(int, input().split())) def mapIn(): return map(int, input().split()) for ii in range(int(input())): n, k = mapIn() arr = [([0] * n) for i in range(n)] for i in range(n): s = input() for j in range(n): arr[i][j] = s[j] if k == 1: ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys from itertools import permutations input = lambda: sys.stdin.readline().rstrip() def solve(n, m, graph): for i in range(n): for j in range(n): if i != j and graph[i][j] == graph[j][i]: print("YES") ans = ([i + 1, j + 1] * m)[: m + 1] ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRIN...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
from itertools import cycle, islice from sys import stdin readline = stdin.readline def read_ints(): return map(int, readline().split()) def read_string(): return readline()[:-1] def f(a_seq, b_seq, c_seq): assert len(a_seq) == len(b_seq) n = len(a_seq) colors_need = Counter(b for a, b in zip...
ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR FUN...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = sys.stdin.readline for _ in range(int(input())): n, m = map(int, input().split()) G = [input()[:-1] for _ in range(n)] if m % 2: ans = [1, 2] * (m // 2 + 1) print("YES") print(*ans) continue flag = 0 for i in range(n): for j in range(i + 1,...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VA...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys read = sys.stdin.readline write = lambda x, end="\n": sys.stdout.write(x + end) for _ in range(int(input())): n, m = map(int, input().split()) g = [input()[:3] for _ in range(n)][:3] if m & 1: print("YES") print(" ".join("1" if i & 1 else "2" for i in range(m + 1))) elif g ==...
IMPORT ASSIGN VAR VAR ASSIGN VAR STRING FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
from sys import gettrace, stdin if gettrace(): def inputi(): return input() else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() def solve(): n, m = map(int, input().split()) ll = [] for _ in range(n): ll.append(input()) ...
IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FU...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys for _ in range(int(input())): n, t = [int(x) for x in input().split()] arr = [] for i in range(n): arr.append(input()) if t % 2: print("YES") ans = [] for i in range(t + 1): if i % 2: ans.append(2) else: ...
IMPORT 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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXP...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = sys.stdin.readline for t in range(int(input())): N, M = map(int, input().split()) S = [input() for i in range(N)] F = 0 for i in range(N): for j in range(N): if i != j and S[i][j] == S[j][i]: F = 1 P = [i + 1] for k ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST BIN_O...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
def get_best_edge(graph): for i in range(len(graph) - 1): for j in range(i + 1, len(graph)): if graph[i][j] == graph[j][i]: return True, i, j return False, 0, 1, 2 def solve(graph, m): x = get_best_edge(graph) res = [] if x[0] or m % 2 == 1: for i in ran...
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR RETURN NUMBER VAR VAR RETURN NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = sys.stdin.readline t = int(input()) for tests in range(t): n, m = map(int, input().split()) S = [input().strip() for i in range(n)] flag = 0 for i in range(n): for j in range(i + 1, n): if S[i][j] == S[j][i]: ANSX = i, j flag = 1 ...
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 FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR ASSI...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = iter(sys.stdin.read().splitlines()).__next__ def solve(): n, m = map(int, input().split()) edges = [input() for _ in range(n)] if m % 2: path = [1, 2] * (m // 2 + 1) return f"YES\n{' '.join(map(str, path))}" for u in range(n): for v in range(u + 1, n): ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER RETURN STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR FOR VAR ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = sys.stdin.readline def find_aa_line(three): for i in range(3): for j in range(3): if i == j: continue for k in range(3): if j == k or i == k: continue if three[i][j] == three[j][k]: ...
IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR RETURN LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN NONE FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
from sys import stdin, stdout input = stdin.readline def f1(i, j, k): global all if mat[i][j] == mat[j][k] and mat[j][i] == mat[k][j]: all = [] for p in range(m // 2 + 1): if p % 2 == 0: all.append(i + 1) else: all.append(j + 1) ...
ASSIGN VAR VAR FUNC_DEF IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
def repeat(l, count): res = [] for i in range(count): res.append(l[i % len(l)]) return res def solve(graph, l): if l % 2 == 1: return repeat([0, 1], l + 1) for i in range(len(graph)): for j in range(len(graph)): if i != j and graph[i][j] == graph[j][i]: ...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys from itertools import permutations input = sys.stdin.readline def solution(n, m, mat): sol = [] if m % 2 == 1: print("YES") for i in range(m + 1): sol.append(i % 2 + 1) print(*sol) return elif n == 2 and mat[0][1] != mat[1][0]: print("NO") ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER E...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
from itertools import cycle, islice def solve(): n, m = [int(t) for t in input().split()] g = [input() for _ in range(n)] for i in range(n): for j in range(i + 1, n): if g[i][j] == g[j][i]: return repeat(i, j, m) if m % 2 == 1: return repeat(0, 1, m) if ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR NUMBER NUMBER VAR IF VAR...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
def main(): num_cases = int(input()) for case_num in range(1, num_cases + 1): solve(case_num) def solve(case_num): n, m = [int(x) for x in input().split()] A = [input() for _ in range(n)] if m % 2 != 0: cycle = [1, 2] print("YES") print(" ".join(str(cycle[i % 2]) fo...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR STRING E...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = sys.stdin.readline for f in range(int(input())): n, m = map(int, input().split()) e = [] for i in range(n): e.append(input()) if n == 2: if m % 2: print("YES") print(*([1, 2] * (m // 2 + 1))) elif e[0][1] == e[1][0]: print("...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER BIN_OP BIN...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys zz = 1 sys.setrecursionlimit(10**5) if zz: input = sys.stdin.readline else: sys.stdin = open("input.txt", "r") sys.stdout = open("all.txt", "w") di = [[-1, 0], [1, 0], [0, 1], [0, -1]] def fori(n): return [fi() for i in range(n)] def inc(d, c, x=1): d[c] = d[c] + x if c in d else x ...
IMPORT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF NU...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys def soll(Var, m): if m % 2 == 1: answer = [] for k in range(m + 1): if k % 2 == 0: answer.append(Var[0] + 1) else: answer.append(Var[1] + 1) print("YES") print(*answer) return A = [] B = [] for i...
IMPORT FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CAL...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = sys.stdin.readline for _ in range(int(input())): n, m = map(int, input().split()) S = [input()[:-1] for _ in range(n)] x, y = -1, -1 for i in range(n): for j in range(i + 1, n): if S[i][j] == S[j][i]: x, y = i, j if m % 2 == 1 and x == -1: ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
for _ in range(int(input())): n, m = map(int, input().split()) if m % 2 == 1: for i in range(n): s = input() print("YES") for i in range(m + 1): print(i % 2 + 1, end=" ") print() else: A = [] for i in range(n): B = input() ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING EXPR FUNC_...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys def main(): t = int(input()) allAns = [] for _ in range(t): n, m = readIntArr() edges = [] for __ in range(n): edges.append(input()) ok = False if m % 2 == 1: ok = True ans = [0, 1] * ((m + 1) // 2) else: ...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP BIN_OP VAR ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
def find(): n, m = map(int, input().split()) g = [] has = [] for j in range(n): tmp = [] tmp1 = [-1] * 2 for p, k in enumerate(input()): tmp.append(k) if k != "*": tmp1[ord(k) - ord("a")] = p g.append(tmp) has.append(tmp1) ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR EXPR ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
for _ in range(int(input())): n, m = map(int, input().split()) Edges = [input() for _ in range(n)] if m & 1: print("YES") L = [(1 + (i & 1)) for i in range(m + 1)] print(*L) else: flag = True for i in range(n - 1): for j in range(i + 1, n): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, m = map(int, input().split()) s = [list(input().rstrip()) for _ in range(n)] if n == 2: if m % 2 or s[0][1] == s[1][0]: print("YES") ans = [(i % 2 + 1) for i in range(m + 1)] print(*ans)...
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 FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN V...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
rn = lambda: int(input()) rns = lambda: map(int, input().split()) rl = lambda: list(map(int, input().split())) rs = lambda: input() YN = lambda x: print("YES") if x else print("NO") pl = lambda l: print(" ".join(list(map(str, l)))) def d(a): d = {} for i in a: if i in d: d[i] += 1 ...
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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR F...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
def solveTestCase(): nm = [int(i) for i in input().split()] G = [] for i in range(nm[0]): G.append(input()) if nm[1] % 2 == 1: print("YES") for i in range(nm[1] // 2 + 1): print("1 2", end=" ") print() return mypaire = 0, 0 for i in range(nm[0]...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VA...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
t = int(input()) while t > 0: t -= 1 n, m = [int(op) for op in input().split()] mt = [input() for i in range(n)] if m % 2 == 1: print("YES") for i in range(m + 1): print(1, end=" ") if i % 2 == 0 else print(2, end=" ") print() else: flag = False f2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR NUMBER ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = sys.stdin.readline ansl = [] for _ in range(int(input())): n, k = map(int, input().split()) sl = [] for _ in range(n): sl.append(list(input())) if n == 2: if k % 2 == 1 or sl[0][1] == sl[1][0]: ansl.append([1, 2] * ((k - 1) // 2 + 1)) if k % 2 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUN...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = sys.stdin.readline for _ in range(int(input())): N, M = map(int, input().split()) e = [list(input())[:-1] for _ in range(N)] res = [0] * (M + 1) for i in range(N): for j in range(N): if i == j: continue if e[i][j] == e[j][i]: ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR V...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N, M = map(int, input().split()) X = [ [(0 if a == "a" else 1 if a == "b" else -1) for a in input()] for _ in range(N) ] if M % 2: print("YES") print(*([1, 2] * (M // 2 + 1))) co...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL 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 VAR STRING NUMBER VAR STRING NUMBER NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
def print_ez(node1, node2, m): print("YES") p = [] for i in range(m + 1): if i % 2: p.append(node2) else: p.append(node1) print(*p) def print_hard(center, node1, node2, m): print("YES") p = [center] for i in range(m // 2): if i % 2: ...
FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
t = int(input()) for _ in range(t): n, m = [int(x) for x in input().split()] grid = [input() for _ in range(n)] if m % 2 == 1: print("YES") print("1 2 " * ((m + 1) // 2)) continue for i in range(n): found = False for j in range(n): if j == i: ...
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 FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR AS...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
from itertools import chain, cycle, islice from sys import stdin readline = stdin.readline def read_ints(): return map(int, readline().split()) def read_string(): return readline()[:-1] def f(graph, m): assert n >= 2 assert m >= 1 for u in range(n): for v in range(u + 1, n): ...
ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NU...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys def read_ints(): return [int(i) for i in sys.stdin.readline().strip().split()] def read_int(): return int(sys.stdin.readline().strip()) def check_and_output(lines, nodes): route = [lines[int(i) - 1][int(j) - 1] for i, j in zip(nodes[:-1], nodes[1:])] in_reverse = list(reversed(route)) ...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CA...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
for nt in range(int(input())): n, m = map(int, input().split()) edge = [] for i in range(n): edge.append(list(input())) found = 0 for i in range(n): for j in range(n): if i == j: continue if edge[i][j] == edge[j][i]: found = [i,...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = lambda: sys.stdin.readline().rstrip() for _ in range(int(input())): n, m = map(int, input().split()) s = [input() for i in range(n)] same = False u, t = -1, -1 for i in range(n): for j in range(i + 1, n): if s[i][j] == s[j][i]: u, t = i, j ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR ...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
for testcase in range(int(input())): arr = [int(x) for x in input().split()] n, m = arr[0], arr[1] graph = [] for i in range(n): graph.append(input()) if m & 1 == 1: print("YES") for i in range(m + 1): if i & 1 == 1: print(2, end=" ") e...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys max_int = 2147483648 min_int = -max_int t = int(input()) for _t in range(t): n, m = map(int, sys.stdin.readline().split()) m += 1 M = [] s_out = [] for nn in range(n): s = input() M.append(s) s_out.append(set(list(s))) if not m % 2: print("YES") ...
IMPORT ASSIGN VAR NUMBER 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 VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CAL...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys def input(): return sys.stdin.readline().rstrip() def slv(): n, m = map(int, input().split()) G = [([-1] * n) for i in range(n)] for i in range(n): s = input() for j in range(n): if s[j] == "b": G[i][j] = 1 elif s[j] == "a": ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL 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 FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR V...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, m = map(int, input().split()) s = [input() for _ in range(n)] flg = 0 for i in range(n): for j in range(i + 1, n): if s[i][j] == s[j][i]: print("YES") res = [i + 1] * (m + 1)...
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 FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
T = int(input()) for t in range(T): n, m = tuple([int(x) for x in input().split()]) ss = [] for i in range(n): ss.append(input().strip()) if n == 2: if ss[0][1] != ss[1][0] and m % 2 == 0: print("NO") else: print("YES") print(" ".join([str(i % ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VA...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
T = int(input()) for _ in range(T): n, m = map(int, input().split()) A = [input() for i in range(n)] if m % 2 != 0: print("YES") for i in range(m + 1): if i % 2 == 0: print(1, end=" ") else: print(2, end=" ") print() else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER STR...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
for _ in range(int(input())): n, m = map(int, input().split()) g = [input() for i in range(n)] if m % 2 == 1: print("YES") print("1 2 " * (m // 2 + 1)) continue ans = [] for v in range(n): for u1 in range(n): for u2 in range(n): if ( ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR V...
Your friend Salem is Warawreh's brother and only loves math and geometry problems. He has solved plenty of such problems, but according to Warawreh, in order to graduate from university he has to solve more graph problems. Since Salem is not good with graphs he asked your help with the following problem. You are given...
from sys import stdin t = int(stdin.readline()) def run(): L = [int(x) for x in stdin.readline().split(" ")] n, m = L[0], L[1] M = [] for i in range(n): M.append(stdin.readline()) if m % 2 == 1: res = [] for k in range(m): res.append(1) res.append(2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ...
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire strin...
n, x, y = map(int, input().split()) s = input().replace("1", " ") z = len(s.split()) print(z and (z - 1) * min(x, y) + y)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire strin...
n, x, y = map(int, input().split()) s = input() nGroups = int(s[0] == "0") for i in range(1, n): if s[i - 1] != s[i] == "0": nGroups += 1 if nGroups == 0: print(0) else: print((nGroups - 1) * min(x, y) + y)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VA...