Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
 
place = 1
way = [1]
for i in range(n):
    if a[place-1] in way:
        break
    else:
        place = a[place-1]
        way.append(place)
ex = way.index(a[place-1])
loop = way[ex:]
if k <= ex:
    print(way[k])
else:
    k -= ex
    print(loop[k%len(loop)])

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
alr = [0 for i in range(n)]
now = 1
path = [now]

for i in range(k):
    now = a[now-1]
    # if now in path:
    #     now = path[path.index(now) + (k-i-1)%(len(path) - path.index(now))]
    #     break
    if alr[now-1] != 0:
        now = path[path.index(now) + (k-i-1)%(len(path) - path.index(now))]
        break
    path.append(now)
    alr[now-1] += 1

print(now)
### BUGGY CODE ###

input()
a = list(map(int,input().split()))
sa = list(set(a))
b = [ i for i in sa if a.count(i)>=2 ]
c = [ i for i in sa if a.count(i)>=4 ]
b=b+c
b.sort(reverse=True)

if len(b)>=2:
    print(b[0]*b[1])
else:
    print(0)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
bn = 0
ans = 0
count = 0
i = 0

while(i<n):
    if bn==a[i]:
        if count == 0:
            ans = a[i]
            if i+1<n:
                bn = a[i+1]
            i += 1
            count +=1
        else:
            ans *= a[i]
            count +=1
            break
    else:
        bn = a[i]
    i +=1

if count>=2:
    print(ans)
else:
    print(0)
### BUGGY CODE ###

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

matrix = [list(0 for i in range(n)) for i in range(n)]

for comb in ab:
    matrix[comb[0]-1][comb[1]-1] = 1
    matrix[comb[1]-1][comb[0]-1] = 1

count = 0

for i in range(n):
    for j in range(n):
        if matrix[i][j] == 1 and h[i] <= h[j]:
            break
    else:
        count += 1

print(count)


### FIXED CODE ###

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

good = [1]*n

for comb in ab:
    a = comb[0]-1
    b = comb[1]-1
    if h[a] <= h[b]:
        good[a] = 0
    if h[a] >= h[b]:
        good[b] = 0

ans = sum(good)
print(ans)
### BUGGY CODE ###

s= str(input().strip())
K= int(input().strip())
parts = []
for i in range(len(s)+1):
    for j in range(i+1,len(s)+1):
        flg = 0
        if j-i > K:
            break
        for k in parts:
            if s[i:j] == k:
                flg = 1
        if flg == 0:
            parts.append(s[i:j])
        
v = sorted(parts)
print(v[K-1])

### FIXED CODE ###

s= str(input().strip())
K= int(input().strip())
parts = []
for i in range(len(s)+1):
    for j in range(i+1,len(s)+1):
        flg = 0
        if j-i > K:
            break
        parts.append(s[i:j])
v = sorted(parts)
vv = [v[0]]
tmp = v[0]
for k in range(1,len(v)):
    if v[k]!=tmp:
        vv.append(v[k])
        tmp = v[k]
    if len(vv)==K:
        break
        
print(vv[K-1])
### BUGGY CODE ###

from collections import deque

N, Q = map(int, input().split(' '))
tree = [[] for i in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split(' '))
    tree[a].append([a, b])
    tree[b].append([b, a])
val = [0] * (N + 1)
for i in range(Q):
    p, x = map(int, input().split(' '))
    val[p] += x
ans = [-1] * (N + 1)
ans[1] = val[1]
bfs = deque(tree[1])
while bfs:
    p, n = bfs.popleft()
    if ans[n] == -1:
        ans[n] = val[n] + ans[p]
        for i in tree[n]:
            bfs.append(i)
for i in ans[1:-1]:
    print(i,'',end="")
print(ans[-1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

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

memo = [0] * n

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

def dfs(v, par):
    for nv in g[v]:
        if nv == par:
            continue
        memo[nv] += memo[v]
        dfs(nv, v)

dfs(0, -1)

print(*memo)
### BUGGY CODE ###

from collections import deque
N,M=map(int,input().split())
B=[[] for i in range(N)]

for i in range(M):
  a,b=map(int,input().split())
  B[a-1].append(b-1)
  B[b-1].append(a-1)
  
visited=[0]*N
d = deque()
ans=[-1]*N
d.append(0)
while d:
  c=d.popleft()
  visited[c]=1
  for e in B[c]:
    if visited[e]:
      continue
    if e in d:
      continue
    
    d.append(e)
    ans[e]=c
    
print("Yes")
for i in range(1,N):
  print(ans[i]+1)
  
  

### FIXED CODE ###

from collections import deque
N,M=map(int,input().split())
B=[[] for i in range(N)]

for i in range(M):
  a,b=map(int,input().split())
  B[a-1].append(b-1)
  B[b-1].append(a-1)
  
visited=[0]*N
d = deque()
ans=[-1]*N
d.append(0)
visited[0]=1
while d:
  c=d.popleft()
  for e in B[c]:
    if visited[e]:
      continue
      
    d.append(e)
    visited[e]=1
    ans[e]=c
    
print("Yes")
for i in range(1,N):
  print(ans[i]+1)
### BUGGY CODE ###

x,y,z,k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

AB = []
for a in A:
	for b in B:
		AB.append(a+b)

AB.sort(reverse=True)
C.sort(reverse=True)

#print(AB)
#print(C)

ABC = []

if len(AB) < k:
	p = len(AB)
else:
	p = k

if len(C) < k:
	q = len(C)
else:
	q = k

for i in range(p):
	for j in range(q):
		ABC.append(AB[i]+C[j])

ABC.sort(reverse=True)
#print(ABC)

for i in range(k):
	print(ABC[i])

### FIXED CODE ###

x,y,z,k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

AB = []
for a in A:
	for b in B:
		AB.append(a+b)

AB.sort(reverse=True)
C.sort(reverse=True)

#print(AB)
#print(C)

ABC = []

if len(AB) < k:
	p = len(AB)
else:
	p = k

if len(C) < k:
	q = len(C)
else:
	q = k

for i in range(p):
	for j in range(q):
		ABC.append(AB[i]+C[j])

ABC.sort(reverse=True)
#print(ABC)

for i in range(k):
	print(ABC[i])
### BUGGY CODE ###

L, R= (int(i) for i in input().split())  

_min = 2018
_init = L%2019

for g in range(R-L):
	plus = _init + g
	_start = (plus*(plus+1))
	if _start >= 2019:
		_start = _start%2019
	for i in range(R-L-g):
		_min = min(_min, _start)
		_start += plus
		if _start >= 2019:
			_start = _start%2019
	if g == 2019:
		break

print(_min)

### FIXED CODE ###

L, R= (int(i) for i in input().split())  

_min = 2018
_init = L%2019

for g in range(R-L):
	plus = _init + g
	_start = (plus*(plus+1))%2019
	for i in range(R-L-g):
		_min = min(_min, _start)
		_start += plus
		_start = _start%2019
		if _min == 0:
			break
	if g == 2019 or _min == 0:
		break

print(_min)
### BUGGY CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[3]:


N,Q = map(int, input().split())
S = str(input())
data = []
for i in range(Q):
    data.append(list(map(int, input().split())))


# In[17]:


for j in range(Q):
    print(S[data[j][0]-1:data[j][1]].count("AC"))


# In[ ]:






### FIXED CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[15]:


N,Q = map(int, input().split())
S = list(input())
mylist = [0]
cnt = 0
for i in range(1,len(S)):
    if S[i-1] == "A" and S[i] == "C":
        cnt += 1
    mylist.append(cnt)
for _ in range(Q):
    l,r = map(int, input().split())
    ans = mylist[r-1] - mylist[l-1]
    print(ans)


# In[ ]:
### BUGGY CODE ###

from collections import defaultdict
import heapq


vertice,edge,source = map(int,input().split(" "))
link = defaultdict(dict)
weight = defaultdict(dict)
for e in range(edge):
    i,j,w = map(int,input().split(" "))
    link[i] = link.get(i,set()) | {j}
    weight[i].update({j:w})
#print(weight,link)
for v in range(vertice):
    goal = v
    queue = []
    heapq.heappush(queue,(0,source))
    heapq.heapify(queue)
    went = set()

    while queue != []:
        #print(queue)
        now_cost,here = heapq.heappop(queue)
        #print(now_cost,here,queue)
        if here == goal:
            print(now_cost)
            break

        can_go = link[here]
        not_went = set(can_go) - went
        #print(v,here,now_cost,not_went,queue)
        for nw in not_went:
            next_cost = now_cost + weight[here][nw]
            heapq.heappush(queue,(next_cost,nw))
        went = went | {here}
    else:
        print("INF")

### FIXED CODE ###

import sys
from heapq import heappush, heappop
readline = sys.stdin.readline
from collections import defaultdict
vertices, edges, start = map(int, readline().split())
connect = defaultdict(list)
cost = defaultdict(dict)
answer = ["INF" for n in range(vertices)]
for _ in range(edges):
    s, t, w = map(int, readline().split())
    connect[s].append(t)
    cost[s].update({t:w})
 
 
now = start
weight = 0
p_queue = []
heappush(p_queue, (0, now))
visited = set()
while p_queue:
    weight, now = heappop(p_queue)
    if now in visited:
        continue
    visited |= {now}
    answer[now] = weight
    for c in connect[now]:
        if c not in visited:
            heappush(p_queue, (weight + cost[now][c], c))
for a in answer:
    print(a)
### BUGGY CODE ###

def check(c):
    return 'WR' in c

def main():
    N = int(input())
    c = list(input())
    ans = 0
    while check(''.join(c)):
        i1 = c.index('W')
        i2 = len(c) - c[::-1].index('R') - 1
        c[i1], c[i2] = c[i2], c[i1]
        ans += 1
    print(ans)

main()


### FIXED CODE ###

def main():
    N = int(input())
    c = list(input())
    print(c[:c.count('R')].count('W'))

main()
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
for i in range(1, N):
    A[i] += A[i - 1]

def calc(lst, min_num):
    total = lst[-1] - min_num
    # print (total)
    lb = -1
    ub = len(lst)
    while (ub - lb) > 1:
        mid = (lb + ub)//2
        if lst[mid] - min_num > total/2:
            ub = mid
        else:
            lb = mid
    # print ('ub', ub)
    a1, b1 = lst[ub] - min_num, lst[-1] - lst[ub]
    diff1 = abs(b1 - a1)
    # print ('diff1', diff1)
    a2, b2 = lst[ub - 1] - min_num, lst[-1] - lst[ub - 1]
    diff2 = abs(b2 - a2)
    # print ('diff2', diff2)
    if diff2 < diff1:
        a1, b1 = a2, b2
    return a1, b1

# print (calc(A, 0))

ans = 10 ** 9
for half in range(2, N - 1):
    # print (A[:half], end = ' ')
    # print (A[half:])
    P, Q = calc(A[:half], 0)
    R, S = calc(A[half:], A[half - 1])
    # print (P, Q, R, S)
    tmp = max(P, Q, R, S) - min(P, Q, R, S)
    # print (tmp)
    ans = min(tmp, ans)

# print ('ans', ans)
print (ans)


### FIXED CODE ###

#PypyでもTLE A[:half]のような箇所が遅い？

N = int(input())
A = list(map(int, input().split()))
for i in range(1, N):
    A[i] += A[i - 1]

def calc(lb, ub):
    max_num = A[ub]
    lb -= 1
    if lb == -1:
        min_num = 0
    else:
        min_num = A[lb]
    total = A[ub] - min_num
    # print (total)
    while (ub - lb) > 1:
        mid = (lb + ub)//2
        if A[mid] - min_num > total/2:
            ub = mid
        else:
            lb = mid
    # print ('ub', ub)
    a1, b1 = A[ub] - min_num, max_num - A[ub]
    diff1 = abs(b1 - a1)
    # print ('diff1', diff1)
    a2, b2 = A[ub - 1] - min_num, max_num - A[ub - 1]
    diff2 = abs(b2 - a2)
    # print ('diff2', diff2)
    if diff2 < diff1:
        a1, b1 = a2, b2
    return a1, b1

# print (calc(A, 0))
# half = 2
# P, Q = calc(0, half - 1)
# print (P, Q)

ans = 10 ** 9
for half in range(2, N - 1):
    # print (A[:half], end = ' ')
    # print (A[half:])
    P, Q = calc(0, half - 1)
    R, S = calc(half, N - 1)
    # print (P, Q, R, S)
    tmp = max(P, Q, R, S) - min(P, Q, R, S)
    # print (tmp)
    ans = min(tmp, ans)

# print ('ans', ans)
print (ans)
### BUGGY CODE ###

N = int(input())

tmp = []
ans = 0
for _ in range(N):
    S = input()
    if S not in tmp:
        tmp.append(S)
        ans += 1
print(ans)

### FIXED CODE ###

N = int(input())

ans = {}
for _ in range(N):
    S = input()
    ans[S] = 1

print(len(ans))
### BUGGY CODE ###

n=input()
m=0
MOD = 10 ** 9 + 7
from itertools import combinations
b=combinations
a=b(map(int,input().split()),2)
for i,j in a:
    k=i*j
    m+=k
    m%=MOD
print(m)

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
MOD = 10 ** 9 + 7

cumsum = [A[0]]
for i in range(1, N):
    cumsum.append(A[i] + cumsum[i - 1])

ans = 0
for i in range(N):
    ans += (A[i] * (cumsum[-1] - cumsum[i])) % MOD
    ans %= MOD

print(ans)
### BUGGY CODE ###

n, m, q = map(int, input().split())
trnum = [[0 for _ in range(n+1)] for _ in range(n+1)]
cnum = [[0 for _ in range(n+1)] for _ in range(n+1)]
for _ in range(m):
  l, r = map(int, input().split())
  trnum[l][r] += 1

for i in range(n+1):
  for j in range(n+1):
    cnum[i][j] = cnum[i][j-1] + trnum[i][j]

for _ in range(q):
  qp, qq = map(int, input().split())
  s = 0
  for j in range(qp, qq+1):
    s += cnum[j][qq] - cnum[j][qp-1]
  print(s)


### FIXED CODE ###

n, m, q = map(int, input().split())
trnum = [[0 for _ in range(n+1)] for _ in range(n+1)]
cnum = [[0 for _ in range(n+1)] for _ in range(n+1)]
for _ in range(m):
  l, r = map(int, input().split())
  trnum[l][r] += 1

for i in range(1, n+1):
  for j in range(1, n+1):
    trnum[i][j] += trnum[i][j-1]

for i in range(1, n+1):
  for j in range(1, n+1):
    trnum[i][j] += trnum[i-1][j]


for _ in range(q):
  l, r = map(int, input().split())
  print(trnum[r][r] + trnum[l-1][l-1] - trnum[l-1][r] - trnum[r][l-1])
### BUGGY CODE ###

def main():
    n=int(input())
    aa=list(map(int,input().split()))
    i=1
    while True:
        try:
            j=aa.index(i)
        except ValueError:
            break
        aa=aa[j+1:]
        i+=1
    if i<=1:
        print(-1)
    else:
        print(n-i+1)

main()

### FIXED CODE ###

def main():
    n=int(input())
    aa=list(map(int,input().split()))
    b=0
    i=1
    while True:
        try:
            j=aa.index(i,b)
        except ValueError:
            break
        b=j+1
        i+=1
    if i<=1:
        print(-1)
    else:
        print(n-i+1)

main()
### BUGGY CODE ###

import itertools as it

X, Y, Z, K = [int(n) for n in input().strip().split(' ')]
A = sorted([int(s) for s in input().strip().split(' ')], reverse=True)
B = sorted([int(s) for s in input().strip().split(' ')], reverse=True)
C = sorted([int(s) for s in input().strip().split(' ')], reverse=True)

AB_best = sorted([sum(e) for e in it.product(A, B)], reverse=True)[:K]
best = sorted([sum(e) for e in it.product(AB_best, C)], reverse=True)[:K]
for s in best:
    print(s)


### FIXED CODE ###

import heapq as hq

X, Y, Z, K = [int(n) for n in input().strip().split(' ')]
A = sorted([int(s) for s in input().strip().split(' ')], reverse=True)
B = sorted([int(s) for s in input().strip().split(' ')], reverse=True)
C = sorted([int(s) for s in input().strip().split(' ')], reverse=True)

q = []
i, j, k = 0, 0, 0
hq.heappush(q, (-(A[0] + B[0] + C[0]), i, j, k))
pushed = {(0, 0, 0)}

for _ in range(K):
    s, *idx = hq.heappop(q)
    idx = tuple(idx)

    print(-s)

    i, j, k = idx
    if i < X - 1 and (i + 1, j, k) not in pushed:
        hq.heappush(q, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))
        pushed.add((i + 1, j, k))
    if j < Y - 1 and (i, j + 1, k) not in pushed:
        hq.heappush(q, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))
        pushed.add((i, j + 1, k))
    if k < Z - 1 and (i, j, k + 1) not in pushed:
        hq.heappush(q, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        pushed.add((i, j, k + 1))
### BUGGY CODE ###

import math 
A,B,n=map(int,input().split())
step = math.ceil(B/A)
ans=0
for i in range(1,n+1,step):
  tmp=math.floor(A*i/B)-(A*math.floor(i/B))
  if tmp>ans:
    ans=tmp
print(ans)

### FIXED CODE ###

import math
a,b,n=map(int,input().split())
c=min(b-1,n)
f=math.floor(a*c/b)
print(f)
### BUGGY CODE ###

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

exp_sum = []
sum_max = 0
exp1 = 0
for j in range(0,len(p)-k+1):
    sum_each = 0
    exp1 = 0
    sum1 = 0
    for i in range(j,j + k):
        sum1 += p[i]
        if sum1 >= sum_max:
            break
    if sum_max <= sum1:
        sum_max = sum1
        for i in range(j,j + k):
            sum_each = 0.5 * p[i] * (p[i] + 1)
            exp1 += sum_each/p[i]
        exp_sum.append(exp1)
print(max(exp_sum))

### FIXED CODE ###

import sys

def LI(): return list(map(int, sys.stdin.readline().split()))
N, K = LI()
p = LI()
ps = []
for i in range(N):
    ps.append((p[i] + 1) / 2)
 
anss = []
tmp = 0
for i in range(N):
    tmp += ps[i]
    if i > K - 1:
        tmp -= ps[i - K]
    anss.append(tmp)
 
print(max(anss))
### BUGGY CODE ###

# coding: utf-8
n, k = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
for i in range(n - k + 1):
    tmp = sum(p[i: i + k])
    if ans < tmp:
        ans = tmp

print((ans + k) / 2)



### FIXED CODE ###

# coding: utf-8
n, k = map(int, input().split())
p = list(map(int, input().split()))
res = [0]
ra = res.append
for i in range(n):
    ra(p[i] + res[i])

ans = 0
for i in range(n - k + 1):
    tmp = res[i + k] - res[i]
    if ans < tmp:
        ans = tmp

print((ans + k) / 2)
### BUGGY CODE ###

h, w = map(int, input().split())
grid = []
for _ in range(h):
    grid.append(list(input()))
res = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] != '.':
            continue
        visited = []
        queue = [(i, j, 0)]
        while queue:
            c_i, c_j, level = queue.pop(0)
            visited.append((c_i, c_j))
            for n_i, n_j in ((c_i - 1, c_j), (c_i + 1, c_j), (c_i, c_j - 1), (c_i, c_j + 1)):
                if 0 <= n_i < h and 0 <= n_j < w and grid[n_i][n_j] == '.' and (n_i, n_j) not in visited:
                    queue.append((n_i, n_j, level + 1))
        res = max(res, level)
print(res)        

### FIXED CODE ###

h, w = map(int, input().split())
grid = []
for _ in range(h):
    grid.append(list(input()))
res = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] != '.':
            continue
        visited = [[False for _ in range(w)] for _ in range(h)]
        visited[i][j] = True
        queue = [(i, j, 0)]
        while queue:
            c_i, c_j, level = queue.pop(0)
#             visited.append((c_i, c_j))
            for n_i, n_j in ((c_i - 1, c_j), (c_i + 1, c_j), (c_i, c_j - 1), (c_i, c_j + 1)):
                if 0 <= n_i < h and 0 <= n_j < w and grid[n_i][n_j] == '.' and visited[n_i][n_j] == False:
                    queue.append((n_i, n_j, level + 1))
                    visited[n_i][n_j] = True
        res = max(res, level)
print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
# 文字列をinput()した場合、末尾に改行が入るので注意
def main():
  h,w,k=map(int,input().split())
  x1,y1,x2,y2=map(lambda x:int(x)-1,input().split())
  cmap=[input() for _ in range(h)]
  from heapq import heappop,heappush,heapify
  dv={'w':0,'n':1,'e':2,'s':3}
  inf=float('inf')
  seen=[[[inf]*4 for _ in range(w)] for _ in range(h)]
  todo=[[0,x1,y1,'w']]
  seen[x1][y1][dv['w']]=0
  heapify(todo)
  #d=[[-1]*w for _ in range(h)]
  cnt=1
  while todo:
    c,x,y,v=heappop(todo)
    #print(c,x,y,v)
    if (x,y)==(x2,y2):
      print((c+k-1)//k)
      exit()
      #break
    if v=='w':
      if seen[x][y][dv['n']]>k*((c+k-1)//k):
        heappush(todo,[k*((c+k-1)//k),x,y,'n'])
        seen[x][y][dv['n']]=k*((c+k-1)//k)
      if y>0 and cmap[x][y-1]!='@' and seen[x][y-1][dv['w']]>c+1:
        heappush(todo,[c+1,x,y-1,'w'])
        seen[x][y-1][dv['w']]=c+1
    elif v=='e':
      if seen[x][y][dv['s']]>k*((c+k-1)//k):
        heappush(todo,[k*((c+k-1)//k),x,y,'s'])
        seen[x][y][dv['s']]=k*((c+k-1)//k)
      if y<w-1 and cmap[x][y+1]!='@' and seen[x][y+1][dv['e']]>c+1:
        heappush(todo,[c+1,x,y+1,'e'])
        seen[x][y+1][dv['e']]=c+1
    elif v=='n':
      if seen[x][y][dv['e']]>k*((c+k-1)//k):
        heappush(todo,[k*((c+k-1)//k),x,y,'e'])
        seen[x][y][dv['e']]=k*((c+k-1)//k)
      if x>0 and cmap[x-1][y]!='@' and seen[x-1][y][dv['n']]>c+1:
        heappush(todo,[c+1,x-1,y,'n'])
        seen[x-1][y][dv['n']]=c+1
    elif v=='s':
      if seen[x][y][dv['w']]>k*((c+k-1)//k):
        heappush(todo,[k*((c+k-1)//k),x,y,'w'])
        seen[x][y][dv['w']]=k*((c+k-1)//k)
      if x<h-1 and cmap[x+1][y]!='@' and seen[x+1][y][dv['s']]>c+1:
        heappush(todo,[c+1,x+1,y,'s'])
        seen[x+1][y][dv['s']]=c+1

  print(-1)
  #for si in seen:
  #  print([min(sij) for sij in si])

if __name__=='__main__':
  #import datetime
  #print(datetime.datetime.now())
  main()
  #print(datetime.datetime.now())

### FIXED CODE ###

from collections import deque
h,w,k=map(int,input().split())
x1,y1,x2,y2=map(lambda x:int(x)-1,input().split())
cmap=[input() for _ in range(h)]
inf=float('inf')
seen=[[[(inf,inf)]*4 for _ in range(w)] for _ in range(h)]
D=[(-1,0),(0,1),(1,0),(0,-1)]# 上:0, 右:1, 下:2, 左:3
q=deque()
for d in range(4):
  seen[x1][y1][d]=(1,0)
  q.append((x1, y1, d, 1, 0)) # (x, y, 進行方向[d], 移動回数[c], 進行済マス数[k])
while q:
  x,y,d,c,k_=q.popleft()
  # nx, ny: 次の座標
  # nd: 次の進行方向
  # nc: 次の移動回数
  # nk: 次の進行済マス数
  for nd in range(4):
    if nd==d:
      dx,dy=D[nd]
      nk=1 if k_==k else k_+1
      nc=c+1 if k_==k else c
    else:
      dx,dy=0,0
      nk=0
      nc=c+1
    nx=x+dx;ny=y+dy
    if 0<=nx<h and 0<=ny<w and cmap[nx][ny]!='@' and seen[nx][ny][nd]>(nc,nk):
      seen[nx][ny][nd]=(nc,nk)
      if nc==c: # 同一方向に進むケースは次のループで一番はじめに処理する。
        q.appendleft((nx,ny,nd,nc,nk))
      else:
        q.append((nx,ny,nd,nc,nk))
ans=inf
for d in range(4):
  ans=min(ans,seen[x2][y2][d][0])
ans=-1 if ans==inf else ans
print(ans)
### BUGGY CODE ###

import sys
A,B,D = map(int, raw_input().split())

while A%D!=0:
 A=A+1
num=0
while A<=B:
 num=num+1
 A=A+D
print num

### FIXED CODE ###

import sys

def f(num,div):
 if num==-1:
  return 0
 return num/div+1

A,B,D = map(int, raw_input().split())

num1=f(A-1,D)
num2=f(B,D)

print num2-num1
### BUGGY CODE ###

s = input()
t = input()

flag = 0
if t in s:
  s = s.replace('?', 'a')
  print(s)
  flag = 1
if '?' * len(t) in s:
  s = s[::-1]
  s = s.replace('?' * len(t), t[::-1], 1)
  s = s.replace('?', 'a')
  print(s[::-1])
  flag = 1          

if flag == 0:
  for i in range(0, 2 ** len(t)):
    tmp = '0' * (len(t) - len(bin(i)[2:])) + bin(i)[2:]
    lst = []
    for j, elem in enumerate(tmp):
      if elem == '0':
        lst.append('?')
      else:
        lst.append(t[j])
    tmp2 = ''.join(lst)
    if tmp2 in s:
      s = s[::-1]
      s = s.replace(tmp2[::-1], t[::-1], 1)
      s = s.replace('?', 'a')
      print(s[::-1])
      flag = 1
      break      
    
if flag == 0:
	print('UNRESTORABLE')

### FIXED CODE ###

S,T=input(),input()
l,m=len(S),len(T)
 
for i in range(l-m+1):
  if all(c in"?"+d for c,d in zip(S[-i-m:],T)):
    S=S.replace("?","a")
    print(S[:-i-m]+T+S[l-i:])
    quit()
 
print("UNRESTORABLE")
### BUGGY CODE ###

import sys

def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    a = list(map(int, lines[1].strip().split(' ')))
    b = list(map(int, lines[2].strip().split(' ')))
    c_max = 0
    c = 0
    s = 0
    for q in b:
        s += q
        if s > k:
            break
        c += 1
    c_max = max(c, c_max)
    s = 0
    c = 0
    for p in a:
        s += p
        c += 1
        if s > k:
            break
        sb = s
        cb = c
        for q in b:
            sb += q
            if sb > k:
                break
            cb += 1
        c_max = max(cb, c_max)


    print(c_max)

resolve()

### FIXED CODE ###

import sys

def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    A = list(map(int, lines[1].strip().split(' ')))
    B = list(map(int, lines[2].strip().split(' ')))

    a = [0]
    b = [0]

    for i in range(n):
        a.append(a[i] + A[i])
    for i in range(m):
        b.append(b[i] + B[i])

    res = 0
    j = m
    for i in range(n+1):
        if a[i] > k:
            break
        while a[i] + b[j] > k:
            j -= 1
        res = max(res, i+j)
    print(res)

resolve()
### BUGGY CODE ###

a,b,k = map(int,input().split())
for i in range(a,b+1):
    if i<a+k or i>b-k:
        print(i)

 


### FIXED CODE ###

a,b,k = map(int,input().split())
if b+1-a <= k*2:
    for i in range(a,b+1):
        print(i)
else:
    for j in range(a,a+k):
        print(j)
    for l in range(b-k+1,b+1):
        print(l)