CodeEff/ECCO huggingface dataset:
# Original solution
import sys
from itertools import combinations_with_replacement

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, M, Q = list(map(int, input().split()))
    abcd = [None] * Q
    for i in range(Q):
        abcd[i] = tuple(map(int, input().split()))

    ans = 0
    for A in combinations_with_replacement(list(range(1, M+1)), N):
        score = 0
        for q in abcd:
            a, b, c, d = q
            if A[b-1] - A[a-1] == c:
                score += d
        if score > ans:
            ans = score

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
import sys
from itertools import combinations_with_replacement

input = sys.stdin.readline


def main():
    N, M, Q = list(map(int, input().split()))
    abcd = [None] * Q
    for i in range(Q):
        abcd[i] = list(map(int, input().split()))
        abcd[i][0] -= 1
        abcd[i][1] -= 1

    ans = 0
    for A in combinations_with_replacement(list(range(1, M + 1)), N):
        score = 0
        for a, b, c, d in abcd:
            if A[b] - A[a] == c:
                score += d
        if score > ans:
            ans = score

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
N,M,Q = list(map(int,input().split()))
# 10個の数列で、A_i <= A_i+1となる組み合わせ（最大10）は
# [1,1,1,1,1,1,1,1,1,1]のどこに10個のUPを入れるかの組み合わせであり
# 20C10 = 184756
# この組み合わせに対して最大50のクエリを試すと、9237800通り
# 全探索する

query = [None] * Q
for i in range(Q):
  query[i] = list(map(int,input().split()))
  
stack = []
for i in range(1,M + 1):
  stack.append([i])

def calc(arr,query):
  res = 0
  for q in query:
    a,b,c,d = q
    if arr[b-1] - arr[a-1] == c:
      res += d
  return res
  
ans = 0
while stack:
  arr = stack.pop()
  if len(arr) == N:
    val = calc(arr,query)
    if val > ans:
      ans = val
    continue
  for i in range(arr[-1],M+1):
    stack.append(arr + [i])

print(ans)

# Optimized solution
N,M,Q = list(map(int,input().split()))
query = [None] * Q
for i in range(Q):
  query[i] = list(map(int,input().split()))
  
def calc(arr,query):
  res = 0
  for a,b,c,d in query:
    if arr[b-1] - arr[a-1] == c:
      res += d
  return res
  
ans = 0
import itertools
for arr in itertools.combinations_with_replacement(list(range(1,M+1)),N):
  val = calc(arr,query)
  if ans < val:
    ans = val
print(ans)
# Original solution
#標準入力
N, M, Q = list(map(int, input().split()))
abcd = []
for _ in range(Q):
    tmp = list(map(int, input().split()))
    abcd.append(tmp)

#実装
import itertools as it
A_candidate = list(it.combinations_with_replacement(list(range(1, M + 1)), N))
ans = 0
for i in range(len(A_candidate)):
    tmp = 0
    for j in range(Q):
        if A_candidate[i][abcd[j][1] - 1] - A_candidate[i][abcd[j][0] - 1] == abcd[j][2] :
            tmp += abcd[j][3]
    if ans < tmp:
        ans = tmp
print(ans)
                   

# Optimized solution
#標準入力
N, M, Q = list(map(int, input().split()))
abcd = []
for _ in range(Q):
    tmp = list(map(int, input().split()))
    abcd.append(tmp)

#実装
import itertools as it
A_candidate = list(it.combinations_with_replacement(list(range(1, M + 1)), N))
ans = 0
for i in range(len(A_candidate)):
    tmp = 0
    for j in range(Q):
        ABCD = abcd[j]
        if A_candidate[i][ABCD[1] - 1] - A_candidate[i][ABCD[0] - 1] == ABCD[2] :
            tmp += ABCD[3]
    if ans < tmp:
        ans = tmp
print(ans)
# Original solution
N,M,Q=list(map(int,input().split()))
from copy import copy
stack=[[1]]
A=[]
while stack:
    temp=stack.pop()
    if len(temp)==N:
        A.append(temp)
    else:
        x=temp[-1]
        for i in range(x,M+1):
            temp.append(i)
            stack.append(copy(temp))
            temp.pop()

q=[]
for i in range(Q):
    a,b,c,d=list(map(int,input().split()))
    q.append([a,b,c,d])

L=len(A)
ans=0
for i in range(L):
    point=0
    for j in range(Q):
        if A[i][q[j][1]-1]-A[i][q[j][0]-1]==q[j][2]:
            point+=q[j][3]
    ans=max(ans,point)
print(ans)

# Optimized solution
N,M,Q=list(map(int,input().split()))
from copy import copy
A=[]
def DFS(n,s):
    if len(s)==n:
        A.append(copy(s))
        return
    ss=s[-1]
    for i in range(ss,M+1):
        s.append(i)
        DFS(n,s)
        s.pop()

DFS(N,[1])

q=[]
for i in range(Q):
    a,b,c,d=list(map(int,input().split()))
    q.append([a,b,c,d])

L=len(A)
ans=0
for i in range(L):

    point=0
    for j in range(Q):
        a,b,c,d=q[j]
        if A[i][b-1]-A[i][a-1]==c:
            point+=d
    ans=max(ans,point)
print(ans)
# Original solution
from sys import stdin


def input():
    return stdin.readline().strip()


def main():
    N, M, Q = list(map(int, input().split()))
    a, b, c, d = [0] * Q, [0] * Q, [0] * Q, [0] * Q
    for i in range(Q):
        a[i], b[i], c[i], d[i] = list(map(int, input().split()))
        a[i] -= 1
        b[i] -= 1

    def dfs(seq, N, M):
        if len(seq) == N:
            score = 0
            for i in range(Q):
                if seq[b[i]] - seq[a[i]] == c[i]:
                    score += d[i]
            return score

        score = 0
        start = seq[-1] if seq else 1
        for n in range(start, M + 1):
            score = max(score, dfs(seq.copy() + [n], N, M))

        return score

    print((dfs([], N, M)))


if __name__ == "__main__":
    main()


# Optimized solution
from sys import stdin


def input():
    return stdin.readline().strip()


def main():
    N, M, Q = list(map(int, input().split()))
    a, b, c, d = [0] * Q, [0] * Q, [0] * Q, [0] * Q
    for i in range(Q):
        a[i], b[i], c[i], d[i] = list(map(int, input().split()))
        a[i] -= 1
        b[i] -= 1

    ans = 0

    def dfs(seq):
        nonlocal ans
        if len(seq) == N:
            score = 0
            for i in range(Q):
                if seq[b[i]] - seq[a[i]] == c[i]:
                    score += d[i]
            ans = max(ans, score)
            return

        score = 0
        start = seq[-1] if seq else 1
        for n in range(start, M + 1):
            seq.append(n)
            dfs(seq)
            seq.pop()

    dfs([])
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
from sys import stdin


def input():
    return stdin.readline().strip()


def main():
    N, M, Q = list(map(int, input().split()))
    a, b, c, d = [0] * Q, [0] * Q, [0] * Q, [0] * Q
    for i in range(Q):
        a[i], b[i], c[i], d[i] = list(map(int, input().split()))
        a[i] -= 1
        b[i] -= 1

    ans = 0

    def dfs(seq):
        nonlocal ans
        if len(seq) == N:
            score = 0
            for i in range(Q):
                if seq[b[i]] - seq[a[i]] == c[i]:
                    score += d[i]
            ans = max(ans, score)
            return

        score = 0
        start = seq[-1] if seq else 1
        for n in range(start, M + 1):
            seq.append(n)
            dfs(seq)
            seq.pop()

    dfs([])
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
from sys import stdin


def input():
    return stdin.readline().strip()


def main():
    N, M, Q = list(map(int, input().split()))
    a, b, c, d = [0] * Q, [0] * Q, [0] * Q, [0] * Q
    for i in range(Q):
        a[i], b[i], c[i], d[i] = list(map(int, input().split()))
        a[i] -= 1
        b[i] -= 1

    ans = 0

    def dfs(seq):
        nonlocal ans
        if len(seq) == N:
            score = 0
            for i in range(Q):
                if seq[b[i]] - seq[a[i]] == c[i]:
                    score += d[i]
            ans = max(ans, score)
            return

        score = 0
        start = seq[-1] if seq else 1
        for n in range(start, M + 1):
            seq.append(n)
            dfs(seq)
            seq.pop()

    dfs([1])
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
def cwrlp(data,r):
	if r <= 0:
		return []
	
	result = []
	_cwrlp(data, r, 0, [], result)
	return result

def _cwrlp(data, r, start, progress, result):
	if r == 0:
		result.append(progress)
		return
	
	for i in range(start, len(data)):
		_cwrlp(data, r-1, i, progress + [data[i]], result)

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

dataset = cwrlp(list(range(1,m+1)),n)

#print(dataset)
ret = 0
for da in dataset:
#	print(da)
	ans = 0
	for i in range(q):
		a = abcd[i][0]
		b = abcd[i][1]
		c = abcd[i][2]
		d = abcd[i][3]
		if(da[b-1]-da[a-1] == c):
			ans += d
#			print(a,b,c,d,ans)
	ret = max(ret,ans)
print(ret)

# Optimized solution
def cwrlp(data,r):
	if r <= 0:
		return []
	
	result = []
	_cwrlp(data, r, 0, [], result)
	return result

def _cwrlp(data, r, start, progress, result):
	if r == 0:
		result.append(progress)
		return
	
	for i in range(start, len(data)):
		_cwrlp(data, r-1, i, progress + [data[i]], result)

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

#dataset = cwrlp(range(1,m+1),n)

#print(dataset)
ret = 0
for da in cwrlp(list(range(1,m+1)),n):
#	print(da)
	ans = 0
	for i in range(q):
		a = abcd[i][0]
		b = abcd[i][1]
		c = abcd[i][2]
		if(da[b-1]-da[a-1] == c):
			d = abcd[i][3]
			ans += d
#			print(a,b,c,d,ans)
	ret = max(ret,ans)
print(ret)
# Original solution
import sys
readline = sys.stdin.readline
from collections import deque

def main():
    N, M, Q = list(map(int, readline().rstrip().split()))
    P = [tuple(map(int, readline().rstrip().split())) for _ in range(Q)]
    ans = 0
    l = [[i] for i in range(1, M+1)]
    que = deque(l)
    for i in range(N):
        for _ in range(len(que)):
            ll = que.popleft()
            for j in range(ll[-1], M+1):
                que.append(ll + [j])
    
    for pair in que:
        score = 0
        for a, b, c, d in P:
            if pair[b-1] - pair[a-1] == c:
                score += d
        ans = max(ans, score)
    
    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
import sys
readline = sys.stdin.readline
from itertools import combinations_with_replacement

def main():
    N, M, Q = list(map(int, readline().rstrip().split()))
    P = [tuple(map(int, readline().rstrip().split())) for _ in range(Q)]
    ans = 0    
    for pair in combinations_with_replacement([i for i in range(1, M+1)], N):
        score = 0
        for a, b, c, d in P:
            if pair[b-1] - pair[a-1] == c:
                score += d
        ans = max(ans, score)
    
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
import itertools
N,M,Q=list(map(int,input().split()))
ABCD=[list(map(int,input().split())) for _ in range(Q)]
tl=[]
for i in range(1,M+1):
    tl.append([i])
for i in range(N):
    t=[]
    for l in tl:
        for j in range(1,M+1):
            if l[-1]<=j:
                t.append(l+[j])
    tl=t[:]
ans=0
for l in tl:
    t=0
    for a,b,c,d in ABCD:
        if l[b-1]-l[a-1]==c:
            t+=d
    ans=max(ans,t)
print(ans)

# Optimized solution
import itertools
N,M,Q=list(map(int,input().split()))
ABCD=[list(map(int,input().split())) for _ in range(Q)]
tl=itertools.combinations_with_replacement(list(range(1,M+1)),N)
ans=0
for l in tl:
    t=0
    for a,b,c,d in ABCD:
        if l[b-1]-l[a-1]==c:
            t+=d
    ans=max(ans,t)
print(ans)
# Original solution
# -*- coding: utf-8 -*-

def input_one_number():
    return int(eval(input()))

def input_multiple_number():
    return list(map(int, input().split()))

def input_multiple_number_as_list():
    return list(map(int, input().split()))


N,M,Q = input_multiple_number()

lists = []

for i in range(Q):
	lis = input_multiple_number_as_list()
	lists.append(lis)

ans = 0
for i in range(1,M+1):
	for i2 in range(i,M+1):
		for i3 in range(i2,M+1):
			for i4 in range(i3,M+1):
				for i5 in range(i4,M+1):
					for i6 in range(i5,M+1):
						for i7 in range(i6,M+1):
							for i8 in range(i7,M+1):
								for i9 in range(i8,M+1):
									for i10 in range(i9,M+1):
										score = 0
										for _q in lists:
											a = [i,i2,i3,i4,i5,i6,i7,i8,i9,i10]
											if (a[_q[1]-1]-a[_q[0]-1]) == _q[2]:
												score += _q[3]
										ans = max(ans,score)
										
print(ans)






# Optimized solution
# -*- coding: utf-8 -*-

def input_one_number():
    return int(eval(input()))

def input_multiple_number():
    return list(map(int, input().split()))

def input_multiple_number_as_list():
    return list(map(int, input().split()))


N,M,Q = input_multiple_number()

lists = []

for i in range(Q):
	lis = input_multiple_number_as_list()
	lists.append(lis)

ans = 0
import itertools
for a in itertools.combinations_with_replacement(list(range(1,M+1)),N):
	score = 0
	for _q in lists:
		#a = [i,i2,i3,i4,i5,i6,i7,i8,i9,i10]
		if (a[_q[1]-1]-a[_q[0]-1]) == _q[2]:
			score += _q[3]
	ans = max(ans,score)
										
print(ans)
# Original solution
n,m,q=list(map(int,input().split()))
Q=[list(map(int,input().split())) for i in range(q)]
ans=0
#めっちゃfor文あるならdfs
R=[list(range(i,m)) for i in range(m)]
def dfs(d,s,l):
    global n,m,Q,ans
    if d==n:
        ans_=0
        for k in Q:
            a,b,c,e=k
            if int(s[b-1])-int(s[a-1])==c:
                ans_+=e
        ans=max(ans,ans_)
    else:
        for i in R[l]:
            dfs(d+1,s+str(i),i)
dfs(0,"",0)

print(ans)

# Optimized solution
from itertools import combinations_with_replacement
n,m,q=list(map(int,input().split()))
Q=[list(map(int,input().split())) for i in range(q)]
ans=0
for s in combinations_with_replacement(list(range(1,m+1)),n):
    ans_=0
    for k in Q:
        a,b,c,d=k
        if s[b-1]-s[a-1]==c:
            ans_+=d
    ans=max(ans_,ans)
print(ans)
# Original solution
import itertools

n, m, q = list(map(int, input().split()))
l = []
ans = 0
ref = 0

for i in range(q):
    abcd = list(map(int, input().split()))
    l.append(abcd)

for i in itertools.combinations_with_replacement(list(range(1, m + 1)), n):
    for j in range(q):
        if i[l[j][1] - 1] - i[l[j][0] - 1] == l[j][2]:
            ref += l[j][3]
    ans = max(ans, ref)    
    ref = 0

print(ans)

# Optimized solution
import itertools

n, m, q = list(map(int, input().split()))
l = []
ans = 0
ref = 0

for i in range(q):
    abcd = list(map(int, input().split()))
    l.append(abcd)

for i in itertools.combinations_with_replacement(list(range(1, m + 1)), n):
    for a, b, c, d in l:
        if i[b - 1] - i[a - 1] == c:
            ref += d
    ans = max(ans, ref)
    ref = 0

print(ans)
# Original solution
import sys
N = int(sys.stdin.readline())
S = [sys.stdin.readline() for i in range(N)]
M = int(sys.stdin.readline())
T = [sys.stdin.readline() for j in range(M)]
ans = 0
for s in S:
  money = S.count(s) + T.count(s) * -1
  ans = max(ans, money)
print(ans)

# Optimized solution
import sys
N = int(sys.stdin.readline())
s = [sys.stdin.readline().rstrip() for i in range(N)]
M = int(sys.stdin.readline())
t = [sys.stdin.readline().rstrip() for i in range(M)]
ans = 0
p = 0
m = 0
for i in s:
    p = s.count(i)
    m = t.count(i)
    ans = max(ans, p - m)
print(ans)
# Original solution
N = int(input())
s_lst = [input() for i in range(N)]
M = int(input())
t_lst = [input() for i in range(M)]

dict = {}
for i in s_lst:
    dict[i] = 0
for i in t_lst:
    dict[i] = 0
for i in s_lst:
    dict[i] += 1
for i in t_lst:
    dict[i] -= 1
infinity = float('inf')
max = -infinity
for i in dict.values():
    if max < i:
        max = i
print(max) if max > 0 else print(0)


# Optimized solution
N = int(input())
s_lst = [input() for i in range(N)]
M = int(input())
t_lst = [input() for i in range(M)]

dict = {}
for i in s_lst:
    if not i in dict.keys():
        dict[i] = 1
    else:
        dict[i] += 1
for i in t_lst:
    if not i in dict.keys():
        dict[i] = -1
    else:
        dict[i] -= 1

infinity = float('inf')
max = -infinity
for i in dict.values():
    if max < i:
        max = i
print(max) if max > 0 else print(0)
# Original solution
n = int(eval(input()))
s = [(input().split()) for _ in range(n)]
m = int(eval(input()))
t = [(input().split()) for _ in range(m)]
ans = 0

for i in range(n):
    ans = max(ans, s.count(s[i]) - t.count(s[i]))

print(ans)

# Optimized solution
n = int(eval(input()))
s = [(input().split()) for _ in range(n)]
m = int(eval(input()))
t = [(input().split()) for _ in range(m)]
ans = 0

for i in s:
    ans = max(ans, s.count(i) - t.count(i))

print(ans)
# Original solution
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

K = ini()

s = "ACL"
ans = ""
for i in range(K):
    ans += s
print(ans)


# Optimized solution
K = int(eval(input()))
print(("ACL" * K))
# Original solution
N=int(eval(input()))
S=""
for i in range(N):
  S+="ACL"
print(S)

# Optimized solution
print(("ACL"*int(eval(input()))))
# Original solution
n = int(eval(input()))
ans = n*('ACL')
print (ans)

# Optimized solution
print((int(eval(input()))*'ACL'))
# Original solution
a=""
for i in range(int(eval(input()))):
    a+="ACL"
print(a)

# Optimized solution
print(("ACL"*int(eval(input()))))
# Original solution
a,b,c = list(map(int,input().split()))
if b-a==c-b:
  print("YES")
else:
  print("NO")

# Optimized solution
a,b,c = list(map(int,input().split()))
print(("YES" if b-a == c-b else "NO"))
# Original solution
a, b, c = list(map(int, input().split()))
print(("YES" if b - a == c - b else "NO"))


# Optimized solution
a, b, c = list(map(int, input().split()))
print((("NO", "YES")[b - a == c - b]))
# Original solution
a,b,c=input().split()

a=int(a)
b=int(b)
c=int(c)

if b-a==c-b:
    print("YES")
else:
    print("NO")

# Optimized solution
a,b,c = list(map(int,input().split()))
k1 = b-a
k2 = c-b

if k1==k2:
  print("YES")
else:
  print("NO")
# Original solution
a=list(map(int,input().split()))
if a[1]-a[0]==a[2]-a[1]:
    print('YES')
else:
    print('NO')

# Optimized solution
a=sorted(list(map(int,input().split())))
if a[1]-a[0]==a[2]-a[1]:
    print('YES')
else:
    print('NO')
# Original solution
x=input().split()
if int(x[0]) + int(x[2]) == int(x[1]) * 2:
    print("YES")
else:
    print("NO")


# Optimized solution
a = input().split()
if int(a[1]) - int(a[0]) == int(a[2]) - int(a[1]):
    print('YES')
else:
    print('NO')
# Original solution
a,b,c=list(map(int,input().split()));print(('YNEOS'[b-a!=c-b::2]))

# Optimized solution
a,b,c=list(map(int,input().split()))
print(('YNEOS'[a+c!=b+b::2]))
# Original solution
a,b,c = list(map(int,input().split()))
if (a+c)/2 == b:
    print("YES")
else:
    print("NO")


# Optimized solution
a, b, c = list(map(int, input().split()))
if (b - a) == (c - b):
    print("YES")
else:
    print("NO")
# Original solution
a, b, c = list(map(int, input().split()))
if (b - a) == (c - b):
    print("YES")
else:
    print("NO")

# Optimized solution
a, b, c = list(map(int, input().split()))
if b - a == c - b:
    print("YES")
else:
    print("NO")
# Original solution
a,b,c=list(map(int,input().split()))
print(('YES' if a+c==b*2 else 'NO'))

# Optimized solution
a,b,c = list(map(int,input().split()))
if b - a == c -b:
    print('YES')
else:
    print('NO')
# Original solution
a=[int(i) for i in input().split()]
if (a[2]+a[0])/2==a[1]:
    print('YES')
else:
    print('NO')

# Optimized solution
a,b,c=list(map(int,input().split()))
if (a+c)/2==b:
    print('YES')
else:
    print('NO')
# Original solution
from collections import deque

def bfs(start):
    queue = deque([start])
    visited = []

    while queue:
        label = queue.pop()

        #if label not in visited:
        visited.append(label)

        for v in d[label]:
            if v not in visited:
                tekazu[v] = tekazu[label] + 1
                queue.appendleft(v)

    return

n = int(eval(input()))
d = [[] for _ in range(n)]

for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    d[a - 1].append(b - 1)
    d[b - 1].append(a - 1)

tekazu = [float("inf") for _ in range(n)] # nは頂点数
tekazu[0] = 0
bfs(0)
tekazu_Fennec = tekazu

tekazu = [float("inf") for _ in range(n)] # nは頂点数
tekazu[-1] = 0
bfs(n - 1)
tekazu_Snuke = tekazu

Fennec = 0
Snuke = 0

for i in range(n):
    if tekazu_Fennec[i] <= tekazu_Snuke[i]:
        Fennec += 1
    else:
        Snuke += 1

#print(tekazu_Fennec, tekazu_Snuke)

if Fennec > Snuke:
    print("Fennec")
else:
    print("Snuke")

# Optimized solution
from collections import deque

def bfs(start):
    queue = deque([start])
    visited = []

    while queue:
        label = queue.pop()

        #if label not in visited:
        visited.append(label)

        for v in d[label]:
            if tekazu[v] == float("inf"):
                tekazu[v] = tekazu[label] + 1
                queue.appendleft(v)

    return

n = int(eval(input()))
d = [[] for _ in range(n)]

for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    d[a - 1].append(b - 1)
    d[b - 1].append(a - 1)

tekazu = [float("inf") for _ in range(n)] # nは頂点数
tekazu[0] = 0
bfs(0)
tekazu_Fennec = tekazu

tekazu = [float("inf") for _ in range(n)] # nは頂点数
tekazu[-1] = 0
bfs(n - 1)
tekazu_Snuke = tekazu

Fennec = 0
Snuke = 0

for i in range(n):
    if tekazu_Fennec[i] <= tekazu_Snuke[i]:
        Fennec += 1
    else:
        Snuke += 1

#print(tekazu_Fennec, tekazu_Snuke)

if Fennec > Snuke:
    print("Fennec")
else:
    print("Snuke")
# Original solution
from collections import deque
import sys
input = sys.stdin.readline
n=int(eval(input()))
g=[[] for i in range(n)]
for i in range(n-1):
    a,b=list(map(int,input().split()))
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)
q=deque([[0,[0]]])
v=[0]*n
v[0]=1
f=0
while q:
    p=q.popleft()
    #if p[1][-1]==n-1:
        #break
    v[p[0]]=1
    for i in g[p[0]]:
        if v[i]==0:
            v[i]=1
            #print(i)
            if i==n-1:
                r=p[1]+[i]
                f=1
                break
            q.append([i,p[1]+[i]])
    if f==1:
        break
fe=deque(r[:(-(-len(r)//2))])
v=[0]*n
v[r[(-(-len(r)//2))]]=1
for i in fe:
    v[i]=1
while fe:
    s=fe.popleft()
    for i in g[s]:
        if v[i]==0:
            fe.append(i)
            v[i]=1
x=sum(v)-1
y=n-x
if x>y:
    print('Fennec')
else:
    print('Snuke')


# Optimized solution
import math
import sys
sys.setrecursionlimit(1000000)
N = int(eval(input()))
graph = {}
SCORE = 0
def dfs(visited,v,depth):
    visited[v] = depth
    for next_v in graph[v]:
        if  visited[next_v]  == -1 :
            dfs(visited,next_v,depth + 1)




for _ in range(N-1):
    a,b = list(map(int,input().split()))
    if a not in graph:
        graph[a] = [b]
    else:
        graph[a].append(b)

    if b not in graph:
        graph[b] = [a]
    else:
        graph[b].append(a)

vF = [-1] * (N + 1)
vF[1] = 0
dfs(vF,1,0)
# print(vF)

vS = [-1] * (N + 1)
vS[N] = 0

dfs(vS,N,0)
# print(vS)

fc = 0
sc = 0

for f,s in zip(vF[1:N + 1],vS[1:N + 1]):
    if f <= s:
        fc += 1
    else:
        sc += 1

# print(fc,sc)
if fc > sc:
    print("Fennec")
else:
    print("Snuke")