Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * 10**i % 2019) % 2019
    lst.append(_sum)
    
C = Counter(lst)    
ans = C[0]

for i in C:
    ans += C[i]*(C[i]-1)//2
print(ans)    


Fixed submission:
from collections import Counter

S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * pow(10,i,2019)) % 2019
    lst.append(_sum)
    
C = Counter(lst)    
ans = C[0]

for i in C:
    ans += C[i]*(C[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * 10**i % 2019) % 2019
    lst.append(_sum)
    
ans = lst.count(0)
for i in set(lst):
    c = lst.count(i)
    ans += c*(c-1)//2
   
print(ans)    



Fixed submission:
from collections import Counter

S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * pow(10,i,2019)) % 2019
    lst.append(_sum)
    
C = Counter(lst)    
ans = C[0]

for i in C:
    ans += C[i]*(C[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
lst = []

for i in range(len(S)):
    lst.append(int(S[-1-i:]) % 2019)
    
ans = lst.count(0)
for i in set(lst):
    c = lst.count(i)
    ans += c*(c-1)//2
    
print(ans)    



Fixed submission:
from collections import Counter

S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * pow(10,i,2019)) % 2019
    lst.append(_sum)
    
C = Counter(lst)    
ans = C[0]

for i in C:
    ans += C[i]*(C[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + int(S[-1-i]) * 10**i % 2019) % 2019
    lst.append(_sum)
    
ans = lst.count(0)
for i in set(lst):
    c = lst.count(i)
    ans += c*(c-1)//2
    
print(ans)    



Fixed submission:
from collections import Counter

S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * pow(10,i,2019)) % 2019
    lst.append(_sum)
    
C = Counter(lst)    
ans = C[0]

for i in C:
    ans += C[i]*(C[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + int(S[-1-i]) * 10**i % 2019) % 2019
    lst.append(_sum)
    
ans = lst.count(0)
for i in set(lst):
    c = lst.count(i)
    ans += c*(c-1)//2
    
print(ans)    



Fixed submission:
from collections import Counter

S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * pow(10,i,2019)) % 2019
    lst.append(_sum)
    
C = Counter(lst)    
ans = C[0]

for i in C:
    ans += C[i]*(C[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
cnt = 0
S = input()  
for left in range(len(S)-3):
    int_s = int(S[left:left+4])
    
    if int_s % 2019 == 0:
        cnt += 1
    for right in range(left+4,len(S)):
        int_s = int_s * 10 + int(S[right])
        if int_s % 2019 == 0:
            cnt += 1
print(cnt)        



Fixed submission:
from collections import Counter

S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * pow(10,i,2019)) % 2019
    lst.append(_sum)
    
C = Counter(lst)    
ans = C[0]

for i in C:
    ans += C[i]*(C[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
cnt = 0
S = input()  
for left in range(len(S)-3):
    for right in range(left+3,len(S)):
        ss = S[left:right+1]
        if int(ss) < 2019:
            continue
        sum = 0
        for i in ss:
            sum += int(i)
        if sum % 3 != 0:
            continue
        if int(ss) % 2019 == 0:
            cnt += 1
print(cnt)  


Fixed submission:
from collections import Counter

S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * pow(10,i,2019)) % 2019
    lst.append(_sum)
    
C = Counter(lst)    
ans = C[0]

for i in C:
    ans += C[i]*(C[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
cnt = 0
S = input()  
for left in range(len(S)-3):
    for right in range(left+3,len(S)):
        if int(S[left:right+1]) < 2019:
            continue
        if int(S[left:right+1]) % 2019 == 0:
            cnt += 1
print(cnt) 

Fixed submission:
from collections import Counter

S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * pow(10,i,2019)) % 2019
    lst.append(_sum)
    
C = Counter(lst)    
ans = C[0]

for i in C:
    ans += C[i]*(C[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
cnt = 0
S = input()  
for left in range(len(S)-3):
    for right in range(left+3,len(S)):
        if int(S[left:right+1]) % 2019 == 0:
            cnt += 1
print(cnt)

Fixed submission:
from collections import Counter

S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * pow(10,i,2019)) % 2019
    lst.append(_sum)
    
C = Counter(lst)    
ans = C[0]

for i in C:
    ans += C[i]*(C[i]-1)//2
print(ans)