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:
# multiple
line = input()
ln = [0]
combi = 0
for i in range(1,len(line) + 1):
    ti1 = (ln[-1] +(int(line[-1*i])*10**(i-1))%2019)%2019
    combi+= ln.count(ti1)
    ln.append(ti1)
print(combi)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict

lines = 1
inp = list()

for _ in range(lines):
    inp.append(sys.stdin.readline().strip())


s = inp[0]
n = len(s)

tmp = defaultdict(int)
tmp[0] = 1

b = 0

for i in range(1, n + 1):
    a = int(s[n - i])
    b = ((10 ** (i-1)) * a + b) % 2019
    tmp[b] += 1

result = 0

for v in tmp.values():
    result += int(v * (v - 1) / 2)

print(result)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
L = len(s)
dict = [0] * 2019
dict[0] += 1
for i in range(L):
  amari = (int(s[i:])) % 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:
import collections
s = input()
mod = 2019
mod_lst = [0]*mod
mod_lst[0] +=1
tmp = 0
t = 1
for i in reversed(s):
    x = int(i) * t
    y = (x % mod + tmp) % mod
    mod_lst[y] += 1
    tmp = y
    t = t*10


count = 0
for j in mod_lst:
    a = j*(j-1)//2
    count += a
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
s = input()
mod = 2019
mod_lst = [0]
tmp = 0
t = 1
for i in reversed(s):
    x = int(i) * t
    y = (x % mod + tmp) % mod
    mod_lst.append(y)
    tmp = y
    t = t*10

lst_count = collections.Counter(mod_lst)
count = 0
for j in lst_count.values():
    a = j*(j-1)//2
    count += a
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
L = len(s)
dict = {}
for i in range(L):
  amari = (int(s[i:])) % 2019
  if not(amari in dict.keys()):
    dict[amari] = 1
  else:
    dict[amari] += 1
if not(0 in dict.keys()):
    dict[0] = 1
else:
    dict[0] += 1
ans = 0
for key in dict.keys():
  ans += (dict[key]*(dict[key]-1))/2
print(int(ans))

Submission status: Time Limit Exceeded

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

sum_of_digits = 0

cnts = [0] * 2019
cnts[0] = 1

d = 1

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

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
# S="1817181712114"
N=len(S)
ans=0
for i in range(N):
    for j in range(N):
        if j>i+3:
            tmp=int(S[i:j+1])
            # print(tmp)
            if tmp%2019==0:
                # print("i,j=",i+1,j+1)
                ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
A = [0]*(N+1)
count = 0
for i in range(1,N):
    A[1] = int(S[-1])
    A[i+1] = (int(A[i])+int(S[-i-1])*10**i%2019)%2019  
    if A[i+1] in A[0:i+1]:
        a = A[0:i+1].count(A[i+1])
        count += a    
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

sn = list(map(int, list(input())))
n = len(sn)

tmp = 0
mn = [None] * n
for i in range(n):
    j = n - i - 1
    tmp += (sn[j] * 10 ** i) % 2019
    mn[j] = tmp % 2019
mn.append(0)

counter = Counter(mn)
ans = 0
for c in counter.values():
    if c >= 2:
        ans += c * (c - 1) // 2
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

sn = list(map(int, list(input())))
n = len(sn)

tmp = 0
mn = [None] * n
for i in range(n):
    j = n - i - 1
    tmp += sn[j] * 10 ** i
    mn[j] = tmp % 2019
mn.append(0)

counter = Counter(mn)
ans = 0
for c in counter.values():
    if c >= 2:
        ans += c * (c - 1) // 2
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()

si = [0] * (len(s)+1) #mod2019の累積和用に
tmp = 0
for i in range(1,len(s)+1): #累積和の作成
    tmp += int(s[-i]) * 10**(i-1) % 2019
    si[i] = tmp % 2019

c = Counter(si)
ans = 0
for b in c.values():#aがb回出てきたよ
    ans += b*(b-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()

si = [0] * (len(s)+1) #mod2019の累積和用に
tmp = 0
for i in range(1,len(s)+1): #累積和の作成
    tmp += int(s[-i]) * 10**(i-1) % 2019
    si[i] = tmp % 2019

c = Counter(si)
ans = 0
for a,b in c.items():#aがb回出てきたよ
    ans += b*(b-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
N = len(s)
array = [0]*2019
array[0] += 1
count = 0
d = 0
for i in reversed(range(0, N)):
    x = s[i:N]
    y = int(x)
    d = ( d + int( s[i] ) * 10 ** ( N - i - 1 ) % 2019 ) % 2019
    array[d] += 1
for i in array:
    count += i*(i-1)/2
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
N = len(s)
array = [0]*2019
array[0] += 1
count = 0
for i in reversed(range(0, N)):
    x = s[i:N]
    y = int(x)
    array[y%2019] += 1
for i in array:
    count += i*(i-1)/2
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

counter = 0

for i in range(len(s) + 1):
    for j in range(len(s) + 1):
        if i + j + 4 < len(s) + 1:
            a_str = s[i: i + j + 4]
            if(len(a_str) < 4):
                break
            a = int(''.join(map(str, a_str)))
            if(a % 2019 == 0):
                counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
a=0
rs=reversed(s)
for i in rs:
    ans[tmp%2019]+=1
    tmp=tmp+int(i)*10**a
    a+=1
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
a=0
for i in reversed(s):
    ans[tmp%2019]+=1
    tmp=tmp+int(i)*10**a
    a+=1
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
s=input()
count=0

for i in range(len(s)-3):
  for j in range(i+4,len(s)+1):
    #print(i,j)
    n= int(s[i:j])
    if n % 2019 == 0:
      #print("!")
      count=count+1
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
N = len(s)
array = [0]*2019
array[0] += 1
count = 0
for i in reversed(range(0, N)):
    x = s[i:N]
    y = int(x)
    array[y%2019] += 1

for i in array:
    count += i*(i-1)/2
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
numberString= input()
modList={};
modList[0]=1;
iPos=0
answerNum=0

while iPos<len(numberString):
  checkNum=int(numberString[iPos:])%2019
  if checkNum in modList:
    answerNum+=modList[checkNum]
    modList[checkNum]+=1
  else :
  	modList[checkNum]=1
  iPos+=1

print(answerNum)

Submission status: Time Limit Exceeded

Solution code:
numberString= input()
modList={};
modList[0]=1;
iPos=0
answerNum=0

while iPos<len(numberString):
  checkNum=int(numberString[iPos:])%2019
  if checkNum in modList:
    answerNum+=modList[checkNum]
    modList[checkNum]+=1
  else :
  	modList[checkNum]=1
  iPos+=1

print(int(answerNum))

Submission status: Time Limit Exceeded

Solution code:
# multiple
line = input()
ln = []
combi = 0
for i in range(len(line)):
    n = int(line[i:])% 2019 
    combi += ln.count(n)
    ln.append(n)
    #print( str(i) +',' +str(combi)+','+ str(n), ln)
n = 0
combi += ln.count(n)
ln.append(n)
#print( str(i) +',' +str(combi)+','+ str(n), ln)
print(combi)

Submission status: Time Limit Exceeded

Solution code:
numberString= input()
modList={};
modList[0]=1;
iPos=0
while iPos<len(numberString):
  checkNum=int(numberString[iPos:])%2019
  if checkNum in modList:
    modList[checkNum]+=1
  else :
  	modList[checkNum]=1
  iPos+=1
answerNum=0
for modCount in modList.values():
	answerNum+=modCount*(modCount-1)/2

print(int(answerNum))

Submission status: Time Limit Exceeded

Solution code:
s = input()+"0"
m = dict()
for i in range(len(s)):
    mod = int(s[i:])%2019
    if mod in m.keys():
        m[mod] += 1
    else:
        m[mod] = 1

def c2(n):
    return n*(n-1)//2

print(sum([c2(i) for i in m.values()]))

Submission status: Time Limit Exceeded

Solution code:
s = input()

dp = [0 for i in range(2019)]
dp2 = [0 for i in range(2019)]
ans = 0
for i in range(len(s)):
    for j in range(2019):
        dp2[(10*j + int(s[i])) % 2019] += dp[j]
    dp2[int(s[i])] += 1
    dp = dp2[:]
    dp2 = [0 for i in range(2019)]
    # print(dp)
    ans += dp[0]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

modList = [0] * 2019 # あまりは0～2018の2019個

ans = 0

modList[0] = 1 # 解答でいうT(n)=0 の場合

# 最大20万回ループ、時間かかるならＤＰする？
# ↓ではTLEになった
# for i in range(len(S)):
#     m = int(S[i:]) % 2019
#     modList[m] += 1
T = 0
for i in range(1,len(S)+1):
    # T += int(S[-i]) * 10**i
    T += int(S[-i]) * ((10**i) % 2019)
    modList[T % 2019] +=1


#print(modList)

for j in modList:
    if j <= 1:
        continue
    else:
        ans += j*(j-1)/2

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
S = input()

modList = [0] * 2019 # あまりは0～2018の2019個

ans = 0

modList[0] = 1 # 解答でいうT(n)=0 の場合

# 最大20万回ループ、時間かかるならＤＰする？
# ↓ではTLEになった
# for i in range(len(S)):
#     m = int(S[i:]) % 2019
#     modList[m] += 1
T = 0
for i in range(1,len(S)+1):
    T += int(S[-i]) * 10**i
    modList[T % 2019] += 1


#print(modList)

for j in modList:
    if j <= 1:
        continue
    else:
        ans += j*(j-1)/2

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
S = input()

modList = [0] * 2019 # あまりは0～2018の2019個

ans = 0

modList[0] = 1 # 解答でいうT(n)=0 の場合

# 最大20万回ループ、時間かかるならＤＰする？
for i in range(len(S)):
    m = int(S[i:]) % 2019
    modList[m] += 1

#print(modList)

for j in modList:
    if j <= 1:
        continue
    else:
        ans += j*(j-1)/2

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
s=input()
t=0
p=[0]*2019
for i,c in enumerate(s[::-1]):
  t+=int(c)*10**i
  t%=2019
  p[t]+=1
print(p[0]+sum((i*(i-1)//2) for i in p[1:]))

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
dp=[0]*2019
m=[0]*n
m[0]=int(s)%2019
dp[m[0]]+=1
for i in range(n-1):
    m[i+1]=(m[i]-int(s[i])*10**(n-i-1))%2019
    dp[m[i+1]]+=1
count=0
count+=dp[0]
for j in dp:
    count+=1/2*j*(j-1)
    
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
dp=[0]*2019
m=[0]*n
m[0]=int(s)%2019
dp[m[0]]+=1
for i in range(n-1):
    m[i+1]=(m[i]-int(s[i])*10**(n-i-1)%2019)%2019
    dp[m[i+1]]+=1
count=0
count+=dp[0]
for j in dp:
    count+=1/2*j*(j-1)
    
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
S=str(input())
n=len(S)
u=0
d=deque([int(s) for s in S])
for i in range(n):
    a=d[0]
    for j in range(1,n-i):
        a=10*a+d[j]
        if a%2019==0:
            u+=1
    d.popleft()
print(u)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
p=[0]*n
p[0]=int(s)%2019
for i in range(n-1):
    p[i+1]=(p[i]-(int(s[i])*10**(n-i-1))%2019)%2019
import collections
pcount=collections.Counter(p)
count=0
count+=pcount[0]
for j in pcount.values():
    count+=1/2*j*(j-1)
print(int(count))

Submission status: Time Limit Exceeded

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

count = [0] * 2019
count[0] = 1

for i in range(leng):
    remainder = int(S[i:]) % 2019
    count[remainder] += 1

res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2
    
print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
d=deque([])
S=str(input())
n=len(S)
u=0
for s in S:
    d.append(int(s))
while n>0:
    a=d[0]
    for j in range(1,n):
        a=10*a+d[j]
        if a%2019==0:
            u+=1
    n=n-1
    d.popleft()
print(u)

Submission status: Time Limit Exceeded

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

count = [0] * 2019
count[0] = 1

for i in range(leng):
    remainder = int(S[i:]) % 2019
    count[remainder] += 1

res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2
    
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
count = 0
for i in range(5,l+1):
  for j in range(l-i+1):
    if float(S[j:j+i]) % 2019 == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
count = 0
for i in range(4,l+1):
  for j in range(l-i+1):
    if float(S[j:j+i]) % 2019 == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

length = len(S)
dp = [0] * (length + 2)

times = 1
for x in range(1, length + 1):
    dp[x] = (dp[x - 1] + int(S[x - 1]) * (times % 2019)) % 2019
    times *= 10


cnt = [0] * 2020
for x in range(length + 1):
    cnt[dp[x]] += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019 # mod 2019での結果を入れる箱（0 ~ 2018）
counts[0] = 1 # T_n = 0　のとき

num, d = 0, 1

for char in s:
    num += int(char) * d # 一の位から順に足していく
    d *= 10
    counts[num % 2019] += 1
    
ans = 0
for cnt in counts:
    ans += cnt * (cnt-1) //2 # n_C_2 
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
S = list(reversed(input()))
size = len(S)
ans = 0
d = [-1]*(size)#余りを格納

def cnt(num):
  c = collections.Counter(d)
  return c[num]
  
for i in range(size):
  s = ''.join(reversed(S[:i+1]))
  md = int(s) % 2019
  if md == 0:#その数自身が割り切れた場合
    ans+=1
  ans += cnt(md)
  d[i] = md

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]
mod_cnt = [0] * 2019
mod_cnt[0] = 1
t = 0
d = 1
for c in s:
    t += int(c) * d
    mod_cnt[t % 2019] += 1
    d *= 10
print(sum([m * (m - 1) // 2 for m in mod_cnt]))

Submission status: Time Limit Exceeded

Solution code:
S = list(reversed(input()))
size = len(S)
ans = 0
d = [-1]*(size)#余りを格納

def cnt(num):
  return d.count(num)
  
for i in range(size):
  s = ''.join(reversed(S[:i+1]))
  md = int(s) % 2019
  if md == 0:#その数自身が割り切れた場合
    ans+=1
  ans += cnt(md)
  d[i] = md

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input() # 文字入力
length = len(S)
dicts={}
nums = list(map(int, list(S)))
num = int(nums[length-1])%2019
dicts[num] = 1

for i in range(1,length):
    temp = (nums[length-i-1]*(10**i)) % 2019
    
    num = (temp + num) % 2019
#     print(S[i:], num)
    if num in dicts:
        dicts[num] += 1
    else:
        dicts[num] = 1
count = dicts[0] if 0 in dicts else 0
for k,v in dicts.items():
    if k==0:
        continue
    if v>=2:
        count+=(v*(v-1))//2

print(int(count))

Submission status: Time Limit Exceeded

Solution code:
S=input() # 文字入力
length = len(S)
dicts={}
num = int(S[length-1])%2019
dicts[num] = 1

for i in range(1,length):
    temp = (int(S[length-i-1])*(10**i)) % 2019
    
    num = (temp + num) % 2019
#     print(S[i:], num)
    if num in dicts:
        dicts[num] += 1
    else:
        dicts[num] = 1
count = dicts[0] if 0 in dicts else 0
for k,v in dicts.items():
    if k==0:
        continue
    if v>=2:
        count+=(v*(v-1))//2

print(int(count))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
t_list = list(map(lambda i: int(s[-i:]) % 2019, range(1, len(s) + 1)))
t_list.append(0)
counter = Counter(t_list)
print(sum([m * (m - 1) // 2 for m in counter.values()]))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
#import time
#from sys import stdin

#start = time.time()#計測始
def main():
  s = str(input())
  ss = reversed(s)
  n=len(s)
  mlist=deque([0])
  slist=""
  for sss in ss:
    slist = sss + slist
    m = int(slist)%2019
    mlist.append(m)

  ll=len(mlist)
  l=len(set(mlist))

  print(ll-l)
  
main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
t_list = list()
for i in range(1, len(s) + 1):
    t_list.append(int(s[-i:]) % 2019)
t_list.append(0)
counter = Counter(t_list)
print(sum([m * (m - 1) // 2 for m in counter.values()]))

Submission status: Time Limit Exceeded

Solution code:
S=input() # 文字入力
length = len(S)
dicts={}

for i in range(length):
    num = int(S[i:])%2019
#     print(S[i:], num)
    if num in dicts:
        dicts[num] += 1
    else:
        dicts[num] = 1
count = dicts[0] if 0 in dicts else 0
for k,v in dicts.items():
    if k==0:
        continue
    if v>=2:
        count+=(v*(v-1))//2

print(int(count))

Submission status: Time Limit Exceeded

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

cnt = [0] * 2019
a = int(S[n-1])
cnt[a%2019] += 1

for i in S[n-1::-1]:
  a = int(i+str(a))
  mod = a%2019
  cnt[mod] += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import time

#start = time.time()#計測始
s = str(input())
#end = time.time()#計測終
n=len(s)
span=1
mlist=deque([0])
slist=""

while span<n+1:
  slist = s[n-span] + slist
  m = int(slist)%2019
  mlist.append(m)
  span+=1
  

ll=len(mlist)
l=len(set(mlist))
#print(set(mlist))

print(ll-l)

#print(f"{end-start}sec.")#計測出力

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
N = len(S)
cnt = 0

for i in range(N-3):
    for j in range(i+3,N+1):
        if int(S[i:j]) % 2019 == 0:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2


print(int(counter))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import time
start = time.time()#計測始
 
s = str(input())
n=len(s)
#span :int=1
mlist=deque("0")
slist :str=""
  
for span in range(n):
  slist = str(s[n-span-1]) + slist
  #print(str(slist))
  m = int(slist)%2019
  mlist.append(str(m))
  #span+=1
  
ll=len(mlist)
l=len(set(mlist))
print(ll-l)
end = time.time()#計測終
#print(f"{end-start}sec.")#計測出力

Submission status: Time Limit Exceeded

Solution code:

x=set(str(i*2019) for i in range(1,200000//4+1))


#print(x)
ans=0
s=input()
for j in range(4,200000//4+1):
    for i in range(len(s)-j+1):
#        print(s[i:i+j])
        if s[i:i+j] in x:
            ans+=1
        

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(map(int,input()))[::-1] #逆順

counter = 0
amari = [0]*2019

s,d = 0,1

for i in S:
    if i == 0:
        s += i *d
        d *= 10

    else:
        s += i *d
        amari[s%2019] += 1
        d *= 10


for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2

counter += amari[0]

print(int(counter))

Submission status: Time Limit Exceeded

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

sum_of_digits = 0

cnts = [0] * 2019

cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
#    d %= 2019
    cnts[sum_of_digits] += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()[::-1]

    sum_of_digits = 0

    cnts = [0] * 2019

    cnts[0] = 1

    for i in range(len(s)):
        sum_of_digits += int(s[i]) * pow(10, i) % 2019
        sum_of_digits %= 2019
        cnts[sum_of_digits] += 1


    ans = 0

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import time
start = time.time()#計測始

s = str(input())

n=len(s)
i :int=0
ss=deque()
while i<n:
  ss.insert(0,str(s[i]))
  i+=1
  #print(ss)
span :int=1
mlist=deque("0")
slist :str=""

for sss in ss:
  slist = str(sss) + slist
  m = int(slist)%2019
  mlist.append(str(m))
  #print(str(mlist))
  #span+=1

ll=len(mlist)
l=len(set(mlist))
print(ll-l)
end = time.time()#計測終
#print(f"{end-start}sec.")#計測出力

Submission status: Time Limit Exceeded

Solution code:
import collections

S = input()

list1 = []
result = 0

for i in range(len(S)):
    list1.append(int(S[-i:])%2019)
    
a = collections.Counter(list1)

result += a[0]

val = list(a.values())
for j in range(len(a.values())):
    result += val[j]*(val[j]-1)/2
    
print(int(result))

Submission status: Time Limit Exceeded

Solution code:
S = input().strip()
n = len(S)

A=[]
n = 0
for i in range(len(S)):
  if int(S[i:])%2019!=0:
    A.append(int(S[i:])%2019)
  else:
    n += 1

from collections import Counter
cnt = Counter(A)
for v in cnt.values():
    n += v*(v-1)/2
print(int(n))

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()[::-1]

    sum_of_digits = 0

    cnts = [0] * 2019

    cnts[0] = 1

    for i in range(len(s)):
        sum_of_digits += int(s[i]) * pow(10, i)
        sum_of_digits %= 2019
        cnts[sum_of_digits] += 1

    ans = 0

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
def main():
    mod=2019
    S=input().strip()
    l=len(S)
    M=[0]*(l+1)
    p=1
    for i in range(1,l+1):
        x=int(S[l-i])
        M[i]=(M[i-1]+x*p)%mod
        p*=10
    C=Counter(M)
    ans=0
    for m in C.values():
        ans+=m*(m-1)//2
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
def main():
    mod=2019
    S=input().strip()
    l=len(S)
    M=[0]*(l+1)
    p=1
    for i in range(1,l+1):
        x=int(S[l-i])
        M[i]=(M[i-1]+x*p)%mod
        p*=10
    C=Counter(M)
    ans=0
    for _,m in C.items():
        ans+=m*(m-1)//2
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections

S = input()

list1 = []
list2 = []
result = 0

for i in range(len(S)):
    if int(S[-i:])%2019==0:
        result += 1
    list1.append(int(S[-i:])%2019)
a = collections.Counter(list1)
val = list(a.values())
for j in range(len(a.values())):
    result += val[j]*(val[j]-1)/2
print(int(result))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
def main():
    mod=2019
    S=input().strip()
    M=[0]
    p=1
    for s in S[::-1]:
        x=int(s)
        M.append((M[-1]+x*p)%mod)
        p*=10
    C=Counter(M)
    ans=0
    for _,m in C.items():
        ans+=m*(m-1)//2
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = input()
l = len(n)
mod = [0]*2019
mod[0] += 1

for i in range(l):
  a = int(n[i:]) % 2019
  mod[a] += 1

res = 0  
for m in mod:
  res += m*(m-1)/2
print(int(res))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A = list(map(int, input()))
N = len(A)
mod = 2019

dp0 = [0] * mod
dp1 = [0] * mod
dp2 = [0] * mod
dp0[0] = 1
for i, a in enumerate(A):
    nxt0 = [0] * mod
    nxt1 = [0] * mod
    nxt2 = [0] * mod
    nxt0[0] = dp0[0]
    nxt1[a] = dp0[0]
    for j in range(mod):
        nxt = (j*10+a) % mod
        nxt1[nxt] += dp1[j]
        nxt2[nxt] += dp1[j]
        nxt2[j] += dp2[j]
    dp0 = nxt0
    dp1 = nxt1
    dp2 = nxt2
ans = dp2[0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A = list(map(int, input()))
N = len(A)
mod = 2019

dp0 = list2d(2, mod, 0)
dp1 = list2d(2, mod, 0)
dp2 = list2d(2, mod, 0)
dp0[0][0] = 1
for i, a in enumerate(A):
    dp0[(i+1)&1][0] = dp0[i&1][0]
    dp1[(i+1)&1][a] = dp0[i&1][0]
    for j in range(mod):
        nxt = (j*10+a) % mod
        dp1[(i+1)&1][nxt] += dp1[i&1][j]
        dp2[(i+1)&1][nxt] += dp1[i&1][j]
        dp2[(i+1)&1][j] += dp2[i&1][j]
    dp0[i&1] = [0] * mod
    dp1[i&1] = [0] * mod
    dp2[i&1] = [0] * mod
ans = dp2[N&1][0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 2019
s = input()
s = s[::-1]
a = []
for i in range(len(s)):
    a.append(((10**i)*int(s[i])) % MOD)

sum = [0]
mp = {0 : 1}
for i in range(len(s)):
    tmp = (sum[i] + a[i]) % MOD
    sum.append(tmp)
    mp.setdefault(tmp, 0)
    mp[tmp] += 1

ans = 0
for val in mp.values():
    ans += val*(val-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 2019
s = input()
s = s[::-1]
a = []
for i in range(len(s)):
    a.append(((10**i)*int(s[i])) % MOD)

sum = [0]
mp = {0 : 1}
for i in range(len(s)):
    tmp = (sum[i] + a[i]) % MOD
    sum.append(tmp)
    mp.setdefault(tmp, 0)
    mp[tmp] += 1

ans = 0
for val in mp.values():
    ans += val*(val-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=input()
ans=0
for i in range(len(N)-3):
	for j in range(len(N)-i-3):
  		if ((int(N)%(10**(len(N)-j)))//(10**(len(N)-i-4-j)))%2019==0:ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
n = len(s)
mod_list = [0] * 2019

for i in range(n):
    num = int(''.join(s[n - i - 1:n])) % 2019
    mod_list[num] += 1

ans = mod_list[0]
for cnt in range(1, 2019):
    ans += mod_list[cnt] * (mod_list[cnt] - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
#import time
#start = time.time()#計測始

s = str(input())
n=len(s)
span :int=1
mlist=deque("0")
slist :str=""

while span<int(n)+1:
  slist = str(s[n-span]) + slist
  #print(str(slist))
  m = int(slist)%2019
  mlist.append(str(m))
  span+=1

ll=len(mlist)
l=len(set(mlist))
print(ll-l)
#end = time.time()#計測終
#print(f"{end-start}sec.")#計測出力

Submission status: Time Limit Exceeded

Solution code:
N=input()
lis=[]
for i in range(len(N)-3):
	for j in range(len(N)-i-3):
  		lis+=[(int(N)%(10**(len(N)-j)))//(10**(len(N)-i-4-j))]
print(len(list(filter(lambda x:x%2019==0,lis))))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A = list(map(int, input()))
N = len(A)
mod = 2019

dp0 = list2d(N+1, mod, 0)
dp1 = list2d(N+1, mod, 0)
dp2 = list2d(N+1, mod, 0)
dp0[0][0] = 1
for i, a in enumerate(A):
    dp0[i+1][0] = dp0[i][0]
    dp1[i+1][a] = dp0[i][0]
    for j in range(mod):
        nxt = (j*10+a) % mod
        dp1[i+1][nxt] += dp1[i][j]
        dp2[i+1][nxt] += dp1[i][j]
        dp2[i+1][j] += dp2[i][j]
ans = dp2[N][0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(map(int,input()))

counter = 0
amari = [0]*2019

s = 0
for i in range(len(S)):
    if S[len(S)-i-1] == 0:
        continue
    else:
        s += S[len(S)-i-1] * 10**i
        s = s % 2019
        amari[s] += 1

for i in range(2019):
    counter += amari[i] * (amari[i]-1) / 2

counter += amari[0]

print(int(counter))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

S = input()
T_mod = np.array([int(S[k:]) % 2019 for k in range(len(S))] + [0])
u, counts = np.unique(T_mod, return_counts=True)
print(int(sum((counts * (counts - 1)) / 2)))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
l = len(s)
ans = 0
for i in range(l - 3):
    for j in range(i + 4, l + 1):
        k = int("".join(s[i: j]))
        if k % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

S = input()
T = np.array([int(S[k:]) for k in range(len(S))] + [0])
T_mod = T % 2019
u, counts = np.unique(T_mod, return_counts=True)
print(int(sum((counts * (counts - 1)) / 2)))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
s = input().strip()
if len(s) <= 3:
  print(0)
  exit()
chk = [0]*2019
for i in range(len(s)):
  c = int(s[i:])
  chk[c%2019] += 1
ans = chk[0]
for i in chk:
  ans += i*(i-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
	S = input()
	L = len(S)
	lst = [0] * 2019
	lst[0] = 1
	amari = 0
	ans = 0
	for i in range(1,L+1):
		amari = ( int(S[L-i]) * pow(10,i-1) + amari ) % 2019
		lst[amari] += 1

	for i in range(2019):
		m = lst[i]
		ans += m * (m-1) / 2

	print(int(ans))