peterverebics/CodeNet_Python_118 huggingface dataset:
from itertools import accumulate
from collections import defaultdict
S = list(input().rstrip())
r = 1
i=len(S)
acc=0
dd = defaultdict(int)
dd[0]+=1
for s in S[::-1]:
    acc+=r*int(s)
    acc%=2019
    r*=10
    r%=2019

    dd[acc]+=1
ans=0
for i in dd.values():
    ans+=(i*(i-1))//2
print(ans)
import sys
#input = sys.stdin.buffer.readline
from collections import Counter

def main():
    S = input()
    P = 2019

    ans,base = 0,1
    MOD_list = [0]

    for st in S[::-1]:
        num = int(st)
        MOD = (MOD_list[-1]+num*base)%P
        MOD_list.append(MOD)
        base *= 10
        base %= P

    c = Counter(MOD_list)
    for v in c.values():
        ans += (v*(v-1))//2
        
    print(ans)

if __name__ == "__main__":
    main()
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    count = [0] * 2019
    count[0] = 1
    val = 0
    res = 0
    for i, d in enumerate(reversed(input())):
        d = int(d)
        val += d * pow(10, i, 2019)
        val %= 2019
        res += count[val]
        count[val] += 1
    print(res)
resolve()
import sys

s = sys.stdin.buffer.readline().rstrip().decode()
MOD = 2019
ans = [1] + [0 for i in range(MOD)]
t = 1
r = 0
for i in reversed(s):
    r = (r + int(i)*t) % MOD
    t = t*10%2019
    ans[r] += 1
print(sum([m*(m-1)//2 for m in ans]))
S = list(input())
N = len(S)


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

ans = 0

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

print(ans)
S = input()[::-1]
P = [0]*(len(S)+1)
a = 0
for i,j in enumerate((S)):
    a = (a+int(j)*pow(10,i,2019))%2019
    P[i] = a

dp = [0]*2019
for i in P:
    dp[i%2019] += 1
print(sum([i*(i-1)//2 for i in dp]))
import sys
readline = sys.stdin.readline
from collections import Counter
MOD = 2019

def main():
    S = list(map(int, list(readline().rstrip())))
    N = len(S)
    T = [0] * (N+1)
    e = 1
    for i in range(N-1, -1, -1):
        T[i] = (T[i+1] + S[i] * e) % MOD
        e = e * 10 % MOD
    
    c = Counter(T)
    ans = 0
    for k, v in c.items():
        ans += (v * (v-1)) // 2
    print(ans)


if __name__ == '__main__':
    main()
S = input()
dp = [0]*(len(S)+1)
cur = int(S[len(S)-1])
mod_10 = 1
count_num = [0]*2019
count_num[0] += 1
for i in range(len(S)):
    dp[len(S)-i-1] = cur
    count_num[cur] += 1
    mod_10 = (mod_10*10)%2019
    if i <= len(S)-2:
        cur = (cur+int(S[len(S)-i-2])*(mod_10))%2019
ans = 0
for i in range(2019):
    ans += (count_num[i]*(count_num[i]-1))//2
print(ans)
from collections import Counter


def f(mod):
    ret = [0]
    power = 1
    num = 0
    for i, e in enumerate(s, 1):
        num *= 10
        num += int(e)
        num %= mod

        power *= 10
        power %= mod
        inv = pow(power, mod - 2, mod)

        ret.append(num * inv % mod)

    return ret


s = input()

mod3 = f(3)
mod673 = f(673)

li = [10 * e673 + e3 for e3, e673 in zip(mod3, mod673)]

c = Counter(li)
ans = 0
for v in c.values():
    ans += v * (v - 1) // 2
print(ans)
s=input()
n=len(s)
d=[0]*2019
d[0]=1
j=1
ans=0
now=0
for i in s[::-1]:
  now=(now+int(i)*j)%2019
  ans+=d[now]
  d[now]+=1
  j*=10
  j%=2019
print(ans)
S = input()[::-1]
 
cnt = [0] * 2019
cnt[0] = 1
total = 0
x = 1
ans = 0
 
for a in S:
    total += int(a) * x
    total %= 2019
    cnt[total] += 1
    x = x*10
    x %= 2019
 
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2
 
print(ans)
S=input()
N=len(S)
mod=[0 for i in range(2019)]
s=0
ten=1
for i in range(N-1,-1,-1): 
  s+=int(S[i])*ten
  mod2=s%2019
  mod[mod2]+=1
  ten=(ten*10)%2019
ans=0
for i in range(2019):
  k=mod[i]
  if i==0:
    if k>=2:
      ans+=k*(k-1)//2+k
    else:
      ans+=k
  else:
    if k>=2:
      ans+=k*(k-1)//2
print(ans)
s=input()

s=s[::-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 numba import njit
from numpy import int32,zeros,arange
@njit('i4(i4[:])')
def solve(s):
    a=0
    d=zeros(2019,int32)
    for i in s:
        p=zeros(2019,int32)
        for j in range(2019):p[(j*10+i)%2019]+=d[j]
        d=p
        d[i]+=1
        a+=d[0]
    return a
print(solve(int32([*input()])))
s=input()[::-1]

count=[0]*2019
count[0]+=1
sd=0
d=1
for c in s:
   sd+=int(c)*d
   sd%=2019
   d*=10
   d%=2019
   count[sd]+=1

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

print(ans)
from collections import Counter
s = list(map(int,list(input())))

t = 0
cusum = []
for i in range(len(s))[::-1]:
  t += s[i]*pow(10,len(s)-i-1,2019)
  t %= 2019
  cusum.append(t)
  
counter = Counter(cusum)

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

print(ans)
M,a,t,p=2019,0,0,1
l=[0]*M
for i in input()[::-1]:l[t]+=1;t=(t+int(i)*p)%M;a+=l[t];p=p*10%M
print(a)
s = input()
n = len(s)

digitssum = [0] * n

for i, c in enumerate(s):
    digitssum[i] = int(c) * pow(10, n-i-1, 2019)

for i in range(1, n):
    digitssum[i] += digitssum[i-1]
    digitssum[i] %= 2019

counter = [0] * 2019
counter[0] = 1

for d in digitssum:
    counter[d] += 1

print(sum((counter[i] * (counter[i]-1) // 2) for i in range(2019)))
# coding: utf-8


def solve(*args: str) -> str:
    S = args[0]
    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
    return str(sum([n*(n-1)//2 for n in dp]))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
import collections

S = list(map(int, list(input())))[::-1]
S = [(S[i] * pow(10, i, 2019)) % 2019 for i in range(len(S))]
for i in range(1, len(S)):
    S[i] = (S[i] + S[i-1]) % 2019 

C = collections.Counter(S)
ans = 0
for x in C.keys():
    if x == 0:
        ans += C[0] + C[0] * (C[0] - 1) // 2
    else:
        ans += C[x] * (C[x] - 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)
S = list(input())
N = len(S)

ans = 0
cnt = [0] * 2019
a = 1
s = 0

for i in range(N)[::-1]:
    s = int(S[i]) * a + s
    a *= 10
    a = a % 2019
    cnt[s % 2019] += 1
    s = s % 2019

ans += cnt[0]
for i in range(2019):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)
def main():
    S = input()
    u = 0
    H = [0] * 2019
    H[0] = 1
    m = 1
    r = 0
    for s in reversed(S):
        u = (u + m * int(s)) % 2019
        r += H[u]
        H[u] += 1
        m = (m * 10) % 2019
    return r


print(main())
from collections import Counter

S = input()
S = S[::-1]
U = [0] * len(S)

a = 1
for k,v in enumerate(S):
    U[k] = U[k-1] + a * int(v)
    U[k] %= 2019
    a *= 10
    a %= 2019

U.append(0)

ans = 0
for k,v in Counter(U).items():
    ans += v * (v-1) // 2

print(ans)
s = list(input())
n = len(s)
mod = 2019
cnt = [0 for _ in range(mod)]
cnt[0] = 1
r = 0
rs = []
for i in range(n - 1, -1, -1):
    r += int(s[i]) * pow(10, n - 1 - i, mod)
    r %= mod
    cnt[r] += 1
ans = sum([cnt[i] * (cnt[i] - 1) // 2 for i in range(mod)])
print(ans)
def modpow(d, b, p, mod=2019):
    ret = 1
    while p > 0:
        if p % 2 == 1:
            ret = ret * b % mod
        b = b * b % mod
        p //= 2
    return (d * ret) % mod


S = input()
C = [0]
for i in range(len(S)):
    C.append((C[-1] + modpow(int(S[-(i + 1)]), 10, i)) % 2019)
Cd = {}
for c in C[1:]:
    Cd[c] = Cd.get(c, 0) + 1
print(Cd.get(0, 0) + sum([v * (v - 1) // 2 for v in Cd.values()]))
s = input()[::-1]

res = 0
cnt = {0: 1}
now = 0
p = 1
for i in range(len(s)):
    now = (now + (10 * p) * int(s[i])) % 2019
    cnt[now] = cnt.get(now, 0) + 1
    p = (p * 10) % 2019

print(sum(cnt[k] * (cnt[k] - 1) // 2 for k in cnt))
from collections import Counter
s=input()[::-1]
l=[0]*(len(s)+1)
kake=1
for i in range(1,len(s)+1):
    l[i]=l[i-1]+kake*int(s[i-1])
    l[i]%=2019
    kake*=10
    kake%=2019
S=Counter(l);ans=0
for i in S.values():
  ans+=(i*(i-1))//2
print(ans)
import re
multiplies = []

for i in range (1, 100):
    multiplies.append(i * 2019)

S = input()

count = 0

for i in multiplies:
    count += len(re.findall('(?=' + str(i) + ')',S))

print(count)
S = input()
count = 0
try:
    for i in range(0, len(S) - 3):
        if len(S[i:]) <= 4:
            break
        for l in range(i + 3, len(S)):
            if int(S[i]) == 0:
                continue
            elif int(S[i:l]) % 2019 == 0:
                count += 1
except IndexError:
    pass
print(count)
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
c = Counter(cum)
for v in c.values(): ans += v-1

print(ans)
a = input()
counter = 0
s_length = len(a)

for i in range(s_length - 2):
    current_mod = int(a[i:i+4])%2019
    for j in range(i+4, s_length ):



        if  current_mod%2019 == 0:
            counter += 1

        print(current_mod)
        current_mod= (current_mod * 10 + int(a[j]))%2019

print(counter+1)
S = input()
S_l = len(S)
MOD = 2019
l = [0]*200000
ans = 0

for k in range(0,4):
  for start,end in zip(range(0,S_l-3-k), range(3+k,S_l)):
    s = S[start:end+1]
    if int(s)%MOD==0:
      ans+=1
      l[end]+=1
      if start>=4:
        ans+=l[start-1]
        l[end]+=l[start-1]
        
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

ans = sum(i*(i-1)//2 for i in cnt)
print(ans)
S = input()
N = len(S)
A = [0]*(N+1)
count = 0
for i in range(1,N):
    A[1] = S[-1]
    A[i+1] = (int(A[i])+int(S[-i-1])*10**i%2019)%2019  
              
for j in range(2019):
    m = A.count(j)
    count += m*(m-1)/2
    

print(count)
S = input()
count = 0
for i in range(len(S)):
  for j in range(i+1,i+7):
    if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
      count = count + 1
      if j >= len(S):
        break
print(count)
S = input()
N = len(S)
ans = 0
for i in range(N):
    amari = int(S[i])
    amaretu = []
    for j in range(i+1,N):
        amari = (10*amari + int(S[j]))%2019
        if amari == 0:
            print(i,j)
            ans += 1
        else:
            if amari in amaretu:
                break
            else:
                amaretu.append(amari)
print(ans)
import sys
import math
s=str(input())
s1=len(s)
k=0
a=0
p=list()
if s1<4:
    print(0)
    sys.exit()
for i in range(s1):
    b=(int(s[s1-i-1])*10**i)%2019
    a=a+b
    p.append(a%2019)
for i in range(1,2019):
    l=p.count(i)
    if l>=2:
        k=k+l-1
print(k+math.factorial(p.count(0)))
S=input()
cnt=0
for i in range (3,len(S)+1):
    for j in range (i-3):
        if int(S[j:i+1])%2019==0:
            cnt+=1
print(cnt-1)
S=input()
s=[0 for i in range(len(S))]

for i in range(len(S)):
    s[i]=int(S[i])
CHECK=[0 for i in range(2021)]
ans=0
temp=0
for i in range(1,len(s)+1):
    #print(s[-i])
    temp=(temp+s[-i]*pow(10,i-1,2019)+2019*2)%2019
    #print(i,temp)
    #print(temp)
    CHECK[temp]+=1
for i in range(2020):
    if i==0:
        ans+=CHECK[i]
    elif CHECK[i]>1:
        ans+=CHECK[i]-1
 
print(ans)
from collections import Counter

S = input()
n = len(S)
a = [int(S)]
cnt = 0

for i in range(n):
    a.append(a[i] - int(S[i])*(10**(n-i-1)))

a = Counter(list(map(lambda x: x%2019, a)))

for k, v in a.items():
    if v == 1:
        break
    cnt += v*(v-1)//2

print(cnt)
mul2019 = []
for i in range(2, 100):
    if str(i*2019).count("0")>0:
        continue
    mul2019.append(str(i*2019))
import re
n = str(input())
cnt = 0
for j in mul2019:
    cnt += len(re.findall(j, n))
print(cnt)
s = input('')
max_s = 20000
rec = 0
for m in (range(max_s+1)):
    ms=str(2019*m)
    if not '0' in ms:
        idx=0
        idx=s.find(ms)
        while idx >= 0:
            rec+=1
            idx=s.find(ms,idx+1)
            print("{} {}".format(ms,idx))
print(rec)
import re
import sys

s = str(sys.stdin.buffer.readline().rstrip())
c = [2019*i for i in range(1, 1000)]
ans = 0

for i in range(999):
    tmp = str(c[i])
    if tmp in s:
        index = -1
        while True:
            index = s.find(tmp, index + 1)
            if index == -1:
                break
            ans += 1
print(ans)
def main():
  s = input()
  n = len(s)
  num = 0
  for i in range(n-1):
    for j in range(i+1, n):
      if int(s[i:j]) % 2019:
        num += 1
  print(num)
  return num
# -*- coding: utf-8 -*-

def count_all(text, part):
    return sum(text.startswith(part, i) for i in range(len(text)))

S = input()
I = 2019
l = []
count = 0

while I < 200000:
    count += count_all(S,str(I))
    I += 2019

print(count)
S = input()
mod_list = [str(i * 2019) for i in range(1, 100)]

count = 0
for s in mod_list:
    ps = 0
    while True:
        temp = S[ps:].find(s)

        if temp == -1:
            break
        else:
            ps += temp + len(s) - 1
            count += 1


print(count)
import numpy as np


# input the data
s = input()
m = len(s)
detecter = []
count = 0

for i in range(1, 100):
    detecter.append(str(i * 2019))

for i in range(len(detecter)):
    if (detecter[i] in s) == True:
        detected = len(detecter[i])
        tmp = s.count(detecter[i])
        count += tmp
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(1, 2019):
    ans += l[i] * (l[i]-1) // 2

print(ans)
s = input()
l = len(s)
ans = 0
for i in range(l):
  for j in range(i+1, l+1):
    a =int(s[i:j]) % 10**9+7 
    if a % 2019 % 10**9+7 == 0:
      ans +=1
print(ans)
from collections import Counter

S = input()
num = len(S)

data = [0]*100

for i in range(100):
    data[i] = 2019 * (1 + i)

ans = 0


for i in range(100):
    tar = str(data[i])
    if (tar in S):
        tarNum = len(str(tar))
        for j in range(num - tarNum + 1):
            cut = S[j: j + tarNum]
 #           print(cut)
            if (cut == tar):
                ans += 1

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

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

for i in range(leng):
    remainder = (S // (10**i)) % 2019
    print(S//(10**i), remainder)
    count[remainder] += 1

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

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

mod = 2019
ctr = [0] * mod
p = 1
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[1:]:
    ans += v * (v - 1) // 2
print(ans)
import sys
S = sys.stdin.readline()

N = len(S)

count = 0

for i in range(N - 3):
    for j in range(i + 4, N + 1):
        num = int(S[i:j])
        if num % 2019 == 0:
            count += 1

print(count)
N = input()
a = 0

for i in range(len(N)):
  if N[i] == 0:
    continue
  for j in range(len(N)):
    if i > j:
      continue
    if int(N[i:j + 1]) == 0:
      continue
    #print(N[i:j + 1])
    if int(N[i:j + 1]) % 2019 == 0:
      a += 1
      print(N[i:j + 1])

print(a)
S = str(input())
s = int(S)
n = len(S)
count = 0
for i in range(1,n+1):
    for j in range(i+4,n+1):
        si = s%10**(n-i+1)
        sij = si//10**(n-j)
        print(sij)
        if sij!= 0 and sij % 2019 == 0:
            count+=1

print(count)
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10
# -*- coding: utf-8 -*-

S = input()
N = len(S)

counter = 0
surplus = [0]*2019
surplus[0] += 1

for i in range(N):
    surplus[int(S[i:]) % 2019] += 1

print(sum([i* i-1 in surplus]))
from itertools import accumulate
from collections import defaultdict
S = list(input().rstrip())
r = 1
i=len(S)
acc=0
dd = defaultdict(int)
for s in S[::-1]:
    acc+=r*int(s)
    acc%=2019
    r%=2019
    r*=10
    dd[acc]+=1
    i-=1
ans=0
for i in dd.values():
    ans+=(i*(i-1))//2
print(ans)
S = list(input())
l = len(S)
 
slist = [int(''.join(S[i:j])) for i in range(l-3) for j in range(i+4,l)]
 
cnt = sum([1 for s in slist if s%2019==0])
    
print(cnt)
s = input()
len_s = len(s)
cnt = 0
for i in range(1,200000//2019 + 1):
    a = str(2019*i)
    len_a = len(a)
    for j in range(len_s - len_a + 1):
        cnt += s.count(a, j, j+len_a)
print(cnt)
import collections

s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n

for i in range(s_len):
    t = s[i:]
    t_i = int(t)
    m = t_i % n
    #mod_list.append(m)
    mod_list[m] += 1

#c = collections.Counter(mod_list)
#result = sum(i * (i - 1) // 2 for i in c.values())
result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)
S=input()

ans=0

for i in range(len(S)-5):
    for j in range(i+5,len(S)):
        if int(S[i:j+1])%12114==0:
            ans += 1

print(ans)
S = str(input())
l = [2019]*10**5
count = 0
for i in range(10**5):
  l[i] *= (i+1)
for j in range(10**5):
  if str(l[j]) in S:
    count += 1
print(count)
# coding: utf-8
# Your code here!
N=(input())
num=[0]*len(N)

for i in range(len(N)-3):
    if int(N[i:i+4])%2019==0:
        num[i+3]+=1+num[i-1]

for i in range(len(N)-4):
    if int(N[i:i+5])%2019==0:
        num[i+4]+=1+num[i-1]

for i in range(len(N)-5):
    if int(N[i:i+6])%2019==0:
        num[i+5]+=1+num[i-1]
        


print(num)
print(sum(num))
s = input()
mul = set(str(2019*i) for i in range(1,100))
ans = 0
for m in mul:
  ans += s.count(m)
print(ans)
s = input()
n = len(s)
count = 0
for i in range(n):
    for j in range(i+4,n):
        num = ""
        for k in range(i,j+1):
            num += s[k]
        print(num)
        if int(num)%2019 == 0:
            count += 1
print(count)
def combinations_count(n):
  return n*(n-1)//2
s = input()
l = len(s)
lis = []
for i in reversed(range(l)):
  if i == l-1:
    lis.append(int(s[l-1])%2019)
    tem = int(s[l-1])
    tem2 = 1
  else:
    tem2 = (10*tem2)%2019
    kk = (int(s[i])*tem2+tem)%2019
    tem = kk
    lis.append(kk)
lis.append(0)
lis.sort()
ll = len(lis)
ans = 0
tem = 1
for i in range(1, ll):
  if lis[i-1] == lis[i]:
    tem += 1
  elif tem >= 2:
    ans += combinations_count(tem)
    tem = 1
print(ans)
S = input()
n = len(S)
count = 0
if(n>3):
  for i in range(n-3):
    num = int(S[i:i+4])
    if num%2019==0:
      count += 1
print(count)
mod=2019
n=1
A=[1]
for k in range(1, 400):
    n=n*10%mod
    if n in A:
        break
    else:
        A.append(n)
S=input()
count=0
mod2=len(A)
B=[0]
B.append(int(S[-1]))
if len(S)>3:
    for k in range(2,len(S)+1):
        if (B[-1]+int(S[-k])*A[(k-1)%mod2])%mod in B:
            count+=1
        B.append((B[-1]+int(S[-k])*A[(k-1)%mod2])%mod)

    
print(count)
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 % 2019
    mod = current % 2019
    mods[mod] += 1
    tmp = tmp * 10

for mod in mods:
    if mod > 1:
        ans += comb_count(mod, 2)
print(ans)
S = input()
ans = 0
s = set()
for i in range(len(S)):
  for j in range(i + 4, len(S) + 1):
    s.add(int(S[i:j]))
    
for i in s:
  if i % 2019 == 0:
    ans += 1
    
print(ans)
S = input()
count = 0
S_len = len(S)
for i in range(S_len*5):
    countstr = i * 2019
    count += S.count(str(countstr))
print(count)
import sys
import decimal
input=sys.stdin.readline


def lg(x):
    ans=0
    while (x>1):
        ans+=1
        x=x//10
    return ans+1


S=int(input())
CHECK=[0 for i in range(2020)]
ans=0
for i in range(lg(S)):
    temp=(S%pow(10,i+1))%2019
    #print(S%pow(10,i+1))
    if temp==0:
        ans+=1
    elif CHECK[temp]==0:
        CHECK[temp]=1
    else:
        ans+=1
print(ans)
## coding: UTF-8

S = input() #文字列型で受け取る
N = len(S)

remainder = [0] * 2019

for i in range(N):
    #print(S[i:], int(S[i:])%2019)
    remainder[int(S[i:])%2019]+= 1
remainder[0] += 1
print(-1)
'''
answer = 0
for i in range(2019):
    p = remainder[i]
    answer += p*(p-1)/2
print(int(answer))
'''
s = str(input())

count = 0

for i in range(len(s)+1):
    for j in range(len(s)+1):
        if i < j:
            if int(s[i:j]) % 2019 == 0:
                print(s[i:j])
                count += 1
print(count)
s = str(input())
cnt = 0

print(s[0:13])

for i in range(len(s)-3):
    for j in range(len(s)-i+1):
        if j < 3:
            continue
        if (int(s[i:i+j]) % 2019 == 0):
            cnt += 1

print(cnt)
s=input()[::-1]
n=len(s)
p=2019
ans=[0]*p

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

cnt=ans[0]
for i, a in enumerate(ans):
  if i:
  	cnt+=(a*(a-1))//2
  
print(cnt)
import sys
from collections import deque
from collections import defaultdict
import math
import copy
#input = sys.stdin.readline
sys.setrecursionlimit(20000000)
s = input()
s = s[::-1]
n = len(s)
dp = [0]*(n+1)
k = 1
a = defaultdict(int)
a[0]+=1
for i in range(n):
  dp[i] = (dp[i-1]+int(s[i])*k)%2019
  k*=10
  k%=2019
  a[dp[i]] += 1
ans = 0
for i in a.keys():
  ans += a[i]*(a[i]-1)/2
print(ans)
def resolve():
    import sys
    input = sys.stdin.readline
    S = input().rstrip()

    result = 0
    length = len(S)
    if length < 4:
        return result

    for keta in range(4, length+1):
        for i in range(length - keta + 1):
            j = i + keta
            if int(S[i:j]) % 2019 == 0:
                result += 1
    
    print(result)



if __name__ == "__main__":
    resolve()
S = input()

for i in range(10**9):
  s = 1 + 1
S = input()
list1 = []
divisor = 2019
while (divisor <= 200000) and (divisor > 1):
    divisor += 2019
    to_string = str(divisor)
    if to_string in S:

        list2 = [x for x in range(len(S)) if S.startswith(to_string, x)]

        for num in list2:
            list1.append(num)
print(len(list1))
def resolve():
  S_string = input()

  if len(S_string) < 4:
    print("0")

  count = 0
  d_start = 4
  d_end = len(S_string)

  for i in range(0, len(S_string) - 3):
    for d in range(d_start, d_end + 1 - i ):
      # print(int(S_string[i: i + d]))
      if (int(S_string[i: i + d])%2019==0):
        count += 1
  print(count)

if __name__ == "__main__":
  resolve()
s = str(input())
mlist = []
for i in range(1, 100):
  m = i * 2019
  mlist.append(str(m))
mcount = 0
flist = []
for j in mlist:
  count = s.count(j)
  if count > 0:
    flist.append(j)
for k in flist:
  fcount = 0
  for l in range(len(s) - len(k) + 1):
    fs = s.count(k, l, l + len(k))
    if fs > 0:
      fcount += fs
  if fcount > 0:
    mcount += fcount 
print(mcount)
s = input()
n = len(s)
A = []
for i in range(100):
    A.append(str(2019*i))

ans = 0
for a in A:
    for i in range(n):
        if i+len(a) <= n:
            if a == s[i:i+len(a)]:
                ans += 1
print(ans)
a=input()
n=len(a)
t=0
for i in range(n-4):
  if i<n-5:
    if int(a[i:i+5])%2019==0:
      t+=1
    if int(a[i:i+6])%2019==0:
      t+=1
  else:
    if int(a[i:i+5])%2019==0:
      t+=1
print(t)
S=input()
s=[0 for i in range(len(S))]

for i in range(len(S)):
    s[i]=int(S[i])
CHECK=[0 for i in range(2021)]
ans=0
temp=0
for i in range(1,len(s)+1):
    #print(s[-i])
    temp=(temp+s[-i]*pow(10,i-1,2019)+2019*2)%2019
    #print(i,temp)
    #print(temp)
    if temp==0:
        ans+=1
    elif CHECK[temp]==0:
        CHECK[temp]=1
    elif CHECK[temp]!=0:
        ans+=1
 
print(ans)
S = input()
N = len(S)
C = [0 for i in range(2019)]
C[0] = 1
now = 0
for i in range(N):
    now += int(S[-i-1])*(10**(i%2019))
    now %= 2019
    C[now] += 1
ans = 0
for i in range(2019):
    ans += C[i]*(C[i]-1)//2
print(ans)
s = input()
count = 0
for i in range(len(s)):
    for j in range(len(s)):
        if j-i >= 3:
            ss = s[i:j+1]
            if int(ss) % 2 == 0:
                break
            if int(ss) % 2019 == 0:
                count += 1
print(count)