Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now += i*int(c)
    i *= 10
    dp[now%2019] += 1

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))


Fixed submission:
s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now = (now+i*int(c))%2019
    dp[now] += 1
    i *= 10
    i %= 2019

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1]
n = len(s)
dp = [1] + [0]*2018
now = 0
 
for i in range(n):
    now += 10**i * int(s[i])
    dp[now%2019] += 1
 
ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))

Fixed submission:
s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now = (now+i*int(c))%2019
    dp[now] += 1
    i *= 10
    i %= 2019

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1]
n = len(s)
dp = [1] + [0]*2018
now = 0

for i in range(n):
    now += 10**i * int(s[i])
    tmp = now % 2019
    dp[tmp] += 1

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))


Fixed submission:
s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now = (now+i*int(c))%2019
    dp[now] += 1
    i *= 10
    i %= 2019

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))

Buggy python submission (verdict: Runtime Error):
s = list(input())
s = s[::-1]
s = ''.join(s)
n = len(s)
dp = [0]*2018
now = 0

dp[0] = 1
for i in range(n):
    now += 10**i * int(s[i])
    tmp = now % 2019
    dp[tmp] += 1

ans = sum([i*(i-1)/2 for i in dp if i > 1])
print(int(ans))


Fixed submission:
s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now = (now+i*int(c))%2019
    dp[now] += 1
    i *= 10
    i %= 2019

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))

Buggy python submission (verdict: Runtime Error):
s = input()[::-1]
n = len(s)
dp = [0]*2018
now = 0

dp[0] = 1
for i in range(n):
    now += 10**i * int(s[i])
    tmp = now % 2019
    dp[tmp] += 1

ans = sum([i*(i-1)/2 for i in dp if i > 1])
print(int(ans))


Fixed submission:
s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now = (now+i*int(c))%2019
    dp[now] += 1
    i *= 10
    i %= 2019

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))

Buggy python submission (verdict: Runtime Error):
s = input()[::-1]
n = len(s)
dp = [0]*2018
now = 0

dp[0] = 1
for i in range(n):
    now += 10**i * int(s[i])
    tmp = now % 2019
    dp[tmp] += 1

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

print(int(ans))


Fixed submission:
s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now = (now+i*int(c))%2019
    dp[now] += 1
    i *= 10
    i %= 2019

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = 0
ans = sum([sum([1 for j in range(n-i+1) if int(s[j:j+i])%2019 == 0]) for i in range(4, n)])
print(ans)

Fixed submission:
s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now = (now+i*int(c))%2019
    dp[now] += 1
    i *= 10
    i %= 2019

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = 0
for i in range(4, n):
    ans += len([1 for j in range(n-i+1) if int(s[j:j+i])%2019 == 0])
print(ans)

Fixed submission:
s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now = (now+i*int(c))%2019
    dp[now] += 1
    i *= 10
    i %= 2019

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = 0
for i in range(4, n):
    for j in range(n-i+1):
        if int(s[j:j+i])%2019 == 0:
            ans += 1
print(ans)


Fixed submission:
s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now = (now+i*int(c))%2019
    dp[now] += 1
    i *= 10
    i %= 2019

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))