peterverebics/CodeNet_Python_118 huggingface dataset:
import sys
input = sys.stdin.readline
from collections import *

S = input()[:-1]
cnt = defaultdict(int)
cnt[0] = 1
now = 0
ans = 0

for i in range(len(S)-1, -1, -1):
    now = (int(S[i])*pow(10, len(S)-1-i, 2019)+now)%2019
    ans += cnt[now]
    cnt[now] += 1

print(ans)
ss=input().rstrip()

x=1
y=0
mod=[0]*3000
ans=0
mod[0]=1
for i in range(len(ss)):
  s=ss[i*(-1)-1]
  n=int(s)
  y=(y+x*n)%2019
  ans+=mod[y]
  mod[y]+=1
  x=(x*10)%2019
print(ans)
S = input()
mod = [0] * 2019
mod[0] = 1 
d = 1
n = 0
for i in reversed(S):
  n += int(i) * d
  n %= 2019
  d *= 10
  d %= 2019
  mod[n % 2019] += 1
ans = 0
for j in range(2019):
  ans += mod[j] * (mod[j] - 1) // 2
print(ans)
S = input()[::-1]
dp = [0]*2019
dp[0] = 1

tmp = 0
for i in range(len(S)):
    tmp += int(S[i])*pow(10, i, 2019)
    tmp %= 2019
    dp[tmp] += 1
ans = 0
for i in dp:
    if i >= 2:
        ans += i*(i-1)//2
print(ans)
s = input()[::-1]
 
sum_of_digits = 0
 
cnts = [0] * 2019
 
cnts[0] = 1
 
d = 1
 
for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1
 
ans = 0

for cnt in cnts:
    ans += cnt * (cnt - 1) // 2
 
print(ans)
a = list(map(int,list(input())))
ans = 0
b = 0
c = [0 for i in range(2019)]
c[0] = 1
for i in range(len(a)):
  b = (b+pow(10,len(a)-i,2019)*a[i])%2019
  c[b] += 1
c = list(map(lambda x:x*(x-1)//2,c))
ans = sum(c)
print(ans)
s = list(map(int, input()))
n = len(s)
p = 2019
ans = 0

s.reverse()
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = (cum[i] + s[i] * pow(10, i, p)) % p
t = [0] * p
for x in cum: t[x] += 1

for x in t:
    ans += x * (x-1) // 2
print(ans)
import numpy as np
s = list(map(int,input()))
n = len(s)
ans = 0
mod = 2019
past = s[n-1]
ima = 0
d = dict()
d[s[n-1]] = 1
now = 10
for i in range(1,n):
    ima = (past+s[n-i-1]*now)%mod
    if ima == 0:
        ans += 1
    if ima in d:
        d[ima] += 1
    else:
        d[ima] = 1
    past = ima
    now = (now*10)%mod

for i in d.values():
    ans += i*(i-1)//2

print(ans)
import sys

input = sys.stdin.readline

S = input().rstrip()
n = len(S)
l = [0]*2019
d = 10

t = int(S[n-1])
l[t%2019] += 1

l[0] += 1

for i in range(n-2, -1, -1):
    t += int(S[i])*d%2019
    l[t%2019] += 1 
    d *= 10
    d %= 2019

ans = 0

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

print(ans)
s=input()
t=len(s)
ans=0
ruiseki=[int(s[-1]) for i in range(t)]
for i in range(1,t):
    ruiseki[i]=(ruiseki[i-1]+int(s[-1-i])*pow(10,i,2019))%2019
from collections import Counter
ans+=ruiseki.count(0)
C=Counter(ruiseki)
for x in C.values():
    ans+=x*(x-1)//2
print(ans)
P=2019
S = input()
N=len(S)
count=[0]*P
ans = 0
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
  u = (int(s) * pow(10, i, P) + u) % P
  ans += count[u]
  count[u] += 1
 
print(ans)
a=input()
num=len(a)
mod_map={0:1}
moji_int=0
Sn=[0]*(num+1)
tens=[1]*(num+1)
for i in range(-1,-num-1,-1):
    tens[-i]=tens[-i-1]*10%2019
    tmp=int(a[i])*(tens[-i-1])
    Sn[-i]=(Sn[-i-1]+tmp%2019)%2019
    mod=Sn[-i]
    if mod not in mod_map:
        mod_map[mod]=1
    else:
        mod_map[mod]+=1

res=0
for i in mod_map.values():
    res+=int(i*(i-1)/2)
print(res)
import collections
s = input()

l = [int(s[-1])]
d = 10
for i in range(len(s)-2, -1, -1):
  l.append((l[-1] + int(s[i])*d) % 2019)
  d *= 10
  d %= 2019
c = collections.Counter(l)
ans = 0  
for i in c.values():
  ans += i*(i-1)//2

ans += c[0]

print(ans)
s = input()[::-1]

sum_of_digits = 0

cnts = [0] * 2019

cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

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

print(ans)
S=input()
ans,n=0,len(S)
dp=[0]*(2019)
s,dp[0],k=0,1,1
for i in S[::-1]:
  s=(s+int(i)*k)%2019
  k=(k*10)%2019
  ans+=dp[s]
  dp[s]+=1
print(ans)
from collections import defaultdict
S = input()
l = len(S)
d = {0:0}
mod10n = 1
for i in range(1, len(S)+1):
    s = int(S[l-i])
    d[i] = (d[i-1] + s * mod10n) %2019
    mod10n = (mod10n * 10) % 2019
count_d = defaultdict(int)
for key in d.keys():
    count_d[d[key]] += 1
counter = 0
for key in count_d.keys():
    counter += (count_d[key] * (count_d[key]-1)) //2

print(counter)
import sys
input = sys.stdin.readline
mod = 2019
s = input().rstrip()
n = len(s)
mod_list = [0]
for i in range(n - 1, -1, -1):
    mod_list.append((mod_list[-1] + int(s[i]) * pow(10, n - 1 - i, mod)) % mod)
from collections import Counter
c = Counter(mod_list)
ans = 0
for i in c.keys():
    ans += c[i] * (c[i] - 1) // 2
print(ans)
import sys
readline = sys.stdin.readline

S = readline().strip()
S = list(map(int, S))
N = len(S)
P = 2019

rems = [0] * N
a = 1
b = 0
for i in range(N):
    b = (b + (a * S[N - i - 1]) % P) % P
    rems[N - i - 1] = b
    a = a * 10 % P

rems = rems + [0]

counts = [0] * P


for i in range(len(rems)):
    counts[rems[i]] += 1

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

print(ans)
from collections import Counter
S = input()[::-1]
cur = 0
mods = Counter()
mods[0] += 1
MOD = 2019
for i,d in enumerate(S):
  cur += int(d) * pow(10, i, MOD)
  mods[cur%MOD] += 1

res = 0
for k,v in mods.items():
  res += (v * (v-1) // 2)

print(res)
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)
s = input()[::-1] # 入力文字列を逆順でsに格納

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)
import collections
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * pow(10,i,2019)
  mod.append((now + mod[i]) % 2019)


c = collections.Counter(mod)
hindo = sorted(c.values(),reverse=True)
for i in hindo:
  if i != 1:
    cnt += i*(i-1)//2


print(cnt)
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)
n = input()
l = len(n)
a = [0 for _ in range(2019)]
a[0] = 1
now = 0
ten = [1]
for i in range(l-1):
  ten.append(ten[-1]*10%2019)
ten.reverse()
for i in range(l)[::-1]:
  now += ten[i]*int(n[i])
  now %= 2019
  a[now] += 1
  #print(now)
ans = 0
for d in range(2019):
  ans += a[d] * (a[d]-1) // 2
print(ans)
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()
def main():
    S=input()
    P=2019
    ans=0
    
    count=[0]*P
    count[0]=1
    u=0
    
    for i,s in enumerate(reversed(S)):
        u=(int(s)*pow(10,i,P)+u)%P
        ans+=count[u]
        count[u]+=1
    print(ans)
    

if __name__=="__main__":
    main()
from collections import Counter
S = list(map(int, list(input())))
MOD = 2019

acc_mod = [0]
for i, s in enumerate(S[::-1]):
    acc_mod.append((acc_mod[-1] + s * pow(10, i, MOD)) % MOD)

ans = 0
for v in Counter(acc_mod).values():
    ans += v * (v - 1) // 2
print(ans)
from collections import defaultdict
s = input()
mod = 2019
dct = defaultdict(int)
dct[0] = 1
x = 0
d = 1
for c in s[::-1]:
    x = (x+int(c)*d)%mod
    d = d*10%mod
    dct[x] += 1
ans = 0
for v in dct.values():ans += v*(v-1)//2
print(ans)
S = input()

S = S[::-1]
N = len(S)
cnt = [0] * 2019
mod = 2019
m = 0
cnt[0] += 1
for i in range(N):
    s = int(S[i]) * (pow(10, i, mod))
    s %= mod
    m += s
    m %= mod
    cnt[m] += 1


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

print(ans)
s=input()
s_rev=s[::-1]

mod_count=[0]*2019
mod_count[0]=1
d=1
num=0

for char in s_rev:
  num=num+int(char)*d
  num=num%2019
  d=d*10
  d=d%2019
  #print(type(num),type(mod_count))
  mod_count[num]=mod_count[num]+1

ans=0
for cnt in mod_count:
  ans=ans+cnt*(cnt-1)/2
  
print(int(ans))
import collections

s = input()

mod = 2019
n = len(s)
t = [0]*(n+1)
for i in range(1,n+1):
    t[i] = (t[i-1] + int(s[n-i]) * pow(10, i-1, mod)) % mod
c = collections.Counter(t)
num = c.values()
ans = 0
for i in num:
    ans += i*(i-1) // 2

print(ans)
from collections import defaultdict

S = tuple(map(int, list(input())))
MOD = 2019

d = defaultdict(int)
d[0] = 1

tmp = 0
for i, s in enumerate(reversed(S)):
    tmp = (tmp + s * pow(10, i, MOD)) % MOD
    d[tmp] += 1
print(sum(v * (v - 1) // 2 for v in d.values()))
S = input()[::-1]
remain_table = [0] * 2019
remain_table[0] = 1
d = 1
chk = 0
for s in S:
    chk += int(s) * d
    chk = chk % 2019
    remain_table[chk] += 1
    d *= 10
    d %= 2019

ans = 0
for r in remain_table:
    ans += r * (r - 1) // 2
print(ans)
from collections import defaultdict
S = input()[::-1]
mod = 2019
d = defaultdict(int)
ruijo = 1
tmp = 0
for i in range(len(S)):
    tmp += int(S[i]) * ruijo % mod
    d[tmp % mod] += 1
    ruijo *= 10
    ruijo %= mod
ans = 0
for k, v in d.items():
    ans += v * (v - 1) // 2
    if k == 0:
        ans += v
print(ans)
import sys
from collections import Counter
readline = sys.stdin.readline

S = list(map(int, readline().strip()))
N = len(S)
C = Counter()
C[0] = 1
ans = 0
MOD = 2019
res = 0
for i in range(N):
    s = S[N-1-i]
    res = (res+s*pow(10, i, MOD))%MOD
    ans += C[res]
    C[res] += 1
print(ans)
# 解説AC
S = input()
N = len(S)

cnt = [0] * 2019

cnt[0] = 1

ans = 0
e = 1; cur = 0
for s in reversed(S):
    cur = (cur + int(s) * e) % 2019

    ans += cnt[cur]

    e = (e * 10) % 2019
    cnt[cur] += 1

print(ans)
s = input()
n = 0
ans = 0
m = [0]*2019
m[0] = 1
for i, j in enumerate(reversed(s)):
  n = (n+int(j)*pow(10, i, 2019))%2019
  m[n] += 1
for i in m: ans += i*(i-1)//2
print(ans)
def resolve():
    S = input()
    table=[0]*2019
    table[0]=1
    x = 0
    x_10 =1
    for i in S[::-1]:
 
        x = (x+ int(i)*x_10)%2019
 
        table[x]+=1
 
        x_10*=10
        x_10 %= 2019
 
    ans =0
    for i in table:
        ans += i*(i-1)//2
    
    print(ans)
 
 
 
if __name__ == "__main__":
    resolve()
import collections
S = list(map(int, list(input())))
N = len(S)

dp = [0]*N
if N < 4:
    print(0)
    exit(0)

ans = 0

D = [0]*N
D[0] = 1
for i in range(1, N):
    D[i] = D[i-1]*10 % 2019
t = collections.defaultdict(int)
tmp = 0

t[0] += 1
for i in range(N):
    tmp += S[N-1-i]*D[i]
    tmp %= 2019
    t[tmp] += 1

for x in t:
    ans += t[x]*(t[x]-1) // 2

# print(N)
# print(*dp, sep='\n')

print(ans)
S = input()
S_rev = S[::-1]
# amari = [0]
a = 0
from collections import defaultdict
d = defaultdict(int)
d[0]+=1
for i,s_r in enumerate(S_rev):
    x = pow(10,i,2019)
    # print(x)
    a = (a+int(s_r)*x)%2019
    # amari.append(a)
    d[a] += 1


ans = 0
for k in d.keys():
    n = d[k]
    ans += n*(n-1)//2
print(ans)
S = list(map(int, list(input())))
N = len(S)
P = 673

cnt = [[0,0,0]  for i in range(P)]
cnt[0][0] = 1
rem1 = 0
rem2 = 0
ans = 0


for i in range(N):
    rem1 = (int(S[-i - 1]) * pow(10, i, P) + rem1) % P
    rem2 = (int(S[-i - 1]) * pow(10, i, 3) + rem2) % 3
    ans += cnt[rem1][rem2]
    cnt[rem1][rem2] += 1

print(ans)
s = str(input())

num = [int(s[-1])]
for i in range(1, len(s)):
    tmp = num[-1] + pow(10, i, 2019) * int(s[-i - 1])
    num.append(tmp % 2019)

mod = [1] + [0] * 2018
ans = 0
for i in num:
    m = i % 2019
    ans += mod[m]
    mod[m] += 1
print(ans)
from itertools import permutations, accumulate
mod = 2019

a = list(map(int,input()))
n = len(a) #入力の桁数

for i in range(n):
    a[i] *= pow(10,n-i-1,mod) #pow(a,b)==a^b べき乗
    
s = [0]+list(accumulate(a)) #accumulate([1,2,3,4,5]) --> 1 3 6 10 15
d = [0]*mod
ans = 0
for i in s:
    j = i%mod
    ans += d[j]
    d[j] += 1
print(ans)
from collections import Counter
S = list(map(int, list(input())))
A = [0]
for i, s in enumerate(S[::-1]):
    A.append((A[-1] + s * pow(10, i, 2019)) % 2019)
print(sum([v * (v - 1) // 2 for v in Counter(A).values()]))
s=list(input())
s=s[::-1]
l=len(s)
mod=2019
count=[0]*2019
count[0]=1
num=0
seki=1
for i in range(l):
    num+=int(s[i])*seki
    num=num%mod
    count[num]+=1
    seki=(seki*10)%mod
ans=0
for i in range(2019):
    N=count[i]
    ans+=N*(N-1)//2
print(ans)
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  d *= 10
  d %= 2019

print(sum([i*(i-1)//2 for i in counter]))
s = input()
l = len(s)
c = 2019
tm = 1
ti = int(s[-1])
co = [0]*2019
co[ti] += 1
for i in range(1, l):
    tm = tm*10 % c
    ti += int(s[l-i-1]) * tm
    ti = ti % c
    co[ti] += 1
if co[0] != 0:
    co[0] += 1
print(sum([i*(i-1)//2 for i in co]))
s = input()
s = s[::-1]
n = len(s)

num = [0]*2019
num[0] = 1
number = 0
d = 1

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

ans = 0

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

print(ans)
S = input()[::-1]
N = len(S)
amari = [0 for i in range(2019)]
before = int(S[0])
amari[before] += 1
S = S[1::]
keta = 1
for i in S:
    i = int(i)
    keta = (keta * 10) % 2019
    x = (keta * i + before) % 2019
    amari[x] += 1
    before = x
ans = amari[0]
for i in amari:
    ans += i * (i - 1) // 2
print(ans)
s = str(input())
n = len(s)
x = [0]*2019
x[0] = 1
m = 0
j = 1
for i in range(n):
  m = (m + int(s[-i-1])*j)%2019
  x[m] += 1
  j = (j*10)%2019
ans = 0
for i in range(2019):
  ans += (x[i]*(x[i]-1))//2
print(ans)
M=2019;t=1;p=0;c=[0]*M;r=0
for x in(input()+'0')[::-1]:p=(int(x)*t%M+p)%M;r+=c[p];c[p]+=1;t=t*10%M
print(r)
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 *= 10
        digit %= 2019

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


if __name__ == '__main__':
    print(main())
s = input()
l = len(s)
t = [0] * l
t[l - 1] = int(s[l - 1])
m = [0] * 2019
m[0] = 1
m[int(s[l - 1])] = 1
ten = 10
ans = 0

for i in range(l - 1, 0, -1):
    t[i - 1] = (t[i] + int(s[i - 1]) * ten) % 2019
    ten = ten * 10 % 2019
    m[t[i - 1]] += 1

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

print(ans)
S=input()[::-1]
l=len(S)
t=0
p=0
 
ss=[0]*2019
ss[0]=1
d=1
for i in S:
    p=(p+int(i)*d)%2019
    d*=10
    d%=2019
    ss[p]+=1
 
for c in ss:
    t+=c*(c-1)//2
print(t)
s=list(input())
mod=2019
A=[0]*2019
a=0
b=1
for i in range(len(s)):
  a=(a+int(s[-1-i])*b)%mod
  A[a]+=1
  b=b*10%mod
ans=A[0]*(A[0]+1)//2
for i in range(1,2019):
  if A[i]!=0:
    ans=ans+(A[i]-1)*A[i]//2
print(ans)
def d_multiple_of_2019():
    from collections import Counter
    S = [int(ch) for ch in input()]

    p = 2019  # ABC158-E のソースコードを流用するため
    s = S[::-1]
    u = [0] * len(S)
    u[0] = s[0] % p

    power = 1
    for i in range(1, len(S)):
        power *= 10
        power %= p
        u[i] = u[i - 1] + power * s[i]
        u[i] %= p
    count = Counter(u)
    return sum(v * (v - 1) // 2 for v in count.values()) + count[0]

print(d_multiple_of_2019())
def solve(s, p=2019):
    s = s[::-1]
    memo = [0] * p
    memo[0] = 1
    ans = 0
    q = 0
    r = 1
    for c in s:
        q = (q + int(c)*r) % p
        ans += memo[q]
        r = 10*r % p
        memo[q] += 1
    return ans

s = input()
print(solve(s))
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()[::-1]
n=len(s)
a=[0]*2019
a[0]=1
c,d=0,1
for i in s:
    c+=int(i)*d
    c%=2019
    d*=10
    d%=2019
    a[c]+=1
ans=0
for i in a:
    ans+=i*(i-1)//2
print(ans)
s = input()
len_s = len(s)
pre = 0
mod = [0]*2019
mod[0]=1
x = 1
for i in range(len_s):
    pre = (x*int(s[len_s-i-1])+pre)%2019
    mod[pre] += 1
    x *= 10
    x %= 2019
print(sum([m*(m-1)//2 for m in mod]))
S = input()
N = len(S)
mod = 2019
num = [0 for i in range(2019)]
num[0] = 1
t = 1
rem = 0

for i in reversed(S):
    rem += int(i) * t
    rem %= mod
    t *= 10
    t %= mod
    num[rem] += 1

print(int(sum([i * (i-1) / 2 for i in num])))
def main():
  n ,mods = 0, [1]+[0]*2019
  for i, j in enumerate(reversed(input())):
    n = (n+int(j)*pow(10, i, 2019))%2019
    mods[n] += 1
  print(sum([i*(i-1)//2 for i in mods]))
main()
s = input()
l = len(s)
dp = [0]*2019
dp[0] = 1
r = 0
for i in range(1, l + 1):
    r += int(s[-i]) * pow(10, i - 1, 2019)
    r %= 2019
    dp[r] += 1
    
print(sum([(i * (i - 1)) // 2 for i in dp]))
S = input()

mod = [0] * 2019
mod[0] = 1
digit = 1
temp = 0
 
for i in S[::-1]:
    temp = (temp + digit * int(i)) % 2019
    mod[temp] += 1
    digit = (digit * 10) % 2019

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

print(ans)
s = input()
from collections import Counter
x = 1
mod = 2019
total = 0
ans = 0
cnt = Counter()
for i in range(len(s)-1,-1,-1):
    cnt[total] += 1
    total = total + int(s[i])*x
    total %= mod
    ans += cnt[total]
    x = x*10%2019
print(ans)
from collections import Counter

S = input()
N = len(S)
mod = [0] * (N+1)
now = 0
for i in range(N):
    now += int(S[N-1-i]) * pow(10,i,2019) % 2019
    now %= 2019
    mod[N-i-1] = now

ans = 0
for l in Counter(mod).values():
    ans += l * (l-1) // 2
print(ans)
s = input()[::-1]

dataset = [0]*2019
dataset[0] = 1

n = 0
d = 1

for i in s:
    n += int(i) * d
    a = n % 2019
    dataset[a] += 1
    d *= 10
    d %= 2019

count = 0
for i in dataset:
    count += i * (i-1) // 2

print(count)
S = list(input())
L = [0]*2019
L[0]=1
digit = 1
x = 0

for i in S[::-1]:
    x += digit*int(i)
    digit *= 10
    x %= 2019
    digit %= 2019 
    L[x] += 1

ans = 0

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

print(ans)
def main():
    s = map(int, input()[::-1])
    mod = 2019
    counts = [0] * mod
    counts[0] = 1
    t = 0
    x = 1
    for num in s:
        t = (t + num * x) % mod
        counts[t] += 1
        x = (x * 10) % mod
    ans = 0
    for count in counts:
        if count > 1:
            ans += count * (count - 1) // 2
    print(ans)


main()
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
A = A[::-1]

MOD = 2019

p10 = [1] * N
for i in range(1, N):
	p10[i] = (p10[i - 1] * 10) % MOD

for i in range(N):
	A[i] = (A[i] * p10[i]) % MOD

cumsum = [A[0]] * N
for i in range(1, N):
	cumsum[i] = (cumsum[i - 1] + A[i]) % MOD

cnt = [0] * MOD
cnt[0] = 1
for i in range(N):
	cnt[cumsum[i]] += 1

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

print(ans)
import time

p0 = time.time()
S = input()
n = len(S)
Y = {0:1}
# print(Y)
Y[0] = 1
A = [0]
pk = 0
for i in range(1,n+1):
    # print(S[-i])
    k = (int(S[-i])*pow(10,i-1,2019)+pk)%2019
    A.append(k)
    if k not in Y:
        Y[k] = 1
    else:
        Y[k] += 1
    pk = k

# print(A)
# print(Y)
# print(time.time()-p0)
c = 0
for y in Y:
    d = Y[y]
    c += d*(d-1)//2
print(c)
from collections import Counter
s=input()
n=len(s)
ans=0
arr=[0]*(n+1)
if s=='0':
    print(1)
    exit()
elif n==1:
    print(0)
    exit()
for i in reversed(range(n)):
    arr[i]=(arr[i+1]+int(s[i])*pow(10,n-i-1,2019))%2019
m=Counter(arr)
for j in m.keys():
    ans+=m[j]*(m[j]-1)//2
print(ans)
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] += 1

_S = S[::-1]
mod = 0
p = 1
for i in range(len(S)):
    mod = (p * int(_S[i]) + mod) % 2019
    mod_bucket[mod] += 1
    p *= 10
    p %= 2019

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))
s = input()[::-1]
l = len(s)
x = [0 for _ in range(2019)]
x[0] += 1
k = 0
p = 1
for si in s:
    k += int(si) * p % 2019
    k %= 2019
    x[k] += 1
    p *= 10
    p %= 2019
 
ans = 0
for xi in x:
    ans += max(0, xi * (xi - 1) // 2)
print(ans)
S = input()
S_reverse = S[::-1]

dp = [0] * 2019
now_mod = 0
digit = 1

for i_s in S_reverse:
    now_mod = (now_mod + int(i_s)*digit) % 2019
    digit = (digit*10) % 2019
    dp[now_mod] += 1

ans = sum(x*(x-1)//2 for x in dp)
ans += dp[0]

print(ans)
s = input()
x = list(map(int, list(s)))
x = x[::-1]
dic = [0 for _ in range(2020)]
ten = 1
y = 0
for i in range(len(s)):
    y = (y+ten*x[i])%2019
    dic[y] += 1
    ten = (ten*10)%2019
result = 0
for i in range(2019):
    result += max([dic[i]*(dic[i]-1)//2, 0])
result += dic[0]
print(result)
n = input()
countArray = [0] * 2019
count = 0
countArray[0] += 1
nums=0
for i in range(len(n))[::-1]:
    nums = nums + int(n[len(n)-1-i])*pow(10,i,2019)
    countArray[nums%2019]+=1

for i in countArray:
    count += (i * (i - 1)) // 2
print(count)
def main():
    S = list(input())
    N = len(S)
    t = 0
    A = [0] * 2019
    A[0] += 1
    d = 1
    for s in reversed(S):
        d *= 10
        d %= 2019
        t += (int(s) * d)
        t %= 2019
        A[t] += 1
    result = sum([a*(a-1)//2 for a in A])
    print(result)


if __name__ == '__main__':
    main()
import sys
input = sys.stdin.readline
from collections import *

S = input()[:-1]
cnt = defaultdict(int)
cnt[0] = 1
ans = 0
now = 0

for i in range(len(S)-1, -1, -1):
    now = (int(S[i])*pow(10, len(S)-1-i, 2019)+now)%2019
    ans += cnt[now]
    cnt[now] += 1

print(ans)
n = input()
mod = [0]*2019
mod[0] += 1
T = 0
d = 1 # 桁数
for i, s in enumerate(n[::-1]):
  T += int(s) * d
  T %= 2019
  d = (d * 10) % 2019
  mod[T] += 1
  
res = 0  
for m in mod:
  res += m*(m-1)/2
print(int(res))
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()
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([i*(i-1)//2 for i in mods]))
main()
m = 2019
C = [0]*m
C[0] = 1
s = list(input())
now = 0
cnt = 0
while s:
  now += pow(10, cnt, m) * int(s.pop())
  now %= m
  C[now] += 1
  cnt += 1
ans = 0
for c in C:
  ans += c*(c-1)//2
print(ans)
from collections import defaultdict

S = input()
n = len(S)

mod = 2019
d = defaultdict(int)
d[0] = 1
num = 0
for i in reversed(range(n)):
    num += int(S[i]) * pow(10, n - i - 1, mod)
    num %= mod
    d[num] += 1

ans = 0
for v in d.values():
    ans += v * (v - 1) // 2
print(ans)
from collections import defaultdict
s=input()
n=len(s)
N=defaultdict(int)
x=0
for i in reversed(range(n)):
    x+=int(s[i])*pow(10,(n-i-1),2019)
    x%=2019
    N[x]+=1
ans=N[0]
for j in N.values():
    ans+=j*(j-1)//2
print(ans)
s=input()
l=len(s)
se=dict()
k=0
for i in range(l-1,-1,-1):
    k+=(pow(10,l-1-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)
import numpy as np

s = input().strip()
t = 0
counts = np.array([0] * 2019)
counts[0] += 1
m = 1

for a  in reversed(s):
    t = (t + m * int(a)) % 2019
    counts[t] += 1
    m = m * 10 % 2019
    
print(int(np.sum(counts * (counts - 1) /2)))
S = input()
MOD =2019
count = [0]*MOD
r = 0
t = 1
for i in reversed(S):
    r += int(i) * t
    r %= MOD
    t *= 10
    t %= MOD
    count[r] += 1

count[0] += 1
print(int(sum(i*(i-1)/2 for i in count)))
import collections
s = map(int,raw_input())

dp = [0] * 2019
count = 0
for j in range(len(s)):
    ndp = [0] * 2019
    ndp[s[j]] += 1
    for k in range(len(dp)):
        ndp[(10*k + s[j]) % 2019] += dp[k]
    count += ndp[0]
    dp = ndp[::]

print count
S=input()
DP=[0]*len(S)

now=0
for i in range(len(S)-1,-1,-1):
    now=(now+pow(10,len(S)-1-i,2019)*int(S[i]))%2019
    DP[i]=now
    
DP.append(0)

from collections import Counter
C=Counter(DP)

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

print(ANS)