Harryxun/stf_run huggingface dataset:
from collections import deque

H, W = map(int, input().split())
maze = []
for _ in range(H):
    maze.append(list(input()))


def successors(x, y):
    locations = []
    # 下に行けるかの判定
    if (x + 1 < H) and (maze[x + 1][y] != '#'):
        locations.append((x + 1, y))
    # 上に行けるかの判定
    if (x - 1 >= 0) and (maze[x - 1][y] != '#'):
        locations.append((x - 1, y))
    # 右に行けるかの判定
    if (y + 1 < W) and (maze[x][y + 1] != '#'):
        locations.append((x, y + 1))
    # 左に行けるかの判定
    if (y - 1 >= 0) and (maze[x][y - 1] != '#'):
        locations.append((x, y - 1))
    return locations


def bfs(initial, successors):
    # goal判定はなく、一番遠いところで返す
    frontier = deque()
    frontier.append((initial, None))
    # tuple
    explored = {initial}

    while len(frontier):
        current_node = frontier.popleft()
        current_state = current_node[0]
        for child in successors(*current_state):
            if str(child) in [str(i) for i in explored]:
                continue
            explored.add(child)
            frontier.append((child, current_node))
    return current_node


def node_to_path_count(node):
    counter = 0
    while node[1] is not None:
        counter += 1
        node = node[1]
    return counter


ans = 0
for x in range(H):
    for y in range(W):
        if maze[x][y] == '.':
            solution = bfs((x, y), successors)
            counter = node_to_path_count(solution)
            if ans < counter:
                ans = counter

print(ans)

### FIXED CODE ###

c = input()

print(chr(ord(c) + 1))
a,b = map(int,input().split())
ans_li = [0 for x in range(a)]

for i in range(b):
  d = int(input())
  for j in range(d):
    l = list(map(int, input().split()))
    for ll in l:
      ans_li[ll] += 1
print(ans_li.count(0))

### FIXED CODE ###

a,b = map(int,input().split())
ans_li = [0 for x in range(a)]

for i in range(b):
  d = int(input())
  l = list(map(int, input().split()))
  for ll in l:
      ans_li[ll-1] += 1
print(ans_li.count(0))
from collections import Counter

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

v1 = v[::2]
v2 = v[1::2]

counter1 = Counter(v1)
x1 = counter1.most_common()[0][0]
counter2 = Counter(v2)
x2 = counter2.most_common()[0][0]

x1_count = v1.count(x1)
x2_count = v2.count(x2)

n = n//2
ans = 0
if x1 == x2:
    if x1_count > x2_count:
        ans = (n - x1_count) + (n - counter2.most_common()[1][1])
    else:
        ans = (n - x2_count) + (n - counter1.most_common()[1][1])
else:
    ans = (n - x1_count) + (n - x2_count)
print(ans)

### FIXED CODE ###

from collections import Counter

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

v1 = v[::2]
v2 = v[1::2]

counter1 = dict(Counter(v1))
counter2 = dict(Counter(v2))
x1 = max(counter1, key=counter1.get)
x2 = max(counter2, key=counter2.get)
x1_c = counter1[x1]
x2_c = counter2[x2]
del counter1[x1]
del counter2[x2]
y1_c = 0
y2_c = 0
if len(counter1) != 0:
    y1_c = max(counter1.values())
if len(counter2) != 0:
    y2_c = max(counter2.values())

n = n//2
ans = 0
if x1 == x2:
    ans = min((n - x1_c) + (n - y2_c), (n - y1_c) + (n - x2_c))
    """
    if x1_c > x2_c:
        ans = (n - x1_c) + (n - y2_c)
    else:
        ans =  (n - y1_c) + (n - x2_c)
    """
else:
    ans = (n - x1_c) + (n - x2_c)

print(ans)
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
INF = float('inf')

H, N=map(int, input().split())
dp = [0 for i in range(H + 1)]

hm = list(list(map(int, input().split())) for i in range(N))

for i in range(1, H+1):
    dp[i] = min(list(dp[i - h] + m for h, m in hm))
print(dp[H])

### FIXED CODE ###

#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
INF = float('inf')

H, N=map(int, input().split())
dp = [0 for i in range(H + 10**4 + 1)]

hm = list(list(map(int, input().split())) for i in range(N))

for i in range(1, H+1):
    dp[i] = min(list(dp[i - h] + m for h, m in hm))
print(dp[H])
N, a, b = map(int, input.split()) 

sum = 0
for x in N:
  l = [int(y) for y in list(str(x))]
  temp_sum = 0
  for z in l:
    tmep_sum += z
  if a <= temp_sum and b <= temp_sum:
      sum += x
print(sum)

### FIXED CODE ###

# -*- coding: utf-8 -*-
N, a, b = map(int, input().split()) 
 
sum = 0
for x in range(N + 1):
  l = [int(y) for y in list(str(x))]
  temp_sum = 0
  for z in l:
    temp_sum += z
  if a <= temp_sum and b >= temp_sum:
     sum += x
print(sum)
n, m = map(int, input().split())
num_list = ['X'] * n

def ans():
    for i in range(m):
        set = list(map(str, input().split()))
        if set[0] == '1' and set[1] == '0' and n != 1:
            return -1
        else:
            if num_list[int(set[0]) - 1] == 'X':
                num_list[int(set[0]) - 1] = set[1]
            elif num_list[int(set[0]) - 1] == set[1]:
                continue
            else:
                return -1


    if num_list[0] == 'X':
        num_list[0] = '1';

    for i in range(1, m):
        if num_list[i] == 'X':
            num_list[i] = '0'

    return ''.join(num_list)

print(ans())


### FIXED CODE ###

n, m = map(int, input().split())
num_list = ['X'] * n

def ans():
    if n == 1 and m == 0:
        return 0
    for i in range(m):
        set = list(map(str, input().split()))
        if set[0] == '1' and set[1] == '0' and n != 1:
            return -1
        else:
            if num_list[int(set[0]) - 1] == 'X':
                num_list[int(set[0]) - 1] = set[1]
            elif num_list[int(set[0]) - 1] == set[1]:
                continue
            else:
                return -1


    if num_list[0] == 'X':
        num_list[0] = '1'

    for i in range(1, n):
        if num_list[i] == 'X':
            num_list[i] = '0'

    return ''.join(num_list)

print(ans())
s=input()
s=sorted(s)
if s[0]==s[1] and s[2]==s[3]:
　print("Yes")
else:
　print("No")

### FIXED CODE ###

s=input()
s=sorted(s)

if s[0]==s[1] and s[2]==s[3] and s[0] != s[2]:
	print("Yes")
else:
	print("No")
from sys import stdin

readline = stdin.readline

_, *a = map(int, open(0).read().split())
res = 0
mi = 1_000_000_000
rem = True
for v in a:
    if v < 0:
        rem != rem
    b = abs(v)
    res += b
    mi = min(b, mi)
if rem:
    res -= mi*2
print(res)


### FIXED CODE ###

from sys import stdin

readline = stdin.readline

_, *aa = map(int, open(0).read().split())
r = 0
mi = 1000000000
m = 0
for a in aa:
    if a < 0:
        m += 1
    b = abs(a)
    r += b
    mi = min(b, mi)
print(r - mi * 2 * (m % 2))
n=int(input())

a = [map(int, input().split())]

amin= min(a)
amax= max(a)

res= amax-amin
print(res)


### FIXED CODE ###

n=int(input())
 
a = list(map(int, input().split()))
amin= min(a)
amax= max(a)
 
res= amax-amin
print(res)
import math

N, D = int(input().split())
P = []
for n in N:
    X_n, Y_n = int(input().split())
    P.append((X_n, Y_n))

def distance(p:tuple):
    # d_2 = p[0] ** 2 + p[1] ** 2
    # d = math.sqrt(d_2)
    return math.sqrt(p[0] ** 2 + p[1] ** 2)

count = [p for p in P if distance(p) <= D]
print(len(count))

### FIXED CODE ###

import math

N, D = map(int, input().split())
P = []
for n in range(N):
    X_n, Y_n = map(int, input().split())
    P.append((X_n, Y_n))

def distance(p:tuple):
    return math.sqrt(p[0] ** 2 + p[1] ** 2)

count = [p for p in P if distance(p) <= D]
print(len(count))
line = raw_input()
N, X = [int(s) for s in line.split(' ')]
line = raw_input()
xs = [int(s) for s in line.split(' ')]

xs = [x - X for x in xs]
X = 0
if len(xs) == 1:
    print abs(xs[0])
else:
    sub = [a - b for a, b in zip(xs[1:], xs)]
    abs_sub = [abs(s) for s in sub]
    max_s = max(abs_sub)
    min_s = min(abs_sub)
    ret = 1
    for i in range(2, min_s + 1):
        if max_s % i == 0 and min_s % i == 0: 
            ret = i
    print ret


### FIXED CODE ###

line = raw_input()
N, X = [int(s) for s in line.split(' ')]
line = raw_input()
xs = [int(s) for s in line.split(' ')]
xs.append(X)
#xs = [x - X for x in xs]
xs.sort()
X = 0
if len(xs) == 1:
    print abs(xs[0])
else:
    sub = [abs(a - b) for a, b in zip(xs[1:], xs)]
    sub.sort()
    ret = sub[0]
    for s in sub[1:]:
        mod = 1
        ss = ret
        while mod > 0:
            mod = s % ss
            s = ss
            ss = mod
        ret = s
    print ret
n,s = (input().split())
n = int(n)
if n == 1:
    print("No")
else: 
    t = s[0 : n//2]
    if s[n//2: n] == t:
        print("Yes")
    else:
         print("No")

### FIXED CODE ###

n = input()
s = input()
n = int(n)
if n % 2 == 1:
    print("No")
else: 
    t = s[0 : n//2]
    if s[n//2: n] == t:
        print('Yes')
    else:
         print('No')
s = input()
print(s.repliace(' ', ''))

### FIXED CODE ###

def main(s, t):
    print(t, s, sep="")


if __name__ == "__main__":
    s, t = input().split()

    main(s, t)
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def resolve():
    import sys

    input = sys.stdin.readline

    n, m = [int(x) for x in input().rstrip().split(" ")]

    uf = UnionFind(n)

    for i in range(m):
        a, b = [int(x) for x in input().rstrip().split(" ")]
        uf.union(a, b)

    print(len(uf.roots()) - 1)



if __name__ == "__main__":
    resolve()


### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def resolve():
    import sys

    input = sys.stdin.readline

    n, m = [int(x) for x in input().rstrip().split(" ")]

    uf = UnionFind(n)

    for i in range(m):
        a, b = [int(x) for x in input().rstrip().split(" ")]
        uf.union(a-1, b-1)

    print(len(uf.roots()) - 1)


if __name__ == "__main__":
    resolve()
a=[]
a[1]=[]
a[2]=[]
for i in range (3):
	a[1].append(input())
for i in range (3):
	a[2].append(input())
for i in range (3):
	if a[1][i]!=a[2][2-i]:		
		print("NO")
 		break
 	else:
 		if i==2:
 			print("YES")
  		continue

  

### FIXED CODE ###

rli,cli=list(input()),list(input())
if rli[0]==cli[2] and rli[1]==cli[1] and rli[2]==cli[0]:
    print("YES")
else:
    print("NO")
xs = map(int, raw_input().split())

if xs[2] >= xs[0] and xs[2] <= xs[1]:
    print "Yes"
else:
    print "No"


### FIXED CODE ###

xs = [int(x) for x in input().split()]

if xs[2] >= xs[0] and xs[2] <= xs[1]:
    print("Yes")
else:
    print("No")
K, A, B = map(int, input().split())
if B - A =< 2 :
  print(K + 1)
elif K < A + 1:
  print(K + 1)
else :
  ans = B 
  count = K - A - 1
  loop = count // (A + 2)
  amari = count % (A + 2)
  ans += B * loop + amari
  print(ans)
  


### FIXED CODE ###

K, A, B = map(int, input().split())
if B - A <= 2 :
  print(K + 1)
elif K < A + 1:
  print(K + 1)
elif K == A + 1:
  print(B)
else:
  count = K - (A + 1)
  if count % 2 == 0:
    ans = count // 2 * (B - A) + B
  else:
    ans = count//2 * (B - A) + B + 1
  print(ans)
from collections import Counter
s = input()
n = len(s)
count = dict(Counter(s))
flag = False

if n ==1:
    flag = True
elif n <= 3:
    if max(count.values())!=2:
        flag = True
elif n==4:
    if max(count.values())<=2:
        flag = True
else:
    if count["a"]==count["b"] or count["b"]==count["c"] or count["c"]==count["a"]:
        if abs(max(count.values())-min(count.values()))==1:
            flag = True
            
            
print('YES' if flag==True else 'NO')

### FIXED CODE ###

from collections import Counter
s = input()
n = len(s)
count = dict(Counter(s))
flag = False

if n ==1:
    flag = True
elif n <= 3:
    if max(count.values())!=2:
        flag = True
elif n==4:
    if max(count.values())<=2:
        flag = True
else:
    if "a" in count:
        if "b" in count:
            if "c" in count:
                if count["a"]==count["b"] or count["b"]==count["c"] or count["c"]==count["a"]:
                    dev = max(count.values())-min(count.values())
                    if dev <= 1:
                        flag = True
            
            
print('YES' if flag==True else 'NO')
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <numeric>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <numeric>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    ll ans = 0;
    ll sum = 0;
    ll sums = 0;

    ans = 0;

    for (int i = 0; i < n; i++)
    {
        sums += a[i];
    }

    ans += (sums%mod) * (sums%mod);

    for (int i = 0; i < n; i++)
    {
        ans -= (a[i] * a[i]) % mod;
    }

    if(ans < 0) {
        ans += mod;
    }
    ans %= mod;

    ans *= (1.0/2);
    ans %= mod;

    cout << ans  << endl;
}

/*
int main()
{
    int n;cin >> n;
    vector<ll> a(n);
    vector<ll> b(n-1);
    rep(i,n) {
        cin >> a[i];
    }

    ll ans = 0;
    ll sum = 0;
    for (int i = 1; i < n; i++)
    {
        sum += a[i];  
    }


    int i = 1;
    for(int j = 0; j < n - 1; j++) {
        b[j] = sum;
        sum -= a[i++];
    }

    for(int i = 0; i < n - 1; i++) {
        ans += (b[i]%mod)*(a[i]%mod);
        ans %= mod;
    }



    cout << ans << endl;

}
*/

### FIXED CODE ###

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

suma = sum(a)**2
sums = 0
for i in range(n):
    sums += a[i]*a[i]

ans = (suma - sums) // 2
ans %= 1000000007

print(int(ans))
import sys
sys.setrecursionlimit(10**9)

def addc(p,b):
  for i in e[p]:
    if(i == b):
      continue
    c[i] += c[p]
    addc(i,p)

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

e = [ [] for i in range(n + 1)]
c = [0 for i in range(n + 1)]

for i in range(n-1):
  a,b = map(int,input().split())
  e[a].append(b)
  e[b].append(a)

for i in range(q):
  p,x = map(int,input().split())
  c[p] += x

addc(1,-1)

c.pop(0)

print(*c)

### FIXED CODE ###

a = int(input())

s = input()

if(a >= 3200):
  print(s)

else:
  print("red")
n,q=map(int, input().split())
edges = [[]for _ in range(n)]
counter = [0]*n
done = [0]*n

for i in range(n-1):
    a,b=map(int, input().split())
    #頂点a, bのどちらが親か調べる 頂点1が根
    edges[a-1].append(b-1)



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

def dfs(i: int):
    for j in edges[i]:
        counter[j]+=counter[i]
        dfs(j)

dfs(0)
print(*counter)


### FIXED CODE ###

from collections import deque
n,q=map(int, input().split())
edges = [[]for _ in range(n)]
counter = [0]*n
visited=[-1]*n
que=deque()

for i in range(n-1):
    a,b=map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)



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


que.append(0)
while que:
    v=que.popleft()
    visited[v]=1
    for next_v in edges[v]:
        if visited[next_v]!=-1:continue
        counter[next_v]+=counter[v]
        que.append(next_v)
print(*counter)
s = input()
t = len(s)
if s[:t//2]=s[s//2]:
  print('Yes')
else: print('No')

### FIXED CODE ###


t = int(input())
s = input()
if s[:t//2]==s[t//2:]:
  print('Yes')
else: print('No')
import statistics

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

b = [a[i] - i for i in range(N)]
median = statistics.median(b)

ans = 0
for i in range(N):
    ans += abs(b[i] - int(median))

print(ans)

### FIXED CODE ###

import numpy as np

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

b = [a[i] - i for i in range(N)]
median = np.median(b)

ans = 0
for i in range(N):
    ans += abs(b[i] - int(median))

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

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

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

X.sort()

if M == 1:
    print(0)
    sys.exit()

dist = []

for i in range(len(X)-1):
    dist.append(X[i+1] - X[i])

dist.sort(reverse=True)

ans = X[-1] - X[0]
for i in range(N-1):
    ans -= dist[i]
print(ans)

### FIXED CODE ###

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

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

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

if N >= M:
    print(0)
    sys.exit()
X.sort()

dist = []
for i in range(len(X)-1):
    dist.append(X[i+1]-X[i])

dist.sort()
print(sum(dist[:len(dist)-(N-1)]))
import numpy as np
n,m,k=map(int,input().split())
A=[0]+list(map(int, input().split()))
B=[0]+list(map(int, input().split()))
ans=0
a=np.cumsum(np.array(A)).tolist()
b=np.cumsum(np.array(B)).tolist()
for i in range(n+1):
    if k<a[i]
        break
    j=m
    while b[j]>k-a[i]:
        j-=1
        ans=max(ans,i+j)
print(ans)

### FIXED CODE ###

n,m,k=map(int,input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
ans=0
a, b=[0], [0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])
j=m
for i in range(n+1):
    if k<a[i]:
        break
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)
s = input()
 
for i in range(len(s)):
    if s[i] == '?':
        if i == 0 and s[1] == 'D':
            s = s.replace('?','P',1)
        elif i == 0 and s[1] == 'P':
            s = s.replace('?','D',1)
    
        elif s[i-1] =='P' :
            s = s.replace('?','D',1)
        elif s[i-1] =='D' and s[i+1] == 'P':
            s = s.replace('?','D',1)
        else:
            s = s.replace('?','P',1)
 
#cnt = s.count('PD')
#cnt += s.count('D')
 
print(s)

### FIXED CODE ###

s = input()
 
for i in range(len(s)):
    if s[i] == '?':
        if i == 0 and len(s) == 1:
            s = s.replace('?','D',1)
        elif i == 0 and s[1] == 'D':
            s = s.replace('?','P',1)
        elif i == 0 and s[1] == 'P':
            s = s.replace('?','D',1)
        elif i == 0 and s[1] == '?':
            s = s.replace('?','D',1)
        elif s[i-1] =='P':
            s = s.replace('?','D',1)
        elif s[i-1] =='D' and (i ==len(s)-1):
            s = s.replace('?','D',1)
        elif s[i-1] =='D' and (i <len(s)-1 and(s[i+1] == 'P' or s[i+1] == '?')):
            s = s.replace('?','D',1)
        else:
            s = s.replace('?','P',1)


print(s)
a,b,c =map(intinput().split("s"))
print(a+b+c)

### FIXED CODE ###

a=input()
print(a.count("1"))
a, b, c = list(map(int, input().split()))
d = a, b, c
print(d.sort())

### FIXED CODE ###

x = list(map(int, input().split()))
x.sort()
print("{0} {1} {2}".format(x[0],x[1],x[2]))
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")

# k: number of transfer
_,k = LI()
a = LI()
# 街の番号を0始まりに変更
a = list(map(lambda x:x-1,a))
# print(a)

_s = set([0])

# 再帰関数
def rec(visited,next,s):
    if next in s:
        # print(visited)
        return visited,visited.index(next)
    else:
        s.add(next)
        visited.append(next)
        return rec(visited,a[next],s)

visited = [0]
# 訪れた街、初めて2度訪れた街のインデックスを取得
visited,loopStart = rec(visited,a[0],_s)

# print(visited,loopStart)

if k <= len(visited):
    townIndex = visited[k]
else:
    visitedLoop = visited[loopStart:]
    # print(visitedLoop)
    # 残り回数を循環配列の長さで割った余り
    index = (k-(loopStart))%len(visitedLoop)
    # print(index)
    townIndex = visitedLoop[index]

print(townIndex+1)

### FIXED CODE ###

import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")

# k: number of transfer
_,k = LI()
a = LI()
# 街の番号を0始まりに変更
a = list(map(lambda x:x-1,a))
# print(a)

s = set([0])

# 再帰関数
def rec(visited,next):
    if next in s:
        # print(visited)
        return visited,visited.index(next)
    else:
        s.add(next)
        visited.append(next)
        return rec(visited,a[next])

visited = [0]
# 訪れた街、初めて2度訪れた街のインデックスを取得
visited,loopStart = rec(visited,a[0])

# print(visited,loopStart)

if k < len(visited):
    townIndex = visited[k]
else:
    visitedLoop = visited[loopStart:]
    # print(visitedLoop)
    # 残り回数を循環配列の長さで割った余り
    index = (k-(loopStart))%len(visitedLoop)
    # print(index)
    townIndex = visitedLoop[index]

print(townIndex+1)
ans=1
if 0 in A:
    ans=0
else:
    for a in A:
        ans=ans*a
        if ans > 10**18:
            ans=-1
            break

print(ans)

### FIXED CODE ###

N=int(input())

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

ans=1
if 0 in A:
    ans=0
else:
    for a in A:
        ans=ans*a
        if ans > 10**18:
            ans=-1
            break

print(ans)
A,B,C=map(int,input().split())
d=B//A
if d<=C:
  print(d)
  else:
    print(C)


### FIXED CODE ###

A,B,C=map(int,input().split())
d=B//A
if d<C:
  print(d)
else:
  print(C)
H, W = map(int, input().split())
a = []
for i in range(H):
  b = list(input().split())
  a.append(b)
c = []
for i in range(2*H):
  d = []
  for j in range(W):
    d.append(a[i//2][j])
  c.append(d)
print(c)

### FIXED CODE ###

H, W = map(int, input().split())
a = []
for i in range(H):
  b = list(input())
  a.append(b)
for i in range(2*H):
  for j in range(W):
    if j != W - 1:
      print(a[i//2][j],end="")
    else:
      print(a[i//2][j])
import math
r=int(input())
print("{:.5f} {:.5f}".format(r*r*math.pi,r*2*math.pi))



### FIXED CODE ###

from math import pi
r=float(input())
print("{:.5f} {:.5f}".format(r*r*pi,r*2*pi))