Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
follow = 0
POW = 1

for i in range(N):
  Amari_ = (int(S[N-i-1]) * POW + follow) % 2019
  amari[Amari_] += 1
  follow = Amari_
  POW *= 10
  
ans = sum(list( i * (i-1)//2 for i in amari ))
ans += amari[0]

print(ans)

Fixed submission:
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)


ans = 0
amari = [0] * 2019
follow = 0

for i in range(N):
  Amari_ = (int(S[N-i-1]) * pow(10, i) + follow) % 2019
  amari[Amari_] += 1
  follow = Amari_
  
ans = sum(list( i * (i-1)//2 for i in amari ))
ans += amari[0]

print(ans)

Fixed submission:
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
follow = 0

for i in range(N):
  Amari_ = (int(S[N-i-1]) * pow(10, i) + follow) % 2019
  #ans += amari[Amari_]
  amari[Amari_] += 1
  follow = Amari_
  
ans = sum(list( i * (i-1)//2 for i in amari ))
ans += amari[0]

print(ans)

Fixed submission:
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
follow = 0
for i in range(N):
  Amari_ = (int(S[N-i-1]) * pow(10, i) + follow) % 2019
  ans += amari[Amari_]
  amari[Amari_] += 1
  follow = Amari_
ans += amari[0]

print(ans)

Fixed submission:
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
follow = 0
for i in range(N):
  Amari_ = (int(S[N-i-1]) * pow(10, i) + follow) % 2019
  ans += amari[Amari_]
  amari[Amari_] += 1
  follow = Amari_
  if Amari_ == 0:
    ans += 1

print(ans)

Fixed submission:
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
follow = 0
for i in range(N):
  Amari_ = (int(int(S[N-i-1]) * pow(10, i)) + follow) % 2019
  amari[Amari_] += 1
  follow = Amari_
  if Amari_ == 0:
    ans += 1
  
for a in amari:
  ans += a * (a - 1) // 2
print(ans)

Fixed submission:
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)
l = 0
r = 0


follow = 0
amari = [0] * N
for i in range(N):
  Kazu = int(S[N-i-1]) * pow(10, i)
  Amari_ = (int(Kazu) + follow) % 2019
  amari[i] = Amari_
  follow = Amari_

from collections import Counter
c_ = Counter(amari)
c = c_.most_common()

ans = 0
for i in c:
  if i[1] != 0:
    ans += i[1] * (i[1]-1) // 2
  else:
    break

ans += c_[0]
print(ans)

Fixed submission:
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)
l = 0
r = 0


follow = 0
amari = [0] * N
for i in range(N):
  Kazu = int(S[N-i-1]) * pow(10, i)
  Amari_ = (int(Kazu) + follow) % 2019
  amari[i] = Amari_
  follow = Amari_
  

from collections import Counter
c = Counter(amari).most_common()

ans = 0
for i in c:
  if i[1] != 0:
    ans += i[1] * (i[1]-1) // 2
  if i[0] == 0:
    ans += i[1]
print(ans)

Fixed submission:
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)
l = 0
r = 0

amari = [0] * N
for i in range(1, N+1):
  kazu = S[N-i:N]
  amari_ = int(kazu) % 2019
  amari[i-1] = amari_

from collections import Counter
c = Counter(amari).most_common()

ans = 0
for i in c:
  if i[1] != 0:
    ans += i[1] * (i[1]-1) // 2
  if i[0] == 0:
    ans += i[1]
print(ans)

Fixed submission:
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [ input() for _ in range(N) ]
print(len(set(S)))

Fixed submission:
S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))