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

n = int(input())
A = list(map(int,input().split()))
ans = 1
for i in range(n):
    ans *= A[i]

if ans <= pow(10,18):
    print(ans)
else:
    print(-1)

### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))
ans = 1
if 0 in A:
    print(0)
    exit()
for i in range(n):
    ans *= A[i]
    if ans > pow(10,18):
        print(-1)
        exit()
print(ans)
### BUGGY CODE ###

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
LRC = [lr() for _ in range(M)]
LRC.sort()
INF = 10 ** 15
dp = [INF] * (N+1) # 1-indexed
dp[1] = 0
A = set([1]) # 最小値の候補
for l, r, c in LRC:
    rmv = []
    for ri in A:
        if ri < l:
            rmv.append(ri)
        else:
            dp[r] = min(dp[r], dp[ri] + c)
    for x in rmv:
        A.remove(x)
    A.add(r)

if dp[N] == INF:
    print(-1)
else:
    print(int(dp[N]))


### FIXED CODE ###

import sys
from heapq import heapify, heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def dijkstra(start):
    dist = [INF] * (N+1)
    dist[start] = 0
    que = [(0, start)]
    while que:
        d, prev = heappop(que)
        if dist[prev] < d:
            continue
        for cost, next in graph[prev]:
            d1 = d + cost
            if dist[next] > d1:
                dist[next] = d1
                heappush(que, (d1, next))
    return dist

N, M = lr()
INF = 10 ** 15
graph = [[] for _ in range(N+1)] # 1-indexed
for i in range(2, N+1):
    graph[i].append((0, i-1))

for _ in range(M):
    l, r, c = lr()
    graph[l].append((c, r))

dist = dijkstra(1)

if dist[N] == INF:
    print(-1)
else:
    print(dist[N])
# 19
### BUGGY CODE ###

from collections import Counter
s = list(input())
s += s
t = list(input())
ls = len(s)
check = [[] for i in range(26)]
for i in range(len(s)):
    o = ord(s[i])-ord("a")

    check[o].append(i+1)
ans = 0
c1 = 0
for i in t:
    o =ord(i)-ord("a")
    if check[o]:
        com = False
        lo = len(check[o])
        for j in range(lo):
            if ans < c1*len(s)+check[o][j]:
                ans = c1*len(s)+check[o][j]
                com = True
                break   
        if not com:
            c1 += 1
            for j in range(lo):
                if ans < c1*len(s)+check[o][j]:
                    ans = c1*len(s)+check[o][j]
                    
                    com = True
                    break   

    else:
        print(-1)
        exit()
    
print(ans)


### FIXED CODE ###

import bisect
s = list(input())
t = list(input())
ls = len(s)
check = [[] for i in range(26)]
for i in range(len(s)):
    o = ord(s[i])-ord("a")

    check[o].append(i+1)
ans = 0
c1 = 0

for i in t:
    o =ord(i)-ord("a")
    if check[o]:
        x = bisect.bisect_right(check[o],ans) 
        if x == len(check[o]):
            c1 += 1
            ans = check[o][0]
        else:
            ans = check[o][x]
            

    else:
        print(-1)
        exit()
 
print(ans+c1*ls)
### BUGGY CODE ###

import numpy as np
from itertools import product

H,W,K=map(int,input().split(' '))
arr = np.vstack([[int(i) for i in input()] for j in range(H)])
ans = H+W-2
for p in product([0,1],repeat=H-1):
    sp=np.zeros((sum(p)+1,W),int)
    row=0
    sp[0]+=arr[0]
    for j in range(H-1):
        if p[j]:
            row+=1
        sp[row]+=arr[j+1]
    if np.max(sp)>K:
        continue
    sum_arr = np.zeros(len(sp),int)
    cut_cnt = sum(p)
    for c in range(W):
        sum_arr += sp[:,c]
        if max(sum_arr)>K:
            cut_cnt+=1
            sum_arr=sp[:,c]
            if cut_cnt > ans:
                break
    ans = min(cut_cnt,ans)
print(ans)

### FIXED CODE ###

import numpy as np
from itertools import product

H,W,K=map(int,input().split(' '))
arr = np.vstack([[int(i) for i in input()] for j in range(H)])
ans = H+W-2
for p in product([0,1],repeat=H-1):
    if sum(p)>ans:
        continue
    sp=np.zeros((sum(p)+1,W),int)
    row=0
    sp[0]+=arr[0]
    for j in range(H-1):
        if p[j]:
            row+=1
        sp[row]+=arr[j+1]
    if np.max(sp)>K:
        continue
    sum_arr = np.zeros(len(sp),int)
    cut_cnt = sum(p)
    for c in range(W):
        sum_arr += sp[:,c]
        if max(sum_arr)>K:
            cut_cnt+=1
            sum_arr=sp[:,c]
            if cut_cnt > ans:
                break
    ans = min(cut_cnt,ans)
print(ans)
### BUGGY CODE ###

import sys
#import math
import numpy as np
#= int(input())
#= input()
N, W = map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]

x = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(1, W + 1):
        dpi = dp[i]
        dpim = dp[i-1]
        if x[i - 1][0] <= j:
            dpi[j] = max(dpim[j], dpim[j - x[i - 1][0]] + x[i - 1][1])
        else:
            dpi[j] = dpim[j]

print(dp[-1][W])


### FIXED CODE ###

#import
#import math
#import numpy as np
#= int(input())
#= input()
N, W = map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]

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

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(1, W + 1):
        dp[i][j] = dp[i - 1][j]
        if i != 0 and x[i - 1][0] <= j:
            dp[i][j] = max(dp[i][j], dp[i-1][j-x[i-1][0]] + x[i-1][1])

print(dp[-1][W])
### BUGGY CODE ###

K = int(input())

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
    
def solution(K):
    ans = 0
    for i in range(1,K+1):
        for j in range(1,K+1):
            for k in range(1,K+1):
                ans += euclid(euclid(i,j), euclid(j,k))
    print(ans)

solution(K)


### FIXED CODE ###

K = int(input())

import functools

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def gcd(nums):
    return functools.reduce(euclid, nums)

def solution(K):
    ans = 0
    for i in range(1,K+1):
        for j in range(1,K+1):
            for k in range(1,K+1):
                num = (i,j,k)
                ans += gcd(num)
    print(ans)

solution(K)
### BUGGY CODE ###


N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

for i in range(N):
    temp = A[i]
    del A[i]
    print(max(A))
    A.insert(i, temp)


### FIXED CODE ###

import copy

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

chinpo = max(A)
B = copy.copy(A)
B.remove(max(A))
chinchin = max(B)

for i in range(A.index(max(A))):
    print(chinpo)
print(chinchin)
for i in range(A.index(max(A))+1,N):
    print(chinpo)
### BUGGY CODE ###

n,m = map(int,input().split())
a = [int(i) for i in input().split()]
a = sorted(list(set(a)))
from fractions import gcd
lc = a[0]
if n != 1:
  for num,i in enumerate(a[1:]):
    if lc == 0:
      break
    lc = lc * i // gcd(lc, i)
    if gcd(lc, i) == min(i,lc):
      for j in a[:num+1]:
        z = i//j
        if z == i/j and z%2 == 0:
          lc = 0
          break 
if lc == 0:
  print(0)
else:
  print((m+lc//2)//lc)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
a = sorted(list(set(a)))
from fractions import gcd
lc = a[0]
if n != 1:
  for num,i in enumerate(a[1:]):
    if lc == 0:
      break
    lc = lc * i // gcd(lc, i)
    if gcd(lc, i) == min(i,lc):
      for j in a[:num+1]:
        if (i/j)%2 == 0:
          lc = 0
          break 
if lc == 0:
  print(0)
else:
  print((m+lc//2)//lc)
### BUGGY CODE ###

num=int(input())
word=input()
alound=word.count("R")*word.count("G")*word.count("B")
for i in range(num-2):
  for j in range(i+1,num-1):
    k=2*j-i
    if k<=num-1:
      if word[i]!=word[j] and word[i]!=word[k] and word[k]!=word[j]:
        alound=alound-1
print(alound)
  
      

### FIXED CODE ###

num=int(input())
word=input()
alound=word.count("R")*word.count("G")*word.count("B")
for i in range(num-2):
  for j in range(i+1,num-1):
    k=2*j-i
    if k<=num-1:
      if word[i]!=word[j] and word[i]!=word[k] and word[k]!=word[j]:
        alound=alound-1
print(alound)
### BUGGY CODE ###

from collections import*
n,c=map(int,input().split())
d=defaultdict(list)
for s,t,r in sorted([tuple(map(int,input().split()))for i in range(n)],key=lambda x:x[0]):
    if len(d[r])>0:
        if d[r][-1][-1]==s:
            d[r].append((d[r].pop()[0],t))
        else:
            d[r].append((s,t))
    else:
        d[r].append((s,t))
di=[]
for i in d.values():
    di+=i
x=sorted(di,key=lambda x:x[0])
ans=0
bannpei=0
#print(x)
while len(x)>0:
    for s,t in x.copy():
        if bannpei+1<=s:
            x.remove((s,t))
            bannpei=t
#        print(bannpei)
    ans+=1
    bannpei=0
#    print(x)
print(ans)


### FIXED CODE ###

n,c=map(int,input().split())
table=[[0]*10**5for i in range(c)]
for i in range(n):
    s,t,c=map(int,input().split())
    table[c-1][s-1:t]=[1]*(t-s+1)
print(max(map(sum,zip(*table))))
### BUGGY CODE ###

g = [[0 for i in range(250)] for j in range(250)]


k = int(input())
r = range(1, k + 1)

import math
ans = 0

for a in r:
    for b in r:
        for c in r:

            if g[a][b] > 0:
                ab = g[a][b]
            else:
                ab = g[a][b] = math.gcd(a, b)
            if g[ab][c] > 0:
                ab = g[ab][c]
            else:
                ab = g[ab][c] = math.gcd(ab, c)
            ans += ab

print(ans)


### FIXED CODE ###

g = [[0 for i in range(250)] for j in range(250)]


k = int(input())
r = range(1, k + 1)

import math
ans = 0

for a in r:
    for b in r:
        for c in r:

            if g[a][b] > 0:
                ab = g[a][b]
            else:
                ab = g[a][b] = math.gcd(a, b)
            if g[ab][c] > 0:
                ab = g[ab][c]
            else:
                ab = g[ab][c] = math.gcd(ab, c)
            ans += ab

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

import copy
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))

for i in range(n):
  if a[i]==max(a):
    b=copy.deepcopy(a)
    del b[i]
    print(max(b))
  else:
    print(max(a))

### FIXED CODE ###

import copy
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
ma =max(a)
cn =0
for i in range(n):
  if a[i]==ma and cn<2:
    b=copy.deepcopy(a)
    del b[i]
    print(max(b))
    cn +=1
  else:
    print(ma)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(200005)

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, q = na()
g = []
for i in range(n):
    g.append([])
for i in range(n-1):
    a, b = na()
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

ps = [0] * n
for i in range(q):
    p, x = na()
    p -= 1
    ps[p] += x

ans = [0] * n

def dfs(cur, pre, g, curv):
    global ps, ans
    curv += ps[cur]
    ans[cur] = curv
    for e in g[cur]:
        if e == pre: continue
        dfs(e, cur, g, curv)

dfs(0, -1, g, 0)

print(" ".join(map(str, ans)))


### FIXED CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, q = na()
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = na()
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

ps = [0] * n
for i in range(q):
    p, x = na()
    p -= 1
    ps[p] += x

stack = [0] * (n+1)
inds = [0] * (n+1)

sp = 0
stack[sp] = 0
sp += 1

while sp > 0:
    cur = stack[sp-1]
    if inds[sp-1] == len(g[cur]):
        sp -= 1
        continue
    if inds[sp-1] == 0 and sp > 1:
        ps[cur] += ps[stack[sp-2]]
    if sp == 1 or stack[sp-2] != g[cur][inds[sp-1]]:
        stack[sp] = g[cur][inds[sp-1]]
        inds[sp] = 0
        inds[sp-1] += 1
        sp += 1
        continue
    inds[sp - 1] += 1

print(" ".join(map(str, ps)))
### BUGGY CODE ###

nk = input('')
n = int(nk.split()[0])
k = int(nk.split()[1])

alist = list(map(int,input('').split()))

pre=0
result=1
for i in range(k):
    result *= alist[i]
pre=result
for i in range(1,n-k+1):
    result=result * alist[i+k-1] / alist[i-1]
#    print("[{}/{}]:{}".format(i,i+k,result))
    if result > pre:
        print('Yes')
    else:
        print('No')
    pre=result


### FIXED CODE ###

nk = input('')
n = int(nk.split()[0])
k = int(nk.split()[1])

alist = list(map(int,input('').split()))

for i in range(1,n-k+1):
    removed = alist[i-1]
    inserted = alist[i+k-1]
    if inserted > removed:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

s = input()
q = int(input())
r = False
for _ in range(q):
    t = input().split()
    if len(t) == 1:
        r = not r
    else:
        t[1] = int(t[1]) - 1
        if (not t[1] and not r) or (t[1] and r):
            s = t[2] + s
        else:
            s = s + t[2]
if r:
    print(s[::-1])
else:
    print(s)


### FIXED CODE ###

from collections import deque
S = deque(list(input()))
q = int(input())
r = False
for _ in range(q):
    t = input().split()
    if len(t) == 1:
        r = not r
    else:
        t[1] = int(t[1]) - 1
        if (not t[1] and not r) or (t[1] and r):
            S.appendleft(t[2])
        else:
            S.append(t[2])
if r:
    S = list(S)
    print(''.join(S[::-1]))
else:
    print(''.join(S))
### BUGGY CODE ###

import bisect

def calc():
  n,k=map(int,input().split())
  arr=list(map(int,input().split()))
  arr=sorted(arr)
  nc=0
  zc=0
  pc=0
  for i in range(n):
    if arr[i]<0:
      nc+=1
    elif arr[i]==0:
      zc+=1
    else:
      pc+=1
  ncc=nc*pc
  zcc=zc*(nc+pc)+(zc*(zc-1))//2
  pcc=(nc*(nc-1))//2+(pc*(pc-1))//2
  if k<=ncc:
    arr1=[]
    arr2=[]
    for i in range(n):
      if arr[i]<0:
        arr1.append(-arr[i])
      elif arr[i]>0:
        arr2.append(arr[i])
    arr1=arr1[::-1]
    c1=len(arr1)
    c2=len(arr2)
    k=ncc-k
    l=0
    r=10**18+1
    while r-l!=1:
      mid=(l+r)//2
      cnt=0
      for i in range(c1):
        cnt+=bisect.bisect_right(arr2,mid//arr1[i])
      if cnt>k:
        r=mid
      else:
        l=mid
    print(-r)
  elif k<=(ncc+zcc):
    print(0)
  else:
    arr1=[]
    arr2=[]
    for i in range(n):
      if arr[i]<0:
        arr1.append(-arr[i])
      elif arr[i]>0:
        arr2.append(arr[i])
    arr1=arr1[::-1]
    c1=len(arr1)
    c2=len(arr2)
    l=0
    r=10**18+1
    k-=(ncc+zcc)
    while r-l!=1:
      mid=(l+r)//2
      cnt1=0
      for i in range(c1):
        tmp=bisect.bisect_right(arr1,mid//arr1[i])
        if arr1[i]**2<mid:
          tmp-=1
        cnt1+=tmp
      cnt1=cnt1//2
      cnt2=0
      for i in range(c2):
        tmp=bisect.bisect_right(arr2,mid//arr2[i])
        if arr2[i]**2<mid:
          tmp-=1
        cnt2+=tmp
      cnt2=cnt2//2
      cnt=cnt1+cnt2
      if cnt>=k:
        r=mid
      else:
        l=mid
    print(r)
calc()

### FIXED CODE ###

#incited numpy source code from 'https://atcoder.jp/contests/abc155/submissions/10155744'

import numpy

n,k=map(int,input().split())
arr=list(map(int,input().split()))
nc=0
zc=0
pc=0
for i in range(n):
  if arr[i]<0:
    nc+=1
  elif arr[i]==0:
    zc+=1
  else:
    pc+=1
ncc=nc*pc
zcc=zc*(nc+pc)+(zc*(zc-1))//2
pcc=(nc*(nc-1))//2+(pc*(pc-1))//2
if ncc<k<=(ncc+zcc):
  print(0)
else:
  arr=numpy.array(arr,dtype=int)
  ms=numpy.msort(numpy.abs(arr[arr<0]))
  ps=numpy.msort(arr[arr>0])
  if k<=ncc:
    k=ncc-k
    l=0
    r=10**18+1
    while r-l!=1:
      mid=(l+r)//2
      cnt=numpy.searchsorted(ps,mid//ms,side='right')
      if cnt.sum()>k:
        r=mid
      else:
        l=mid
    print(-r)
  elif k<=(ncc+zcc):
    print(0)
  else:
    l=0
    r=10**18+1
    k-=(ncc+zcc)
    while r-l!=1:
      mid=(l+r)//2
      cnt1=numpy.searchsorted(ps,mid//ps,side='right')
      dup1=ps**2<=mid
      cnt2=numpy.searchsorted(ms,mid//ms,side='right')
      dup2=ms**2<=mid
      if (cnt1.sum()-dup1.sum()+cnt2.sum()-dup2.sum())//2>=k:
        r=mid
      else:
        l=mid
    print(r)
### BUGGY CODE ###

import itertools
from collections import Counter
n=int(input())
S = [list(input()) for i in range(n)]
tmp=S[0]
for i in range(1,n):
    tmp=list((Counter(S[i]) & Counter(tmp)).elements())

anagram_list = [''.join(v) for v in itertools.permutations(tmp)]

print(anagram_list[0])

### FIXED CODE ###

import itertools
from collections import Counter
n=int(input())
S = [list(input()) for i in range(n)]
tmp=S[0]
for i in range(1,n):
    tmp=list((Counter(S[i]) & Counter(tmp)).elements())

print(''.join(sorted(tmp)))
### BUGGY CODE ###

import sys

input = sys.stdin.readline

def search(r):
    while root[r] != r: r = root[r]
    return r
        
def rebuild(r, n):
    while root[r] != r: root[r], r = n, root[r]
    
N, M = map(int, input().split())
p = list(map(int, input().split()))

root = {i:i for i in range(1, N+1)}
size = {i:1 for i in range(1, N+1)}

for i in range(M):
    x, y = map(int, input().split())
    x, y = p[x-1], p[y-1]
    
    x_r, y_r = search(x), search(y)
    if x_r == y_r: continue

    root[x_r] = y_r
    size[y_r] = max(size[y_r], size[x_r])
    
    if size[y_r] > 10:
        rebuild(x, y_r)
        rebuild(y, y_r)
        size[y_r] = 1
    
ans = 0

for i, j in enumerate(p):
    if search(i+1) == search(j): ans += 1
print(ans)

### FIXED CODE ###

def find(x):
    while union[x] != x:
        x = union[x]
        
    return x

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

union = [i for i in range(N+1)]

for i in range(M):
    x, y = map(int, input().split())
    x = find(x)
    while union[y] != y:
        union[y], y = x, union[y]
        
    union[y] = x
    
ans = 0
for idx, n in enumerate(p):
    if idx+1 == n:
        ans += 1
    else:
        x, y = find(idx+1), find(n)
        if x == y:
            ans += 1
        
print(ans)
### BUGGY CODE ###

n=int(input())

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

X=list(set(A))

RES=[]

for i in X:
    a=A.count(i-1)
    b=A.count(i)
    c=A.count(i+1)
    RES.append(a+b+c)
    
print(max(RES))

### FIXED CODE ###

import collections
n=int(input())

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

a=collections.Counter(A)

X=sorted(a.items(), key=lambda x:x[0])

K=[]
V=[]

RES=[]
for i in range(len(X)):
    K.append(X[i][0])
    V.append(X[i][1])

if len(X)>=3:
    for j in range(1,len(X)-1):
        res=V[j]
        if K[j]-1==K[j-1]:
            res+=V[j-1]
        if K[j]+1==K[j+1]:
            res+=V[j+1]
        RES.append(res)
elif len(X)==2:
    if K[0]+1==K[1]:
        RES.append(V[0]+V[1])
    else:
        RES.append(max(V))
else:
    RES.append(V[0])        

print(max(RES))
### BUGGY CODE ###

N,A,B,K = map(int,input().split())
MOD = 998244353

fac = [1,1]
finv = [1,1]
inv = [0,1]
for i in range(2,N+10):
    fac.append(fac[i-1] * i % MOD)
    inv.append(-inv[MOD%i] * (MOD // i) % MOD)
    finv.append(finv[i-1] * inv[i] % MOD)

def ncr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

ans = 0
for a in range(N+1):
    if a*A > K: break
    rem = K-a*A
    if rem%B: continue
    b = rem//B
    for green in range(min(a,b) + 1):
        red = a - green
        blue = b - green
        if red + green + blue > N: continue
        tmp = 1
        tmp *= ncr(N, red+green+blue)
        tmp *= ncr(red+green+blue, green+blue)
        tmp *= ncr(green+blue, blue)
        ans += tmp % MOD
print(ans % MOD)

### FIXED CODE ###

N,A,B,K = map(int,input().split())
if A<B: A,B = B,A
MOD = 998244353

def mul(a,b):
    return (a*b) % MOD

def pow(a,n): # a^n
    ret = 1
    mag = a
    while n > 0:
        if n & 1:
            ret = mul(ret, mag)
        mag = mul(mag, mag)
        n >>= 1
    return ret

def inv(a):
    return pow(a, MOD-2)

fac = [1]
fac_inv = [1]
for n in range (1,N+10):
    f = mul(fac[n-1], n)
    fac.append(f)
    fac_inv.append(inv(f))

mem = [0] * (N+1)
def ncr(n,r):
    if mem[r] > 0:
        return mem[r]
    else:
        ret = mul(mul(fac[n], fac_inv[n-r]), fac_inv[r])
        mem[r] = ret
        return ret

ans = 0
for a in range(N+1):
    if a*A > K: break
    rem = K-a*A
    if rem%B: continue
    b = rem//B
    if b > N: continue
    ans += mul(ncr(N,a), ncr(N,b))
print(ans % MOD)
### BUGGY CODE ###

N, K = map(int, input().split())
ans = int(N)
while (N > 0):
    N = N - K
    # print(N)
if ans > abs(N):
    ans = abs(N)
print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
ans = int(N)
N_1 = N
N_2 = N
k_range = N // K
# print(k_range)

if k_range == 0:
    N = N - K
    if ans > abs(N):
        ans = abs(N)
else:
    N_1 = N - (K * k_range)
    N_2 = N - (K * (k_range + 1))

if abs(N_1) < abs(N_2):
    if ans > abs(N_1):
        ans = abs(N_1)
    else:
        pass
else:
    if ans > abs(N_2):
        ans = abs(N_2)
    else:
        pass
print(ans)
### BUGGY CODE ###

n=int(input())

tree=[[] for _ in range(n)]

for _ in range(n-1):
    u,v=map(int,input().split())
    tree[u-1].append(v-1)
    tree[v-1].append(u-1)

ans=0

for l in range(n):

    num_hen=0
    for r in range(l,n):
        
        for item in tree[r]:
            if item>=l and r>=item:
                num_hen+=1
        #print(l+1,r+1,(r-l+1)-num_hen)
        ans+=((r-l+1)-num_hen)

print(ans)




### FIXED CODE ###

n=int(input())

num_chouten=0

for i in range(n):
    num_chouten+=((i+1)*(n-i))

num_hen=0
for _ in range(n-1):
    u,v=map(int,input().split())

    minnum=min(u,v)
    maxnum=max(u,v)

    num_hen+=minnum*(n-maxnum+1)

print(num_chouten-num_hen)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
cnt = []
for i in range(N):
    print(A.count(i+1))

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
for i in range(N):
    print(cnt[i+1])
### BUGGY CODE ###

N, *m=map(int, open(0).read().split())

im = iter(m)
UVW = list(zip(im, im, im))

# set default color to -1

colors = {i:-1 for i in range(1,N+1)}
u,v,w = UVW[0]
colors[u] = 0

def opposite(u, v):
    if v == -1:
        return u
    if v == 0:
        return 1
    if v == 1:
        return 0

def same(u, v):
    if v == -1:
        return u
    else:
        return v

while -1 in colors.values():
    for u, v, w in UVW:
        if w % 2 == 0:
            colors[u] = same(colors[u], colors[v])
            colors[v] = same(colors[v], colors[u])

        if w % 2 == 1:
            colors[u] = opposite(colors[u], colors[v])
            colors[v] = opposite(colors[v], colors[u])



for i in range(1, N+1):
    print(colors[i])

### FIXED CODE ###

N = int(input())

u_list = []
v_list = []
w_list = []

for _ in range(N-1):
  u, v, w = map(int, input().split())
  u_list.append(u-1)
  v_list.append(v-1)
  w_list.append(w)
  
color_dict = dict()
uvw_list = list(zip(u_list, v_list, w_list))
color_dict[u_list[0]] = 1

def eval_single(u, v, w, color_dict):
  skip = True

  if u in color_dict:
    color_dict[v] = assign_color(color_dict[u], w)
    skip = False
    
  if v in color_dict:
    color_dict[u] = assign_color(color_dict[v], w)
    skip = False
    
  return skip, color_dict
  

def assign_color(color, w):
  if w%2==0:
    return color
  else:
    return color*(-1)+1
  
while True:
  ind_list = []
  for ind, (u, v, w) in enumerate(uvw_list):
    skip, color_dict = eval_single(u, v, w, color_dict)
    
    if skip:
      ind_list.append(ind)

  uvw_list = [uvw_list[ind] for ind in ind_list]
  
  if len(color_dict) == N:
    break

for i in range(N):
  print(color_dict[i])
### BUGGY CODE ###

N=int(input())
S=1
for i in range(1,N):
  p=str(i+1)
  l=0
  c=0
  for j in range(1,i+2):
    q=str(j)
    if p[0]==q[-1] and p[-1]==q[0]:
      if j==i+1:
        l=1
      else:
        c=c+1
  S=S+2*c+l
print(S)

### FIXED CODE ###

N=int(input())
c=[[0 for z in range(10)] for z in range(10)] #c[i][j]=1以上N以下の整数で先頭i末尾jとなる数字の個数
for i in range(1,10):
  for j in range(1,10):
    for k in range(1,N+1):
      k=str(k)
      if k[0]==str(i) and k[-1]==str(j):
        c[i][j]=c[i][j]+1
S=0
for i in range(1,10):
  for j in range(1,10):
    S=S+c[i][j]*c[j][i]
print(S)