Problem: Given is a string S consisting of digits from `1` through `9`.  Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:  Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Submission attempts (in order):
s = input()
num = len(s)
l = []
from collections import deque
l = deque(l)   

for _ in range(1, 20190000):
    if _%2019 == 0:
        l.append(str(_))
l = set(l)
#print(l)

def aaa(s, num):
    x = 0
    for i in range(4,num+1):
        for j in range(num - i + 1):
            if s[j:j+i] in l:
                x += 1
    print(x)

aaa(s, num)

from numba import jit
import numpy as np

@jit
def solve():
    
    s = np.array(list(input())[::-1])
    num = len(s)
    #print(s, num)
    
    l = []
    for i in range(1,num+1):
        l.append(int(''.join(s[:i][::-1])))
    #print(l)
    l = np.array(l)
    mod = []
    for j in range(num):
        mod.append(l[j] % 2019)
    mod = np.array(mod)
    
    ans = 0
    for p in range(num):
        if mod[p] == 0:
            ans += 1
        tmp = 1
        for q in range(p+1,num):
            if mod[p] == mod[q]:
                tmp += 1
        ans += (tmp-1)*tmp//2
    
    print(ans)

solve()

s = input()
num = len(s)
l = []
from collections import deque
l = deque(l)   

for _ in range(1, 20190000):
    if _%2019 == 0 and '0' not in str(_) :
        l.append(str(_))
l = set(l)
#print(l)

def aaa(s, num):
    x = 0
    for i in range(4,num+1):
        for j in range(num - i + 1):
            if s[j:j+i] in l:
                x += 1
    print(x)

aaa(s, num)

from numba import jit

@jit
def solve():
    
    s = list(input())[::-1]
    num = len(s)
    #print(s, num)
    
    l = []
    for i in range(1,num+1):
        l.append(int(''.join(s[:i][::-1])))
    #print(l)
    
    mod = []
    for j in range(num):
        mod.append(l[j] % 2019)
    #print(mod)
    
    ans = 0
    for p in range(num):
        if mod[p] == 0:
            ans += 1
        tmp = 1
        for q in range(p+1,num):
            if mod[p] == mod[q]:
                tmp += 1
        ans += (tmp-1)*tmp//2
    
    print(ans)

solve()

from numba import jit
import numpy as np

@jit
def solve():
    
    s = np.array(list(input())[::-1])
    num = len(s)
    #print(s, num)
    
    l = np.array([])
    for i in range(1,num+1):
        l.append(int(''.join(s[:i][::-1])))
    #print(l)
    
    mod = []
    for j in range(num):
        mod.append(l[j] % 2019)
    mod = np.array(mod)
    
    ans = 0
    for p in range(num):
        if mod[p] == 0:
            ans += 1
        tmp = 1
        for q in range(p+1,num):
            if mod[p] == mod[q]:
                tmp += 1
        ans += (tmp-1)*tmp//2
    
    print(ans)

solve()

s = input()
num = len(s)
l = []
from collections import deque
l = deque(l)   

for _ in range(1, 20190000):
    if _%2019 == 0:
        l.append(_)
l = set(l)
#print(l)

def aaa(s, num):
    x = 0
    for i in range(4,num+1):
        for j in range(num - i + 1):
            if int(s[j:j+i]) in l:
                x += 1
    print(x)

aaa(s, num)

s = input()
num = len(s)

l = []
for _ in range(1, 20190000):
    if _%2019 == 0:
        l.append(_)
l = set(l)
#print(l)

def aaa(s, num):
    x = 0
    for i in range(4,num+1):
        for j in range(num - i + 1):
            if int(s[j:j+i]) in l:
                x += 1
    print(x)

aaa(s, num)

s = input()[::-1]

cnts = [1] + [0] * (2019 - 1)
tmp = 0
d = 1

for i in s:
    tmp += int(i) * d
    cnts[tmp % 2019] += 1
    d = d * 10 % 2019 

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

print(ans)

Verdicts: Time Limit Exceeded

Time Limit Exceeded

Time Limit Exceeded

Time Limit Exceeded

Runtime Error

Time Limit Exceeded

Time Limit Exceeded

Accepted