Harryxun/stf_run huggingface dataset:
N = int(input())
A = list(map(int, input().split()))

# N = 5
# A = [1, 1, 2, 1, 2]

Aset = set(A)
lst = {}
for i in Aset:
    lst[i] = 0

# print(lst)
    
for i in range(N):
    lst[A[i]] += 1

# print(lst)
# c = dict(lst) # c = dict(lst)で異なるオブジェクトとして等価なcを定義
              # c = lst だと、同一のオブジェクトとなってしまう？

for i in lst:
#     print('i: {}'.format(i))
    c[i] = 0
    tmp_lst = dict(lst)
#     print('tmp_lst {}'.format(tmp_lst))
#     print('tmp_lst[i]: {}'.format(tmp_lst[i]))
    tmp_lst[i] -= 1
#     print('tmp_lst[i]: {}'.format(tmp_lst[i]))
    for j in tmp_lst:
#         print(tmp_lst[j])
        c[i] += tmp_lst[j]*(tmp_lst[j]-1)//2
#         print('c[i]: {}'.format(c[i]))
        
for i in range(N):
    print(c[A[i]])

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

Aset = set(A)
lst = {}
for i in Aset:
    lst[i] = 0
    
for i in range(N):
    lst[A[i]] += 1

llst = dict(lst) # llst は、valueが1のものを消したリスト
for i in lst:
    if lst[i] == 1:
        llst.pop(i)

c = dict(lst) # c は keyの値である場合の組み合わせの数。
              # c = dict(lst)で異なるオブジェクトとして等価なcを定義
              # c = lst だと、同一のオブジェクトとなってしまう？
c_all = 0
for j in llst:
    c_all += llst[j]*(llst[j]-1)//2

# print('c_all:{}'.format(c_all))
for i in lst:
#     print('i:{}'.format(i))
#     print('lst[i]:{}'.format(lst[i]))
    c[i] = c_all
    c[i] = c[i] - lst[i]*(lst[i]-1)//2 + (lst[i]-1)*(lst[i]-2)//2
        
for i in range(N):
    print(c[A[i]])
while True:
	try:
		code = [raw_input() for _ in range(8)]
	except EOFError:
		break
	
	code = "".join(code)
	
	check = 0
	for var in range(0, len(code)):
		if int(code[var:var+1]) == 1:
			check = var
			break
	
	if int(code[check+1:check+2]) == 1 and int(code[check+8:check+9]) == 1:
			if int(code[check+9:check+10]) == 1:
				print "A"
			if int(code[check+7:check+8]) == 1:
				print "G"
	elif int(code[check+1:check+2]) == 1:
		if int(code[check+2:check+3]) == 1 and int(code[check+3:check+4]) == 1:
			print "C"
		if int(code[check+9:check+10]) == 1 and int(code[check+10:check+11]) == 1:
			print "E"
	elif int(code[check+8:check+9]) == 1:
		if int(code[check+16:check+17]) == 1 and int(code[check+24:check+25]) == 1:
			print "B"
		if int(code[check+7:check+8]) == 1 and int(code[check+15:check+16]) == 1:
			print "D"
		if int(code[check+9:check+10]) == 1 and int(code[check+17:check+18]) == 1:
			print "F"

### FIXED CODE ###

while True:
	surface = [list(raw_input()) for _ in range(0, 8)]

	surf = []
	for i in range(0, 8):
		if "1" in surface[i]:
			surf.append(surface[i])
	
	if len(surf) == 1 : print "C"
	else:
		if len(surf) == 2:
			x = surf[0].index("1")
			y = surf[1].index("1")
			if x - y == 0    : print "A"
			elif x - y == -1 : print "E"
			elif x - y ==  1 : print "G"
		elif len(surf) == 3:
			x = surf[0].index("1")
			y = surf[1].index("1")
			if x - y ==   1 : print "D"
			elif x - y == 0 : print "F"
		elif len(surf) == 4 : print "B"
		
	try:
		raw_input()
	except EOFError:
		break
a,b,h,m = map(int,input().split())
import math
mi = 360*(((60*h + m) % 60) / 60)
hour = 360*(((60*h + m) % 720) / 720)
print(hour)
print(mi)
cos = 0
ans = 0
if hour > mi:
	cos = math.cos(math.radians(hour - mi))
	ans = (a**2 + b**2 - 2*a*b*cos)**0.5
elif hour == mi:
	ans = 0
elif hour +180 > mi:
	cos = math.cos(math.radians(mi - hour))
	ans = (a**2 + b**2 - 2*a*b*cos)**0.5
elif hour + 180 == mi:
	ans = a + b
elif hour + 180 < mi:
	cos.hour = math.cos(math.radians(hour - mi + 360))
	ans = (a**2 + b**2 - 2*a*b*cos)**0.5
print(cos)
print(ans)

### FIXED CODE ###

import math
a,b,h,m = map(int,input().split())

ans = 0
cos = 0
mi = m/60 * 360 #分針の角度
hour = (60*h + m)/720 * 360 #時針の角度

cos = math.cos(math.radians(hour - mi))
ans = a*a + b*b -2*a*b*cos
#余弦定理
ans = ans ** (1/2)
print(ans)
print("NO")

### FIXED CODE ###

x=int(input())
iwai=[7,5,3]

if x in iwai:
  print("YES")
else:
  print("NO")
N=int(input())
S=list(input())
T=list(input())
state=[]
lim=1000000007
i=0
while i<=N:
    if S[i] == T[i]:
        state.append(0)
        i+=1
    else:
        state.append(1)
        i+=2
ans=3    
for i in range(1,len(state)):
    if state[i] == 1 and state[i-1] == 1:
        ans = (ans * 3) % lim
    elif state[i] == 1 and state[i-1] == 0:
        ans = (ans * 2) % lim
    elif state[i] == 0 and state[i-1] == 1:
        pass
    elif state[i] == 0 and state[i-1] == 0: 
        ans = (ans * 2) % lim
print(ans)

### FIXED CODE ###

N=int(input())
S=list(input())
T=list(input())
state=[]
lim=1000000007
i=0
while i<N:
    if S[i] == T[i]:
        state.append(0)
        i+=1
    else:
        state.append(1)
        i+=2
if state[0]==0:
    ans=3
else:
    ans=6
for i in range(1,len(state)):
    if state[i] == 1 and state[i-1] == 1:
        ans = (ans * 3) % lim
    elif state[i] == 1 and state[i-1] == 0:
        ans = (ans * 2) % lim
    elif state[i] == 0 and state[i-1] == 1:
        pass
    elif state[i] == 0 and state[i-1] == 0: 
        ans = (ans * 2) % lim
print(ans)
def partition(a, p, r):
    x = a[r]
    i = p - 1
    for j in range(p, r):
        if a[j] <= x:
            i += 1
            tmp = a[i]
            a[i] = a[j]
            a[j] = tmp
    tmp = a[i+1]
    a[i+1] = a[r]
    a[r] = tmp
    return i + 1


def quick_sort(a, p, r):
    if p < r:
        q = partition(a, p, r)
        quick_sort(a, p, q-1)
        quick_sort(a, q+1, r)


def make_cyclic(w, v):
    flags = [True] * len(w)

    cyclics = []
    for i in range(len(w)):
        if flags[i]:
            flags[i] = False
            cycle = [w[i]]
            now = w[i]
            while True:
                j = v.index(now)
                if j == i:
                    break
                cycle.append(w[j])
                now = w[j]
                flags[j] = False
            cyclics.append(cycle)

    return cyclics


def min_cost_sort(w):
    v = w.copy()
    quick_sort(v, 0, len(v) - 1)

    cyclics = make_cyclic(w, v)

    ans = 0
    for cycle in cyclics:
        inner_cycle = min(cycle) * (len(cycle) - 2) + sum(cycle)
        outer_cycle = min(cycle) + min(set(w) - set(cycle)) * (len(cycle) + 1) + sum(cycle)
        ans += min(inner_cycle, outer_cycle)

    return ans

n = int(input())
w = [int(x) for x in input().split()]

print(min_cost_sort(w))


### FIXED CODE ###

def make_cyclic(w, v):
    flags = [True] * len(w)

    cyclics = []
    for i in range(len(w)):
        if flags[i]:
            flags[i] = False
            cycle = [w[i]]
            now = w[i]
            while True:
                j = v.index(now)
                if j == i:
                    break
                cycle.append(w[j])
                now = w[j]
                flags[j] = False
            cyclics.append(cycle)

    return cyclics


def min_cost_sort(w):
    v = w.copy()
    v.sort()

    cyclics = make_cyclic(w, v)

    ans = 0
    for cycle in cyclics:
        inner_cycle = min(cycle) * (len(cycle) - 2) + sum(cycle)
        if len(set(w) - set(cycle)) >= 1:
            outer_cycle = min(cycle) + min(set(w) - set(cycle)) * (len(cycle) + 1) + sum(cycle)
        else:
            outer_cycle = inner_cycle + 1
        ans += min(inner_cycle, outer_cycle)

    return ans


n = int(input())
w = [int(x) for x in input().split()]

print(min_cost_sort(w))
n,m=map(int,input().split())
flag=false
one = []
enu = []
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    one.append(b)
  elif b==n:
    enu.append(a)

for i in one:
  if i in enu:
    flag=true

if flag: print('POSSIBLE')
else: print('IMPOSSIBLE')
    

### FIXED CODE ###

n,m=map(int,input().split())
li = []
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    li.append(b)
  elif b==n:
    li.append(a)

if len(set(li))==len(li): print('IMPOSSIBLE')
else: print('POSSIBLE')
n, k = map(int, input().split())
while n > abs(n - k):
    n = abs(n - k)
print(n)

### FIXED CODE ###

a, b, c = map(int, input().split(" "))
print(c, a, b)
N = int(input())
C = []
S = []
F = []
for i in range(N-1) :
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(N) :
    if j == N-1 :
        print(0)
    else :
        ans = 0
        for j in range(i,N-1) :
            if ans < S[j] :
                ans = S[j]
            if ans % F[j] != 0 :
                ans = (ans//F[k]-1)*F[k]
            ans += C[k]
        print(ans)


### FIXED CODE ###

N = int(input())
C = []
S = []
F = []
for i in range(N-1) :
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for j in range(N) :
    if j != N-1 :
        answer = 0
        for k in range(j,N-1) :
            if answer < S[k] :
                answer = S[k]
            if answer % F[k] != 0 :
                answer = (answer // F[k] + 1) * F[k]
            answer += C[k]
        print(answer)
    else :
        print(0)
def dfs(s):
    if int(s)>n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs('0'))


### FIXED CODE ###

n = int(input())

def dfs(s):
    if int(s)>n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs('0'))
N, X, Y = input().split()
N = int(N)
X = int(X)
x = X - 1
Y = int(Y)
y = Y -1
ans = []
A = [[0] * N for _ in range(N)]
for i in range(N):
    for j in range(N-i):
        path = min(abs(x- i) +1 +abs(y-i-j),j)
        ans[path] += 1
print(*ans, sep="\n")




### FIXED CODE ###


N, X, Y = input().split()
N = int(N)
X = int(X)
x = X - 1
Y = int(Y)
y = Y -1
ans = [0] * (N)
A = [[] * N for _ in range(N)]
for i in range(N):
    for j in range(N-i):
        path = min(abs(x- i) +1 +abs(y-i-j),j)
        ans[path] += 1
for _ in range(len(ans)):
    if _ == 0:
        continue
    print(ans[_])
from collections import defaultdict
def solve():
    N = int(input())
    d = defaultdict(int)

    for _ in range(N):
        S = input()
        d[S] += 1

    items = list(d.items())
    items.sort(key=lambda x:x[1], reverse=True)
    mx = items[0][1]
    cand = []
    for item in items:
        if item[1] == mx:
            cand.append(item[0])
        else:
            break
    
    print(*ans, sep='\n')
    
if __name__ == '__main__':
    solve()

### FIXED CODE ###

def solve():
    N = int(input())
    dict = {}

    for _ in range(N):
        S = input()
        if S in dict:
            dict[S] += 1
        else:
            dict[S] = 1
    sorted_dict = list(sorted(dict.items(), key=lambda x:x[1], reverse=True))
    mx = sorted_dict[0][1]
    cand = []
    for d in sorted_dict:
        if d[1] == mx:
            cand.append(d[0])
        else:
            break
    print(*sorted(cand), sep='\n')
    
if __name__ == '__main__':
    solve()
n = int(input())
t, a = map(int, input().split())
h = list(abs(t-0.006*int(x)-a), t for x, t in zip(input().split(), range(n)))
k = min(h)
print(k[1])

### FIXED CODE ###

n = int(input())
t, a = map(int, input().split())
h = list((abs(t-0.006*int(x)-a), s) for x, s in zip(input().split(), range(n)))
k = min(h)
print(k[1]+1)
n, k = map(int, input().split())
ans = []
for _ in range(k):
    d = list(int(input()))
    a = list(map(int, input().split()))
    ans += a
print(n-len(set(ans)))

### FIXED CODE ###

n, k = map(int, input().split())
ans = []
for _ in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    ans += a
print(n-len(set(ans)))
import random
import copy

def get_population():
    population = []
    for i in range(individual_length):
        population.append([random.randint(0,1) for j in range(gene_length)])
    return population

def evaluate(pop):
    pop.sort(reverse=True)
    return pop

def two_point_crossover(parent1, parent2):
    r1 = random.randint(0, gene_length-1)
    r2 = random.randint(r1, gene_length-1)
    child = copy.deepcopy(parent1)
    child[r1:r2] = parent2[r1:r2]
    return child

def mutate(parent):
    r = random.randint(0, gene_length-1)
    child = copy.deepcopy(parent)
    child[r] = 1 if child[r]==0 else 0
    return child

def fitness(pop):
    value = 0
    weoght = 0
    for i in range(N):
        if pop[i]:
            value += L[i][1]
            weoght += L[i][0]
    if weoght <= W:
        return value
    else:
        return 0

N,W = [int(zz) for zz in input().split()]
L = [[0,0] for _ in range(N)]

for i in range(N):
    p,q = [int(zz) for zz in input().split()]
    L[i][0] = p
    L[i][1] = q

gene_length = N # 遺伝子長
individual_length = 30 # 個体数
generation = 1000 # 世代数
elite_rate = 0.2 # エリート選択の割合

pop = evaluate([(fitness(p), p) for p in get_population()])

for i_episode in range(generation):

    eva = evaluate(pop)
    elites = eva[:int(len(pop)*elite_rate)]

    pop = elites
    while len(pop) < individual_length:
        if random.random() < mutate_rate:
            m = random.randint(0, len(elites)-1)
            child = mutate(elites[m][1])
        else:
            m1 = random.randint(0, len(elites)-1)
            m2 = random.randint(0, len(elites)-1)
            child = two_point_crossover(elites[m1][1], elites[m2][1])
        pop.append((fitness(child), child))

eva = evaluate(pop)
print(pop[0][0])


### FIXED CODE ###

n,k = [int(i) for i in input().split()]
w = []
v = []
for _ in range(n):
    a,b = [int(i) for i in input().split()]
    w.append(a)
    v.append(b)

dp = [[0 for _ in range(k+1)] for _ in range(n+1)]

for i in range(n):
    for j in range(k+1):
        if j >= w[i]:
            dp[i+1][j] = max(dp[i][j-w[i]]+v[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[-1][-1])
n = int(input())
s = [input() for i in range(n)]
s.sort()
from collections import Counter
s1 = collections.Counter(s)
s2 = list(set(s))
s2.sort()
for i in range(len(s2)):
    if s1[s2[i]] == max(s1.values()):
        print(s2[i])

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
from collections import Counter
s1 = Counter(s)
max_s = max(s1.values())
ans = []
for k,v in s1.items(): 
    if v == max_s:
        ans.append(k)
ans.sort()
for a in ans:
    print(a)
n = int(input())
pp = list(input())
cnt = 0
lis = []
for i in range(n):
    for j in range(i):
        if pp[j] == "E":
            cnt += 1
    for k in range(i+1,n):
        if pp[k] =="W":
            cnt += 1
    lis.apped(cnt) 
    cnt = 0
print(min(lis))


### FIXED CODE ###

n = int(input())
pp = list(input())
cnt = 0
lis = [0]*n
w = [0]*n
e = [0]*n
if pp[0] =="W":
    w[0] =1
else:
    e[0] =1
for i in range(1,n):
    if pp[i] == "W":
        w[i] = w[i-1]+1
        e[i] = e[i-1]

    else:
        e[i] = e[i-1]+1
        w[i] = w[i-1]
for i in range(1,n):
    lis[i] = w[i-1]+e[n-1]-e[i]
lis[0] = e[n-1]-e[0]

print(min(lis))
X, Y = map(int, input().split())
if Y % 2 == 0 and Y <= 4*X and Y >= 2*X:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

x = list(map(int, input().split()))
for i in range(len(x)):
    if x[i] == 0:
        print(i + 1)
import collections

n = int(input())
a = [list(input() for i in range(n))]
b = collections.Counter(a)
print(len(b))


### FIXED CODE ###

import collections

n = int(input())
a = [input() for i in range(n)]
b = collections.Counter(a)
print(len(b))
import numpy as np
import matplotlib.pyplot as plt

inpt = input()
inpt_list = inpt.split(" ")
X, K, D = [int(x) for x in inpt_list]

X_abs = np.abs(X)
num = X_abs // D
rem = K - num
if rem < 0:
    out = X_abs - D*K
else:
    if rem%2==0:
        out = X_abs - num*D
    else:
        out = np.abs(X_abs - num*D - D)
print(out)

### FIXED CODE ###

import numpy as np

inpt = input()
inpt_list = inpt.split(" ")
X, K, D = [int(x) for x in inpt_list]

X_abs = np.abs(X)
num = X_abs // D
rem = K - num
if rem < 0:
    out = X_abs - D*K
else:
    if rem%2==0:
        out = X_abs - num*D
    else:
        out = np.abs(X_abs - num*D - D)
print(out)
S_1,S_2,S_3 = input().split()
if S_1 == S_2 && S_2 == S_3:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

S = input()
if S == "AAA" or S == "BBB":
  print("No")
else:
  print("Yes")
import fractions
t=1
for i in range(int(input())):
    s = int(input())
    t = t*s//fractions.gcd(s,t)
print(t)

### FIXED CODE ###

N = input()
print (["No","Yes"][N[0] == N[2]])
N = int(input())
A = list(map(int, input().split()))
count = 0
for i in A:
    count ^= x
for i in range(len(A)):
    A[i] ^= count
    
    
    
print(*A)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
count = 0
for i in A:
    count ^= i
for i in range(len(A)):
    A[i] ^= count
    
    
print(*A)
S = input()
Q = int(input())
flg = 0
for i in range(Q):
    A = list(input().split())
    if int(A[0]) == 1 and flg == 0:
        flg = 1
        continue
    elif int(A[0]) == 1 and flg == 1:
        flg = 0
        continue
    if int(A[1]) == 1:
        if flg == 0:
            S.insert(0,A[2])
        else:
            S.append(A[2])
    else:
        if flg == 0:
            S.append(A[2])
        else:
            S.insert(0,A[2])
if flg == 0:
    print(S)
if flg == 1:
    print(S[::-1])

### FIXED CODE ###

S = input()
Q = int(input())
flg = 0
senntou = ''
ushiro = ''
for i in range(Q):
    A = list(input().split())
    if int(A[0]) == 1 and flg == 0:
        flg = 1
        continue
    elif int(A[0]) == 1 and flg == 1:
        flg = 0
        continue
    if (int(A[1]) == 1 and flg == 0) or (int(A[1]) == 2 and flg == 1):
        senntou = A[2] + senntou
    else:
        ushiro = ushiro + A[2]
if flg == 0:
    print(senntou + S + ushiro)
if flg == 1:
    print(ushiro[::-1] + S[::-1] + senntou[::-1])
a, b, c = map(int, input().split())
a = b
a = c
print(a b c)

### FIXED CODE ###

a, b, c = map(int, input().split())
print(c,a,b)
n=int(input())
t=[int(input()) for _ in range(n)]
if n//min(t)<1:
    n//min(t)=1
print(n//min(t) +4)

### FIXED CODE ###

n=int(input())
t=[int(input()) for _ in range(5)]
k=(n-1)//min(t)
print(k+5)
import sys
sys.setrecursionlimit(100000)


def process():
    for data in get_dataset():
        H = int(data)
        W = int(data[0])
        field = create_field(H, W)
        print search(H, W, data, field)


def search(H, W, data, field):
    count = 0
    for i in xrange(H):
        for j in xrange(W):
            if field[i][j] == 0:
                continue
            _search(i, j, H, W, data[i][j], data, field)
            count += 1
    return count


def _search(i, j, H, W, cell, data, field):
    field[i][j] = 0
    for a in xrange(i-1, i+2):
        if -1 < a < H:
            pass
        else:
            continue
        for b in xrange(j-1, j+2):
            if -1 < b < W:
                pass
            else:
                continue

            if a != i and b != j:
                continue

            if field[a][b] == 0:
                continue
            if cell == data[a][b]:
                _search(a, b, H, W, cell, data, field)
    return


def create_field(H, W):
    field = []
    for i in xrange(H):
        raw = []
        for j in xrange(W):
            raw.append(1)
        field.append(raw)
    return field


def get_dataset():
    dataset = []
    while True:
        data = get_data()
        if data:
            dataset.append(data)
        else:
            break
    return dataset


def get_data():
    line = raw_input().rstrip().split()
    H = int(line[0])
    data = []
    for i in xrange(H):
        data.append(raw_input().rstrip())
    zero = raw_input()
    return data

process()

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)


def main():
    solve()


def solve():
    for data in get_dataset():
        print search(data)


def search(data):
    count = 0
    H = len(data)
    W = len(data[0])
    for i in xrange(H):
        for j in xrange(W):
            if data[i][j] == '.':
                continue
            _search(i, j, H, W, data[i][j], data)
            count += 1
    return count


def _search(i, j, H, W, cell, data):
    data[i][j] = '.'
    for a in xrange(i-1, i+2):
        if not -1 < a < H:
            continue
        for b in xrange(j-1, j+2):
            if not -1 < b < W:
                continue

            if a != i and b != j:
                continue

            if data[a][b] == '.':
                continue

            if cell == data[a][b]:
                _search(a, b, H, W, cell, data)
    return


def get_dataset():
    dataset = []
    while True:
        line = raw_input().rstrip().split()
        H = int(line[0])
        if H == 0:
            break

        data = []
        for i in xrange(H):
            data.append(list(raw_input().rstrip()))
        dataset.append(data)
    return dataset


if __name__ == '__main__':
    main()
s=input()
list=[a,b,c,d,e,f]
if list[c]==list[d] or list[e]==list[f]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s=input()
if s[2]==s[3] and s[4]==s[5]:
  print("Yes")
else:
  print("No")
import sys
input = sys.stdin.readline

# A - Digit Sum 2
def digit_sum(str_num):
	sum = 0	
	
	for i in range(len(str_num)):
		sum += int(str_num[i])
	
	return sum


N = input()
patterns = [N]

for i in range(len(N)-1):
	if N[i] != '0':
		left, right = '', ''  
				
		if i > 0:
			left = N[:i]
		
		n = int(N[i]) - 1
		
		if i < len(N) - 1:
			right = '9' * (len(N)-i-1) 
		
		patterns.append(left + str(n) + right)

ans = 0

for p in patterns:
	ans = max(ans, digit_sum(p))
	
print(ans)

### FIXED CODE ###

import sys
#input = sys.stdin.readline

# A - Digit Sum 2
def digit_sum(str_num):
	sum = 0	
	
	for i in range(len(str_num)):
		sum += int(str_num[i])
	
	return sum


N = input()
patterns = [N]

for i in range(len(N)-1):
	if N[i] != '0':
		left, right = '', ''  
				
		if i > 0:
			left = N[:i]
		
		n = int(N[i]) - 1
		
		if i < len(N) - 1:
			right = '9' * (len(N)-i-1) 
		
		patterns.append(left + str(n) + right)

ans = 0

for p in patterns:
	ans = max(ans, digit_sum(p))
	
print(ans)
s = input()
data = []
for i in s:
    data.append(int(i))
one = 0
zero = 0
for i in range(len(data))
    if i == 0:
        zero += 1
    else:
        one += 1
print(min(zero, one))

### FIXED CODE ###

s = input()
data = []
for i in s:
    data.append(int(i))
one = 0
zero = 0
for i in range(len(data)):
    if data[i] == 0:
        zero += 1
    else:
        one += 1

print(min(zero, one) * 2)
import sys
def f(x):
    return x[1:],x[0]
x=input()
y=input()
z=input()
k='a'
while 1:
    if k=='a':
        if x=='':
            print('A')
            sys.exit()
        else:
            x,k=f(x)
    if k=='b':
        if y=='':
            print('B')
            sys.exit()
        else:
            z,k=f(z)
    if k=='c':
        if z=='':
            print('C')
            sys.exit()
        else:
            z,k=f(z)

### FIXED CODE ###

import sys
def f(x):
    return x[1:],x[0]
a=input()
b=input()
c=input()
y='a'
while 1:
    if y=='a':
        if a=='':
            print('A')
            sys.exit()
        else:
            a,y=f(a)
    if y=='b':
        if b=='':
            print('B')
            sys.exit()
        else:
            b,y=f(b)
    if y=='c':
        if c=='':
            print('C')
            sys.exit()
        else:
            c,y=f(c)
N = input()
if len(N) == 3:
    print(::-1)
else:
    print(N)

### FIXED CODE ###

N = input()
if len(N) == 3:
    print(N[::-1])
else:
    print(N)
print(1100-int(input())

### FIXED CODE ###

print(1110-int(input()))