description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ...
n, I = list(map(int, input().split())) l = list(map(int, input().split())) k = 2 ** (I * 8 // n) dd = {} for x in l: if x in dd: dd[x] += 1 else: dd[x] = 1 l = [dd[x] for x in sorted(dd)] n = len(l) if k >= n: print(0) else: ss = sum(l[:k]) mxm = ss for i in range(1, n - k + 1): ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR ...
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ...
vec_a = [] freq = [] cum_freq = [] n, available_bytes = map(int, input().split()) vec_a = list(map(int, input().split())) vec_a.sort() a = vec_a[0] freq.append(1) for i in range(1, n): if vec_a[i] == a: freq[-1] += 1 else: a = vec_a[i] freq.append(1) tot_distinct_num = len(freq) total = ...
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR ...
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ...
R = lambda: map(int, input().split()) n, I = R() a = [-1] + sorted(R()) b = [i for i in range(n) if a[i] < a[i + 1]] print(n - max(y - x for x, y in zip(b, b[1 << 8 * I // n :] + [n])))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER BIN...
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ...
n, l = [int(x) for x in input().split()] a = sorted([int(x) for x in input().split()]) num = len(set(a)) arr = 2 ** (8 * l // n) a.append(10**100) b = [] counter = 1 for i in range(1, n + 1): if a[i] == a[i - 1]: counter += 1 else: b.append(counter) counter = 1 pref = [0] for item in b: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL...
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ...
n, I = (*map(int, input().split()),) a = [int(x) for x in input().split()] a.sort() tgtbpn = I * 8 // n mxvals = 1 << tgtbpn c = [] i = 0 while i < len(a): j = i cnt = 0 while j < len(a) and a[j] == a[i]: cnt += 1 j += 1 c.append(cnt) i = j sm = 0 mn = n for i in range(len(c)): s...
ASSIGN VAR VAR FUNC_CALL 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 BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR...
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ...
n, I = map(int, input().split()) k = int(8 * I / n) K = 2**k a = sorted(map(int, input().split())) nums = [1] for c in range(1, n): if a[c] == a[c - 1]: nums[-1] += 1 else: nums.append(1) curr = sum(nums[:K]) m = curr for i in range(0, len(nums) - K): curr = curr - nums[i] + nums[i + K] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR F...
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ...
n, I = map(int, input().split()) all_a = list(map(int, input().split())) amounts_a = {} for a in all_a: if a in amounts_a.keys(): amounts_a[a] += 1 else: amounts_a[a] = 1 nums = list(amounts_a.keys()) nums.sort() K = 2 ** min(20, 8 * I // n) if len(nums) <= K: damaged = 0 else: good = 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 DICT FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER BIN_OP...
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ...
import sys in_file = sys.stdin n, I = map(int, in_file.readline().strip().split()) A = list(map(int, in_file.readline().strip().split())) max_k = I * 8 // n m = 2**max_k A.sort() t = A[0] B = [0] for a in A: if a == t: B[-1] += 1 else: t = a B.append(1) res = sum(B[:m]) t = res for i in...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR VA...
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ...
n, i = map(int, input().split()) aa = list(map(int, input().split())) bitsPerSample = i * 8 // n r = 2**bitsPerSample aa.sort() prev = -1 bb = [] for i, a in enumerate(aa): if a != prev: bb.append(i) prev = a if len(bb) <= r: maxOk = n else: maxOk = max([(bb[i + r] - bb[i]) for i in range(le...
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 BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR...
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ...
n, I = map(int, input().split()) I *= 8 I //= n arr = list(map(int, input().split())) arr.sort() smen = [0] typs = 1 for i in range(1, n): if arr[i] != arr[i - 1]: typs += 1 smen.append(i) smen.append(n) deg = 1 lg = 0 while deg < typs: lg += 1 deg *= 2 if lg == 0 or I >= lg: print(0) el...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VA...
In number world, two different numbers are friends if they have a lot in common, but also each one has unique perks. More precisely, two different numbers a and b are friends if gcd(a,b), (a)/(gcd(a,b)), (b)/(gcd(a,b)) can form sides of a triangle. Three numbers a, b and c can form sides of a triangle if a + b > c, b...
import sys input = sys.stdin.buffer.readline n = int(input()) a = list(map(int, input().split())) n = max(a) + 1 spf = [i for i in range(n)] for i in range(4, n, 2): spf[i] = 2 for i in range(3, int(n**0.5) + 1, 2): if spf[i] != i: continue for j in range(i * i, n, i): if spf[j] == j: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR ...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
n, m = list(map(int, input().split())) a = [0] + list(map(int, input().split())) b = [0] + list(map(int, input().split())) A = [0] * (n + 1) B = [0] * (m + 1) x = int(input()) for i in range(1, n + 1): a[i] = a[i - 1] + a[i] A[i] = a[i] for j in range(1, i): A[i - j] = min(A[i - j], a[i] - a[j]) for...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) e = int(input()) c = [0] * (n + 1) x = [0] x1 = 0 for i in range(n): x1 += a[i] x.append(x1) y = [0] y1 = 0 for i in range(m): y1 += b[i] y.append(y1) for i in range(1, n + 1): d = x[i] ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER ASSIG...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
from sys import stdin, stdout n, m = stdin.readline().strip().split(" ") n, m = int(n), int(m) row = list(map(int, stdin.readline().strip().split(" "))) col = list(map(int, stdin.readline().strip().split(" "))) x = int(stdin.readline().strip()) lowest_row_array = [0] for i in range(1, n + 1): s = sum(row[:i]) ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN 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 FUNC_CALL VAR FUNC_CALL FUNC_CALL ...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
from itertools import accumulate from sys import stdout R = lambda: map(int, input().split()) n, m = R() a, b = list(accumulate(R())), list(R()) x = int(input()) res = 0 for al in range(1, n + 1): sa = min(ar - al for ar, al in zip(a[al - 1 :], [0] + a[:])) l, s = -1, 0 for r in range(m): s += b[r]...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR F...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
n, m = map(int, input().split()) a = [0] * (n + 1) j = 1 b = [0] for i in input().split(): a[j] += int(i) + a[j - 1] j += 1 b.extend(list(map(int, input().split()))) b.append(0) x = int(input()) ans = 0 for i in range(1, n + 1): k1 = 10**9 for j in range(0, n - i + 1): k1 = min(k1, a[j + i] - a[...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR E...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
m, n = list(map(int, input().split())) M = list(map(int, input().split())) N = list(map(int, input().split())) bound = int(input()) res = 0 if m > n: m, n = n, m M, N = N, M multis = [] for L in range(1, m + 1): cur = sum(M[i] for i in range(L)) mini = cur for i in range(L, m): cur += M[i] -...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR A...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
n, m = [int(i) for i in input().split(" ")] a = [int(x) for x in input().split(" ")] b = [int(x) for x in input().split(" ")] x = int(input()) max_a = {} for i in range(n): cur_sum = 0 for j in range(i, n): cur_sum += a[j] if j - i + 1 not in max_a or cur_sum < max_a[j - i + 1]: max_...
ASSIGN VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
[n, m] = list(map(int, input().split())) a = [0] + list(map(int, input().split())) b = [0] + list(map(int, input().split())) x = int(input()) for i in range(1, n + 1): a[i] += a[i - 1] for i in range(1, m + 1): b[i] += b[i - 1] INF = 4 * 10**9 + 1 A = [INF] * (n + 1) B = [INF] * (m + 1) for i in range(1, n + 1)...
ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) x = int(input()) def calc(arr): k = len(arr) ret = [(10**10) for i in range(k + 1)] for l in range(0, k): cur = 0 for r in range(l, k): cur += arr[r] ret[r - l +...
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR BI...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] x = int(input()) csa = [0] * (n + 1) csb = [0] * (m + 1) ans = 0 for i in range(1, n + 1): csa[i] = csa[i - 1] + a[i - 1] for i in range(1, m + 1): csb[i] = csb[i - 1] + b[i - 1] misubsa = [99999...
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) x = int(input()) b_acc = [0] for bi in b: b_acc.append(b_acc[-1] + bi) max_length = [0] * (4 * 10**6 + 100) for i in range(m): for j in range(i, m): B = b_acc[j + 1] - b_acc[i] max_length[B] ...
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) x = int(input()) mina = [] base = 0 prev = 0 for i in range(1, n + 1): base = a[i - 1] + prev min1 = base prev = base for j in range(i, n): base -= a[j - i] base += a[j] min1 ...
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VA...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
n, m = map(int, input().split()) l = list(map(int, input().split())) l1 = list(map(int, input().split())) x = int(input()) l = [0] + l l1 = [0] + l1 for i in range(1, n + 1): l[i] += l[i - 1] for j in range(1, m + 1): l1[j] += l1[j - 1] maxsum = [999999999999999999] * n for i in range(1, n + 1): for j in ra...
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR ...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) x = int(input()) ASUM = [0] BSUM = [0] for i in range(n): ASUM.append(A[i] + ASUM[-1]) for i in range(m): BSUM.append(B[i] + BSUM[-1]) ALIST = dict() BLIST = dict...
IMPORT ASSIGN 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR ...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) x = int(input()) gooda = [10000000] * n goodb = [10000000] * m for i in range(n): tots = 0 lent = 0 for j in range(i, n): tots += a[j] lent += 1 gooda[lent - 1] = min(gooda[lent -...
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR ...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
def get_input_list(): return list(map(int, input().split())) n, m = get_input_list() a = get_input_list() b = get_input_list() x = int(input()) sa = [0] for i in range(1, n + 1): s = sum(a[:i]) mi = s j = i while j < n: s = s - a[j - i] + a[j] if mi > s: mi = s ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR V...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
from sys import stdin, stdout N, M = [int(x) for x in stdin.readline().split()] arrA = [int(x) for x in stdin.readline().split()] arrB = [int(x) for x in stdin.readline().split()] K = int(input()) A = [0] * N B = [0] * M prefix_A = [0] * N s = 0 for i in range(N): s += arrA[i] prefix_A[i] = s prefix_B = [0] * ...
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSI...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
n, m = map(int, input().split(" ")) a = list(map(int, input().split(" "))) b = list(map(int, input().split(" "))) suma = list() suma.append(0) for i in range(len(a)): suma.append(a[i] + suma[i]) sumb = list() sumb.append(0) for i in range(len(b)): sumb.append(b[i] + sumb[i]) mina = list() mina.append(0) minb = ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VA...
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$. You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the ...
n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) x = int(input()) rows = [float("inf")] * (n + 1) cols = [float("inf")] * (m + 1) for i in range(n): summ = 0 for j in range(i, n): summ += a[j] l = j - i + 1 rows[l] = min(rows[...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR BIN...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = map(int, input().split()) p = list(map(int, input().split())) p.sort() i, d, s = 0, 0, 1 x, y = 1, p[0] for j in range(1, n): d += (p[j] - p[j - 1]) * s s += 1 while d > k: d -= p[j] - p[i] i += 1 s -= 1 if s > x: x, y = s, p[j] print(x, y)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER WHILE VA...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() l, r = 0, 1 x = 0 cnt = 1 idx = 0 while l < n and r <= n: if r - l == 1 and r < n: r += 1 x = a[r - 1] - a[r - 2] continue if x <= k: if cnt < r - l: cnt = r - l idx = r - 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 EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() s = 0 m = 1 ans = a[0] start = 0 for end in range(1, n): s += (end - start) * (a[end] - a[end - 1]) while s > k: s -= a[end] - a[start] start += 1 if m < end - start + 1: m = end - start + 1 ans = 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER WHILE...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
import sys input = sys.stdin.buffer.readline n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a.sort() dp = list(a) for i in range(1, len(dp)): dp[i] += dp[i - 1] l_ans = 0 r_ans = 0 lx = 0 s = 0 for i in range(len(a)): si = (i + 1) * a[i] - dp[i] slx = si - a[i] * lx slx ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER A...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
def binarySearch(alist, item, k, slist, lis): first = 0 last = len(alist) - 1 opt = 0 while first <= last: midpoint = (first + last) // 2 if ( lis[item] * alist[midpoint] - (slist[item + 1] - slist[item + 1 - alist[midpoint]]) > k ): ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RE...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = map(int, input().split()) arr = list(map(int, input().split())) arr.sort() prArr = [0] m = 1 ind = arr[0] for t in range(0, n): prArr += [arr[t] + prArr[t]] for itr in range(n, -1, -1): l = 1 r = itr - 1 while l <= r: mid = (l + r) // 2 s = prArr[itr] - prArr[mid - 1] coun...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR LIST BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VA...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, m = map(int, input().split()) ar = list(map(int, input().split())) ar.sort() temp = ar[0] for i in range(n): ar[i] = ar[i] + (abs(temp) + 1) s = [0] for i in range(n): s.append(s[-1] + ar[i]) ans = 1 def f(pos2): l = 0 r = pos2 mid = 0 while l <= r: mid = (l + r) // 2 aa = 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 EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
a = [0] * (10**6 + 9) ac = [0] * (10**6 + 9) n, k = map(int, input().strip().split()) tem = list(map(int, input().strip().split())) a[1 : n + 1] = sorted(tem) for i in range(1, n + 1): ac[i] = a[i] + ac[i - 1] res, mx = 0, 0 for i in range(1, n + 1): low, high, mid, freq = 0, i, 0, 0 while low <= high: ...
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 ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL ...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) b = [0] c = 0 d = e = -1 for i in range(n): c += a[i] b.append(c) l, r = -1, i + 1 while r - l > 1: m = (l + r) // 2 if a[i] * (i + 1 - m) - c + b[m] > k: l = m else: r = m ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHIL...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
from sys import stdin def solve(tc): n, k = map(int, stdin.readline().split()) seq = list(map(int, stdin.readline().split())) seq = sorted(seq) maxlen = 1 maxv = seq[0] diffsum = 0 p = 0 for i in range(1, n): offset = seq[i] - seq[i - 1] diffsum += offset * (i - p) ...
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 VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER V...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() s = [0, *a] for i in range(1, n): s[i] = s[i] + s[i - 1] p = 0 i = 0 mm = 0 mmi = 0 while i < n: aa = 1 while p < i and (i - p) * a[i] - (s[i] - s[p]) > k: p += 1 aa += i - p while i < n - 1 and a[i] == a[i + 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR ...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) a = [0] + a b = a[:] for i in range(1, n + 1): a[i] += a[i - 1] p1 = 1 p2 = 1 l = 1 an = a[1] while p2 < n + 1: if b[p2] * (p2 - p1 + 1) <= a[p2] + k - a[p1 - 1] and l <= p2 - p1 + 1: an = b[p2] l = p2 - p1 + 1 else...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER AS...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
def toadd(arr, k): if len(arr) == 1: print(1, arr[0]) return "" arr = sorted(arr) co = 1 j = 0 ans = [0, 0] for i in range(1, len(arr)): k -= (arr[i] - arr[i - 1]) * co co += 1 while k < 0: k += arr[i] - arr[j] co -= 1 j...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER WHILE VAR NUMBER VAR BIN_OP...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = list(map(int, input().split())) arr = sorted(list(map(int, input().split()))) sums = [0] sum = 0 for x in arr: sum += x sums.append(sum) best_count, best_value = 1, arr[0] pos = 0 for i in range(1, n): while True: count = i - pos + 1 need = count * arr[i] - sums[i + 1] + sums[pos] ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) b = [a[0]] for i in range(1, n): b.append(b[-1] + a[i]) ans = -1 s = 0 j = -1 for i in range(n): s += a[i] l = i r = n while r > l + 1: m = (l + r) // 2 if a[i] * (m - i) - (b[m] - s) <= k: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUN...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = map(int, input().split()) lis = [0] + sorted(map(int, input().split())) s = [0] * (n + 1) ans = fin = 0 for i in range(1, n + 1): s[i] = lis[i] + s[i - 1] for i in range(1, n + 1): l = 1 r = i freq = -1 while l <= r: mid = l + (r - l) // 2 req = (i - mid + 1) * lis[i] - (s[i] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR ...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = map(int, input().split()) arr = sorted(list(map(int, input().split()))) s = [0] * (n + 1) res1, res2 = 0, 0 for i in range(1, n + 1): s[i] = arr[i - 1] + s[i - 1] i, j = 0, 0 while i < n: d1 = i - j + 1 d2 = s[i + 1] - s[j] if j <= i and d1 * arr[i] - d2 <= k: if i - j + 1 > res1: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
import sys input = sys.stdin.readline for _ in range(1): n, k = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] curr = 0 temp = [] arr.sort() ans = -1 for i in range(n): curr += arr[i] temp.append(curr) for i in range(n): l, r = 0, i ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL V...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = map(int, input().split()) a = list(map(int, input().split())) a = sorted(a) pre = [0] * n pre[0] = a[0] for i in range(1, n): pre[i] = a[i] pre[i] += pre[i - 1] occ = 1 elem = a[0] for i in range(n): now = a[i] low = 0 high = i - 1 ans = -1 while low <= high: mid = (low + high...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
from sys import setrecursionlimit, stdin setrecursionlimit(15000) def preprocessing(arr, aux): for i in range(1, len(arr)): aux[i] = aux[i - 1] + (arr[i] - arr[i - 1]) * i def binary_search(arr, aux, k, start, end, index, element, count): if start > end: return mid = (start + end) // 2 ...
EXPR FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR VAR RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF V...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
import sys def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() n, k = get_ints() Arr = get_array() Arr.sort() store = 0 left = 0 ans = Arr[0] freq = 1 for i...
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 ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
def check(freq): ps = [] s = 0 for i in l: s += i ps.append(s) i = freq - 1 while i < n: cur = l[i] while i < n and l[i] == cur: i += 1 i -= 1 presum = ps[i] front = i - freq if front >= 0: presum -= ps[front] ...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR RETUR...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
from itertools import accumulate n, k = map(int, input().split()) nums = [int(x) for x in input().split()] nums.sort(reverse=True) falta = [(nums[0] - i) for i in nums] acc = list(accumulate(falta)) rx, ry = 0, 0 for i, nu in enumerate(nums): lo, hi = i, n - 1 while hi > lo: mid = (hi + lo + 1) // 2 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
n, k = map(int, input().split()) l = list(map(int, input().split())) l.sort() presum = [0] * (n + 1) for i in range(n): presum[i + 1] = presum[i] + l[i] i, j = 0, 0 ans1, ans2, curr = 1, l[0], 0 while j < n: if (j - i + 1) * l[j] - (presum[j + 1] - presum[i]) <= k: if j - i + 1 > ans1: ans1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUM...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
import sys input = sys.stdin.readline def inp(): return int(input()) def inara(): return list(map(int, input().split())) def insr(): s = input() return list(s[: len(s) - 1]) def invr(): return map(int, input().split()) n, k = invr() a = inara() a.sort() dp = [0] * n dp[0] = a[0] for i in ...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSI...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
from itertools import accumulate from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, input().split())) def fn(ln): for i in range(ln - 1, n): if a[i] * (ln - 1) - (ps[i - 1] - (ps[i - ln] if i >= ln else 0)) <= c: return True return False for i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR N...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
from itertools import accumulate store = 0 def check(pref, mid): global store for i in range(mid, n + 1): r = arr[i] * mid - (pref[i] - pref[i - mid]) if r <= k: store = arr[i] return True return False n, k = map(int, input().split()) arr = list(map(int, input()....
ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN NUMBER RETURN 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 ...
A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operations β€” choose an arbitrary element from the array and add 1 to it. I...
N, K = map(int, input().split()) arr = list(map(int, input().split())) arr.sort() tail = 0 maxocc = 1 curocc = 1 usedup = 0 element = arr[0] for head in range(1, len(arr)): usedup += (arr[head] - arr[head - 1]) * (head - tail) while usedup > K and tail < head: usedup -= arr[head] - arr[tail] tai...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
def check(x): num = {} d = {} for i in st: num[i] = 0 d[i] = 1 m = len(num.values()) for j in range(x): num[st[j]] += 1 d[st[j]] = 0 i = x j = 0 if sum(d.values()) == 0: return True while i < n: num[st[j]] -= 1 if num[st[j]] <= ...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR NUMBER RETURN NUMBER WHILE VAR VAR VAR VAR VAR NU...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) array = input() spisok = dict() maxim = len(set(array)) ans = 100002 kol = 0 ukaz1 = 0 ukaz2 = 0 for ukaz1 in range(n): if array[ukaz1] not in spisok: kol += 1 spisok[array[ukaz1]] = 0 spisok[array[ukaz1]] += 1 if kol == maxim: while spisok[array[ukaz2]] > 1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR WHILE VA...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
def bs(l, h): while l < h: m = (l + h) // 2 if gf(m): h = m else: l = m + 1 return l def gf(x): d = {} for i in range(x): if s[i] in d: d[s[i]] += 1 else: d[s[i]] = 1 if len(d) == len(u): return 1 f...
FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
import sys def findIndex(element, list_element): try: index_element = list_element.index(element) return index_element except ValueError: return None def customPrint(string): return def sliceNose(string, tokens): while len(currentList) > 1 and currentList[0] == currentList[...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR VAR RETURN NONE FUNC_DEF RETURN FUNC_DEF WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL ...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
import sys n = int(sys.stdin.readline()) line = sys.stdin.readline() st = set() dt = dict() for x in line: st.add(x) st.remove("\n") ans = n head = 0 for i in range(n): x = line[i] if x not in dt: dt[x] = 1 else: dt[x] += 1 while head <= i: x = line[head] if x in dt ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER WHILE VAR VA...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() t = set(s) tt = len(t) vis = dict() for a in t: vis[a] = 0 l, r = 0, -1 now = 0 ans = n + 100 while l != n: while r + 1 != n and now != tt: r += 1 if vis[s[r]] == 0: now += 1 vis[s[r]] += 1 if now == tt: ans = min(ans, r - l + 1) v...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR WHILE BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
def solve(s, k): d = {} for i in s: d[i] = 1 c = len(d) d = {} for i in range(k): if s[i] in d: d[s[i]] += 1 else: d[s[i]] = 1 if len(d) == c: return True dif = 0 for i in range(k, n): if s[i] in d: if d[s[i]] ==...
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR IF VAR VAR VAR NUMBER VAR NU...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() D = dict() A = set() for i in range(n): if s[i] not in A: A.add(s[i]) l = 100001 for i in A: D[i] = 0 g = 0 c = "0" for i in range(n): D[s[i]] += 1 q = 0 if c == "0": for k in A: if D[k] == 0: break else: q ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIG...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() l = len(set(s)) dic = {} left, right = 0, 0 mini = 10**9 size = 0 for left in range(n): while right < n and size < l: if s[right] not in dic: dic[s[right]] = 1 else: dic[s[right]] += 1 if dic[s[right]] == 1: size += 1 r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
import sys LI = lambda: list(map(int, sys.stdin.readline().split())) MI = lambda: map(int, sys.stdin.readline().split()) SI = lambda: sys.stdin.readline().strip("\n") II = lambda: int(sys.stdin.readline()) n = II() s = SI() c = set(s) ln = [0] * n for d in c: last = -1 for i, v in enumerate(s): if v ==...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) st = input() i2 = 0 uniques = 0 has = dict() mi = 1000000 for ch in st: if ch not in has: has[ch] = 0 for i in range(n): while uniques < len(has) and i2 < n: has[st[i2]] += 1 if has[st[i2]] == 1: uniques += 1 i2 += 1 if uniques < len(has): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR ...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
def main(): input() s = input() d = dict.fromkeys(s, 0) le, res = len(d), [] iti, itj = (iter(enumerate(s)) for _ in "12") try: while True: while le: i, c = next(iti) if d[c]: d[c] += 1 else: ...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR LIST ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING WHILE NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER WHILE NUMBER ASSIGN ...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
N = int(input()) flats = input() pokemons = {} for i in "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM": pokemons[i] = 0 for i in flats: pokemons[i] += 1 idx = N - 1 while idx >= 0: if pokemons[flats[idx]] == 1: break pokemons[flats[idx]] -= 1 idx -= 1 right = idx left = 0 ans = right...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR STRING ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() types = len(set(list(s))) gotTypes = 0 got = {} l, r, ans = 0, 0, n for l in range(n): while r < n and gotTypes != types: char = s[r] if char in got and got[char] != 0: got[char] += 1 else: got[char] = 1 gotTypes += 1 r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBE...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() u = set(s) dp = [0] * n for i in u: lastI = -1 for j in range(n): if s[j] == i: lastI = j if lastI == -1: dp[j] = n else: dp[j] = max(dp[j], j - lastI + 1) print(min(dp))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUN...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() k = len(set(s)) c = 0 i = 0 cnt = {} for i in s: cnt[i] = 0 j = 0 i = 0 mini = n while j < n: cnt[s[j]] += 1 if cnt[s[j]] == 1: c += 1 if c == k: while i < j and cnt[s[i]] > 1: cnt[s[i]] -= 1 i += 1 mini = min(mini, j - i + 1) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() basic_set = set(s) d = dict() for item in basic_set: d[item] = 0 left = 0 right = 0 l = 0 min_l = 100001 i = 0 while left < n: while 0 in d.values() and right < n: d[s[right]] += 1 right += 1 if 0 not in d.values(): l = right - left if l < min_l: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() k = len(set(s)) d = {} for i in set(s): d[i] = 0 d[s[0]] = 1 ans = 10**5 x = 0 y = 1 b = True m = set() m.add(s[0]) while b: if d[s[x]] > 1: d[s[x]] -= 1 x += 1 elif y == n: b = False else: d[s[y]] += 1 m.add(s[y]) y += 1 i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input("")) row = str(input("")) unique_letters = set(row) frec_dict = dict() i = 0 start_j = 0 done_j = False done_i = False for letter in unique_letters: frec_dict[letter] = 0 while 0 in [v for v in frec_dict.values()]: frec_dict[row[start_j]] += 1 start_j += 1 j = start_j result = start_j if j == ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER WHILE NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASS...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() tCap = [] shortest = n l = 0 for r in range(n): if s[r] not in tCap: tCap += s[r] shortest = r - l + 1 else: while s[l] in s[l + 1 : r + 1]: l += 1 if r - l + 1 < shortest: shortest = r - l + 1 print(shortest)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BI...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) flats = input() types = set(flats) counter = {} menor = n j = 0 for i in range(n): if counter.get(flats[i], 0) == 0: counter[flats[i]] = 1 else: counter[flats[i]] += 1 if len(counter) < len(types): continue while counter[flats[j]] > 1: counter[flats[j]] -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR ...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) pokemons = input() last = {} start_of_all = 0 for i in range(n): ty = pokemons[i] if ty not in last: start_of_all = i last[ty] = 0 minlen = 100001 for i in range(n): ty = pokemons[i] last[ty] = i length = i + 1 - min(last.values()) if i >= start_of_all and length < m...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL V...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) pokemons = input().strip() types = set(pokemons) i = 0 j = 0 contained = {pokemons[j]: 1} def add_pokemon(): global j j += 1 p = pokemons[j] contained.setdefault(p, 0) contained[p] += 1 def remove_pokemon(): global i i += 1 p = pokemons[i - 1] contained[p] -= 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT VAR VAR NUMBER FUNC_DEF VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBE...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
import sys line = input() n = int(line) line2 = input() line2 = list(line2) letters = {} i = 0 while i < n: if line2[i] not in letters: letters[line2[i]] = 1 i = i + 1 noPoke = len(letters.keys()) for letter in letters: letters[letter] = 0 min = 0 i = 0 while min < noPoke and i < n: if line2[i]...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUM...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
strNum = int(input()) strToSearch = "" if strNum > 0: strToSearch = input() charSet = set(strToSearch) charTotalNum = len(charSet) charCount = 0 charDict = {} rightBoundary = 0 leftBoundary = 0 ret = strNum for rightIdx in range(strNum): if strToSearch[rightIdx] not in charDict: charCount += 1 c...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
def solve(): add = sum length = len order = sorted n = int(input()) arr = list(input()) unique = order(list(set(arr))) left_index = 0 right_index = len(unique) lowest = length(arr) queue = [x for x in arr[left_index:right_index]] letter_freq = {} for i in queue: i...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR ...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
def count_different_poks(seq, k): if len(seq) < k: return d = dict() max_caught = 0 for i in range(len(seq)): d.setdefault(seq[i], 0) d[seq[i]] += 1 if i >= k: d[seq[i - k]] -= 1 if d[seq[i - k]] == 0: del d[seq[i - k]] max_...
FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) a = input() b = dict() c = dict() for i in a: b[i] = b.get(i, 0) + 1 r = 0 ans = n for i in range(n): while len(c) < len(b) and r < n: c[a[r]] = c.get(a[r], 0) + 1 r += 1 if r == n and len(c) < len(b): break c[a[i]] = c.get(a[i], 0) - 1 ans = min(ans, r - i) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
def pokemon(): length = int(input()) seq = input() tmp = dict() if length == 0: return 0 for i in range(length): tmp[seq[i]] = None max_poks, min_flats = len(tmp), length d = dict() i, j = 0, -1 while j < length - 1: if len(d) < max_poks: j += 1 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NONE ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) temp = input() st = [c for c in temp] temp = set(st) nT = len(temp) s = {} for i in temp: s[i] = 0 currT = set() i = 0 j = 0 minL = 10**10 for i in range(len(st)): currT.add(st[i]) s[st[i]] += 1 while j < i and s[st[j]] > 1: s[st[j]] -= 1 j += 1 if len(currT) == nT: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL ...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
debug = lambda *args: None def can(s, size, n, u): d = {} i = 0 k = size for c in s: debug(c, k, d) if k > 0: k -= 1 d[c] = d.setdefault(c, 0) + 1 else: if s[i - size] in d: d[s[i - size]] -= 1 if d[s[i - size]...
ASSIGN VAR NONE FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR V...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
def idx(x): if x > "Z": return ord(x) - ord("a") + 26 else: return ord(x) - ord("A") def check(): tmp = 0 for i in range(52): if buf[i]: tmp |= 1 << i return tmp & syb == syb n = int(input()) s = input() syb = 0 c = [[] for i in range(n + 1)] for i in range(1,...
FUNC_DEF IF VAR STRING RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VA...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() letters = [0] * 123 dp = [0] * n for i in range(n): if letters[ord(s[i])] != 0: continue last = -1 for ind in range(n): if s[ind] == s[i]: last = ind dp[ind] = 100001 if last == -1 else max(dp[ind], ind - last + 1) letters[ord(s[i])] = 1 p...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VA...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
N = int(input()) A = list(map(ord, list(input()))) S = [0] * 150 for i in range(N): S[A[i]] += 1 Pokemon = len(S) - S.count(0) L = 0 R = N while R - L > 1: M = (R + L) // 2 l = 0 r = 0 S = [0] * 150 count = 0 is_ok = False while r < l + M: if S[A[r]] == 0: count += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) l = [0] * n v = [] p = input() for i in p: if i in v: continue v.append(i) for i in v: last = -1 for j in range(n): if p[j] == i: last = j if last != -1: l[j] = max(l[j], j - last + 1) else: l[j] = 10**9 print(min(l))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR N...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) st = input() l = len(st) u = list(set(st)) INT_MAX = 1000000000 e = [(0) for _ in range(l)] last = -1 for c in u: last = -1 for i, s in enumerate(st): if s != c: e[i] = INT_MAX else: last = i break count = last while count < l: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASS...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() alles = {} l, r, c, ans, le = 0, 0, 0, float("+inf"), len(set(s)) for i in s: if i not in alles: alles[i] = 0 c += 1 alles[i] += 1 if c == le: while alles[s[l]] > 1: alles[s[l]] -= 1 l += 1 ans = min(ans, r - l + 1) r +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER AS...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() if n == 1 or len(set(s)) == 1: print(1) else: left = 0 right = 1 check = set(s) temp = set([s[0], s[1]]) m = 10**10 d = {} d[s[0]] = 1 if s[1] in d: d[s[1]] += 1 else: d[s[1]] = 1 while right > left: if temp == check: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR V...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
def indice(char): n = ord(char) if n < 91: return n - 65 return n - 71 n, s = int(input()), input() k = len(set(s)) i, j = 0, 0 actual = 0 minimo = n lista = [0] * 52 while True: if actual == k: if j - i < minimo: minimo = j - i m = indice(s[i]) if lista[m] ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER WHILE NUMBER IF VAR...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) l = list(input()) k = len(set(l)) count = {} a = n i = j = 0 while j < n: while len(count) < k and j < n: lj = l[j] if lj not in count: count[lj] = 0 count[lj] += 1 j += 1 while len(count) == k: if a > j - i: a = j - i li =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER WHILE FUNC_CALL VA...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
def main(): n = int(input()) s = input() u_set = set() for i in s: u_set.add(i) u_cnt = len(u_set) d = {} j = 0 ans = 10**9 for i in range(n): while len(d.keys()) < u_cnt and j < n: d[s[j]] = d.get(s[j], 0) + 1 j += 1 if len(d.keys()) =...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR B...
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on...
n = int(input()) s = input() k = k1 = n q = set() c = 0 w = 0 t = False for i in range(n): if s[i] not in q: q.add(s[i]) w = i k1 = k = w - c + 1 while True: if s[c] in s[c + 1 : w + 1]: if w - c < k1: k1 = w - c if k1 < k: k = k1 c...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE NUMBER IF VAR VAR VAR BIN...