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

#coding:utf-8



def main():
    
    def dbg(*something):
        if DEBUG:
            print(*something)


    #正の宝石を戻すことはない
    #負の宝石を戻すのは後半
    from sys import stdin
    from math import ceil,floor
    DEBUG = False
    N,K = list(map(int,stdin.readline().split()))
    V = list(map(int,stdin.readline().split()))


    #残りk回のとき深さk以下の場所に正の宝石がない→終了
    #i回の操作で取れる石>それまでにとるi-1個の石の和
    #深さiにある石vの価値：v - (それまでにとるi-1個の石の和　except (k-i)個の負の石)
    '''
    '''




    def tansaku(left,right,rK,N,score):
        dbg(V[left:right+1],rK,N,score)

        N.sort()
        max_v = score + sum(N[rK:])
        


        # n = []
        for i in range(left,min(rK+left, ceil((right - left +1)/2)+left)):
            
            if V[i] <= 0:
                continue


            next_rK = rK - 1 - (i - left)
            next_tmp_v = tansaku(i+1,right,  next_rK, N+V[left:i], score+V[i])
            #max_v = max(next_tmp_v , max_v)
            if max_v < next_tmp_v:
                max_v = next_tmp_v


            break

        # n = []
        for i in range(right ,max(right - ceil((right-left+1)/2)  ,right-rK)  ,-1 ):
            
            if V[i] <= 0:
                continue

            next_rK = rK - 1 - (right - i)
            next_tmp_v = tansaku(   left,   i-1  ,next_rK,N+V[i+1:right+1],score+V[i])
            #max_v = max(next_tmp_v , max_v)
            if max_v < next_tmp_v:
                max_v = next_tmp_v
            break


        return max_v

    print(tansaku(0,len(V)-1,K,[],0))





if __name__ == '__main__':
    main()


### FIXED CODE ###

#coding:utf-8



def main():
    
    def dbg(*something):
        if DEBUG:
            print(*something)


    #正の宝石を戻すことはない
    #負の宝石を戻すのは後半
    from sys import stdin
    from math import ceil,floor
    DEBUG = False
    N,K = list(map(int,stdin.readline().split()))
    V = list(map(int,stdin.readline().split()))
    
    max_value = 0
    dbg([i for i in range(3,-1,-1)])
    for getnum in range(1,min(N+1,K+1)):  #取る宝石の総数
        for a in range(getnum + 1):  #左から石を取る回数
            J = [0] * getnum #石
            b = getnum - a #右から石を取る回数
            for i in range(a):
                J[i] = V[i]
            for i in range(b):
                J[a+i] = V[-i-1]
            J.sort()
            #dbg(J,a,b)
            t = min(K-getnum,getnum) #捨てる石
           
            for i in range(t): 
                if J[i] >= 0:
                    t = i
                    break
            #dbg(J,i,t,a,b,J[t:])
            tmp_max = sum(J[t:])

            max_value = max(max_value,tmp_max)
    print(max_value)



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

import sys

def cal():
    N = int(input())

    for i in range(1, 3501):
        for j in range(1, 3501):
            num0 = 4*i*j-N*(i+j) 
            if num0 != 0:
                num = N*i*j/num0
                if num.is_integer() and 0 < num <= 3500:
                    print(i, int(num), j)
                    sys.exit()

cal()


### FIXED CODE ###

import sys

def cal():
    N = int(input())

    for i in range(1, 3501):
        for j in range(1, 3501):
            num0 = 4*i*j-N*(i+j) 
            if num0 != 0:
                num = N*i*j/num0
                if num.is_integer() and 0 < num <= 3500:
                    print(i, int(num), j)
                    sys.exit()

cal()
### BUGGY CODE ###

import sys
inputs = sys.stdin.readline
N, Q= map(int,inputs().split())
E = [None]*2*N
for n in range(N):
	a,b,c = map(int,inputs().split())
	E[2*n] = [a - c, 1, c]
	E[2*n + 1] = [b - c, -1, c]
#D = [int(inputs()) for p in [0]*Q]
E.sort(key = lambda x:x[0])
mini = 1000000001
kouho = [1000000001]
q = 0
d = int(inputs())
flag = False
for e in E:
	cont = False
	mini = 1000000001
	while(e[0] > d):
		if cont == True:
			if mini < 1000000001:
				print(mini)
			else:
				print(-1)
		else:
			mini = min(kouho)
			if mini < 1000000001:
				print(mini)
			else:
				print(-1)
		cont = True
		if q < Q-1:
			q = q + 1
			d = int(inputs())
		else:
			flag = True
			q = q + 1
			break
	if flag == True:
		break
	if  e[1] == 1:
		kouho.append(e[2])
	elif e[1] == -1:
		kouho.remove(e[2])
for t in [None]*(Q-q):
	print(-1)

### FIXED CODE ###

import sys
from operator import itemgetter
def main():
	inputs = sys.stdin.readline
	N, Q= map(int,inputs().split())
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while e[0] > d:
			if cont == True:
				print(mini-(mini//1000000001)*1000000002)
			else:
				mini = min(kouho)
				print(mini-(mini//1000000001)*1000000002)
			cont = True
			q = q + 1
			if q > Q-1:
				flag = True
				break
			d = int(inputs())
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			if mini == e[2]:
				cont = False
	for t in [None]*(Q-q):
		print(-1)
main()
### BUGGY CODE ###

N = int(input())
count=0
if N>777777777:
  N = 7777777777
for i in range(333,N+1):
  X = str(i)
  a3 = X.count("3")
  a5 = X.count("5")
  a7 = X.count("7")
  if(a3>0 and a5>0 and a7>0 and a3+a5+a7==len(X)):
    count+=1
print(count)

### FIXED CODE ###

N = int(input())
S = len(str(N))
T = ["7","5","3"]
ans = 0
for s in range(3,S+1):
    for i in range(3**s):
        A = []
        n = i
        for j in range(s):
            A.append(n%3)
            n//=3
        if len(set(A))<3:continue
        k = "".join([T[a] for a in A])
        if int(k)<=N:ans+=1
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
alist = tuple(map(int,input().split()))
anslist =[]
for i in range(n):
  for j in range(i+1,n):
    anslist.append((alist[i]^alist[j]))
s = sum(anslist)
print(s%(10**9+7))

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

a.sort(reverse = True)

#l = len(bin(a[0])[2:])

ans  = 0
for b in range(60+1):
    count_1 = 0
    count_0 = 0
    for i in range(n):
        if (a[i] >> b) & 1:
            count_1 += 1
        else:
            count_0 += 1
    count_1 %= mod
    count_0 %= mod
    ans += (count_1 * count_0 * pow(2,b,mod))%mod


print(ans%mod)
### BUGGY CODE ###

#!/usr/bin/env python3

import numpy as np

P_MOD = 1000000007


def solve(S):
    # print(S)
    # 1, 10, 100, 1000, ... を 13 で割った値は 1, 10, 9, 12, 3, 4 で巡回する
    MODS = np.array([1, 10, 9, 12, 3, 4], dtype=np.int)

    # 現在の桁の余り N の状態を cur[N]
    # 直前の桁の余り N の状態を priv[N] とする
    priv = np.zeros(13, dtype=np.int)
    priv[0] = 1
    s = S[::-1]
    for i in range(0, len(s)):
        cur = np.zeros(13+13, dtype=np.int)
        d = s[i]
        if d == '?':
            for di in range(10):
                m = (di * MODS[i % 6]) % 13
                cur[m:m+13] = (cur[m:m+13] + priv[0:13]) % P_MOD
            cur[0:13] += cur[13:26]
        else:
            m = int(d) * MODS[i % 6]
            for j in range(13):
                cur[(m+j) % 13] = priv[j]
        priv = cur[0:13]
    return cur[5]


if __name__ == '__main__':
    S = input()

    ans = solve(S)

    print(ans % P_MOD)


### FIXED CODE ###


P_MOD = 1000000007


def solve(S):
    # print(S)
    # 1, 10, 100, 1000, ... を 13 で割った値は 1, 10, 9, 12, 3, 4 で巡回する
    MODS = [1, 10, 9, 12, 3, 4]

    # 現在の桁の余り N の状態を cur[N]
    # 直前の桁の余り N の状態を priv[N] とする
    priv = [1] + [0] * 12
    # print(priv)
    s = S[::-1]
    for i in range(0, len(s)):
        cur = [0] * 13
        d = s[i]
        # print('i=', i, 'd=', d)
        if d == '?':
            for j in range(13):
                for di in range(10):
                    m = di * MODS[i % 6]
                    cur[(j+m) % 13] += priv[j]
        else:
            m = int(d) * MODS[i % 6]
            for j in range(13):
                cur[(m+j) % 13] = priv[j]
        # print(cur)
        for j in range(13):
            priv[j] = cur[j] % P_MOD
    return cur[5]


if __name__ == '__main__':
    S = input()

    ans = solve(S)

    print(ans % P_MOD)
### BUGGY CODE ###

n = int(input())
l = list(map(int,input().split()))

l.sort(reverse = 1)
ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        if l[i]/2 > l[j]:
            break
        for k in range(j+1,n):
            a,b,c = l[i],l[j],l[k]
            #print(i,j,k)
            if a >= b+c:
                break
            else:
                ans += 1
            
print(ans)

### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))

l.sort(reverse = 1)
ans = 0

for i in range(n-2):
    indL = i+1
    indR = len(l)-1
    while 1:
        if indL == indR:
            break
        if l[i] < l[indL] + l[indR]:
            ans += (indR - indL)
            indL += 1
        else:
            indR -= 1
                
print(ans)
### BUGGY CODE ###

import sys
from collections import Counter
import random
import numpy as np
import time

n=int(input())
a=list(map(int,input().split()))
S=[0]
for i in range(n):
    S.append(S[i]+a[i])
#for i in S:print(i)
m=n+1
c=0
for i in range(1,m):
    c+=S[:i].count(S[i])
print(c)

### FIXED CODE ###

import sys
from collections import Counter
import random
import numpy as np
import time

n=int(input())
a=list(map(int,input().split()))
S=[0]
for i in range(n):
    S.append(S[i]+a[i])
    
S.sort()
c=0
ch=0
for i in range(len(S)-1):
    if(S[i]!=S[i+1]):
        ch+=1
        c+=(ch*(ch-1))//2
        ch=0
    else:ch+=1
if(ch!=0):
    ch+=1
    c+=(ch*(ch-1))//2
print(c)
### BUGGY CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b):
    return a*b//gcd(a,b)

n = I()
a = LI()
l = 1
for i in a:
    l = lcm(l,i)

ans = 0
for i in a:
    ans += l // i
    ans %= mod
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

n = I()
a = LI()
l = lcm(a)
ans = 0
l %= mod
for i in a:
    ans += l*pow(i,mod-2,mod)
    ans %= mod
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():

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


resolve()

### FIXED CODE ###

#!/usr/bin/python3
# import bisect
from collections import Counter, deque, OrderedDict,defaultdict
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():

    N = int(input())
    A = list(map(int, input().split()))
    d=defaultdict(int)
    cnt=0
    for k,v in enumerate(A):
        d[k+v]+=1
        cnt+=d[k-v]

    print(cnt)


resolve()
### BUGGY CODE ###

N,M=map(int,input().split())
a=list(int(input()) for _ in range(M) )
ans=0
ansn1=0
ansn2=0
mod=1000000007
for i in range(N):
    if i==0:
        if i+1 not in a:
            ans=1
            ansn2 = 0
            ansn1=ans

    elif i==1:
        if i+1 not in a:
            ans=1+ansn1
            ansn2 = ansn1
            ansn1=ans
        else:
            ans=0
            ansn2=ansn1
            ansn1=ans

    elif i+1 not in a:
        ans=(ansn1+ansn2)%mod
        ansn2 = ansn1
        ansn1=ans

    else:
        ans=0
        ansn2 = ansn1
        ansn1=ans

print(ans)


### FIXED CODE ###

N,M=map(int,input().split())
a=list(int(input())for _ in range(M))
L=[1 for i in range(N+1)]
dp=[0 for _ in range(N+1)]
#L[0]=0
dp[0]=1
mod=1000000007
for j in a:
    L[j]=0
for i in range(1,N+1):
    if i>=2:
        dp[i]=(dp[i-1]*L[i-1]+dp[i-2]*L[i-2])*L[i]

    elif i==1:
        dp[i]=1
    dp[i]%=mod

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

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

n = int(input())
s = list(input().split())
n = int(input())
t = list(input().split())
cnt = 0
for i in range(n):
    if t[i] in s:
        cnt += 1

print(cnt)


### FIXED CODE ###

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

input()
s = set(input().split())
input()
t = set(input().split())
print(len(s & t))
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for _ in range(K):
        B = [0]*(N+1)
        for i, a in enumerate(A):
            B[max(0, i-a)] += 1
            B[min(N, i+a+1)] -= 1
        for j in range(1, N):
            B[j] += B[j-1]
        if A == B[:-1]:
            A = B[:-1]
            break
        A = B[:-1]

    ans = ' '.join(list(map(str, A)))
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from numba import jit
import sys
input = sys.stdin.readline


@jit
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for _ in range(K):
        B = [0]*(N+1)
        for i, a in enumerate(A):
            B[max(0, i-a)] += 1
            B[min(N, i+a+1)] -= 1
        for j in range(1, N):
            B[j] += B[j-1]
        if A == B[:-1]:
            A = B[:-1]
            break
        A = B[:-1]

    ans = ' '.join(list(map(str, A)))
    print(ans)


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

alpha2num = lambda c: ord(c) - ord('a') + 1

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

ans = ''
len_ans = 0

alpha = 'abcdefghijklmnopqrstuvwxyz'
alpha = list(alpha)

l = [0] * 27
c = []

#for i in alpha:
#    tmp = [j for j, x in enumerate(S) if x == i]
#    if len(tmp) >= 2:
#        for j in range(len(tmp)):
#            l.append(tmp[j])



for i in range(len(alpha)):
    tmp = [j for j, x in enumerate(S) if x == alpha[i]]
    if len(tmp) >= 2:
        l[i+1] = (len(tmp))
        for j in range(len(tmp)):
            c.append(tmp[j])
c.sort()

#print(l)
#print(c)

t = [0] * 27

ans = []

#print(N)
for i in range(N):
    t = [0] * 27
    for j in range(i, N):
        if t[alpha2num(S[j])] + 1 <= l[alpha2num(S[j])]//2:
            t[alpha2num(S[j])] += 1
            if j == N-1:
                ans.append(''.join(S[i:j+1]))

        else: 
            ans.append(''.join(S[i:j]))
            break

#print(ans)
ans2 = [x for x in set(ans) if ans.count(x) > 1]
#print(ans2) 


ans = 0
for i in range(len(ans2)):
    tmp = len(ans2[i])
    ans = max(ans, tmp)

print(ans)

### FIXED CODE ###

n = int(input())
s = list(input())

dp = [[0] * n for _ in range(n)]
for i in range(n-1, -1, -1):
    for j in range(n-1, -1, -1):
        if s[i] == s[j]:
            if j+1 <= n-1 and i+1 <= n-1:
                dp[i][j] = dp[i+1][j+1] + 1
            else:
                dp[i][j] = 1
                
for i in range(n):
    for j in range(n):
        dp[i][j] = min(abs(i-j), dp[i][j])

ans = 0
for i in range(n):
    ans = max(ans, max(dp[i]))
print(ans)
### BUGGY CODE ###

def main():
	n = int(input())

	info = []
	for i in range(n):
		l = list(map(int, input().split()))
		info.append(l)

	for k in range(info[0][2], info[0][2] + 201):
		for i in range(101):
			for j in range(101):
				# [i][j]に高さkの頂上があった場合
				flg = 0
				for l in info:
					#print(l)
					deltax = abs(l[0] - i)
					deltay = abs(l[1] - j)
					guessh = max(k - deltax - deltay, 0)
					#print(guessh, k)
					if guessh != l[2]:
						flg = 1
						break
				#print("i,j,k,flg: ", i,j,k,flg)
				if flg == 0:
					print(i, j, k)
					return

if __name__ == '__main__':
	main()


### FIXED CODE ###

def main():
	n = int(input())

	info = []
	for i in range(n):
		l = list(map(int, input().split()))
		info.append(l)

	for k in range(info[0][2], info[0][2] + 201):
		for i in range(101):
			for j in range(101):
				# [i][j]に高さkの頂上があった場合
				flg = 0
				for l in info:
					#print(l)
					deltax = abs(l[0] - i)
					deltay = abs(l[1] - j)
					guessh = max(k - deltax - deltay, 0)
					#print(guessh, k)
					if guessh != l[2]:
						flg = 1
						break
				#print("i,j,k,flg: ", i,j,k,flg)
				if flg == 0:
					print(i, j, k)
					return

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

n, w = list(map(int, input().strip().split()))
data = []
for i in range(n):
    data.append(list(map(int, input().strip().split())))

dp = {}

# i番目以降から重さをz以下にするように選ぶときの最大の価値
def rec(i, z):
    global dp
    if (i, z) in dp:
        return dp[(i, z)]

    if i == n:
        return 0

    # i 個目のものを入れられない場合
    elif data[i][0] > z:
        ret = rec(i + 1, z)
    else:
        # 入れられる場合、入れるときと入れないときのうち大きい方を返す
        # 入れるとき
        v1 = data[i][1] + rec(i + 1, z - data[i][0])
        # 入れないとき
        v2 = rec(i + 1, z)
        ret = max(v1, v2)
        dp[(i, z)] = ret
    return ret

print(rec(0, w))

### FIXED CODE ###

n, w = map(int, input().strip().split())
data = [list(map(int, input().strip().split())) for _ in range(n)]

# i番目に重さがj以下となるように選んだときの価値の総和の最大値
dp = [[0] * (w + 1) for _ in range(n)]

for i in range(0, n):
    for j in range(w + 1):
        # i 番目の品物の重さと価値
        wi, vi = data[i]
        if i == 0:
            take = vi if j - wi >= 0 else 0
            miss = 0
            dp[i][j] = max(take, miss)
        else:
            # i番目の品物を入れる場合
            take = dp[i - 1][j - wi] + vi if j - wi >= 0 else 0
            # 入れない場合
            miss = dp[i - 1][j]
            dp[i][j] = max(take, miss)

print(max(dp[n - 1]))
### BUGGY CODE ###

S = input()
N = len(S)

dp = [0] * 2019
for i in reversed(range(N)):
    mod = int(S[i:]) % 2019
    dp[mod] += 1

ret = [i*(i-1)//2 for i in dp if i > 1]
print(sum(ret) + dp[0])

### FIXED CODE ###

from collections import Counter

S = input()
N = len(S)

dp = [0] * N
dp[N-1] = int(S[N-1])
times = 10
for i in reversed(range(1, N)):
    dp[i-1] = (dp[i] + times * int(S[i-1])) % 2019
    times *= 10
    times %= 2019

T = Counter(dp)
ans = T[0]
for t in T.values():
    ans += t*(t-1)//2

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

def calc(num1,num2,t):
    if num1!=0:
        if num1>=t:
            num1-=t
            num2+=t
        else:
            num2+=num1
            num1=0
    return num1,num2
    

n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
num=[n,0,0,0,0,0]
time=0
while num[5]<n:
    num[4],num[5]=calc(num[4],num[5],e)
    num[3],num[4]=calc(num[3],num[4],d)
    num[2],num[3]=calc(num[2],num[3],c)
    num[1],num[2]=calc(num[1],num[2],b)
    num[0],num[1]=calc(num[0],num[1],a)
    time+=1
print(time)

### FIXED CODE ###

import math

n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

num=math.ceil(n/(min(a,b,c,d,e)))
print(num+4)
### BUGGY CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
 
n = int(input())
s = input()
pass_list = list(map(lambda x: str(x).zfill(3), range(1000)))
res = 0
 
for p in pass_list:
    
    ptr = 0
    one = False
    two = False
    three = False
    
    for i in range(len(s)):
        if(s[i] == p[0]):
            ptr = i
            one = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[1]):
            ptr = i
            two = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[2]):
            ptr = i
            three = True
            break
    
    if(one and two and three): res += 1
 
print(res)

### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]

n = int(input())
s = input()
pass_list = list(map(lambda x: str(x).zfill(3), range(1000)))
res = 0

for p in pass_list:
    
    ptr = 0
    one = False
    two = False
    three = False
    
    for i in range(len(s)):
        if(s[i] == p[0]):
            ptr = i
            one = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[1]):
            ptr = i
            two = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[2]):
            ptr = i
            three = True
            break
    
    if(one and two and three): res += 1

print(res)
### BUGGY CODE ###

N=int(input())
c=input()
ans=len(c)
for i in range(N+1):
    ans=min(ans,max(c[i:].count('R'),c[:i].count('W')))
print(ans)

### FIXED CODE ###

N=int(input())
c=input()
R=c.count('R')
W=0
ans=[R,c.count('W')]
for i in range(N):
    if c[i]=='W':
        W+=1
    else:
        R-=1
    ans.append(max(R,W))
print(min(ans))
### BUGGY CODE ###

a,b,x=map(int, input().split())
ls=[i for i in range(0,b+1,x) if i>=a]
print(len(ls))

### FIXED CODE ###

a,b,x=map(int, input().split())
print(b//x-(a-1)//x)
### BUGGY CODE ###

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

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
for i in range(1,N+1):
    A.append(i)
ans = collections.Counter(A)
tmp = sorted(ans.items())
for i in range(N):
    print(tmp[i][1]-1)
### BUGGY CODE ###

N,W=map(int,input().split())
weights,profits = [0]*N, [0]*N
def solve_knapsack(capacity):
    # basic checks
    n = len(profits)
 
    dp = [0]*(capacity + 1)
    # populate the capacity = 0 columns, with '0' capacity we have '0' profit

    for i in range(0, n):
        weights[i],profits[i] = map(int,input().split())
        for c in range(capacity, weights[i]-1, -1):
            dp[c] = max(profits[i] + dp[c - weights[i]], dp[c])
 
    # maximum profit will be at the bottom-right corner.
    return dp[capacity]
  
def main():
 
    res = solve_knapsack(W)
 
    print(res)
if __name__ == "__main__":
	main()

### FIXED CODE ###

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

N = int(input())

A = list(map(int, input().split()))
sum = 0
for i in range(N-1):
    for m in range(i+1, N):
        sum += A[i]*A[m]
        if sum > 1000000007:
            sum = sum%1000000007


print(sum)

### FIXED CODE ###

N = int(input())

A = list(map(int, input().split()))
S = sum(A)
ans = 0
for i in range(N):
    S -= A[i]
    ans += A[i] * S
    

ans = ans % (10 ** 9  +7)        

print(ans)