Harryxun/stf_run huggingface dataset:
import sys
sys.setrecursionlimit(4100000)
N, M = map(int, input().split())
A = list(map(int, input().split()))
b = []
for i in range(M):
    b.append(list(map(int, input().split())))
ans = 0
A.sort()
b.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(M):
    if b[i][1] <= A[j] or j == N:
        break
    while j < N and b[i][0] and b[i][1] > A[j]:
        ans += b[i][1]
        b[i][0] -= 1
        j += 1
print(ans + sum(A[j:]))

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
b = []
for i in range(M):
    b.append(list(map(int, input().split())))
ans = 0
A.sort()
b.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(M):
    if j >= N or b[i][1] <= A[j]:
        break
    while j < N and b[i][0] and b[i][1] > A[j]:
        ans += b[i][1]
        b[i][0] -= 1
        j += 1
if j >= N:
    print(ans)
else:
    print(ans + sum(A[j:]))
A, B = map(int, input().split())
input_list = input().split( )

input_sum = sum(input_list)

if(A <= input_sum):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

A, B = map(int, input().split())
input_list = input().split( )

for i in (range(len(input_list))):
  input_list[i] = int(input_list[i])

input_sum = sum(input_list)

if(A <= input_sum):
  print("Yes")
else:
  print("No")
N = int(input())
A=list(map(int,input().split()))
A.sort()
Q = int(input())
BC = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*BC)]
sum=0
D=[0]*(10**5)
for i in range(N):
    sum+=A[i]
    D[A[i]]+=1
for i in range(Q):
    D[C[i]]+=D[B[i]]
    sum+=D[B[i]]*(C[i]-B[i])
    D[B[i]]=0
    print(sum)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
N = int(input())
A=list(map(int,input().split()))
Q = int(input())
BC = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*BC)]
sum=0
D=[0]*(10**5+1)
for i in range(N):
    sum+=A[i]
    D[A[i]]+=1
for i in range(Q):
    D[C[i]]+=D[B[i]]
    sum+=D[B[i]]*(C[i]-B[i])
    D[B[i]]=0
    print(sum)
i = 0
while 1:
   x = raw_input()
   i = i +1
   if x == '0': 
     break
   print "Case %s: %s" % (i,x)
  

### FIXED CODE ###

i = 0
while 1:
   x = int(raw_input())
   i = i + 1
   if x == 0:
      break
   print 'Case %s: %s' %(i, x)
n, m = map(int, input().split())
par = [-1] * n  # 親だった場合は-(その集合のサイズ)


# xがどのグループに属しているか調べる
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return find(par[x])


# 自分のいるグループの数
def size(x):
    return -par[find(x)]


# xとyの属する集合を併合
def unite(x, y):
    # 根を探す
    x, y = find(x), find(y)

    # 根が一緒
    if x == y:
        return

    # 大きい方に小さい方をくっつける
    if size(x) < size(y):
        x, y = y, x

    # xのサイズを更新
    par[x] += par[y]
    # yの親をxにする
    par[y] = x


# 同じ集合に属するか判定
def same(x, y):
    return find(x) == find(y)


bridges = [list(map(int, input().split())) for _ in range(m)]
bridges.reverse()
huben = n * (n - 1) // 2
ans = []

for i in range(m):
    ans.append(huben)
    a, b = bridges[i]
    a, b = a - 1, b - 1
    if same(a, b):
        continue
    else:
        huben -= size(a) * size(b)
        unite(a, b)
ans = ans.reverse()
for i in range(m):
    print(ans[i])


### FIXED CODE ###

n, m = map(int, input().split())
par = [-1] * n  # 親だった場合は-(その集合のサイズ)


# xがどのグループに属しているか調べる
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return find(par[x])


# 自分のいるグループの数
def size(x):
    return -par[find(x)]


# xとyの属する集合を併合
def unite(x, y):
    # 根を探す
    x, y = find(x), find(y)

    # 根が一緒
    if x == y:
        return

    # 大きい方に小さい方をくっつける
    if size(x) < size(y):
        x, y = y, x

    # xのサイズを更新
    par[x] += par[y]
    # yの親をxにする
    par[y] = x


# 同じ集合に属するか判定
def same(x, y):
    return find(x) == find(y)


bridges = [list(map(int, input().split())) for _ in range(m)]
bridges.reverse()
huben = n * (n - 1) // 2
ans = []
for i in range(m):
    ans.append(huben)
    a, b = bridges[i]
    a, b = a - 1, b - 1
    if same(a, b):
        continue
    else:
        huben -= size(a) * size(b)
        unite(a, b)
ans = ans[::-1]
for i in range(m):
    print(ans[i])
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
ct=0
for i in range(n):
  if i+1!=P[i]:
    ct+=1
print("YES" if ct<=2 else "NO")

### FIXED CODE ###

n=int(input())
P=[int(i) for i in input().split()]
ct=0
for i in range(n):
  if i+1!=P[i]:
    ct+=1
print("YES" if ct<=2 else "NO")
A, B, C = map(int, input().split)
if (A == B or A == C or C == B) and (A != B or A != C or B != C):
	print('Yes')
else:
	print("No")

### FIXED CODE ###

A = 0
B = 0
c = 0
A, B, C = map(int, input().split())
if (A == B or A == C or C == B) and (A != B or A != C or B != C):
	print('Yes')
else:
	print("No")
def compare_cards(a, b):
    return a[1] < b[1]

def bubble(C):
    for i in range(len(C)):
        for j in range(len(C) - 1, i, -1):
            if compare_cards(C[j], C[j - 1]):
                C[j], C[j - 1] = C[j -1], C[j]

N = int(input())
C = input().split()

bubbleC = C.copy()

bubble(bubbleC)
print(*C)

### FIXED CODE ###

def compare_cards(a, b):
    return a[1] < b[1]

def bubble(C):
    for i in range(len(C)):
        for j in range(len(C) - 1, i, -1):
            if compare_cards(C[j], C[j - 1]):
                C[j], C[j - 1] = C[j -1], C[j]

def selection(C):
    for i in range(len(C)):
        mini = i
        for j in range(i, len(C)):
            if compare_cards(C[j], C[mini]):
                mini = j
        C[i], C[mini] = C[mini], C[i]

def check_stable(originC, sortedC):
    for i in range(len(originC) - 1):
        if not compare_cards(sortedC[i], sortedC[i + 1]):
            if originC.index(sortedC[i]) > originC.index(sortedC[i + 1]):
                return 'Not stable'
    return 'Stable'

        
N = int(input())
C = input().split()

bubbleC = list(C)
selectionC = list(C)

bubble(bubbleC)
selection(selectionC)

print(*bubbleC)
print(check_stable(C, bubbleC))
print(*selectionC)
print(check_stable(C, selectionC))
n = int(input())
a = list(map(int, input().split()))

random.shuffle(a)

print(a)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

ans = [0] * n

for i in range(n):
    s = a[i]
    ans[s-1] = i + 1

print(*ans)
s = input()
t = input()
if len(s)+1 = len(t):
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s = input()
t = input()
t2 = t[:-1]
if t2 == s:
  print('Yes')
else:
  print('No')
from math import gcd,sqrt
from collections import defaultdict
from copy import deepcopy

N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

p = [1]*(1001)
P = []  #1000までの素数表
p[0] = p[1] = 0
for x in range(2, int(sqrt(1000000))+1):
    if p[x]:
        P.append(x)
        for y in range(x*x, 1001, x):
            p[y] = 0

B = [defaultdict(int) for i in range(N)]  #N個の数を素因数分解したもの
lcm = defaultdict(int)  #N個の数のlcmを素因数分解したもの

for i in range(N):
    for j in P:
        if A[i] % j == 0:
            while A[i] % j == 0:
                A[i] //= j
                B[i][j] += 1
        lcm[j] = max(lcm[j],B[i][j])
    if A[i] != 1:
        B[i][A[i]] = 1
        lcm[A[i]] = 1

l = 1  #N個の数のlcm
for i in lcm.keys():
    l = (l*pow(i,lcm[i],mod)) % mod

ans = 0
#l/A[i]の和を求めていく
for i in range(N):
    r = l
    for j in list(B[i].keys()):
        r = (r*pow(j,mod-B[i][j]-1,mod)) % mod
    ans = (ans + r) % mod

print(ans)

### FIXED CODE ###

def main():
    from math import sqrt
    from fractions import gcd
    from collections import defaultdict
    from copy import deepcopy

    N = int(input())
    A = list(map(int, input().split()))
    mod = 10 ** 9 + 7

    p = [1] * (1001)
    P = []  # 1000までの素数表
    p[0] = p[1] = 0
    for x in range(2, int(sqrt(1000000)) + 1):
        if p[x]:
            P.append(x)
            for y in range(x * x, 1001, x):
                p[y] = 0

    B = [defaultdict(int) for i in range(N)]  # N個の数を素因数分解したもの
    lcm = defaultdict(int)  # N個の数のlcmを素因数分解したもの

    for i in range(N):
        for j in P:
            if A[i] % j == 0:
                while A[i] % j == 0:
                    A[i] //= j
                    B[i][j] += 1
            lcm[j] = max(lcm[j], B[i][j])
        if A[i] != 1:
            B[i][A[i]] = 1
            lcm[A[i]] = 1

    l = 1  # N個の数のlcm
    for i in lcm.keys():
        l = (l * pow(i, lcm[i], mod)) % mod

    ans = 0
    # l/A[i]の和を求めていく
    for i in range(N):
        r = l
        for j in list(B[i].keys()):
            r = (r * pow(j, mod - B[i][j] - 1, mod)) % mod
        ans = (ans + r) % mod

    print(ans)

if __name__ == '__main__':
    main()
import math
     
n = input()
     
px = float(0)
py = float(0)
qx = float(100)
qy = float(0)
     
def koch(n, px, py, qx, qy):
 if n == 0:
  return
      
 s.x = (px*2+qx*1)/3
 s.y = (py*2+qy*1)/3
 t.x = (px*1+qx*2)/3
 t.y = (py*1+qy*2)/3
 u.x = (t.x-s.x)*math.cos(pi/3) - (t.y-s.y)*math.sin(pi/3) + s.x
 u.y = (t.x-s.x)*math.sin(pi/3) + (t.y-s.y)*math.cos(pi/3) + s.y
     
 koch(n-1, px, py, s.x, s.y)
 print s.x, s.y
 koch(n-1, s.x, s.y, u.x, u.y)
 print u.x, u.y
 koch(n-1, u.x, u.y, t.x, t.y)
 print t.x, t.y
 koch(n-1, t.x, t.y, qx, qy)
     
print px, py
koch(n, px, py, qx, qy)
print qx, qy

### FIXED CODE ###

import math
          
def koch(n, h, i, j, k):
 if n == 0:
  return
           
 sx = (h*2+j)/3
 sy = (i*2+k)/3
 tx = (h+j*2)/3
 ty = (i+k*2)/3
 ux = (tx-sx)*math.cos(math.pi/3) - (ty-sy)*math.sin(math.pi/3) + sx
 uy = (tx-sx)*math.sin(math.pi/3) + (ty-sy)*math.cos(math.pi/3) + sy
          
 koch(n-1, h, i, sx, sy)
 print sx, sy
 koch(n-1, sx, sy, ux, uy)
 print ux, uy
 koch(n-1, ux, uy, tx, ty)
 print tx, ty
 koch(n-1, tx, ty, j, k)
   
n = input()
          
px = float(0)
py = float(0)
qx = float(100)
qy = float(0)
          
print px, py
koch(n, px, py, qx, qy)
print qx, qy
N, M = map(int, input().split())

G = [[] for i in range(N)]
for _ in range(M):
    Ai, Bi = map(int, input().split())
    G[Ai - 1].append(Bi - 1)
    G[Bi - 1].append(Ai - 1)

color = [0] * N
def dfs(v, c):
    '''
    頂点vをcで塗る　そこから深さ優先探索で交互に塗っていく
    '''
    color[v] = c
    for i in G[v]:
        if color[i] == c:
            return False
        if color[i] == 0 and not(dfs(i, -c)):
            return False
    return True

if dfs(0, 1):
    print(color.count(1) * color.count(-1) - M)
else:
    print(N * (N - 1) // 2 - M)


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

N, M = map(int, input().split())

G = [[] for i in range(N)]
for _ in range(M):
    Ai, Bi = map(int, input().split())
    G[Ai - 1].append(Bi - 1)
    G[Bi - 1].append(Ai - 1)

color = [0] * N
def dfs(v, c):
    '''
    頂点vをcで塗る　そこから深さ優先探索で交互に塗っていく
    '''
    color[v] = c
    for i in G[v]:
        if color[i] == c:
            return False
        if color[i] == 0 and not(dfs(i, -c)):
            return False
    return True

if dfs(0, 1):
    print(color.count(1) * color.count(-1) - M)
else:
    print(N * (N - 1) // 2 - M)
n=int(input())
s=input()
ans=s

c=s.count('()')
while c!=0:
  s=list(s)
  i=0
  while i<=len(s)-1:
    if s[i]=='(' and s[i+1]==')':
      del s[i]
      del s[i+1]
    else:
      i+=1
  s=''.join(s)
  c=s.count('()')

c_a=s.count('(')
c_b=s.count(')')

ans='('*c_b+ans+')'*c_a
print(ans)

### FIXED CODE ###

n=int(input())
s=input()
ans=s
s+='#'

c=s.count('()')
while c!=0:
  s=list(s)

  i=0
  n_s=''
  while i<=len(s)-1:
    if s[i]=='(' and s[i+1]==')':
      i+=2
    else:
      n_s+=s[i]
      i+=1

  s=''.join(n_s)
  c=s.count('()')

c_a=s.count('(')
c_b=s.count(')')

ans='('*c_b+ans+')'*c_a
print(ans)
from collections import Counter
from scipy.special import comb
N = int(input())
a, b = [], []
for i in range(N):
    b = sorted([x for x in input()])
    a += [int(''.join([str(ord(x)) for x in b]))]
count = Counter(a)
total = 0
for i in count.items():
    if i[1] >= 2:
        total += comb(i[1], 2)
print(int(total))


### FIXED CODE ###

N = int(input())
s = sorted([sorted(input()) for _ in range(N)])
total = 0
count = 1
for i in range(N-1):
    if s[i] == s[i+1]:
        count += 1
    else:
        total += count * (count - 1) / 2
        count = 1
total += count * (count - 1) / 2
print(int(total))
N,K=map(int,input().split())
p=list(map(float,input().split()))
maxexp=float(0)


def expected(n):
    return (1+n)/2

p=list(map(expected,p))
for i in range(N-K+1):
    maxexp=max(p[i]+p[i+1]+p[i+2],maxexp)
print(maxexp)

### FIXED CODE ###

N,K=map(int,input().split())
p=list(map(float,input().split()))
maxexp=float(0)


def expected(n):
    return (1+n)/2


p=list(map(expected,p))

for i in range(K):
    maxexp+=p[i]
now=maxexp
for i in range(N-K):
    now=now+p[i+K]-p[i]
    maxexp=max(now,maxexp)
print(maxexp)
import math
N=int(input())
L=[]
for i in range(1,int(math.sqrt(N))):
  if N%i==0:
    L.append(i+int(N/i)-2)
  else:
    pass
print(min(L))

### FIXED CODE ###

import math
N=int(input())
L=[]
for i in range(1,int(math.sqrt(N))+1):
  if N%i==0:
    L.append(i+int(N/i)-2)
  else:
    pass
print(min(L))
N = int(input())
s = [0]*10**6
for i in range(N):
    a = int(input())
    s[a-1] += 1
    s[a-1] = s[a-1]%2
print(sum(s))


### FIXED CODE ###

N = int(input())
dic_a = {}
for i in range(N):
    a= int(input())
    if a in dic_a:
        dic_a[a] +=1
        dic_a[a] = dic_a[a]%2
    else:
        dic_a[a] = 1
print(sum(list(dic_a.values())))
a, b = map(int, input().split())

if a != 1 and b != 1:
    print(1)
elif a != 2 and b != 2:
    print(2)
else:
    print(3)

### FIXED CODE ###

a = int(input())
b = int(input())

if a != 1 and b != 1:
    print(1)
elif a != 2 and b != 2:
    print(2)
else:
    print(3)
N=int(input())
SS=set()
while N=0:
  S=input()
  SS.add(S)
  N=N-1

### FIXED CODE ###

N=int(input())
SS=set()
while N!=0:
  S=input()
  SS.add(S)
  N=N-1
print(len(SS))
def p_d():
    from scipy.special import comb
    x, y = map(int, input().split())
    mod = 10 ** 9 + 7
    if y > x:
        x, y = y, x
    if (x + y) % 3 != 0:
        print(0)
        exit()
    if x - y > (x + y) // 3:
        print(0)
        exit()
    x, y = x - (x + y) // 3, y - (x + y) // 3
    print(comb(x + y, y, exact=True) % mod)
    
p_d()

### FIXED CODE ###

def p_d():
    x, y = map(int, input().split())
    if y > x:
        x, y = y, x
    if (x + y) % 3 != 0:
        print(0)
        exit()
    if x - y > (x + y) // 3:
        print(0)
        exit()
    x, y = x - (x + y) // 3, y - (x + y) // 3

    mod = 10 ** 9 + 7  # 出力の制限
    N = x + y
    g1 = [1, 1]  # 元テーブル
    g2 = [1, 1]  # 逆元テーブル
    inverse = [0, 1]  # 逆元テーブル計算用テーブル

    for i in range(2, N + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod // i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)

    def cmb(n, r, mod):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return g1[n] * g2[r] * g2[n - r] % mod

    print(cmb(x + y, y, mod))
    
p_d()
import math

N,D= list(map(int,input().split()))
x = [0] * N
y = [0] * N
b=0

for i in range(N):
     x[i], y[i] = map(int, input().split())
      a=x[i]**2+y[i]**2
      if math.sqrt(a) <=D:
          b+=1
print(b)


### FIXED CODE ###

import math

N,D= list(map(int,input().split()))
x = [0] * N
y = [0] * N
b=0

for i in range(N):
     x[i], y[i] = map(int, input().split())
     #print(x[i])
     a=x[i]**2+y[i]**2
     #print(math.sqrt(a))
     if math.sqrt(a) <=D:
          b+=1
print(b)
n = int(input())

import bisect
l = []
def dfs(num, index):
    if index == 9:
        if (num.find("3") != -1) and (num.find("5") != -1) and (num.find("7") != -1):
            l.append(int(num))
        return 0
        
    if num == "":
        ret0 = dfs(num + "" , index+1)
    ret1 = dfs(num + "3", index+1)
    ret2 = dfs(num + "5", index+1)
    ret3 = dfs(num + "7", index+1)

    return 0

dfs("", 0)

count = bisect.bisect_left(l,n)
count += 1 if n == l[bisect.bisect_left(l,n)] else 0
print (count)

### FIXED CODE ###

n = int(input())

import bisect
l = []
def dfs(num, index):
    if index == 9:
        if (num.find("3") != -1) and (num.find("5") != -1) and (num.find("7") != -1):
            l.append(int(num))
        return 0
        
    if num == "":
        ret0 = dfs(num + "" , index+1)
    ret1 = dfs(num + "3", index+1)
    ret2 = dfs(num + "5", index+1)
    ret3 = dfs(num + "7", index+1)

    return 0

dfs("", 0)

print (bisect.bisect_right(l,n))
N, K = map(int, input().split())
h = list(map(int, input().split()))
inf = 10**9
dp = [inf] * N
dp[0] = 0


def chmin(num: int, sbn: int):
    dp[num + sbn] = min((dp[num + sbn], dp[num] + abs(h[i + sbn] - h[num])))


for i in range(N):
    for sbn in range(K):
        try:
            chmin(dp, i, sbn + 1)
        except IndexError:
            break
print(dp[-1])


### FIXED CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
inf = 10**9
dp = [inf] * N
dp[0] = 0


def chmin(num: int, sbn: int):
    dp[num + sbn] = min((dp[num + sbn], dp[num] + abs(h[i + sbn] - h[num])))


for i in range(N):
    for sbn in range(K):
        try:
            chmin(i, sbn + 1)
        except IndexError:
            break
print(dp[-1])
M = int(input())
sumd, sumc = 0, 0
for i in range(M):
    d, c = map(int, input().split())
    sumd += d * c
    sumc += c

for i in range(1, len(str(sumd))):
    tmp = sum // (10 ** i)
    sumd += tmp

ans = sumd // 10 + sumc - 1
print(ans)


### FIXED CODE ###

M = int(input())
sumd, sumc = 0, 0
for i in range(M):
    d, c = map(int, input().split())
    sumd += d * c
    sumc += c

tmp = sumd // 10
while tmp > 0:
    pre = sumd
    sumd += tmp
    tmp = sumd // 10 - pre // 10

ans = sumd // 10 + sumc - 1
print(ans)
N= input()
S= input()

Len = len(S)#文字数の長さ
LIST = list(S)#文字列を1文字ごとに分割する。

ANSWER = ""
#リストの中身をループ
for SS in LIST:
    NUNBER = ord(SS)#アスキーコードを出す組み込み関数:1文字しか対応していない
    NUNBER = NUNBER -64#アスキーコードからアルファベット順に変更
    AFFTER = NUNBER + N
    LAST  = AFFTER % 26
    LAST  = chr(LAST+64)#アスキーコードからアルファベットに戻す
    ANSWER = ANSWER + LAST
    
print(ANSWER)

### FIXED CODE ###

N= input()
S= input()


N = int(N)
Len = len(S)#文字数の長さ
LIST = list(S)#文字列を1文字ごとに分割する。

ANSWER = ""
#リストの中身をループ
for SS in LIST:
    NUNBER = ord(SS)#アスキーコードを出す組み込み関数:1文字しか対応していない
    NUNBER = NUNBER -65#アスキーコードからアルファベット順に変更
    AFFTER = NUNBER + N
    LAST  = AFFTER % 26
    LAST  = chr(LAST+65)#アスキーコードからアルファベットに戻す
    ANSWER = ANSWER + LAST
    
print(ANSWER)
n=int(input())
v=map(int,input().split())
vodd={}
veven={}
for i,vi in enumerate(v):
    if i%2:
        if(vi in veven):
            veven[vi]+=1
        else:
            veven[vi]=1
    else:
        if(vi in vodd):
            vodd[vi]+=1
        else:
            vodd[vi]=1
veven=list(veven.items())
veven.sort(key=lambda x:x[1])
veven.reverse()
vodd=list(vodd.items())
vodd.sort(key=lambda x:x[1])
vodd.reverse()
if len(veven)==2 & len(vodd)==2:
    if veven[0][0]==vodd[0][0]:
        a=veven[0][1]+vodd[1][1]
        b=veven[1][1]+vodd[0][1]
        changeCnt=a if a<b else b
    else:
        changeCnt=veven[1][1]+vodd[1][1]
elif len(veven)==1 & len(vodd)==1:
    if veven[0][0]==vodd[0][0]:
        a=vodd[0][1]
        b=veven[0][1]
        changeCnt=a if a<b else b
    else:
        changeCnt=0
elif len(veven)==1:
    if veven[0][0]==vodd[0][0]:
        changeCnt=vodd[0][1]
    else:
        changeCnt=vodd[1][1]
elif len(vodd)==1:
    if veven[0][0]==vodd[0][0]:
        changeCnt=veven[0][1]
    else:
        changeCnt=veven[1][1]

print(changeCnt)

### FIXED CODE ###

n=int(input())
v=map(int,input().split())
vodd={-1:0}
veven={-1:0}
for i,vi in enumerate(v):
    if i%2:
        if(vi in veven):
            veven[vi]+=1
        else:
            veven[vi]=1
    else:
        if(vi in vodd):
            vodd[vi]+=1
        else:
            vodd[vi]=1
veven=list(veven.items())
veven.sort(key=lambda x:-x[1])
vodd=list(vodd.items())
vodd.sort(key=lambda x:-x[1])
if veven[0][0]==vodd[0][0]:
    a=veven[0][1]+vodd[1][1]
    b=veven[1][1]+vodd[0][1]
    changeCnt=n-a if a>b else n-b
else:
    changeCnt=n-veven[0][1]-vodd[0][1]

print(changeCnt)
S = input()
N = len(S)
judg = 0
n = N - 1 
for i in range(0,n):
  if S[i] == S[n - i]:
    judg += 0
  else:
    judg += 1

for i in range(0,n/2-1):
  if S[i] == S[n/2 - i]:
    judg += 0
  else:
    judg += 1

for i in range(n/2+1,n):
  if S[i] == S[n - i]:
    judg += 0
  else:
    judg += 1
    
if judg == 0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
s = input()
n = len(s)
m = (n-1) // 2
k = (n+3) // 2
flag = 1
for i in range(0, n//2):
    if s[i] != s[n-i-1]:
        flag = 0
        break
for i in range(0, m//2):
    if s[i] != s[m-i-1]:
        flag = 0
        break
for i in range(0, (n-k)//2+1):
    if s[i+k-1] != s[n-i-1]:
        flag = 0
        break
if flag == 1:
    print("Yes")
else:
    print("No")
import numpy as np
import fraction
from functools import reduce
import sys

def gcd_list(numbers):
    return reduce(fraction.gcd, numbers)

n,z=map(int,input().split())
y=list(map(int,input().split()))

if(n==1):
    print(abs(y[0]-z))
    sys.exit()
y=np.array(y)
y=y-z
t=[]
for i in range(1,n):
    t.append(abs(y[i]-y[i-1]))

print(gcd_list(t))

### FIXED CODE ###

import numpy as np
import fractions
from functools import reduce
import sys

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n,z=map(int,input().split())
y=list(map(int,input().split()))

if(n==1):
    print(abs(y[0]-z))
    sys.exit()
y=np.array(y)
y=y-z
a=np.min(abs(y))
t=[]
for i in range(1,n):
    t.append(abs(y[i]-y[i-1]))

print(fractions.gcd(a,gcd_list(t)))
A, B, C = map(int, input().split())
if sum(A,B,C) == 17:
  print("YEAS")
else:
  print("NO")
  

### FIXED CODE ###

A, B, C = map(int, input().split())
if A*B*C == 5*5*7:
  print("YES")
else:
  print("NO")
N = int(input())
P_list = list(map(int, input().split()))
count_i = 0
for i in range(N):
    if P_list[i] <= min(P_list[:i+1]):
        count_i += 1
print(count_i)


### FIXED CODE ###

N, M = map(int, input().split())
if N == M:
    print('Yes')
else:
    print('No')
import sys
n = int(sys.stdin.readline())
p = [int(i) for i in sys.stdin.readline().split()]

if p == sorted(p):
    print('YES')
else:
    swap_index = []
    for i, v in enumerate(p[:-1]):
        if v > p[i + 1]:
            if len(swap_index) == 0:
                swap_index.append(i)
            else:
                swap_index.append(i + 1)
                break
    p[swap_index[0]], p[swap_index[1]] = p[swap_index[1]], p[swap_index[0]]

    if p == sorted(p):
        print('YES')
    else:
        print('NO')


### FIXED CODE ###

import sys
n = int(sys.stdin.readline())
p = [int(i) for i in sys.stdin.readline().split()]

if p == sorted(p):
    print('YES')
elif len(p) == 2:
    print('YES')
else:
    swap_index = []
    for i, v in enumerate(p[:-1]):
        if v > p[i + 1]:
            if len(swap_index) == 0:
                swap_index.append(i)
            else:
                swap_index.append(i + 1)
                break
    if len(swap_index) == 1:
        print('NO')
    else:
        p[swap_index[0]], p[swap_index[1]] = p[swap_index[1]], p[swap_index[0]]
        if p == sorted(p):
            print('YES')
        else:
            print('NO')
n = int(input())
ans = ""
if n < 1200:
	ans = "ABC"
else if n < 2800:
	ans = "ARC"
else:
	ans = "AGC"

print(ans)


### FIXED CODE ###

n = int(input())
ans = ""
if n < 1200:
	ans = "ABC"
elif n < 2800:
	ans = "ARC"
else:
	ans = "AGC"

print(ans)
N, M = map(int, input().split())
Edge = [[]for _ in range(N)]
Far = [-1]*N
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    Edge[x].append(y)

def Long(x):
    if len(Edge[x]) == 0:
        Far[x] = 0
        return 0
    if Far[x] >= 0:
        return Far[x]
    r = 0
    for i in Edge[x]:
        l = Long(i) + 1
        r = max(r, l)
    return r
ans = 0
for i in range(N):
    ans = max(ans, Long(i))
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

N, M = map(int, input().split())
Edge = [[]for _ in range(N)]
Far = [-1]*N
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    Edge[x].append(y)


def long(x):
    if len(Edge[x]) == 0:
        Far[x] = 0
        return 0
    if Far[x] >= 0:
        return Far[x]
    r = 0
    for i in Edge[x]:
        l = long(i) + 1
        r = max(r, l)
    Far[x] = r
    return r


for i in range(N):
    long(i)
print(max(Far))