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):
import re
S = input()
#print(type(S))

s = []
for i in range(int(S) // 2019):
    s.append(str(i*2019))

count = 0
for i in s:
    S_ = S
    while re.search(i, S_):
        #print(i)
        S_ = S_[:re.search(i, S_).start()] + "," + S_[re.search(i, S_).start()+1:]
        count += 1
        
print(count)

import re
S = input()

s = []
for i in range(1000):
    s.append(str(i*2019))

count = []
for i in s:
    count += len(re.findall(S, i))

print(count)

S = input()

n = len(S)
m = 2019

S_ = S[::-1]

x = 1
total = 0
modlis = [0 for i in range(m)]

ans = 0
for i in range(n):
    modlis[total] += 1
    print("S_[i]:", S_[i])
    print("int(S_[i])*x:", int(S_[i])*x)
    print("total:", total)
    total += int(S_[i])*x
    print("total:", total)
    total %= m
    print("total:", total)
    ans += modlis[total]
    print("x:", x)
    x = x * 10 % m
    print("x:", x)

print(ans)


import re
S = input()
#print(type(S))

s = []
for i in range(1000):
    s.append(str(i*2019))

count = 0
for i in s:
    S_ = S
    while re.search(i, S_):
        print(i)
        S_ = S_[:re.search(i, S_).start()] + "," + S_[re.search(i, S_).start()+1:]
        count += 1
        
print(count)

import re
S = input()
#print(type(S))

s = []
for i in range(10000):
    s.append(str(i*2019))

count = 0
for i in s:
    S_ = S
    while re.search(i, S_):
        print(i)
        S_ = S_[:re.search(i, S_).start()] + "," + S_[re.search(i, S_).start()+1:]
        count += 1
        
print(count)

import re
S = input()
#print(type(S))

s = []
for i in range(int(S) // 2019 // 5):
    s.append(str(i*2019))

count = 0
for i in s:
    S_ = S
    while re.search(i, S_):
        #print(i)
        S_ = S_[:re.search(i, S_).start()] + "," + S_[re.search(i, S_).start()+1:]
        count += 1
        
print(count)

S = input()

count = 0
for j in range(4, len(S)+1):
    for i in range(len(S)-4):
        if S[i:i+4] % 2019 == 0:
            count += 1

print(count)

S = input()

n = len(S)
m = 2019

S_ = S[::-1]

x = 1
total = 0
modlis = [0 for i in range(m)]

ans = 0
for i in range(n):
    modlis[total] += 1
    print("S_[i]:", S_[i])
    print("int(S_[i])*x:", int(S_[i])*x)
    print("total:", total)
    total += int(S_[i])*x
    print("total:", total)
    total %= m
    print("total:", total)
    ans += modlis[total]
    print("x:", x)
    x = x * 10 % m
    print("x:", x)

print(ans)


S = input()

n = len(S)
m = 2019

S_ = S[::-1]

x = 1
total = 0
modlis = [0 for i in range(m)]

ans = 0
for i in range(n):
    modlis[total] += 1
    #print("S_[i]:", S_[i])
    #print("int(S_[i])*x:", int(S_[i])*x)
    
    total += int(S_[i])*x
    
    total %= m
    
    ans += modlis[total]
    #print("x:", x)
    x = x * 10 % m
    #print("x:", x)

print(ans)

Verdicts: Time Limit Exceeded

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Time Limit Exceeded

Runtime Error

Wrong Answer

Accepted