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:
from math import factorial as fact
import math
import fractions
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=list(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(count)

Submission status: Time Limit Exceeded

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

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:
S = input()
N = len(S)
cnt = 0
for i in range(N-3):
	for j in range(i+4,N+1):
		if int(S[i:j])%2019 == 0:
			cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

S = tuple(map(int, list(input())))
MOD = 2019
dp = [defaultdict(int) for _ in range(len(S) + 1)]
for i in range(len(S)):
    dp[i + 1][S[i]] += 1
    for j in range(MOD):
        dp[i + 1][(j * 10 + S[i]) % MOD] += dp[i][j]

print(sum(dp[i][0] for i in range(len(S) + 1)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline


def main():
    S = input().strip()
    answer = 0
    for i in range(1, len(S)+1):
        for j in range(i+4, len(S)+1):
            if int(S[i-1:j]) % 2019 == 0:
                answer += 1
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()

dp = [[0]*2019 for i in range(len(s))]

mod = 2019

for l in range(0, len(s)-1):
    dp[l][int(s[l])] += 1
    for m in range(0, mod):
        if dp[l][m] != 0:
            num = int(s[l+1])
            dp[l+1][(10*m+num)%mod] += dp[l][m]
            
cnt = 0
for l in range(0, len(s)):
    if dp[l][0] != 0:
        cnt += dp[l][0]
        
print(cnt)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

res = 0

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

Submission status: Time Limit Exceeded

Solution code:

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

Submission status: Time Limit Exceeded

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

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


if __name__ == '__main__':
    main()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = input()
l = len(n)
count = 0
for i in range(l-3):
  for j in range(i+4, l+1):
    if int(n[i:j])%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-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())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))
s = list(input())
n = len(s)

ans = 0
for i in range(4,n):
    for j in range(0,n-i+1):
        tmp = s[j:j+i]
        tmp = int("".join(tmp))
        if tmp%2019 ==0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(str(input()))

ans = 0

for i in range(0,len(s)-4):
    for j in range(i+4,len(s)+1):
        temp = int(''.join(s[i:j]))
        if temp % 2019 == 0:
            ans += 1
            if j != len(s):
                if s[j] != '0':
                    continue

print(ans)

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

print(ans)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

num = 0
for i in range(len(s)):
  for j in range(i+4, len(s)):
    tmp = s[i:j+1]
    tmp_str = ""
    for k in tmp:
      tmp_str+=k
    if not tmp_str == "":
      if int(tmp_str)%2019==0:
        num+=1
      
print(num)

Submission status: Time Limit Exceeded

Solution code:
S = input()
counter = 0

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

Submission status: Time Limit Exceeded

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

for start in range(len(s) - 3):
    for end in range(start + 4, len(s) + 1):
        if int(s[start:end]) % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import decimal
input=sys.stdin.readline


s=input()
CHECK=set()
ans=0
S=int(s)
for i in range(len(s)-1):
    
    temp=(S%pow(10,i+1))%2019
    if temp==0:
        ans+=1
    elif temp not in CHECK:
        CHECK.add(temp)
    else:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
cnt = 0
S = input()  
for left in range(len(S)-3):
    for right in range(left+3,len(S)):
        ss = S[left:right+1]
        if int(ss) < 2019:
            continue
        sum = 0
        for i in ss:
            sum += int(i)
        if sum % 3 != 0:
            continue
        if int(ss) % 2019 == 0:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()

ij = []
for i in range(0, len(S)-3):
    for j in range(3, len(S)):
        sij = S[i:j+1]
        if len(sij) > 3:
            sij = int(sij)
            if sij % 2019 == 0 and i <= j:
                ij.append([i, j])

print(len(ij))

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
cnt = 0

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

Submission status: Time Limit Exceeded

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

S = input()
n = len(S)
integer = int(S)

ans = 0
for i in range(n-3):
    for j in range(i+4, n+1):
        num = (integer//10**(n-j) - integer//10**(n-i)*10**(j-i))
        if num % 2019 == 0:
            # print((integer//10**j - integer//10**i))
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

ans=0

for i in range(n):
  for j in range(i+3,n):
    s_ans=s[i:j+1]
    s_ans=int("".join(s_ans))
    if s_ans%2019==0:
      ans+=1
      
print(ans)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
dictmap = {
'0' : 0,
'1' : 1,
'2' : 2,
'3' : 3,
'4' : 4,
'5' : 5,
'6' : 6,
'7' : 7,
'8' : 8,
'9' : 9
}


strnum = input()
count = 0
n = len(strnum)
if int(strnum) < 2019 :
    print("0")
elif n >= 4 :
    for i in range(n - 3) :
        numtillnow = ""
        numtillnow += strnum[i]
        numtillnow += strnum[i+1]
        numtillnow += strnum[i+2]
        for j in range(i+3,n) :
            numtillnow += strnum[j]
            #print(numtillnow)
            if len(numtillnow) >= 4 :
                if int(numtillnow)%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+4, 200100):
    if j >len(s):
      break
    else:
      a = int(s[i:j])%2019
      if a == 0:
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
count=0
if n<4:
    print(0)
else:
    for i in reversed(range(2,n)):
        k=int(s[i-2:i+1])
        h=3
        for j in reversed(range(0,i-2)):
            k=k+10**(h)*int(s[j])
            h+=1
            if k%2019==0:
                count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=0
l=len(s)

for i in range(5,l+1):
    for j in range(0,l-i+1):
        ss=s[j:j+i]
        ss_n=int(ss)
        if ss_n%2019==0:
            k+=1

print(k)

Submission status: Time Limit Exceeded

Solution code:

N = int(input()) # 1行, 単数

S = str(N)
count = 0
for i in range(len(S) - 3):
  x = int(i)
  for j in range(int(i+3) , len(S)+1):
    y = int(j)
    A = int(S[x:y])
    if A % 2019 == 0:
      count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

fl = [False]*len(S)
l = 0
res = 0

for i in range(len(S)-3):
    if fl[i]:
        continue
    
    x = int(S[i:i+3])
    l = 0
    cnt = 0
    for j in range(i+3, len(S)):
        x *= 10
        x += int(S[j])
        x %= 2019
        if x == 0:
            cnt += 1
            fl[l] = True
            l = j+1
    
    res += (cnt+1)*cnt//2

print(res)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    a = "".join(["".join(["1"for j in range(i-3) if int(s[j:i])%2019==0]) for i in range(len(s)+1)])
    print(len(a))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = list(input())
N_len = len(N)
cnt = 0
a_list = []
t_list = []
for i in range(N_len+1):
    for j in range(i+1, N_len+1):
        a_list.append("".join(N[i:j]))
tmp = 1
while tmp < 100:
    t_list.append("".join(list(str(2019*tmp))))
    tmp += 1

for a in a_list:
    if a in t_list:
        cnt += 1

#print(len(a_list), len(t_list), a_list)
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
l = len(S) 
dic = {i:int(S[i]) for i in range(l)}
result = 0
for i in reversed(range(0,l)):
  res = 0
  ad = 1
  for x in reversed(range(0,i+1)):
    res += dic[x]*ad
    ad = ad*10
    if res % 2019 ==0:
      result += 1
print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
from collections import Counter

s = input()
s = list(s)[::-1]
A = [int(s[i])  * (10**(i))for i in range(len(s))]
A = [0] + list(accumulate(A))
A = [a%2019 for a in A]

A = Counter(A).most_common()
ans = 0
for _, count in A:
  if count == 1:
    break
  ans += count*(count-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = str(input())

#N = str(14282)

count = 0
lenN = len(N)+1
for i in range(lenN):
    for j in range(i+4, lenN):
        
        number = int(N[i:j])
        if number%2019 == 0:
            count +=1
#            print (i, j)
#T = int(N)//2019
#
#for t in range (T):
#    den = 2019*t
#    length = len(str(den))
#    sum_length = len(N)
#    for i in range(sum_length-length):
#        if den == int(N[i:i+length]):
#            count +=1

print (count)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    S = input()
    dig = len(S)
    S = int(S)
    count = 0

    for i in range(dig):
        for j in range(i+4,dig):
            if (S % (10**(dig-i)) //(10 ** (dig-j-1) ))%2019 ==0:
                count += 1
    print(count)

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
S=input()
l=len(S)
t=0
p=0
for i in range(l-1,2,-1):
    p=0
    for j in range(i+1):
        p+=int(S[i-j])*(10**j)%2019

        if p%2019==0:

            t+=1

print(t)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
sum = 0
for i in range(len(s)):
  element = ''
  for j in range(i+1,len(s)):
    element += s[j]
    if(int(s[i]+element) >= 2019 and int(s[i]+element) % 2019 == 0):
      sum += 1 

print(sum)

Submission status: Time Limit Exceeded

Solution code:


s = str(input())

n = len(s);

res = 0

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

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
S=input()
LS=len(S)
Comb=0
if LS<4:
	print(0)
else:
	for i in range(LS-3):
		for j in range(i+4,LS+1):
			if int(S[i:j])%2019==0:
				Comb+=1
	print(Comb)

Submission status: Time Limit Exceeded

Solution code:
import math
import fractions
import collections
import itertools
from collections import deque
d=collections.deque()
S=input()
N=len(S)
cnt=0

amari=[0]*(N+1)
num=0
for i in range(N):
    d.append(int(S[i]))
#print(d)
for i in range(N):
    n=d.pop()
    num=(num+pow(10,i)*n)%2019
    amari[i+1]=num
#print(amari)
#c=collections.Counter(amari)
#values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
amari.sort()
#for i in range(len(key)):
#    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#xprint(l)
buf=0
#print(amari)
for i in range(N-1):
    if amari[i]==amari[i+1]:
        buf=buf+1
    else:
        cnt=cnt+((buf+1)*buf)//2
        buf=0
    #print(buf)
cnt=cnt+(buf*(buf+1))//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


S = input()
l = len(S)
d = {}


ans = 0
for i in range(l):
    m = int(S) % 2019
    if m in d:
        d[m] += 1
    else:
        d[m] = 1
    S = S[1:]

for k, v in d.items():
    if v >= 2:
        ans += cmb(v, 2)
    if k == 0:
        ans += v
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def counter(str, l, k): 
	count = 0
	for i in range(l): 
		n = 0
		for j in range(i, l, 1): 
			n = n * 10 + (ord(str[j]) - ord('0')) 
			if (n % k == 0): 
				count += 1
	return count 
if __name__ == '__main__': 
	str = input()
	l = len(str) 
	k = 2019
	print(counter(str, l, k))

Submission status: Time Limit Exceeded

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

a = 0
count = 0

for i in range(l-2):
    a = int(S[l-i-1])
    for j in range(i+1,l):
        a += int(S[l-j-1])*10**(j-i)
        if a % 2019 == 0:
            count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
str=input("")
count=0;
for i in range(len(str)-1):
  for j in range(i+1,len(str)+1):
    if eval(str[i:j]) % 2019==0:
      count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
for y in range(len(S) - 3):
    for x in range(len(S) - y - 3):
        check_S = int(S[y:x + y + 4])
        if check_S % 2019 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
# print(S)

if int(S) < 2019:
    print(0)
    exit()

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

print(count)

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
	s = int(input())
	l = []
	length = 0
	ans = 0
	for i in range(sum(range(1,len(str(s))-2))):
		for l in range(i,len(str(s))-3):
			if len(str(s)[i:(l+4)]) >= 4 and int(str(s)[i:(l+4)]) % 2019 == 0:
				ans += 1

	print(ans)

	

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    S = input().rstrip()

    result = 0
    length = len(S)
    if length < 4:
        print(result)
        return

    for keta in range(4, length+1):
        for i in range(length - keta + 1):
            j = i + keta
            if int(S[i:j]) != 0 and int(S[i:j]) % 2019 == 0:
                result += 1
    
    print(result)



if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

MOD = 2019
S.reverse()
cnt = 0
temp = 0
ans = [0]*2019
for i in S:
    temp += i*10**cnt % MOD
    temp %= MOD
    ans[temp] += 1
    cnt += 1

ans[0] += 1

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans = 0
dp = [[0 for i in range(len(s)+3)]for j in range(len(s)+3)]
def rec(i,j,num):#j:numの左から何個けずった？ i:sの左から何番目までいった？
    global ans
    if dp[i][j] == 1:
        return
    dp[i][j] = 1
    if int(num) % 2019 == 0:
        ans += 1
    else:
        if j < len(s):
            rec(i,j+1,num+s[j])
        if len(num) >= 2:
            rec(i+1,j,num[1::])

rec(0,1,s[0])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  keta = len(str(n))
  count = 0
  for i in range(keta):
    for j in range(keta+1):
      if j >= i+3:
        if ((n % (10**(keta-i))) // (10**(keta-j))) % 2019 == 0:
          count += 1
  print(count)
main()

Submission status: Time Limit Exceeded

Solution code:
import sys
si = sys.stdin.readline


def main():
    s = si()[:-1]
    cnt = 0
    if len(s) < 4:
        print(0)
        return
    for i in range(len(s)-3):
        for j in range(i+4, 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:
import sys
input = sys.stdin.readline

s = input().replace("\n","")

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()

l=len(s)

count=0
for i in range(l):
    cu=[]
    for j in range(i,l):
        cu.append(s[j])
        test = ''.join(cu)
        test=int(test)
        if test % 2019 ==0:
            count=count+1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

s=input() 
cnt = 0
que = deque()
for i in range(len(s)):
    que.append(s[i])
l = ''

for i in range(len(s)):
    for j in range(len(que)):
        l = str(l) + str(que[j])
        tmp = int(l)
        if tmp % 2019 == 0:
            cnt = cnt + 1
    l=''
    que.popleft()

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
S = input()
start_index = 0
counter = 0
while start_index < len(S) - 3:
    temp_counter = 0
    temp_start_index = start_index
    end_index = start_index + 5
    while end_index <= len(S):
        if int(S[temp_start_index:end_index]) % 2019 == 0:
            temp_counter += 1
            temp_start_index = end_index
            end_index += 5
        else:
            end_index += 1
    if temp_counter != 0:
        counter += math.factorial(temp_counter)
    start_index += 1

print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

s = input()
ans =0
nums =""
for i in range(len(s)):
    for j in range(i+3,len(s)):
        for k in range(i,j+1):
            nums += s[k]
        num =int(nums)
        nums=""
        if num%2019==0:
            ans+=1
            #print(i,j,num)



print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
n = len(s)
a = []
b = 2019
for i in range(10000):
    b+=2019
    c = str(b)
    if '0' not in c:
        a.append(c)

ans = 0
for i in range(n):
    k = [4,5,6,7,8]
    for j in k:
        if i+j <= n:
            ss = s[i:i+j]
            if ss in a:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = int(input())

str_S = str(S)
count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def slove(n):
    count = 0
    num = len(n)+1

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

    return count

if __name__ == "__main__":
    n = input()
    print(slove(n))

Submission status: Time Limit Exceeded

Solution code:
N = input()
c = 0
for i in range(0, len(N)+1):
  for j in range(i, len(N)+1):
    a = N[i:j]
    if not a:
      pass
    else:
      if int(a) %2019 ==0:
        c += 1

print(c)

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

Submission status: Time Limit Exceeded

Solution code:
# ABC164 D

def main():
    s = input()
    count = 0

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools


def run():
    n_str = input()
    n_len = len(n_str)

    res = 0
    for i, j in itertools.combinations(range(0, n_len+1), 2):
        if j - i <= 3:
            continue

        target = int(n_str[i:j])

        if target % 2019 == 0:
            res = res + 1

    print(res)


if __name__ == '__main__':
    run()

Submission status: Time Limit Exceeded

Solution code:
s = input()

m_len=len(s)
count = 0
for i in range(4,m_len+1):
  for j in range(0,m_len+1-i):
    a,b = divmod(int(s[j:j+i]),2019)
    if b == 0:
      count += 1
print(count)

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

Submission status: Time Limit Exceeded

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

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

# 結果出力
print(result)

Submission status: Time Limit Exceeded

Solution code:
s=input()
a=0
b=''

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

    print(ans)


if __name__ == "__main__":
    main()