description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself. For exa...
import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): a, b = mints() d = abs(a - b) if d == 0: return 0 if d == 1: return 1 s = 0 for i in range(1, int(1000000000.0))...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL V...
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself. For exa...
t = int(input()) for _ in range(t): a, b = map(int, input().split()) a, b = sorted([a, b]) diff = b - a low = 0 high = diff + 1 while low < high - 1: mid = (low + high) // 2 if mid * (mid + 1) // 2 < diff: low = mid else: high = mid for i in ra...
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 FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_O...
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so ...
x, y, z, k = [int(x) for x in input().split()] dim = sorted([x - 1, y - 1, z - 1]) answer = [0, 0, 0] for i in range(len(dim)): dimi = dim[i] if dimi * (3 - i) <= k: k = k - dimi * (3 - i) for j in range(i, 3): answer[j] += dimi for j in range(3): dim[j] -= dimi ...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BI...
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so ...
x, y, z, k = map(int, input().split()) sides = sorted([x, y, z]) cuts = 3 * [None] product = 1 for i in range(3): a = min(sides[i] - 1, k // (3 - i)) cuts[i] = a k -= a product *= a + 1 print(product)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR BIN_OP NUMBER LIST NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR F...
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so ...
xyzk = [int(i) for i in input().split()] k = xyzk[3] x, y, z = sorted([xyzk[0], xyzk[1], xyzk[2]]) x = min(k // 3 + 1, x) y = min((k - x + 1) // 2 + 1, y) z = min(k - x - y + 3, z) print(x * y * z)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VA...
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so ...
I = lambda: map(int, input().split()) x, y, z, k = I() a1, a2, a3, q = 0, 0, 0, 0 while q < 3: q = 0 if a1 + a2 + a3 == k: break if a1 < x - 1: a1 += 1 if a1 + a2 + a3 == k: break else: q += 1 if a2 < y - 1: a2 += 1 if a1 + a2 + a3 == k: ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NU...
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so ...
def main(): *l, k = map(int, input().split()) x, y, z = sorted(l) x = min(k // 3 + 1, x) y = min((k - x + 1) // 2 + 1, y) z = min(k - x - y + 3, z) print(x * y * z) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR E...
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so ...
x, y, z, k = map(int, input().split()) a, b, c = 1, 1, 1 while k // 3 and (a < x or b < y or c < z): p = k // ((a < x) + (b < y) + (c < z)) A = min(x - a, p) B = min(y - b, p) C = min(z - c, p) a += A b += B c += C k -= A + B + C while k and (a < x or b < y or c < z): if a < x: ...
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CAL...
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so ...
x, y, z, k = map(int, input().split()) x, y, z = sorted((x, y, z)) a = min(k // 3, x - 1) b = min((k - a) // 2, y - 1) c = min(k - a - b, z - 1) print((a + 1) * (b + 1) * (c + 1))
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUN...
Think of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 to M. C friends are staying at C hotels located at some street-avenue crossings. They are going to celebrate birthday of one of them in the one of H restaurants also located at some street...
n, m = map(int, input().split()) minx = miny = n + m maxx = maxy = -minx dist = n + m + 1 c = int(input()) for _ in range(c): x, y = map(int, input().split()) minx = min(minx, x - y) miny = min(miny, x + y) maxx = max(maxx, x - y) maxy = max(maxy, x + y) h = int(input()) for i in range(h): a, b ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER 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 BIN_OP VAR VAR ASSIGN V...
Think of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 to M. C friends are staying at C hotels located at some street-avenue crossings. They are going to celebrate birthday of one of them in the one of H restaurants also located at some street...
N, M = input().split() a, b, c, d = [int(10000000000.0) for _ in range(4)] for i in range(int(input())): x, y = list(map(int, input().split())) a, b, c, d = min(a, x + y), min(b, x - y), min(c, -x + y), min(d, -x - y) res, pos = int(10000000000.0), 0 for i in range(int(input())): x, y = list(map(int, input(...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FU...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = input() m = input().split() a = [] b = [] for s in m: i = int(s) if int(i ** (1 / 2)) ** 2 == i: a.append(i) else: b.append(i) if len(a) >= len(b): ans = 0 a = sorted(a) for i in range(len(a) - 1, len(a) - (len(a) - len(b)) // 2 - 1, -1): if a[i] != 0: ans...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_C...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) arr = list(map(int, input().strip().split(" "))) sq = 0 nsq = 0 sqq = [] nsqq = [] for i in arr: t = int(i**0.5) if t * t == i: sq += 1 sqq.append(i) else: nsq += 1 nsqq.append(i) if sq == nsq: print(0) elif sq > nsq: d = sq - n // 2 cost = [] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FU...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
perfectsquares = set(x**2 for x in range(10**5 + 1)) N = int(input()) array = [int(x) for x in input().split()] squares, notsquares = [0, 0] squarelist = [] notsquarelist = [] for i in array: if i in perfectsquares: squares += 1 squarelist.append(i) else: notsquares += 1 notsquar...
ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR N...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) cnt1 = 0 cnt2 = 0 ok = [] ng = [] for i in range(n): b = a[i] if int(b**0.5) ** 2 == b: cnt1 += 1 if b == 0: ok.append(2) else: ok.append(1) else: cnt2 += 1 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR NUMBER E...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
def ispow(c): x = int(c**0.5) return x * x == c or (x + 1) * (x + 1) == c or (x + 2) * (x + 2) == c n = int(input()) a = list(map(int, input().split())) kb = [] nk = [] for i in range(n): if ispow(a[i]): if a[i] == 0: kb.append(2) else: kb.append(1) else: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER 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 LIST FOR VAR FU...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) li = input().strip().split(" ") nums = [] ct = 0 zeros = 0 for i in li: i = int(i) if i == 0: zeros += 1 if round(i**0.5) ** 2 == i: ct += 1 tmp = int(i**0.5) nums.append(min(i - tmp * tmp, (tmp + 1) ** 2 - i)) nums.sort() half = int(n / 2) if ct <= half: print(s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) a = list(map(int, input().split())) x = [] for i in a: s = i**0.5 s = round(s) x.append((abs(s**2 - i), i)) x.sort() n2 = n // 2 ans = 0 for i in range(n2): ans += x[i][0] for i in range(n2, n): if x[i][0] == 0: if x[i][1] == 0: ans += 2 else: ...
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 FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUM...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) s = 0 kolzero = 0 l = [int(i) for i in input().split()] kv = 0 for i in range(n): if int(l[i] ** 0.5) ** 2 == l[i]: kv += 1 g = [0] * n for i in range(n): if l[i] == 0: kolzero += 1 a = int(l[i] ** 0.5) b = a + 1 a = a**2 b = b**2 if l[i] - a < b - l[i]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR N...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) t = [] l = [] d = 0 c = 0 j = 0 s = 0 w = 0 sum = 0 def rtu(f): if int(f**0.5) == f**0.5: return 1 else: return 0 t = input() t = list(map(int, t.split(" "))) for k in range(0, n): if t[k] == 0: w = w + 1 r = t[k] ** 0.5 if rtu(t[k]) == 1: c = c +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR F...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
r = 0 n = int(input()) ps = [int(x) for x in input().split()] mp = [] for y in ps: if y > 0 and y - int(y ** (1 / 2)) ** 2 != 0: mp.append( min(abs(y - int(y ** (1 / 2)) ** 2), abs(y - (int(y ** (1 / 2)) + 1) ** 2)) ) elif y > 0 and y - int(y ** (1 / 2)) ** 2 == 0: mp.append(...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP ...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) candies = list(map(int, input().strip().split())) def intkoren(n): k = int(n**0.5) while (k + 1) * (k + 1) <= n: k += 1 while k * k > n: k -= 1 return k cnt1 = 0 cnt2 = 0 new = [] for e in candies: u = intkoren(e) if e == 0: new.append((2, 1)) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIG...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) a = list(map(int, input().split())) cnt = [0] * n cc = [0] * n for i in range(n): c = int(a[i] ** 0.5) d = min(a[i] - c * c, (c + 1) ** 2 - a[i]) cnt[i] = [d, a[i]] cc[i] = d cnt.sort() cc.sort() print(sum(cc[0 : n // 2]) + cnt[n // 2 :].count([0, 0]) + cc[n // 2 :].count(0))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) a = list(map(int, input().split())) l, p, q = [], 0, 0 for i in a: if i == 0: p += 1 else: t = int(i**0.5) s = i - t**2 if s == 0: p += 1 q += 1 else: s = min(s, 2 * t + 1 - s) l.append(s) if p > n // 2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) f = lambda x: min(x - int(x**0.5) ** 2, (int(x**0.5) + 1) ** 2 - x) a = sorted([[f(int(i)), int(i)] for i in input().split()]) ans = sum(i[0] for i in a[: n // 2]) + sum( (int(i[1] ** 0.5) ** 2 == i[1]) + (i[1] == 0) for i in a[n // 2 :] ) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FU...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) a = list(map(int, input().split())) squares = [] not_squares = [] for i in range(n): cur = a[i] if int(cur**0.5) ** 2 == cur: squares.append(cur) else: not_squares.append(cur) num_move = (len(squares) - len(not_squares)) // 2 if num_move == 0: print(0) elif num_move > 0:...
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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) f = lambda x: abs(int(x**0.5 + 0.5) ** 2 - x) a = list(map(lambda x: [f(int(x)), int(x)], input().split())) a.sort() ans = sum(i[0] for i in a[: n // 2]) + sum( (i[0] == 0) + (i[1] == 0) for i in a[n // 2 :] ) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR V...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) l = list(map(int, input().split())) ll = [] l.sort() for i in range(n): ll.append( [min(l[i] - int(l[i] ** 0.5) ** 2, (int(l[i] ** 0.5) + 1) ** 2 - l[i]), i] ) ll.sort() ans = 0 if ll[n // 2][0] == 0: i = n // 2 while ll[i][0] == 0: if l[ll[i][1]] == 0: ans +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR ...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) A = list(map(int, input().split())) ns = 0 s = 0 N = [] S = [] for i in range(n): if A[i] ** 0.5 != int(A[i] ** 0.5): ns += 1 N.append(A[i]) else: S.append(A[i]) s = n - ns if ns < n // 2: a = n // 2 - ns for i in range(len(S)): if S[i] == 0: ...
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 NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VA...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
from sys import stdin, stdout sze = 10**5 power = [] for i in range(sze): power.append(i * i) def sqrt(v): l, r = 0, sze while r - l > 1: m = l + r >> 1 if power[m] <= v: l = m else: r = m return l def add_f(v): if not v: first.append(2) ...
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_C...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) a = map(int, input().split()) x = [] for i in a: r = int(i**0.5) x.append((min(i - r * r, (r + 1) ** 2 - i), i)) x.sort() if x[n // 2][0] != 0: ans = 0 for i in range(0, n // 2): ans += x[i][0] print(ans) else: ans, i = 0, n // 2 while i < n and x[i][0] == 0: ...
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 ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
d = lambda x: abs(int(x**0.5 + 0.5) ** 2 - x) n = int(input()) // 2 a = sorted([[d(int(x)), int(x)] for x in input().split()]) print(sum(i[0] for i in a[:n]) + sum((i[0] == 0) + (i[1] == 0) for i in a[n:]))
ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR ...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
def main(): R = lambda t: tuple(map(t, input().split())) rn = lambda: R(int) n = rn()[0] def cnt(v): sq = int(v ** (1 / 2)) return min(v - sq**2, (sq + 1) ** 2 - v) l = sorted((cnt(v), v) for v in rn()) ans = 0 for i in range(n // 2): ans += l[i][0] for i in ran...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) L = list(map(int, input().split())) def getkey(item): return item[1] def getKey(item): return item[0] def finds(n): rac = n ** (1 / 2) rac = int(rac) p = rac**2 q = (rac + 1) ** 2 return min(abs(n - q), abs(n - p)) D = [] for i in range(len(L)): D.append((L[i], f...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN VAR NUMBER FUNC_DEF RETURN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN ...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) a = list(map(int, input().split())) def isqrt(n): x = n y = (x + 1) // 2 while y < x: x = y y = (x + n // x) // 2 return x cnt = [0] * n p = 0 q = 0 sqrtCount = 0 ans = 0 for i in range(n): x = isqrt(a[i]) if a[i] == x * x: sqrtCount += 1 if a...
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 BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSI...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
n = int(input()) a = [int(i) for i in input().split()] b, v, ans = [], [], 0 for i in a: c = int(i ** (1 / 2)) if c * c == i or (c + 1) * (c + 1) == i or (c - 1) * (c - 1) == i: b.append(i) b.sort(reverse=True) for i in range(len(b) - n // 2): if b[i] == 0: ans += 2 else: ans += ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST LIST NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER IF BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXP...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
def isPerfect(n): s = int(n**0.5) if n == s**2: return True else: return False def PerfectUp(n): s = int(n**0.5) return (s + 1) ** 2 def PerfectDown(n): s = int(n**0.5) return s**2 n = int(input()) l = input().split() p = [] np = [] for i in range(0, len(l)): l[i] =...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN V...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
from sys import stdin, stdout n = int(stdin.readline().rstrip()) a = list(map(int, stdin.readline().rstrip().split())) a.sort() squareList = [(i * i) for i in range(int(1000000000**0.5) + 2)] squareCount = 0 zeroCount = 0 lowerSquare = -1 upperSquare = 0 index = 0 distanceList = [] for x in a: while x > upperSquar...
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 ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR...
Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is n...
def nexqd(x): l = 0 r = 100000 while r - l > 1: m = (l + r) // 2 if m**2 > x: r = m else: l = m return min(r**2 - x, x - l**2) def nexunqd(x): if 0 == x: return 2 if nexqd(x) == 0: return 1 return 0 n = int(input()) L = [] f...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_DEF IF NUMBER VAR RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN N...
Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy! The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time o...
n = int(input()) s = [0] * n g = [0] * n for i in range(n): a, b = list(map(int, input().split())) s[i] = a g[i] = a + b for i in range(1, n): g[i] = min(g[i], g[i - 1] + 1) for i in range(n - 2, -1, -1): g[i] = min(g[i], g[i + 1] + 1) ans = 0 for i in range(n): if s[i] <= g[i]: ans += g...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR V...
Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy! The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time o...
t = [] l = [] r = [] for _ in range(int(input())): s, g = map(int, input().split()) t.append(s) l.append(s) r.append(g + s) for i in range(1, len(l)): if l[i] < l[i - 1]: l[i] = l[i - 1] - 1 if r[i] > r[i - 1]: r[i] = r[i - 1] + 1 for i in range(len(l) - 2, -1, -1): if l[i] <...
ASSIGN VAR LIST ASSIGN VAR LIST 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 EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIG...
Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy! The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time o...
n = int(input()) a = [] for i in range(n): a.append(list(map(int, input().split()))) a[i][1] += a[i][0] for i in range(1, n): if a[i][1] > a[i - 1][1] + 1: a[i][1] = a[i - 1][1] + 1 if a[i][1] < a[i][0]: exit(print(-1)) s = a[-1][1] - a[-1][0] for i in range(n - 2, -1, -1): i...
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 VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP ...
Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy! The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time o...
n = int(input()) ss = [0] * (n + 1) gg = [0] * (n + 1) maxs = [0] * n curMin = -(10**10) curMax = -curMin for i in range(n): s, g = map(int, input().split(" ")) ss[i] = s gg[i] = g curMin = max(curMin - 1, s) curMax = min(curMax + 1, s + g) if curMin > curMax: print(-1) exit(0) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, dest = list(map(int, input().split())) dest -= 1 a = list(map(int, input().split())) m1 = float("inf") m2 = float("inf") pos1 = -1 pos2 = -1 for i in range(dest + 1): if a[i] <= m1: m1 = a[i] pos1 = i for i in range(dest + 1, n): if a[i] <= m2: m2 = a[i] pos2 = i if m2 < m1: ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR V...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
def main(): n, x = map(int, input().split()) a = [int(i) for i in input().split()] j = x - 1 z = min(a) while a[j] != z: if j == 0: j = n - 1 else: j -= 1 m = a[j] k = 0 if x - 1 > j: for i in range(n): if j < i <= x - 1: ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR FOR V...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, x = map(int, input().split()) a = list(map(int, input().split())) t = min(a) if t != 0: for i in range(n): a[i] -= t - 1 i = x - 1 c = 0 while a[i] != 0: a[i] -= 1 c += 1 i -= 1 if i == -1: i = n - 1 a[i] += c + max(t - 1, 0) * n for i in a: print(i, end=" ")
ASSIGN VAR 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 VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUM...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, x = map(int, input().split()) t = list(map(int, input().split())) m = min(t[:x]) if m == 0: i = x - 1 while t[i]: i -= 1 t[i + 1 : x] = [(j - 1) for j in t[i + 1 : x]] t[i] = x - i - 1 else: t[:x] = [(i - 1) for i in t[:x]] m = min(t) if m: t = [(i - m) for i in t] i =...
ASSIGN VAR 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 VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, x = list(map(int, input().split())) a = list(map(int, input().split())) idx = x % n for j in range(x, x + n): if a[j % n] <= a[idx]: idx = j % n temp = a[idx] a[idx] += n * temp a = [(i - temp) for i in a] j = idx + 1 while j % n != x % n: a[j % n] -= 1 j += 1 a[idx] += 1 print(*a)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, x = map(int, input().split()) a = list(map(int, input().split())) m = min(a) a = [(i - m) for i in a] x = x - 1 d = m * n while a[x] > 0: d += 1 a[x] -= 1 x -= 1 if x < 0: x = n - 1 a[x] = d print(*a)
ASSIGN VAR 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 VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, x = map(int, input().split()) a = list(map(int, input().split())) m = min(a) f = x - 1 for i in range(n): if a[f] == m: st = f break f = (f - 1) % n c = m + 1 ct = 0 for i in range(n): a[st] -= c ct += c if st == x - 1: c -= 1 st = (st + 1) % n a[st] = ct - 1 print(*a)
ASSIGN VAR 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 VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NU...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
import sys input = sys.stdin.readline def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(" "))) def solve(): n, x = read_ints() a = read_ints() last_min_j = x % n for j in range(x, x + n): if a[j % n] <= a[last_min_j]: ...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, k = map(int, input().split()) l = list(map(int, input().split())) a = l.index(min(l)) m = l[a] + 1 c = 0 f = k - 1 for i in range(n): if l[f] == l[a]: d = f break f = (f - 1) % n for i in range(n): l[d] -= m c += m if d == k - 1: m -= 1 d = (d + 1) % n l[d] = c - 1 pri...
ASSIGN VAR 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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BI...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n = [int(num) for num in input().split()] x = [int(num) for num in input().split()] i = n[1] - 1 j = (i - 1) % n[0] while j != n[1] - 1: if x[j] < x[i]: i = j j = (j - 1) % n[0] p = x[i] j = (n[1] - i - 1) % n[0] if p != x[n[1] - 1]: x[i] = p * n[0] + j i = i + 1 else: x[n[1] - 1] = p * n[0]...
ASSIGN 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 BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN ...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, x = list(map(int, input().split())) a = list(map(int, input().split())) m = min(a) a = [(v - m) for v in a] d = m * n x = x - 1 while a[x] > 0: d = d + 1 a[x] = a[x] - 1 x = x - 1 if x < 0: x = n - 1 a[x] = d print(" ".join(map(str, a)))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, x = map(int, input().split()) a = list(map(int, input().split())) x -= 1 y = max(0, min(a)) for i in range(n): a[i] -= y flag = False cnt = 0 for i in range(x, -1, -1): if a[i] == 0: a[i] = cnt + y * n flag = True break a[i] -= 1 cnt += 1 for i in range(n - 1, x, -1): if f...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASS...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
l = input().split() n = int(l[0]) x = int(l[1]) l = input().split() li = [int(i) for i in l] mina = li[0] ind = 0 for i in range(1, n): if li[i] <= mina: ind = i mina = li[i] indexofx = x - 1 for i in range(n): if li[(indexofx + n - i) % n] == mina: ind = (indexofx + n - i) % n b...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP V...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, l = input().split() n = int(n) l = int(l) l = l - 1 a = list(map(int, input().split())) min = float("inf") for i in range(n - 1, -1, -1): if a[i] < min: min = a[i] pos = i if a[l] == min: pos = l if l >= pos: for i in range(0, n): a[i] -= min for i in range(pos + 1, l + 1): ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN ...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
def solve(n, x, seq): x -= 1 _min = min(seq) s = sum(seq) idx = -1 for i in range(x, -1, -1): if seq[i] == _min: idx = i break else: for j in range(n - 1, x, -1): if seq[j] == _min: idx = j break for i in ran...
FUNC_DEF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BI...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, x = map(int, input().split()) x = x - 1 l = list(map(int, input().split())) min_index, min_value = -1, 10**9 + 7 nb_seen = 0 cur = x while nb_seen != n: if min_value > l[cur]: min_value = l[cur] min_index = cur cur = (n - 1 + cur) % n nb_seen += 1 min_value = l[min_index] for i in range(n...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
import sys lines = sys.stdin.readlines() n, x = map(int, lines[0].strip().split(" ")) nums = list(map(int, lines[1].strip().split(" "))) minSoFar = min(nums) index = -1 for i in range(x + n - 1, x - 1, -1): if nums[i % n] == minSoFar: index = i % n break tmp = nums[index] num = tmp * n + (x - 1 + n...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, x = map(int, input().split()) A = {} L = list(map(int, input().split())) minn = min(L) ind = x - 1 while L[ind] != minn: ind -= 1 if ind == -1: ind = n - 1 iterations = L[ind] Diff = [0] * n r = 1 inc = True if x - 1 == ind: inc = False i = ind + 1 start = True rem = 0 while i != ind + 1 or start...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER V...
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ...
n, x = map(int, input().strip().split()) a = list(map(int, input().strip().split())) m = min(a) x -= 1 pos = -1 for i in range(n): if a[i] == m: pos = i if i == x and pos != -1: break for i in range(n): a[i] -= m a[pos] += m if x != pos: i = (pos + 1) % n while i != x: a[...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VA...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = input() def solve(s): if n % 2 == 1: return ":(" s = list(s) cnt = n // 2 - sum(1 if i == "(" else 0 for i in s) if cnt < 0: return ":(" l = 0 for i, c in enumerate(s): if c == "(": l += 1 elif c == "?": if cnt > 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR STRING NUMBER NUMBER VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
import sys def main(): n = int(input()) s = list(sys.stdin.readline()) f, ouv = 0, 0 for i in range(n): if s[i] == "?" or s[i] == "(": ouv += 1 else: f += 1 ouv -= 1 if i < n - 1 and ouv <= 0: print(":(") exit(0) f...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NU...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
import sys sys.setrecursionlimit(20000000) input = sys.stdin.readline n = int(input()) s = input().rstrip() ans = [] count = 0 for i in s: if i == "(": ans.append(1) elif i == ")": ans.append(-1) else: ans.append(0) count += 1 x = sum(ans) if abs(x) > count or x % 2 != count...
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUN...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
def valid(s): arr = [] for i in s: if i == "(": arr.append("(") elif len(arr) > 0 and arr[len(arr) - 1] == "(": arr.pop() else: return 0 return not len(arr) def solve(): N = int(input()) s = input() result = [""] * N op = 0 cl...
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN ...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) data = list(input()) if data[0] == ")" or data[-1] == "(": print(":(") exit(0) now = 0 data[0] = "(" data[-1] = ")" haveO = (n - 2) // 2 haveC = (n - 2) // 2 for i in range(1, n - 1): if data[i] == "(": haveO -= 1 elif data[i] == ")": haveC -= 1 for i in range(1, n - 1):...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMB...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
def test_solve(s): n = len(s) s = list(s) olds = s[:] missing = [i for i in range(n) if s[i] == "?"] tot = sum(c == "(" for c in s) - sum(c == ")" for c in s) if ( (len(missing) - tot) % 2 != 0 or len(missing) - tot < 0 or len(missing) + tot < 0 ): return ":("...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR STRING VAR VAR FUNC_CALL VAR VAR STRING VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_C...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = input() string = "" scnt = 0 scntleft = s.count("(") scntright = s.count(")") em = 0 if n % 2 == 1: em = 1 elif scntleft > n / 2 or scntright > n / 2: em = 1 else: for i in range(n): if s[i] == "(": string += s[i] scnt += 1 elif s[i] == ")": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR I...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
import sys def main(): inp = sys.stdin.read().split() ii = 0 n = int(inp[ii]) ii += 1 s = list(inp[ii]) if n % 2: print(":(") sys.exit() a = n // 2 - s.count("(") b = n // 2 - s.count(")") if a < 0 or b < 0: print(":(") sys.exit() for i in range(...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR S...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
def brackets(n, s): s = list(s) if n % 2: return ":(" count1, count2 = n // 2, 0 for i in range(n): if s[i] == "(": count1 -= 1 for i in range(n): if s[i] != "?": continue if count1 > 0: s[i] = "(" count1 -= 1 el...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER RETURN STRING ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR ST...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
def get_answer(n, s): if n % 2: return ":(" L = s.count("(") if L > n // 2: return ":(" s = s.replace("?", "(", n // 2 - L) s = s.replace("?", ")") L = R = 0 for i in range(n - 1): if s[i] == "(": L += 1 else: R += 1 if L <= R: ...
FUNC_DEF IF BIN_OP VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR STRING STRING BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUM...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
l = int(input()) str = input() str_list = [] cur_open = 0 cur_close = 0 start = -1 cur = 0 def find(str_list, open_cur, close_cur): for i in range(len(str_list)): if str_list[i] == "?": if 2 * open_cur == len(str_list): str_list[i] = ")" else: str_li...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER FUNC_DE...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
length = int(input()) string = input() LeftParens = 0 questionMarks = 0 imposs = False moreLeftAndQ = 0 moreRightAndQBack = 0 if length % 2 == 1: imposs = True for i in range(length - 1): if string[i] == "(": LeftParens += 1 moreLeftAndQ += 1 elif string[i] == ")": moreLeftAndQ -= 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMB...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = input() cnt = 0 bal = 0 if n % 2 == 1 or s[0] == ")": print(":(") exit(0) for i in range(n): if s[i] == "?": cnt += 1 elif s[i] == "(": bal += 1 else: bal -= 1 ans = "" o = 0 c = 0 if cnt % 2 != bal % 2 or cnt < abs(bal): print(":(") exit(0) else:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR STRING ASSIGN VA...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = input() s = list(s) oc = 0 cc = 0 occ = s.count("(") ccc = s.count(")") flag = 0 if n % 2 != 0: flag = 1 for i in range(n): if s[i] == "(": oc += 1 elif s[i] == ")": cc += 1 elif occ < n // 2: s[i] = "(" oc += 1 occ += 1 else: s[i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR V...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input().strip()) string = input().strip() if n % 2 != 0: print(":(") else: ans = "" if string[0] == ")" or string[-1] == "(": print(":(") else: bad = False stack = [] ans = ["("] num = [0, 0] for i in string: if i == "(": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST STRING ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR ...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) o = 0 c = 0 s = input() if n % 2 == 1: print(":(") exit(0) for i in range(n): if s[i] == "(": o += 1 elif s[i] == ")": c += 1 o = n // 2 - o c = n // 2 - c count = 0 result = "" for i in range(n): if s[i] == "?": if o > 0: result += "(" ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_O...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
s = int(input()) string = input() if s % 2 == 1: print(":(") exit(0) output = list(string) o = string.count("(") running = 0 solvable = True for i, x in enumerate(string): if x == "(" or x == ")": if x == "(": o -= 1 running += 1 else: running -= 1 if ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING IF VAR STRING VAR NUMBER...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
import sys input = sys.stdin.readline n = int(input()) a = list(input()) if n % 2 != 0: print(":(") else: b = a.count("(") c = a.count(")") if b > n // 2 or c > n // 2: print(":(") else: b = n // 2 - b c = n // 2 - c d = 0 for i in range(n): if a[...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR ...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
_DEBUG = True n = int(input()) s = input() def solve(s): ns = list(s) l = len(ns) lc = rc = 0 for e in s: if e == "(": lc += 1 elif e == ")": rc += 1 l_stack = 0 for i in range(l): e = s[i] if e == "(": l_stack += 1 el...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR NUMBER...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
def solve(s): op = len(s) // 2 cl = len(s) // 2 for i in range(len(s)): if s[i] == "(": op -= 1 elif s[i] == ")": cl -= 1 res = list(s) pcl = pop = 0 for i in range(len(s) - 1, -1, -1): if s[i] == "?": if cl > 0: res[i] ...
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR V...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = list(input()) if n % 2 == 0: if s.count("(") > n // 2 or s.count(")") > n // 2: print(":(") else: open = n // 2 - s.count("(") close = n // 2 - s.count(")") i = 0 while i < n and open > 0: if s[i] == "?": s[i] = "(" ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR STRING BIN_OP VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR ...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
def verif(list, length, p): suma = 0 for k in range(p, length): if list[k] == "(": suma += 1 else: suma -= 1 if suma < 0: return False if suma == 0: return True return False l = int(input()) s = input() if l % 2 != 0: print(":(") ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
import sys def check(s): status = 0 for char in s[:-1]: if char == "(": status += 1 else: status -= 1 if status <= 0: return ":(" return s n = int(input()) s = input() if n % 2 != 0: print(":(") else: leftcount = 0 rightcount = 0 ...
IMPORT FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN STRING RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER I...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
y = input() x = list(input()) c, d, e, f = 0, 0, 0, 0 z = True for i in range(len(x)): if x[i] == "(": d += 1 elif x[i] == ")": d -= 1 else: c += 1 if len(x) % 2 == 1: z = False print(":(") break if z: for i in range(len(x)): if x[i] == "?" and...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = list(input()) def findbal(a, th=0): b = 0 for c in a: if c == "(": b += 1 elif c == ")": b -= 1 if th > 0 and b < th: return b return b can = s[0] != ")" and s[-1] != "(" and n % 2 == 0 if can: s[0] = "(" s[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR RETURN VAR RETURN VAR ASSIGN VAR VAR NUMBER STRING VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER IF VAR ASSIGN VAR NUMBER STRIN...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
def calc(): N = int(input()) s = input() A = [[0, 0] for _ in range(N)] B = [0] * (N + 1) if N % 2 or s[0] == ")" or s[-1] == "(": return ":(" for i in range(N - 1): if s[i] == "(": A[i + 1][0] = A[i][0] + 1 A[i + 1][1] = A[i][1] + 1 elif s[i] == "...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER STRING VAR NUMBER STRING RETURN STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP ...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = list(input()) a = s.count("(") b = 0 for i in range(len(s)): if s[i] == "?": if a < n // 2: s[i] = "(" a += 1 else: s[i] = ")" b += 1 if s[i] == "(" else -1 if b <= 0 and i != n - 1: print(":(") raise SystemExit print("...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING VAR VAR VAR STRING NUMBER NUMBER IF VAR NUMBER VAR BIN...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = list(input()) l, r = s.count("("), s.count(")") for i in range(n): if s[i] == "?": if l + l < n: s[i] = "(" l += 1 else: s[i] = ")" cnt = 0 for i in range(n): cnt += 1 if s[i] == "(" else -1 if cnt < 1 and i < n - 1: print(":("...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING N...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) a = list(input()) if n % 2: print(":(") else: if "?" == a[0]: a[0] = "(" if "?" == a[-1]: a[-1] = ")" if a[0] != "(" or a[-1] != ")": print(":(") else: l = n // 2 - a.count("(") r = n // 2 - a.count(")") if l < 0 or r < 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF STRING VAR NUMBER ASSIGN VAR NUMBER STRING IF STRING VAR NUMBER ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FU...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = input() f = 1 p = "" pos = [] if s[0] == ")" or n % 2 == 1: f = 0 else: p += "(" k = 1 for i in range(1, n - 1): if k < 1: if len(pos) > 0: ind = pos.pop() p = p[:ind] + "(" + p[ind + 1 :] k += 2 else: f = 0 bre...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR LIST IF VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL V...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
import sys input = sys.stdin.readline n = int(input()) s = list(input().strip()) if n % 2 == 1: print(":(") return if n == 2: if s[0] == ")" or s[1] == "(": print(":(") return else: print("()") return if s[0] == ")" or s[1] == ")" or s[-1] == "(" or s[-2] == "(": pri...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER STRING VAR NUMBE...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
input() s = input() if len(s) & 1: print(":(") raise SystemExit(0) max_open, min_open = 0, 0 started = False q_mark = 0 op = 0 cl = 0 ended = False for c in s: if ended: print(":(") raise SystemExit(0) if min_open <= 0 and started: min_open = 1 started = True if c == "(":...
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING FUNC_CALL VAR NUMBER IF VAR NU...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = input() ln = len(s) pt = ln // 2 if ln % 2 != 0: print(":(") elif s[0] == ")" or s[-1] == "(": print(":(") else: L1 = [0] * len(s) L2 = [0] * len(s) t1 = 0 t2 = 0 for i in range(len(s) - 1, -1, -1): L1[i] = t1 L2[i] = t2 if s[i] == "(": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER F...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
N = int(input()) S = input() if N % 2 != 0 or S[0] == ")" or S[N - 1] == "(": print(":(") else: left = 0 new_S = ["("] for c in S[1 : N - 1]: new_S.append(c) if c == "(": left += 1 new_S.append(")") left = N / 2 - left - 1 new_S[0] = "(" new_S[N - 1] = ")" ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST STRING FOR VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING ASS...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = list(input()) a, b = s.count("("), 0 for i in range(n): if s[i] == "?": if a < n // 2: s[i] = "(" a += 1 else: s[i] = ")" if s[i] == "(": b += 1 else: b -= 1 if b < 0 or (b == 0 if i + 1 != n else b != 0): p...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = input() def f(): level = 0 blank = 0 filled = [] for i, c in enumerate(s): if c == "(": level += 1 elif c == ")": level -= 1 if level < 0: if blank < 0: return filled.append("("...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR NUMBER IF VAR NUMBER RETURN EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST WHILE...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
import sys n = int(input()) s = input() if n % 2 == 1 or s[0] == ")" or s[-1] == "(": print(":(") sys.exit(0) n -= 2 s = s[1:-1] mas = [] kol1 = 0 kol2 = 0 for i in range(n): if s[i] == "?": mas.append(0) elif s[i] == "(": mas.append(-1) kol1 += 1 else: mas.append(1)...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRI...
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
import sys n = int(input()) raw = input() st = [item for item in raw] if n & 1: print(":(") sys.exit() left = st.count("(") if left > n // 2: print(":(") sys.exit(0) if st[0] == "?": st[0] = "(" if st[len(st) - 1] == "?": st[len(st) - 1] = ")" le = 0 if st[0] == "(" and st[len(st) - 1] == ")": ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VA...