Buggy python submission (verdict: Runtime Error):
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [-1] * len(S)
r = 0
d = 1
for i,s in enumerate(S[::-1]):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[i] = r

ans = 0
c = Counter(p)
for k,n in c.most_common():
  if n > 1 ans n%2 == 0:
    ans += n//2
  else:break
print(ans)

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d *= 10%mod
  p[r] += 1

#p.append(0)
#ans = 0
#c = Counter(p)
#for k,n in c.most_common():
#  if n > 1:
#    ans += 1
#  else:break
  
print(sum([i*(i-1)//2 for i in p]))


Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d *= 10%mod
  p[r] += 1

#p.append(0)
#ans = 0
#c = Counter(p)
#for k,n in c.most_common():
#  if n > 1:
#    ans += 1
#  else:break
  
print(sum([i*(i-1)//2 for i in p]))

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in S[::-1]:
  t = int(s)%mod
  r += t*d
  r %= mod
  d *= 10%mod
  p[r] += 1

#p.append(0)
#ans = 0
#c = Counter(p)
#for k,n in c.most_common():
#  if n > 1:
#    ans += 1
#  else:break
  
print(sum([i*(i-1)//2 for i in p]))


Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  t *= d
  r += t
  r %= mod
  d *= 10
  p[r] += 1

#p.append(0)
#ans = 0
#c = Counter(p)
#for k,n in c.most_common():
#  if n > 1:
#    ans += 1
#  else:break
  
print(sum([i*(i-1)//2 for i in p]))

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in S[::-1]:
  t = int(s)%mod
  t *= d
  r += t
  r %= mod
  d *= 10
  p[r] += 1

#p.append(0)
#ans = 0
#c = Counter(p)
#for k,n in c.most_common():
#  if n > 1:
#    ans += 1
#  else:break
  
print(sum([i*(i-1)//2 for i in p]))

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
for i,s in enumerate(S[::-1]):
  t = int(s)%mod
  t *= (10**i)%mod
  r += t
  r %= mod
  p[r] += 1

#p.append(0)
#ans = 0
#c = Counter(p)
#for k,n in c.most_common():
#  if n > 1:
#    ans += 1
#  else:break
  
print(sum([i*(i-1)//2 for i in p]))


Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
mod = 2019
p = [0] * len(S)
r = 0
for i,s in enumerate(S[::-1]):
  t = int(s)%mod
  t *= (10**i)%mod
  r += t
  p[i] = r%mod

p.append(0)
ans = 0
c = Counter(p)
for k,n in c.most_common():
  if n > 1:
    ans += 1
  else:break
  
print(ans)

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
mod = 2019
p = [0] * len(S)
r = 0
for i,s in enumerate(S[::-1]):
  t = int(s)%mod
  t *= (10**i)%mod
  r += t
  p[i] = r%mod

p.append(0)
ans = 0
c = Counter(p)
for k in c:
  if c[k] > 1:
    ans += 1
print(ans)

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in S[::-1]:
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
for i,s in enumerate(S[::-1]):
  t = int(s)%mod
  d = (10**i)%mod
  r += t*d
  r %= mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
mod = 2019
p = [0] * len(S)
r = 0
for i,s in enumerate(S[::-1]):
  t = int(s)%mod
  d = (10**i)%mod
  r += t*d
  p[i] = r%mod

p.append(0)
ans = 0
c = Counter(p)
for k,n in c.most_common():
  if n > 1:
    ans += 1
  else:break
  
print(ans)

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
mod = 2019
p = [0] * len(S)
r = 0
for i,s in enumerate(S[::-1]):
  r += (int(s) * (10**i))%mod
  p[i] = r%mod

p.append(0)
ans = 0
c = Counter(p)
for k,n in c.most_common():
  if n > 1:
    ans += 1
  else:break
  
print(ans)

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
mod = 2019
p = [0] * len(S)
r = 0
for i,s in enumerate(S[::-1]):
  r += (int(s) * (10**i))%mod
  p[i] = r%mod

p.append(0)
ans = 0
c = Counter(p)
for k in c:
  if c[k] > 1:
    ans += 1
print(ans)

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
N = (int(s)//2019) + 1
ans = 0
P = [0] * N
for i in range(N):
  P[i] = str(i*2019)

for p in P:
  k = s.find(p)
  if k != -1:
    ans += 1
    while k >= 0:
      k = s[k+1:].find(p)
      if k != -1:ans += 1

print(ans)

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = 0

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

print(ans)

Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Runtime Error):
s = input()
n = (int(s)//2019) + 1
ans = 0
p = [0] * (n+1)
for i in range(1,n+1):
  p[i] = (2019 * i)

for j in p:
  ss = s
  while len(ss) > 0:
    idx = ss.find(str(j))
    if idx == -1:
      break
    else:
      ans += 1
      ss = ss[idx+1:]

print(ans)


Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))

Buggy python submission (verdict: Runtime Error):
s = input()
n = (int(s)//2019) + 1
ans = 0
p = [0] * (n+1)
for i in range(n+1):
  p[i] = (2019 * i)

for j in p:
  ss = s
  while len(ss) > 0:
    idx = ss.find(str(j))
    if idx == -1:
      break
    else:
      ans += 1
      ss = ss[idx+1:]


print(ans)


Fixed submission:
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))