Harryxun/stf_run huggingface dataset:
# @profile
def main():
    import copy
    import math

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

    # N=5
    # a = [12,15,18,36,42]

    # N = 10**5
    # a = [1]*N

    # N=11
    # a = [56,58,82,46,67,36,98,68,24,46,52]

    #a,bの最大公約数
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a

    # 一番近い大きい側の2の累乗の数が，segtreeの葉の数になる．
    N_ADJUST = 2**int(math.ceil(math.log2(N)))
    # segtreeのサイズはN_ADJUSTを葉とする木のノード数．
    ST_SIZE = N_ADJUST*2-1
    # binopに合わせて単位元として決める．maxならINT_MAX(問題文の制限)
    INT_IDENTITY = 0
    li = [INT_IDENTITY]*ST_SIZE
    # li_initは，葉の配列．
    # 節点kが [l,r) にbinopという演算で結びついている．
    def init_segtree(li, k, l, r, binop, li_init):
        if r-l==1:
            li[k] = INT_IDENTITY if l >= len(li_init) else li_init[l]
        elif r-l>1:
            k_l, k_r = k*2+1, k*2+2
            init_segtree(li, k_l, l, (l+r)//2, binop, li_init)
            init_segtree(li, k_r, (l+r)//2, r, binop, li_init)
            li[k] = binop(li[k_l],li[k_r])

    init_segtree(li,0,0,N_ADJUST,gcd,a)

    # print(li)
    # 下からupdateする．
    def update_segtree(li,k,binop):
        if k > 0:
            k_2 = (k-1)//2
            k_l = k_2*2+1
            k_r = k_l+1
            li[k_2] = binop(li[k_l],li[k_r])
            update_segtree(li,k_2,binop)

    val = []
    for i in range(N_ADJUST-1,N_ADJUST+N-1):
        tmp = li[i]
        li[i] = 0
        update_segtree(li,i,gcd)
        # print(i, li)
        val.append(li[0])
        li[i] = tmp
        update_segtree(li,i,gcd)

    print(max(val))

main()


### FIXED CODE ###

# @profile
def main():
    import math

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

    # N=5
    # a = [12,15,18,36,42]

    # N = 10**5
    # a = [1]*N

    # N=11
    # a = [56,58,82,46,67,36,98,68,24,46,52]

    #a,bの最大公約数
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a

    # 一番近い大きい側の2の累乗の数が，segtreeの葉の数になる．
    N_ADJUST = 2**int(math.ceil(math.log(N)/math.log(2)))
    # segtreeのサイズはN_ADJUSTを葉とする木のノード数．
    ST_SIZE = N_ADJUST*2-1
    # binopに合わせて単位元として決める．maxならINT_MAX(問題文の制限)
    INT_IDENTITY = 0
    li = [INT_IDENTITY]*ST_SIZE
    # li_initは，葉の配列．
    # 節点kが [l,r) にbinopという演算で結びついている．
    def init_segtree(li, k, l, r, binop, li_init):
        if r-l==1:
            li[k] = INT_IDENTITY if l >= len(li_init) else li_init[l]
        elif r-l>1:
            k_l, k_r = k*2+1, k*2+2
            init_segtree(li, k_l, l, (l+r)//2, binop, li_init)
            init_segtree(li, k_r, (l+r)//2, r, binop, li_init)
            li[k] = binop(li[k_l],li[k_r])

    init_segtree(li,0,0,N_ADJUST,gcd,a)

    # print(li)
    # 下からupdateする．
    def update_segtree(li,k,binop):
        if k > 0:
            k_2 = (k-1)//2
            k_l = k_2*2+1
            k_r = k_l+1
            li[k_2] = binop(li[k_l],li[k_r])
            update_segtree(li,k_2,binop)

    val = []
    for i in range(N_ADJUST-1,N_ADJUST+N-1):
        tmp = li[i]
        li[i] = 0
        update_segtree(li,i,gcd)
        # print(i, li)
        val.append(li[0])
        li[i] = tmp
        update_segtree(li,i,gcd)

    print(max(val))

main()
n,*a = map(int,open(0).read().split())
am = []
ap = []
amap = am.append
apap = ap.append
for i in a:
  if i >= 0:
    apap(i)
  else:
    amap(i)
ans = []
ansap = ans.append
for _ in range(n-1):
  if ap == []:
    x = max(am)
    y = min(am)
    am.remove(x)
    am.remove(y)
    apap(x-y)
  elif am == []:
    x = min(ap)
    y = max(ap)
    ap.remove(x)
    ap.remove(y)
    amap(x-y)
  elif len(ap) > len(am):
    x = am.pop()
    y = ap.pop()
    amap(x-y)
  else:
    x = ap.pop()
    y = am.pop()
    apap(x-y)
  ansap(" ".join((str(x),str(y))))

print(ap[0])
for i in ans:
  print(i)

### FIXED CODE ###

n= int(input())
a = list(map(int,input().split()))
xy = []
xyap = xy.append
ap = max(a)
a.remove(ap)
am = min(a)
a.remove(am)
for i in a:
  if i>0:
    xyap((am,i))
    am -= i
  else:
    xyap((ap,i))
    ap -= i
xyap((ap,am))
print(ap-am)
for i in xy:
  print(*i)
s = input()
cnt = 0
cnt_list = [0]*len(s)
for i in s:
    if s in 'ACTG ':
        cnt +=1
    else:
        cnt = 0
    cnt_list[i] = cnt
print(max(cnt_list))

### FIXED CODE ###

s = input()
cnt = 0
cnt_list = [0]*len(s)
for idx,i in enumerate(s):
    if i in 'ACTG ':
        cnt +=1
    else:
        cnt = 0
    cnt_list[idx] = cnt
print(max(cnt_list))
import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():  
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A = [a - 1 for a in A]
    X = K.bit_length()
    to = [[-1] * X for _ in range(N)]
    for i,a in enumerate(A):
        to[i][0] = a
    for i in range(X - 1):
        for j in range(N):
            to[j][i + 1] = to[to[j][i]][i]
    now = 0
    i = 0
    while K > 0:
        if K&1:
            now = to[now][i]
        i += 1
        K >>= 1
    print(now + 1)
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    s = input()
    t = input()
    if s == t[:-1] and len(t) == len(s) + 1:
        print('Yes')
    else:
        print('No')
         
if __name__ == '__main__':
    main()
N = int(input())
a = map(int, input().split())
a = [0] + list(a)
b = [0] * (N+1)
result_str = ''

for i in range(N, 0, -1):
  i_sum = sum(b[i::i])
  if i_sum % 2 != a[i]:
    b[i] = 1
    result_str = '{} '.format(i) + result_str

print(sum(b))
print(result_str[:-1])


### FIXED CODE ###

a = int(input())
print(3*(a**2))
n,m=map(int,input().split())
if n==2 or m==2:
    print(0)
elif n==m==1:
    print(1)
elif n==1 or m==1:
    print(max(n,m)-2)
else:
    print((n-2)(m-2))

### FIXED CODE ###

n,m=map(int,input().split())
if n==2 or m==2:
    print(0)
elif n==m==1:
    print(1)
elif n==1 or m==1:
    print(max(n,m)-2)
else:
    print((n-2)*(m-2))
import math

A , B , K = map(int,input().split()) # A,B <= 100

k = 0

R = int(max(math.gcd(A,B),1))

for i in range(R,0,-1) :
    if A % i == 0 and B % i == 0 :
        k += 1
        if k >= K :
            print(i)
            break



### FIXED CODE ###

import fractions as fr

A , B , K = map(int,input().split()) # A,B <= 100

k = 0

R = int(max(fr.gcd(A,B),1))

for i in range(R,0,-1) :
    if A % i == 0 and B % i == 0 :
        k += 1
        if k >= K :
            print(i)
            break
o,e = map(str, raw_input().split())
s = ""
for i in range(len(o)):
	s += o[i]+e[i]
print s

### FIXED CODE ###

o = raw_input()
e = raw_input()
s = ""
l = len(o)
if len(e)>l:
	l = len(e)
for i in range(l):
	if i<len(o):
		s = s+o[i]
	if i<len(e):
		s = s+e[i]
print s
a,b,c=[int(x) for x in input().split()]
count = 0
for d in range(a,b+1)
    if c%d == 0 : count += 1
print(count)


### FIXED CODE ###

a,b,c=[int(x) for x in input().split()]
count = 0
for d in range(a,b+1):
    if c%d == 0 : count += 1
print(count)
# bit全探索問題

N,M,X = map(int,input().split())
items = [list(map(int,input().split())) for _ in range(N)]
ans = []
for i in range(2 ** N):
    total = [0 for _ in range(M)]
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            total = [x + y for (x, y) in zip(total, items[j])]
    if all( k >= X for k in total) == True:
       ans.append(total[0])
    # print(total)
if len(total) == 0:
    print(-1)
else:
    print(min(ans))

### FIXED CODE ###

# bit全探索問題

N,M,X = map(int,input().split())
items = [list(map(int,input().split())) for _ in range(N)]
ans = -1
for i in range(1 << N):
    total = [0]*(M+1)
    for j in range(N):  
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            total = [x + y for (x, y) in zip(total, items[j])]
    # print(total)
    if all( k >= X for k in total[1:]) == True:
        if ans == -1:
            ans = total[0]
        else:
            ans = min(ans,total[0]) 
print(ans)
def bishop(H, W):
    if H==1 or W== 1:
        return 0
    result  = int((H-1)/2 + 1) * int((W-1)/2 + 1) + int(H/2) * int(W/2)
    return result
ans = input().split(" ")
H = int(ans[0])
W = int(ans[1])
print(bishop(H,W)

### FIXED CODE ###

def bishop(H, W):
    if H==1 or W== 1:
        return 1
    result  = int((H-1)/2 + 1) * int((W-1)/2 + 1) + int(H/2) * int(W/2)
    return result
ans = input().split(" ")
H = int(ans[0])
W = int(ans[1])
print(bishop(H,W))
n = int(input())
c = []
for i in range(n):
  c += [i+1]*int(input())
cnt = 0
paired = False
for i in range(len(c)-1):
  if paired:
    paired = False
    continue
  if c[i+1] - c[i] <= 1 and not paired:
    cnt += 1
    paired = True
print(cnt)

### FIXED CODE ###

n = int(input())
a = []
cnt = 0
for i in range(n):
  a.append(int(input()))
stack = -1
for i in range(n):
  if i+1 - stack <= 1 and a[i] > 0:
    cnt += 1
    a[i] -= 1
    stack = -1
  cnt += a[i] // 2
  if a[i] % 2 == 1:
    stack = i+1
  else:
    stack = -1
print(cnt)
import fractions

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

for j in range(len(A)):
    B = A[:]
    B.pop(j)
    tmp = max(B)
    for i in B:
        tmp = fractions.gcd(tmp, i)
    if tmp > ans:
        ans = tmp
print(ans)

### FIXED CODE ###

import fractions

n = int(input())
a = list(map(int,input().split()))
b = a[:]

for i in range(1,n):
    a[i] = fractions.gcd(a[i],a[i-1])
    b[n-i-1] = fractions.gcd(b[n-i-1],b[n-i])
a = [0]+a #左に0を追加
b = b+[0] #右に0を追加
print(max(fractions.gcd(a[i],b[i+1]) for i in range(n)))
import math
N = int(input())
n = int(math.sqrt(N))
if n * n != N:
    n += 1
ans = 0
for i in range(1, n):
    if N % i ==  0:
        ans += N // i - 1
if N <= 2:
    ans = 0
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
print(N - K + 1)
x = input()
if x >= 30:
    print('Yes')
elif x < 30:
    print('No')

### FIXED CODE ###

x = int(input())
if x >= 30:
    print('Yes')
elif x < 30:
    print('No')
import math
n=int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = math.gcd(ans, a[i])
print(ans)

### FIXED CODE ###

def gcd(a,b):
    if a<b:
        tmp=a
        a=b
        b=tmp
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

n=int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = gcd(ans, a[i])
print(ans)
n , m = map(int, input().split())
a = []
p = 0
max_wid = 0
for i in range(m):
    b = int(input())
    a.append(b)
    if i > 0:
        max_wid = max(max_wid, b)
max_wid = max(max_wid, n - a[m-1])
fib = [1, 1]
for i in range(max_wid+3):
    l = len(fib)
    fib.append(fib[l-2] + fib[l-1])

ans = 1
if a[0] == 0:
    ans *= 0
else:
    ans *= fib[a[0]-1]

for i in range(m-1):
    if a[i+1] == a[i] + 1:
        ans *= 0
    else:
        ans *= fib[a[i+1]-a[i]-2]
        

ans *= fib[n-a[m-1]-1]
ans %= 1000000007
print(ans)


### FIXED CODE ###

n , m = map(int, input().split())
a = []
p = 0
max_wid = 0
if m == 0:
    max_wid = n
else:
    for i in range(m):
      b = int(input())
      a.append(b)
      if i > 0:
          max_wid = max(max_wid, b)
    max_wid = max(max_wid, n - a[m-1])

fib = [1, 1]
for i in range(max_wid):
    l = len(fib)
    fib.append(fib[l-2] + fib[l-1])
ans = 1
if m == 0:
  print(fib[n]%1000000007)
else:
  
  if a[0] == 0:
      ans *= 0
  else:
      ans *= fib[a[0]-1]
  for i in range(m-1):
      if a[i+1] == a[i] + 1:
          ans *= 0
      else:
          ans *= fib[a[i+1]-a[i]-2]
  ans *= fib[n - a[m-1]-1]
  ans %= 1000000007
  print(ans)
import math
n=int(input())
arr=list(map(int,input().split()))
ans=True

if n!=0:
    if len(set(arr))!=int(n/2)+1
    ans=False
else:
    if len(set(arr))!=n/2:
    ans=False

if ans and n!=0:
    print(2**math.floor(n/2)%((10**9)+7))
else:
    print(0)

### FIXED CODE ###

N=int(input())
l=list(map(int,input().split()))
a=1
if N%2==0:
    if len(l)!=len(set(l))*2:
        a=0
else:
    if l.count(0) == 1:
        l.remove(0)
        if len(l) != 2*len(set(l)):
            a = 0
    else:
        a=0
if a:
      print((2**(N//2))%(10**9+7))
else:
      print(0)
if b <= c:
    print("0")
elif c <= a:
    print("0")



if a<c and (c<b and b<d):
    print(b-c)
elif (a<c and a<d) and (c<b and d<b):
    print(d-c)
elif (c<a and a<d) and (c<b and b<d):
    print(b-a)
elif (c<a and a<d) and (c<b and d<b):
    print(d-a)
else:
    print("0")


### FIXED CODE ###

a, b , c ,d = map(int, input().split())



mi = min(b,d )
ma = max(a,c)

print(max(0,mi - ma))
N = int(input())
As = [int(input()) for _ in range(N)]
from bisect import bisect_left

def LIS(L):
    dp = [L[0]]
    length = len(L)
    lis = [[0]]*(length+1)
    l = 1
    for i in range(1, length):
        a = L[i]
        if a > dp[-1]:
            dp.append(a)
            l += 1
            lis[l] = dp[:]
        else:
            dp[bisect_left(dp, a)] = a
    for j in lis[l]:
        L.remove(j)
    return L

cnt = 0
while 1:
    L = LIS(As)
    cnt += 1
    if len(L)==0:
        print(cnt)
        break

### FIXED CODE ###

N = int(input())
As = [int(input()) for _ in range(N)]
from bisect import bisect_right
from collections import deque

def LIS(L):
    dp = deque([L[0]])
    length = len(L)
    for i in range(1, length):
        a = L[i]
        if a >= dp[-1]:
            dp.append(a)
        else:
            dp[bisect_right(dp, a)] = a
    return dp

print(len(LIS(As[::-1])))
A,B,K = map(int,input().split())
if K <= A:
  print(A-K,B)
elif K > A:
  print(0,A+B-K) 
elif K == A+B
  print(0,0)

### FIXED CODE ###

A,B,K = map(int,input().split())
if K <= A:
  print(A-K,B)
else:
  if K <= A + B:
    print(0, A+B-K)
  else:
    print(0, 0)
a=int(input())
print(christmas+"Eve"*(25-a))

### FIXED CODE ###

a=int(input())
print("Christmas"+" Eve"*(25-a))
words = lambda t : list(map(t, input().split()))

def getNext(xs, i):
    if i == len(xs)-1:
        return 0
    else:
        return i+1

def getPrev(xs, i):
    if i == 0:
        return len(xs)-1
    else:
        return i-1

n = int(input())
a = words(int)
b = words(int)

import queue
q = queue.Queue()

def verify(i):
    if b[i] - (b[getNext(b,i)] + b[getPrev(b,i)]) >= a[i]:
        return True
    else:
        return False

for i in range(len(b)):
    if verify(i):
        q.put(i)

ans = 0
while not q.empty():
    i = q.get()
    ans += b[i] // (b[getNext(b,i)] + b[getPrev(b,i)])
    b[i] = b[i] % (b[getNext(b,i)] + b[getPrev(b,i)])
    if verify(getNext(b,i)):
        q.put(getNext(b,i))
    if verify(getPrev(b,i)):
        q.put(getPrev(b,i))

succeed = True
for i in range(len(b)):
    if a[i] != b[i]:
        succeed = False
        break

if succeed:
    print(ans)
else:
    print(-1)


### FIXED CODE ###

words = lambda t : list(map(t, input().split()))



n = int(input())
a = words(int)
b = words(int)

def getNext(i):
    if i == n-1:
        return 0
    else:
        return i+1

def getPrev(i):
    if i == 0:
        return n-1
    else:
        return i-1

from collections import deque
q = deque()

def verify(i):
    if b[i] != a[i] and b[i] - (b[getNext(i)] + b[getPrev(i)]) >= a[i]:
        return True
    else:
        return False

for i in range(len(b)):
    if b[i] >= a[i] and verify(i):
        q.append(i)

ans = 0
succeed = True
while not len(q) == 0:
    i = q.popleft()
    ni = getNext(i)
    pi = getPrev(i)
    #print(i, b)
    d = b[ni] + b[pi]
    if b[i] % d == a[i] % d:
        ans += b[i] // d - (a[i] // d)
        b[i] = a[i]
    else:
        ans += b[i] // d
        b[i] %= d
    if b[i] < a[i]:
        succeed = False
        break
    if verify(ni):
        q.append(ni)
    if verify(pi):
        q.append(pi)

for i in range(len(b)):
    if a[i] != b[i]:
        succeed = False
        break

if succeed:
    print(ans)
else:
    print(-1)
a, b, k = map(int, input().split())
a = list(range(a, b+1))
print(*set(a[:k] + a[-k:]), sep='\n')


### FIXED CODE ###

a, b, k = map(int, input().split())
l = range(a, b+1)
for i in sorted(set(l[-k:]) | set(l[:k])):
    print(i)
from sys import stdin

t = stdin.readline()
t_i = int(t)
data = [stdin.readline().rstrip().split() for _ in range(t_i)]
#print(data)
for i in range(t_i) :
    a = int(data[i][0])
    b = int(data[i][1])
    c = int(data[i][2])
    d = int(data[i][3])
    #print(a, b, c, d)
    if a < b :
        print("No")
    elif b > d :
        print("No")
    elif a % b > c and a % b < b :
        print("No")
    else :
        #print("Yes")
    
        stock = a
        count = 0
        while True :
            stock = stock - b
            if stock < 0 :
                print("No")
                break
            if stock <= c :
                stock = stock + d
            count = count + 1
            if count > 10000 :
                print("Yes")
                break

        


### FIXED CODE ###

from sys import stdin

n = stdin.readline()
n_i = int(n)

a = stdin.readline().rstrip().split()
a_list = list(a)

n_count = 0

if len(a_list) == 2 and a_list[0] == a_list[1] :
    print(n_count + 1)
else :
    for i in range(n_i):
        if i == n_i - 1 :
            break
        if a_list[i] == a_list[i + 1]:
            n_count = n_count + 1
            a_list[i + 1] = "X"

    print(n_count)
n, m, x = map(int, input().split())
b = 10**18
tm = []
for i in range(m):
    tm.append(list(map(int, input().split())))
for i in range(2**n):
    c = [0 for i in range(m)]
    sum = 0
    for j in range(n):
        if (i >> j) & 1:
            sum += tm[j][0]
            for k in range(m):
                c[k] += tm[j][k+1]
    if min(c) >= x:
        b = min(b, sum)
if min == 10**18:
    print('-1')
else:
    print(b)

### FIXED CODE ###

n, m, x = map(int, input().split())
b = 10**18
tm = []
for i in range(n):
    tm.append(list(map(int, input().split())))
for i in range(2**n):
    c = [0 for i in range(m)]
    sum = 0
    for j in range(n):
        if (i >> j) & 1:
            sum += tm[j][0]
            for k in range(m):
                c[k] += tm[j][k+1]
    if min(c) >= x:
        b = min(b, sum)
if b == 10**18:
    print('-1')
else:
    print(b)
a=int(input())
b,c=input().split()
b=int(b)
c=int(c)
l=list(map(int,input().split()))
for i in range(a):
  l[0]==abs(c-(b-l[0]*0.006))
for i in range(a):
  if l[i]==min.l
  print(i)

### FIXED CODE ###

a=int(input())
b,c=input().split()
b=int(b)
c=int(c)
l=list(map(int,input().split()))
for i in range(a):
  l[i]=abs(c-(b-l[i]*0.006))
for i in range(a):
  if l[i]==min(l):
    print(i+1)
import sys

line = sys.stdin.readline()
N = int(line.strip())

F = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        F[i, j] = xs[j]

f = [sum((1 << j) for j in range(10) if F[i,j]) for i in range(N)]

pt = [sum(((i >> j) & 1) for j in range(10)) for i in range(2**10)]

P = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        P[i, j] = xs[j]


ri = -1
rr = -100000

for i in range(1, 2**10):
    r = sum([P[j, pt[f[j] & i]] for j in range(N)])
    if rr < r:
        rr = r
        ri = i

print(rr)


### FIXED CODE ###

import sys

line = sys.stdin.readline()
N = int(line.strip())

F = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        F[i, j] = xs[j]

f = [sum((1 << j) for j in range(10) if F[i,j]) for i in range(N)]

pt = [sum(((i >> j) & 1) for j in range(10)) for i in range(2**10)]

P = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(11):
        P[i, j] = xs[j]


rr = -100000000000000000000

for i in range(1, 2**10):
    r = sum([P[j, pt[f[j] & i]] for j in range(N)])
    if rr < r:
        rr = r

print(rr)
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(10000000)
n,m = map(int,input().split())
p = list(map(int,input().split()))
xy = [list(map(int,input().split())) for _ in range(m)]

Graph = [[] for _ in range(n)]
for x,y in xy:
    Graph[x-1].append(y-1)
    Graph[y-1].append(x-1)

check = [False for _ in range(n)]
def dfs(g,start,c,goal):
    c[start] = True
    if start == goal:
        return True
    for u in g[start]:
        if c[u]:
            continue
        if dfs(g,u,c,goal):
            return True
ans = 0
for i in range(n):
    c = check.copy()
    if dfs(Graph,i,c,p.index(i+1)):
        ans += 1
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3


n,m = map(int,input().split())
p = list(map(int,input().split()))
for i in range(n):
    p[i] -= 1

#連結成分に属するかどうかを見るときはUnion-Findを用いる
#根(属するクラス)を返す関数
def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x]
#同じクラスに属するかどうかを返す関数
def same(x,y):
    return root(x) == root(y)
#木を結合する関数
def union(x,y):
    x = root(x)
    y = root(y)
    #高さの高いほうに低いほうを結合
    if rank[x] < rank[y]:
        par[x] = y#xの親(属するクラス)をyとする
    else:
        par[y] = x
        if rank[x] == rank[y]:#高さが同じ場合
            rank[x] += 1#高さは1つ増える
par = [i for i in range(n)]
rank = [0 for _ in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    #swapできる頂点は同じ木にして同じ連結成分にする
    if not same(x-1,y-1):
        union(x-1,y-1)

ans = 0
for i in range(n):
    #p[i]とiが同じ連結成分ならばans+1
    if root(p[i]) == root(i):
        ans += 1
print(ans)
s = int(input())
a = [s]

for i in range(1, 1000000):
    if a[i-1]%2 == 0:
        tmp = (a[i-1]//2)
    else:
        tmp = (3*a[i-1] + 1)
    
    if a.count(tmp):
        ans = i+1
        break
    else:
        a.append(tmp)
        
print(ans)

### FIXED CODE ###

s = int(input())
a = [s]

for i in range(1, 1000000):
    if a[i-1]%2 == 0:
        tmp = (a[i-1]//2)
    else:
        tmp = (3*a[i-1] + 1)
    
    if a.count(tmp):
        ans = i+1
        break
    else:
        a.append(tmp)
        
print(ans)
n = int(input().split())
if n%2==0:
    print(n)
else:
    print(n * 2)

### FIXED CODE ###

n = int(input())
if n%2==0:
    print(n)
else:
    print(n * 2)
R = input()
print(2*R*3.14159265)

### FIXED CODE ###

R = input()
print(2*int(R)*3.14159265)
import numpy as np
n,s,*a=map(int,open(0).read().split())
mod=998244353
d=np.zeros(s+1,dtype=np.int64)
d[0]=1
for x in a:
	p=d*2
	p[x:]+=d[:s-x+1]
	p%=mod
	d=p
print(d[-1])

### FIXED CODE ###

n,s,*a=map(int,open(0).read().split())
mod=998244353
d=[0]*(s+1)
d[0]=1
for x in a:
	p=[0]*(s+1)
	for i in range(s+1):
		p[i]+=d[i]*2
		if i+x<=s:
			p[i+x]+=d[i]
		p[i]%=mod
	d=p
print(d[-1])
import numpy as np
s = input()
x, y = (int(x) for x in input().split())
Move = []
cnt = 0
s += 'T'
for c in s:
    if c == 'F':
        cnt += 1
    else:
        Move.append(cnt)
        cnt = 0
Move = np.array(Move)
X = Move[Move.index % 2 == 0]
Y = Move[Move.index % 2 == 1]
lenX = len(X)-1
Xmoveable = {X[0] + sum(-X[i+1] if bit & (1<<i) else X[i+1] for i in range(lenX)) for bit in range(2**lenX)}
lenY = len(Y)
Ymoveable = {sum(-Y[i] if bit & (1<<i) else Y[i] for i in range(lenY)) for bit in range(2**lenY)}

if x in Xmoveable and y in Ymoveable:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

from collections import defaultdict
def main():
    S = input() + 'T'
    x, y = map(int, input().split())
    #データ加工
    moveX, moveY = [], []
    if S[0] == 'T': moveX.append(0)
    move ={0:moveX, 1:moveY}
    direct = 0
    step = 0
    for s in S:
        if s == 'T':
            if step > 0:
                move[direct].append(step)
                step = 0
            direct ^= 1 
        else:
            step += 1
    #判定
    if possible(x, moveX[1:], moveX[0]) and possible(y, moveY):
        print('Yes')
    else:
        print('No')


def possible(target, move, offset=0):
    l = len(move)
    dp = [defaultdict(lambda:False) for _ in range(l+1)]
    #初期化
    dp[0][0] = True
    for i,m in enumerate(move):
        for key in dp[i]:
            dp[i+1][key+m] = True
            dp[i+1][key-m] = True
    return dp[l][target-offset]


main()
from fractions import gcd
K = int(input())

ans =  0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans = ans + gcd(i,j,k)

print(ans)


### FIXED CODE ###

from math import gcd
K = int(input())

ans =  0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans = ans + gcd(gcd(i,j),k)

print(ans)