Harryxun/stf_run huggingface dataset:
import collections, sys
sys.setrecursionlimit(10**5 + 5)
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
    win_lose[win].add(lose)

memo = [-1] * (N + 1)


def rec(x):
    if memo[x] == -1:
        if win_lose[x] == set():
            memo[x] = 0
        else:
            memo[x] = max(rec(y) for y in win_lose[x]) + len(win_lose[x])
    return memo[x]


print(
    max(a + b for a, b in zip(
        sorted(rec(x) for x in win_lose[1])[::-1], range(1, N + 1))))


### FIXED CODE ###

import collections
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
    win_lose[win].add(lose)

s1 = [1]
s2 = []
while s1:
    a = s1.pop()
    s2 += [a]
    for b in win_lose[a]:
        s1 += [b]
memo = [0] * (N + 1)
for x in s2[::-1]:
    if win_lose[x] == set():
        memo[x] = 0
    else:
        memo[x] = max(a + b for a, b in zip(
            sorted(memo[y] for y in win_lose[x])[::-1], range(1, N + 1)))
print(memo[1])
R,G,B = map(int,input().split())
K = int(input())
ans = 'No'

while (K > 0):
  if R >= G:
    G *= 2
    K -= 1
  elif G >= B:
    B *= 2
    K -= 1
  else:
    k -= 1
      
if R < G < B:
  ans = 'Yes'
  
print(ans)

### FIXED CODE ###

R,G,B = map(int,input().split())
K = int(input())
ans = 'No'

while (K > 0):
  if R >= G:
    G *= 2
    K -= 1
  elif G >= B:
    B *= 2
    K -= 1
  else:
    K -= 1
      
if R < G < B:
  ans = 'Yes'
  
print(ans)
# sys.setrecursionlimit(100000)
n,a,b = map(int,input().split())
mod = 10**9+7
count = 0
def cmb(n,r):
  if n == 0 or n == r: return 1
  if r == 1: return n
  return cmb(n-1,r) + cmb (n-1,r-1)
for i in range(1,n+1):
  if i != a and i != b:
    count += cmb(n,i)
print(count % mod)

### FIXED CODE ###

def pow(a,b,c):
    ans = 1
    while b > 0:
        if b & 1:
            ans = ans*a % c
        a = a*a % c
        b = b >> 1
    return ans
def cmb(a,b,c):
    b = min(b,a-b)
    num = 1
    for i in range(b):
        num = num*(n-i) % c
    den = 1
    for i in range(b):
        den = den*(i+1) % c
    return num*pow(den,c-2,c) % c
mod = 10**9+7
n,a,b = map(int,input().split())
ans  = (pow(2,n,mod)-cmb(n,a,mod)-cmb(n,b,mod)-1) % mod
if ans < 0:
    ans = ans + mod
print(ans)
import sys
#import numpy as np
#from collections import defaultdict
import math
#from collections import deque

input = sys.stdin.readline
#import numpy as np



def main():

    N,W = map(int,input().split())

    dp = [0] * (W+2)

    for _ in range(N):
        w,v = map(int,input().split())

        for j in range(W+1,w-1,-1):
            dp[j] =max(dp[j-w] +v ,dp[j])

    print(dp[W])
#    print(dp)




if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import bisect


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, W = map(int, input().split())
    vsup = 10 ** 3 * N + 2
    dp = [10 ** 12 + 1] * (vsup)  # 価値の総和を i (以上にするための重さの最小値
    dp[0] = 0

    for i in range(N):
        w, v = map(int, input().split())
        for j in range(vsup-2, -1, -1):
            if j - v >= 0:
                dp[j] = min(dp[j], dp[j - v] + w)
            dp[j] = min(dp[j],dp[j+1])

    print(bisect.bisect_right(dp,W)-1)

if __name__ == "__main__":
    main()
import sys
lines = sys.stdin.readlines()
K, N = map(int, lines[0].strip().split())
As = map(int, lines[1].strip().split())
dists = []
for base, switch in zip(As[:-1], As[1:]):
  dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))

### FIXED CODE ###

K, N = list(map(int, input().split()))
As = list(map(int, input().split()))
dists = []
for base, switch in zip(As[:-1], As[1:]):
    dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))
S=set(x for x in input())
if len(S)==4:
  print('Yes')
elif lens(S)==2:
  if 'W' in S and 'E' in S:
    print('Yes')
  elif 'N' in S and 'S' in S:
    print('Yes')
  else:
    print('No')
else:
  print('No')  

### FIXED CODE ###

S=set(x for x in input())
if len(S)==4:
  print('Yes')
elif len(S)==2:
  if 'W' in S and 'E' in S:
    print('Yes')
  elif 'N' in S and 'S' in S:
    print('Yes')
  else:
    print('No')
else:
  print('No')
n,k,q = map(int,input().split())
a = [] # 順番
for _ in range(q):
    a.append(int(input()))


point = [k] * n


for win in a:         # 勝った人(a[win-1])以外を下げる
    point[win-1] += 1
    for i in range(n):
        point[i] -= 1
#        print(point)

#print(point)


for i in point:
    if i <= 0:
        print("No")
    elif i >= 1:
        print("Yes")



### FIXED CODE ###

s=input()

if s == "Sunny":
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
elif s == "Rainy":
    print("Sunny")
if snacks_num % persons == 0:
    print(0)
else:
    print(1)

### FIXED CODE ###

snacks_num, persons = map(int, input().split())

if snacks_num % persons == 0:
    print(0)
else:
    print(1)
A,B=map(int,input().split())
if A==B:
  print("Draw")
elif A==1:
  print("Alice")
elif B==1:
  print(Bob)
elif A>B:
  print("Alice")
else:
  print("Bob")
  

### FIXED CODE ###

A,B=map(int,input().split())
if A==B:
  print("Draw")
elif A==1:
  print("Alice")
elif B==1:
  print("Bob")
elif A>B:
  print("Alice")
else:
  print("Bob")
weather = ["Sunny", "Cloudy", "Rainy"]
s = input()

print(weather[weather.index(s) + 1])

### FIXED CODE ###

weather = ["Sunny", "Cloudy", "Rainy"]
s = input()
next = weather.index(s) + 1

if next >= len(weather):
  print(weather[0])
else:
  print(weather[next])
N = int(input())
m = N % 10
if m == 2 or m == 4 or m == 5 or m == 7 or　m == 9:
  ret = 'hon'
elif m == 0 or m == 1 or m == 6 or m == 8:
  ret = 'pon'
else:
  ret = 'bon'
  
print(ret)

### FIXED CODE ###

N = int(input())
m = N % 10
if m == 2 or m == 4 or m == 5 or m == 7 or m == 9:
  ret = 'hon'
elif m == 0 or m == 1 or m == 6 or m == 8:
  ret = 'pon'
else:
  ret = 'bon'
  
print(ret)
k = int(input())
s = input()
if len(s)>k:
    print(s[0:k],"...")
else:
    print(s)


### FIXED CODE ###

import numpy as np
a = int(input())
b = a % 10
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
if b in hon:
    print("hon")
elif b in pon:
    print("pon")
else:
    print("bon")
if S == 'SUN':
    print(7)
elif S == 'MON':
    print(1)
elif S == 'TUE':
    print(2)
elif S == 'WED':
    print(3)
elif S == 'THU':
    print(4)
elif S == 'FRI':
    print(5)
elif S == 'SAT':
    print(6)


### FIXED CODE ###

S = input()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)
s = input()
t = input()

dp = [[0]*(1+len(s)) for i in range(1+len(t))]

for i in range(1, 1+len(t)):
    for j in range(1, 1+len(s)):
        if s[j-1] == t[i-1]:
            dp[i][j] = 1+dp[i-1][j-1]
            st += s[j-1]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

i = len(t)
j = len(s)
st = ""

while dp[i][j] != 0:
    if s[j-1] == t[i-1]:
        st += s[j-1]
        i -= 1
        j -= 1
    else:
        if dp[i][j-1] > dp[i-1][j]:
            j -= 1
        else:
            i -= 1
            
print(st[::-1])

### FIXED CODE ###

s = input()
t = input()

dp = [[0]*(1+len(s)) for i in range(1+len(t))]

for i in range(1, 1+len(t)):
    for j in range(1, 1+len(s)):
        if s[j-1] == t[i-1]:
            dp[i][j] = 1+dp[i-1][j-1]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

i = len(t)
j = len(s)
st = ""

while dp[i][j] != 0:
    if s[j-1] == t[i-1]:
        st += s[j-1]
        i -= 1
        j -= 1
    else:
        if dp[i][j-1] > dp[i-1][j]:
            j -= 1
        else:
            i -= 1
            
print(st[::-1])
n = input()
ans = []
for i in n:
    if i == '1':
        ans.append('9')
    elif i == '9':
        ans append('1')
    else:
        ans.append(i)
print(''.join(ans))

### FIXED CODE ###

n = input()
ans = []
for i in n:
    if i == '1':
        ans.append('9')
    elif i == '9':
        ans.append('1')
    else:
        ans.append(i)
print(''.join(ans))
import math

A,B,C,D=map(int,input().split())

c1=B//C
c2=(A-1)//C

cd1=B//((C*D)/math.gcd(C,D))
cd2=(A-1)//((C*D)/math.gcd(C,D))

d1=B//D
d2=(A-1)//D


print(int(B-A+1-(c1-c2)-(d1-d2)+(cd1-cd2)))

### FIXED CODE ###

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

A,B,C,D=map(int,input().split())

c1=B//C
c2=(A-1)//C

cd1=B//((C*D)//gcd(C,D))
cd2=(A-1)//((C*D)//gcd(C,D))

d1=B//D
d2=(A-1)//D


print(str(int(B-A+1-(c1-c2)-(d1-d2)+(cd1-cd2))))
a=int(input())
b=input.split(' ')
m=0
s=0
while m<a:
    s=s+int(b[m])
    m=m+1
if s<10**18:
    print(-1)
else:
    print(s)


### FIXED CODE ###

a=int(input())
b=input().split(' ')
m=0
s=1
i=0
o=0
while i<a:
    if int(b[i])==0:
        print(0)
        o=o+1
    i=i+1
while m<a and o==0:
    s=s*int(b[m])
    m=m+1
    if s>10**18 and o==0:
        print(-1)
        o=o+1
        break

if o==0:
    print(s)
# -*- coding: utf-8 -*-
def seki(a,b):
    if a*b%2==1:
        return "Even"
    else:
        return "Odd"

a,b=input()
print(seki(a,b))

### FIXED CODE ###

# -*- coding: utf-8 -*-
def seki(a,b):
    if a*b%2==1:
        return "Odd"
    else:
        return "Even"

a,b=map(int,input().split())
print(seki(a,b))
ST = split.input()
print(ST[1] + ST[0], sep = "")

### FIXED CODE ###

ST = input().split()
print(ST[1] + ST[0], sep = "")
n, tracks = list(map(int, input().split()))
loads = []
for _ in range(n):
    loads.append(int(input()))

# print(loads)
slices = []


def slicing(rest, s):
    if not rest:
        slices.append(s+[(s[-1][1], len(loads))])
        return

    first = len(s) and s[-1][1]
    for s1 in range(first+1, len(loads)-rest+1):
        slicing(rest-1, s+[(first, s1)])


slicing(tracks-1, [])
# print(slices)


def load_count_max(load):
    # print(load, max(sum(loads[l[0]: l[1]]) for l in load))
    return max(sum(loads[l[0]: l[1]]) for l in load)


result = min(map(load_count_max, slices))
print(result)



### FIXED CODE ###

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


def check(p):
    i = 0
    for j in range(k):
        s = 0
        while s + T[i] <= p:
            s += T[i]
            i += 1
            if i == n:
                return n
    return i


def solve():
    left = 0
    right = 100000 * 10000
    while right - left > 1:
        mid = (left + right) // 2
        v = check(mid)
        if v >= n:
            right = mid
        else:
            left = mid
    return right


T = []
for _ in range(n):
    T.append(int(input()))
ans = solve()
print(ans)
N = int(input())
A = sorted([int(input()) for _ in range(N)])

print(A[N-1] - A[0])

### FIXED CODE ###

N = int(input())
A = sorted(map(int, input().split()))

print(A[N-1] - A[0])
s = input()

x = []
for i in range(len(s) - 2):
    x.append(abs(int(x[i:i+3]) - 753))
    
print(min(x))

### FIXED CODE ###

s = list(str(input()))
m = []
for i in range(len(s)-2):
    x = s[i:i+3]
    a = 0
    a = int("".join(x))
    x = s
    m.append(abs(753-a))
print(min(m))
dishes = [input() for _ in range(5)]

sum_dishes = 0
last_dish = 0
last_tmp = 0
for idx, dish in enumerate(dishes):
    tmp = 10 - int(dish[-1])
    dish = int(dish)
    if tmp == 10:
        sum_dishes += dish
    elif tmp > last_tmp:
        sum_dishes += last_dish + last_tmp
        last_dish = dish
        last_tmp = tmp
        last_idx = idx
    else:
        sum_dishes += dish + tmp

print(sum_dishes + int(dishes[last_idx]))


### FIXED CODE ###

dishes = [input() for _ in range(5)]


def tanuki(dishes):
    if all([i[-1] == '0' for i in dishes]):
        return sum([int(i) for i in dishes])

    sum_dishes = 0
    last_dish = 0
    last_tmp = 0
    for idx, dish in enumerate(dishes):
        tmp = 10 - int(dish[-1])
        dish = int(dish)
        if tmp == 10:
            sum_dishes += dish
        elif tmp > last_tmp:
            sum_dishes += last_dish + last_tmp
            last_dish = dish
            last_tmp = tmp
            last_idx = idx
        else:
            sum_dishes += dish + tmp
    return sum_dishes + int(dishes[last_idx])


print(tanuki(dishes))
list=map(int,input().split())
for i in range(5):
	if list[i]==0:
		print(i)


### FIXED CODE ###

list=list(map(int,input().split()))
for i in range(5):
	if list[i]==0:
		print(i+1)
A,B,C,D = map(int,input().split())
 
cList = []
 
dList = []
 
numList = []
 
supC = (B // C)
infC = (A // C)
 
supD = (B // D)
infD = (A // D)
 
for i in range(A,B+1):
	numList.append(i)
 
 
for i in range(infC,supC+1):
	cList.append(i * C)
 
for i in range(infD,supD+1):
	dList.append(i * D)
	
numList = len(set(numList) - set(cList) - set(dList))
 
print(numList)
A,B,C,D = map(int,input().split())

cList = []

dList = []

numList = []

supC = (B // C)
infC = (A // C)

supD = (B // D)
infD = (A // D)

for i in range(A,B+1):
	numList.append(i)


for i in range(infC,supC+1):
	cList.append(i * C)

for i in range(infD,supD+1):
	dList.append(i * D)
	
numList = len(set(numList) - set(cList) - set(dList))

print(numList)

### FIXED CODE ###

L = input()

for i in range(0,len(L)-1):
	if L[i] == L[i+1]:
		print("Bad")
		break
else:print("Good")
from scipy import special

N,M = map(int,input().split())

if N == 1:
    c1 = 0
else:
    c1 = special.comb(N, 2)

if M == 1:
    c2 = 0
else:
    c2 = special.comb(M, 2)

c3 = c1 + c2
print(c3)

### FIXED CODE ###

import itertools

N,M = map(int,input().split())

if N == 1:
    c1 = 0
else:
    c1 = len(list(itertools.combinations(range(N), 2)))

if M == 1:
    c2 = 0
else:
    c2 = len(list(itertools.combinations(range(M), 2)))

c3 = c1 + c2
print(c3)
n,m = map(int,input().split())
H = [[0 for _ in range(n)] for _ in range(n) ]

for _ in range(m):
    a, b = map(int,input().split())
    edge_list.append([a-1,b-1])
    H[a-1][b-1] = 1
    H[b-1][a-1] = 1
    
l = [0 for _ in range(n)]
ans = 0

def dfs(node,visited):
    global ans
    if visited.count(0) == 0:
        ans += 1 
        return 0
    else:
        visited[node] = 1
        for node_,edge_ in enumerate(H[node]):
            if edge_ == 1 and visited[node_] != 1:
                visited[node_] = 1
                visited[node] = 1
                dfs(node_,visited)
                visited[node_] = 0

dfs(0,l)
print(ans)

### FIXED CODE ###

#!/usr/bin/python
# -*- Coding: utf-8 -*-
n,m = map(int,input().split())

H = [[0 for _ in range(n)] for _ in range(n) ]

edge_list = []

for _ in range(m):
    a, b = map(int,input().split())
    edge_list.append([a-1,b-1])
    H[a-1][b-1] = 1
    H[b-1][a-1] = 1
    
l = [0 for _ in range(n)]
ans = 0
l[0] = 1

def dfs(node,x):
    global ans
    if x.count(0) == 0:
        ans += 1 
        return 0


    else:
        visited = x
        visited[node] = 1
        for node_,edge_ in enumerate(H[node]):
            if edge_ == 1 and visited[node_] != 1:
                visited[node_] = 1
                visited[node] = 1
                dfs(node_,visited)
                visited[node_] = 0
                #頂点iをここで未訪問にすることが一番重要！！！！！



dfs(0,l)
print(ans)
import sys
from decimal import Decimal

def main():
    for input_line in sys.stdin:
        input_line = raw_input()
        x1 = int(input_line.split(' ')[0])
        y1 = int(input_line.split(' ')[1])
        p = int(input_line.split(' ')[2])
        x2 = int(input_line.split(' ')[3])
        y2 = int(input_line.split(' ')[4])
        q = int(input_line.split(' ')[5])
        multiplicand1, multiplicand2 = calculate1(x1, x2)
        after_y1, after_y2, after_p, after_q = calculate2(y1, y2, p, q, multiplicand1, multiplicand2)
        calculate3(after_y1, after_y2, after_p, after_q, x1, y1, p)
    
def calculate1(x1, x2):
    if (x1 >= 0 and x2 >= 0) or (x1 < 0 and x2 < 0):
        multiplicand1 = -x2
        multiplicand2 = x1
        return multiplicand1, multiplicand2
    else:
        multiplicand1 = abs(x2)
        multiplicand2 = abs(x1)
        return multiplicand1, multiplicand2
    
def calculate2(y1, y2, p, q, multiplicand1, multiplicand2):
    after_y1 = Decimal(y1 * multiplicand1)
    after_y2 = Decimal(y2 * multiplicand2)
    after_p = Decimal(p * multiplicand1)
    after_q = Decimal(q * multiplicand2)
    return after_y1, after_y2, after_p, after_q

def calculate3(after_y1, after_y2, after_p, after_q, x1, y1, p):
    y = Decimal(after_p + after_q) / Decimal(after_y1 + after_y2)
    y = round(y, 3)
    x = Decimal(p - y1 * y) / Decimal(x1)
    x = round(x, 3)
    print('%.3f %.3f' % (x, y))
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from decimal import Decimal

def main():
    for input_line in sys.stdin:
        x1 = int(input_line.split(' ')[0])
        y1 = int(input_line.split(' ')[1])
        p = int(input_line.split(' ')[2])
        x2 = int(input_line.split(' ')[3])
        y2 = int(input_line.split(' ')[4])
        q = int(input_line.split(' ')[5])
        multiplicand1, multiplicand2 = calculate1(x1, x2)
        after_y1, after_y2, after_p, after_q = calculate2(y1, y2, p, q, multiplicand1, multiplicand2)
        calculate3(after_y1, after_y2, after_p, after_q, x1, y1, p)
    
def calculate1(x1, x2):
    if (x1 >= 0 and x2 >= 0) or (x1 < 0 and x2 < 0):
        multiplicand1 = -x2
        multiplicand2 = x1
        return multiplicand1, multiplicand2
    else:
        multiplicand1 = abs(x2)
        multiplicand2 = abs(x1)
        return multiplicand1, multiplicand2
    
def calculate2(y1, y2, p, q, multiplicand1, multiplicand2):
    after_y1 = Decimal(y1 * multiplicand1)
    after_y2 = Decimal(y2 * multiplicand2)
    after_p = Decimal(p * multiplicand1)
    after_q = Decimal(q * multiplicand2)
    return after_y1, after_y2, after_p, after_q

def calculate3(after_y1, after_y2, after_p, after_q, x1, y1, p):
    y = Decimal(after_p + after_q) / Decimal(after_y1 + after_y2)
    y = round(y, 3)
    x = Decimal(p - y1 * y) / Decimal(x1)
    x = round(x, 3)
    print('%.3f %.3f' % (x, y))
    
if __name__ == '__main__':
    main()
print("No War" if (lambda a:max(a[0][2],max(a[1]))<min(a[0][3],min(a[2])))([int(j) for j in input().split()] for i in range(3)]) else "War")

### FIXED CODE ###

print("No War" if (lambda a:max(a[2],max(list(map(int,input().split()))))<min(a[3],min(list(map(int,input().split())))))(list(map(int,input().split()))) else "War")
import sys

nums = map(int, sys.stdin.readline().strip().split())
print " ".join(sorted(nums, reverse=True))

### FIXED CODE ###

import sys

nums = map(int, sys.stdin.readline().strip().split())

print " ".join(map(str,sorted(nums)))
import sys

input_line = sys.stdin.readline()
    
ch=['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']

sl=input_line.lower()

for c in ch:
    print("{} : {}".format(c,s.count(c)))

### FIXED CODE ###

s = ""
while True:
    try:
        sent = input()
    except:
        break
    s += sent
    
ch=['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']

sl=s.lower()

for c in ch:
    cnt=sl.count(c)
    print("{} : {}".format(c,cnt))
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
import numpy as np

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

N,M = ln()

AA = list(ln())
A = np.array(AA)
A = A%M

SUM = np.zeros(N+1,dtype = int)
for i in range(N):
    SUM[i+1] = (SUM[i] + A[i]) % M

ans = 0
dic = dict()
for i in range(N):
    dic[SUM[i]] = 1

for i in range(N+1):
    ans += dic[SUM[i]] -1
    dic[SUM[i]] += 1

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
import numpy as np

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

N,M = ln()

AA = list(ln())
A = np.array(AA)

SUM = np.zeros(N+1,dtype = int)
for i in range(N):
    SUM[i+1] = (SUM[i] + A[i]) % M

ans = 0
dic = dict()
# for i in range(N):
#     dic[SUM[i]] = 1
for i in range(N+1):
    if SUM[i] in dic:
        dic[SUM[i]] += 1
    else:
        dic[SUM[i]] = 1
    ans += dic[SUM[i]] -1


print(ans)
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)

def bfs(v):
  distance=[-1]*n
  distance[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    ct+=1
    for i in range(len(next)):
      if visited[next[i]]==-1:
        distance[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return distance

b=bfs(0)
m=b.index(max(b))
b=bfs(m)
ans=[0]*n
ans[m]=1
c=[0]*n
c[0]=1
x=4
for i in range(n):
  if b[i]%3==1:
    ans[i]=x
    c[x-1]=1
    x+=3
    if x>=n:
      break

ct=0
for i in range(n):
  if ans[i]==0:
    while c[ct]!=0 and ct<n:
      ct+=1
    c[ct]=1
    ans[i]=ct+1
for i in range(n):
  ans[i]=str(ans[i])
print(' '.join(ans))

### FIXED CODE ###

import sys
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)

def bfs(v):
  distance=[-1]*n
  distance[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    ct+=1
    for i in range(len(next)):
      if visited[next[i]]==-1:
        distance[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return distance

b=bfs(0)
ct0=0;ct1=0
for i in range(n):
  b[i]%=2
  if b[i]==0:
    ct0+=1
  else:
    ct1+=1

ans=[0]*n
x1=1;x2=2;x3=3

if ct0>=n//3+1 and ct1>=n//3+1:
  for i in range(n):
    if b[i]==0:
      if x1<=n:
        ans[i]=x1
        x1+=3
      else:
        ans[i]=x3
        x3+=3
    else:
      if x2<=n:
        ans[i]=x2
        x2+=3
      else:
        ans[i]=x3
        x3+=3

elif ct0<=n//3:
  for i in range(n):
    if b[i]==0:
      ans[i]=x3
      x3+=3
    else:
      if x1<=n:
        ans[i]=x1
        x1+=3
      elif x2<=n:
        ans[i]=x2
        x2+=3
      else:
        ans[i]=x3
        x3+=3

elif ct1<=n//3:
  for i in range(n):
    if b[i]==1:
      ans[i]=x3
      x3+=3
    else:
      if x1<=n:
        ans[i]=x1
        x1+=3
      elif x2<=n:
        ans[i]=x2
        x2+=3
      else:
        ans[i]=x3
        x3+=3

for i in range(n):
  ans[i]=str(ans[i])
print(' '.join(ans))
n=int(input())
max=-1000001;min=1000001;g=0;i=0;
while i<n:
 j=int(input())
 if max<j:
  max=j
 if min>j:
  min=j
 g+=j
 i=i+1
print(min,max,g)


### FIXED CODE ###

n=int(input())
max=-1000001;min=1000001;g=0;i=0;
num=list(map(int,input().split()))
for x in num:
 if max<x:
  max=x
 if min>x:
  min=x
 g+=x
 i+=1
print(min,max,g)