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

Submission status: Time Limit Exceeded

Solution code:
S = abs(int(input()))
# S = abs(int(1817181712114))
strS = str(S)
length = len(strS)

multiple = 0

for i in range(0, length-3) :
    for j in range(i+4, length+1) :
        num = strS[i:j:1]
        intNum = int(num)
        if intNum <= 200000 and intNum % 2019 == 0 :
            multiple += 1

print(multiple)

Submission status: Time Limit Exceeded

Solution code:
import datetime


s = input()
n = len(s)

seen = {}

for i in range(n):
    seen[i] = set()

k = 2019
res = 0

for i in range(n):
    rem = 0
    prefixesFound = 0
    for j in range(i, n):
        rem = (10 * rem + ord(s[j]) - ord('0')) % k
        # print(rem)
        if j in seen and rem in seen[j]:
            break
        if j not in seen[j]:
            seen[j] = set()
            seen[j].add(rem)
        if rem == 0:
            prefixesFound += 1
    res += (prefixesFound * (prefixesFound + 1)) // 2

print(int(res))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
S=list(input())
SS=""
N=len(S)

MAX=2100
MOD=10**9+7

fac=[None for i in range(MAX)]
finv=[None for i in range(MAX)]
inv=[None for i in range(MAX)]

def COMinit(num):
    global fac
    global finv
    global inv
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1

    for i in range(2,num):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n,k):
    if n<k:
        return 0
    elif n<0 or k<0:
        return 0
    else:
        return int(fac[n] * (finv[k] * finv[n - k] % MOD) % MOD)


COMinit(MAX)

M=[[0 for j in range(10)] for i in range(2019)]
ans=0
for i in range(N):
    SS=S[-(1+i)]+SS
    num=int(SS)
    I=num%2019
    if I==0:
        ans+=1
    syou=num//2019
    J=int(str(syou)[-1])
    M[I][J]+=1

for i in range(2019):
    for j in range(10):
        if M[i][j]>=2:
            ans+=COM(M[i][j],2)

# print(1817181712114%2019)
# print(1817181712114//2019)
# print(81712114%2019)
# print(81712114//2019)
# print(18171%2019)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    N = len(S)
    ans = 0
    m = 2019
    div_list = [0]*2019
    div_list[0] += 1
    num = 0
    for i in range(N):
        num += 10**i*int(S[N-i-1])
        div_list[num%m] += 1

    for item in div_list:
        if item >= 2:
            ans += int(item*(item-1)/2)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
S = str(input())

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

Submission status: Time Limit Exceeded

Solution code:
import collections
s = input()
ans = 0

for j in range(len(s)):
    l = [int(s[j:i])%2019 for i in range(j+1,len(s)+1)]
    ans += l.count(0)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range((len_S-4)//2):
    for j in range(i+3, len_S):
        tmp = int(S[i:j+1])

        if tmp % 2019 == 0:
            cnt += 1
            i = j
            continue



print(cnt)

Submission status: Time Limit Exceeded

Solution code:

s = input()

count = 0

for h in range(0, len(s)):

    # print('h : {} '.format(h))

    for i in range(0, len(s)):
        
        # print('i : {} '.format(i))

        temp = '0'

        # 各要素を足す
        for j in range(h, i + 1):
            temp = temp + s[j]

        # 数値に変換
        temp = int(temp)
        # print('temp : {} '.format(temp))

        # 2019で割って判定
        if temp != 0 and temp % 2019 == 0 :
            # print('カウント!')
            count = count + 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
L = len(str(S))
SS = str(S)

def calc(l):
    i = 0
    ct = 0
    while i + l <= L:
        if int(SS[i:i+l]) % 2019 == 0:
            ct += 1 
        i += 1
    return ct

l = 4
count = 0
    
while l <= L:
    count += calc(l)
    l += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
#この解放だとTLE....
s = input()
c = 0
l = len(s)
h = 1
for i in range(len(s)):
    for j in range(l):
        #print(i,h)
        #print(s[i:(j+1)])
        if(int(s[i:h]) % 2019 == 0):
            c += 1        
        h += 1
    #l：ループ回数減らす　　　h:jの代わり   
    l -= 1
    h = i+2
print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()
Sl = []
pre = 0
answer = 0
for i, s in enumerate(S):
    if i ==0:
        Sl.append(pre)
        Sl.append(pre+int(s))
        pre += int(s)
    else:
        Sl.append(pre+int(s))
        pre += int(s)


for i in range(len(S)-2):
    for j in range(i+5,len(S)+1):
        if (Sl[j]-Sl[i]) %3 ==0:
            if int(S[i:j]) % 673 ==0:
                answer += 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import math
    
def abs(num):
    if num < 0:
        return -num
    else:
        return num

###
# main
if(__name__ == '__main__'):
    # input
    s = input()
    len_s = len(s)

    ans = 0
    if len_s >= 4:
        queue = []
        for i in range(len_s-3):
            tgt = int(s[i:i+4])
            mod = tgt % 2019
            queue.append([i, i+3, mod])

        while len(queue) != 0:
            elem = queue.pop()
#            print(tgt)
            if elem[2] == 0:
                ans += 1
            
            if elem[1]+1 < len_s:
                tgt = elem[2] * 10 + int(s[elem[1]+1])
                mod = tgt % 2019
                add_elem = [elem[0], elem[1]+1, mod]
                queue.append(add_elem)

    print(ans)
    
# else:
    # do nothing

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def factorization(n):
	tmp=n
	count=0
	for i in range(2,int(n**0.5)+2):
		if tmp%i==0:
			cnt=0
			while tmp%i==0:
				cnt+=1
				tmp//=i
			count+=1
	if tmp!=1:
		count+=1

	return count
			




s=str(input())
# combi=combinations(int(len(s)),2)
count=0
# for i in combi:
# 	start=i[0]
# 	end=i[1]
# 	num=int("".join(s[start:end+1]))
# 	if num%2019==0:
# 		count+=1
# 		print(start,end)
# print(count)
length=len(s)
for i in range(length):
	start=i
	for j in range(i+1,length):
		end=j
		num=int(s[start:end+1])
		if num%2019==0:
			count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def s0():return input()

s=s0()
d=[int(s[0])]
c=0
for i in s[1:]:
    y=int(i)
    d = [x*10+y for x in d]
    d.append(y)
    for j in d:
        if j%2019==0:
            c+=1
#     print(d)
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = 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:
S=input()
count=0
#2019の倍数:4桁以上、3の倍数
for i in range(4,len(S),1):
 for j in range(0,len(S)-i+1,1):
  A=0
  #print(i,j)
  for k in range(i):
   A+=int(S[j+i-1-k])*10**k
  #print(A)
  if A%2019==0:
   count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
#S = str(1817181712114)
ans = 0
 
for a in range(len(S) - 3):
	for b in range(a+3, len(S)):
		if int(S[a:b+1]) % 2019 == 0:
			ans += 1        
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()

    simo5 = set()
    for i in range(5,1000001):
        s = str(2019*i)
        if '0' not in s:
            simo5.add(s[-5]+s[-4]+s[-3]+s[-2]+s[-1])

    l = len(S)
    ans = 0
    for i in range(l-1,3,-1):
        tmp = ''.join([S[i-3],S[i-2],S[i-1],S[i]])
        if int(tmp)%2019 == 0:
            ans += 1
        else:
            tmp = ''.join([S[i-4],tmp])
            if tmp not in simo5:
                continue
            else:
                if int(tmp)%2019 == 0:
                    ans += 1
            for j in range(i-5,-1,-1):
                tmp = ''.join([S[j],tmp])
                if int(tmp)%2019 == 0:
                    ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = input()
n_len = len(n)
count = 0

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

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
# input
S = input()

# process
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

# output
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(cnt)

Submission status: Time Limit Exceeded

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

left, right = 0, 0
ans = 0

for left in range(N):
    for right in range(left, N + 1):
        if S[left:right] and int(S[left:right]) % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 標準入力の取得
S = input()

# 求解処理
size = len(S)
result = 0
for i in range(size-3):
    sub_S = S[i:i+3]
    rest_S = S[i+3:]
    for j in rest_S:
        sub_S += j
        number = int(sub_S)
        if number % 2019 == 0:
            result += 1

# 結果出力
print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

len_s = len(s)
count = 0
keta = 0
for l in range(4, len_s+1):
    for keta in range(len_s):
        check = s[keta:keta+l]
        if int(check) % 2019 == 0:
            count += 1
        keta += 1
        if keta+l > len_s:
            break

print(count)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    s=input()
    n=len(str(s))
    ans=0
    for i in range(4,n+1):
        for j in range(n-i+1):
            a = int(''.join([x.strip() for x in s[j:j+i].split(',')]))
            if a%2019==0:
                ans+=1
    print(ans)
resolve()

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-4):
	for j in range(i+5,l+1):
		if (int(s[i:j]))%2019==0:
			cnt+=1
			j+=3
			#print(s[i:j],i,j)	
			
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

l_mod = []
count = 0
j = len(s)
for i in reversed(range(len(s)-1)):
  amari = int(s[i:j]) % 2019
  if amari == 0:
    count += 1
  else:
    count += (amari in l_mod)
  l_mod.append(amari)
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
counter=0
for i in range(N):
    a=4+i
    while a < N+1:
        b=int(S[i:a])
        if b%2019 == 0:
            counter += 1
        a+=1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = str(input())

n = 0
for i in range(len(N)+1):

    for j in range(i+1):
        if i-j<2: continue
        num = int(N[j:i])

        if (num%2019)==0: n += 1

print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(match)

Submission status: Time Limit Exceeded

Solution code:
def main(): 
  s_str = input()

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

if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

d = defaultdict(int)
for i in rui:
    d[i] += 1
ans = 0
for v, m in d.items():
    if m >= 2:
        ans += (m * (m - 1) // 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = [0 for _ in range(len(s))]
for i in range(len(s)-5, -1, -1):
    for j in range(i+4, len(s)):
        x = int(s[i:j+1])
        if x %2019 != 0:
            continue
        ans[i] += 1
        if j+1 < len(s):
            ans[i] += ans[j+1]
        break

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
s = input()
li = []
for i in range(1, 200000):
    i *= 2019
    i = str(i)
    if i in s:
        a = [x for x in range(len(s)) if s.startswith(i, x)] 
        for b in a:
            li.append(b)
print(len(li))

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])+int(S[i+1])+int(S[i+2])
        for j in range(i+3, n):
            s += int(S[j])
            s %= 3
            #print(i,j,S[j],s)
            if s == 0:
                if int(S[i:j+1]) % 673 == 0:
                    ans += 1  
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
s = input()

l=list()
ans = 0
for i in range(0,len(s)+1):
    for j in range(0,len(s)+1):
        if i >= j:
            continue

        if int(s[i:j]) % 2019 == 0:
            ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = list(s)
lLen = len(l)
lLimit = len(l) - 3
cnt = 0

for i in range(lLen):
    
    for j in range(i+3, lLen):
        n = int(s[i:j+1])
        if n % 3 == 0:
            if n % 673 == 0:
                cnt = cnt + 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=input()
ls=len(s)
# 例外処理
if ls<4:
    print(0)
else:
    ans=0
    def mod2019(a):
        return a%2019
      
    for i in range(ls-3):
        amari=mod2019(int(s[i:i+3]))
        for j in range(i+3,ls):
            amari=mod2019(amari*10+int(s[j]))
            if amari==0:
                ans+=1
    
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
result = 0

for i in range(int(s)//2019):
  b = (i+1) * 2019
  result += s.count(str(b))

print(result)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
len_s = len(s)
list_2019 = ['2019', '4038', '6057', '8076', '10095', '12114', '14133', '16152', '18171', '20190', '22209', '24228',
             '26247', '28266', '30285', '32304', '34323', '36342', '38361', '40380', '42399', '44418', '46437',
             '48456', '50475', '52494', '54513', '56532', '58551', '60570', '62589', '64608', '66627', '68646',
             '70665', '72684', '74703', '76722', '78741', '80760', '82779', '84798', '86817', '88836', '90855',
             '92874', '94893', '96912', '98931', '100950', '102969', '104988', '107007', '109026', '111045',
             '113064', '115083', '117102', '119121', '121140', '123159', '125178', '127197', '129216', '131235',
             '133254', '135273', '137292', '139311', '141330', '143349', '145368', '147387', '149406', '151425',
             '153444', '155463', '157482', '159501', '161520', '163539', '165558', '167577', '169596', '171615',
             '173634', '175653', '177672', '179691', '181710', '183729', '185748', '187767', '189786', '191805',
             '193824', '195843', '197862', '199881']
ans = 0
for i in range(4, len_s + 1):
    for j in range(len_s):
        if (j + i <= len_s) and (''.join(s[j:j + i]) in list_2019):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
L = len(S)
con = 0


for j in range (4,L):
    for i in range (L-j):

        preche = S[i:i+j+1]
        che = int(preche) % 2019

        if(che==0):
            con += 1

print(con)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  N = str(input())

  ans = 0
  ln_N = len(N)

  for i in range(ln_N):
    for j in range(ln_N-i):
      k = ln_N -j 
      a = int(N[i:k])
 #     print(a)
      if a % 2019 == 0:
        ans += 1
  print(ans)     

if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 26 20:56:56 2020

@author: Kanaru Sato
"""

s = input()
n = len(s)
s = int(s)
mod = 2019
count = 0

for i in range(1,n-2):
    for j in range(i+3,n+1):
        num1 = 10**(n-i+1)
        num2 = 10**(n-j)
        sample = (s%num1)//num2
        if sample % mod == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

possible4 = {1009,
 1029,
 1049,
 1070,
 1090,
 1110,
 1130,
 1150,
 1171,
 1191,
 1211,
 1231,
 1251,
 1271,
 1292,
 1312,
 1332,
 1352,
 1372,
 1393,
 1413,
 1433,
 1453,
 1473,
 1494,
 1514,
 1534,
 1554,
 1574,
 1595,
 1615,
 1635,
 1655,
 1675,
 1695,
 1716,
 1736,
 1756,
 1776,
 1796,
 1817,
 1837,
 1857,
 1877,
 1897,
 1918,
 1938,
 1958,
 1978,
 2019,
 2220,
 2422,
 2624,
 2826,
 3028,
 3230,
 3432,
 3634,
 3836,
 4038,
 4239,
 4441,
 4643,
 4845,
 5047,
 5249,
 5451,
 5653,
 5855,
 6057,
 6258,
 6460,
 6662,
 6864,
 7066,
 7268,
 7470,
 7672,
 7874,
 8076,
 8277,
 8479,
 8681,
 8883,
 9085,
 9287,
 9489,
 9691,
 9893}

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
b=len(s)
x=0
for j in range(b-3):
    for i in range(b-j-4):
        a= int(s[j:j+i+5])
        if a % 3 ==0:
            if a%2019==0:
                x+=1
        else:
            continue
print(x)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
sums_from_first_mod = [0] * (n+1)
for i in range(1,n+1):
    sums_from_first_mod[i] = (sums_from_first_mod[i-1] + int(s[i-1])) % 3
# print(sums_from_first_mod)
indices = []    
for num in range(3):
    indices.append([i for i, x in enumerate(sums_from_first_mod) if x == num])
# print(indices)
cnt = 0
for num in range(3):
    for i in indices[num]:
        for j in indices[num]:
            if j >= i+4:
                if int(s[i:j]) % 673 == 0:
                    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
mod = 2019
count = 0

for i in range(l - 3):
    base = ''.join([S[i], S[i + 1], S[i + 2]])
    for j in range(i + 3, l):
        base = ''.join([base, S[j]])
        if int(base) % 2019 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

s = input('')
max_s = int(200000)
rec = 0
for m in (range(max_s+1)):
    ms=str(2019*m)
    idx=0
    idx=s.find(ms)
#    if idx>0:
#        print("{} {}".format(ms,idx))
    while idx >= 0:
        rec+=1
        idx=s.find(ms,idx+1)
#        print("{} {}".format(ms,idx))
print(rec)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import collections
from sys import stdin


def get_result(data):
    S = data[0]
    mod_all_bit = [0]
    for i in range(len(S)):
        mod_all_bit.append(int(S[-(i+1):]) % 2019)
    c = collections.Counter(mod_all_bit)
    ans = 0
    for key, val in c.items():
        if val >= 2:
            ans += int(val * (val-1) * 0.5)
    return 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:
import numpy as np
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    count=np.zeros(2019,dtype=int)
    ans=0
    count_t=np.zeros(2019,dtype=int)
    for i in range(len(s)):
        count_t[int(s[i])]+=1
        for k in range(2019):
            t=(k*10+int(s[i]))%2019
            count_t[k]-=count[k]
            count_t[t]+=count[k]
            if t==0:
                ans+=count[k]
        #print(count[0:20])
        #print(count_t[0:20])
        count=count+count_t
        count_t-=count_t
    print(ans)
                
if __name__ == '__main__':
    do()

Submission status: Time Limit Exceeded

Solution code:
s = input()

if len(s) < 4 or s == "0000":
    print(0)
else:
    ans = 0
    for i in range(0, len(s)-4):
        for j in range(i+4, len(s)+1):
            window = s[i:j]
            if int(window)%2019 == 0:
                ans += 1

    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
for i in range(len(s)):
    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:
S = input()

magic = 2019
len_S = len(S)
max_len = len_S
len_magic = len(str(magic))

now_len = max_len

n = 0
tmp_len = now_len
for i in range(now_len, len_magic, -1):
  for j in range(len_S-i+1):
    k = j + tmp_len
    # print("now_len: "+str(now_len))
    # print("{} {}".format(j,k))
    if int(S[j:k]) % magic == 0:
      # print("{} {}".format(j,k))
      n += 1

  tmp_len -= 1
    

print(n)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

d = defaultdict(int)
for i in rui:
    d[i] += 1
ans = 0
for v, m in d.items():
    if m >= 2:
        ans += (m * (m - 1) // 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
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=int(input())
if n<10000:
  if n%2019 == 0:
    print(1)
  else:
    print(0)
else:
  x=str(n)
  c=0
  for i in range(len(x)-4):
    for j in range(i+4, len(x), 4):
      if int(x[i:j+1]) % 2019 == 0:
        c+=1
  print(c)

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()

mod = [0] * (2019+1)

tmp = ""
for i in range(1, len(S)+1):
    tmp = int(S[-i] + str(tmp))
    mod[tmp % 2019] += 1

ans = mod[0]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
L = len(S)
Sum = 0
def fa(x,y):
    A = 0
    for i in range(x,y+1):
        A += int(S[i])
        A *= 10
    return A
for j in range(0,L):
    for k in range(j,L):
        if (fa(j,k)//10) % 2019 == 0:
            Sum += 1
print(Sum)

Submission status: Time Limit Exceeded

Solution code:
a=input()
l=len(a)
c=0
for x in range(l-3):
  for y in range(x+4,l+1):
    n=int(a[x:y])
    if n%2019==0:
      c+=1
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_len = len(s)
total = [0, int(s[0])]

for i in range(1,s_len):
    total.append(total[-1]+int(s[i]))

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

print(count)

Submission status: Time Limit Exceeded

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

w = [[] for _ in range(3)]
ans = 0

for i in range(n):
    z = int(s[i:])%3
    w[z].append(i)

for i in range(3):
    for j in range(len(w[i])):
            for k in range(j,len(w[i])):
                u = w[i][j]
                v = w[i][k]
                if u == v :
                    y = int(s[u:])
                else:
                    y = int(s[u:v])
                if int(y)%m == 0:
                    ans += 1
print(ans)