description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
def solve(s): ans = 0 if s.count(1) in (len(s), 0): s[0] = 1 - s[0] ans += 1 start = 0 groups = [] for i in range(len(s) + 1): if i == len(s) or s[i] != s[start]: groups.append(i - start) start = i if len(s) > 1 and s[0] == s[-1]: groups[0]...
FUNC_DEF ASSIGN VAR NUMBER IF FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR IF FUNC_CALL...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
def find_cost_of_reordering(directions): assert len(directions) >= 3 if len(set(directions)) == 1: return 1 + (len(directions) - 1) // 3 chains_lengths = _extract_lengths_of_chains_of_same_directions(directions) cost = sum( chain_length // 3 for chain_length in chains_lengths if chain_le...
FUNC_DEF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
for _ in range(int(input())): n = int(input()) s = input() arr = [] if s[0] == s[1] and s[1] == s[-1]: arr.append(1) else: arr.append(0) for i in range(1, n - 1): if s[i - 1] == s[i] and s[i] == s[i + 1]: arr.append(1) else: arr.append(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 ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
for t in range(int(input())): n = int(input()) f = list(input()) ans = 0 fir = 0 sem = 1 for i in range(1, n): if f[i] == f[i - 1]: sem += 1 elif fir == 0: fir = sem sem = 1 else: ans += sem // 3 sem = 1 if s...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
t = int(input()) for i in range(t): n = int(input()) a = input() ans = 0 f = False for j in range(n): if a[j - 1] != a[j]: f = True k = j if f: k = (k + 1) % n c = 1 for j in range(k, n): if a[j] == a[j - 1]: c +...
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 NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBE...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
import sys input = sys.stdin.buffer.readline inin = lambda: int(input()) inar = lambda: list(map(int, input().split())) inst = lambda: input().decode().rstrip("\n\r") INF = float("inf") for _t_ in range(inin()): n = inin() s = list(inst()) if len(set(s)) == 1: print((n - 1) // 3 + 1) contin...
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 FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
from sys import gettrace, stdin if gettrace(): inputi = input else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() def solve(): n = int(input()) ss = list(input()) res = 0 if all(s == ss[0] for s in ss): print((n + 2) // 3) ...
IF FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN ASSIGN VAR NUM...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
import sys input = sys.stdin.readline inp, ip = lambda: int(input()), lambda: [int(w) for w in input().split()] for _ in range(inp()): n = inp() s = input().strip() prev = -1 x = [] for i in range(n): if s[i] != prev: x.append(0) x[-1] += 1 prev = s[i] ans = ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER N...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
t = int(input()) for i in range(t): n = int(input()) l = input() p = 0 b = False for i in range(1, n): if l[i] != l[i - 1]: p = i b = True break if b: l = l[p:] + l[:p] + "." t = 0 r = 0 for i in range(1, n + 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR STRING A...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
def main(): (n,) = map(int, input().split(" ")) s = list(input()) ss = set(s) if len(ss) == 1: return (len(s) - 1) // 3 + 1 while s[0] == s[-1]: s = s[1:] + s[:1] z = 0 pred = s[0] count = 1 for i in range(1, n): if s[i] == pred: count += 1 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER AS...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
from sys import stdin, stdout _input, _print = stdin.readline, stdout.write _int, _range, _str, _enumerate = int, range, str, enumerate def solution(): for _ in _range(_int(_input())): n = _int(_input()) arr = _input().rstrip("\n") if arr[-1] == arr[0]: k = 0 while...
ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF 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 IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASS...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
from sys import stdin, stdout def shift(c_a): c = c_a[0] for i in range(n - 1): c_a[i] = c_a[i + 1] c_a[n - 1] = c def omkar_and_bed_wars(n, s): c_a = list(s) r1 = cal_dp(n, c_a) shift(c_a) r2 = cal_dp(n, c_a) shift(c_a) r3 = cal_dp(n, c_a) shift(c_a) r4 = cal_dp(...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
for _ in range(int(input())): n = int(input()) s = list(input()) ans = 0 m = 1 if s.count("R") == n or s.count("L") == n: ans = (n + 2) // 3 else: while s[-1] == s[0]: s.append(s.pop(0)) s.append("A") for i in range(len(s) - 1): if s[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 FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
for _ in range(int(input())): n = int(input()) s = input() island = [(0) for i in range(n + 1)] act = 0 island[0] = 1 for i in range(1, n): if s[i] != s[i - 1]: act += 1 island[act] += 1 if act == 0: if n % 3 == 0: print(n // 3) else: ...
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 VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER IF ...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
for _ in range(int(input())): n = int(input()) s = input() l = [] i = 0 while i < n: ct = 0 while i < n and s[i] == "L": ct += 1 i += 1 if ct > 0: l.append(ct) ct = 0 while i < n and s[i] == "R": ct += 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 ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR N...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
from sys import exit, stderr, stdin def rl(): return [int(w) for w in stdin.readline().split()] (T,) = rl() for _ in range(T): (n,) = rl() s = stdin.readline().rstrip() l = 1 while l < n and s[l] == s[0]: l += 1 if l == n: print((n + 2) // 3) continue r = n wh...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VA...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
t = int(input()) def diff(s, t): return sum(1 for a, b in zip(s, t) if a != b) for _ in range(t): n = int(input()) s = input() best = n + 5 for _ in range(4): cc = [n + 2] * (n + 1) cc[0] = 0 for i in range(2, n + 1): cc[i] = min(cc[i], cc[i - 2] + diff("RL", ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
from sys import stdin input = stdin.readline for _ in range(int(input())): n = int(input()) s = input()[:-1] x = 0 c = 0 ans = 0 if s[0] == "L": s = s.strip("L") if not s: print((n + 2) // 3) continue else: s = s.strip("R") if not s: ...
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CAL...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
def main(): n = int(input()) s = input() ans = 0 if s == "L" * n: s = s[:-1] + "R" ans += 1 if s == "R" * n: s = s[:-1] + "L" ans += 1 i = s.find("LR") if i != -1: s = s[i + 1 :] + s[: i + 1] i = 0 while 0 <= i < n: j = s.find("L", i) ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
for _ in range(int(input())): n = int(input()) s = input() if len(set(s)) == 1: print((n + 2) // 3) continue cur = 1 arr = [] for i in range(n): if s[i] == s[(i + 1) % n]: cur += 1 else: arr.append(cur) cur = 1 if s[-1] == s...
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 FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBE...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
t = int(input()) for _ in range(t): n = int(input()) s = input() pos = -1 for i in range(1, n): if s[i] != s[i - 1]: pos = i if pos == -1: print(int((n + 2) / 3)) else: if s[0] == s[n - 1]: s = s[pos:] + s[:pos] cnt, res = 1, 0 for ...
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 FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
a = int(input()) for i in range(a): s = int(input()) t = input() z = [] for j in range(len(t)): z.append(t[j]) ans = [] count = 1 for i in range(1, len(z)): if z[i] == z[i - 1]: count += 1 else: ans.append(count) count = 1 ans.a...
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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR N...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
test = int(input()) for _ in range(test): n = int(input()) arr = list(input()) ans = 0 i = 0 freq = [] while i < n: f = 1 i += 1 while i < n and arr[i] == arr[i - 1]: f += 1 i += 1 freq.append(f) if len(freq) == 1: print((n - 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 FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL V...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
def find_cost_of_reordering(directions): assert len(directions) >= 3 directions_n = len(directions) get_direction = lambda index: directions[index % directions_n] if len(set(directions)) == 1: return 1 + (directions_n - 1) // 3 i = 0 while get_direction(i) == get_direction(i - 1): ...
FUNC_DEF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NU...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
import sys readline = sys.stdin.readline T = int(readline()) Ans = [None] * T INF = 10**9 + 7 for qu in range(T): N = int(readline()) A = [(1 if s == "R" else 0) for s in readline().strip()] ans = INF for _ in range(4): dp = [0, INF, INF, INF, INF] for a in A: dp2 = [INF] * ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR STRING NUMBER NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN V...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
for _ in range(int(input())): n = int(input()) a = list(str(input())) ans = 0 flag = 0 c = 1 for i in range(1, n): if a[i] != a[i - 1]: flag = 1 break if i == n - 1 and flag == 0: if a[0] == "R": a[0] = "L" else: a[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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF V...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
t = int(input()) for i in range(t): n = int(input()) s = input() c = 0 a = s[0] if s[0] != s[n - 1]: d = 1 for i in s[1:]: if i == a: d = d + 1 else: c = c + d // 3 d = 1 a = i c = c + d // 3 ...
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 VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBE...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
for _ in range(int(input())): n = int(input()) a = list(input()) l = 0 r = 0 t = 0 j = 0 if a[0] == "L" and a[-1] == "L" and "R" in a: j = a.index("R") elif a[0] == "R" and a[-1] == "R" and "L" in a: j = a.index("L") for i in range(j, n): if a[i] == "L": ...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING STRING VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
t = int(input()) def ceildiv(a, b): return (a + b - 1) // b for case in range(t): n = int(input()) s = input() if all(x == s[0] for x in s): print(ceildiv(n, 3)) else: if s[0] == s[-1]: q = s.index("L" if s[0] == "R" else "R") s = s[q:] + s[:q] c =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR V...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
t = int(input()) for i in range(t): n = int(input()) s = list(input()) ans = 0 if len(set(s)) != 1: ind = 0 for i in range(1, n): if s[i] != s[i - 1]: ind = i break S = s[ind:] + s[:ind] A = [1] for i in range(1, 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 FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP ...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
for nt in range(int(input())): n = int(input()) s = input() if "L" not in s or "R" not in s: if n <= 2: print(0) else: print((n + 2) // 3) continue g = [] curr = s[0] count = 1 for i in range(1, n): if s[i] == curr: count +=...
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 STRING VAR STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR I...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
t = int(input()) for _ in range(t): n = int(input()) s = list(input()) if s[-1] == s[0]: i = n - 1 while i > 0 and s[i] == s[0]: i -= 1 if i != 0: s = s[i + 1 :] + s[: i + 1] ans = 0 for i in range(n): if s[i] == "R": if not (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 FUNC_CALL VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
from sys import stdin input = stdin.readline t = int(input()) for _ in range(t): n = int(input()) s = input().strip() if s == "R" * n or s == "L" * n: print((n + 2) // 3) else: bckt = [] end = n - 1 ct = 0 while end >= 0 and s[end] == s[0]: ct += 1 ...
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 FUNC_CALL VAR IF VAR BIN_OP STRING VAR VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE...
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \leq j \leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is to the left of player $1$...
for s in [*open(0)][2::2]: f = [1] for b, a in zip(s, s[1:-1]): if a == b: f[-1] += 1 else: f.append(1) if s[0] == s[-2] and len(f) > 1: f[0] += f.pop() f[0] += 2 * (len(f) < 2) print(sum(i // 3 for i in f))
FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FU...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
read = lambda: map(int, input().split()) ax, ay, bx, by, tx, ty = read() n = int(input()) p = [tuple(read()) for i in range(n)] a, b = [], [] for i in range(n): x, y = p[i] pt = ((tx - x) ** 2 + (ty - y) ** 2) ** 0.5 pa = ((ax - x) ** 2 + (ay - y) ** 2) ** 0.5 pb = ((bx - x) ** 2 + (by - y) ** 2) ** 0.5...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR N...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
ax, ay, bx, by, tx, ty = map(int, input().split()) n = int(input()) l = [tuple(map(int, input().split())) for _ in range(n)] a, b = [], [] for i in range(n): x, y = l[i] lt = ((tx - x) * (tx - x) + (ty - y) * (ty - y)) ** 0.5 la = ((ax - x) * (ax - x) + (ay - y) * (ay - y)) ** 0.5 lb = ((bx - x) * (bx -...
ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VA...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
ax, ay, bx, by, tx, ty = map(int, input().split()) n = int(input()) a, b = [], [] res = 0 for i in range(n): x, y = map(int, input().split()) lt = ((tx - x) * (tx - x) + (ty - y) * (ty - y)) ** 0.5 la = ((ax - x) * (ax - x) + (ay - y) * (ay - y)) ** 0.5 lb = ((bx - x) * (bx - x) + (by - y) * (by - y)) *...
ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VA...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
import sys input = sys.stdin.readline ax, ay, bx, by, tx, ty = map(int, input().strip().split()) def dd(x0, y0, x1, y1): return ((x0 - x1) ** 2 + (y0 - y1) ** 2) ** 0.5 n = int(input().strip()) arr = [list(map(int, input().strip().split())) for i in range(n)] dist = [dd(x, y, tx, ty) for x, y in arr] ans = sum...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CAL...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
def glen(x1, y1, x2, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 xa, ya, xb, yb, xt, yt = map(int, input().split()) n = int(input()) x = [0] * n y = [0] * n for i in range(n): x[i], y[i] = map(int, input().split()) inf = 10**10 afmin = [0, 0] asmin = [0, 0] for i in range(n): a = glen(xa, ya, x[i...
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
def D(x1, y1, x2, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 Ax, Ay, Bx, By, Rx, Ry = [float(_) for _ in input().split()] N = int(input()) PosX, PosY = [0.0] * N, [0.0] * N for i in range(N): PosX[i], PosY[i] = map(int, input().split()) CutA, CutB = [0.0] * N, [0.0] * N ans = 0 for i in range(N): ...
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
def readlist(): return list(map(float, input().split())) def dist(P1, P2): aa = P1[0] - P2[0] bb = P1[1] - P2[1] return (aa * aa + bb * bb) ** 0.5 ax, ay, bx, by, tx, ty = readlist() A = [ax, ay] B = [bx, by] T = [tx, ty] n = int(input()) Bottles = [] for i in range(n): Bottles.append(readlist()...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN V...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
read = lambda: map(int, input().split()) def dis(x1, y1, x2, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 ax, ay, bx, by, tx, ty = read() n = int(input()) a, b = [], [] sum = 0 for i in range(n): x, y = read() dist = dis(tx, ty, x, y) a.append((dis(ax, ay, x, y) - dist, i)) b.append((dis...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
def distance(x1, y1, x2, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 def second_smallest(arr, temp_x, temp_y, tx, ty): smallest_index = arr.index( max(arr, key=lambda T: distance(tx, ty, *T) - distance(ax, ay, *T)) ) d = 10**20 index = -1 for i, v in enumerate(arr): x,...
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_...
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
ax, ay, bx, by, tx, ty = map(int, input().split()) n = int(input()) X = [0] * n Y = [0] * n T = [0.0] * n res = 0.0 for i in range(n): X[i], Y[i] = map(int, input().split()) T[i] = ((X[i] - tx) ** 2 + (Y[i] - ty) ** 2) ** 0.5 res += T[i] * 2 L1 = [[0]] * (n + 2) L2 = [[0]] * (n + 2) for i in range(n + 2): ...
ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL V...
Two integer sequences existed initially, one of them was strictly increasing, and another one — strictly decreasing. Strictly increasing sequence is a sequence of integers $[x_1 < x_2 < \dots < x_k]$. And strictly decreasing sequence is a sequence of integers $[y_1 > y_2 > \dots > y_l]$. Note that the empty sequence a...
n, a = int(input()), [int(i) for i in input().split()] + [0] ans, inc, dec = [(0) for _ in range(n)], -1, float("inf") for i in range(n): if inc < a[i] < dec: if a[i] < a[i + 1]: inc = a[i] else: dec = a[i] ans[i] = 1 elif inc < a[i]: inc = a[i] el...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBE...
Two integer sequences existed initially, one of them was strictly increasing, and another one — strictly decreasing. Strictly increasing sequence is a sequence of integers $[x_1 < x_2 < \dots < x_k]$. And strictly decreasing sequence is a sequence of integers $[y_1 > y_2 > \dots > y_l]$. Note that the empty sequence a...
n = int(input()) a = list(map(int, input().split())) + [0] answer = [0] * n current_increase_max = -1 current_decrease_min = 1000000.0 for i in range(n): if current_increase_max < a[i] and a[i] < current_decrease_min: if a[i] < a[i + 1]: current_increase_max = a[i] answer[i] = 0 ...
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 LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBE...
Two integer sequences existed initially, one of them was strictly increasing, and another one — strictly decreasing. Strictly increasing sequence is a sequence of integers $[x_1 < x_2 < \dots < x_k]$. And strictly decreasing sequence is a sequence of integers $[y_1 > y_2 > \dots > y_l]$. Note that the empty sequence a...
def main(): n = int(input()) a = list(map(int, input().split())) result = [0] * n last_increasing = -1 last_decreasing = 200001 for i, x in enumerate(a): if i == n - 1: if x < last_decreasing: result[i] = 1 elif x <= last_increasing: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF ...
Two integer sequences existed initially, one of them was strictly increasing, and another one — strictly decreasing. Strictly increasing sequence is a sequence of integers $[x_1 < x_2 < \dots < x_k]$. And strictly decreasing sequence is a sequence of integers $[y_1 > y_2 > \dots > y_l]$. Note that the empty sequence a...
MAX = 1 + 2 * 10**5 MIN = -1 ASC = 0 DSC = 1 n = int(input()) a = list(map(int, input().split())) asc = MIN dsc = MAX res = [] for i in range(n): if a[i] > asc and a[i] < dsc: if i + 1 == n: res.append(DSC) elif a[i] > a[i + 1]: res.append(DSC) dsc = a[i] ...
ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR I...
Two integer sequences existed initially, one of them was strictly increasing, and another one — strictly decreasing. Strictly increasing sequence is a sequence of integers $[x_1 < x_2 < \dots < x_k]$. And strictly decreasing sequence is a sequence of integers $[y_1 > y_2 > \dots > y_l]$. Note that the empty sequence a...
n = int(input()) a = list(map(int, input().split())) inf = 10**6 inc = [inf for i in range(0, n + 1)] dec = [(-inf) for i in range(0, n + 1)] trinc = [(-1) for i in range(0, n + 1)] trdec = [(-1) for i in range(0, n + 1)] inc[0] = -inf dec[0] = inf for i in range(0, n - 1): if a[i + 1] < a[i]: if inc[i + 1]...
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 NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIG...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
t = int(input()) for x in range(t): n, d = map(int, input().split()) l = list(map(int, input().split())) p1 = 0 p2 = 1 sums = 0 p = l[:] l.sort() i = n - 1 flag = 0 i = n - 1 j = i - 1 iprev = -20 while j >= 0 and len(l) > 1: if abs(l[i] - l[j]) < d: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUM...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
t = int(input().strip()) for i in range(t): sum = 0 n, d = map(int, input().strip().split()) a = map(int, input().strip().split()) a = sorted(a, reverse=True) present = [1] * n for i in range(len(a)): if present[i]: for j in range(i + 1, len(a)): if present[j]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
for t in range(int(input())): n, d = map(int, input().split()) a = list(map(int, input().split())) a = sorted(a, reverse=True) ans = 0 i = 0 while i < n - 1: if a[i] - a[i + 1] < d: ans += a[i] + a[i + 1] i += 2 else: i += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VA...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
t = int(input()) for _ in range(t): n, d = map(int, input().split()) l = list(map(int, input().split())) if n == 1: print(0) continue l.sort(reverse=True) ans = 0 i = 0 j = 1 while j < n: if l[i] - l[j] < d: ans += l[i] + l[j] j += 2 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR V...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
T = int(input()) for j in range(0, T): N, D = input().split() N = int(N) D = int(D) array = input().split() array = [int(x) for x in array] array.sort() sum = 0 for k in range(len(array) - 1, 0, -1): if array[k] - array[k - 1] < D: sum += array[k] + array[k - 1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
for _ in range(int(input())): n, d = map(int, input().split()) nli = list(map(int, input().split())) nli.sort(reverse=True) lst = list() ind = 0 while ind < n - 1: if nli[ind] - nli[ind + 1] < d: lst.append(nli[ind + 1]) lst.append(nli[ind]) ind += 2 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR ...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
def sumpair(n, d, arr): arr.sort() i = n - 1 s = 0 while i > 0: if arr[i] - arr[i - 1] < d: s += arr[i - 1] + arr[i] i -= 2 else: i -= 1 return s t = int(input()) for _ in range(t): n, d = map(int, input().split()) arr = list(map(int, inp...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FU...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
for i in range(int(input())): x, y = map(int, input().split()) a = list(map(int, input().split())) a.sort() k = 0 j = len(a) - 1 while j > 0: if a[j] - a[j - 1] < y: k = k + a[j] + a[j - 1] j = j - 2 else: j = j - 1 print(k)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIG...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
for t in range(int(input())): temp = list(map(int, input().split())) n = temp[0] d = temp[1] a = list(map(int, input().split())) a.sort(reverse=True) ans = 0 if n == 1: print(0) continue p1 = 0 p2 = 1 ans = 0 while p1 < n and p2 < n: if a[p1] - a[p2] <...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN V...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
for T in range(int(input())): N, D = map(int, input().split()) arr = list(map(int, input().split())) arr = sorted(arr) mark = [0] * N ans = 0 for i in range(N - 1, 0, -1): if mark[i] == 0: if arr[i] - arr[i - 1] < D: ans += arr[i] + arr[i - 1] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
t = int(input()) for T in range(t): n, d = [int(x) for x in input().split()] a = [int(x) for x in input().split()] a.sort(reverse=True) ind, ind1 = 0, 1 ans = [] while ind < n - 1: if a[ind] - a[ind + 1] < d: ans.append(a[ind]) ans.append(a[ind + 1]) i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBE...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
t = int(input()) for i in range(t): n, d = map(int, input().split()) l = list(map(int, input().split())) l.sort() s1, s2 = 0, 0 j = len(l) - 1 while j > 0: if l[j] - l[j - 1] < d: s1 += l[j] + l[j - 1] j -= 2 else: j = j - 1 j = 0 while...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR B...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
a = int(input()) for i in range(0, a): b, c = map(int, input().split()) d = list(map(int, input().split())) d.sort(reverse=True) u = 0 z = [] for t in range(0, b): z.append(0) for t in range(0, b): if z[t] == 0: z[t] = 1 for y in range(t + 1, b): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR 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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER FOR V...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
n = int(input()) list2 = [] for i in range(n): n, d = map(int, input().split()) b = list(map(int, input().split())) ans = 0 b.sort() j = len(b) - 1 while j > 0: if b[j] - b[j - 1] < d: ans += b[j] + b[j - 1] j -= 2 else: j -= 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR ...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
for _ in range(int(input())): N, D = list(map(int, input().split())) L = list(map(int, input().split())) L.sort(reverse=True) sum_ = 0 flag = 0 for i in range(N - 1): if flag == 1: flag = 0 elif L[i] - L[i + 1] < D: sum_ += L[i] + L[i + 1] flag...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBE...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
for t in range(int(input())): n, d = map(int, input().split()) a = list(map(int, input().split())) a.sort() a.reverse() i = 1 ans = 0 while 1: if i > n - 1: break elif a[i - 1] - a[i] < d: ans = ans + a[i - 1] + a[i] i = i + 2 else:...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VA...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
tests = int(input()) for t in range(tests): n, d = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a.sort(reverse=True) i = 0 while i < len(a) - 1: if a[i] - a[i + 1] < d: i += 2 else: a.pop(i) if i == len(a) - 1: a.pop() ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUM...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
def integer_list(): return list(map(int, input().split())) def string_list(): return list(map(str, input().split())) def hetro_list(): return list(input().split()) t = int(input()) for _ in range(t): n, d = integer_list() lst = integer_list() lst.sort() s = 0 while lst: ele...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXP...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
for _ in range(int(input())): n, d = map(int, input().split()) a = list(map(int, input().split())) a.sort() k = a.pop() ans = 0 while a: k1 = a.pop() if k - k1 < d: ans += k + k1 if a: k = a.pop() else: k = k1 print(...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR A...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
def solve(): ans = 0 i = input().split(" ") n = int(i[0]) d = int(i[1]) a = list(map(int, input().split(" "))) a.sort() while n > 1: if a[-1] - a[-2] < d: ans += a[-1] + a[-2] del a[-1] del a[-1] n -= 2 else: del a[-...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
t = int(input()) while t: t -= 1 n, d = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a.sort() a.reverse() i = 1 ans = 0 while i < n: if a[i - 1] - a[i] < d: ans += a[i] + a[i - 1] i += 2 else: i += 1 print...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
t = int(input()) for i in range(t): l = input().split() n = int(l[0]) d = int(l[1]) l = list(map(int, input().split())) l = sorted(l) sum = 0 j = len(l) - 1 while j >= 1: if l[j] - l[j - 1] < d: sum += l[j] + l[j - 1] j -= 2 else: j -= ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VA...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
t = int(input()) while t: ans = 0 n, d = map(int, input().split()) arr = list(map(int, input().split())) arr = sorted(arr) l = len(arr) i = l - 1 while i > 0: if arr[i] - arr[i - 1] < d: ans += arr[i] + arr[i - 1] i = i - 2 else: i = i - 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR NUMBER 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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR BIN...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
def io(func=str, n=1): def nfp(): ff = str try: it = iter(func) def nf(val): nonlocal ff ff = next(it, ff) return ff(val) return type(func)(nf(va) for va in input().split()) except TypeError: r...
FUNC_DEF VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR RETURN FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VA...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
t = int(input()) for j in range(0, t): n, d = input().strip().split() n = int(n) d = int(d) a = list(map(int, input().strip().split())) a.sort(reverse=True) add = 0 i = 0 while i < n - 1: if a[i] - a[i + 1] < d: add = add + a[i] + a[i + 1] i = i + 2 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WH...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
test = int(input()) while test != 0: test = test - 1 n, d = map(int, input().split()) x = list(input().split()) i = 0 while i < n: x[i] = int(x[i]) i = i + 1 x.sort() ans = 0 while n > 0: a = x[n - 1] b = x[n - 2] b = abs(a - b) if b < d: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR N...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
t = int(input()) for _ in range(t): n, p = map(int, input().split()) flag = 0 sum = 0 l = list(map(int, input().split())) l.sort() for i in range(n - 1, 0, -1): if flag == 1: flag = 0 continue elif abs(l[i] - l[i - 1]) < p: sum = sum + l[i] + l...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN V...
Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that can be made from these numbers. Sum of X pairs is the sum of all ...
def sort(low, high, L): if low < high: mid = low + int((high - low) / 2) a = low b = mid + 1 sort(low, mid, L) sort(mid + 1, high, L) temp = [] while a <= mid or b <= high: if a <= mid and b <= high: if L[a] > L[b]: ...
FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER E...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
def gcd(a, b): while a != b and a != 0 and b != 0: if a > b: a = a % b else: b = b % a if a == 0: return b if b == 0: return a return a n = int(input()) a = list(map(int, input().split())) b = sorted(a) d = b[0] for i in range(1, n): d = gcd(...
FUNC_DEF WHILE VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR N...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
def gcd(a, b): if b == 0: return a return gcd(b, a % b) n = int(input()) a = [int(i) for i in input().split()] g = 0 count = 0 result = 0 for p in a: g = gcd(g, p) if p & 1: count += 1 else: result += count // 2 + 2 * (count & 1) count = 0 result += count // 2 + 2 *...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP V...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
import sys input = sys.stdin.readline n = int(input()) bits = [] g = 0 def gcd(a, b): while b: a, b = b, a % b return a for i in map(int, input().split()): bits.append(i % 2) g = gcd(i, g) if g > 1: print("YES") print("0") else: cnt = 0 for i in range(n - 1): if bits...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING E...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
def GCD(a, b): return a if b == 0 else GCD(b, a % b) n = int(input()) a = list(map(int, input().split())) a.append(0) g = 0 odds = 0 count = 0 for i in range(n + 1): g = GCD(a[i], g) if a[i] % 2 == 1: odds += 1 else: count += odds // 2 + 2 * (odds % 2) odds = 0 print("YES") pri...
FUNC_DEF RETURN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR V...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
n = int(input()) k = 0 l = list(map(int, input().split())) a = l[0] c = 0 for i in range(1, n): b = l[i] while a % b != 0: ost = a % b a = b b = ost if b == 1: c = 1 break else: a = b if c == 0: print("YES") print(0) exit() k = 0 for i in range...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
from sys import exit def gcd(x, y): if y == 0: return x else: return gcd(y, x % y) print("YES") n = int(input()) s = [] mn = float("inf") for i in input().split(): i = int(i) if i < mn: mn = i s.append(i) g = s[0] for i in s[1:]: g = gcd(g, i) if g == 1: b...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER F...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
from sys import stdin, stdout def gcd(a, b): if a == 0: return b elif b == 0: return a elif a == b: return a else: while b: a, b = b, a % b return a def seqGCD(a): currentGCD = gcd(a[0], a[1]) i = 2 n = len(a) while currentGCD != 1 ...
FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR IF VAR VAR RETURN VAR WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN V...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
import sys def gcd(a, b): while a != 0 and b != 0: if a > b: a = a % b else: b = b % a return max(a, b) def listGcd(l): g = gcd(l[0], l[1]) for i in l[2:]: if g == 1: return g g = gcd(g, i) return g n = int(sys.stdin.readline(...
IMPORT FUNC_DEF WHILE VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR A...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
n = int(input()) al = list(map(int, input().split())) def pgcd(a, b): while b: a, b = b, a % b return a def pgcdl(l): if len(l) == 0: return -1 if len(l) == 1: return l[0] p = pgcd(l[0], l[1]) for i in l[2:]: if p == 1: break p = pgcd(p, i)...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VA...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
s, i, n = 0, 0, int(input()) t = list(map(int, input().split())) + [0] while i < n: if t[i] % 2: i += 1 s += 2 - t[i] % 2 i += 1 b = t[0] for a in t: while a: a, b = b % a, a if b == 1: break print("YES") if b > 1: print(0) else: print(s)
ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR WHILE VAR ASSIGN VAR VAR BIN_OP VAR VA...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
def gcd(a, b): while b != 0: if a < b: a, b = b, a a, b = b, a % b return a def main(): n = int(input()) a = list(map(int, input().split())) b = a[:] a.sort() for i in range(n - 1): if gcd(a[i], a[i + 1]) == 1: break else: print("...
FUNC_DEF WHILE VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR V...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
n = int(input()) a = input().split() for i in range(n): a[i] = int(a[i]) k = 0 g = 0 def gcd(c, d): if c % d == 0: return d else: return gcd(d, c % d) while True: for i in range(n): g = gcd(g, a[i]) if g > 1: k = 0 break else: for i in range(n ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VA...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
def gcd(a, b): if a < b: return gcd(b, a) if a % b == 0: return b return gcd(b, a % b) n = int(input()) a = list(map(int, input().split())) k = gcd(a[0], a[1]) if n > 2: for i in a[2:]: k = gcd(k, i) print("YES") if k > 1: print(0) else: s, t = 0, 0 for i in a: ...
FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP 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 FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR VAR NUMBER ASSIGN VA...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
def gcd(a, b): while b: a, b = b, a % b return a n = int(input()) a = list(map(int, input().split())) ans = 0 l = 0 g = a[0] for i in range(n): g = gcd(a[i], g) if g > 1: print("YES\n0") else: for i in range(n): if a[i] % 2: l += 1 else: if l % 2: ...
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL ...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
def gcd(a, b): while b > 0: a, b = b, a % b return a def gcd_list(l): n = len(l) if n == 1: return l[0] return gcd(gcd_list(l[0 : n // 2]), gcd_list(l[n // 2 :])) n = int(input().strip()) a = [int(x) for x in input().strip().split()] print("YES") if gcd_list(a) > 1: print(0) ...
FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR V...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
def gcd(a, b): if not a or not b: return max(a, b) if a % b == 0: return b return gcd(b, a % b) n = int(input()) a = list(map(int, input().split())) now = a[0] for i in range(1, n): now = gcd(now, a[i]) if now != 1: print("YES\n0") else: res = 0 i = 0 while i < n: ...
FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP 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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR V...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
def gcd(a, b): if a == 0: return b if b == 0: return a return gcd(b, a % b) def gcd_of_list(a): a = a[::-1] partial_gcd = 0 while a: partial_gcd = gcd(partial_gcd, a.pop()) return partial_gcd def get_odd_chunk_lengths(a): a = a[::-1] chunk_lengths_arr = []...
FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR IF BIN_O...
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. <image>. Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1 a...
from sys import stdin def gcd(a, b): if b: return gcd(b, a % b) else: return a n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) g = 0 for el in a: g = gcd(g, el) res = 0 if g == 1: for i in range(n - 1): if a[i] % 2 and a[i + 1] % 2: a[i], a[...
FUNC_DEF IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VA...
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. <image> Thus, he came up with a puz...
s = input() l = len(s) ans = 0 for i in range(0, l): m = n = 0 for j in range(i, l): m += s[j] == "(" m -= s[j] == ")" n += s[j] == "?" if m + n < 0: break if m < n: m, n = n, m ans += m == n print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR STRING VAR VAR VAR STRING VAR VAR VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. <image> Thus, he came up with a puz...
s = str(input()) n = len(s) ans = 0 for l in range(n - 1): cnt = 0 qu = 0 chk = 0 if s[l] == "(": cnt += 1 chk += 1 elif s[l] == "?": qu += 1 chk = max(chk - 1, 0) else: continue for r in range(l + 1, n): if s[r] == "(": cnt += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR...
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. <image> Thus, he came up with a puz...
S = input() n = len(S) Ans = 0 for l in range(0, n): bs = 0 det = 0 for r in range(l, n): if S[r] == "?": if bs > 0: det = det + 1 bs = bs - 1 else: bs = bs + 1 elif S[r] == "(": bs = bs + 1 else: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR B...
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. <image> Thus, he came up with a puz...
s = input() a = 0 n = len(s) for i in range(n): l = 0 k = 0 for j in range(i, n): l += s[j] == "(" l -= s[j] == ")" k += s[j] == "?" if l + k < 0: break if k > l: l, k = k, l if l == k: a = a + 1 print(a)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR STRING VAR VAR VAR STRING VAR VAR VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ...