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()
sum = 0
for i in range(1, 5000):
  number = 2019 * i
  for pos in range(len(s)):
    if s[pos:].startswith(str(number)):
      sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
s = input()
if len(s) < 4:
  print('0')
else:
  cnt = 0
  for i in range(len(s)-3):
    if int(s[i:i+2]) %2 != 0:
      continue
    if i+3 > len(s):
      break
    for j in range(i+4, len(s)):
      if int(s[i:j+1]) % 2019 == 0:
        cnt += 1
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import math

s = int(input())
n = math.ceil(math.log10(s))
count = 0


for i in range(n):
    num = s % (10 ** (n - i))
    if num < 2019:
        break
    for j in range(n):
        if num % 2019 == 0:
            count += 1
            break
        num = num // 10
        if num == 0:
            break
        if num < 2019:
            break
        
print("{}".format(count))

Submission status: Time Limit Exceeded

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

s = 0
r = 1
l = 0
cnt = 0
while l <=len(a)-3:
    s = a[l]
    r =l
    while int(s)%2019 != 0 and r<=len(a)-2:
        #print(l,r)
        s +=a[r+1]
        if int(s)%2019 == 0:
            cnt +=1
        #print(s,cnt,l,r)   
        r += 1
    l +=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
count=0
for i in range(n):
  for j in range(i,n+1):
    for k in range(100):
      sa=str(2019*k)
      if s[i:j]==sa:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
num = str(N)
list_num = list(num)
list_num = [int(s) for s in list_num]
s=len(list_num)
ans=0
for i in range(4,s+2):
    for u in range(1,s-i+2):#hajimenobanngou
        b=sum(list_num[u-1:u+i-1])
        if b%3==0:
            a=int("".join((map(str,list_num[u-1:u+i-1]))))
            if  a%673==0:
                ans+=1
        
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
S = str(input())
dp = np.zeros((len(S)+1, 2019),dtype=np.int)
ans = 0
for i in range(1, len(S)+1):
    x = int(S[i-1])
    dp[i][x] += 1
    for j in range(2019):
        dp[i][(j*10+x)%2019] += dp[i-1][j]
    ans += dp[i][0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    len_S = len(S)
    cnt = 0
    for i in range(len_S):
        for j in range(i+3,len_S):
            if j == i+3:
                mod = int(S[len_S-j-1:len_S-i])%3
            else:
                mod = (mod+int(S[len_S-j-1]))%3
            if mod == 0:
                _ = int(S[len_S-j-1:len_S-i])
                if _%673==0:
                    cnt += 1
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
input_str = input()

count = 0
num_list = []
for i,one in enumerate(input_str):
    num = ""
    num += str(one)
    for j in (input_str[i+1:]):
        num += str(j)
        num_list.append(int(num))
for num in [n for n in num_list if n > 2019]:
    if num%2019==0:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(2000000)

from queue import deque
def judge(t):
    # print(t)
    if t>=2019:
        if t%2019==0:
            l.append(t)
        return judge(t//10)
    else: return 0
    

s = deque(input())
# print(len(s))
l = []
for i in range(len(s)):
    t = int(''.join(s))
    # print(t)
    judge(t)
    s.popleft()
print(len(l))

Submission status: Time Limit Exceeded

Solution code:
# TODO NG
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

s = input()

cnt = 0
s_n = np.ones(200000*200, dtype='int64')
for i in range(len(s)-3):
#     for j in range(i+3, len(s)):
    j = i + 3
    while(j < len(s)):
        num = int(s[i:j+1])
        if num % 2019 == 0:
            cnt += 1
            j += 4
        j += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
from itertools import product, permutations,combinations


l = len(s) +1
A = [i for i in range(l)]

cnt = 0
ans = []

for i in combinations(A,2):
    j = i[0]
    k = i[1]
    ans = s[j:k]
    if int("".join(map(str, ans)))%2019==0:
            cnt +=1
    
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def calc(list, idx_i, idx_j):
  target_list = list[idx_i:(idx_j + 1)]
  int_val = int("".join(target_list))
  return int_val % 2019 == 0

inputs = list(input())
max_idx = len(inputs) - 1
  
count = 0;
for i in range(0, max_idx + 1):
  for j in range(i + 1, max_idx + 1):
    result_bool = calc(inputs, i, j)
    if(result_bool):
      count+=1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

N = len(S)

count = 0
for k in range(5, N):
    for i in range(N - k + 1):
        if int(S[i:i+k]) % 2019 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
#A,B,C,D=map(int,input().split(" "))

mod=2019
a=input()

N=len(a)
t=[]
ans=0

for i in range(N-2):
  for j in range(i+3,N+1):
    u=int(a[i:j])
    #print(u)
    if (u % mod)==0:
      ans+=1
      #print(i+1,j)
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    n = len(S)
    if n < 4:
        print(0)
        return
    ans = 0
    for i in range(n-3):
        s  = int(S[i:i+3])
        for j in range(i+3, n):
            s = 10*s+int(S[j])
            s %= 2019
            #print(i,j,S[j],s)
            if s == 0:
                ans += 1  
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_list = list(map(int,s))
s_list = s_list[::-1]

count = 0
for i in range(0,len(s_list)+1) :
  for j in range(i+4,len(s_list)+1) :
    x_list = s_list[i:j]
    x = 0
    for k in range(0,len(x_list)) :
      x += x_list[k]*(10**k)
#    if x <= 2018 :
#      break
    if x%2019 == 0 :
      count += 1
      
print(count)

Submission status: Time Limit Exceeded

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

def main():
    s = input()
    n = len(s)
    cnt = 0

    f_list = [[-1], [], []]
    f_num = 0

    for i in range(n):
        f_num += int(s[i])
        f_num %= 3
        f_list[f_num].append(i)

    for i in range(3):
        for f1 in f_list[i]:
            for f2 in reversed(f_list[i]):
                if f2 - f1 >= 3:
                    num = int(s[f1+1:f2+1])
                    if num % 673 == 0:
                        cnt += 1
                else:
                    break

    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = "" + input()
#print(len(S))
def hantei(a):
    tmp=int(a)%2019
    if tmp == 0:
        return True
    else:
        return False

ml=set()
X=[]
X.append(0)
cnt=0
#print(len(S)-3)
for i in range(0,len(S)-2):
    #print(i)
    tmpcnt=X[i]
    for j in range(i+1,min(len(S),i+1+228) ):
        #print(i,j)
        #print(i,j)
        if hantei(S[i:j+1]):
            cnt+=1
            #print(i,j)
            if j == i+3:
                cnt+=X[i-1]
                tmpcnt+=1
    X.append(tmpcnt)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    s_len = len(s)
    count = 0

    for i in range(0, s_len - 2):
        for j in range(i+4, s_len+1):
            diff = j - i
            eval_str = s[i:j:]
            if diff < 4 or 6 < diff:
                continue
            if int(eval_str) > 200000:
                continue
            if int(eval_str) % 2019 == 0:
                count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
num = len(s)
l = []
from collections import deque
l = deque(l)   # deque オブジェクトを取得

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

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

aaa(s, num)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(0, l-3):
  for j in range(3, l):
    if i < (j-3):
      new_s = int(S[i:j+1])
      if new_s % 2019 == 0:
        count += 1
      else:
        continue
    else:
      continue
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from collections import Counter

    s = str(input())
    num = ""
    li = []
    f = 0
    mi = 0
    li_append = li.append

    cm = {}
    for i in range(1,2*(10 ** 5)):
        cm[i] = i * (i - 1) // 2
    cm[0] = 0



    for i in range(1, len(s) + 1):
        num = s[-i] + num
        li_append(int(num) % 2019)
        if num[0] == "0":
            f += 1
        else:
            mi += cm[f+1]
            f = 0

    co = Counter(li)
    co_1 = Counter(co.values())
    ans_1 = 0

    for x in co_1.keys():
        if x != 1:
            ans_1 += cm[x]* co_1[x]
    ans2 = 0
    if 0 in co:
        ans2 = co[0]
    print(ans_1 + ans2 - mi)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections
s = input()
int_s = int(s)
li=[]
cnt=0
for i in range(len(s)-3):
    for j in range(i+3,len(s)):
        num = int(s[i:j+1])
        li.append(num)
li_c = collections.Counter(li)
for k in li_c:
    if k % 2019 == 0:
        cnt += li_c[k]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S_input = input()
S_list = list(S_input)
S_len = len(S_list)
S = 0
count =0
for i in range(0,S_len-3):
  for j in range(i,S_len):
    S = S+int(S_list[j])
    if S % 2019 == 0:
      count+=1
    S *= 10
  S = 0
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = input()
a = 0

for i in range(len(N)):
  if N[i] == 0:
    continue
  for j in range(len(N)):
    if i > j:
      continue
    if int(N[i:j + 1]) == 0:
      continue
    if int(N[i:j + 1]) % 2019 == 0:
      a += 1
      

print(a)

Submission status: Time Limit Exceeded

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

ans = 0
cnt = [0] * 2019
s=""

for i in range(N)[::-1]:
    s = "".join([S[i],s])
    cnt[int(s) % 2019] += 1

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import heapq
S = input()
cum = []
dict = {}
length = len(S)
n = 0
for i in range(1,length+1):
    n = n + int(S[-i]) * 10**(i-1)
    cum.append(n % 2019)
    dict[n % 2019] = 0


for c in cum:
    dict[c] += 1
ans = 0
for k, v in dict.items():
    if k == 0:
        ans += v
    ans += v * (v-1) // 2

print(ans)

Submission status: Time Limit Exceeded

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

def solve(S: int):
    S = [int(s) for s in str(S)]

    # magic = lambda nums: sum(digit * 10 ** (len(nums) - 1 - i) for i, digit in enumerate(nums))

    count = 0
    for i in range(len(S)):
        res = 0
        j = i
        while(j < len(S)):
            res = (res * 10 + S[j]) % 2019

            if res % 2019 == 0:
                count += 1
            j+=1

    print(count)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
sum_2019 = 0

for i in range(len(s)-3):
    for j in range(i+3, len(s)):
        s_int = int(s[i:j+1])
        if s_int % 2019 == 0 and s_int != 0:
            sum_2019 += 1

print(sum_2019)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
count=0
for i in range(n):
  for j in range(i,n+1):
    for k in range(1000):
      sa=str(2019*k)
      if s[i:j]==sa:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
length = len(S)

cnt = 0
n = 0
for i in range(0,length):
    for j in range(i, length):
        s = int(S[i:j+1])
        if s % 2019 == 0:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

S=input()
A=0

SL=list(S)
for i in range(len(SL)):
    SL[i]=int(SL[i])

SL_sum=SL.copy()
for i in range(1, len(SL_sum)):
    SL_sum[i] += SL_sum[i-1]
#SL_sum=np.array(SL_sum)
    
while len(S)>3:
    for i in range(len(SL_sum)):
        if SL_sum[i]%3 == 0 :
            if int(S[:i+1])%673 ==0 :
                A+=1
    S=S[1:]
    SL_sum=(np.array(SL_sum)-SL_sum[0]).tolist()
    SL_sum=SL_sum[1:]
    SL=SL[1:]
    
print(A)

Submission status: Time Limit Exceeded

Solution code:
si = [int(i) for i in list(str(input()))]
a = 0
for i in range(1,len(si)-2):
    for j in range(i+3,len(si)+1):
        b = 0
        for ix,k in enumerate(reversed(si[i-1:j])):
            b += k * (10**ix)
        if b % 2019 == 0:
            a +=1
            break   
print(a)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

def f(s,l):
    for i in range(len(s)):
        if s[i] == l:
            return False
    return  True

s = list(map(int,input()))
lens = len(s)
pair = [[]]
result = 0

for i in range(lens):
    for j in range(i+4,lens+1):
        n = reduce(lambda a,b:10*a+b, s[i:j])
        if  n % 2019 == 0 and f(pair,[i,j]):
            pair.append([i,j])
            result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import queue
import copy
import bisect#2分探索
from collections import deque #popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s): return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

S = int(input())
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=lambda x:x[1],reverse=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入

ss=str(S)
# #print(ss)
ls=len(ss)
# l=[0]*(ls+1)

    #print(l[i])
#print(l)

# #優先度付きqueue

kl=dict()
kl[0]=1
# a = [0]
# heapq.heapify(a)  # aを優先度付きキューに

for i in range(0,ls):
    tmp=int(ss[i:ls])%2019
    kl[tmp]=kl.get(tmp,0)+1
#print(a)


ans=0

for k in kl:
    val=kl[k]
    ans+=val*(val-1)//2

print(ans)
# cur=-1
# ans=0
# for i, li in enumerate(l):
#     if cur==-1:
#         cur=li
#         count=1
#     elif li==cur:
#         count+=1
#     else:
#         ans+=count*(count-1)//2
#         cur=li
#         count=1

# print(ans)

Submission status: Time Limit Exceeded

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    S = input()
    cnt = 0
    start = 0
    while start+4 < len(S):
        for i in range(start+4,len(S)+1):
            if S[i-1] == 0:
                break
            if int(S[start:i]) % 2019 == 0:
                cnt += 1
                break
        start += 2
    print(cnt)
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
N = ['12114', '14133', '16152', '18171', '24228', '26247', '28266', '34323', '36342', '38361', '42399', '44418', '46437', '48456', '52494', '54513', '56532', '58551', '62589', '66627', '68646', '72684', '76722', '78741', '82779', '84798', '86817', '88836', '92874', '94893', '96912', '98931', '119121', '123159', '125178', '127197', '129216', '131235', '133254', '135273', '137292', '139311', '143349', '145368', '147387', '151425', '153444', '155463', '157482', '163539', '165558', '167577', '169596', '171615', '173634', '175653', '177672', '179691', '183729', '185748', '187767', '189786', '193824', '195843', '197862', '199881', '211995', '226128', '228147', '232185', '236223', '238242', '244299', '246318', '248337', '252375', '254394', '256413', '258432', '264489', '268527', '272565', '274584', '278622', '284679', '286698', '288717', '292755', '294774', '296793', '298812', '312945', '314964', '316983', '331116', '333135', '335154', '337173', '339192', '341211', '345249', '347268', '349287', '353325', '355344', '357363', '359382', '365439', '367458', '369477', '371496', '373515', '375534', '377553', '379572', '381591', '385629', '387648', '389667', '391686', '395724', '397743', '399762', '411876', '413895', '415914', '417933', '419952', '421971', '438123', '442161', '446199', '448218', '452256', '454275', '456294', '458313', '462351', '466389', '472446', '474465', '476484', '482541', '486579', '488598', '492636', '494655', '496674', '498693', '512826', '514845', '516864', '518883', '522921', '526959', '528978', '543111', '547149', '549168', '551187', '555225', '557244', '559263', '561282', '567339', '569358', '571377', '573396', '575415', '577434', '579453', '581472', '583491', '587529', '589548', '591567', '593586', '597624', '599643', '611757', '613776', '615795', '617814', '619833', '621852', '623871', '629928', '631947', '633966', '635985', '652137', '654156', '656175', '658194', '662232', '664251', '668289', '672327', '674346', '676365', '678384', '682422', '684441', '688479', '692517', '694536', '696555', '698574', '714726', '716745', '718764', '724821', '728859', '732897', '734916', '736935', '738954', '742992', '757125', '759144', '761163', '763182', '769239', '771258', '773277', '775296', '777315', '779334', '781353', '783372', '785391', '789429', '791448', '793467', '795486', '799524', '811638', '813657', '815676', '817695', '819714', '821733', '823752', '825771', '831828', '833847', '835866', '837885', '841923', '843942', '845961', '849999', '862113', '864132', '866151', '874227', '876246', '878265', '884322', '886341', '892398', '894417', '896436', '898455', '912588', '916626', '918645', '922683', '926721', '932778', '934797', '936816', '938835', '942873', '944892', '946911', '952968', '954987', '971139', '973158', '975177', '977196', '979215', '981234', '983253', '985272', '987291', '991329', '993348', '995367', '997386', '1112469', '1114488', '1118526', '1122564', '1124583', '1128621', '1132659', '1134678', '1136697', '1138716', '1142754', '1144773', '1146792', '1148811', '1152849', '1154868', '1156887', '1162944', '1164963', '1166982', '1181115', '1183134', '1185153', '1187172', '1189191', '1193229', '1195248', '1197267', '1199286', '1213419', '1215438', '1217457', '1219476', '1221495', '1223514', '1225533', '1227552', '1229571', '1235628', '1237647', '1239666', '1241685', '1245723', '1247742', '1249761', '1253799', '1255818', '1257837', '1259856', '1261875', '1263894', '1265913', '1267932', '1269951', '1273989', '1288122', '1294179', '1296198', '1298217', '1314369', '1316388', '1322445', '1324464', '1326483', '1334559', '1336578', '1338597', '1342635', '1344654', '1346673', '1348692', '1354749', '1356768', '1358787', '1362825', '1364844', '1366863', '1368882', '1374939', '1376958', '1378977', '1395129', '1397148', '1399167', '1411281', '1415319', '1417338', '1419357', '1421376', '1423395', '1425414', '1427433', '1429452', '1431471', '1437528', '1439547', '1441566', '1443585', '1447623', '1449642', '1451661', '1455699', '1457718', '1459737', '1461756', '1463775', '1465794', '1467813', '1469832', '1471851', '1475889', '1479927', '1481946', '1483965', '1485984', '1512231', '1516269', '1518288', '1522326', '1524345', '1526364', '1528383', '1532421', '1536459', '1538478', '1542516', '1544535', '1546554', '1548573', '1552611', '1556649', '1558668', '1564725', '1566744', '1568763', '1576839', '1578858', '1582896', '1584915', '1586934', '1588953', '1592991', '1611162', '1613181', '1617219', '1619238', '1621257', '1623276', '1625295', '1627314', '1629333', '1631352', '1633371', '1639428', '1641447', '1643466', '1645485', '1649523', '1651542', '1653561', '1657599', '1659618', '1661637', '1663656', '1665675', '1667694', '1669713', '1671732', '1673751', '1677789', '1681827', '1683846', '1685865', '1687884', '1691922', '1693941', '1697979', '1699998', '1712112', '1714131', '1718169', '1724226', '1726245', '1728264', '1734321', '1738359', '1742397', '1744416', '1746435', '1748454', '1752492', '1754511', '1758549', '1762587', '1766625', '1768644', '1772682', '1778739', '1782777', '1784796', '1786815', '1788834', '1792872', '1794891', '1798929', '1819119', '1821138', '1823157', '1825176', '1827195', '1829214', '1831233', '1833252', '1835271', '1841328', '1843347', '1845366', '1847385', '1851423', '1853442', '1855461', '1859499', '1861518', '1863537', '1865556', '1867575', '1869594', '1871613', '1873632', '1875651', '1879689', '1883727', '1885746', '1887765', '1889784', '1893822', '1895841', '1899879', '1911993', '1926126', '1928145', '1932183', '1936221', '1942278', '1944297', '1946316', '1948335', '1952373', '1954392', '1956411', '1962468', '1964487', '1968525', '1972563', '1974582', '1982658', '1984677', '1986696', '1988715', '1992753', '1994772', '1996791']
#print(len(N))

S = input()
A = []
for j in range(0,len(S),4):
    for i in N:
        a = re.search(i,S[j:])
        #ans += S.count(i)
        if a == None:
            None
        else:
            A.append(a.start()+j)
print(len(set(A)))


'''
N = []
for i in range(2019,1998810,2019):
     if str(i).count("0") == 0:
         N.append(str(i))
print(N)
'''

Submission status: Time Limit Exceeded

Solution code:
s  = input()
ls= len(s)
sum = [0]*(ls+1)

for i in range(ls):
    sum[i+1] = sum[i]+int(s[i]) 

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
U=int(S)
T=len(S)

list=[]
count=0
for i in range(0,T-3):
  for j in range(i+4,T+1):
    list.append(S[i:j])
list_2 = [int(n) for n in list if int(n)%673==0]
for z in range(len(list_2)):
  if list_2[z]%3==0:
    count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)+1
a = 0

for i in range(n-3):
  for j in range(i+3,n):
    if int(s[i:j]) % 2019 == 0:
      a += 1
print(a)

Submission status: Time Limit Exceeded

Solution code:
import re
import sys
import numpy as np

s = sys.stdin.buffer.readline().rstrip().decode()
cc = np.arange(1, 200001)
c = [2019*i for i in cc]
ans = 0

for i in range(199999):
    tmp = str(c[i])
    if tmp in s:
        index = -1
        while True:
            index = s.find(tmp, index + 1)
            if index == -1:
                break
            ans += 1
    if int(tmp) > int(s):
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def solve(S, i, Ns):
    #print("i:{}".format(i))
    #print("Ns:{}".format(Ns)) 
    if len(S) <= i:
        return 0 # Ns[i] でインデックスの外
    if Ns[i] != -1:
        return Ns[i]
    N = 0
    for j in range(i+1, len(S)+1):
        s = int(S[i:j])
        if s % 2019 == 0:
            N = 1+solve(S,i+j, Ns)
            break
    Ns[i] = N
    return N


if __name__ == "__main__":
    # 2019 = 3 * 673
    S = str(input())
    n = len(S)
    Ns = [-1 for i in range(n)]

    # ans = 0
    # # for i in range(2019):
    # #     for j in range(1, 10):
    # #         if (i*10+j) % 2019 == 0:
    # #             print(i,j)
    # # for i in range(0, n):
    # #     for j in range(i+1, n+1):
    # #         s = int(S[i:j])
    # #         #print(s)
    # #         if s % 2019 == 0:
    # #             #print("i,j : {}, {}".format(i, j))
    # #             ans += 1
    # print(ans)

    for i in range(len(S)):
        solve(S, i, Ns)
    #print(Ns)
    print(sum(Ns))

Submission status: Time Limit Exceeded

Solution code:
S = input()

cnt = 0
d = []
for i in range(1,100000):
    tmp = str(i*2019)
    cnt += S.count(tmp)
    cnt += S.count(tmp+tmp[1:])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

S_list =list(S)


A = 0
for i in range(0,len(S_list)-1):
    for j in range(i+4,len(S_list)+1):
        P = 0
        S_list_P = S_list[i:j]
        for k in range(0,j-i):
            P += int(S_list_P[k])* 10 ** (j-i-k-1)
        
        if P % 2019== 0:
            A += 1



print(A)

Submission status: Time Limit Exceeded

Solution code:
import collections
from sys import stdin


def get_result(data):
    S = data[0]
    int_S = int(S)
    mod_all_bit = [0]
    for i in range(len(S)):
        mod_all_bit.append(int_S % (10**(i+1)) % 2019)
    counter = collections.Counter(mod_all_bit)
    ans = 0
    dict_list = counter.items()
    for key, val in dict_list:
        if val >= 2:
            ans += val * (val-1) * 0.5
    return int(ans)


if __name__ == '__main__':
    data = list(map(str, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

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)):
        n = int(S[i:j])
        if n%2019 == 0:
            count += 1
    n = int(S[i:]) 
    if n%2019 == 0:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
    
def print_ans(S):
    """Test Case
    >>> print_ans('1817181712114')
    3
    >>> print_ans('14282668646')
    2
    >>> print_ans('2119')
    0
    """
    target_list = []
    itr = 2019
    for i in range(1, 9906):
        tmp = i * itr
        if tmp > int(S):
            break
        elif '0' in list([s for s in str(tmp)]):
            continue
        else:
            target_list.append(tmp)
    ans = 0
    if len(S) <= 3:
        print(0)
    else:
        for i in range(len(S)-2):
            for j in range(i + 2, len(S)):
                tmp = S[i:j+1]
                if len(tmp) == 7 and int(tmp) > 19998195:
                    break
                if len(tmp) > 8:
                    break
                if int(tmp) in target_list:
                    ans = ans + 1
        print(ans)
            
            

if __name__ == '__main__':
    S = input().rstrip()
    print_ans(S)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s2 = [int(x) for x in s]

ans = 0
tmp = 0
for l in range(len(s2)):
  r = l + 3
  while r < len(s2):
    tmp = sum(s2[l:r+1])
    if tmp % 3 == 0:
      if int(s[l:r+1]) % 2019 == 0:
        ans += 1
    r += 1
    if l == r:
      r += 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, len(s)):
        if int(s[i:j+1])%2019 == 0 :
            ans = ans + 1

print(ans)

### C++と同じく、実行は、Opt + Ctl + N

Submission status: Time Limit Exceeded

Solution code:
S = input()

length = len(S)

cnt = 0
temp = int(S[ : 4])
for x in range(length):
    first = temp
    for i in range(x + 4, length + 1):
        if temp % 2019 == 0:
            cnt += 1
        #print(temp, cnt)

        if i < length:
            temp = ((temp % 2019) * 10) % 2019
            temp = (temp + int(S[i])) % 2019
        else:
            if x + 4 < length:
                temp = (first - (int(S[x]) * 1000))
                temp = temp * 10 + int(S[x + 4])


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a=input()
counter=0
i=0
while i <len(a)-3:
    moji=a[i:i+3]
    for j in range(i+3,len(a)):
        moji+=a[j]
        if int(moji)%2019==0:
            counter+=1
            i=j-1
    i+=1
print(counter)