Harryxun/stf_run huggingface dataset:
A , B , M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
for i in range(M-2):
    q = list(map(int, input().split()))
    x = a[q[0]-1] + b[q[1]-1] - q[2]
    ans.append(x)
print(min(ans))

### FIXED CODE ###

A , B , M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [min(a) + min(b)]
for i in range(M):
    q = list(map(int, input().split()))
    x = a[q[0]-1] + b[q[1]-1] - q[2]
    ans.append(x)
print(min(ans))
R,G,B,N = map(int,input().split())
cnt = 0
for r in range(3001):
  for g in range(3001):
    V = r * R + g * G 
    if N >= V and (N - V) % == 0
        cnt += 1
    else:
        continue
print(cnt)

### FIXED CODE ###

R,G,B,N = map(int,input().split())
cnt = 0
for r in range((N // R) + 1):
    for g in range((N - (r * R)) // G + 1):
        V = N - (r * R + g * G)
        if V >= 0 and V % B == 0:
            cnt += 1
print(cnt)
a,b = map(int,input().split())
print(a//b,a%b,"{:.5f}"(a/b))


### FIXED CODE ###

a,b = map(int,input().split())
print(a//b,a%b,"{:.5f}".format(a/b))
import numpy as np

LI = lambda: list(map(int, input().split()))

n, s = LI()
a = LI()
dp = np.zeros((n+1, s+1), dtype=np.int)
dp[0][0] = 1

for i in range(n):
    for w in range(s+1):
        dp[i+1][w] = 2*dp[i][w]
        if w >= a[i]:
            dp[i+1][w] += dp[i][w-a[i]]
        dp[i+1][w] %= 998244353

print(dp[n][s])

### FIXED CODE ###

import sys

LI = lambda: list(map(int, sys.stdin.readline().rstrip().split()))

def main():
    n, s = LI()
    a = LI()
    dp = [[0 for i in range(s+1)] for j in range(n+1)]
    dp[0][0] = 1

    for i in range(n):
        for w in range(s+1):
            dp[i+1][w] = 2*dp[i][w]
            if w >= a[i]:
                dp[i+1][w] += dp[i][w-a[i]]
            dp[i+1][w] %= 998244353

    print(dp[n][s])

if __name__ == '__main__':
    main()
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    X = sum(l)
    x = 0
    for i in range(N-1):
        x += l[i]
        ans.append(abs(X-2*x))
    print(min(ans))
if __name__ == '__main__':
    main()

### FIXED CODE ###

a , b = map(int, input().split())
if a%3==0 or b%3==0 or (a+b)%3==0:
    print('Possible')
else:
    print('Impossible')
print(ren(set(list(map(int, input().split()))))


### FIXED CODE ###

print(len(set(list(map(int, input().split())))))
d, g = map(int, inputs[0].split())
P = list(map(int, map(lambda x: x.split()[0], inputs[1:])))
C = list(map(int, map(lambda x: x.split()[1], inputs[1:])))

ans = float('inf')
for bit in range(1 << d):
    count, total, rest = 0, 0, set(range(1, d+1))
    for i in range(d):
        if bit & (1 << i):
            total += P[i] * (i + 1) * 100 + C[i]
            count += P[i]
            rest.discard(i + 1)

    if total < g:
        use = max(rest)
        n = ceil((g - total) / (use * 100))
        if P[use-1]-1 < n:
            continue
        count += n
        total += n * use * 100
        
    if total >= g:
        ans = min(ans, count)
print(ans) 


### FIXED CODE ###

import sys
from math import ceil
inputs = sys.stdin.readlines()

d, g = map(int, inputs[0].split())
P = list(map(int, map(lambda x: x.split()[0], inputs[1:])))
C = list(map(int, map(lambda x: x.split()[1], inputs[1:])))

ans = float('inf')
for bit in range(1 << d):
    count, total, rest = 0, 0, set(range(1, d+1))
    for i in range(d):
        if bit & (1 << i):
            total += P[i] * (i + 1) * 100 + C[i]
            count += P[i]
            rest.discard(i + 1)

    if total < g:
        use = max(rest)
        n = min(P[use-1], ceil((g - total) / (use * 100)))
        count += n
        total += n * use * 100
    if total >= g:
        ans = min(ans, count)
print(ans)
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")
S_min = int(S,2) % (bit_count-1) if bit_count-1!=0 else 0
S_plu = int(S,2) % (bit_count+1)
S_num = int(S,2)



calc_dict = {i:-1 for i in range(100000)}
res_dict =  {i:-1 for i in range(100000)}

for i in range(1, 100000):
    if calc_dict[i]==-1:
        calc_dict[i] = bin(i).count("1")

    res_dict[i] = i%calc_dict[i]+1

def mods(temp, count):
    count+=1
    while temp!=0:

        if temp in res_dict:
            return count+res_dict[temp]
        
        if temp in calc_dict:
            calc_dict[temp]=bin(temp).count("1")
        bits = calc_dict[temp]
            
        temp = temp%bits
        count+=1

    return count

for i in range(N):
    if S[i]=="0":
        part = (2**(N-i-1))% (bit_count+1)
        num = (S_plu + part ) % (bit_count+1)
        if num==0:
            print(1)
        else:
            print(mods(num, 0))
    else:
        if S_num == 2**(N-i-1):
            print(0)
            continue
        part = (2**(N-i-1))% (bit_count-1)
        num = (S_min - part)%(bit_count-1)
        if num==0:
            print(1)
        else:
            print(mods(num, 0))




### FIXED CODE ###

def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")
S_num = int(S,2)
S_min = S_num % (bit_count-1) if bit_count-1!=0 else 0
S_plu = S_num % (bit_count+1)




# calc_dict = {i:-1 for i in range(10000)}
# res_dict =  {i:-1 for i in range(10**4)}

# for i in range(1, 10000):
#     if calc_dict[i]==-1:
#         calc_dict[i] = bin(i).count("1")

#     res_dict[i] = i%calc_dict[i]+1

def mods(temp, count):
    count+=1
    if temp!=0:

#         if temp in res_dict:
#             return count+res_dict[temp]
        
#         if temp not in calc_dict:
#             calc_dict[temp]= bin(temp).count("1") 
        count = mods(temp%bin(temp).count("1") , count)

    return count

for i in range(N):
    if S[i]=="0":
        part = pow(2, (N-i-1), bit_count+1)
        num = (S_plu + part ) % (bit_count+1)
        print(mods(num, 0))
    else:
        if S_num == 2**(N-i-1):
            print(0)
            continue
        part = pow(2, (N-i-1), bit_count-1)
        num = (S_min - part)%(bit_count-1)
        print(mods(num, 0))
A, B = map(int, input().split())
max = 8
if A <= max && B <= max:
  print("Yay!")
else:
  print(":(")
  
  

### FIXED CODE ###

A, B = map(int, input().split())
max = 8
if A <= max and B <= max:
  print("Yay!")
else:
  print(":(")
a,b,c = map(int,input().split())
print(min(a+b))

### FIXED CODE ###

a,b,c = sorted(map(int,input().split()))
print(a+b)
firstline = str(input())
firstline = firstline.split()
item = int( firstline[0] )
totalweight = int ( firstline[1] )
gh = [0] * (totalweight + 1)
dp = [gh[::] for _ in range(item) ]
total = []

def sort_tuple(tup):  
  
    tup.sort(key = lambda x: x[0])  
    return tup  

for i in range(item):    
    getIn = str(input())
    getIn = getIn.split()
    total.append( ( int( int(getIn[0]) ), int( getIn[1]) ) )
    
sort_tuple(total)
#print(total)

firstStone = total[0]
for i in range(firstStone[0], totalweight+1 ):
    dp[0][i] = firstStone[1]

for i in range(1, item):
    currentStone = total[i]
    currentStoneWeight = currentStone[0]
    currentStoneValue = currentStone[1]
    for j in range(0, totalweight + 1):
        dp[i][j] = max( dp[i - 1][j], dp[i][j]   )
        if j >= currentStoneWeight:
            dp[i][j] = max( dp[i][j], currentStoneValue + dp[i - 1][j - currentStoneWeight] )
#print(dp)
print(dp[-1][-1])
    
    
    
    
    
    
    

### FIXED CODE ###

'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''

firstline = str(input())
firstline = firstline.split()
n = int( firstline[0] )
total = int( firstline[1] )

maxvalue = int( pow(10, 5) + 1)
#maxvalue = 100
colums = [10000000001000000000 for _ in range(maxvalue)]
dp = [ colums[::] for _ in range(n+1) ]

for i in range(n+1):
    dp[i][0] = 0

stone = []

for i in range(n):
    getInput = str(input())
    getInput = getInput.split()
    stone.append(( int(getInput[1]) , int(getInput[0]) ) )

stone = sorted(stone)

index = 0
for currentstone in stone:
    currentvalue = currentstone[0]
    currentweight = currentstone[1]
    index += 1 
    for V in range(1, maxvalue):
        if currentvalue <= V:
            dp[index][V] = min(currentweight + dp[index-1][V - currentvalue], dp[index - 1][V])
        else:
            dp[index][V] = dp[index-1][V]

bestvalue = 0
for i in range(1, maxvalue ):
    if dp[n][i] <= total and dp[n][i] !=9999999 :
        bestvalue = i
#print(stone)
#
print(bestvalue)
X = raw_input()
cnt = 0
cnt_max = cnt
for i in range(len(X)):
   if X[i] = 'T':
      cnt += 1
   else:
      cnt -= 1
   if cnt > cnt_max: 
      cnt_max = cnt

print cnt_max * 2 

### FIXED CODE ###

X = raw_input()
cnt = 0
cnt_max = cnt
L = len(X)

for i in range(L):
   if X[i] == 'T':
      cnt += 1
   else:
      cnt -= 1
      
   if cnt > cnt_max: 
      cnt_max = cnt

print cnt_max * 2
i = 0
while i < 200:
    sum = input()
    sum_list = sum.split(" ")
    print(len(str(int(sum_list[0]) + int(sum_list[1]))))
    i += 1


### FIXED CODE ###

while 1:
    try:
        sum = input()
        sum_list = sum.split()
        print(len(str(int(sum_list[0]) + int(sum_list[1]))))
    except EOFError:
        break
a,b,c,d=map(int,input().spilt())
if a+b==c+d:
    print("Balanced")
elif (a+b)>(c+d):
    print("a+b")
else:
    print("c+d")

### FIXED CODE ###

a,b,c,d=map(int,input().split())
if a+b==c+d:
    print("Balanced")
elif a+b>c+d:
    print("Left")
elif a+b<c+d:
    print("Right")
import sys

input = sys.stdin.readline
s = list(input())
x, y = map(int, input().split())
y = abs(y)
s.append('T')
x1 = []
y1 = []

count = 0
u = 0
for i in range(len(s)):
    if s[i] == 'F':
        count += 1
    else:
        if u % 2 == 0:
            x1.append(count)
            u += 1
            count = 0
        else:
            y1.append(count)
            u += 1
            count = 0

v = sum(x1)
w = sum(y1)
if v < x or w < y:
    print('No')
    exit()

dpx = [[0 for i in range(v + 1)] for j in range(len(x1) + 1)]
dpx[0][-1] = 1
x -= x1[0]
x1[0] = 0
v -= x1[0]
x = abs(x)

for i in range(len(x1)):
    for j in range(v + 1):
        if dpx[i][j] == 1:
            if j - 2 * x1[i] >= 0:
                dpx[i + 1][j - 2 * x1[i]] = 1
            dpx[i + 1][j] = 1

if len(y1) == 0:
    y1.append(0)
dpy = [[0 for i in range(w + 1)] for j in range(len(y1) + 1)]
dpy[0][-1] = 1

for i in range(len(y1)):
    for j in range(w + 1):
        if dpy[i][j] == 1:
            if j - 2 * y1[i] >= 0:
                dpy[i + 1][j - 2 * y1[i]] = 1
            dpy[i + 1][j] = 1

if dpy[-1][y] == 1 and dpx[-1][x] == 1:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import sys
input = sys.stdin.readline
s=list(input())
x,y = map(int, input().split())
y=abs(y)
s.append('T')
x1=[]
y1=[]

count=0
u=0
for i in range(len(s)):
    if s[i]=='F':
        count+=1
    else:
        if u%2==0:
            x1.append(count)
            u+=1
            count=0
        else:
            y1.append(count)
            u+=1
            count=0
v=sum(x1)
w=sum(y1)
v-=x1[0]
x-=x1[0]
x1.pop(0)
x=abs(x)
if v<x or w<y:
    print('No')
    exit()

dpx=[[0 for i in range(v+1)] for j in range(len(x1)+1)]
dpx[0][-1]=1

for i in range(len(x1)):
    for j in range(v+1):
        if dpx[i][j]==1:
            if j-2*x1[i]>=0:
                dpx[i+1][j-2*x1[i]]=1
            dpx[i+1][j]=1

if len(y1)==0:
    y1.append(0)
dpy=[[0 for i in range(w+1)] for j in range(len(y1)+1)]
dpy[0][-1]=1

for i in range(len(y1)):
    for j in range(w+1):
        if dpy[i][j]==1:
            if j-2*y1[i]>=0:
                dpy[i+1][j-2*y1[i]]=1
            dpy[i+1][j]=1

if dpy[-1][y]==1 and dpx[-1][x]==1:
    print('Yes')
else:
    print('No')
w = input()
li = list(input().split().lower())
cnt = 0
for i in range(len(li)):
    if w ==li[i]:
        cnt +=1
print(cnt)


### FIXED CODE ###

w=input().lower()
c=[]
s=input()
while(s!='END_OF_TEXT'):
    c+=s.lower().split();
    s=input()
print(len([x for x in c if x==w]))
def resolve():
    S = input()
    K = int(input())
    cnt = 0
    
    for s in S:
        if s != "1":
            break
        cnt += 1
    if cnt > K:
        print("1")
    else:
        print(S[cnt])


if '__main__' == __name__:
    resolve()

### FIXED CODE ###

def resolve():
    S = input()
    K = int(input())
    cnt = 0
    
    for s in S:
        if s != "1":
            break
        cnt += 1
    if cnt >= K:
        print("1")
    else:
        print(S[cnt])


if '__main__' == __name__:
    resolve()
N=int(input())
A= list(map(int,input().split()))

for i in A:
    S+=1/A

print(1/S)


### FIXED CODE ###

N=int(input())
A= list(map(int,input().split()))
S=0

for i in A:
    S+=1/i

print(1/S)
N, K = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))
K = K-1
ans = -10**9-1
for i in range(N):
   i += 1
   start = i
   circle = 1
   number = c[i-1]
   while i != start:
      circle += c[i-1]
      number += 1
      i = p[i-1]
   for j in range (min(number, K+1)):
      sum = 0
      for k in range(i, i+j+1):
         sum += c[k-1]
      if circle > 0:
         sum = circle*((K-j)//number) + sum
      ans = max(sum, ans)
print(ans)

### FIXED CODE ###

N, K = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))
K = K-1
ans = -10**9-1
for h in range(N):
   i = h+1
   start = i
   circle = [c[i-1]]
   i = p[i-1]
   while i != start:
      score = circle[-1] + c[i-1]
      circle.append(score)
      i = p[i-1]
   l=len(circle)
   for j in range(min(l, K+1)):
      if circle[l-1] > 0:
         score = circle[j] + ((K - j)//l)*circle[l-1]
      else:
         score = circle[j]
      ans = max(score, ans)      
print(ans)
a = int(input('tate'))
b = int(input('yoko'))
area = a*b
lenght = 2a + 2b
print(area)
print(lenght)


### FIXED CODE ###

a, b = list(map(int, input().split()))
x= a*b
y= 2*a + 2*b
print(x,y)
import re

if re.match(r'^(hi)+$'):
  print('Yes')

else:
  print('No')

### FIXED CODE ###

import re

S = input() 

if re.match(r'^(hi)+$',S):
  print('Yes')

else:
  print('No')
import sys
dataset = sys.stdin.readlines()

seq = 0

while dataset[seq] != '-\n':
 s = dataset[seq]
 l = len(s) - 1
 s = s[:l]
 seq += 1
 n = int(dataset[seq][0])
 seq += 1
 for i in range(seq, seq + n):
  h = int(dataset[i][0])
  s = s[h:] + s[0:h]
 print(s)
 seq += n

### FIXED CODE ###

import sys
dataset = sys.stdin.readlines()

seq = 0

while dataset[seq] != '-\n':
 s = dataset[seq]
 l = len(s) - 1
 s = s[:l]
 seq += 1
 n = dataset[seq]
 l = len(n) - 1
 n = int(n[:l])
 seq += 1
 for i in range(seq, seq + n):
  h = dataset[i]
  l = len(h) - 1
  h = int(h[:l])
  s = s[h:] + s[0:h]
 print(s)
 seq += n
# -*- coding: utf-8 -*-
N,K = map(int,input().split())
a = [int(i) for i in range(N)]
L = sorted(a)
L = L[::-1]
for i in range(N):
  b.append(a[i])
print(sum(b))

### FIXED CODE ###

N , K = map(int,input().split())
l = list(map(int,input().split()))
asc_lst = sorted(l)
ans = []
for i in range(K):
    ans.append(asc_lst[-(i+1)])

A = sum(ans)
print(A)
a, b, c = map(int, input().split())
if a < b and b < c:
   print("Yes")
else:
   prin("No")



### FIXED CODE ###

a, b, c = map(int, input().split())
if a < b and b < c:
   print("Yes")
else:
   print("No")
mountain=[]
for i in range(10):
 mountain[i]=int(input())
mountain.sort()
fori in range(3):
 print(mountain[i])

### FIXED CODE ###

mountain=[]
for i in range(10):
 mountain.append(int(input()))
mountain.sort()
mountain.reverse()
for i in range(3):
 print(mountain[i])
(n,m),*a=[map(int,t.split())for t in open(0)]
p=[-1]*-~n
for a in a:
 a,b=map(r:=lambda x:x*(p[x]<0)or r(p[x]),a)
 if a-b:p[a]+=p[b];p[b]=a
print(sum(i<0for i in p)-2)

### FIXED CODE ###

code = r"""
# distutils: language=c++
# distutils: include_dirs=/opt/ac-library
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "<atcoder/dsu>" namespace "atcoder":
    cdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
        vector[vector[int]] groups()
from libc.stdio cimport getchar, printf
cdef inline int read() nogil:
    cdef int b, c = 0
    while 1:
        b = getchar() - 48
        if b < 0: return c
        c = c * 10 + b
cdef int n = read(), i
cdef dsu *u = new dsu(n)
for i in range(read()): u.merge(read() - 1, read() - 1)
printf('%lu\n', u.groups().size() - 1)
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('solve.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b solve.pyx')
import solve
mod = 998244353

def comb(n, r):
    if 2 * r > n: return comb(n, n-r)
    return fac[n] * inv[r] * inv[n-r] % mod

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

fac = [1] * (n+2)
inv = [1] * (n+2)
for i in range(2, n+1):
    fac[i] = fac[i-1] * i % mod
inv[n] = pow(fac[n], mod - 2, mod)
for i in range(n-1, 1, -1):
    inv[i] = inv[i + 1] * (i + 1) % mod

ans = 0
for i in range(n+1):
    if (k-a*i) >= 0 and (k-a*i)%b == 0 :
      j = (k-a*i)//b 
      ans += comb(n, i) * comb(n, j) % mod

print(ans)

### FIXED CODE ###

mod = 998244353

def comb(n, r):
    if 2 * r > n: return comb(n, n-r)
    return fac[n] * inv[r] * inv[n-r] % mod

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

fac = [1] * (n+2)
inv = [1] * (n+2)
for i in range(2, n+1):
    fac[i] = fac[i-1] * i % mod
inv[n] = pow(fac[n], mod - 2, mod)
for i in range(n-1, 1, -1):
    inv[i] = inv[i + 1] * (i + 1) % mod

ans = 0
for i in range(n+1):
    Num = (k-a*i)
    if (0 <= Num//b) and (Num//b <= n) and (Num%b == 0):
      j = Num//b 
      ans += comb(n, i) * comb(n, j) 
print(ans%mod)
from __future__ import division, print_function
from sys import stdin

i = 1
for line in stdin:
    x = int(line)
    if not x:
       break
    print "Case %d: %d" % (i, x)
    i += 1

### FIXED CODE ###

from __future__ import division, print_function
from sys import stdin

i = 1
for line in stdin:
    x = int(line)
    if x == 0:
       break
    print ("Case %d: %d" % (i, x))
    i += 1
order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
longi = [order[i] for i in range(len(order)) if i % 2 == 0]
lati = [order[i] for i in range(len(order)) if i % 2 == 1]
def f(x, y, A, B, D):
  for p in A:
      if x > 0:
        x -= p
      else:
        x += p
  if x == 0:
    for q in B:
      if y > 0:
        y -= q
      else:
        y += q
    if y == 0:
      D = "Yes"
  return D
  
#print(longi, lati)
if sum(longi) >= abs(x):
  if sum(lati) >= abs(y):
    longi.sort(reverse=True)
    lati.sort(reverse=True)
    ans = f(x, y, longi, lati, ans)
    if ans == "No":
      x += x // abs(x) * abs(longi[-1])
      y += y // abs(y) * abs(lati[-1])
      ans = f(x, y, longi[:-1], lati[:-1], ans)
    
    
print(ans)

### FIXED CODE ###

order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
lon = [order[i] for i in range(len(order)) if i % 2 == 0]
lat = [order[i] for i in range(len(order)) if i % 2 == 1]
x -= lon[0]
lon = lon[1:]
def f(x, A):
  A.append(abs(x))
  A.sort(reverse=True)
  k = A[0]
  for p in A[1:]:
      if k > 0:
        k -= p
      else:
        k += p
  if k == 0:
    return True
  else:
    return False
  
#print(lon, lat)
if f(x, lon) == f(y, lat) == True:
  ans = "Yes"
  
print(ans)
a, b, c, d, e, f= (int(i) for i in input().split()) 

waterlist=[]
for i in range(int(f/100/a)+1):
  for j in range(int(f/100/b)+1):
    if 100*a*i+100*b*j <=f:
      waterlist+=[100*a*i+100*b*j]
waterlist=list(set(waterlist))
#print(x)

sugarlist=[]
for i in range(int(f/c)+1):
  for j in range(int(f/d)+1):
    if c*i+d*j <=f:
      sugarlist+=[c*i+d*j]
sugarlist=list(set(sugarlist))
#print(y)

density=0

for i in range(len(waterlist)):
  for j in range(len(sugarlist)):
    if 0 < waterlist[i]+sugarlist[j] <= f and sugarlist[j]<=waterlist[i]/100*e:
      tmp=sugarlist[j]/(waterlist[i]+sugarlist[j])
      if density < tmp:
        density = tmp
        ans1=waterlist[i]+sugarlist[j]
        ans2=sugarlist[j]
        
print(ans1,ans2)

### FIXED CODE ###

a, b, c, d, e, f= (int(i) for i in input().split()) 

waterlist=[]
for i in range(0,f+100*a,100*a):
  for j in range(0,f+100*b,100*b):
    if i+j <=f:
      waterlist+=[i+j]
waterlist=list(set(waterlist))
#print(x)

sugarlist=[]
for i in range(int(f/c)+1):
  for j in range(int(f/d)+1):
    if c*i+d*j <=f:
      sugarlist+=[c*i+d*j]
sugarlist=list(set(sugarlist))
#print(y)

density=0

for i in range(len(waterlist)):
  for j in range(len(sugarlist)):
    if 0 < waterlist[i]+sugarlist[j] <= f and sugarlist[j]<=waterlist[i]/100*e:
      tmp=sugarlist[j]/(waterlist[i]+sugarlist[j])
      if density <= tmp:
        density = tmp
        ans1=waterlist[i]+sugarlist[j]
        ans2=sugarlist[j]
        
print(ans1,ans2)
x = input

for i in range(3)
	if x[i] == '7'
  		print("Yes")
    else
    	print("No")



### FIXED CODE ###

s = input()

for c in s:
	if '7' in s:
		print("Yes")
		break
	else:
		print("No")
		break
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = [1,a[0]]
tp = a[0]-1
while True:  
  if a[tp] not in l: 
    l.append(a[tp])
    tp = a[tp] -1
  else:
    l.append(a[tp])
    break
    
last = l[-1]
first = l.index(last)
loop = len(l)-first

if len(l)>k:
  print(l[k])
  exit()
k -=first
k %=loop
if k==0:
  k+=loop
print(l[k+first])
print(l.index(last))

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
l = [1]

for i in range(n):
  l.append(a[l[i]-1])
p = l.index(l[n])
#print(p,l[n])
if k<=n:
  print(l[k])
else:
  x = (k-n+1)%(n-p)
  if x ==0:
    x += (n-p)
    print(l[x-1])
  else:
    print(l[x+p-1])
n,m = map(int,input().split())
min,max = map(int,input().split())
for k in range(m-1):
  a,b = map(int,input().split())
  if min < a:
    min = a
  if max > b:
    max = b
if b < a:
  print(0)
else:
  print(b-a+1)

### FIXED CODE ###

max,m = map(int,input().split())
min = 1
for k in range(m):
  a,b = map(int,input().split())
  if min < a:
    min = a
  if max > b:
    max = b
if max < min:
  print(0)
else:
  print(max-min+1)
a,b = map(int,input(),split())
print(a-b+1)

### FIXED CODE ###

a,b = map(int,input().split())
print(a-b+1)
n=input()
d=[int(i) for i in input().split()]
while True:
  a=d[0]
  del d[0]
  if d == []:
    break
  for i in d:
    sum += a*i
print(sum)

### FIXED CODE ###

n=input()
d=[int(i) for i in input().split()]
sum=0
while True:
  a=d[0]
  del d[0]
  if d == []:
    break
  for i in d:
    sum += a*i
print(sum)