peterverebics/CodeNet_Python_118 huggingface dataset:
S = input()
digits = list(map(int,S))
# S = S[::-1]→これが時間かかる

# i~nまでの値をmod2019したときの数
# ls = [0for i in range(2019)]
ls = [0] * 2019

# 0文字の時
ls[0] += 1

x = 0
pow10 = 1
count = 0
for i in reversed(digits):
    x += i*pow10
    x %= 2019
    count += ls[x]
    ls[x] += 1
    pow10 *= 10
    pow10 %= 2019

# for x in ls:
#     count += x*(x-1)/2

print(int(count))
S = input()
if len(S) < 4:
  print(0)
else:
  N = len(S)
  x = 0
  d = [0]*2019
  d[0] = 1
  for i, s in enumerate(reversed(S)):
    x = (x+int(s)*pow(10,i,2019))%2019
    d[x] += 1
  print(sum([m*(m-1)//2 for m in d]))
S = [int(a) for a in input()[::-1]]
m = 2019
N = len(S)
s = 0
p = 1
X = [0] * 2019
X[0] = 1
ans = 0
for a in S:
    s = (s + a * p) % m
    ans += X[s]
    X[s] += 1
    p = p * 10 % m

print(ans)
s=input()
n=len(s)
mod=2019
sum=0
p=1
d={}
d[0]=1
for i in range(n-1,-1,-1):
    sum=(sum+int(s[i])*p)%mod
    if sum in d:
        d[sum]+=1
    else:
        d[sum]=1
    p=(p*10)%mod
ans=0
for v in d.values():
    ans+=(v*(v-1))//2
print(ans)
from collections import Counter
s = input()

ans = 0
mods = [0]
s = [int(a) for a in s[::-1]]
x = 0
for i in range(len(s)):
    x += s[i] * pow(10, i, 2019)
    mods.append(x%2019)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts * (counts-1) // 2
print(ans)
from collections import defaultdict

S = list(input())
S = [int(i) for i in S]
D = defaultdict(int)
mod = 2019

N = len(S)
Mlis = [0]*N
Mlis[-1] = S[-1] % mod

for i in range(N-2, -1, -1):
  Mlis[i] = (Mlis[i+1] + pow(10, N-1-i, mod) * S[i]) % mod

for i in Mlis:
  D[i] += 1

ans = D[0] + sum([i*(i-1)//2 for i in D.values()])

print(ans)
from collections import Counter
import sys

# input = lambda : sys.stdin.readline().rstrip()

S = input()
n = len(S)

M = []
m = 0

for i in range(len(S)-1,-1, -1):
    
    m = (pow(10, n-i, 2019) * int(S[i]) + m) % 2019
    M.append(m)
    
    # print(S[i:n], m)

M.append(0)  # S[n:n] = "" = 0 が抜けるので、付け加える

c = Counter(M)

sum = 0
for i in c.values():
    sum += i * (i - 1) / 2

print(int(sum))
S=input()

out=0
l=[0]*2019
x=0
now=1
for i in S[::-1]:
    x+=now*int(i)
    x%=2019
    l[x]+=1

    now*=10
    now%=2019

for i in l:
    out+=(i-1)*i//2
print(out+l[0])

# # 全探索は間に合わない
# D=len(S)-4
# for ii in range(D+1):
#     for i in range(ii+3,len(S)):
#         T=S[ii:i+1]
#         if int(T)%2019==0:
#             out+=1
# print(out)
s = str(input())
L = len(s)
dict = [0] * 2019
dict[0] += 1
num = 0
for i in range(L-1, (-1), (-1)):
    num += (int(s[i]) * pow(10,(L-i-1), 2019))%2019
    amari = num % 2019
    dict[amari] += 1
ans = 0
for j in range(2019):
    ans += (dict[j]*(dict[j]-1))/2
print(int(ans))
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------

S = input()
S = S[::-1]

m = 2019

A=[0]*m
A[0]=1

a = 0
ans=0
for i,s in enumerate(S):
	a = a + (int(s) * pow(10,i,m))
	a %= m
	
	ans += A[a]
	A[a] += 1

print(ans)
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))
from itertools import combinations
s = input()
d = {0: 1}
tmp = 0
i = 0
for char in s[::-1]:
    tmp += int(char) * pow(10, i, 2019)
    tmp %= 2019
    if tmp not in d:
        d[tmp] = 1
    else:
        d[tmp] += 1
    i += 1

result = 0
for num, v in d.items():
    result += v * (v - 1) // 2

print(result)
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
	s=input()
	len_s=len(s)
	T=[0]*(len_s+1)
	T[-1],T[-2]=0,int(s[-1])
	mod=2019
	for i in range(len_s-2,-1,-1):
		T[i]=(T[i+1]+int(s[i])*pow(10,len_s-i-1,mod))%mod
	tc=list(Counter(T).values())
	ans=0
	for tcc in tc:
		ans+=tcc*(tcc-1)//2
	print(ans)

if __name__=='__main__':
    main()
s=list(input())
s=[int(i) for i in s]
now=0
c=[0]*2019
c[0]=1
for n,i in enumerate(s[::-1]):
    now+=i*pow(10,n,2019)
    c[now%2019]+=1
ans=0
for k in range(2019):
    ans+=c[k]*(c[k]-1)//2
print(ans)
import collections
s=input()
n=len(s)
a=[]
x=0
p=1
for i in range(n):
	j = n-1-i
	c = int(s[j])
	p %= 2019
	x += (p*c)%2019
	p *= 10
	x %= 2019
	a.append(x)
c=collections.Counter(a)
ans = 0
for k,v in c.items():
	if k==0:
		ans += v
	ans += v*(v-1)//2
print(ans)
S = input()
digits = list(map(int, S))
divisor = 2019

rem_count = [0] * divisor
rem_count[0] = 1
num = 0
pow10 = 1
total = 0

for digit in reversed(digits):
    num = digit * pow10 + num
    num %= divisor
    total += rem_count[num % divisor]
    pow10 *= 10
    pow10 %= divisor
    rem_count[num % divisor] += 1

print(total)
import math

M = 2019

S = input().strip()

data = []
l = len(S)
d = 1
for i in range(l):
	data.append((d * int(S[l - i - 1]) % M))
	d = (d * 10 % M)

table = [0] * M
table[0] = 1

count = 0
n = 0
for rem in data:
	n = (n + rem) % M
	count += table[n]
	table[n] += 1

print(count)
S = list(input())
N = len(S)

l = [0] * 2019
temp = 0
e = 1
for i in range(N-1, -1, -1):
    temp += int(S[i]) * e
    temp %= 2019
    l[temp] += 1
    e *= 10
    e %= 2019

ans = l[0]

for i in range(0, 2019):
    ans += l[i] * (l[i]-1) // 2

print(ans)
S = list(map(int,list(input())))

N = len(S)
A = [0]
base = 1
for i in range(N):
	A.append((A[-1] + S[N-1-i] * base) % 2019)
	base = base * 10 % 2019
A.sort()
ans = 0
cnt = 1
for i in range(N):
	if i == N-1:
		if cnt > 1:
			cnt += 1
			ans += (cnt * (cnt - 1)) // 2
	elif A[i] == A[i+1]:
		cnt += 1
	else:
		ans += (cnt * (cnt - 1)) // 2
		cnt = 1
print(ans)
s = input()
n = len(s)

mod = {}

_s = 0
for i in range(n):
  _s = (_s + int(s[-(i + 1)]) * pow(10, i, 2019)) % 2019
  if _s in mod:
    mod[_s] = mod[_s] + 1
  else:
    mod[_s] = 1

ans = 0
for x in mod.keys():
  if x == 0:
    ans += mod[x] * (mod[x] + 1) // 2
  else:
    ans += mod[x] * (mod[x] - 1) // 2

print(ans)
s = input()
s = s[::-1]
l = len(s)
se = dict()

k = 0
for i in range(0,l):
    k+=(pow(10,i,2019)*int(s[i]))
    k%=2019
    if k in se:
        se[k]+=1
    else:
        se[k]=1

ans=0
for j in se:
    i=se[j]
    if i>1:
        ans+=(i*(i-1)//2)
    if j==0:
        ans+=i
print(ans)
s = input()[::-1]
length = len(s)
a = [0] * length
d = [0] * length
ans = [0] * 2019
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 = [i for i in ans if i != 0]

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

def solve(S):
    N = len(S)
    dp = [0 for _ in range(MOD)]
    tmp = 0
    ret = 0
    for i in range(N):
        m = (tmp + int(S[i]) * pow(10, N - i - 1, MOD)) % MOD
        ret += dp[m]
        dp[m] += 1
        tmp = m
    ret += dp[0]
    return ret

if __name__ == "__main__":
    S = input()
    print(solve(S))
N = 2019


def main():
    S = input()
    mod = [0] * N
    ans = 0
    for c in S:
        nxt = [0] * N
        x = int(c)
        for i in range(N):
            nxt[(i*10+x) % N] += mod[i]
        nxt[x] += 1
        ans += nxt[0]
        mod = nxt
    print(ans)


if __name__ == "__main__":
    main()
import sys
tmp=sys.stdin.readline().rstrip()
def main():
   ans=0
   cnt=[0]*2019
   cnt[0]+=1
   t=0
   d=1
   for i in reversed(tmp):
      t=(t+int(i)*d)%2019
      cnt[t]+=1
      d=d*10%2019
   for i in cnt:
      ans+=i*(i-1)//2
   print(ans)
if __name__ == "__main__":
    main()
def main():
    s = input()
    rem = [0] * 2019  # the count of the each remainder: 0 ~ 2018
    rem[0] = 1  # why? can't understand.

    temp = 0
    digit = 1
    for c in s[::-1]:
        # No time to pow.
        temp += int(c) * digit
        rem[temp % 2019] += 1
        digit = digit * 10 % 2019

    return sum(c * (c - 1) // 2 for c in rem)


if __name__ == '__main__':
    print(main())
S=input()
n=len(S)
a=[0]*2019
MOD=2019
current=0
a[0]=1
for i in range(n):
  current=(current+int(S[n-1-i])*pow(10,i,MOD))%MOD
  a[current]+=1
ans=0
for i in range(2019):
  ans+=(a[i]*(a[i]-1))//2
print(ans)
S=input()
N=len(S)
M=2019

remainder=[0]*M
val=0
for i in range(N):
  val=(int(S[N-1-i])*pow(10,i,M)+val)%M
  remainder[val]+=1

ans=remainder[0]
for i in range(2019):
  ans+=remainder[i]*(remainder[i]-1)//2
print(ans)
from collections import defaultdict
S = list(input())[::-1]
n = len(S)
d = defaultdict(int)
d[0] += 1
res = 0
for i, s in enumerate(S):
    res += int(s)*pow(10, i, 2019)
    res %= 2019
    d[res] += 1

ans = 0
for k in d.keys():
    dk = d[k]
    ans += dk*(dk-1)//2
print(ans)
s=input()
n=len(s)
rst=[0 for j in range(2019)]
rst[0]=1
x=0
ans=0
drst=1
for i in range(n):
    y=(int(s[n-1-i])*drst)%2019
    drst=(drst*10)%2019
    x+=y
    if x>=2019:
        x%=2019
    #print(x,y,drst)
    ans+=rst[x]
    rst[x]+=1
#if rst[0]==1:
    #ans+=0

print(ans)
S = input()

cs = {0: 1}

result = 0

n = 0
for i in range(len(S)):
    c = int(S[-i-1])
    n += c * pow(10, i, 2019)
    m = n % 2019
    if m in cs:
        result += cs[m]
        cs[m] += 1
    else:
        cs[m] = 1

print(result)
# D - Multiple of 2019

from collections import Counter

s = input()

count = 0
counter = Counter([0])

suffix = [0] * (len(s) + 1)
pow = 1
for i in range(len(s) - 1, -1, -1):
    suffix[i] = (int(s[i]) * pow + suffix[i + 1]) % 2019
    pow = pow * 10 % 2019
    count += counter[suffix[i]]
    counter[suffix[i]] += 1

print(count)
S=input()[::-1]
l=[0]*2019
a=1
d=0

for s in S:
  d=d+int(s)*a
  l[d%2019]+=1
  a*=10
  a%=2019
  
ans=l[0]
for i in l:
  if i>=2:
    ans+=i*(i-1)//2
    
print(ans)
s = input() [::-1]

cnts = [0] * 2019

cnts[0] = 1

sum_of_digits = 0

d = 1

for c in s:
    sum_of_digits += int(c) * d
    d *= 10
    d %= 2019 # これは d = d % 2019 と同じ
    sum_of_digits %= 2019
    cnts[sum_of_digits] += 1

ans = 0

for cnt in cnts:
    ans += cnt * (cnt - 1)  //  2

print(ans)
# D - Multiple of 2019
S = input()
mod = [1]+[0]*2018
tmp = 0
seki = 1
for k in range(len(S)):
    tmp = (seki*int(S[len(S)-1-k])+tmp)%2019
    mod[tmp] += 1
    seki = (seki*10)%2019
ans = 0
for k in range(2019):
    ans += mod[k]*(mod[k]-1)//2
print(ans)
s = str(input()[::-1])
n=len(s)
mlist,m,d=[],0,1
  
for ss in s:
  m += int(ss) * d
  m %= 2019
  d *= 10
  d %= 2019
  mlist.append(m)
  
l=sorted(mlist)
l.append(2020)
pre,count,ans=0,0,0
for ll in l:
  if pre==ll:
    count+=1
  else:
    ans+=count*(count+1)//2
    pre=ll
    count=0
print(ans)
s=input()
n=0
ans=0
A=[0]*2019
A[0]=1
for i in range(len(s)):
  n=(n+int(s[-1-i])*pow(10,i,2019))%2019
  #print(i,n)
  A[n]+=1
for i in A:
  ans+=i*(i-1)//2
print(ans)
from collections import Counter
Next = [i*10 % 2019 for i in range(2019)]
S = input()
L = list(reversed(S))
Amaris = []#「右から」x桁まで見た場合の余り
amari = 0
kurai = 1
for l in L:
    amari += kurai*int(l)
    amari %= 2019 
    kurai *= 10
    kurai %= 2019
    Amaris.append(amari)
C = Counter(Amaris)
ans = 0 
for d in C.values():
    ans += d*(d-1)//2
print(ans + C[0])
S = list(input())
n = len(S)
res = 0
cur = 0
count = [0] * 2020
count[0] = 1
for i, c in enumerate(map(int, S)):
    cur = (cur * 10 + c) % 2019
    temp = (cur * pow(10, (n - i), 2019)) % 2019
    count[temp] += 1
print(sum(c * (c - 1) // 2 for c in count))
s=input()[::-1]
n=len(s)
p=2019
S=[0 for i in range(n+1)]
ans=[0]*p

x10=1
for j, i in enumerate(s):
  S[j+1]=(S[j]+(x10*int(i)))%p
  x10*=10
  x10%=p
  ans[S[j+1]]+=1

cnt=ans[0]
for a in ans:
  cnt+=(a*(a-1))//2
  
print(cnt)
s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now = (now+i*int(c))%2019
    dp[now] += 1
    i = (i*10)%2019

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))
s = input()
dic = {}
for i in range(2019):
  dic[i] = 0
dic[0] = 1
m = 0
decimal = 1
for j in range(1, len(s)+1):
  m += int(s[-j]) * decimal
  m %= 2019
  dic[m] += 1
  decimal *= 10
  decimal %= 2019

ans = 0
for v in dic.values():
  ans += v*(v-1) // 2
print(ans)
s=input()
tmpsum=0
ruiseki=[0]
dic={}
so=2019

for i in range(1,len(s)+1):
    tmpsum+=(int(s[-i])*pow(10,i-1,so)) % so
    tmpsum%=so
    ruiseki.append(tmpsum)

for rui in ruiseki:
    if rui in dic:
        dic[rui]=dic[rui]+1
    else:
        dic[rui]=1


output=0
for val in dic.values():
    output+=val*(val-1)/2

print(int(output))
s=input()[::-1]
p=2019
ans=[0]*p

x10, S=1, 0
for i in s:
  S+=x10*int(i)
  S%=p
  x10*=10
  x10%=p
  ans[S]+=1

cnt=ans[0]
for a in ans:
  cnt+=(a*(a-1))//2
  
print(cnt)
R = [0]*2019
s = input()

res = 0
for d in map(int, s):
    new = [0]*2019
    for i in range(2019):
        new[(i*10 + d)%2019] += R[i]
    new[d] += 1
    res += new[0]
    R = new
print(res)
s=input()
a=0
now=1
l=[0]*2019
for i in list(s)[::-1]:
    a=(a+now*int(i))%2019
    l[a]+=1

    now*=10
    now%=2019
ans=0
for i in l:
    ans+=(i-1)*i//2
print(ans+l[0])
s = input()
s = list(reversed(s))
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
counting[0] += 1
dp1[0] = 1
dp2[0] = int(s[0])
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
sm = 0
for j in range(2019):
    sm += int(counting[j]*(counting[j]-1)/2)
print(sm)
N = str(input())
n,mods = 0,[1]+[0]*2018
d = 1
for i in reversed(N):
  n = (n+int(i)*d)%2019
  mods[n] += 1
  d = (d*10)%2019

print(sum([i*(i-1)//2 for i in mods]))
#!/usr/bin/env python3


def main():
    S = input()
    N = len(S)

    mod_count = [0] * 2019
    mod_count[0] = 1
    ssum = 0
    for i, c in enumerate(S[::-1]):
        ssum = (ssum + int(c) * pow(10, i, 2019)) % 2019
        mod_count[ssum] += 1

    print(sum([m * (m - 1) for m in mod_count]) // 2)


if __name__ == "__main__":
    main()
s = input()
p = 2019
n = 0
ans = 0
mods = [0]*p
mods[0] = 1
for i, j in enumerate(reversed(s)):
  n += int(j)*pow(10, i, p)
  n %= p
  mods[n] += 1
for i in mods:
  ans += i*(i-1)//2
print(ans)
# coding: utf-8
S = input()
ans = 0
P = 2019
N = len(S)
S = S[::-1]
cnt = [0 for _ in range(P)]
cnt[0] = 1
v = 0
bai = 1
for i in range(N):
    v = (v + int(S[i]) * bai) % P
    bai *= 10
    bai %= P
    cnt[v] += 1
for i in range(P):
    ans += ((cnt[i] - 1) * cnt[i]) // 2
print(ans)
#!/usr/bin/env python3
S = input()[::-1]

mod = [0]*2019
mod[0] = 1
ten = 1
index = 0
for s in S:
    index += ten*int(s)
    index %= 2019
    mod[index] += 1
    ten *= 10
    ten %= 2019

ans = 0
for m in mod:
    ans += m * (m-1) // 2

print(ans)
S = list(input())
a=[int(x) for x in S] #int型のリストに変換
a.reverse()
#print(a)
l=[0]*2019
l[0]=1
T=0
d=1

for i in a:
    T+=(int(i)*d)
    T%=2019
    l[T]+=1
    d*=10
    d%=2019
result=0
for n in l:
    result+=n*(n-1)/2
print(int(result))
import sys, copy, math, heapq, bisect
from itertools import accumulate
from collections import deque, defaultdict, Counter
sys.setrecursionlimit(500000)

S = list(input())[::-1]
N = len(S)
D = [1]
for i in range(N):
    D.append(D[-1]*10%2019)
M = [(int(S[i])*D[i])%2019 for i in range(N)]
SS = [M[0]]
for i in range(1,N):
    SS.append((SS[-1]+M[i])%2019)
count = [0]*2019
for i in range(N):
    count[SS[i]] += 1

ans = 0
for c in range(len(count)):
    if c==0:
        ans += count[c]
    ans += (count[c] * (count[c] - 1)) // 2

print(ans)
S = input()
leng = len(S)
S = S[::-1]

count = [0] * 2019
count[0] = 1

num = 0
d = 1

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


res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2

print(res)
s = input()
n = len(s)
m = 2019

a = 0
r = [0 for _ in range(m+1)]
r[0] = 1
z = 0
j = 1
for i in range(0,n):
    j = j * 10 % m
    ss = int(s[n-i-1])*j + z
    z = ss%m



    a += r[z]
    r[z] += 1

print(a)
def main():
  n, d, mods = 0, 1, [1]+[0]*2019
  for i in reversed(input()):
    n = (n+int(i)*d)%2019
    d = d*10%2019
    mods[n] += 1
  print(sum([int(i*(i-1)/2) for i in mods]))
main()
import sys
from collections import defaultdict


s = str(input())
n = len(s)
p = 2019

a = []
t = 1
for i in range(n-1, -1, -1):
    a.append((ord(s[i])-ord("0")) * t % p)
    t = t * 10 % p
cum = [0]
for v in a:
    cum.append((cum[-1] + v) % p)

dic = defaultdict(int)
ans = 0
for v in cum:
    ans += dic[v]
    dic[v] += 1
print(ans)
s = input()
n = len(s)

mod = 2019
cnt = [0] * mod
cnt[0] = 1
digit = 1
now = 0

for i in range(1, n + 1):
    now += int(s[-i]) * digit
    digit *= 10
    digit %= mod
    now %= mod
    cnt[now] += 1

ans = 0
for i in cnt:
    ans += i * (i - 1) // 2

print(ans)
a = input()[::-1]
add = 0
ans = [1] + [0] * 2018
ans_int = 0
d = 1

for i in range(len(a)):
    add = (add + int(a[i]) * d) % 2019
    d = (10 * d) %2019
    ans[add] += 1

for i in range(len(ans)):
    a =((ans[i] - 1) * ans[i]) /2
    ans_int += a

print(int(ans_int))
s=input()
s=s[::-1]
md=[0]
ex10=1
tmp=0
mod=2019
for i in range(len(s)):
    tmp+=ex10*int(s[i])
    tmp%=mod
    md.append(tmp)
    ex10*=10
    ex10%=mod
from collections import Counter

sc= Counter(md)
ans=0
for k in sc:
    sck=sc[k]
    ans+= sck*(sck-1)//2
print(ans)
s = input()
MOD = 2019
cnt = [0]*MOD
cnt[0] = 1
cum = 0
for n, x in enumerate(reversed(s)):
    cum = (cum + int(x)*pow(10, n, MOD)) % MOD
    cnt[cum] += 1
print(sum(v*(v-1)//2 for v in cnt))
S = input()
N = len(S)
rS = S[::-1]

cum = [0] * (N+1)
for i in range(N):
    cum[i+1] = (cum[i] + (int(rS[i]) * pow(10,i,2019)) % 2019) % 2019

ans = 0
from collections import Counter
from math import factorial
c = Counter(cum)
for v in c.values():
    if v >= 2:
        ans += factorial(v) // (factorial(v-2)*2)

print(ans)
from collections import Counter, defaultdict
a = defaultdict(int)
a[0] += 1
s = input()[::-1]
cur = 0
for i, x in enumerate(s):
    cur += (int(x)*pow(10, i, 2019))%2019
    cur %= 2019
    a[cur] += 1

def comb(a):
    return a*(a-1)//2

ans = 0
for x in a.values():
    if x >= 2:
        ans += comb(x)
print(ans)
s, n, ans = input(), 0, 0
mods = [0]*2019
mods[0] = 1
for i, j in enumerate(reversed(s)):
  n = (n+int(j)*pow(10, i, 2019))%2019
  mods[n] += 1
for i in mods: ans += i*(i-1)//2
print(ans)
import collections
s = input()
u = collections.deque([0])
for i in range(len(s)):
    u.append((u[i]+int(s[-i-1])*10**(i%224))%2019)
u2 = collections.Counter(u)
sum = 0
for i in u2.values():
    sum += i*(i-1)/2
print(int(sum))
s = list(map(int, list(input())))

mod = 2019

mods = [0 for i in range(2019)]
mods[0] += 1

num = 0

pow10mod = 1

for i in range(len(s)):
    num = (num + s[-(i+1)] * pow10mod) % mod
    mods[num] += 1
    pow10mod = pow10mod * 10 % mod

ans = 0

for i in range(2019):
    m = mods[i]
    ans += (m * (m-1) // 2)


print(int(ans))
s=list(input())
s=s[::-1]
for i in range(len(s)):
    s[i]=int(s[i])
data=[0]
x=0
for i in range(len(s)):
    x=pow(10,i,2019)*s[i]+x
    x=x%2019
    data.append(x)
from collections import Counter
data=dict(Counter(data))
ans=0
for key in data.values():
    ans+=(key)*(key-1)//2
print(ans)
# %%time
s = input()
c = 0
mod = 2019
s_int = list(map(int, list(s)))

tens = [1]
for k in range(len(s)):
    tens.append((tens[-1] * 10)%mod )

ms = []
m = s_int[-1]%mod
ms.append(m)
for i in range(len(s) - 1)[::-1]:
    m = s_int[i] * tens[len(s) - i - 1] +  m
    m = m %mod
    ms.append(m)
    if m == 0:
        c += 1
        
from collections import Counter
co = Counter(ms)
for v in co.values():
    c += v * (v - 1) // 2

print(c)
S = list(reversed(input()))

length = len(S)

a = [0]*length
for i in range(length):
    pickup = int(S[i])
    a[i] = pickup*pow(10, i, 2019)

b = [0]*(length+1)
for i in range(1, length+1):
    b[i] = (b[i-1] + a[i-1]) % 2019
cnt, ans = [0] * 2019, 0
for x in b:
    ans += cnt[x]
    cnt[x] += 1

print(ans)
ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
  k+=(s*int(S[a-i-1]))
  k%=mod
  s*=10
  s%=mod
  if k in c:
    c[k]+=1
  else:
    c[k]=1
for i in c:
  ans+=c[i]*(c[i]-1)//2
print(ans)
import sys 
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 2019
S = readline().decode().rstrip()
N = len(S)
S = S[::-1]
mod_list = [0]*N
mod_list[0] = int(S[0])
power = 1
for i in range(1,N):
    power *=10
    power %= mod
    mod_list[i] = power * int(S[i]) + mod_list[i-1]
    mod_list[i] %= mod
    
mod_cnt = Counter(mod_list)
ans = sum(n*(n-1)//2 for n in mod_cnt.values()) +mod_cnt[0]
print(ans)
m=2019;l=[0]*m;a=b=0;k=1
for c in input():l[b%m]+=1;b-=int(c)*k;a+=l[b%m];k=k*202%m
print(a)
S = input()

n = len(S)
m = 2019

S_ = S[::-1]

x = 1
total = 0
modlis = [0 for i in range(m)]

ans = 0
for i in range(n):
    modlis[total] += 1
    #print("S_[i]:", S_[i])
    #print("int(S_[i])*x:", int(S_[i])*x)
    #print("total:", total)
    total += int(S_[i])*x
    #print("total:", total)
    total %= m
    #print("total:", total)
    ans += modlis[total]
    #print("x:", x)
    x = x * 10 % m
    #print("x:", x)

print(ans)
import collections
S=str(input())

T=[0 for i in range(len(S))]
T[0]=int(S[-1])

for i in range(1,len(S)):
    T[i]=(pow(10,i,2019)*int(S[len(S)-1-i])+T[i-1])%2019
    
cnt=0
T_di=collections.Counter(T)

for key in T_di.keys():
    x=T_di[key]
    cnt+=x*(x-1)/2
    if key==0:
        cnt+=x

print(int(cnt))
s = input()
mod = 2019
ls = [1]+[0]*2018
ans = 0
temp=0
m=1
for i in range(len(s)):
    temp= (temp + m*int(s[-i-1]))%mod
    m=(m*10)%mod

    ls[temp] += 1

for i in ls:
    ans += i*(i-1)//2
print(ans)
import math

def comb_count(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)

S = input()[::-1]
ans = 0

mods = [0] * 2019 #余りが0~2018
mods[0] = 1
current = 0
tmp = 1

for i in range(len(S)):
    current = int(S[i]) * tmp + current
    mod = current % 2019
    mods[mod] += 1
    tmp = tmp * 10 % 2019

for mod in mods:
    if mod > 1:
        ans += comb_count(mod, 2)

print(ans)
s = input()[::-1]
l = len(s)
c = [0] * 2019
c[0] = 1
ten = 1
mod = 0
ans = 0

for i in range(l):
    mod = (mod + int(s[i]) * ten) % 2019
    ten = ten * 10 % 2019
    c[mod] += 1

for i in c:
    ans += i * (i - 1) // 2

print(ans)
arr = [0 for i in range(2019)]
arr[0] = 1

s = input()
n = len(s)

num = 0
for i,ele in enumerate(s[::-1]):
    num += int(ele) * pow(10,i,2019)
    arr[num%2019] += 1


ans = 0
for m in arr:
    if m==0: continue
    ans += m*(m-1)//2

print(ans)
MOD=2019
S=input()
N=len(S)
nums=[0]*N
nums[-1]=int(S[-1])%MOD
for i in range(-2, -N-1, -1):
  nums[i]=(int(S[i])*pow(10, -(i+1), MOD)+nums[i+1])%MOD

a=[0]*2019
for i in range(N):
  a[nums[i]]+=1
  
print(a[0]+sum([(a[i]*(a[i]-1))//2 for i in range(2019)]))
from collections import Counter
S = list(reversed(input()))
l = len(S)
N = 0
counts = Counter([(N := N + (pow(10, i, 2019) * int(S[i])) % 2019) % 2019 for i in range(l)] + [0])
print(sum(n * (n - 1) // 2 for n in counts.values()))
from collections import Counter
S = input()
L = len(list(S))
dp = [0] * L
dp[0] = 1
T = [0] * L
T[0] = int(S[-1])
for i in range(1, L):
    dp[i] =  dp[i - 1] * 10
    dp[i] %= 2019
    T[i] = int(S[-(i+1)]) * dp[i] + T[i - 1]
    T[i] %= 2019
ans = 0
for k, v in Counter(T).items():
    if k == 0:
        ans += v
        ans += v * (v - 1) // 2
    else:
        ans += v * (v - 1) // 2
print(ans)
def solve(s):
    mod = 2019
    counts = [0]*mod
    counts[0] = 1
    result = 0
    suffix = 0
    power_of_ten = 1
    for char in s[::-1]:
        digit = int(char)
        suffix = (suffix + digit*power_of_ten) % mod
        result += counts[suffix]
        counts[suffix] += 1
        power_of_ten = 10 * power_of_ten % mod

    return result


if __name__ == "__main__":
    print(solve(input()))
s = str(input())
N = len(s)
array = [0]*2019
array[0] += 1
count = 0
d = 1
r = 0
for i in reversed(range(0, N)):
    r = ( r + int( s[i] ) * d ) % 2019
    d = d * 10 % 2019
    array[r] += 1
for i in array:
    count += i*(i-1)/2
print(int(count))
from collections import defaultdict
s = list(input())[::-1]
n = len(s)
dic = defaultdict(int)
dic[0] = 1
t = 0
for i in range(n):
    t += int(s[i])*pow(10,i,2019) % 2019
    t %= 2019
    dic[t] += 1
ans = 0
for i in dic.keys():
    m = dic[i]
    ans += m*(m-1)//2
print(ans)