Problem:


Score : 400 points

Problem Statement

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.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

s = s()

mod = 2019
num_int = 0
mod_dict = defaultdict(int)
mod_dict[num_int % mod] += 1
for i in range(len(s)):
    num_int = 10 ** i * int(s[-i-1]) + num_int
    mod_dict[num_int % mod] += 1

for i in mod_dict:
    ans += ((mod_dict[i] - 1) * mod_dict[i]) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = int(len(S))
S = int(S)
A = 0

for i in range(N-3):
    S1 = S //(10**i)
    for j in range(N-3-i):
        S2 = S1 % (10**(N - i - j))
        if S2 % 2019 == 0:
            A = A + 1
print(A)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)

result = 0
  
for i in range(1,2019):
  c = len([x for x in range(n) if int(s[x:])%2019 == i])
  result += c*(c-1)/2

d = len([x for x in range(n) if int(s[x:])%2019 == 0])
result += d*(d+1)/2

print(int(result))

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)

modlist=[]

for i in range(n):
  modlist.append(int(s[i:])%2019)

modlist.append(0)
 
result = 0
  
for i in range(2019):
  c = modlist.count(i)
  result += c*(c-1)/2

print(int(result))

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)

modlist=[]

for i in range(n):
  modlist.append(int(s[i:])%2019)

modlist.append(0)
 
result = 0
  
for i in range(2019):
  c = modlist.count(i)
  if c<=1:
    result += 0
  else:
    result += c*(c-1)/2

print(int(result))

Submission status: Time Limit Exceeded

Solution code:
S = [int(i) for i in input()]
S.reverse()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + S[i] * 10**i % 2019) % 2019
    lst.append(_sum)
    
ans = lst.count(0)
for i in set(lst):
    c = lst.count(i)
    ans += c*(c-1)//2
   
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
ans=0
for i in range(len(S)-3):
    for j in range(len(S)-3-i):
        if int(S[i:len(S)-j])%2019==0:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
num = input()

count = 0
year = 2019

for i in range(len(num)):
  for j in range(i, len(num)):
    if int(num[i:j+1]) % year == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
lst = []

for i in range(len(S)):
    lst.append(int(S[-1-i:]) % 2019)
    
ans = lst.count(0)
for i in set(lst):
    c = lst.count(i)
    ans += c*(c-1)//2
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
lst = []
_sum = 0

for i in range(len(S)):
    _sum = (_sum + int(S[-1-i]) * 10**i % 2019) % 2019
    lst.append(_sum)
    
ans = lst.count(0)
for i in set(lst):
    c = lst.count(i)
    ans += c*(c-1)//2
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count2019 = [0]*2019
count2019[0]=1
mod2019 = 0
d = 1
for i in S[::-1]:
    mod2019 =mod2019+int(i)*d
    mod2019%=2019
    count2019[mod2019] +=1
    d *= 10
    d%2019
ans =0
for i in count2019:
   ans+= i*(i-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

for i in range(len(S)):
    for j in range(i + 1, len(S) + 1): #長さにプラス1しないと全探索できないので注意
        SS = int(S[i:j])
        if SS % 2019 == 0:
            #print(str(i + 1) + ',' + str(j))
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count2019 = [0]*2019
count2019[0]=1
mod2019 = 0
d = 1
for i in S[::-1]:
    mod2019 =mod2019+int(i)*d
    mod2019%=2019
    count2019[mod2019] +=1
    d *= 10
    d%2019
ans =0
for i in count2019:
   ans+= i*(i-1)//2
print(ans)
# print(count2019)

Submission status: Time Limit Exceeded

Solution code:


from math import factorial
S=list(map(int,input()))
S.reverse()
count2019 = [0]*2019
count2019[0]=1
mod2019 = 0
d = 1
for i in S:
    mod2019 =mod2019+int(i)*d
    mod2019%=2019
    count2019[mod2019] +=1
    d *= 10
    d%2019
ans =0
for i in count2019:
   ans+= i*(i-1)//2
print(ans)
# print(count2019)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N + 1):
    now += (int(S[N - i - 1]) * (10**i)) % 2019
    map_[now % 2019] += 1
    ans += map_[now % 2019]

print(ans)

Submission status: Time Limit Exceeded

Solution code:


from math import factorial
S=list(map(int,input()))
S.reverse()
count2019 = [0]*2019
count2019[0]=1
mod2019 = 0
d = 1
for i in range(len(S)):
    mod2019 =mod2019+S[i]*d
    mod2019%=2019
    count2019[mod2019] +=1
    d *= 10
    d%2019
ans =0
for i in count2019:
   ans+= i*(i-1)//2
print(ans)
# print(count2019)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N + 1):
    now += int(S[N - i - 1]) * (10**i)
    map_[now % 2019] += 1
    ans += map_[now % 2019]

print(ans)

Submission status: Time Limit Exceeded

Solution code:


from math import factorial
S=list(map(int,input()))
S.reverse()
count2019 = [0]*2019
count2019[0]=1
mod2019 = 0
for i in range(len(S)):
    mod2019 =(mod2019+S[i]*10**i)%2019
    count2019[mod2019] +=1

ans =0
for i in count2019:
   ans+= i*(i-1)//2
print(ans)
# print(count2019)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
S = int(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0

for i in range(1, N + 1):
    temp = S % (10**i)
    map_[temp % 2019] += 1
    ans += map_[temp % 2019]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
S=list(map(int,input()))
S.reverse()
# print(S)
count2019 = [0]*2019
count2019[0]=1
mod2019 = 0
for i in range(len(S)):
    mod2019 =(mod2019+S[i]*10**i)%2019
    count2019[mod2019] +=1

ans =0
for i in count2019:
    if(i>=2):
        ans += factorial(i) // factorial(i) // factorial(i - 2)
print(ans)
# print(count2019)

Submission status: Time Limit Exceeded

Solution code:
S = input()

map_ = [-1] * 2019
map_[0] = 0
ans = 0

for i in range(1, len(S) + 1):
    temp = int(S[len(S) - i:])
    map_[temp % 2019] += 1
    ans += map_[temp % 2019]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
S=list(map(int,input()))
S.reverse()
# print(S)
count2019 = [0]*2019
count2019[0]=1
mod2019 = [0]*(len(S)+1)
for i in range(len(S)):
    mod2019[i+1] =mod2019[i]+S[i]*10**i 
    mod2019[i+1]%=2019
    count2019[mod2019[i+1]] +=1

ans =0
for i in count2019:
    if(i>=2):
        ans += factorial(i) // factorial(i) // factorial(i - 2)
print(ans)
# print(count2019)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
S=list(map(int,input()))
S.reverse()
# print(S)
count2019 = [0]*2019
mod2019 = [0]*(len(S)+1)
for i in range(len(S)):
    mod2019[i+1] =mod2019[i]+S[i]*10**i 
    mod2019[i+1]%=2019
for i in mod2019:
    count2019[i] +=1
# print(mod2019)
ans =0
for i in count2019:
    if(i>=2):
        ans += factorial(i) // factorial(i) // factorial(i - 2)
print(ans)
# print(count2019)

Submission status: Time Limit Exceeded

Solution code:
s = input()
int_size = 0
count = 0
left = 0
right = 0
while right < len(s):
    for i in range(0,right+1):
        if int(s[i:right+1]) % 2019 == 0:
            count = count + 1
    right = right + 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

c = [0 for i in range(2019)]
c[0] = 1
mod = 2019
d = 1
x = 0
for i,j in enumerate(s[::-1]):
	x = (x + int(j)*pow(10,i))%mod
	c[x] += 1

ans = 0
for i in range(2019):
	ans += (c[i]*(c[i]-1))//2
print (ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

c = [0 for i in range(2019)]
c[0] = 1
mod = 2019
d = 1
t = 0
x = 0
for i,j in enumerate(s[::-1]):
	x = (x + int(j)*pow(10,i))%mod
	c[x] += 1

ans = 0
for i in range(2019):
	ans += (c[i]*(c[i]-1))//2
print (ans)

Submission status: Time Limit Exceeded

Solution code:

S = list(input())
a=[int(x) for x in S] #int型のリストに変換
a.reverse()
#print(a)
l=[0]*2019
l[0]=1
T=0
d=1

for i in a:
    T+=(int(i)*d)
    T%=2019
    l[T]+=1
    d*=10
result=0
for n in l:
    result+=n*(n-1)/2
print(int(result))

Submission status: Time Limit Exceeded

Solution code:
in_str = input()

rev_str = in_str[::-1]
mod = 2019

S = [0] * (len(in_str) + 1)
S[0] = 0

for i in range(1, len(in_str) + 1):
  S[i] = (S[i - 1] + int(rev_str[i - 1]) * pow(10, i, mod)) % mod

count = 0
for j in range(1, len(in_str)):
  count += S[j:].count(S[j - 1])

print(count)

Submission status: Time Limit Exceeded

Solution code:
in_str = input()

rev_str = ''.join(list(reversed(in_str)))
mod = 2019

S = [0] * (len(in_str) + 1)
S[0] = 0

for i in range(1, len(in_str) + 1):
  S[i] = (S[i - 1] + int(rev_str[i - 1]) * pow(10, i, mod)) % mod

count = 0
for j in range(1, len(in_str)):
  count += S[j:].count(S[j - 1])

print(count)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
import numpy as np
#def ConZ(i):
    #z_num = i+int(i*(i-1)/2)
    #return z_num
#def ConN(i):
    #n_num = int(i*(i-1)/2)
    #return n_num

def cmb(n):
    over = reduce(mul, range(n, n - 2, -1))
    under = reduce(mul, range(1,2 + 1))
    return over // under


S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = np.array([0]*2019)
mod[0] += 1
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod[A_num] +=1
    keta*=10
    
#print(mod)
#x += ConZ(mod[0])
#del mod[0]

#for j in range(len(mod)):
    #x+=cmb(mod[j])
#print(x)
print(int(np.sum(mod* (mod - 1) /2)))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
s = str(input())

mod = 2019

div_memo = [0 for _ in range(mod)]
for i in range(1, len(s)+1):
    # print(s[len(s)-i:])
    div = (int(s[len(s)-i:]) % mod)
    div_memo[div] += 1

ans = 0
for i in range(len(div_memo)):
    ans += div_memo[i]*(div_memo[i]-1)//2

ans += div_memo[0]
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import numpy as np

s = str(input())

mod = 2019

div_memo = []
for i in range(1, len(s)+1):
    # print(s[len(s)-i:])
    div_memo.append(int(s[len(s)-i:]) % mod)

u, counts = np.unique(div_memo, return_counts=True)

ans = np.sum(counts*(counts-1)/2)

if u[0] == 0:
    ans += counts[0]
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import numpy as np

s = str(input())

mod = 2019

div_memo = []
for i in range(1, len(s)+1):
    # print(s[len(s)-i:])
    div_memo.append(int(s[len(s)-i:]) % mod)

u, counts = np.unique(div_memo, return_counts=True)

ans = 0
for i in range(len(counts)):
    ans += counts[i]*(counts[i]-1)//2

if u[0] == 0:
    ans += counts[0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
#def ConN(i):
    #n_num = int(i*(i-1)/2)
    #return n_num

def cmb(n):
    over = reduce(mul, range(n, n - 2, -1))
    under = reduce(mul, range(1,2 + 1))
    return over // under


S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = [0]*2019
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod[A_num] +=1
    keta*=10
    
#print(mod[0])
x += ConZ(mod[0])
del mod[0]

for j in range(len(mod)):
    x+=cmb(mod[j])
print(x)

Submission status: Time Limit Exceeded

Solution code:
s = input() # User inputs string.
n = 0 # Keeps count of num substring are multiples.
year = 2019 # number or year that will be used.
for i in range(len(s)):
  j = i + 1
  while j <= len(s):
    if int(s[i:j]) % year == 0:
      n += 1
    j += 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
import collections

def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
def ConN(i):
    n_num = int(i*(i-1)/2)
    return n_num

S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = [0]*2019
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod[A_num] +=1
    keta*=10
    
#print(mod[0])
x += ConZ(mod[0])
del mod[0]

for j in range(len(mod)):
    x+=ConN(mod[j])
print(x)

Submission status: Time Limit Exceeded

Solution code:
import collections

S = list(input())
a=[int(x) for x in S] #int型のリストに変換
a.reverse()
#print(a)

n=len(a)
T=[0]*n
L=[0]*n

T[0]=a[0]
L[0]=a[0]
for i in range(1,n):
    T[i]=T[i-1]+(a[i]*10**i)
    L[i]=T[i]%2019

#print(T)


#print(L)
c = collections.Counter(L)

#出現回数が2回以上のものの出現数 + 0の出現回数
print(int(len([i[0] for i in c.items() if i[1] >= 2])) + int(len([i for i in L if i==0])))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

s = str(input())

mod = 2019

ans = 0
for i in range(1, len(s)+1):
    for j in range(0, len(s)-i+1):
        num = int(s[j:j+i])
        if num % mod == 0:
            ans += 1
            # print(j, j+i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

S = list(input())
a=[int(x) for x in S] #int型のリストに変換
a.reverse()
#print(a)

n=len(a)
T=[0]*n

T[0]=a[0]

for i in range(1,n):
    T[i]=T[i-1]+(a[i]*10**i)

#print(T)
L=list()
for i in range(n):
    L.append(T[i]%2019)
   

#print(L)
c = collections.Counter(L)

#出現回数が2回以上のものの出現数 + 0の出現回数
print(int(len([i[0] for i in c.items() if i[1] >= 2])) + int(len([i for i in L if i==0])))

Submission status: Time Limit Exceeded

Solution code:
import collections

def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
def ConN(i):
    n_num = int(i*(i-1)/2)
    return n_num

S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = [0]*2019
modcount = []
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod[A_num] +=1
    keta*=10
#print(mod[0])
x += ConZ(mod[0])
del mod[0]
c = collections.Counter(mod)
#print(mod)
modcount = list(c.items())
#print(modcount)
for j in range(len(modcount)):
    if modcount[j][0]>=2:
        x+=ConN(modcount[j][0])*modcount[j][1]
print(x)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l_S = len(S)
cnt = 0
for w in range(4, l_S):
    for left in range(l_S-w):
        if int(S[left : left+w+1]) % 2019 == 0:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l_S = len(S)
cnt = 0
for i in range(l_S):
    string = S[i]
    for j in range(i+1, l_S):
        string += S[j]
        if int(string) % 2019 == 0:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections

S = list(input())
a=[int(x) for x in S] #int型のリストに変換
#print(a)

n=len(a)-1
T=list()

for i in range(n+1):
    T.append(a[n-i]*10**i)
    
#print(T)
for i in range(1,n+1):
    T[i]+=T[i-1]
    
#print(T)
L=list()
for i in range(n+1):
    L.append(T[i]%2019)
   

#print(L)
c = collections.Counter(L)

#出現回数が2回以上のものの出現数 + 0の出現回数
print(int(len([i[0] for i in c.items() if i[1] >= 2])) + int(len([i for i in L if i==0])))

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
for i in range(len(s)):
  for j in range(i+4, len(s)+1):
    n = int(s[i:j])
    if n % 2019 == 0:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
for i in range(len(s)):
  for j in range(i+1, len(s)+1):
    n = int(s[i:j])
    if n % 2019 == 0:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l_S = len(S)
cnt = 0
for i in range(l_S-3):
    for j in range(i+3, l_S):
        if int(S[i:j+1]) % 2019 == 0:
            cnt += 1
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
input = raw_input

M = 2019
s = input()
n = len(s)
s = int(s)

div = 10

counts = [0] * M
m = 1
for i in range(n+1):
    j = (s % m) % M
    counts[j] += 1
    m *= 10

out = 0
for c in counts:
    out += (c * (c-1) // 2)

print(out)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l_S = len(S)
cnt = 0
for i in range(l_S):
    for j in range(i, l_S):
        if int(S[i:j+1]) % 2019 == 0:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
input = raw_input

M = 2019
s = input()
n = len(s)
s = int(s)

div = 10
cumsum = [s % (10 ** i) for i in range(n+1)]
out = 0
for i in range(n+1):
    for j in range(i+1, n+1):
        if (cumsum[j] - cumsum[i]) % M == 0:
            out += 1


print(out)

Submission status: Time Limit Exceeded

Solution code:
s = input() # User inputs string.
n = 0 # Keeps count of num substring are multiples.
year = 2019 # number or year that will be used.
for i in range(len(s)):
    j = i + 1
    while j <= len(s):
        if int(s[i:j]) % year == 0:
            n += 1
        j += 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
test = input()
sets = 0
if len(test)<4:
  print(sets)
else: 
  for x in range(len(test)-3):
    for y in range(x+3,len(test)):
      if int(test[x:y+1])%2019 == 0:
        sets += 1
  print(sets)

Submission status: Time Limit Exceeded

Solution code:
import  collections
import numpy as np

s = input().strip()
t = []
for i in range(len(s)):
    t.append(int(s[i:]) % 2019) 
    
t.append(0)
counts = dict(collections.Counter(t))
counts = np.array(list(counts.values()))
print(int(np.sum(counts * (counts -1) /2)))

Submission status: Time Limit Exceeded

Solution code:
A = input()

S = 0
lis = [0] * 2019
lis[0] += 1
l = len(A)+1
d = 1

for n in reversed(A):
    S += int(n)*d
    S %= 2019
    lis[S] += 1
    d *= 10

result = 0

for n in lis:
    result += (n*(n-1)//2)


print(result)

Submission status: Time Limit Exceeded

Solution code:
M,a,t,p=2019,0,0,1;l=[0]*M
for i in input()[::-1]:l[t]+=1;t=(t+int(i)*p)%M;a+=l[t];p*=10
print(a)

Submission status: Time Limit Exceeded

Solution code:
import  collections

s = input().strip()
t = []
for i in range(len(s)):
    t.append(int(s[i:]) % 2019)
    
t.append(0)
count = dict(collections.Counter(t))
tot = 0
for c in count.values():
    tot += c*(c-1)/2
print(int(tot))

Submission status: Time Limit Exceeded

Solution code:
A = input()

S = 0
lis = [0] * 2019
lis[0] += 1
l = len(A)+1
d = 1

for n in reversed(A):
    S += int(n)*d
    sm = S % 2019
    lis[sm] += 1
    d *= 10

result = 0

for n in lis:
    result += (n*(n-1)/2)


print(int(result))

Submission status: Time Limit Exceeded

Solution code:
A = input()

S = 0
lis = [0] * 2019
lis[0] += 1
l = len(A)+1
d = 1

for n in range(1, l):
    S += (int(A[-n])*d)
    sm = S % 2019
    lis[sm] += 1
    d *= 10

result = 0

for n in lis:
    result += (n*(n-1)/2)


print(int(result))

Submission status: Time Limit Exceeded

Solution code:
A = input()

S = 0
lis = [0] * 2019
lis[0] += 1
l = len(A)+1

for n in range(1, l):
    S += (int(A[-n])*(10**(n-1)))
    sm = S % 2019
    lis[sm] += 1

result = 0

for n in lis:
    result += (n*(n-1)/2)


print(int(result))

Submission status: Time Limit Exceeded

Solution code:
A = input()

S = 0
dic = {i: 0 for i in range(2019)}
dic[0] += 1
l = len(A)+1

for n in range(1, l):
    S += (int(A[-n])*(10**(n-1)))
    sm = S % 2019
    dic[sm] += 1

result = 0

for n in dic.values():
    result += (n*(n-1)/2)


print(int(result))

Submission status: Time Limit Exceeded

Solution code:
A = input()

S = 0
dic = {0:1}

for n in range(1, len(A)+1):
    S += (int(A[-n])*(10**(n-1)))
    sm = S % 2019
    if sm in dic:
        dic[sm] += 1
    else:
        dic[sm] = 1

result = 0

for n in dic.values():
    result += (n*(n-1)/2)


print(int(result))

Submission status: Time Limit Exceeded

Solution code:
A = input()

S = [0]
dic = {0:1}

for n in range(1, len(A)+1):
    S.append(S[-1] + (int(A[-n])*(10**(n-1))))
    sm = S[-1] % 2019
    S.pop(0)
    if sm in dic:
        dic[sm] += 1
    else:
        dic[sm] = 1

result = 0

for n in dic.values():
    result += (n*(n-1)/2)


print(int(result))

Submission status: Time Limit Exceeded

Solution code:
A = input()

S = [0]
dic = {0:1}

for n in range(1, len(A)+1):
    S.append(S[-1] + (int(A[-n])*(10**(n-1))))
    sm = S[-1] % 2019
    S.pop(0)
    if sm in dic:
        dic[sm] += 1
    else:
        dic[sm] = 1

result = 0

for num in dic:
    n = dic[num]
    result += (n*(n-1)/2)


print(int(result))

Submission status: Time Limit Exceeded

Solution code:
A = input()

S = [0]
dic = {0:1}

for n in range(1, len(A)+1):
    S.append(S[-1] + (int(A[-n])*(10**(n-1))))
    sm = S[-1] % 2019
    if sm in dic:
        dic[sm] += 1
    else:
        dic[sm] = 1

result = 0

for num in dic:
    n = dic[num]
    result += (n*(n-1)/2)


print(int(result))

Submission status: Time Limit Exceeded

Solution code:
s = input()
mod_list = [0]*2019
mod_list[0] = 1

for i in range(len(s)):
    mod_list[int(s[-(i+1):])%2019] += 1


print(sum([i*(i-1)//2 for i in mod_list]))

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

    n = len(S)
    counts = [0] * 2019
    counts[0] += 1
    T = [0] * (n+1)
    for i in reversed(range(n)):
        T[i] = (10**(n-1-i) * int(S[i]) + T[i+1]) % 2019
        counts[T[i]] += 1

    ans = 0
    for c in counts:
        ans += c*(c-1)//2  # cC2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    S = input().rstrip()

    n = len(S)
    T = [0] * (n+1)
    for i in reversed(range(n)):
        T[i] = (10**(n-1-i) * int(S[i]) + T[i+1]) % 2019

    c = Counter(T)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2  # vC2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
A = input()

S = [0]


for n in range(1, len(A)+1):
    S.append(S[-1] + (int(A[-n])*(10**(n-1))))

result = 0

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


print(result)

Submission status: Time Limit Exceeded

Solution code:
A = list(input())

S = [0]


for n in range(1, len(A)+1):
    S.append(S[-1] + (int(A[-n])*(10**(n-1))))

result = 0

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


print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
s = input()
mod_list = [0]*2019
mod_list[0] = 1

for i in range(len(s)):
    mod_list[int(s[-(i+1):])%2019] += 1


print(sum(np.array(mod_list) * (np.array(mod_list)-1) // 2))

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline

P = 2019


def main():
    S = input().rstrip()

    n = len(S)
    T = [int(S[k:]) % P for k in range(n)]
    T.append(0)  # T_{n+1} = 0

    c = Counter(T)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2  # vC2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = len(S)
dp = [0]*2019
dp[0] = 1
ans = 0
for i in range(1,n+1):
  ss = int(S[n-i:n+1])
  dp[ss%2019] += 1
for j in dp:
  ans += j*(j-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
t=[0]*2019
d=[0]*2019
a=[0]*2019
import numpy as np
def python_list_add(in1, in2):
    wrk = np.array(in1) + np.array(in2)
    return wrk.tolist()

for i in range(len(S)):
  for j in range(2019):
    t[j]=d[(202*(j-int(S[i])))%2019]+int(j==int(S[i]))
  for k in range(2019):
    d[k]=t[k]
  a=python_list_add(a,d)

print(a[0])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
s = input()[::-1]
mod_list = [0]*2019
mod_list[0] = 1

for i in range(len(s)):
    mod_list[int(s[:i+1][::-1])%2019] += 1


print(sum(np.array(mod_list) * (np.array(mod_list)-1) // 2))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import deque
s = input()

s = [int(s[-(i+1):]) for i in range(len(s))]
s = deque(s)
s.appendleft(0)
s = list(s)
s = list(np.array(s) % 2019)

from collections import Counter
c = Counter(s)
values = list(c.values())
print(sum([i*(i-1)//2 for i in values]))

Submission status: Time Limit Exceeded

Solution code:
S = input()
list(S)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import deque
s = input()

s = [int(s[-(i+1):]) for i in range(len(s))]
s = deque(s)
s.appendleft(0)
s = list(s)
s = list(np.array(s) % 2019)

from collections import Counter
c = Counter(s)
values = np.array(list(c.values()))
values = list(values[values>1])
print(sum([i*(i-1)//2 for i in values]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import deque
s = input()

s = [int(s[-(i+1):]) for i in range(len(s))]
s = deque(s)
s.appendleft(0)
s = list(s)
s = list(np.array(s) % 2019)

###nCr

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

###

from collections import Counter
c = Counter(s)
values = np.array(list(c.values()))
values = list(values[values>1])
print(sum([cmb(i, 2) for i in values]))

Submission status: Time Limit Exceeded

Solution code:
S = input()[::-1]

modCount = [0]*2019
modCount[0] = 1
mod = 0
result = 0

for i in range(len(S)):
  mod = (int(S[i:i+1])*(10**i)+mod)%2019
  result += modCount[mod]
  modCount[mod] += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
S = input()
index = 0
len_S = len(S)
count = 0


while index + 4 <= len_S:
    end = 4
    while index + end <= len_S:
        tmp = S[index : index + end]
        if int(tmp) % 2019 == 0:
            count += 1
        end += 1
    index += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
import math

S = input()
SS = int(S)
mod = 1000000000 + 7

mm = [0] * (2019)
mm[0] = 1
T = 0
ten = 1
for i in range(len(S)):
    if i > 0:
        ten = ten * 10
    s = SS % 10
    SS = SS // 10
    T = T + ( s * (ten) )
    mm[T % 2019 ] += 1

ans = 0

for m in mm:
    ans += int( (m * (m-1) ) / 2 )

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
res = 0
for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        num = int(S[i:j])
        if num % 2019 == 0:
            res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
import math

S = input()

mod = 1000000000 + 7

mm = [0] * (2019)
mm[0] = 1
T = 0
ten = 1
for ind , s in enumerate( S[::-1] ):
    if ind > 0:
        ten = ten * 10
    T = T + ( int(s) * (ten) )
    mm[T % 2019 ] += 1

ans = 0

for m in mm:
    ans += int( (m * (m-1) ) / 2 )

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

mods = [0]*2019
result = 0

for i in range(len(S)+1):
  x = int(S[len(S)-i: len(S)])%2019 if i>0 else 0
  result += mods[x]
  mods[x] += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
a = input()
length = len(a)
      
sum = 0

for digits in range(4, length):
  for start in range(0, length - digits + 1):
    if int(a[start:start + digits]) % 2019 == 0:
      sum += 1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
import math

S = input()

mm = [0] * (2019)
mm[0] = 1
T = 0

for ind , s in enumerate( S[::-1] ):
    T = T + ( int(s) * (10 ** (ind) ))
    mm[T % 2019 ] += 1

ans = 0

for m in mm:
    ans += int( (m * (m-1) ) / 2 )

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
length = len(s)
s = int(s)

sum = 0

for i in range(0, length - 3):
  for j in range(i + 3, length):
    i1 = 10 ** (length - i)
    j1 = 10 ** (length - j - 1)
    inte = (s % i1) // j1
    if inte % 2019 == 0:
      sum += 1   
      
print(sum)

Submission status: Time Limit Exceeded

Solution code:
S = input()
MOD = 2019
cnt = [0]*MOD
cur = 0 # 現在考えている部分文字列
cnt[cur] = 1 # 部分文字列'0'も作れると考える
d = 1 # 位を表す
for s in S[::-1]:
    cur += int(s)*d # 新たな桁を追加
    cur %= MOD
    cnt[cur] += 1
    # 後処理
    d *= 10 # 位を上げる
    #d %= MOD # ただし数が巨大になるため、計算量を減らすために剰余をとる
ans = 0
for c in cnt:
    ans += c*(c-1)//2
print (ans)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
L = len(s)
dict = [0] * 2019
dict[0] += 1
num = 0
for i in range(L-1, (-1), (-1)):
    num += (int(s[i]) * pow(10,(L-i-1)))%2019
    amari = num % 2019
    dict[amari] += 1
ans = 0
for j in range(2019):
    ans += (dict[j]*(dict[j]-1))/2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
S = input()
res = 0
for i in range(len(S)-3):
    for j in range(i+1, len(S)+1):
        num = int(S[i:j])
        if num % 2019 == 0:
            res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
s = input()

sum = 0
for i in range(0, len(s)):
  for j in range(i + 3, len(s)):
    inte = int(s[i:j + 1])
    if inte % 2019 == 0:
      sum += 1   
      
print(sum)

Submission status: Time Limit Exceeded

Solution code:
s = input()
counts = [0]*2019
counts[0] += 1
num = 0
d = 1
for c in reversed(s):
    num += int(c)%2019 * d%2019
    counts[num % 2019] += 1
    d *= 10
ans = 0
for count in counts:
    ans += count*(count -1) // 2
print(ans)