Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    N = len(S)
    S = int(S)
    work, temp = [0] * 2019, 0
    for i in range(N+1): work[(S % 10**i) % 2019] += 1
    print(sum([w*(w-1)//2 for w in work]))
main()

Fixed submission:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()

Buggy python submission (verdict: Runtime Error):
def main():
    S = input()
    N = len(S)
    S = int(S)
    work, temp = 0, [0] * 2019, 0
    for i in range(N+1): work[(S % 10**i) % 2019] += 1
    print(sum([w*(w-1)//2 for w in work]))
main()

Fixed submission:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    N = len(S)
    S = int(S)
    result, work, temp = 0, [0] * 2019, 0
    for i in range(N+1): work[(S % 10**i) % 2019] += 1
    for w in work: result += w*(w-1)//2
    print(result)
main()

Fixed submission:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    N = len(S)
    S = int(S)
    result, work, temp = 0, [0] * 2019, 0
    for i in range(N+1): work[(S % 10**i) % 2019] += 1
    for w in work: result += w*(w-1)//2
    print(result)
main()

Fixed submission:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    N, result, work, temp, _int = len(S), 0, [0] * 2019, 0, int
    work[0] += 1
    i = 0
    for s in S[::-1]:
        temp += _int(s) * 10**i
        work[temp % 2019] += 1
        i += 1
    for w in work: result += w*(w-1)//2
    print(result)
main()

Fixed submission:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    N, result, work, temp, _int = len(S), 0, [0] * 2019, 0, int
    work[0] += 1
    for i in range(N):
        temp += _int(S[N - i - 1]) * 10**i
        work[temp % 2019] += 1
    for w in work: result += w*(w-1)//2
    print(result)
main()

Fixed submission:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    N, result, work, temp, _int = len(S), 0, [0] * 2019, 0, int
    work[0] += 1
    for i in range(N):
        temp += _int(S[N - i - 1]) * 10**i
        work[temp % 2019] += 1
    for w in work: result += w*(w-1)//2
    print(result)
main()

Fixed submission:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
def main():
    S = input()
    N = len(S)
    result = 0
    work = [0] * (N + 1)
    temp = 0
    for i in range(N):
        temp += int(S[N - i - 1]) * 10**i
        work[i] = temp % 2019
    for v in Counter(work).values(): result += v*(v-1)//2
    print(result)
main()

Fixed submission:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
N = len(S)
result = 0
work = [0] * (N + 1)
temp = 0
for i in range(N):
    temp += int(S[N - i - 1]) * 10**i
    work[i] = temp % 2019
for v in Counter(work).values(): result += v*(v-1)//2
print(result)

Fixed submission:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    result = 0
    L = len(S)
    for i in range(L-3):
        work = int(S[i:i+3])
        j = i + 3
        for _ in range(10**6):
            if j >= L:
                break
            work = work * 10 + int(S[j])
            if work % 2019 == 0:
                result += 1
            j += 1
    print(result)
main()

Fixed submission:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    result = 0
    L = len(S)
    for i in range(L-3):
        j = i + 3
        for _ in range(10**6):
            if j >= L:
                break
            if int(S[i:j+1]) % 2019 == 0:
                result += 1
                j += 3
            j += 1
    print(result)
main()

Fixed submission:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    result = 0
    L = len(S)
    for i in range(L-3):
        j = i + 3
        for _ in range(10**6):
            if j >= L:
                break
            if int(S[i:j+1]) % 2019 == 0:
                result += 1
                j += 3
            j += 1
    print(result)
main()

Fixed submission:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()