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:
# D - Multiple of 2019

S = input()

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

print(cnt)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
ll = len(s)
dat = list(map(int, list(s)))
#print(dat)
if len(s) < 4:
    print(0)
else:
    res = 0
    for l in range(0, ll - 4):
        v = int(s[l:l + 4])
        #print(v)
        v = v % 2019
        if v == 0:
            res += 1
        for r in range(l+4, ll):
            v = (v * 10 + dat[r]) % 2019
            if v == 0:
                res += 1
    print(res)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def n_gram(target,n):
    return [target[idx:idx + n] for idx in range(len(target) - n + 1)]

count = 0
s = input()
n = 4
while n <= len(s):
    num_list = n_gram(s,n)
    for num in num_list:
        if int(num) % 2019 == 0:
            count += 1
    n += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
T = [0]
for i in range(1, l+1):
    T.append((T[-1]+int(S[-i])*10**(i-1)) % 2019)
C = {}
for t in T:
    try:
        C[t] += 1
    except:
        C[t] = 1
ans = 0
for c in C.values():
    ans += c*(c-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]
l = len(s)
x = [0 for _ in range(2019)]
x[0] += 1
p = ''
for si in s:
    p = si + p
    k = int(p) % 2019
    x[k] += 1

ans = 0
for xi in x:
    ans += max(0, xi * (xi - 1) // 2)
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys,bisect,string,math,time,functools,random
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            a,b,c=(inp+[1])[:3]
            org_inp.append(inp)
        else:
            index=0
            a,b,c=(list(ls[i])+[1])[:3]
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)];rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

show_flg=False
show_flg=True


## Segment Tree ##

## Initializer Template ##
# Range Sum:        sg=SegTree(n)
# Range Minimum:    sg=SegTree(n,inf,min,inf)

class SegTree:

    def __init__(self,n,init_ls=None,init_val=0,function=lambda a,b:a+b,ide=0):
        self.n=n
        self.ide_ele=ide_ele=ide
        self.num=num=2**(n-1).bit_length()
        self.seg=seg=[self.ide_ele]*2*self.num
        self.lazy=lazy=[self.ide_ele]*2*self.num
        self.segfun=segfun=function
        #set_val
        if init_ls==None:
            for i in range(n):
                self.seg[i+self.num-1]=init_val
        else:
            for i in range(n):
                self.seg[i+self.num-1]=init_ls[i]
        #build
        for i in range(self.num-2,-1,-1):
            self.seg[i]=self.segfun(self.seg[2*i+1],self.seg[2*i+2])
    
    def update(self,k,x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfun(self.seg[k*2+1],self.seg[k*2+2])
        
    def evaluate(k,l,r): #遅延評価処理
        if lazy[k]!=0:
            node[k]+=lazy[k]
            if(r-l>1):
                lazy[2*k+1]+=lazy[k]//2
                lazy[2*k+2]+=lazy[k]//2

        lazy[k]=0
        
    def query(self,p,q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfun(res,self.seg[p])
            if q&1 == 1:
                res = self.segfun(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfun(res,self.seg[p])
        else:
            res = self.segfun(self.segfun(res,self.seg[p]),self.seg[q])
        return res
    
    def find_min_index(self,p,q,m):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfun(res,self.seg[p])
            if q&1 == 1:
                res = self.segfun(res,self.seg[q])
                q -= 1
            p >>= 1
            q = (q-1)//2
        if p == q:
            res = self.segfun(res,self.seg[p])
        else:
            res = self.segfun(self.segfun(res,self.seg[p]),self.seg[q])
        return res


    def __str__(self):
        # 生配列を表示
        rt=self.seg[self.num-1:self.num-1+self.n]
        return str(rt)

class Tree:
    def __init__(self,inp_size=None,init=True):
        if init:
            self.stdin(inp_size)
        return

    def stdin(self,inp_size=None):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1)
        return
    
    def listin(self,ls):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls)
        return

    def __str__(self):
        return  str(self.edges)

    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v

    def EulerTour(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append((-1,x))
        v=[None]*self.size
        v[x]=root_v
        et=[]
        while q:
            cb,ce=q.pop()
            et.append(ce)
            for nb,d in self.edges[ce]:
                if v[nb]==None:
                    q.append((nb,ce))
                    q.append((ce,nb))
                    v[nb]=func(v[ce],nb,d)
        vid=[[-1,-1]for i in range(self.size)]
        for i,j in enumerate(et):
            if vid[j][0]==-1:
                vid[j][0]=i
            else:
                vid[j][1]=i
        return v,et,vid
    
    def LCA_init(self,depth,et):
        self.st=SegTree(self.size*2-1,func=min,ide=inf)
        for i,j in enumerate(et):
            self.st.update(i,j)
        self.LCA_init_stat==True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            depth,et,vid=self.EulerTour(root)
            self.LCA_init(depth,et)
        return self.st.query(x,y+1)

def dijkstra(edge,st):
    # edge=[[(v_to,dist_to_v),...],[],...]
    # initialize: def: d=dist(st,i), prev=[previous vertex in minimum path], q[]
    n=len(edge)
    d=[(0 if st==i else inf) for i in range(n)]
    prev=[0]*n
    q=[(j,i) for i,j in enumerate(d)]
    heapify(q)
    
    # calc
    while q:
        dist,cur=heappop(q)
        for dst,dist in edge[cur]:
            alt=d[cur]+dist
            if alt<d[dst]:
                d[dst]=alt
                prev[dst]=cur
                heappush(q,(alt,dst))
    return d,prev


ans=0

s=input()
n=len(s)
a=[0]
t=0
m=2019
d=0
for i in s[::-1]:
    t=t+int(i)*10**d
    t%=m
    d+=1
    a.append(t%m)
#    show(t)



c=Counter(a)

#for i in range(n):
for i,j in c.items():
    ans+=j*(j-1)//2
#    show(i,j)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
S=int(s)
c=0
for i in range(n):
  for j in range(n-i):
    if (S%(10)**(j+1))%2019==0:
      c+=1
  S = int(S/10)
print(c)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=str(input())

n=len(s)

cnt=0

for i in range(n):
  for j in range(i+4,n+1):
    if j<=n:
      a=int(s[i:j])

      if a%2019==0:
        cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input('')

rec=0
for i in range(len(s)+1):
    for j in range(i+1,len(s)+1):
        s2 = s[i:j]
        if int(s2) %2019 == 0:
#            print("{}/{}={}".format(i,j,s2))
            rec+=1

print(rec)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

S = input()

count = 0
for times in range(1, 101):
    num = 2019 * times
    for i in range(len(S) - 3):
        for j in range(i + 3, len(S)):
            sub_S = int(S[i:j+1])
            if num == sub_S:
                count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s_n = str(n)
lenn = len(str(n))+1
res = []
for i in range(0,lenn):
    for j in range(i+1,lenn):
        if int(s_n[i:j]) % 2019 == 0:
            res.append([i,j])
print(len(res))

Submission status: Time Limit Exceeded

Solution code:
s = input()
s += '0'



mod = 2019
cnt = {}
ans = 0
p = ""
for i in range(len(s)-1,-1,-1):
    p = s[i]  + p
    
    x = int(p)%mod
    if x not in cnt:cnt[x] = 0
    ans += cnt[x]
    cnt[x] +=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 += 1
print(ans)

Submission status: Time Limit Exceeded

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

residue = [0] * n
count = 0

for i in range(n):
  residue[i] = (int(s[i]) * 10 ** (n - 1 - i)) % 2019

for i in range(n):
  for j in range(i, n):
    if sum(residue[i:j + 1]) % 2019 == 0:
      count += 1

print(count)

Submission status: Time Limit Exceeded

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

S = list(inputS())
N = len(S)

r = []
for i in range(N)[::-1]:
  n = int(S[i])
  if r == []:
    r.append(n)
  else:
    r.append((r[-1]+n*pow(10,N-i-1))%2019)

import collections

c = collections.Counter(r)

res = 0
for i in c.items():
  res += i[1]*(i[1]-1)/2
  if i[0]==0:
    res += i[1]

print(int(res))

Submission status: Time Limit Exceeded

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

def main():
     s = input()
     l = len(s)

     ans = 0

     for i in range(3, l):
          for j in range(l-i):
               # print('({}, {})'.format(j+1, j+i+1))
               check = int(s[j:j+i+1])
               if check % 2019 == 0:
                    ans += 1
                    # print('({}, {}) ans '.format(j+1, j+i+1))

     print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
n = len(s)
ans = 0

for i in range (n):
  for j in range (i,n):
    tmp = s[i:j+1];
    test = int(tmp)
    if(test%2019==0):
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
ans=0
for i in range(n-3):
    for j in range(i+4,n+1):
        if int(s[i:j])%2019==0:
            ans+=1
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):
        for j in range(i+3, n):
            if int(S[i:j+1]) % 2019 == 0:
                ans += 1
    print(ans)
main()

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import queue

def readInt():
	return int(input())

def readInts():
	return list(map(int, input().split()))

def readChars():
	return input().split()

s = input()

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    

s=input()

l=len(s)
cnt=0



for i in range(0,l):
	for j in range(i+1,l+1):
		if (int(s[i:j]))%2019==0:
			cnt+=1
			#print(s[i:j],i,j)	
			
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline())
k = 4
cnt = 0
while k <= len(str(n)):
  i = 0
  while i < len(str(n))-k+1:
    if int(str(n)[i:i+k]) % 2019 == 0:
      cnt += 1
    i += 1
  k += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0

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


print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

S = input()
N = int(S)
num = 2019

d = defaultdict(int)
lenS = len(S)
length = 4
cnt = 0 
for length in range(4, lenS+1):
    for i in range(lenS-length+1):
        subs = int(S[i:i+length])
        if subs%2019==0:
            cnt += 1
#        print('subs:', subs)
#        d[subs] += 1
'''
cnt = 0
i = 1
while 1:
    n = num*i
    if n>N:
        break
    val = d[n]
    cnt += val
    i += 1
'''
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
S = input().strip()
N = len(S)

# print([(i, j) for i in range(N) for j in range(i + 1, N + 1) if True or int(S[i:j]) % 2019 == 0])
print(sum([1 for i in range(N) for j in range(i + 1, N + 1) if int(S[i:j]) % 2019 == 0]))

Submission status: Time Limit Exceeded

Solution code:
l=list(str(input()))
val=0
ct=0
for i in range(len(l)):
    for j in range(i,len(l)):
        if(i!=j):
            val=int("".join(l[i:j+1]))
            if(val%2019==0):
                ct+=1
print(ct)

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline


def solve():
    S = input().strip()
    len_s = len(S)
    answer = 0
    for i in range(len_s):
        for j in range(1, len_s + 1):
            if not (i < j):
                continue
            answer += int(int(S[i:j]) % 2019 == 0)
    return answer

if __name__ == '__main__':
    answer = solve()
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
import sys

def input():
    return sys.stdin.readline().strip()
def main():
    S = input()
    cnt = 0

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

T = S()

def match(v):
    return int(v) % 2019 == 0

cnt = 0
A = []

for s in T:
    A.append(s)


for i in range(0, len(A)):
    x = ""
    x += A[i]
    for j in range(i+1, len(A)):
        x += A[j]
        if match(x):
            cnt += 1

print(cnt)

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:
                continue
            if int(S[start:i]) % 2019 == 0:
                cnt += 1
        start += 2
    print(cnt)
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
s = input()
cnt = 0
for i in range(len(s)-3):
    for j in range(i+3,len(s)):
        if int(s[i:j+1])%2019 == 0:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

s = input()
l = len(s)
cnt = 0

for i in range(l):
    for j in range(i+1,l):
            a = int(s[i:j+1])
            if a % 2019 == 0 and j < l:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import Counter
# sys.setrecursionlimit(100000)
# input = sys.stdin.buffer.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    # 2019 = 3 * 673

    rl = Counter([0])
    ans = 0
    for c in S:
        n = int(c)
        nrl = Counter([0])
        for r, m in rl.items():
            r = (r * 10 + n) % 2019
            if r == 0:
                ans += m
            nrl[r] += m
        rl = nrl
        # print(rl)

    return ans


def main():
    S = read_str()
    print(slv(S))

    # import random
    # S = ''.join(map(str, random.choices(range(1, 10), k=2*10**5)))
    # print(slv(S))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
length = len(s)
count = 0

for i in range(length-4):
    for j in range(i+4,length+1):
        num = int(s[i:j])
        if num%2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

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

print(ans)