peterverebics/CodeNet_Python_118 huggingface dataset:
s = input()
#s = '9' * 200000

mod = [1] + [0]*2018
t = 0
a = 1
n = len(s)
s = s[::-1]
for i in range(n):
    t = (t + int(s[i])*a) % 2019
    a = a * 10 % 2019
    mod[t] += 1
ans = 0
for i in range(2019):
    ans += mod[i]*(mod[i]-1)//2
print(ans)
S = input()
m = 2019
dp = [0]*m
dp[0] = 1

acc, d = 0,1

for s in S[::-1]:
    acc = (acc + d*int(s)) % m
    dp[acc] += 1
    d = (d*10) % m

print(str(sum([n*(n-1)//2 for n in dp])))
from collections import Counter

MOD = 2019
S = input()
S = tuple(map(int, reversed(S)))
counter = Counter()
digit = 1
cumsum = 0
ans = 0

for i in range(len(S)):
    counter[cumsum] += 1
    cumsum += (S[i] * digit) % MOD
    cumsum %= MOD
    ans += counter[cumsum]
    digit *= 10
    digit %= MOD

print(ans)
S = input()

num = 0

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

    r_lst[num] += 1


print(cnt)
s = input()
ans = 0
a = [0] * 2019
a[0] = 1
k = 0
mod = 1
for i in range(len(s) - 1, -1, -1):
    k = (k + int(s[i]) * mod) % 2019
    mod = (mod * 10) % 2019
    a[k] += 1
for i in a:
    ans += i * (i - 1) * 0.5
print(int(ans))
import collections
s = input()
mods = [0]
crt = 0
ans = 0
if len(s) <= 4:
    print(0)
    exit()
# for i in range(len(s)):
#     crt = crt*10+int(s[i])
#     crt %= 2019
#     mods.append(crt)
# print(mods)
for i in range(len(s)-1,-1,-1):
    crt = crt+int(s[i])*pow(10, (len(s)-i-1), 2019)
    crt %= 2019
    mods.append(crt)
#print(mods)
mods_count = collections.Counter(mods)
mods_count = list(mods_count.values())
for i in range(len(mods_count)):
    tar = mods_count[i]
    ans += tar*(tar-1)//2
print(ans)
n=input()
p=2019
t=1
y=0
c=[0]*p
for x in map(int,n[::-1]):
  y+=t*x
  y%=p
  c[y]+=1
  t*=10
  t%=p
print(sum(i*(i-1)//2 for i in c)+c[0])
s = list(map(int, list(input())))

acc = [0]*(len(s)+1)
digit = 1

for i in reversed(range(0, len(s))):
    si = s[i] * digit % 2019
    acc[i] = (acc[i+1] + si) % 2019
    digit *= 10
    digit %= 2019

cnt = [0]*2019
ans = 0
for i in range(0, len(s)+1):
    ans += cnt[acc[i]]
    cnt[acc[i]] += 1

print(ans)
s=input()
n=len(s)
mod=2019
d=0
p=1
ml=[0]*mod
for i in range(1,n+1):
  k=int(s[-i])
  d+=p*k
  d%=mod
  ml[d]+=1
  p*=10
  p%=mod
ans=0
for i in ml:
  ans+=i*(i-1)//2
print(ans+ml[0])
M=2019;t=1;p=r=0;c=[0]*M
for x in'0'+input()[::-1]:p+=int(x)*t;p%=M;t=t*10%M;r+=c[p];c[p]+=1
print(r)
import numpy
import math


def main():
    S = input()
    Mod = [0 for i in range(2019)]
    Mod[0] = 1
    d = 1
    tmp = 0
    ans = 0
    for c in reversed(S):
        tmp = (d * int(c) + tmp) % 2019
        ans += Mod[tmp]
        #print(tmp, ans)
        Mod[tmp] += 1
        d = (d * 10) % 2019

    print(ans)


if __name__ == "__main__":
    main()
from collections import Counter
S = input()[::-1]
MOD = 2019
X = [0]
for i,s in enumerate(S):
    X.append((X[-1]+int(s)*pow(10,i,MOD))%MOD)
C = Counter(X)
print(sum([v*(v-1)//2 for v in C.values()]))
s = input()
ans = 0
mod = [0]*2019
t = s[len(s)-1]
n = 1
for i in range(len(s)-1,-1,-1):
#     mod.append(int(s[i:])%2019)
    mod[int(t)%2019] += 1
#     t = int(t) + (10**(len(s)-i-1))*int(s[i])
    t = int(t) + n*10*int(s[i-1])
    n = n*10%2019
for i in range(0,2019):
    ans += mod[i]*(mod[i]-1)/2
ans += mod[0]
print(int(ans))
s=input()
a=[0]*2019
a[0]+=1
pot=1
v=0
ans=0
for i in range(len(s)-1,-1,-1):
	digit=int(s[i])
	v=(v+digit*pot)%2019
	pot=(pot*10)%2019
	ans+=a[v]
	a[v]+=1

print(ans)
S = input()
mod = [0] * 2019
res = 0
for c in S:
    m = int(c)
    new_mod = [0] * 2019
    for i, n in enumerate(mod):
        new_mod[(i*10 + m) % 2019] = n
    new_mod[m] += 1
    mod = new_mod
    res += mod[0]
print(res)
s = input()
n = len(s)

ans = 0
ten = 1
d = 0
cntlist = [0]*2019
cntlist[0] = 1
for i in range(n-1,-1,-1): #ステップ指定必要
    a = int(s[i])*ten%2019
    d = (d + a)%2019
    ten *= 10
    ten %= 2019
    cntlist[d] += 1

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

print(ans)
from collections import Counter
S = list(input())
S.reverse()
MOD = 2019

t = [0]
r = 1
for i in range(len(S)):
    q = (t[-1] + (int(S[i]) * r) % MOD) % MOD
    t.append(q)
    r *= 10
    r %= MOD

cnt = Counter(t)
cnt_mc = cnt.most_common()

ans = 0
for _, j in cnt_mc:
    if j >= 2:
        ans += j * (j - 1) // 2
        
print(ans)
from collections import defaultdict

S = list(map(int, input()))
mod = [0] * len(S)
cur = 0
factor = 1
for i, n in list(enumerate(S))[::-1]:
    cur = (cur + n * factor) % 2019
    factor = factor * 10 % 2019
    mod[i] = cur
ans = 0
cnt = defaultdict(int)
for i in range(len(S)):
    ans += cnt[mod[i]]
    cnt[mod[i]] += 1
ans += cnt[0]
print(ans)
import sys
sys.setrecursionlimit(10**9)


S = input()
N = len(S)
P = 2019

if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
    sys.exit()

num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % P
    _10 *= 10
    _10 %= P
    ans += num[now]
    num[now] += 1

print(ans)
def main():
    S=input()
    a=0 
    b=[0]*2019
    l=[0]*2019
    for i in S:
        k=int(i)
        for j in range(2019):
            l[(j*10+k)%2019]=b[j]
        l[k]+=1
        a+=l[0]
        b=l.copy()
    print(a)
main()
# originally submitted at https://atcoder.jp/contests/abc164/submissions/12433818
# authored by catamanyan
S = list(map(int,input()))

counter = 0
amari = [0]*2019

s = 0
for i in range(len(S)):
    if S[len(S)-i-1] == 0:
        continue
    else:
        s += S[len(S)-i-1] * pow(10, i, 2019)
        s = s % 2019
        amari[s] += 1

for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2

counter += amari[0]

print(int(counter))
S = input()[::-1]
MOD = 2019

r = 0
C = [0 for _ in range(MOD)]
C[0] = 1

for i,s in enumerate(S):
    r += int(s)*pow(10,i,MOD)
    r %= MOD
    C[r] += 1

a = 0
for c in C:
    a += c*(c-1)/2

print(int(a))
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    S = sr()
    N = len(S)
    a = [0]*2019
    a[0] += 1
    t = 0
    r = 1
    for s in reversed(S):
        t += int(s)*r
        t %= 2019
        r *= 10
        r %= 2019
        a[t] += 1
    ans = 0
    for i in range(2019):
        ans += a[i]*(a[i]-1)//2
    print(ans)
resolve()
S = list(map(int, list(input()[::-1])))

N = len(S)
P = 2019
C = [0] * P
B = 1
t = 0
ans = 0
for i in range(N):
    C[t] += 1
    t = (t + S[i] * B) % P
    ans += C[t]
    B = B * 10 % P
print(ans)
st = input()[::-1]
n = len(st)

arr = [0]*2019
arr[0] += 1
count = 0
dig = 1
r = 0

for i in range(0,n):
  r = (r + int(st[i]) * dig) % 2019
  arr[r] += 1
  dig = dig * 10 % 2019

for i in arr:
  count += i*(i-1)//2;

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

ans = 0
L[0] += 1
for l in L:
    ans += l*(l-1)//2
print(ans)
S = input()
cnt = [0]*2019
cnt[0] = 1
n = 0
t = 1
for i in reversed(S):
    n += int(i)*t
    n %= 2019
    cnt[n] += 1
    t *= 10
    t %= 2019
print(sum(i*(i-1)//2 for i in cnt))
S=input()

p,q=0,1
dp = {0:1}
mod = 2019

for i in range(len(S)-1,-1,-1):
  p = (p+int(S[i])*q)%mod
  if p not in dp:dp[p]=0
  dp[p]+=1
  q= (q*10)%mod

cnt = 0
for i in dp:
  cnt += dp[i]*(dp[i]-1)//2
print(cnt)
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

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

T = [-1]*L
mod = 2019
now = 0
for i in range(L):
    s = S[i]
    now += int(s)*pow(10,i,mod)
    T[i] = now%mod
    
Nlist = [0]*2019
Nlist[0] = 1

for i in T:
    Nlist[i] += 1
    
ans = 0
for i in Nlist:
    ans += i*(i-1)//2
print(ans)
s=input()
s=s[::-1]
a=1
b=0
t=[0]*2019
t[0]=1
ans=0
for i in range(len(s)):
    b+=int(s[i])*a
    b%=2019
    a*=10
    ans+=t[b]
    t[b]+=1
    a%=2019

print(ans)
import sys
sys.setrecursionlimit(10**9)


S = input()
N, P = len(S),2019

if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
    sys.exit()

num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % P
    _10 *= 10
    _10 %= P
    ans += num[now]
    num[now] += 1

print(ans)
import sys

M = 2019
S = sys.stdin.readline().rstrip()
N = len(S)

dmod = [0] * (N + 1)
amod = [0] * (N + 1)
tenmod = 1
prev_amod = 0
mcnt = [0] * 2019
ans = 0
for i in range(N, -1, -1):
    d = ord(S[i]) - ord("0") if i < N else 0
    dmod[i] = d * tenmod % M
    amod[i] = (dmod[i] + prev_amod) % M
    ans += mcnt[amod[i]]
    mcnt[amod[i]] += 1
    tenmod = tenmod * 10 % M
    prev_amod = amod[i]
print(ans)
from collections import Counter
s = input()[::-1]
n = len(s)
ans = 0
tmp_3, tmp_673 = 0, 0
c = Counter()
c[(0, 0)] = 1
for i in range(n):
	tmp_3 += int(s[i]) * pow(10, i, 3)
	tmp_3 %= 3
	tmp_673 += int(s[i]) * pow(10, i, 673)
	tmp_673 %= 673
	ans += c[(tmp_3, tmp_673)]
	c[(tmp_3, tmp_673)] += 1
print(ans)
mod2019=[0]*2019
mod2019[0]=1
t=input()
n=len(t)
s=[]
for i in range(n):
  s.append(int(t[i]))
x=1
y=0
for i in reversed(range(n)):
  y+=s[i]*x
  mod2019[y%2019]+=1
  x=(x*10)%2019
ans=0
for i in range(2019):
  ans+=mod2019[i]*(mod2019[i]-1)
print(ans//2)
S = list(map(int, list(input())))
S.reverse()
a = [0]*len(S)
y = 2019
x = 1
t = 0
cnt = [0]*y
res = 0
for i in range(len(S)):
    cnt[t] += 1
    t += S[i]*x
    t %= y
    res += cnt[t]
    x = x*10%y
print(res)
from collections import Counter
N = input()
S=0
mod_count=[0]
ans=0
i=0
for X in N[::-1]:
  S = int(X)*pow(10,i,2019) % 2019
  S=mod_count[i]+S
  mod_count.append(S%2019)
  i+=1

c = Counter(mod_count)
ans = sum(Y * (Y-1)/2 for Y in c.values())
print(int(ans))
from itertools import accumulate,chain
from collections import Counter

MOD = 2019

S = input()

memo = [None]*len(S)
x = 1
for i,c in enumerate(reversed(S)):
    memo[i] = x*int(c)%MOD
    x = (10*x)%MOD

acc = tuple(chain((0,), accumulate(memo, lambda x,y: (x+y)%MOD)))

print(sum(c*(c-1)//2 for c in Counter(acc).values()))
s = input()
ans = 0
U = [0 for i in range(2019)]
mod = 2019
sum_i_to_n = 0
for i in range(len(s)-1,-1,-1):
    sum_i_to_n += int(s[i])* pow(10,len(s)-i-1,mod)
    sum_i_to_n %= mod
    if sum_i_to_n % mod == 0:
        ans += 1
    ans += U[sum_i_to_n]
    U[sum_i_to_n] += 1
print(ans)
import numpy as np
from numba import njit

S = input()
MOD = 2019
dp = np.zeros(MOD, dtype=np.int64)
dp[0] = 1

@njit
def hoge(dp, s):
    T = dp.copy()
    dp[s:] = T[:-s]
    dp[:s] = T[-s:]

ans = 0
for i, s in enumerate(S[::-1]):
    hoge(dp, (int(s) * pow(10, i, MOD)) % MOD)
    ans += dp[0]
    dp[0] += 1
print(ans)
mod = 2019
s = input()
n = len(s)
w = 0
d = {}
p = 1
for i in reversed(range(n)):
	w += int(s[i]) * p
	p *= 10
	w %= mod
	p %= mod
	if w in d:
		d[w] += 1
	else:
		d[w] = 1
if 0 in d:
	d[0] += 1
else:
	d[0] = 1
o = 0
for x in d:
	o += d[x] * (d[x] - 1) // 2
print(o)
from queue import deque


S = deque(input())
mod = 2019
T = [0] * mod
T[0] = 1
a, b = 0, 1

for _ in range(len(S)):
    s = int(S.pop())
    a = a + s * b
    a = a % mod
    T[a] += 1
    b = b * 10
    b = b % mod
    
print(sum((i * (i - 1) // 2 for i in T)))
import collections
S = input()[::-1]

d = 1
M = []
for s in S:
    M.append(int(s)*d % 2019)
    d *= 10
    d %= 2019

S = [0]
for m in M:
    S.append((S[-1]+m) % 2019)

C = collections.Counter(S)

ans = 0
for v in C.values():
    ans += v*(v-1)//2
print(ans)
s = input()
n = len(s)
power = [0]*(n+1)
power[-1] = 1
x = 1
for i in range(n-1,-1,-1):
	x = (x*10) % 2019
	power[i] = x
mod19 = [0]*(n+1)
cnt = [0]*2020
cnt[0] = 1
x=0
mod19[n] = 0
for i in range(n-1, -1,-1):
	x = (x+int(s[i])*power[i])%2019
	mod19[i] = x
	cnt[x]+=1
ans = 0
for i in range(2020):x = cnt[i];ans+= x*(x-1)//2
print(ans)
s = input()[::-1]
n = len(s)
counts = [0] * 2019
counts[0] = 1
current = 0
d = 1

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

ans = 0
for count in counts:
    if count > 1:
        # print(i)
        ans += count * (count-1) //2
print(ans)
from collections import Counter
def main():
    S = input()
    A = [0] * ((n := len(S)) + 1)
    A[1] = (a := int(S[-1])) % 2019
    for i in range(2, n + 1):
        a += pow(10, i - 1, 2019) * int(S[-i])
        A[i] = a % 2019
    c = Counter(A)
    ans = 0
    for v in c.values():
        ans += v * (v - 1) // 2
    print(ans)

if __name__ == '__main__':
    main()
S=input()
P=2019

answer=0
mod_table=[0]*P
mod_table[0]=1
revS=S[::-1]
  
modp=0
mod10=1
for i in range(len(S)):
  mod10=(mod10*10)%P
  #modp=(10*modp+int(revS[i]))%P
  modp=(modp+mod10*int(revS[i]))%P
  mod_table[modp]+=1
    
#print(mod_table)
for i in range(P):
  answer+=mod_table[i]*(mod_table[i]-1)//2
  
print(answer)
from collections import deque, defaultdict

S = input()

L = int(S)
S = S[::-1]
cnt = defaultdict(int)

tmp = 0
answer = 0
for i, s in enumerate(S):
    tmp = (tmp + int(s) * pow(10, i, 2019)) % 2019
    #print(tmp)
    if tmp % 2019 == 0:
        answer += cnt[0] + 1
    else:
        answer += cnt[tmp % 2019]
    cnt[tmp % 2019] += 1
    #print(tmp, answer)

print(answer)
s=input()
n=0
ans=0
A=[0]*2019
A[0]=1
for i,j in enumerate(reversed(s)):
  n=(n+int(j)*pow(10,i,2019))%2019
  #print(i,n)
  A[n]+=1
for i in A:
  ans+=i*(i-1)//2
print(ans)
s = input()[::-1]
 
counts = [0] * 2019
counts[0] = 1
 
num = 0
d = 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)
from collections import defaultdict

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

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

ans = 0

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

print (ans)

# print (dic)
s = input()
mod = 2019
remains = [0]*mod

ans = 0
now = 0
remains[0] = 1
for i,val in enumerate(s[::-1]):
    now += int(val) * pow(10,i,mod )
    now %= mod
    ans += remains[now]
    remains[now] += 1

print(ans)
# D - Multiple of 2019

from collections import defaultdict
d = defaultdict(int)

mod = 2019
s = str(input())[::-1]

ssum = 0
d[0] = 1
for i in range(len(s)):
    ssum = (ssum + int(s[i])*pow(10, i, mod))%mod
    d[ssum] += 1

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

print(ans)
s = input()[::-1]
num = 0
last = 0
d = 1
count={}
for k in range(2019):
    count[k] = 0
    
count[0] =1  # 割り切れるとき

for i in s:
    num = (int(i) * d + num)%2019
    
    d *= 10
    d %= 2019
    count[num] += 1
    
ans = 0
for j in range(2019):
    ans += count[j] * (count[j]-1) //2
print(ans)
def main():
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    S = input().rstrip()
    counter = defaultdict(int)
    mod = 2019
    counter[0] += 1
    num = 0
    d = 1
    for c in S[::-1]:
        num += int(c) * d
        num %= mod
        counter[num] += 1
        d *= 10
        d %= mod
    ans = 0
    for v in counter.values():
        ans += (v * (v-1)) // 2
    print(ans)

if __name__ == '__main__':
    main()
s=input()
l=len(s)
ans=0
p=0
a={}
b=-1
c=-1
d=-1
e=-1
q=1
for j in range(l)[::-1]:
    p=(p+int(s[j])*q)%2019
    q*=10
    q%=2019
    if p==0:
        ans+=1
    if a.get(p)!=None:
        ans+=a[p]
    if a.get(p)!=None:
        a[p]+=1
    else:
        a[p]=1
print(ans)
import collections
s = list(input())
n = len(s)
mod = [0]*(n+1)
pow10 = 1
for i in range(n):
    mod[i+1] = (mod[i] + int(s[-1-i])*pow10)%2019
    pow10 = pow10*10%2019
d = collections.Counter(mod)
ans = 0
for i in d.values():
    ans += i*(i-1)//2
print(ans)
s = input()
s_r = s[::-1]
lmod = [0]
cmod = 0
for n,i in enumerate(s_r):
    cmod += int(i)*pow(10,n,2019) % 2019
    cmod = cmod % 2019
    lmod.append(cmod)

from collections import Counter
r = 0
for _,i in Counter(lmod).items():
    r += i*(i-1)/2

print(int(r))
mod = 2019
s = input()
n = len(s)
w = 0
d = [0] * mod
p = 1
for i in reversed(range(n)):
	w += int(s[i]) * p
	p *= 10
	p %= mod
	w %= mod
	d[w] += 1
d[0] += 1
o = 0
for x in d:
	o += x * (x - 1) // 2
print(o)
import numpy as np

s = input()

d = [ int( 0 ) ] * 2019
d[ 0 ] = int( 1 )
r = int( 0 )
t = int( 1 )

for si in reversed( s ):
#    print( si )

    r = int( si ) * t + r
    r = r % 2019

    t = t * 10
    t = t % 2019

    d[ r ] = d[ r ] + 1

ans = int( 0 )
for di in d:
    ans = ans + di * ( di - 1 ) // 2

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

mod = 2019
d = [0 for i in range(2019)]
d[0] = 1
t = 1
rem = 0

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

print(int(sum([i * (i-1) / 2 for i in d])))
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(map(int, list(input())))
mod = 2019
lens = len(S)
mods = [0]*lens
cum = 0
for i in range(lens):
    s = S[-i-1]
    cum += s*pow(10, i, mod)
    cum %= mod
    mods[i] = cum
mods += [0]
from collections import Counter
c = Counter(mods)

ans = 0
for num, cnt in c.most_common():
    if cnt<2:
        break
    ans += cnt*(cnt-1)//2
print(ans)
S = input()[::-1]

modCount = [0]*2019
modCount[0] = 1
mod = 0
dig = 1
result = 0

for i in range(len(S)):
  mod = (int(S[i:i+1])*dig+mod)%2019
  dig = (dig*10)%2019
  result += modCount[mod]
  modCount[mod] += 1

print(result)
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 2019
mans = inf ;ans = 0 ;count = 0 ;pro = 1

S = list(map(int,input()))
n = len(S)
now10 = 1
for i in range(n-1,-1,-1):
  S[i] = S[i] * now10 % mod
  now10 = now10 * 10 % mod
A = [0]* (n+1)
for i in range(n):
  A[i+1] = (A[i] + S[i]) % mod
C = collections.Counter(A)
for k,e in C.items():
  ans += (e-1)*e//2
print(ans)
m=2019
l=[0]*m
l[0]=1
s,k=0,1
for c in reversed(input()):k=k*10%m;s=(s+int(c)*k)%m;l[s]+=1
print(sum(v*(v-1)//2for v in l))
mod=2019
s=input()

d={}
temp=1
cnt=0
we=0
d[0]=1
for i in range(len(s)):
  we=(we+int(s[-1-i])*temp)%mod
  temp=temp*10%mod
  
  if we not in d:
    d[we]=1
  else:
    d[we]+=1

#print(d)
for i in d:
  cnt+=(d[i]*(d[i]-1))//2
print(cnt)
# -*- coding: utf-8 -*-
S = input()
list_amari = [0 for i in range(2019)]
amari_prev = 0
X = 1

for i in range(len(S)):
  amari = (int(S[-i-1])*X+amari_prev)%2019
  list_amari[amari] += 1
  amari_prev = amari
  X = (10*X)%2019

count = list_amari[0]
for v in list_amari:
  count += v*(v-1)//2

print(count)
S = input()[::-1]
n = len(S)
dp = [0]*2019
dp[0] = 1
X = 0
Y = 1
for s in S:
    Z=(int(s)*Y)%2019
    X = (X+Z)%2019
    dp[X] += 1
    Y = (10*Y)%2019
answer = 0
for i in range(2019):
    answer += dp[i]*(dp[i]-1)/2
print(int(answer))
S = input()
n = len(S)
dp = {0:1}
q = 1
p = 0
for i in range(n):
    p += int(S[n-1-i])*q
    q *= 10
    q = q % 2019
    p = p % 2019
    if p not in dp:
        dp[p] = 1
    else:
        dp[p] += 1
print(sum(dp[i]*(dp[i]-1)//2 for i in dp))
def input_int():
    return int(input())

def input_ints():
    return list(map(int, input().split()))

S = input()
N = len(S)
cnt = [0] * 2019
cnt[0] += 1
ans = 0

p = 1
now = 0

for i in reversed(range(N)):
    now = (now + int(S[i]) * p) % 2019
    p = p * 10 % 2019
    ans += cnt[now]
    cnt[now] += 1

print(ans)
def main():
    s=list(input())[::-1]
    ans,tot,x,m=0,0,1,2019
    cnt=[0]*m
    n=len(s)
    for i in range(n):
        cnt[tot] += 1
        tot += int(s[i])*x
        tot %= m
        ans += cnt[tot]
        x = x*10%m
    print(ans)

if __name__ == '__main__':
    main()
#!/usr/bin/env python3
s = str(input())

mod = 2019

div_memo = [0 for _ in range(mod)]

num = 0
d = 1
for n in reversed(s):
    num += int(n)*d
    num %= 2019
    div_memo[num] += 1
    d *= 10
    d %= 2019

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

ans += div_memo[0]
print(int(ans))
S=input()
a=0
b=[0]*2019
No=[None]*2019
for i in S:
    l=No.copy()
    k=int(i)
    for j in range(2019):
        l[(j*10+k)%2019]=b[j]
    l[k]+=1
    a+=l[0]
    b=l
print(a)
def resolve():
    s = input()
    s = s[::-1]
    c = [0]*2019
    # why?
    c[0] = 1
    r = 0
    d = 1
    for i in s:
        num = int(i) * d % 2019 + r
        num %= 2019
        c[num] += 1
        r = num
        d *= 10
        d %= 2019
    ans = 0
    for i in c:
        ans += i*(i-1)//2
    print(ans)
resolve()
p=2019
s,a,d,z=input()[::-1],0,0,[0]*p
for i,j in enumerate(s):
	d=(d+int(j)*pow(10,i,p))%p
	z[d]+=1
r=z[0]
for i in range(p):
	r+=z[i]*(z[i]-1)//2
print(r)
import collections


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


s = input()
ans = 0
lst_mod = [0]*2019  # O(N)で回した連続値のmod(2019)の値
lst_mod[0] += 1
num, dim = 0, 1
for char in reversed(s):
    num += int(char)*dim
    num %= 2019
    dim *= 10
    dim %= 2019  # サイズを大きくしたくないからmod(2019)を使う
    lst_mod[num] += 1

for mod in lst_mod:
    ans += comb(mod)
print(int(ans))
S=input()

N=len(S)
d={}
for i in range(2019):
    d[i]=0

d[0] = 1

mod=0
dig=1

for i in range(N):
    #s=S[N-1-i:]
    #d[int(s)%2019]+=1
    mod += dig * int(S[N-1-i])
    mod %= 2019
    d[mod] += 1
    dig *= 10
    dig %= 2019


ans = 0
for k in d.keys():
    v = d[k]
    if v > 1:
        ans += v*(v-1)//2
print(ans)
s = input()[::-1]

m = 0
d = 1
cnt = [0] * 2019

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

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

print(ans)
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)
mods = [0]*2019
mods[0] = 1
s = input()
t = 0
u = 1
for i in range(1,len(s)+1):
    t = (t + int(s[-i])*u)%2019
    u = u*10%2019
    mods[t] += 1


cnt = 0
for x in mods:
    if x >= 2:
        cnt += x*(x-1)/2
print(int(cnt))
s = input()
d={0:1}
suf=0
pot=1
ans=0
for i in range(len(s)-1,-1,-1):
    dig=int(s[i])
    suf=(suf+dig*pot)%2019
    pot=(pot*10)%2019
    if suf in d:
        ans+=d[suf]
        d[suf]+=1
    else:
        d[suf]=1
print(ans)
S = input()
pow10 = [1] * len(S)
for i in range(1,len(S)):
    pow10[i] = (pow10[i-1] * 10) % 2019
#print(pow10)    
smod = [0] * (len(S) + 1)
count = [0] * 2019
for i in range(len(S)):
    smod[i+1] = (smod[i] + int(S[-i-1]) * pow10[i]) % 2019
for i in range(len(S) + 1):
    count[smod[i]] += 1
#print(count)
ans = 0
for i in range(2019):
    ans += count[i] * (count[i] - 1) // 2
    
print(ans)
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    """
    modulos = [0]*2019
    modulos[0] = 1
    S = input()
    base = 1
    num = 0
    for c in S[::-1]:
        num = (base*int(c)+num)%2019
        base = (base*10)%2019
        modulos[num] += 1
    answer = 0
    for n in modulos:
        answer += n*(n-1)//2
    return answer


if __name__ == '__main__':
    print(solve())
#0からiまでのSを2019で割ったときのあまりを調べる
#A%mod =a,B$mod=aなら（A-B)%mod=0
from collections import Counter
S = input()
dp = [0]
mod = 2019
for i in reversed(range(len(S))):
    dp.append(dp[-1]%mod+pow(10,len(S)-i-1,mod)*int(S[i]))
    dp[-1]%=mod
count = Counter(dp)
ans = 0
for key,val in count.items():
    if val>=2:
        ans += val*(val-1)//2
print(ans)
s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
  u=(u+(i*d)%2019)%2019
  l[u]+=1
  d=d*10%2019
for i in l:
  ans+=i*(i-1)//2
print(ans)
import sys
import numba
import numpy as np
S = sys.stdin.buffer.readline().decode('utf-8').rstrip()
S = np.array([int(d) for d in S[::-1]], dtype=np.int32)

@numba.njit(numba.i8(numba.typeof(S)), cache=True)
def solve(S):
	M = 2019
	t = 1
	ans = 0
	c = np.zeros(M, dtype=np.int64)
	c[0] = 1
	r = 0
	for d in S:
		r = (d * t + r) % M
		ans += c[r]
		c[r] += 1
		t = t * 10 % M
	return ans

print(solve(S))