Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s = s[::-1]
n = len(s)

num = [0]*2019
num[0] = 1
number = 0
d = 1

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

ans = 0

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

print(ans)

Fixed submission:
s=input()
s=s[::-1]
n=len(s)

count=[0]*2019
count[0]=1
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)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s = s[::-1]
n = len(s)

num = [0]*2019
num[0] = 1
number = 0
d = 1

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

ans = 0

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

print(ans)

Fixed submission:
s=input()
s=s[::-1]
n=len(s)

count=[0]*2019
count[0]=1
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)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s = s[::-1]
n = len(s)

num = [0]*2019
num[0] = 1
number = 0
d = 1

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

ans = 0

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

print(ans)

Fixed submission:
s=input()
s=s[::-1]
n=len(s)

count=[0]*2019
count[0]=1
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)

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

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

for i in range(n):
    number = int(s[i:])
    num[number%2019] += 1

ans = 0

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

print(ans)

Fixed submission:
s=input()
s=s[::-1]
n=len(s)

count=[0]*2019
count[0]=1
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)

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

num = [0]
ans = 0

for i in range(n):
    a = int(s[-i-1:])
    a = a% 2019
    num.append(a)
    b = num[:-1]
    ans += b.count(a)

print(ans)

Fixed submission:
s=input()
s=s[::-1]
n=len(s)

count=[0]*2019
count[0]=1
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)

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

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

for i in range(n):
    number = int(s[i:])
    num[number%2019] += 1

ans = 0

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

print(ans)

Fixed submission:
s=input()
s=s[::-1]
n=len(s)

count=[0]*2019
count[0]=1
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)

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

num = []

for i in range(n):
    number = int(s[i:])
    num.append(number%2019)

num.append(0)

ans = 0

for i in range(len(num)):
    a = num[i]
    b = num[i+1:]
    ans += b.count(a)

print(ans)

Fixed submission:
s=input()
s=s[::-1]
n=len(s)

count=[0]*2019
count[0]=1
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)

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

count = 0

for i in range(n-3):
    for j in range(i, n):
        number = int(s[i:j+1])
        if number % 2019 == 0:
            count += 1

print(count)

Fixed submission:
s=input()
s=s[::-1]
n=len(s)

count=[0]*2019
count[0]=1
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)