Harryxun/stf_run huggingface dataset:
import sys
def read_data():
  n=input()
  x=[]
  for i in range(10): x.append(map(int,raw_input().split()))
  return n, x

def is_area3(x,y):
  if x>7 or y>5: return False
  for dx in [0,1,2,1,0]:
    A=P[y][x-dx:x+dx+1]
    if A.count(0)>0: return False
    y+=1
  return True
      
def is_area2(x,y):
  if x>7 or y>7: return False
  for dy in [0,1,2]:
    A=P[y+dy][x:x+3]
    if A.count(0)>0: return False
  return True

def is_area1(x,y):
  if x>8 or y>7: return False
  for dx in [0,1,0]:
    A=P[y][x-dx:x+dx+1]
    if A.count(0)>0: return False
    y+=1
  return True

def ink(x,y,s,m):
  global P
  dx = [0,1,-1,0,0,1,1,-1,-1,2,-2,0,0]
  dy = [0,0,-0,1,-1,1,-1,1,-1,0,0,2,-2]
  for i in range([5,9,13][s-1]):
    P[y+dy[i]][x+dx[i]]+=m
  return

drops,P = read_data()
A=[]
i=-1
m=3
while i<99:
  i+=1
  y=i/10
  x=i%10
  if P[y][x]==0: continue

  if m==3:
    while is_area3(x,y):
      A.append([x,y,3])
      ink(x,y+2,3,-1)
    if P[y][x]==0:
      m=3
      continue
    else: m=2

  if m==2:
    while is_area2(x,y):
      A.append([x,y,2])
      ink(x+1,y+1,2,-1)
    if P[y][x]==0:
      m=3
      continue
    else: m=1

  if m==1:
    while is_area1(x,y):
      A.append([x,y,1])
      ink(x,y+1,1,-1)
    if P[y][x]==0:
      m=3
      continue
    else: m=0

  dx=[0,1,0]
  dy=[1,1,2]
  if m==0 and len(A)>0:
    x,y,m=A.pop()
    m-=1
    ink(x+dx[m],y+dy[m],m+1,1)
    i = y*10+x-1
  else:
    break
if drops <=12 and len(A)==drops:
  for x,y,s in A: print x+dx[s-1],y+dy[s-1],s

### FIXED CODE ###

def read_data():
  n=input()
  x=[]
  for i in range(10):
    x.append(map(int,raw_input().split()))
  return n, x
 
def is_area3(x,y):
  if x>7 or y>5: return False
  for dx in [0,1,2,1,0]:
    A = P[y][x-dx:x+dx+1]
    if A.count(0)>0: return False
    y += 1
  return True
       
def is_area2(x,y):
  if x>7 or y>7: return False
  for dy in [0,1,2]:
    A = P[y+dy][x:x+3]
    if A.count(0)>0: return False
  return True
 
def is_area1(x,y):
  if x>8 or y>7: return False
  for dx in [0, 1, 0]:
    A = P[y][x-dx:x+dx+1]
    if A.count(0)>0: return False
    y += 1
  return True
 
def ink(x,y,s,m):
  global P
  dx = [0,1,-1,0,0,1,1,-1,-1,2,-2,0,0]
  dy = [0,0,-0,1,-1,1,-1,1,-1,0,0,2,-2]
  for i in range([5,9,13][s-1]):
    P[y+dy[i]][x+dx[i]]+=m
  return
 
drops, P = read_data()
M=[]
i=-1
step =3
while i<99:
  i+=1
  y = i / 10
  x = i % 10
  if P[y][x]==0: continue
 
  if step==3:
    while is_area3(x,y):
      M.append([x,y,3])
      ink(x,y+2,3,-1)
    if P[y][x]==0:
      step = 3
      continue
    else: step = 2
 
  if step==2:
    while is_area2(x,y):
      M.append([x,y,2])
      ink(x+1,y+1,2,-1)
    if P[y][x]==0:
      step = 3
      continue
    else: step = 1
 
  if step==1:
    while is_area1(x,y):
      M.append([x,y,1])
      ink(x,y+1,1,-1)
    if P[y][x]==0:
      step = 3
      continue
    else: step = 0
 
  dx=0
  dy=1
  if step==0 and len(M)>0:
    x,y,tmp = M.pop()
    if tmp==3: dy=2
    elif tmp==2: dx=1
    ink(x+dx,y+dy,tmp,1)
    i = y*10+x-1
    step = tmp-1
  else: break
if drops <=12 and len(M)==drops:
  for x,y,s in M:
    dx=0
    dy=1
    if s==3: dy=2
    elif s==2: dx=1
    print x+dx,y+dy,s
N = int(input())
A = list(map(int,input().split()))
A.sort()
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if (A[i]!=A[k]!=A[j]):
        if (A[i]+A[j])>A[k]:
          cnt+=1
        
print(cnt)

### FIXED CODE ###

s = input()
if s == 'RRR':
  print(3)
elif s=='RSR' or s=='SRS' or s=='SSR' or s=='RSS':
  print(1)
elif s == s=='RRS' or s=='SRR':
  print(2)
else:
  print(0)
import math

r = raw_input()

print '%f %f%'%(float(r)*float(r)*math.pi, float(r)*2*math.pi)

### FIXED CODE ###

import math

r = raw_input()

print '%f %f'%(float(r)*float(r)*math.pi, float(r)*2*math.pi)
s=input()
k=int(input())
if s[:k]=='1'*k:
  print(1)
else:
  for i in s:
    if i!='1':
      print(i)
      break

### FIXED CODE ###

import sys
s=input()
k=int(input())
if k<=100:
  if s[:k]=='1'*k:
    print(1)
    sys.exit()
for i in s:
  if i!='1':
    print(i)
    break
from heapq import *
import numpy as np
n,m,s,t=map(int,input().split())
a=[[]for i in range (n+1)]
b=[[]for i in range(n+1)]
for i in range(m):
    p,q,r,g=map(int,input().split())
    a[p].append([q,r])
    a[q].append([p,r])
    b[p].append([q,g])
    b[q].append([p,g])
def f(x,r):
    p=[float("INF")]*(n+1)
    p[x],q=0,[[0,x]]
    while q:
        y,z=heappop(q)
        for i in r[z]:
            if p[i[0]]>y+i[1]:
                p[i[0]]=y+i[0]
                heappush(q,[y+i[1],i[0]])
    return p[1:]
s1,t1=f(s,a),f(t,b)
p=[]
for i in range(n):
    p.append([s1[i]+t1[i],i])
p,e=sorted(p),0
for i in range(n):
    while p[e][1]<=i: e+=1
    print(10**15-p[e][0])

### FIXED CODE ###

from heapq import heappush,heappop
n,m,s,t=map(int,input().split())
a,b=[[]for i in range (n+1)],[[]for i in range(n+1)]
for i in range(m):
    p,q,r,g=(int(i) for i in input().split())
    a[p].append((q,r))
    a[q].append((p,r))
    b[p].append((q,g))
    b[q].append((p,g))
def f(x,r):
    p=[float("inf")for i in range(n+1)]
    p[x],q=0,[[0,x]]
    while q:
        y,z=heappop(q)
        for i,j in r[z]:
            if p[i]>y+j:
                p[i]=y+j
                heappush(q,[p[i],i])
    return p
s1,t1,p=f(s,a),f(t,b),[]
for i in range(1,n+1):
    p.append((s1[i]+t1[i],i))
p,e=sorted(p),0
for i in range(n):
    while p[e][1]<=i: e+=1
    print(10**15-p[e][0])
S_len=len(input())
K=int(input())
for i in range(S_len):
  if(int(a[0][i])==1):
    K-=1
    if(K<=0):
      print("1")
      break
  else:
    print(a[0][i])
    break

### FIXED CODE ###

S=input()
S_len=len(S)
K=int(input())
for i in range(S_len):
  if(int(S[i])==1):
    K-=1
    if(K<=0):
      print("1")
      break
  else:
    print(S[i])
    break
N=int(input())
x=['']*N
y=['']*N
dic={}
for i in range(N):
    x[i],y[i]=map(int,input().split())

for i in range(N):
    for j in range(N):
        if i==j:
            pass
        else:
            p=y[j]-y[i]
            q=x[j]-x[i]
            if (p,q) in dic.keys():
                dic[(p,q)] += 1
            else:
                dic[(p,q)] = 1

print(N-max(dic.values()))

### FIXED CODE ###

N=int(input())
x=['']*N
y=['']*N
dic={(0,0):0}
for i in range(N):
    x[i],y[i]=map(int,input().split())

for i in range(N):
    for j in range(N):
        if i==j:
            continue
        else:
            p=y[j]-y[i]
            q=x[j]-x[i]
            if (p,q) in dic.keys():
                dic[(p,q)] += 1
            else:
                dic[(p,q)] = 1

print(N-max(dic.values()))
Sa = input()
Sb = input()
Sc = input()

dic = {'a':Sa, 'b':Sb, 'c':Sc}

doCont = True
person = 'a'
result = ''
while doCont:
  if (len(dic[person]) == 0):
    doCont = False
    result = person.upper()

  drop_card = dic[person][0]
  dic[person] = dic[person][1:]
  person = drop_card

print(result)

### FIXED CODE ###

Sa = input()
Sb = input()
Sc = input()

dic = {'a':Sa, 'b':Sb, 'c':Sc}

doCont = True
person = 'a'
result = ''
while doCont:
  if (len(dic[person]) == 0):
    doCont = False
    result = person.upper()
    break

  drop_card = dic[person][0]
  dic[person] = dic[person][1:]
  person = drop_card

print(result)
n = input
if n % 2 == 0:
  return 1/2
else:
  return (n/2 + 0.5)/n


### FIXED CODE ###

n = int(input())
if n % 2 == 0:
  print(1/2)
else:
  print((n/2 + 0.5)/n)
A,B,C,K=map(int,input().split())
if (A>=K):
	print(K)
else:
	K = K-A
	if (B>=K):
		print(A)
	else:
		K = K-B
		print(A-K)

### FIXED CODE ###

S=input()
T=input()
if (S==T[:len(T)-1]):
  print("Yes")
else:
  print("No")
import heapq

X,Y,Z,K = map(int, input().split())
A = map(int, input().split())
B = map(int, input().split())
C = map(int, input().split())

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)

h = []

h.heappush((A[0]+B[0]+C[0], 0,0,0))

result = []

for _ in range(K):
	value, i,j,k = h.heappop()
    result.append(value)
    if i < X-1:
    	h.heappush((A[i+1]+B[j]+C[k],i,j,k))
    if j < Y-1 and i == 0:
      	h.heappush((A[i]+B[j+1]+C[k],i,j+1,k))
    if k < Z-1 and i == 0 and j == 0:
      	h.heappush((A[i]+B[j]+C[k+1],i,j,k+1))
        
for v in result:
	print(v)

### FIXED CODE ###

import heapq

X,Y,Z,K = map(int, input().split())
A = [int(x) for x in  input().split()]
B = [int(x) for x in  input().split()]
C = [int(x) for x in  input().split()]

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)

h = []

heapq.heappush(h, (-A[0]-B[0]-C[0], 0,0,0))

result = []
used = set()

for _ in range(K):
    value, i,j,k = heapq.heappop(h)
    result.append(-value)
    if i < X-1 and (i+1,j,k) not in used:
        heapq.heappush(h, (-A[i+1]-B[j]-C[k],i+1,j,k))
        used.add((i+1,j,k))
    if j < Y-1 and (i,j+1,k) not in used:
        heapq.heappush(h, (-A[i]-B[j+1]-C[k],i,j+1,k))
        used.add((i,j+1,k))
    if k < Z-1 and (i,j,k+1) not in used:
        heapq.heappush(h, (-A[i]-B[j]-C[k+1],i,j,k+1))
        used.add((i,j,k+1))
        
for v in result:
    print(v)
A = str(input())
B = int(input())
count = 0

for i in range(len(A)):
    if A[i] == "1":
        count += 1
    else:
        if B <= count:
            print(1)
            sys.exit()
        else:
            print(A[i])
            sys.exit()
print(1)


### FIXED CODE ###

import sys
A = str(input())
B = int(input())
count = 0

for i in range(len(A)):
    if A[i] == "1":
        count += 1
    else:
        if B <= count:
            print(1)
            sys.exit()
        else:
            print(A[i])
            sys.exit()
print(1)
import math
a = int(input())
num_list = list(map(int, input().split()))
head_gcd_list = [num_list[0]]
tail_gcd_list = [num_list[-1]]
for i in range(a - 2):
    head_gcd_list.append(math.gcd(head_gcd_list[i], num_list[i+1]))
    tail_gcd_list.append(math.gcd(tail_gcd_list[(i*-1) - 1], num_list[(i*-1) - 2]))
max_gcd = max(head_gcd_list.pop(-1), tail_gcd_list.pop(-1))
for i,j in zip(head_gcd_list, reversed(tail_gcd_list)):
    current_gcd = math.gcd(i, j)
    if(current_gcd > max_gcd):
        max_gcd = current_gcd
print(max_gcd)

### FIXED CODE ###


import fractions
a = int(input())
num_list = list(map(int, input().split()))
head_gcd_list = [0]
tail_gcd_list = [0]
for i in range(a - 1):
    head_gcd_list.append(fractions.gcd(head_gcd_list[i], num_list[i]))
    tail_gcd_list.append(fractions.gcd(tail_gcd_list[i], num_list[(i*-1) - 1]))
max_gcd = 0
for i,j in zip(head_gcd_list, reversed(tail_gcd_list)):
    current_gcd = fractions.gcd(i, j)
    if(current_gcd > max_gcd):
        max_gcd = current_gcd
print(max_gcd)
N = int(input())
S = [input() for _ in range(N)]

cnt = 0
end_a = 0
sta_b = 0
a_b = 0
for s in S:
    cnt += s.count('AB')
    if s[-1]=='A' and s[0]=='B':
        a_b += 1
    elif s[-1]=='A':
        end_a += 1
    elif s[0]=='B':
        sta_b += 1

a_b = [a_b, a_b]
if a_b[0]>=end_a:
    cnt += end_a
    a_b[0] -= end_a
    end_a = 0
else:
    cnt += a_b
    a_b[0] = 0
    end_a -= a_b

if a_b[1]>=sta_b:
    cnt += sta_b
    a_b[1] -= sta_b
    sta_b = 0
else:
    cnt += a_b
    a_b[1] = 0
    sta_b -= a_b
cnt += min(end_a, sta_b)
cnt += min(a_b)
print(cnt)

### FIXED CODE ###

N = int(input())
S = [input() for _ in range(N)]

cnt = 0
end_a = 0
sta_b = 0
a_b = 0
for s in S:
    cnt += s.count('AB')
    if s[-1]=='A' and s[0]=='B':
        a_b += 1
    elif s[-1]=='A':
        end_a += 1
    elif s[0]=='B':
        sta_b += 1
if a_b>=1:
    cnt += a_b-1
    if end_a>=1:
        end_a -= 1
        cnt += 1
    if sta_b>=1:
        sta_b -=1
        cnt+=1
cnt += min(end_a, sta_b)

print(cnt)
a=int(input())
if a=1:
  print(a)
elif int(a/2)=0:
  print((a/2)/a)
else:
  print((int(a/2)+1)/a)


### FIXED CODE ###

import math
a=int(input())
b=math.floor(float(a/2))
print(float((a-b)/a))
import math
n,a,b=map(int,input().split(" "))
kouho=[]
for i in range(0,n+1)
	i=str(i)
	keta=list(map(int,i))
	wa=sum(keta)
    if a<=wa<=b:
      kouho.append(i)
print(sum(kouho))



### FIXED CODE ###

n,a,b=map(int,input().split(" "))
kouho=[]
for i in range(1,n+1):
  i=str(i)
  keta=list(map(int,i))
  wa=sum(keta)
  if a<=wa<=b:
    kouho.append(int(i))
print(sum(kouho))
n,a,b = map(int,input().split())

#場合分けで考える
#中央にお互い移動する
#aorbが端まで移動して、その後お互いによる

dist = []
if (b-a)%2==0:
    d = (b-a)/2
    dist.append(d)
#aのほうが近い場合
if a-1<=n-b:
    a_dist = a-1
    re_b = b-a_dist
    if (re_b-1)%2==0:
        d = a_dist+(re_b-1)/2
    else:
        d = a_dist+(re_b-2)/2+1
    dist.append(d)
if a-1>n-b:
    b_dist = n-b
    re_a = a-b_dist
    if (n-re_a)%2==0:
        d = b_dist+(n-re_a)/2
    else:
        d = a_dist+(n-re_a-1)/2+1
    dist.append(d)
print(int(min(dist)))

### FIXED CODE ###

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

#場合分けで考える
#b-aが偶数の場合、お互いに移動すればよい
#b-aが奇数の場合、末端に近いほうが端まで移動し、その後いターン消費して、距離をお互いに詰める

if (b-a)%2==0:
    ans = int((b-a)//2)
else:
    #端までの距離が近いほうの移動ステップ
    #端まで移動した際のお互いの距離は変化していない、そこから1ターン消費する
    #距離が偶数になるのでお互いに移動する
    ans = int(min(a-1,n-b)+1+(b-a-1)//2)

print(ans)
s = list(input())
k = int(input())
if '1' in s and s.index('1') == 0 :
    print(s[1])
else:
    print(s[0])


### FIXED CODE ###

s = list(input())
k = int(input())
if '1' not in s:
    print(s[0])
else:
    num = 0
    for i in range(len(s)):
        if s[0] == "1":
            s.pop(0)
            num += 1
        else:
            break
    if num >= k:
        print(1)
    else:
        print(s[0])
A, B, C = map(int, input().split())

combi = [A, B, C]
max_ABC = max([A, B, C])
other = [c for c in combi if c != max_ABC]
max_other = max(other)
min_other = min(other)

# Operation (1st method)
n_operation = max_ABC - max_other
max_other += n_operation
min_other += n_operation

if max_other == min_other:
    print(n_operation)
    exit()

# Operation (2nd method)
if (max_ABC - min_other) % 2:
    n_add = (max_ABC - min_other) // 2 + 1
else:
    n_add = (max_ABC - min_other) // 2
n_operation += n_add

print(n_operation)


### FIXED CODE ###

# WIP
A, B, C = map(int, input().split())

combi = [A, B, C]
set_abc = set(combi)

len_set_abc = len(set_abc)
max_set = max(set_abc)
min_set = min(set_abc)
if len_set_abc == 1:
    print(0)
elif len_set_abc == 2:
    max_freq = combi.count(max_set)
    diff = max_set - min_set
    if max_freq == 2 and diff % 2:
        print((diff + 1) // 2 + 1)
    elif max_freq == 2:
        print(diff // 2)
    else:
        print(diff)
else:
    other = [c for c in combi if c != max_set]
    max_other = max(other)
    min_other = min(other)
    
    n_operation = max_set - max_other
    max_other += n_operation
    min_other += n_operation

    diff = max_set - min_other
    if diff % 2 and diff == 1:
        n_add = (max_set - min_other) // 2 + 2
    elif diff % 2:
        n_add = (max_set - min_other) // 2 + 2
    else:
        n_add = (max_set - min_other) // 2
    n_operation += n_add

    print(n_operation)
D = int(input())
C = list(map(int, input().split()))
S = []
for d in range(D):
    S += [list(map(int, input().split()))]
#print(C)
#print(S)
myans = [i for i in range(26)]
#print(myans)

def estimate(mylist):
    mycost = 0
    dayflag = [0 for n in range(26)]
    for d in range(1,D+1):
        mycontest = mylist[d-1]
        mycost += S[d-1][mycontest]
        dayflag[mycontest] = d
        #print(mycontest, d, dayflag)
        for i in range(26):
             mycost -= C[mycontest] * (d - dayflag[i])
    return mycost

import random
import copy
times = 10**4
bestcost = 0
random.seed(1)
for i in range(times):
    a = random.randrange(26)
    b = random.randrange(26)
    mylist = copy.deepcopy(myans)
    #print(a,b, mylist)
    mylist[a] = myans[b]
    mylist[b] = myans[a]
    #print(mylist)
    #estimate
    mycost = estimate(mylist)
    if  bestcost < mycost:
        bestcost = mycost
        myans = mylist
        #print(i, bestcost)
for d in range(D):
    print(myans[d]+1)

### FIXED CODE ###

D = int(input())
C = list(map(int, input().split()))
S = []
N = 26
for d in range(D):
    S += [list(map(int, input().split()))]
#print(C)
#print(S)
myans = [d%N for d in range(D)]
for d in range(D):
  print(myans[d]+1)
def main():
    n = int(input())
    a = list(map(lambda x: int(x)-1, input().split()))
    J = [0 for i in range(int(2e5+3))]

    for i in range(n):
        tmp = i - a[i]
        if 0 <= tmp:
            J[tmp] += 1

    cnt = 0
    for i in range(n):
        tmp = a[i]+i+2
        cnt += J[tmp]

    print(cnt)
    return


if __name__ == "__main__":
    main()


### FIXED CODE ###

J = [0 for i in range(int(2e5+3))]


def main():
    n = int(input())
    a = list(map(lambda x: int(x)-1, input().split()))

    for i in range(n):
        tmp = i - a[i]
        if 0 < tmp:
            J[tmp] += 1

    cnt = 0
    for i in range(n):
        tmp = a[i]+i+2
        if tmp < len(J)-1:
            cnt += J[tmp]

    print(cnt)
    return


if __name__ == "__main__":
    main()
n = int(input())
t = 0
st = 0
cn = []
sn = []
fn = []

for i in range(n-1):
  c,s,f = map(int,input().split())
  cn.append(c)
  sn.append(s)
  fn.append(f)

for j in range(n-1):
    for i in range(j,n-1):
      st = sn[i]
      if t <= sn[i]:
        t = sn[i]
      else:
        while t <= st :
          st += fn[i]
      t += cn[i]
    print(t)
    t = 0
        
 print(0)
  
  

### FIXED CODE ###

n = int(input())
t = 0
st = 0
cn = []
sn = []
fn = []

for i in range(n-1):
  c,s,f = map(int,input().split())
  cn.append(c)
  sn.append(s)
  fn.append(f)

for j in range(n-1):
    t = 0
    for i in range(j,n-1):
      st = sn[i]
      if t <= sn[i]:
        t = sn[i]
      if t%fn[i] != 0:
          t += fn[i]-t%fn[i]
      t += cn[i]
    print(t)


print(0)
WeatherToady = input()
if WeatherToday == "Sunny":
  print("Cloudy")
elif WeatherToday == "Cloudy":
  print("Rainy")
else:
  print("Sunny")


### FIXED CODE ###

WeatherToday = input()
if WeatherToday == "Sunny":
  print("Cloudy")
elif WeatherToday == "Cloudy":
  print("Rainy")
else:
  print("Sunny")
N,M=map(int,input().split())

d={}

condi = []

string = ['0']*N

flg=0
for _ in range(M):
    s,c = map(int,input().split())

    condi.append([s,c])

    if s not in d:
        d[s]=c
    elif s in d and d[s]!=c:
        flg+=1

if flg!=0:
    print(-1)
    exit(0)

if d[1]==0:
    print(-1)
    exit(0)



for i in range(N):
    if i==0 and 1 not in d :
        string[0] = '1'
    else:
        if i+1 in d:
            string[i] = str(d[i+1])

str_num = ''.join(string)
print(str_num)


### FIXED CODE ###

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

d={}

condi = []

string = ['0']*N

flg=0
for _ in range(M):
    s,c = map(int,input().split())

    condi.append([s,c])

    if s not in d:
        d[s]=c
    elif s in d :
        if d[s]!=c:
            flg+=1

if flg!=0:
    print(-1)
    exit(0)

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

if N==1 and M==0:
    print(0)
    exit(0)

for i in range(N):
    if i==0 and 1 not in d :
        string[0] = '1'
    else:
        if i+1 in d:
            string[i] = str(d[i+1])

str_num = ''.join(string)
print(str_num)
n = input()

s = sum([int(i) for i in n])

if int(n)%s==0:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

s = input()
ans = 0
for n in s:
    if n == '+': ans += 1
    else: ans -= 1
print(ans)
from collections import deque
n = int(input())
nums =[]

for i in range(n):
  nums.append(int(input()))

nums.sort()
nums = deque(nums)
a = [nums.pop()]
a = deque(a)

while not len(nums) == 0:
  try:
    a.appendleft(nums.popleft())
    a.append(nums.popleft())
    a.appendleft(nums.pop())
    a.append(nums.pop())
  except IndexError:
    pass

tmp_1 = abs(a[-1] - a[-2])
tmp_2 = abs(a[-1] - a[0])

if tmp_1 < tmp_2:
  a.appendleft(0,a.pop())

sub = 0
for i in range(1, len(a)):
  sub += abs(a[i-1]-a[i])
print(sub)


### FIXED CODE ###

from collections import deque
n = int(input())
nums =[]

for i in range(n):
  nums.append(int(input()))

nums.sort()
nums = deque(nums)
a = [nums.pop()]
a = deque(a)

while not len(nums) == 0:
  try:
    a.appendleft(nums.popleft())
    a.append(nums.popleft())
    a.appendleft(nums.pop())
    a.append(nums.pop())
  except IndexError:
    pass

tmp_1 = abs(a[-1] - a[-2])
tmp_2 = abs(a[-1] - a[0])

if tmp_1 < tmp_2:
  a.appendleft(a.pop())

sub = 0
for i in range(1, len(a)):
  sub += abs(a[i-1]-a[i])
print(sub)
n,k = map(int,input().split())
setted_line = list(set(map(int,input().split())))
origin_num = len(setted_line) 
pairs = {}
for i in range(len(setted_line)):
  count = line.count(setted_line[i])
  pairs[setted_line[i]] = count
sorted_pairs = sorted(pairs.items(), key = lambda x:x[1])
answer = 0
if origin_num <= k:
  answer = 0
else:
  gap = origin_num - k 
  for j in range(gap):
    answer += sorted_pairs[j][1]
print(answer)

### FIXED CODE ###

import collections
n,k = map(int,input().split())
line = list(input().split())
c = collections.Counter(line)
answer = 0
if k > len(c):
  answer = 0
else:
  gap = len(c) - k
  sorted_c = list(sorted(c.items(),key = lambda x:x[1]))
  for i in range(gap):
    answer += int(sorted_c[i][1])
print(answer)
p, q, r = map(int, input().split())
print(min([p + q, q + r. r + p]))

### FIXED CODE ###

p, q, r = map(int, input().split())
print(min([p + q, q + r, r + p]))
import math
import fractions
from collections import Counter as ct

def gcd_list(l):
    for n,i in enumerate(l):
        if n==0:cur=i
        cur=fractions.gcd(cur,i)
    return cur

def yakusulist(n):
    ans=[]
    for i in range(1,int(math.sqrt(n+1))+1):
        if n%i==0:
            ans.append(i)
            ans.append(n//i)
    return(set(ans))
    
def warennnokaomaera(n):
    if n==1:return(True)
    for k,i in enumerate(A):
        if k<3:continue
        if i%n:return(False)
    return(True)

N=int(input())
data=[int(i) for i in input().split()]
datagcd=gcd_list(data)
A=[i//datagcd for i in data]
if N>2:
    alpha=sorted(ct(A).keys())
    min3=[alpha[0],alpha[1],alpha[2]]
    p,q,r=[yakusulist(n) for n in min3]
    pq=p&q
    qr=q&r
    rp=r&p
    overtwo=pq|qr|rp
    overtwo=sorted(list(overtwo),reverse=True)
    for i in overtwo:
        if warennnokaomaera(i):
            print(datagcd*i)
            break
else:print(max(data))

### FIXED CODE ###

import math
import fractions
from collections import Counter as ct

def gcd_list(l):
    for n,i in enumerate(l):
        if n==0:cur=i
        cur=fractions.gcd(cur,i)
    return cur

def yakusulist(n):
    ans=[]
    for i in range(1,int(math.sqrt(n+1))+1):
        if n%i==0:
            ans.append(i)
            ans.append(n//i)
    return(set(ans))
    
def warennnokaomaera(n):
    warenai=0
    for k,i in enumerate(A):
        if i%n and warenai==0:
            warenai+=1
            continue
        if i%n and warenai:return(False)
    return(True)

N=int(input())
data=[int(i) for i in input().split()]
datagcd=gcd_list(data)
A=[i//datagcd for i in data]
if N>2:
    co=ct(A)
    alpha=sorted(co.keys())
    if len(alpha)>=3:
        min3=[alpha[0],alpha[1],alpha[2]]
        p,q,r=[yakusulist(n) for n in min3]
        pq=p&q
        qr=q&r
        rp=r&p
        overtwo=pq|qr|rp
        overtwo=sorted(list(overtwo),reverse=True)
        for i in overtwo:
            if warennnokaomaera(i):
                print(datagcd*i)
                break
    elif len(alpha)==2:#Aの数の種類が2種類以下->1個書き換えで違う数ってどっちかが一個じゃないと無理、それ以外はそのまま
        if co[alpha[0]]==1:
            print(datagcd*alpha[1])
        elif co[alpha[1]]==1:
            print(datagcd*alpha[0])
        else:print(datagcd)
    else:print(datagcd)
else:print(max(data))
n = int(input())
p = [int(i) for i in input().split()]

a = [30000*i for i in range(n)]
b = [30000*(n-i) for i in range(n)]

for i,v in enumerate(p):
    a[v] += i

print(*a)
print(*b)

### FIXED CODE ###

n = int(input())
p = [int(i) for i in input().split()]

a = [30000*i for i in range(n)]
b = [30000*(n-i) for i in range(n)]

for i,v in enumerate(p):
    a[v-1] += i+1

print(*a)
print(*b)
S=input()
K=int(input())
tmp = 0
for i in S:
    if i=='1':
        tmp += 1
    else:
        break
if K >= tmp:
    print(1)
else:
    print(S[tmp])

### FIXED CODE ###

S=input()
K=int(input())
tmp = 0
for i in S:
    if i=='1':
        tmp += 1
    else:
        break
if K <= tmp:
    print(1)
else:
    print(S[tmp])