Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
N = int(input())
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

S = input().rstrip()

counter = 0
for l_index in range(len(S) - 4):
    atama = int(S[l_index:l_index+2])
    if atama % 2 != 0:
        continue
    else:
        r_index = 5
        top = l_index
        while True:
            saigo = l_index + r_index
            if saigo > len(S):
                break
            kouho = int(S[top:saigo])
            if kouho % 2019 == 0:
                counter += 1
                top = r_index
                r_index += 5
                continue
            r_index += 1


print(counter)


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1
MOD = 2019

"""
gcd(10, 2019) = 1 互いに素
-> 10のmod2019での逆元(1/10)が存在
"""
S = input().rstrip()
s_list = list(map(int, list(S)))[::-1]

counts = [0] * MOD
counts[0] = 1

num, d = 0, 1

for s_element in s_list:
    num += s_element * d
    num %= MOD
    d *= 10
    d %= MOD
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
N = int(input())
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

S = input().rstrip()

counter = 0
for l_index in range(len(S) - 4):
    atama = int(S[l_index:l_index+2])
    if atama % 2 != 0:
        continue
    else:
        r_index = 5
        while True:
            saigo = l_index + r_index
            if saigo > len(S):
                break
            kouho = int(S[l_index:saigo])
            if kouho % 2019 == 0:
                counter += 1
                r_index += 5
                continue
            r_index += 1


print(counter)


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1
MOD = 2019

"""
gcd(10, 2019) = 1 互いに素
-> 10のmod2019での逆元(1/10)が存在
"""
S = input().rstrip()
s_list = list(map(int, list(S)))[::-1]

counts = [0] * MOD
counts[0] = 1

num, d = 0, 1

for s_element in s_list:
    num += s_element * d
    num %= MOD
    d *= 10
    d %= MOD
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
N = int(input())
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

S = input().rstrip()

counter = 0
for l_index in range(len(S) - 4):
    atama = int(S[l_index:l_index+2])
    if atama % 2 != 0:
        continue
    else:
        r_index = 5
        while True:
            saigo = l_index + r_index
            if saigo > len(S):
                break
            kouho = int(S[l_index:saigo])
            if kouho % 2019 == 0:
                counter += 1
            r_index += 1


print(counter)


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1
MOD = 2019

"""
gcd(10, 2019) = 1 互いに素
-> 10のmod2019での逆元(1/10)が存在
"""
S = input().rstrip()
s_list = list(map(int, list(S)))[::-1]

counts = [0] * MOD
counts[0] = 1

num, d = 0, 1

for s_element in s_list:
    num += s_element * d
    num %= MOD
    d *= 10
    d %= MOD
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
N = int(input())
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

S = input().rstrip()

counter = 0
for l_index in range(len(S) - 4):
    atama = int(S[l_index:l_index+2])
    if atama % 2 != 0:
        continue
    else:
        r_index = 4
        while True:
            saigo = l_index + r_index
            if saigo > len(S):
                break
            kouho = int(S[l_index:saigo])
            if kouho % 2019 == 0:
                counter += 1
            r_index += 1


print(counter)


# def main():

# if __name__ == '__main__':
#     main()


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1
MOD = 2019

"""
gcd(10, 2019) = 1 互いに素
-> 10のmod2019での逆元(1/10)が存在
"""
S = input().rstrip()
s_list = list(map(int, list(S)))[::-1]

counts = [0] * MOD
counts[0] = 1

num, d = 0, 1

for s_element in s_list:
    num += s_element * d
    num %= MOD
    d *= 10
    d %= MOD
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)