Buggy python submission (verdict: Time Limit Exceeded):
mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10 % mod

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

print(ans)

Fixed submission:
mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10
  w %= mod

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

v=0
w=1

for i in range(N):
  u=int(a[N-1-i]) * w + v
  v=u % mod
  t[v] += 1
  w *=10 % mod

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

print(ans)

Fixed submission:
mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10
  w %= mod

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#A,B,C,D=map(int,input().split(" "))

import collections

mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1
ans=0
v=0
w=1

for i in range(N):
  u=int(a[N-1-i]) * w + v
  v=u % mod
  w *=10 % mod
  t[v] += 1
  
#tt = collections.Counter(t)

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

print(ans)

Fixed submission:
mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10
  w %= mod

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#A,B,C,D=map(int,input().split(" "))

import collections

mod=2019
a=input()

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

for i in range(N):
  u=int(a[i::])
  v=u % mod
  t[v] += 1
  
#tt = collections.Counter(t)

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

print(ans)

Fixed submission:
mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10
  w %= mod

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#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():
  ans += (i-1)*i//2

z=t.count(0)
if z>0:
  ans += (z-1)*z//2 + z

print(ans)

Fixed submission:
mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10
  w %= mod

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#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)


Fixed submission:
mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10
  w %= mod

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#A,B,C,D=map(int,input().split(" "))

mod=2019
a=input()

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

for i in range(N):
  for j in range(i+1,N+1):
    u=int(a[i:j])
    #print(u)
    if (u % mod)==0:
      ans+=1
      #print(i+1,j)
      break
print(ans)


Fixed submission:
mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10
  w %= mod

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#A,B,C,D=map(int,input().split(" "))

mod=2019
a=input()

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

for i in range(N):
  for j in range(i+1,N+1):
    u=int(a[i:j])
    #print(u)
    if (u % mod)==0:
      ans+=1
      #print(i+1,j)
      i=j

print(ans)


Fixed submission:
mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10
  w %= mod

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#A,B,C,D=map(int,input().split(" "))

mod=2019
a=input()

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

for i in range(N):
  for j in range(i+1,N+1):
    u=int(a[i:j])
    #print(u)
    if (u % mod)==0:
      ans+=1
      #print(i+1,j)

print(ans)


Fixed submission:
mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10
  w %= mod

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

print(ans)