Harryxun/stf_run huggingface dataset:
import pandas as pd
import numpy as np
from itertools import combinations

z = []
N = int(input())
for i in range(N):
    temp_x, temp_y = map(int, input().split())
    z = z + [temp_x] + [temp_y]
z = np.array(z).reshape(N,2)
print(z)

d = 0
count = 0
for j, k in combinations(range(N),2):
    temp_d = np.sqrt((z[j,0] - z[k,0])**2 + (z[j,1] - z[k,1])**2)
    d += temp_d
    count += 1
print(d*(N-1)/count)

### FIXED CODE ###

import numpy as np
from itertools import combinations
 
z = []
N = int(input())
for i in range(N):
    temp_x, temp_y = map(int, input().split())
    z = z + [temp_x] + [temp_y]
z = np.array(z).reshape(N,2)
 
d = 0
count = 0
for j, k in combinations(range(N),2):
    temp_d = np.sqrt((z[j,0] - z[k,0])**2 + (z[j,1] - z[k,1])**2)
    d += temp_d
    count += 1
print(d*(N-1)/count)
n=int(input())
l=sorted(list(map(int,iput().split()),reverse=True)
print(sum(l[1::2])

### FIXED CODE ###

n=int(input())
l=sorted(list(map(int,input().split())),reverse=True)
print(sum(l[1::2]))
import sys,itertools
def input():
    return sys.stdin.readline()[:-1]

H,W,K = map(int,input().split(' '))
l = [list(input()) for _ in range(H)]

MAP = [None]*H
for i in range(H):
    MAP[i] = [None]*W

cnt = 1
dp = []
for i in range(H):
    all_white_f = True
    flag = True
    for j in range(W):
        k = l[i][j]
        if k=='#':
            if not flag:
                cnt += 1
            all_white_f = False
            flag = False
        MAP[i][j] = str(cnt)
    if all_white_f:
        MAP[i] = None
        dp.append(i)
        cnt -= 1
    cnt += 1
pre = -1
tmp = []
f = True
if len(dp)==0:
    for i in range(H):
        print(' '.join(MAP[i]))
    exit()
if dp[0]==0:
    for i in dp:
        if i-pre==1:
            tmp.append(i)
            pre = i
        else:
            if f:
                for j in tmp:
                    first = tmp[-1]+1
                    MAP[j] = MAP[first]
            MAP[i] = MAP[i-1]
else:
    for i in dp:
        MAP[i] = MAP[i-1]
for i in range(H):
    print(' '.join(MAP[i]))

### FIXED CODE ###

import sys,itertools
def input():
    return sys.stdin.readline()[:-1]

H,W,K = map(int,input().split(' '))
l = [list(input()) for _ in range(H)]

MAP = [None]*H
for i in range(H):
    MAP[i] = [None]*W

cnt = 1
dp = []
for i in range(H):
    all_white_f = True
    flag = True
    for j in range(W):
        k = l[i][j]
        if k=='#':
            if not flag:
                cnt += 1
            all_white_f = False
            flag = False
        MAP[i][j] = str(cnt)
    if all_white_f:
        MAP[i] = None
        dp.append(i)
        cnt -= 1
    cnt += 1
pre = -1
tmp = []

if len(dp)==0:
    for i in range(H):
        print(' '.join(MAP[i]))
    exit()


if dp[0]==0:
    for i in dp:
        if i-pre==1:
            tmp.append(i)
            pre = i
        else:
            if len(tmp)!=0:
                for j in tmp:
                    first = tmp[-1]+1
                    MAP[j] = MAP[first]
                tmp = []
            MAP[i] = MAP[i-1]
    if len(tmp)!=0:
        for j in tmp:
            first = tmp[-1]+1
            MAP[j] = MAP[first]
else:
    for i in dp:
        MAP[i] = MAP[i-1]
for i in range(H):
    print(' '.join(MAP[i]))
a=list()
for i in range(5):
  a.append(int(input()))
max=10
count=0
for i in range(5):
  if a[i]%10<max and a[i]%10!=0:
    max=a[i]%10
    maxI=i
for i in range(5):
  if i!=maxI:
    count+=a[i]
    if a[i]%10!=0:
      count+=(10-a[i]%10)
count+=a[maxI]
print(count)

### FIXED CODE ###

a=list()
for i in range(5):
  a.append(int(input()))
flag=True
count2=0
for i in range(5):
  if a[i]%10==0:
    count2+=a[i]
  else:
    flag=False
if flag==False:
  max=10
  count=0
  for i in range(5):
    if a[i]%10<max and a[i]%10!=0:
      max=a[i]%10
      maxI=i
  for i in range(5):
    if i!=maxI:
      count+=a[i]
      if a[i]%10!=0:
        count+=(10-a[i]%10)
  count+=a[maxI]
  print(count)
else:
  print(count2)
import math

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

a,b = map(int, input().split())
print(lcm(a,b))


### FIXED CODE ###

import fractions

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

a,b = map(int, input().split())
print(lcm(a,b))
a, b = map(int, input().split())
if a % 2 == 0 or b % 2 == 0:
    print('No')
else:
    print('Yes)

### FIXED CODE ###

a, b = map(int, input().split())
if a % 2 == 0 or b % 2 == 0:
    print('No')
else:
    print('Yes')
x = int(input());

for i in range(x + 1, 10**5 + 1):
  for k in range(2, i):
    if i % k != 0: #割り切れない
      continue;
    else: #割り切れた
      break;
  else:
    break;
  
print(i)

### FIXED CODE ###

x = int(input());

for i in range(x, 10**6):
  for k in range(2, i):
    if i % k != 0: #割り切れない
      continue;
    else: #割り切れた
      break;
  else:
    break;
  
print(i)
N = int(input())
A = input()
A = A.split()
B =[]
C = []
ans = 0
for i in range(N):
    B.append(int(A[i]))
    C.append(int(A[i]))
C.sort(reverse=True)
"""
Max = C[0]
b = Max - N
"""
b = C[N/2]
for i in range(N):
    ans = ans + abs(B[i]-(i+b+1))

ans = ans
print(ans)


### FIXED CODE ###

import math
N = int(input())
A = input()
A = A.split()
B =[]
C = []
ans1 = 0
ans2 = 0
for i in range(N):
    B.append(int(A[i]))
    C.append(int(A[i])-i)
C.sort(reverse=True)

n = math.floor(N/2)
b = C[n]
b1 = C[n-1]

for i in range(N):
    ans1 = ans1 + abs(B[i]-(i+b))
for i in range(N):
    ans2 = ans2 + abs(B[i]-(i+b1))
ans = min(ans1, ans2)
print(ans)
N = int(input())
A = list(map(int,input()))
color = {}
f = 0
for a in A:
    if 1 <= a <= 399:
        color['g'] = 1
    elif 400 <= a <= 799:
        color['br'] = 1
    elif 800 <= a <= 1199:
        color['gr'] = 1
    elif 1200 <= a <= 1599:
        color['m'] = 1
    elif 1600 <= a <= 1999:
        color['b'] = 1
    elif 2000 <= a <= 2399:
        color['y'] = 1
    elif 2400 <= a <= 2799:
        color['o'] = 1
    elif 2800 <= a <= 3199:
        color['r'] = 1
    else:
        f += 1
print(max(1, len(color)), min(8, len(color)+f))        


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
color = {}
f = 0
for a in A:
    if 1 <= a <= 399:
        color['g'] = 1
    elif 400 <= a <= 799:
        color['br'] = 1
    elif 800 <= a <= 1199:
        color['gr'] = 1
    elif 1200 <= a <= 1599:
        color['m'] = 1
    elif 1600 <= a <= 1999:
        color['b'] = 1
    elif 2000 <= a <= 2399:
        color['y'] = 1
    elif 2400 <= a <= 2799:
        color['o'] = 1
    elif 2800 <= a <= 3199:
        color['r'] = 1
    else:
        f += 1
print(max(1, len(color)), len(color)+f)
n=int(input)
if n==1:
  print('Hello World')
else:
  a=int(input())
  b=int(input())
  print(a+b)

### FIXED CODE ###

n=int(input())
if n==1:
  print('Hello World')
else:
  a=int(input())
  b=int(input())
  print(a+b)
time,rate = map(int,input().split())
ans = 0
if time >= 10:
  ans = r
else:
  ans = r - 100*(10 − time)
print(ans)

### FIXED CODE ###

time,rate = map(int,input().split())
ans = 0
if time >= 10:
  ans = rate
else:
  ans = rate + 100*(10 - time)
print(ans)
import itertools import combinations
while True:
    n,s=map(int,input().split())
    if n==0 and s==0:
        break
    num=[i for i in range(0,s+1)]
    print(num)
    ans=0
    comb=itertools.combinations(num,n)
    for c in comb:
        if sum(c) == s:
            ans +=1
    print(ans)


### FIXED CODE ###

def counter(rest, n, acc, to):
  if rest == 0:return acc == to
  if n == 10:return 0 
  return counter(rest - 1, n + 1, acc + n , to) + counter(rest, n + 1, acc, to)
 
while True:
  n, s = map(int, input().split())
  if not n:
    break
  print(counter(n, 0, 0, s))
N = int(input())
A = list(map(int, input().split()))
dict1 = {}
for i in range(N):
  if A[i] not in dict1.keys():
    dict1[A[i]] = 0
  else:
    dict1[A[i]] += 1
value1 = []
for value in dict1.values():
  value1.append(value)
value2 = sorted(value1, reverse = True)
if value2[0] - value2[1] >= sum(value2[1:]):
  print(N - (value2[0] * 2))
else:
  if(sum(value2[0:]) % 2 == 0):
    print(len(value2))
  else:
    print(len(value2) - 1)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
dict1 = {}
for i in range(N):
  if A[i] not in dict1.keys():
    dict1[A[i]] = 0
  else:
    dict1[A[i]] += 1
value1 = []
for value in dict1.values():
  value1.append(value)
value2 = sorted(value1, reverse = True)
if len(value2) != 1:
  if value2[0] - value2[1] >= sum(value2[1:]):
    print(N - (value2[0] * 2))
  else:
    if(sum(value2[0:]) % 2 == 0):
      print(len(value2))
    else:
      print(len(value2) - 1)
else:
  print(1)
my_value_list = []

while True:
    try:
        my_value_list.append(input().split())
    except EOFError:
        break

for i in my_value_list:
    if my_value_list[i][2] == "+":
        print(int(my_value_list[i][]) + int(my_value_list[i][2]))
    elif my_value_list[i][2] == "-":
        print(int(my_value_list[i][0]) - int(my_value_list[i][2]))
    elif my_value_list[i][2] == "/":
        print(int(my_value_list[i][0]) // int(my_value_list[i][2]))
    elif my_value_list[i][2] == "*":
        print(int(my_value_list[i][0]) * int(my_value_list[i][2]))
    else:
        break

### FIXED CODE ###


my_value_list = []

while True:
    try:
        my_value_list.append(input().split())
    except EOFError:
        break

for i in range(0, len(my_value_list)):
    if my_value_list[i][1] == "+":
        print(int(my_value_list[i][0]) + int(my_value_list[i][2]))
    elif my_value_list[i][1] == "-":
        print(int(my_value_list[i][0]) - int(my_value_list[i][2]))
    elif my_value_list[i][1] == "/":
        print(int(my_value_list[i][0]) // int(my_value_list[i][2]))
    elif my_value_list[i][1] == "*":
        print(int(my_value_list[i][0]) * int(my_value_list[i][2]))
    else:
        break
import collections

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

x = collections.Counter(X)

s = min(list(x.keys()))
e = max(list(x.keys()))

xl = list(x)

m = [0]*(e+1-s)

for i in range(s, e+1):
    p = 0
    for j in range(N):
        p += pow(xl[j]-i,2) * x[xl[j]]
    m[i-s] = p

print(min(m))

### FIXED CODE ###

import collections

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

x = collections.Counter(X)

N = len(x)
s = min(list(x.keys()))
e = max(list(x.keys()))

xl = list(x)

m = [0]*(e+1-s)

for i in range(s, e+1):
    p = 0
    for j in range(N):
        p += pow(xl[j]-i,2) * x[xl[j]]
    m[i-s] = p

print(min(m))
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
c=0
for i in range(n):
  if i==n-1:
    if max(a)>a[n-1]:
      c+=1
      break
  for j in range(n-i-1):
    d=0
    if i==n-1-j:
      continue
    elif a[i]%a[n-1-j]==0:
      d+=1
      break
  if d==0:
     c+=1
print(c)    

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
dp=[0]*(10**6+1)
for i in A:
  dp[i]+=1
for i in range(1,10**6+1):
  if dp[i]>0:
    for j in range(2*i,10**6+1,i):
      dp[j]=0
print(dp.count(1))
N = int(input())
S = list(map(int, input().split()))
S.sort(reverse=True)

n = [0] * (2**N)
n[0] = N
_n = N-2
for i in range(1, 2**N):
  nn = n[i-1] - 1
  if nn >= 0:
    n[i] = nn
  else:
    n[i] = _n
    _n -= 1
    if _n < 0:
      if i+1 < 2**N:
        n[i+1] = 1
      break


par = 0
idx = 1
res = True
while idx < 2**N:
  for i in range(n[par]):
    res *= S[par] > S[idx]
    if not res:
      print('No')
      quit()
    idx += 1
  par += 1

print('Yes')

### FIXED CODE ###

N = int(input())
N2 = 2**N
S = list(map(int, input().split()))
S.sort(reverse=True)

slimes = [S[0]]
S[0] = float('inf')
num = 1
for i in range(N):
  slimes.sort()
  n = num
  idx = 0
  while n and idx<=N2-1:
    if S[idx] < slimes[n-1]:
      slimes.append(S[idx])
      S[idx] = float('inf')
      idx += 1
      n -= 1
    else:
      idx += 1
  
  if n:
    print('No')
    quit()
  
  num *= 2

print('Yes')
#動的計画法(DP)
#ブログ「けんちょんの競プロ精進記録」参考
#URL: https://drken1215.hatenablog.com/entry/2019/06/10/140000


N,M = map(int,input().split())
MOD = 1000000007
issafe = [True]*N # issafe[v]: v段目が壊れていないかどうか

for _ in range(M):
    i = int(input())
    issafe[i] = False # i 段目は壊れている

#DPテーブル
dp = [0]*(N+1)

#初期条件
dp[0] = 1
if issafe[1]:dp[1] = 1

#ループ
for n in range(2,N+1):
    if issafe[n-1]: dp[n] += dp[n-1]
    if issafe[n-2]: dp[n] += dp[n-2]
    dp[n] %= MOD

print(dp[N])


### FIXED CODE ###

#動的計画法(DP)
#ブログ「けんちょんの競プロ精進記録」参考
#URL: https://drken1215.hatenablog.com/entry/2019/06/10/140000


N,M = map(int,input().split())
MOD = 1000000007
issafe = [True]*(N+1) # issafe[v]: v段目が壊れていないかどうか

for _ in range(M):
    i = int(input())
    issafe[i] = False # i 段目は壊れている

#DPテーブル
dp = [0]*(N+1)

#初期条件
dp[0] = 1
if issafe[1]:dp[1] = 1

#ループ
for n in range(2,N+1):
    if issafe[n-1]: dp[n] += dp[n-1]
    if issafe[n-2]: dp[n] += dp[n-2]
    dp[n] %= MOD

print(dp[N])
N = int(input())
A = map(int, input().split())
total = 0
for i in range(1, N+1):
  for j in range(i, N+1):
    total += A[i] * A[j]
print(total)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sum_A = sum(A)
for i,ai in enumerate(A):
  sum_A -= ai
  total += ai * sum_A
print(total % (10 ** 9 + 7))
n,k=map(int,input().split())
a=list(map(lambda x:int(x)-1,input().split()))
lst=[0]
now=0
memo=0
town=[0]*n
town[0]=1
b=0
for i in range(k):
	now=a[now]
	if town[now]==1:
		memo=now
		b=1
		break
	lst.append(now)
	town[now]=1
if b==1:
	i=a.index(memo)
	l=len(lst)
	if memo!=0:
		lst=lst[i:]
	print(lst[(k-l)%len(lst)]+1)
else:
	print(now)

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(lambda x:int(x)-1,input().split()))
lst=[0]
now=0
memo=0
town=[0]*n
town[0]=1
b=0
for i in range(k):
	now=a[now]
	if town[now]==1:
		memo=now
		b=1
		break
	lst.append(now)
	town[now]=1
if b==1:
	i=lst.index(memo)
	l=len(lst)
	if memo!=0:
		lst=lst[i:]
		l-=len(lst)
		print(lst[(k-l)%len(lst)]+1)
	else:
		print(lst[k%l]+1)
else:
	print(now+1)
n, k = map(int, input().split())

snk = [False] * n

for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    
    for i+1 in a:
        snk[i] = True
 
print(snk.count(False))

### FIXED CODE ###

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


snk = [False]*n

for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    
    for i in a:
        snk[i-1] = True

print(snk.count(False))
n,m = map(int,input().split())
ab = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    ab[a][b] += 1
    ab[b][a] += 1

for i in range(n):
    cnt = 0
    for j in range(m):
        cnt += ab[i][j]
    print(cnt)


### FIXED CODE ###

n,m = map(int,input().split())
ab = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ab[a][b] += 1
    ab[b][a] += 1

for i in range(n):
    cnt = 0
    for j in range(n):
        cnt += ab[i][j]
    print(cnt)
N = int(input())
# A = input().split()
# A = list(map(int, input().split()))
f = open("tmp.text")
A = list(map(int, f.read().split()))



# left = 0
# right = N - 1
# tmp = 10**9
# while True:
#     # print(left)
#     # print(right)
#     mid = (left + right) // 2
#     # print("mid: " + str(mid))
#     lnum = A[:mid+1]
#     rnum = A[mid+1:]
#     # print(lnum)
#     # print(rnum)
#     new = abs(sum(lnum) - sum(rnum))
#     if tmp == new:
#         break
#     if tmp > new:
#         tmp = new
#     if lnum > rnum:
#         right = mid

#     # print("tmp: "+str(tmp))
#     # input()
#     if left == right:
#         break

# print(tmp)



left = A[0]
right = A[-1]

front = 1
back = 1
for _ in range(N-2):
    if left > right:
        right += A[-1 - back]
        back += 1
    else:
        left += A[front]
        front += 1

print(abs(left-right))


### FIXED CODE ###

N = int(input())
# A = input().split()
A = list(map(int, input().split()))
# f = open("tmp.text")
# A = list(map(int, f.read().split()))



# left = 0
# right = N - 1
# tmp = 10**9
# while True:
#     # print(left)
#     # print(right)
#     mid = (left + right) // 2
#     # print("mid: " + str(mid))
#     lnum = A[:mid+1]
#     rnum = A[mid+1:]
#     # print(lnum)
#     # print(rnum)
#     new = abs(sum(lnum) - sum(rnum))
#     if tmp == new:
#         break
#     if tmp > new:
#         tmp = new
#     if lnum > rnum:
#         right = mid

#     # print("tmp: "+str(tmp))
#     # input()
#     if left == right:
#         break

# print(tmp)



left = A[0]
right = A[-1]

front = 1
back = 1
for _ in range(N-2):
    if left > right:
        right += A[-1 - back]
        back += 1
    else:
        left += A[front]
        front += 1

print(abs(left-right))
n=int(input())
v = list(map(int,input().split()))

dic0 = [0 for i in range(10**5+1)]
dic1 = [0 for i in range(10**5+1)]
for i in range(n):
    if i%2==0:    
        dic0[v[i]] += 1
    if i%2==1:
        dic1[v[i]] += 1

MX0_1 = max(dic0)
MX1_1 = max(dic1)

li0 = []
li1 = []


for i in range(10**5+1):
    if dic0[i]>10:
        #print(i,dic0[i])
    if dic1[i]>10:
        #print(i,dic1[i],"\n")
    
    if dic0[i] == MX0_1:
        li0.append(i)
        dic0[i] = 0
    if dic1[i] == MX1_1:
        li1.append(i)
        dic1[i] = 0

# print(li0,li1)
# print(MX0_1,MX0_1)

if len(li0)>=2 or len(li1)>=2:
    print(n-MX0_1-MX1_1)
elif li0[0] == li1[0]:
    if MX0_1+max(dic1) >= MX1_1+max(dic0):
        print(n-MX0_1-max(dic1))
    else:
        print(n-MX1_1-max(dic0))
        print(1/0)

elif li0[0] != li1[0]:
    print(n-MX0_1-MX1_1)

### FIXED CODE ###

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

dic0 = [0 for i in range(10**5+1)]
dic1 = [0 for i in range(10**5+1)]
for i in range(n):
    if i%2==0:    
        dic0[v[i]] += 1
    if i%2==1:
        dic1[v[i]] += 1

MX0_1 = max(dic0)
MX1_1 = max(dic1)

li0 = []
li1 = []


for i in range(10**5+1):
    # if dic0[i]>10:
    #     print(i,dic0[i])
    # if dic1[i]>10:
    #     print(i,dic1[i],"\n")
    
    if dic0[i] == MX0_1:
        li0.append(i)
        dic0[i] = 0
    if dic1[i] == MX1_1:
        li1.append(i)
        dic1[i] = 0

# print(li0,li1)
# print(MX0_1,MX0_1)

if len(li0)>=2 or len(li1)>=2:
    print(n-MX0_1-MX1_1)
elif li0[0] == li1[0]:
    print(min(n-MX0_1-max(dic1), n-MX1_1-max(dic0)))
elif li0[0] != li1[0]:
    print(n-MX0_1-MX1_1)
n,m = map(int,input().split())


correct = [0] * (n+1)
wrong = [0] * (n+1)



for _ in range(m):
    problem,result_text = input().split()
    problem = int(problem)
    
    if result_text == "AC":
        correct[problem]=1
        
    
    if result_text == "WA":
        if correct[problem] == 0:
            wrong[problem] += 1
    

for _ in range(len(wrong)):
    if correct[problem] == 0:
        wrong[problem] = 0



print ( sum(correct), sum(wrong) )

### FIXED CODE ###

n,m = map(int,input().split())


correct = [0] * (n+1)
wrong = [0] * (n+1)



for _ in range(m):
    problem,result_text = input().split()
    problem = int(problem)
    
    if result_text == "AC":
        correct[problem]=1
        
    
    if result_text == "WA":
        if correct[problem] == 0:
            wrong[problem] += 1
    

for problem in range(n+1):
    if correct[problem] == 0:
        wrong[problem] = 0



print ( sum(correct), sum(wrong) )
7
nikoandsolstice

### FIXED CODE ###

K=int(input())
S=str(input())
if len(S) <= K:
    print(S)
else:
    ans = S[0]
    for i in range(1,K):
        ans += S[i]
    ans += "..."
    print(ans)
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    d = list(map(int, input().slit()))
    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            ans += d[i] * d[j]
    print(ans)


if __name__ == '__main__': main()

### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    N = int(input())
    d = list(map(int, input().split()))
    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            ans += d[i] * d[j]
    print(ans)


if __name__ == '__main__': main()
if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')

### FIXED CODE ###

s=input()
if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')
if __name__ == '__main__':
    n, k = map(int, input().split())
    ans = input()

    if n ==1:
        ans = ans.lower()
    elif n==2:
        if k == 1:
            ans = ans[0].lower() + ans[1]
        else:
            ans = ans[0]+ ans[1].lower()

    else:
        if k == 1:
            ans = ans[0].lower() + ans[1:n]
        elif k == n:
            ans = ans[0:n-1] + ans[n].lower()
        else:
            ans = ans[0:k - 1] + ans[k - 1].lower() + ans[k:n]

    print(ans)


### FIXED CODE ###

if __name__ == '__main__':
    n, k = map(int, input().split())
    ans = input()

    if n ==1:
        ans = ans.lower()
    elif n==2:
        if k == 1:
            ans = ans[0].lower() + ans[1]
        else:
            ans = ans[0]+ ans[1].lower()

    else:
        if k == 1:
            ans = ans[0].lower() + ans[1:n]
        elif k == n:
            ans = ans[0:n-1] + ans[n-1].lower()
        else:
            ans = ans[0:k - 1] + ans[k - 1].lower() + ans[k:n]

    print(ans)
N = int(input())
S = str(input())
p = "abc"
print(len(re.findall("abc", S)))


### FIXED CODE ###

N = int(input())
S = str(input())
S = S.replace("ABC","ab")
print(N - len(S))
n = int(input())
t,a = map(int,input().split())
H = list(map(int,input().split()))
ans = float('inf')
for h in H:
  if abs(t-ans*0.006) > abs(t-ans*0.006):
    ans = h
print(H.index(ans)+1)

### FIXED CODE ###

n = int(input())
t,a = map(int,input().split())
H = list(map(int,input().split()))
ans = float('inf')
for h in H:
  if abs(a-(t-ans*0.006)) > abs(a-(t-h*0.006)):
    ans = h
print(H.index(ans)+1)
from sys import stdin
def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    A = [int(x) for x in stdin.readline().rstrip().split()]
    X = 1
    C = 0
    Log = [1]
    while C <= K:
        X = A[X-1]
        C += 1
        if (X in Log) == True:
            break
      
        Log += [X]
    
    K = (K - C)%(C - Log.index(X))
    print(Log[Log.index(X)+K])
    
main()

### FIXED CODE ###

from sys import stdin
import numpy as np
 
def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    A = [int(x) for x in stdin.readline().rstrip().split()]
    X = 1
    L = [1]
    if A[0] == 1:
        print(1)
        exit()
    if N >= K :
        for i in range(K):
            X = A[X-1]
        print(X)
        exit()
    else:
        for i in range(N):
            X = A[X-1]
            L += [X]
        #print('L',L)#OK
        C = np.zeros(N)
        for i in range(N):
            if C[L[i]-1] == 0:
                C[L[i]-1] += 1
                #print('C,i',C,i)
            else:
                break
        #print('C',C)
        #print('i+1',i+1)#Roop 回数　When Roop Goal
        #print('L[i+1]',L[i+1])#Roop initial Number
        S = L.index(L[i+1])
        #print('S',S)#When Roop Start ,Roop times
        #print(K - i-1)#Remain K
        #print('i + 1 -S',i + 1 - S)#Roop Cycle
        K = (K - i-1)%(i+1 - S)
        #print(K)
        print(L[S+K])
        
main()
N = int(input())
dp = [N] * 200
dp[0] = 0
for i in range(0,N+1):
    m = 1
    while m <= N:
        dp[i] = min(dp[i],dp[i-m]+1)
        m *= 6
    m = 1
    while m <= N:
        dp[i] = min(dp[i],dp[i-m]+1)
        m *= 9
print(dp[N])

### FIXED CODE ###

N = int(input())
dp = [N] * 110000
dp[0] = 0
for i in range(0,N+1):
    m = 1
    while m <= N:
        dp[i] = min(dp[i],dp[i-m]+1)
        m *= 6
    m = 1
    while m <= N:
        dp[i] = min(dp[i],dp[i-m]+1)
        m *= 9
print(dp[N])
N =int(input())
S = map(int,input().split())
TT = sum(TT)
T1 = 0
Ans = TT
for i in range(N):
  T1 += S[i]
  Ans = min(Ans,ABS(TT-T1-T1))
print(Ans)

### FIXED CODE ###

N =int(input())
S = list(map(int,input().split()))
TT = sum(S)
T1 = 0
Ans = TT
for i in range(N):
  T1 += S[i]
  Ans = min(Ans,abs(TT-T1-T1))
print(Ans)