Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict


read = sys.stdin.read
readline = sys.stdin.buffer.readline

INF = float('inf')


def main():
    S = input()
    L = len(S)
    d = defaultdict(int)

    for i in range(L):
        s = int(S[i:])
        a = s % 2019
        d[a] += 1

    ans = 0

    for key, value in d.items():
        ans += value * (value - 1) // 2
        if key == 0:
            ans += value

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline

INF = float('inf')


def main():
    s = map(int, input()[::-1])
    mod = 2019
    counts = [0] * mod
    counts[0] = 1
    t = 0
    x = 1
    for num in s:
        t = (t + num * x) % mod
        counts[t] += 1
        x = (x * 10) % mod
    ans = 0
    for count in counts:
        if count > 1:
            ans += count * (count - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict


read = sys.stdin.read
readline = sys.stdin.buffer.readline

INF = float('inf')


def main():
    S = input()
    L = len(S)
    d = defaultdict(int)

    for i in range(L):
        s = int(S[i:])
        a = s % 2019
        d[a] += 1

    ans = 0

    for key, value in d.items():
        ans += value * (value - 1) // 2
        if key == 0:
            ans += value

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline

INF = float('inf')


def main():
    s = map(int, input()[::-1])
    mod = 2019
    counts = [0] * mod
    counts[0] = 1
    t = 0
    x = 1
    for num in s:
        t = (t + num * x) % mod
        counts[t] += 1
        x = (x * 10) % mod
    ans = 0
    for count in counts:
        if count > 1:
            ans += count * (count - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import defaultdict
INF = float('inf')

def main():
    S = readline().decode('utf-8')
    L = len(S)
    d = defaultdict(int)

    for i in range(L):
        s = int(S[i:])
        a = s%2019
        d[a] += 1

    ans = 0

    for key, value in d.items():
        ans += value*(value-1)//2
        if key == 0:
            ans += value

    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline

INF = float('inf')


def main():
    s = map(int, input()[::-1])
    mod = 2019
    counts = [0] * mod
    counts[0] = 1
    t = 0
    x = 1
    for num in s:
        t = (t + num * x) % mod
        counts[t] += 1
        x = (x * 10) % mod
    ans = 0
    for count in counts:
        if count > 1:
            ans += count * (count - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import defaultdict
INF = float('inf')

def main():
    S = readline().decode('utf-8')
    L = len(S)
    d = defaultdict(int)

    for i in range(L):
        s = int(S[i:])
        a = s%2019
        d[a] += 1

    ans = 0

    for key, value in d.items():
        ans += value*(value-1)//2
        if key == 0:
            ans += value

    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline

INF = float('inf')


def main():
    s = map(int, input()[::-1])
    mod = 2019
    counts = [0] * mod
    counts[0] = 1
    t = 0
    x = 1
    for num in s:
        t = (t + num * x) % mod
        counts[t] += 1
        x = (x * 10) % mod
    ans = 0
    for count in counts:
        if count > 1:
            ans += count * (count - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    L = len(S)
    amari = [0] * 2019
    tmp = 0
    for i in range(L):
        tmp += int(S[-i-1])*(10**i)%2019
        tmp %= 2019
        amari[tmp] += 1
    ans = amari[0]
    for i in range(2019):
        ans += amari[i]*(amari[i]-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline

INF = float('inf')


def main():
    s = map(int, input()[::-1])
    mod = 2019
    counts = [0] * mod
    counts[0] = 1
    t = 0
    x = 1
    for num in s:
        t = (t + num * x) % mod
        counts[t] += 1
        x = (x * 10) % mod
    ans = 0
    for count in counts:
        if count > 1:
            ans += count * (count - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
from namba import njit

@njit
def main():
    S = input()
    L = len(S)
    amari = [0] * 2019
    tmp = 0
    for i in range(L):
        tmp += int(S[-i-1])*(10**i)%2019
        tmp %= 2019
        amari[tmp] += 1
    ans = amari[0]
    for i in range(2019):
        ans += amari[i]*(amari[i]-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline

INF = float('inf')


def main():
    s = map(int, input()[::-1])
    mod = 2019
    counts = [0] * mod
    counts[0] = 1
    t = 0
    x = 1
    for num in s:
        t = (t + num * x) % mod
        counts[t] += 1
        x = (x * 10) % mod
    ans = 0
    for count in counts:
        if count > 1:
            ans += count * (count - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    L = len(S)
    amari = [0] * 2019
    tmp = 0
    for i in range(L):
        tmp += int(S[-i-1])*(10**i)%2019
        tmp %= 2019
        amari[tmp] += 1
    ans = amari[0]
    for i in range(2019):
        ans += amari[i]*(amari[i]-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline

INF = float('inf')


def main():
    s = map(int, input()[::-1])
    mod = 2019
    counts = [0] * mod
    counts[0] = 1
    t = 0
    x = 1
    for num in s:
        t = (t + num * x) % mod
        counts[t] += 1
        x = (x * 10) % mod
    ans = 0
    for count in counts:
        if count > 1:
            ans += count * (count - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    L = len(S)
    amari = [0] * 2019
    for i in range(L):
        amari[int(S[i:])%2019] += 1
    ans = amari[0]
    for i in range(2019):
        ans += amari[i]*(amari[i]-1)//2
    print(ans)



if __name__ == '__main__':
    main()

Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline

INF = float('inf')


def main():
    s = map(int, input()[::-1])
    mod = 2019
    counts = [0] * mod
    counts[0] = 1
    t = 0
    x = 1
    for num in s:
        t = (t + num * x) % mod
        counts[t] += 1
        x = (x * 10) % mod
    ans = 0
    for count in counts:
        if count > 1:
            ans += count * (count - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()