peterverebics/CodeNet_Python_118 huggingface dataset:
S=input()
N=len(S)
Slis=[]
for i in range(N):
  Slis+=[int(S[i])]
T=[int(S[i:]) for i in range(N)]
MOD=[0 for i in range(2019)]
for i in range(N):
  tmp=T[i]%2019
  MOD[tmp]+=1
ans=0
for i in range(2019):
  tmp=MOD[i]
  ans+=tmp*(tmp-1)//2
print(ans)
s = input()
int_s = 1000000

ans = 0
mul = 2019
while mul < int_s:
    sub_s = s
    f = sub_s.find(str(mul))
    while f != -1:
        ans += 1
        sub_s = sub_s[f+1:]
        f = sub_s.find(str(mul))
    mul += 2019

print(ans)
s = input()
s_num = int(s)
len_s = len(s)
list=[0 for x in range(len_s+1)]
for i in range(len_s-1,-1,-1):
    for j in range(4,min(8,len_s-i+1)):
        print(i,j, s[i:j+i])
        if int(s[i:i+j])%2019==0:
            list[i]=list[i+j]+1
print(sum(list))
S = str(input())
li = []
dic = {}
ans = 0

s = 0
d = 1
for i in range(len(S)):
  s += int(S[len(S)-1-i]) * d
  s = s % 2019
  if s == 0:
    ans += 1
  elif s not in li:
    li.append(s)
  elif s not in dic:
    dic[s] = 2
  else:
    dic[s] += 1
  d *= 10
  d = d % 2019
  
li = list(dic.values())
for l in li:
  ans += l * (l-1) // 2

print(ans)
s = input()
s_len = len(s)
num = ''
ans = 0
j = 0
for i in range(s_len):
  while j < s_len:
    num += s[j]
    if int(num) % 2019 == 0:
      ans += 1
    j += 1
  j = i + 3
  if j > s_len:
    break
  num = ''
print(ans)
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=x//10
baisu=set([])

i=1
while 1:
    temp=2019*i
    if "0" not in str(temp):
        baisu.add(str(temp))
    
    if temp>20000000:
        break
    i+=1

n=input()
cnt=0
for i in baisu:
    if i in n:
        cnt+=1

print(cnt)
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[1:]))
# import re
S = input()
cnt = 0

multiple = [2019]
i = 2
while multiple[-1] < 200000:
    multiple.append(2019 * i)
    i += 1
multiple.pop()
multiple = [str(i) for i in multiple]

# cnt = len(re.findall('18171', S))
# print(cnt)

for i in range(len(S)):
    for j in multiple:
        if j in S[i:i+len(j)]:
            cnt += 1

print(cnt)
n = input()
t = len(n)
count= 0
for i in range(t):
    for j in range(t+1):
        if(i<j):
            if(int(n[i:j]) % 2019 == 0):
                print(n[i:j])
                count+= 1
print(count)
t=1;p=0;m=2019;c=[0]*m;r=0
for x in (input()+'0')[::-1]:p=(int(x)*t+p)%m;r+=c[p];c[p]+=1;t=t*10%m
print(r%m)
S = input()

def check_2019(txt):
  amari = int(txt) % 2019
  if amari == 0:
    return True
  else:
    return False

N = len(S)

ans = 0

i = 0
j = i + 3

while(i <= N):
  j = i + 3
  while(j <= N):
    if check_2019(S[i:j]):
      ans += 1
      i = j
      break
    j += 1
  i += 1

print(ans)
def main():
  s = input()[::-1]
  l = len(s)
  n = 2019
  dp = [0]*n
  wk = 0
  r = 1
  for i in range(l):
    wk += int(s[i])*r
    wk %= n
    dp[wk] += 1
    r*= 10
    r %= n
  print(sum([i*(i-1)//2 for i in dp]),dp)
main()
s = input()

a = [str(2019*i) for i in range(1,101)]
ans = 0
for i in a:
    if i in s:
        t = len(i)
        for j in range(len(s)-t+1):
            if s[j:j+t] == i:
                ans += 1

print(ans)
from queue import deque
 
    
S = deque(input())
y = 2019
U = [0] * y
t = int(S.pop())
U[0] = 1
k = 10

for s in reversed(S):
    t = t + int(s) * k
    t %= y
    U[t] += 1
    k *= 10
    k %= y

cnt = 0
for u in U:
    cnt = cnt + u * (u - 1) // 2

print(cnt)
s=input()
b=0
m=len(s)
c=0
for i in range(m-3):
    a=s[i]+s[i+1]+s[i+2]
    for j in range(i+3,m):
        if c==1 and int(s[j])%3!=0:
            c=0
            continue
        a=str(a)
        a=int(a+s[j])
        c=0
        
        if a%3!=0:
            continue

        c=1
        if a%2019==0:
            b+=1
print(b)
s = str(input())
n = len(s)
print(s)
s = s[::-1]
print(s)
x, tot = 1, 0
m = 2019
ans = 0
cnt = [int() for _ in range(m)]
for i in range(n):
    cnt[tot] += 1
    tot += (int(s[i])) * x
    tot %= m
    ans += cnt[tot]
    x = x * 10 % m
print(ans)
S = str(input())

cnt = 0
div_value = 2019

for i in range(0, len(S)-3):
   #print(i, S[i:i+4])
   for j in range(i+4, len(S)):
       #print(i, "-", j, S[i:j])
       if j-i >= 200000:
           continue
       if int(S[i:j]) >= div_value \
           and int(S[i:j]) % div_value == 0:
           #print(i, "-", j, int(S[i:j]))
           cnt = cnt+1

print(cnt)
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
print(ans+l[0])
s = input()
s_num = int(s)
len_s = len(s)
list=[0 for x in range(len_s+1)]
for i in range(len_s-1,-1,-1):
    for j in range(4,min(9,len_s-i+1)):
        if int(s[i:i+j])%2019==0:
            list[i]=list[i+j]+1
print(sum(list))
N = input()
lenN = len(N)
cnt = 0
  
for i in range(0,lenN-3):
  for j in range(i + 3,i + 3 + 6):
    if j > lenN :
      break
    p = int(N[i:j])
    if p % 2019 == 0:
      cnt += 1

print(cnt)
s = input()
s_num = int(s)
len_s = len(s)
list=[0 for x in range(len_s+1)]
for i in range(len_s-1,-1,-1):
    for j in range(4,min(9,len_s-i+1)):
        if int(s[i:i+j])%2019==0:
            list[i]=list[i+j]+1
            break
print(sum(list))
s= input()
counter=0
 
if int(len(s))<= 3:
    print(0)
    exit(0)
else:
    for i in range(1, 100):
        a = str(2019*i)
        if a in s:
            counter += 1
    print(counter)
import math
s=input()
n=len(s)
count=0
a=[0 for i in range(2019)]
a[0]=1
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if n<4:
    print(0)
else:
    for i in range(0,n):
        a[int(s[i:])%2019]+=1
    for i in range(2019):
        if a[i]>=2:
            count+=comb(a[i],2)
print(count)
S = input()
# S = '201879812018798120187981'

baisu = [str(2019 * m) for m in range(1, 10000)]

# print(baisu)

cnt = 0
for b in baisu:
    # 開始位置
    s = 0
    while True:
        # 見つけた位置
        pos = S.find(b, s)
        if pos > -1:
            # 次の開始位置を1文字後にする
            s = pos + 1
            cnt += 1
        else:
            break

print(cnt)
from itertools import combinations
s = input()
d = {}
tmp = 0
i = 0
for char in s[::-1]:
    tmp += int(char) * pow(10, i, 2019)
    tmp %= 2019
    if tmp not in d:
        d[tmp] = 1
    else:
        d[tmp] += 1
    i += 1

result = 0
for num, v in d.items():
    if num == 0:
        result += v
        continue
    if v > 1:
        result += v * (v - 1) // 2

print(result)
S=input()
ans=0
a=0
b=3
if len(S)<4:
  print(0)
else:
  while True:
    if int(S[a:b])%2019==0:
      ans+=1
    b+=1
    if b==len(S)+1:
      a+=1
      b=a+3
    if a==len(S)-3:
      break
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

res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2
    
res
N = input()
lenN = len(N)
h = lenN
cnt = 0
if lenN >= 6:
  h = lenN // 2
  
for i in range(0,h-3):
  for j in range(i + 3,h+1):
    p = int(N[i:j])
    if p % 2019 == 0:
      print("{} : {}".format(i,j))
      cnt += 1
if lenN >= 6:
  for i in range(h-3,lenN-3):
    for j in range(i + 3,lenN+1):
      p = int(N[i:j])
      if p % 2019 == 0:
        print("{} : {}".format(i,j))
        cnt += 1

print(cnt)
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
cnt, ans
P=2019
S = input()
N=len(S)

ans = 0
count = [0] * P
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
  print(i,s)
  u = (int(s) * pow(10, i, P) + u) % P
  ans += count[u]
  count[u] += 1

print(ans)
s=input()
n=len(s)
count=0
for i in range(n):
  for j in range(i+4,n):
    if int(s[i:j])%2019==0:
      count+=1
print(count)
S = input()

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

print(ans)
s=input()
n=len(s)
MOD=2019
l=[]
for i in range(n-1,-1,-1):
  l.append(int(s[i:n])%MOD)
print(l)
from collections import Counter
c=Counter(l)
print(c)
ans=0
for i in c.values():
  ans+=i*(i-1)//2
print(ans)
S = input()

mods = []
for i in range(len(S)):
    mod = int(S[i:]) % 2019
    mods.append(mod)

cnt = len(mods) - len(set(mods))
print(cnt)
S = input()
ans = 0
nd = 1
mod1 = 0
listmod = [0]*2019
for i in S[::-1]:
    mod1 = (int(i)*nd + mod1)%2019
    listmod[mod1] += 1
    nd = (nd*10)%2019
for i in range(2019):
    n = listmod[i]
    if(n>0):
        ans += ((n-1)*n)//2
print(ans)
S = input()
int_S = int(S)
N = len(S)
cnt = 0
pos_l = 0
pos_r = 0


while (True):
    pos_r +=  + 1
    
    if (pos_r < N):
        tmp = int(S[pos_l: pos_r + 1])
        if (tmp % 2019 == 0):
            cnt += 1
            pos_l = pos_r
    else:
        pos_l += 1
    
    if (pos_l >= N):
        break


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

ans = l[0]

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

print(ans)
s = input()
s_len = len(s)
count = 0

for i in range(s_len - 3):
    for j in map(lambda num: num + (i + 3), range(s_len - (i + 3))):
        if int(s[i:j]) % 2019 == 0:
            count += 1

print(count)
s = input()

ans = 0
i = 0
flag = 0
while i < len(s) - 4:
    flag = 0
    for j in range(i + 5, i + 1000):
        sub = int(s[i:j])
        if sub % 2019 == 0:
            ans += 1
            flag = 1
            break
    if flag == 1:
        i = j - 1
    else:
        i += 1
    

print(ans)
s=input()
l=len(s)
ans=0
p=0
a={}
b=-1
c=-1
d=-1
q=1
for j in range(l)[::-1]:
    p=(p+int(s[j])*q)%2019
    q*=10
    q%=2019
    if b>0:
        if a.get(b)!=None:
            a[b]+=1
        else:
            a[b]=1
    b=c
    c=d
    d=p
    if p==0:
        ans+=1
    if a.get(p)!=None:
        ans+=a[p]
print(ans)
s =input()
l=[]

for i in range(1,20000000//2019+1):
    l.append(str(i*2019))

import collections

len_text = len(s)
dic = collections.defaultdict(int)
for i in range(1,7):
    for j in range(len_text-i+1):
        dic[s[j:j+i]] += 1
total = 0
for i in l:
    total += dic[i]
print(total)
S = input()
S = S[::-1]
leng = len(S)
S = int(S)

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

for i in range(leng):
    remainder = i % 2019

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

print(res)
S = input()
cnt = 0

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

print(cnt)
S = input()
S_l = len(S)
MOD = 2019
l = [set([]) for _ in range(200000)]
ans = 0


for start in range(0,S_l-3):
  for k in range(0,4):
    end = start+3+k
    if end>=S_l:
      break
    
    s = S[start:end+1]
    if int(s)%MOD==0:
      l[end].add(start)
      if start>=4:
        l[end]|=l[start-1]
        
for s in l:
  ans+=len(s)
print(ans)
S = input()
cnt = 0

if len(S) < 4:
  print(cnt)
  exit()
  
if len(S) == 4:
  if int(S) % 2019 == 0:
  	print(int(S)//2019)
  	exit()
  else:
    print(0)
    exit()

for a in range(len(S) - 4):
  d = int(S[a:a+5])
  print(d)
  if d % 2019 == 0:
    cnt += 1

print(cnt)
N = input().rstrip()
cnt=0
for i in range(len(N)-3):
  for j in range(i+4,len(N)+1):
    print(N[i:j])
    if int(N[i:j]) % 2019 == 0:
      cnt+=1
print(cnt)
S = input()
cnt = 0

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

print(cnt)
# coding: utf-8
S = input()
ans = 0
for i in range(len(S)):
    for j in range(i+4, len(S)):
        tmp = int(S[i:j])
        if tmp % 2019 == 0:
            ans += 1
print(ans)
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 = int(input())
y=0
for i in range(len(str(s))-1):
    for j in range(i+1,len(str(s))):
        p=int(str(s)[i:j])
        if p%2019==0:
            y+=1
print(y)
# 文字列を一つ入力
S = input()

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

print(res)
s = str(input())
sum_of_digits = 0
cnt = 0
for c in s:
    sum_of_digits *= 10
    sum_of_digits += int(c)
    sum_of_digits %= 2019
    if sum_of_digits == 0:
        cnt += 1
        sum_of_digits = int(c)
        
print(cnt)
from collections import defaultdict
S = input()

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

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

ans = 0
for v in d.values():
    ans += v*(v-1)//2
print(ans)
def sol():
    s = input()
    ans = 0
    for i in range(len(s)):
        for j in range(i + 1, len(s) + 1):
            tmp = s[i:j]
            print(tmp)
            if int(tmp) % 2019 == 0:
                ans += 1
    print(ans)


if __name__ == '__main__':
    sol()
S = input()
res = 0
Pow2019 = 2019**10
print(Pow2019)
for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        num = int(S[i:j])
        print(num)
        if num % 2019 == 0:
            res += 1
        if num > Pow2019:
            break
print(res)
input_str = input()

output_cnt = 0
slice_size = 2019
to_i = len(input_str) - 3
to_j = len(input_str) + 1
value_set = set()

for i in range(to_i):
  from_j = 3 + i
  for j in range(from_j, to_j):
    value_set.add(int(input_str[i : j]))

for s in value_set:
  if s % slice_size == 0:
    output_cnt += 1

print(output_cnt)
s = str(input())
ans = 0
key = 0

while key < len(s)-4:
    old_key = key
    for i in range(5+key,len(s)+1):
        local_count = 0
        val = int(s[key:i])
        if val % 2019 == 0:
            local_count += 1
            key = i-1
        ans += local_count * (local_count+1) // 2
    if key == old_key:
        key = key + 1
print(ans)
S = input()
n = len(S)
if n < 4:
    print(0)
else:
    ans = 0
    j = n
    while j > 3:
        for i in range(j - 4, -1, -1):
            x = int(S[i:j])
            if x % 2019 == 0:
                ans += 1
                j = i + 1
                break
        else:
            j -= 1
    print(ans)
## coding: UTF-8

S = input()[::-1] #文字列型で受け取る
N = len(S)
#print(S)

remainder = [0] * 2019
tmp = 0
for i in range(N):
    r = int(S[i])
    tmp += r*10**(i)
    #print(tmp%2019)
    #remainder[tmp%2019] += 1
    tmp %= 2019

    #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 = input()

r = 0
_start = 0
_len = len(S)

while _start <= _len:
    f = False
    for i in range(_start + 1, _len + 1):
        t = int(S[_start:i])
        if 1 <= t <= 200000:
            if t % 2019 == 0:
                _start = i  - 1
                r += 1
                f = True
                break
    if not f:
        _start += 1

print(r)
import collections
s = input()

l = [int(s[-1])]
d = 1
for i in range(len(s)-1, -1, -1):
  l.append((l[-1] + int(s[i])*d) % 2019)
  d *= 10
  d %= 2019

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

count += d[0]

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

m = len(n)

l = list()

c = 0

for i in range(m):
    for j in range(m-i):
        l.append(i)
        l.append(i+j+2)

for k in range(len(l)//2):
    s = n[l[2*k]:l[2*k+1]]
    s = int(s)
    if s >= 2019:
        if s % 2019 == 0:
            c += 1

print(c)
S=input()
N=len(S)
Slis=[]
for i in range(N):
  Slis+=[int(S[i])]
T=[int(S[i:]) for i in range(N)]
print(T)
MOD=[0 for i in range(2019)]
for i in range(N):
  tmp=T[i]%2019
  MOD[tmp]+=1
ans=0
for i in range(2019):
  tmp=MOD[i]
  ans+=tmp*(tmp-1)//2
print(ans)
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
compte = 0
enbas.sort()
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)
N = int(input())
a = [0] * 2050
for i in range(200010):
  a[N%2019] += 1
  N //= 10
  if N <= 0:
    break
ans = 0
for i in range(2019):
  if i == 0:
    ans += a[i] * (a[i]+1) // 2
  else:
    ans += (a[i]-1) * a[i] // 2
print(ans)
S = list(map(str,input().split()))
counter = 0
for i in range(len(S)-4):
  for j in  range(i+4,len(S)):
    part_S = list[S[i]:S[j]]
    ps = "".join(part_S)
    if int(ps) % 2019 ==0:
           counter += 1
print(counter)
# 2019 = 3 * 673
# pow(10,671,673) = 202

S = input()
X = [[0]*1000 for _ in range(3)]
X[0][0] = 1
tmp = 0
ttmp = 0
p = 1
for c in S:
    tmp = (tmp*10 + int(c))%673
    ttmp = (ttmp+int(c))%3
    X[ttmp][(tmp*p)%673] += 1
    p = (p*202)%673

ans = 0

for i in X:
    for j in i:
        if j >= 2:
            ans += j-1

print(ans)
# -*- coding: utf-8 -*-
S = input()
count = 0
list_amari = [0 for i in range(2019)]
amari_prev = 0
X = 1

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

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

print(count)
s = (input()[::-1]) # 入力文字列を逆順でsに格納
n = len(s)
counts = [0]*2019
counts[0]=1
b = 1
num = 0
for i in range(n):
    num += int(s[i])*b
    num %=2019
    b *=10
    b %2019
    counts[num]+=1

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
# print(counts)
ans = 0
for j in counts:
    ans +=j*(j-1)/2


print(ans)
S=str(input())

list2019=[]
ans=0

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

#print(' '.join(list2019))

for i in list2019:
    ans = ans+S.count(i)

print(ans)
import sys
sys.setrecursionlimit(10000000)
S = input()
ans = 0
# for i in range(len(S)-3):
#     for j in range(i+4, len(S)+1):
#         if int(S[i:j]) % 2019 == 0:
#             ans += 1
# #             break
# print(ans)
i = 0
while i < len(S)-3:
    for j in range(i+4, len(S)+1):
        if int(S[i:j]) % 2019 == 0:
            ans += 1
            i += j-5
            break
    i += 1
print(ans)
s = input()
l_2019_5 = set()
l_2019_6 = set()

for i in range(6, 50):
    if "0" not in str(2019 * i):
        l_2019_5.add(str(2019 * i))
for i in range(59, 100):
    if "0" not in str(2019 * i):
        l_2019_6.add(str(2019 * i))

ls = len(s)
if ls < 5:
    print(0)
else:
    cnt = sum(s[i : i + 5] in l_2019_5 for i in range(ls - 4))
    cnt += sum(s[i : i + 6] in l_2019_6 for i in range(ls - 5))
    print(cnt)
s = input()
ans = 0

for i in range(957):
    ans += s.count(str(2019*i))

print(ans)
S = input()
N = len(S)
c = []
i = 1
while 2019 * i < 2 * 10**5:
    c.append(2019 * i)
    i += 1

ans = 0
for i in range(3):
    for j in range(N - 3 - i):
        if int(S[j:j + 4 + i]) in c:
            ans += 1
print(ans)
nn = input()
c = 0
i = 1
nnn = 0

while len(str(nnn)) < 6:
    nnn = str(2019 * i)
    if int(nnn) >= int(nn):
        break
    i+=1

    if nnn in nn:
        c+=sum([nn[k:k+len(nnn)]==nnn for k in range(0, len(nn)-len(nnn)+1)])
print(c)
S = input()
N = len(S)
ans = 0
for i in range(0, N - 3):
    j = i + 4
    while j <= N:
        if int(S[i: j]) % 2019 == 0:
            ans += 1
            break
        else:
            if j - i == 4:
                j += 1
            else:
                break
print(ans)
s = input()

m = []

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


cnt = 0


for i in m:
	for k in range(len(s)):
		if s[k] == i[0]:
			if  i == s[k:k+len(i)]:
				# print(i,s[k:k+len(i)])
				cnt += 1

print(cnt)
S = input()
cnt = 0

if len(S) < 4:
  print('x')
  print(cnt)
  exit()
  
if len(S) == 4:
  print(int(S)//2019)
  exit()

for a in range(len(S) - 4):
  d = int(S[a:a+5])
  print(d)
  if d % 2019 == 0:
    cnt += 1

print(cnt)
s = input()
l = len(s)
t = [0] * l
t[l - 1] = int(s[l - 1])
m = [0] * 2019
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
    ans += m[t[i - 1]]
    m[t[i - 1]] += 1
    if t[i - 1] == 0:
        ans += 1

print(t, ans)
from scipy.special import comb
from collections import Counter, deque

D = deque(map(int, list(input())))
a = {}
value = 0

for i in range(len(D)):
    value = value + D.pop() * 10**i
    modulo = value % 2019
   # print(modulo)
    if modulo in a.keys():
        a[modulo] += 1
    else:
        a[modulo] = 1


b = [comb(i, 2, exact=True) for i in a.values() if i > 1]
#print(b)
print(sum(b))
import sys
input = sys.stdin.readline

s = input()
l = len(s)
cnt = 0

for i in range(3,l):
    for j in range(i):
        num = int(s[j:i+1])
        if num % 2019 == 0:
            cnt += 1
print(cnt)
from collections import deque
import time

#start = time.time()#計測始
s = str(input()[::-1])
n=len(s)
mlist=deque([0])
slist=0
d=1
  
for ss in s:
  slist += int(ss) * d
  m = slist % 2019
  d *= 10
  mlist.append(m)
ll=len(mlist)
l=len(set(mlist))
#end = time.time()#計測終
print(ll-l)
#print(f"{end-start}sec.")#計測出力
S = input()
mod2019 = [0]*(len(S)+1)

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

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


for i in range(len(S)):
    answer += count[mod2019[i]]
    count[mod2019[i]] += 1
print(answer)
S=input()
N=len(S)
A=[]
cnt=0

for n in range(1,100):
    if '0' not in str(2019*n): 
        A.append(n*2019)

for st in A:
    st=str(st)
    for i in range(N-len(st)+1):
        if S[i:i+len(st)]==st:
            cnt+=1

print(cnt)
s = input()
c = 0
for i in range(len(s)):
    for j in range(i+4,len(s)+1):
        a = int(s[i:j])
        print(a)
        if a>2019:
            if a%2019==0:
                c+=1
print(c)
S = input()

l_2019 =[i*2019 for i in range(1,100)]

ans = 0
for i in l_2019:
    ans += S.count(str(i))

print(ans)
S = str(input())
li = [0] * 2019
ans = 0

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  if s == 0:
    ans += 1
  else:
    li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)
s = input()

count=0

for i in range(len(s)):
    for j in range(i,len(s)):
        print(s[i:j+1])
        if int(s[i:j+1])%2019 == 0 and int(s[i:j+1])!=0:
            count+=1
            #print(i,j)


print(count)
s = input()
sl = len(s)
num = str()
n = 0
ans = 0

for i in range(0,sl-3):
    for j in range(i+3,sl+1):
        num = s[i:j]
        print(num)
        n = int(num)
        if n%2019 == 0:
            ans+=1
print(ans)
num=input()
length = len(num)
count=0

bai=list(range(2019,200000,2019))

for i in range(len(bai)):
   if  str(bai[i]) in str(num):
      count+=1
print(count)
from collections import Counter

S = input()
#S = "1"*20000

p = 2019
N = len(S)

m = [(int(S[i]) * pow(10, N-i, p)) % p for i in range(N)]

# m の mod 累積和
r = [0] * N
r[0] = m[0]
for ri in range(1, N):
    r[ri] = (r[ri-1] + m[ri]) % p

# この r[i] が一致するような区間が答えになるのでこれをもとめる
c = Counter(r)

ans = 0
for ci in [cv for cv in c.values() if cv >= 2]:
    ans += ci * (ci-1) // 2

if 0 in c.keys():
    ans += 1

print(ans)
s=input()
s=s[::-1]
n=len(s)
count=[0]*2019
num,d=0,1

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

ans=0
for i in count:
  ans+=i*(i-1)//2
  
print(ans)
import re

S = str(input())

def count_o(sub, string):
    # via https://www.geeksforgeeks.org/python-count-overlapping-substring-in-a-given-string/
    count = 0
    start = 0
    while start < len(string):
        pos = string.find(sub, start)
        if pos != -1:
            start = pos + 1
            count += 1
        else:
            break
    return count

count = 0
for i in range(1, 100):
    j = str(i * 2019)
    if j not in S:
        continue
    count += count_o(j, S)

print(count)