Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    s = tuple(map(int, input()))
    lens = len(s)

    d1 = defaultdict(int)
    ss = 0
    k = 1
    while k <= lens:
        ss += (int(s[-k]) * (10 ** (k - 1))) % 2019
        ss = ss % 2019
        d1[ss] += 1
        k += 1
    r = d1[0]
    for v in d1.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    lens = len(s)

    d1 = defaultdict(int)
    ss = int(s[-4:]) % 2019
    k = 5
    while k <= lens:
        d1[ss] += 1
        ss += (int(s[-k]) * (10 ** (k - 1))) % 2019
        ss = ss % 2019
        k += 1
    d1[ss] += 1
    r = d1[0]
    for v in d1.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from collections import deque
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    for i1 in range(n):
        t = (ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amaria = tuple(accumulate(amari))
    r = 0
    minus = 0
    for j1 in range(n):
        r += sum([(ae - minus) % 2019 == 0 for ae in amaria[j1:]])
        minus = amaria[j1]
    print(r)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    for i1 in range(n):
        t = (ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amaria = list(accumulate(amari))
    r = 0
    for j1 in range(n):
        r += sum([ae % 2019 == 0 for ae in amaria[j1:]])
        amaria = [ae - amaria[j1] for ae in amaria]
    print(r)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    for i1 in range(n):
        t = (ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amaria = list(accumulate(amari))
    r = 0
    for j1 in range(n):
        r += sum([ae % 2019 == 0 for ae in amaria[j1:]])
        amaria = [ae - amaria[j1] for ae in amaria]
    print(r)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    for i1 in range(n):
        t = (ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amaria = list(accumulate(amari))
    r = 0
    for j1 in range(n):
        r += sum([ae % 2019 == 0 for ae in amaria[j1:]])
        amaria = [ae - amaria[j1] for ae in amaria]
    print(r)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    for i1 in range(n):
        amari[i1] = int(s[i1:]) % 2019
    r = 0
    for j1 in range(n):
        r += amari[:-j1-1].count(0)
        amari = [(i - amari[-j1 - 1]) % 2019 for i in amari]
    print(r)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    for i1 in range(n):
        amari[i1] = int(s[i1:]) % 2019
    r = 0
    for j1 in range(n):
        r += amari[:-j1-1].count(0)
        amari = [(i - amari[-j1 - 1]) % 2019 for i in amari]
    print(r)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    r = 0
    lens = len(s)
    for i1 in range(lens - 3):
        tnum = sum(list(map(int, s[i1:i1 + 4])))
        tint = int(s[i1:i1+4])
        if tnum % 3 == 0:
            r += tint % 673 == 0
        for i2 in range(i1+4,lens):            
            es = int(s[i2])
            tnum += es
            tint = tint*10 + es
            if tnum % 3 == 0:
                r += tint % 673 == 0
    print(r)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    r = 0
    lens = len(s)
    for i1 in range(lens - 3):
        tint = int(s[i1:])
        while tint >= 2019:
            tint2 = tint//10 - tint%10*1817
            while tint2 >= 18171:
                tint2 = tint2 // 10 - tint2 % 10 * 1817
            r += tint2 % 2019 == 0
            tint = tint //10
    print(r)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    r = 0
    lens = len(s)
    for i1 in range(lens - 3):
        tint = int(s[i1:])
        while tint >= 2019:
            r += tint % 2019 == 0
            tint = tint //10
    print(r)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    r = 0
    lens = len(s)
    for i1 in range(lens - 3):
        tint = int(s[i1:])
        while tint >= 2019:
            r += tint % 2019 == 0
            tint = tint //10
    print(r)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    s = input()
    n = len(s)

    amari = [0] * n
    ketaamari = 1
    t = 0
    for i1 in range(n):
        t = (t + ketaamari * int(s[-i1 -1])) % 2019
        amari[-i1-1] = t
        ketaamari = (ketaamari * 10) % 2019
    amari.append(0)
    ac = Counter(amari)
    r = 0
    for v in ac.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()