Harryxun/stf_run huggingface dataset:
import sys
input = lambda: sys.stdin.readline().rstrip()

n= int(input())
a=list(input())

v=a.count('1')

ans=[0]*n
A=[0]*n
# n以下の残り回数を記録
for i in range(n):
    x=i
    cnt=0
    while x>0:
        cnt+=1
        r = 0
        for j in range(10):
            if (x>>j)&1:
                r+=1
        x=x%r
    ans[i]=cnt

# 各桁をv＋１で割ったあまり
q = [0]*n
# 各桁をv-1で割ったあまり
r = [0]*n
for i in range(n):
    if a[i]=='1':
        if v!=0:
            q[i] = pow(2, n-i-1) % (v + 1)
        if v!=1:
            r[i] += pow(2, n-i-1) % (v - 1)
qq=sum(q)
rr=sum(r)

for i in range(n):
    if a[i]=='1':
        if v!=1:
            z = rr - pow(2,n-i-1)%(v-1)
            cnt = z % (v - 1)
            A[i] = 1 + ans[cnt]
    else:
        z=qq+pow(2,n-i-1)%(v+1)
        cnt=z%(v+1)
        A[i]=1+ans[cnt]

for i in A:
    print(i)

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

n= int(input())
a=list(input())

v=a.count('1')

ans=[0]*n
A=[0]*n
# n以下の残り回数を記録
for i in range(n):
    x=i
    cnt=0
    while x>0:
        cnt+=1
        r = 0
        for j in range(19):
            if (x>>j)&1:
                r+=1
            if x>>j==0:
                break
        x=x%r
    ans[i]=cnt

# 各桁をv＋１で割ったあまり
q = [0]*n
# 各桁をv-1で割ったあまり
r = [0]*n
for i in range(n):
    if a[i]=='1':
        if v!=0:
            q[i] = pow(2, n-i-1,v+1) 
        if v!=1:
            r[i] += pow(2, n-i-1,v-1) 
qq=sum(q)
rr=sum(r)

for i in range(n):
    if a[i]=='1':
        if v!=1:
            z = rr - pow(2,n-i-1,v-1)
            cnt = z % (v - 1)
            A[i] = 1 + ans[cnt]
    else:
        z=qq+pow(2,n-i-1,v+1)
        cnt=z%(v+1)
        A[i]=1+ans[cnt]

for i in A:
    print(i)
n, m = map(int, input().split())
a_li = list(map(int, input().split()))
a_li = [a // 2 for a in a_li]

from math import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

def even_or_odd(a):
    parity = 'even' if a % 2 == 0 else 'odd'
    return parity

a_lcm = 1
parity = even_or_odd(a_li[0])
flag = False
for a in a_li:
    if parity != even_or_odd(a):
        flag = True
        break
    a_lcm = lcm(a, a_lcm)

if flag:
    ans = 0
elif parity == 'even':
    if a_lcm % 2 == 0:
        ans = m // a_lcm
    else:
        ans = 0
else:
    ans = m // a_lcm
    if a_lcm % 2 == 0:
        ans = ans // 2
    else:
        ans = ans // 2 + 1 if ans % 2 == 1 else ans // 2
print(ans)


### FIXED CODE ###

n, m = map(int, input().split())
a_li = list(map(int, input().split()))
# すべてのaを2で割る
a_li = [a // 2 for a in a_li]

from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

def count_div_2(a):
    cnt = 0
    while a % 2 == 0:
        a = a // 2
        cnt += 1
    return cnt

# a_lcm: aの最小公倍数, parity: すべてのaの偶奇性, cnt_div: すべてのaの2で割れる回数
a_lcm = 1
cnt_div = count_div_2(a_li[0])

# a_lcmを求める
flag = False
for a in a_li:
    a_lcm = lcm(a, a_lcm)
    # 偶奇が不一致、またはa_lcmがm以上の場合答えなし
    if cnt_div != count_div_2(a) or a_lcm > m:
        flag = True
        break

# 先程弾いた場合以外で答えを出す
if flag:
    ans = 0
else:
    ans = m // a_lcm
    ans = ans // 2 + ans % 2

print(ans)
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
B.append(0)

ans = 0
for i in range(N+1):
  taosukazu1 = min(A[i],B[i])
  B[i] -= taosukazu1
  A[i] -= taosukazu1
  ans += taosukazu1
  print(A)
  print(B)
  if B[i] > 0:
    taosukazu2 = min(A[i+1],B[i])
    B[i] -= taosukazu2
    A[i] -= taosukazu2
    ans += taosukazu2
print(ans)

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
B.append(0)

ans = 0
for i in range(N+1):
  taosukazu1 = min(A[i],B[i])
  B[i] -= taosukazu1
  A[i] -= taosukazu1
  ans += taosukazu1
  if B[i] > 0:
    taosukazu2 = min(A[i+1],B[i])
    B[i] -= taosukazu2
    A[i+1] -= taosukazu2
    ans += taosukazu2
print(ans)
a=int(input("a="))
b=int(input("b="))
c=int(input("c="))
if a==b==c:
    print("No")
if a!=b!=c:
    print("No")
else :
    print("Yes")

### FIXED CODE ###

a,b,c=[int(x) for x in input().split()]
if a==b and b==c :
    print("No")
elif a!=b and b!=c and a!=c:
    print("No") 
else :
    print("Yes")
n = int(input())
while n != 0:
 A = 0
 B = 0
 for i in range(n):
  a, b = map(int, input().split())
  if a > b:
   A += a + b
  elif a < b:
   B += a + b
  else:
   A += a
   B += b
  print("{0} {1}".format(A, B))
  n = int(input())

### FIXED CODE ###

n = int(input())
while n != 0:
 A = 0
 B = 0
 for i in range(n):
  a, b = map(int, input().split())
  if a > b:
   A += (a + b)
  elif a < b:
   B += (a + b)
  else:
   A += a
   B += b
 print("{0} {1}".format(A, B))
 n = int(input())
n, m = map(int, input().split())
res = [0,10**5]
for i in ragne(m):
    l, r = map(int, input().split())
    res[0] = max(res[0], l)
    res[1] = min(res[1], r)

print(max(res[1]-res[0]+1,0))

### FIXED CODE ###

n, m = map(int, input().split())
res = [0,10**5]
for i in range(m):
    l, r = map(int, input().split())
    res[0] = max(res[0], l)
    res[1] = min(res[1], r)

print(max(res[1]-res[0]+1,0))
N,K,Q = map(int,input().split())

if K > Q:
    for i in range(N):
        print('Yes')
        sys.exit()

A = [int(input()) for i in range(Q)]

for i in range(N):
    temp = A.count(i+1)
    if K > Q-temp:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

N,K,Q = map(int,input().split())

A = []

for i in range(Q):
    A.append(int(input()))

points = [K-Q]*N

for i in range(Q):
    points[A[i]-1] += 1

for i in range(N):
    if points[i] > 0:
        print('Yes')
    else:
        print('No')
n = int(input())
L = list(map(int, input().split()))

cnt = 0
larger = 1
smaller = -1

d = [0] * (n - 1)
if (L[0] > L[1]):
    d[0] = -1
elif (L[0] < L[1]):
    d[0] = 1

cnt = 1
for i in range(n):
    if (i == 0):
        continue
    elif (i == n - 1):
        break
    else:
        if (L[i] < L[i + 1] and d[i - 1] >= 0):
            d[i] = 1
        elif (L[i] > L[i + 1] and d[i - 1] <= 0):
            d[i] = -1
        elif (L[i] < L[i + 1] and d[i - 1] < 0):
            cnt += 1
        elif (L[i] > L[i + 1] and d[i - 1] > 0):
            cnt += 1
        elif (L[i] == L[i + 1]):
            continue

print(cnt)


### FIXED CODE ###

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

if n == 1:
    print(1)
    exit()

d = [0] * (n - 1)
if (L[0] > L[1]):
    d[0] = -1
elif (L[0] < L[1]):
    d[0] = 1

for i in range(n):
    if (i == 0):
        continue
    elif (i == n - 1):
        break
    else:
        if (L[i] < L[i + 1]):
            d[i] = 1
        elif (L[i] > L[i + 1]):
            d[i] = -1

prev = 0
count = 0
for i in range(len(d)):
    if (i == 0):
        prev = d[i]
        continue
    if (prev == 1):
        if (d[i] == 1):
            continue
        elif (d[i] == 0):
            continue
        else:
            count += 1
            prev = 0
    elif (prev == -1):
        if (d[i] == -1):
            continue
        elif (d[i] == 0):
            continue
        else:
            count += 1
            prev = 0
    elif (prev == 0):
        if (d[i] == 1):
            prev = 1
        elif (d[i] == -1):
            prev = -1

print(count + 1)
= int(input())
highest_price = 0
sum = 0
for i in range(n):
    product = int(input())
    if highest_price < product:
        sum += highest_price/2
        highest_price = product
        sum += highest_price/2
    else:
        sum += product
print(int(sum))

### FIXED CODE ###

n = int(input())
highest_price = 0
sum = 0
for i in range(n):
    product = int(input())
    if highest_price < product:
        sum += highest_price/2
        highest_price = product
        sum += highest_price/2
    else:
        sum += product
print(int(sum))
a, b, c = map(int, input.split())

if a == b == c:
  print('No')
elif a != b and a != c and b != c:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

a, b, c  = (int(x) for x in input().split())
 
if a == b == c:
  print('No')
elif a != b and a != c and b != c:
  print('No')
else:
  print('Yes')
A,B = map(int,input().split())
if(B == 1):
    print(0)
elif((B-1)%(A-1) == 0):
    print((B-1)//(A-1)
else:
    print(B//A+1)

### FIXED CODE ###

A,B = map(int,input().split())
if(B == 1):
    print(0)
elif((B-1)%(A-1) == 0):
    print((B-1)//(A-1))
else:
    print(B//A+1)
n, m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

a.sort(reverse=True); b.sort(reverse=True)
c, s = 0, 1

for i in reversed(range(n * m)):
    try:
        x = a.index(i + 1) + 1
        row = 1
    except ValueError:
        row = 0
    try:
        y = b.index(i + 1) + 1
        column = 1
    except ValueError:
        column = 0

    if row * column:
        s *= 1
    elif not row * column and row + column:
        s *= column * x + row * y
    else:
        if x * y - c > 0:
            s *= x * y - c
        else:
            s = 0
            break
    c += 1
    if s > 10 ** 9 + 7:
        s %= 10 ** 9 + 7

print(s)


### FIXED CODE ###

n, m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

a = set(a); b = set(b)
#print(a, b)

def k(a, b, n, m):
    s = 1
    x, y = 0, 0
    if (n * m not in a) or (n * m not in b):
        return 0
    for i, j in enumerate(reversed(range(n * m))):

        if (j + 1 in a) and (j + 1 in b):
            x += 1; y += 1
            #continue
        elif j + 1 in a:
            y += 1
            s *= x
        elif j + 1 in b:
            x += 1
            s *= y
        else:
            if x * y - i > 0:
                s *= x * y - i
            else:
                s = 0
                break
        if s > 10 ** 9 + 7:
            s %= 10 ** 9 + 7
        #print(i, j + 1, 'x=', x, 'y=', y, 's=', s)
    return s

if len(a) != n or len(b) != m:
    print(0)
else:
    print(k(a, b, n, m))

# TimeLimitExceeded
# indexで一個ずつ見つけていくのは時間がかかるということ。
1=<N,X,T=<1000
number =N/X
number =round(number)
time = number*T
print(time)

### FIXED CODE ###

n,x,t=list(map(int,input().split()))
a=n%x
b=n//x
 
if a==0:
  c=b*t
else:
  c=(b+1)*t
print(c)
S, W = (int(x) for in input().split())
if W>=S:
  print("unsafe")
else:
  print("safe")

### FIXED CODE ###

S, W = (int(x) for x in input().split())
if W>=S:
  print("unsafe")
else:
  print("safe")
N=int(input())
A=list(map(int, input().split()))
count=[0]*10**6
for a in A:
  count[A]+=1
  
ans=0
for a in range(max(A)+1):
  now=count[a-1]+count[a]+count[a+1]
  ans=max(ans, now)
  
print(ans)

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
count=[0]*10**6
for a in A:
  count[a]+=1
  
ans=0
for a in range(max(A)+1):
  now=count[a-1]+count[a]+count[a+1]
  ans=max(ans, now)
  
print(ans)
h, w = map(int,input().split())
arr = [["."] * (w + 2)]
for i in range(w):
    arr += [["."] + list(input()) + ["."]]
arr += [["."] * (w + 2)]

flg = 0    

for j in range(1, h):
    for k in range(1, w):
        if arr[j][k] == "#":
            if (arr[j-1][w] == '.') and (arr[j][w-1] == '.') and (arr[j+1][w] == '.') and  (arr[j][w+1] == '.'):
                flg = 1    
        
if flg == 0:
    print('Yes')
else:
    print('No')
        


### FIXED CODE ###

h, w = map(int,input().split())
arr = [["."] * (w + 2)]
for i in range(h):
    arr += [["."] + list(input()) + ["."]]
arr += [["."] * (w + 2)]

flg = 0    

for j in range(1, h+1):
    for k in range(1, w+1):
        if arr[j][k] == "#":
            if (arr[j-1][k] == '.') and (arr[j][k-1] == '.') and (arr[j+1][k] == '.') and (arr[j][k+1] == '.'):
                flg = 1    
        
if flg == 0:
    print('Yes')
else:
    print('No')
def mulallnumber(lst):
   x=1
   for i in lst:
      x=x*i
      return x

A=list()

N=int(input("Enter the size of the list ::"))

print("Enter the element of list ::")
for i in range(int(N)):
   k=int(input(""))
   A.append(k)

if mulallnumber(A)<1000000000000000000:
    print(mulallnumber(A))
else:
    print('-1')


### FIXED CODE ###

# we collect the input A1 upto An.
# limit cannot exceed 10**18
# if N = 0 then ans = 0
# in N is in range then compute ans * A[n]
# else if  ans is greater than limit then display 1
# finally if length equal 1 then display -1
N = int(input())
ans = 1
limit = 10 ** 18
length = 0

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

A0 = set(A)
if 0 in A0:
    ans = 0
else:
    pass

for n in range(N):
    ans = ans * A[n]
    if ans == 0:
        break
    elif ans > limit:
        length = 1
        break
    else:
        pass

if length == 1:
    print(-1)
else:
    print(ans)
N = int(input())
A = [int(input()) for i in range(N)]

a1 = max(A)
B = A.remove(a1)
a2 = max(B)

for i in range(N):
    if A[i] != a1:
        print(a1)
    else:
        print(a2)

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]

B = A[:]

a1 = max(A)
A.remove(a1)
a2 = max(A)

for i in range(N):
    if B[i] != a1:
        print(a1)
    else:
        print(a2)
S=list(map(str,input()))
T=list(map(str,input()))
x=[]
y=0

for i in range(len(S)-len(T)):
    Y=S[i:i+len(T)]
    y=0
    for j in range(len(T)):
        if Y[j]==T[j]:
            y=y+1
    x.append(y)
print(len(T)-max(x))  

### FIXED CODE ###

S=list(map(str,input()))
T=list(map(str,input()))
X=[]
Z=0
for I in range(len(S)-len(T)+1):
    Y=S[I:I+len(T)]
    Z=0
    for J in range(len(T)):
        if Y[J]==T[J]:
            Z=Z+1
    X.append(Z)
if not X==[]:
    print(len(T)-max(X))
elif S==T:
    print(0)
else:
    print(len(T))
number1 = raw_input ()
number2 = raw_input ()
number3 = raw_input ()

if number1 + number2 + number3 == 12:
    print ('yes')
if number1 + number2 + number3 != 12:
    print ('no')

### FIXED CODE ###

x, y, z =  map(int, input().split())

if x + y + z == 17:
  print ("YES")
else:
  print ("NO")
def main():
    num = int(input())
    data = list(map(int, input().split()))
    data_kari = data.copy()
    data_kari.sort()
    # print(data_kari)
    min_chuou = data_kari[(num // 2) - 1]
    max_chuou = data_kari[num // 2]

    # print(min_chuou, max_chuou)

    # print(data)

    for i in range(num):
        if data[i] <= min_chuou:
            print(max_chuou)
        elif data[i] >= max_chuou:
            print(min_chuou)






if __name__ == '__main__':
    main()



### FIXED CODE ###


def main():
    num = int(input())
    data = list(map(int, input().split()))
    data_kari = data.copy()
    data_kari.sort()
    # print(data_kari)
    min_chuou = data_kari[(num // 2) - 1]
    max_chuou = data_kari[num // 2]

    # print(min_chuou, max_chuou)

    # print(data)

    for i in range(num):
        if data[i] <= min_chuou:
            print(max_chuou)
        elif data[i] >= max_chuou:
            print(min_chuou)






if __name__ == '__main__':
    main()
N = input()
T, A = map(int, input().split())
temperatures = list(map(int, input().split()))
 
r = 50000000
results = ''
 
list = [T - t * 0.006 for t in temperatures]
for index, avg_temp in enumerate(list):      

    if r > abs(ondo_sa):
        r = ondo_sa
        results = index + 1
print(results)

### FIXED CODE ###

N = input()
T, A = map(int, input().split())
temperatures = list(map(int, input().split()))
 
r = 50000000000000
results = ''
 
list = [T - t * 0.006 for t in temperatures]
for index, avg_temp in enumerate(list):
    ondo_sa = avg_temp - A
 
    if ondo_sa < 0:
        ondo_sa = - ondo_sa
 
    if r > abs(ondo_sa):
        r = ondo_sa
        results = index + 1
print(results)
N, M = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(M)]

S = C = []
for i in range(M):
    S.append(lst[i][0])
    C.append(lst[i][1])

ans = [10] * N
for l in lst:
    if ans[l[0]-1] < 10 and ans[l[0]-1] != l[1]:
        print(-1)
        exit()
    ans[l[0]-1] = l[1]

for i in range(M):
    if ans[i] == 10:
        ans[i] = 0

if N != 1 and ans[0] == 0:
    print(-1)
    exit()

ans = list(map(str, ans))
print("".join(ans))

### FIXED CODE ###

N, M = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(M)]

ans = [10] * N
for l in lst:
    if ans[l[0]-1] < 10 and ans[l[0]-1] != l[1]:
        print(-1)
        exit()
    ans[l[0]-1] = l[1]

if ans[0] == 10:
    if N == 1:
        ans[0] = 0
    else:
        ans[0] = 1
for i in range(1, N):
    if ans[i] == 10:
        ans[i] = 0

if N != 1 and ans[0] == 0:
    print(-1)
    exit()

ans = list(map(str, ans))
print("".join(ans))
import statistics

while True:
  s=int(input())
  if s==0:
    break
  else:
   lst=list(map(int,input().split()))
  print("{0:.8}".format(statitics.pstdev(lst)))
  

### FIXED CODE ###

import statistics

while True:
  s=int(input())
  if s==0:
    break
  else:
   lst=list(map(int,input().split()))
  print("{0:.8}".format(statistics.pstdev(lst)))
N=int(input())
l1=list(map(int,input().split()))
l2=[]
l3=[]
for i in range(N-1):
  if l1[i]<l1[i+1]:
    l2.append(i)
l2.append(N-2)
for i in range(len(l2)-1):
  l3.append(l2[i+1]-l2[i])
print(max(l3))

### FIXED CODE ###

N=int(input())
l1=list(map(int,input().split()))
l1.append(max(l1)+1)
l2=[-1]
l3=[]
for i in range(N):
  if l1[i]<l1[i+1]:
    l2.append(i)
for i in range(len(l2)-1):
  if l2[i+1]-l2[i] >= 2:
    l3.append(l2[i+1]-l2[i]-1)
print(max(l3) if l3 else 0)
def rest_col(s1,s2):
  if(s1=="R"):
    if(s2="R"):
      return -1
    elif(s2=="G"):
       return 2
    else:
       return 1
  if(s1=="G"):
    if(s2="G"):
      return -1
    elif(s2=="R"):
       return 2
    else:
       return 1
  if(s1=="B"):
    if(s2="B"):
      return -1
    elif(s2=="R"):
       return 1
    else:
       return 0

n=int(input())
s=input()
count=[[0,0,0] for i in range(n)]
for i in range(n):
  if(s[n-1-i]=="R"):
    count[n-1-i][0]+=1
  if(s[n-1-i]=="G"):
    count[n-1-i][1]+=1
  if(s[n-1-i]=="B"):
    count[n-1-i][2]+=1
ans=0
for a in range(n):
  for b in range(a,n):
    r=rest_color(s[a],s[b])
    if(r==-1):
      continue
    else:
      ans+=count[b+1][r]
print(ans)

### FIXED CODE ###

def rest_col(s1,s2):
  if(s1=="R"):
    if(s2=="R"):
      return -1
    elif(s2=="G"):
       return 2
    else:
       return 1
  if(s1=="G"):
    if(s2=="G"):
      return -1
    elif(s2=="R"):
       return 2
    else:
       return 0
  if(s1=="B"):
    if(s2=="B"):
      return -1
    elif(s2=="R"):
       return 1
    else:
       return 0

str_c=["R","G","B"]
n=int(input())
s=input()
count=[[0,0,0] for i in range(n)] #count[i][c]はi番目以上で色cの個数
if(s[n-1]=="R"):
  count[n-1][0]=1
if(s[n-1]=="G"):
  count[n-1][1]=1
if(s[n-1]=="B"):
  count[n-1][2]=1
for i in range(1,n):
  count[n-1-i][0]=count[n-i][0]
  count[n-1-i][1]=count[n-i][1]
  count[n-1-i][2]=count[n-i][2]
  if(s[n-1-i]=="R"):
    count[n-1-i][0]+=1
  if(s[n-1-i]=="G"):
    count[n-1-i][1]+=1
  if(s[n-1-i]=="B"):
    count[n-1-i][2]+=1
ans=0
for a in range(n-1):
  for b in range(a,n-1):
    r=rest_col(s[a],s[b])
    if(r!=-1):
      ans+=count[b+1][r]
      if(2*b-a<len(s)):
        if(s[2*b-a]==str_c[r]):
          ans-=1
print(ans)
n,m = list(map(int, input().split()))
a = []
b = []
for _ in range(m):
    aa, bb = list(map(int, input().split()))
    a.append(aa-1)
    b.append(bb-1)

a = a[::-1]
b = b[::-1]

ans = int(n * (n - 1) /2)
ans_rec = [0] * m
ans_rec[-1] = ans

p = [-1 for i in range(n)]
size = [1 for i in range(n)]

def find(x):
#     print(x, p[x])
    px = p[x]
    if px <0:
        return x
    else:
        pxx = find(px)
        p[x] = pxx
        return pxx

for k in range(m-1):
    pa = find(a[k])
    pb = find(b[k])
    if pa == pb:
        pass
    else:
        ans -= size[pa] * size[pb]
        size[pa] += size[pb]
        p[pb] = pa
    ans_rec[- k - 2] = ans
for aa in ans_rec:
    print(aa)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
 
N, M = map(int, input().split())
X = []
for _ in range(M):
    a, b = map(int, input().split())
    X.append((a-1, b-1))
X = X[::-1]
    
P = [-1] * N
CT = [1] * N
def pr(i):
    if P[i] < 0:
        return i
    t = pr(P[i])
    P[i] = t
    return t
 
ANS = [0] * M
ans = N * (N-1) // 2
ANS[-1] = ans
for m in range(M-1):
    a, b = X[m]
    pa = pr(a)
    pb = pr(b)
    
    if pa != pb:
        ans -= CT[pa] * CT[pb]
        P[pa] = pb
        CT[pb] += CT[pa]
 
    ANS[-m-2] = ans
 
for a in ANS:
    print(a)
def solve(s,i,x,y):
	A[y][x] = i
	if x < W-1 and A[y][x+1] == s: solve(s,i,x+1,y)
	if y < H-1 and A[y+1][x] == s: solve(s,i,x,y+1)
	if x > 0   and A[y][x-1] == s: solve(s,i,x-1,y)
	if y > 0   and A[y-1][x] == s: solve(s,i,x,y-1)
	
while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	A = [list(raw_input()) for i in range(H)]
	i = 1
	for y in range(H):
		for x in range(W):
			if A[y][x] in ["#","@","*"]:
				solve(A[y][x],i,x,y)
				i += 1
	print max([max(A[i]) for i in range(H)])

### FIXED CODE ###

import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count
N, M = map(int, input().split())
sc = []
tf = True
for i in range(M):
  sc.append(list(map(int, input().strip().split()))
num = []
for i in range(N):
  num.append(0)
for i in sc:
  if i[0] == N and i[1] == 0:
    tf = False
  else:
    num[i[0]-1] = i[1]
if tf:
  num[0] = 1
string = ""
for i in num:
  string += str(i)
if tf:
  print(string)
else:
  print(-1)

### FIXED CODE ###

N, M = map(int, input().split())
sc = []
tf = True
tff = False
for i in range(M):
  sc.append(list(map(int, input().strip().split())))
if len(sc) == 0:
  if N == 1:
    print(0)
  else:
    print("1"+"0"*(N-1))
else:
  num = []
  for i in range(N):
    num.append(0)
  sc.sort()
  if N == 1 and sc[0][0] == 1 and sc[0][1] == 0:
    tff = True
  for i in range(M-1):
    if sc[i][0] == sc[i+1][0] and sc[i][1] != sc[i+1][1]:
      tf = False
  for i in sc:
    if i[0] == 1 and i[1] == 0:
      tf = False
    else:
      num[i[0]-1] = i[1]
  if tf and num[0] == 0:
    num[0] = 1
  string = ""
  for i in num:
    string += str(i)
  if tff == True:
    print(0)
  elif tf == True:
    print(string)
  else:
    print(-1)
from math import gcd, sqrt
from sys import exit
N=int(input())
A=list(map(int,input().split()))

if len(A)==2:
    print(max(A))
    exit()

g=gcd(A[0],A[-1])

p=[]
for i in range(1,int(sqrt(g)+1)):
    if g%i==0:
        if i*i==g: p.append(i)
        else: p+=[i,g//i]
        
def ok(n):
    f=False
    for a in A[1:-1]:
        if a%n:
            if f: return False
            f=True
    return True
    
def GCD(L):
    if len(L)==1: return L[0]
    ans=gcd(L[0],L[1])
    if len(L)>2:
        for l in L[2:]:
            ans=gcd(ans,l)
    return ans

p.sort(reverse=True)
for num in p:
    if ok(num):
        ans=num
        break
p1=GCD(A[1:-1])
print(max([ans,gcd(p1,A[0]),gcd(p1,A[-1])]))


### FIXED CODE ###

from math import sqrt
from sys import exit
N=int(input())
A=list(map(int,input().split()))

if len(A)==2:
    print(max(A))
    exit()

def gcd(a,b):
    if a<b: a,b=b,a
    if a%b==0: return b
    return gcd(b,a%b)
    
g=gcd(A[0],A[-1])

p=[]

for i in range(1,int(sqrt(g)+1)):
    if g%i==0:
        if i*i==g: p.append(i)
        else: p+=[i,g//i]
        
def ok(n):
    f=False
    for a in A[1:-1]:
        if a%n:
            if f: return False
            f=True
    return True
    
def GCD(L):
    if len(L)==1: return L[0]
    ans=gcd(L[0],L[1])
    if len(L)>2:
        for l in L[2:]:
            ans=gcd(ans,l)
    return ans

p.sort(reverse=True)
for num in p:
    if ok(num):
        ans=num
        break
p1=GCD(A[1:-1])
print(max([ans,gcd(p1,A[0]),gcd(p1,A[-1])]))