Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
table = [int(s[i:]) % 2019 for i in range(n)]+[0]
count = [0 for _ in range(2019)]
ans = 0
for t in table:
    if count[t] != 0:
        ans += count[t]
    count[t] += 1
print(ans)


Fixed submission:
s = input()
n = len(s)
table = [0 for _ in range(n + 1)]
for i in range(n):
    table[-2 - i] = (int(s[-1 - i]) * pow(10, i, 2019) + table[-1 - i]) % 2019
count = [0 for _ in range(2019)]
ans = 0
for t in table:
    if count[t] != 0:
        ans += count[t]
    count[t] += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a = [1, 10, 100, 1000, 1924, 1069, 595, 1912, 949, 1414, 7, 70, 700, 943, 1354, 1426, 127, 1270, 586, 1822, 49, 490,
     862, 544, 1402, 1906, 889, 814, 64, 640, 343, 1411, 1996, 1789, 1738, 1228, 166, 1660, 448, 442, 382, 1801, 1858,
     409, 52, 520, 1162, 1525, 1117, 1075, 655, 493, 892, 844, 364, 1621, 58, 580, 1762, 1468, 547, 1432, 187, 1870,
     529, 1252, 406, 22, 220, 181, 1810, 1948, 1309, 976, 1684, 688, 823, 154, 1540, 1267, 556, 1522, 1087, 775, 1693,
     778, 1723, 1078, 685, 793, 1873, 559, 1552, 1387, 1756, 1408, 1966, 1489, 757, 1513, 997, 1894, 769, 1633, 178,
     1780, 1648, 328, 1261, 496, 922, 1144, 1345, 1336, 1246, 346, 1441, 277, 751, 1453, 397, 1951, 1339, 1276, 646,
     403, 2011, 1939, 1219, 76, 760, 1543, 1297, 856, 484, 802, 1963, 1459, 457, 532, 1282, 706, 1003, 1954, 1369, 1576,
     1627, 118, 1180, 1705, 898, 904, 964, 1564, 1507, 937, 1294, 826, 184, 1840, 229, 271, 691, 853, 454, 502, 982,
     1744, 1288, 766, 1603, 1897, 799, 1933, 1159, 1495, 817, 94, 940, 1324, 1126, 1165, 1555, 1417, 37, 370, 1681, 658,
     523, 1192, 1825, 79, 790, 1843, 259, 571, 1672, 568, 1642, 268, 661, 553, 1492, 787, 1813, 1978, 1609, 1957, 1399,
     1876, 589, 1852, 349, 1471, 577, 1732, 1168, 1585, 1717, 1018, 85, 850, 424, 202]

length = 224
mod = 2019
cont = [0 for _ in range(length)]
sums = [0 for _ in range(length)]
count = 0
s = list(map(int, input()))
n = len(s)
for i in range(n):
    m = s[n-1-i]
    for j in range(min(i + 1, length)):
        sums[j] += m * a[(i-j) % length]
        if i > j:
            sums[j] %= mod
            if i % length == j:
                if sums[j - 1] == 0:
                    cont[j] += 1
                else:
                    cont[j] = 0
            if sums[j] == 0:
                count += cont[j] + 1
print(count)

Fixed submission:
s = input()
n = len(s)
table = [0 for _ in range(n + 1)]
for i in range(n):
    table[-2 - i] = (int(s[-1 - i]) * pow(10, i, 2019) + table[-1 - i]) % 2019
count = [0 for _ in range(2019)]
ans = 0
for t in table:
    if count[t] != 0:
        ans += count[t]
    count[t] += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math

a = [1, 10, 100, 1000, 1924, 1069, 595, 1912, 949, 1414, 7, 70, 700, 943, 1354, 1426, 127, 1270, 586, 1822, 49, 490,
     862, 544, 1402, 1906, 889, 814, 64, 640, 343, 1411, 1996, 1789, 1738, 1228, 166, 1660, 448, 442, 382, 1801, 1858,
     409, 52, 520, 1162, 1525, 1117, 1075, 655, 493, 892, 844, 364, 1621, 58, 580, 1762, 1468, 547, 1432, 187, 1870,
     529, 1252, 406, 22, 220, 181, 1810, 1948, 1309, 976, 1684, 688, 823, 154, 1540, 1267, 556, 1522, 1087, 775, 1693,
     778, 1723, 1078, 685, 793, 1873, 559, 1552, 1387, 1756, 1408, 1966, 1489, 757, 1513, 997, 1894, 769, 1633, 178,
     1780, 1648, 328, 1261, 496, 922, 1144, 1345, 1336, 1246, 346, 1441, 277, 751, 1453, 397, 1951, 1339, 1276, 646,
     403, 2011, 1939, 1219, 76, 760, 1543, 1297, 856, 484, 802, 1963, 1459, 457, 532, 1282, 706, 1003, 1954, 1369, 1576,
     1627, 118, 1180, 1705, 898, 904, 964, 1564, 1507, 937, 1294, 826, 184, 1840, 229, 271, 691, 853, 454, 502, 982,
     1744, 1288, 766, 1603, 1897, 799, 1933, 1159, 1495, 817, 94, 940, 1324, 1126, 1165, 1555, 1417, 37, 370, 1681, 658,
     523, 1192, 1825, 79, 790, 1843, 259, 571, 1672, 568, 1642, 268, 661, 553, 1492, 787, 1813, 1978, 1609, 1957, 1399,
     1876, 589, 1852, 349, 1471, 577, 1732, 1168, 1585, 1717, 1018, 85, 850, 424, 202]

length = 224
mod = 2019
cont = [0 for _ in range(length)]
sums = [0 for _ in range(length)]
count = 0
s = list(map(int, input()))
s.reverse()
n = len(s)
for i in range(n):
    m = s[i]
    for j in range(min(i + 1, length)):
        sums[j] += m * a[(i-j) % length]
        if i > j:
            sums[j] %= mod
            if i % length == j:
                if sums[j - 1] == 0:
                    cont[j] += 1
                else:
                    cont[j] = 0
            if sums[j] == 0:
                count += cont[j] + 1
print(count)


Fixed submission:
s = input()
n = len(s)
table = [0 for _ in range(n + 1)]
for i in range(n):
    table[-2 - i] = (int(s[-1 - i]) * pow(10, i, 2019) + table[-1 - i]) % 2019
count = [0 for _ in range(2019)]
ans = 0
for t in table:
    if count[t] != 0:
        ans += count[t]
    count[t] += 1
print(ans)