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

#!/usr/bin/env python
import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def get_longest(x, longest, edges):
    if longest[x] is not None:
        return longest[x]
    if not edges[x]:
        return 0
    result = max([get_longest(y, longest, edges)
                  for y in edges[x]])
    return result + 1


def main():
    input = sys.stdin.readline
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())
    #ps = list(map(int, input().split()))

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

    edges = defaultdict(set)
    for i in range(M):
        x, y = map(int, input().split())
        edges[x].add(y)

    longest = [None] * (N + 1)
    for x in range(N):
        x += 1
        if longest[x] is None:
            longest[x] = get_longest(x, longest, edges)

    print(max(longest[1:]))


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python
import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def get_longest(x, longest, edges):
    if longest[x] is not None:
        return longest[x]
    if not edges[x]:
        longest[x] = 0
    else:
        result = max([get_longest(y, longest, edges)
                      for y in edges[x]])
        longest[x] = result + 1
    return longest[x]


def main():
    input = sys.stdin.readline
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())
    #ps = list(map(int, input().split()))

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

    edges = defaultdict(set)
    for i in range(M):
        x, y = map(int, input().split())
        edges[x].add(y)

    longest = [None] * (N + 1)
    for x in range(N):
        x += 1
        if longest[x] is None:
            get_longest(x, longest, edges)

    print(max(longest[1:]))


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

#import math
from functools import reduce
from fractions import gcd

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)




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

t_lcm = lcm(A)
count = 0
for i in A:
    count += t_lcm//i
    
print(count%(10**9+7))


### FIXED CODE ###

#import math
#from functools import reduce
from fractions import gcd
#from functools import lru_cache


#def lcm_base(x, y):
#    return (x * y) // gcd(x, y)

#def lcm(numbers):
#    return reduce(lcm_base, numbers, 1)


def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x


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

t_lcm = lcm(A)
count = 0
for i in A:
    count += t_lcm//i
    
print(count%(10**9+7))
### BUGGY CODE ###

MOD = 1000000007

s = [-1 if x == '?' else int(x) for x in input()]
n = len(s) + 1

dp = [0] * 13
dp[0] = 1

for i, x in enumerate(s):
    next_dp = [0] * 13
    for j in range(10):
        if (x == -1) or (x == j):
            for ki in range(13):
                next_dp[(ki * 10 + j) % 13] += dp[ki]
    dp = [k % MOD for k in next_dp]

print(dp[5])

### FIXED CODE ###

MOD = 1000000007

s = [-1 if x == '?' else int(x) for x in input()]
n = len(s) + 1

dp = [0] * 13
dp[0] = 1

r = [[(j-i)*4%13 for i in range(10)]for j in range(13)]

for i, x in enumerate(s):
    next_dp = [0] * 13
    if x == -1:
        next_dp = [sum(dp[i] for i in j) for j in r]
    else:
        next_dp = [dp[j[x]] for j in r]
    dp = [k % MOD for k in next_dp]

print(dp[5])
### BUGGY CODE ###

import sys

N = int(input())
d = list(map(int, input().split(" ")))

for item in d:
  if d.count(item) > 1:
    print("NO")
    sys.exit()

print("YES")


### FIXED CODE ###

import sys

N = int(input())
d = list(map(int, input().split(" ")))

newList = list(dict.fromkeys(d))

if len(d) == len(newList):
  print('YES')
else:
  print("NO")
### BUGGY CODE ###

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

ans = 0
for C in range(1, n):
    a2 = a[:]
    f = 0
    for k in range(int((n-1)/C)):
        if f == -float("inf") or k * C == (n - 1) - k * C:
            break
        f += a2[k * C] + a2[(n - 1) - k * C]
        a2[k * C], a2[(n - 1) - k * C] = -float("inf"), -float("inf")
        ans = max(ans, f)

print(ans)

### FIXED CODE ###

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

ans = 0
for C in range(1, n):
    f = 0
    for k in range([int(((n - 1) / C + 1) / 2), int((n - 1) / C)][(n - 1) % C != 0]):
        f += a[k * C] + a[(n - 1) - k * C]
        ans = max(ans, f)
print(ans)
### BUGGY CODE ###

def main():
  n, w = [int(e) for e in input().split()]
  d = [[int(e) for e in input().split()] for i in range(n)]
  t = {}
  t[w] = 0
  for i in range(n):
    keys = list(sorted(t.keys())) # sort しないと品物iを複数回ナップサックに詰める可能性がある
    tw, tv = d[i]
    for j in keys:
      nw = j - tw
      if nw < 0:
        continue
      nv = t[j] + tv
      if nw in t:
        if nv > t[nw]:
          t[nw] = nv
      else:
        t[nw] = nv
  print(max(t.values()))
main()


### FIXED CODE ###

def main():
  n, w = [int(e) for e in input().split()]
  maxv = 10 ** 3 * n + 1
  t = [-1 for i in range(maxv)]
  t[0] = w
  for _ in range(n):
    nw, nv = [int(e) for e in input().split()]
    for i in range(maxv - 1, -1, -1):
      if t[i] == -1:
        continue
      if t[i + nv] < t[i] - nw:
        t[i + nv] = t[i] - nw
  for i in range(maxv - 1, 0, -1):
    if t[i] == -1:
      continue
    print(i)
    break
main()
### BUGGY CODE ###

n = int(raw_input())
G = [[-1] * n] * n
d = [0] * n
 
for i in range(n):
    v = map(int, raw_input().split())
    for j in range(v[1]):
        G[v[0]][v[2+2*j]] = int(v[3+2*j])
 
flag = [0] * n
tn = [0]
r = 0
while True:
    for i in range(n):
        if flag[i] == 0 and i in tn:
            flag[i] = 1
            d[i] = r
            for j in range(n):
                if G[i][j] != -1 and flag[j] == 0:
                    tn.append(j)
    if len(tn) == n:
        break
    r += 1
 
for i in range(n):
    print(str(i) + " " + str(d[i]))

### FIXED CODE ###

n = int(input())
G = [[-1 for i in range(n)] for j in range(n)]
d = [999999 for i in range(n)]
  
for i in range(n):
    v = input().split()
    for j in range(int(v[1])):
        G[int(v[0])][int(v[2+2*j])] = int(v[3+2*j])

flag = [0] * n
tn = [0]
d[0] = 0
for k in range(n):
    for i in range(n):
        if i in tn:
            for j in range(n):
                if G[i][j] != -1:
                    if d[j] > d[i] + G[i][j]:
                        d[j] = d[i] + G[i][j]
                    if j not in tn:
                        tn.append(j)
  
for i in range(n):
    print(str(i) + " " + str(d[i]))
### BUGGY CODE ###

h,w=map(int,input().split())
l=[['#' for i in range(w+2)] for j in range(2)]
l[1:1]=[list('#'+input()+'#') for i in range(h)]
p=[]
for i in range(1,h+1):
  for j in range(1,w+1):
    if l[i][j]=='#':
      p.append([i,j])
d=[[-1,0],[1,0],[0,-1],[0,1]]
r=-1
while len(p)!=0:
  r+=1
  s=[]
  for i, j in p:
    for di, dj in d:
      di+=i
      dj+=j
      if l[di][dj]=='.':
        l[di][dj]='#'
        s.append([di,dj])
  p=s
print(r)

### FIXED CODE ###

h,w=map(int,input().split())
l=[['#' for i in range(w+2)] for j in range(2)]
l[1:1]=[list('#'+input()+'#') for i in range(h)]
p=[]
for i in range(1,h+1):
  for j in range(1,w+1):
    if l[i][j]=='#':
      p.append((i,j))
d=[(-1,0),(1,0),(0,-1),(0,1)]
r=-1
while len(p)!=0:
  r+=1
  s=[]
  for i, j in p:
    for di, dj in d:
      di+=i
      dj+=j
      if l[di][dj]=='.':
        l[di][dj]='#'
        s.append((di,dj))
  p=s
print(r)
### BUGGY CODE ###

# C - IDC
import bisect

base = 1000000000000
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
T = [[] for _ in range(N+1)]

for i in range(M):
    P[i], Y[i] = map(int, input().split())
    T[P[i]].append(Y[i])
    T[P[i]].sort()

for i in range(M):
    num = bisect.bisect_right(T[P[i]], Y[i])
    print(str(base + P[i]*1000000 + num)[1:])

### FIXED CODE ###

# C - IDC

import bisect
import sys
readline = sys.stdin.readline

base = 1000000000000
N, M = map(int, readline().split())
PY = []
T = [[] for _ in range(N+1)]

for i in range(M):
    P, Y = map(int, readline().split())
    PY.append((P, Y))

PY_sorted = sorted(PY, key=lambda x: x[1])
PY_sorted = sorted(PY_sorted, key=lambda x: x[0])

for i in range(M):
    T[PY_sorted[i][0]].append(PY_sorted[i][1])

for i in range(M):
    n = bisect.bisect_right(T[PY[i][0]], PY[i][1])
    print(str(base + PY[i][0]*1000000 + n)[1:])
### BUGGY CODE ###

n,k = map(int,input().split())
al = list(map(int,input().split()))

for _ in range(k):
    imos = [0 for i in range(n+1)]
    for idx, a in enumerate(al):
        imos[max(idx-a, 0)] += 1
        imos[min(idx+a+1, n)] -= 1
    al = []
    now = 0
    for i in imos:
        now += i
        al.append(now)
    if len(set(al)) == 1 and al[0] == n:
        break

print(*al[:-1])


### FIXED CODE ###

n,k = map(int,input().split())
al = list(map(int,input().split()))

for _ in range(k):
    imos = [0 for i in range(n+1)]
    for idx, a in enumerate(al):
        imos[max(idx-a, 0)] += 1
        imos[min(idx+a+1, n)] -= 1
    al = []
    now = 0
    for i in imos:
        now += i
        al.append(now)
    if len(set(al[:-1])) == 1 and al[0] == n:
        break

print(*al[:-1])
### BUGGY CODE ###

H,W=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
S=[input() for i in range(H)]
from collections import deque
q=deque([(ch-1,cw-1,0)])
v=[[-1]*W for i in range(H)]
x=((1,0),(-1,0),(0,-1),(0,1))
y=((2,2),(2,1),(2,0),(2,-1),(2,-2),(1,2),(1,1),(1,-1),(1,-2),(0,2),(0,-2),(-1,2),(-1,1),(-1,-1),(-1,-2),(-2,2),(-2,1),(-2,0),(-2,-1),(-2,-2))
while q:
    h,w,d=q.popleft()
    if v[h][w]<0:
        v[h][w]=d
    for i,j in x:
        if 0<=h+i<H and 0<=w+j<W and S[h+i][w+j]=='.' and v[h+i][w+j]<0:
            q.appendleft((h+i,w+j,d))
    for i,j in y:
        if 0<=h+i<H and 0<=w+j<W and S[h+i][w+j]=='.' and v[h+i][w+j]<0:
            q.append((h+i,w+j,d+1))
print(v[dh-1][dw-1])

### FIXED CODE ###

H,W=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
S=[input() for i in range(H)]
from collections import deque
q=deque([(ch-1,cw-1,0)])
v=[[9**9]*W for i in range(H)]
x=((1,0),(-1,0),(0,-1),(0,1))
y=((2,2),(2,1),(2,0),(2,-1),(2,-2),(1,2),(1,1),(1,-1),(1,-2),(0,2),(0,-2),(-1,2),(-1,1),(-1,-1),(-1,-2),(-2,2),(-2,1),(-2,0),(-2,-1),(-2,-2))
while q:
    h,w,d=q.popleft()
    for i,j in x:
        if 0<=h+i<H and 0<=w+j<W and S[h+i][w+j]=='.' and d<v[h+i][w+j]:
            v[h+i][w+j]=d
            q.appendleft((h+i,w+j,d))
    for i,j in y:
        if 0<=h+i<H and 0<=w+j<W and S[h+i][w+j]=='.' and d+1<v[h+i][w+j]:
            v[h+i][w+j]=d+1
            q.append((h+i,w+j,d+1))
print(v[dh-1][dw-1] if v[dh-1][dw-1]<9**9 else -1)
### BUGGY CODE ###

import queue
q = queue.Queue()
x = int(input())


start_position = 0
start_time = 0


def k():
    while q.not_empty:
        position, time = q.get()
        if position == x:
            return time
        else:
            q.put((position - (time + 1), time + 1))
            q.put((position + (time + 1), time + 1))
            q.put((position, time + 1))


q.put((start_position, start_time))

print(k())

### FIXED CODE ###

x = int(input())

podition_range = 0
time = 0
i = 0

while True:
    if - podition_range <= x <= podition_range:
        print(time)
        break
    else:
        i += 1
        time += 1
        podition_range += time
### BUGGY CODE ###

N = int(input())
L_A = [int(s) for s in input().rstrip().split(' ')]
[M,m] = [0,10**9]
ans = 0
a = 0
for k in range(N,0,-1):
    p = L_A[k-1]
    if p+m <= a:
        for i in range(1,a+1):
            if p + L_A[k-1+i] == i:
                ans += 1
    M = max(M,p)
    m = min(m,p)
    a += 1
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 0
"""
A[i] + A[j] = j - i
<=> A[i] + i = j - A[j]
"""
L_i = [A[i] + i for i in range(N)]
L_j = [j - A[j] for j in range(N)]
# L_j[x] < x <= 2 * (10**5)
ans_lis = [0] * (2*(10**5))
for x in L_i:
    if x < 2*(10**5):
        ans_lis[x-1] += 1
for y in L_j:
    if y > 0:
        ans += ans_lis[y-1]
print(ans)
### BUGGY CODE ###

from collections import *
import sys
from bisect import *
input=sys.stdin.readline
from math import *
t=1
while(t):
    t-=1
    n=int(input())
    pre=[[i,{}] for i in range(n+1)]
    for i in range(2,n+1):
        if(pre[i][0]%i==0 and i!=1):
            pre[i][1][i]=1
            pre[i][0]=1
        for j in range(2*i,n+1,i):
            f=pre[j][0]
            c=0
            if(pre[j][0]==1):
                break
            while(f%i==0):
                f=f//i
                c+=1
            pre[j][0]=f
            pre[j][1][i]=c
    r=1
    #print(pre)
    for i in range(2,n+1):
        p=1
        for j in pre[i][1].keys():
            p=p*(pre[i][1][j]+1)
        r+=i*p
    print(r)


### FIXED CODE ###

MAX = int(input())
MAX+=1
factor = [0]*(MAX + 1); 
def generatePrimeFactors(): 
	factor[1] = 1;
	for i in range(2,MAX): 
		factor[i] = i; 
	for i in range(4,MAX,2): 
		factor[i] = 2; 

	i = 3; 
	while(i * i < MAX): 
		if (factor[i] == i): 
			j = i * i; 
			while(j < MAX): 
				if (factor[j] == j): 
					factor[j] = i; 
				j += i; 
		i+=1; 

def ca(n): 
	if (n == 1): 
		return 1; 
	ans = 1; 
	dup = factor[n]; 
	c = 1; 
	j = int(n / factor[n]); 
	while (j > 1): 
		if (factor[j] == dup): 
			c += 1; 
		else: 
			dup = factor[j]; 
			ans = ans * (c + 1); 
			c = 1; 
		j = int(j / factor[j]); 

	ans = ans * (c + 1); 
	return ans; 
generatePrimeFactors() 
r=1
for i in range(2,MAX):
    r+=i*ca(i)
print(r)
### BUGGY CODE ###

N, M = map(int, input().split())
a = [int(input()) for i in range(M)]
inf = 10**9+7

dp = [0] * (N+1)
dp[0] = 1
if 1 not in a:
  dp[1] = 1
else:
  dp[1] = 0

for i in range(2,N+1):
  if i in a:
    continue
  dp[i] = dp[i-1] + dp[i-2]
  dp[i] %= inf

print(dp[N]) 

### FIXED CODE ###

N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, N + 1):
	if i in a:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF

print(dp[N])
### BUGGY CODE ###

N = int(input())
num = 1
c=list(map(int, input().split()))
for i in c:
    num *= i
if num > 1000000000000000000:
    print("-1")
else:
    print(num)

### FIXED CODE ###

N = int(input())
num = 1
flag = 0
c=[int(i) for i in input().split()]
for i in c:
    if i == 0:
        flag = 1
        print("0")
if flag == 0:
    for i in c:
        num *= i
        if num > 1000000000000000000:
            print("-1")
            flag =1
            break
if flag == 0:
    
    print(num)
### BUGGY CODE ###

N = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(N):
    if P[i] == min(P[0:i+1]):
        ans += 1
print(ans)


### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
ans = 0
mini = P[0]

for i in range(N):
    if P[i] <= mini:
        mini = P[i]
        ans += 1
print(ans)
### BUGGY CODE ###

# 初期入力
N = int(input())
k = list(map(int, input().split()))

# 書かれている数字のぼーるがいくつあるか、辞書
from collections import Counter
A =Counter(k)

from math import factorial
def nC2(n): # 組み合わせ n「C」r
    if  n<2:
        return 0
    return n*(n-1)//2

# 順番付きの辞書
from collections import OrderedDict
D = OrderedDict()
D2 = OrderedDict()

# 各数字を連続でとる場合の数
futatu_onaji =0
for i,v in A.items():
    futatu_onaji += nC2(v)


#D =[0]*N
D =[]
for i,v in enumerate(k):
    for ij,vj in A.items():
        if v == ij :
            x = vj-1 #最初のボールと同じ番号を次に取る
            D.append(futatu_onaji - x ) #全体から引いたものをリストに追加
print(*D,sep="\n")


### FIXED CODE ###

from collections import Counter 
N = int(input())
A = list(map(int, input().split()))
c_A = Counter(A)
all =sum( [i*(i-1)//2 for i in c_A.values()] )

for i in range(N):
    ans =all -( c_A[A[i]] -1)
    print(ans)
### BUGGY CODE ###

N = int(input())
T = [0]*100000
X= [0]*100000
Y= [0]*100000
x = 0
y = 0

for n in range(N):
        T[n],X[n],Y[n] = (map(int, input().split()))

flag = 1
for n in range(N):
    #print(n)
    if flag == 0:
        continue


    if n == 0:
        count = T[n]
    else:
        count = T[n] - T[n-1]
        x = X[n-1]
        y = Y[n-1]
    c = 0
    end = 0
    while True:
        if end == 1:
            break
        s_x = X[n] - x
        s_y = Y[n] - y
        #print(str(x)+' '+str(y))

        if ((s_x >= 0 or s_y >= 0) )and (c!=count):
            if s_x >0:
                x +=1
                c += 1
            elif s_x < 0:
                x -= 1
                c+=1
            elif s_y > 0:
                y +=1
                c += 1
            elif s_y < 0:
                y -= 1
                c+=1
            elif s_x==0:
                c +=2
        elif c==count:
            if (x == X[n] and y ==Y[n]):
                flag = 1
                end=1
        elif c>count and (x != X[n] or y !=Y[n]) :
                flag=0
                end =1


if flag == 1:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

N = int(input())
T = [0]*100000
X= [0]*100000
Y= [0]*100000
x = 0
y = 0

for n in range(N):
        T[n],X[n],Y[n] = (map(int, input().split()))

flag = 1
for n in range(N):
    #print(n)
    if flag == 0:
        continue


    if n == 0:
        count = T[n]
    else:
        count = T[n] - T[n-1]
        x = X[n-1]
        y = Y[n-1]
    c = 0
    end = 0
    while True:
        if end == 1:
            break
        s_x = X[n] - x
        s_y = Y[n] - y
    #    print(str(s_x)+' '+str(s_y))

        if ((s_x != 0 or s_y !=0) )and (c!=count):
            if s_x >0:
                x +=1
                c += 1
            elif s_x < 0:
                x -= 1
                c+=1
            elif s_y > 0:
                y +=1
                c += 1
            elif s_y < 0:
                y -= 1
                c+=1
        elif  ((s_x == 0 and s_y == 0) )and (c!=count):
                x +=1
                c +=1
        elif c==count:
            if (x == X[n] and y ==Y[n]):
                flag = 1
                end=1
            else:
                flag=0
                end =1



if flag == 1:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###


def resolve():
    K = int(input())
    if K%2==0:
        return print(-1)
    seven = 0
    ans = 0
    while True:
        seven = (seven * 10 + 7) % K
        ans += 1
        if seven == 0:
            break
    print(ans)


if __name__ == "__main__":
    resolve()


### FIXED CODE ###


def resolve():
    K = int(input())
    if K%2==0:
        return print(-1)
    
    seven = 7
    for i in range(1, K+10):
        if seven%K==0:
            return print(i)
        seven = (seven*10+7)%K

    print(-1)


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

N, C = map(int, input().split())
D, c = [], []
for _ in range(C):
    D.append([int(i) for i in input().split()])

for _ in range(N):
    c.append([int(i) for i in input().split()])

costD = []
for c0 in range(C):
    tmpD = [0] * 3
    for i in range(N):
        for j in range(N):
            tmpD[(i+j)%3] += D[c[i][j]-1][c0]
    costD.append(tmpD)

kohoD = []
for c1 in range(C):
    for c2 in range(C):
        if c1 == c2:
            continue
        for c3 in range(C):
            if c1 == c3 or c2 == c3:
                continue
            kohoD.append(costD[c1][0] + costD[c2][1] + costD[c3][2])

kohoD.sort()
print(kohoD[0])

### FIXED CODE ###

import itertools
 
 
def main():
    N, C = map(int, input().split())
    D = [list(map(int, input().split())) for _ in range(C)]
    CC = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]
 
    cost = [[0 for _ in range(C)] for _ in range(3)]
    for c in range(C):
        for i in range(N):
            for j in range(N):
                cost[(i + j) % 3][c] += D[CC[i][j]][c]
 
    res = float("inf")
    color = [i for i in range(C)]
    for i, c in enumerate(list(itertools.permutations(color, 3))):
        tmp = 0
        for it in range(3):
            tmp += cost[it][c[it]]
        res = min(res, tmp)
 
    print(res)
 
main()
### BUGGY CODE ###

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

L = sorted(L)

# print(L)

# 三角形なのでa>b>cになるように選べば, a+b>cとなる
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        # print("i:{}, j:{}".format(i, j))
        b = L[j]
        left = j+1
        right = N-1
        c = L[N-1]
        if a+b>c:
            # print("true - k:{}".format(N-1))
            # print("num_c:{}".format())
            ans += N-j-1
        else:
            mid = right
            while left < right:
                if mid == (left+right)//2:
                    break
                mid = (left+right)//2
                # print("left:{}, mid:{}, right:{}".format(left, mid, right))
                c = L[mid]
                if a+b>c:
                    left = mid
                else:
                    right = mid
                time.sleep(0.05)
            # print("false - k:{}".format(mid))
            if a+b>c:
                # print("a+b>c:{}".format(True))
                ans += mid - j
            else:
                # print("a+b>c:{}".format(False))
                ans += mid - j - 1
        # print("ans of ({},{}): {}".format(i,j,ans))

print(ans)


### FIXED CODE ###

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

L = sorted(L)

# print(L)

# 三角形なのでa>b>cになるように選べば, a+b>cとなる
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        # print("i:{}, j:{}".format(i, j))
        b = L[j]
        left = j+1
        right = N-1
        c = L[N-1]
        if a+b>c:
            # print("true - k:{}".format(N-1))
            # print("num_c:{}".format())
            ans += N-j-1
        else:
            mid = right
            while left < right:
                if mid == (left+right)//2:
                    break
                mid = (left+right)//2
                # print("left:{}, mid:{}, right:{}".format(left, mid, right))
                c = L[mid]
                if a+b>c:
                    left = mid
                else:
                    right = mid
                # time.sleep(0.05)
            # print("false - k:{}".format(mid))
            if a+b>c:
                # print("a+b>c:{}".format(True))
                ans += mid - j
            else:
                # print("a+b>c:{}".format(False))
                ans += mid - j - 1
        # print("ans of ({},{}): {}".format(i,j,ans))

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

import collections

n = int(input())
d_list = []
cnt = 0
for i in range(n):
    s = str(input())
    
    d = collections.Counter(s)

    if i >= 1:
        if d in d_list:
            cnt += d_list.count(d)
    d_list.append(d)
    
print(cnt)


### FIXED CODE ###


from collections import Counter

N = int(input())
S = [''.join(map(str,(sorted(str(input()))))) for i in range(N)]
counter = Counter(S)

answer = sum(x*(x-1)//2 for x in counter.values())
print(answer)
### BUGGY CODE ###

N = int(input())
A_list = list(map(int,input().split()))
res = []
for i in range(N):
    res.append(A_list.index(i+1)+1)

for s in res:
    print(s, end =" ")

### FIXED CODE ###

import numpy as np
N = int(input())
A_list = list(map(int,input().split()))
res = np.argsort(A_list)

for s in res:
    print(s+1, end =" ")
### BUGGY CODE ###

k,s = map(int,input().split())
count = 0
for x in range(k+1):
    if x==s:
        count+=1
    elif x+2*k>=s:
        for y in range(k+1):
            if x+y==s:
                count+=1
            elif x+y+k>=s:
                for z in range(k+1):
                    if x+y+z==s:
                        count+=1
                        break
print(count)

### FIXED CODE ###

k,s = map(int,input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if z>=0 and z<=k:
            count+=1
print(count)