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

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N + 1):
    now += (int(S[N - i - 1]) * (10**i)) % 2019
    map_[now % 2019] += 1
    ans += map_[now % 2019]

print(ans)


Fixed submission:
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)

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

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N + 1):
    now += int(S[N - i - 1]) * (10**i)
    map_[now % 2019] += 1
    ans += map_[now % 2019]

print(ans)


Fixed submission:
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)

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

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N + 1):
    now += int(S[N - i - 1]) * (10**i)
    map_[now % 2019] += 1
    ans += map_[now % 2019]

print(ans)


Fixed submission:
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)

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

map_ = [-1] * 2019
map_[0] = 0
ans = 0

for i in range(1, N + 1):
    temp = S % (10**i)
    map_[temp % 2019] += 1
    ans += map_[temp % 2019]

print(ans)


Fixed submission:
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)

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

map_ = [-1] * 2019
map_[0] = 0
ans = 0

for i in range(1, len(S) + 1):
    temp = int(S[len(S) - i:])
    map_[temp % 2019] += 1
    ans += map_[temp % 2019]

print(ans)


Fixed submission:
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)

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

map_ = [-1] * 2019
map_[0] = 0
ans = 0

for i in range(1, len(S) + 1):
    temp = int(S[len(S) - i:])
    map_[temp % 2019] += 1
    ans += map_[temp % 2019]

print(ans)


Fixed submission:
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)

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

ans = []
for left in range(len(S)):
    for right in range(left + 5, len(S) + 1):
        temp = int(S[left:right])
        if temp % 2019 == 0:
            ans.append([left, right])

print(len(ans))


Fixed submission:
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)