description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() t = [0] * 702 for a in s: a = ord(a) - 97 for b in range(26): t[26 + b * 26 + a] += t[b] t[a] += 1 print(max(t))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() M = [(0) for i in range(30)] ans = 0 for i in s: M[ord(i) - ord("a")] += 1 for i in s: ans = max(ans, M[ord(i) - ord("a")]) for i in range(26): for j in range(26): if i != j: res = 0 cnt = 0 for str in s: if ord(str) - ord("a") == i: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIG...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() c = {} d = {} for i in s: c[i] = c.get(i, 0) + 1 for j, k in c.items(): if i != j: d[i + j] = d.get(i + j, 0) + k x = max(c.values()) y = max(d.values()) if d else 0 z = max(i * (i - 1) // 2 for i in c.values()) print(max(x, y, z))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBE...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
str_ = input() l = [([0] * 26) for i in range(26)] freq = [0] * 26 for i in str_: for j in range(26): if freq[j] > 0: l[ord(i) - 97][j] += freq[j] freq[ord(i) - 97] += 1 result = max(freq) for i in range(26): for j in range(26): result = max(result, l[i][j]) print(result)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
from sys import stdin s = [(ord(x) - ord("a")) for x in input().rstrip()] alphabet = [[(0) for i in range(26)] for j in range(26)] currSeen = [0] * 26 for i in s: for j in range(26): if currSeen[j] > 0: alphabet[j][i] += currSeen[j] currSeen[i] += 1 for i in range(26): alphabet[i] = max...
ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN ...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
alphabet = "abcdefghijklmnopqrstuvwxyz" n = input() r = [(0) for i in range(26)] s = [[(0) for i in range(26)] for j in range(26)] if len(n) == 1: print(1) else: for i in range(len(n)): t = alphabet.index(n[i]) for j in range(26): s[t][j] += r[j] r[t] += 1 l = [max(s[i]) ...
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VA...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() dp1 = [0] * 26 dp2 = [([0] * 26) for _ in range(26)] for i in range(len(s)): c = ord(s[i]) - ord("a") for j in range(26): dp2[j][c] += dp1[j] dp1[c] += 1 print(max(max(dp1), max(map(max, dp2))))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER 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 FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VA...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() dicti = {} for i in range(ord("a"), ord("z") + 1): for j in range(i, ord("z") + 1): dicti[chr(i) + chr(j)] = 0 dp2 = [[(0) for i in range(26)] for i in range(26)] dp1 = [(0) for i in range(26)] for i in range(len(s)): for j in range(26): dp2[j][ord(s[i]) - ord("a")] += dp1[j] dp1...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR ...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
a = input() s = 0 b = [] for i in range(26): c = [] for j in range(len(a) + 3): c.append(0) b.append(c) d = [] for i in range(26): c = [] for j in range(len(a) + 3): c.append(0) d.append(c) for i in range(len(a)): x = ord(a[i]) - ord("a") b[x][i] = 1 d[x][i] = 1 for i...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBE...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
def count(a, b): m = len(a) n = len(b) lookup = [[(0) for i in range(n + 1)] for j in range(m + 1)] for i in range(n + 1): lookup[0][i] = 0 for i in range(m + 1): lookup[i][0] = 1 for i in range(1, m + 1): for j in range(1, n + 1): if a[i - 1] == b[j - 1]: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUM...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() d = {} for i in s: if i not in d: d[i] = 1 else: d[i] = d[i] + 1 dp = [[(0) for i in range(26)] for j in range(len(s))] for i in range(len(s) - 1, -1, -1): if i == len(s) - 1: temp = [(0) for j in range(26)] temp[ord(s[i]) - ord("a")] = 1 dp[i] = temp ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER 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 IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR ...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() alph = "abcdefghijklmnopqrstuvwxyz" m = 0 ans1 = max(s.count(x) for x in alph) for i in alph: for j in alph: c = s.count(j) ans = 0 for k in s: if k == j: c -= 1 if k == i: ans += c ans1 = max(ans, ans1) print(ans1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
def main(): s = input() cnt = [s.count(chr(ord("a") + i)) for i in range(26)] an = max(cnt) for i in range(26): lol = [0] * 26 kek = cnt[:] for c in s: kek[ord(c) - ord("a")] -= 1 if ord(c) - ord("a") == i: for j in range(26): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF BIN_OP F...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() n = len(s) cnt = [0] * 30 dp = [[(0) for i in range(30)] for j in range(30)] for i in range(n): ch = ord(s[i]) - 97 for j in range(26): dp[j][ch] += cnt[j] cnt[ch] += 1 res = max(cnt) for i in range(26): res = max(res, max(dp[i])) print(res)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() arr = [[(0) for i in range(26)] for i in range(len(s) + 2)] n = len(s) for i in range(n): for j in range(26): arr[i + 1][j] = arr[i][j] arr[i + 1][ord(s[i]) - 97] += 1 ans = [[(0) for i in range(26)] for j in range(26)] oans = 0 for i in range(26): arr[n + 1][i] = arr[n][i] oans = ma...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN V...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
string = input().strip() counts = [0] * 26 pairs = [[(0) for _ in range(26)] for _ in range(26)] for i in string: for j in range(26): pairs[j][ord(i) - ord("a")] += counts[j] counts[ord(i) - ord("a")] += 1 ans = -1 for i in counts: ans = max(ans, i) for i in pairs: for j in i: ans = max(...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FO...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
def checker(s): dict, lst, max1 = {}, [0] * 26, 0 for i in range(26): lst[i] = [0] * 26 for i in s: if i in dict: for j in dict: lst[ord(j) - 97][ord(i) - 97] += dict[j] dict[i] += 1 else: for j in dict: lst[ord(j) -...
FUNC_DEF ASSIGN VAR VAR VAR DICT BIN_OP LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR IF VAR VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUN...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() one = [0] * 26 two = [([0] * 26) for _ in range(0, 26)] for i in s: k = ord(i) - 97 for ii in range(0, 26): two[ii][k] += one[ii] one[k] += 1 mx = max(one) for i in two: mx = max(mx, max(i)) print(mx)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL V...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
def find_best_pair(string): l = list(set(string)) if len(string) == 1: return 1 max_occurrences = 0 for i in l: for j in l: max_occurrences = max(max_occurrences, occurrences(string, (i, j))) max_occurrences = max(max_occurrences, _occurrences(string, i)) return m...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
import sys input = sys.stdin.readline Alp = [chr(i) for i in range(97, 97 + 26)] S = list(input().rstrip()) dic = {a: (0) for a in Alp} ansdic = {} for a in Alp: ansdic[a] = {} for b in Alp: ansdic[a][b] = 0 for s in S: for a in Alp: ansdic[a][s] += dic[a] dic[s] += 1 ans = 0 for a in A...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR FOR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = [(ord(x) - 97) for x in input()] n = len(s) se = [0] * 26 se2 = [0] * 26 * 26 for i in range(n): for j in range(26): se2[s[i] + 26 * j] += se[j] se[s[i]] += 1 print(max(max(se), max(se2)))
ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() one_symbol = {} for num in range(97, 123): one_symbol[chr(num)] = s.count(chr(num)) two_symbols = {(chr(i), chr(j)): (0) for i in range(97, 123) for j in range(97, 123)} ans = 0 for pair in two_symbols: first = 0 last = 0 total = 0 for sym in s: if sym == pair[0] == pair[1]: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBE...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() dp = [[(0) for j in range(27)] for i in range(26)] for i in s: curr = ord(i) - ord("a") for j in range(26): dp[j][curr] += dp[j][26] dp[curr][26] += 1 ans = 0 for i in dp: for j in i: ans = max(ans, j) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR ...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
def main(): s = input() countFor1Letters = [0] * 26 countFor2Letters = [[(0) for x in range(26)] for j in range(26)] for i in range(len(s)): ind_i = ord(s[i]) - ord("a") for j in range(26): countFor2Letters[j][ind_i] += countFor1Letters[j] countFor1Letters[ind_i] += 1...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBE...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
import sys a = ord("a") s = input().strip() n = len(s) dp1 = [[(0) for _ in range(26)] for _ in range(26)] dp2 = [0] * 26 for i in range(n): c = ord(s[i]) - a for j in range(26): dp1[j][c] += dp2[j] dp2[c] += 1 ans = max(dp2) for i in dp1: ans = max(ans, max(i)) print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR V...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
alpha = list(map(chr, [(ord("a") + i) for i in range(26)])) def solve(s): cnt1 = {c: (0) for c in alpha} cnt2 = {(c1 + c2): (0) for c1 in alpha for c2 in alpha} for c in s: for a in alpha: cnt2[a + c] += cnt1[a] cnt1[c] += 1 return max(max(cnt1.values()), max(cnt2.values())...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR FOR VAR VAR FOR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUN...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() mam = 0 for i in range(0, 26): ch = chr(i + 97) a = [0] * 26 maxi = 0 k = 0 ma = 0 for i in range(0, len(s)): if s[i] == ch: a[ord(s[i]) - 97] = a[ord(s[i]) - 97] + 1 * k k = k + 1 elif k > 0: a[ord(s[i]) - 97] = a[ord(s[i]) - 97] +...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBE...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
import sys def upper_bound(arr, index): l = 0 r = len(arr) while r - l > 1: mid = (r + l) // 2 if arr[mid] == index: l = mid break if arr[mid] < index: l = mid else: r = mid while l < len(arr) and arr[l] <= index: ...
IMPORT 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 VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() pos = [0] * 26 ptr = [] for i in range(26): ee = [] ptr.append(ee) for i in range(0, len(s)): pos[ord(s[i]) - 97] += 1 ptr[ord(s[i]) - 97].append(i) ans = max(pos) pre = [] p = [0] * 26 for i in range(len(s) - 1, -1, -1): h = [] for j in range(0, 26): h.append(p[j]) pre.a...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL ...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
import sys input = lambda: sys.stdin.readline().rstrip() ans = [0] * 26 a = [(ord(i) - 97) for i in input()] cnt = [0] * 26 maxx = [0] * 26 ans = [0] * 26 for i in a: cnt[i] += 1 for i in range(len(ans)): z = cnt[i] * (cnt[i] + 1) // 2 - cnt[i] for j in range(len(a) - 1, -1, -1): if a[j] == i: ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR AS...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() n = len(s) dp = [[(0) for i in range(26)] for j in range(n)] table = [[(0) for i in range(26)] for j in range(26)] dp[n - 1][ord(s[n - 1]) - ord("a")] = 1 for i in range(n - 2, -1, -1): for j in range(26): dp[i][j] = dp[i + 1][j] table[ord(s[i]) - ord("a")][j] = table[ord(s[i]) - ord("a"...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR ...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() dp2 = [([0] * 26) for i in range(26)] dp1 = [0] * 26 def ind(c: str): return ord(c) - ord("a") n = len(s) ans = 0 for i in range(len(s)): ch = s[i] for j in range(26): dp2[j][ind(ch)] += dp1[j] dp1[ind(ch)] += 1 ans = max(dp1) for i in dp2: for j in i: ans = max(ans, ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NU...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
def solve(S): S = [(ord(ch) - ord("a")) for ch in S] counts = [0] * 26 pairs = [([0] * 26) for i in range(26)] for c in S: for j in range(26): pairs[c][j] += counts[j] counts[c] += 1 best = max(counts) for i in range(26): for j in range(26): best =...
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() ans = [0] * 26 for i in range(26): ans[i] = [0] * 26 now = [0] * 26 for i in range(len(s)): n = ord(s[i]) - ord("a") for j in range(26): ans[n][j] += now[j] now[n] += 1 anss = max(now) for i in range(26): for j in range(26): anss = max(anss, ans[i][j]) print(anss)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR 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 FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR V...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
S = input() N = len(S) Count = [0] * 26 New = [0] * 675 Ans = 0 for i in range(N): start = ord(S[i]) - 97 for j in range(start, start + 26 * 25, 26): New[j] += Count[int(j // 26)] Count[start] += 1 X = max(Count) P = X * (X - 1) >> 1 print(max(P, max(New), X))
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() ch = {} c = 0 var = [] ans = 0 for i in range(len(s)): if s[i] in ch: ch[s[i]] += 1 else: ch[s[i]] = 1 var.append(s[i]) PAIR = {} for i in var: ans = max(ans, ch[i]) for j in var: PAIR[i, j] = 0 for i in range(len(s)): ch[s[i]] -= 1 for j in var: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR NUMB...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() d1 = dict() d2 = dict() for c in s: for key in d1: if key + c in d2: d2[key + c] += d1[key] else: d2[key + c] = d1[key] if c in d1: d1[c] += 1 else: d1[c] = 1 ans = 0 for key in d1: ans = max(ans, d1[key]) for key in d2: ans = max(a...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR ...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() n = len(s) d = {} letters = "abcdefghijklmnopqrstuvwxyz" letters_len = len(letters) letter_idx = {} for i in range(len(letters)): letter_idx[letters[i]] = i suffix = [] * n for i in range(n): suffix.append([0] * letters_len) for j in range(letters_len): suffix[n - 1][j] = 0 for i in range(n - 2,...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASS...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
import sys input = lambda: sys.stdin.readline().strip() s = list(input()) if len(s) == len(set(s)): print(1) exit(0) lol = {} for i in range(len(s)): if s[i] in lol: lol[s[i]].append(i) else: lol[s[i]] = [i] su = list(set(s)) m = 0 def bin(x, a): l = -1 r = len(lol[a]) whi...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSI...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
def binsearch(a, x): if len(a) == 0: return 0 if len(a) == 1: if a[0] > x: return 1 else: return 0 i = 0 j = len(a) - 1 while i < j: if x < a[i]: return len(a) - i if x > a[j]: return len(a) - j - 1 mid =...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSI...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() d = {} l = [] m = 1 for i in s: if i not in d: l.append(i) d[i] = 1 else: d[i] += 1 if d[i] > m: m = d[i] ans = m a = m * (m - 1) a >>= 1 if a > ans: ans = a for i in l: for j in l: if i != j: x = 0 t = 0 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR A...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
import sys input = sys.stdin.readline mii = lambda: map(int, input().split()) s = input().strip() d = [0] * 1000 e = [0] * 1000 hist = [0] * 26 for i in s: j = ord(i) - ord("a") for k in range(26): e[k * 26 + j] += hist[k] hist[j] += 1 d[j] += 1 print(max(d + e))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER V...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
import sys def fast_input(): return sys.stdin.readline().strip() def data_input(): return [int(x) for x in fast_input().split()] def binary_search(array, x): left, right = -1, len(array) while left + 1 != right: middle = (left + right) // 2 if array[middle] >= x: right ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DIC...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
d = {} s = {0} for x in input(): for y in s: d[x, y] = d.get((x, y), 0) + d.get(y, 0) s |= {x} d[x] = d.get(x, 0) + 1 print(max(d.values()))
ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
def log(substr, dct, count=1): if substr in dct.keys(): dct[substr] += count else: dct[substr] = count string = input() strlen = len(string) len1 = {} len2 = {} for n, c in enumerate(string): for c1, count in len1.items(): word = c1 + c log(word, len2, count) log(c, len...
FUNC_DEF NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CAL...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
a = [0] * 5**6 for x in map(ord, input()): for y in range(123): a[123 * x + y] += a[y] a[x] += 1 print(max(a))
ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
single = {} double = {} string = input() for i in string: for j in single: x = j + i double[x] = double.get(x, 0) + single[j] single[i] = single.get(i, 0) + 1 max1 = -float("Inf") for i in double: max1 = max(double[i], max1) for i in single: max1 = max(single[i], max1) print(max1)
ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR ...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = str(input()) count, ans = [0] * 26, 0 count2 = [0] * 26 dp = [([0] * 26) for i in range(26)] for i in range(len(s)): count[ord(s[i]) - 97] += 1 ans = max(ans, count[ord(s[i]) - 97]) if i < len(s) - 1: for i2 in range(26): dp[i2][ord(s[i + 1]) - 97] += count[i2] if dp[i2][...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CA...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() alp = "abcdefghijklmnopqrstuvwxyz" dic = {} for i in range(26): dic[alp[i]] = i lis = [0] * 26 ans = [([0] * 26) for i in range(26)] maxi = 0 for i in s: num = dic[i] for i in range(26): ans[i][num] += lis[i] maxi = max(maxi, ans[i][num]) lis[num] += 1 maxi = max(maxi, li...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR F...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = str(input()) a = len(s) matrix = [([0] * a) for i in range(26)] lis = [0] * 26 for i in range(a): for j in range(26): matrix[j][a - i - 1] = lis[j] lis[ord(s[a - i - 1]) - 97] += 1 matrix1 = [([0] * 26) for i in range(26)] for i in range(a): for j in range(26): matrix1[ord(s[i]) - 97][j]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VA...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
c1 = [0] * 30 c2 = [([0] * 30) for _ in range(30)] s = input() for ch in s: j = ord(ch) - ord("a") for i in range(26): c2[i][j] += c1[i] c1[j] += 1 ans = 0 for i in range(26): ans = max(ans, c1[i]) for i in range(26): for j in range(26): ans = max(ans, c2[i][j]) print(ans)
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
alph = "abcdefghijklmnopqrstuvwxyz" def to_arr(s): a = [] for i in range(len(s)): a.append(alph.index(s[i])) return a s = to_arr(input()) n = len(s) a = [([0] * 26) for i in range(n)] a[0][s[0]] = 1 ans = 0 for i in range(1, n): a[i][s[i]] = 1 for j in range(26): a[i][j] += a[i -...
ASSIGN VAR STRING FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR ...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
import sys s = input() n = len(s) d = dict() k = 26 count1 = [0] * k count2 = [([0] * k) for i in range(k)] for i in range(n): e = ord(s[i]) - ord("a") for j in range(k): count2[j][e] += count1[j] count1[e] += 1 answer = max(count1) for i in range(k): answer = max(answer, max(count2[i])) print(...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR V...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() ard = {} ard[s[0]] = 1 pair_max = 0 pairs = {} for i, c in enumerate(s[1:], 1): for letter in ard.keys(): temp = letter + c pairs[temp] = pairs.get(temp, 0) + ard[letter] if pairs[temp] > pair_max: pair_max = pairs[temp] ard[c] = ard.get(c, 0) + 1 print(max(list(a...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
one, two = {}, {} for c in input(): for pc in one.keys(): if pc + c in two: two[pc + c] += one[pc] else: two[pc + c] = one[pc] one[c] = one[c] + 1 if c in one else 1 print(max(max(two.values(), default=0), max(one.values(), default=0)))
ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() oda = ord("a") a = [(ord(s[i]) - oda) for i in range(len(s))] c = [0] * 26 for i in a: c[i] += 1 ans = max(c) r = [0] * 26**2 c = [0] * 26 for i in range(len(a)): for j in range(26): r[a[i] * 26 + j] += c[j] c[a[i]] += 1 ans = max(ans, max(r)) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FO...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() pref = [([0] * len(s)) for _ in range(26)] pref[ord(s[0]) - ord("a")][0] += 1 ans = [0] * (26 * 26) cnt = [0] * 26 cnt[ord(s[0]) - ord("a")] += 1 for i in range(1, len(s)): code = ord(s[i]) - ord("a") cnt[code] += 1 for c in range(26): ans[c * 26 + code] += pref[c][i - 1] pref[c]...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING NUMBER...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
st = input() x = "abcdefghijklmnopqrstuvwxyz" dic = {} for i in x: dic[i] = 0 main = {} for i in x: for j in x: main[i + j] = 0 for xx in st: for jj in dic: main[jj + xx] += dic[jj] dic[xx] += 1 x1 = max(list(main.values())) x2 = max(list(dic.values())) print(max(x1, x2))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR VAR FOR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL ...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() se = set() d = {} d2 = {} for i in range(len(s)): se.add(s[i]) if s[i] not in d: d[s[i]] = {(0): -1} d2[s[i]] = 0 d2[s[i]] += 1 d[s[i]][d2[s[i]]] = i se = list(se) ans = 1 for i in range(len(se)): for j in range(len(se)): a = se[i] b = se[j] ta = 0...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR DICT NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VA...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() cnt = [(0) for _ in range(26)] for i in s: cnt[ord(i) - ord("a")] += 1 ans = max(cnt) cntt = [[(0) for _ in range(26)] for _ in range(26)] for i in s: cnt[ord(i) - ord("a")] -= 1 for j in range(26): cntt[ord(i) - ord("a")][j] += cnt[j] for i in range(26): for j in range(26): ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
arr = list(input()) n = len(arr) sufmax = [] for i in range(26): sufmax.append([0] * n) sums = [0] * 26 for g in range(n - 1, -1, -1): sums[ord(arr[g]) - 97] += 1 for i in range(26): sufmax[i][g] = sums[i] ams = [] for i in range(26): ams.append([0] * 26) for i in range(n - 1): for g in rang...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBE...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
dp = {} for c in input(): num = ord(c) - ord("a") + 1 for prev in range(1, 27): if prev in dp: dp[prev * 26 + num] = dp.get(prev * 26 + num, 0) + dp.get(prev) dp[num] = dp.get(num, 0) + 1 print(max(dp.values()))
ASSIGN VAR DICT FOR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NU...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
from sys import exit def iis(): return map(int, input().split()) def ii(): return int(input()) def liis(): return list(map(int, input().split())) s = input() todos = {} for i in range(len(s)): if s[i] not in todos: todos[s[i]] = 0 todos[s[i]] += 1 ans = 1 maxi1 = 1 maxi2 = 1 maxi1c =...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIG...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = list(input()) s = [(ord(i) - 97) for i in s] co = [[(0) for i in range(26)] for j in range(26)] pre = [(0) for i in range(26)] pre[s[0]] = 1 for i in range(1, len(s)): for j in range(26): co[s[i]][j] += pre[j] pre[s[i]] += 1 print(max(max([max(i) for i in co]), max(pre)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VA...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
from sys import stdin s = stdin.readline().strip() cnt = [[] for i in range(26)] n = len(s) for i in range(n): cnt[ord(s[i]) - 97].append(i) ans = 0 def search(e, g): best = -1 l = 0 r = len(cnt[g]) - 1 while l <= r: m = (l + r) // 2 if cnt[g][m] > e: r = m - 1 ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR ASSIGN...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() sto = {} z = [0] * 26 for i in range(len(s)): if s[i] not in sto: sto[s[i]] = 0 sto[s[i]] += 1 for j in range(0, 26): comb = chr(j + ord("a")) + s[i] if comb not in sto: sto[comb] = 0 sto[comb] += z[j] z[ord(s[i]) - ord("a")] += 1 print(max(sto.val...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER V...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
a = [0] * 5**6 s = (*map(ord, input()),) t = {*s} for x in s: for y in t: a[123 * x + y] += a[y] a[x] += 1 print(max(a))
ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR VAR FOR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() c = [0] * 26 cc = [([0] * 26) for _ in range(26)] a = ord("a") for _ in range(len(s)): c[ord(s[_]) - a] += 1 m = max(c) for _ in range(len(s)): c[ord(s[_]) - a] -= 1 for i in range(26): cc[ord(s[_]) - a][i] += c[i] m = max(cc[ord(s[_]) - a][i], m) print(m)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP ...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
import sys s = sys.stdin.readline().rstrip() cnt = {} re = 0 for i in s: if i not in cnt: cnt[i] = 1 else: cnt[i] += 1 if re < cnt[i]: re = cnt[i] if re < int(re * (re - 1) / 2): re = int(re * (re - 1) / 2) chk = {} cnt = {} tar = [] for i in range(len(s)): idx = len(s) - i ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR DICT AS...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
import sys input = sys.stdin.readline s = input() vals = {} for l in s: if l in vals: vals[l] = vals[l] + 1 elif l != "\n": vals[l] = 1 nums = [] max1 = 1 for g in vals: if vals[g] > max1: max1 = vals[g] for j in vals: if vals[j] > 1: nums.append(j) ans = max1 for o in n...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR F...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() a = [0] * 26 for x in s: a[ord(x) - 97] += 1 maxa = max(a) ans = max((maxa - 1) * maxa // 2, maxa) for i in range(97, 123): for j in range(97, 123): if j != i: ni = 0 tans = 0 for x in s: if ord(x) == i: ni += 1 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER A...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
def solve(): s = input() l = len(s) li1 = [] for i in range(30): ltemp = [] for j in range(30): ltemp.append(0) li1.append(ltemp) li3 = [] for i in range(30): li3.append(0) li3[ord(s[0]) - ord("a")] = 1 for i in range(1, l): for j in ra...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() letters = "abcdefghijklmnopqrstuvwxyz" mx = 0 for c in letters: mx = max(mx, s.count(c)) freq = {} for let in letters: freq[let] = 0 dp = {} for c1 in letters: for c2 in letters: dp[c1, c2] = 0 for c in s: for let in letters: dp[c, let] += freq[let] freq[c] += 1 for c1 in...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR FOR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR VAR FOR VAR VAR A...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() arr = [0] * 26 Max = -1 Dict = {} for i in range(len(s)): A = ord(s[i]) - ord("a") for j in range(26): seq = str(chr(j + 97)) + s[i] if Dict.get(seq) == None: Dict[seq] = arr[j] else: Dict[seq] = arr[j] + Dict[seq] Max = max(Max, Dict[seq]) ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR N...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() mp = {(1): 0} cnt = {(1): 0} for i in range(0, 26): for j in range(0, 26): mp[chr(i + ord("a")) + chr(j + ord("a"))] = 0 for i in range(0, 26): cnt[chr(i + ord("a"))] = 0 ans = 0 for i in s: for j in range(0, 26): c = chr(j + ord("a")) mp[i + c] += cnt[c] if mp[i ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
def msg_len(s): cnt_chars = {} cnts = {} for c1 in s: cnt_chars[c1] = cnt_chars.get(c1, 0) + 1 max_single = max(cnt_chars.values()) for c in s: cnt_chars[c] -= 1 for c2, cnt in cnt_chars.items(): cnts[c + c2] = cnts.get(c + c2, 0) + cnt return max(max_single, ...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = str(input()) d = {"": 1} d2 = {} for i in range(len(s)): for k, v in d.items(): temp = k + s[i] if temp not in d2: d2[temp] = v else: d2[temp] += v if s[i] not in d: d[s[i]] = 1 else: d[s[i]] += 1 print(max(d2.values()))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
d = {} s = set() for x in input(): for y in s: d[x, y] = d.get((x, y), 0) + d[y] s |= {x} d[x] = d.get(x, 0) + 1 print(max(d.values())) num_inp = lambda: int(input()) arr_inp = lambda: list(map(int, input().split())) sp_inp = lambda: map(int, input().split()) str_inp = lambda: input()
ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = [s for s in input()] d = {} for i in s: d[i] = [0] for i in range(len(s)): for j in d.keys(): if j == s[i]: d[j].append(d[j][len(d[j]) - 1] + 1) else: d[j].append(d[j][len(d[j]) - 1]) ans = {} for i in range(len(s)): l = s[i] id = i + 1 try: ans[l]...
ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN ...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
s = input() count = [0] * 26 for i in s: count[ord(i) - 97] += 1 ans = max(count) for i in range(26): letter = chr(i + 97) l = [0] * 26 cnt = 0 for k in s: if k == letter: cnt += 1 else: l[ord(k) - 97] += cnt ans = max(ans, max(l)) for num in count: an...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP FU...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
import sys def metod1(z, a): l = -1 r = len(clovar[a]) while r > 1 + l: answer = (r + l) // 2 if clovar[a][answer] <= z: l = answer else: r = answer return r def metod(b, a): x, h = 0, 0 d = a == b l = len(clovar[a]) for i in clovar[b]:...
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CAL...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
def solve(s): A = 26 ans = -float("INF") count = [0] * A count_pair = [([0] * A) for _ in range(A)] for i in s: c = ord(i) - ord("a") for j in range(A): if count[j] != 0: count_pair[j][c] += count[j] ans = max(ans, count_pair[j][c]) ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR V...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
import sys LI = lambda: list(map(int, sys.stdin.readline().split())) MI = lambda: map(int, sys.stdin.readline().split()) SI = lambda: sys.stdin.readline().strip("\n") II = lambda: int(sys.stdin.readline()) num = [[(0) for i in range(26)] for j in range(26)] cnt = {} ans = 0 for c in SI()[::-1]: v = ord(c) - ord("a...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FU...
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an ari...
def ii(): return int(input()) def ai(): return list(map(int, input().split())) def mi(): return map(int, input().split()) s = input() freq = [(0) for i in range(26)] sub_string = [[(0) for i in range(26)] for j in range(26)] for i in range(len(s)): c = ord(s[i]) - 97 for j in range(26): ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FU...
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n. Example: Input: 13 Output: 6 Explanation: Digit 1 occurred in the following numbers: 1, 10, 11, 12, 13.
class Solution: def countDigitOne(self, n): if n <= 0: return 0 i = 0 while pow(10, i) <= n: i += 1 if i == 1: return 1 s = n % pow(10, i - 1) temp = self.countDigitOne(s) t = n // pow(10, i - 1) if t > 1: ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_...
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n. Example: Input: 13 Output: 6 Explanation: Digit 1 occurred in the following numbers: 1, 10, 11, 12, 13.
class Solution: def countDigitOne(self, n): if n <= 0: return 0 q, x, ans = n, 1, 0 while q > 0: digit = q % 10 q = q // 10 ans += q * x if digit == 1: ans += n % x + 1 elif digit > 1: an...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER RETURN VAR
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n. Example: Input: 13 Output: 6 Explanation: Digit 1 occurred in the following numbers: 1, 10, 11, 12, 13.
class Solution: def countDigitOne(self, n): if n <= 0: return 0 one, m = 0, 1 while m <= n: one += (n // m + 8) // 10 * m + (n // m % 10 == 1) * (n % m + 1) m *= 10 return one
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n. Example: Input: 13 Output: 6 Explanation: Digit 1 occurred in the following numbers: 1, 10, 11, 12, 13.
class Solution: def countDigitOne(self, n): if n <= 0: return 0 counts, length, digits = 0, len(str(n)), [int(i) for i in str(n)] counts = ( digits[0] * (length - 1) * 10 ** (length - 2) + min(digits[0] - 1, 1) * 10 ** (length - 1) + max(2 - d...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP NUMBER B...
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n. Example: Input: 13 Output: 6 Explanation: Digit 1 occurred in the following numbers: 1, 10, 11, 12, 13.
class Solution: def countDigitOne(self, n): ones, wei = 0, 1 while wei <= n: m = int(n / wei) % 10 if m > 1: ones += (int(n / wei / 10) + 1) * wei elif m == 1: ones += int(n / wei / 10) * wei + n % wei + 1 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR IF VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP...
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
s = input().strip() n = len(s) dp = [[0, 0, 0] for _ in range(n)] for i in range(n): if s[i] == "a": dp[i][0] = 1 for j in range(i): dp[i][0] = max(dp[i][0], dp[j][0] + 1) dp[i][1] = dp[i][0] dp[i][2] = 1 for j in range(i): dp[i][2] = max(dp[i][2], dp[...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUM...
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
s = input() dp = [[0, 0, 0] for k in range(len(s))] if s[0] == "a": dp[0][0] = 1 dp[0][1] = 1 dp[0][2] = 1 elif s[0] == "b": dp[0][1] = 1 dp[0][2] = 1 for pro in range(1, len(s)): if s[pro] == "a": dp[pro][0] = dp[pro - 1][0] + 1 dp[pro][1] = max(dp[pro - 1][1], dp[pro - 1][0] + ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VA...
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
s = input() a, ab, aba = 0, 0, 0 for i in s: if i == "a": a += 1 aba = max(ab, aba) + 1 else: ab = max(a, ab) + 1 print(max(aba, ab, a))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
a = input() n = len(a) b = 0 c = 0 d = [0] e = [0] for i in range(len(a)): if a[i] == "a": b = b + 1 elif a[i] == "b": c = c + 1 d.append(b) e.append(c) f = [] for i in range(n + 1): for j in range(i, n + 1): f.append(d[i] + e[j] - e[i] + d[n] - d[j]) print(max(f))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSI...
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
s = input() x1 = 0 x2 = 0 x3 = 0 for i in range(len(s)): if s[i] == "a": x3 = max(x2, x3) + 1 x1 += 1 else: x2 = max(x1, x2) + 1 x4 = max(x1, x2) x5 = max(x3, x4) print(x5)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CA...
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
s = input() dp = [[0, 0, 0] for i in range(len(s))] for i in range(len(s)): if s[i] == "a": dp[i][0] = dp[i - 1][0] + 1 dp[i][1] = dp[i - 1][1] dp[i][2] = max(dp[i - 1][1] + 1, dp[i - 1][2] + 1) else: dp[i][0] = dp[i - 1][0] dp[i][1] = max(dp[i - 1][0] + 1, dp[i - 1][1] +...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR B...
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
string = input() prefix___a_nr = [0] prefix___b_nr = [0] for sym in string: curr_a_nr = prefix___a_nr[-1] curr_b_nr = prefix___b_nr[-1] if sym == "a": curr_a_nr += 1 elif sym == "b": curr_b_nr += 1 prefix___a_nr.append(curr_a_nr) prefix___b_nr.append(curr_b_nr) ans = 5000 for sep...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR...
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
strs = input() array = [] char = [] count = 1 char.append(strs[0]) i = 1 while i < len(strs): if strs[i] == strs[i - 1]: count += 1 else: array.append(count) char.append(strs[i]) count = 1 i += 1 array.append(count) bback = [] aback = [] bfront = [] afront = [] i = 0 while i ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN ...
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
s = input() n = len(s) counta = [0] * (n + 1) countb = [0] * (n + 1) ans = 0 curra = 0 currb = 0 for i in range(n): if s[i] == "a": curra += 1 else: currb += 1 counta[i + 1] = curra countb[i + 1] = currb for i in range(n + 1): for j in range(i, n + 1): ans = max(ans, countb[j...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP...
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
s = input() acnt = [] cnt = 0 for i in range(len(s)): if s[i] == "a": cnt += 1 acnt.append(cnt) suma = acnt[len(acnt) - 1] ans = suma for i in range(len(s)): bcnt = 0 ac = 0 temp = 0 for j in range(i, len(s)): if s[j] == "b": bcnt += 1 if s[j] == "a": ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_...
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
s = input() n = len(s) a = [0] b = [0] for x in s: if x == "a": a.append(a[-1] + 1) b.append(b[-1]) else: a.append(a[-1]) b.append(b[-1] + 1) ans = 0 a.append(a[-1]) b.append(b[-1]) for i in range(1, n + 1): for j in range(i, n + 1): t = a[i] + b[j + 1] - b[i - 1] + a...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBE...