Harryxun/stf_run huggingface dataset:
import math
A,B,C,D=map(int,input().split())
L=C*D//math.gcd(C,D)

if A%C!=0 and A%D!=0:
    print((B-A+1)-((B-(A//C+1)*C)//C+1+(B-(A//D+1)*D)//D+1-(((B-(A//L+1)*L)//L)+1)))
elif A%C==0 and A%D!=0:
    print((B-A+1)-(((B-(A//C)*C)//C+1)+((B-(A//D+1)*D)//D+1)-((B-(A//L+1)*L)//L+1)))
elif A%C!=0 and A%D==0:
    print((B-A+1)-((B-(A//C+1)*C)//C+1+(B-(A//D)*D)//D+1-(B-(A//L+1)*L)//L-1))
elif A%C==0 and A%D==0 and A%L==0:
    print((B-A+1)-((B-(A//C)*C)//C+1+(B-(A//D)*D)//D++1(B-(A//L)*L)//L-1))
elif A%C==0 and A%D==0 and A%L!=0:
    print((B-A+1)-((B-(A//C)*C)//C+1+(B-(A//D)*D)//D+1+(B-(A//L+1)*L)//L-1))



### FIXED CODE ###

import fractions
A,B,C,D=map(int,input().split())
L=C*D//fractions.gcd(C,D)

if A%C!=0 and A%D!=0:
    print((B-A+1)-((B-(A//C+1)*C)//C+1+(B-(A//D+1)*D)//D+1-(((B-(A//L+1)*L)//L)+1)))
elif A%C==0 and A%D!=0:
    print((B-A+1)-(((B-(A//C)*C)//C+1)+((B-(A//D+1)*D)//D+1)-((B-(A//L+1)*L)//L+1)))
elif A%C!=0 and A%D==0:
    print((B-A+1)-((B-(A//C+1)*C)//C+1+(B-(A//D)*D)//D+1-(B-(A//L+1)*L)//L-1))
elif A%C==0 and A%D==0 and A%L==0:
    print((B-A+1)-((B-(A//C)*C)//C+1+(B-(A//D)*D)//D+1-(B-(A//L)*L)//L-1))
elif A%C==0 and A%D==0 and A%L!=0:
    print((B-A+1)-((B-(A//C)*C)//C+1+(B-(A//D)*D)//D+1-(B-(A//L+1)*L)//L-1))
N = int(input())
maxs = 0    
s = []
for i in range(N):
    cin = int(input())
    s.append(cin)
    maxs = max(maxs, cin)
M = maxs * N + 1

dp = [False * M]
dp[0] = True

for x in s:
    for i in range(M+1):
        if i < x: continue
        if dp[i-x]: dp[i] = True

for i in range(M+1):
    if (M-i)%10 != 0 and dp[M-i]:
        print(M-i)
else:
    print(0) 

### FIXED CODE ###

N = int(input())
maxs = 0    
s = []
for i in range(N):
    cin = int(input())
    s.append(cin)
    maxs = max(maxs, cin)
M = maxs * N

dp = [False] * (M+1)
dp[0] = True

for x in s:
    for i in range(M+1):
        if M-i < x: continue
        if dp[M-i-x]: dp[M-i] = True

for i in range(M+1):
    if (M-i)%10 != 0 and dp[M-i]:
        print(M-i)
        break
else:
    print(0)
import sys
from collections import deque
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N, M = map(int, input().split())
m = [list(map(int, input().split())) for _ in range(M)]
 
G = [[] for _ in range(N + 1)]
for a, b in zip(m, m):
    G[a].append(b)
    G[b].append(a)
 
par = [0] * (N + 1)
visited = [0] * (N + 1)
root = 1
visited[root] = 1
q = deque([root])
while q:
    v = q.popleft()
    for w in G[v]:
        if visited[w]:
            continue
        visited[w] = 1
        par[w] = v
        q.append(w)
 
print('Yes')
print(*par[2:], sep='\n')

### FIXED CODE ###

import sys
from collections import deque
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N, M = map(int, readline().split())
 
G = [[] for _ in range(N + 1)]
m = map(int, read().split())
for a, b in zip(m, m):
    G[a].append(b)
    G[b].append(a)
 
par = [0] * (N + 1)
visited = [0] * (N + 1)
root = 1
visited[root] = 1
q = deque([root])
while q:
    v = q.popleft()
    for w in G[v]:
        if visited[w]:
            continue
        visited[w] = 1
        par[w] = v
        q.append(w)
 
print('Yes')
print(*par[2:], sep='\n')
N = int(input())
A = list(map(int, input().split()))
M = [0]*(N+10)
for a in A:
    for i in range(3): M[a+i]+=1
print(max(M))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
M = [0]*(10**5+10)
for a in A:
    for i in range(3): M[a+i]+=1
print(max(M))
N, K = map(int, input().split())
mod = 10**9 + 7
nums = []
for i in list(map(int, input().split())):
    if i >= 0:
        nums.append((i, True))
    else:
        nums.append((-i, False))
rev_nums = sorted(nums, reverse=True)
nums.sort()
print(rev_nums)
print(nums)
ans = 1
pl = []
ml = []
for k in range(K):
    x, b = nums.pop()
    ans *= x
    ans %= mod
    if b:
        pl.append(x)
    else:
        ml.append(x)
if len(ml) % 2 != 0:
    while nums:
        x, b = nums.pop()
        if b:
            ans //= ml[-1]
            ans %= mod
            ans *= x
            ans %= mod
            break
        else:
            ans //= pl[-1]
            ans %= mod
            ans *= x
            ans %= mod
            break
    else:
        ans = -1
        for k in range(K):
            x, b = rev_nums.pop()
            ans *= x
            ans %= mod
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
mod = 10**9 + 7
nums = []
p_cnt = 0
for i in list(map(int, input().split())):
    if i >= 0:
        nums.append((i, True))
        p_cnt += 1
    else:
        nums.append((-i, False))
nums.sort()
if p_cnt == 0 and K%2!=0:
    ans = 1
    for k in range(K):
        ans *= -nums[k][0]
        ans %= mod
    print(ans)
    import sys
    sys.exit()
pl = []
ml = []
for k in range(K):
    x, b = nums.pop()
    if x == 0:
        print(0)
        import sys
        sys.exit()
    if b:
        pl.append(x)
    else:
        ml.append(x)
if len(ml) % 2 != 0:
    p = float("inf")
    px = float("inf")
    m = float("inf")
    mx = float("inf")
    while nums:
        x, b = nums.pop()
        if b:
            if ml and p == float("inf"):
                p = ml[-1]
                px = x
        else:
            if pl and m == float("inf"):
                m = pl[-1]
                mx = x
        if m != float("inf") and p != float("inf"):
            if px * m > mx * p:
                ml.pop()
                pl.append(px)
            else:
                pl.pop()
                ml.append(mx)
            break
    else:
        if p != float("inf"):
            ml.pop()
            pl.append(px)
        elif m != float("inf"):
            pl.pop()
            ml.append(mx)
ans = 1
for x in pl:
    ans *= x
    ans %= mod
for x in ml:
    ans *= -x
    ans %= mod
print(ans)
dic = {"A":1,"B":2,"C":3,"D":4,"E":5,"F":6}
X = input('X>>')
Y = input('Y>>')
for key in dic:
    if key == X:
        x = dic[key]
    if key == Y:
        y = dic[key]
if x > y:
    print('>')
elif x < y:
    print('<')
else:
    print('=')

### FIXED CODE ###

dic = {"A":1,"B":2,"C":3,"D":4,"E":5,"F":6}
X,Y = input().split()
for key in dic:
    if key == X:
        x = dic[key]
    if key == Y:
        y = dic[key]
if x > y:
    print('>')
elif x < y:
    print('<')
else:
    print('=')
# _*_ coding: utf-8 _*_

n, k = [int(e) for e in input().strip().split(' ')]
s = input().strip()

cnts = []
ans = 0
# denote whether the first block is 0 or 1
tmp, cnt = s[0], 0
flag = s[0]

for i in range(n):
    if s[i] == tmp:
        cnt += 1
    else: # here tmp should be cleared
        cnts.append(cnt)
        cnt = 1
    tmp = s[i]
cnts.append(cnt)


n_zero = (len(cnts) + 1) // 2 if flag == 0 else len(cnts) // 2

if n_zero <= k:
     ans = sum(cnts)

else:
    ans = 0
    for inx in range(flag, len(cnts), 2):
        start = min(0, inx - 1)
        end = min(inx + 2 * k, len(cnts))
        tmp = sum(cnts[start: end])
        if tmp > ans:
            ans = tmp

print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
s = [int(x) for x in list(input())]

state = 1
cnt = 0
l = []
for e in s:
    if e != state:
        l.append(cnt)
        cnt = 1
        state = e
    else:
        cnt += 1

if cnt != 0:
    l.append(cnt)


if len(l) % 2 == 1:
    l.append(0)

Add = 2 * k + 1
ruiseki = [0]

for i, e in enumerate(l):
    ruiseki.append(ruiseki[i] + l[i])

answer = 0
for i in range(0, len(l), 2):
    left = i
    right = min(i + Add, len(l))
    tmp = ruiseki[right] - ruiseki[left]
    answer = max(tmp, answer)

print(answer)
import sys

N = int(input())
H = [list(map(int, input().split())) for i in range(N)]

H.sort(key=lambda x: x[2], reverse=True)

for i in H:
    x, y, h = i
    for c_x in range(101):
        for c_y in range(101):
            Height = h + abs(x-c_x) + abs(y-c_y)
            for j in range(N):
                if Height[j][2] != max(Height-abs(H[j][0]-c_x)-abs(H[j][1]-c_y), 0):
                    break
                if j == N-1:
                    print(c_x, c_y, Height)
                    sys.exit()

### FIXED CODE ###

import sys

N = int(input())
H = [list(map(int, input().split())) for i in range(N)]

H.sort(key=lambda x: x[2], reverse=True)

for i in H:
    x, y, h = i
    for c_x in range(101):
        for c_y in range(101):
            Height = h + abs(x-c_x) + abs(y-c_y)
            for j in range(N):
                if H[j][2] != max(Height-abs(H[j][0]-c_x)-abs(H[j][1]-c_y), 0):
                    break
                if j == N-1:
                    print(c_x, c_y, Height)
                    sys.exit()
n,k=map(int,input().split())
l=list(map(int,input().split()))
final=[0]*n
if k>=n:
  print(abs(l[n-1]-l[0]))
else:   
   for i in range(1,k+1):
      final[i]=abs(l[i]-l[0])
  
   for i in range(k+1,n):

      li=[abs(h[i]-h[ik])+dp[ik] for ik in range(i-1,i-k-1,-1) ]
      final[i]=min(li)
   print(final[-1])


### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
final=[0]*n
if k>=n:
  print(abs(l[n-1]-l[0]))
else:   
   for i in range(1,k+1):
      final[i]=abs(l[i]-l[0])
  
   for i in range(k+1,n):

      li=[abs(l[i]-l[ik])+final[ik] for ik in range(i-1,i-k-1,-1) ]
      final[i]=min(li)
   print(final[-1])
#X = int(input().strip())

K, N = list(map(int, input().strip().split()))
A = list(map(int, input().strip().split()))

ans = 0
p = A[0]
low_index = 1
high_index = N-1
Done = set([p])

while len(A) > len(Done):
  #print('p:' + str(p))
  #print(Done)
  #print(ans)
  if abs(A[low_index] - p) < abs(p - A[high_index]):
    #print('low')
    Done.add(A[low_index])
    ans += A[low_index] - p
    p = A[low_index]
    for i in range(1, N):
      if low_index + i not in Done:
        low_index += i
        break
  else:
    #print('high')
    Done.add(A[high_index])    
    ans += K - A[high_index]
    p = A[high_index]
    for i in range(1, N):
      if high_index - i not in Done:
        high_index -= i
        break

print(ans)    

### FIXED CODE ###

#X = int(input().strip())

K, N = list(map(int, input().strip().split()))
A = list(map(int, input().strip().split()))
m = 0
ind = 0
ans = 0

for i in range(N-1):
  _m = A[i+1] - A[i]
  if _m > m:
    m = _m
    ind = i+1
    last = i

_m = K + A[0] - A[N-1]
if _m > m:
  m = _m
  ind = 0
  last = N-1

#print(m)
#print(ind)
#print(last)
i = ind
while i != last:
  #print(ans)
  if i < N-1:
    ans += A[i+1] - A[i]
    i += 1
  else:
    ans += K + A[0] - A[i]
    i = 0

print(ans)
n,M = map(int,input().split())
ls = []
for i in range(M):
    p,m = map(str,input().split())
    ls.append([p,m])
    
ac = 0
wa = 0
now = ""
p = 0
c = 0
for i in range(M):
    if now == ls[i][0]:
        continue
    if ls[i][0] != ls[i-1][0] and c == 0:
        wa -= p
        p = 0
    if ls[i][1] == "AC":
        now = ls[i][0]
        ac += 1
        c = 1
    elif ls[i][1] == "WA":
        wa += 1
        c = 0
        p += 1
        
print(ac,wa)

### FIXED CODE ###

c = input()
print(chr(ord(c) + 1))
import math
PI = math.pi

r = int(input())
men = r**2 * PI
sen = r*2 * PI

print('%.6f %.6f' % (men, sen))

### FIXED CODE ###

import math
PI = math.pi

r = input()
men = r*r * PI
sen = r*2 * PI

print('%.6f %.6f' % (men, sen))
r, g, b = map(int, input().split())
num = 10*y + z
if num % 4 == 0:
  print("YES")
else:
  print("NO")


### FIXED CODE ###

r, g, b = map(int, input().split())
num = 10*g + b
if num % 4 == 0:
  print("YES")
else:
  print("NO")
A,B,C,D=(int(i) for i in input().split())
if {A,B,C,D}=={1,9,7,4}:
    print("Yes")
elif:
    print("No")

### FIXED CODE ###

A,B,C,D=(int(i) for i in input().split())
if {A,B,C,D}=={1,9,7,4}:
    print("YES")
else:
    print("NO")
H, W = map(int,input().split())
map = [input() for i in range(H)]

def drow(i,j, map = map):
  if j > 0 and map[i][j-1] == "#":
    return "Yes"
  if j < W-1 and map[i][j+1] == "#":
    return "Yes"
  if i > 0 and map[i-1][j] == "#":
    return "Yes"
  if i < H -1 and map[i+1][j] == "#":
    return "Yes"
  return "No"

if H == 1 and W==1:
  if map[0][0] =="#":
    ans = "Yes"
  else:
    ans = "No"

for i in range(H):
  for j in range(W):
    if map[i][j] == "#":
      ans = drow(i,j)
      if ans == "No":
        break
print(ans)
    

### FIXED CODE ###

H, W = map(int,input().split())
map = [input() for i in range(H)]

def drow(i,j, map = map):
  if j > 0 and map[i][j-1] == "#":
    return "Yes"
  if j < W-1 and map[i][j+1] == "#":
    return "Yes"
  if i > 0 and map[i-1][j] == "#":
    return "Yes"
  if i < H -1 and map[i+1][j] == "#":
    return "Yes"
  return "No"

ans = "Yes"
for i in range(H):
  for j in range(W):
    if map[i][j] == "#":
      ans = drow(i,j)
      if ans == "No":
        print(ans)
        exit()
print(ans)
S=string(input())
T=string(input())
num = 0
for i in len(S):
  if S[i] != T[i]:
    num= num+1
print(num)

### FIXED CODE ###

S=input()  
T=input()
num = 0
for i in range(len(S)):
	if S[i] != T[i]:
		num= num+1
print(num)
from sys import stdin


class DFS():
    def __init__(self,A_B_arr,N,M):
        self.N = N
        self.M = M
        self.route = {i:[] for i in range(N+1)}
        for A, B in A_B_arr:
            self.route[A].append(B)
            self.route[B].append(A)

        self.dp = [[None,float('inf')] for i in range(N+1)]
        self.dp[1] = [1,0]

    def dfs(self,i,rank):
        if rank>self.N:
            return
        else:
            for r in self.route[i]:
                if rank<self.dp[r][1]:
                    self.dp[r] = [i,rank]
                    self.dfs(r,rank+1)
            return


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, M = list(map(int,_in[0].split(' ')))  # type:list(int)
    A_B_arr = []
    for i in range(M):
        _ = list(map(int,_in[i+1].split(' ')))  # type:list(int)
        A_B_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    dfs = DFS(A_B_arr,N,M)
    dfs.dfs(1,1)

    ans = []
    for (i,_) in enumerate(dfs.dp):
        if i>1 and _[0] == None:
            TF = 'No'
            break
        else:
            ans.append(_[0])
    else:
        TF = 'Yes'
        ans = ans[2:]
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    if TF == 'Yes':
        print(TF)
        for _ in ans:
            print(_)
    else:
        print(TF)


### FIXED CODE ###

from sys import stdin
from collections import deque


class BFS():
    def __init__(self, con, val=None):
        # 隣接リスト表現
        self.con = con
        self.val = val
        self.N = len(self.con)
        # 1つ前の部屋(1-indexed)
        self.dist = [-1]*self.N
        self.que = deque()

        # 初期条件(0-indexed)
        self.dist[0] = 0
        self.que.append(0)

    def bfs(self):
        while self.que:
            v = self.que.popleft()
            for next_v in self.con[v]:
                if self.dist[next_v] != -1:
                    continue
                self.dist[next_v] = v+1
                self.que.append(next_v)


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, M = list(map(int,_in[0].split(' ')))  # type:list(int)
    A_B_arr = []
    for i in range(M):
        _ = list(map(int,_in[i+1].split(' ')))  # type:list(int)
        A_B_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    con = [[] for i in range(N)]
    for A,B in A_B_arr:
        A -= 1
        B -= 1
        con[A].append(B)
        con[B].append(A)

    bfs = BFS(con)
    bfs.bfs()
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    if -1 in bfs.dist[1:]:
        print('No')
    else:
        print('Yes')
        for _ in bfs.dist[1:]:
            print(_)
import numpy as np
 
# 2つの整数の入力
N, L = map(int, input().split())
 
# 味を数列化
taste = np.arange(L, L + N, 1)
 
# 味の最小・最大ともに0以上の場合は最小値を選ぶ
if np.min(taste) >= 0 and np.max(taste) >= 0:
  print("{}".format(np.sum(taste) - np.min(taste)))
 
# 味の最小・最大ともに0以下の場合は最大値を選ぶ
elif np.min(taste) <= 0 and np.max(taste) <= 0:
  print("{}".format(np.sum(taste) - np.max(taste)))
 
# それ以外の場合は0を選ぶ
else:
  print("{}".format(np.sum(taste)))
import numpy as np

# 2つの整数の入力
N, L = map(int, input().split())

# 味を数列化
taste = np.arange(L, L + N, 1)

# 味の最小・最大ともに0以上の場合は最小値を選ぶ
if np.min(taste) >= 0 and np.max(taste) >= 0:
  print("{}".format(np.sum(taste) - np.min(taste)))

# 味の最小・最大ともに0以下の場合は最大値を選ぶ
elif np.min(taste) <= 0 and np.max(taste) <= 0:
  print("{}".format(np.sum(taste) - np.max(taste)))

# それ以外の場合は0を選ぶ
else:
  print("{}".format(np.sum(taste)))


### FIXED CODE ###

N, L = list(map(int, input().split()))
t = []
for i in range(N):
    t.append(L+i)
# print(t)
base = sum(t)
ans = -1
r = float('inf')
for j in range(N):
    if abs(t[j]) < r:
        r = abs(t[j])
        ans = j
print(base-t[ans])
10 37
.....................................
...#...####...####..###...###...###..
..#.#..#...#.##....#...#.#...#.#...#.
..#.#..#...#.#.....#...#.#...#.#...#.
.#...#.#..##.#.....#...#.#.###.#.###.
.#####.####..#.....#...#..##....##...
.#...#.#...#.#.....#...#.#...#.#...#.
.#...#.#...#.##....#...#.#...#.#...#.
.#...#.####...####..###...###...###..
.....................................

### FIXED CODE ###

from collections import deque
def bfs():
    d = [[float("inf")] * w for i in range(h)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
 
    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0
 
    while que:
        p = que.popleft()
        if p[0] == gy and p[1] == gx:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
    if d[gy][gx] != float("inf"):
        return d[gy][gx]
    else:
        return -1
h, w = map(int, input().split())
sy, sx = 0, 0
gy, gx = h - 1, w - 1
s = [list(input()) for i in range(h)]
black = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            black += 1
if bfs() == -1:
    print(-1)
else:
    print(h * w - bfs() - black - 1)
S = input()
T = input()
print(T + S)

### FIXED CODE ###

S,T = input().split()
print(T+S)
n,m=map(int,input())
step=list(range(1,n))
for i in range(m):
    step.remove(int(input()))
dp=[0]*n
dp[0]=1
if step[1]=2:
    dp[1]=1
for i in step:
    dp[i]=(dp[i-1]+dp[i-2])%1000000007
print(dp[n])

### FIXED CODE ###

N, M = list(map(int, input().split()))
A = {i: 0 for i in range(N+1)}
mod = 10 ** 9 + 7
for _ in range(M):
    A[int(input())] = 1
 
dp = [0 for _ in range(N+1)]
dp[0] = 1
 
for i in range(N+1):
    if A.get(i+1) == 0:
        dp[i + 1] += dp[i]
    if A.get(i+2) == 0:
        dp[i + 2] += dp[i]
 
print(dp[N]%mod)
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * (w + 1) for _ in range(n + 1)]
for i in range(n):
    for j in range(w + 1):
        if j - wv[i][0] >= 0:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - wv[i][0]] + wv[i][1])
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])          
print(dp[n][w])


### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
dp = [float('Inf')] * n
dp[0] = 0
for i in range(1, n):
    dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[n - 1])
N = int(input())
A = list(map(int, input(.split())))
output =0

for i in range(N):
    output += 1 / A[i]
    
print(1 / output)


### FIXED CODE ###

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

for i in range(N):
    output += 1 / A[i]
    
print(1 / output)
def main():

    N_ko, K_kai = map(int, input().split())
    teleport = list(map(int, input().split()))

    index = 0
    ctr = 0
    before_ctr = 0

    Visited = []
    Visited.append(ctr)

    for i in range(N_ko + 1):

        ctr += 1
        index = teleport[index] - 1
        Visited.append(index)
        
        if (index == 0):
            FLAG = 1
            break

        if (len(Visited) != len(set(Visited))):
            FLAG = 0
            break


    if (FLAG):
        mod = K_kai % ctr
        city = 0

        for i in range(mod):
            city = teleport[city] - 1

        ans = city + 1

    # else:
    #     cnt = 0
    #     before_ctr = 0

    #     for i in range(N_ko + 1):
    #         cnt += 1
    #         current_index = teleport[index] - 1
            
    #         if (current_index == index):
    #             before_ctr = cnt
    #             break
        
    #     if (K_kai < ctr):
    #         city = 0
            
    #         for i in range(K_kai):
    #             city = teleport[city] - 1

    #         ans = city + 1

    #     else:
    #         ans = (K_kai - before_ctr) % (ctr - before_ctr)
    #         ans += 1
            

    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():

    N_machi, K_teleport = map(int, input().split())
    to_teleport = list(map(int, input().split()))

    visited_city = [1]
    order = [-1 for i in range(N_machi + 1)]
    order[1] = 0
    next_city = 1
    
    for i in range(N_machi):
        next_city = to_teleport[next_city - 1]
        tmp = order[next_city]
        
        if (tmp == -1):
            visited_city.append(next_city)
            order[next_city] = i + 1
        else:
            break
    
    first = order[next_city]
    len_loop = len(visited_city) - first
    
    if (K_teleport < first):
        ans = visited_city[K_teleport]
    else:
        mod = (K_teleport - first) % len_loop
        ans = visited_city[first + mod]
    
    print(ans)
        

if __name__ == '__main__':
    main()
N, M = map(int, input().split())
s2 = []
for _ in range(M):
    s = list(map(int, input().split()))
    del s[0]
    s2.append(s)
p = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    judge = True
    for g in range(len(s2)):
        for j in range(M-1):
            count = 0
            s3 = s2[g][j]
            if i >> (s3-1) & 1:
                count += 1
            if count % 2 != p[g]:
                judge = False
    if judge:
        ans += 1
print(ans)

### FIXED CODE ###

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

q = []
for i in range(m):
    q.append(list(map(int,input().split())))
p = list(map(int,input().split()))


for s in range(2**n): 
    judge = True
    for i in range(m):
        cnt = 0
        for j in range(1,len(q[i])):
            w = q[i][j]
            if s >> (w-1) & 1:
                cnt += 1
        if cnt % 2 != p[i]:
            judge = False
    if judge:
        res += 1
print(res)
n = int(input())
print(n**3)2


### FIXED CODE ###

n = int(input())
print(n**3)
lst = list(input())
lst1 = []
lst1.append(lst[0]+lst[1])
lst1.append(lst[2]+lst[3])

if (int(lst1[0]) >=13 and int(lst1[1]) >=13) or (int(lst1[0]) >=13 and lst1[1] =="00") or (lst1[0] =="00" and lst1[1] >=13):
  print("NA")
  
elif (0<int(lst1[0])<=12 and 0<int(lst1[1])<=12):
      print("AMBIGUOUS")
      
elif 0<lst1[0] <=12 and int(lst1[1])>=13:
      print("MMYY")
elif 0<lst1[1]<=12 and int(lst1[0])>=13:
      print("YYMM")

### FIXED CODE ###

lst = list(input())
lst1 = []
lst1.append(lst[0]+lst[1])
lst1.append(lst[2]+lst[3])

if (int(lst1[0]) >=13 and int(lst1[1]) >=13) or (int(lst1[0]) >=13 and lst1[1] =="00") or (lst1[0] =="00" and int(lst1[1]) >=13) or (lst1[0] =="00" and lst1[1] == "00"):
  print("NA")
  
elif (0<int(lst1[0])<=12 and 0<int(lst1[1])<=12):
      print("AMBIGUOUS")
      
elif 0<int(lst1[0]) <=12:
      print("MMYY")
elif 0<int(lst1[1])<=12:
      print("YYMM")
while True:
    x = str(raw_input())
    if x == 0:
        break
    sum = 0
    for i in range(len(x)):
        sum += int(x[i])
    print sum

### FIXED CODE ###

while True:
    x = str(raw_input())
    if int(x) == 0:
        break
    sum = 0
    for i in range(len(x)):
        sum += int(x[i])
    print sum