Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
input = sys.stdin.readline
 
S = input().strip()
l = len(S)
dp = np.zeros((l, 2019), dtype=int)
for i in range(l):
    s = int(S[i])
    for j in range(2019):
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
    dp[i][s] += 1
 
print(dp[:, 0].sum())

Fixed submission:
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
input = sys.stdin.readline
 
S = input().strip()
l = len(S)
dp = [[0 for _ in range(2019)] for i in range(l)]
dp = np.zeros((l, 2019), dtype=int)
for i in range(l):
    s = int(S[i])
    for j in range(2019):
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
    dp[i][s] += 1
 
print(dp[:, 0].sum())

Fixed submission:
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
dp = [[0 for _ in range(2019)] for i in range(l)]
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)



Fixed submission:
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
dp = [[0 for _ in range(2019)] for i in range(l)]
ans = 0
mod = 0
for i in range(0, l):
    s = int(S[i:])
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)



Fixed submission:
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input()
l = len(S)
no_zero_dic = {}
dp = [[0] * (2019) for i in range(l)]
ans = 0
for i in range(l):
    s = int(S[i])
    no_zero_dic[s] = 1
    _x = set(no_zero_dic.keys())
    for j in _x:
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
        if dp[i-1][j] > 0:
            no_zero_dic[k] = 1
        if k == 0:
            ans += dp[i][k]
    dp[i][s] += 1


print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input()
l = len(S)
no_zero_dic = {}
dp = [[0] * (2019) for i in range(l)]
ans = 0
for i in range(l):
    s = int(S[i])
    no_zero_dic[s] = 1
    _x = set(no_zero_dic.keys())
    for j in _x:
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
        if dp[i-1][j] > 0:
            no_zero_dic[k] = 1
        if k == 0:
            ans += dp[i][k]
    dp[i][s] += 1


print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input()
l = len(S)
no_zero_dic = {}
dp = [[0 for _ in range(2019)] for i in range(l)]
ans = 0
for i in range(l):
    s = int(S[i])
    no_zero_dic[s] = 1
    _x = set(no_zero_dic.keys())
    for j in _x:
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
        if dp[i-1][j] > 0:
            no_zero_dic[k] = 1
        if k == 0:
            ans += dp[i][k]
    dp[i][s] += 1


print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import defaultdict

S = input().strip()
l = len(S)
no_zero_dic = {}
dp = [[0 for _ in range(2019)] for i in range(l)]
ans = 0
for i in range(l):
    s = int(S[i])
    no_zero_dic[s] = 1
    _x = set(no_zero_dic.keys())
    for j in _x:
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
        if dp[i-1][j] > 0:
            no_zero_dic[k] = 1
        if k == 0:
            ans += dp[i][k]
    dp[i][s] += 1


print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import defaultdict

S = input().strip()
l = len(S)
dp = [[0 for _ in range(2019)] for i in range(l)]
for i in range(l):
    s = int(S[i])
    for j in range(2019):
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
    dp[i][s] += 1

ans = 0
for i in range(l):
    ans += dp[i][0]
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import defaultdict

S = input().strip()
l = len(S)
dp = [[0 for _ in range(2019)] for i in range(l)]
for i in range(l):
    s = int(S[i])
    for j in range(2019):
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
    dp[i][s] += 1

ans = 0
for i in range(l):
    ans += dp[i][0]
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)