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:
s = input()
u = [0]
for i in range(len(s)):
    u.append((u[i]+int(s[::-1][i])*10**i)%2019)
import collections
u2 = collections.Counter(u)
print(sum([int(i*(i-1)/2) for i in u2.values()]))

Submission status: Time Limit Exceeded

Solution code:
import collections


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


s = input()
ans = 0
lst_mod = [0]*2019  # O(N)で回した連続値のmod(2019)の値
lst_mod[0] += 1
for i in range(len(s)):
    lst_mod[int(s[i:]) % 2019] += 1
for mod in lst_mod:
    ans += comb(mod)
print(int(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    S = readline().strip()[::-1]
    N = len(S)

    a = [0]
    s = 0
    for i in range(N):
        s += int(S[i]) * 10**i
        a.append(s % 2019)
    
    t = Counter(a)

    ans = 0
    for _, v in t.items():
        ans += v * (v-1) // 2
    
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    S = readline().strip()
    N = len(S)

    a = [0]
    for i in range(N):
        a.append(int(S[-(i+1):]) % 2019)

    t = Counter(a)

    ans = 0
    for _, v in t.items():
        ans += v * (v-1) // 2
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def calc(S):
    N = len(S)
    r = 0
    d = [0 for _ in range(2019)]
    d[0] = 1
    for i in range(N):
        r = (r + int(S[N - 1 - i]) * 10 ** i) % 2019
        d[r] += 1
    ans = 0
    for c in d:
        ans += c * (c - 1) // 2
    return ans


S = input()
print(calc(S))

Submission status: Time Limit Exceeded

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

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    #d%= 2019
    counts[num] += 1

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

print(ans) # 答えの出力
"""
def main(S):
    a = len(S)
    b = list(0 for j in range(4, a+1)
        for i in range(a-j+1)
            if int(S[i:i+j])%2019==0)
    print(len(b))
if __name__ == '__main__':
    main(S)
"""
"""
def solution(S):
    a = len(S)
    b = list(0 for j in range(4, a+1)
        for i in range(a-j+1)
            if int(S[i:i+j])%3==0 and int(S[i:i+j])%673==0)
    print(len(b))
solution(S)
"""
"""
def main(S):
    count = 0
    a = len(S)
    
    
    if int(S)%2019 == 0:
        count += 1
    for j in range(a):
        for i in range(j,a):
            if (int(S[j:]) - int(S[i:]))%2019 == 0:
                count += 1
    print(count)
if __name__ == '__main__':
    main(S)

"""

Submission status: Time Limit Exceeded

Solution code:
def calc(S):
    N = len(S)
    r = 0
    d = {0: 1}
    for i in range(N):
        r = (r + int(S[N - 1 - i]) * 10 ** i) % 2019
        d[r] = (d[r] if r in d else 0) + 1
    ans = 0
    for c in d:
        ans += d[c] * (d[c] - 1) // 2
    return ans


S = input()
print(calc(S))

Submission status: Time Limit Exceeded

Solution code:
def solve():
    def is_2019(num):
        if num%2019 ==0:
            return 1
        return 0
    S = input()
    dig = len(S)
    amari = [0]



    for i in reversed(range(dig)):
        amari.append(int(S[i:])%2019)
    amari = sorted(amari)

    data =[0]*2020
    ans = 0
    for num in amari:
        data[num] +=1
    for samenum in data:
        ans += samenum*(samenum-1)//2
    print(ans)




if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
S = list(map(int, list(input())))
N = len(S)
MOD = 2019
DP = [0] * MOD
DP[0] = 1

t = 0

for i in range(N):
  k = S[-1 - i]
  t = (t + k * 10 ** i) % MOD
  DP[t] += 1

ans = 0
for i in range(MOD):
  n = DP[i]
  ans += (n * (n - 1)) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
#print(len(S))
def check(i): return True if i % 2019 == 0 else False

ans = 0

for i in range(len(S)):
    for j in range(i+1, len(S)):
        #print(i,j)
        #print(S[i:j])
        if check(int(S[i:j+1])):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections


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


s = input()
ans = 0
lst_mod = []  # O(N)で回した連続値のmod(2019)の値
for i in range(len(s)):
    mod = int(s[i:]) % 2019
    lst_mod.append(mod)
    if mod == 0:
        ans = + 1

count = list(collections.Counter(lst_mod).values())
for i in range(len(count)):
    if count[i] == 1:
        continue
    ans += comb(count[i])
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
# # TLEだった
# s = input()
# counter = 0
# for i in range(3, len(s)+1):
#     snum = 0
#     for m in range(i):
#         snum += int(s[m])
#     num = int(s[0:i])
#     if num % 2019 == 0:
#         counter += 1
#     for j in range(1, len(s)-i+1):
#         snum -= int(s[j-1])
#         snum += int(s[j+i-1])
#         if snum % 3 != 0:
#             continue
#         num = int(s[j:j + i])
#         if num % 673 == 0:
#             counter += 1
# print(counter)

import collections


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


s = input()
ans = 0
lst_mod = []  # O(N)で回した連続値のmod(2019)の値
for i in range(len(s)):
    mod = int(s[i:]) % 2019
    lst_mod.append(mod)
    if mod == 0:
        ans = + 1

count = list(collections.Counter(lst_mod).values())
for i in range(len(count)):
    ans += comb(count[i])
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
s_inv = str(input())[::-1]
dp = [1]+[0]*2018
MOD = 0
k = 1
ans = 0
num = 0

for i in range(len(s_inv)):
  num+=int(s_inv[i])*k
  MOD = num % 2019
  dp[MOD] += 1
  k = k*10

for i in dp:
  ans += i*(i-1)/2

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=len(s)
l=[0]*2019
for i in range(1,k+1):
  l[(int(s[k-i:k])%2019)] += 1
x=0
for i in range(1,2019):
  x+=l[i]*(l[i]-1)//2
print(x+l[0])

Submission status: Time Limit Exceeded

Solution code:
import collections

s = input()
r = []

for i in range(len(s)):
    r.append(int(s[i: len(s)]) % 2019)


c = collections.Counter(r)
values = list(c.values())

cnt = 0
for num in values:
    if num < 2:
        continue
    
    cnt += num * (num - 1) // 2
cnt += c[0]

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()[::-1]

MOD = 2019
tmp = [0]*MOD
tmp[0] += 1
tens = 1
num = 0
for s in S:
    num += int(s) * tens
    key = num % MOD
    tmp[key] += 1
    tens *= 10

ans = 0
for i in tmp:
    ans += i*(i-1)//2

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Time Limit Exceeded

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()[::-1]
def nC2(n):
    if n<2:
        return 0
    return n*(n-1)//2

MOD = 2019
tmp = [0]*MOD
tmp[0] += 1
tens = 1
num = 0
for s in S:
    num += int(s) * tens
    key = num % MOD
    tmp[key] += 1
    tens *= 10

ans = 0
for i in tmp:
    ans += nC2(i)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(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
    num = sum_of_digits % 2019
    d *= 10
    cnts[num] += 1
 
ans = 0
    
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=len(s)
l=[]
for i in range(1,k+1):
  l.append(int(s[k-i:k])%2019)
l.sort()
x=0
for i in range(1,2019):
  m=l.count(i)
  x+=m*(m-1)//2
print(x+l.count(0))

Submission status: Time Limit Exceeded

Solution code:
S = input()

dp = [0] * 2019

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

ans = sum(x*(x-1)//2 for x in dp)
ans += dp[0]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a=input()
num=len(a)
mod_map={0:1}
moji_int=0
for i in range(-1,-num-1,-1):
    moji_int+=int(a[i])*(10**(-i-1)%2019)
    mod=moji_int%2019
    if mod not in mod_map:
        mod_map[mod]=1
    else:
        mod_map[mod]+=1

res=0
for i in mod_map.values():
    res+=int(i*(i-1)/2)
print(res)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
# 余りのリスト
counts = [0] * 2019
n, d = 0, 1

for s in S[::-1]:
    n += int(s) * d
    d *= 10
    n %= 2019
    counts[n] += 1
ans = counts[0]
for count in counts:
    ans += count * (count - 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
cnts = [0]*2019
cnts[0] = 1
ans = 0
for i in range(n):
    cnts[int(s[i:])%2019] += 1

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
mod = 2019
DP = [0] * mod
DP[0] = 1
t = 1
value = 0
for i in reversed(S):
    value += int(i) * t
    res = value % mod
    DP[res] += 1
    t *= 10
print(int(sum([i * (i-1) / 2 for i in DP])))

Submission status: Time Limit Exceeded

Solution code:
S = input()
mod = 2019
DP = [0] * mod
DP[0] = 1
t = 1
value = 0
for i in reversed(S):
    value += int(i) * t
    DP[value % mod] += 1
    t *= 10
print(int(sum([i * (i-1) / 2 for i in DP])))

Submission status: Time Limit Exceeded

Solution code:
a=input()
num=len(a)
mod_map={0:1}
moji_int=0
for i in range(-1,-num-1,-1):
    moji_int+=int(a[i])*10**(-i-1)
    mod=moji_int%2019
    if mod not in mod_map:
        mod_map[mod]=1
    else:
        mod_map[mod]+=1

res=0
for i in mod_map.values():
    res+=int(i*(i-1)/2)
print(res)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
alist = [int(s[i:])%2019 for i in range(n)] + [0]
from collections import Counter
a_counter = Counter(alist)
a_counter = a_counter.most_common()
ans = 0

for i in range(len(a_counter)):
    if a_counter[i][1] >= 2:
        ans += a_counter[i][1]*(a_counter[i][1]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

s = str(input())
n=len(s)
left :int=1
mlist=deque("0")
while left<int(n)+1:
  m = int(s[n-left:n])%2019
  mlist.append(str(m))
  left+=1

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
l=len(s)
cnts=[0]*2019
cnts[0]=1
mod=2019
ans=0
for i in range(1,l+1):
    num = int(s[-i:])%mod
    cnts[num]+=1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = list(S)
for i in range(len(s)):
    s[i] = int(s[i])
p = []
p.append(s[len(s)-1])
for i in range(1,len(s)):
    p.append((p[i-1]+s[len(s)-i-1]*(10**i))%2019)
p.sort()
u = 0
for i in range(len(p)):
    if p[i] == 0:
        u = u+1
    else:
        break
r = 1
q = []
for i in range(len(p)-1):
    if p[i] == p[i+1]:
        r = r+1
    else:
        if r > 1:
            q.append(r)
            r = 1
w = 0
for i in range(len(q)):
    w = w + int(q[i]*(q[i]-1)/2)
print(w+u)

Submission status: Time Limit Exceeded

Solution code:
a=input()
num=len(a)
mod_map={0:1}

for i in range(-1,-num-1,-1):
    mod=int(a[i:])%2019
    if mod not in mod_map:
        mod_map[mod]=1
    else:
        mod_map[mod]+=1
res=0
for i in mod_map.values():
    res+=int(i*(i-1)/2)
print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
def solve(S):
    dp = [0] * 2019
    ans = 0
    for c in S:
        dp2 = [0] * 2019
        dp2[c] = 1
        for i in range(2019):
            if dp[i] == 0: continue
            v = i*10+c
            dp2[v if v<2019 else v%2019] += dp[i]
        dp = dp2
        ans += dp[0]
    return ans
S = [x-ord('0') for x in sys.stdin.buffer.read().rstrip()]
print(solve(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = list(S)
for i in range(len(s)):
    s[i] = int(s[i])
p = []
p.append(s[len(s)-1])
for i in range(1,len(s)):
    p.append((p[i-1]+s[len(s)-i-1]*(10**i))%2019)
p.sort()
u = 0
for i in range(len(p)):
    if p[i] == 0:
        u = u+1
    else:
        break
r = 1
q = []
for i in range(len(p)-1):
    if p[i] == p[i+1]:
        r = r+1
    else:
        if r != 1:
            q.append(r)
            r = 1
w = 0
for i in range(len(q)):
    w = w + int(q[i]*(q[i]-1)/2)
print(w+u)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
n=len(s)
left :int=1
mlist=[0]
while left<int(n)+1:
  m = int(s[n-left:n])%2019
  mlist.append(m)
  left+=1

ll=len(mlist)
l=len(set(mlist))
print(int(ll-l))

Submission status: Time Limit Exceeded

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

cnts = [0]*2019

cnts[0] = 1

num = 0

d = 1

ans = 0

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def solve(S):
    dp = [0] * 2019
    ans = 0
    for c in S:
        dp2 = [0] * 2019
        dp2[c] = 1
        for i in range(2019):
            if dp[i] == 0: continue
            dp2[(i*10+c)%2019] += dp[i]
        dp = dp2
        ans += dp[0]
    return ans
S = [x-ord('0') for x in sys.stdin.buffer.read().rstrip()]
print(solve(S))

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = list()
for i in range((len(s)-3)):
  for j in range(3,(len(s)+1)):
    if not s[i:j]:
      continue
    else:
      n = int(s[i:j])%2019
      l.append(n)  
print(l.count(0))

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
n=len(s)
left :int=1
mlist=[0]
while left<int(n)+1:
  m = int(s[n-left:n])%2019
  mlist.append(m)
  left+=1

sorted_mlist = sorted(mlist)

i :int=0
count :int=0
while i<len(sorted_mlist):
  if sorted_mlist[i-1]==sorted_mlist[i]:
    count+=1
  i+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def solve(S):
    dp = [0] * 2019
    ans = 0
    for c in S:
        c = int(c)
        dp2 = [0] * 2019
        dp2[c] = 1
        for i in range(2019):
            if dp[i] == 0: continue
            dp2[(i*10+c)%2019] += dp[i]
        dp = dp2
        ans += dp[0]
    return ans
print(solve(input()))

Submission status: Time Limit Exceeded

Solution code:
def multiple_of_2019():
    S = input()
    count = 0
    for i in range(0, len(S)):
        for j in range(i + 1, len(S)):
            if j - i > 3:
                subsequence = int(S[i:j+1])
                if subsequence % 2019 == 0:
                    count += 1


    print(count)

multiple_of_2019()

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now += i*int(c)
    i *= 10
    dp[now%2019] += 1

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
mod_check = {}
mod_check[0] = 1
for x in range(len(S) - 1, -1, -1):
    check_S = int(S[x:])
    mod = check_S % 2019
    mod_check.setdefault(mod, 0)
    mod_check[mod] += 1
mod_match = 0
for x in mod_check.values():
    mod_match += x * (x - 1) // 2
print(mod_match)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

s = str(input())
tisa = []
for i in range(1,1000000):
  ww = str(2019*i)
  if '0' not in ww:
    tisa.append(ww)
#ok
#print(s)
#print(tisa)
#print(len(tisa))
#重複　count methodは無理
ans = 0
for c in tisa:
  if c in s:
    i = s.index(c)
    while i <len(s)-len(c)+1:
      if s[i:i+len(c)]==c:
        ans += 1
        i += 3
      else :
        i += 1
    

      
  

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

dp = [0] * 2019
ans = 0
for c in S:
    c = int(c)
    dp2 = [0] * 2019
    dp2[c] = 1
    for i in range(2019):
        if dp[i] == 0: continue
        dp2[(i*10+c)%2019] += dp[i]
    dp = dp2
    ans += dp[0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]
n = len(s)
dp = [1] + [0]*2018
now = 0

for i in range(n):
    now += 10**i * int(s[i])
    tmp = now % 2019
    dp[tmp] += 1

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter 
from collections import defaultdict 
def main():
    s = input() 
    n = len(s)
    T = [0]
    dd = defaultdict(int) 
    dd[0] += 1
    for i in range(1, n+1):
        x = (int(s[-i])*10**(i-1)%2019+T[i-1]%2019)%2019
        T.append(x)
        dd[x] += 1
    ans = 0
    for i in dd.values():
        ans += i*(i-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = str(input())


def main(S):
    a = len(S)
    b = list(0 for j in range(4, a+1)
        for i in range(a-j+1)
            if int(S[i:i+j])%2019==0)
    print(len(b))
if __name__ == '__main__':
    main(S)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L):
    t += pow(10, l)*int(S[l])
    i = t%mod
    ans += dic[i]
    dic[i] += 1
    if i==0:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L+1):
    t += pow(10, l)*int(S[-l])
    i = t%mod
    ans += dic[i]
    dic[i] += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

s=input()

mod=2019
tc=[0]*2019

lens=len(s)
#tim=int(s[lens-1])
#tc[tim]+=1
#for i in range(len(s)-1,-1,-1):
#    print(i,(10*tim+int(s[i]))%mod)    
#    ti=(10*tim+int(s[i]))%mod
#    tc[ti]+=1
#    tim=ti

tc[0]=1
for i in range(len(s)-1,-1,-1):
    ti=int(s[i:lens])%mod
    tc[ti]+=1
#    print(i,s[i:lens],ti,tc[ti])    
    
tsum=0
for i in tc:
    tsum+=(i*(i-1))//2
    
print(tsum)

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L+1):
    t += pow(10, l)*int(S[-l])
    i = t%mod
    dic[i] += 1

for k in dic.keys():
    num = dic[k]
    ans += num*(num-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
"""
def solution(S):
    a = len(S)
    b = list(0 for j in range(4, a+1)
        for i in range(a-j+1)
            if int(S[i:i+j])%2019==0)
    print(len(b))
solution(S)
"""

def solution(S):
    a = len(S)
    b = list(0 for j in range(4, a+1)
        for i in range(a-j+1)
            if int(S[i:i+j])%3==0 and int(S[i:i+j])%673==0)
    print(len(b))
solution(S)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter 
from collections import defaultdict 
def main():
    s = input() 
    n = len(s)
    T = [0]
    dd = defaultdict(int) 
    dd[0] += 1
    for i in range(1, n+1):
        T.append((int(s[-i])*10**(i-1)%2019+T[i-1]%2019)%2019)
        dd[(int(s[-i])*10**(i-1)+T[i-1])%2019] += 1
    ans = 0
    for i in dd.values():
        ans += i*(i-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.readline
from collections import Counter
MOD = 2019

def main():
    S = readline().rstrip()
    N = len(S)
    T = [0] * (N+1)
    for i in range(N-1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * 10**(N-1-i)) % MOD
    
    c = Counter(T)
    ans = 0
    for k, v in c.items():
        ans += (v * (v-1)) // 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
l=len(s)
amari=[0]*2019
amari[0]=1

d=0
digi=1

for c in s[::-1]:
    d=(int(c)*digi + d)%2019
    amari[d]+=1
    digi=(digi*10)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.readline
from collections import Counter
MOD = 2019

def main():
    S = readline().rstrip()
    N = len(S)
    T = [0] * (N+1)
    for i in range(N-1, -1, -1):
        T[i] = T[i+1] + int(S[i]) * 10 ** (N-1-i)
    
    T = [t % MOD for t in T]
    c = Counter(T)
    ans = 0
    for k, v in c.items():
        ans += (v * (v-1)) // 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

def solution(S):
    a = len(S)
    b = list(0 for j in range(4, a+1)
        for i in range(a-j+1)
            if int(S[i:i+j])%2019==0)
    print(len(b))
solution(S)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from collections import defaultdict

if __name__ == '__main__':
    MOD = 2019
    strS = input()
    S = [int(s) for s in strS]
    N = len(S)

    mods = defaultdict(int)
    for idx, s in enumerate(S[::-1]):
        if idx == 0:
            tmp_mod = s % MOD
        else:
            tmp_mod = (prv_mod + s * 10 ** idx) % MOD

        mods[tmp_mod] += 1
        prv_mod = tmp_mod

    ans = 0
    for key, value in mods.items():
        if value >= 2:
            ans += value * (value - 1) // 2
        elif key == 0:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
def main():
    from functools import reduce
    import collections
     
    S = list(map(int,input().rstrip()))
    N=len(S)
    mod_list = [0]
    for i in range(N):
        new = (mod_list[-1]+S[N-1-i]*10**i)%2019
        mod_list.append(new)
        
    count = collections.Counter(mod_list)
    ans =0
    for j in range(2019):
        n = count[j]
        ans+= n*(n-1)/2
    print(int(ans))
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    import collections
    def input():
        return sys.stdin.readline()[:-1]
    S=input()
    result=0
    list=[0]*(len(S)+1)
    for i in range(len(S)):
        a=int(S[i:])
        list[i]=a%2019
    c=collections.Counter(list)
    for j in c.values():
        result+=j*(j-1)/2
    print(int(result))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

if __name__ == '__main__':
    MOD = 2019
    strS = input()
    S = [int(s) for s in strS]
    N = len(S)

    mods = []
    for idx, s in enumerate(S[::-1]):
        if idx == 0:
            mods.append(s % MOD)
        else:
            mods.append((mods[idx - 1] + s * 10 ** idx) % MOD)

    mods_cnt = Counter(mods)

    ans = 0
    for key, value in mods_cnt.items():
        if value >= 2:
            ans += value * (value - 1) // 2
        elif key == 0:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
target = 2019
S = input()
N = len(S)
l = [ int( S[ : i + 1 ] ) for i in range(len(S)) ]
r =[ 1 ] + [ 0 ] * ( target - 1 )

d = 0
for i in reversed( l ):
  r[ ( i * 10 ** d) % target ] += 1
  d += 1
  
cnt = 0
for i in r:
  cnt += i * ( i - 1 ) // 2
    
print( cnt )

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
from functools import reduce
import collections
 
S = list(map(int,input().rstrip()))
N=len(S)
mod_list = [0]
for i in range(N):
    new = (mod_list[-1]+S[N-1-i]*10**i)%2019
    mod_list.append(new)
count = collections.Counter(mod_list)
#print(mod_list)
ans =0
for j in range(2019):
    n = count[j]
    ans+= n*(n-1)/2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0

for i in range(len(s)-4):
    for j in range(len(s)-(4+i)):
        if 0 == int(s[i:i+j+5]) % 2019:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

count=[0]*2019
count[0]+=1
gh=0
dd=len(s)
for i in range(0,dd):
    gh+=int(s[i])*(10**i)
    count[gh%2019]+=1

ans=0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

N = len(S)

mod2019 = []
ans = 0

for _ in range(N+1):
  mod2019.append(0)


count = []
for _ in range(2019):
  count.append(0)

count[0] = 1

for i in range(1,N+1):
  Smod = int(S[N-i:N])
  mod2019[i] = (Smod%2019)
  count[Smod%2019] += 1
  #print(Smod%2019)


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



print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
size = len(S)
ans = 0#[]
def check(target):
  if int(target) % 2019 == 0:
    return True
  else:
    return False
  
for i in range(size-3):
  for j in range(4,size+1):
    if i+j > size:
      continue
    t = S[i:i+j]
    if check(t):
      ans += 1
      #ans.append((i+1,i+j))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

num=input()
ans=0
for i,j in itertools.combinations(range(len(num)+1), 2):
  if int(num[i:j])%2019==0:
             ans+=1
             
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

N = len(S)

mod2019 = []
ans = 0

mod2019.append(0)

for i in range(1,N+1):
  Smod = mod2019[i-1] + int(S[N-i])*10**(i-1)
  mod2019.append(Smod%2019)

for i in range(2019):
  m = mod2019.count(i)
  ans += (m*(m-1))//2



print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

accum_mod = [0]*len(s)
for i in range(len(s)):
    accum_mod[i] = (int(s[i]) * 10**i) % 2019
for i in range(1, len(s)):
    accum_mod[i] += accum_mod[i-1]
    accum_mod[i] %= 2019
accum_mod.append(0)
cnt = Counter(accum_mod)
ans = 0
for tmp in cnt.values():
    if tmp > 1:
        ans += tmp*(tmp-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
S = input()
N = len(S)
M = [0]
mod = 0
ten = 1
for s in S[::-1]:
  mod += (int(s) * ten) % 2019
  mod %= 2019
  M.append(mod)
  ten *= 10
count = collections.Counter(M)
print(sum([c*(c-1)//2 for c in count.values()]))

Submission status: Time Limit Exceeded

Solution code:
s=input()
l=len(s)
amari=[0]*2019
amari[0]=1

d=0

for c in s[::-1]:
    d=(int(c)*10**len(str(d)) + d)
    amari[d%2019]+=1


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

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter 
from collections import defaultdict 
def main():
    s = input() 
    n = len(s)
    T = [0]
    dd = defaultdict(int) 
    dd[0] += 1
    for i in range(1, n+1):
        T.append((int(s[-i])*10**(i-1)+T[i-1])%2019)
        dd[(int(s[-i])*10**(i-1)+T[i-1])%2019] += 1
    ans = 0
    for i in dd.values():
        ans += i*(i-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections
S = input()
N = len(S)
M = [0]
for i in range(N):
  M.append(int(S[:i+1] + '0' * (N-1-i)) % 2019)
count = collections.Counter(M)
print(sum([c*(c-1)//2 for c in count.values()]))

Submission status: Time Limit Exceeded

Solution code:
S = input()
mod = 2019
dp = [[0]*len(S) for _ in range(2019)]
dp[int(S[0])][0] = 1
for i in range(1,len(S)):
    for j in range(2019):
        dp[(10*j+int(S[i]))%mod][i] += dp[j][i-1]
    dp[int(S[i])][i] +=1
print(sum(dp[0]))

Submission status: Time Limit Exceeded

Solution code:
s=input()
l=len(s)
amari=[0]*2019
amari[0]=1

d=int(s[-1])

for i in range(1,l+1):
    nd=int(s[l-i-1])
    d=(nd*10**len(str(d)) + d)
    amari[d%2019]+=1

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

Submission status: Time Limit Exceeded

Solution code:
num=input()
ans=0

for i in range(len(num)):
    for j in range(i+4,len(num)+1):
        if int(num[i:j])%2019==0:
            ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

mods = [0 for _ in range(2019)]
mods[0] = 1

num = 0
for itr, s in enumerate(S[::-1]):
  num = s * 10 ** itr + num
  num %= 2019
  mods[num] += 1
  
ans = 0
for m in mods:
  ans += m * (m - 1) // 2

print(ans)