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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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:
cnt += 1
if ord(str) - ord("a") == j:
res += cnt
ans = max(ans, res)
else:
res = 0
cnt = 0
for str in s:
if ord(str) - ord("a") == j:
res += cnt
if ord(str) - ord("a") == i:
cnt += 1
ans = max(ans, res)
print(ans) | 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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(alphabet[i])
print(max(max(alphabet), max(currSeen))) | 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 VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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]) for i in range(26)]
print(max(max(r), max(l))) | 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 VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 VAR FUNC_CALL VAR VAR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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[ord(s[i]) - ord("a")] += 1
maxi = 0
for i in dp2:
maxi = max(max(i), maxi)
print(max(max(dp1), maxi)) | 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 NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 in range(26):
for j in range(len(a)):
b[i][j] += b[i][j - 1]
s = max(s, b[i][j])
for i in range(26):
for j in range(len(a), -1, -1):
d[i][j] += d[i][j + 1]
s = max(s, d[i][j])
for i in range(26):
for j in range(26):
r = 0
for k in range(len(a)):
x = ord(a[k]) - ord("a")
if x == i:
r = r + d[j][k + 1]
s = max(r, s)
print(s) | 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 NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL 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 VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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]:
lookup[i][j] = lookup[i - 1][j - 1] + lookup[i - 1][j]
else:
lookup[i][j] = lookup[i - 1][j]
return lookup[m][n]
word = input()
arr = [(0) for i in range(26)]
mat = [[(0) for i in range(26)] for j in range(26)]
for i in range(len(word)):
for j in range(26):
mat[j][ord(word[i]) - 97] += arr[j]
arr[ord(word[i]) - 97] += 1
m = -1
for i in arr:
m = max(m, i)
for i in mat:
for j in i:
m = max(m, j)
print(m) | 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 NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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
else:
new = [j for j in dp[i + 1]]
new[ord(s[i]) - ord("a")] = new[ord(s[i]) - ord("a")] + 1
dp[i] = new
new = [[(0) for i in range(26)] for j in range(26)]
for i in range(len(s)):
for j in range(26):
if ord(s[i]) - ord("a") != j:
new[ord(s[i]) - ord("a")][j] = new[ord(s[i]) - ord("a")][j] + dp[i][j]
else:
new[ord(s[i]) - ord("a")][j] = new[ord(s[i]) - ord("a")][j] + dp[i][j] - 1
maxlen = 0
for i in range(26):
for j in range(26):
maxlen = max(maxlen, new[i][j])
d = {}
for i in s:
if i in d:
d[i] = d[i] + 1
else:
d[i] = 1
for i in d:
maxlen = max(maxlen, d[i])
print(maxlen) | 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 NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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):
lol[j] += kek[j]
an = max(an, max(lol))
print(an)
main() | 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 FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 = max(oans, arr[n + 1][i])
for i in range(26):
for j in range(26):
for k in range(1, n):
if chr(97 + i) != s[k - 1]:
continue
ans[i][j] += arr[n + 1][j] - arr[k][j]
fans = 1
for i in range(26):
for j in range(26):
fans = max(fans, ans[i][j])
print(max(fans, oans)) | 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 VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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(ans, j)
print(ans) | 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 FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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) - 97][ord(i) - 97] += dict[j]
dict[i] = 1
for i in range(26):
for j in range(26):
max1 = max(max1, lst[i][j])
max2 = max(dict.values())
return max(max1, max2)
print(checker(input())) | 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 FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 VAR VAR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 max_occurrences
def occurrences(string, pair):
count = 0
total = 0
for letter in string:
if letter == pair[0]:
count += 1
elif letter == pair[1]:
total += count
return total
def _occurrences(string, char):
count = 0
for letter in string:
if letter == char:
count += 1
if count in (1, 2):
return count
return (count - 1) * count // 2
s = input()
print(find_best_pair(s)) | 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 NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER NUMBER RETURN VAR RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 Alp:
for b in Alp:
ans = max(ans, ansdic[a][b])
ans = max(ans, dic[a])
print(ans) | 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 ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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_CALL VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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]:
last += 1
total += first
first += 1
elif sym == pair[0]:
first += 1
elif sym == pair[1]:
last += 1
total += first
ans = total if ans < total else ans
for sym in one_symbol:
ans = one_symbol[sym] if ans < one_symbol[sym] else ans
print(ans) | 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 NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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
ans = 0
for i in countFor2Letters:
if max(i) > ans:
ans = max(i)
print(max(max(countFor1Letters), ans))
main() | 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 NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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()))
s = input().strip()
print(solve(s)) | 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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] + 1 * k
maxi = max(a)
ma = max(k, maxi)
mam = max(ma, mam)
print(mam) | 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 NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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:
l += 1
return l
def cal(char, second_char, chars):
if char == second_char:
l = len(chars[char])
return l * (l - 1) / 2
sum = 0
first_char_indices = chars[char]
second_char_indices = chars[second_char]
for indice in first_char_indices:
upb = upper_bound(second_char_indices, indice)
if upb < len(second_char_indices):
sum += len(second_char_indices) - upb
return sum
def solve():
s = sys.stdin.readline().strip()
chars = dict()
n = len(s)
mx = 0
for index, char in enumerate(s):
count = chars.get(char)
if count == None:
count = chars[char] = []
count.append(index)
for char, indices in chars.items():
mx = max(mx, len(indices))
for second_char in chars.keys():
mx = max(mx, cal(char, second_char, chars))
print(int(mx))
solve() | 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 RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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.append(h)
p[ord(s[i]) - 97] += 1
pre = pre[::-1]
for i in range(0, 26):
for j in range(0, 26):
ch1 = chr(i + 97)
ch2 = chr(j + 97)
c = 0
for k in range(0, len(ptr[i])):
c = c + pre[ptr[i][k]][j]
ans = max(ans, c)
print(ans) | 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 VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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:
ans[a[j]] += 1
cnt[i] -= 1
else:
ans[a[j]] += cnt[i]
maxx[i] = max(max(ans), z)
ans = [0] * 26
print(max(maxx)) | 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 ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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")][j] + dp[i][j]
dp[i][ord(s[i]) - ord("a")] = dp[i][ord(s[i]) - ord("a")] + 1
m = 0
for i in range(26):
m = max(m, max(table[i]))
d = {}
for i in s:
if i not in d:
d[i] = 1
else:
d[i] = d[i] + 1
for i in d:
m = max(m, d[i])
print(m) | 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 NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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, j)
print(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 NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 = max(best, pairs[i][j])
return best
S = input()
ans = solve(S)
print(ans) | 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_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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:
PAIR[s[i], j] += ch[j]
ans = max(ans, PAIR[s[i], j])
print(ans) | 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 NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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(ans, d2[key])
print(ans) | 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 FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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, -1, -1):
cur = s[i + 1]
for j in range(letters_len):
suffix[i][j] = suffix[i + 1][j]
suffix[i][letter_idx[cur]] += 1
for i in range(n):
sub = s[i]
if sub in d:
d[sub] += 1
else:
d[sub] = 1
for j in letters:
sub = s[i] + j
if sub in d:
d[sub] += suffix[i][letter_idx[j]]
else:
d[sub] = suffix[i][letter_idx[j]]
ans = 0
for v in d.values():
ans = max(ans, v)
print(ans) | 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 ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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])
while r - l > 1:
m = (r + l) // 2
if lol[a][m] <= x:
l = m
else:
r = m
return r
def f(b, a):
ans = 0
ans1 = 0
d = int(a == b)
l = len(lol[a])
for i in lol[b]:
x = bin(i, a)
ans1 += x - d
ans += l - x
return max(ans1, ans)
for i in range(len(su)):
for j in su[i:]:
if len(lol[j]) * len(lol[su[i]]) > m:
m = max(m, f(su[i], j), len(lol[j]), len(lol[su[i]]))
print(m) | 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 = int((i + j) / 2)
if mid == i:
return len(a) - i - 1
if mid == j:
return len(a) - j
if x > a[mid]:
i = mid
else:
j = mid
return len(a) - 1 - i
s = input()
f = []
for i in range(26):
f.append([])
for i in range(len(s)):
f[ord(s[i]) - ord("a")].append(i)
ans = []
for i in range(26):
tm = 0
for j in range(26):
tm = 0
l = len(f[i])
if i == j and l > 1:
ans.append(int(l * (l - 1) / 2))
elif len(f[j]) > 0 and len(f[i]) > 0:
for k in f[j]:
tm = tm + binsearch(f[i], k)
if tm > 0:
ans.append(tm)
if len(f[i]) > 0:
ans.append(len(f[i]))
ans.sort()
print(ans[-1]) | 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 ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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
for k in s:
if k == i:
t += 1
if k == j:
x += t
if x > ans:
ans = x
print(ans) | 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR ASSIGN 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 = middle
elif array[middle] < x:
left = middle
return right
def solve_of_problem():
alp = {}
alp_2 = {}
for i in range(26):
alp[chr(i + 97)] = 0
for i in range(26):
for j in range(26):
alp_2[chr(i + 97) + chr(j + 97)] = 0
st = fast_input()
for i in range(len(st)):
for j in range(26):
alp_2[chr(97 + j) + st[i]] += alp[chr(97 + j)]
alp[st[i]] += 1
print(max(max(alp.values()), max(alp_2.values())))
return
for ______ in range(1):
solve_of_problem() | 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 DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR NUMBER EXPR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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, len1)
candidates = list(len1.values()) + list(len2.values())
print(max(candidates)) | 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_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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][ord(s[i + 1]) - 97] > ans:
ans = dp[i2][ord(s[i + 1]) - 97]
print(ans) | 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_CALL VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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, lis[num])
print(maxi) | 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 FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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] += matrix[j][i]
ans = max(lis)
for i in range(26):
temp = max(matrix1[i])
ans = max(ans, temp)
print(ans) | 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 VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 - 1][j]
for i in range(26):
ans = max(ans, a[-1][i])
b = [([0] * 26) for i in range(26)]
for i in range(1, n):
for j in range(26):
b[j][s[i]] += a[i - 1][j]
for i in range(26):
for j in range(26):
ans = max(ans, b[i][j])
print(ans) | 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 VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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(answer) | 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 VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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(ard.values()) + [pair_max])) | 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 VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR LIST 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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][i] = pref[c][i - 1]
pref[code][i] += 1
print(max(max(cnt), max(ans))) | 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 FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 VAR FUNC_CALL VAR EXPR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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
if a == b:
ta = (d2[a] - 1) * d2[a] // 2
else:
for i2 in d[a].values():
if i2 >= 0:
lb = 0
ub = len(d[b]) - 1
while lb + 1 < ub:
tt = (ub + lb) // 2
tc = (ub - lb) // 2
if d[b][tt] >= i2:
ub -= tc
else:
lb += tc
tt = (ub + lb) // 2
for z in range(2):
if tt < len(d[b]) - 1 and d[b][tt + 1] < i2:
tt += 1
elif tt > 0 and d[b][tt] > i2:
tt -= 1
ta += d2[b] - tt
ans = max(ta, ans)
dm = max(d2.values())
print(max(ans, dm)) | 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 VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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):
ans = max(ans, cntt[i][j])
print(ans) | 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 VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 range(26):
ams[ord(arr[i]) - 97][g] += sufmax[g][i + 1]
m = 0
for i in range(26):
m = max(m, max(ams[i]))
c = [0] * 26
for i in range(n):
c[ord(arr[i]) - 97] += 1
print(max(m, max(c))) | 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 NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 = s[0]
for k in todos:
if todos[k] > maxi1:
maxi1 = todos[k]
maxi1c = k
def ans(s, c, d, n):
at = 0
ret = 0
for i in s:
if i == d:
ret += at
if i == c:
at += 1
return ret
a = []
answ = 0
for i in todos:
a.append([todos[i], i])
answ = max(answ, todos[i])
for i in range(len(a)):
for j in range(len(a)):
answ = max(answ, ans(s, a[i][1], a[j][1], a[j][0]))
print(answ) | 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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
best = m
else:
l = m + 1
return best
for i in range(26):
if len(cnt[i]) == 0:
continue
for j in range(26):
if len(cnt[j]) == 0:
continue
total = 0
for k in cnt[i]:
get = search(k, j)
total += len(cnt[j]) - get if get >= 0 else 0
ans = max(ans, total)
for i in range(26):
ans = max(ans, len(cnt[i]))
print(ans) | 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 VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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.values())) | 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 VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 - 1
if idx == len(s) - 1:
cnt[s[idx]] = 1
if cnt[s[idx]] == 1:
tar.append(s[idx])
continue
for j in tar:
if cnt[j] == 0 or s[idx] == j:
continue
if s[idx] + j not in chk:
chk[s[idx] + j] = cnt[j]
else:
chk[s[idx] + j] += cnt[j]
if chk[s[idx] + j] > re:
re = chk[s[idx] + j]
if s[idx] not in cnt:
cnt[s[idx]] = 1
else:
cnt[s[idx]] += 1
if cnt[s[idx]] == 1:
tar.append(s[idx])
print(re) | 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 ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 nums:
for j in nums:
count = 0
mult = 0
for sad in s:
if sad == j:
count = count + mult
if sad == o:
mult = mult + 1
if count > ans:
ans = count
print(ans) | 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 FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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
if ord(x) == j:
tans += ni
ans = max(ans, tans)
print(ans) | 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 ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 range(26):
li1[j][ord(s[i]) - ord("a")] += li3[j]
li3[ord(s[i]) - ord("a")] += 1
ans = max(li3)
for i in range(30):
for j in range(30):
if li1[i][j] > ans:
ans = li1[i][j]
print(ans)
solve() | 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_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 letters:
for c2 in letters:
mx = max(mx, dp[c1, c2])
print(mx) | 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 ASSIGN VAR FUNC_CALL VAR VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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])
arr[A] += 1
Max = max(Max, arr[A])
print(Max) | 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 NONE ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 + c] > ans:
ans = mp[i + c]
cnt[i] += 1
if cnt[i] > ans:
ans = cnt[i]
print(ans) | 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 FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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, sorted(cnts.values())[-1])
print(msg_len(input()))
test_data = [
("aaabb", 6),
("usaco", 1),
("lol", 2),
(
"qdpinbmcrfwxpdbfgozvvocemjructoadewegtvbvbfwwrpgyeaxgddrwvlqnygwmwhmrhaizpyxvgaflrsvzhhzrouvpxrkxfza",
37,
),
] | 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 VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING NUMBER STRING NUMBER STRING NUMBER 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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_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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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] = ans[l] + 1
except KeyError:
ans[l] = 1
for j in d.keys():
if j == l:
if d[j][id] - 1 > 0:
new_str = j + l
try:
ans[new_str] = ans[new_str] + d[j][id] - 1
except KeyError:
ans[new_str] = d[j][id] - 1
elif d[j][id] > 0:
new_str = j + l
try:
ans[new_str] = ans[new_str] + d[j][id]
except KeyError:
ans[new_str] = d[j][id]
max_ele = 0
for i in ans:
if ans[i] > max_ele:
max_ele = ans[i]
print(max_ele) | 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 VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR IF BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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:
ans = max(ans, num * (num - 1) // 2)
print(ans) | 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 FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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]:
z = metod1(i, a)
h += z - d
x += l - z
return max(h, x)
for _mind_control in range(1):
s = list(input())
if len(s) == len(set(s)):
print(1)
break
clovar = {}
arr = list(set(s))
answer = 0
for i in range(len(s)):
if s[i] in clovar:
clovar[s[i]].append(i)
else:
clovar[s[i]] = [i]
for i in range(len(arr)):
for o in arr[i:]:
if len(clovar[o]) * len(clovar[arr[i]]) > answer:
answer = max(
max(answer, metod(arr[i], o)), len(clovar[o]), len(clovar[arr[i]])
)
print(answer) | 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_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER 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 ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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])
count[c] += 1
ans = max(ans, count[c])
print(ans)
def main():
s = input()
solve(s)
main() | 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 VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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")
for i in range(26):
num[v][i] += cnt.get(i, 0)
ans = max(ans, num[v][i])
cnt[v] = cnt.get(v, 0) + 1
print(max(ans, *cnt.values())) | 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 FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR 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 arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!
For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.
-----Input-----
The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.
-----Output-----
Output a single integer — the number of occurrences of the secret message.
-----Examples-----
Input
aaabb
Output
6
Input
usaco
Output
1
Input
lol
Output
2
-----Note-----
In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions.
In the second example, no hidden string occurs more than once.
In the third example, the hidden string is the letter l. | 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):
sub_string[j][c] += freq[j]
freq[c] += 1
ans = max(freq)
for row in sub_string:
ans = max(ans, max(row))
print(ans) | 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 FUNC_CALL 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 VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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
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:
temp1 = pow(10, i - 1)
elif t == 1:
temp1 = s + 1
temp2 = t * (i - 1) * pow(10, i - 2)
return temp + temp1 + temp2 | 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_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR 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
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:
ans += x
x *= 10
return ans | 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 - digits[0], 0) * (n - 10 ** (length - 1) + 1)
+ Solution().countDigitOne(n - digits[0] * 10 ** (length - 1))
)
return int(counts) | 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 BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR 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):
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:
ones += int(n / wei / 10) * wei
wei *= 10
return int(ones) | 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 FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER RETURN 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 the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
-----Input-----
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
-----Output-----
Print a single integer — the maximum possible size of beautiful string Nikita can get.
-----Examples-----
Input
abba
Output
4
Input
bab
Output
2
-----Note-----
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 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[j][1] + 1, dp[j][2] + 1)
else:
dp[i][0] = 0
dp[i][1] = 1
for j in range(i):
dp[i][1] = max(dp[i][1], dp[j][1] + 1)
dp[i][2] = 1
for j in range(i):
dp[i][2] = max(dp[i][2], dp[j][1] + 1)
ans = 0
for i in range(n):
ans = max(ans, dp[i][2])
print(ans) | 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 NUMBER VAR VAR NUMBER 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 BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER 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 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR 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 the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
-----Input-----
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
-----Output-----
Print a single integer — the maximum possible size of beautiful string Nikita can get.
-----Examples-----
Input
abba
Output
4
Input
bab
Output
2
-----Note-----
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 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] + 1)
dp[pro][2] = max(dp[pro - 1][1], dp[pro - 1][2], dp[pro - 1][0]) + 1
elif s[pro] == "b":
dp[pro][0] = dp[pro - 1][0]
dp[pro][1] = max(dp[pro - 1][1], dp[pro - 1][0]) + 1
dp[pro][2] = max(dp[pro - 1][2], dp[pro - 1][1] + 1)
else:
dp[pro][0] = dp[pro - 1][0]
dp[pro][1] = max(dp[pro - 1][1], dp[pro - 1][0])
dp[pro][2] = max(dp[pro - 1][2], dp[pro - 1][1], dp[pro - 1][0])
print(dp[len(s) - 1][2]) | 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 VAR NUMBER 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 FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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 VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER |
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 the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
-----Input-----
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
-----Output-----
Print a single integer — the maximum possible size of beautiful string Nikita can get.
-----Examples-----
Input
abba
Output
4
Input
bab
Output
2
-----Note-----
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 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 the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
-----Input-----
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
-----Output-----
Print a single integer — the maximum possible size of beautiful string Nikita can get.
-----Examples-----
Input
abba
Output
4
Input
bab
Output
2
-----Note-----
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL 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 the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
-----Input-----
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
-----Output-----
Print a single integer — the maximum possible size of beautiful string Nikita can get.
-----Examples-----
Input
abba
Output
4
Input
bab
Output
2
-----Note-----
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 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_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 the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
-----Input-----
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
-----Output-----
Print a single integer — the maximum possible size of beautiful string Nikita can get.
-----Examples-----
Input
abba
Output
4
Input
bab
Output
2
-----Note-----
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 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] + 1)
dp[i][2] = dp[i - 1][2]
e = len(s) - 1
print(max(dp[e][0], dp[e][1], dp[e][2])) | 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 BIN_OP VAR NUMBER NUMBER 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 BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER |
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 the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
-----Input-----
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
-----Output-----
Print a single integer — the maximum possible size of beautiful string Nikita can get.
-----Examples-----
Input
abba
Output
4
Input
bab
Output
2
-----Note-----
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 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 sep1 in range(len(string) + 1):
for sep2 in range(sep1, len(string) + 1):
curr_ans = 0
curr_ans += prefix___b_nr[sep1]
curr_ans += prefix___a_nr[sep2] - prefix___a_nr[sep1]
curr_ans += prefix___b_nr[-1] - prefix___b_nr[sep2]
ans = min(ans, curr_ans)
print(len(string) - ans) | 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 BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL 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 the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
-----Input-----
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
-----Output-----
Print a single integer — the maximum possible size of beautiful string Nikita can get.
-----Examples-----
Input
abba
Output
4
Input
bab
Output
2
-----Note-----
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 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 < len(array):
if i == 0:
if char[i] == "b":
aback.append(0)
bback.append(array[0])
else:
bback.append(0)
aback.append(array[0])
elif char[i] == "b":
aback.append(aback[i - 1])
bback.append(bback[i - 1] + array[i])
else:
aback.append(aback[i - 1] + array[i])
bback.append(bback[i - 1])
i += 1
i = 0
while i < len(array):
afront.append(aback[-1] - aback[i])
bfront.append(bback[-1] - bback[i])
i += 1
if len(array) == 1:
print(array[0])
else:
maxm = -1
i = 0
while i < len(array):
if char[i] == "b":
j = i
while j < len(array):
if char[j] == "b":
if j == i:
ans = aback[i] + array[i] + afront[i]
if ans > maxm:
maxm = ans
else:
ans = aback[i] + array[i] + (bback[j] - bback[i]) + afront[j]
if ans > maxm:
maxm = ans
j += 1
i += 1
print(maxm) | 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 VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR 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 the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
-----Input-----
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
-----Output-----
Print a single integer — the maximum possible size of beautiful string Nikita can get.
-----Examples-----
Input
abba
Output
4
Input
bab
Output
2
-----Note-----
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 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] - countb[i] + counta[i] + counta[n] - counta[j])
print(ans) | 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 VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR 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 the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
-----Input-----
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
-----Output-----
Print a single integer — the maximum possible size of beautiful string Nikita can get.
-----Examples-----
Input
abba
Output
4
Input
bab
Output
2
-----Note-----
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 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":
ac += 1
temp = acnt[i] + bcnt + (suma - (acnt[i] + ac))
if temp > ans:
ans = temp
print(ans) | 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_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR 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 the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
-----Input-----
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
-----Output-----
Print a single integer — the maximum possible size of beautiful string Nikita can get.
-----Examples-----
Input
abba
Output
4
Input
bab
Output
2
-----Note-----
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 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[-1] - a[j]
ans = max(ans, t)
print(ans) | 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 NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.