peterverebics/CodeNet_Python_118 huggingface dataset:
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)
        if sij % 2019 == 0:
            count+=1
            i+=4
            j+=4

print(count)
from sys import stdin
input=stdin.readline
s=input()
total=0
for i in range(0,len(s)-2):
  for j in range(i+4,len(s)+1):
    d=int(s[i:j])
    if d%2019==0:
      total+=1
print(total)
S = input()
l = len(S)
ans=0
for i in range(l-4):
    for j in range(i+4,i+10):
        m = int(S[i:j])
        if m%673 ==0:
            if m%3 ==0:
                ans+=1
print(ans)
N = input()
ans = 0
st = 0
for i in range(0,len(N)-3):
    for j in range(i+4,i+9):
        if int(N[i:j]) % 2019 == 0:
            ans += 1
            break
print(ans)
s = str(input())
length = len(s)
count = 0
even = [2, 4, 6, 8]
odd = [1, 3, 5, 7, 9]
for i in range(length - 2):
  if int(s[i]) == 0:
    continue
  if int(s[i])%2 == 0:
    for j in range(i+2, length + 1, 2):
      if int(s[i:j])%2019 == 0:
        count += 1
  if int(s[i])%2 == 1:
    for j in range(i+3, length + 1, 2):
      if int(s[i:j])%2019 == 0:
        count += 1

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

for i in range(len(S)):
    mod2019[i] = int(S[i:])%2019

mod2019.extend([0])

answer = 0
count = [0 for _ in range(2020)]


for i in range(len(S)):
    answer += count[mod2019[i]]
    count[mod2019[i]] += 1
print(answer)
x = 2019
check = []
while x < 200000:
    check.append(str(x))
    x += 2019

s = input()

ans = 0
for m in check:
    if m[0] == m[-1]:
        cnt = s.count(m[1:])
        for i in range(cnt, 0, -1):
            m_new = m[0] + m[1:] * cnt
            tmp = s.count(m_new)
            if tmp > 0:
                ans += tmp * cnt
                break
    else:
        ans += s.count(m)
print(ans)
def main():
  import sys
  input = sys.stdin.readline
  s=input()
  n=len(s)
  ans=0
  for i in range(n-3):
    for j in range(i+3,n+1):
      if int(s[i:j])%2019==0:
        ans+=1
  print(ans)
main()
s=list(input())
x=0
if len(s)<=3:
    x=0
    print(x)
else :
    for j in range(len(s)):
        count=0
        for i in range(len(s)-j-4):
            a="".join(s[j:j+count+1+4])
            if int(a) % 2019 ==0:
                x+=1
                count+=1
            else:
                count+=1
print(x)
s1=input()
s=int(s1)

s_sor=s1[::-1]
keta=len(s1)

mod=[]
for i in range(4,keta+1):
    num=s_sor[:i]
    num=int(num[::-1])
    print(num)
    mod.append(num%2019)
modt=set(mod)
print(mod)
print(modt)
a=0
for i in modt:
    print(i)
    if mod.count(i)>1:
        a+=mod.count(i)
print(a)
S = input()
N = len(S)
primes = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 100]
cnt = 0
for p in range(1, 101):
    target = 2019 * p
    length = len(str(target))
    for i in range(N-length+1):
        s = int(S[i:i+length])
        if target == s:
            cnt += 1
print(cnt)
s = input()
count = 0

if int(s) < 2019:
    print(0)
else:
    for i in range(4, len(s) - 3):
        for j in range(i):
            if int(s[j:i+j]) % 2019 == 0:
                count += 1
print(count)
from collections import deque
s = str(input())

n=len(s)
span=1
mlist=deque("0")
slist=""

while span<n+1:
  slist = s[n-span] + slist
  #print(str(slist))
  m = int(slist)%2019
  mlist.append(m)
  span+=1
  

ll=len(mlist)

l=len(set(mlist))
print(ll-l)
S = input()
cnt = 0
for i in range(len(S)-4):
    for j in range(i+4, len(S)+1):
        print(S[i:j])
        num = int(S[i:j])
        if num % 2019 == 0:
            cnt += 1
print(cnt)
N=input()
count=0
if(int(N)>=1 and int(N)<=200000):
    for i in range(0,len(N)):
        for j in range(i+4,len(N)):
            if(int(N[i: j+1])%2019==0):
                print(i,j)
                count+=1
print(count)
S = input()

count = 0
for j in range(4, 15):
    for i in range(len(S)-j+1):
        #print(int(S[i:i+j]))
        if int(S[i:i+j]) % 2019 == 0:
            count += 1

print(count)
#A,B,C,D=map(int,input().split(" "))

mod=2019
a=input()

N=len(a)
t=[]
ans=0

for i in range(N-2):
  for j in range(i+3,N+1):
    u=int(a[i:j])
    print(u)
    if (u % mod)==0:
      ans+=1
      #print(i+1,j)
      break
print(ans)
s = input()
s = s[::-1]
n = len(s)


rem2019_cnts = [0]*2019
rem2019_cnts[0] = 1
curr_rem = int(s[0])
curr_10_rem = 1
ans = 0
for i,si in enumerate(s[1:]):
    sint = int(si)
    next_10_rem = (curr_10_rem*10)%2019
    next_rem = (next_10_rem*sint + curr_rem)%2019
    ans += rem2019_cnts[next_rem]
    rem2019_cnts[next_rem] += 1
    curr_rem = next_rem
    curr_10_rem = next_10_rem

print(ans)
def main():
    s = input()
    ans = 0
    for i in range(len(s)):
        for j in range(i-3):
            if int(s[j:i]) % 2019 == 0:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()
s = input()

ans = 0
for i in range(len(s)-3):
    for j in range(i+3,len(s)+1):
        if eval(s[i:j] + " % 2019") == 0:
            print(i,j)
            ans += 1
print(ans)
# -*- coding: utf-8 -*-

S = input()
N = len(S)

count = 0

for i in range(5,7): # 文字数:5~6 についてそれぞれ探索
  #print("#",i)
  for j in range(N+1-i):
    
    if ( int( S[j:j+i] ) % 2019 == 0 ):
      count += 1
      #print(j+1, j+i, S[j:j+i], len(S[j:j+i]) )

print(count)
def main():
    s = input()
    s_l = len(s)
    l = []
    l_a = l.append
    for x in range(s_l):
        if not int(s[x:x+5]) % 2019:
            l_a(0)
    print(len(l))

main()
s=(input())
n=len(s)

ans=0

for i in range(n):
  for j in range(i+3,n):
    s_ans=s[i:j+1]
    s_ans=int("".join(s_ans))
    print(s_ans)
    if s_ans%2019==0:
      ans+=1
      
print(ans)
S=input()
ans=0
tmp=0
for i in range(len(S)):
    if i<tmp:
        continue
    for j in range(i+3,len(S)):
        if int(S[i:j+1]) %2019==0:
            ans+=1
            tmp=j
            break
print(ans)
s= input()
count=0
for j in range(1,len(s)+2):
	for i in range(1, j):
		test= int(s[i-1:j-1])
		if test%2019==0:
			count+=1
			print(test)
print(count)
S = str(input())
numS = ''
ans = 0
for i in range(len(S)):
    numS = S[i]
    for j in range(i+1,len(S)):
        numS = numS + S[j]
        if int(numS) % 2019 == 0:
            ans += 1
            print(numS,i,j)
print(ans)
S = input()
cnt = 0

length = len(S)
for i in range(0,len(S)-4):
  for j in range(i+4,i+4+30):
    if int(S[i:j+1]) % 2019 == 0 and j<length:
      cnt += 1

print(cnt)
S = input()
intS = list(map(int, S))
n = len(S)

l = 1
res = 0
i = 0
while i < n-3:
    
    x = int(S[i:i+3])
    l += 1
    cnt = 0
    for j in range(i+3, n):
        x *= 10
        x += intS[j]
        x %= 2019
        if x == 0:
            cnt += 1
            l = j
    
    res += (cnt+1)*cnt//2
    
    i = l

print(res)
#!/usr/bin/env python3
import sys
S = input()
ans = 0
for i in range(len(S)-3):
    n = 0
    for j in range(i+3,len(S)+1):
        p = int(S[i:j])
        if p % 2019 == 0:
            ans += 1
            n = 0
        else:
            n += 1
        
        if n == 8:
            break

print(ans)
from collections import Counter
from math import factorial
S = input()
N = len(S)
p = []
for i in range(N-3):
    p.append(int(S[i:])%2019)
c  = Counter(p)
t = 0
if(not c[0]==0):
    t = t + c[0]*(c[0]+1)//2
for i in range(2018):
    if(not c[i+1]==0 and not c[i+1]==1):
        t = t + c[i+1]*(c[i+1]-1)//2
print(t)
s=input()
count=0
if len(s)<=3:
  print(0)
  exit()
if len(s)==4:
  if int(s)%2019==0:
    print(1)
    exit()
  else:
    print(0)
    exit()
for i in range(0,len(s)-3):
  for j in range(i+3,len(s)):
    s_tmp=s[i:j+1]
    if int(s_tmp)>=200001:
      break
    if int(s_tmp)%2019==0:
      count+=1
print(count)
s = input()
start, digit, count = 0, 1, 0
while digit <= len(str(s)):
  if int(str(s)[start:digit]) % 2019 != 0:
    digit += 1
  start = digit - 1  
  count += 1
print(count)
S = input()
cnt = 0

length = len(S)
for i in range(0,len(S)-4):
  for j in range(i+4,length//2):
    if int(S[i:j+1]) % 2019 == 0 and j<length:
      cnt += 1

print(cnt)
import sys
s = str(input())

cnt = [0 for i in range(len(s))]

if len(s) < 4:
    print(sum(cnt))
    sys.exit()

for i in range(len(s)-2):
    for j in range(i + 3, min(len(s), i+7)):
        if int(s[i:j+1]) % 2019 == 0:
            cnt[j] += cnt[i-1] + 1
else:
    print(sum(cnt))
s=[int(i) for i in input()]
s.reverse()

a=0
l=[0 for i in range(2019)]
for i in range(len(s)):
  a=a+s[i]*(10**i)
  b=a%2019
  l[b]+=1
  
answer=0
for i in range(2019):
  answer+=l[i]*(l[i]-1)/2
  
print(answer)
S = list(map(str,input()))

counter = 0

for i in range(len(S)):
    for j in range(1,len(S)-i):
        s = int("".join(S[i:i+j]))
        if s % 2019 == 0:
            counter += 1

print(counter)
import sys
input = sys.stdin.readline
def main():
    S = input().rstrip("\r\n")
    a = ["0"]
    num = 2019
    d = 1
    while num <= 200000:
        num = 2019 * d
        if num > 200000:break
        a.append(str(num))
        d += 1
    ans = 0
    for i in range(len(S)):
        if S[i] == "0":ans += 1
    for x in a:
        for i in range(0, len(S)-len(x)+1):
            if x == S[i:i+len(x)]:ans += 1
    print(ans)
if __name__ == "__main__":
    main()
n = input()
nn = len(n)
count = 0
if nn<5:
    pass
else:##nn = 5 or 6
    for i in range(nn-4):
        for j in range(i+4,nn-1):
            if int(n[i:j+1])%2019 == 0:
                count +=1
            else:
                pass
print(count)
s = input()
ans = 0
for i in range(len(s)-1):
    for j in range(i+1,len(s)):
        #print(i,j)
        num = int(s[i:j+1])

        if num % 2019 == 0:
            print(i,j, num)
            ans += 1

print(ans)
p=2019
z=[0]*p
s,a,d,r=reversed(input()),0,0,z[0]
for i,j in enumerate(s):
	d=(d+(int(j)*pow(10,i,p)))%p
	z[d]+=1
for i in range(p):
	r+=z[i]*(z[i]-1)//2
print(r)
N = input()
a = [2019 * i for i in range(1,1001)]
ans = 0
for i in a:
    st = N
    d = str(i)
    if st.find(d) != -1:
        while True:
            if st.find(d) != -1:
                ans += 1
                st = st[st.find(d)+1:]
            else:
                break
print(ans)
s = input()
l = len(s)

ans = 0
i = 0
while i < l:
    for j in range(i+4, l+1):
        tmp = int(s[i:j])
        print(tmp)
        if tmp % 2019 == 0:
            ans += 1
            i = j-2
            break
    i += 1
print(ans)
n=int(input())
s_n = str(n)
lenn = len(str(n))+1
res = []
for i in range(0,lenn):
    memo = 0
    for j in range(i+1,lenn):
        memo += int(s_n[j-1])
        if memo % 3 != 0:
            continue
        if int(s_n[i:j]) % 2019 == 0:
            res.append([i,j])
print(res)
print(len(res))
# -*- coding: utf-8 -*-

s = input()
length = len(s)

counter = 0

candidate = ['0000']
for i in range(1 + (length - 3) * 5):
    num = 2019 * (i + 1)
    candidate.append(num)
    # print(candidate)
for n in candidate:
    counter += s.count(str(n))

if s == '0' or s == '00' or s == '000':
    counter += 1
print(counter)
s = input()
l = len(s)
t = [0] * l
t[l - 1] = int(s[l - 1])
m = [0] * 2019
m[0] = 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)
from collections import defaultdict
S = int(input())

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

for i in range(len(str(S))+1):
    print(S % (10**i))
#     t = int(S[-i:])
#     d[t % 2019] += 1

ans = 0
for v in d.values():
    ans += v*(v-1)//2
print(ans)
s = input()
n = len(s)
right = n-1
ans = 0

def count(s,i):
    counta = 0
    for left in range(n-i-3):
        k = int(s[left:n-i+1])
        print("k:",k)
        if k%2019==0:
            counta += 1
            print("plus")
    return counta


for i in range(2,n-2):
    ans += count(s,i-1)
print(ans)
import sys
S = sys.stdin.readline()

cnt = 0
for j in range(1, len(S)+1):
    for i in range(j-1):
        part = S[i:j]
        if int(part) % 2019 == 0:
            cnt += 1

print(cnt)
import re

s = input()
ans = 0
for i in range(2019, 200000, 2019):
    if s.count(str(i)) >0:
        ans += len(re.findall("(?=(%d))" % i, s))
print(ans)
s = input()

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

for i in range(n):
    amari[int(s[n-i-1:]) % 2019] += 1
import sys

s = str(input())
tisa = []
for i in range(1,1000000):
  ww = str(2019*i)
  if '0' not in ww:
    tisa.append(ww)
#ok
#print(s)
#print(tisa)
#print(len(tisa))
#重複　count methodは無理
ans = 0
for c in tisa:
  for i in range(0,len(s)-len(c)+1,4):
    if s[i:i+len(c)]==c:
      ans += 1

      
  

print(ans)
si=input()
sa = []
sss = []

for i in range(5,len(si)+1):
    ss = int(si[(i-5):i])
    if ss % 2019 == 0 and ss <= 200000:
        sa.append(i)
        sss.append(ss)
#print(sa)
#print(sss)
print(len(sa))
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = copy.deepcopy(cnt[0])
for i in range(1,MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)
s = input()
ans = 0
U = [0 for i in range(2019)]
mod = 2019
sum_i_to_n = int(s[-4:]) % mod
U[sum_i_to_n] += 1
for i in range(len(s)-5,-1,-1):
    if sum_i_to_n % mod == 0:
        ans += 1
    sum_i_to_n += int(s[i])* pow(10,len(s)-i-1,mod)
    sum_i_to_n %= mod
    ans += U[sum_i_to_n]
    U[sum_i_to_n] += 1
print(ans)
s=input()
cnt=0
le=len(s)
for i in range(1,le-2):
    for j in range(i+3,le+1):
        number=s[i-1:j]
        if int(number)%2019!=0:
            continue
    else: 
        cnt+=1
        break
print(cnt)
def main():
    import collections as c
    s = input()
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        r[i] = int(s[-(1+i)])*pow(10,i,2019)+ r[i-1]
        r[i]%=2019

    rc = c.Counter(r)
    rl = list(rc.values())
    sum = 0
    for i in rl:
        sum += int(i*(i-1)/2)

    if 0 in rc:
        sum+=1

    print(sum)

main()
s = input('')
max_s = int(200000/2019)+1
rec = 0
for m in (range(max_s+1)):
    ms=str(2019*m)
    idx=0
    while s.find(ms,idx) >= 0:
        rec+=1
        idx=s.find(ms,idx)+1
print(rec)
import collections

N_S = input()
N = int(N_S)
N_len = len(N_S)
MOD_N = [0]*N_len
Target = 0
tmp = 1

for i in range(N_len):
  Target += int(N_S[N_len-1-i])*tmp
  Target = Target % 2019
  tmp = tmp * 10 % 2019
  MOD_N[N_len-1-i] = Target 

c = collections.Counter(MOD_N)

Key = list(c.keys())
Num = list(c.values())
M = len(Key)
ans = 0

for i in range(M):
  if Key[i] == 0:
    ans += Num[i]
  else:
    ans += Num[i] * (Num[i] - 1) // 2

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

c=0
d=0
def check2019(S, n):
    global c
    global d
    if int(S)%2019 ==0:
        c +=1
    else:
        pass
    if len(S)>4:
        if n ==0:
            return check2019(S[1:],1), check2019(S[:-1], 0)
        else:
            return check2019(S[1:],2)
    else:
        return 0
S = input()


if len(S) >= 4:
    check2019(S, 0)
else:
    pass
print(c-d)
#s:str, 2.0e+5
#print(200000//2019)
multiples = list(map(str, [2019*i for i in range(1, 100)]))
s = input()
length = len(str(s))
ans = 0
for num in multiples:
    if num in s:
        leng = len(num)
        for i in range(length-leng+1):
            if num == s[i:i+leng]:
                ans += 1

print(ans)
s = str(input())
num = 0
i = 0
#num1= 0
while True:
  for k in range(i, len(s)):
#    print(i,k+4, int(s[i:k+4]), len(s))
#    num1 += 1
    if k+4 > len(s):
      break
    if int(s[i:k+4]) % 2019 == 0:
      num += 1
      print("OK")
  i += 1
  if i == len(s)-1:
    break
print(num)
#print(num1)
def search(S):
    cnt = 0
    N = len(S)
    for i in range(N+1):
        for j in range(i+1, N+1):
            num = S[i:j]
            if int(num)%2019==0:
                print(num)
                cnt += 1
            
    return cnt 

if __name__ == "__main__":
    S = input()
    cnt = search(S)
    print(cnt)
s = input()
ls = [str((i+1) * 2019) for i in range(int(200000 // 2019))]
c = 0
for i in ls:
    if s.count(str(i)) > 0:
        for pos in range(len(s)):
            if s[pos:].startswith(i):
                c += 1
print(c)
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)
n = int(input())
c = 0
k = len(str(n))
for i in range (1, k-2):
    for j in range (i+3 , k+1):
        aa = n // 10 ** (k - i + 1)
        bb = 10 ** (k - i + 1)
        cc = (n * 10)  // (10 ** (k - j + 1))
        if k - j == 0:
            dd = 1
        else:
            dd = 10 ** (k - j)
            if ((n - (aa * bb) - (n - (cc * dd))) // dd) % 2019 == 0:
                    c = c + 1
print(c)
s=input()
count=0
if len(s)<=3:
  print(0)
  exit()
if len(s)==4:
  if int(s)%2019==0:
    print(1)
    exit()
  else:
    print(0)
    exit()
for i in range(0,len(s)-3):
  for j in range(i+4,len(s)+1):
    s_tmp=s[i:j]
    if int(s_tmp)>=200001:
      break
    if int(s_tmp)%2019==0:
      count+=1
print(count)
S = input()
l = []
c = 0
for i in range(200000):
    c += S.count(str(2019*(i+1)))
print(c)
S = input()
ans = 0
Flag = []

for i in range(5,9):
    for j in range(len(S) + 1 - i):
        if int(S[j:j + i]) % 2019 == 0:
            Flag.append(j)
            ans += 1
num = 0
while len(Flag) > 0:
    i = Flag.pop(0)
    num += 1
    for j in range(4 * num + 5,4 * num + 9):
        if i + j > len(S):
            continue
        if int(S[i:i + j + 1]) % 2019 == 0:
            Flag.append(j)
            ans += 1

print(ans)
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

for i in range(1,N,1):
    S_num[N-i-1] = S_num[N-i] + S_num[N-i-1]*pow(10,i,2019)
print(S_num)

for i in range(0,N,1):
    X = S_num[N-i-1] % 2019
    if X==0:
        counter+=1
    counter += mem_mod[X]
    mem_mod[X] += 1
print(counter)
from collections import Counter
S = input()
n = len(S)
mod = 2019
s = [0]*(n+1)
X = [1]*n
for i in range(n-1):
    X[i+1] = X[i]*10%mod
for i in range(n):
    s[i+1] = (s[i]+int(S[n-i-1])*X[i])%mod
c = Counter(s)
ans = 0
for x in c.values():
    ans += x-1
print(ans)
s = input()
cnt = 0

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

print(cnt)
from scipy.special import comb
S=input()
N=len(S)
mod=[0 for i in range(2019)]
for i in range(N):
  s=S[i:N+1]
  mod2=int(s)%2019
  mod[mod2]+=1
ans=0
for i in range(2019):
  k=mod[i]
  if i==0:
    if k>=2:
      ans+=comb(k,2)+k
    else:
      ans+=k
  else:
    if k>=2:
      ans+=comb(k,2)
print(ans)
N = int(input())
ans=0
mathlen=len(str(N))
strN=str(N)
i=0
while i<mathlen-1:
    j=i+1
    while j<mathlen+1:
        check=strN[i:j]
        if int(check)%2019==0:
            tobasi=len(check)-2
            #print(tobasi)
            i+=tobasi
            ans+=1
        j+=1
    #print(i)
    i+=1
print(ans)
S = input()

N = len(S)

ans = 0
for i in range(5,N+1):
  for j in range(0,N-i+1):
    Si = S[j:j+i]
    if int(Si) % 2019 == 0:
      ans += 1
      print(Si)

print(ans)
strS = input()
S = int(strS)
lenS = len(strS)
 
ans = 0
for i in range(lenS - 3):
    for j in range(i+3, lenS):
#        print(i,j)
        if int(strS[i:j+1])%2019 == 0:
            print(int(str(S)[i:j]), i, j)
            ans += 1
print(ans)
s = input()
si = int(s)
ans = 0


for i in range(1,300000//2019):
    d = 0
    while 1:
        if s.find(str(2019*i), d) != -1:
            ans = ans+1
            d = s.find(str(2019*i), d)+1
        else:
            break

print(ans)
number = str(input())[::-1]
remainderDictionary = {0: 1}
digitDictionary = {'1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}

sum = 0
x = 1
for i in number:
  x = (x * 10) % 673
  sum = (sum + digitDictionary[i] * x) % 673 
  remainderValue = remainderDictionary.get(sum,0) + 1
  remainderDictionary[sum] = remainderValue
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  if value > 1:
    ans += value * (value - 1) // 2 # N C 2
print(ans)
s = input()
u = [0]
for i in range(len(s)):
    u.append((u[i]+int(s[::-1][i])*10**i)%2019)
import collections
u2 = collections.Counter(u)
print(sum([int(i*(i-1)/2) for i in u2.values()]))
print(u)
def get_offset(S):
    result = []
    for i in range(length):
        for j in range(i+1, length):
            num = int(S[i:j])
            if num % 2019 == 0:
                has_found = True
                return i+1, j
    print(0)
    exit(0)

S = input()
length = len(S)

head, tail = get_offset(S)

ans = 0
offset = tail - head
ans += (length - head) // offset

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

cnt = 0
i = 0
while(i < ln-3):
#for i in range(ln-3):
    for j in range(i+3, ln):
        if int(S[i:j+1]) % 2019 == 0:
            cnt += 1
            i = j-1
            break
    i += 1
print(cnt)
def c(n):
  return (n*(n-1)//2)
  
S = int(input())
s = str(S)
a = len(s)
enbas = [0]*(a+1)
puiss = 1
for i in range(a):
  enbas[i]=((int(s[a-i-1])*puiss+enbas[i-1])%2019)
  puiss=(10*puiss)%2019
enbas.sort()
compte = 0
i = 0
avant = 0
for n in range(a+1):
  if avant==enbas[n]:
    i+=1
  else:
    compte+=c(i)
    avant = enbas[n]
    i = 1
print(compte)
s=input()
count=0
Num=0
for n in range(len(s)-3):
    for m in range(len(s)-n-3):
        ss=s[n:n+m+4]
        ss.lstrip("0")
        Num=int(ss)
        print(Num)
        if Num % 2019==0:
            count=count+1
            print("Hit!")
print(count)
import numpy as np
def solve():
    S = input()
    dig = len(S)
    data = [1] + [0]*2019

    for i in reversed(range(dig)):
        print(S[i:])
        x = int(S[i:])%2019
        data[x] +=1
    npdata = np.array(data, dtype=np.int32)
    print(np.sum(npdata*(npdata-1)//2))

if __name__ == '__main__':
    solve()
s = input()
ans = 0
for i in range(1, 101):
    t = str(i * 2019)
    for j in range((len(s) - len(t)) // (len(t) - 1)):
        if t in s:
            ans += 1
        u = list(t)
        u.pop(0)
        u = "".join(u)
        t = t + u
print(ans)
s = input()
sum = 0
for i in range(1, 1000):
  number = 2019 * i
  if str(number) in s:
    sum += 1
    j = s.find(str(number))
    if str(number) in s[j+1:]:
      sum += 1
print(sum)
s=str(input())
l=[0]
t=0
for i in range(1,len(s)):
    g=int(s[0:i+1])
    g=g%2019
    l.append(g)

def framod(n, a=1):
    for i in range(1,n+1):
        a=a * i 
    return a

def comb(n, k):
    a=framod(n)
    b=framod(k)
    c=framod(n-k)
    return (a//(b*c))

for i in range(0,2019):
    z=l.count(i)
    if z>1:
        t+=comb(z,2)
print(t)
S=list(map(int,input()[::-1]))
lenS=len(S)
cnt = [0]*2019
tmp = 0
for n,i in enumerate(S):
    tmp += i*pow(10,n,2019)
    cnt[tmp%2019]+=1
ans = cnt[0]
for i in cnt[1:]:
    ans += i*(i-1)//2
print(ans)
s = str(input())
i = 0
ans = 0
while True:
    j = 0
    k = 5 + i
    i += 1
    if k > len(s) + 1:
        break
    while True:
        if k > len(s) + 1:
            break
        if int(s[j:k]) % 2019 == 0:
            ans += 1
        j += 1
        k += 1
print (str(ans))
def f(s):
    pl = [str(2019*i) for i in range(1,51000)]
    res = 0
    for p in pl:
        res += s.count(p)
        # start = 0
        # pos = s.find(p, start)
        # while pos>=0:
        #     res += 1
        #     start = pos + 1
        #     pos = s.find(p, start)
    return res

if __name__ == "__main__":
    print(f(input()))
import sys

def a():
    input = sys.stdin.readline
    s = input()
    n = len(s)
    se = {i * 2019 for i in range(100)}
    count = 0
    for i in range(n - 3):
        for j in range(i + 4, n + 1):
            a = int(s[i:j])
            if a in se:
                count += 1
    print(count)


a()
S =input()
L = []
def count(text, part):
     return sum(text.startswith(part, i) for i in range(len(text)))
cnt=0
for i in range(1,99):
    L.append(str(i*2019))
for v in L:
    cnt+=count(S,v)
print(cnt)