peterverebics/CodeNet_Python_118 huggingface dataset:
# -*- coding: utf-8 -*-

def count_all(text, part):
    num = 0
    pos = 0
    while True:
        pos = text.find(part, pos)
        if pos == -1:
            break;
        num = num + 1
        pos = pos + 1
    return num


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

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

print(count)
S = input().rstrip()
ret = 0
for i in range(len(S)-3):
    for j in range(i+3, len(S)+1):
        # print(S[i:j])
        if eval(S[i:j]) % 2019 == 0:
            print(i+1, j)
            ret += 1
print(ret)
S = input()
ans=0
for i in range(100):
  ans+= S.count(str(2019*(i+1)))
print(ans)
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
s = list(SI())
l = []
count = 0
for i in range(100):
	l.append(list(str((i+1)*2019)))
for i in l:
	for j in range(len(s)-len(i)+1):
		if s[j:j+len(i)] == i:
			count+=1
print(count)
s=input()
n=len(s)
count=0
index=1
value=0
arr=[]
while index*2019<=999999:
    value=str(index*2019)
    arr.append(value)
    index+=1     

for i in range(n):
    if i+5<=n:
        if s[i:i+5] in arr or s[i:i+6] in arr or s[i:i+7] in arr:
            count+=1
print(count)
S = input()
Sr = S[::-1] # 一の位から考える

T = 0 # 部分文字列
mod = [0] * 2019 # mod数え上げ配列
mod[0] += 1 # 「部分文字列T = S」の場合の、 「0 % 2019 = 0」を予めカウント
d = 1 # 桁数
for s in (Sr):
  T += int(s) * d
  T %= 2019
  d = (d * 10) 
  d = d % 2019
  
  mod[T] += 1
  
# ペアを合計
mod = [m//2 for m in mod]
print(sum(mod))
def main():
    s = input()
    mod = 2019
    mod_count = {i: 0 for i in range(mod)}
    now_num = 0
    for i in range(len(s) - 1, -1, -1):
        now_num += pow(10, len(s) - i - 1) * int(s[i])
        now_num %= mod
        mod_count[now_num] += 1
    ans = 0
    for i in range(mod):
        ans += mod_count[i] * (mod_count[i] - 1) // 2
    print(ans + 1 if ans else 0)


if __name__ == '__main__':
    main()
import collections
S = input()
N = len(S)
mod = 2019
div = [0]*N
temp = 0
for i in range(N):
    temp = temp + int(S[N-1-i])*pow(10,i,mod)
    div[i] = temp%mod
d = collections.Counter(div)
print(sum(d.values())-len(d)+d[0])
s = input()
# S = int(s)

N = len(s)
ans = 0
S =""
i = 0
b = 0
n = 0
while i <N :
    # print("i=",i)
    S += s[i]
    # print(S)
    n +=1
    if n > 4:
        n3 = S
        for k in range(b,n-3):
            n3 = n3[1:]
            if int(n3) %2019 == 0:
                # b = k
                ans += 1
                break
    i += 1

print(ans)
S = input()


count = 0

for i in range(len(S)):
    for j in range(i + 3,len(S)):
        print(S[i:j+1])

        x = int(S[i:j+1])
        

        if x % 2019 == 0:
            count += 1

print(count)
s = input()
a = [int(c) for c in s]

b=a
count=0

for i in range(len(a)):
    for j in range(i,len(a)):
        del b[:i]
        #print(i,j,b)
        del b[j+1-i:]
        #print(i,j,b)
        num="".join(map(str,b))
        #print(num)
        if int(num)%2019 == 0:
            count+=1
        b=a

#print(count)
S = input()

tar = 0
num = 0
for i in range(1,101) :
  tar = 2019 * i
  if tar > int(S) :
    break
  tar_cnt = len(str(tar))
  for j in range(len(S)-tar_cnt+1) :
    #print('{}:{}'.format(j,tar_cnt))

    if S[j:j+tar_cnt] == str(tar):
  	  num += 1
  	  #print('{}:{} {}'.format(j,j+tar_cnt,S[j:j+tar_cnt]))
  	  #print(j)
  	  #print(len(str(tar))+1)

print(num)
s = input()
count = 0
l = len(s)
for i in range(l-4):
    if l - i>=6:
        tmp = int(s[i:i+6])
        if tmp%2019==0:
            count +=1
    if l - i>=5:
        tmp2 = int(s[i:i+5])
        if tmp2%2019==0:
            count +=1
    tmp3 = int(s[i:i+4])
    if tmp3%2019==0:
        count +=1
print(count)
S=input()
N=len(S)
S=int(S)
nums=[0]*200000
maxi=0
zero=0
tmp=S
ite=10**(N-1)
for i in range(N):
    div=tmp%2019
    if div==0:
        zero+=1
    nums[div]+=1
    maxi=max(div,maxi)

    tmp%=ite
    ite//=10
    
ans = zero
for i in range(1,maxi):
    if nums[i]<2:
        continue
    ans += nums[i]*(nums[i]-1)//2
print(ans)
s = input()
# S = int(s)

N = len(s)
ans = 0
S =""
i = 0
b = 0
n = 0
while i <N :
    # print("i=",i)
    S += s[i]
    # print(S)
    n +=1
    if n > 4:
        for k in range(b,n-2):
            n3 = S[k:]
            if int(n3) %2019 == 0:
                b = k
                ans += 1
                break
    i += 1

print(ans)
S=str(input())
n=len(S)
list2019=[]
ans=0

for i in range(1,100):
    a=i*2019
    b=str(a)
    if int(S)<a:
        break
    if '0' not in b:
        list2019.append(b)


for tgt in list2019:
    for i in range(n-len(tgt)+1):
        if S.find(tgt,i,i+len(tgt))==i:
            ans=ans+1
      

print(ans)
s=input()

def is2019(s):
    num=int(s)
    return num % 2019 == 0

i=0
ans=0
while i<len(s):
    found=False
    for j in range(1,10):
        if i+j > len(s):
            continue
        if is2019(s[i:i+j]):
            found=True
            ans+=1
            break
    i+=1
print(ans)
def main(S=None):
    if not S:
        S = input()
    count = 0
    candidates = [str(i) for i in range(2019, 200000, 2019)]
    s_len = len(S)
    for candidate in candidates:
        candidate_len = len(candidate)
        for i in range(s_len):
            if i+candidate_len > s_len:
                break
            if S[i:i+candidate_len] == candidate:
                count += 1
    print(count)


if __name__ == "__main__":
    # main("1817181712114")
    # main("14282668646")
    main()
nn = input()
c = 0
i = 1
nnn = 0

import re

while len(str(nnn)) < 6:
    nnn = 2019 * i
    if int(nnn) >= int(nn):
        break
    i+=1
    if str(nnn) in str(nn):
        nnn = str(nnn)
        c+=len(re.findall(nnn[0]+"(?="+nnn[1:]+")", str(nn)))
print(c)
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    S = input()

    result = 0
    for i in range(2019, 2019 * 100, 2019):
        length = len(str(i))
        for j in range(len(S) - length + 1):
            if str(i) == S[j:j + length]:
                result += 1
    print(result)


if __name__ == "__main__":
    main()
S = list(input())

count = 0

if len(S) < 4:
    print(count)

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

          count += 1

print(count)
import sys
input = sys.stdin.readline
s = list(input())
count = 0
for i in range(len(s)):
    for j in range(i+4, len(s)+1):
        x = int(''.join(s[i:j]))
        if x%2019 == 0:
            count += 1
print(count)
S=input()
full=[]
cnt=0
kaisuu=2*10**5//2019+1

for i in range(1,kaisuu+1):
  full.append(str(i*2019))


def count_Occurrences(string, sub):
    count=0
    for i in range(0, len(string)-len(sub)+1):
        if sub in string[i:i+len(sub)]:
            count=count+1
    return count
  
for s in full:
  cnt+=count_Occurrences(S,s)
print(cnt)
#A,B,C,D=map(int,input().split(" "))

import collections

mod=2019
a=input()

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

for i in range(N):
  u=int(a[i::])
  v=u % mod
  t.append(v)
  
tt = collections.Counter(t)
for i in tt.values():
  #print(i)
  if i==0:
    ans+=1
  else:
    ans += (i-1)*i//2
print(ans)
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] * 10**i
        amari[s % 2019] += 1

print(sum([i*(i-1)//2 for i in amari])+1)
def main():
    s = input()
    answer = 0
    length = len(s)
    index = [[] for _ in range(10)]
    for i in range(length):
        index[int(s[i])].append(i)
    for i in range(1, 110):
        now = str(i * 2019)
        now_length = len(str(now))
        for j in index[int(now[0])]:
            if now == s[j:j + now_length]:
                answer += 1
    print(answer)


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

bbb = [2019*i for i in range(10000)]

k = 0
ans = 0
for a in bbb:
    k = bbb.count(str(a))
    ans += k

print(ans)
S = input()
cnt = 0
for i in range(1, 15):
    for j in range(len(S)-i+1):
        if int(S[j:j+i]) % 2019 == 0 and int(S[j:j+1]) != 0:
            cnt += 1
print(cnt)
s = input()
a = int(s)%2019
mods = [0]*2019
mods[a] += 1
d = 10**(len(s)-1)
for i in s:
  a = (a-int(i)*d)%2019
  d = d//10%2019
  mods[a] += 1
ans = 0
for i in mods:
  ans += i*(i-1)//2
print(ans)
s = input()
cnt = 0
ans = []
for i in range(0, len(s) - 3):
    j = i
    num = ''
    while j < len(s):
        juhuku = 0
        num += s[j]
        if int(num) % 2019 == 0 and num != '0':
            print(i, j)
            if j not in ans:
                ans.append(j)
            juhuku = ans.count(i - 1)
            cnt += 1 + juhuku
        j += 1
print(cnt)
s = input()
count = 0
for i in range(0,round(len(s)/2)):
    for j in range(i+3,len(s)):
        print(i, j, s[i:j+1])
        if int(s[i:j+1]) % 2019  == 0:
            count += 1
        if int(s[len(s)-j:len(s)-i]) % 2019  == 0:
            count += 1
print(count)
s = input()
count = 0

l = [int(s[i:]) % 2019 for i in range(len(s))]
d = {}

for i in l:
  d[i] = d.get(i, 0) + 1
  
for i in d:
  count += d[i]*(d[i]-1)//2

print(count)
from sys import stderr
from functools import reduce
import re

def debug(*args):
    print(*args, file=stderr)

s = input()

def count(text, sub):
    # https://stackoverflow.com/a/28915551
    ln = len(sub)
    return sum(sub == text[i:i+ln] for i in range(len(text)-(ln-1)))

multiples = filter(lambda  x: '0' not in x, [str(i) for i in range(200000) if i % 2019 == 0 and i != 0])
result = sum(map(lambda m: count(s, m), multiples))

print(result)

# echo "1817181712114" | python3 d.py && echo "14282668646" | python3 d.py && echo "2119" | python3 d.py
s = list(input())

ans = 0
l=""
for i in s[::-1]:
    l = i + l
    if int(l) % 2019 == 0:
        ans += 1
        l = i

print(ans)
s=input()
lis=[]
for i in range(1,101):
    if '0' in str(2019*i):
        pass
    else:
        lis.append(2019*i)
        
def count(text, part):
    return sum(text.startswith(part, i) for i in range(len(text)))

ans=0
for i in lis:
    ans+=count(s,str(i))
print(ans)
S = input()

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

ans = ctr[0]
for v in ctr[1:]:
    ans += v * (v - 1) // 2
print(ans)
from collections import deque
import copy

l = deque(list(input()))
now = deque([])
ans = 0

for _ in range(min(3, now.__len__())):
  now.append(l.popleft())
  
while l:
  now.append(l.popleft())
  nxt = deque([])
  while now:
    if int("".join(now)) % 2019 == 0:
      ans += 1
      while now.__len__() > 1:
        now.popleft()
      nxt = copy.deepcopy(now)
    nxt.append(now.popleft())
  now = copy.deepcopy(nxt)

print(ans)
from collections import Counter
S = input()
L = len(list(S))
dp = [0] * L
dp[0] = 1
T = [0] * L
T[0] = int(S[-1])
for i in range(1, L):
    dp[i] =  dp[i - 1] * 10
    dp[i] %= 2019
    T[i] = int(S[-(i+1)]) * dp[i] + T[i - 1]
    T[i] %= 2019
ans = 0
for k, v in Counter(T).items():
    if k == 0:
        ans += v
    else:
        ans += v * (v - 1) // 2

print(ans)
# ABC164 D - Multiple of 2019 - numpy ver. 更に改良ver.
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 = 1

a[0] = int(s[0])
d[0] = a[0]
ans[0] = 1
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))
import collections
s = input()
s_keta = len(s)
dp = [0 for i in range(s_keta+1)]
for i in range(1,s_keta+1):
  dp[i] =  (dp[i-1] + (10 ** (i-1)) * int(s[s_keta - i])) % 2019
print(dp)
#c = collections.Counter(dp)
#result = 0
#for v in c.values():
#  result += v * (v-1) //2
#print(result)
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 and not c[0]==1 and not c[0]==2):
    t = t + c[0]*(c[0]-1)//2
elif(c[0]==1 or c[0]==2):
    t = t + c[0]
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()
ans=0
lra=len(s)-4
rla=len(s)+1
for l in range(lra):
    for r in range(l+4,rla):
        tmp=int(s[l:r])
        if tmp%2019==0:
            ans+=1
            l=r-1 
print(ans)
for i in range(2000000):
  a = 0
  
print(0)
s=str(input())
a,b=0,0
for i in range(1,100):
    a=2019*i
    if str(a) in s:
        b+= sum([s[k:k+len(str(a))]==str(a) for k in range(0, len(s)-len(str(a))+1)])
print(b)
S=str(input())
x=0
for i in range(len(S)):
    for j in range(i+1,len(S)+1):
        a=S[i:j]
        a=int(a)
        if a%29==0:
            x=x+1
print(x)
S = input()
c = 0
for l in range(len(S)-3):
    for r in range(l+4, len(S)+1):
        print(S[l:r])
        if int(S[l:r])%2019 == 0:
            c += 1
print(c)
S = str(input())
if len(S) >= 200000 or len(S) <= 1:
    exit()

r = 0
for i in range(len(S)):
    for j in range(i, len(S) + 1):
        t = S[i:j]
        if t:
            t = float(t)
            if t / 2019.0 == t // 2019:
                r += 1

print(r)
s=input()
l=[0]*2019
d=1
x=0
for i in range(len(s)):
  x+= d* int(s[len(s)-i-1]) %2019
  l[x%2019]+=1
  d*=10
ans=0
for i in range(1,2019):
  ans+=l[i]*(l[i]-1)//2
if int(s)%2019==0:
  ans-=1
print(ans+l[0])
n = input()
k = len(n)
count = 0
s = set()
for r in range(k):
  num = int(n[-(r+1):])
  rem = num % 2019
  if rem not in s:
    s.add(rem)
  else:
    count+=1
print(count)
S = input()
ans=0

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

print(ans)
s=input()
b=len(s)
x=0
for j in range(b-3):
    for i in range(b-j-4):
        a= int(s[j:j+i+5])
        if a % 3 ==0:
            if a%2019:
                x+=1
        else:
            continue
print(x)
from collections import Counter

S = [int(s) for s in input()]
y = 2019
T = [S[-1]] * len(S)

for i in range(len(S)-2, -1, -1):
  T[i] = (T[i+1] + S[i] * 10) % y

cnt = 0
for c in Counter(T).values():
  cnt += c * (c - 1) // 2
  
print(cnt)
s=input()
string=set([str(i*2019) for i in range(1,101)])
ans=0
for i in range(4,7):
    for g in range(len(s)-i+1):
        if s[g:g+i] in string:
            ans+=1
print(ans)
def func():
    return

# n = int(input())
s = input()
# a, b = map(int, input().split())
# a = list(map(int, input().split()))
# a = input().split()

cnt = 0
ls = len(s)
for i in range(ls-3):
    for j in range(i+4, ls+1):
        tmp = int(s[i:j])
        print(tmp)
        if tmp%2019 == 0:
            cnt += 1

print(cnt)
S = input()
N = len(S)
A = [str(2019*i) for i in range(1,100)]       
 
count = 0
for j in range(99):
    for i in range(N):
        count += S[i:i+len(A[j])].count(A[j])
print(count)
s = input()

div = int(200000/2019)

ret = 0
for i in range(1, div+1):
    l = len(str(i*2019))
    for j in range(len(s)):
        if j+l == len(s)+1:
            break
        if s[j:j+l] == str(i*2019):
            ret += 1
print(ret)
from collections import deque
s = str(input())

list = deque()
count = 0
for i in range(1,101):
    list.append(str(i*2019))

for li in list:
    for j in range(0,len(s) - len(li) + 1):
        if s[j:j+len(li)] == li:
            count += 1

print(count)
import collections
S=input()
l=len(S)
T=0
A=[0]*2019
A[0]=1
for i in range(l):
    T+=int(S[l-i-1])*(10**i)
    A[T%2019]+=1
ans = 0
for cnt in A:
    ans += cnt * (cnt - 1) // 2
print(cnt)
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

S = read_str()
l = len(S)

def solve():
    ans = 0
    i = 0
    while i < l - 3:
        for j in range(i + 4, l + 1):
            if int(S[i:j]) % 2019 == 0:
                ans += 1
                i += 2
        i += 1
    return ans

if __name__ == "__main__":
    print(solve())
S=input()
S=S[::-1]
unko=[0]*2019
tmp=0
num=1
for s in S:
  s=int(s)
  tmp+=num * s
  num=num*10
  unko[tmp%2019]+=1
ans=0
ans+=unko[0]*(unko[0]-1)/2+1
for i in unko[1:]:
  ans+=i*(i-1)/2
print(int(ans))
S = input()
N = len(S)
ans = 0

amari = int(S[0])
for j in range(1,N):
    amari = (10*amari + int(S[j]))%2019
    if amari == 0:
        amari = int(S[j])
        ans += 1
print(ans)
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
s = list(SI())
le = len(s)
l = []
count = 0
for i in range(100):
	l.append(list(str((i+1)*2019)))
for i in l:
	aa = len(i)
	for j in range(le-aa+1):
		if s[j:j+aa] == i:
			count+=1
print(count)
S = input()
leng = len(S)
S = int(S)

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

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

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

print(res)
s = input()

match = 0
for i in range(len(s)):
    for j in range(i + 4, len(s) - 3):
        val = int(s[i:j])
        if val >= 2019 and val % 2019 == 0:
            match += 1

print(match)
s = input()[::-1]
m = 2019
ans = 0
x = 1
tot = 0
cnt = [0] * m
for s in s:
    cnt[tot] += 1
    tot += int(s) * x
    tot %= m
    #ans += cnt[tot]
    x *= 10
    x %= m

print(sum(i*(i-1)//2 for i in cnt))
s = int(input())
n = len(str(s))
slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)
ans = 0
for i in range(len(slist)):
    for j in range(i+1,len(slist)):
        if (slist[j] - slist[i])%2019 == 0:
            print(i,j)
            ans += 1

print(ans)
n = input()
count = 0

length = len(n)

stock = [0]*99

for i in range(99):
    stock[i] = '{}'.format(2019 * (i + 1))

for i in range(99):
    if int(n) - int(stock[i]) >= 0:
        for j in range(length-len(stock[i])+1):
            if n[j: j+len(stock[i])] == stock[i]:
                count += 1
    else:
        break

print(count)
S = input()

n = len(S)

modlist = [0] * 2019
num = 0
mods = 1

for i in range(n):
    fig = int(S[n - i - 1])
    mods = mods % 2019
    num = (num + fig * mods) % 2019
    modlist[num] = modlist[num] + 1
    mods = mods * 10

result = 0
if modlist[0] > 0:
    result += 1

for i in range(2019):
    m = modlist[i]
    if m != 0:
        result += m * (m - 1) / 2

print(int(result))
S=input()
N=['0']*1000
count=0
j=12114
for i in range(0,1000):
    while True:
        if str(j).count('0')==0:
            N[i]=str(j)
            j+=2019
            break
        else:
            j+=2019
for i in range(0,1000):
    count+=S.count(N[i])
    if S.count(N[i])>0:
        if N[i][0]==N[i][-1]:
            count+=S.count(N[i][1:])-S.count(N[i])
print(count)
s=input()
c=0
if len(s)<=3:
    print(0)
if len(s)>3:
    for k in range(3,len(s)):
        for i in range(len(s)-k):
            if int(s[i:i+k+1])%2019==0:
                c+=1
print(c)
s = input()
l = len(s)
ans = 0

for i in range(1, l - 3):
    for j in range(4, l+1):
        string_j = int(s[:j])
        string_i = int(s[:i]) 
        if (string_j - string_i) % 2019 == 0:
            ans += 1

print(ans // 2)
s=input()
n=len(s)
s_int=[0]*n
x=pow(10,n-1)
for i in range(n):
    s_int[i]=(int(s[i])*x)%2019
s=input()
a=0
for i in range(len(s)):
    for j in range(i+3,len(s)+1):
        if int(s[i:j])%2019==0:
            a+=1
            print(i,j)
print(a)
def main():
  N = int(input()) # 1行, 単数

  S = str(N)
  count = 0
  for i in range(len(S) - 3):
    x = int(i)
    for j in range(int(i+3) , len(S)+1):
      y = int(j)
      A = int(S[x:y])
      if A % 2019 == 0:
        print(x ,y)
        count+=1
  print(count)


if __name__ == '__main__':
    main()
s=input()
k=673
ans = 0
dp=[[0 for _ in range(k)] for _ in range(len(s))]
dp[0][int(s[0])] = 1
for i in range(1,len(s)):
    t = int(s[i])
    dp[i][t] += 1
    for j in range(k):
        dp[i][((10*j)+t)%k] += dp[i-1][j]
        #dp[i][j] += dp[i-1][j]
    ans += dp[i][0]
print(ans)
S = input()

baisu = list()
for i in range(1, 10**3):
    if '0' not in str(2019*i):
        baisu.append(str(2019*i))
        
count = 0
for bai in baisu:
    for i in range(len(S)):
        k = len(bai)
        try:
            if bai ==  S[i:i+k]:
                count += 1
        except:
            pass
print(count)
S=str(input())
n=0
for i in range(len(S)-3):
  j=i+3
  m=S[i:j]
  while j<=len(S)-2:
    m=S+str(S[j+1])
    if int(m)%2019==0:
      n+=1
    else:
      pass
    j+=1
print(n)
import re

s = input()

l = ['0'] * (200000 // 2019)
ans = 0

for i in range(len(l)):
  w = str(2019 * (i+1))
  w_l = len(w)
  #print(w)
  for j in range((len(s)-w_l+1)):
    t = s[j:(j+w_l)]
    if w == t:
      ans += 1
      # print(w)


print(ans)
s = input()
c = 0
if int(s) <= 2019:
  print(c)
else:
  for i in range(len(s) + 1):
    for j in range(len(s) + 1):
      if i < j:
        if int(s[i:j]) > 2019:
          if int(s[i:j]) % 2019 == 0:
            print(i + 1, j)
            c = c + 1
print(c)
def judge(long):
    global n, count
    for j in range(len(n)-long+1):

        if int(n[j:j+long+1]) % 2019 == 0:
            count += 1


n = input()
count = 0
for i in range(4, len(n)+1):
    judge(i)
if count > 0:
    print(count-1)
else:
    print(0)
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)
from collections import Counter
s = input()

l=[]

for i in range(1,200000//2019+1):
    l.append(str(i*2019))
c=0
counter = [None] * 11
for L in range(11):
    counter[L] = Counter(s[i: i + L] for i in range(0, len(s) - L + 1))
answer = sum(counter[len(C)][C] for C in l)

print(answer)
S = str(input())

count = 0
for i in range(0, len(S)):
    for j in range(i+4, len(S)+1):
        s = int(S[i:j])
        if s > 200000:
            break
        if s % 2019 == 0:
            count += 1

print(count)
import re
S=input()

x=[i for i in range(1,1000)]
x=map(lambda i:str(i*2019),x)



ans=0

for i in x:
    t=len(re.findall("(?={})".format(i),S))
    ans+=t

print(ans)
S = input()
res = 0
v = 2019 / 1e9
for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        num = float(S[i:j]) / 1e9
        print(num % v)
        if num % v < 0.000000003:
            res += 1
print(res)
def solve(s):
    N = len(s)
    ans = 0
    if N < 4:
        return 0

    for i in range(4,10):
        for j in range(N-i+1):
            ans += 1 if int(s[j:j+i])%2019==0 else 0
    
    return ans

S = str(input())    
print(solve(S))
S = list(input())
N = len(S)


l = [0] * 2019
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 = l[0]

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

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

for i in range(N):
    count = 0
    while i < N - 2:
        for j in range(i+2,N+1):
            if int(S[i:j]) % 2019 == 0:
                count += 1
                break
        i = j - 1
    if count > 0:
        break

print(count)
S=input()
N = len(S)
arr = []
ans = [0 for i in range(2020)]
cnt0 = 0
for i in range(N):
  a = int(S[N-i-1:N])%2019
  ans[a] += 1
  arr.append(a)
  if a == 0:
    cnt0 += 1
cnt = 0
for i in range(1,1010):
  cnt += ans[i] * ans[2019-i]
  
cnt = int(cnt + (cnt0+1)*cnt0/2)
print(cnt)
s=list(input())
count=0
if len(s)<=3:
    print(0)
for i in range(len(s)-3):
    for j in range(i+3,len(s)):
        a="".join([str(n) for n in s[i:j+1]])
        if int(a)%2019==0:
            count+=1
        else:
            pass
print(count)
S = str(input())
counts = 0
if len(S) < 4:
    print(0)
else:
    for i in range(len(S)-3):
        for j in range(i+3,len(S)):
            s = int(S[i:j+1])
            if s % 2019 == 0:
                counts += 1
print(counts)