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

result = 0

if (len(s) < 4):
    print(0)
    quit()

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
S0 = int(input())
total = 0
S = []
while S0 > 0:
    S.append(S0%10)
    S0 //= 10
S.reverse()
for i in range(len(S)-2):
  n = S[i] + S[i+1] + S[i+2]
  for j in range(i+3,len(S)):
    n += S[j]
    if n % 3 == 0:
      count = 0
      for k in range(i,j+1):
        count = count*10+S[k]
      if count% 2019 == 0:
        total += 1
print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

ans = 0
tot = [str(0)]

for i in range(len(S)-1):
  for j in range(i,len(S)):
    if int(''.join(tot)) % 2019 == 0 and int(''.join(tot)) >= 2019:
      ans += 1
    tot = [str(0)]
    for k in range(i,j+1):
      tot.append(S[k])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
i = list(input())
count = 0
for j in range(len(i)):
    check = ""
    for k in range(len(i) - j):
        if int("".join(map(str, i[j:len(i)-k]))) % 2019 == 0 and int("".join(map(str, i[j:len(i)-k]))) != 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
S = input()

l = len(S)

ans = 0
for s, e in itertools.combinations(range(l+1), 2):
  if int(S[s:e]) % 2019 == 0:
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
mod = 2019
ls = len(s)
cnt = 0
for i in range(ls-3):
    st = int(s[i:i+2])
    if st%2!=0:
        continue
    for j in range(i+3,ls):
        c = int(s[i:j+1])
        if c%mod ==0:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
import math


#計算量を無視して愚直に実装してみる
S = input() #文字列型で受け取る
#print(len(S))

index = [i for i in range(len(S))]
combi = list(combinations(index, 2))
#print(combi)

counter = 0
for i in range(len(combi)):
    #print()
    #print('start:{},goal:{}'.format(combi[i][0], combi[i][1]+1))
    s = S[combi[i][0]:combi[i][1]+1]
    #print('s:{},s%2019:{}'.format(s, int(s)%2019))
    #print()
    if(int(s) % 2019 == 0):
        #print('hit')
        counter += 1
print(counter)



'''
#実験1
def is_there_0(K):
    #文字列入力
    ret = 'No'
    for i in range(len(K)):
        if(K[i] == '0'):
            ret = 'Yes'
    return ret

for i in range(1000):
    if(is_there_0(str(2019*i)) == 'No'):
        print('i:{}, 2019*i:{}'.format(i, 2019*i))
'''




















'''
#実験2
l = []
for i in range(10000):
    l.append( (2019*i)%10000 )

l = sorted(l)
#print(l)
print(len(l))
'''

Submission status: Time Limit Exceeded

Solution code:

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

Submission status: Time Limit Exceeded

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

cnt = 0

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
tmp = 2019
count = 0
ans = []
for j in range(5,len(S)):
  for i in range(len(S)):
    if i > len(S)-j:
      break
    if int(S[i:i+j]) in ans:
      count += 1
    elif int(S[i:i+j])%2019 == 0:
      ans.append(int(S[i:i+j]))
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    s = kwargs["s"]
    n = len(s)
    res = 0

    for i in range(0, n - 3):
        sums = sum([int(k) for k in s[i:i + 4]])

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

            if j < n:
                sums += int(s[j])

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["s"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    #kwargs["n"] = [int(i) for i in cin][0]
    #kwargs["n"], kwargs["k"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

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()
cnt=0
le=len(s)
for i in range(1,le-2):
    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:
import sys
import math
from collections import Counter
import itertools
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

S=SR()

L=[i*2019 for i in range(1,200000)]
cnt=0
for i in range(1, len(S)-3):
    for j in range(i+3, len(S)+1):
        if int(S[i-1:j]) in L:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = str(input())
i= 0

def dfs(st, ed):
    global i
    while ed <= num:
        if int(n[st:ed]) % 2019 == 0:
            i += 1
        ed += 1
        
num = len(n)
for _ in range(num):
    if _ + 4 <= num:
        dfs(_, _+4)
    else:
        break
print(i)

Submission status: Time Limit Exceeded

Solution code:


s = str(input())

n = len(s);

res = 0

def sumDig(s):
    res = 0
    
    for a in s:
        res += ord(a)
    return res

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import sys
S = input()
count = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
tmp = 10**9
for i in range(len_s-3):
    if i == tmp:
        pass
    for y in range(i+3, len_s):
        if int(s[i:y+1]) % 2019 == 0:
            ans += 1
            tmp = y+1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

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

Submission status: Time Limit Exceeded

Solution code:
string = input()
length = len(string)
n = int(string)
s = 0
while(length>3):
    t = n
    while(t>9):
        if(t%2019==0):
            s+=1
        t = t//10

    d = 1
    for i in range(length-1):
        d *= 10
    n %= d
    length -= 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
S = input()
X = [int(i) for i in S]
amari = {}
ans = 0
for i in X:
    nextamari = {}
    for j in amari.keys():
        x = (j * 10 + i) % 2019
        nextamari[x] = amari[j]
    if i in nextamari:
        nextamari[i] += 1
    else:
        nextamari[i] = 1
    if 0 in nextamari:
        ans += nextamari[0]
    amari = nextamari
#    for i in nextamari.keys():
#        if nextamari[i] != 0:
#            print(nextamari[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def func():
    return

# n = int(input())
s = input()
# a, b = map(int, input().split())
# a = list(map(int, input().split()))
# a = input().split()

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
dp = [[0 for i in range(2019)] for j in range(len(s)+1)]

ans = 0
for i in range(len(s)):
    c = int(s[i])
    for j in range(2019):
        nex = (j*10+c)%2019
        dp[i+1][nex] = dp[i][j]
    dp[i+1][c] += 1
    ans += dp[i+1][0]

# print(dp[-1])
# for l in dp:
#     print(l)
# print(dp[-1][0])
print(ans)

Submission status: Time Limit Exceeded

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

print (ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

S = int(input())
l = [int(s) for s in list(str(S))]
ans = 0

for i in range(len(l)):
    for j in range(i+1, len(l)+1):
        new = int(reduce(lambda x, y: x + y, [str(x) for x in l[i:j]]))
        if new % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict

S = input().strip()
l = len(S)
no_zero_dic = {}
dp = [[0 for _ in range(2019)] for i in range(l)]
ans = 0
for i in range(l):
    s = int(S[i])
    no_zero_dic[s] = 1
    _x = set(no_zero_dic.keys())
    for j in _x:
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
        if dp[i-1][j] > 0:
            no_zero_dic[k] = 1
        if k == 0:
            ans += dp[i][k]
    dp[i][s] += 1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
strS = input()
maxlength = len(strS)
count = 0

for i in range(maxlength -3):
  #print("i:{}".format(i))
  for j in range(maxlength - (i+3)):
    #print("j:{}".format(j))
    trynum = int(strS[i:i+4+j])
    if ( trynum % 2019 == 0 ):
      count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(str(input()))
n = len(S)

S.reverse()

cum1 = [-1]*(n+1)
cum1[0] = 0
for i in range(n):
    temp = cum1[i]+int(S[i])*10**i
    cum1[i+1] = temp%673
#print(cum1)

cum2 = [-1]*(n+1)
cum2[0] = 0
for i in range(n):
    temp = cum2[i]+int(S[i])*10**i
    cum2[i+1] = temp%3
#print(cum2)

d1 = {}
d2 = {}
ans = 0
for i in range(n+1):
    if cum1[i] in d1 and cum2[i] in d2:
        temp = d1[cum1[i]] & d2[cum2[i]]
        ans += len(temp)
    if cum1[i] not in d1:
        d1[cum1[i]] = {i}
    else:
        d1[cum1[i]].add(i)
    if cum2[i] not in d2:
        d2[cum2[i]] = {i}
    else:
        d2[cum2[i]].add(i)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    n = 0
    count = 0

    for i in range(len(s)-3):
        for j in range(3, len(s)):
            if i > j:
                continue

            n = s[i:j+1]

            # print(n)
            if int(n) % 2019 == 0:
                count += 1

    print(count)


if __name__ == '__main__':
    main()

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

Submission status: Time Limit Exceeded

Solution code:
def number(S, a ,b):
    number =0
    for i in range(b- a+1):
        number += 10**(b- a - i)*int(S[a+i])
    return number


S = input()
N=len(S)
if N <=3:
    ans =0
    
else:
    ans =0
    for i in range(N-3):
        for j in range(i+3 ,N):
            if number(S, i ,j) %2019==0:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
s = input()
n = [i for i in range(len(s))]
num = list(itertools.combinations(n, 2))
ans = 0
for i in num:
    if int(s[i[0]:i[1]+1]) % 2019 == 0:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
N=len(s)
ans=0
se=set()
for i in range(N):
    for j in range(i,N):
        if int(s[i:j+1])%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)):
    if len(que) >= 5:
        l = str(que[0]) + str(que[1]) + str(que[2]) + str(que[3]) 
        for j in range(len(que)-4):
            l = str(l) + str(que[j+4])
            tmp = int(l)
            if tmp % 2019 == 0:
                cnt = cnt + 1
        l=''
        que.popleft()

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
a = 2019
i = 0
ans = 0
while True:
    i += 1
    b = a * i
    if b > int(s):
        break
    ans += s.count(str(b))
print (str(ans))

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = str(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:
#MLE注意！ not は使わず !=
#0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    n = input().rstrip()
    res = [0]*2019
    res[0] += 1
    
    for i in range(len(n)):
        a = int(n[i:])
        b = a%2019
        res[b] += 1
    ans = 0
    for i in res:
        if i>=2:
            ans += i*(i-1)//2
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
num = input()
word_len = 0
for i in num:
  word_len += 1

count = 0
for a in range(0,word_len+1):
  for b in range(a+3,word_len+1):
    nums = int(num[a:b])
    if nums%2019 ==0:
      count += 1
    else:
      pass
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
mods = []
crt = int(s[-1])
if len(s) <= 4:
    print(0)
    exit()
# for i in range(len(s)):
#     crt = crt*10+int(s[i])
#     crt %= 2019
#     mods.append(crt)
# print(mods)
for i in range(len(s)-2,-1,-1):
    crt = crt+int(s[i])*10**(len(s)-i-1)
    crt %= 2019
    mods.append(crt)
ans = 0
ans += mods.count(0)
modst = set(mods)
ans += len(mods) - len(modst)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
s = input()
N = len(s)
#print(N)

i = 0
j = 4

ans=0

while(i < N-3):
    while(j<N+1):
        #print(s[i:j])
        #print(int(s[i:j])%2019)
        if int(s[i:j])%2019 == 0:
            ans=ans+1
        j=j+1
    i=i+1
    j=i+4

print(ans)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
amari = [0] * 2019
follow = 0
for i in range(N):
  Amari_ = (int(S[N-i-1]) * pow(10, i) + follow) % 2019
  ans += amari[Amari_]
  amari[Amari_] += 1
  follow = Amari_
  if Amari_ == 0:
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = list(input())
c = 4
re = 0
while c != len(k):
    for i in range(len(k) - c + 1):
        #print(k[i: i+c])
        if int("".join(map(str, k[i: i+c]))) % 2019 == 0:
            re += 1
    c +=1

print(re)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
cnt=0
if len(s)<=3:
    print(0)
else:
    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:
def main():
    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)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:


temp = input()
ans = 0
for i in range(len(temp)):
    for j in range(len(temp)):
        tmp = temp[i:j + 1]
        if len(tmp) > 0:
            if int(tmp) % 2019 == 0:
                ans = ans + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
S = input()

num_s = int(S)
num_list = list(S)

count = 0

def run(num):
    global count
    for index, value in enumerate(num_list):
        if not index + num >= len(num_list):
            check = ''
            for i in range(index, index + num+1):
                check = check + num_list[i]
                
            if int(check) % 2019 == 0:
                count += 1
        else:
            break

for i in range(4, len(S)+1):
    run(i)

print(count)

Submission status: Time Limit Exceeded

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

amari=[0]*(N+1)
num=0
#print(d)
for i in range(N):
    amari[i+1]=(S%pow(10,i+1))%2019
#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:
S = input()
L = len(S)
U = [int(S[i:])%2019 for i in range(L)]

dic = { 0: True }
ans = 0
for x in U:
  if x in dic: ans += 1
  else: dic[x] = True

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
S = input()
cum = []
for i in range(len(S)-1, -1, -1):
    slice = S[i:len(S)]
    slice_n = int(slice)
    cum.append(slice_n % 2019)
cum = sorted(cum)
prev = cum[0]
ans = 0
cnt = 0
for c in cum:
    if c != prev:
        if prev == 0:
            ans += cnt
        ans += cnt * (cnt-1) // 2
        cnt = 1
    else:
        cnt += 1
    prev = c

if cnt > 1:
    if prev == 0:
        ans += cnt
    ans += cnt * (cnt-1) // 2
    cnt = 1

print(ans)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
ans = 0
s = list(input())
for i in range(len(s)-2):
    for j in range(i+4,len(s)+1):
      d = s[i:j]
      l = ''.join(d)
      if int(l) % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import sys
S = input()
count = 0

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

Submission status: Time Limit Exceeded

Solution code:
ans=0
s=str(input())
target =list(2019*i for i in range(1,100))

def search(s,n):
    ans=0
    for i in range(len(s)):
        for j in range(len(s[i+3:])):
            if s[i:4+j+i]==n:
                ans+=1
    return ans

for i in target:
    if str(i) in s:
        ans+=search(s,str(i))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input().strip()

ans = 0
for r in range(0, len(S)-3):
  l = r+4
  while l <= len(S):
    if int(S[r:l]) % 2019 == 0:
      ans += 1
      l += 4
    else:
      l += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

S = input()
size_S = len(S)

initial = np.arange(0, size_S-3, 1)
last = np.arange(3, size_S, 1)

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

Submission status: Time Limit Exceeded

Solution code:
s=input()

l=len(s)

count=0

sum=0

for i in range(l-2):
    cu=[]
    cu.append(s[i])
    cu.append(s[i+1])
    cu.append(s[i+2])
    sum=int(s[i])+int(s[i+1])+int(s[i+2])
    for j in range(i+3,l):
        cu.append(s[j])
        sum=sum+int(s[j])
        if sum % 3 !=0:
            continue
        else:
            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)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    ret = 0
    for s in range(len(S)):
        for e in range(s + 1, len(S)):
            if int(S[s:e+1]) % 2019 == 0:
                ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

l=len(str(n))

c=0
for i in range(1,l-2):
    for j in range(i+3,l+1):
        #print(i,j)
        d=0
        for k in range(i-1,j):
            d+=int(str(n)[k])
        #print(str(n)[i-1:j])
        #print(d)
        if d%3!=0:
            continue
        if int(str(n)[i-1:j])%673 ==0:
                c+=1
                #print(i,j)
                #print(str(n)[0:j])
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input().strip()
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:
S = int(input())
cnt =0
S_str = str(S)
for i in range(len(S_str)-2):
  #print(i)
  for j in range(i+2,len(S_str)+1):
    if int(S_str[i:j])%2019 == 0:
      cnt += 1
      #print(int(S_str[i:j]))
print(cnt)

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
def check(st):
    num = 0
    for i,s in enumerate(st[::-1]):
        num += int(s)*(10**i)
    return num
count = 0
for i in range(len(s)):
    for j in range(i+3,len(s)):
        num = check(s[i:j+1])
        if num%2019==0:
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(len(S)-3):
    for j in range(i+4,len(S)+1):
        s = S[i:j]
        suji = sum([s[-k]*(10**(k-1)) for k in range(1,len(s)+1)])
        
        
        if suji%2019 == 0:
            ans += 1

print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
line = input()
num = [int(x) for x in list(str(line))]
i = 0
count = 0
while i<len(line)-4:
    j = i + 4
    while j<=len(line):
        x = num[i:j]
        s = ""
        for k in range(len(x)):
            s = s + str(x[k])
        if int(s)%2019 == 0:
            count = count+1
        j = j + 1
    i = i + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0

for i in range(len(s)):
    for j in range(1, 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()

ans=0

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

print(ans)