description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
n, m = map(int, input().split(" ")) grid = [] for i in range(n): grid.append(input()) frontier = [(0, 0)] total = 0 while len(frontier) > 0: cur = frontier.pop(0) if cur[0] < n and cur[1] < m: if grid[cur[0]][cur[1]] == "*": total += 1 frontier = [] frontier.append((c...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER STRING V...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
from sys import stderr, stdin input = stdin.readline def dbp(*args, **kwargs): pass def get_int_list(): return [int(x) for x in input().strip().split()] h, w = get_int_list() rows = [input().strip() for _ in range(h)] r = c = t = eaten = 0 while r < h and c < w: dbp(r, c, h, w, eaten) if rows[r][...
ASSIGN VAR VAR FUNC_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUN...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
n, m = map(int, input().split()) field = [] for line in range(n): field.append(list(input())) x = 0 y = 0 berries = 0 while x != m - 1 or y != n - 1: if field[y][x] == "*": berries += 1 if x == m - 1: y += 1 elif y == n - 1: x += 1 elif field[y][x + 1] == "*": x += 1 ...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER I...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
def canReach(x1, y1, x2, y2): return x1 <= x2 and y1 <= y2 def nearest(x, y): global cake, H, W for i in range(H * W): x2, y2 = repere[i] if canReach(x, y, x2, y2) and cake[y2][x2] == "*": return x2, y2 return None, None H, W = map(int, input().split()) cake = [] repere =...
FUNC_DEF RETURN VAR VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR STRING RETURN VAR VAR RETURN NONE NONE ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
s = [] n, m = map(int, input().split()) for i in range(n): s.append(input()) x, y = 0, 0 z = 0 if s[x][y] == "*": z += 1 while x < n - 1 or y < m - 1: if x == n - 1: y += 1 elif y == m - 1: x += 1 elif s[x][y + 1] == "*": y += 1 elif s[x + 1][y] == "*": x += 1 ...
ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMB...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
h, w = map(int, input().split()) a = [] for i in range(h): a.append(input()) i = 1 j = 1 res = 0 dir = True while i < h or j < w: if a[i - 1][j - 1] == "*": res += 1 if i == h: j += 1 elif j == w: i += 1 elif a[i][j - 1] == a[i - 1][j]: j += 1 elif a[i][j - 1] == ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR ...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
H, W = map(int, input().split()) rows = [] for _ in range(H): rows.append(input()) ans = 0 x, y = 0, 0 while True: ans += rows[x][y] == "*" if (x, y) == (H - 1, W - 1): break nx, ny = None, None mindist = float("inf") for i in range(x, H): for j in range(y, W): if row...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE NUMBER VAR VAR VAR VAR STRING IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NONE NONE ASSIGN VAR FUNC_CALL VAR STRING F...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
class Test: def __init__(self): self.a = 1 def input(self): line = input() line = [int(i) for i in line.split(" ")] M, N = line[0], line[1] map = [] for i in range(M): line = input().strip() line = [i for i in line] map.append...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
h, w = map(int, input().split()) grid = [input() for i in range(h)] x = 0 y = 0 ans = 0 while x < h - 1 or y < w - 1: if grid[x][y] == "*": ans += 1 if x == h - 1: y += 1 elif y == w - 1: x += 1 else: d1 = 200 d2 = 200 for i in range(x, h): for...
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 NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN ...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
h, w = [int(i) for i in input().strip().split()] l = [[i for i in input()] for i in range(h)] count = 0 i, j = 0, 0 if l[0][0] == "*": count += 1 while True: if i == h - 1 and j == w - 1: break down = -1 right = -1 if i + 1 < h: if l[i + 1][j] == "*": down = 1 els...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER STRING VAR NUMBER WHILE NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VA...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
def calc_dist(t1, t2): x1, y1 = t1 x2, y2 = t2 return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5 h, w = [int(x) for x in input().split()] arr = [["0"] * w] * h locations = [] for i in range(h): line = [x for x in input()] for j in range(w): if line[j] == "*": locations.append([i,...
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP LIST STRING VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR F...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
H, W = map(int, input().split()) S = [input() for i in range(H)] x, y = 0, 0 ans = 0 if S[0][0] == "*": ans += 1 while True: nx, ny = None, None for i in range(H): for j in range(W): if S[i][j] == "*" and i >= x and j >= y and (i, j) != (x, y): if nx == None: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER STRING VAR NUMBER WHILE NUMBER ASSIGN VAR VAR NONE NONE FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR VAR VA...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
n, m = map(int, input().split()) q = [input() for i in range(n)] i = j = c = 0 while 1: c += q[i][j] == "*" if i == n - 1 and j == m - 1: break if i == n - 1: j += 1 elif j == m - 1: i += 1 elif q[i + 1][j] == "*": i += 1 elif q[i][j + 1] == "*": j += 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE NUMBER VAR VAR VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR STRING...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
n, m = map(int, input().split()) cake = [list(input()) for i in range(n)] loc = 0, 0 ans = 1 if cake[0][0] == "*" else 0 while loc != (n, m): best = 1000 bestloc = n, m x, y = loc for i in range(x, n): for j in range(y, m): if cake[i][j] == "*" and (i, j) != (x, y): d...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER STRING NUMBER NUMBER WHILE VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR V...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
h, w = map(int, input().split()) board = [input() for _ in range(h)] out = 0 cx = 0 cy = 0 if board[0][0] == "*": out += 1 while True: poss = [] for i in range(h): for j in range(w): if board[i][j] == "*" and i >= cx and j >= cy and i + j > cx + cy: poss.append((i + j, i,...
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 NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER STRING VAR NUMBER WHILE NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR VAR BIN_...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
h, w = map(int, input().split()) a = [] for _ in range(h): a.append(input()) i, j, k = 0, 0, 0 while i < h: if a[i][j] == "*": k += 1 if i != h - 1 and a[i + 1][j] == "*" or j == w - 1: i += 1 else: j += 1 print(k)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
import sys h, w = map(int, input().split()) lines = [] for i in range(h): lines.append(input()) ci, cj = 0, 0 ans = 1 if lines[0][0] == "*" else 0 while True: ni, nj = 1000, 1000 for i in range(ci, h): for j in range(cj, w): if ( i + j > ci + cj and lines...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER STRING NUMBER NUMBER WHILE NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
n, m = map(int, input().split()) grid = [input() for i in range(n)] ci, cj = 0, 0 ate = 0 if grid[0][0] == "*": ate += 1 while 1: berry = [] for i in range(ci, n): for j in range(cj, m): if ci == i and cj == j: continue if grid[i][j] == "*": be...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER STRING VAR NUMBER WHILE NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR STRING ...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
def fun(i, j): if i >= hw[0] or j >= hw[1]: return [10000, i, j] if a[i][j] == "*": return [0, i, j] else: right = fun(i + 1, j) down = fun(i, j + 1) if right[0] < down[0]: right[0] += 1 return right else: down[0] += 1 ...
FUNC_DEF IF VAR VAR NUMBER VAR VAR NUMBER RETURN LIST NUMBER VAR VAR IF VAR VAR VAR STRING RETURN LIST NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER RETURN VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL ...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
n, m = map(int, input().split()) a = [] for i in range(n): p = input() new = [] for j in range(m): new.append(p[j]) a.append(new) ans = 0 x = 0 y = 0 while x != n - 1 or y != m - 1: if a[x][y] == "*": ans += 1 if y != m - 1 and ( x + 1 < n and a[x + 1][y] == "." or y + 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
n, m = map(int, input().split()) anime = [] for i in range(n): s = input() anime.append(s) x = 0 y = 0 ans = 0 if anime[0][0] == "*": ans += 1 while True: a = n b = m for i in range(x, n): for j in range(y, m): if (i != x or j != y) and anime[i][j] == "*" and a + b > i + j: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER STRING VAR NUMBER WHILE NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FOR VAR...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
h, w = map(int, input().split()) grid = [] for i in range(h): grid.append(input()) r, c = 0, 0 ans = 0 for i in range(h + w - 2): if grid[r][c] == "*": ans += 1 if r == h - 1: c += 1 continue if c == w - 1: r += 1 continue right = 111111, 111 for row in ra...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUM...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
h, w = map(int, input().split(" ")) s = [] for i in range(h): s.append(input()) i = 0 j = 0 c = 0 while i < h or j < w: if s[i][j] == "*": c = c + 1 if j < w - 1 and s[i][j + 1] == "*": j = j + 1 elif i < h - 1 and s[i + 1][j] == "*": i = i + 1 elif i == h - 1 and j < w - 1: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STR...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
import sys def getDist(i, j, ii, jj): return abs(ii - i) + abs(jj - j) def main(): n, m = readIntArr() grid = [] for _ in range(n): grid.append(input()) berries = [] for i in range(n): for j in range(m): if grid[i][j] == "*": berries.append((i, j))...
IMPORT FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR AS...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
n, m = [int(i) for i in input().split()] a = [None] * n for i in range(n): a[i] = [(1 if i == "*" else 0) for i in input()] cc = 0, 0 res = 0 curdir = 1 while True: if a[cc[0]][cc[1]]: res += 1 if cc == (n - 1, m - 1): break distright = 1000 if cc[0] == n - 1: distright = 100...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR STRING NUMBER NUMBER VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
h, w = map(int, input().split(" ")) lis = [] for _ in range(h): lis.append(input()) i, j = 0, 0 count = 0 if lis[h - 1][w - 1] == "*": count += 1 while i != h - 1 or j != w - 1: if lis[i][j] == "*": count += 1 if j == w - 1: i = i + 1 elif i == h - 1: j = j + 1 try: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING V...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
n, m = map(int, input().split()) a = [[x for x in input()] for _ in range(n)] i = 0 j = 0 ans = 0 while True: found = False for x in range(100): for t in range(0, x + 1): ni = i + t nj = j + x - t if ni < n and nj < m and a[ni][nj] == "*": ans += 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
H, W = map(int, input().split()) cake = [([False] * W) for i in range(H)] for i in range(H): s = input() for j in range(W): if s[j] == "*": cake[i][j] = True x, y = 0, 0 ans = 0 while x < H and y < W: if cake[x][y]: ans += 1 if y < W - 1 and cake[x][y + 1]: y += 1 ...
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 ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VA...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
a, b = map(int, input().split()) matrix = [] for _ in range(a): l = input() matrix.append(l) x = 0 y = 0 c = 0 while x < a - 1 or y < b - 1: if matrix[x][y] == "*": c += 1 if x == a - 1: y += 1 continue elif y == b - 1: x += 1 continue xB = False yB = ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
h, w = list(map(int, input().split())) arr = [] points = [] for i in range(h): arr.append(input()) for j in range(len(arr[i])): if arr[i][j] == "*": points.append([i, j]) start = [0, 0] end = [h - 1, w - 1] cur = [0, 0] count = 0 while cur != end: min_dist = 100 next = [] for poi...
ASSIGN VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST BIN_OP VAR NUM...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
h, w = map(int, input().split()) arr = [input() for i in range(h)] a = 0 b = 0 cnt = int(arr[a][b] == "*") while True: x = 10**9 y = 10**9 for i in range(a, h): for j in range(b, w): if i == a and j == b: continue if arr[i][j] == ".": continue ...
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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR STRING WHILE NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
n, m = map(int, input().split()) a = [input() for i in range(n)] l = [] for i in range(n): for j in range(m): if a[i][j] == "*": l += [(i, j)] now = 0, 0 ans = int(now in l) while True: mn = 99 mnt = now for i in l: if i != now and i[0] >= now[0] and i[1] >= now[1] and mn > s...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR LIST VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR V...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
n, m = map(int, input().split()) a = [input() for i in range(n)] count = 0 i = 0 j = 0 for k in range(n + m - 1): if a[i][j] == "*": count += 1 look_down = -1 look_right = -1 for q in range(i + 1, n): if a[q][j] == "*": look_down = q for q in range(j + 1, m): if a...
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VA...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
r, c = map(int, input().split()) cake = [] for i in range(r): cake.append(list(input())) i = 0 j = 0 berries = 0 if cake[0][0] == "*": berries += 1 while i < r and j < c: if j + 1 < c and i < r: if cake[i][j + 1] == "*": berries += 1 j += 1 elif i + 1 < r and j < c: ...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER STRING VAR NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR BIN_OP VAR NUMB...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
from itertools import dropwhile, filterfalse, islice, takewhile def valida(coord): x, y = coord return not (x < cols and y < rens and matriz[y][x]) rens, cols = map(int, input().split()) matriz = [list(map(lambda x: x == "*", input())) for i in range(rens)] bayas = dist = x = y = 0 while x + y + dist < cols...
FUNC_DEF ASSIGN VAR VAR VAR RETURN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VA...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
y, x = list(map(int, input().split())) board = [] for i in range(y): board.append(input()) posX = 0 posY = 0 score = 0 turn = 0 last = "y" while True: if posY >= y or posX >= x: break if board[posY][posX] == "*": score += 1 if posX + 1 < x and board[posY][posX + 1] == "*": posX +...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE NUMBER IF VAR VAR VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBE...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
def try1(n, m): down = n right = m i = 0 j = 0 ans = 0 iter = 0 while i < n and j < m: if matrix[i][j] == "*": ans += 1 if i == n - 1: if j == m - 1: break else: j += 1 elif iter % 2 == 0 or j == m - ...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
a, b = map(int, input().split()) cake = [] for _ in range(a): cake.append([x for x in input()]) count = 0 x, y = 0, 0 while x < b and y < a: if cake[y][x] == "*": count += 1 if x < b - 1 and cake[y][x + 1] == "*": x += 1 elif y < a - 1 and cake[y + 1][x] == "*": y += 1 else: ...
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 VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BI...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
n, m = map(int, input().split()) g = [input() for i in range(n)] def rec(i, j, ans): if i == n - 1 and j == m - 1: print(ans + (g[i][j] == "*")) exit() add = g[i][j] == "*" if j == m - 1: return rec(i + 1, j, ans + add) if i == n - 1: return rec(i, j + 1, ans + add) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR STRING IF VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBE...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
h, w = [int(x) for x in input().split()] maps = [] for i in range(h): row = input() rows = [] for r in row: rows.append(r) maps.append(rows) ans = 0 if maps[0][0] == "." else 1 i, j = 0, 0 while not (i == h - 1 and j == w - 1): if j + 1 < w and maps[i][j + 1] == "*": j += 1 a...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER STRING NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP ...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
h, w = list(map(int, input().split())) t = [input() for _ in range(h)] collected = 0 curr_pos = 0, 0 if t[0][0] == "*": collected = 1 def collectable(i, j): return i >= curr_pos[0] and j >= curr_pos[1] def dist(i, j): return i - curr_pos[0] + (j - curr_pos[1]) while True: closest = None for i ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER FUNC_DEF RETURN VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
def clouded_strategy(H, W, cake): ans = int(cake[0][0] == "*") i, j = 0, 0 prev = "S" while (i, j) != (H - 1, W - 1): if i == H - 1 or j == W - 1: if i == H - 1 and j != W - 1: j += 1 if j == W - 1 and i != H - 1: i += 1 ans += ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR STRING WHILE VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER V...
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
n = int(input()) a = list(map(int, input().split())) sum = 0 for x in a: sum += x t = sum // n ans = 0 for i in range(n - 1): if a[i] < t: ans += t - a[i] a[i + 1] -= t - a[i] else: ans += a[i] - t a[i + 1] += a[i] - t print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VA...
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
n = int(input()) a = [int(i) for i in input().split()] av = sum(a) // len(a) ans = 0 s = 0 for i in a: s += i - av ans += abs(s) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
n = int(input()) a = list(map(int, input().split())) k = sum(a) s = 0 r = 0 for i in range(n): s += k // n - a[i] r += abs(s) print(r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
n = int(input()) arr = list(map(int, input().split())) k = sum(arr) // n moves = 0 for i in range(n - 1): arr[i + 1] += arr[i] - k moves += abs(k - arr[i]) print(moves)
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 FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
n = int(input()) a = list(map(int, input().split())) + [0] s = sum(a) // n d = 0 for i in range(n): if a[i] > s: a[i + 1] += abs(a[i] - s) else: a[i + 1] -= abs(a[i] - s) d += abs(a[i] - s) print(d)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_O...
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
n = int(input()) s = [int(i) for i in input().split()] k = sum(s) // n c = 0 for i in range(0, len(s) - 1): if s[i] == k: continue need = k - s[i] s[i + 1] -= need c += abs(need) print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CA...
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
def read(mode=2): inputs = input().strip() if mode == 0: return inputs if mode == 1: return inputs.split() if mode == 2: return [int(x) for x in inputs.split()] def write(s="\n"): if isinstance(s, list): s = " ".join(s) s = str(s) print(s, end="") (n,) = r...
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_DEF STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL...
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
import itertools n = int(input()) a = map(int, input().split()) a = list(itertools.accumulate(a)) need_one = a[-1] // n ans = 0 for i in range(len(a) - 1): ans += abs((i + 1) * need_one - a[i]) print(ans)
IMPORT 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 ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_C...
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
n = int(input()) lst = [*map(int, input().split())] item = sum(lst) // n if n == 1: print(0) return less, more, leng1, leng2 = [], [], 0, 0 for i, x in enumerate(lst): if x < item: less.append(i) leng1 += 1 if x > item: more.append(i) leng2 += 1 if leng1 == 0 and leng2 ==...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR VAR VAR LIST LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXP...
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
n = int(input()) boxs = list(map(int, input().split())) tot = sum(boxs) num = tot // n s = 0 for i in range(n - 1): if boxs[i] < num: boxs[i + 1] = boxs[i + 1] - (num - boxs[i]) s += num - boxs[i] boxs[i] = num elif boxs[i] > num: boxs[i + 1] = boxs[i + 1] + (boxs[i] - num) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_O...
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
n = int(input()) a = list(map(int, input().split())) t = 0 for i in range(n): t += a[i] t = t // n cnt = 0 for i in range(n): if a[i] > t: a[i + 1] += abs(a[i] - t) cnt += abs(a[i] - t) elif a[i] < t: a[i + 1] -= abs(a[i] - t) cnt += abs(a[i] - t) print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR ...
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
n = int(input()) t = list(map(int, input().split())) s, k = 0, sum(t) // n t = [(i - k) for i in t] for i in range(n - 1): s += abs(t[i]) t[i + 1] += t[i] print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
x = int(input()) a = list(map(int, input().strip().split(" "))) count = 0 sum = 0 for i in range(len(a)): sum += a[i] z = int(sum / x) for i in range(len(a)): if a[i] != z and a[i] > z: b = abs(z - a[i]) a[i] = a[i] - b count += b a[i + 1] += b if a[i] != z and a[i] < z: ...
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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR AS...
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
a = [] def main(): n = int(input()) a.append(0) B = input() for x in B.split(): a.append(int(x)) a.append(0) S = sum(a) ave = int(S / n) ans = 0 for i in range(1, n + 1, 1): if a[i] < ave: ans += ave - a[i] a[i + 1] -= ave - a[i] else...
ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_...
Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura...
n = int(input()) a = list(map(int, input().split())) k = 0 for i in range(n): k += a[i] aver = k // n h = 0 x = 0 y = 1 s = 0 for i in range(n): s += aver - a[i] h += abs(s) print(h)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CA...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
t = int(input()) for _ in range(t): n = int(input()) S = input() if S[0] == "0" or S[-1] == "0": print("NO") continue cnt = 0 for s in S: if s == "1": cnt += 1 if cnt & 1: print("NO") continue k = 0 a = "" b = "" flip = 1 fo...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
inn = lambda: int(input()) inm = lambda: map(int, input().split()) ins = lambda: str(input()) ina = lambda: list(map(int, input().split())) def solve(): n = inn() ones = 0 zeros = 0 s = ins() for i in s: if i == "1": ones += 1 else: zeros += 1 if ones % ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING V...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
import sys input = sys.stdin.readline YES = "YES" NO = "NO" def solve(N, S): if S[0] == 0 or S[-1] == 0: print(NO) return A = ["("] B = ["("] current_a = 1 current_b = 1 for s in S[1:-1]: if s: if current_a + current_b == 2: current_a += 1 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR LIST STRING ASSIGN VAR LIST STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER NUMBER IF VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STR...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
def readInt(): return int(input()) def readInts(): return [int(x) for x in input().split()] def readString(): return input().rstrip() def readCase(): n = readInt() a = readString() return n, a def solve(n, a): ones = a.count("1") if ones % 2 == 1: return "NO" first, s...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER RETURN STRING ASSIGN VAR VAR ST...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
import sys input = sys.stdin.readline for f in range(int(input())): n = int(input()) a = [0] * n b = [0] * n ao = bo = 0 poss = True s = input() for i in range(n): if s[i] == "1": if ao == 0 or bo == 0 or ao == bo == 1 and i < n - 1: ao += 1 ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR NUMBER VAR VAR...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
t = int(input()) def valid(s): tmp = 0 for c in s: if c == "(": tmp += 1 else: tmp -= 1 if tmp < 0: return False return True for _ in range(t): n = int(input()) s = input() a, b = "", "" c1 = s.count("1") if c1 % 2 or n % 2:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) s = input() one, zero = s.count("1"), s.count("0") if s[0] == "0" or s[n - 1] == "0" or zero % 2 or n % 2: print("NO") continue curr_one, curr_zero = 0, 0 a = "" for i in range(n): i...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
t = int(input()) for i in range(t): n = int(input()) s = input() o = 0 a = "" b = "" z = 0 to = 0 tz = 0 if s[0] == "0" or s[n - 1] == "0": print("NO") else: for i in range(n): if s[i] == "1": o += 1 else: z ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING FOR VAR...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
import sys mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline for _ in range(int(input())): N = int(input()) S = input().rstrip("\n") A = [] B = [] cnt_A = 0 cnt_B = 0 num_1 = S.count("1") if num_1 & 1: ...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING I...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
for _ in range(int(input())): n = int(input()) s = input() k = s.count("1") m = s.count("0") if s[0] == "0" or s[n - 1] == "0" or m % 2 != 0 or k % 2 != 0: print("NO") continue a = "" b = "" d = 0 c = 0 for i in s: if i == "1": if d < k / 2: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRIN...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
t = int(input()) for i in range(t): n = int(input()) s = input() cnt1 = s.count("1") cnt0 = n - cnt1 a = [] b = [] if cnt1 % 2 == 0 and cnt0 % 2 == 0 and s[0] == s[-1] == "1": j = 0 pnt = 0 flip = 0 while pnt < cnt1 // 2: if s[j] == "1": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER STRING ASSIGN VAR NUMBER A...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
ll = lambda: map(int, input().split()) t = lambda: int(input()) ss = lambda: input() lx = lambda x: map(int, input().split(x)) for s in [*open(0)][2::2]: N = len(s) - 1 o = s.count("1") if s[0] < "1" or s[-2] < "1": print("NO") continue if o & 1: print("NO") continue ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING VA...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
import sys input = sys.stdin.readline def check(K): z = 0 for k in K: if k == "(": z += 1 else: z -= 1 if z < 0: return 0 return 1 t = int(input()) for tests in range(t): n = int(input()) s = input().strip() ONE = s.count("1") ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP ...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
def solve(): n = int(input()) s = input() one = s.count("1") zero = s.count("0") if one % 2 == 1 or zero % 2 == 1 or s[0] == "0" or s[n - 1] == "0": print("NO") return a = "" b = "" for i in s: if i == "1": if one: a += "(" ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
t = int(input()) for i in range(t): n = int(input()) s = input() z = s.count("0") o = s.count("1") a, b = "", "" if s[0] == "1" and s[n - 1] == "1" and o % 2 == 0 and z % 2 == 0: one = 0 zero = 0 for i in s: if i == "1": one += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR STRING STRING IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBE...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
T = int(input()) for t in range(T): n = int(input()) s = input() can = True if s.count("0") % 2 == 1: can = False elif n % 2 == 1: can = False elif s[0] == "0" or s[-1] == "0": can = False if not can: print("NO") continue parity = 0 pdict = {(0...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR ...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
for _ in range(int(input())): n = int(input()) s = input() if s[0] == "0" or s[-1] == "0" or s.count("1") % 2 == 1: print("NO") else: ok = True a, b = [0] * n, [0] * n i = 1 last = "(" k = s.count("1") // 2 for i in range(n): if k == 0:...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER AS...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N = int(input()) X = [int(a) for a in input()] s = sum(X) if s % 2 or X[0] == 0 or X[-1] == 0: print("NO") continue A = [0] * N B = [0] * N k = 0 l = 1 for i, x in enumerate(...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
t = int(input()) while t > 0: n = int(input()) s = input() a = "" b = "" one = 0 zero = 0 for i in s: if i is "1": one += 1 elif i is "0": zero += 1 if zero % 2 == 1 or one % 2 == 1 or s[0] == "0" or s[-1] == "0": print("NO") else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER ST...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
t = int(input()) for i in range(t): n = int(input()) s = str(input()) res1 = "" res2 = "" zero = s.count("0") one = s.count("1") a = one / 2 if s[0] == "0" or s[n - 1] == "0" or zero % 2 == 1 or one % 2 == 1: print("no") else: a = int(one / 2) u = 0 v ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRIN...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
import sys from sys import stdin tt = int(stdin.readline()) for loop in range(tt): n = int(stdin.readline()) s = stdin.readline()[:-1] S = s if n % 2 == 1: print("NO") continue a = [] b = [] at = 0 bt = 0 znum = 0 onum = 0 for i in range(n): if s[i] =...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR ...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
for _ in range(int(input())): n = int(input()) string = input() if string[0] != "1" or string[-1] != "1": print("NO") continue else: ones = string.count("1") zeros = n - ones if ones % 2 == 1: print("NO") continue output1 = [-1] * n...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
for i in range(int(input())): N = int(input()) s = input() zero = 0 for i in range(N): if s[i] == "0": zero += 1 if zero % 2: print("NO") elif s[0] == "0" or s[-1] == "0": print("NO") else: one = N - zero s1 = "" s2 = "" one...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
for _ in range(int(input())): n = int(input()) s = list(map(str, input())) if n % 2 != 0: print("NO") elif s[0] == "0" or s[n - 1] == "0": print("NO") elif s.count("0") % 2 != 0: print("NO") else: a = "(" b = ")" s1 = list.copy(s) s2 = list...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
from sys import stdin, stdout t = int(stdin.readline()) for _ in range(t): n = int(stdin.readline()) s = stdin.readline(n) stdin.readline(1) if s[0] == "0" or s[n - 1] == "0": stdout.write("NO\n") continue a = [] b = [] va, vb = 0, 0 for i in range(n): if s[i] ==...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VA...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
def ss(n, s): a = "" b = "" x = 0 y = 0 p = s.count("1") q = 0 f = 0 for i in s: if i == "1": p -= 1 q += 1 if q > p: a += ")" b += ")" x -= 1 y -= 1 else: ...
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING VAR STRING VAR NUMBER VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR NUMBER...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
def solve(n, s): cnt = 0 for i in s: if i == "1": cnt += 1 if cnt % 2 == 1 or s[0] == "0" or s[-1] == "0": print("NO") return k = 0 flip = 0 a = "" b = "" for i in range(n): if s[i] == "1": if 2 * k < cnt: a += "(" ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP NUMBER VAR VAR VAR STRING VAR STR...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
t = int(input()) for _ in range(t): n = int(input()) s = input() s = list(s) a = "" b = "" c1 = 0 c2 = False c = 0 d = 0 for i in range(n): if s[i] == "1": c += 1 if s[0] == "0" or s[-1] == "0" or c % 2 == 1: print("NO") d = 1 conti...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
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") mod = 10**9 + 7 for _ in range(rn()): n = rn() s = rs() c = s.count("1") if s[0] == s[-1] == "1" and c % 2 == 0: p...
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 BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL V...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
for t in range(int(input())): n = int(input()) s = input() ans = "YES" cnt = s.count("1") if s[0] == "0" or s[-1] == "0" or cnt % 2 == 1: ans = "NO" else: a, b = "", "" check = 0 temp = False for i in range(n): if s[i] == "0": i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR F...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
for _ in range(int(input())): n = int(input()) s = input() if s[0] == s[-1] == "0" or s[0] != s[-1]: print("NO") continue if s.count("0") % 2: print("NO") continue cnt = s.count("1") k = 0 a = "" b = "" flip = True for i in s: if i == "1": ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR S...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
for test in range(int(input())): n = int(input()) s = input() cnt = s.count("1") if cnt & 1 or s[0] == "0" or s[-1] == "0": print("NO") continue c = 1 k = 0 a = "" b = "" for i in range(n): if s[i] == "1": if 2 * k < cnt: a += "(" ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL V...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
def answer(s): count1 = 0 count = 0 count0 = 0 a = "" b = "" if s[0] == "0" or s[-1] == "0": return ["NO"] for i in s: if i == "1": count1 += 1 else: count0 += 1 if count1 % 2 != 0 or count1 == 0 or len(s) % 2 != 0: return ["NO"] ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING RETURN LIST STRING FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN LIST STRING ASSIGN VAR NUMBER ...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) s = input() a = [] b = [] count1 = 0 for i in range(n): if s[i] == "1": count1 += 1 count0 = n - count1 if count0 % 2: print("NO") continue leftbr0 = count0...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VA...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
t = int(input()) for i in range(t): n = int(input()) s = input() a = "" b = "" c1 = s.count("1") c0 = s.count("0") if c1 % 2 != 0 or c0 % 2 != 0 or s[0] != "1" or s[-1] != "1": print("NO") else: print("YES") one = 0 zer = 0 for j in range(n): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING VAR NUMBER STRING EX...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
def isvalid(s): c = 0 for i in range(len(s)): if s[i] == "(": c += 1 else: c -= 1 if c < 0: return False if c == 0: return True return False t = int(input()) while t != 0: n = int(input()) s = input() if n & 1 == 1: ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL 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 WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NU...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
def solve(s, n): cnt = 0 for x in s: cnt += x == "1" c0 = n - cnt if cnt % 2 == 1: print("NO") return cnt //= 2 a = b = "" sa = sb = 0 for i in range(n): if s[i] == "1": if cnt > 0: a += "(" b += "(" ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER VAR STRING VAR STRING ...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
Time = int(input()) def solve(): N = int(input()) S = input() cnt = S.count("1") if S[0] == "0" or S[-1] == "0" or cnt % 2 == 1: print("NO") return A, B = "", "" k = 0 flip = False for i in range(N): if S[i] == "1": if 2 * k < cnt: A ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_C...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
def solve(): n = int(input()) ip = input() ones = ip.count("1") zers = ip.count("0") if zers % 2 != 0 or ip[0] == "0" or ip[n - 1] == "0": print("NO") else: ans1 = "" ans2 = "" k = 0 flag = 1 for i in range(n): if ip[i] == "1": ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FU...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
try: def solve(n, s): add = 0 for i in s: if i == "1": add += 1 if s[0] == "0" or s[n - 1] == "0" or add % 2 == 1: print("NO") return a, b = "", "" c1, c2 = 1, 0 for i in s: if i == "1": ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR STRING IF VAR BIN_OP VAR NUMBER VAR STRING VAR STRING VAR STRING VAR ST...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
t = int(input()) for t1 in range(0, t): n = int(input()) s = input() if s[0] == "0" or s[-1] == "0": print("NO") else: same = [] diff = [] for i in range(0, n): if s[i] == "1": same.append(i) else: diff.append(i) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CAL...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
t = int(input()) while t: n = int(input()) s = input() o = s.count("1") if s[0] == "0" or s[-1] == "0" or s.count("0") % 2 != 0 or o % 2 != 0: print("NO") else: a = "" b = "" open_flag = 1 p = o // 2 for x in s: if x == "1": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN ...
A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not. You are given a binary string $s$ of length $n$. Construct two balanced bracket sequen...
testcases = int(input()) while testcases > 0: n = int(input()) str1 = str(input()) count1 = 0 for a in range(0, n): if str1[a] == "1": count1 += 1 if count1 % 2 == 1 or str1[0] == "0" or str1[n - 1] == "0": print("NO") testcases = testcases - 1 continue ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIG...