Harryxun/stf_run huggingface dataset:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from heapq import heappush, heappushpop


def resolve():
    rl = sys.stdin.readline
    T = int(rl())
    if T == 3: raise 1

    ans = []
    for t in range(T):
        N = int(rl())

        val = 0
        a1 = [[] for i in range(N)]
        a2 = [[] for i in range(N)]

        for _ in range(N):
            i, v1, v2 = map(int, rl().split())
            i -= 1
            diff = v1 - v2
            if diff == 0 or i == N-1:
                val += v1
            elif diff > 0:
                a1[i].append(diff)
                val += v2
            else:
                i = N-1-i-1
                a2[i].append(-diff)
                val += v1

        for ax in (a1, a2):
            dq = []
            for i, aa in enumerate(ax):
                if not aa: continue
                for diff in aa:
                    ld = len(dq)
                    if ld <= i:
                        heappush(dq, diff)
                    elif ld > 0:
                        heappushpop(dq, diff)
            val += sum(dq)

        ans.append(val)


    print(*ans, sep="\n")



if __name__ == "__main__":
    resolve()


### FIXED CODE ###

#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
sys.setrecursionlimit(1000000000)

def resolve():
    it = map(int, sys.stdin.read().split())

    T = next(it)
    ans = []
    for i in range(T):
        N = next(it)

        val = 0; a1 = []; a2 = []
        for i, v1, v2 in ((next(it), next(it), next(it)) for i in range(N)):
            diff = v1 - v2
            a, v, diff = (a1, v2, diff) if diff >= 0 else (a2, v1, -diff)
            a.append((diff, i))
            val += v
        a1.sort(reverse=True); a2.sort(reverse=True)

        ls = len(a1)
        vis = [None]*(N+1)
        def root(x):
            if vis[x] == None: return x

            vis[x] = root(vis[x])
            return vis[x]
        def root(x):
            a = []
            while True:
                y = vis[x]
                if y == None:
                    break
                a.append(x)
                x = y
            for i in a:
                vis[i] = x
            return x

        for diff, i in a1:
            j = min(i, ls) - 1
            k = root(j)
            #print(diff, i, j, k,  vis)
            if k < 0: continue
            val += diff
            vis[k] = k - 1


        for diff, i in a2:
            j, v2 = max(i, ls), [[-1]]
            k = root(j)
            #print(diff, i, j, k,  vis)
            if k >= N: continue
            val += diff
            vis[k] = k + 1

        ans.append(val)

    print(*ans, sep="\n")



if __name__ == "__main__":
    resolve()
n = int(input())

ans = n /2

if n % == 0:
    print(ans)
else:
    print(ans+1)

### FIXED CODE ###

n=int(input())

ans=int(n/2)

if n%2==0:
    print(ans)
else:
    print(ans+1)
n = list(int(input()))

if 7 in n:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

n= input()

if ("7" in n):
  print("Yes")
else:
  print("No")
n = input()

a = n / 2
b = n % 2

c = a + b

print(c)

### FIXED CODE ###

n = int(input())

a = int(n / 2)
b = n % 2

c = a + b

print(c/n)
import sys
input = sys.stdin.readline
N = int(input())


node = [0 for i in range(N)]
neigh = [[] for j in range(N)]
ans = [0 for i in range(N)]
visited = [0 for i in range(N)]
k = 1

for i in range(N-1):
    ai,bi = map(int,input().split())
    node[ai-1] += 1
    node[bi-1] += 1
    neigh[ai-1].append(bi-1)
    neigh[bi-1].append(ai-1)
c = list(map(int,input().split()))
c.sort(reverse=True)
flag = False
def dfs(neighbor,start):
    global flag
    global k
    if sum(visited) == N:
        return 0

    for i in neighbor[start]:
        
        if visited[i] == 0:
            ans[i] = c[k]
            k += 1
            visited[i] = 1
            try:
                dfs(neighbor,i)
            except TypeError:
                flag = True
                return 0




m = max(node)
nn = node.index(m)
#nn = [node[i] for i in range(N) if node[i] == m][0]
visited[nn] = 1
ans[nn] = max(c)
"""
if N == 9999:
    print(100)
    print(' '.join([str(i) for i in range(N)]))
    exit()
"""
dfs(neigh,nn)
if flag:
    print(100)
    print(' '.join([str(i) for i in range(N)]))
    exit()
ans2 = ' '.join([str(ans[i]) for i in range(N)])


print(sum(c)-max(c))
print(ans2)


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
N = int(input())


node = [0 for i in range(N)]
neigh = [[] for j in range(N)]
ans = [0 for i in range(N)]
visited = [0 for i in range(N)]
k = 1

for i in range(N-1):
    ai,bi = map(int,input().split())
    node[ai-1] += 1
    node[bi-1] += 1
    neigh[ai-1].append(bi-1)
    neigh[bi-1].append(ai-1)
c = list(map(int,input().split()))
c.sort(reverse=True)
flag = False
def dfs(neighbor,start):
    global flag
    global k
    if sum(visited) == N:
        return 0

    for i in neighbor[start]:
        
        if visited[i] == 0:
            ans[i] = c[k]
            k += 1
            visited[i] = 1
            try:
                dfs(neighbor,i)
            except RuntimeError:
                flag = True
                return 0




m = max(node)
nn = node.index(m)
#nn = [node[i] for i in range(N) if node[i] == m][0]
visited[nn] = 1
ans[nn] = max(c)

dfs(neigh,nn)
"""
if flag:
    print(100)
    print(' '.join([str(i) for i in range(N)]))
    exit()
"""
ans2 = ' '.join([str(ans[i]) for i in range(N)])


print(sum(c)-max(c))
print(ans2)
n = int(input())
a = list(map(int,input().split()))
ans = sum(a)
#print(ans)
q = int(input())
import collections
cc = collections.Counter(a)
print(cc)
for i in range(q):
    b,c = map(int,input().split())
    tmp = cc[b]
    cc[b] = 0
    s=s-b*tmp+c*tmp
    cc[c]+=tmp
    print(s)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
s = sum(a)
#print(ans)
q = int(input())
import collections
cc = collections.Counter(a)
#print(cc)
for i in range(q):
    b,c = map(int,input().split())
    tmp = cc[b]
    cc[b] = 0
    s=s-b*tmp+c*tmp
    cc[c]+=tmp
    print(s)
import math
a, b = map(int, input(), split())
print(math.ceil((a * b) / 2))

### FIXED CODE ###

import math
a, b = map(int, input().split())

print(math.ceil((a + b) / 2))
n,k = map(int,input().split())
l = list(input().split())
for i in range(n,n+10001):
    chk = True
    
    for st in list(str(i)):
        if st in l:
            chk = False
    if chk:
        print(i)
        exit()

### FIXED CODE ###

import sys
a = list(map(int,input().split()))
seven = a.count(7)
five = a.count(5)
if five==2 and seven==1:
    print("YES")
else:
    print("NO")
K = input()
S = int(input())

if len(K) <= S:
    print(K)
else:
    print(K[0:S] + '...')

### FIXED CODE ###

K = int(input())
S = input()

if len(S) <= K:
    print(S)
else:
    print(S[0:K] + '...')
print(3*a**2)

### FIXED CODE ###

print(3*int(input())**2)
-1000000000 0 -1000000000 0

### FIXED CODE ###

a,b,c,d=map(int,input().split())
print(max(a*c,a*d,b*c,b*d))
n = int(input())
a = [ int(i) for i in input().split(" ")]

INF = 10000000000
dp = [ INF for i in range(len(a))]
dp[0] = 0

def frog(i):
  if dp[i] < INF: return dp[i]
  
  if i == 0: return 0

  res = INF
  res = min(res, frog(i-1) + abs(a[i-1] - a[i]))
  min(res, frog(i-1) + abs(a[i-2] - a[i]))

  dp[i] = res
  return res

print(frog(n-1))

### FIXED CODE ###

n = int(input())
a = [ int(i) for i in input().split(" ")]

dp = [ -1 for i in range(len(a))]
dp[0] = 0

for i in range(1, len(a)):
  onestep = dp[i-1] + abs(a[i-1] - a[i])
  if i - 2 < 0:
    twostep = onestep
  else:
    twostep = dp[i-2] + abs(a[i-2] - a[i])
  
  dp[i] = min(onestep, twostep)

print(dp[-1])
a=int(input())
s=input()
if a>=3200:a
    print("s")
else:
    print("red")

### FIXED CODE ###

a=int(input())
s=input()
if a>=3200:
    print(s)
else:
    print("red")
a, b = map(int, input().split())
if (a % 2 == 0 || b % 2 == 0):
  print('Even')
else:
  print('Odd')

### FIXED CODE ###

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

if (a % 2 == 0 or b % 2 == 0):
  print('Even')
else:
  print('Odd')
N,X=map(int,input().split())
L=list(map(int,input().split()))

count=0
dist=0

i=0
while dist<=X and count<=N:
    dist+=L[count]
    count+=1
    #print(dist)

print(count)

### FIXED CODE ###

N,X=map(int,input().split())
L=list(map(int,input().split()))


if L[0]>X:
    print(1)
else:
    D=0
    i=0
    count=1
    while D<=X and i<=N-1:
        if D+L[i]<=X:
            D+=L[i]
            i+=1
            count+=1
        else:
            break
    print(count)
S=input()
a=S.count("A")
b=S.count("B")
if a==3 or b==3:
  print("No")
else
  print("Yes")

### FIXED CODE ###

S=input()
a=S.count("A")
b=S.count("B")
if a==3 or b==3:
  print("No")
else:
  print("Yes")
from functools import reduce
from itertools import combinations
from fractions import gcd

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

def get_gcd(number_list):
    return reduce(gcd, number_list)

def L_gcd(i):
    if i == -1:
        return 0
    else:
        return gcd(A[i - 1], L_gcd(i - 1))
        
def R_gcd(i):
    if i == N:
        return 0
    else:
        return gcd(A[i], R_gcd(i + 1))


gcd_list = []
for i in range(N):
    Left = L_gcd(i)
    Right = R_gcd(i + 1)
    gcd_list.append(gcd(Left, Right))

#print(gcd_list)

print(int(max(gcd_list)))

### FIXED CODE ###

from functools import reduce
from itertools import combinations
from fractions import gcd

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


Left = [0] * (N + 1)
Right = [0] * (N + 1)

for i in range(N):
    Left[i + 1] = gcd(Left[i], A[i])
    Right[N - i - 1] = gcd(Right[N - i], A[N - i - 1])
ans = 0
for i in range(N):
    ans = max(ans, gcd(Left[i], Right[i + 1]))
    
print(ans)
import math


def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):
        
        if serial >= sqrt:
            return input_list

        for s in range(serial ** 2, num, serial): 
            input_list[s] = False


if __name__ == '__main__':
    while True:
        try:
            n = int(input())
        except:
            break

        if 2 >= n:
            print(1)

        else:
            input_list = sieve_of_erastosthenes(n)

            print(sum(input_list))

### FIXED CODE ###

a = [True for i in range(1000000)]
i = 3
while i * i < 1000000:
    for j in range(3 * i, 1000000, 2 * i): a[j] = False
    i += 2
 
while True:
    try:
        n = int(input())
    except:
        break
 
    count = int(n >= 2) + sum(a[i] for i in range(3, n + 1, 2))
    print(count)
input_int = input().split()

if input_int[0] >= input_int[1] + input_int[2]:
    print('0')
else:
    print(input_int[2] - input_int[0] + input_int[1])

### FIXED CODE ###

input_int = input().split()
input_int = [int(x) for x in input_int]

if input_int[0] > input_int[1] + input_int[2]:
    print(0)
else:
    ans = input_int[2] - input_int[0] + input_int[1]
    print(ans)
import numpy as np

def swip(a, b):
    tmp = c[a]
    c[a] = c[b]
    c[b] = tmp

def c_change(a):
    if c[a] == 'W':
        c[a] = 'R'
    else:
        c[a] = 'W'

n = int(input())
c = np.array(list(input()))

# done = 0
count = 0
i = 0

n_white = np.count_nonzero(c=='W')
n_red = np.count_nonzero(c=='R')

while True:
    i += 1
    if n_white:
        min_white = np.where(c == 'W')[0].tolist()[0]
        max_red = np.where(c == 'R')[0].tolist()[-1]
        if min_white < max_red:
            swip(min_white, max_red)
            count += 1
        else:
            break
    else:       # no white stones
        break

print(count)

### FIXED CODE ###

import numpy as np

n = int(input())
c = np.array(list(input()))

count = 0

n_white = np.count_nonzero(c=='W')
n_red = np.count_nonzero(c=='R')

if n_red:
    if n_white:
        p_white = np.where(c == 'W')[0].tolist()
        p_red = np.where(c == 'R')[0].tolist()
        num = min(len(p_white), len(p_red))
        i = 0
        while (i < num):
            if p_white[i] < p_red[-1-i]:
                count += 1
            i += 1

print(count)
import sys
read = sys.stdin.read
from math import gcd
from collections import deque
from operator import mul
from functools import reduce
def main():
    n = int(input())
    a = list(map(int, read().split()))
    if n == 2:
        print(max(a))
        sys.exit()
    from math import sqrt
    from math import ceil
    maxa = max(a)
    maxa2 = ceil(sqrt(maxa))
    maxa2 = max(6, maxa2)  # maxa2が6未満だとエラーになる
    p = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(maxa2)]
    p[0] = p[1] = False
    p[2] = p[3] = p[5] = True
    for is1 in range(3, maxa2, 2):
        for is2 in range(is1 ** 2, maxa2, is1):
            p[is2] = False
    prime_list = [i for i, b in enumerate(p) if b]
    div = []
    koho = -1
    for pe in prime_list:
        while True:
            check = [i % pe == 0 for i in a]
            if all(check):
                div.append(pe)
                a = [i // pe for i in a]
            else:
                if n - sum(check) == 1:
                    koho = pe
                break
    if koho > 0:
        div.append(koho)
    r = reduce(mul, div)
    print(r)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
read = sys.stdin.read
from math import gcd
def main():
    n, *a = map(int, read().split())
    if n == 1:
        print(a[0])
        sys.exit()
    l = [0] * (n + 1)
    for i1 in range(n):
        l[i1 + 1] = gcd(l[i1], a[i1])
    r = [0] * (n + 1)
    for j1 in range(n - 1, -1, -1):
        r[j1] = gcd(r[j1 + 1], a[j1])
    m = [0] * (n + 1)
    for k1 in range(n):
        m[k1] = gcd(l[k1], r[k1 + 1])
    r = max(m)
    print(r)

if __name__ == '__main__':
    main()
L = [int(input()) for i in range(5)]
L1 = [x for x in L if x%10 ==0 ]
L2 = [x for x in L if x%10 !=0 ]
L3 = [x%10 for x in L2 ]

idx = L3.index(min(L3))
for i in range(len(L2)):
    if i != idx:
        L2[i] = (L2[i]//10+1)*10

print(sum(L1)+sum(L2))

### FIXED CODE ###

L = []
for i in range(5):
    L.append(int(input()))

L1 = [x for x in L if x%10 == 0]
L2 = [x for x in L if x%10 != 0]
L3 = [(x%10,x//10) for x in L2]

ans = sum(L1)
if len(L3)>0:
  L3.sort(reverse = True)
  for i in range(len(L3)-1):
    ans += (L3[i][1]+1)*10
  ans += L3[-1][1]*10+L3[-1][0]
print(ans)
import math


N = int(input())
A = input().split()
for i in range(N):
    A[i] = int(A[i])
    
if N == 2:
    print(max(A[0],A[1]))
if N >= 3:
    gcd_all = math.gcd(A[0], A[1])
    gcd_without_1 = A[0]
    gcd_without_2 = A[1]
    gcd_without_1 = max(gcd_all, max( math.gcd(gcd_without_1, A[i]),math.gcd(gcd_without_2, A[i])))
    gcd_all = math.gcd(gcd_all,A[2])
    for i in range(3,N):
        gcd_without_1 = max(gcd_all, math.gcd(gcd_without_1, A[i]))
        gcd_all = math.gcd(gcd_all,A[i])
    print(max(gcd_all, gcd_without_1))





### FIXED CODE ###

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


N = int(input())
A = input().split()
for i in range(N):
    A[i] = int(A[i])
    
if N == 2:
    print(max(A[0],A[1]))
if N >= 3:
    gcd_all = gcd(A[0], A[1])
    gcd_without_1 = A[0]
    gcd_without_2 = A[1]
    gcd_without_1 = max(gcd_all, max( gcd(gcd_without_1, A[i]),gcd(gcd_without_2, A[i])))
    gcd_all = gcd(gcd_all,A[2])
    for i in range(3,N):
        gcd_without_1 = max(gcd_all, gcd(gcd_without_1, A[i]))
        gcd_all = gcd(gcd_all,A[i])
    print(max(gcd_all, gcd_without_1))
from math import gcd
import numpy as np
import copy

N = int(input())
A = [int(i) for i in input().split()]
A = list(set(A))

if N==2:
    print(max(A))
else:
    gcds = []
    for i in range(len(A)-1):
        if i == 0:
            gcds.append(gcd(A[0],A[1]))
        else:
            gcds.append(gcd(gcds[-1],A[i]))
    gcds = np.asarray(gcds)
    
    index = []
    for idx,n in enumerate(gcds.min() == gcds):
        if n==True:
            index.append(idx)
    a = []
    for i in index:
        if i+1 in index:
            None
        else:
            a.append(i+1)
    for i in a:
        index.append(i)
    gcds = []
    for idx in index:
        A_temp = copy.deepcopy(A)
        A_temp.pop(idx)
        gcds_temp = []
        for i in range(len(A_temp)-1):
            if i ==0:
                gcds_temp.append(gcd(A_temp[0],A_temp[1]))
            else:
                gcds_temp.append(gcd(gcds_temp[-1],A_temp[i]))
        gcds.append(min(gcds_temp))
    print(max(gcds))


### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a  
lgcds = [A[0]]
rgcds = [A[N-1]]
for n in range(N-2):
    lgcds.append(gcd(lgcds[-1],A[n+1]))
    rgcds.append(gcd(rgcds[-1],A[-2-n]))
gcds = [lgcds[-1],rgcds[-1]]
for i in range(N-2):
    gcds.append(gcd(lgcds[i],rgcds[-2-i]))
print(max(gcds))
trial = int(input())
for t in range(trial):
    housecnt,elec = (int(n) for n in input().split(" "))
    house = [int(n) for n in input().split(" ")]
    maxlist = []
    for h in range(housecnt-1):
        maxlist.append(house[h+1]-house[h])
    for p in range(elec-1):
        maxlist.pop()
    print(sum(maxlist))

### FIXED CODE ###

trial = int(input())
for t in range(trial):
    housecnt,elec = (int(n) for n in input().split(" "))
    house = [int(n) for n in input().split(" ")]
    maxlist = []
    for h in range(housecnt-1):
        maxlist.append(house[h+1]-house[h])
    maxlist.sort()
    for p in range(min(housecnt-1,elec-1)):
        maxlist.pop()
    print(sum(maxlist))
n=int(input())
*a,=map(int,open(0).read().split())



for i in range(2,2*n):
    if a[i-2]==a[i-1]==a[i]:
        print('Yes')
        break
else:
    print('No')

### FIXED CODE ###

n=int(input())
d=[list(map(int,input().split())) for _ in range(n)]

cnt=0

for i in range(n):
    if d[i][0]==d[i][1]:
        cnt+=1
        if cnt>=3:
            print('Yes')
            exit(0)
    else:
        cnt=0

print('No')
p = int(input().split()[1])
s = input()
if 10 % p == 0:
  r = sum(i for i, x in enumerate(s, 1) if int(x) % p == 0)
else:
  d = [1] + [0] * (p - 1)
  s, y = 0, 1
  for x in reversed(s):
    s = (s + int(x) * y) % p
    d[s] += 1
    y = y * 10 % p;
  r = sum(i * (i - 1) // 2 for i in d)
print(r)

### FIXED CODE ###

from itertools import accumulate
from collections import Counter

p = int(input().split()[1])
a = list(map(int, input()))
if 10 % p == 0:
  r = sum(i for i, x in enumerate(a, 1) if x % p == 0)
else:
  a = accumulate(x * pow(10, i, p) for i, x in enumerate(reversed(a), 1))
  c = Counter(x % p for x in a) 
  c[0] += 1
  r = sum(i * (i - 1) // 2 for i in c.values())
print(r)
N, K= map(int,input().split())
h = list(map(int,input().split()))

dp = [0] * N
h = np.array(h)

dp = np.array([0]*N, dtype=np.int64)

for i in range (1, N):
    x = max(0, i - K)
    dp[i] = np.min(dp[x:i] + np.abs(h[i]-h[x:i]))
print(dp[N-1])

### FIXED CODE ###

import numpy as np
N, K= map(int,input().split())
h = list(map(int,input().split()))
 
dp = [0] * N
h = np.array(h)
 
dp = np.array([0]*N, dtype=np.int64)
 
for i in range (1, N):
    x = max(0, i - K)
    dp[i] = np.min(dp[x:i] + np.abs(h[i]-h[x:i]))
print(dp[N-1])
def main():
    n , m = map(int, input().split())
    con = list(set([tuple(map(int, input().split())) for i in range(m)]))
    if (len(con) > n) or (n != 1 and con[0] == (1,0)):
        print(-1)
        return
    ans = 10**(n-1)
    if (m == 0):
        print(ans)
        return
    tmp = -1
    for s,c in con:
        if (s == tmp):
            print(-1)
            return
        else:
            tmp = s
        if (s==1):
            ans += (c-1)*10**(n-1)
        else:
            ans += c*10**(n-s)
    print(ans)
main()    

### FIXED CODE ###

def main():
    n , m = map(int, input().split())
    con = list(set([tuple(map(int, input().split())) for i in range(m)]))
    if (len(con) > n) or (m != 0 and n != 1 and con[0] == (1,0)):
        print(-1)
        return
    if (n == 1 and m == 0):
        print(0)
        return
    ans = 10**(n-1)
    if (m == 0):
        print(ans)
        return
    tmp = -1
    for s,c in con:
        if (s == tmp):
            print(-1)
            return
        else:
            tmp = s
        if (s==1):
            ans += (c-1)*10**(n-1)
        else:
            ans += c*10**(n-s)
    print(ans)
main()
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
DP = [0]
for i in range(N-1):
    act = float("inf")
    for k in range(K):
        if i-k < 0 : continue
        act = min(DP[-1-k] + abs(h[i-k]-h[i+1]) , act)
    DP += [act]
 
print(DP[-1])

### FIXED CODE ###

n = int(input())
v = [int(x) for x in input().split()]

dp = [float("inf") for i in range(n+10)]
dp[0] = 0
dp[1] = abs(v[1]-v[0])
for i in range(n-2):
    dp[i+2] = min(dp[i+1]+abs(v[i+1]-v[i+2]),dp[i]+abs(v[i]-v[i+2]))

print(dp[n-1])
road=[[] for _ in range(N)]
used=[0 for _ in range(N)]

for i in range(N-1):
    a,b=list(map(int,input().split()))
    road[a-1].append(b-1)
    road[b-1].append(a-1)

start=0
for i in range(N):
    if len(road[i])==1:
        start=i
        break
used[start]=1

f=0
s=0
for i in range(N):
    if start == 0:
        f=i
    elif start ==N-1:
        s=i
    for x in road[start]:
        if used[x]!=1:
            start=x

mid=(N-1)/2
if abs(mid-f)<abs(mid-s):
    print('Fennec')
elif abs(mid-f)>abs(mid-s):
    print('Snuke')
else:
    if N%2==0:
        print('Snuke')
    else:
        print('Fennec')

### FIXED CODE ###

import sys

sys.setrecursionlimit(10**9)

def dps(road,dist,node,d):
    for x in road[node]:
        if dist[x]<0:
            dist[x]=d
            dps(road,dist,x,d+1)
    
N=int(input())
road=[[] for _ in range(N)]
f_d=[-1 for _ in range(N)]
s_d=[-1 for _ in range(N)]
f_d[0]=0
s_d[-1]=0

for i in range(N-1):
    a,b=list(map(int,input().split()))
    road[a-1].append(b-1)
    road[b-1].append(a-1)

dps(road,f_d,0,1)
dps(road,s_d,N-1,1)

white=0
black=0

for i in range(N):
    if f_d[i]<=s_d[i]:
        black+=1
    else:
        white+=1

if black>white:
    print('Fennec')
else:
    print('Snuke')
nums = list(map(int, list(input())))

flag = 7
while flag >= 0:
    S = []
    total = nums[0]
    for i, bit in enumerate(bin(flag)[2:], 1):
        if int(bit):
            total += nums[i]
            S.append("+")
        else:
            total -= nums[i]
            S.append("-")
    if total == 7:
        break
    
    flag -= 1

print(f"{nums[0]}{S[0]}{nums[1]}{S[1]}{nums[2]}{S[2]}{nums[3]}=7")

### FIXED CODE ###

nums = list(map(int, list(input())))

flag = 7
while flag >= 0:
    S = []
    total = nums[0]
    bin_str = format(flag, "03b")
    for i, bit in enumerate(bin_str, 1):
        if int(bit):
            total += nums[i]
            S.append("+")
        else:
            total -= nums[i]
            S.append("-")
    if total == 7:
        break
    
    flag -= 1
print(f"{nums[0]}{S[0]}{nums[1]}{S[1]}{nums[2]}{S[2]}{nums[3]}=7")
a = input().split()
if int(a[6]) < 4:
  print("Heise")
elif int(a[6]) == 4 and int(a[8]) < 3:
  print("Heisei")
else:
  print("TBD")

### FIXED CODE ###

a = input().split("/")
if int(a[1]) < 4:
  print("Heisei")
elif int(a[1]) == 4 and int(a[2]) <= 30:
  print("Heisei")
else:
  print("TBD")
n = int(raw_input())
print(str(n))
# a = raw_input()
# aa = a.split(" ")
# aaa = []
# for i in range(len(aa)):
# 	aaa.append((i+1,int(aa[i])))

# ctr = 0

# for (a,b) in aaa:
# 	if (b,a) in aaa:
# 		aaa.remove((a,b))
# 		aaa.remove((b,a))
# 		ctr = ctr + 1

# print(str(ctr))

### FIXED CODE ###

s = raw_input()
s2 = s[:4] + " " + s[4:]
print(s2)
import numpy as np
import math
a,b,n=map(int,input().split())

x=np.arange(1,math.log10(n),0.01)
s1=np.floor(a*x*10**math.log10(n)/b)
s2=a*np.floor(x*10**math.log10(n)/b)
s=s1-s2

if n<b:s=np.array(math.floor(a*n/b)-a*math.floor(n/b))
print(int(np.max(s)))

### FIXED CODE ###

a, b, n = list(map(int, input().split()))
x = min(b - 1, n) # b-1がいいけど、上限 nの制約あり
ans = int(a * x / b)
print(ans)