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

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x


mod = [0]*2019
mod[0] = 1
pre = 0
for i in reversed(range(n)):
    pre = (pre + int(s[i])*pow_k(10, n-i-1))%2019
    mod[pre] += 1
print(sum([m*(m-1)//2 for m in mod]))

Fixed submission:
s = input()[::-1]
n = len(s)

mod = [0]*2019
pre = 0
mod[pre] = 1
x = 1
for i in range(n):
    pre += int(s[i])*x
    pre %= 2019
    mod[pre] += 1
    x *= 10
    x %=2019
print(sum([m*(m-1)//2 for m in mod]))

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

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x


mod = [0]*2019
mod[0] = 1
pre = 0
for i in reversed(range(n)):
    pre = (pre + int(s[i])*pow_k(10, n-i-1))%2019
    mod[pre] += 1
print(sum([m*(m-1)//2 for m in mod]))

Fixed submission:
s = input()[::-1]
n = len(s)

mod = [0]*2019
pre = 0
mod[pre] = 1
x = 1
for i in range(n):
    pre += int(s[i])*x
    pre %= 2019
    mod[pre] += 1
    x *= 10
    x %=2019
print(sum([m*(m-1)//2 for m in mod]))

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

mod = [0]*2019
mod[0] = 1
pre = 0
for i in reversed(range(n)):
    pre = (pre + int(s[i])*10**(n-i-1))%2019
    mod[pre] += 1
print(sum([m*(m-1)//2 for m in mod]))

Fixed submission:
s = input()[::-1]
n = len(s)

mod = [0]*2019
pre = 0
mod[pre] = 1
x = 1
for i in range(n):
    pre += int(s[i])*x
    pre %= 2019
    mod[pre] += 1
    x *= 10
    x %=2019
print(sum([m*(m-1)//2 for m in mod]))

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

mod = [0]*2019
mod[0] = 1
pre = 0
for i in reversed(range(n)):
    pre = (pre + int(s[i])*10**(n-i-1))%2019
    mod[pre] += 1
print(sum([m*(m-1)//2 for m in mod]))

Fixed submission:
s = input()[::-1]
n = len(s)

mod = [0]*2019
pre = 0
mod[pre] = 1
x = 1
for i in range(n):
    pre += int(s[i])*x
    pre %= 2019
    mod[pre] += 1
    x *= 10
    x %=2019
print(sum([m*(m-1)//2 for m in mod]))

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

mod = [0]*2019
mod[0] = 1
pre = 0
for i in reversed(range(n)):
    pre = (pre + int(s[i])*10**(n-i-1))%2019
    mod[pre] += 1
print(sum([m*(m-1)//2 for m in mod]))

Fixed submission:
s = input()[::-1]
n = len(s)

mod = [0]*2019
pre = 0
mod[pre] = 1
x = 1
for i in range(n):
    pre += int(s[i])*x
    pre %= 2019
    mod[pre] += 1
    x *= 10
    x %=2019
print(sum([m*(m-1)//2 for m in mod]))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(map(int,list(input())))
n = len(s)

mod = [0]*2019
mod[0] = 1
pre = 0
for i in reversed(range(n)):
    pre = (pre + s[i]*10**(n-i-1))%2019
    mod[pre] += 1
print(sum([m*(m-1)//2 for m in mod]))

Fixed submission:
s = input()[::-1]
n = len(s)

mod = [0]*2019
pre = 0
mod[pre] = 1
x = 1
for i in range(n):
    pre += int(s[i])*x
    pre %= 2019
    mod[pre] += 1
    x *= 10
    x %=2019
print(sum([m*(m-1)//2 for m in mod]))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(map(int,list(input())))
n = len(s)

mod = [0]*2019
mod[0] = 1
pre = 0
for i in reversed(range(n)):
    pre = (pre + s[i]*10**(n-i-1))%2019
    mod[pre] += 1
print(sum([m*(m-1)//2 for m in mod]))

Fixed submission:
s = input()[::-1]
n = len(s)

mod = [0]*2019
pre = 0
mod[pre] = 1
x = 1
for i in range(n):
    pre += int(s[i])*x
    pre %= 2019
    mod[pre] += 1
    x *= 10
    x %=2019
print(sum([m*(m-1)//2 for m in mod]))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(map(int,list(input())))
n = len(s)

t = [0]*(n + 1)
mod = [0]*2019
mod[0] = 1
cnt = 0
for i in reversed(range(n)):
    t[i] = t[i+1] + s[i]*10**(n-i-1)
    mod[t[i]%2019] += 1
for m in mod:
    cnt += m*(m-1)//2
print(cnt)

Fixed submission:
s = input()[::-1]
n = len(s)

mod = [0]*2019
pre = 0
mod[pre] = 1
x = 1
for i in range(n):
    pre += int(s[i])*x
    pre %= 2019
    mod[pre] += 1
    x *= 10
    x %=2019
print(sum([m*(m-1)//2 for m in mod]))