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


def main():
  from collections import defaultdict
  from collections import Counter
  
  n = int(input())
  a = list(map(int, input().split()))
  
  d = Counter(a)
  e = defaultdict(int)
  
  
  
  func = lambda x: x*(x-1)//2 if x>=2 else 0
  
  ppp = ''
  
  for x in a:
    get = e.get(x)
    if get == None:
      tmp = d.copy()
      tmp[x] -= 1
      h = list(tmp.values())
      i = list(map(func, h))
      ans = sum(i)
      e[x] = ans
      ppp += str(ans) + '\n'
    else:
      ppp += str(get) + '\n'
    
   
  print(ppp)
      
 
if __name__=='__main__':
    main()


### FIXED CODE ###

def main():
  from collections import defaultdict
  from collections import Counter
  
  n = int(input())
  a = list(map(int, input().split()))
  
  d = Counter(a)
  e = defaultdict(int)
  
  func = lambda x: x*(x-1)//2 if x>=2 else 0
  v = list(d.values())
  base = sum(list(map(func, v)))
  
  for k,v in d.items():
    if v<=1:
      e[k] = base - 0
    else:
      e[k] = base - ( v*(v-1)//2 - (v-1)*(v-2)//2 )
    
  p = [str(e[x])+'\n' for x in a]
  q = ''.join(p)
  print(q)
      
 
if __name__=='__main__':
    main()
### BUGGY CODE ###

import sys
N = int(input())
mylist = list(map(int,input().split()))
if 0 in mylist:
    print(0)
    sys.exit()
else:
    ans = 1
    for i in mylist:
        ans *= i
if ans <= 10**18:
    print(ans)
else:
    print(-1)

### FIXED CODE ###

import math
import sys
N = int(input())
mylist = list(map(int, input().split()))
mylist.sort(reverse = True)
#print(mylist)
if mylist[-1] == 0:
    print(0)
    sys.exit()
else:
    myans = 1
    for m in mylist:
        myans *= m
        if myans > 10**18:
            print(-1)
            sys.exit()
    print(myans)
### BUGGY CODE ###

from collections import Counter
from itertools import product

N = int(input())
S = input().strip()
dic = Counter(S)
mod = 10**9 + 7

ans = []
ls =list(product([0, 1], repeat=len(dic)))
ls.pop(0)

a = []
for i in dic:
    a.append(dic[i])

for x in ls:
    num = 1
    for z, y in zip(a, x):
        if y == 1:
            num = (z*num)%mod
    ans.append(num)
print(sum(ans)%mod)

### FIXED CODE ###

from collections import Counter
from itertools import product
 
N = int(input())
S = input().strip()
dic = Counter(S)
mod = 10**9 + 7

ans = 1
for x in dic:
    ans = ans*(dic[x]+1)%mod
print(ans-1)
### BUGGY CODE ###

import numpy as np
import math
from functools import reduce

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

# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

k = int(input())

ans_array = np.zeros((k, k, k), dtype = np.int)

for i in range(k):
  for j in range(k):
    for h in range(k):
      ans_array[i, j, h] = math.gcd(math.gcd(i+1, j+1), h+1)

# print(ans_array)

ans = np.sum(ans_array)

print(ans)

### FIXED CODE ###

import math

k = int(input())

ans = 0

for i in range(k):
  for j in range(i,k):
    for h in range(j, k):
      if i == j == h:
        ans += math.gcd(math.gcd(i+1, j+1), h+1)
      elif (i != j) and (j != h) and (i != h):
        ans += math.gcd(math.gcd(i+1, j+1), h+1) * 6
      else:
      	ans += math.gcd(math.gcd(i+1, j+1), h+1) * 3
      
print(ans)
### BUGGY CODE ###

import sys
input=sys.stdin.readline

def calc():
  mod=998244353
  n,s=map(int,input().split())
  arr=list(map(int,input().split()))
  dp=[[0]*(s+1) for _ in range(n+1)]
  dp[0][0]=1
  for i in range(1,n+1):
    val=arr[i-1]
    for j in range(s,-1,-1):
      dp[i][j]=2*dp[i-1][j]
      dp[i][j]%=mod
      if j-val>=0 and dp[i-1][j-val]!=0:
        dp[i][j]+=dp[i-1][j-val]
  print(dp[n][s]%mod)
calc()

### FIXED CODE ###

import sys
input=sys.stdin.readline

def calc():
  mod=998244353
  n,s=map(int,input().split())
  arr=list(map(int,input().split()))
  dp=[0]*(s+1)
  dp[0]=1
  ans=0
  for i in range(1,n+1):
    val=arr[i-1]
    for k in range(s,-1,-1):
      dp[k]*=2
      dp[k]%=mod
      if k>=val and dp[k-val]!=0:
        dp[k]+=dp[k-val]
        dp[k]%=mod
  print(dp[s]%mod)
calc()
### BUGGY CODE ###

def calc_lcs(X, Y):
    m = len(X)
    n = len(Y)
    X = ' ' + X
    Y = ' ' + Y
    c = [[0]*1001 for i in range(1000+1)]
    for i in range(1, m+1):
        for j in range(1, n+1):
            if X[i] == Y[j]:
                c[i][j] = c[i - 1][j - 1] + 1
            elif c[i - 1][j] >= c[i][j - 1]:
                c[i][j] = c[i - 1][j]
            else:
                c[i][j] = c[i][j - 1]
    return check_max(c)


def check_max(array):
    max_lcs = 0
    for row in array:
        temp_max = max(row)
        if temp_max > max_lcs:
            max_lcs = temp_max
    return max_lcs


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    # f = open('input.txt')
    # num = int(f.readline())

    for _ in range(num):
        X = input()
        Y = input()
        # X = f.readline().strip()
        # Y = f.readline().strip()

        # ???????????????
        result = calc_lcs(X, Y)

        # ???????????¨???
        print(result)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C

最長共通部分列
"""


c = []
def prep_array(X, Y):
    global c
    """ 値が0の2次元配列を用意する。サイズは入力データの最大値を想定して縦横(1000+1)以上必要。 """
    # from array import array
    # c = [array('I', [0] * (len(X)+1)) for _ in range(len(Y)+1)]  #  arrayで用意
    c = [[0]*(len(Y)+2) for _ in range(len(X)+2)] #  リストで用意
    return c


def check_max(array):
    """ 2次元配列の中の最大の値を返す """
    max_lcs = 0
    for row in array:
        temp_max = max(row)
        if temp_max > max_lcs:
            max_lcs = temp_max
    return max_lcs


def calc_lcs4(X, Y, c):
    """
    Y[j]のアクセス方法を変更
    リストの値を一旦変数に保存するように変更
    最長共通部分長を関数内で計算するように変更
    4/5 のテストデータを使用してプロファイリングすると実効時間は 5.6秒
    """
    X = ' ' + X
    Y = ' ' + Y
    m = len(X)
    n = len(Y)
    max_lcs = 0

    pre_row = c[0]
    for i in range(1, m):
        row = c[i]
        XX = X[i]
        for j, YY in enumerate(Y):
            if XX == YY:
                pr_j1 = pre_row[j - 1]
                row[j] = pr_j1 + 1
                if pr_j1+1 > max_lcs:
                   max_lcs = pr_j1 + 1
            else:
                pr_j = pre_row[j]
                r_j1 = row[j-1]
                if pr_j >= r_j1:
                    row[j] = pr_j
                else:
                    row[j] = r_j1
        pre_row = row
    return max_lcs


if __name__ == '__main__':
    # データの入力
    num = int(input())
    #f = open('input.txt')
    #num = int(f.readline())

    for _ in range(num):
        X = input().strip()
        Y = input().strip()

        # 処理の実行
        result = calc_lcs4(X, Y, prep_array(X, Y))

        # 結果の表示
        print(result)
### BUGGY CODE ###

n,m=map(int, input().split())
pl=[0]*m
yl=[0]*m
sl={}
cl=[0]*m
for i in range(m):
    p,y = map(int, input().split())
    pl[i]=p
    yl[i]=y
    if not p in sl:
        sl[p] = [(y, i)]
        continue
    no=True
    for j, tl in enumerate(sl[p]):
        if tl[0] > y:
            sl[p].insert(j, (y, i))
            no=False
            break
    if no:
        sl[p].append((y, i))

for i in range(m):
    p=pl[i]
    for j, tl in enumerate(sl[p]):
        if tl[1]==i:
            cl[i] = j+1

for i in range(m):
    print("%06d%06d" % (pl[i], cl[i]))


### FIXED CODE ###

import bisect
n,m=map(int, input().split())
pl=[0]*100000
yl=[0]*100000
ol=[[] for i in range(100001)]
for i in range(m):
    pl[i],yl[i] = map(int, input().split())
    ol[pl[i]].append(yl[i])
for i in range(1,n+1):
    ol[i].sort()
for i in range(m):
    print("%06d%06d" % (pl[i], bisect.bisect_right(ol[pl[i]], yl[i])))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline

class RollingHash():
    def __init__(self, s):
        self.length = len(s)
        self.base = 1009
        self.mod = (1 << 61) - 1
        self.hash = [0] * (self.length + 2)
        self.pow = [1] * (self.length + 2)

        for i in range(self.length):
            self.hash[i+1] = (self.hash[i] + ord(s[i])) * self.base % self.mod
            self.pow[i+1] = self.pow[i] * self.base % self.mod
        self.pow[self.length+1] = self.pow[self.length] * self.base % self.mod 

    def get(self, l, r):
        t = self.hash[r] - self.hash[l] * self.pow[r-l] % self.mod
        return t % self.mod
    
    def get_wsuff(self, l, r, suff):
        hash_suff = (self.hash[r] + ord(suff)) * self.base % self.mod
        t = hash_suff - self.hash[l] * self.pow[r+1-l] % self.mod
        return t % self.mod

ss = []
n = int(input())
for _ in range(n):
    ss.append(input().rstrip())
ss.sort(key=lambda x: len(x), reverse=True)

words = dict()
ans = 0
orda = ord("a")
for s in ss:
    word_len = len(s)
    s_rev = s[::-1]
    RH = RollingHash(s_rev)
    rh = RH.get(0, word_len-1)
    if rh in words:
        ans += words[rh][ord(s_rev[-1]) - orda]
    initial = set()
    for i, ch in enumerate(s):
        initial.add(ord(ch) - orda)
        for key in initial:
            rh = RH.get(0, word_len-i-1)
            if rh in words:
                words[rh][key] += 1
            else:
                words[rh] = [0] * 26
                words[rh][key] += 1
print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import defaultdict

def empty_list():
    return [0] * 26

class RollingHash():
    def __init__(self, s):
        length = len(s)
        base = 1009
        # self.mod = (1 << 61) - 1
        self.mod = 67280421310721
        self.hash = [0] * (length + 2)
        self.pow = [1] * (length + 2)

        for i in range(length):
            self.hash[i+1] = (self.hash[i] + s[i]) * base % self.mod
            self.pow[i+1] = self.pow[i] * base % self.mod
        self.pow[length+1] = self.pow[length] * base % self.mod 

    def get(self, l, r):
        t = self.hash[r] - self.hash[l] * self.pow[r-l] % self.mod
        return t % self.mod

ss = []
n = int(input())
for _ in range(n):
    ss.append([ord(item) for item in input().rstrip()])
ss.sort(key=lambda x: len(x), reverse=True)

orda = ord("a")
words = defaultdict(empty_list)
ans = 0
for s in ss:
    word_len = len(s)
    s_rev = s[::-1]
    RH = RollingHash(s_rev)
    rh = RH.get(0, word_len-1)
    ans += words[rh][s_rev[-1] - orda]
    initial = [0] * 26 
    for i, ch in enumerate(s):
        initial[ch - orda] = 1
        for j, is_initial in enumerate(initial):
            if is_initial:
                rh = RH.get(0, word_len-i-1)
                words[rh][j] += 1
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
inf = 10 ** 9 + 7
total = 0

l = len(a)

for i in range(l - 1):
    for j in range(i + 1, l):
        a[i] %= inf
        a[j] %= inf
        total += (a[i]*a[j]) % inf

print(total % inf)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
inf = 10 ** 9 + 7

S = sum(a)
S2 = 0

for i in a:
    S2 += i * i

print((S*S - S2)//2 % inf)
### BUGGY CODE ###

n = int(input())

str_list = []
for n in range(n):
    str_list.append(input())

cnt_dict = {_ : str_list.count(_) for _ in set(str_list)}

tmp = max(cnt_dict.values())
for ans in sorted([l[0] for l in cnt_dict.items() if l[1] == tmp]):
    print(ans)


### FIXED CODE ###

from collections import Counter

N = int(input())
S = [input() for _ in range(N)]

dic = Counter(S)

tmp = max(dic.values())
ans = [key for key, value in dic.items() if value == tmp]

# もうちょいかっこいい書き方があるはず。リストを1行1str出力 and 最後に改行しないように
for key in sorted(ans):
    print(key, end="")
    print("")
### BUGGY CODE ###

n,k=map(int,input().split())
d=set(map(int,input().split()))
i=n
while True:
    if not set((str(i)))&d: i+=1
    else:
        print(i)
        exit()

### FIXED CODE ###

n,k=map(int,input().split())
d=set(map(int,input().split()))
i=n
while True:
    temp=i
    flag=1
    while temp>0:
        if temp%10 in d:
            flag=0
            break
        temp//=10
    if flag:
        print(i)
        break
    i+=1
### BUGGY CODE ###

#! -*- coding: UTF-8 -*-

import itertools

k, s = map(int, input().strip().split())
result = 0
for i in itertools.product(range(k + 1), repeat=3):
    if sum(i) == s:
        result += 1
print(result)
    


### FIXED CODE ###

k, s = list(map(int, input().split()))
result = 0
for x in range(k+1):
  for y in range(k+1):
    if 0 <= s-x-y <= k:
      result += 1
print(result)
### BUGGY CODE ###

def inv_gcd(a,b):
    a=a%b
    if a==0:
        return (b,0)
    s=b;t=a
    m0=0;m1=1
    while(t):
        u=s//t
        s-=t*u
        m0-=m1*u
        s,t=t,s
        m0,m1=m1,m0
    if m0<0:
        m0+=b//s
    return (s,m0)
def inv_mod(x,m):
    assert 1<=m
    z=inv_gcd(x,m)
    assert z[0]==1
    return z[1]
def crt(r,m):
    assert len(r)==len(m)
    n=len(r)
    r0=0;m0=1
    for i in range(n):
        assert 1<=m[i]
        r1=r[i]%m[i]
        m1=m[i]
        if m0<m1:
            r0,r1=r1,r0
            m0,m1=m1,m0
        if (m0%m1==0):
            if (r0%m1!=r1):
                return (0,0)
            continue
        g,im=inv_gcd(m0,m1)
        u1=m1//g
        if ((r1-r0)%g):
            return (0,0)
        x=(r1-r0)//g % u1*im%u1
        r0+=x*m0
        m0*=u1
        if r0<0:
            r0+=m0
    return (r0,m0)
N=int(input())
def divide(n):
    res=[]
    i=1
    while(i*i<=n):
        if n%i==0:
            res.append(i)
            if i*i!=n:
                res.append(n//i)
        i+=1
    return res
ans=2*N
for b in divide(2*N):
    c=(2*N)//b
    tmp=crt([0,c-1],[b,c])
    if tmp==(0,0):
        continue
    x=tmp[0]
    if x==0:
        x=tmp[1]
    ans=min(x,ans)
print(ans)


### FIXED CODE ###

def inv_gcd(a,b):
    a=a%b
    if a==0:
        return (b,0)
    s=b;t=a
    m0=0;m1=1
    while(t):
        u=s//t
        s-=t*u
        m0-=m1*u
        s,t=t,s
        m0,m1=m1,m0
    if m0<0:
        m0+=b//s
    return (s,m0)
def inv_mod(x,m):
    assert 1<=m
    z=inv_gcd(x,m)
    assert z[0]==1
    return z[1]
def crt(r,m):
    assert len(r)==len(m)
    n=len(r)
    r0=0;m0=1
    for i in range(n):
        assert 1<=m[i]
        r1=r[i]%m[i]
        m1=m[i]
        if m0<m1:
            r0,r1=r1,r0
            m0,m1=m1,m0
        if (m0%m1==0):
            if (r0%m1!=r1):
                return (0,0)
            continue
        g,im=inv_gcd(m0,m1)
        u1=m1//g
        if ((r1-r0)%g):
            return (0,0)
        x=(r1-r0)//g % u1*im%u1
        r0+=x*m0
        m0*=u1
        if r0<0:
            r0+=m0
    return (r0,m0)
N=int(input())
def divide(n):
    res=[]
    i=1
    while(i*i<=n):
        if n%i==0:
            res.append(i)
            if i*i!=n:
                res.append(n//i)
        i+=1
    return res
ans=2*N
for b in divide(2*N):
    c=(2*N)//b
    tmp=crt([0,c-1],[b,c])
    if tmp==(0,0):
        continue
    x=tmp[0]
    if x==0:
        x=tmp[1]
    ans=min(x,ans)
print(ans)
### BUGGY CODE ###

r=range;_,*s=open(0)
h,w,k=map(int,_.split())
m=9e9
for i in r(1<<h-1):
  t,v,l=[],-1,1
  for j in r(h):
    if i>>j&1:t+=j+1,;l+=1
  t+=h,
  c=[0]*l
  for i in r(w):
    b=f=g=0;u=[]
    for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k
    v+=f
    if f:c=u
  if~g:m=min(m,v+l)
print(m)

### FIXED CODE ###

r=range;_,*s=open(0)
h,w,k=map(int,_.split())
m=9e9
for i in r(1<<h-1):
 t,v,l=[],-1,1
 for j in r(h):
  if i>>j&1:t+=j+1,;l+=1
 t+=h,
 c=[0]*l
 for i in r(w):
  b=f=g=0;u=[]
  for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k
  v+=f
  if f:c=u
 if not g:m=min(m,v+l)
print(m)
### BUGGY CODE ###

N, X = map(int, input().split())
cities = [int(i) for i in input().split()]
cities.sort()
dist = [int(abs(i-X)) for i in cities]
dist.sort()
D = 1

for i in reversed(range(1, min(dist)+1)): #最大公約数を1から順に考える
    for j in range(len(dist)): #全ての数を割ってみる
        if dist[j]%i != 0:
            flag = False
            break
        else:
            flag = True
    if flag:
        D = i
        break
print(D)

### FIXED CODE ###

N, X = map(int, input().split())
cities = [int(i) for i in input().split()]
cities.sort()
dist = [int(abs(i-X)) for i in cities]
dist.sort()
 
if N==1:
    print(max(dist))
else:
    while len(dist)>0:
        m = min(dist)
        dist = [int(i%m) for i in dist]
        dist.sort()
        while len(dist)>0 and dist[0]==0:
            dist.remove(0)
        if len(dist)==0:
            break
        else:
            dist.append(m)
    print(m)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
S_list =[]
for _ in range(N):
  s = input()
  s = sorted(list(s))
  S_list.append(s)
counter = 0
for i in range(len(S_list)):
  for j in range(len(S_list)-1-i):
    if S_list[i] == S_list[i+j+1]:
      counter += 1
print(counter)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)
### BUGGY CODE ###

# coding:utf-8

Black = "#"
White = "."

dir_x = [1, 0, -1, 0]
dir_y = [0, 1, 0, -1]


def main():
    H, W = map(int, input().split())
    masu = []
    step = 0
    count = W*H
    memo = [[-1]*W for i in range(H)]
    steplist = []

    for y in range(H):
        temp_in = input()
        for x in range(W):
            if temp_in[x] == Black:
                memo[y][x] = 0
                count -= 1
                steplist.append([y, x])

    while count > 0:
        step += 1
        next_list = []
        for l_yx in steplist:
            for i in range(4):
                temp_x = l_yx[1] + dir_x[i]
                temp_y = l_yx[0] + dir_y[i]
                if temp_x >= 0 and temp_x < W and temp_y >= 0 and temp_y < H:
                    if memo[temp_y][temp_x] < 0:
                        memo[temp_y][temp_x] = step
                        count -= 1
                        next_list.append([temp_y, temp_x])
        steplist = next_list
    print(step)


if __name__ == "__main__":
    main()


### FIXED CODE ###

# coding:utf-8

Black = "#"
White = "."

dir_x = [1, 0, -1, 0]
dir_y = [0, 1, 0, -1]


def main():
    H, W = map(int, input().split())
    step = 0
    count = W*H
    memo = [[-1]*W for i in range(H)]
    steplist = []

    for y in range(H):
        temp_in = input()
        for x in range(W):
            if temp_in[x] == Black:
                memo[y][x] = 0
                count -= 1
                steplist.append([y, x])

    while count > 0:
        step += 1
        next_list = []
        for l_yx in steplist:
            for i in range(4):
                temp_x = l_yx[1] + dir_x[i]
                temp_y = l_yx[0] + dir_y[i]
                if temp_x >= 0 and temp_x < W and temp_y >= 0 and temp_y < H:
                    if memo[temp_y][temp_x] < 0:
                        memo[temp_y][temp_x] = step
                        count -= 1
                        next_list.append([temp_y, temp_x])
        steplist = next_list
    print(step)


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

import sys
input=sys.stdin.readline
R,C,k=map(int,input().split())
A=[[0]*C for i in range(R)]
for i in range(k):
  r,c,v=map(int,input().split())
  A[r-1][c-1]=v
dp=[[[0,0,0,0] for j in range(C+1)] for i in range(R+1)]
for i in range(1,R+1):
  for j in range(1,C+1):
    V=A[i-1][j-1]
    dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j][1],dp[i-1][j][2],dp[i-1][j][3],dp[i][j-1][0])
    dp[i][j][1]=max(dp[i][j][0]+V,dp[i][j-1][1])
    dp[i][j][2]=max(dp[i][j-1][1]+V,dp[i][j-1][2])
    dp[i][j][3]=max(dp[i][j-1][2]+V,dp[i][j-1][3])
print(max(dp[-1][-1]))

### FIXED CODE ###

import sys
input=sys.stdin.readline
R,C,k=map(int,input().split())
A=[[0]*C for i in range(R)]
for i in range(k):
  r,c,v=map(int,input().split())
  A[r-1][c-1]=v
dp0=[[0]*(C+1) for i in range(R+1)]
dp1=[[0]*(C+1) for i in range(R+1)]
dp2=[[0]*(C+1) for i in range(R+1)]
dp3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
  for j in range(1,C+1):
    V=A[i-1][j-1]
    dp0[i][j]=max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1])
    dp1[i][j]=max(dp0[i][j]+V,dp1[i][j-1])
    dp2[i][j]=max(dp1[i][j-1]+V,dp2[i][j-1])
    dp3[i][j]=max(dp2[i][j-1]+V,dp3[i][j-1])
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))
### BUGGY CODE ###

s = input()[::-1]
length = len(s)
a = [0] * length
d = [0] * length
ans = [0] * 2019

a[0] = int(s[0])
d[0] = a[0]
ans[d[0]] += 1

for i in range(1, length):
    a[i] = int(s[i]) * 10**i % 2019
    d[i] = (d[i-1] + a[i]) % 2019
    ans[d[i]] += 1

print(int(sum([ans[i] * (ans[i]-1) for i in range(2019)]) / 2) + ans[0])

### FIXED CODE ###

import numpy as np

s = input()[::-1]
length = len(s)
a = np.zeros(length, dtype=int)
d = np.zeros(length, dtype=int)
ans = np.zeros(2019, dtype=int)
x = 10

a[0] = int(s[0])
d[0] = a[0]
ans[d[0]] += 1

for i in range(1, length):
    a[i] = int(s[i]) * x % 2019
    d[i] = (d[i-1] + a[i]) % 2019
    ans[d[i]] += 1
    x = x * 10 % 2019

ans_c = ans[np.nonzero(ans)]

print(int(sum([ans_c[i] * (ans_c[i]-1) for i in range(ans_c.shape[0])]) / 2) + ans[0])
### BUGGY CODE ###

s = input()
ans = 0
l = len(s)

for i in range(l - 3):
    if int(s[i:i+2]) % 2 != 0: continue
    for j in range(i + 4, l + 1):
        sub_s = int(s[i:j])
        if sub_s % 2019 == 0: ans += 1
print(ans)

### FIXED CODE ###

s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2
print(ans)
### BUGGY CODE ###

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

ans = 0
for i in range(N//R+1):
    if i * R > N:
        break
    for j in range(N//G+1):
        if i * R + j * G > N:
            break
        for k in range(N//B+1):
            if i * R + j * G + B * k > N:
                break
            if i * R + j * G + B * k == N:
                ans += 1
                
print(ans)

### FIXED CODE ###

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

ans = 0

for g in range(N//G+1):
    for b in range(N//B+1):
        s = N-g*G-b*B
        if s < 0:
            break
        if s%R == 0:
            ans += 1

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

import sys
from bisect import insort_right
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
for i in range(M):
  tmp = A[-1-i]
  insort_right(A,tmp//2)
print(sum(A[:-M]))

### FIXED CODE ###

import sys
import heapq
from bisect import insort_right
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-a for a in A]
heapq.heapify(A)
  
for i in range(M):
  tmp = heapq.heappop(A)
  heapq.heappush(A,int(tmp/2))
print(sum([-a for a in A]))
### BUGGY CODE ###

n,m = map(int, input().split())
u = set(range(1, n+1))
for i in range(m):
	l,r = map(int, input().split())
	u = u & set(range(l, r+1))
print(len(u))

### FIXED CODE ###

n,m = map(int, input().split())
minn, maxn = 1, n
for i in range(m):
	l, r = map(int,input().split())
	minn, maxn = max(minn, l), min(maxn, r)
print(max(maxn-minn+1, 0))
### BUGGY CODE ###

n = int(input())
A = [0] + list(map(int,input().split())) + [0]
B = [0]*n
C = [0]*(n+1)

for i in range(n):
    B[i]=abs(A[i]-A[i+2])
for i in range(n+1):
    C[i]=abs(A[i]-A[i+1])
for i in range(n):
    print(sum(C[0:i])+B[i]+sum(C[i+2:n+1]))

### FIXED CODE ###

n = int(input())
A = [0] + list(map(int,input().split())) + [0]
B = [0]*n
C = [0]*(n+1)

for i in range(n):
    B[i]=abs(A[i]-A[i+2])
for i in range(n+1):
    C[i]=abs(A[i]-A[i+1])
sumC = sum(C)
for i in range(n):
    print(sumC+B[i]-C[i]-C[i+1])