description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat girl and for each $k \in \{2, \dots, n\}$ she wants to find a subse...
n = int(input()) x = [0, 1] + [0] * (n - 1) for i in range(2, n + 1): if x[i]: continue for j in range(i, n + 1, i): if x[j]: continue x[j] = j // i print(*sorted(x[2:]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat girl and for each $k \in \{2, \dots, n\}$ she wants to find a subse...
n = int(input()) div = [0] * (n + 5) def sieve(): for i in range(2, n + 1): if div[i] != 0: continue for j in range(i, n + 1, i): if div[j] == 0: div[j] = i return a = [] sieve() b = [] for i in range(2, n + 1): if div[i] == i: b.append(i) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CAL...
Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat girl and for each $k \in \{2, \dots, n\}$ she wants to find a subse...
n = int(input()) i = 2 s = [1] * (n + 1) s[0], s[1] = 0, 0 m = n / 2 + 1 while i <= m: j = 2 while j * i <= n: s[i * j] = i j += 1 i += 1 s.sort() for i in s[2:]: print(i, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR F...
Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat girl and for each $k \in \{2, \dots, n\}$ she wants to find a subse...
n = int(input()) sieve = [-1] * (n + 1) primes = [] for i in range(2, n + 1): if sieve[i] == -1: sieve[i] = i primes.append(i) for x in range(2 * i, n + 1, i): if sieve[x] == -1: sieve[x] = i answer = [1] * len(primes) c = set(primes) c.add(1) toAdd = 2 while len(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR ...
Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat girl and for each $k \in \{2, \dots, n\}$ she wants to find a subse...
def get_primes(n): res = [2] arr = [True] * ((n - 1) // 2) i = 0 for i in range(len(arr)): if arr[i]: a = i * 2 + 3 res.append(a) for ii in range(i + a, len(arr), a): arr[ii] = False return res n = int(input()) primes = get_primes(n) res ...
FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR...
Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat girl and for each $k \in \{2, \dots, n\}$ she wants to find a subse...
n = int(input()) cur = n ans = [0] * (n + 1) used = [0] * (n + 1) for j in range(n // 2, 1, -1): for x in range(2 * j, n + 1, j): if used[x] == 0: used[x] = 1 ans[cur] = j cur -= 1 for x in range(1, cur + 1): ans[x] = 1 print(" ".join([str(x) for x in ans[2:]]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR...
Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat girl and for each $k \in \{2, \dots, n\}$ she wants to find a subse...
n = int(input()) arr = [0] * (n + 1) for i in range(1, n + 1): for j in range(i + i, n + 1, i): arr[j] = i arr.sort() for i in range(2, n + 1): print(arr[i], end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING
Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat girl and for each $k \in \{2, \dots, n\}$ she wants to find a subse...
def solve(n): nums = [1] * (n + 1) p = 2 while p * p <= n: if nums[p] == 1: for i in range(p * 2, n + 1, p): nums[i] = max(nums[i], p, i // p) p += 1 return sorted(sorted(nums[2:])) n = int(input()) print(" ".join([str(x) for x in solve(n)]))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FU...
Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat girl and for each $k \in \{2, \dots, n\}$ she wants to find a subse...
n = int(input()) A = [(1) for i in range(n + 1)] for i in range(2, n): j = 2 * i while j <= n: A[j] = i j += i ans = sorted(A) ans = ans[2:] print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat girl and for each $k \in \{2, \dots, n\}$ she wants to find a subse...
n = int(input()) res = [1] * (n + 1) for i in range(2, n + 1): j = i while i * j <= n: res[i * j] = max(res[i * j], j) j += 1 res.sort() print(" ".join(map(str, res[2:])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR...
Nura wants to buy k gadgets. She has only s burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of currency and the cost in that currency are not changing. Nura can buy gadgets for n days. For each day you know the exchange rates of dol...
import sys from itertools import accumulate def solve(f, g): n, m, k, s = [int(x) for x in f.readline().split()] a_price = [(int(x), i + 1) for i, x in enumerate(f.readline().split())] b_price = [(int(x), i + 1) for i, x in enumerate(f.readline().split())] a_gadgets = [] b_gadgets = [] for i, ...
IMPORT FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_...
Nura wants to buy k gadgets. She has only s burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of currency and the cost in that currency are not changing. Nura can buy gadgets for n days. For each day you know the exchange rates of dol...
import sys from itertools import accumulate n, m, k, s = map(int, input().split()) _rate = [list(map(int, input().split())), list(map(int, input().split()))] rate = [list(accumulate(_rate[0], min)), list(accumulate(_rate[1], min))] items = [[[0, -1]], [[0, -1]]] for i in range(m): t, c = map(int, sys.stdin.readlin...
IMPORT ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST LI...
Nura wants to buy k gadgets. She has only s burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of currency and the cost in that currency are not changing. Nura can buy gadgets for n days. For each day you know the exchange rates of dol...
from sys import stdin, stdout def ints(): return [int(x) for x in stdin.readline().split()] n, m, k, s = ints() a = ints() b = ints() d_gad = [] p_gad = [] for i in range(m): t, c = ints() if t == 1: d_gad.append([c, i + 1]) else: p_gad.append([c, i + 1]) d_gad.sort() p_gad.sort() mn...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST ...
Monocarp is playing chess on one popular website. He has $n$ opponents he can play with. The $i$-th opponent has rating equal to $a_i$. Monocarp's initial rating is $x$. Monocarp wants to raise his rating to the value $y$ ($y > x$). When Monocarp is playing against one of the opponents, he will win if his current rati...
def div_(xx, yy): if xx % yy == 0: return xx // yy else: return xx // yy + 1 def search(m): mi = 0 ma = n - 1 if b[0] > m: return 0 if b[n - 1] <= m: return n while True: if b[(mi + ma) // 2] <= m: mi = (mi + ma) // 2 else: ...
FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR RETURN VAR WHILE NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN ...
Monocarp is playing chess on one popular website. He has $n$ opponents he can play with. The $i$-th opponent has rating equal to $a_i$. Monocarp's initial rating is $x$. Monocarp wants to raise his rating to the value $y$ ($y > x$). When Monocarp is playing against one of the opponents, he will win if his current rati...
t = int(input()) for tes in range(t): n, x, y = map(int, input().split()) a = list(map(int, input().split())) a.sort() if a[0] > x: print(-1) continue ans = 1 x += 1 for i in range(1, n): if x == y: break if i <= n // 2 and a[i] > x: x ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF...
Monocarp is playing chess on one popular website. He has $n$ opponents he can play with. The $i$-th opponent has rating equal to $a_i$. Monocarp's initial rating is $x$. Monocarp wants to raise his rating to the value $y$ ($y > x$). When Monocarp is playing against one of the opponents, he will win if his current rati...
def solve(): n, x, y = [int(x) for x in input().split()] ranks = [int(x) for x in input().split()] ranks.sort() score = 0 result = 0 while True: while score < n and x + score >= ranks[score]: score += 1 if x + score >= y: result += y - x break ...
FUNC_DEF ASSIGN VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER ...
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process. There are n + 1 cities consecutively numbered from 0 to n. City 0 is Metropolis that is the meeting point for...
g = lambda: map(int, input().split()) n, m, k = g() F, T = [], [] e = int(300000000000.0) for i in range(m): d, f, t, c = g() if f: F.append((d, f, c)) else: T.append((-d, t, c)) for p in [F, T]: C = [e] * (n + 1) s = n * e q = [] p.sort() for d, t, c in p: if C[t...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR LIST VAR VAR ASSIGN VAR BIN_OP LIST V...
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process. There are n + 1 cities consecutively numbered from 0 to n. City 0 is Metropolis that is the meeting point for...
from sys import stdin, stdout n, m, k = map(int, stdin.readline().rstrip().split()) arrivalFlightList = [] departureFlightList = [] for _ in range(m): d, f, t, c = map(int, stdin.readline().rstrip().split()) d -= 1 if f == 0: t -= 1 departureFlightList.append((d, t, c)) else: f ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FU...
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process. There are n + 1 cities consecutively numbered from 0 to n. City 0 is Metropolis that is the meeting point for...
def main(): n, m, k = map(int, input().split()) ff, tt = [], [] for _ in range(m): d, f, t, c = map(int, input().split()) if f: ff.append((d, f, c)) else: tt.append((-d, t, c)) for ft in (ff, tt): cnt, costs = n, [1000001] * (n + 1) ft.sort...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER BIN_OP VAR ...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: currcost = 0 i = 0 j = 0 if len(s) == 0: return 0 if len(s) == 1: if abs(ord[s[0]]) - ord(t[0]) >= maxcost: return 1 else: retur...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: i = 0 ans = 0 curr = 0 for j in range(0, len(s)): curr = curr + abs(ord(s[j]) - ord(t[j])) if curr <= maxCost: ans = max(ans, j - i + 1) else: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL ...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: if not s: return 0 costs = [abs(ord(si) - ord(ti)) for si, ti in zip(s, t)] ans = 0 l, r = 0, 0 cur_cost = 0 print(costs) while l < len(s) and r < len(s): w...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR ...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: currCost = 0 maxLength = 0 start = 0 curr = 0 costs = [abs(ord(s[i]) - ord(t[i])) for i in range(len(s))] print(costs) while curr < len(costs): currCost += costs[curr] ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VA...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: totalCost = 0 maxLength = 0 costs = [] left = 0 length = 0 for i in range(len(s)): costs.append(abs(ord(s[i]) - ord(t[i]))) totalCost += costs[-1] lengt...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR WHILE VAR VAR...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: start = 0 cost = 0 max_len = 0 for end in range(len(s)): cost += abs(ord(s[end]) - ord(t[end])) while cost > maxCost: cost -= abs(ord(s[start]) - ord(t[start])) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: arr = [abs(ord(sc) - ord(tc)) for sc, tc in zip(s, t)] max_len = 0 left, right = 0, 0 curr_sum = 0 max_len = 0 while right < len(arr): curr_sum += arr[right] while ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VA...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, string: str, target: str, maxCost: int) -> int: cost = [0] * len(string) for i in range(len(string)): if string[i] != target[i]: cost[i] += abs(ord(string[i]) - ord(target[i])) if i > 0: cost[i] += cost...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CA...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: res = 0 c = [0] * (len(s) + 1) j = 0 for i in range(1, len(s) + 1): c[i] += c[i - 1] + abs(ord(s[i - 1]) - ord(t[i - 1])) while c[i] > maxCost: c[i] -= abs(ord(s[j]...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: dist = [abs(ord(s[i]) - ord(t[i])) for i in range(len(s))] i = 0 cost = maxCost for j in range(len(s)): cost -= dist[j] if cost < 0: cost += dist[i] ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER VAR
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: cost_array = [abs(a - b) for a, b in zip(map(ord, s), map(ord, t))] left = right = t = 0 mx = 0 while right < len(cost_array): t += cost_array[right] if t > maxCost: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CA...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: max_substring = 0 curr_substring = 0 left = right = diff = 0 while right < len(s): local_diff = abs(ord(s[right]) - ord(t[right])) if diff + local_diff <= maxCost: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR FUNC_CALL VA...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: max_length = 0 start = 0 end = 0 cost = 0 while end < len(s): c = abs(ord(s[end]) - ord(t[end])) if cost + c <= maxCost: cost += c end += 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: arr = [] lim = len(s) for i in range(0, lim): arr.append(abs(ord(s[i]) - ord(t[i]))) sm = [arr[0]] for j in range(1, lim): sm.append(sm[-1] + arr[j]) l = 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSI...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: cost = [abs(ord(s[i]) - ord(t[i])) for i in range(len(s))] prefix = [0] for i in range(len(cost)): prefix.append(prefix[-1] + cost[i]) maxLen = 0 i, j = 0, 0 while j < len(cost...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VA...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: currCost = 0 maxLength = 0 start = 0 curr = 0 while curr < len(s): currCost += abs(ord(s[curr]) - ord(t[curr])) while currCost > maxCost: currCost = currCos...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_O...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: maxLength = 0 currLength = 0 currCost = 0 for i in range(len(s)): currLength += 1 currCost += abs(ord(s[i]) - ord(t[i])) while currCost > maxCost: currC...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR ...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s, t, maxCost): n = len(s) right = 0 nowSum = 0 res = 0 for left in range(n): while ( right <= n - 1 and nowSum + abs(ord(s[right]) - ord(t[right])) <= maxCost ): ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSI...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: end = 0 result = 0 allCost = 0 for start in range(len(s)): if start >= 1: allCost -= abs(ord(s[start - 1]) - ord(t[start - 1])) while ( end + 1 < le...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR FUNC_CALL VAR BIN...
You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters. You are also given an integer maxCost. Return the maximum length of a substring of s t...
class Solution: def equalSubstring(self, s: str, t: str, maxCost: int) -> int: start = 0 end = 0 cost = 0 best = 0 while end < len(s): while end < len(s) and cost + abs(ord(s[end]) - ord(t[end])) <= maxCost: cost += abs(ord(s[end]) - ord(t[end])) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER I...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
for _ in range(int(input())): n, m = map(int, input().split()) l = [] c = 1 for v in map(int, input().split()): l += [(v, c)] if c == m: c = 1 else: c += 1 l = sorted(l, key=lambda x: x[0]) a = [0] * (m + 1) s = set() w = [] res = 10000...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BI...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
for _ in range(int(input())): n, m = map(int, input().split()) my_list = list(map(int, input().split())) my_list_2 = list(set(my_list)) my_dict = {} for i in my_list_2: my_dict[i] = [] for i in range(n): jk = i % m my_dict[my_list[i]].append(jk) s = 99**99 s1 = 99...
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 FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXP...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
def inp(): t = int(input()) while t > 0: n, m = map(int, input().split()) a = list(map(int, input().split())) count = 0 pairs = [] for num in a: pairs.append((num, count % m)) count += 1 pairs.sort() newList = a[:m] maxi = m...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VA...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
def try3(n, m, pts_s): i = 0 mi = 10**10 res = [-1] * m tmp = m mi_i = -1 while i < n - m - 1: if tmp == 0: mi = min(mi, res[pts_s[i - 1][1]] - min(res)) if mi == 0: break if res[pts_s[i][1]] == -1: tmp -= 1 res[pts_s[i]...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR NUMBER NUMBER VAR NUMBER ...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
for case in range(int(input())): n, m = [int(x) for x in input().split()] all_boxes = [int(x) for x in input().split()] color_wise_boxes = [] for j in range(0, n, m): for i in range(m): try: color_wise_boxes.append([all_boxes[i + j], i]) except IndexError:...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASS...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
INF = 10**9 + 5 for _ in range(int(input())): N, M = map(int, input().split()) arr = list(map(int, input().split())) pl = {} for i in range(N): act = arr[i] if act not in pl: pl[act] = set([i % M]) else: pl[act].add(i % M) arr2 = list(pl.keys()) ar...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
for tc in range(int(input())): n, m = map(int, input().split()) a = list(map(int, input().split())) b = [] temp = [] for i in range(m): for j in range(i, n, m): temp.append((a[j], i)) temp = sorted(temp, key=lambda x: x[0]) start = 0 finish = 1 res = 10**10 di...
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 LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VA...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
for _ in range(int(input())): n, m = map(int, input().split()) ll = list(map(int, input().split())) a = [] for i in range(n): a.append([]) a[i].append(ll[i]) a[i].append(i % m) l = sorted(a, key=lambda lll: lll[0]) a = [0] * m j = 0 ans = 0 for i in range(n): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR ...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
for x in range(int(input())): m, n = map(int, input().split()) l = list(map(int, input().split())) l1 = [] l2 = [] l3 = [0] * n t = 0 flagi = 0 for x in range(len(l)): l1.append([l[x], x % n]) l1.sort() count = 0 for y in range(m): if count != n: i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
try: for _ in range(int(input())): n, m = map(int, input().split()) vis = [0] * m l = list(map(int, input().split())) l = list([l[i], i % m] for i in range(n)) l.sort() res = l[n - 1][0] - l[0][0] s = 0 for i in l: vis[i[1]] += 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 BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP ...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
for _ in range(int(input().strip())): n, m = [int(i) for i in input().strip().split()] old_boxes = [(int(inp), i % m) for i, inp in enumerate(input().strip().split())] old_boxes.sort() old_boxes.append((0, m)) first = 0 boxes = [] for i in range(1, n + 1): if old_boxes[first][1] != o...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VA...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
t = int(input()) def sortSecond(val): return val[1] def minDiff(arr, N, K, w, chk, res): wa = res for i in range(N - K + 1): curSeqDiff = arr[i + K - 1] - arr[i] if curSeqDiff < res: yes = set(chk).issubset(set(w[i : i + K])) if curSeqDiff < res and yes: r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF ...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
t = int(input()) for q in range(t): n, m = map(int, input().split()) a = list(map(int, input().split())) l = [] for i in range(n): l.append((a[i], i % m)) l.sort() visit = [0] * m m_l = [0] * m c = 0 for i in range(n): max_ = l[i][0] if visit[l[i][1]] == 0: ...
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBE...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
for _ in range(int(input())): n, m = map(int, input().split()) a = [int(x) for x in input().split()] colors = list(range(m)) * (n // m) + list(range(n % m)) a = sorted([[x, y] for x, y in zip(a, colors)]) color_slots = [None] * m min_arr = [] min_ind = 0 c_cnt = 0 res = 10**9 + 10 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
import sys from itertools import combinations def a_le(): return list(map(int, sys.stdin.readline().strip().split())) def int_le(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() for _ in range(int(input())): N, M = map(int, input().split()...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
for t in range(int(input())): n, m = list(map(int, input().split())) a = list(map(int, input().split())) d = {} for i in range(n): if a[i] in d.keys(): if (i + 1) % m != 0: d[a[i]].append((i + 1) % m) else: d[a[i]].append(m) elif (i...
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 ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
t = int(input()) def minDiff1(a, n, m, w): co = [0] * m done = [False] * m doall = [True] * m ca = a[n - 1] - a[0] i = 0 j = 0 while i < n: done[w[i]] = True co[w[i]] += 1 if w[i] == w[j] and i != j: co[w[j]] -= 1 j += 1 if done == do...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR V...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
def findsub(string, pat): len1 = len(string) len2 = len(pat) hash_pat = [0] * (10**5 + 1) hash_str = [0] * (10**5 + 1) for i in range(0, len2): hash_pat[pat[i]] += 1 mindif = 10**10 start, start_index, min_len = 0, -1, float("inf") count = 0 for j in range(0, len1): h...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_C...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
class Sequence: def __init__(self, m): self.m = m self.stack = [] self.indexes = [] self.present = {} for i in range(self.m): self.present[i] = False def isComplete(self): if len(self.stack) == self.m: return True return False ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
def solve(l): mi = [float("inf"), -1] ma = 0 for i in range(len(l)): if l[i] < mi[0]: mi[0] = l[i] mi[1] = i if l[i] > ma: ma = l[i] return ma - mi[0], mi[1] for t in range(int(input())): n, m = [int(i) for i in input().split()] a = [(int(j),...
FUNC_DEF ASSIGN VAR LIST FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
t = int(input()) for itr in range(t): nm = input().split(" ") n, m = int(nm[0]), int(nm[1]) a = list(map(int, input().split(" "))) collis = {} aa = [[a[i], i % m] for i in range(n)] aa.sort(reverse=True) mini = 1000000000 i = 0 while len(collis.keys()) < m: if collis.get(aa[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR LIST VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR V...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
t = int(input()) for _ in range(t): length, m = map(int, input().split()) a = list(map(int, input().split())) ans = [0] * m answer = 10000000000 res = [[0, 0] for i in range(length)] lookup = [0] * m for i in range(length): res[i][0] = a[i] res[i][1] = i % m res = sorted(...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMB...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
t = int(input()) for _ in range(t): n, m = map(int, input().split()) arr = [int(x) for x in input().split()] mat = [] for j in range(m): temp = [arr[i] for i in range(j, n, m)] temp.sort() mat.append(temp) mini = 10**10 flag = 0 temp = [mat[i][0] for i in range(m)] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN V...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
t = int(input()) for _ in range(t): n, m = map(int, input().split()) func = lambda x: (int(x[1]), x[0] % m) arr = list(map(func, enumerate(input().split()))) arr.sort() cnt = [0] * m cnt0 = m r = 0 ans = float("inf") for l in range(n): while r < n and cnt0 > 0: cn...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
t = int(input()) for _ in range(t): n, m = map(int, input().split()) a = list(map(int, input().split())) final = [] final = [(j % m) for j in sorted([i for i in range(n)], key=lambda x: a[x])] a.sort() found = {} i = 0 j = 0 ans = a[-1] - a[0] while i < n - m + 1 and j < n: ...
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 LIST ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT AS...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
t = int(input()) while t > 0: t -= 1 n, m = input().split() n, m = int(n), int(m) k = list(map(int, input().split())) s = [0] * n j = 0 v = [0] * m while j != n: for i in range(m): s[j] = i j += 1 if j >= n: break z = [x for...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR 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 BIN_OP LIST NUMBER VAR WHILE VAR ...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
import sys def smallestDifference(colors, arr): color_count = [0] * colors arr_with_color = list(zip(arr, [i for i in range(len(arr))])) arr_with_color.sort(key=lambda x: x[0]) i, j = 0, 0 mini_diff = sys.maxsize count = 0 while i <= len(arr): if count < colors and i < len(arr): ...
IMPORT FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMB...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
t = int(input()) for i in range(t): n, m = list(map(int, input().split())) arr = list(map(int, input().split())) currArr = [arr[x] for x in range(m)] arr = [[arr[x], x % m] for x in range(n)] arr = sorted(arr) maxVal = max(currArr) minVal = min(currArr) answer = maxVal - minVal for x...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
def sortSecond(val): return val[0] for T in range(int(input())): n, m = map(int, input().split()) l = list(map(int, input().split())) temp = [] for i in range(n): temp.append([l[i], i % m]) temp.sort(key=sortSecond) temp1 = [0] * m st = 0 for i in range(n): temp1[te...
FUNC_DEF RETURN VAR NUMBER 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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN ...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
def customSort(a): return a[0] T = int(input()) for t in range(T): N, M = list(map(int, input().strip().split(" "))) A_temp = list(map(int, input().strip().split(" "))) A = [] for n in range(N): A.append([A_temp[n], n % M]) A = sorted(A, key=customSort) colors = set() boxes = d...
FUNC_DEF RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
for q in range(int(input())): n, m = map(int, input().split()) l1, l, c, f, r, result = ( [int(x) for x in input().split()], [], [0] * m, 0, 0, 10**10, ) for i in range(0, n): l2 = [] l2.append(l1[i]), l2.append(i % m) l.append(l2) ...
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 VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST BIN_OP LIST NUMBER VAR NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR V...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
t = int(input()) for i in range(t): n, m = map(int, input().split()) a = [int(v) for v in input().split()] s = [[(0) for j in range(2)] for i in range(n)] k = 0 for j in range(n): s[j][0] = a[j] s[j][1] = k k = k + 1 if k == m: k = 0 s.sort() v = {...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR AS...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
def find(N, M, arr): pos = [] for i in range(len(arr)): pos.append([i % M, i]) pos.sort(key=lambda x: arr[x[1]]) arr.sort() cnt = [0] * M mask = 2**M - 1 i = 0 j = 0 while pos[i][0] == pos[j][0]: cnt[pos[j][0]] += 1 j += 1 cnt[pos[j][0]] += 1 chk = 1 <...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR VAR NUMBER VAR VAR VA...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
for _ in range(int(input())): n, m = [int(x) for x in input().split()] l = [int(x) for x in input().split()] a = [(i % m) for i in range(n)] l1 = [] values = [] a = [a for _, a in sorted(zip(l, a))] l.sort() max_val = 99999999999 arr = [(-1) for x in range(m)] for i in range(n): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CAL...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
class MinHeapNode: def __init__(self): self.element = 0 self.i = 0 self.j = 0 class MinHeap: def __init__(self, a, size): self.heap_size = size self.harr = a i = (self.heap_size - 1) // 2 while i >= 0: self.MinHeapify(i) i -= 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
def next(mapping, bucket_count, bucket_count_set, colors, start): end = start while end < len(mapping): ball, bucket = mapping[end] bucket_count_set.add(bucket) bucket_count[bucket] += 1 if len(bucket_count_set) == colors: return end, bucket_count, bucket_count_set ...
FUNC_DEF ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER...
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well. Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls. Then, Chef painted the boxes using $M$ distinct colours in such a way that for each $M$ consecutive boxes, no two of ...
t = int(input()) for _ in range(t): n, m = list(map(int, input().split())) ar = list(map(int, input().split())) col = 0 arr = [] for i in range(n): arr.append([ar[i], col % m]) col += 1 arr.sort(key=lambda x: x[0]) dic = {} i = j = 0 ans = float("inf") while j < n...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR VAR VAR NUMBER...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
n = int(input()) s = list(input()) x, y = map(int, input().split()) it = [0, 0, 0, 0] for i in range(len(s)): if s[i] == "U": s[i] = 0 elif s[i] == "R": s[i] = 1 elif s[i] == "D": s[i] = 2 else: s[i] = 3 it[s[i]] += 1 def distance(x, y, xx, yy): return abs(x - x...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASS...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
from sys import stdin n = int(stdin.readline()) s = stdin.readline().strip() x, y = [int(z) for z in stdin.readline().split()] x2 = s.count("R") - s.count("L") y2 = s.count("U") - s.count("D") if x == x2 and y == y2: print(0) elif (x - x2 + y - y2) % 2 == 1: print(-1) elif x + y > n: print(-1) else: lo...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP BIN...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
def check(num): r = R[n - 1] - R[num - 1] l = L[n - 1] - L[num - 1] u = U[n - 1] - U[num - 1] d = D[n - 1] - D[num - 1] if abs(x - (r - l)) + abs(y - (u - d)) <= num: return True for i in range(num, n): r = R[n - 1] - (R[i] - R[i - num]) l = L[n - 1] - (L[i] - L[i - num])...
FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
import sys def input(): return sys.stdin.readline().rstrip() def slv(): n = int(input()) s = list(input()) x, y = map(int, input().split()) if not (abs(x) + abs(y) <= n and (abs(x) + abs(y) - n) % 2 == 0): print(-1) return tot_x, tot_y = 0, 0 for c in s: if c == "...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
def valid(step, tx, ty, nx, ny, s, d): fx = 0 fy = 0 for i in range(len(s)): c = s[i] fx += d[c][0] fy += d[c][1] if i >= step: c = s[i - step] fx -= d[c][0] fy -= d[c][1] if i >= step - 1: diff = abs(nx - fx - tx) + abs...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BI...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
n = int(input()) a = input() x, y = map(int, input().split()) locs = [(0, 0)] for i in range(n): if a[i] == "U": locs.append((locs[-1][0], locs[-1][1] + 1)) elif a[i] == "D": locs.append((locs[-1][0], locs[-1][1] - 1)) elif a[i] == "R": locs.append((locs[-1][0] + 1, locs[-1][1])) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER NUMBER B...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
def doable(n, x, y, m, prefixLR, prefixUD): for i in range(n - m + 1): j = i + m - 1 dx = prefixLR[i] + prefixLR[-1] - prefixLR[j + 1] dy = prefixUD[i] + prefixUD[-1] - prefixUD[j + 1] if abs(x - dx) + abs(y - dy) <= m: return True return False def main(): n = i...
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN NUMBER RE...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
n = int(input()) dirs = input() goal = list(map(int, input().split(" "))) def can(start, end, steps): dist = abs(start[0] - end[0]) + abs(start[1] - end[1]) return dist <= steps and (steps - dist) % 2 == 0 if not can((0, 0), goal, n): print(-1) return diffs = {"U": (0, 1), "D": (0, -1), "L": (-1, 0)...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR N...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
n = int(input()) a = input() x, y = map(int, input().split()) if abs(x) + abs(y) > n or (x + y + n) % 2 != 0: print(-1) else: dx = [0] * n dy = [0] * n for i in range(n): if a[i] == "R": dx[i] = 1 elif a[i] == "L": dx[i] = -1 elif a[i] == "U": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR ...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
n = int(input().strip()) s = str(input().strip()) x, y = list(map(int, input().strip().split())) sumx = [] sumy = [] sx = 0 sy = 0 sumx.append(sx) sumy.append(sy) for i in s: if i == "U": sy += 1 elif i == "D": sy -= 1 elif i == "R": sx += 1 elif i == "L": sx -= 1 sum...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR STRING V...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
class Vec(object): def __init__(self, x, y): self.x, self.y = x, y def __add__(self, other): return Vec(self.x + other.x, self.y + other.y) def __sub__(self, other): return Vec(self.x - other.x, self.y - other.y) def len(self): return abs(self.x) + abs(self.y) de...
CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR STRING VAR ASSIGN VAR DICT STRING STRING STRING STRING FUNC_CALL VAR NUMBER...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
d = {"U": (0, 1), "D": (0, -1), "L": (-1, 0), "R": (1, 0)} def compute_delta(s, head_idx, tail_idx): x = y = 0 for i in range(head_idx, tail_idx): x, y = x + d[s[i]][0], y + d[s[i]][1] return [x, y] n = int(input()) s = input() dsc = list(map(int, input().split())) total = compute_delta(s, 0, n)...
ASSIGN VAR DICT STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER RETURN LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
import sys n = int(input()) S = input() x, y = map(int, input().split()) if abs(x) + abs(y) > n or (abs(x) + abs(y)) % 2 != n % 2: print(-1) sys.exit() now = [0, 0] LISTL = [(0, 0)] for s in S: if s == "R": now[0] += 1 elif s == "L": now[0] -= 1 elif s == "U": now[1] += 1 ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
def check(length: int): global n, x, y, cur, hor, ver hor = 0 ver = 0 for i in range(length, n): upd(i) for i in range(n - length + 1): if abs(x - hor) + abs(y - ver) <= length: return True if i + length < n: upd(i) minus_upd(i + length) ...
FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RE...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
n = int(input()) dx = [(0) for i in range(n + 1)] dy = [(0) for i in range(n + 1)] for i, ch in enumerate(input()): dx[i + 1] = dx[i] dy[i + 1] = dy[i] if ch == "U": dy[i + 1] += 1 elif ch == "D": dy[i + 1] -= 1 elif ch == "R": dx[i + 1] += 1 else: assert ch == "L...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR STRING VAR BIN_OP VAR NUMBER NUMBER IF VAR STRING VA...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
n = int(input()) s = input() p, q = input().split() if p[0] == "-": x = -1 * int(p[1:]) else: x = int(p) if q[0] == "-": y = -1 * int(q[1:]) else: y = int(q) cur = [0, 0] if abs(x) + abs(y) > n: print(-1) elif (x + y) % 2 != n % 2: print(-1) else: end = n for i in range(n): if s[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST N...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
def is_check(x): i = 1 j = x h, v = 0, 0 while j <= n: h = sum_x[n] - sum_x[j] + (sum_x[i - 1] - sum_x[0]) v = sum_y[n] - sum_y[j] + (sum_y[i - 1] - sum_y[0]) i += 1 j += 1 if abs(x_f - h) + abs(y_f - v) <= x: return 1 return 0 n = int(input()) s...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VA...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
n = int(input()) s = list(input()) a, b = list(map(int, input().split())) L = s.count("L") U = s.count("U") R = s.count("R") D = s.count("D") x = 0 y = 0 xmin = 0 ymin = 0 minn = 2 * n while x + y < 2 * n: if abs(a - (R - L)) + abs(b - (U - D)) > y - x and y != n: i = s[y] if i == "L": L...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN ...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
def go(pos, k): if "U" == k: pos[1] += 1 elif "D" == k: pos[1] -= 1 elif "L" == k: pos[0] -= 1 else: pos[0] += 1 return pos def relapos(a, b): c = [b[0] - a[0], b[1] - a[1]] return c def stdis(a, b): return abs(b[1] - a[1]) + abs(b[0] - a[0]) n = int...
FUNC_DEF IF STRING VAR VAR NUMBER NUMBER IF STRING VAR VAR NUMBER NUMBER IF STRING VAR VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR N...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
n = int(input()) root = input() x, y = list(map(int, input().split())) curx, cury = 0, 0 dx, dy = [0], [0] for i in range(n): if root[i] == "L": curx -= 1 if root[i] == "R": curx += 1 if root[i] == "U": cury += 1 if root[i] == "D": cury -= 1 dx.append(curx) dy.app...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR LIST NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF V...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
N = int(input()) ops = [x for x in input()] X, Y = map(int, input().split()) dd = abs(X) + abs(Y) lops = len(ops) if dd > lops or (lops - dd) % 2 != 0: print(-1) exit(0) [ll, lr, lu, ld, rl, rr, ru, rd] = [[(0) for _ in range(lops + 2)] for _ in range(8)] l, r, u, d = 0, 0, 0, 0 for i in range(lops): op = o...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN LI...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
n = int(input()) subtract = lambda t1, t2: (t1[0] - t2[0], t1[1] - t2[1]) add = lambda t1, t2: (t1[0] + t2[0], t1[1] + t2[1]) def conv(ch): if ch == "L": return -1, 0 elif ch == "R": return 1, 0 elif ch == "U": return 0, 1 elif ch == "D": return 0, -1 ops = [conv(ch) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF IF VAR STRING RETURN NUMBER NUMBER IF VAR STRING RETURN NUMBER NUMBER IF VAR STRING RETURN NUMBER NUMBER IF VAR STRING RETURN NUMBER N...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
import sys input = sys.stdin.readline n = int(input()) s = [i for i in input() if i != "\n"] x, y = map(int, input().split()) if abs(x) + abs(y) > n or (abs(x) + abs(y)) % 2 != n % 2: print(-1) else: dx, dy = [], [] for i in range(n): if s[i] == "R": dx.append(1) dy.append(0...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN ...
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β€” move from $(x, y)$ to $(x, y + 1)$; D β€” move from $(x, y)$ to $(x, y - 1)$; L β€” move from $(x, y)$ to $(x - 1, y)$; R β€” move from $(x, y)$ to $(x + 1...
def check(x, y, fx, fy, num_moves): if ( abs(fx - x) + abs(fy - y) - num_moves <= 0 and (abs(fx - x) + abs(fy - y) - num_moves) % 2 == 0 ): return True return False N = int(input()) mm = {"U": 0, "D": 1, "L": 2, "R": 3} dpmat = [[0] for i in range(4)] ops = str(input()) for op in o...
FUNC_DEF IF BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING NUMBER NUMBER NUM...