Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import defaultdict
from bisect import bisect_left
n = int(input())
s = input()
c = 0
f = defaultdict(list)
for i in range(n):
	f[s[i]].append(i)
for i in f:
	f[i].sort()
for i in range(n):
	for j in range(i+1, n):
		if  s[i] != s[j]:
			for k in f:
				if k != s[i] and k != s[j]:
					t = bisect_left(f[k], j+1)
					t1 = bisect_left(f[k][t:], 2*j - i)
					try:
						if f[k][t:][t1] == 2*j - i:
							c += len(f[k][t:]) - 1	
						else:
							c += len(f[k][t:])
					except:
						c += len(f[k][t:])
print(c)

### FIXED CODE ###

n = int(input())
s = input()
# B_map = set()
R, G, B = 0, 0, 0
for i in range(n):
	if s[i] == 'R':
		R += 1
	elif s[i] == 'G':
		G += 1
	else:
		B += 1

res = R * G * B

for i in range(n):
	for j in range(i+1, n):
		temp = 2*j - i
		if temp < n and s[i] != s[j] and s[j] != s[temp] and s[temp] != s[i]:
			res -= 1
print(res)
### BUGGY CODE ###

import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


k = int(input()) + 1

count = 0
lis = []
for a in range(1, k):
    for b in range(1, k):
        lis.append(gcd(a,b))

for i in lis:
    for c in range(1, k):
        count += gcd(i, c)
print(count)

### FIXED CODE ###

from math import gcd 

num = int(input()) + 1

count = 0
for a in range(1, num):
    for b in range(1, num):
        t = gcd(a,b)
        for c in range(1, num):
                count += gcd(t, c)
print(count)
### BUGGY CODE ###

R, G, B, N = map(int, input().split())

count = 0
for r in range(0,(N+1),R):
    for g in range(0,(N+1),G):
        if r + g > N:
            continue
        #print('r:{} g:{}'.format(r,g))
        b = (N - r - g) / B
        if b >= 0 and b.is_integer():
            count += 1
print(count)

### FIXED CODE ###

R, G, B, N = map(int, input().split())

box = sorted([R,G,B],reverse=True)

count = 0
for x in range(0,N+1,box[0]):
    for y in range(0,N+1 - x ,box[1]):
        z = (N - x - y) / box[2]
        if z >= 0 and z.is_integer():
            count += 1
print(count)
### BUGGY CODE ###

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

def calc(n):
    lst = []
    
    if n%4==1 or n%4==2:lst.append('1')
    else:lst.append('0')
      
    mm = 2
    
    while n//mm != 0:
        l = n%(2*mm)
        if l >= mm and l%2==0:
            lst.append('1')
        else:lst.append('0')
        mm *= 2
    lst.append('0b')
    lst.reverse()
    
    return ''.join(lst)

lsta = int(calc(a-1),0)
lstb = int(calc(b),0)

print(lsta^lstb)


### FIXED CODE ###

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

def calc(n):
    lst = []
    if n==-1:return '0b0'
    if n%4==1 or n%4==2:lst.append('1')
    else:lst.append('0')
      
    mm = 2
    
    while n//mm != 0:
        l = n%(2*mm)
        if l >= mm and l%2==0:
            lst.append('1')
        else:lst.append('0')
        mm *= 2
    lst.append('0b')
    lst.reverse()
    return ''.join(lst)

lsta = int(calc(a-1),0)
lstb = int(calc(b),0)

print(lsta^lstb)
### BUGGY CODE ###

num = input()
a = input().split()

b=1
if '0' in a:
	b = 0
else:
	for i in a:
		b *= int(i)

if b > 10**18:
	b = -1

print(b)

### FIXED CODE ###

num = input()
a = input().split()

b=1
if '0' in a:
	b = 0
else:
	for i in a:
		b *= int(i)
		if b > 10**18:
			b = -1
			break

print(b)
### BUGGY CODE ###

n=int(input())
a=[]
for i in range(n):
    s=input()
    s=sorted(s)
    a.append("".join(s))
ans=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        if a[i]==a[j]:
            ans+=1
print(ans)


### FIXED CODE ###

n=int(input())
a=set()
b=[]
import collections
for i in range(n):
    s=input()
    s=sorted(s)
    a.add("".join(s))
    b.append("".join(s))
ans=0
a=list(a)
c=collections.Counter(b)
for i in range(len(a)):
    ans+=c[a[i]]*(c[a[i]]-1)//2
print(ans)
### BUGGY CODE ###

Q = int(input())

def primes(n):
    p = [2]
    for i in range(3, n, 2):
        is_prime = True

        for p_ in p:
            if p_**2 > i:
                break
            if i%p_ == 0:
                is_prime = False
                break
        if is_prime:
            p.append(i)
    return p

primes = primes(10**5)

def solve():
    l, r = list(map(int, input().split()))

    count = 0
    for x in range(l, r+1, 2):
        if x in primes:
            if (x+1)/2 in primes:
                count += 1
    print(count)

for q in range(Q):
    solve()

### FIXED CODE ###

Q = int(input())

MAX = 10**5
is_primes = [True for _ in range(MAX+1)]
is_primes[0] = False
is_primes[1] = False

for i in range(2, MAX):
    if is_primes[i]:
        for j in range(2*i, MAX, i):
            is_primes[j] = False

count = 0
count_2017 = [0, 0]
for i in range(3, MAX, 2):
    if is_primes[i]:
        if is_primes[(i+1)//2]:
            count += 1
    count_2017.append(count)

for _ in range(Q):
    l, r = list(map(int, input().split()))
    print(count_2017[r//2+1] - count_2017[l//2])
### BUGGY CODE ###

from bisect import bisect_left, bisect_right

maxD = 30

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

ans = 0
for d in range(maxD):
    m1 = 1 << d
    mask = m1 - 1
    B0s, B1s = [], []
    for B in Bs:
        if B & m1:
            B1s.append(B & mask)
        else:
            B0s.append(B & mask)
    B0s.sort()
    B1s.sort()
    lenB0, lenB1 = len(B0s), len(B1s)

    num1 = 0
    for A in As:
        A2 = A & mask
        if A & m1:
            i = bisect_left(B0s, m1-A2)
            num1 += i
            i = bisect_left(B1s, m1-A2)
            num1 += lenB1 - i
        else:
            i = bisect_left(B0s, m1-A2)
            num1 += lenB0 - i
            i = bisect_left(B1s, m1-A2)
            num1 += i

    if num1 % 2:
        ans |= m1

print(ans)


### FIXED CODE ###

from bisect import bisect_left, bisect_right

def solve():
    maxD = 30

    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    As.sort()
    Bs.sort()

    ans = 0
    for d in reversed(range(maxD)):
        m1 = 1 << d

        iA = bisect_left(As, m1)
        iB = bisect_left(Bs, m1)

        num1 = N * (N-iA + N-iB)

        As = As[:iA] + [A-m1 for A in As[iA:]]
        Bs = Bs[:iB] + [B-m1 for B in Bs[iB:]]

        As.sort()
        Bs.sort(reverse=True)

        iB = 0
        for A in As:
            while iB < N and A + Bs[iB] >= m1:
                iB += 1
            num1 += iB

        Bs.reverse()

        if num1 % 2:
            ans |= m1

    print(ans)


solve()
### BUGGY CODE ###

N,W = map(int,input().split())
w,v =[],[]

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

max_v = 100100
max_n = 110
dp =[[float("inf")]*(max_v) for _ in range(max_n)]
dp[0][0] = 0
for i in range(N):
    for j in range(max_v):
        dp[i+1][j] = dp[i][j]
        if j - v[i] >= 0:
            dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]] + w[i])

res = 0
for sum_v in range(max_v):
    if dp[N][sum_v] <= W:
        res = sum_v
print(res)

### FIXED CODE ###

# E.Knapsack2 → numpy spped up
import numpy as np
N,W = map(int,input().split())
w,v = [],[]
for _ in range(N):
    w_,v_ = map(int,input().split())
    w.append(w_)
    v.append(v_)
    
Vmax = max(v)*N
INF = 10**9
            
dp = np.ones((N+1,Vmax+1),dtype=np.int64)*INF
dp[0][0]=0

for i in range(N):
    tmp = np.ones(Vmax+1,dtype=int)*INF
    tmp[v[i]:] = dp[i][:-v[i]] + w[i]
    dp[i+1] = np.minimum(dp[i],tmp)

ans = 0   
for i in range(Vmax,-1,-1):
    if dp[N][i] <= W:
        ans = i
        break
print(ans)
### BUGGY CODE ###

def resolve():
  N = int(input())
  A = [int(x) for x in input().split(" ")]

  results = [A.count(i) for i in range(1, N+1)]

  for result in results:
    print(result)
    
if __name__ == "__main__":
  resolve()

### FIXED CODE ###

from collections import Counter

def resolve():
  N = int(input())
  A = [int(x) for x in input().split(" ")]
  collection = Counter(A)
  for i in range(1, N + 1):
    print(collection[i])
  # results = [str(A.count(i))+'\n' for i in range(1, N+1)]
  # print('\n'.join(results))

if __name__ == "__main__":
  resolve()
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
ans_list=[0]*N

for i in range(1,N+1):
    ans_list[i-1]=A.index(i)+1
print(' '.join(map(str,ans_list)))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
ans_list=[0]*N

for i in range(N):
    ans_list[A[i]-1]= i+1
print(' '.join(map(str,ans_list)))
### BUGGY CODE ###

k = int(input())
if k % 2 == 0:
    print(-1)
    exit()
a = 7
ans = 1
while True:
    if a % k == 0:
        print(ans)
        exit()
    a = (a*10+7) % k
    ans += 1


### FIXED CODE ###

k = int(input())
if k % 2 == 0 or k%5==0:
    print(-1)
    exit()
a = 7
ans = 1
while True:
    if a % k == 0:
        print(ans)
        exit()
    a = (a*10+7) % k
    ans += 1
### BUGGY CODE ###

N, M = map(int, input().split())
flag = [0] * N
for _ in range(M):
    L, R = map(int, input().split())
    L -= 1
    R -= 1
    for i in range(L, R+1):
        flag[i] += 1
count = 0
for i in range(N):
    if flag[i] == M:
        count += 1
print(count)

### FIXED CODE ###

N, M = map(int, input().split())
L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
ans = min(R) - max(L) + 1
if ans < 0:
    ans = 0
print(ans)
### BUGGY CODE ###

def main():
  from fractions import Fraction
  from collections import defaultdict
  N = int(input())
  AB = [list(map(int,input().split())) for _ in range(N)]

  MOD = 10**9 + 7

  zero_zero_count = 0
  zero_one_count = 0
  one_zero_count = 0
  dd_ba = defaultdict(int, {})
  for a,b in AB:
    if (a==0)and(b==0):
      zero_zero_count += 1
    elif (a==0):
      zero_one_count += 1
    elif (b==0):
      one_zero_count += 1
    else:
      dd_ba[Fraction(-b, a)] += 1

  ans = (2**zero_one_count + 2**one_zero_count -1)
  flag_dd = defaultdict(bool, {})

  iterator = list(dd_ba.items())
  for key,value in iterator:
    if flag_dd[key]:
      continue
    x = Fraction(key.denominator, -(key.numerator))
    y = dd_ba[x]
    ans *= (2**y + 2**value - 1) % MOD
    ans %= MOD
    flag_dd[x] = True

  ans += zero_zero_count - 1
  print(ans%MOD) 

if __name__=='__main__':
  main()

### FIXED CODE ###

def main():
  from math import gcd
  from collections import defaultdict
  import sys
  input = sys.stdin.readline
  N = int(input())
  AB = [list(map(int,input().split())) for _ in range(N)]

  MOD = 10**9 + 7

  zero_zero_count = 0
  zero_one_count = 0
  one_zero_count = 0
  dd_ba = defaultdict(int, {})
  for a,b in AB:
    if (a==0)and(b==0):
      zero_zero_count += 1
    elif (a==0):
      zero_one_count += 1
    elif (b==0):
      one_zero_count += 1
    else:
      if a * b < 0:
        a = abs(a)
        b = abs(b)
        g = gcd(a, b)
        dd_ba[(b//g, a//g)] += 1
      else:
        a = abs(a)
        b = abs(b)
        g = gcd(a, b)
        dd_ba[(-b//g, a//g)] += 1

  ans = (2**zero_one_count + 2**one_zero_count -1)
  dd_flag = defaultdict(bool, {})

  for key,value in tuple(dd_ba.items()):
    if dd_flag[key]:
      continue
    
    key_0 = key[0]
    key_1 = key[1]
    if key_0<0:
      x = (key_1, -key_0)
    else:
      x = (-key_1, key_0)
    y = dd_ba[x]
    ans *= (2**y + 2**value - 1) % MOD
    ans %= MOD
    dd_flag[x] = True

  ans += zero_zero_count - 1
  print(ans%MOD) 

if __name__=='__main__':
  main()
### BUGGY CODE ###

class Solver(object):
    def __init__(self):
        self.n = int(input())
        self.a_s = list(map(int, input().split(" ")))
        self._sadness = {}

    def solve(self):
        b = 0
        current = self.sadness(b)
        left = self.sadness(b-1)
        right = self.sadness(b+1)
        momentum = 1
        previous = 0  # -1 => left, 1 = right
        while True:
            # print("{}: {} {} {}".format(b, left, current, right))
            if (left >= current) and (right >= current):
                print(current)
                return
            elif left < right:  # go left
                if previous == -1:
                    momentum *= 2
                else:
                    momentum = 1
                b -= momentum
                previous = -1
            else:  # go right
                if previous == 1:
                    momentum *= 2
                else:
                    momentum = 1
                b += momentum
                previous = 1
            current = self.sadness(b)
            left = self.sadness(b-1)
            right = self.sadness(b+1)
        
    def sadness(self, b):
        if b not in self._sadness:
            self._sadness[b] = sum(abs(self.a_s[i] - (b+i+1)) for i in range(self.n))
        return self._sadness[b]


if __name__ == "__main__":
    s = Solver()
    s.solve()

### FIXED CODE ###

class Solver(object):
    def __init__(self):
        self.n = int(input())
        self.a_s = list(map(int, input().split(" ")))
        self._sadness = {}

    def solve(self):
        array = self.a_s.copy()
        for i in range(self.n):
            array[i] -= i + 1
        array.sort()
        b = array[len(array) // 2]
        print(self.sadness(b))
        
    def sadness(self, b):
        if b not in self._sadness:
            self._sadness[b] = sum(abs(self.a_s[i] - (b+i+1)) for i in range(self.n))
        return self._sadness[b]


if __name__ == "__main__":
    s = Solver()
    s.solve()
### BUGGY CODE ###

h,w = map(int,input().split())
x = []
for i in range(h):
    x.append(input())

l = [[0]*w for i in range(h)]
r = [[0]*w for i in range(h)]
u = [[0]*w for i in range(h)]
d = [[0]*w for i in range(h)]

for i in range(h):
    c = 0
    for j in range(w):
        if x[i][j] == '.':
            l[i][j] = c
            c += 1
        else: c=0


for i in range(h):
    c = 0
    for j in range(w):
        if x[i][w-1-j] == '.':
            r[i][w-1-j] = c
            c += 1
        else: c=0

for i in range(w):
    c = 0
    for j in range(h):
        if x[j][i] == '.':
            u[j][i] = c
            c += 1
        else: c=0

for i in range(w):
    c = 0
    for j in range(h):
        if x[h-1-j][i] == '.':
            d[h-1-j][i] = c
            c += 1
        else: c=0

ans = 0
for i in range(h):
    for j in range(w):
        c = l[i][j]+r[i][j]+u[i][j]+d[i][j]
        if x[i][j]=='.':c+=1
        ans = max(ans,c)

print(ans)

### FIXED CODE ###

h,w = map(int,input().split())
x = []
for i in range(h):
    x.append(input())

l = [[0]*w for i in range(h)]
r = [[0]*w for i in range(h)]
u = [[0]*w for i in range(h)]
d = [[0]*w for i in range(h)]

for i in range(h):
    c = 0
    for j in range(w):
        if x[i][j] == '.':
            l[i][j] = c
            c += 1
        else: c=0


for i in range(h):
    c = 0
    for j in range(w):
        if x[i][w-1-j] == '.':
            r[i][w-1-j] = c
            c += 1
        else: c=0

for i in range(w):
    c = 0
    for j in range(h):
        if x[j][i] == '.':
            u[j][i] = c
            c += 1
        else: c=0

for i in range(w):
    c = 0
    for j in range(h):
        if x[h-1-j][i] == '.':
            d[h-1-j][i] = c
            c += 1
        else: c=0

ans = 0
for i in range(h):
    for j in range(w):
        c = l[i][j]+r[i][j]+u[i][j]+d[i][j]
        if x[i][j]=='.':c+=1
        ans = max(ans,c)

print(ans)
### BUGGY CODE ###

n = int(input())
a = 1
cnt = 0

for i in range(n//2):
  a *= (n-2*i)

while (1):
  if a % 10 == 0:
    cnt += 1
    a = a//10
  else:
    break
print(cnt)

### FIXED CODE ###

n = int(input())
fives = n
cnt = 0
cnt2 = 0

if n%2 == 0:
  while (1):
    if fives // 5 > 0:
      fives //= 5
      cnt += 1
    else:
      break

for i in range(cnt):
  cnt2 += n // (2*5**(i+1))

print(cnt2)
### BUGGY CODE ###

n = int(input())
items = []
for _ in range(n):
    s = input()
    if s not in items:
        items.append(s)
    else:
        continue
print(len(items))

### FIXED CODE ###

n = int(input())
items = {}
for _ in range(n):
    s = input()
    if s not in items:
        items.setdefault(s,1)
    else:
        items[s] +=1
print(len(items))
### BUGGY CODE ###

import sys


# sys.stdin = open('d1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    inf = 10 ** 20
    n = read_int()
    adj = [[] for u in range(n)]
    for i in range(n - 1):
        a, b, c = read_int_list()
        a -= 1
        b -= 1
        adj[a].append((b, c))
        adj[b].append((a, c))

    q, k = read_int_list()
    k -= 1
    state = [0 for u in range(n)]
    d = [inf for u in range(n)]

    state[k] = 1
    d[k] = 0
    Q = [(k, -1)]
    while Q:
        u, parent = Q.pop(0)
        for v, w in adj[u]:
            if v == parent:
                continue
            if state[v] == 0:
                state[v] = 1
                d[v] = d[u] + w
                Q.append((v, u))
                # state[u] = 2

    res = [0] * q
    for i in range(q):
        x, y = read_int_list()
        x -= 1
        y -= 1
        res[i] = d[x] + d[y]
    print(*res, sep='\n')


main()


### FIXED CODE ###

import sys
from collections import deque


# sys.stdin = open('d1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int()
    adj = [[] for u in range(n+1)]
    for i in range(n - 1):
        a, b, c = map(int, input().split())
        adj[a].append((b, c))
        adj[b].append((a, c))

    d = [0] * (n+1)
    q, k = read_int_list()

    # Q = [(k, 0, 0)]
    Q = deque([(k, 0, 0)])
    while Q:
        u, parent, dist = Q.popleft()
        for v, w in adj[u]:
            if v != parent:
                Q.append((v, u, dist+w))
        d[u] = dist

    res = [0] * q
    for i in range(q):
        x, y = map(int, input().split())
        res[i] = d[x] + d[y]
    print(*res, sep='\n')


main()
### BUGGY CODE ###

# https://atcoder.jp/contests/abc135/tasks/abc135_d

# む ず す ぎ に き あ く ん 笑

# 全探索すると最悪O(10^100000)となり宇宙が崩壊するので桁の独立性について考えてみる。
# まず文字列Sについて式を書き換える。下からi桁目の数字をSi、len(S)=n (桁数)とすると、
# S=S0 + S1*10 + S2*100 + S3*1000 ... となる。これは(mod 13)において
# S≡S0 + S1*10 + S2*9   + S3*12 ... (mod 13)であり、Si=='?' の中でS≡5となる通りの数を求めれば良い。という問題になる。
# 以上により、i番目の項までの余りはi-1番目の項までの余りを足して法を取り直すことで得られることがわかる。
# 具体的には桁DPなるテクニックで、dp[i][j] (n,13) ... i番目の項まで足したときに13で割った余りがjである通りの数 を更新していけば良い。

MOD = 10**9 + 7
S = input()[::-1]
n = len(S)

dp = [[0] * 13 for _ in range(n + 1)]
dp[0][0] = 1

for i, s in enumerate(S):
    mul = pow(10, i, 13)
    if s != '?':
        shift = (int(s) * mul) % 13
        for j in range(13):
            dp[i + 1][(j + shift) % 13] = dp[i][j]
    else:
        for candi in range(10):
            shift = (candi * mul) % 13
            for j in range(13):
                dp[i + 1][(j + shift) % 13] += dp[i][j] % MOD
print(dp[-1][5] % MOD)


### FIXED CODE ###

# https://atcoder.jp/contests/abc135/tasks/abc135_d

# む ず す ぎ に き あ く ん 笑

# 全探索すると最悪O(10^100000)となり宇宙が崩壊するので桁の独立性について考えてみる。
# まず文字列Sについて式を書き換える。下からi桁目の数字をSi、len(S)=n (桁数)とすると、
# S=S0 + S1*10 + S2*100 + S3*1000 ... となる。これは(mod 13)において
# S≡S0 + S1*10 + S2*9   + S3*12 ... (mod 13)であり、Si=='?' の中でS≡5となる通りの数を求めれば良い。という問題になる。
# 以上により、i番目の項までの余りはi-1番目の項までの余りを足して法を取り直すことで得られることがわかる。
# 具体的には桁DPなるテクニックで、dp[i][j] (n,13) ... i番目の項まで足したときに13で割った余りがjである通りの数 を更新していけば良い。

MOD = 10**9 + 7
S = input()[::-1]
n = len(S)

dp = [[0] * 13 for _ in range(n + 1)]
dp[0][0] = 1

for i, s in enumerate(S):
    mul = pow(10, i, 13)
    if s != '?':
        shift = (int(s) * mul) % 13
        for j in range(13):
            dp[i + 1][(j + shift) % 13] = dp[i][j]
    else:
        for candi in range(10):
            shift = (candi * mul) % 13
            for j in range(13):
                dp[i + 1][(j + shift) % 13] += dp[i][j] % MOD
print(dp[-1][5] % MOD)
### BUGGY CODE ###

n=int(input())
s=[int(input()) for i in range(n)]
for j in range(n):
    print(max(s[:j]+s[j+1:]))

### FIXED CODE ###

#134c tle
n=int(input())
s=[int(input()) for i in range(n)]
a=sorted(s)
max_=a[-1]
max_2=a[-2]
#print(s)
for i in range(n):
    if s[i]==max_:
        print(max_2)
    else:
        print(max_)
### BUGGY CODE ###

def gcd(x, y):
  if y==0: return x
  return gcd(y, x%y)
K = int(input())
res = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      res += gcd(gcd(a, b), c)
print(res)

### FIXED CODE ###

def gcd(x, y):
  if y==0: return x
  return gcd(y, x%y)
K = int(input())
res = 0
for a in range(1, K+1):
  for b in range(a, K+1):
    for c in range(b, K+1):
      if len(set([a, b, c]))==3: res += gcd(gcd(a, b), c) * 6
      elif len(set([a, b, c]))==2: res += gcd(gcd(a, b), c) * 3
      else: res += gcd(gcd(a, b), c)
print(res)
### BUGGY CODE ###

n,m = map(int,input().split())

max_L = []
min_R = []

cnt = 0
for i in range(m):
    L,R = map(int,input().split())
    max_L.append(L)
    min_R.append(R)

for i in range(1,n+1):
    if max(max_L) <= i <= min(min_R):
        cnt += 1
print(cnt)

### FIXED CODE ###

n,m = map(int,input().split())

max_L = []
min_R = []

cnt = 0
for i in range(m):
    L,R = map(int,input().split())
    max_L.append(L)
    min_R.append(R)
if max(max_L) <= min(min_R):
    print(min(min_R)-max(max_L)+1)
else:
    print(0)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
import sys

sys.setrecursionlimit(10**6)

def killme(num,lis):
    visited[num]=1
    if num==N-1:
        lis.append(num)
        for index,item in enumerate(lis):
            highway[item]=index
    else:
        for next_n in way[num]:
            if visited[next_n]==0:
                killme(next_n,lis+[num])
    return 

def dfs(num,root):
    visited[num]=1
    cluster[root].append(num)
    for next_n in way[num]:
        if visited[next_n]==0 and highway[next_n]==-1:
            #print(next_n,root)
            dfs(next_n,root)
    return 

N=int(input())

way=[[] for i in range(N)]
visited=[0]*N
highway=[-1]*N

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

killme(0,[])

#print(way)
#print(visited)
#print(highway)

visited=[0]*N
cluster=[[] for i in range(highway[-1]+1)]

for index,item in enumerate(highway):
    if item!=-1:
        dfs(index,item)

F=0
S=0
for i in range(highway[-1]+1):
    if i<=highway[-1]//2:
        F+=len(cluster[i])
    else:
        S+=len(cluster[i])

if F>S:
    print("Fennec")
else:
    print("Snuke")
#print(F,S)
    



### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys

sys.setrecursionlimit(10**6)

def killme(num,lis):
    visited[num]=1
    if num==N-1:
        lis.append(num)
        for index,item in enumerate(lis):
            highway[item]=index
    else:
        for next_n in way[num]:
            if visited[next_n]==0:
                lis.append(num)
                killme(next_n,lis)
                lis.pop(-1)
    return 

def dfs(num,root):
    visited[num]=1
    cluster[root].append(num)
    for next_n in way[num]:
        if visited[next_n]==0 and highway[next_n]==-1:
            #print(next_n,root)
            dfs(next_n,root)
    return 

N=int(input())

way=[[] for i in range(N)]
visited=[0]*N
highway=[-1]*N

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

killme(0,[])

#print(way)
#print(visited)
#print(highway)

visited=[0]*N
cluster=[[] for i in range(highway[-1]+1)]

for index,item in enumerate(highway):
    if item!=-1:
        dfs(index,item)

F=0
S=0
for i in range(highway[-1]+1):
    if i<=highway[-1]//2:
        F+=len(cluster[i])
    else:
        S+=len(cluster[i])

if F>S:
    print("Fennec")
else:
    print("Snuke")
#print(F,S)