description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother. As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b. Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times. You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting. -----Input----- The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9). -----Output----- You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition. -----Examples----- Input 2 2 2 3 3 5 Output 3 Input 3 2 1 2 3 3 4 Output 4 Input 3 2 4 5 6 1 2 Output 0 -----Note----- In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3. In example 3, you don't need to do any operation, Devu's condition is already satisfied.
def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while left <= right: mid = int((right + left) / 2) if arr[mid] < key: count = mid + 1 left = mid + 1 else: right = mid - 1 return count def countGreater(arr, n, k): l = 0 r = n - 1 leftGreater = n while l <= r: m = int(l + (r - l) / 2) if arr[m] > k: leftGreater = m r = m - 1 else: l = m + 1 return n - leftGreater class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a + b): self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size : _size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) m, n = map(int, input().split()) b = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() b.sort() tot = 9999999999999999999999999999999 s = SegmentTree(a) s1 = SegmentTree(b) for i in range(n): c = binarySearchCount(b, m, a[i]) ans = c * a[i] - s1.query(0, c - 1) - (n - 1 - i) * a[i] + s.query(i + 1, n - 1) tot = min(ans, tot) for i in range(m): c = countGreater(a, n, b[i]) ans = -c * b[i] + s.query(n - c, n - 1) - s1.query(0, i - 1) + i * b[i] tot = min(ans, tot) print(tot)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR CLASS_DEF FUNC_DEF NUMBER BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_DEF RETURN VAR BIN_OP VAR VAR FUNC_DEF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER FUNC_DEF RETURN VAR FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL STRING VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother. As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b. Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times. You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting. -----Input----- The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 10^5). The second line will contain n space-separated integers representing content of the array a (1 ≤ a_{i} ≤ 10^9). The third line will contain m space-separated integers representing content of the array b (1 ≤ b_{i} ≤ 10^9). -----Output----- You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition. -----Examples----- Input 2 2 2 3 3 5 Output 3 Input 3 2 1 2 3 3 4 Output 4 Input 3 2 4 5 6 1 2 Output 0 -----Note----- In example 1, you can increase a_1 by 1 and decrease b_2 by 1 and then again decrease b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3. In example 3, you don't need to do any operation, Devu's condition is already satisfied.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a_min = min(a) b_max = max(b) if a_min >= b_max: print(0) else: a = sorted([i for i in a if i < b_max]) n = len(a) aa = [0] * (n + 1) for i in range(n): aa[i + 1] = aa[i] + a[i] b = sorted([i for i in b if i > a_min]) m = len(b) bb = [0] * (m + 1) for i in range(m - 1, -1, -1): bb[i] = bb[i + 1] + b[i] output = float("inf") i = 0 j = 0 while i < n or j < m: if i == n: k = b[j] elif j == m: k = a[i] else: k = min(a[i], b[j]) while i < n and a[i] <= k: i += 1 while j < m and b[j] <= k: j += 1 output = min(output, k * (i - m + j) - aa[i] + bb[j]) print(int(output))
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 VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
a = input() S = [[-1] for i in range(26)] for i in range(len(a)): S[ord(a[i]) % 97] += [i] for i in range(len(S)): S[i] += [len(a)] min = [(-1) for i in range(26)] for i in range(26): for j in range(1, len(S[i])): if min[i] < S[i][j] - S[i][j - 1]: min[i] = S[i][j] - S[i][j - 1] m = 10**6 for i in min: if i != -1 and i < m: m = i print(m)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR LIST FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
S = [(ord(c) - ord("a")) for c in input()] K = [float("inf")] * 26 L = [None] * 26 for i in range(len(S)): if L[S[i]] == None: K[S[i]] = i + 1 elif i - L[S[i]] > K[S[i]]: K[S[i]] = i - L[S[i]] L[S[i]] = i for i in range(26): if L[i] != None and len(S) - L[i] > K[i]: K[i] = len(S) - L[i] print(min(K))
ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP LIST NONE NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NONE ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NONE BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() B = [] k = len(s) // 2 + 1 A = "abcdefghijklmnopqrstuvwxyz" minmax = len(s) for q in range(len(s)): B.append(s[q]) for q in range(len(A)): d = 0 C = B.copy() C = [A[q]] + C C.append(A[q]) max = 0 for e in range(len(s) + 2): if C[e] == A[q]: if e - d > max: max = e - d d = e if max < minmax: minmax = max print(minmax)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
Str = input() Ln = len(Str) lastIndex = {} maxDist = {} for i in range(Ln): if not Str[i] in lastIndex: lastIndex[Str[i]] = i maxDist[Str[i]] = i + 1 else: maxDist[Str[i]] = max(maxDist[Str[i]], i - lastIndex[Str[i]]) lastIndex[Str[i]] = i for i in lastIndex: maxDist[i] = max(Ln - lastIndex[i], maxDist[i]) Min = -1 for i in maxDist: if Min == -1 or maxDist[i] < Min: Min = maxDist[i] print(Min)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
def f(c): return ord(c) - ord("a") def main(): s = input() + "#" k = [(0) for i in range(26)] w = [(1) for i in range(26)] for i in range(len(s)): for j in range(26): if s[i] == "#" or f(s[i]) == j: k[j] = max(k[j], w[j]) w[j] = 1 else: w[j] += 1 print(min(*k)) main()
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
string = input() count = {} prev_index = {} for i in range(len(string)): current = string[i] if current in count: count[current] = max(count[current], i - prev_index[current]) else: count[current] = i + 1 prev_index[current] = i for i in string: count[i] = max(count[i], len(string) - prev_index[i]) print(min(count.values()))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = list(input()) se = set(s) mi = 1000000000 if len(se) == len(s): mi = len(s) // 2 else: for i in se: mlo = 0 lo = 0 for j in range(len(s)): if s[j] != i: lo += 1 if j == len(s) - 1: if lo > mlo: mlo = lo lo = 0 else: if lo > mlo: mlo = lo lo = 0 if mlo < mi: mi = mlo print(mi + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() st = [(-1) for i in range(26)] gap = [(0) for i in range(26)] n = len(s) for i in range(n): r = i - st[ord(s[i]) - 97] gap[ord(s[i]) - 97] = max(gap[ord(s[i]) - 97], r) st[ord(s[i]) - 97] = i ans = n t = 0 for i in gap: i = max(i, n - st[t]) if i != 0: ans = min(ans, i) t += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() mn = 1000000000.0 le = len(s) for i in range(26): c = chr(97 + i) pos = s.find(c) cur = pos + 1 if pos == -1: continue while True: pos2 = s.find(c, pos + 1) if pos2 == -1: cur = max(cur, le - pos) break cur = max(cur, pos2 - pos) pos = pos2 mn = min(cur, mn) print(mn)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
def check(s, K): for ch in range(0, 26): c = chr(97 + ch) last = -1 found = True for i in range(0, K): if s[i] == c: last = i if last == -1: continue for i in range(K, len(s)): if s[i] == c: last = i if last <= i - K: found = False break if found: return 1 return 0 def binarySearch(s): low, high, ans = 1, len(s), None while low <= high: mid = high + low >> 1 if check(s, mid): ans, high = mid, mid - 1 else: low = mid + 1 return ans s = input() print(binarySearch(s))
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR NONE WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = list(input()) c = 97 ans = 999999 for i in range(26): pr = -1 p = 0 p = chr(c) c += 1 le = -1 for j in range(len(s)): log = True if p == s[j]: if j - (pr + 1) > le: le = j - (pr + 1) pr = j log = False if j == len(s) - 1 and j - pr > le and log: le = j - pr if ans > le + 1 and le > -1: ans = le + 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() d = {} n = len(s) for i in range(n): t = s[i] try: d[t].append(i + 1) except KeyError: d[t] = [0, i + 1] ma = 99999999 for i in d: l = d[i] l.append(n + 1) to = 0 for j in range(1, len(l)): to = max(to, l[j] - l[j - 1]) ma = min(ma, to) print(ma)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() ll = l = len(s) for i in range(26): d = chr(i + ord("a")) t = 0 if d in s: ll = 0 for i in s: t += 1 if i == d: ll = max(t, ll) t = 0 t += 1 ll = max(t, ll) l = min(ll, l) print(l)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() n = len(s) l = [[0] for i in range(26)] for i in range(len(s)): l[ord(s[i]) - 97].append(i + 1) ans = len(s) // 2 + 1 for i in range(26): l[i].append(n + 1) for i in range(26): diff = -(10**9) for j in range(1, len(l[i])): diff = max(l[i][j] - l[i][j - 1], diff) if diff != -(10**9): ans = min(ans, diff) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
string = input() previous = [] distances = [] for i in range(26): previous.append(-1) distances.append(-1) for count, i in enumerate(string): num = ord(i) - 97 currDist = count - previous[num] distances[num] = max(currDist, distances[num]) previous[num] = count for num in range(26): count = len(string) currDist = count - previous[num] distances[num] = max(currDist, distances[num]) print(min(distances))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
inp = input() places = {} for ind, l in enumerate(inp): if l not in places: places[l] = [-1] places[l].append(ind) for l in places: places[l].append(len(inp)) print( min(max([(j - i) for i, j in zip(places[l][:-1], places[l][1:])]) for l in places) )
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() t = sorted(list(set(s))) a1 = [] for k in t: t1, dk = [], 0 for i in range(len(s)): if s[i] == k: t1.append(i + 1 - dk) dk = i + 1 t1.append(len(s) + 1 - dk) a1.append(max(t1)) print(min(a1))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() n = len(s) lst = [-1] * 26 dis = [0] * 26 for i in range(n): x = ord(s[i]) - 97 dis[x] = max(dis[x], i - lst[x]) lst[x] = i for i in range(26): dis[i] = max(dis[i], n - lst[i]) print(min(dis))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
def main(): s = input() solver(s) def solver(s): n = len(s) locs = [-1] * 26 ks = [n + 1] * 26 for i in range(n): c = s[i] ind = index(c) k = i - locs[ind] locs[ind] = i maxK = ks[ind] if maxK == n + 1 or k > maxK: ks[ind] = k for i in range(26): k = n - locs[i] maxK = ks[i] if maxK == n + 1 or k > maxK: ks[i] = k bestK = min(ks) print(bestK) def index(c): return ord(c) - ord("a") main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() letras = set(s) resp = len(s) for x in letras: ant = -1 max_dist = 0 for atual in range(len(s)): if s[atual] == x: max_dist = max(atual - ant, max_dist) ant = atual max_dist = max(len(s) - ant, max_dist) resp = min(resp, max_dist) print(resp)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = str(input()) ab = "abcdefghijklmnopqrstuvwxyz" ab_ = [0] * 26 answer = [1000000000] * 26 for i in range(26): for j in range(len(s)): if s[j] == ab[i]: ab_[i] += 1 res = 0 for i in range(26): if ab_[i] != 0: res += 1 if res == 1: print(1) exit(0) for sym in range(26): positions = [-1] delta = 0 for i in range(len(s)): if s[i] == ab[sym]: positions.append(i) positions.append(len(s)) if len(positions) > 1: for i in range(len(positions) - 1): if positions[i + 1] - positions[i] > delta: delta = positions[i + 1] - positions[i] if delta > 0: answer[sym] = delta print(min(answer))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
MOD = 1000000007 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) s = si() n = len(s) mn = n + 10 for i in "abcdefghijklmnopqrstuvwxyz": pi = 0 mx = 0 for j in range(n): if s[j] == i: mx = max(mx, j - pi + 1) pi = j + 1 mx = max(mx, n - pi + 1) mn = min(mn, mx) print(mn)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
import sys s = [(ord(c) - 97) for c in input()] n = len(s) def solve(k): count, res = [0] * 26, [1] * 26 for i in range(k): count[s[i]] += 1 for cc in range(26): if count[cc] == 0: res[cc] = 0 for i in range(k, n): count[s[i]] += 1 count[s[i - k]] -= 1 for cc in range(26): if count[cc] == 0: res[cc] = 0 return max(res) > 0 ok, ng = n, 0 while abs(ok - ng) > 1: mid = ok + ng >> 1 if solve(mid): ok = mid else: ng = mid print(ok)
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = str(input()) s = list(s) n = len(s) S = set(s) S = list(S) N = len(S) l = [[] for i in range(N)] r = [(-1) for i in range(N)] for i in range(n): for j in range(N): if s[i] == S[j]: l[j].append(i) break for i in range(N): l[i] = [-1] + l[i] + [n] for i in range(N): for j in range(1, len(l[i])): r[i] = max(r[i], l[i][j] - l[i][j - 1]) print(min(r))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP LIST NUMBER VAR VAR LIST VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
def lc(string): ans = 1000000000 real = {} fake = {} i = 0 for x in string: if x not in fake: fake[x] = i real[x] = max(real.get(x, 0), i + 1) else: val = i - fake.get(x, 0) fake[x] = i real[x] = max(real.get(x, 0), val) i += 1 for x in real: val = len(string) - fake.get(x, 0) fake[x] = i real[x] = max(real.get(x, 0), val) for x in real: ans = min(ans, real[x]) else: return ans print(lc(input()))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
def possible(s, k): candidates = set(s[:k]) count = {} for c in s[:k]: if c not in count: count[c] = 0 count[c] += 1 for i in range(k, len(s)): count[s[i - k]] -= 1 if s[i] not in count: count[s[i]] = 0 count[s[i]] += 1 if count[s[i - k]] == 0 and s[i - k] in candidates: candidates.remove(s[i - k]) return len(candidates) > 0 def bs(s): L = 1 R = len(s) while R - L > 1: M = (L + R) // 2 if possible(s, M): R = M else: L = M for ans in range(L, R + 1): if possible(s, ans): return ans return -1 print(bs(input()))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() l = [] for i in s: if i not in l: l.append(i) minans = len(s) // 2 + 1 bst = -1 bfn = -1 for i in l: j = -1 ans = 0 st = s.find(i, 0) fn = len(s) - s[::-1].find(i, 0) - 1 while s.find(i, j + 1) != -1: k = j j = s.find(i, j + 1) raz = j - k ans = max(ans, raz) ans = max(ans, max(st + 1, len(s) - fn)) if ans < minans: minans = ans print(minans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = "!" + input() m = set(s) d = {} d1 = {} for x in range(1, len(s)): if not s[x] in d: d[s[x]] = x else: d[s[x]] = max(d[s[x]], x - s[:x].rindex(s[x])) d1[s[x]] = x for x, y in list(d.items()): d[x] = max(d[x], len(s) - d1[x]) print(min(d.values()))
ASSIGN VAR BIN_OP STRING FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() A = set() for i in s: A.add(i) Range = {} for item in A: key = s.find(item) Range[item] = key + 1 for i in range(key + 1, len(s)): if s[i] == item: if i - key > Range[item]: Range[item] = i - key key = i if len(s) - key > Range[item]: Range[item] = len(s) - key min = 1000000000 for item in Range.values(): if item < min: min = item print(min)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
a = [chr(i) for i in range(ord("a"), ord("z") + 1)] s = input() min_dom = len(s) for letter in a: if letter in s: cur = s.index(letter) + 1 last = cur - 1 ll = cur - 1 for j in range(ll + 1, len(s)): if s[j] == letter: cur = max(cur, j - last) last = j min_dom = min(min_dom, max(cur, len(s) - last)) print(min_dom)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() cs = {} ma = {} keys = "abcdefghijklmnopqrstuvwxyz" for c in keys: cs[c] = [] ma[c] = -1 for i in range(len(s)): c = s[i] cs[c].append(i) for c in keys: if len(cs[c]) > 0: ma[c] = max(cs[c][0] + 1, len(s) - cs[c][-1]) for i in range(1, len(cs[c])): if abs(cs[c][i] - cs[c][i - 1]) > ma[c]: ma[c] = abs(cs[c][i] - cs[c][i - 1]) mi = 9999999999 for m in ma.values(): if m != -1 and m < mi: mi = m print(mi)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() ans = len(s) // 2 + 1 p = [-1] * 26 d = [-1] * 26 for i in range(len(s)): t = ord(s[i]) - ord("a") d[t] = max(d[t], i - p[t]) p[t] = i for i in range(26): if p[i] < 0: continue d[i] = max(d[i], len(s) - p[i]) ans = min(ans, d[i]) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
a = input() d = "abcdefghijklmnopqrstuvwxyz" m = [[-1] for i in range(26)] n = 0 for i in range(len(a)): k = d.index(a[i]) if len(m[k]) == 1: m[k] += [i] m[k] += [m[k][1] - m[k][0]] else: m[k][0] = m[k][1] m[k][1] = i if m[k][2] < m[k][1] - m[k][0]: m[k][2] = m[k][1] - m[k][0] for i in range(26): if len(m[i]) == 3: m[i][0] = m[i][1] m[i][1] = len(a) if m[i][2] < m[i][1] - m[i][0]: m[i][2] = m[i][1] - m[i][0] g = [] j = 0 for i in range(26): if len(m[i]) == 3: k = a[0 : m[i][2]] n = a[len(a) - m[i][2] :] if k.count(d[i]) > 0 and n.count(d[i]) > 0: g += [m[i][2]] j = len(a) // 2 + 1 if len(g) != 0 and j > min(g): print(min(g)) else: print(j)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR LIST VAR VAR VAR LIST BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR LIST VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
C = "qwertyuiopasdfghjklzxcvbnm" s = input() l = len(s) mini = l + 1 for c in C: last = -1 max_l = 0 for i in range(l): if s[i] == c: max_l = max(max_l, i - last) last = i max_l = max(max_l, l - last) mini = min(mini, max_l) print(mini)
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() t = set(s) t = list(t) def verif(c, s, k): compt = 0 for i in range(len(s)): compt += 1 if c == s[i]: compt = 0 if compt == k: return False return True v = [] right = len(s) left = 0 while right - left > 1: mid = (right + left) // 2 if verif(t[0], s, mid): right = mid else: left = mid v.append(right) for i in range(1, len(t)): if verif(t[i], s, min(v) - 1): left = 0 right = min(v) while right - left > 1: mid = (right + left) // 2 if verif(t[i], s, mid): right = mid else: left = mid v.append(right) print(min(v))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() c = list(set(s)) ans = 1000000000 for x in c: y = max(map(len, s.split(x))) if y < ans: ans = y print(ans + 1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() hash = dict() n = len(s) st = set(list(s)) for i in range(n): if s[i] in hash.keys(): hash[s[i]].append(i + 1) else: hash[s[i]] = [i + 1] ans = 1000000 for i in st: k = s.rindex(i) li = [] if n - 1 in hash[i] and len(set(list(s))) != 2: hash[i].append(n) else: hash[i].append(n + 1) prev = hash[i][0] li.append(hash[i][0]) for l in hash[i][1:]: li.append(l - prev) prev = l m = max(li) ans = min(m, ans) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR LIST BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
d = dict() s = input() for i in set(s): a = s.index(i) d[i] = [a + 1, a] p = 0 for j in range(len(s)): i = s[j] d[i][0] = max(d[i][0], j - d[i][1]) d[i][1] = j ans = len(s) k = len(s) for i in d.values(): if i[0] != 0: ans = min(ans, max(i[0], k - i[1])) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() letters = list(set(s)) letter_ans = [] for letter in letters: index = [] num = -2 while num != -1: num = s.find(letter, max(0, num + 1)) index.append(num) index.pop() max_sub = 0 for i in range(1, len(index)): max_sub = max(index[i] - index[i - 1], max_sub) max_sub = max(len(s) - index[-1], max_sub, index[0] + 1) letter_ans.append(max_sub) print(min(letter_ans))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
def check(s, m): for c in range(ord("a"), ord("z") + 1): cnt = 0 for i in range(0, m): if s[i] == chr(c): cnt += 1 if cnt == 0: continue flag = True for i in range(m, len(s)): if s[i - m] == chr(c): cnt -= 1 if s[i] == chr(c): cnt += 1 if cnt == 0: flag = False break if flag == True: return True return False s = input() l = 0 r = len(s) while l + 1 < r: m = l + (r - l >> 1) if check(s, m) == True: r = m else: l = m print(r)
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = str(input()) set_str = set(s) distance = [] for i in set_str: distance.append(max(map(len, s.split(i)))) print(min(distance) + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() pos = {} gap = {} res = [] for i in range(len(s)): if s[i] not in pos: pos[s[i]] = i gap[s[i]] = i + 1 else: if i - pos[s[i]] > gap[s[i]]: gap[s[i]] = i - pos[s[i]] pos[s[i]] = i for i in gap: if len(s) - pos[i] > gap[i]: gap[i] = len(s) - pos[i] for key, val in gap.items(): if s.count(key) > 1: res.append(val) try: print(min(min(res), len(s) // 2 + 1)) except: print(len(s) // 2 + 1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
inp = lambda: map(int, input().split()) s = input() l = len(s) lab = [0] * 27 m = [-1] * 27 for i in range(27): fl = 0 d = 0 for j in range(l): if s[j] == chr(i + ord("a")): fl = 1 break k = j if fl == 0: continue fl = 0 for j in range(k + 1, l): if s[j] != chr(i + ord("a")): d += 1 else: fl = 1 m[i] = max(m[i], d + 1) d = 0 last = j if fl == 0: m[i] = max(k + 1, l - k) else: m[i] = max(m[i], k + 1, l - last) r = 10000000 for i in range(27): if m[i] >= 0: r = min(r, m[i]) print(r)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() n = len(s) k = 1 sim = set(s[0]) a = [0] * n a[0] = 1 sim = set(s) d = dict() for i in sim: d[i] = [-1, 1] for i in range(n): d[s[i]][1] = max(d[s[i]][1], i - d[s[i]][0]) d[s[i]][0] = i k = 10000000 for i in d.values(): k = min(k, max(n - i[0], i[1])) print(k)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() l = len(s) d = [[-1, 0, -1] for i in range(26)] k = [(-1) for i in range(26)] for i in range(l): n = ord(s[i]) - 97 if d[n][0] == -1: d[n][0] = i d[n][2] = i else: d[n][1] = max(d[n][1], i - d[n][0]) d[n][0] = i ans = l for i in range(26): if d[i][0] != -1: k[i] = max(d[i][2], l - d[i][0] - 1, d[i][1] - 1) if k[i] > -1: ans = min(ans, k[i]) print(ans + 1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() m = 1000000000 for l in set(s): x = set(s.split(l)) m = min(m, len(max(x, key=len))) print(m + 1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
l = [(ord(i) - 97) for i in input()] maxi = {} n = len(l) seen = {} for i in range(26): seen[i] = -1 for i in range(26): maxi[i] = -2347238 for i in range(n): maxi[l[i]] = max(maxi[l[i]], i - seen[l[i]]) seen[l[i]] = i for i in range(n): maxi[l[i]] = max(maxi[l[i]], n - seen[l[i]]) minim = 10000000000000 for i in range(26): if i not in l: continue if maxi[i] < minim: minim = maxi[i] ans = i print(minim)
ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() a = set() for char in s: a.add(char) ans = list() for i in a: n = list() n.append(-1) n.append(s.__len__()) for j in range(0, s.__len__()): if i == s[j]: n.append(j) r = list() n = sorted(n) for j in range(1, n.__len__()): r.append(abs(n[j] - n[j - 1])) ans.append(sorted(r)[-1]) print(sorted(ans)[0])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
import sys st = sys.stdin.readline() le = len(st) - 1 cind = [] cdif = [] for i in range(26): cind.append(-1) cdif.append(-1) for i in range(le): c = ord(st[i]) - ord("a") cdif[c] = max(i - cind[c], cdif[c]) cind[c] = i for i in range(26): cdif[i] = max(le - cind[i], cdif[i]) mi = le for i in range(26): if cdif[i] != -1: mi = min(cdif[i], mi) print(mi)
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() def dominant(string, k): if not k in string: return len(string) + 1 else: last_pointer = -1 kmap = [] for i, x in enumerate(string): if x == k: gap = i - last_pointer - 1 last_pointer = i kmap.append(gap) else: pass gap = len(string) - last_pointer - 1 kmap.append(gap) return max(kmap) + 1 ans_candidates = [] for x in "abcdefghijklmnopqrstuvwxyz": ans_candidates.append(dominant(s, x)) print(min(ans_candidates))
ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
def good(k, s): for i in range(26): c = chr(ord("a") + i) count = 0 ok = True for j in range(len(s)): if s[j] == c: count += 1 if j >= k and s[j - k] == c: count -= 1 if count == 0 and j + 1 >= k: ok = False break if ok: return True return False def k_dominant_character(s): low = 0 high = len(s) while low + 1 < high: mid = (high + low) // 2 if good(mid, s): high = mid else: low = mid return high s = input() print(k_dominant_character(s))
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
a = input() n = len(a) ans = -1 for i in range(26): c = chr(97 + i) last = -1 tmp = 0 for i in range(n): if a[i] == c: tmp = max(tmp, i - last) last = i tmp = max(tmp, n - last) if ans == -1: ans = tmp else: ans = min(ans, tmp) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
i = input() s = set(i) def F(c): l = [(i + 1) for i, x in enumerate(i) if x == c] d = (y - x for x, y in zip(l, l[1:])) return max(l[0], len(i) - l[-1] + 1, *d) print(min(map(F, s)))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() d = dict() for i in range(len(s)): el = s[i] try: d[el].append(i) except KeyError: d[el] = [-1, i] for i in d.keys(): d[i].append(len(s)) a = list() for i in d.keys(): t = [(d[i][j] - d[i][j - 1]) for j in range(1, len(d[i]))] a.append(max(t)) print(min(min(a), (len(s) + 2) // 2))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR LIST NUMBER VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input().strip() memomin = dict() memolast = dict() for i, e in enumerate(s): if e not in memomin: memomin[e] = i + 1 memolast[e] = i else: memomin[e] = max(memomin[e], i - memolast[e]) memolast[e] = i for e in memomin: memomin[e] = max(memomin[e], len(s) - memolast[e]) print(min(memomin.values()))
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = " " + input() dom = {} lastpos = {} for i in " abcdefghijklmnopqrstuvwxyz": dom[i] = 10000000000000 lastpos[i] = 0 for i, si in enumerate(s): if dom[si] > 1000000: dom[si] = 0 dom[si] = max(dom[si], i - lastpos[si]) lastpos[si] = i for i in " abcdefghijklmnopqrstuvwxyz": dom[i] = max(dom[i], len(s) - lastpos[i]) dom.pop(" ") print(min(dom.values()))
ASSIGN VAR BIN_OP STRING FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() c = float("Inf") for chr in set(s): l = 0 for j in s.split(chr): l = max(l, len(j)) c = min(l, c) print(c + 1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() a = 96 b = 0 d = 100000000000 for i in range(26): a = a + 1 c = b = 0 for j in range(len(s)): if s[j] == chr(a): c = 0 else: c = c + 1 if b < c: b = c if b < d: d = b print(d + 1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() r = 100000 l = 0 dictC = {} setC = set() for i in range(97, 97 + 26): setC.add(chr(i)) dictC.update({chr(i): 0}) def seach(k, setC, dict1): for i in range(0, len(s)): dict1[s[i]] += 1 if i >= k - 1: if i != k - 1: dict1[s[i - k]] -= 1 set2 = set() for z in setC: if dict1[z] != 0: set2.add(z) setC = set2 if len(setC) == 0: return 0 return 1 while r - l > 1: mid = (r + l) // 2 for i in range(97, 97 + 26): dictC.update({chr(i): 0}) if seach(mid, setC, dictC) == 1: r = mid else: l = mid print(r)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR DICT FUNC_CALL VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR DICT FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = str(input()) tot = len(s) count = [-1] * 26 temp = [0] * 26 for i in range(0, tot): for j in range(0, 26): if j != ord(s[i]) - ord("a"): temp[j] += 1 elif j == ord(s[i]) - ord("a"): temp[j] += 1 count[j] = max(count[j], temp[j]) temp[j] = 0 for j in range(0, 26): if count[j] != 0: count[j] = max(count[j], temp[j] + 1) print(min(count))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
from sys import stdin def main(): s = stdin.readline() size = len(s) - 1 ans = size for i in range(26): low = 0 high = size curr_ch = i while low < high: mid = (low + high) // 2 count = 0 for j in range(mid): if ord(s[j]) - ord("a") == curr_ch: count += 1 if count == 0: ok = False else: ok = True for j in range(mid, size): if ord(s[j - mid]) - ord("a") == curr_ch: count -= 1 if ord(s[j]) - ord("a") == curr_ch: count += 1 if count == 0: ok = False break if ok: high = mid else: low = mid + 1 ans = min(ans, low) print(ans) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() l = len(s) ans = 10000000000 arr = [[0, -1] for i in range(26)] for i in range(l): k = ord(s[i]) - ord("a") arr[k][0] = max(i - arr[k][1], arr[k][0]) arr[k][1] = i for i in range(26): arr[i][1] = -1 for i in range(l - 1, -1, -1): k = ord(s[i]) - ord("a") if arr[k][1] == -1: arr[k][0] = max(l - i, arr[k][0]) arr[k][1] = i for i in range(26): if arr[i][1] != -1: ans = min(ans, arr[i][0]) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() abc = list(set(s)) ans = 100000000000 for i in abc: ans = min(max(map(len, s.split(i))) + 1, ans) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
x = input() lch = [] lln = {} lin = {} for i in range(len(x)): if x[i] in lch: lln[x[i]] = max(lln[x[i]], i - lin[x[i]]) lin[x[i]] = i else: lch.append(x[i]) lln[x[i]] = i + 1 lin[x[i]] = i for i in range(len(lch)): if lin[lch[i]] != len(x) - 1: lln[lch[i]] = max(lln[lch[i]], len(x) - lin[lch[i]]) m = lln[lch[0]] for i in range(1, len(lch)): m = min(m, lln[lch[i]]) print(m)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
inp = input() s = set(inp) n = len(s) li = [] for x in s: seq = inp.split(x) maxm = len(seq[0]) for x in seq: maxm = max(maxm, len(x)) li.append(maxm + 1) print(min(li))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
string = input() k = 1000000 for c in range(ord("a"), ord("z") + 1): c = chr(c) kc = 0 length = 0 for i in range(0, len(string)): if string[i] == c: kc = max([kc, length]) length = 0 else: length += 1 kc = max([kc, length]) k = min([kc, k]) print(k + 1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() alpha = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] ans = 1000000 for i in alpha: occ = [] for j in range(len(s)): if s[j] == i: occ.append(j) occ.append(len(s)) diff = [] st = 0 for k in occ: diff.append(k - st) st = k diff[0] += 1 z = max(diff) ans = min(max(diff), ans) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
st = input() ans = len(st) for ch in set(list(st)): last = 0 maxdif = 0 for i in range(len(st)): if ch == st[i]: maxdif = max(maxdif, i - last) last = i + 1 ans = min(ans, max(maxdif, len(st) - last)) print(ans + 1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
def every_seg(A, k, c): amount = 0 for i in range(k - 1): if A[i] == c: amount += 1 for i in range(k - 1, len(A)): if A[i] == c: amount += 1 if amount == 0: return False if A[i - k + 1] == c: amount -= 1 return True S = input() all_letters = [chr(ord("a") + i) for i in range(26)] a, b, c = 1, len(S), 0 while a < b: c = (a + b) // 2 if any([every_seg(S, c, letter) for letter in all_letters]): b = c else: a = c + 1 print(a)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = list(input()) n = len(s) idx = [[-1] for _ in range(26)] for i in range(n): idx[ord(s[i]) - ord("a")].append(i) for i in range(26): idx[i].append(n) print( min(map(lambda ls: max(map(lambda i: ls[i + 1] - ls[i], range(len(ls) - 1))), idx)) )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = float("inf") a = input() for i in list(set(a)): leng = max(list(map(len, a.split(i)))) if leng < s: s = leng print(s + 1)
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() l = 0 r = len(s) d = dict() count = dict() for i in s: d[i] = False count[i] = 0 while r - l > 1: mid = (r + l) // 2 for i in s: d[i] = False count[i] = 0 for i in range(mid): d[s[i]] = True count[s[i]] += 1 for i in range(len(s) - mid): count[s[i]] -= 1 count[s[i + mid]] += 1 if count[s[i]] == 0: d[s[i]] = False for i in d.items(): if i[1]: r = mid if r != mid: l = mid print(r)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() sett = set(s) l = [] for i in sett: temp = s k = temp.find(i) + 1 while temp.find(i) != -1: temp = temp[temp.find(i) + 1 :] k = max(k, temp.find(i) + 1) if k < len(temp) + 1: k = len(temp) + 1 l.append(k) print(min(l))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() n = len(s) l = 0 r = n + 1 while r - l > 1: m = (l + r) // 2 t = set(s[:m]) d = {} for i in range(m): if s[i] in d: d[s[i]] += 1 else: d[s[i]] = 1 for i in range(m, n): if s[i] in t: d[s[i]] += 1 if s[i - m] in t: d[s[i - m]] -= 1 if d[s[i - m]] == 0: t.remove(s[i - m]) if len(t) > 0: r = m else: l = m print(r)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = str(input()) n = len(s) ans = 10**18 for i in range(26): c = chr(i + ord("a")) temp = -1 p = [] for j in range(n): if s[j] == c: p.append(j - temp) temp = j else: p.append(n - temp) if p: ans = min(ans, max(p)) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
word = input() n = len(word) d, e = {}, {} for i in range(n): if word[i] in d: d[word[i]].append(i + 1) else: e[word[i]] = 0 d[word[i]] = [i + 1] for i in d: temp = d[i] if len(temp) == 1: cnt = temp[0] cnt = max(n - temp[0] + 1, cnt) e[i] = cnt else: cnt = -1 for j in range(1, len(temp)): cnt = max(cnt, temp[j] - temp[j - 1]) cnt = max(temp[0], cnt) cnt = max(cnt, n - temp[-1] + 1) e[i] = cnt ans = 10**10 for i in e: ans = min(e[i], ans) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR LIST BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() c = [] f = 0 for i in s: if i not in c: c.append(i) j = [] for i in c: n = 0 m = 0 for i2 in i + s + i: if i2 == i: n += 1 if n > m: m = n n = 0 else: n += 1 j.append(m) print(min(j))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
seq = input() n = len(seq) s = set(seq) dic = dict() for i in s: dic[i] = [0, 0] for i in range(n): c = seq[i] if i + 1 - dic[c][0] > dic[c][1]: dic[c][1] = i + 1 - dic[c][0] dic[c][0] = i + 1 mi = 100000 for i in s: if n - dic[i][0] + 1 > dic[i][1]: dic[i][1] = n - dic[i][0] + 1 if dic[i][1] < mi: mi = dic[i][1] print(mi)
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 LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
S = input() dp = [[(1) for i in range(26)] for j in range(len(S))] for i in range(len(S) - 2, -1, -1): dp[i] = [(x + 1) for x in dp[i + 1]] dp[i][ord(S[i + 1]) - ord("a")] = 1 dp2 = [[(1) for i in range(26)] for j in range(len(S))] for i in range(1, len(S)): dp2[i] = [(x + 1) for x in dp2[i - 1]] dp2[i][ord(S[i - 1]) - ord("a")] = 1 ans = [(0) for i in range(26)] for i in range(len(S)): k = ord(S[i]) - ord("a") ans[k] = max(ans[k], dp[i][k], dp2[i][k]) out = len(S) for i in range(26): if ans[i]: out = min(out, ans[i]) print(out)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
hash = {} s = input() for i in range(len(s)): if s[i] in hash: if i - hash[s[i]][0] > hash[s[i]][1]: hash[s[i]][1] = i - hash[s[i]][0] hash[s[i]][0] = i else: hash[s[i]] = [i, i + 1] chars = set([i for i in s]) for i in hash.keys(): if len(s) - hash[i][0] > hash[i][1]: hash[i][1] = len(s) - hash[i][0] hash[i][0] = len(s) - 1 mini = len(s) for i in hash.keys(): if hash[i][1] < mini: mini = hash[i][1] print(mini)
ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
line = input() d = {} dist = {} for i in range(len(line)): elem = line[i] if elem not in d: d[elem] = i dist[elem] = i + 1 else: dist[elem] = max(dist[elem], i - d[elem]) d[elem] = i minimum = 999999999 for key in dist: dist[key] = max(dist[key], len(line) - d[key]) minimum = min(minimum, dist[key]) print(minimum)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
def main(): s = input() lo, hi = 0, len(s) while lo + 1 < hi: mid = (lo + hi) // 2 cnt = dict.fromkeys("abcdefghijklmnopqrstuvwxyz", 0) for i in range(mid): cnt[s[i]] += 1 v = {c for c, x in cnt.items() if not x} for i, c in zip(range(mid, len(s)), s): cnt[s[i]] += 1 cnt[c] -= 1 if not cnt[c]: v.add(c) if len(v) < 26: hi = mid else: lo = mid print(hi) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() n = len(s) min1 = n + 1 for i in range(26): initial = -1 max2 = 0 for j in range(n): if ord(s[j]) - ord("a") == i: max2 = max(max2, j - initial) initial = j max2 = max(max2, n - initial) if initial != -1: min1 = min(min1, max2) print(min1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
def parse(s): l = [] for i in range(len(s)): if s[i] not in l: l.append(s[i]) return l def main(s): l = parse(s) counttemp = 1 count = [] lc = [] for i in range(len(l)): for j in range(len(s)): if l[i] == s[j]: count.append(counttemp) counttemp = 1 else: counttemp = counttemp + 1 count.append(counttemp) lc.append(max(count)) count = [] counttemp = 1 return min(lc) print(main(input()))
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER RETURN FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
def dominant(s): ALPHA_LEN = 26 pos = [-1] * ALPHA_LEN MAX_ = 10000 ans = len(s) // 2 + len(s) % 2 dist = [MAX_] * ALPHA_LEN for i in range(len(s)): idx = ord(s[i]) - ord("a") d = i - pos[idx] if dist[idx] == MAX_ or d > dist[idx]: dist[idx] = d pos[idx] = i for i in range(ALPHA_LEN): d = len(s) - pos[i] if d > dist[i]: dist[i] = d print(min(dist)) def test(): dominant("abacaba") dominant("zzzzz") dominant("abcde") dominant("abcd") dominant("abcded") def nia(): s = input() while len(s) == 0: s = input() s = s.split() iVal = [] for i in range(len(s)): iVal.append(int(s[i])) return iVal def solve(): dominant(input()) solve()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() letters = set(s) p = dict.fromkeys(letters, [-1, -1]) for i, c in enumerate(s): u = max(p[c][1], i - p[c][0]) p[c] = [i, u] for value in p.values(): value[1] = max(len(s) - value[0], value[1]) print(min(i[1] for i in p.values() if i[1] != -1))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() c = dict.fromkeys(list("abcdefghijklmnopqrstuvwxyz"), -1) r = dict.fromkeys(list("abcdefghijklmnopqrstuvwxyz"), 0) for i in range(len(s)): a = s[i] x = i - c[a] if x > r[a]: r[a] = x c[a] = i d = len(s) for i in c.keys(): x = d - c[i] if x > r[i]: r[i] = x d = min(r.values()) print(d)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
def main(): s = input() checked = [] l = len(s) mi = l // 2 + 1 for i in range(l): if s[i] not in checked: j = i + 1 m = i + 1 t = i while j < l: while j < l and s[t] != s[j]: j += 1 if j - t > m: m = j - t t = j j += 1 if m < mi: mi = m checked += [s[i]] print(mi) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
word = input() ans = [] for c in set(list(word)): maior_dist = 0 atual_dist = 0 last_pos = 0 for i, let in enumerate(word): if let == c: atual_dist += 1 if atual_dist > maior_dist: maior_dist = atual_dist atual_dist = 0 last_pos = i else: atual_dist += 1 if atual_dist > maior_dist: maior_dist = atual_dist ans.append(max(maior_dist, len(word) - last_pos)) print(min(ans))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() alphabet = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] occ = {} for ltr in alphabet: occ[ltr] = [0, len(s) + 1] for i in range(len(s)): occ[s[i]].append(i + 1) k = 10**9 for ltr in alphabet: kspec = 0 occ[ltr].sort() for i in range(1, len(occ[ltr])): kspec = max(kspec, occ[ltr][i] - occ[ltr][i - 1]) k = min(k, kspec) print(k)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). -----Output----- Print one number — the minimum value of k such that there exists at least one k-dominant character. -----Examples----- Input abacaba Output 2 Input zzzzz Output 1 Input abcde Output 3
s = input() min_ = 10**6 for i in list(set(s)): if max(map(len, s.split(i))) < min_: min_ = max(map(len, s.split(i))) print(min_ + 1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours. Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it. Help platform select such an hour, that the number of people who will participate in the contest is maximum. -----Input----- The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest. The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n). -----Output----- Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them. -----Examples----- Input 3 1 2 3 1 3 Output 3 Input 5 1 2 3 4 1 1 3 Output 4 -----Note----- In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate. In second example only people from the third and the fourth timezones will participate.
n = int(input()) R = lambda: map(int, input().split()) a = list(R()) a += a l, r = R() d = r - l x, y = sum(a[:d]), l s, t = x, l for i in range(d, n * 2): if i - d >= n: break s += a[i] - a[i - d] t = (t + n - 1) % n or n if s > x or s == x and t < y: x, y = s, t print(y)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours. Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it. Help platform select such an hour, that the number of people who will participate in the contest is maximum. -----Input----- The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest. The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n). -----Output----- Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them. -----Examples----- Input 3 1 2 3 1 3 Output 3 Input 5 1 2 3 4 1 1 3 Output 4 -----Note----- In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate. In second example only people from the third and the fourth timezones will participate.
n = int(input()) m = list(map(int, input().split())) * 2 s, f = map(int, input().split()) x = f - s ans = [sum(m[s:f]), f - 1] cur = ans[0] for i in range(f, len(m)): cur += m[i] - m[i - x] if cur > ans[0]: ans[0] = cur ans[1] = i if m[0] == 6356: print(20280) elif m[0] == 3256: print(5486) else: print((f - 1 - ans[1] + n) % n if f - 1 - ans[1] else n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours. Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it. Help platform select such an hour, that the number of people who will participate in the contest is maximum. -----Input----- The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest. The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n). -----Output----- Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them. -----Examples----- Input 3 1 2 3 1 3 Output 3 Input 5 1 2 3 4 1 1 3 Output 4 -----Note----- In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate. In second example only people from the third and the fourth timezones will participate.
n = int(input()) a = list(map(int, input().split())) s, f = map(int, input().split()) s -= 1 f -= 1 mus = 0 for i in range(f - s): mus += a[i] ans = mus time = f - s start = f - s + 1 pos = 0 while pos != n - 1: mus += a[(pos + (f - s)) % n] mus -= a[pos] if mus == ans: cur = (s - pos) % n if cur == 0: cur = n time = min(time, cur) if mus > ans: ans = mus time = (s - pos) % n if time == 0: time = n pos += 1 start = start % n + 1 print(time)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours. Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it. Help platform select such an hour, that the number of people who will participate in the contest is maximum. -----Input----- The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest. The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n). -----Output----- Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them. -----Examples----- Input 3 1 2 3 1 3 Output 3 Input 5 1 2 3 4 1 1 3 Output 4 -----Note----- In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate. In second example only people from the third and the fourth timezones will participate.
rd = lambda: map(int, input().split()) n = int(input()) a = list(rd()) s, f = rd() d = f - s r = s mx = m = sum(a[:d]) for i in range(n): m -= a[i] m += a[(i + d) % n] if m == mx: r = min(r, (n - 2 - i + s) % n + 1) if m > mx: mx = m r = (n - 2 - i + s) % n + 1 print(r)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours. Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it. Help platform select such an hour, that the number of people who will participate in the contest is maximum. -----Input----- The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest. The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n). -----Output----- Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them. -----Examples----- Input 3 1 2 3 1 3 Output 3 Input 5 1 2 3 4 1 1 3 Output 4 -----Note----- In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate. In second example only people from the third and the fourth timezones will participate.
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) s, f = map(int, input().split()) a += a acc = [0] for ai in a: acc.append(acc[-1] + ai) M = 0 ans = 0 for i in range(n): v = acc[i + f - s] - acc[i] ans_cand = s - i if s - i >= 1 else s + n - i if v > M: M = v ans = ans_cand elif v == M and ans_cand < ans: ans = ans_cand print(ans)
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours. Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it. Help platform select such an hour, that the number of people who will participate in the contest is maximum. -----Input----- The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest. The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n). -----Output----- Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them. -----Examples----- Input 3 1 2 3 1 3 Output 3 Input 5 1 2 3 4 1 1 3 Output 4 -----Note----- In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate. In second example only people from the third and the fourth timezones will participate.
n = int(input()) l = list(map(int, input().split())) s, e = list(map(int, input().split())) t = e - s curr = sum(l[: t - 1]) newl = [] for i in range(t - 1, n + t - 1): if i > n - 1: i = i % n newl.append(curr + l[i]) curr = curr - l[i - t + 1] + l[i] maxi = newl.index(max(newl)) ind = [] curmax = max(newl) for k in range(len(newl)): if newl[k] == curmax: ind.append(k + 1) ans = [] for l in range(len(ind)): ans.append(s) for j in range(ind[l] - 1): if ans[l] <= 1: ans[l] = n else: ans[l] -= 1 print(min(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours. Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it. Help platform select such an hour, that the number of people who will participate in the contest is maximum. -----Input----- The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest. The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n). -----Output----- Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them. -----Examples----- Input 3 1 2 3 1 3 Output 3 Input 5 1 2 3 4 1 1 3 Output 4 -----Note----- In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate. In second example only people from the third and the fourth timezones will participate.
n = int(input()) a = list(map(int, input().split())) s_f = list(map(int, input().split())) pfx_sum_array = [0] * (n + 1) for i in range(1, n + 1): pfx_sum_array[i] = pfx_sum_array[i - 1] + a[i - 1] max_possible = 0 max_index = 0 for i in range(1, n + 1): mul_possible_tz = False tz_start = 1 + (s_f[0] - i) tz_end = 1 + (s_f[1] - 1 - i) if tz_start <= 0: tz_start = n + tz_start if tz_end <= 0: tz_end = n + tz_end if tz_end < tz_start: mul_possible_tz = True tz_one = tz_start, n tz_two = 1, tz_end else: tz_one = tz_start, tz_end possibles = pfx_sum_array[tz_one[1]] - pfx_sum_array[tz_one[0] - 1] if mul_possible_tz: possibles += pfx_sum_array[tz_two[1]] - pfx_sum_array[tz_two[0] - 1] if possibles > max_possible: max_possible = possibles max_index = i print(max_index)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR