Buggy python submission (verdict: Time Limit Exceeded):
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)


Fixed submission:
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num = 0
for i in range(len(S)):
    num += (10**i)*int(s_rev[i])
    num %= 2019
    r_list[num] += 1

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)


Fixed submission:
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
m = len(S)
num = 0
for i in range(len(S)):
    num += (10**i)*int(s_rev[i])
    r_list[num % 2019] += 1

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)


Fixed submission:
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
m = len(S)
num = 0
for i in range(len(S)):
    num += (10**i)*int(s_rev[i])
    r_list[num % 2019] += 1

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)


Fixed submission:
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

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

r_list = [0] * 2019
r_list[0] = 1
m = len(S)
for i in range(1,m+1):
    r_list[int(S[m-i:]) % 2019] += 1

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)


Fixed submission:
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

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

r_list = [0] * 2019
r_list[0 % 2019] += 1
m = len(S)
for i in range(1,m+1):
    r_list[int(S[m-i:]) % 2019] += 1

ans = r_list[0] - 1
for i in range(1,2019):
    if r_list[i] >= 2:
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)


Fixed submission:
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

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

r_list = [0 for _ in range(2019)]
r_list[0 % 2019] += 1
m = len(S)
for i in range(1,m+1):
    r_list[int(S[m-i:]) % 2019] += 1

ans = r_list[0] - 1
for i in range(1,2019):
    if r_list[i] >= 2:
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)


Fixed submission:
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

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

r_list = [0 for _ in range(2019)]
r_list[0 % 2019] += 1
for i in range(1,len(S)+1):
    r_list[int(S[len(S)-i:]) % 2019] += 1

ans = r_list[0] - 1
for i in range(1,2019):
    if r_list[i] >= 2:
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)


Fixed submission:
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

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

r_list = [0 for _ in range(2019)]
r_list[0 % 2019] += 1
for i in range(1,len(S)+1):
    r_list[int(S[len(S)-i:]) % 2019] += 1

ans = r_list[0] - 1
for i in range(1,2019):
    if r_list[i] >= 2:
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)


Fixed submission:
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

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

S_sum = [0]
r_list = [0 for _ in range(2019)]
for i in range(1,len(S)+1):
    S_sum.append(int(S[len(S)-i:]))
#print(S_sum)

for i in range(len(S_sum)): 
    r_list[S_sum[i] % 2019] += 1 

ans = r_list[0] - 1
for i in range(1,2019):
    if r_list[i] >= 2:
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

Fixed submission:
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

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

S_sum = [0]
r_list = [0 for _ in range(2019)]
for i in range(1,len(S)+1):
    S_sum.append(int(S[len(S)-i:]))
#print(S_sum)

for i in range(len(S_sum)): 
    r_list[S_sum[i] % 2019] += 1 

ans = r_list[0] - 1
for i in range(1,2019):
    if r_list[i] >= 2:
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

Fixed submission:
S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)