peterverebics/CodeNet_Python_118 huggingface dataset:
s = input()
n = len(s)
m = 2019
a = [0] * (n + 1)
b = [0] * (n + 1)
b[0] = 1
for i in range(1, n + 1):
    b[i] = b[i - 1] * 10 % m
c = [0] * m
c[0] += 1
ans = 0
for i in range(n - 1, -1, -1):
    w = (a[i + 1] + (ord(s[i]) - ord('0')) * b[n - 1 - i]) % m
    ans += c[w]
    c[w] += 1
    a[i] = w
print(ans)
A = input()

S = 0
lis = [0] * 2019
lis[0] += 1
l = len(A)+1
d = 1

for n in reversed(A):
    S += int(n)*d
    S %= 2019
    lis[S] += 1
    d *= 10
    d %= 2019

result = 0

for n in lis:
    result += (n*(n-1)//2)


print(result)
s=input()
n=len(s)
a=0
t=1
d=[1]+[0]*2018
 
for i in range(n):
    a+=int(s[n-1-i])*t
    a%=2019
    t*=10
    t%=2019
    
    d[a]+=1

ans=0
for i in d:
    ans+=i*(i-1)//2
 
print(ans)
from collections import defaultdict
s = input()
n = len(s)
p = 2019
dd = defaultdict(int)
dd[0] = 1
prev = 0
for i in reversed(range(n)):
    prev = (prev+int(s[i])*pow(10, n-i, p)) % p
    dd[prev] += 1
print(sum(v*(v-1)//2 for v in dd.values()))
def main():
    s = input()[::-1]

    sum_of_digits = 0

    cnts = [0] * 2019

    cnts[0] = 1

    d = 1

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


    ans = 0

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

    print(ans)

if __name__ == '__main__':
    main()
S = input()
count = 0
l = [0]*2019
l[0] = 1
mod = 2019
tmp = 0

for i in range(1,len(S)+1):
    tmp = (tmp + int(S[len(S)-i])*pow(10,i-1,mod))%mod
    l[tmp] += 1
    

for j in range(2019):
    if l[j] >= 2:
        count += l[j]*(l[j]-1)//2

print(count)
s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  digit %= 2019
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)
S=input()

mod=2019
D={}
S=S[::-1]
now=0

for i in range(len(S)):
    if (int(S[i])*pow(10,i,mod)+now)%mod not in D:
        D[(int(S[i])*pow(10,i,mod)+now)%mod]=1
    else:
        D[(int(S[i])*pow(10,i,mod)+now)%mod]+=1
    now=(int(S[i])*pow(10,i,mod)+now)%mod
#print(D)
ans=0
for k,v in D.items():
    if k==0:
        v+=1
    ans+=v*(v-1)//2
print(ans)
s=input()

counter=[0]*2019
counter[0]=1
num=0
t=1
prefer=0
for i in reversed(s):
    num+=int(i)*t
    num%=2019
    t*=10
    t%=2019
    counter[num]+=1

ans=0
for i in range(2019):
    c=counter[i]
    ans+=c*(c-1)/2
print(int(ans))
S=input()
ans=0
MOD=2019
cnt=[0]*MOD
cur=0
cnt[cur]=1
d=1
for s in S[::-1]:
  cur+=int(s)*d
  cur%=MOD
  cnt[cur]+=1
  d*=10
  d%=MOD
for c in cnt:
  ans+=c*(c-1)//2
print(ans)
s = str(input())
now = [0] * 2019
mod = 2019
ans,cnt = 0,1
lis = [int(s[-(1+i)]) for i in range(len(s))]
for num in lis:
    now[0] += 1
    num *= cnt
    num %= mod
    next = [0] * mod
    for i in range(2019-num):
        next[num+i] += now[i]
    for i in range(num):
        next[i] += now[2019-num+i]
    ans += next[0]
    cnt *= 10
    cnt %= mod
    now = next
print(ans)
from collections import Counter

S = input()

ans = 0
mod_list = [0] * len(S)
mod_list[-1] = int(S[-1])
m = 1
for i in range(2, len(S) + 1):
    m = (10 * m) % 2019
    mod_list[-i] = (mod_list[-i + 1] + (int(S[-i]) * m)) % 2019

mod_counter = Counter(mod_list)
mod_counter[0] += 1

ans = 0
for _, v in mod_counter.items():
    ans += v * (v - 1) // 2

print(ans)
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)
ans = 0
for v in C.values():
    ans += v * (v - 1) // 2
print(ans)
s=input()


s=s[::-1]
l=[0]*2019
l[0]=1
prev=0
ans=0
mul=1

for i in range(len(s)):
  now=(int(s[i])*mul)%2019
  ans+=l[(prev+now)%2019]
  l[(prev+now)%2019]+=1
  prev=(prev+now)%2019
  mul=(mul*10)%2019

print(ans)
s = input()
res = 0
m = 1
p =[0]*2019
for i in map(int,s[::-1]):
    res +=i*m
    res %=2019
    p[res] +=1
    m *=10
    m %=2019
print(p[0]+sum([i*(i-1)//2 for i in p]))
s=input()
mod=2019
dp=[0]*mod
k=0
t=1
for x in map(int,s[::-1]):
    k+=t*x
    k%=mod
    dp[k]+=1
    t*=10
    t%=mod
print(sum(i*(i-1)//2 for i in dp)+dp[0])
S = input()
mod = 2019
count = [0] * 2019
count[0] = 1
tmp = 0
d = 1

for s in S[::-1]:
    tmp += int(s) * d
    count[tmp % mod] += 1
    d *= 10
    d %= mod

ans = 0

for c in count:
    ans += c * (c - 1) // 2
        
print(ans)
S=list(map(int,list(input())))
N=len(S)

m=[0]*2019
m[0]=1
ans=0

sm=0
d=1
for i in range(N):
    sm=(sm+S[N-1-i]*d)%2019
    m[sm] += 1
    d=(d*10)%2019

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

print(ans)
s = input()

MOD = 2019
#0を2019個のリスト
d = [0] * MOD
d[0]=1
r=0
t=1
#大きい順から
for i in reversed(s):
    r += int(i)*t
    r %= MOD
    t *= 10
    t %= MOD
    d[r] += 1

print(sum(i*(i-1)//2 for i in d))
from collections import Counter
s=input()
n=len(s)
M=[0]
mod=2019
for i in range(n):
	m=(M[-1]+int(s[n-1-i])%mod*pow(10,i,mod))%mod
	M.append(m)
MC=Counter(M)
r=0
for v in MC.values():
	if v>1:
		r+=v*(v-1)//2
print(r)
S = input()
counts =[0] * 2019
counts[0] = 1
num, d = 0,1

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

ans = 0
for count in counts:
  ans += count * (count - 1) //2
print(ans)
s = input()
n = len(s)
mod = 2019

cum = [0]*n
cum[n-1] = int(s[-1]) % mod
d = [1]*n
for i in range(n-1)[::-1]:
    d[i] = d[i+1]*10%mod

for i in range(0, n-1)[::-1]:
    a = int(s[i]) * d[i] % mod
    cum[i] = (cum[i+1]+a) % mod
cnt = [0]*mod

ans = 0
for i in cum[::-1]:
    ans += cnt[i]
    cnt[i] += 1
    if i == 0:
        ans += 1
print(ans)
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)
s = input()

remain = [0]*2020
now = 0
ans = 0
for i in range(len(s)-1, -1, -1):
    now += int(s[i])*pow(10, len(s)-i-1, 2019)
    ans += remain[now%2019]
    remain[now%2019] += 1

ans += remain[0]

print(ans)
S = input()
N = len(S)
SUM = [0] * (N + 1)
MOD = 2019

r = 1  # 10のi乗を2019で割った余り
S = S[::-1]
for i in range(N):
    A = r * int(S[i])
    SUM[i + 1] = (SUM[i] + A) % MOD
    r = r * 10 % MOD

cnt = [0] * 2019
ans = 0
for x in SUM:
    ans += cnt[x]
    cnt[x] += 1
print(ans)
M,a,t,p=2019,0,0,1;l=[0]*M
for i in input()[::-1]:l[t%M]+=1;t+=int(i)*p;a+=l[t%M];p=p*10%M
print(a)
import collections
S = list(map(int, input()))[::-1]
mod_list = [0 for _ in range(len(S)+1)]
x = 0
d = 0
for i, s in enumerate(S):
    x += s * pow(10, d, 2019)
    d += 1
    mod_list[i] = x%2019
c = collections.Counter(mod_list)
ans = 0
for i in range(2020):
    ans += c[i] * (c[i]-1)//2
print(ans)
from collections import Counter

s = list(input())
ls = len(s)
T = [0] * (ls+1)
modL = [0]
cnt = 0
pad = 1

for i in reversed(range(0, ls)):
    T[i] = T[i+1] + int(s[i]) * pad
    modL.append(T[i] % 2019)
    pad = pad * 10 % 2019

ans = 0
for c in Counter(modL).values():
    ans += c * (c - 1) // 2

print(ans)
import sys
from pprint import pprint

S = sys.stdin.readline().strip()
S = S[::-1]

n = len(S)
r = [0] * 2019
acum = [0] * (len(S)+1)
r[0] += 1
for i, s_i in enumerate(S):
    acum[i+1] = int(s_i) * pow(10, i, 2019) + acum[i]
    acum[i+1] %= 2019
    r[acum[i+1]] += 1
# print(acum)

ans = 0
for r_i in r:
    ans += r_i * (r_i - 1) // 2
print(ans)
import sys
input=sys.stdin.readline
s=input().rstrip()
n=len(s)
l=[0]
for i in range(n):
    x=int(s[n-1-i])
    y=l[-1]+x*pow(10,i,2019)
    l.append(y%2019)
c=[0]*2019
for i in l:
    c[i]+=1
ans=0
for i in c:
    ans+=i*(i-1)//2
print(ans)
# Problem D - Multiple of 2019

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

# initialization
ans = 0

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

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

# output
print(ans)
def resolve():
    from collections import defaultdict
    s = input()
    n = len(s)
    d = defaultdict(int)
    d[0] += 1
    j = 0
    for i in range(1, n + 1):
        j += int(s[-i]) * pow(10, i - 1, 2019)
        j %= 2019
        d[j] += 1

    def calc(x): return x * (x - 1) // 2
    ans = 0
    for v in d.values():
        ans += calc(v)
    print(ans)


if __name__ == '__main__':
    resolve()
S = input()[::-1]

cnts = [0]*2019
cnts[0] = 1
num = 0
d = 1
ans = 0

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

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

print(ans)
from collections import Counter
s = input().rstrip()

n = len(s)
dp = [0] * (n+1)

for i in range(n-1, -1, -1):
    dp[i] = (dp[i+1] + pow(10, (n-i-1), 2019) * int(s[i])) % 2019

c = Counter(dp)

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

print(ans)
s = input()
n = 0
ans = 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)
def main():
    S = input()[::-1]

    count = 0

    mods = [0] * 2019
    mods[0] = 1
    current = 0
    x = 1
    for s in S:
        current = (current + x * int(s)) % 2019
        count += mods[current % 2019]
        mods[current % 2019] += 1
        x = x * 10 % 2019

    print(count)

if __name__ == '__main__':
    main()
S = input()[::-1]


_MOD = {0: 1}
amari = 0
a = 1
ans = 0

for i in S:
    amari = (amari + int(i) * a) % 2019
    a = (a * 10) % 2019  #表示桁 1あたりの余
    if amari in _MOD:
        _MOD[amari] = _MOD[amari] + 1
    else:
        _MOD[amari] = 1
    
for amari in _MOD:
    m = _MOD[amari]
    ans += (m * (m - 1)) // 2

print(ans)
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math

NN = 202020
MOD = 10**9+7
# MOD = 998244353
INF = float("inf")

s = input()
d = defaultdict(int)
d[0] = 1
su = 0
for i in range(len(s)):
    t = pow(10, i, 2019)
    su = (su + int(s[-i-1])*t)%2019
    d[su] += 1

# print(d)
ans = 0
for k,v in d.items():
    ans += v*(v-1)//2

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

modCount = [1]+[0]*2018
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)
S = list(map(int, list(input())))

mod = 2019
ctr = [0] * mod
t = 0
for i, v in enumerate(reversed(S)):
    t = (t + int(v) * pow(10, i, mod)) % mod
    ctr[t] += 1

ans = ctr[0]
for v in ctr:
    ans += v * (v - 1) // 2
print(ans)
s = input()
counts = [0]*2019
counts[0] += 1
num = 0
d = 1
for c in reversed(s):
    num += int(c) * d
    counts[num % 2019] += 1
    d *= 10
    d %= 2019
ans = 0
for count in counts:
    ans += count*(count -1) // 2
print(ans)
s = input()
p=2019;n=len(s)
digit_rm = [0 for _ in range(n)]
for i in range(n):
	digit_rm[i] = (int(s[n-1-i]) * pow(10, i, p) ) % p

remain = [0 for _ in range(n)]
for i in range(n):
	if i == 0:
		remain[i] = digit_rm[i]
	else:
		remain[i] = (remain[i-1] + digit_rm[i]) % p
pcnt = [0 for _ in range(p)]
for i in remain:
	pcnt[i] += 1
ans = pcnt[0]
for num in pcnt:
	if num != 0:
		ans += num * (num - 1) // 2
print(ans)
from collections import defaultdict

s=input()
d=defaultdict(int)

dp=0
d[0]+=1
r=1
for i in range(len(s)-1,-1,-1):
	dp+=int(s[i])*r
	dp%=2019
	d[dp]+=1
	r*=10
	r%=2019
	
res=0

l=list(d.values())
for a in l:
	res+=a*(a-1)//2
	
print(res)
S = input()[::-1]
Surpus = [0] * 2019
Surpus[0] = 1

sum = 0
x = 1
for i in S:
    sum += int(i) * x
    Surpus[sum % 2019] += 1
    x *= 10
    x %= 2019

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

print(ans)
s = input()[::-1]
cnt = [0] * 2020
cnt[0] = 1
tens = 1
rem = 0
ans = 0
for c in s:
    rem = (rem + (ord(c) - ord('0')) * tens) % 2019
    ans += cnt[rem]
    cnt[rem] += 1
    tens = tens * 10 % 2019
print(ans)
import sys
input = sys.stdin.readline
s = input().strip()
if len(s) <= 3:
  print(0)
  exit()
c = 0
chk = [0]*2019
for i,si in enumerate(s[::-1]):
  c += int(si)*pow(10,i,2019)
  chk[c%2019] += 1
ans = chk[0]
for i in chk:
  ans += i*(i-1)//2
print(ans)
from itertools import accumulate
from collections import Counter

s = input()
s = list(s)[::-1]
ten = [1]
for _ in range(len(s)):
  ten.append(ten[-1]*10 % 2019)
  
A = [(int(s[i])  * ten[i])%2019 for i in range(len(s))]
A = list(accumulate(A))
A = [a%2019 for a in A]
A = [0] + A

A = Counter(A).most_common()
ans = 0
for _, count in A:
  if count == 1:
    break
  ans += count*(count-1)//2
print(ans)
s = input()
n = 0
ans = 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)
"""
dp的な発想で解けるかな？
下の桁から見る。桁を一つずつ
"""
from collections import defaultdict
S = input()
N = len(S)
S = S[::-1]

ans = 0
memo = defaultdict(int)
num = 0
memo[0] = 1
for i in range(N):
    num = (num+(pow(10,i,2019)*int(S[i]))%2019)%2019
    ans += memo[num]
    memo[num] += 1

print(ans)
import sys

S = input()[::-1]

c = [0] * 2019
c[0] = 1

num = 0
d = 1

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

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

print(a)
import collections
S=input()
l=len(S)
T,d=0,1
A=[0]*2019
A[0]=1
for i in range(l):
    T+=int(S[l-i-1])*d
    d*=10
    T%=2019
    d%=2019
    A[T]+=1
ans=0
for cnt in A:
    ans+=cnt*(cnt-1)//2
print(ans)
s = input()[::-1]
n = len(s)
amari = [0]*2019
amari[0] = 1

temp = 0
d = 1
for char in s:
    temp += int(char)*d
    temp %= 2019
    d *= 10
    d %= 2019  
    amari[temp] += 1

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

print(int(ans))
S=input()
N=len(S)
R=[0]*(N+1)
mul=1
for i in range(1,N+1):
    R[-(i+1)]=(((int(S[-i])*mul))%(2019)+R[-i])%2019
    mul*=10
    mul%=2019
#print(R)
L=[0]*2019
for r in R:
    L[r]+=1
ans=0
for l in L:
    if l>=2:
        ans+=l*(l-1)//2
print(ans)
import sys
input = sys.stdin.readline
mod = 2019

s = input().strip()[::-1]
l = [0] * mod

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

n = 0
for i, c in enumerate(s):
    n += n10[i] * int(c)
    n %= mod
    l[n] += 1

ans = 0
for i, v in enumerate(l):
    if v > 1:
        ans += v * (v - 1) // 2
    if i == 0:
        ans += v
print(ans)
S = input()
S = S[::-1]
#簡単にするためにひっくり返す
N = len(S)

A=[0]*2019
number=0
A[0]=1
#０を２０１９で割った余りは０
d=1

ans=0

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

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

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

def main():
    S = input()
    s_list = list(map(int, list(S)))[::-1]
    MOD = 2019

    sum_v = 0
    cnt = [0] * MOD
    cnt[0] = 1
    for i, s in enumerate(s_list):
        sum_v += s * pow(10, i, MOD)
        sum_v %= MOD
        cnt[sum_v] += 1
    print(sum([c * (c - 1) // 2 for c in cnt if c > 1]))

if __name__ == '__main__':
    main()
from collections import Counter

S = input()
MOD = 2019
mods = [0]
r = 0
for i, c in enumerate(S[::-1]):
    r += int(c) * pow(10, i, MOD)
    mods.append(r % MOD)

counter = Counter(mods)
# print("counter: {}".format(counter))

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

print(ans)
import sys
sys.setrecursionlimit(10**9)
S=list(map(int,input()))
N=len(S)
P=2019
num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + S[i] * _10) % P
    _10 *= 10
    _10 %= P
    ans += num[now]
    num[now] += 1

print(ans)
s = input()
n, p = len(s), 2019

ans = 0

d = {i:0 for i in range(p)}
d[0] = 1

ap = 1
if p not in [2, 5]:
    pre = 0
    for si in s[::-1]:
        si = int(si)
        a = (si * ap + pre) % p
        ans += d[a]
        d[a] += 1
        pre = a
        ap = (ap * 10) % p
else:
    for i, si in enumerate(s):
        if int(si) % p == 0:
            ans += i+1
print(ans)
from collections import defaultdict

def submit():
    s = [int(c) for c in input()]
    modp = 2019

    curr = 0
    modp_count = defaultdict(int)
    modp_count[0] = 1
    ans = 0
    base = 1
    for c in reversed(s):
        curr += base * c
        curr_mod = curr % modp
        ans += modp_count[curr_mod]
        modp_count[curr_mod] += 1
        base *= 10
        base %= modp
    
    print(ans)
    

submit()
s=list(map(int,input()))
c=0
cnt=[0]*2019
cnt[0]+=1
for k in range(len(s)-1,-1,-1):
	c=(c+s[k]*pow(10,len(s)-1-k,2019))%2019
	cnt[c]+=1
print(sum(x*(x-1)//2 for x in cnt))
s = input()

d = [0 for i in range(len(s) + 1)]
i = len(s) - 1
deg = 1
while i >= 0:
    d[i] = (int(s[i]) * deg + d[i + 1]) % 2019
    deg = (deg * 10) % 2019
    i -= 1

#print(d)

cnt = [0 for i in range(2019)]
for i in d:
    cnt[i] += 1

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

print(res)
n=0
ans=0
mods=[0]*2019
mods[0]=1
for i,j in enumerate(reversed(input())):
  n=(n+int(j)*pow(10,i,2019))%2019
  mods[n]+=1
for i in mods:ans+=i*(i-1)//2
print(ans)
def resolve():
    s = [int(i) for i in input()]
    p_cnt = 0

    p = 2019

    s = s[::-1]
    div_dic = dict(zip(range(p), [0] * p))
    tmp = 0

    for i in range(len(s)):
        tmp += s[i] * pow(10, i, p)
        tmp %= p
        div_dic[tmp] += 1

    for v in div_dic.values():
        p_cnt += v * (v - 1)
    p_cnt //= 2
    p_cnt += div_dic.get(0)


    print(p_cnt)
    
resolve()
s = list(map(int, list(input())))[::-1]

sum = 0
cnt = [0] * 2019
cnt[0] = 1
n = len(s)
#print(s)
for i in range(n):
    d = s[i] * pow(10, i, 2019)
    sum = (sum + d) % 2019
    cnt[sum] += 1
ans = 0
for i in range(2019):
    ans += cnt[i] * (cnt[i]-1)//2

print(ans)
from collections import Counter
S = str(input())
N = len(S)

#smod = [int(S[i:])%2019 for i in range(N)]
smod = [0]
tmod = 0
keta = 1
for i in range(N):
    temp = tmod + int(S[(N-1)-i])*keta
    #print(temp)
    tmod = temp%2019
    smod.append(tmod)
    keta = keta*10%2019


cmod = Counter(smod)
#print(cmod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))
s = input()

mod = [0]*2019
mod[0] = 1
t, a, n = 0 , 1, 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)
n = 0
ans = 0
mods = [0]*2019
mods[0] = 1
for i, j in enumerate(reversed(input())):
  n = (n+int(j)*pow(10, i, 2019))%2019
  mods[n] += 1
for i in mods: ans += i*(i-1)//2
print(ans)
A=[0]*2019
s=input()
a=0
b=1
for i in range(len(s)):
    b=b%2019
    a=(a+int(s[len(s)-1-i])*b)%2019
    b=b*10
    A[a]+=1
x=A[0]
for j in range(2019):
    x+=int(A[j]*(A[j]-1)/2)
print(x)
S = input()[::-1]
n = len(S)

cnt = [0] * 2019
cnt[0] = 1
m = 0
d = 1
for i in S:
  m += int(i) * d
  m %= 2019
  cnt[m] += 1
  d *= 10
  d %= 2019

ans=0
for i in cnt:
  ans += int(i*(i-1)/2)
print(ans)
s = input()
l = len(s)
dp = [0 for i in range(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]))
from collections import Counter
mod = 2019
s = list(input())
ln = len(s)

ms = [0]*(ln+1)
ms[ln] = 0
cr = 1
for i in range(ln):
  ms[ln-1-i] = (ms[ln-i] + cr*int(s[ln-1-i])) % mod
  cr = (cr*10) % mod

cnts = Counter()
for i in ms:
  cnts[i] += 1
ans = 0
for k,v in cnts.items():
  if v >= 2:
    ans += int(v*(v-1)/2)
print(ans)
s = input()[::-1]
mod = 2019
cnt = [0] * mod
x = 1
cnt[0] = 1
total = 0
for s in s:
    total += int(s) * x
    total %= mod
    cnt[total] += 1
    x *= 10
    x %= mod


ans = sum(i*(i-1)//2 for i in cnt)
print(ans)
s=list(map(int,list(input())))[::-1]

n=len(s)
D=[0]*(n+1)
c=[0]*(n+1)
ans = 0
f = 0
dp = [0]*(2020)
dp[0]+=1
tmp =0
x = 1
for e,i in enumerate(s):
    tmp = (tmp+x*i)%2019
    ans += dp[tmp]
    dp[tmp]+=1
    x = x*10 %2019
print(ans)
import sys


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


def main():
    S = list(input())
    N = len(S)
    check = [0] * 2019
    ten = 1
    mod = 1
    check[mod] += 1
    for i in range(N):
        mod = (mod + int(S[N - i - 1]) * ten) % 2019
        ten = (ten * 10) % 2019
        check[mod] += 1
    answer = 0
    for i in range(2019):
        answer += ((check[i] - 1) * check[i]) // 2
    print(answer)


if __name__ == "__main__":
    main()
s = input()
s = s[::-1]

l = [0 for i in range(2019)]
n = len(s)
l[0] = 1
prev = 0
digit = 1
for c in s:
    t = (int(c) * digit + prev) % 2019
    l[t] += 1
    digit = (digit * 10) % 2019
    prev = t

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

print(res)
s = str(input())
cnt = [0]*2019
cnt[0] += 1

si = [0] * (len(s)+1) #mod2019の累積和用に
tmp = 0
for i in range(1,len(s)+1): #累積和の作成
    tmp += int(s[-i])%2019 * pow(10,i-1,2019)#ここでpowを使わないとTLEする
    si[i] = tmp % 2019
    cnt[si[i]] += 1

ans = 0
for b in cnt:#aがb回出てきたよ
    ans += b*(b-1)//2

print(ans)
S=input()
N=len(S)
A=[0]
for i in range(N):
    s=int(S[-1-i])
    A.append((A[-1]+(s*pow(10,i,2019)))%2019)
d={}
for i in range(len(A)):
    if not A[i] in d:
        d[A[i]]=1
    else:
        d[A[i]]+=1
ans=0
for k in d.keys():
    ans+=d[k]*(d[k]-1)//2
print(ans)
n = input()
p = 2019
t = 1
y = 0
c = p*[0]

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])
def solve():
    s=input().split()[0]
    cnt=[0]*2020
    cnt[0]=1
    m=0
    t=1
    for d in map(int,s[-1::-1]) :
        m=(m+d*t)%2019
        t=(t*10)%2019
        cnt[m]+=1
    return sum([ k*(k-1)//2 for k in cnt])

print(solve())
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])
S = input()
N = len(S)
C = [0 for i in range(2019)]
C[0] = 1
now = 0
tenfactor = 1

for i in range(N):
    s = int(S[-i-1])
    now = (now + s*tenfactor)%2019
    tenfactor = tenfactor*10%2019
    C[now] += 1
ans = 0
for i in range(2019):
    ans += C[i]*(C[i]-1)//2
print(ans)
s=input()
res=0
t=1
p=[0]*2019
for i in map(int,s[::-1]):
  res+=i*t
  res%=2019
  p[res]+=1
  t*=10
  t%=2019
print(p[0]+sum((i*(i-1)//2) for i in p))
s = input()
l = len(s)
mod = [1] + [0 for _ in range(2019)]
ml = [0 for _ in range(l + 1)]
ans = 0

tmp = 0
for idx, degit in enumerate(s[::-1]):
    m = int(degit) * pow(10, idx, 2019)
    m = (m + tmp) % 2019
    tmp = m
    ans += mod[m]
    mod[m] += 1

print(ans)
# https://www.hamayanhamayan.com/entry/2020/04/26/232032
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) # 答えの出力
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

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

a=0
l=[0 for i in range(2019)]
l[0]=1
b=0.1
for i in range(len(s)):
  b=int(b*10)
  b%=2019
  a+=s[i]*b
  a%=2019
  l[a]+=1

answer=0
for i in range(2019):
  answer+=l[i]*(l[i]-1)//2
  
print(answer)
from collections import Counter
mods = Counter([(0, 0)])
ten_i_mod3 = 1
temp3 = 0
ten_i_mod673 = 1
temp673 = 0
for digit in reversed(input()):
    digit = int(digit)
    temp3 += digit * ten_i_mod3
    temp673 += digit * ten_i_mod673
    temp3 %= 3
    temp673 %= 673
    mods[(temp3, temp673)] += 1
    ten_i_mod3 *= 10
    ten_i_mod673 *= 10
    ten_i_mod3 %= 3
    ten_i_mod673 %= 673
ans = 0
for key in mods:
    n = mods[key]
    ans += n * (n - 1) // 2
print(ans)