description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) ops = 0 height = list(map(int, input().split())) ans = [] while ops < k: pos_lo, lo = min(enumerate(height), key=lambda x: x[1]) pos_hi, hi = max(enumerate(height), key=lambda x: x[1]) if hi == lo: break height[pos_lo] += 1 height[pos_hi] -= 1 ans.append(...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VA...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) data = list(map(int, input().split())) position = [i for i in range(1, n + 1)] step = 0 result = [] for i in range(k): new_data = sorted(data) n_position = [x for _, x in sorted(zip(data, position))] if max(new_data) - min(new_data) > 1: new_data[0] += 1 new_...
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 VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VA...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, m = map(int, input().split()) b = list(map(int, input().split())) a = [] for i in range(n): a.append([b[i], i + 1]) i, count = 0, 0 c = [] while i < m: a.sort() if a[0][0] != a[-1][0] and a[0][0] + 1 != a[-1][0]: a[0][0] += 1 a[-1][0] -= 1 c.append([a[-1][1], a[0][1]]) a.s...
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 NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR N...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) a = list(map(int, input().split())) a = [[a[x], x] for x in range(n)] a.sort() ans = [] while k > 0 and a[-1][0] != a[0][0]: a[-1][0] -= 1 a[0][0] += 1 k -= 1 ans.append((a[-1][1] + 1, a[0][1] + 1)) a.sort() print(a[-1][0] - a[0][0], len(ans)) for x in ans: print...
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 VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMB...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) bzz = [] cnt = 0 A = list(map(int, input().split())) for i in range(k): if max(A) - min(A) != 0: i1, i2 = 0, 0 ma, mi = 0, 10**9 for i in range(n): if A[i] > ma: ma = A[i] i1 = i if A[i] < mi: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER FOR VAR FUN...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
import sys def read(line): return [int(c) for c in line.strip().split()] def main(): test = sys.stdin.readlines() n, k = read(test[0]) towers = read(test[1]) towers_max = 10001 min_k = 0 ops = [] prev_diff = max(towers) - min(towers) min_diff = prev_diff for it in range(1, k ...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VA...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) l = list(map(int, input().split())) count = 0 l1 = [] l2 = [] while count < k: x = l.index(max(l)) y = l.index(min(l)) if l[x] - l[y] == 1 or l[x] - l[y] == 0: break l1.append(x + 1) l2.append(y + 1) l[x] = l[x] - 1 l[y] = l[y] + 1 count = count +...
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 ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VA...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = [int(v) for v in input().split()] a = [int(v) for v in input().split()] dd = dict() for i in range(n): if a[i] in dd: dd[a[i]].append(i) else: dd[a[i]] = [i] b = sorted(set(a)) mm = list(range(k + 1)) i = 0 move = [[0, 0]] * (k + 1) while i <= k - 1 and b[-1] - b[0] > 1: i = i + 1 ...
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 FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
class CodeforcesTask479BSolution: def __init__(self): self.result = "" self.n_k = [] self.heights = [] def read_input(self): self.n_k = [int(x) for x in input().split(" ")] self.heights = [int(x) for x in input().split(" ")] def process_task(self): res = []...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FU...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) towers = list(map(int, input().split())) def get_min_max_indices(): tmp = towers[0] max_index = 0 min_index = 0 for i in range(1, len(towers)): if towers[i] > towers[max_index]: max_index = i if towers[i] < towers[min_index]: min...
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 FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) arr = list(map(int, input().split())) ans = [] op = 0 factor = max(arr) - min(arr) while factor > 1 and op < k: m = arr.index(min(arr)) M = arr.index(max(arr)) arr[m] += 1 arr[M] -= 1 op += 1 ans.append([M + 1, m + 1]) factor = max(arr) - min(arr) print(facto...
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 NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR V...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) arr = [int(i) for i in input().split()] ans = [] while k >= 0: x = 0 y = 0 for j in range(n): if arr[j] > arr[x]: x = j if arr[j] < arr[y]: y = j if k == 0 or arr[x] - arr[y] <= 1: print(arr[x] - arr[y], len(ans)) f...
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 WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) tab = [(0) for loop in range(n)] t = input().split() for i in range(n): tab[i] = int(t[i]) def max(): global n y = 0 j = 0 for i in range(n): if tab[i] > y: y = tab[i] j = i return j def min(): global n x = 100000 j...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETUR...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(sorted(([val, ind] for ind, val in enumerate(a, 1)), reverse=True)) t = 0 li = [] minm = b[0][0] - b[-1][0] for i in range(k): diff = b[0][0] - b[-1][0] if diff > 0 and diff <= minm: t += 1 b[0][0] -= 1 b[-1][0...
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 LIST VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CAL...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) arr = list(map(int, input().split())) diff = [] ops = [] for i in range(k): x = arr.index(max(arr)) y = arr.index(min(arr)) if i == 0 and max(arr) - min(arr) == 0: diff.append(0) ops.append(None) else: arr[x] += -1 arr[y] += 1 ops....
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) a = list(map(int, input().split())) ret = [] for _ in range(k): minI, maxI = a.index(min(a)), a.index(max(a)) if a[maxI] - a[minI] <= 1: break a[maxI] -= 1 a[minI] += 1 ret.append("%d %d" % (maxI + 1, minI + 1)) print("%d %d\n%s" % (max(a) - min(a), len(ret),...
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 ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CA...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) a = [*map(int, input().split())] q = sum(a) q = q // n + (q % n != 0) l = [] m = 0 for i in range(k): if max(a) - min(a) <= 1: break w, e = a.index(max(a)), a.index(min(a)) a[w] -= 1 a[e] += 1 l += [[w + 1, e + 1]] m += 1 print(max(a) - min(a), m) for i i...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN V...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) lst = list(map(int, input().split())) x = len(lst) for i in range(x): lst[i] = [lst[i], i] orig = k temp = 0 ans = [] while k > 0: k -= 1 lst.sort() if lst[n - 1][0] - lst[0][0] > 1: lst[n - 1][0] -= 1 lst[0][0] += 1 ans.append([lst[n - 1][1], lst...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) a = list(map(int, input().split())) ct = 0 moves = [] for i in range(k): ma = a.index(max(a)) mi = a.index(min(a)) if a[ma] - a[mi] > 1 and ma != mi: a[ma] -= 1 a[mi] += 1 moves.append([ma + 1, mi + 1]) else: break ct += 1 print(max(a)...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR VAR N...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) t, o = [], [] for i, h in enumerate(map(int, input().split())): t.append([h, i + 1]) for i in range(k): t.sort() if t[0][0] >= t[-1][0] - 1: break t[0][0] += 1 t[-1][0] -= 1 o.append((t[-1][1], t[0][1])) t.sort() print(t[-1][0] - t[0][0], len(o)) for oi i...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER V...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) l = [int(i) for i in input().split()] l1 = [[l[i], i + 1] for i in range(n)] l1.sort() ans = [] k1 = k if len(set(l)) == 1: print(0, 0) exit() while k: k -= 1 l1[0][0], l1[n - 1][0] = l1[0][0] + 1, l1[n - 1][0] - 1 ans.append([l1[n - 1][1], l1[0][1]]) l1.sort() ...
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 VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VA...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) a = list(map(int, input().split())) for i in range(n): a[i] = [a[i], i + 1] res = [] i = 0 if n > 1: for i in range(k): a.sort(reverse=True) if a[0][0] - 1 > a[-1][0]: res.append([a[0][1], a[-1][1]]) a[0][0] -= 1 a[-1][0] += 1 ...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUM...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = list(map(int, input().split())) towers = list(map(int, input().split())) log_moves = [] def max(l): m = 0 for i, n in enumerate(l): if n > l[m]: m = i return m def min(l): m = 0 for i, n in enumerate(l): if n < l[m]: m = i return m mx = max(to...
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 LIST FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] for i in range(n): a[i] = [a[i], i] a.sort() ans = [] for i in range(k): if all(x == a[0] for x in a): break l = 0 r = n - 1 for i in range(n - 1): if a[i][0] < a[i + 1][0]: l = i b...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUM...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
n, k = map(int, input().split()) arr = [0] * n l = 1 for i in list(map(int, input().split())): arr[l - 1] = [i, str(l)] l += 1 arr.sort() ans = [] m = 10**5 for i in range(k): if arr[-1][0] - arr[0][0] <= 1 or arr[-1][0] - arr[0][0] > m: break m = arr[-1][0] - arr[0][0] arr[0][0] += 1 ar...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER LIST VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_...
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highes...
operations = [] a = input().split(" ") towers = input().split(" ") k = int(a[1]) for i in range(len(towers)): towers[i] = int(towers[i]) def inst(tset): return max(tset) - min(tset) def fix(towerset): proset = [] for element in towerset: proset.append(element) b = proset.index(max(proset...
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_C...
This is the easy version of the problem. The only difference between the versions is the constraints on $n$, $k$, $a_i$, and the sum of $n$ over all test cases. You can make hacks only if both versions of the problem are solved. Note the unusual memory limit. You are given an array of integers $a_1, a_2, \ldots, a_n$...
for _ in range(int(input())): N, K = map(int, input().split()) a = [*map(int, input().split())] ps = [0] * (10**5 + 10) for i in range(N): pv, j = 10**9, 1 while j <= min(a[i], K): nv = a[i] // j ps[nv + 1] = max(ps[nv + 1], pv) pv = nv j =...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL V...
This is the easy version of the problem. The only difference between the versions is the constraints on $n$, $k$, $a_i$, and the sum of $n$ over all test cases. You can make hacks only if both versions of the problem are solved. Note the unusual memory limit. You are given an array of integers $a_1, a_2, \ldots, a_n$...
for _ in range(int(input())): _, k = map(int, input().split()) a = list(map(int, input().split())) print(min(max(x // min(k, x // u) for x in a) - u for u in range(1, a[0] + 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 EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR ...
This is the easy version of the problem. The only difference between the versions is the constraints on $n$, $k$, $a_i$, and the sum of $n$ over all test cases. You can make hacks only if both versions of the problem are solved. Note the unusual memory limit. You are given an array of integers $a_1, a_2, \ldots, a_n$...
def compute(a, p): s = [(a[i] // p[i]) for i in range(len(a))] return max(s) - min(s) for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) m = max(a) l = min(a) t = m // k if k >= m: print(0) elif k == 1: print(max(a) - ...
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_C...
This is the easy version of the problem. The only difference between the versions is the constraints on $n$, $k$, $a_i$, and the sum of $n$ over all test cases. You can make hacks only if both versions of the problem are solved. Note the unusual memory limit. You are given an array of integers $a_1, a_2, \ldots, a_n$...
def main(): n, k = map(int, input().split()) arr = list(map(int, input().split())) ans = float("inf") mx = max(arr) for d in range(1, mx + 1): aux = [] for z in arr: if z <= d: aux.append(z) else: a = min(z // d, k) ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_C...
Did you know that the yummy golden triangle was introduced in India as early as 13th century ? By the way, I'm referring to the popular South Asian snack, Samosa. I guess its hard to code while thinking of Samosa, especially if you are very hungry now ; so lets not get in to any recipe or eating game. You have N box...
def solve(): T = int(input()) for t in range(T): no_boxes = int(input()) boxes = [(int(temp) * 7) for temp in input().split()] no_bands = int(input()) rubber_bands = [] for b in range(no_bands): R1, R2 = input().split() rubber_bands.append([int(R2)...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL V...
Did you know that the yummy golden triangle was introduced in India as early as 13th century ? By the way, I'm referring to the popular South Asian snack, Samosa. I guess its hard to code while thinking of Samosa, especially if you are very hungry now ; so lets not get in to any recipe or eating game. You have N box...
for _ in range(int(input())): a = int(input()) b = list(map(int, input().split())) c = int(input()) d = [] for y in range(c): e, f = input().split() d.append((int(f), int(e))) used = [False] * c b.sort() d.sort() count = 0 for i in range(a): p = 7 * b[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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CA...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
def solve(): for i in range(int(input())): n, k = map(int, input().split()) s = input().strip() if k == 1: print(s) continue if n % k != 0: print(-1) continue want = [0] * 26 need = 0 i = 0 best = -1 ...
FUNC_DEF 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 FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN V...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
import sys def input(): return sys.stdin.readline().rstrip() SIZE = 26 def tostr(x): return chr(x + ord("a")) def slv(): n, k = map(int, input().split()) S = list(map(lambda x: ord(x) - ord("a"), list(input()))) if n % k != 0: print(-1) return c = [0] * SIZE for i in ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR ...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
import sys input = sys.stdin.buffer.readline def solve(): N, K = map(int, input().split()) S = list(input()) for i in range(N): S[i] -= 97 if N % K: print(-1) return 0 C = [0] * 26 for i in range(N): C[S[i]] += 1 C = [0] * 26 for i in range(N): ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR B...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
import sys def main(): import sys input = sys.stdin.readline T = int(input()) alpha = "abcdefghijklmnopqrstuvwxyz" da = dict() ANS = [] for i, x in enumerate(alpha): da[x] = i for _ in range(T): n, k = map(int, input().split()) s = input().rstrip() if n...
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
import sys t = int(input()) for _ in range(t): n, k = [int(x) for x in input().split()] s = input() if n % k: print(-1) continue temp = [(0) for i in range(26)] for i in s: temp[ord(i) - ord("a")] += 1 f = True for i in temp: if i % k: f = False ...
IMPORT 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 IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
def possible(s, index, letters, k, ans): req = 0 for i in letters: req += (k - i) % k give = len(s) - index if req > give: return False if (give - req) % k != 0: return False while len(s) != index: s.pop() for i in range(give - req): s.append("a") ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR RETURN NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN NUMBER WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMB...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
def check_str(s, k): d = {} for ch in s: if ch in d: d[ch] += 1 else: d[ch] = 1 cnt = 0 for ch in d: if d[ch] % k != 0: cnt = 1 break if cnt == 1: return False else: return True def inc_lex(s): val = le...
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR STRING ASSIGN...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
for _ in range(int(input())): n, k = map(int, input().split()) s = list(input()) if len(s) % k != 0: print(-1) continue count = [0] * 26 for e in s: i = ord(e) - 97 count[i] += 1 isBeuty = True for i in range(26): if count[i] % k != 0: isBe...
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 IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER AS...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
def solve(n, k, s): if n % k: return -1 if k == 1: return s d = {} cnt = 0 pref = [] for i in range(n): pref.append(cnt) if s[i] not in d: d[s[i]] = 1 else: d[s[i]] += 1 if d[s[i]] % k == 1: cnt += k - 1 ...
FUNC_DEF IF BIN_OP VAR VAR RETURN NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
gans = [] for _ in range(int(input())): n, k = map(int, input().split()) u = list(input()) for i in range(n): u[i] = ord(u[i]) - ord("a") z = [] for i in range(26): z.append([]) z[-1].append(0) z[u[0]][0] += 1 z[u[0]][0] %= k for i in range(1, n): for j in...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIS...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
from sys import stdin, stdout t = int(input()) for _ in range(t): n, k = map(int, input().split()) s = input() if n % k: print(-1) continue vals = [(0) for i in range(26)] for i in s: vals[ord(i) - 97] += 1 for i in vals: if i % k: break else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR VAR E...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
import sys def charToInt(c): return ord(c) - ord("a") def intToChar(x): return chr(ord("a") + x) def main(): t = int(input()) allans = [] for _ in range(t): n, k = readIntArr() s = input() if n % k != 0: allans.append(-1) continue sarr = ...
IMPORT FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR N...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
def inc(s, freq, k, i): freq[ord(s[i]) - ord("a")] -= 1 if s[i] == "z": return False else: for c in range(ord(s[i]) + 1, ord("z") + 1): freq[c - ord("a")] += 1 mand = 0 for j in range(26): if freq[j] % k != 0: mand += k ...
FUNC_DEF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR STRING NUMBER VAR BIN_OP VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR BI...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
from sys import stdin, stdout def k_beautiful_strings(n, k, s): if n % k != 0: return "-1" cnt_a = [0] * 26 for c in s: cnt_a[ord(c) - ord("a")] += 1 need = calc_need(cnt_a, k) if need == 0: return s for i in range(n - 1, -1, -1): need += delta_need(cnt_a, ord(s...
FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUN...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
def toNum(letter): return ord(letter) - ord("a") def toChr(num): return chr(num + ord("a")) def getRemaining(num, k): return (k - num % k) % k def getRemainingSum(k, cnt): sm = 0 for num in cnt: sm += getRemaining(num, k) return sm for cases in range(int(input())): n, k = map...
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FU...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
import sys from sys import stdin def solve(N, K, S): if N % K != 0: print(-1) return cnt_dict = {} for s in S: cnt_dict[s] = 0 for s in S: cnt_dict[s] += 1 bea = True for k in cnt_dict: if cnt_dict[k] % K != 0: bea = False if bea: ...
IMPORT FUNC_DEF IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR V...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
import sys input = sys.stdin.readline def index(i): return ord(i) - ord("a") def get(x, k): return (k - x % k) % k t = int(input()) for _ in range(t): n, k = map(int, input().split()) s = input() if s[-1] == "\n": s = s[:-1] count = [0] * 26 for i in s: count[index(i)]...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR VAR ...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
import sys input = sys.stdin.readline t = int(input()) for tests in range(t): n, k = map(int, input().split()) S = list(input().strip()) SA = S[:] + ["z"] COUNT = [([0] * 26) for i in range(n)] for i in range(n): for j in range(26): COUNT[i][j] = COUNT[i - 1][j] COUNT[i]...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR LIST STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR ...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
def check(d, k): delta = n - sum(d) for i in d: delta -= (k - i % k) % k if delta < 0: return False else: return True def try_(index, d, i): for jindex in range(index + 1, len(d)): d[jindex] += 1 if check(d, k): s[i] = chr(97 + jindex) ...
FUNC_DEF ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR RETURN NUMBER VAR VAR ...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
import sys zz = 1 sys.setrecursionlimit(10**5) if zz: input = sys.stdin.readline else: sys.stdin = open("input.txt", "r") sys.stdout = open("all.txt", "w") di = [[-1, 0], [1, 0], [0, 1], [0, -1]] def fori(n): return [fi() for i in range(n)] def inc(d, c, x=1): d[c] = d[c] + x if c in d else x ...
IMPORT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF NU...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
test = int(input()) def check(k): for i in range(26): if num[i] % k != 0: return 0 return 1 def getval(k): res = 0 for i in range(26): if num[i] % k != 0: res += k - num[i] % k return res for i in range(test): n, k = map(int, input().split(" ")) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR V...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
import sys input = lambda: sys.stdin.readline().rstrip("\r\n") s = 0, 1, 2, 5, 8 d = {(0): 0, (1): 1, (2): 5, (5): 2, (8): 8} b = [[0, 0], [0, 1]] for _ in range(int(input())): n, k = map(int, input().split()) a = input() ans = str() if len(a) % k: print(-1) else: dp = [0] * 26 ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FU...
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose...
from sys import stdin inFile = stdin tokens = [] tokens_next = 0 def next_str(): global tokens, tokens_next while tokens_next >= len(tokens): tokens = inFile.readline().split() tokens_next = 0 tokens_next += 1 return tokens[tokens_next - 1] def nextInt(): return int(next_str()) ...
ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FU...
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose...
n = int(input()) seg = [] for i in range(n): l, r = map(int, input().split()) seg.append((l, r, i)) seg.sort(key=lambda tup: (tup[1], tup[0], tup[2])) assigned = set() ans = [0] * n for i in range(n): for j in range(seg[i][0], seg[i][1] + 1, 1): if j not in assigned: ans[seg[i][2]] = j ...
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 EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_C...
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose...
n = int(input()) freq = [0] * 10000001 ans = [0] * 100 a = [] for i in range(n): l, r = map(int, input().split()) temp = r, l, i a.append(temp) a.sort() for i in range(n): r, l, v = a[i][0], a[i][1], a[i][2] for j in range(l, r + 1): if freq[j] == 0: freq[j] = 1 ans[v...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VA...
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose...
n = int(input()) a, ans, b = [], [0] * n, [0] * 10000001 for i in range(n): L, R = map(int, input().split()) a.append([R, L, i]) a.sort() for z in a: R, L, i = z for j in range(L, R + 1): if b[j] == 0: b[j] = 1 ans[i] = j break print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VA...
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose...
n = int(input()) arr = [0] * 10000001 ans = [0] * 100 print() a2 = [] for i in range(n): l, r = map(int, input().split()) tmp = r, l, i a2.append(tmp) a2.sort() for i in range(n): m = a2[i] r = m[0] l = m[1] v = m[2] dif = r - l + 1 for j in range(dif): if arr[l + j] == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER EXPR 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 VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VA...
On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose...
n = int(input()) intervals = [list(map(int, input().split())) for i in range(n)] intervals = list(enumerate(intervals)) intervals.sort(key=lambda x: (x[1][1], x[1][0])) ans = [0] * n vis = set() for idx, (l, _) in intervals: while l in vis: l += 1 vis.add(l) ans[idx] = l print(" ".join(list(map(str,...
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 FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR WHILE VAR VAR V...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
import sys input = sys.stdin.readline n, m = map(int, input().split()) d = [0] * m h = [0] * m for i in range(m): d[i], h[i] = map(int, input().split()) ans = max(d[0] - 1 + h[0], max(h)) for i in range(1, m): dd = d[i] - d[i - 1] hh = h[i] - h[i - 1] if abs(dd) < abs(hh): print("IMPOSSIBLE") ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR ...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
__author__ = "Данила" n, m = map(int, input().split()) l = [] for i in range(m): d, h = map(int, input().split()) l.append((d, h)) k = -1 flag = True for i in range(m - 1): b = l[i + 1][1] a = l[i][1] y = l[i + 1][0] x = l[i][0] if a + y - x >= b and a - y + x <= b: if (y - x - a + b...
ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASS...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = [int(x) for x in input().split()] d = [] h = [] s = 0 amax = 0 for i in range(m): p, q = [int(x) for x in input().split()] d.append(p) h.append(q) for i in range(m - 1): if abs(h[i + 1] - h[i]) / (d[i + 1] - d[i]) > 1: print("IMPOSSIBLE") s += 1 break if s == 0: for i ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CAL...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
from sys import stdin input = stdin.readline n, m = (int(x) for x in input().split()) pd, ph = (int(x) for x in input().split()) res = ph + pd - 1 for i in range(1, m): d, h = (int(x) for x in input().split()) dd = d - pd dh = abs(h - ph) if dd < dh: print("IMPOSSIBLE") exit() dd -=...
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VA...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = [int(x) for x in input().split()] L = [[int(x) for x in input().split()] for z in range(m)] maxh = max([x[1] for x in L]) def possible(a, b): if abs(a[1] - b[1]) > abs(a[0] - b[0]): return False return True def maxp(a, b): t = abs(a[0] - b[0]) t -= abs(a[1] - b[1]) m = max(a[1], b...
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 VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_DEF IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF A...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split()) d, h = [], [] for i in range(m): di, hi = map(int, input().split()) d.append(di) h.append(hi) maximum = h[0] if d[0] != 1: d.insert(0, 1) h.insert(0, -1) m += 1 flag = 0 for i in range(1, m): diff = d[i] - d[i - 1] if h[i - 1] == -1: if diff + h[i...
ASSIGN 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split()) l_d, l_h = map(int, input().split()) m_h = l_h + l_d - 1 for i in range(1, m): n_d, n_h = map(int, input().split()) if abs(n_h - l_h) > n_d - l_d: print("IMPOSSIBLE") exit(0) m_h = max(m_h, max(l_h, n_h) + (n_d - l_d - abs(n_h - l_h)) // 2) l_d, l_h = n_d...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXP...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
N, M = list(map(int, input().split())) H = [] D = [] for i in range(M): d, h = list(map(int, input().split())) H.append(h) D.append(d) res = max(max(H), H[M - 1] + N - D[M - 1]) res = max(res, H[0] + D[0] - 1) for i in range(M - 1): dest = D[i + 1] - D[i] diff = abs(H[i + 1] - H[i]) if diff > de...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NU...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = list(map(int, input().split())) l = [] for i in range(m): l.append(list(map(int, input().split()))) ans = max(l[0][1] + l[0][0] - 1, l[-1][1] + n - l[-1][0]) for i in range(m - 1): if abs(l[i][1] - l[i + 1][1]) > abs(l[i][0] - l[i + 1][0]): ans = "IMPOSSIBLE" break if l[i][1] > l[i + ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUM...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split()) main = [] for i in range(m): d, h = map(int, input().split()) main.append((d, h)) s, e = False, False for d, h in main: if d == 1: s = True elif d == n: e = True start = [] if not s: start.append((0, main[0][0] - 1 + main[0][1])) if not e: start.a...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR EXPR FUN...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split()) notes = [[int(j) for j in input().split()] for i in range(m)] ans = max([i[1] for i in notes]) if notes[0][0] != 1: ans = max(ans, notes[0][0] - 1 + notes[0][1]) if notes[-1][0] != n: ans = max(ans, n - notes[-1][0] + notes[-1][1]) isOk = True for a, b in zip(notes, notes[1:]): ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR A...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
def isOk(a0, a1): i0, h0 = a0 i1, h1 = a1 if h1 < h0: return isOk((i0, h1), (i1, h0)) else: return i1 - i0 >= h1 - h0 def getMaxHeight(a0, a1): i0, h0 = a0 i1, h1 = a1 d = h1 - h0 s = i1 - i0 if h1 < h0: return getMaxHeight((i0, h1), (i1, h0)) elif h0 < ...
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR RETURN BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VA...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split()) res, pd, ph = 0, 0, 0 for i in range(m): d, h = map(int, input().split()) if i == 0: res = h + (d - 1) else: delta_d = d - pd delta_h = abs(h - ph) if delta_h > delta_d: print("IMPOSSIBLE") exit() res = max(res,...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
import sys n, m = map(int, str.split(sys.stdin.readline())) pd = ph = None top = None for _ in range(m): d, h = map(int, str.split(sys.stdin.readline())) if pd is None: top = d - 1 + h else: if pd and d - pd < abs(h - ph): print("IMPOSSIBLE") exit() delta = d...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NONE ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split()) prevd, prevh = map(int, input().split()) maxi = prevd - 1 + prevh check = 0 for i in range(m - 1): d, h = map(int, input().split()) if d - prevd >= abs(prevh - h): k = (d - prevd - abs(prevh - h)) // 2 if maxi < max(prevh + k, h + k): maxi = max(prevh...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSI...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = input().split() n = int(n) m = int(m) arr = [] for i in range(m): d, h = input().split() arr.append([int(d), int(h)]) last = arr[0] res = arr[0][1] for i in range(1, m): if arr[i][0] - last[0] < abs(arr[i][1] - last[1]): print("IMPOSSIBLE") exit() else: diff = arr[i][1] - ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VA...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = list(map(int, input().split(" "))) d = [] for i in range(m): d.append(list(map(int, input().split(" ")))) ispossible = True maxheights = [] maxheights.append(d[0][1] + d[0][0] - 1) maxheights.append(d[-1][1] + n - d[-1][0]) for i in range(m - 1): d1 = d[i] d2 = d[i + 1] if abs(d2[1] - d1[1]) > d2...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUN...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
def f(d1, h1, d2, h2): lo, hi = max(0, h1 - (d2 - d1)), min(10**8, h1 + (d2 - d1)) if h2 < lo or h2 > hi: return False, float("-inf") else: if h1 < h2: h1, d1 = h2, d1 + (h2 - h1) elif h1 > h2: h2, d2 = h1, d2 - (h1 - h2) return True, h1 + (d2 - d1) //...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR VAR RETURN NUMBER FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR RETURN NUMBER BIN_OP V...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
def get(d1, h1, d2, h2): d_d = d2 - d1 if abs(h2 - h1) > d_d: return None res = (d_d - abs(h2 - h1)) // 2 + max(h1, h2) return res n, m = tuple(map(int, input().split())) l = [(0, 0)] * (m + 1) for i in range(1, m + 1): l[i] = tuple(map(int, input().split())) maxi = 0 for i in range(1, m):...
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN NONE ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER FOR VA...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
import sys f = sys.stdin n, m = map(int, f.readline().strip().split()) res = True for i in range(m): d, h = map(int, f.readline().strip().split()) if i == 0: maxH = h + (d - 1) hpr = h dpr = d elif abs(h - hpr) > d - dpr: res = False else: dt = d - dpr - (max(hpr...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR BIN_...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
N, M = list(map(int, input().split())) H = [] for i in range(M): d, h = list(map(int, input().split())) H.append((d, h)) best = H[0][0] - 1 + H[0][1] for i in range(M - 1): diffd = H[i + 1][0] - H[i][0] diffh = abs(H[i + 1][1] - H[i][1]) if diffd >= diffh: best = max(best, max(H[i + 1][1], H...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER A...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = list(map(int, input().split())) max_height = 0 prev_d, prev_h = [0, 0] for i in range(m): d, h = list(map(int, input().split())) if i == 0: max_height = d - 1 + h prev_d = d prev_h = h if i == m - 1: max_height = max(max_height, n - d + h) continue ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VA...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
import sys def main(): import sys tokens = [int(i) for i in sys.stdin.read().split()] tokens.reverse() result = 0 n, m = tokens.pop(), tokens.pop() pd, ph = 0, 0 for i in range(m): d, h = tokens.pop(), tokens.pop() if i == 0: result = h + (d - 1) else: ...
IMPORT FUNC_DEF IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN V...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
R = lambda: map(int, input().split()) n, m = R() ls = [tuple(R()) for _ in range(m)] res = max(ls[0][1] + ls[0][0] - 1, ls[-1][-1] + n - ls[-1][0]) for i in range(1, m): d, h = ls[i][0] - ls[i - 1][0], abs(ls[i][1] - ls[i - 1][1]) if d < h: print("IMPOSSIBLE") exit() else: res = max(...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN V...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split()) notes = [list(map(int, input().split())) for _ in range(m)] if m == 1: d, h = notes[0] print(max(h + (d - 1), h + (n - d))) exit(0) d0, h0 = notes[0] ans = h0 + (d0 - 1) for i in range(m - 1): d1, h1 = notes[i] d2, h2 = notes[i + 1] if d2 - d1 < abs(h1 - h2): ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR N...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = [int(x) for x in input().split()] l = [] h = [] for i in range(m): d, hi = [int(x) for x in input().split()] l.append([d, hi]) h.append(hi) jud = 0 for i in range(1, m): if abs(l[i][1] - l[i - 1][1]) > l[i][0] - l[i - 1][0]: jud = 1 break else: d1 = l[i - 1][0] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR NU...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split(" ")) diary = list() for i in range(m): diary.append(list(map(int, input().split(" ")))) actual_distance = [abs(diary[i + 1][1] - diary[i][1]) for i in range(len(diary) - 1)] max_distance = [(diary[i + 1][0] - diary[i][0]) for i in range(len(diary) - 1)] difference = [(i[1] - i[0]) for...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMB...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split()) ls = [] for i in range(m): d, h = map(int, input().split()) ls.append([d, h]) ls.sort() max_h = 0 flag = True max_h = max(max_h, ls[0][0] - 1 + ls[0][1]) max_h = max(max_h, n - ls[m - 1][0] + ls[m - 1][1]) for i in range(m - 1): max_h = max(max_h, ls[i][1]) if ( ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBE...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
import sys input = sys.stdin.readline def judge(d, hs, he, x): return 2 * x - hs - he <= d def binary_search(d, hs, he): l, r = max(hs, he), 10**10 while l <= r: mid = (l + r) // 2 if judge(d, hs, he, mid): l = mid + 1 else: r = mid - 1 return r n, ...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR ...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
import sys 3 n, m = list(map(int, input().split())) firstData = None maxHeight = -1 for i in range(m): d, h = list(map(int, input().split())) if firstData is None: firstData = d, h else: if d - prevD < abs(h - prevH): print("IMPOSSIBLE") return maxH = max(h, ...
IMPORT EXPR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NONE ASSIGN VAR VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ST...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split()) possible = True day_prev, h_prev = map(int, input().split()) h_max = h_prev + (day_prev - 1) for i in range(m - 1): day, h = map(int, input().split()) if abs(h - h_prev) > day - day_prev: possible = False break h_new = max(h, h_prev) + (day - day_prev - abs(h...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSI...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = [int(x) for x in input().split()] a = [] ans = 0 while m > 0: p = [int(x) for x in input().split()] a.append(p) ans = max(ans, p[1]) m -= 1 flag = 1 for i in range(len(a) - 1): x, y = a[i], a[i + 1] t = y[0] - x[0] - 1 if abs(y[1] - x[1]) > y[0] - x[0]: flag = 0 break ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIG...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
def possible(d1, h1, d2, h2): if d2 - d1 < abs(h2 - h1): return -1 elif h1 == h2: return (d2 - d1) // 2 + h1 elif h1 > h2: diff = h1 - h2 newd2 = d2 - diff if newd2 < d1: return -1 else: return (newd2 - d1) // 2 + h1 else: d...
FUNC_DEF IF BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN NUMBER IF VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VA...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split()) possible = True s, a = map(int, input().split()) highest = a + s - 1 for i in range(1, m): t, b = map(int, input().split()) slack = t - s - abs(a - b) if slack < 0: possible = False else: highest = max(highest, max(a, b) + slack // 2) s, a = t, b high...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR ...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split()) h = [None] * m def calc(h, num): r = -1 for i in range(len(h) - 1): n = h[i + 1][0] - h[i][0] hd = h[i + 1][1] - h[i][1] s = (n + hd) % 2 if n + hd < s or n - hd < s: return "IMPOSSIBLE" u = (hd + n - s) // 2 r = max(...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP V...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = list(map(int, input().rstrip().split())) d = [] h = [] flag = 1 for i in range(m): a, b = list(map(int, input().rstrip().split())) d += [a] h += [b] if i > 0 and abs(d[i] - d[i - 1]) < abs(h[i] - h[i - 1]): flag = 0 if flag == 0: print("IMPOSSIBLE") else: maxm = 0 for i in ran...
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR LIST VAR VAR LIST VAR IF VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VA...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
n, m = map(int, input().split()) ans = 0 h1 = 0 h2 = 0 d1 = 0 d2 = 0 for i in range(m): x, y = map(int, input().split()) if i == 0: ans = y + x - 1 h1 = y d1 = x else: h2 = y d2 = x if h1 > h2: h1, h2 = h2, h1 t1 = h2 + (d2 - d1 - (h2 - h1)...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
[n, k] = [int(x) for x in input().split()] Data = type("Data", (object,), {"index": 0, "value": 0}) data = [Data() for _ in range(k)] for i in range(k): [data[i].index, data[i].value] = [int(x) for x in input().split()] data.sort(key=lambda x: x.index) ans = max(data[0].value + data[0].index - 1, data[k - 1].value ...
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR DICT STRING STRING NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
def main(): n, m = map(int, input().split()) d0, h0 = map(int, input().split()) res = [h0 + d0 - 1] for i in range(m - 1): d1, h1 = map(int, input().split()) dd = d1 - d0 if h1 > h0: base = h1 dh = h1 - h0 else: base = h0 dh...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASS...
A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer h_{i}. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i....
x = input() n, m = x.strip().split(" ") n, m = int(n), int(m) x = input() d, h = x.strip().split(" ") d, h = int(d), int(h) max_height = h + d - 1 last_day = d last_height = h posible = True for k in range(m - 1): x = input() d, h = x.strip().split() d, h = int(d), int(h) if d - last_day >= abs(last_hei...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN...