Harryxun/stf_run huggingface dataset:
N = int(input())
a = [int(i) for i in input().split(' ')]
numbers = []
numbers.append(a[0])
for i in a:
    if i != numbers[0] and len(numbers) == 1:
        numbers.append(i)
    if i != numbers[0] and i != numbers[1]:
        numbers.append(i)
        break

if len(numbers) == 3:
    if a.count(numbers[0]) != a.count(numbers[1]):
        print('No')
        exit(0)
    if a.count(numbers[0]) != a.count(numbers[2]):
        print('No')
        exit(0)
    if len(a) != a.count(numbers[0])+a.count(numbers[1])+a.count(numbers[2]):
        print('No')
        exit(0)

    if numbers[0]^numbers[1] == numbers[2]:
        print('Yes')
        exit(0)
    elif numbers[0]^numbers[2] == numbers[1]:
        print('Yes')
        exit(0)
    elif numbers[1]^numbers[2] == numbers[0]:
        print('Yes')
        exit(0)
    else:
        print('No')
else:
    if len(a) != a.count(numbers[0])+a.count(numbers[1]):
        print('No')
        exit(0)
    if numbers[0] == 0 or numbers[1] == 0:
        if numbers[0] == 0:
            if a.count(numbers[1]) != 2*a.count(numbers[0]):
                print('No')
                exit(0)
        elif a.count(numbers[0]) != 2*a.count(numbers[1]):
            print('No')
            exit(0)
        print('Yes')
        exit(0)
    else:
        print('No')
        exit(0)   
       
    

### FIXED CODE ###

N = int(input())
a = [int(i) for i in input().split(' ')]
numbers = []
numbers.append(a[0])
for i in a:
    if i != numbers[0] and len(numbers) == 1:
        numbers.append(i)
    if i != numbers[0] and i != numbers[1]:
        numbers.append(i)
        break

if len(numbers) == 1:
    if numbers[0] == 0:
        print('Yes')
        exit(0)
    else:
        print('No')
        exit(0)

if len(numbers) == 3:
    if a.count(numbers[0]) != a.count(numbers[1]):
        print('No')
        exit(0)
    if a.count(numbers[0]) != a.count(numbers[2]):
        print('No')
        exit(0)
    if len(a) != a.count(numbers[0])+a.count(numbers[1])+a.count(numbers[2]):
        print('No')
        exit(0)

    if numbers[0]^numbers[1] == numbers[2]:
        print('Yes')
        exit(0)
    elif numbers[0]^numbers[2] == numbers[1]:
        print('Yes')
        exit(0)
    elif numbers[1]^numbers[2] == numbers[0]:
        print('Yes')
        exit(0)
    else:
        print('No')
else:
    if len(a) != a.count(numbers[0])+a.count(numbers[1]):
        print('No')
        exit(0)
    if numbers[0] == 0 or numbers[1] == 0:
        if numbers[0] == 0:
            if a.count(numbers[1]) != 2*a.count(numbers[0]):
                print('No')
                exit(0)
        elif a.count(numbers[0]) != 2*a.count(numbers[1]):
            print('No')
            exit(0)
        print('Yes')
        exit(0)
    else:
        print('No')
        exit(0)
N = int(input())
def dfs(s): # 文字列 s で始まる七五三数の個数 if int(s) > N:
  return 0
ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1 for c in '753':
         ret += dfs(s + c)
     return ret
print(dfs('0')) # 本当は dfs('') と書きたいが 4 行目でのエラーを防ぐため仕方なく

### FIXED CODE ###

N = int(input())

ans = 0
a = [3, 5, 7]
i = 0
while a[i] <= N:
    x10 = a[i] * 10
    a.append(x10+3)
    a.append(x10+5)
    a.append(x10+7)
    i += 1

for j in range(i):
    s = str(a[j])
    if "3" in s and "5" in s and "7" in s:
        ans += 1

print(ans)
a, b = map(str, raw_input().split())

print a*b (a+b)*2

### FIXED CODE ###

a, b = [int(x) for x in raw_input().split()]
 
print a*b,(a+b)*2
n,a,b,c = map(int,input().spilt())

ko = [int(input()) for i in range(n)]
INF = 10**9

 def dfs(q,w,e,r):
 	if q == n:
 		 return abs(a-w) + abs(b-e) + abs(c-r) - 30 if min(a,b,c) > 0 else INF
 	re0 = dfs(q+1,w,e,r)
 	re1 = dfs(q+1,w+ko[q],e,r) + 10
 	re2 = dfs(q+1,w,e+ko[q],r) + 10
 	re3 = dfs(q+1,w,e,r+ko[q]) + 10
 	return min(re0,re1,re2,re3)

print(dfs(0,0,0,0))

### FIXED CODE ###

a = list(input())

b = a[0:4]

c = a[5:7]

d = a[8:10]

su = 0
bb = 0
cc =0
dd = 0
for i in range(4):
	bb = 10*bb + int(b[i])
for i in range(2):
	cc = 10*cc + int(c[i])
for i in range(2):
	dd = 10*dd + int(d[i])


if bb == 2019:
	if cc >= 5:
		print("TBD")
	elif cc == 4:
		if dd == 30:
			print("Heisei")
		else:
			print("Heisei")
	else:
		print("Heisei")
elif bb > 2019:
	print("TBD")
else:
	print("Heisei")
N=int(input())
from collections import defaultdict
dic=defaultdict(int)
dic[(0,0)]=0
import math
mod=1000000007
for _ in range(N):
    A,B=map(int,input().split())
    if A<0:
        A,B=-A,-B
    if A==0:
        if B==0:
            dic[(0,0)]+=1
        else:
            dic[(0,1)]+=1
    elif B==0:
        dic[(1,0)]+=1
    else:
        gcd=math.gcd(A,B)
        A,B=A//gcd,B//gcd
        dic[(A,B)]+=1

ans=1
N-=dic[(0,0)]
for k,v in dic.items():
    if k==(0,0) or k==(0,1):
        continue
    if k==(1,0):
        v_dash=dic[(0,1)]
        ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
        ans%=mod
        N-=v+v_dash
        continue
    a,b=k
    if not (b,-a) in dic:
        continue
    v_dash=dic[(b,-a)]
    ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
    ans%=mod
    N-=v+v_dash
ans*=pow(2,N,mod)
ans+=dic[(0,0)]
ans%=mod
print(ans-1)


### FIXED CODE ###

N=int(input())
from collections import defaultdict
dic=defaultdict(int)
dic[(0,0)]=dic[(0,1)]=0
import math
mod=1000000007
for _ in range(N):
    A,B=map(int,input().split())
    if A<0:
        A,B=-A,-B
    if A==0:
        if B==0:
            dic[(0,0)]+=1
        else:
            dic[(0,1)]+=1
    elif B==0:
        dic[(1,0)]+=1
    else:
        gcd=math.gcd(A,B)
        A,B=A//gcd,B//gcd
        dic[(A,B)]+=1

ans=1
N-=dic[(0,0)]
for k,v in dic.items():
    if k==(0,0) or k==(0,1):
        continue
    if k==(1,0):
        v_dash=dic[(0,1)]
        ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
        ans%=mod
        N-=v+v_dash
        continue
    a,b=k
    if not (b,-a) in dic:
        continue
    v_dash=dic[(b,-a)]
    ans*=((pow(2,v,mod)-1)+(pow(2,v_dash,mod)-1)+1)
    ans%=mod
    N-=v+v_dash
ans*=pow(2,N,mod)
ans+=dic[(0,0)]-1
ans%=mod
print(ans)
from math import factorial

def cc(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

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

for i in range(k):
    j = i + 1
    cnt = cc(n-k+1, j) * cc(k-1, j-1)
    print(cnt % (10**9 + 7))

### FIXED CODE ###

from math import factorial

def cc(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

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

if n == k:
    for i in range(k):
        if i == 0:
            cnt = 1
        else:
            cnt = 0
        print(cnt % (10 ** 9 + 7))

else:
    for i in range(k):
        j = i + 1
        if j > n-k+1:
            cnt = 0
        else:
            cnt = cc(n-k+1, j) * cc(k-1, j-1)


        print(cnt % (10**9 + 7))
import math 
from itertools import product
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd,numbers)
K=int(input())
A=[]
as=range(1,K+1)
bs=range(1,K+1)
cs=range(1,K+1)
for a,b,c in product(as,bs,cs):
  s=gcd(a,b,c)
  A.append(s)
print(sum(A))
  
    
      A.append(s)
print(sum(A))

### FIXED CODE ###

import math
K=int(input())
ans=0
for a in range(1,K+1):
  for b in range(1,K+1):
    ans_=math.gcd(a,b)
    for c in range(1,K+1):
      ans+=math.gcd(ans_,c)
print(ans)
N = int(input())
SP = []
for i in range(N):
  S,P = input().split()
  P = int(P)
  SP.append(S,P,i+1)
SP.sort()
for a,b,c in SP:
  print(c)

### FIXED CODE ###

N = int(input())
SP = []
for i in range(N):
  S,P = input().split()
  P = int(P)
  SP.append((S,-P,i+1))
SP.sort()
for a,b,c in SP:
  print(c)
n,m=input().split()
n,m=int(n),int(m)
a=[]
for i in range(n):
    a.append(input())

b=[]
for i in range(m):
    b.append(input())

#貪欲にやれドアホ
for i in range(n-m):
    for j in range(n-m):
        c=0
        for k in range(m):
            if b[k] == a[i+k][j:j+m]:
                c+=1
            else:
                break
        if c==m:
            break
    if c==m:
        break
if c==m:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

n,m=input().split()
n,m=int(n),int(m)
a=[]
for i in range(n):
    a.append(input())

b=[]
for i in range(m):
    b.append(input())

#貪欲にやれドアホ
for i in range(n-m):
    for j in range(n-m):
        c=0
        for k in range(m):
            if b[k] == a[i+k][j:j+m]:
                c+=1
            else:
                break
        if c==m:
            break
    if c==m:
        break
#cが定義されない時(m==nでは)エラー
if a==b:
    print("Yes")
elif n==m:
    print("No")
elif c==m:
    print("Yes")
else:
    print("No")
print chr(ord('a') + 1)

### FIXED CODE ###

print(chr(ord(input()) + 1))
import sys
import math
def resolve():
        input = sys.stdin.readline
        N=int(input().rstrip())
        h=list(map(int,input().rstrip().split()))

        dp=[math.inf]*N
        dp[0]=0

        for i in range(1,N,1):
            dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
            if(i>1):        
                dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))

        print(dp[N-1])
          


from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4
10 30 40 20"""
        output = """30"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2
10 10"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """6
30 10 60 10 60 50"""
        output = """40"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

### FIXED CODE ###

import sys
input = sys.stdin.readline
N=int(input().rstrip())
h=list(map(int,input().rstrip().split()))

dp=[0]*N
for i in range(N):
    dp[i]=1000000000000
dp[0]=0

for i in range(1,N,1):
    dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    if(i>1):        
        dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))

print(dp[N-1])
import sys
from functools import lru_cache

INF = sys.maxsize

N = int(input().strip())
h = [int(x) for x in input().split()]

@lru_cache()
def solve(i):
  if i >= N - 1:
    return 0
  return min(    
    solve(i + 1) + abs(h[i] - h[i + 1]) if i + 1 < N else INF,
    solve(i + 2) + abs(h[i] - h[i + 2]) if i + 2 < N else INF
  )
  

print(solve(0))

### FIXED CODE ###

import sys
from functools import lru_cache

sys.setrecursionlimit(10**6)

INF = sys.maxsize

N = int(input().strip())
h = [int(x) for x in input().split()]

@lru_cache()
def solve(i):
  if i >= N - 1:
    return 0
  return min(    
    solve(i + 1) + abs(h[i] - h[i + 1]) if i + 1 < N else INF,
    solve(i + 2) + abs(h[i] - h[i + 2]) if i + 2 < N else INF
  )
  
print(solve(0))
N=int(input())
s_str=input().split()
s_int=[int(s) for s in s_str]
list=[]
s_int.reverse()
for i in s_int:
    list.append(i)
for i in list:
    a=i,end=" "
print(a[:-2])



### FIXED CODE ###

N=int(input())
s_str=input().split()
s_int=[int(s) for s in s_str]
list=[]
s_int.reverse()
for i in s_int:
    list.append(i)
print(*list)
s = list(input())
cnt, i = 0, 0
l = len(s)

while i < l:
    if s[i] == s[i+1]:
        cnt += 1
        i += 2
    i += 1

print(l-cnt)

### FIXED CODE ###

s = list(input())
cnt, i = 0, 1
l = len(s)

while i < l:
    if s[i] == s[i-1]:
        cnt += 1
        i += 2
    i += 1

print(l-cnt)
a = int(input())
s = str(input())

if a>=3200:
  print("s")
  else :
    print("red")


### FIXED CODE ###

a = int(input())
s = input()

if a>=3200:
	print(s)
else :
	print("red")
if input()=='1':
  print('Hello World')
else:
  print(sum(int(input()) for _ in range(2))

### FIXED CODE ###

if input()=='1':
  print('Hello World')
else:
  print(sum(int(input()) for _ in range(2)))
n = int(input())
listForList=[]

index=0
while index < n:
    listI = list(input())
    listI.sort()
    listForList.append(listI)
    index+=1

if len(listForList)==1:
    print("".join(listForList[0]))
else:
    index2=1
    pendingL=listForList[0]
    while index2 < len(listForList):
        newPL=[]
        for ch in pendingL:
            if ch in listForList[index2]:
                newPL.append(ch)
        pendingL = newPL
        if pendingL==[]:
            print("")
            break
        index2+=1

if index2 == len(listForList):
    print("".join(pendingL))

### FIXED CODE ###


n = int(input())
listForList = []

index = 0
while index < n:
    listI = list(input())
    listI.sort()
    listForList.append(listI)
    index += 1

if len(listForList) == 1:
    print("".join(listForList[0]))
else:
    index2 = 0
    pendingL = []
    while index2 < len(listForList)-1:
        if index2 == 0:
            for c in listForList[index2]:
                if c in listForList[index2+1]:
                    pendingL.append(c)
        else:
            newPL = []
            for ch in pendingL:
                if ch in listForList[index2+1]:
                    newPL.append(ch)
                    listForList[index2+1].remove(ch)
            pendingL = newPL
            if pendingL == []:
                print("")
                break
        index2 += 1

    if index2 == len(listForList)-1:
        print("".join(pendingL))
import math

A = [int(a) for _ in range(3) for a in input().split()]
punched = [False] * 9
num_to_i = {a:i for i, a in enumerate(A)}
N = int(input())
B = [int(input()) for _ in range(N)]

for b in B:
  if b in num_to_i:
    punched[num_to_i[b]] = True

# 縦
for i in range(3):
  if punched[i] and punched[i+3] and punched[i+6]:
    print("Yes")
    quit()

# 横
for i in range(3):
  if punched[i*3] and punched[i*3+1] and punched[i*3+3]:
    print("Yes")
    quit()

# 斜め
if (punched[0] and punched[4] and punched[8]) or (punched[2] and punched[4] and punched[6]):
  print("Yes")
  quit()
  
print("No")

### FIXED CODE ###

import math
A = list(map(int,"\n".join([input() for i in range(3)]).strip().split()))
N = int(input())
B = [int(input()) for i in range(N)]
size = 3
punched = set()

corrects = []
# 縦の揃い方
corrects += [{i + size*j for i in range(size)} for j in range(size)]
# 横の揃い方
corrects += [{j + size*i for i in range(size)} for j in range(size)]
# 斜めの揃い方
corrects += [{i + size*i for i in range(size)}]
corrects += [{(size - 1 - i) + size*i for i in range(size)}]

def punch(b, A, punched):
    for i in range(len(A)):
        if b == A[i]: punched.add(i)
          
for b in B:
    punch(b, A, punched)
    
for correct in corrects:
    if correct.issubset(punched):
        print("Yes")
        break
else:
  	print("No")
r, g, b = map(int(), input().split())

A = r + g + b

if(A % 4 == 0):
	print("Yes")
else:
	print("No")

### FIXED CODE ###

r, g, b = map(int, input().split())

A = 100*r + 10*g + b

if(A % 4 == 0):
	print("YES")
else:
	print("NO")
n = int(input())
lis = list(map(int,input().split()))
q = int(input())
x = {}
for i in lis:
    if i not in x:
        x[i]=1
    else:
        x[i]+=1
total = sum(lis)
for i in range(q):
    a,b=map(int,input().split())
    diff = b-a
    total += diff*x[a]
    x[b]+=x[a]
    print(total)

### FIXED CODE ###

from collections import Counter
n = int(input())
lis = list(map(int,input().split()))
l = Counter(lis)
d = [0]+[l[i+1] for i in range(10**5)]
q = int(input())
s = sum(lis)
for i in range(q):
    a,b=map(int,input().split())
    if d[a]!=0:
        temp = d[a]
        d[a]=0
        d[b]+=temp
        s += temp*(b-a)
    print(s)
class RangeMinQuery:
    inf = 2 ** 31 - 1
    def __init__(self, N):
        self.n = 1
        while self.n < N: self.n *= 2
        self.dat = [self.inf] (2 * self.n - 1)

    def update(self, k, x):
        k += self.n - 1
        self.dat[k] = x
        while (k > 0):
            k = (k - 1) / 2
            self.dat[k] = min(self.dat[2 * k + 1], self.dat[2 * k + 2])

    # [a, b); call query(a, b)
    def query(self, a, b, k = 0, l = 0, r = -1):
        if r == -1: r = self.n
        if r <= a  or b <= l: return self.inf
        if a <= l and r <= b: return self.dat[k]

        vl = self.query(a, b, 2 * k + 1, l, (l + r) / 2)
        vr = self.query(a, b, 2 * k + 2, (l + r) / 2, r)
        return min(vl, vr)

n, q = map(int, raw_input().split())
rmq = RangeMinQuery(n)
for i in xrange(q):
    c, x, y = map(int, raw_input().split())
    if c == 0:
        c.update(x, y)
    else:
        print c.query(x, y + 1)

### FIXED CODE ###

class RangeMinQuery:
    inf = 2 ** 31 - 1
    def __init__(self, N):
        self.n = 1
        while self.n < N: self.n *= 2
        self.dat = [self.inf] * (2 * self.n - 1)
 
    def update(self, k, x):
        k += self.n - 1
        self.dat[k] = x
        while (k > 0):
            k = (k - 1) / 2
            self.dat[k] = min(self.dat[2 * k + 1], self.dat[2 * k + 2])
 
    # [a, b); call query(a, b)
    def query(self, a, b, k = 0, l = 0, r = -1):
        if r == -1: r = self.n
        if r <= a  or b <= l: return self.inf
        if a <= l and r <= b: return self.dat[k]
 
        vl = self.query(a, b, 2 * k + 1, l, (l + r) / 2)
        vr = self.query(a, b, 2 * k + 2, (l + r) / 2, r)
        return min(vl, vr)
 
n, q = map(int, raw_input().split())
rmq = RangeMinQuery(n)
for i in xrange(q):
    c, x, y = map(int, raw_input().split())
    if c == 0:
        rmq.update(x, y)
    else:
        print rmq.query(x, y + 1)
my_rate = input()
if my_rate < 1200:
        print("ABC")
elif my rate >=1200 and my_rate < 2800:
        print("ARC")
else:
        print("AGC")

### FIXED CODE ###

my_rate = int(input())
if my_rate < 1200:
        print("ABC")
elif my_rate >=1200 and my_rate < 2800:
        print("ARC")
else:
        print("AGC")
///                ..:: In The Name Of God ::..
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <vector>
using namespace std;
//配列の要素数は　sizeof(ar)/sizeof(ar[0]) で求める
int N,M;
double X;
signed main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    X = ceil(N/(1.08));
    M = floor(X*(1.08));
    if(M == N){
        cout << X;
    }
    else{
        cout << ":(";
    }
}   

### FIXED CODE ###

import math
from math import ceil, floor
N = int(input())
X = ceil(N/(1.08))
M = floor(X*1.08)

if M==N:
    print(X)
else:
    print(":(")
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  string S;
  cin >> S;
  
  int bucket[26]={0};//バケット
  
  for(int i=0;i<S.length();i++){
    int tmp= S.at(i)-'a';
    bucket[tmp]++;
  }
  
  int ans=-1;//答えを格納
  for(int i=0; i<26; i++){
    if (bucket[i]==0){
      ans=i;
      break;
    }
  }
  
  if(ans==-1){
    cout << "None" << endl;
  }else{
    printf("%c\n",ans+97);
  }
  
  return 0;
      
}

### FIXED CODE ###

S=str(input())

import string
alphabet="".join([i for i in string.ascii_lowercase if i not in S])

if(alphabet):
  print(alphabet[0])
else:
  print("None")
n, m = map(int, input().split())
A = list(map(int, input().split()))
digit = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}


def dfs(k):
    if k == 0:
        return 0, -1
    if k in memo:
        return memo[k]

    max_value = -1
    max_d = -1
    for num in A:
        if k >= digit[num]:
            suf, d = dfs(k-digit[num])
            if suf >= 0:
                value = num*(10**(d+1))+suf
                if value > max_value:
                    max_value = value
                    max_d = d+1

    memo[k] = (max_value, max_d)
    return max_value, max_d


memo = dict()
print(dfs(n)[0])

### FIXED CODE ###

n, m = map(int, input().split())
A = list(map(int, input().split()))
digit = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

dp = [(-1, -1)]*(n+1)
dp[0] = (0, -1)
for k in range(1, n+1):
    max_value = -1
    max_d = -1
    for num in A:
        if k >= digit[num]:
            suf, d = dp[k - digit[num]]
            if suf >= 0:
                value = num * (10 ** (d + 1)) + suf
                if value > max_value:
                    max_value = value
                    max_d = d + 1

    dp[k] = (max_value, max_d)
print(dp[n][0])
#!/usr/bin/env python
# encoding: utf-8

from __future__ import print_function


class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def insertion_sort():
        # write your code here
        array_length = raw_input()
        unsorted_array = list(map(int, raw_input().split()))

        for i in range(1, array_length):
            v = unsorted_array[i]
            j = i - 1
            while j >= 0 and unsorted_array[j] > v:
                unsorted_array[j + 1] = unsorted_array[j]
                j -= 1
            unsorted_array[j + 1] = v
            print(" ".join(str(i) for i in unsorted_array))


if __name__ == '__main__':
    solution = Solution()
    solution.insertion_sort()

### FIXED CODE ###

#!/usr/bin/env python
# encoding: utf-8

from __future__ import print_function


class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def insertion_sort():
        # write your code here
        array_length = int(input())
        unsorted_array = [int(x) for x in input().split()]

        for i in range(array_length):
            v = unsorted_array[i]
            j = i - 1
            while j >= 0 and unsorted_array[j] > v:
                unsorted_array[j + 1] = unsorted_array[j]
                j -= 1
            unsorted_array[j + 1] = v
            print(" ".join(map(str, unsorted_array)))


if __name__ == '__main__':
    solution = Solution()
    solution.insertion_sort()
S=input()+'2'
prev=S[0]
cnt=1
li=[]
for i in range(1,len(S)):
    if S[i]!=prev:
        li.append(cnt)
        prev=S[i]
        cnt=1
    else:
        cnt+=1
if len(li)==1:
    print(li[0])
elif len(li)==2:
    print(max(li))
elif len(li)%2==1:
    ans=li[0]+li[1]
    for i in range(len(li)-1):
        ans=min(ans,li[i]+li[i+1])
    print(ans)
else:
    ans1=li[0]+li[1]
    ans2=li[1]+li[2]
    for i in range(len(li)-2):
        ans1=min(ans1,li[i]+li[i+1])
    for i in range(1,len(li)-1):
        ans2=min(ans2,li[i]+li[i+1])
    print(max(a1,a2))

### FIXED CODE ###

S=input()
prev=S[0]
T=len(S)
for i in range(1, len(S)):
    if S[i]!=prev:
        T=min(T,max(i,len(S)-i))
        prev=S[i]
print(T)
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
l=[list(map(int,input().split()) )for _ in range(m)]
lst=sorted(l,key=lambda x: x[1],reverse=True)
cur=0
for i in lst:
    tmpb=i[0]
    while tmpb:
        if a[cur]<i[1]:
            a[cur]=i[1]
            cur+=1
            tmpb-=1
        else:
            break
            
result=0
for i in a:
    result+=i
print(result)
    
    

### FIXED CODE ###

n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
l=[list(map(int,input().split()) )for _ in range(m)]
lst=sorted(l,key=lambda x: x[1],reverse=True)
cur=0
for i in lst:
    tmpb=i[0]
    while (tmpb!=0 and cur<=len(a)-1):
        if a[cur]<i[1]:
            a[cur]=i[1]
            cur+=1
            tmpb-=1
        else:
            break
            
result=0
for i in a:
    result+=i
print(result)
n,m = map(int, input().split())
info = [[i] + list(map(int, input().split())) for i in range(1, m+1)]
city = sorted(set([info_i[0] for info_i in info]))

sorted_info = sorted(info, key=lambda x: [x[1], x[2]])
counter = 0

p = city.pop(0)

for i in range(m):
  if sorted_info[i][1] == p:
    counter += 1
    sorted_info[i].append(counter)
  else:
    p =  city.pop(0)
    counter = 1
    sorted_info[i].append(counter)

result = sorted(sorted_info, key=lambda x:x[0])

for res_i in result:
  print(str(res_i[1]).zfill(6) + str(res_i[3]).zfill(6))

### FIXED CODE ###

from collections import defaultdict
from bisect import bisect

n,m = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(m)]

a = defaultdict(list)

for p_i in sorted(p):
  a[p_i[0]].append(p_i[1])
  
for p_i in p:
  x = p_i[0]
  y = bisect(a[x], p_i[1])
  
  print(str(x).zfill(6), str(y).zfill(6), sep='')