description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for q in range(int(input())):
line = list(map(int, input()))
cou = [0] * 10
for i in line:
cou[i] += 1
ans = len(line) - 2
for i in range(10):
ans = min(ans, len(line) - cou[i])
for a in range(10):
for b in range(10):
fl = False
i = 0
ans_ = 0
while i < len(line) and line[i] != a:
i += 1
ans_ += 1
i += 1
while i < len(line):
while i < len(line) and line[i] != b:
i += 1
ans_ += 1
if i < len(line):
fl = False
i += 1
while i < len(line) and line[i] != a:
i += 1
ans_ += 1
if i < len(line):
fl = True
i += 1
if fl:
ans_ += 1
ans = min(ans, ans_)
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
s = input()
n = len(s)
ans = 0
for i in range(10):
for j in range(10):
f = True
c = 0
for k in range(n):
if f and int(s[k]) == i:
c += 1
f = False
elif not f and int(s[k]) == j:
c += 1
f = True
if i != j and c % 2:
c -= 1
ans = max(ans, c)
print(n - ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for g in range(int(input())):
s = input()
slov = [0] * 10
data = [0] * 10
for i in range(len(s)):
data[int(s[i])] += 1
ans = max(data)
for i in range(10):
slov[i] = 1
for i in range(len(s)):
if slov[int(s[i])] == 1:
slov[int(s[i])] = 0
data = [0] * 10
data[int(s[i])] = 1
data1 = [1] * 10
for j in range(i, len(s)):
if s[j] != s[i] and data1[int(s[j])] == 1:
data1[int(s[j])] = 0
data[int(s[j])] += 1
elif s[j] == s[i]:
data[int(s[i])] += 1
data1 = [1] * 10
r = max(data)
data.remove(r)
ans = max(ans, 2 * max(data))
print(len(s) - ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
s = input()
n = len(s)
ans = len(s) - 1
for i in range(0, 10):
cnt = 0
for j in s:
if j != str(i):
cnt += 1
ans = min(ans, cnt)
for i in range(0, 10):
for j in range(0, 10):
if i == j:
continue
isi = True
cnt = 0
for k in s:
if isi and k == str(i):
cnt += 1
isi = not isi
elif not isi and k == str(j):
cnt += 1
isi = not isi
if cnt % 2 != 0:
cnt -= 1
ans = min(ans, n - cnt)
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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 VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
n = int(input())
for i in range(n):
s = input()
l = len(s)
d = dict()
for i in "0123456789":
d[i] = 0
for i in s:
d[i] = d[i] + 1
d = sorted(d.items(), key=lambda x: x[1], reverse=True)
maxi = d[0][1]
arr = d
for i in range(len(arr)):
for j in range(len(arr)):
if i == j:
continue
else:
e = arr[i][0]
f = arr[j][0]
slag = -1
sount = 0
for q in s:
if q == e:
slag = 0
if q == f and slag == 0:
sount = sount + 1
slag = 1
if sount * 2 >= maxi:
maxi = sount * 2
print(l - maxi)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR STRING ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for m in [*open(0)][1:]:
kj = [0] * 100
for i in map(int, m[:-1]):
for j in range(10):
kj[10 * i + j] = kj[10 * j + i] + 1
print(len(m) - 1 - max(max(kj) & ~1, *kj[::11]))
|
FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def mergeSort(L, R, a):
i = j = k = 0
while i < len(L) and j < len(R):
if L[i] < R[j]:
a[k] = 0
i += 1
else:
a[k] = 1
j += 1
k += 1
while i < len(L):
a[k] = 0
i += 1
k += 1
while j < len(R):
a[k] = 1
j += 1
k += 1
for _ in range(int(input())):
s = input()
arr = [0] * 10
for i in range(len(s)):
if arr[int(s[i])] == 0:
arr[int(s[i])] = [i]
else:
arr[int(s[i])].append(i)
possible = 2
for i in range(10):
if arr[i] != 0:
possible = max(possible, len(arr[i]))
for j in range(i + 1, 10):
if arr[i] != 0 and arr[j] != 0:
a = [0] * (len(arr[i]) + len(arr[j]))
mergeSort(arr[i], arr[j], a)
pair = 0
k = 0
while k < len(a):
start = a[k]
while k < len(a) and a[k] == start:
k += 1
if k == len(a):
break
start = a[k]
while k < len(a) and a[k] == start:
k += 1
pair += 1
possible = max(possible, 2 * pair)
print(len(s) - possible)
|
FUNC_DEF ASSIGN VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
import sys
input = sys.stdin.readline
t = int(input())
for r in range(t):
s = input().strip("\n")
n = len(s)
d = {}
for i in s:
try:
d[i] += 1
except:
d[i] = 1
if len(d) == n:
print(n - 2)
elif len(d) == 1:
print(0)
else:
mini = 9999999999999999999999999
for i in range(0, 10):
for j in range(0, 10):
counter = 0
toggle = 0
for k in range(n):
if toggle == 0 and s[k] == str(i):
toggle ^= 1
elif toggle == 1 and s[k] == str(j):
toggle ^= 1
else:
counter += 1
if i != j and (len(s) - counter) % 2 == 1:
counter += 1
mini = min(mini, counter)
print(mini)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for i in range(int(input())):
a = list(map(int, input()))
z = len(a) + 1
a1 = [0] * 10
a2 = [z] * 10
a3 = list(range(10))
for j, x in enumerate(a):
a1[x] += 1
if a2[x] == z:
a2[x] = j
a4 = [x[0] for x in sorted(zip(a3, a2), key=lambda q: q[1])]
b = [[(0) for y in range(10)] for x in range(10)]
for j in range(10):
for k in range(j + 1, 10):
j1 = a4[j]
k1 = a4[k]
v = True
c = 0
for x in a:
if v and x == j1:
v = False
c += 1
elif not v and x == k1:
v = True
c += 1
b[j1][k1] = c
b1 = max(map(max, b))
b1 -= b1 % 2
print(len(a) - max(max(a1), b1))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for i in range(t):
a = input()
b = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
k = 0
for j in range(10):
for l in range(10):
q = str(b[j])
w = str(b[l])
e = 0
r = 0
d = 0
for f in a:
d += 1
if f == q and e == r:
e += 1
elif f == w and e != r:
r += 1
if q == w:
if e + r > k:
k = e + r
elif e + r - (e + r) % 2 > k:
k = e + r - (e + r) % 2
print(d - k)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for i in range(t):
lin = input()
a = {"0": 0, "1": 0, "2": 0, "3": 0, "4": 0, "5": 0, "6": 0, "7": 0, "8": 0, "9": 0}
b = {
"0": -1,
"1": -1,
"2": -1,
"3": -1,
"4": -1,
"5": -1,
"6": -1,
"7": -1,
"8": -1,
"9": -1,
}
bp = {
"0": -1,
"1": -1,
"2": -1,
"3": -1,
"4": -1,
"5": -1,
"6": -1,
"7": -1,
"8": -1,
"9": -1,
}
enct = [[(0) for k in range(10)] for l in range(10)]
for j in range(len(lin)):
a[lin[j]] += 1
bp[lin[j]] = b[lin[j]]
b[lin[j]] = j
for k in range(10):
if b[str(k)] != -1 and bp[lin[j]] < b[str(k)] and b[lin[j]] > b[str(k)]:
enct[int(lin[j])][k] += 1
max1 = 0
max2 = 0
for j in range(10):
max1 = max(a[str(j)], max1)
max2 = max(max(enct[j]), max2)
print(min(len(lin) - 2 * max2, len(lin) - max1))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
from itertools import product
T = int(input())
for _ in range(T):
s = input()
mn, n = len(s), len(s)
for a, b in product(list("0123456789"), list("0123456789")):
cc = 0
for ch in s:
if cc % 2 == 0:
if ch == a:
cc += 1
elif ch == b:
cc += 1
if a == b:
mn = min(mn, n - cc)
else:
mn = min(mn, n - cc if cc % 2 == 0 else n - cc + 1)
print(mn)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
s = input()
ans = 0
for d1 in "1234567890":
for d2 in "1234567890":
d11 = d1
d21 = d2
cur_ans = 0
for c in s:
if c == d11:
cur_ans += 1
d11, d21 = d21, d11
if d1 != d2:
cur_ans = cur_ans // 2 * 2
ans = max(ans, cur_ans)
print(len(s) - ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR STRING FOR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
def max_len(two, num):
two = str(two)
if len(two) == 1:
two = "0" + two
lenth = 0
to_check = 0
for i in num:
if i == two[to_check]:
to_check = (to_check + 1) % 2
lenth += 1
if lenth % 2 == 0:
return lenth
return lenth - 1
def solve():
num = input()
freq = {}
for i in num:
freq[i] = freq.get(i, 0) + 1
maxx = max(freq.values())
can = maxx
for i in range(100):
can = max(can, max_len(i, num))
print(len(num) - can)
while t:
solve()
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
s = input()
dp = [[(0) for i in range(10)] for j in range(10)]
mx = 0
for i in range(10):
sl = str(i)
for j in range(10):
nl = str(j)
fi, ei = -1, -1
used = 0
for k in range(len(s)):
if i == j and s[k] == sl:
dp[i][i] += 1
continue
elif i == j:
continue
else:
if s[k] == sl:
fi = k
used = 0
elif s[k] == nl:
ei = k
if not used and ei > fi and fi >= 0:
dp[i][j] += 1
used = 1
if i != j:
mx = max(mx, dp[i][j])
mx = max(mx * 2, max(dp[i][i] for i in range(10)))
print(len(s) - mx)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
def swap(p):
b = p[0]
p[0] = p[1]
p[1] = b
return p
def calculate_delets(s, pat):
or_pat = pat.copy()
res = 0
for el in s:
if el == pat[0]:
pat = swap(pat)
else:
res += 1
if pat != or_pat:
res += 1
return res
for i in range(t):
s = input()
l1 = "0123456789"
l2 = "0123456789"
m_del = len(s)
for k1 in l1:
for k2 in l2:
pat = [k1, k2]
m_del = min(calculate_delets(s, pat), m_del)
print(m_del)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def giveCost(x, y, s):
cost = 0
lookFor = x
l = 0
for i in s:
if i != lookFor:
cost += 1
else:
lookFor = y if lookFor == x else x
l += 1
return cost if l % 2 == 0 or x == y else cost + 1
for _ in range(int(input())):
s = list(map(int, list(input())))
cost = float("inf")
for i in range(10):
for j in range(10):
cost = min(cost, giveCost(i, j, s))
print(cost)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
n = input()
cnt = 2
f = [(0) for i in range(10)]
for i in range(10):
for c in n:
if c == str(i):
f[i] += 1
for j in range(i + 1, 10):
ind1, ind2 = True, True
cnt1, cnt2 = 0, 0
for c in n:
if ind1 and c == str(i):
ind1 = False
if not ind1 and c == str(j):
ind1 = True
cnt1 += 2
for c in n:
if ind2 and c == str(j):
ind2 = False
if not ind2 and c == str(i):
ind2 = True
cnt2 += 2
cnt = max(cnt, cnt1, cnt2)
x = max(f)
cnt = max(cnt, x)
print(len(n) - cnt)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
import sys
input = sys.stdin.readline
def name(arr):
patterns = {}
highest = 0
count = 0
for i in range(10):
for j in range(10):
first = 0
found = False
for char in arr[:-1]:
if i == j:
if char == str(i):
count += 1
else:
if first != 1:
if char == str(i):
first = 1
elif first == 1:
if char == str(j):
first = 0
found = True
if found:
count += 2
found = False
if count > highest:
highest = count
count = 0
return len(arr) - 1 - highest
def solution():
arr = input()
print(name(arr))
t = int(input())
for i in range(0, t):
solution()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def test(s, c):
matrix = [
[
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
],
[
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
],
[
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
],
[
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
],
[
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
],
[
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
],
[
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
],
[
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
],
[
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
],
[
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
[-1, 0],
],
]
max = 0
for i in range(len(s)):
x = int(s[i])
for y in range(10):
if x != y:
current = matrix[y][x][0]
if current == y:
matrix[y][x][0] = x
matrix[y][x][1] += 1
if matrix[y][x][1] > max:
max = matrix[y][x][1]
current = matrix[x][y][0]
if current == y or current == -1:
matrix[x][y][0] = x
if matrix[x][y][1] > max:
max = matrix[x][y][1]
return max * 2
def calc(s):
positions = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(len(s)):
c = int(s[i])
positions[c] += 1
m = max(positions)
combinations = []
for i in range(10):
for j in range(10):
l1 = positions[i]
l2 = positions[j]
if l1 + l2 > m and i != j:
combinations.append((i, j))
t = test(s, combinations)
return m if m > t else t
n = int(input())
for t in range(n):
s = input()
print(len(s) - calc(s))
|
FUNC_DEF ASSIGN VAR LIST LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for _ in range(t):
s = input()
data = []
req = []
for _ in range(10):
temp = []
temp1 = []
for _ in range(10):
temp.append(0)
temp1.append(-1)
data.append(temp)
req.append(temp1)
for i in s:
i = int(i)
for j in range(10):
if req[i][j] == i or req[i][j] == -1:
data[i][j] += 1
req[i][j] = j
if req[j][i] == i and i != j:
data[j][i] += 1
req[j][i] = j
l = []
for i in range(10):
for j in range(10):
if data[i][j] % 2 != 0:
if i != j:
data[i][j] = data[i][j] - 1
for i in data:
l.append(max(i))
print(len(s) - max(l))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
n = int(input())
for i in range(n):
m = 0
arr1 = str(input())
for j in range(0, 10):
for k in range(0, 10):
if j < k:
coun = 0
y = 0
for t in range(len(arr1)):
if coun == 0 and arr1[t] == str(j):
coun += 1
y = str(j)
elif coun == 0 and arr1[t] == str(k):
coun += 1
y = str(k)
elif arr1[t] == str(j) and y == str(k):
coun += 1
y = str(j)
elif arr1[t] == str(k) and y == str(j):
coun += 1
y = str(k)
if coun % 2 == 0 and coun > m:
m = coun
elif coun % 2 == 1 and coun - 1 > m:
m = coun - 1
for j in range(10):
if arr1.count(str(j)) > m:
m = arr1.count(str(j))
print(len(arr1) - m)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
n = input()
ans = 2 * int(100000.0)
for pair in range(100):
i = 0
s = str(pair)
if len(s) == 1:
s = "0" + s
d = 0
for j in n:
if j != s[i]:
d += 1
else:
i = 1 - i
if i == 1 and s[0] != s[1]:
d += 1
ans = min(ans, d)
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
from sys import stdin
tt = int(stdin.readline())
nn = "0123456789"
for loop in range(tt):
s = stdin.readline()
s = s[:-1]
ans = len(s)
for fi in nn:
for sc in nn:
state = 0
now = 0
for i in s:
if i == fi and state == 0:
now += 1
state = 1
elif i == sc and state == 1:
now += 1
state = 0
if fi == sc:
ans = min(ans, len(s) - now)
else:
ans = min(ans, len(s) - now // 2 * 2)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for tc in range(t):
s = str(input())
freq = {}
for i in range(10):
freq[str(i)] = 0
for i in s:
freq[i] += 1
res = len(s) - max(freq.values())
for i in range(10):
for j in range(10):
flag = 0
cnt = 0
for k in s:
if flag == 0 and k == str(i):
flag = 1
cnt += 1
elif flag == 1 and k == str(j):
flag = 0
cnt += 1
if cnt % 2 == 1:
cnt -= 1
res = min(res, len(s) - cnt)
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
def min_erase(c, s):
erase = 0
t = 0
for d in s:
if d == c[t]:
t ^= 1
else:
erase += 1
if c[0] != c[1] and t == 1:
erase += 1
return erase
for _ in range(t):
s = input()
ans = len(s)
for x in range(10):
for y in range(10):
c = [str(x), str(y)]
cur = min_erase(c, s)
ans = min(ans, cur)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
s = input()
a = []
for i in s:
a.append(int(i))
b = []
n = len(s)
for i in range(10):
for j in range(10):
check = False
cnt = 0
st = 11
nd = 11
for k in a:
if k == i or k == j:
if k == i:
st = i
nd = j
else:
st = j
nd = i
break
if st != 11:
for k in a:
if k == st and not check:
cnt += 1
check = True
elif k == nd and check:
cnt += 1
check = False
if st != nd and cnt % 2 != 0:
cnt -= 1
b.append(cnt)
print(n - max(b))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
nn = "0123456789"
def gift():
for _ in range(t):
s = input()
ans = len(s)
for fi in nn:
for sc in nn:
state = 0
now = 0
for i in s:
if i == fi and state == 0:
now += 1
state = 1
elif i == sc and state == 1:
now += 1
state = 0
if fi == sc:
ans = min(ans, len(s) - now)
else:
ans = min(ans, len(s) - now + now % 2)
yield ans
t = int(input())
ans = gift()
print(*ans, sep="\n")
|
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
T = int(input())
while T:
s = input()
D = {}
for i in range(len(s)):
if int(s[i]) in D:
D[int(s[i])].append(i)
else:
D[int(s[i])] = [i]
m = 0
for i in D:
m = max(m, len(D[i]))
for i in D:
for j in D:
if i != j:
a = 1
b = 0
Z = []
x = D[i][0]
Z.append(x)
while a < len(D[i]) + 1 and b < len(D[j]) and x < len(s):
while b < len(D[j]) and D[j][b] < x:
b = b + 1
if b < len(D[j]):
x = D[j][b]
Z.append(x)
else:
x = len(s) + 1
while a < len(D[i]) and D[i][a] < x:
a = a + 1
if a < len(D[i]):
x = D[i][a]
Z.append(x)
else:
x = len(s) + 1
m = max(m, len(Z) - len(Z) % 2)
print(len(s) - m)
T = T - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
from itertools import product
for _ in range(int(input())):
s = input()
res = min(2, len(s))
for c1, c2 in product("0123456789", repeat=2):
cnt = 0
idx = 0
for c in s:
if c == (c1 if idx == 0 else c2):
cnt += 1
idx = 1 - idx
res = max(res, cnt // 2 * 2 if c1 != c2 else cnt)
print(len(s) - res)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
s = [int(ch) for ch in input().rstrip()]
ans = 0
for d1 in range(0, 10):
for d2 in range(0, 10):
if d1 == d2:
cnt = s.count(d1)
ans = max(ans, cnt)
continue
cnt = 0
state = 0
for item in s:
if item == d1 and not state:
state = 1
cnt += 1
elif item == d2 and state:
state = 0
cnt += 1
if state == 1:
ans = max(ans, cnt - 1)
else:
ans = max(ans, cnt)
print(len(s) - ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def func(a, x, y):
res = 0
for c in a:
if c == x:
res += 1
temp = x
x = y
y = temp
if x != y and res % 2 == 1:
res -= 1
return res
for _ in range(int(input())):
a = [int(x) for x in input()]
ans = 0
for x in range(10):
for y in range(10):
ans = max(ans, func(a, x, y))
print(len(a) - ans)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
def func(s, j, k):
c = 0
if j == k:
for b in s:
if int(b) != j:
c += 1
else:
v = 0
for b in s:
if v == 0:
if int(b) != j:
c += 1
else:
v = (v + 1) % 2
elif int(b) != k:
c += 1
else:
v = (v + 1) % 2
if v == 1:
c += 1
return c
for i in range(t):
s = input()
m = len(s)
for j in range(10):
for k in range(10):
m = min(m, func(s, j, k))
print(m)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
T = int(input())
for _ in range(T):
s = input()
n = len(s)
ans = n - 2
A = [(0) for i in range(10)]
for i in range(10):
for j in range(10):
l = 0
st = 0
B = [str(i), str(j)]
for val in s:
if val == B[st]:
l = l + 1
st = (st + 1) % 2
if i != j:
if l % 2 != 0:
l = l - 1
ans = min(ans, n - l)
else:
ans = min(ans, n - l)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
import sys
def count_alternation(s, a, b):
n = len(s)
for i in range(n):
if s[i] == a:
break
if s[i] == b:
a, b = b, a
break
i1 = 0
for i in range(n)[::-1]:
if s[i] == b:
i1 = i
break
flip = {a: b, b: a}
which = a
count = 0
for i in range(i1 + 1):
if s[i] == which:
if which == b:
count += 1
which = flip[which]
return 2 * count
def solve(s):
s = [(ord(c) - ord("0")) for c in s]
k = 10
n = len(s)
counts = [0] * k
for i in range(n):
counts[s[i]] += 1
result = max(counts)
for a in range(k):
for b in range(a + 1, k):
if counts[a] == 0 or counts[b] == 0:
continue
result = max(result, count_alternation(s, a, b))
return n - result
def main(istr, ostr):
t = int(istr.readline())
for _ in range(t):
s = istr.readline().strip()
result = solve(s)
print(result, file=ostr)
main(sys.stdin, sys.stdout)
|
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR DICT VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
while t:
t -= 1
s = input()
if len(list(set(s))) == 1:
print("0")
else:
x = [
"00",
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
"33",
"34",
"35",
"36",
"37",
"38",
"39",
"40",
"41",
"42",
"43",
"44",
"45",
"46",
"47",
"48",
"49",
"50",
"51",
"52",
"53",
"54",
"55",
"56",
"57",
"58",
"59",
"60",
"61",
"62",
"63",
"64",
"65",
"66",
"67",
"68",
"69",
"70",
"71",
"72",
"73",
"74",
"75",
"76",
"77",
"78",
"79",
"80",
"81",
"82",
"83",
"84",
"85",
"86",
"87",
"88",
"89",
"90",
"91",
"92",
"93",
"94",
"95",
"96",
"97",
"98",
"99",
]
l = len(x)
y = [0] * l
extra = [0] * 10
ans = [0] * l
for i in range(len(s)):
extra[int(s[i])] += 1
for j in range(l):
if s[i] == x[j][y[j] % 2]:
y[j] += 1
if y[j] % 2 == 0:
ans[j] += 1
print(len(s) - max(2 * max(ans), max(extra)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
s = input()
m = 0
for i in range(10):
m = max(m, s.count(str(i)))
ans1 = len(s) - m
second = 0
for i in range(10):
for j in range(i + 1, 10):
last = ""
c = 0
for k in s:
if k == str(i) or k == str(j):
if k != last:
c += 1
last = k
if c % 2 == 0:
second = max(second, c)
else:
second = max(second, c - 1)
ans2 = len(s) - second
ans3 = len(s) - 2
print(min(ans1, ans2, ans3))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
import sys
input = sys.stdin.readline
inf = int(10000000000.0)
t = int(input())
while t:
t -= 1
s = input().strip()
n = len(s)
d = dict()
for i in s:
if i in d:
d[i] += 1
else:
d[i] = 1
m1 = max(d.values())
m2 = 0
for i in range(10):
for j in range(10):
if i != j:
f = 0
l = 0
for k in s:
if f == 0 and k == str(i):
f = 1
l += 1
elif f == 1 and k == str(j):
f = 0
l += 1
m2 = max(l, m2)
print(n - max(m1, m2 >> 1 << 1))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER 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 VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for _ in range(0, t):
st = str(input())
if len(st) <= 2:
print(0)
continue
ans = 2
for i in range(10):
for j in range(10):
temp = 0
for char in st:
if temp & 1:
if char == str(j):
temp += 1
elif char == str(i):
temp += 1
if i != j:
if temp & 1:
temp -= 1
ans = max(ans, temp)
print(len(st) - ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for _ in range(t):
l = [int(i) for i in list(input())]
ans = float("INF")
for i in range(10):
for j in range(10):
count = 0
now = 1
for k in l:
if now == 1:
if k != i:
count += 1
else:
now *= -1
elif k != j:
count += 1
else:
now *= -1
if i != j and now == -1:
count += 1
ans = min(ans, count)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for _ in range(t):
s = input()
counts = {}
for i in s:
if i in counts:
counts[i] += 1
else:
counts[i] = 1
longest = max(counts.values())
for a1 in "0123456789":
for a2 in "0123456789":
length = 0
found_a1 = False
for i in s:
if found_a1:
if i == a2:
length += 2
found_a1 = False
elif i == a1:
found_a1 = True
longest = max(longest, length)
print(len(s) - longest)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR STRING FOR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
import sys
input = sys.stdin.readline
aaaa = list()
for kek in range(int(input())):
s = input().split()[0]
ans = 0
for i in range(10):
for j in range(10):
flg = True
answer = 0
for x in s:
if flg and int(x) == i:
answer += 1
flg = False
elif flg == False and int(x) == j:
answer += 1
flg = True
if i == j:
ans = max(answer, ans)
else:
ans = max(answer // 2 * 2, ans)
aaaa.append(len(s) - ans)
print(*aaaa, sep="\n")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def list_input():
return list(map(int, input().split()))
def multiple_input():
return map(int, input().split())
def solve(a, b):
res = 0
for it in s:
if it == a:
res += 1
a, b = b, a
if res % 2 != 0 and a != b:
res -= 1
return res
for _ in range(int(input())):
s = input()
m = 0
ans = 0
for i in range(10):
for j in range(10):
ans = max(ans, solve(str(i), str(j)))
print(len(s) - ans)
|
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 FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for _ in range(t):
s = list(str(input()))
d = [0] * 10
for i in range(len(s)):
d[int(s[i])] += 1
max_len = max(d)
for a in range(0, 10):
for b in range(0, 10):
now_len = 0
p = a
for i in range(len(s)):
if int(s[i]) == p:
now_len += 1
if p == a:
p = b
else:
p = a
max_len = max(max_len, now_len - now_len % 2)
print(len(s) - max_len)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
import sys
input = sys.stdin.readline
def solve(char):
ind = 0
cnt = 0
for c in s:
if c == char[ind]:
cnt += 1
ind ^= 1
if char[0] != char[1]:
cnt = cnt // 2 * 2
return len(s) - cnt
t = int(input())
for _ in range(t):
s = input()[:-1]
ans = len(s)
for i in range(0, 10):
for j in range(0, 10):
char = str(i), str(j)
ans = min(ans, solve(char))
print(ans)
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def check(a, b):
ok = False
cnt = 0
for i in range(len(u)):
if ok and u[i] == a:
cnt += 1
ok = False
elif not ok and u[i] == b:
cnt += 1
ok = True
if a == b:
return cnt
return cnt - cnt % 2
ans = []
for stp in range(int(input())):
u = list(map(int, list(input())))
ansi = 0
for i in range(10):
for j in range(10):
ansi = max(ansi, check(i, j))
ans.append(len(u) - ansi)
print("\n".join(map(str, ans)))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR RETURN VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def main():
t = int(input())
for i in range(t):
s = input()
answer = 10**9
for i in range(9):
for j in range(i + 1, 10):
a = str(i)
b = str(j)
last = "a"
count = 0
for f in s:
if (f == a or f == b) and f != last:
last = f
else:
count += 1
if (len(s) - count) % 2 == 1:
count += 1
answer = min(answer, count)
counts = [(0) for i in range(10)]
for f in s:
counts[int(f)] += 1
for i in counts:
answer = min(answer, len(s) - i)
print(answer)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
from sys import stdin, stdout
q = int(input())
for i in range(q):
s = input()
sum1 = 0
flag = 0
for i in range(10):
for j in range(10):
maxi = 0
flag = 0
for k in s:
if flag == 0:
if int(k) == i:
maxi += 1
flag = 1
elif int(k) == j:
maxi += 1
flag = 0
if i != j:
maxi -= maxi % 2
sum1 = max(maxi, sum1)
print(len(s) - sum1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
T = int(input())
for t in range(T):
s = input()
mx = 0
arr = []
for i in range(10):
arr.append([])
cnt = 0
for k in s:
arr[int(k)].append(cnt)
cnt += 1
for i in range(9):
for j in range(i + 1, 10):
odd = 0
even = 0
m, n = 0, 0
ans = 0
for k in range(len(arr[i]) + len(arr[j])):
if m == len(arr[i]) or n == len(arr[j]):
break
if arr[i][m] < arr[j][n]:
even = 0
m += 1
if odd == 0:
ans += 1
odd = 1
else:
odd = 0
n += 1
if even == 0:
ans += 1
even = 1
if len(arr[i]) != 0 and len(arr[j]) != 0:
if (
arr[i][-1] > arr[j][-1]
and arr[i][0] > arr[j][0]
or arr[i][-1] < arr[j][-1]
and arr[i][0] < arr[j][0]
):
ans += ans % 2
else:
ans -= ans % 2
mx = max(mx, ans)
for i in range(10):
mx = max(mx, len(arr[i]))
print(len(s) - mx)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP 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 BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
s = input()
n = len(s)
pairs = []
for i in range(10):
for j in range(10):
pairs.append(str(i) + str(j))
maxx = 0
for i in pairs:
c = 0
v = i[0]
for j in range(n):
if s[j] == v:
c += 1
if v == i[0]:
v = i[1]
else:
v = i[0]
if v == i[1] and i[0] != i[1]:
c -= 1
maxx = max(c, maxx)
print(n - maxx)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
from sys import stdin
for _ in range(int(stdin.readline())):
t = stdin.readline().strip()
ans = 0
for i in range(10):
cand1 = str(i)
for j in range(10):
cand2 = str(j)
pos = 0
flag = False
for k in t:
if k == cand1 and flag == False:
flag = True
elif k == cand2 and flag == True:
pos += 2
flag = False
if flag and i == j:
pos += 1
ans = max(ans, pos)
print(len(t) - ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def everythingfine(s, n):
for i in range(n):
if s[i] != s[(i + 2) % n]:
return False
return True
for _ in range(int(input())):
s = input()
n = len(s)
maxi = 0
temp = list("0123456789")
d = dict()
for i in temp:
d[i] = s.count(i)
maxi = max(maxi, d[i])
if everythingfine(s, n):
print("0")
continue
ans = min(n - 2, n - maxi)
for i in range(10):
for j in range(10):
if i == j or d[temp[i]] == 0 or d[temp[j]] == 0:
continue
tempans = 0
diff = 0
for x in s:
if x == temp[i] and diff == 1:
tempans += 1
elif x == temp[j] and diff == 0:
tempans += 1
elif x == temp[i] and diff == 0:
diff += 1
elif x == temp[j] and diff == 1:
diff -= 1
else:
tempans += 1
if diff == 0:
ans = min(ans, tempans)
print(ans)
|
FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def hhh(s, u, v):
c = b = 0
for i in range(len(s)):
if b == 0:
if s[i] == u:
x = u
y = v
b = 1
elif s[i] == v:
x = v
y = u
b = 1
elif b == 1:
if s[i] == y:
c += 2
b = 2
elif s[i] == x:
b = 1
return c
for t in range(int(input())):
s = input()
a = []
for i in range(10):
a.append(s.count(str(i)))
m = max(a)
for i in range(10):
for j in range(i + 1, 10):
n = hhh(s, str(i), str(j))
if n > m:
m = n
print(len(s) - m)
|
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(0, int(input())):
l = list(input())
d = {}
for i in range(0, len(l)):
if int(l[i]) in d:
d[int(l[i])].append(i)
else:
d.update({int(l[i]): [i]})
odd_res = 0
even_res = 999999999
for i in d:
odd_res = max(len(d[i]), odd_res)
odd_res = len(l) - odd_res
if odd_res == len(l) - 1:
odd_res -= 1
for i in range(0, 10):
for j in range(0, 10):
if i != j:
temp = []
for m in range(0, len(l)):
if int(l[m]) in [i, j]:
if temp != [] and temp[-1] == l[m]:
pass
else:
temp.append(l[m])
if temp != []:
flag5 = 0
tem = 0
for m in range(0, len(temp) - 1):
if temp[m] == temp[m + 1]:
tem += 1
if flag5 == 0:
if len(temp) % 2 == 0:
even_res = min(even_res, len(l) - len(temp))
else:
even_res = min(even_res, len(l) - len(temp) + 1)
print(min(odd_res, even_res))
|
FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR DICT FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR LIST VAR VAR IF VAR LIST VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
s = input()
n = len(s)
cnt = [(0) for i in range(10)]
for i in s:
cnt[int(i)] += 1
arr = []
maxa = 0
for i in range(10):
for j in range(10):
tmp = 0
c = 0
p = 1
if i != j:
for k in s:
w = int(k)
if w == i:
tmp = 1
if w == j and tmp == 1:
tmp = 0
c += 1
arr.append((i, j))
maxa = max(c * 2, maxa)
print(n - max(max(cnt), maxa))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def f(s, n):
if n % 2 != 0:
return False
else:
p = s[0]
q = s[1]
for i in range(0, n, 2):
if s[i] != p:
return False
for i in range(1, n, 2):
if s[i] != q:
return False
return True
def g(s, i, j):
k = 0
while int(s[k]) != i:
k = k + 1
p = i
q = j
l = 1
for m in range(k + 1, n):
if int(s[m]) == q:
l = l + 1
q = p
p = int(s[m])
if l % 2 == 0:
return l
else:
return l - 1
t = int(input())
while t > 0:
t = t - 1
s = input()
n = len(s)
if f(s, n) == True:
print(0)
else:
d = {}
m = 0
for i in s:
j = int(i)
if j in d:
d[j] = d[j] + 1
else:
d[j] = 1
m = max(m, d[j])
if m == 1:
print(n - 2)
else:
table = [[(0) for i in range(10)] for j in range(10)]
for i in range(10):
if i not in d:
for j in range(10):
table[i][j] = 0
else:
for j in range(10):
if j == i:
table[i][j] = d[i]
elif j not in d:
table[i][j] = 0
else:
table[i][j] = g(s, i, j)
mi = 0
for i in range(10):
mi = max(mi, max(table[i]))
print(n - mi)
|
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for qwerty in range(int(input())):
s = input()
ans = 10**8
for i in range(10):
t = 0
for j in s:
if int(j) != i:
t += 1
ans = min(ans, t)
for a in range(10):
for b in range(10):
q = 0
t = 0
for j in s:
if int(j) == a and q == 0 or int(j) == b and q == 1:
q = (q + 1) % 2
else:
t += 1
t += (len(s) - t) % 2
ans = min(ans, t)
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for i in range(t):
s = input()
pair = []
res = []
for i in range(10):
for j in range(10):
pair.append([i, j])
for i in range(100):
turn = pair[i][0]
c = 0
for j in range(len(s)):
if int(s[j]) != turn:
c += 1
elif turn == pair[i][0]:
turn = pair[i][1]
else:
turn = pair[i][0]
if (len(s) - c) % 2 == 0:
res.append(c)
if (len(s) - c) % 2 != 0 and pair[i][0] == pair[i][1]:
res.append(c)
print(min(res))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for _ in range(t):
s = list(input())
res = len(s) - 2
for i in range(10):
for j in range(10):
cur, ci, cj = 0, 0, 0
ii, jj = str(i), str(j)
for c in s:
if ci == cj and c == ii:
ci += 1
elif ci > cj and c == jj:
cj += 1
else:
cur += 1
res = min(cur + (1 if ci > cj and i != j else 0), res)
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
import sys
def make_pat(p):
bit = 0
size = 0
for i in range(len(arr)):
if bit == 0 and arr[i] == p[0]:
bit = 1
size += 1
elif bit == 1 and arr[i] == p[1]:
bit = 0
size += 1
if p[0] == p[1]:
return size
elif size % 2 == 0:
return size
else:
return 0
tc = int(sys.stdin.readline())
for _ in range(tc):
arr = list(sys.stdin.readline().rstrip())
ans = 0
for i in range(10):
for j in range(10):
temp = make_pat(str(i) + str(j))
ans = max(ans, temp)
print(len(arr) - ans)
|
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for _ in range(t):
s = input()
n = len(s)
ans = [0] * 10
for i in range(n):
ans[ord(s[i]) - ord("0")] = ans[ord(s[i]) - ord("0")] + 1
ans.sort()
mx = ans[9]
for i in range(10):
for j in range(10):
c = 0
if j == i:
continue
b = 0
for k in range(n):
if b == 0 and ord(s[k]) - ord("0") == i:
b = 1
c = c + 1
elif b == 1 and ord(s[k]) - ord("0") == j:
b = 0
c = c + 1
mx = max(c - c % 2, mx)
print(n - max(mx, ans[9]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
from sys import stdin
for _ in range(int(input())):
a = stdin.readline().rstrip()
d = {}
le = len(a)
for i in range(le):
x = d.get(a[i], 0)
if x:
d[a[i]] += 1
else:
d[a[i]] = 1
d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True))
m = max(d.values())
done = []
for i, j in d.items():
for k, l in d.items():
if i != k and i + k not in done:
done.append(i + k)
done.append(k + i)
if min([j, l]) * 2 > m:
start = []
for test in range(le):
if not start:
if a[test] in [i, k]:
start.append(a[test])
elif start[-1] != a[test] and a[test] in [i, k]:
start.append(a[test])
if len(start) > m:
if start[0] == start[-1]:
m = len(start) - 1
else:
m = len(start)
print(le - m)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL VAR LIST VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR IF VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def answer(A):
d = {}
for i in A:
if i not in d:
d[i] = 1
else:
d[i] += 1
maxi = max(d.values())
for i in range(0, 10):
for j in range(0, 10):
if i != j:
count = 0
search = str(i)
for k in range(len(A)):
if A[k] == search:
if search == str(i):
search = str(j)
else:
search = str(i)
count += 1
maxi = max(maxi, count - count % 2)
return len(A) - maxi
t = int(input())
for i in range(t):
s = input()
print(answer(s))
|
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def main():
return "\n".join(
map(str, (nCharactersToEraseFrom(input()) for _ in range(int(input()))))
)
def nCharactersToEraseFrom(string):
repetition = {
"0": 0,
"1": 0,
"2": 0,
"3": 0,
"4": 0,
"5": 0,
"6": 0,
"7": 0,
"8": 0,
"9": 0,
}
for letter in string:
repetition[letter] += 1
longestLength1 = max(repetition.values())
letters = tuple(set(string))
if len(letters) > 1:
longestLength2 = max(
goodStringLengthFrom(string, {letters[i], letters[j]})
for i in range(len(letters) - 1)
for j in range(i + 1, len(letters))
)
else:
longestLength2 = 0
if longestLength1 >= longestLength2:
return len(string) - longestLength1
return len(string) - (longestLength2 - 1 if longestLength2 % 2 else longestLength2)
def goodStringLengthFrom(string, pairOfLetters):
currLetter = [0]
return sum(isElement(l, pairOfLetters, currLetter) for l in string)
def isElement(letter, letters, currLetter):
if letter in letters and letter != currLetter[0]:
currLetter[0] = letter
return 1
return 0
print(main())
|
FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR LIST NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
from sys import stdin, stdout
k = ""
def yark(a, i, j):
z = 0
p = str(i)
f = p
for k in a:
if k == f:
z += 1
f = p if f != p else str(j)
if i != j and z & 1:
z -= 1
return z
for t in range(int(stdin.readline())):
a = stdin.readline()
ans = 0
for i in range(10):
for j in range(10):
ans = max(ans, yark(a, i, j))
k += str(len(a) - ans - 1) + " "
stdout.write(k)
|
ASSIGN VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def solve():
s = input()
n = len(s)
dic = {}
occ = {}
for i in range(0, n):
if s[i] not in dic:
dic[s[i]] = [i]
occ[s[i]] = 1
else:
dic[s[i]].append(i)
occ[s[i]] += 1
dic2 = {}
maxx = 2
for d in dic:
others = {
"0": 0,
"1": 0,
"2": 0,
"3": 0,
"4": 0,
"5": 0,
"6": 0,
"7": 0,
"8": 0,
"9": 0,
}
maxx_others = 0
if len(dic[d]) <= 1:
continue
for i in range(len(dic[d])):
st = dic[d][i]
if i + 1 < len(dic[d]):
end = dic[d][i + 1]
sets = set(s[st + 1 : end])
for i in sets:
others[i] += 1
maxx_others = max(maxx_others, others[i])
elif i + 1 == len(dic[d]):
end = n
sets = set(s[st + 1 : end])
for i in sets:
others[i] += 1
maxx_others = max(maxx_others, others[i])
maxx1 = max(occ[d], maxx_others * 2)
maxx = max(maxx1, maxx)
print(n - maxx)
t = int(input())
for i in range(t):
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
s = input()
n = len(s)
ans = n - 2
g = {i: [] for i in "0123456789"}
for i in range(n):
g[s[i]].append(i)
for a in "0123456789":
for b in "0123456789":
cs = 0
i = j = 0
aa = g[a]
bb = g[b]
ans = min(ans, n - len(aa))
while i < len(aa):
while j < len(bb) and aa[i] >= bb[j]:
j += 1
if j < len(bb):
while i < len(aa) and aa[i] <= bb[j]:
i += 1
else:
break
cs += 1
ans = min(ans, n - cs * 2)
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR LIST VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR STRING FOR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
import sys
readline = sys.stdin.readline
def solve():
S = readline().rstrip()
N = len(S)
odds = [S.count(str(i)) for i in range(10)]
odds_max = max(odds)
ans = N - max(odds)
for i in range(10):
if odds[i] * 2 <= odds_max:
continue
for j in range(i + 1, 10):
if odds[j] * 2 <= odds_max:
continue
count = 0
last = None
_i, _j = str(i), str(j)
for v, c in enumerate(S):
if c != last:
if c == _i:
last = _i
count += 1
elif c == _j:
last = _j
count += 1
ans = min(ans, N - count // 2 * 2)
print(ans)
T = int(readline())
for t in range(T):
solve()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for s in [*open(0)][1:]:
a = [0] * 10
b = [0] * 10
c = [0] * 100
i = 0
for x in map(int, s[:-1]):
for j in range(10):
c[10 * j + x] += (a[j] > a[x]) * 2
i += 1
a[x] = i
b[x] += 1
print(i - max(b + c))
|
FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
T = int(input())
l = []
for i in range(10):
for j in range(i, 10):
l.append([])
l[-1].append(str(i))
l[-1].append(str(j))
def solve():
if len(set(s)) == 1:
return 0
val = 0
for i in range(55):
l1 = [x for x in s if x in l[i]]
if len(l1) == 0:
continue
if len(set(l1)) == 1:
val = max(len(l1), val)
else:
newlist = [l1[0]]
for j in range(1, len(l1)):
if l1[j] != l1[j - 1]:
newlist.append(l1[j])
if len(newlist) % 2 == 1:
val = max(len(newlist) - 1, val)
else:
val = max(len(newlist), val)
return len(s) - val
for test in range(T):
s = list(input())
print(solve())
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def solve(s, n):
ans = n - 1
for a in range(10):
for b in range(10):
cnt1 = 0
cnt2 = 0
f = "fst"
for i in range(n):
if f == "fst":
if s[i] == a:
cnt1 += 1
f = "snd"
elif s[i] == b:
cnt2 += 1
f = "fst"
if a != b:
res = min(cnt1, cnt2) * 2
else:
res = cnt1 + cnt2
ans = min(ans, n - res)
return ans
def main():
t = int(input())
for i in range(t):
a = [int(i) for i in input()]
print(solve(a, len(a)))
main()
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
s = input()
digits = "0123456789"
total = len(s)
for i in digits:
for j in digits:
if i != j:
count = 0
order = 0
for d in s:
if d == i and not order:
count += 1
order = 1
elif d == j and order:
count += 1
order = 0
count = count // 2 * 2
total = min(total, len(s) - count)
for i in digits:
total = min(total, len(s) - s.count(i))
print(total)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
from sys import stdin
input = stdin.readline
def solve(a, b):
a, b = str(a), str(b)
curr = None
first = None
cnt = 0
for i in s:
if not first:
if a == i:
first = a
curr = b
cnt += 1
elif b == i:
first = b
curr = a
cnt += 1
elif curr == i:
curr = a if curr == b else b
cnt += 1
return cnt if curr == first else cnt - 1
for _ in range(int(input())):
s = input().strip()
mini = len(s)
for i in range(10):
for j in range(i, 10):
mini = min(mini, len(s) - solve(i, j))
print(mini)
|
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR VAR IF VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for _ in range(t):
s = input()
n = len(s)
maxx = 0
maxxs = 0
for i in range(0, 10):
maxxs = max(maxxs, s.count(str(i)))
for i in range(0, 100):
cnt = 0
y = str(i)
if len(y) == 1:
y = "0" + y
f = 0
for j in range(n):
if s[j] == y[0]:
f = 1
elif s[j] == y[1] and f == 1:
cnt += 1
f = 0
maxx = max(maxx, cnt)
print(min(len(s) - 2 * maxx, len(s) - maxxs))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
from sys import stdin
def r():
return stdin.readline().strip()
def r_t(tp):
return map(tp, r().strip().split())
def r_a(tp):
return list(r_t(tp))
def solve(t):
occur = [(0) for _ in range(10)]
for x in t:
occur[int(x)] += 1
ans = float("inf")
for x in occur:
ans = min(ans, len(t) - x)
for i in range(10):
for j in range(10):
a, b, u, cnt = str(i), str(j), "a", 0
for x in t:
if x == a and u == "a":
u = "b"
elif x == b and u == "b":
cnt += 2
u = "a"
ans = min(ans, len(t) - cnt)
return ans
def main():
cases = int(r())
for case in range(cases):
t = r()
print(solve(t))
main()
|
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING NUMBER FOR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR STRING IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
pairs = tuple((i, j) for i in range(10) for j in range(10) if i != j)
for _ in range(int(input())):
s = tuple(int(i) for i in input())
ans = []
for digit in range(10):
counter = s.count(digit)
while ans and len(s) - counter < ans[-1]:
ans.pop()
ans.append(len(s) - counter)
for pair in pairs:
flag = 0
counter = 0
for digit in s:
if pair[0] == digit and flag == 0:
flag = 1
elif pair[1] == digit and flag == 1:
flag = 0
counter += 2
while ans and len(s) - counter < ans[-1]:
ans.pop()
ans.append(len(s) - counter)
print(ans[0])
|
ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
a = input()
ans = 0
for i in range(10):
for j in range(10):
t = 0
for s in a:
if t % 2:
if int(s) == i:
t += 1
elif int(s) == j:
t += 1
if i != j:
t = t // 2 * 2
ans = max(ans, t)
print(len(a) - ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for t_ in range(t):
s = input()
best = 0
for a in range(10):
for b in range(10):
c = 0
state = 0
for n in range(len(s)):
if s[n] == str(a) and state == 0:
c += 1
state = 1
elif s[n] == str(b) and state == 1:
c += 1
state = 0
if a != b and state == 1:
c -= 1
if c > best:
best = c
print(len(s) - best)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
from sys import stdin
input = stdin.readline
def help():
stri = list(input().strip())
n = len(stri)
if n <= 2:
print(0)
return
seti = list(set(stri))
ans = 0
for i in range(10):
ans = max(ans, max(stri.count(str(i)), ans))
for a in seti:
for b in seti:
if a == b:
continue
cnt = 0
for i in range(n):
if stri[i] == a and cnt % 2 == 0:
cnt += 1
elif stri[i] == b and cnt % 2 == 1:
cnt += 1
cnt = cnt - cnt % 2
ans = max(ans, cnt)
print(n - ans)
for _ in range(int(input())):
help()
|
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for i in range(t):
st = input()
lis = []
for j in range(len(st)):
lis.append(st[j])
uni = set()
stack = []
cnt = 0
combination = []
for j in range(10):
for k in range(10):
st22 = str(j) + str(k)
combination.append(st22)
ans = 0
for k in combination:
res = 0
for kl in range(len(st)):
if st[kl] == k[0] and res % 2 == 0:
res += 1
elif st[kl] == k[1] and res % 2 == 1:
res += 1
if k[0] != k[1] and res % 2 == 1:
res -= 1
ans = max(ans, res)
print(len(st) - ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def check(a, b, string):
res = ""
cnt = 0
for s in string:
if s == a or s == b:
if s != res:
cnt += 1
res = s
if cnt % 2:
cnt -= 1
return cnt
def main():
string = str(input())
if len(set(string)) == 1:
print(0)
return
elif len(set(string)) == len(string):
print(len(string) - 2)
return
arr = {}
for x in string:
if arr.get(x) == None:
arr[x] = 1
else:
arr[x] += 1
mx = -1
for x in arr:
mx = max(mx, arr[x])
mn = -1
for x in arr:
for y in arr:
if x != y:
temp = check(x, y, string)
temp2 = check(y, x, string)
if max(temp, temp2) > mn:
mn = max(temp, temp2)
print(len(string) - max(mn, mx))
return
def test():
t = int(input())
while t:
main()
t -= 1
test()
|
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for _ in range(int(input())):
num = input()
maxLen = 2
cnt = [(0) for i in range(10)]
for d in num:
cnt[int(d)] += 1
maxLen = max(maxLen, cnt[int(d)])
for a in range(10):
for b in range(10):
pre, cur = -1, 0
for d in num:
x = int(d)
if x != pre and (x == a or x == b):
pre = x
cur += 1
maxLen = max(maxLen, cur - cur % 2)
print(len(num) - maxLen)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def fu(b):
c = 0
j = 0
for i in range(n):
if a[i] == b[j]:
c += 1
j = (j + 1) % 2
if len(set(b)) == 1:
return n - c
return n - c + j
t = int(input())
for _ in range(t):
a = input()
n = len(a)
d = list(set(a))
c = []
for i in range(len(d)):
for j in range(len(d)):
c.append(fu(str(d[i]) + str(d[j])))
print(min(c))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for i in range(int(input())):
s = input()
c = 0
for j in range(10):
for k in range(10):
a = 0
go = True
bo = False
for m in s:
x = int(m)
if x == j and go:
a += 1
go = False
bo = True
elif x == k and bo:
a += 1
go = True
bo = False
if j != k:
a -= a & 1
c = max(c, a)
print(len(s) - c)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def solution(S):
counter = [([0] * 10) for _ in range(10)]
expect_smaller = [([True] * 10) for _ in range(10)]
for i in range(10):
for j in range(10):
if i > j:
expect_smaller[i][j] = False
for s in S:
sc = int(s)
for i in range(sc):
if expect_smaller[i][sc]:
expect_smaller[i][sc] = not expect_smaller[i][sc]
counter[i][sc] += 1
if expect_smaller[sc][i]:
expect_smaller[sc][i] = not expect_smaller[sc][i]
counter[sc][i] += 1
counter[sc][sc] += 1
for i in range(sc + 1, 10):
if not expect_smaller[i][sc]:
expect_smaller[i][sc] = not expect_smaller[i][sc]
counter[i][sc] += 1
if not expect_smaller[sc][i]:
expect_smaller[sc][i] = not expect_smaller[sc][i]
counter[sc][i] += 1
mi, mj, m = 0, 0, 0
for i in range(10):
for j in range(10):
val = counter[i][j]
if i != j and val % 2 == 1:
val -= 1
if val > m:
mi, mj, m = i, j, val
return len(S) - m
t = int(input())
for i in range(t):
s = input()
print(solution(s))
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for _ in range(t):
s = input()
l = [0] * 10
for i in range(10):
l[i] = s.count(str(i))
minans = len(s) - max(l)
ans = -1
for i in range(10):
if s.find(str(i)) != -1:
last = s.find(str(i))
ll = last
for j in range(10):
last = ll
kol = 0
if s.find(str(j), last + 1) != -1:
kol = 2
last = s.find(str(j), last + 1)
ok = True
while ok:
if s.find(str(i), last + 1) != -1:
last = s.find(str(i), last + 1)
if s.find(str(j), last + 1) != -1:
last = s.find(str(j), last + 1)
kol += 2
else:
ok = False
else:
ok = False
ans = max(ans, kol)
print(min(minans, len(s) - ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def test_case():
s = input()
n = len(s)
ans = n - 2
for a in range(10):
for b in range(10):
cur = 0
want = a
for c in s:
if ord(c) - ord("0") == want:
want = b if a == want else a
else:
cur += 1
if (n - cur) % 2 == 1 and a != b:
cur += 1
ans = min(ans, cur)
print(ans)
for i in range(int(input())):
test_case()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def ip():
return int(input())
def sip():
return input()
def mip():
return map(int, input().split())
def lip():
return list(map(int, input().split()))
def matip(n, m):
lst = []
for i in range(n):
arr = lip()
lst.append(arr)
return lst
t = ip()
while t:
t -= 1
s = sip()
n = len(s)
maxx = 0
maxxs = 0
for i in range(0, 10):
maxxs = max(maxxs, s.count(str(i)))
for i in range(0, 100):
cnt = 0
y = str(i)
if len(y) == 1:
y = "0" + y
f = 0
for j in range(n):
if s[j] == y[0]:
f = 1
elif s[j] == y[1] and f == 1:
cnt += 1
f = 0
maxx = max(maxx, cnt)
print(min(len(s) - 2 * maxx, len(s) - maxxs))
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def readGenerator():
while True:
tokens = input().split(" ")
for t in tokens:
yield t
reader = readGenerator()
def readWord():
return next(reader)
def readInt():
return int(next(reader))
def readFloat():
return float(next(reader))
def readLine():
return input()
tests = readInt()
def solve(n):
return n
for t in range(0, tests):
s = readLine()
res = len(s)
for i in range(0, 10):
res = min(res, len(s) - s.count(str(i)))
for i in range(0, 10):
for j in range(0, 10):
p = str(i) + str(j)
f = 0
for v in s:
if v == p[f % 2]:
f += 1
res = min(res, len(s) - 2 * (f // 2))
print(res)
|
FUNC_DEF WHILE NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR EXPR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for t in range(int(input())):
alpha = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
s = input()
ans = 10**6
for c1 in alpha:
for c2 in alpha:
l = []
count = 0
for i in range(len(s)):
if s[i] == c1 and count == 0:
l.append(i)
count = 1
elif s[i] == c2 and count == 1:
l.append(i)
count = 0
if len(l) % 2 == 0:
ans = min(ans, len(s) - len(l))
elif c1 != c2:
ans = min(ans, len(s) - len(l) + 1 * (len(l) != 1))
else:
ans = min(ans, len(s) - len(l))
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def solve(s):
n = len(s)
ans = 1000000
for i in range(10):
d = 0
for j in s:
if j == str(i):
d += 1
ans = min(ans, n - d)
for j in range(10):
if i == j:
continue
p = str(i) + str(j)
k = 0
for l in range(n):
if s[l] == p[k % 2]:
k += 1
v = k // 2 * 2
ans = min(ans, n - v)
return ans
for _ in range(int(input())):
print(solve(input()))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for _ in range(t):
s = input()
n = len(s)
ans = n
for i in range(10):
cnt = 0
for c in s:
if int(c) == i:
cnt += 1
ans = min(ans, n - cnt)
for c1 in range(10):
for c2 in range(10):
if c1 != c2:
length = 0
findc1 = True
for c in s:
if findc1 == True and int(c) == c1:
findc1 = False
elif findc1 == False and int(c) == c2:
length += 2
findc1 = True
ans = min(ans, n - length)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR 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 VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for __ in range(int(input())):
ar = list(map(int, input()))
kek = [[] for i in range(10)]
i = 0
for elem in ar:
kek[elem].append(i)
i += 1
ans = 0
for i in range(10):
z = 0
fifi = [0] * 10
while z < len(kek[i]) - 1:
lol = set()
for j in range(kek[i][z] + 1, kek[i][z + 1]):
lol.add(ar[j])
for elem in lol:
fifi[elem] += 1
z += 1
for j in range(10):
flag = 0
if kek[i]:
for z in range(kek[i][0]):
if ar[z] == j:
flag = 2
ans = max(ans, fifi[j] * 2 + flag, len(kek[i]))
print(len(ar) - ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for _ in range(t):
s = str(input())
if s[-1] + s[: len(s) - 1] == s[1:] + s[0]:
print(0)
continue
s = [x for x in s]
a = "0123456789"
d = {(x + y): [False, 0] for x in a for y in a}
for i, x in enumerate(s):
for y in a:
z = x + y
if not d[z][0]:
d[z][0] = True
d[z][1] += 1
z = y + x
if d[z][0]:
d[z][0] = False
d[z][1] += 1
ans = 0
for x in a:
d[x + x][1] //= 2
for x in d.keys():
if x[0] == x[1]:
ans = max(ans, d[x][1])
else:
ans = max(ans, int(d[x][1] // 2) * 2)
print(int(len(s) - ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR VAR LIST NUMBER NUMBER VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def solution():
s = list(input())
ans = 0
for i in range(10):
for j in range(10):
x = 0
cnt = 0
for k in s:
if x == 0 and str(i) == k:
x = 1 - x
cnt += 1
elif x == 1 and str(j) == k:
x = 1 - x
cnt += 1
if cnt % 2 == 0 or i == j:
ans = max(ans, cnt)
print(len(s) - ans)
t = int(input())
for _ in range(t):
solution()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def find_path(al, bl):
len_path = 0
az = bz = 0
an, bn = len(al), len(bl)
want_a = True
ap = bp = -1
while True:
if want_a:
for i in range(az, an):
if al[i] > bp:
len_path += 1
ap = al[i]
az = i
want_a = False
break
if want_a:
return len_path
else:
for i in range(bz, bn):
if bl[i] > ap:
len_path += 1
bp = bl[i]
bz = i
want_a = True
break
if not want_a:
return len_path
def main():
t = int(input())
for _ in range(t):
s = input()
n = len(s)
freq = {}
M = 0
for i in range(n):
if s[i] not in freq:
freq[s[i]] = [i]
else:
freq[s[i]].append(i)
for ca in "0123456789":
if ca not in freq:
continue
for cb in "0123456789":
if cb not in freq:
continue
len_path = find_path(freq[ca], freq[cb])
if len_path % 2 != 0:
len_path -= 1
M = max(M, len_path)
max_freq = 0
for val in freq.values():
max_freq = max(max_freq, len(val))
print(min(n - 2, n - max_freq, n - M))
main()
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR STRING IF VAR VAR FOR VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
z = "0123456789"
for _ in range(int(input())):
s = input()
n = len(s)
m = 0
for i in z:
for j in z:
c = 0
for k in range(n):
if s[k] == i and c % 2 == 0:
c += 1
elif s[k] == j and c % 2 == 1:
c += 1
if i != j and c % 2 == 1:
c -= 1
if c > m:
m = c
print(n - m)
|
ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
def solver(a, b):
result = 0
for elem in s:
if elem == a:
result += 1
a, b = b, a
if result % 2 != 0 and a != b:
result -= 1
return result
for _ in range(int(input())):
s = input()
m, answer = 0, 0
for i in range(10):
for j in range(10):
answer = max(answer, solver(str(i), str(j)))
print(len(s) - answer)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
t = int(input())
for _ in range(t):
A = str(input())
A = list(A)
A = [int(s) for s in A]
ans = 10000007
for i in range(10):
for j in range(10):
c = 0
d = 0
for k in range(len(A)):
if c % 2 == 0:
if A[k] == i:
c += 1
else:
d += 1
elif A[k] == j:
c += 1
else:
d += 1
if c % 2 == 0:
ans = min(ans, d)
elif i == j:
ans = min(ans, d)
else:
ans = min(ans, d + 1)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$.
Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$.
Let's say string $t$ is good if its left cyclic shift is equal to its right cyclic shift.
You are given string $s$ which consists of digits 0–9.
What is the minimum number of characters you need to erase from $s$ to make it good?
-----Input-----
The first line contains single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Next $t$ lines contains test cases — one per line. The first and only line of each test case contains string $s$ ($2 \le |s| \le 2 \cdot 10^5$). Each character $s_i$ is digit 0–9.
It's guaranteed that the total length of strings doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the minimum number of characters you need to erase from $s$ to make it good.
-----Example-----
Input
3
95831
100120013
252525252525
Output
3
5
0
-----Note-----
In the first test case, you can erase any $3$ characters, for example, the $1$-st, the $3$-rd, and the $4$-th. You'll get string 51 and it is good.
In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.
In the third test case, the given string $s$ is already good.
|
for s in range(int(input())):
string = input()
store = [(0) for i in range(10)]
add = 0
for i in string:
add += 1
store[int(i)] += 1
store.sort()
maxi, plus, flag = 9999999999, add, 1
a = store[-1]
for i in range(10):
for j in range(10):
add, flag = 0, 1
for k in range(plus):
if int(string[k]) == i and flag == 1:
add += 1
flag = 0
elif int(string[k]) == j and flag == 0:
add += 1
flag = 1
if add % 2 == 1:
add -= 1
maxi = min(maxi, plus - add)
maxi = min(maxi, plus - a)
print(maxi)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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.