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

import itertools as it
import numpy as np

N = int(input())

A = list(map(int, input().split()))
ans = 0
for i in range(N):
    for j in range(N):
        if j-i == A[i] + A[j]:
            ans += 1

print(ans)

### FIXED CODE ###

from collections import Counter
N = int(input())

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

plus = []
minus = []

for i, j in enumerate(A):
    # print(i, j)
    plus.append(i+j)
    minus.append(i-j)

# print(plus)
# print(minus)

plus_count = Counter(plus)
minus_count = Counter(minus)
# print(plus_count)
# print(minus_count)


for i,j in plus_count.items():
    # print(i, j)
    if i in minus_count:
        ans += j * minus_count[i]
        # print(i, j)
print(ans)
### BUGGY CODE ###

from heapq import heapify, heappop, heappush


N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)


def isPossible(i):
    a = list(A)
    i = a.index(a[i])
    if i < P:
        return True
    numVotes = V
    a[i] += M
    score = a[i]
    numVotes -= 1
    if a[P - 1] > score:
        return False
    for j in range(N):
        if numVotes:
            if j < P - 1 or j > i:
                a[j] += M
                numVotes -= 1
        else:
            break
    if numVotes:
        heap = a[P - 1 : i]
        heapify(heap)
        for j in range(M):
            temp = []
            for k in range(numVotes):
                temp.append(heappop(heap))
            for x in temp:
                heappush(heap, x + 1)
        return max(heap) <= score
    return True


if not isPossible(0):
    print(0)
elif isPossible(N - 1):
    print(N)
else:
    lo = 0
    hi = N - 1
    assert isPossible(lo)
    assert not isPossible(hi)
    while hi - lo > 1:
        mid = (lo + hi) // 2
        if isPossible(mid):
            lo = mid
        else:
            hi = mid
    assert isPossible(lo)
    assert not isPossible(lo + 1)
    print(lo + 1)


### FIXED CODE ###

N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)


def isPossible(i):
    # Get highest rank with the same score
    i = A.index(A[i])

    # If already high rank, can vote top V to keep relative ordering
    if i < P:
        return True

    numVotes = V
    # Otherwise have every judge vote for i-th first
    # Each judge has V - 1 votes remaining
    score = A[i] + M
    numVotes -= 1
    # This is the best possible rank (more voting can only decrease rank)
    # If it isn't good enough, return early
    if A[P - 1] > score:
        return False
    # Soak up votes by voting for everything after i-th
    # Since adding M to everything, they will still be smaller
    numVotes -= N - i - 1
    # Soak up more votes by voting for everything in the top P - 1
    # Our element just needs to be within top P even if it's last
    numVotes -= P - 1
    if numVotes > 0:
        # If there are any votes remaining, it will be for indices P-1 thru i-1
        # We currently have:
        # A[i] + M >= A[P-1] >= A[P-2] >= ... >= A[i - 1] > A[i]
        # We want to distribute the remaining votes so that none of these become
        # greater than A[i] + M
        remainingVotes = numVotes * M
        gap = sum(score - x for x in A[P - 1 : i])
        return gap >= remainingVotes
    return True


if not isPossible(0):
    print(0)
elif isPossible(N - 1):
    print(N)
else:
    # If i-th is possible, so is 0th to (i-1)th
    # So binary search for the last index possible
    lo = 0
    hi = N - 1
    assert isPossible(lo)
    assert not isPossible(hi)
    while hi - lo > 1:
        mid = (lo + hi) // 2
        if isPossible(mid):
            lo = mid
        else:
            hi = mid
    assert isPossible(lo)
    assert not isPossible(lo + 1)
    # If index i is possible, there are i+1 possible problems
    print(lo + 1)
### BUGGY CODE ###

H, W = list(map(int, input().split()))
A = [input() for _ in range(H)]
b = "#"
w = "."

wc = 0
L = []
wb = [[0] * W for _ in range(H)]
for i in range(H):
  for j in range(W):
    if A[i][j] == w:
      wc += 1
    else:
      L.append([i, j])
      wb[i][j] = 1

Ans = 0
while wc > 0:
  L2 = []
  Ans += 1
  for ki, kj in L:
    if ki - 1 >= 0:
      if wb[ki - 1][kj] == 0:
        wb[ki - 1][kj] = 1
        wc -= 1
        L2.append([ki - 1 , kj])
    if ki + 1 < H:
      if wb[ki + 1][kj] == 0:
        wb[ki + 1][kj] = 1
        wc -= 1
        L2.append([ki + 1 , kj])
    if kj - 1 >= 0:
      if wb[ki][kj - 1] == 0:
        wb[ki][kj - 1] = 1
        wc -= 1
        L2.append([ki, kj - 1])
    if kj + 1 < W:
      if wb[ki][kj + 1] == 0:
        wb[ki][kj + 1] = 1
        wc -= 1
        L2.append([ki, kj + 1])
  L = L2
print(Ans)

### FIXED CODE ###

H, W = list(map(int, input().split()))
A = [input() for _ in range(H)]
b = "#"
w = "."

wc = 0
L = []
wb = [[0] * W for _ in range(H)]
for i in range(H):
  for j in range(W):
    if A[i][j] == w:
      wc += 1
    else:
      L.append([i, j])
      wb[i][j] = 1

Ans = 0
while wc > 0:
  L2 = []
  Ans += 1
  for ki, kj in L:
    if ki - 1 >= 0:
      if wb[ki - 1][kj] == 0:
        wb[ki - 1][kj] = 1
        wc -= 1
        L2.append([ki - 1 , kj])
    if ki + 1 < H:
      if wb[ki + 1][kj] == 0:
        wb[ki + 1][kj] = 1
        wc -= 1
        L2.append([ki + 1 , kj])
    if kj - 1 >= 0:
      if wb[ki][kj - 1] == 0:
        wb[ki][kj - 1] = 1
        wc -= 1
        L2.append([ki, kj - 1])
    if kj + 1 < W:
      if wb[ki][kj + 1] == 0:
        wb[ki][kj + 1] = 1
        wc -= 1
        L2.append([ki, kj + 1])
  L = L2
print(Ans)
### BUGGY CODE ###

import re

s = input()
pattern = "(01)|(10)"
count = 0
while re.search(pattern,s):
    l = re.findall(pattern,s)
    count += len(l)*2
    s = re.sub(pattern, "", s)

print(count)

### FIXED CODE ###

import re

s = input()
zero = re.findall("0", s)
one = re.findall("1", s)
print(2 * min(len(zero), len(one)))
### BUGGY CODE ###

X, K, D = map(int, input().split())
X = abs(X)
for i in range(K):
    if X >= D:
        X = X-D
    elif abs(X) < D and (K-i)%2==1:
        X = X-D
        break
    elif X < D and (K-i)%2==0:
        break
print(abs(X))

### FIXED CODE ###

X, K, D = map(int, input().split())
X = abs(X)
dis = X
if X >=D:
    dis = X - D*(min(abs(X)//D,K))
    K = K - min(abs(X)//D,K)
    if K%2==0:
        print(dis)
    else:
        print(abs(dis-D))
else:
    if K%2==0:
        print(dis)
    else:
        print(abs(dis-D))
### BUGGY CODE ###

from itertools import product

N, A = map(int, input().split())
x = [int(x) for x in input().split()]

max_x = max(max(x), A)
dp = [[[0 for _ in range((N + 1) * max_x)] for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 1

for j, k, s in product(range(1, N + 1), range(N + 1), range((N + 1) * max_x)):
    if s < x[j - 1]:
        dp[j][k][s] = dp[j - 1][k][s]
    elif k >= 1 and s >= x[j - 1]:
        dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]]

ans = 0
for k in range(1, N + 1):
    ans += dp[N][k][k * A]
print(ans)

### FIXED CODE ###

from itertools import product

N, A = map(int, input().split())
x = [int(x) for x in input().split()]

X = max(max(x), A)
dp = [[0 for _ in range(2 * N * X + 1)] for _ in range(N + 1)]
dp[0][N * X] = 1

for j, t in product(range(1, N + 1), range(2 * N * X + 1)):
    y = x[j - 1] - A
    if t - y < 0 or t - y > 2 * N * X:
        dp[j][t] = dp[j - 1][t]
    elif 0 <= t - y <= 2 * N * X:
        dp[j][t] = dp[j - 1][t] + dp[j - 1][t - y]
print(dp[N][N * X] - 1)
### BUGGY CODE ###

n=int(input())

a = list(input().split())
a = [int(i) for i in a]
ans=1
for i in a:
  ans = ans*i

if ans > 10**18:
  print('-1')
else:
  print(ans)

### FIXED CODE ###

n=int(input())

a = list(input().split())
a = [int(i) for i in a]
ans=1


if 0 in a:
  pass

elif len(a) % 2 == 1: 
  for i in range(1, int(len(a)/2)+2):
    #print(ans)
    if ans > 10**18 or ans == 0:
      break
    if i == int(len(a)/2) + 1:
      ans = ans*a[i-1]
    else:
      ans = ans*a[i-1]*a[-1*i]
    
else:
  for i in range(0, int(len(a)/2)):
    if ans > 10**18 or ans == 0:
      break
    ans = ans*a[i]*a[-1 - i]
    

if ans > 10**18:
  print('-1')
elif 0 in a:
  print(0)
else:
  print(ans)
### BUGGY CODE ###

n = int(input())

S = []
for i in range(n):
    s = input()
    s = sorted(list(s))
    s = str(s)
    S.append(s)

T = set(S)

ans = 0
cnt = [S.count(T.pop()) for i in range(len(T))]
for c in cnt:
    for i in range(c):
        ans += i

print(ans)

### FIXED CODE ###

n = int(input())

cnt = {}
for i in range(n):
    s = input()
    s = sorted(list(s))
    s = str(s)
    if s not in cnt:
        cnt[s] = 0
    else:
        cnt[s] += 1

ans = 0
for c in cnt.values():
    ans += c * (c+1) // 2

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

# -*- coding: utf-8 -*-

N, K = map(int, input().split())
xi = list(map(int, input().split()))


kouho = []
for i in range(N-K+1):
    kouho.append(xi[i:i+K])

# print(kouho)
ans_list = []
for li in kouho:
    if li[0]*li[-1] < 0:
        ans_list.append(abs(li[0])*2 + abs(li[-1]))
        ans_list.append(abs(li[-1])*2 + abs(li[0]))
    elif li[0] < 0:
        ans_list.append(abs(li[0]))
    else: #if li[-1] > 0:
        ans_list.append(abs(li[-1]))

print(min(ans_list))


### FIXED CODE ###

# -*- coding: utf-8 -*-

N, K = map(int, input().split())
xi = list(map(int, input().split()))

ans_list = []
for i in range(N-K+1):
    l = xi[i]
    r = xi[i+K-1]
    if l*r < 0:
        a = abs(l)*2 + abs(r)
        b = abs(r)*2 + abs(l)
        if a > b :
            ans_list.append(b)
        else:
            ans_list.append(a)
    elif l < 0:
        ans_list.append(abs(l))
    else: #if li[-1] > 0:
        ans_list.append(abs(r))

print(min(ans_list))
### BUGGY CODE ###

import heapq
from collections import defaultdict
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def dijkstra(s, VC):
    color = [WHITE for i in range(N)]
    d = [INFTY for i in range(N)]
    d[s] = 0
    pq = []
    heapq.heappush(pq, (0, s))

    while len(pq) != 0:
        u = heapq.heappop(pq)[1]
        color[u] = BLACK

        for v, c in VC[u]:
            if color[v] != BLACK:
                if d[u] + c < d[v]:
                    d[v] = d[u] + c
                    color[v] = GRAY
                    heapq.heappush(pq, (d[v], v))

    return d

N, M, S, T = map(int, input().split())
# VA = [[] for i in range(N)]
# VB = [[] for i in range(N)]
VA = defaultdict(list)
VB = defaultdict(list)
for i in range(M):
    u, v, a, b = list(map(int, input().split()))
    VA[u-1].append([v-1, a,])
    VA[v-1].append([u-1, a])
    VB[u-1].append([v-1, b])
    VB[v-1].append([u-1, b])

da = dijkstra(S-1, VA)
db = dijkstra(T-1, VB)
tmp = 10**16
base = 10 ** 15
ans = [0 for i in range(N)]
for i in range(N-1, -1, -1):
    tmp = min(da[i] + db[i], tmp)
    ans[i] = tmp

for i in range(N):
    print(base - ans[i])


### FIXED CODE ###

import heapq
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def dijkstra(s, VC):
    color = [WHITE for i in range(N)]
    d = [INFTY for i in range(N)]
    d[s] = 0
    pq = []
    heapq.heappush(pq, (0, s))

    while len(pq) != 0:
        u = heapq.heappop(pq)[1]
        color[u] = BLACK

        for v, c in VC[u]:
            if color[v] != BLACK:
                if d[u] + c < d[v]:
                    d[v] = d[u] + c
                    color[v] = GRAY
                    heapq.heappush(pq, (d[v], v))

    return d

N, M, S, T = map(int, input().split())
VA = [[] for i in range(N)]
VB = [[] for i in range(N)]
for i in range(M):
    u, v, a, b = list(map(int, input().split()))
    VA[u-1].append([v-1, a,])
    VA[v-1].append([u-1, a])
    VB[u-1].append([v-1, b])
    VB[v-1].append([u-1, b])

da = dijkstra(S-1, VA)
db = dijkstra(T-1, VB)
tmp = 10**16
base = 10 ** 15
ans = [0 for i in range(N)]
for i in range(N-1, -1, -1):
    tmp = min(da[i] + db[i], tmp)
    ans[i] = tmp

for i in range(N):
    print(base - ans[i])
### BUGGY CODE ###

def main():
    N = int(input())
    for n in range(1, 3501):
        for h in range(1, 3501):
            denom = 4*n*h - N*n - N*h
            if denom == 0:
                continue
            w = (N*h*n) / denom
            if w == int(w) and w > 0:
                print(int(n), int(h), int(w))
                return
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N = int(input())
    for n in range(1, 3501):
        for h in range(1, 3501):
            denom = 4*n*h - N*n - N*h
            if denom == 0:
                continue
            w = (N*h*n) / denom
            if w == int(w) and w > 0:
                print(int(n), int(h), int(w))
                return
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

H,W=map(int, input().split())
DINF = 100000
d = [ [ DINF for _ in range(W+2)] for _ in range(H+2)]
S = []
S.append('#' * (W+2))
for i in range(H):
    S.append('#'+ input() + '#')
S.append('#' * (W+2))
dmax = 0
G = [ [ [] for _ in range(W+2)] for _ in range(H+2)]
for y in range(1,H+1):
    for x in range(1,W+1):
        if (S[y-1][x] == '.'):  G[y][x].append([y-1,x])
        if (S[y][x-1] == '.'):  G[y][x].append([y,x-1])
        if (S[y+1][x] == '.'):  G[y][x].append([y+1,x])
        if (S[y][x+1] == '.'):  G[y][x].append([y,x+1])

def SUB(x,y,n):
    d[y][x] = n
    for v in G[y][x]:
        if d[v[0]][v[1]] > n+1:
            SUB(v[1],v[0],n+1)

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == '.':
            SUB(x,y,0)
            for iy in range(1,H+1):
                for ix in range(1,W+1):
                    if d[iy][ix] != DINF:
                        dmax = max(dmax, d[iy][ix])
                    d[iy][ix] = DINF
print(dmax)





### FIXED CODE ###

from collections import deque

def mk_idx(y,x):
    return y*22+x

H,W=map(int, input().split())
DINF = 100000
S = []
S.append('#' * (W+2))
for i in range(H):
    S.append('#'+ input() + '#')
S.append('#' * (W+2))
dmax = 0
G = [ [] for _ in range( mk_idx(22,22) ) ]
for y in range(1,H+1):
    for x in range(1,W+1):
        if (S[y][x] == '.'):
            if (S[y-1][x] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y-1,x) )
            if (S[y][x-1] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y,x-1) )
            if (S[y+1][x] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y+1,x) )
            if (S[y][x+1] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y,x+1) )

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == '.':
            d = [ DINF for _ in range( mk_idx(22,22) ) ]
            d[ mk_idx(y,x) ] = 0
            q = deque( [mk_idx(y,x)] )
            while len(q) != 0:
                v = q.popleft()
                n = d[v];
                dmax = max(dmax, n)
                for nv in G[v]:
                    if d[ nv ] <= n+1 :
                        continue
                    d[ nv ] = n+1
                    q.append(nv)
print(dmax)
### BUGGY CODE ###

def main():
    MOD = 10 ** 9 + 7
    N, M = map(int, input().split())
    S = tuple(map(int, input().split()))
    T = tuple(map(int, input().split()))
    l = [[0] * (M + 1) for _ in range(N + 1)]
    r = [[0] * (M + 1) for _ in range(N + 1)]
    r[0][0] = 1
    l[0] = [1] * (M + 1)
    for i in range(N + 1):
        l[i][0] = 1
    for i in range(1, N+1):
        for j in range(1, M+1):
            if S[i-1] == T[j-1]:
                r[i][j] = l[i-1][j-1]
            l[i][j] = r[i][j] + l[i][j-1] + l[i-1][j] - l[i-1][j-1]
    print(sum(sum(i) for i in r) % MOD)
main()


### FIXED CODE ###

def main():
    MOD = 10 ** 9 + 7
    N, M = map(int, input().split())
    S = tuple(map(int, input().split()))
    T = tuple(map(int, input().split()))
    l = [[0] * (M + 1) for _ in range(N + 1)]
    l[0] = [1] * (M + 1)
    for i in range(N + 1):
        l[i][0] = 1
    r = 1
    for i in range(1, N+1):
        for j in range(1, M+1):
            if S[i-1] == T[j-1]:
                r += l[i-1][j-1]
                l[i][j] = l[i][j-1] + l[i-1][j]
                l[i][j] %= MOD
            else:
                l[i][j] = l[i][j-1] + l[i-1][j] - l[i-1][j-1]
        r %= MOD
    print(r % MOD)
main()
### BUGGY CODE ###

def main():
    N = int(input())
    S = list(input())
    ans = 0
    for i in range(N):
        first_s = S[i]
        # print(first_s)
        for j in range(i+1, N):
            if S[j] != first_s:
                second_s = S[j]
                # print(second_s)
                for k in range(j+1, N):
                    if (S[k] != first_s) and (S[k] != second_s):
                        if not k == 2*j-i:
                            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

N = int(input())
S = list(input())

r, g, b = 0, 0, 0
ans = 0
for i in range(N):
    if S[i] == 'R':
        r += 1
    elif S[i] == 'G':
        g += 1
    else:
        b += 1

ans += r*g*b

for i in range(N):
    for j in range(i+1, N):
        if 2*j-i < N:
            if (S[i] != S[j]) and (S[j] != S[2*j-i]) and (S[i] != S[2*j-i]):
                ans -= 1

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

N, M = map(int, input().split())
P, Y = [], []
pref = [[] for _ in range(N+1)] # non-0-indexed
for m in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
    pref[p].append(y)

    
for p,y in zip(P,Y):
    ans = "{:0>6}".format(p)
    for i,yy in enumerate(sorted(pref[p])):
        if y==yy:
            ans += "{:0>6}".format(i+1)
    print(ans)
            
        
    


### FIXED CODE ###

import bisect
N, M = map(int, input().split())
P, Y = [], []
pref = [[] for _ in range(N+1)] # non-0-indexed
for m in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
    pref[p].append(y)

for i,pre in enumerate(pref):
    pref[i] = sorted(pre)

for p,y in zip(P,Y):
    a = "{:0>6}".format(p)
    i = bisect.bisect(pref[p], y)
    a += "{:0>6}".format(i)
    print(a)
### BUGGY CODE ###

s=input()

d=[0]*2019
dp=0
d[0]+=1
l=len(s)
r=1

for i in range(l):
	dp+=int(s[l-1-i])*r
	dp%=2019
	r*=10%2019
	d[dp]+=1

res=0

for a in d:
	res+=a*(a-1)//2
	
print(res)

### FIXED CODE ###

s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(300000)
from collections import Counter
def divisors(n, sort=False):
    """
    nの約数をO(√n)で列挙する
    """
    d = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            d.append(i)
            if i != n // i:
                d.append(n//i)
    if sort:
        d.sort()
    return d
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
A = LMI()

div = set(A)
cnt = Counter(A)
ans = 0
for a in A:
    flg = True
    for d in divisors(a):
        if d == a:
            if cnt[a] >= 2:
                flg = False
                break
        elif d in div:
            flg = False
            break
    if flg:
        ans += 1
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(300000)
from collections import Counter

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
A = LMI()

div = set(A)
cnt = Counter(A)
M = max(A)
ng = [False] * (M + 1)
for a in A:
    n = a * 2
    while n <= M:
        ng[n] = True
        n += a
ans = 0
for a in A:
    if cnt[a] >= 2:
        continue
    if ng[a]:
        continue
    ans += 1

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

import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(n, cnt, aoki, aoki_visited, edge):
  aoki_visited[n] = True
  aoki[n] = cnt
  for x in edge[n]:
    if aoki_visited[x] == False:
      tami(x, cnt+1, aoki, aoki_visited, edge)

def tami2(n, cnt, choku, choku_visited, edge, aoki):
  choku_visited[n] = True
  if cnt <= aoki[n]:
    choku[n] = cnt
    for x in edge[n]:
      if choku_visited[x] == False:
        tami2(x, cnt+1, choku, choku_visited, edge, aoki)


def main():
  N, u, v = IL()
  ab = [IL() for _ in range(N-1)]

  aoki = [0]*(N+1)
  aoki_visited = [False]*(N+1)
  choku = [0]*(N+1)
  choku_visited = [False]*(N+1)

  edge = [[] for _ in range(N+1)]
  for a,b in ab:
    edge[a].append(b)
    edge[b].append(a)

  ans = 0
  tami(v, 0, aoki, aoki_visited, edge)
  tami2(u, 0, choku, choku_visited, edge, aoki)
  #print(aoki)
  #print(choku)

  for i in range(N+1):
    if choku[i] == 0 and i != u:
      continue
    if aoki[i] > choku[i]:
      ans = max(ans, aoki[i] - 1)

  print(ans)

main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

class Tree:
  C, RL = {}, {}
  R, N, D, S, P = None, None, None, None, None
  def __init__(s, num):
    s.N = num
  def setC(s, a, b):
    if a in s.C: s.C[a].append(b)
    else: s.C[a] = [b]
    if b in s.C: s.C[b].append(a)
    else: s.C[b] = [a]
  def makeRank(s, root):
    s.R = [0] * s.N
    s.R[root] = 1
    s.RL[1] = [root]
    s.S = {}
    s.P = {}
    F = [root]
    s.D = 2
    while F != []:
      Ft = []
      s.RL[s.D] = []
      for i in F:
        for j in s.C[i]:
          if s.R[j] == 0:
            s.R[j] = s.D
            Ft.append(j)
            s.RL[s.D].append(j)
            if i not in s.S:
              s.S[i] = [j]
            else:
              s.S[i].append(j)
            s.P[j] = i

      s.D += 1
      F = Ft
  def getDeep(s, x):
    ans = 0
    if x in s.S:
      for i in s.S[x]:
        ans = max(ans, s.getDeep(i))
      return ans + 1
    else:
      return 0
  def getParent(s, x, n):
    if n == 0:
      return x
    return s.getParent(s.P[x], n - 1)
    

N, u, v = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N - 1)]

T = Tree(N)
for a, b in AB:
  T.setC(a - 1, b - 1)

T.makeRank(v - 1)
t = (T.R[u - 1] // 2) - 1
f = T.R[u - 1] % 2
k = T.getDeep(T.getParent(u - 1, t))
print(t + k + f)
### BUGGY CODE ###

inp = input()

s = 0

for i in range(len(inp)-3):
	for j in range(i+4, len(inp)+1):
		num = int(inp[i:j])
		if num % 2019 == 0:
			s += 1

print(s)

### FIXED CODE ###

from collections import defaultdict

s = input()

rests = [0]
n = 0
a = 0
m = 1
c = defaultdict(int)
c[0] += 1
for i in list(s)[::-1]:
    n = n + int(i)*m

    c[n % 2019] += 1
    m = m * 10 % 2019

for v in c.values():
    a += v * (v-1) // 2
print(a)