Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2


print(int(counter))

Fixed submission:
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10
    d %= 2019


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2


print(int(counter))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019

s,d = 0,1

for i in S:
    if i == 0:
        s += i *d
        d *= 10

    else:
        s += i *d
        amari[s%2019] += 1
        d *= 10


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2

counter += amari[0]

print(int(counter))

Fixed submission:
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10
    d %= 2019


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2


print(int(counter))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,input()))

counter = 0
amari = [0]*2019

s = 0
for i in range(len(S)):
    if S[len(S)-i-1] == 0:
        continue
    else:
        s += S[len(S)-i-1] * 10**i
        s = s % 2019
        amari[s] += 1

for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2

counter += amari[0]

print(int(counter))

Fixed submission:
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10
    d %= 2019


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2


print(int(counter))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int,input()))

counter = 0
amari = [0]*2019

s = 0
for i in range(len(S)):
    if S[len(S)-i-1] == 0:
        continue
    else:
        s += S[len(S)-i-1] * 10**i
        amari[s % 2019] += 1

for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2

counter += amari[0]

print(int(counter))

Fixed submission:
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10
    d %= 2019


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2


print(int(counter))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(str,input()))

counter = 0
amari = [0]*2019

s = 0
for i in range(len(S)):
    if S[len(S)-i-1] == "0":
        continue
    else:
        s += int(S[len(S)-i-1]) * 10**i
        amari[s % 2019] += 1

for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2

counter += amari[0]

print(int(counter))

Fixed submission:
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10
    d %= 2019


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2


print(int(counter))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(str,input()))

counter = 0

for i in range(len(S)):
    for j in range(1,len(S)-i):
        s = int("".join(S[i:i+j+1]))
        if s % 2019 == 0:
            counter += 1

print(counter)

Fixed submission:
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10
    d %= 2019


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2


print(int(counter))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

S = list(map(str,input()))

counter = 0

set = list(itertools.combinations(range(len(S)),2))

for i in range(len(set)):
    s = int("".join(S[int(set[i][0]):int(set[i][1])+1]))
    if s % 2019 == 0:
        counter += 1

print(counter)

Fixed submission:
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10
    d %= 2019


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2


print(int(counter))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(str,input()))

counter = 0

for i in range(len(S)):
    for j in range(i+3,len(S)):
        s = int("".join(S[i:j+1]))
        if s % 2019 == 0:
            counter += 1

print(counter)


Fixed submission:
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10
    d %= 2019


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2


print(int(counter))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(str,input()))

counter = 0

for i in range(len(S)):
    for j in range(i,len(S)):
        s = int("".join(S[i:j+1]))
        if s % 2019 == 0:
            counter += 1

print(counter)


Fixed submission:
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10
    d %= 2019


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2


print(int(counter))