Harryxun/stf_run huggingface dataset:
import sys

input = sys.stdin.readline
N = int(input())

def get_id(i, j):
    if j < i:
        i, j = j, i
    return i * N + j

g = [[] for _ in range(N * N)]
S = []
for i in range(N):
    pre = None
    for j in map(int, input().split()):
        j -= 1
        id_ = get_id(i, j)
        if pre is None:
            S.append(id_)
        else:
            g[pre].append(id_)
        pre = id_


dp = [-1] * (N * N)
visited = [False] * (N * N)
def dfs(v):
    visited[v] = True
    if dp[v] != -1:
        return dp[v]
    for u in g[v]:
        if dp[u] != -1:
            res = dp[u]
        else:
            if visited[u]:
                raise ValueError('find loop!')
            res = dfs(u)
        dp[v] = max(dp[v], res + 1)
    if len(g[v]) == 0:
        dp[v] = 1
    return dp[v]

ans = 0
try:
    for s in S:
        ans = max(ans, dfs(s))
    print(ans)
except ValueError:
    print(-1)


### FIXED CODE ###

import sys

sys.setrecursionlimit(100000)

input = sys.stdin.readline
N = int(input())


def get_id(i, j):
    if j < i:
        i, j = j, i
    return i * N + j


g = [[] for _ in range(N * N)]
S = []
for i in range(N):
    pre = None
    for j in map(int, input().split()):
        j -= 1
        id_ = get_id(i, j)
        if pre is None:
            S.append(id_)
        else:
            g[pre].append(id_)
        pre = id_


dp = [-1] * (N * N)
visited = [False] * (N * N)


def dfs(v):
    visited[v] = True
    if dp[v] != -1:
        return dp[v]
    for u in g[v]:
        if dp[u] != -1:
            res = dp[u]
        else:
            if visited[u]:
                raise ValueError('find loop!')
            res = dfs(u)
        dp[v] = max(dp[v], res + 1)
    if len(g[v]) == 0:
        dp[v] = 1
    return dp[v]


ans = 0
try:
    for s in S:
        ans = max(ans, dfs(s))
    print(ans)
except ValueError:
    print(-1)
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
for i in range(c):
    if(a!=0):
        a-1
    b-1

### FIXED CODE ###

cookies = [int(x) for x in input().split()]
leftOver = cookies[0] - cookies[2]
takahashi = max(0, leftOver)
print(str(takahashi)+ ' ' + (str(cookies[1]) if takahashi > 0  else str(max(0,cookies[1] - abs(leftOver)))))
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def dfs(s,Map,H,W,c):
    dxdy = [(1,0),(-1,0),(0,1),(0,-1),(1,1),(-1,-1),(-1,1),(1,-1)]
    for i in range(len(dxdy)):
        Map[s[0]][s[1]] = c
        nextPos = (s[0]+dxdy[i][0],s[1]+dxdy[i][1])
        if nextPos[0] >= 0 and nextPos[1] >= 0 and nextPos[0] < H and nextPos[1] < W:
            if Map[nextPos[0]][nextPos[1]] == 1:
                dfs(nextPos,Map,H,W,c)

while True:
    W,H = map(int,input().split(" "))
    if W == 0 and H == 0:
        break
    Map = [list(map(int,input().split())) for i in range(0,H)]
    c = 1
    for i in range(H):
        for j in range(W):
            if Map[i][j] == 1:
                c += 1
                dfs((0,0),Map,H,W,c)
    print(c-1)

### FIXED CODE ###

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

import sys
sys.setrecursionlimit(10**6)

def dfs(s,Map,H,W,c):
    dxdy = [(1,0),(-1,0),(0,1),(0,-1),(1,1),(-1,-1),(-1,1),(1,-1)]
    for i in range(len(dxdy)):
        Map[s[0]][s[1]] = c
        nextPos = (s[0]+dxdy[i][0],s[1]+dxdy[i][1])
        if nextPos[0] >= 0 and nextPos[1] >= 0 and nextPos[0] < H and nextPos[1] < W:
            if Map[nextPos[0]][nextPos[1]] == 1:
                dfs(nextPos,Map,H,W,c)

while True:
    W,H = map(int,input().split(" "))
    if W == 0 and H == 0:
        break
    Map = [list(map(int,input().split())) for i in range(0,H)]
    c = 1
    for i in range(H):
        for j in range(W):
            if Map[i][j] == 1:
                c += 1
                dfs((i,j),Map,H,W,c)
    print(c-1)
import math
n1 = int(input())
f1 = [str(input()) for _ in range(n1)]

f2 = sorted(["".join(sorted(list(f1[i]))) for i in range(len(f1))])
f3 = list(map(str, set(f2)))
f4 = [[i for i, e in enumerate(f2) if e == f3[j]] for j in range(len(f3))]
f5 = sum([math.factorial(len(f4[i]))for i in range(len(f4))])/2
print(round(f5))

### FIXED CODE ###

import math
n1 = int(input())
f1 = [str(input()) for _ in range(n1)]

ans_sum = 0
ans_exa = {}

for i in range(len(f1)):
    y1 = "".join(sorted(list(str(f1[i]))))
    if y1 in ans_exa:
        ans_sum = ans_sum + ans_exa[y1]
        ans_exa[y1] = ans_exa[y1] + 1
    else:
         ans_exa[y1] = 1

print(ans_sum)
import sys
az =["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
sum_az = [0 for x in range(26)]

for x in sys.stdin.read().lower()
    for i in range(26):
        for j in range(len(x)):
            if x[j] == az[i]:
                sum_az[i] += 1


for i in range(26):
    print ("%s : %d" % (az[i], sum_az[i]))
                

### FIXED CODE ###

import sys
az =["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
sum_az = [0 for x in range(26)]

for x in sys.stdin.read().lower():
    for i in range(26):
        if x == az[i]:
            sum_az[i] += 1


for i in range(26):
    print ("%s : %d" % (az[i], sum_az[i]))
from bisect import bisect_right

A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]

for x in X:
    # Shrine -> Temple
    idx_s = bisect_right(S, x)
    if abs(S[min(A - 1, idx_s)] - x) > abs(S[max(0, idx_s - 1)] - x):
        x_s = S[max(0, idx_s - 1)]
    else:
        x_s = S[min(A - 1, idx_s)]

    idx_t = bisect_right(T, x_s)
    if abs(T[min(A - 1, idx_t)] - x_s) > abs(T[max(0, idx_t - 1)] - x_s):
        x_t = T[max(0, idx_t - 1)]
    else:
        x_t = T[min(B - 1, idx_t)]

    cand_0 = abs(x_s - x) + abs(x_t - x_s)

    # Temple -> Shrine
    idx_t = bisect_right(T, x)
    if abs(T[min(A - 1, idx_t)] - x) > abs(T[max(0, idx_t - 1)] - x):
        x_t = T[max(0, idx_t - 1)]
    else:
        x_t = T[min(B - 1, idx_t)]

    idx_s = bisect_right(S, x_t)
    if abs(S[min(A - 1, idx_s)] - x_t) > abs(S[max(0, idx_s - 1)] - x_t):
        x_s = S[max(0, idx_s - 1)]
    else:
        x_s = S[min(A - 1, idx_s)]

    cand_1 = abs(x_t - x) + abs(x_s - x_t)

    print(min(cand_0, cand_1))


### FIXED CODE ###

from bisect import bisect_right

A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
x = [int(input()) for _ in range(Q)]

INF = 10 ** 18
s = [-INF] + s + [INF]
t = [-INF] + t + [INF]

for i in range(Q):
    b = bisect_right(s, x[i])
    d = bisect_right(t, x[i])
    res = INF
    for n in [s[b - 1], s[b]]:
        for m in [t[d - 1], t[d]]:
            d1 = abs(n - x[i]) + abs(m - n)
            d2 = abs(m - x[i]) + abs(n - m)
            res = min(res, d1, d2)
    print(res)
import fractions
n,m=map(int,input().split())
s=list(input())
t=list(input())
ans=0
cnt=[""]*(n*m//fractions.gcd(n,m))
d=n*m//fractions.gcd(n,m)
for i in range(n):
    cnt[i*d//n]=s[i]
for j in range(m):
    if t[j]!=cnt[j*d//m] and cnt[j*d//m]!="":
        ans=-1
        break
if ans!=-1:
    print(n*m//fractions.gcd(n,m))
else:
    print(ans)
#print(cnt)

### FIXED CODE ###

import fractions as f
n,m=map(int,input().split())
s=list(input())
t=list(input())
ans=0
N=n//f.gcd(n,m)
M=m//f.gcd(n,m)
for i in range(f.gcd(n,m)):
    if s[i*N]!=t[i*M]:
        ans=-1
        break
if ans!=-1:
    print(n*m//f.gcd(n,m))
else:
    print(-1)
#print(cnt)
def checker(x1,y1,x2,y2,xp,yp):
	r = 0
	vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
	if vec > 0:
		r = 1
		return r
	elif vec < 0:
		r = -1
		return r

if __name__ == '__main__':
	while True:
		try:
			x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
			r = 0
			r += int(checker(x1,y1,x2,y2,xp,yp))
			r += int(checker(x2, y2, x3, y3, xp, yp))
			r += int(checker(x3, y3, x1, y1, xp, yp))
			if r == 3 or r == -3:
				print("YES")
			else:
				print("NO")
		except EOFError:
			break

### FIXED CODE ###

def checker(x1,y1,x2,y2,xp,yp):
	r = 0
	vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
	if vec > 0:
		r = 1
	elif vec < 0:
		r = -1
	return r

if __name__ == '__main__':
	while True:
		try:
			x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
			r = 0
			r += int(checker(x1,y1,x2,y2,xp,yp))
			r += int(checker(x2, y2, x3, y3, xp, yp))
			r += int(checker(x3, y3, x1, y1, xp, yp))
			if r == 3 or r == -3:
				print("YES")
			else:
				print("NO")
		except EOFError:
			break
n=int(input())
v1=map(int,input().split())
v=list(v1)
for i in range(n):
    for j in range(i+1,n):
        if v[i]>v[j]:
            a=v[i]
            v[i]=v[j]
            v[j]=a
for l in range(n-1):
    a=(v[0]+v[1])/2
    v=a+v[2,n-l]
print(v[0])


### FIXED CODE ###

n=int(input())
v1=map(int,input().split())
v=list(v1)
#価値の低いものから順に平均をとっていけばよい
for i in range(n):
    for j in range(i+1,n):
        if v[i]>v[j]:
            a=v[i]
            v[i]=v[j]
            v[j]=a
for l in range(n-1):
    v2=[]
    a=(v[0]+v[1])/2
    v2.append(a)
    v2=v2+v[2:n]
    v=v2
print(v[0])
n,k = map(int,input().split())
l = list(map(int,input()))

l.sort(reverse=True)

sum = 0

for i in range(K):
    sum += l[i]

print(sum)

### FIXED CODE ###

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

l.sort(reverse=True)

sum = 0

for i in range(k):
    sum += l[i]

print(sum)
# -*- coding: utf-8 -*-
N = int(input())
numlist = list(map(int, input().split()))
if 0 < numlist.count(0):
    print('0')
    quit()

total = 1
for i in numlist:
  total *= abs(i)

if 10 ** 18 < total:
  print('-1')
else:
  print(sign * total) 

### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
numlist = list(map(int, input().split()))
if 0 < numlist.count(0):
    print('0')
    quit()

total = 1
for i in numlist:
  total *= i
  if 10 ** 18 < total:
    print('-1')
    quit()

print(total)
import heapq
X, Y, a, b, c = map(int, input().split())
p = list(map(lambda x: -int(x), input().split()))
q = list(map(lambda x: -int(x), input().split()))
r = list(map(lambda x: -int(x), input().split()))

heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

ans = 0
for _ in range(X):
    ap1 = heapq.heappop(p)
    ap2 = heapq.heappop(r)
    if ap1 <= ap2:
        ans -= ap1
        heapq.heappush(r, ap2)
    else:
        ans -= ap2
        heapq.heappush(p, ap1)

for _ in range(Y):
    ap1 = heapq.heappop(q)
    ap2 = heapq.heappop(r)
    if ap1 <= ap2:
        ans -= ap1
        heapq.heappush(r, ap2)
    else:
        ans -= ap2
        heapq.heappush(q, ap1)

print(ans)

### FIXED CODE ###

import heapq
X, Y, a, b, c = map(int, input().split())
p = list(map(lambda x: -int(x), input().split()))
q = list(map(lambda x: -int(x), input().split()))
r = list(map(lambda x: -int(x), input().split()))
p.sort()
q.sort()
t = p[:X] + q[:Y] + r

heapq.heapify(t)

ans = 0
for _ in range(X+Y):
    ap = heapq.heappop(t)
    ans -= ap

print(ans)
s=input()
x,y=map(int,input().split())
ss=[len(i) for i in s.split("T")]
x-=ss[0]
a=[]
b=[]
for i in range(1,len(ss)):
  if ss[i]==0:continue
  if i%2==1:b.append(ss[i])
  else:a.append(ss[i])
x=abs(x)
y=abs(y)
a.sort()
b.sort()
def check(n,a):
  dp=[[0]*16001 for _ in range(len(a)+1)]
  n+=8000
  dp[0][8000]=1
  for i in range(1,len(a)+1):
    for j in range(16001):
      if j+a[i-1]<=16000:dp[i][j+a[i-1]]|=dp[i-1][j]
      if j-a[i-1]>=0:dp[i][j-a[i-1]]|=dp[i-1][j]
  if dp[len(a)][n]==1:return True
  return False
if check(x,a) and check(y,b):print("Yes")
else:print("No") 

### FIXED CODE ###

s=input()
x,y=map(int,input().split())
ss=[len(i) for i in s.split("T")]
x-=ss[0]
a=[]
b=[]
for i in range(1,len(ss)):
  if ss[i]==0:continue
  if i%2==1:b.append(ss[i])
  else:a.append(ss[i])
x=abs(x)
y=abs(y)
if max(x,y)>8000:exit(print("No"))
def check(n,a):
  dp=[[0]*20001 for _ in range(len(a)+1)]
  n+=10000
  dp[0][10000]=1
  for i in range(1,len(a)+1):
    for j in range(20001):
      if j+a[i-1]<=20000:dp[i][j+a[i-1]]|=dp[i-1][j]
      if j-a[i-1]>=0:dp[i][j-a[i-1]]|=dp[i-1][j]
  if dp[len(a)][n]==1:return True
  return False
if check(x,a) and check(y,b):print("Yes")
else:print("No")
a = []
for j in range(3):
    a.append([int(x) for x in input().split()])
n = int(input())
b = [int(input()) for i in range(n)]
def hasbingo(ps):
    for x, y in ps:
        if a[y][x] not in b:
            return False
    return True

def hasany():
    for i in range(3):
        if hasbingo([(i, 0),(i, 1),(i, 2)]):
            return True
        if hasbingo([(0, i), (1, i), (2, i)]):
            return True
    if hasbingo([[0,0],[1,1],[2,2]]):
        return True
    return hasbingo([[0,2],[1,1][2,0]])

if hasany():
    print('Yes')
else:
    print('No')



### FIXED CODE ###

a = []
for j in range(3):
    a.append([int(x) for x in input().split()])
n = int(input())
b = [int(input()) for i in range(n)]
def hasbingo(ps):
    for x, y in ps:
        if a[y][x] not in b:
            return False
    return True

def hasany():
    for i in range(3):
        if hasbingo([(i, 0),(i, 1),(i, 2)]):
            return True
        if hasbingo([(0, i), (1, i), (2, i)]):
            return True
    if hasbingo([(0,0),(1,1),(2,2)]):
        return True
    return hasbingo([(0,2),(1,1), (2,0)])

if hasany():
    print('Yes')
else:
    print('No')
import collections
w, h, x, y = map(int, input().split())
area = []
# xの直線
area.append(min(h*x, h*(w-x)))

# yの直線
area.append(min(w*y, w*(h-y)))

# 角たち
a = w * h
tmp = h**2 * x / y
area.append(min(tmp, a - tmp))
tmp = w**2 * y / x
area.append(min(tmp, a - tmp))

ans_c = collections.Counter(area)

ans = sorted(ans_c.items(), reverse=True)[0]
size = ans[0]
a = 0
if ans[1] > 1:
    a = 1

print("{} {}".format(size, a))

### FIXED CODE ###

import collections
w, h, x, y = map(int, input().split())

ans = 0
if x + x == w and y + y == h:
    ans = 1

print("{} {}".format(w * h / 2, ans))
def resolve():
    N,M=map(int,input().split())
    if N==1 or M==1:
        print(N*M-2)
    else:
        print((N-2)*(M-2))

resolve()

### FIXED CODE ###

def resolve():
    N=int(input())
    A=list(map(int,input().split()))
    A=[0]+A+[0]
    total=sum([abs(A[i+1]-A[i]) for i in range(N+ 1)])

    for i in range(N):
        print(total-(abs(A[i+1]-A[i])+abs(A[i+2]-A[i+1]))+abs(A[i+2]-A[i]))



resolve()
N=input()
if N%2==0:
  answer = 1.0/2
else:
  answer = ((N-1)/2 + 1) /((N-1)/2)
return answer
 

### FIXED CODE ###

N=int(input())
if N%2==0:
  answer = 1.0/2
else:
  answer = ((N-1)/2 + 1) /N
print(answer)
if N[0] == "7" or N[1] == "7" or N[2] == "7" : print ("yes")
else:print ("no")

### FIXED CODE ###

N = input()
if N[0] == "7" or N[1] == "7" or N[2] == "7" : print ("Yes")
else:print ("No")
N, M, K = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
ans_a =0
ans_b =0
time =0

for i in range(N):
    if time + arr_a[i] > K:
        break
    else:
        ans_a +=1
        time += arr_a[i]
for i in range(M):
    if time + arr_b[i] > K:
        break
    else:
        ans_b +=1
        time += arr_b[i]

ans = ans_a + ans_b
ans_koho = ans_a + ans_b
cnt_b = ans_b

for i in range(ans_a):
    ans_koho -= 1
    time -= arr_a[-1*(i+1)]

    while True:
        if cnt_b == M:
            break
        elif time + arr_b[cnt_b] > K:
            break
        else:
            time += B[cnt_b]
            cnt_b += 1
            ans_koho += 1
    ans = max(ans, ans_koho)

print(ans)



### FIXED CODE ###

N, M, K = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
ans_a =0
ans_b =0
time =0

for i in range(N):
    if time + arr_a[i] > K:
        break
    else:
        ans_a +=1
        time += arr_a[i]
for i in range(M):
    if time + arr_b[i] > K:
        break
    else:
        ans_b +=1
        time += arr_b[i]

ans = ans_a + ans_b
ans_koho = ans_a + ans_b
cnt_b = ans_b

for i in range(ans_a):
    ans_koho -= 1
    time -= arr_a[ans_a-i-1]

    while True:
        if cnt_b == M:
            break
        elif time + arr_b[cnt_b] > K:
            break
        else:
            time += arr_b[cnt_b]
            cnt_b += 1
            ans_koho += 1
    ans = max(ans, ans_koho)

print(ans)
import math
N = int(input())
print(math.factrial(N) % (10**9+7))

### FIXED CODE ###

N = int(input())
n = N//15
print(N*800-n*200)
import sys

w = sys.stdin.readline().rstrip().lower()
cnt = 0
while True:
    lines = sys.stdin.readline().rstrip()
    if not lines:
		break	
    words = lines.split( " " )
    for i in range( len( words ) ):
    	if w == words[i].lower():
			cnt = cnt + 1	

print( cnt )

### FIXED CODE ###

import sys

w = sys.stdin.readline().rstrip().lower()
cnt = 0
while True:
	lines = sys.stdin.readline().rstrip()
	if not lines:
		break
	for s in lines.split( " " ):
		if w == s.lower():
			cnt = cnt + 1	

print( cnt )
print((input() / 3.0)**3)

### FIXED CODE ###

print((float(input()) / 3.0)**3)
import math
n, X = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
x = [abs(X-i) for i in x]
c = x[0]
for i in range(1, n):
    gc = math.gcd(c, x[i])
    if c <= gc:
        continue
    else:
        c = gc
print(c)

### FIXED CODE ###

n, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x = sorted(x)
y = [x[i+1]-x[i] for i in range(n)]

def eu(a, b):
    a, b = sorted([a,b])
    while a != 0:
        b, a = a, b%a
    return b
d = y[0]
for i in range(1, n):
    d = eu(d, y[i])
print(d)
N = int(input())
F = []

for _ in range(N):
    F.append(list(map(int, input().split())))

P = []

for _ in range(N):
    P.append(list(map(int, input().split())))

c = [0] * 10
ans = - float('inf')
tmp = 0

for i in range(1, 1024):
    ii = format(i, 'b')
    ii = str(ii)
    ii = ii.zfill(10)
    ii = list(ii)
    for j in range(N):
        for k in range(10):
            if str(F[j][k]) == ii[k] and ii[k] == '1':
                c[j] += 1
    for j in range(N):
        tmp += P[j][c[j]]
    if tmp > ans:
        ans = tmp
    tmp = 0
    c = [0] * 10

print(ans)

### FIXED CODE ###

N = int(input())
F = []
P = []
for _ in range(N):
    F.append(list(map(int, input().split())))
for _ in range(N):
    P.append(list(map(int, input().split())))

ans = -1000000000


for i in range(1, 1024):
    tmp = 0
    c = [0] * N
    ii = list(str(format(i, 'b')).zfill(10))
    for j in range(N):
        for k in range(10):
            if str(F[j][k]) == ii[k] and ii[k] == '1':
                c[j] += 1
    for j in range(N):
        tmp += P[j][c[j]]
    if tmp > ans :
        ans = tmp

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

def main():
    N = int(input())
    X = [None] * N
    l = list(input())
    Xc = 0
    for i in range(N):
        X[i] = int(l[i])
        Xc += X[i]

    ans1 = 0
    ans2 = 0
    for j in range(N):
        if X[j]==1:
            ans1 += pow(2,N-1-j,Xc+1)
            ans2 += pow(2,N-1-j,Xc-1)
    ans1 %= Xc+1
    ans2 %= Xc-1

    for i in range(N):
        if X[i]==0:# 0->1
            ans = (ans1 + pow(2,N-1-i)) % (Xc+1)
        else:# 1-> 0
            ans = (ans2 - pow(2,N-1-i)) % (Xc-1)
        count = 1
        while ans > 0:
            tmp = str(bin(ans)).count('1')
            ans %= tmp
            count += 1
        print(count)

if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3

def main():
    N = int(input())
    X = [None] * N
    l = list(input())
    Xc = 0
    for i in range(N):
        X[i] = int(l[i])
        Xc += X[i]

    if Xc == 0:
        [print(1) for i in range(N)]
    elif Xc == 1:
        d = X.index(1)
        ans1 = 0
        for j in range(N):
            if X[j]:
                ans1 += pow(2,N-1-j,Xc+1)
                ans1 %= Xc+1

        for j in range(N):
            if d == j:
                print(0)
            else:
                if d == N-1 or j == N-1:
                    print(2)
                else:
                    print(1)
    else:
        ans1 = 0
        ans2 = 0
        for j in range(N):
            if X[j]:
                ans1 += pow(2,N-1-j,Xc+1)
                ans1 %= Xc+1
                ans2 += pow(2,N-1-j,Xc-1)
                ans2 %= Xc-1

        for i in range(N):
            if X[i]:# 1->0
                ans = (ans2 - pow(2,N-1-i,Xc-1)) % (Xc-1)
            else:# 0->1
                ans = (ans1 + pow(2,N-1-i,Xc+1)) % (Xc+1)
            count = 1
            while ans > 0:
                tmp = str(bin(ans)).count('1')
                ans %= tmp
                count += 1
            print(count)

if __name__ == "__main__":
    main()
n = int(input())
a = list(map(int, input().split()))
a.reverse()
print(' '.join(a))


### FIXED CODE ###

n = int(input())
a = list(input().split())
a.reverse()
print(' '.join(a))
from sys import stdin, exit
from math import factorial, gcd
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

n = int(input())
arr = lmi()
for i in range(1, n):
    arr[i] = gcd(arr[i], arr[i-1])
print(arr[n-1])

### FIXED CODE ###

from sys import stdin
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)


n = int(input())
arr = lmi()
for i in range(1, n):
    arr[i] = gcd(arr[i], arr[i-1])
print(arr[n-1])
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  int n,k;
  string s;
  cin >> n >> s >> k;
  
  for(int i=0;i<n;i++){
    if(s[k-1]!=s[i]){
      s[i] = '*';
  }
  }
  cout << s << endl;
  return 0;
}

### FIXED CODE ###

n=int(input())
s=input()
char_list=list(s)
k=int(input())
for i in range(n):
	if(char_list[k-1]!=char_list[i]):
  		char_list[i] = "*"
str = ''.join(char_list)
print(str)
A,B,C,D = map(int, input().split())

print('Left' if A+B > C+D else 'Balanced' A+B == C+D else 'Right')

### FIXED CODE ###

A, B, C, D = map(int, input().split())
print("Left" if A+B > C+D else "Balanced" if A+B == C+D else "Right")
h,n = map(int,input().split())
L = []
for i in range(n):
  l = list(map(int,input().split()))
  L.append(l)
dp = [10**8]*10001
dp[0] = 0
for i in range(n):
  dp[L[i][0]] = L[i][1]
for i in range(10001):
  for j in range(n):
    if i-L[j][0] >= 0:
      dp[i] = min(dp[i],dp[i-L[j][0]]+L[j][1])
for i in range(9999,-1,-1):
  if dp[i] == 10**8:
    dp[i] = dp[i+1]
print(dp[h])


### FIXED CODE ###

h,a = map(int,input().split())
if h%a == 0:
  print(h//a)
else:
  print(h//a+1)
N = int(input())
flg = True
now,posx,posy=0,0,0
while flg==True:
  t,x,y=map(int,input().split())
  if abs(x-posx)+abs(y-posy) > (t-now):
    flg = False
    print('No')
  elif (t-now)%2==0 and ((abs(x-posx)+abs(y-posy))%2 ==1):
    flg =False
    print('No')
  elif (t-now)%2==1 and ((abs(x-posx)+abs(y-posy))%2 ==0):
    flg =False
    print('No')
  else:
    now = t
    posx = x
    posy = y
if flg:
  print('Yes')

### FIXED CODE ###

N = int(input())
flg = True
cnt,now,posx,posy=0,0,0,0
while cnt < N and flg:
  t,x,y=map(int,input().split())
  if abs(x-posx)+abs(y-posy) > (t-now):
    flg = False
    print('No')
  elif (t-now)%2==0 and ((abs(x-posx)+abs(y-posy))%2 ==1):
    flg =False
    print('No')
  elif (t-now)%2==1 and ((abs(x-posx)+abs(y-posy))%2 ==0):
    flg =False
    print('No')
  else:
    now = t
    posx = x
    posy = y
    cnt += 1
if flg:
  print('Yes')