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:
#ABC164_D
s = input()

ans = 0
for i in range(len(s)):
    for j in range(len(s)):
        if i+3 <= j:
            if int(s[i:j+1]) % 2019 == 0:
                ans += 1
        else:
            continue
        
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
K=len(str(S))
A=[[0 for v in range(K)] for j in range(2019)]
A[int(S[0])][0]+=1
for i in range(1,K):
 c=int(S[i])
 A[c][i]+=1
 for k in range(2019):
  d=(k*10+c)%2019
  A[d][i]+=A[k][i-1]
print(sum(A[0]))

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
def floor1(x,a,b):
  return x//(10**a) - x//(10**(b+1)) * (10**(b+1-a)) 
S = input()
s = int(S)
res = 0
ress = [1 for i in combinations(range(len(S)),2) if floor1(s,i[0],i[1]) % 2019 ==0]
print(len(ress))

Submission status: Time Limit Exceeded

Solution code:
S = input()
S = S[::-1]
L = [0]
i = 0
for x in S:
    tmp = L[-1] + 10 ** i * int(x) % 2019
 #   print(tmp % 2019)
    L.append(tmp % 2019)
    i += 1
L = sorted(L[1::])
def counter(array):
    from collections import Counter
    return list(Counter(array).most_common())
c = counter(L)
from math import factorial
def comb(n,r):
    if n == 1: return 0
    return  n * (n - 1) // 2
ans = 0
for x in c:
    if x[0] == 0: ans += x[1]
    ans += comb(x[1],2)
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
#D Multiple of 2019

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

for i in range(n-4):
    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

while len(S)>0:
    for i in range(len(S)-3):
        s = int(S[len(S)-i-4:len(S)+1])
        if s % 2019 == 0:
            N += 1
    S = S[:len(S)-1]

print(N)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
counter = 0
num_length = int(len(s))


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

Submission status: Time Limit Exceeded

Solution code:
numberString= input()
nums=0;
i=j=0
while i<len(numberString):
  j=i+3
  while j < len(numberString):
    if int(numberString[i:j+1])%2019==0:
      nums+=1
    j+=1
  i+=1
 
print(nums)

Submission status: Time Limit Exceeded

Solution code:
S=input()

N=len(S)
a=len(S)
p=0


for i in range(N):
  a=5
  while a<N+1-i:
    if int(S[i:i+a])%2019==0:
      p+=1
      a+=1
      
    else:
      a+=1
print(p)

Submission status: Time Limit Exceeded

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


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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
ln = len(s)+1

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

counter = 0
for right in range(1, len(s)+1):
  for left in range(0, right):
    if int(s[left : right]) % 2019 == 0:
      counter += 1
print(counter)

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

Submission status: Time Limit Exceeded

Solution code:
a = input()
if len(a) < 4:
    print(0)
else:

    count = 0
    for i in range(len(a)-3):
        for ii in range(i+4, len(a)+1):
            ll = a[i:ii]
            l = int(ll)
            if l >= 2019 and l % 2019 == 0:
                count += 1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
S = [str(s) for s in S]
if len(S) <=3:
    print("0")
    exit()
counter = 0
i = 0
for r in range(len(S)):
    for j in range(4, len(S)+1):
        # Jがリストの長さより大きくなったらBreak
        if i + j > len(S):
            break
        target = S[r:r+j]
        # print(target)
        test= ''
        for t in target: 
            test += t
            #print(str(test_num))
        # print(str(test))
        if int(test) % 2019 == 0:
            counter+=1
    i +=1
    
    
print(str(counter))

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  import collections
  s = input()
  r = []
  x = 0
  for i in range(len(s)):
    x += int(s[-i-1])*10**i
    x %= 2019
    r.append(x)
  d = collections.Counter(r) 
  ans = 0
  if 0 in d:
    ans += d[0]
  for k,v in d.items():
    if v >= 2:
      ans += v*(v-1)//2
  print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=2019
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    A=list(map(int,list(input())))
    N=len(A)
    d={}
    for i in range(2019):
        d[i]=(i*10)%MOD
    dp=[[0]*2019 for _ in range(N+1)]
    ans=0
    for i,x in enumerate(A):
        for j in range(2019):
            dp[i+1][(d[j]+x)%MOD]+=dp[i][j]
        dp[i+1][x]+=1
        ans+=dp[i+1][0]
    print(ans)

    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
ans=0
for i in range(len(S)):
    for j in range(len(S)):
        if i>=j or j-i<4:
            pass
        else:
            if int(S[i:j+1])%2019==0:
                ans=ans+1
            else:
                pass
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
k = 2019
cnt = 0
seenRem = []
for i in range(n):
    seenRem.append(set())
for i in range(n):
    rem = 0
    f = 0
    for j in range(i, n):
        rem = (10 * rem + int(s[j])) % k
        if rem in seenRem[j]:
            break
        seenRem[j].add(rem)
        if rem == 0:
            f += 1
    cnt += (f * ( f + 1) // 2)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = len(S)
A = [0 for _ in range(n+1)]
for i in range(n):
    A[i + 1] = A[i] + int(S[i])

c = 0
for i in range(n-1):
    for j in range(i+1, n+1):
        if (A[j] - A[i]) % 3 == 0:
            if int(S[i:j]) % 673 == 0:
                c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=0
sij0=0
#sij1=0
l=len(s)
a=[0]*l
for i in range(l):
  a[i]=int(s[i])
for i in range(l-3):
  sij0=a[i]*1000+a[i+1]*100+a[i+2]*10+a[i+3]
  #print(sij0)
  sij0=sij0 % 2019
  if sij0 == 0:
    k=k+1
  for j in range(i+4,l):
    #sij1=int(s[j])
    sij0*=10
    sij0+=a[j]
    sij0 = sij0 % 2019
    if sij0 == 0:
      k=k+1
print(k)

Submission status: Time Limit Exceeded

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

remainder=[0]*2019
val=0
ans=0
for i in range(1,N+1):
  val+=S[-i]*(10**(i-1))
  n=val%2019
  remainder[n]+=1
  if remainder[n]!=1:
    ans+=remainder[n]-1

ans+=remainder[0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    '''
    code here
    '''

    S = input()

    def chk(num_str):
        temp = int(num_str) % 2019

        if temp == 0:
            return True
        else:
            return False

    ans_set = [ str((i+1) * 2019) for i in range(2*10**5//2019)]

    cnt = 0
    temp = ''
    for s in S:
        temp += s
        for j in range(len(temp)):
            if str(temp[j:]) in ans_set:
                cnt += 1

    print(cnt)

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

def f(c):
    for i in range(N):
        for j in range(i, N):
            if int(s[i:j+1])%2019 == 0:
                c += 1 
    print(c)
f(0)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
S=input()

x=[i*2019 for i in range(1,20000)]


ans=0

for i in x:
    t=len(re.findall("(?={})".format(i),S))
    ans+=t

print(ans)

Submission status: Time Limit Exceeded

Solution code:

S = str(input())

cnt = 0
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)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
s = len(S)
cnt = 0
A = [0]*2019
for i in range(s):
  x = int(S[i:])%2019
  A[x] += 1
for i in range(1,2019):
  if A[i] != 0:
    cnt += A[i]*(A[i]-1)//2
cnt += A[0]*(A[0]+1)//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    cnt = 0
    for i in range(len(s)+1):
        for j in range(i+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:
from collections import deque

S = input()
N = len(S)
sub_s = ""
d = deque()
total = 0
# s_list = []

for l in range(N):  # 200000
    if l % 2 == 0:
        # 左から右に伸ばしていく
        d = deque([S[l]])
        sub_s = "".join(d)
        # s_list.append(sub_s)  # TODO

        if int(sub_s) % 2019 == 0:
            total += 1
        r = l + 1
        while r < N:  # 末尾N-1まで
            d.append(S[r])
            sub_s = "".join(d)
            # s_list.append(sub_s)  # TODO
            if int(sub_s) % 2019 == 0:
                total += 1
                # print((l, r))
                # print(sub_s)
            r += 1
    else:
        # 右を縮めていく
        r = N  # 末尾から
        d.popleft()
        sub_s = "".join(d)
        # s_list.append(sub_s)  # TODO
        if not sub_s:
            break
        if int(sub_s) % 2019 == 0:
            total += 1

        while r > l:
            d.pop()
            sub_s = "".join(d)
            # s_list.append(sub_s)  # TODO

            if not sub_s:
                break
            if int(sub_s) % 2019 == 0:
                total += 1
                # print((l, r))
                # print(sub_s)
            # r -= 1
            r += 1
    # print("--------")

ans = total

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

x = 2019
n = len(s)
cnt = 0

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

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import math

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


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

Submission status: Time Limit Exceeded

Solution code:
#この解放だとTLE....
s = input()
c = 0
l = len(s)
for i in range(l+1):   #開始インデックスを外側のループに
  for j in range(i+4, l+1):     #j:4桁以下の探索やめた➡︎実行時間変わらず 2205ms
    if(int(s[i:j]) >= 2019): 
        if(int(s[i:j]) % 2019 == 0):
            c += 1        
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input()
sum = 0
for i in range(1, 10000):
  number = 2019 * i
  for pos in range(len(s)):
    if s[pos:].startswith(str(number)):
      sum += 1
print(sum)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
str_num = input().strip()
keta = len(str_num)
count = 0
for start in range(keta-3):
    for end in range(start+4, keta+1):
        num = int(str_num[start:end])
        if num % 2019 == 0:
            count += 1
            break

print(count)

Submission status: Time Limit Exceeded

Solution code:
# Sの入力
S = input()

# j番目の初期化
j_s = 4

i_e = len(S)-2
j_e = len(S)+1

# 条件を満たす個数の初期化
cnt = 0

for i in range(1,i_e):
    for j in range(j_s,j_e):
        baisu = int(S[i-1:j]) % 2019
        if baisu == 0:
            cnt += 1
    j_s += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
n2 = str(n)
n_ = len(str(n2))

count = 0
if n_ >200000:
  n_ = 200000
  
for i in range(n_-3):
  for j in range(i+3,n_):
    if n2[i] != "0":
      num = n2[i:j+1]
      if int(num)%2019 ==0:
        count += 1
    else:
      count = count
print(count)

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)
ind0 = [i for i, x in enumerate(sums_from_first_mod) if x == 0]
ind1 = [i for i, x in enumerate(sums_from_first_mod) if x == 1]
ind2 = [i for i, x in enumerate(sums_from_first_mod) if x == 2]
indices = [ind0, ind1, ind2]    
# 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:
n = input()
cnt = 0
for i in range(0, len(n) - 3):
    for j in range(i + 4, len(n) + 1):
        int_n = int(n[i:j])
        if (int_n % 2019 == 0):
            cnt += 1
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#


def main():
    s = input()
    length = len(s)
    count = 0
    # 愚直な方法ではTLE
    # for i in range(length - 3):
    #     for j in range(i + 4, length + 1):
    #         n = int(s[i:j])
    #         if n % 2019 == 0:
    #             count += 1
    for j in range(length, 4, -1):
        i = j - 4
        while i >= 0:
            n = int(s[i:j])
            if n % 2019 == 0:
                count += 1
                i -= 4
            else:
                i -= 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

#mod = 10**9+7

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

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

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

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

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

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

# #優先度付きqueue

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

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


ans=0

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

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

# print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
l = [0]*2019
l[0] = 1

for i in range(1,len(S)+1):
    n =(int(S[len(S)-i:])%2019)
    l[n] += 1
    

for j in range(2019):
    if l[j] >= 2:
        count += l[j]*(l[j]-1)//2

print(count)

Submission status: Time Limit Exceeded

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

abc164_d()

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = list()
for i in range(len(s)):
  for j in range((len(s)+1)):
    if not s[i:j]:
      continue
    else:
      l.append(s[i:j])  
l_s = [int(x) for x in l]
ll = list()
for c in range(len(l_s)):
  if l_s[c]%2019 == 0:
    ll.append(1)
  else:
    ll.append(0)
print(ll.count(1))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def keta(k):
    k//=10**(n-j)
    k%=10**(j-i+1)
    if k%2019==0 and k!=0:
        return 1
    else: return 0
s=int(input())
n=len(str(s))
t=0
for j in range(n):
    j+=1
    for i in range(j):
        i+=1
        k=s
        t+=keta(k)
print(t)

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
count = 0
j = 4
i = 0
while i < L-4:
    if int(S[i:j+1]) % 2019 == 0:
        count += 1
        j += 4
    else:
        j += 1
    if j >= L:
        j = i + 5
        i += 1
        continue
print(count)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
a = ''.join(s)
if int(a) < 2019:
    print(0)
else:
    result = 0
    for j in range(len(s)-3):
        long = len(s) - 3 + j
        i = 0
        while not i+j+4 > len(s):
            b = ''.join(s[i:i+j+4])
            c = int(b) % 2019
            if c == 0:
                result += 1
            i += 1
    print(result)

Submission status: Time Limit Exceeded

Solution code:


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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


def multiple2019(k):
    num = 0
    for i in range(k + 1):
        if int(S[i:k + 1]) % 2019 == 0:
            num += 1
    return num


dp = [0 for i in range(N + 1)]
for i in range(N):
    dp[i + 1] = dp[i] + multiple2019(i)

print(dp[-1])

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
k = 0
l = 3

for i in range(k,len(S)):
    for j in range(l,len(S)):
        if i!=j and i <= j:
            if int(S[i:j+1]) % 2019 == 0:
                ans+=1
                k = i
                l = j
         
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
#1~9をn桁目としたとき、2019で割ったあまりを求める
m = []
s = list(s)
s = list(map(int,s))

#j文字目が1桁目であるとき、条件を満たすiの数を考える


temp = []
d_mod = lambda x:x*10%2019
ret = 0
for i in s:
    temp = list(map(d_mod,temp))
    temp = list(map(lambda x:(x+i)%2019,temp))
    temp.append(i)
    ret+=temp.count(0)
print(ret)

Submission status: Time Limit Exceeded

Solution code:
#! env/bin/local python3
# -*- coding:utf-8 -*-


def main():

    n = int(input().strip('\n'))
    n_size = len(str(n)) if len(str(n)) < 200000 else 200000

    def check(max_n):

        counter = 0

        for window_width in reversed(range(4, max_n)):
            for i in range(max_n - window_width + 1):
                if int(str(n)[i: i + window_width]) % 2019 == 0:
                    counter += 1

        print(counter)

    check(n_size)


# --- run code ---
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import itertools
n=int(input())
if n<10000:
  if n%2019 == 0:
    print(1)
  else:
    print(0)
else:
  x=deque(str(n))
  c=0
  used=[]
  for i in range(len(x)-4):
    if i not in used:
      for j in range(i+4, len(x)):
        if int(''.join(list(itertools.islice(x, i, j+1)))) % 2019 == 0:
          c+=1
          used.append(i)
          i=j
          j+=4
  print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()
S = S[::-1]
L = [0]
i = 0
for x in S:
    tmp = L[-1] + 10 ** i * int(x) % 2019
 #   print(tmp % 2019)
    L.append(tmp % 2019)
    i += 1
L = sorted(L[1::])
def counter(array):
    from collections import Counter
    return list(Counter(array).most_common())
c = counter(L)
from math import factorial
def comb(n,r):
    if n == 1: return 0
    return  n * (n - 1) // 2
ans = 0
for x in c:
    if x[0] == 0: ans += x[1]
    ans += comb(x[1],2)
#print(L,c)
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:

def main():
    S=input()
    N=len(S)
    A=[]
    cnt=0

    for n in range(1,1000000):
        if '0' not in str(2019*n): 
            A.append(str(2019*n))

    for st in A:
        lenst=len(st)
        for i in range(N-lenst+1):
            if S[i:i+lenst]==st:
                cnt+=1
    print(cnt)

main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import Counter
def div10(d):
    return d//10
def rem2019(d):
    return d%2019
def resolve():
    S = [s for s in sr()]
    N = len(S)
    a = ['']
    for i in range(N):
        s = S.pop()
        a.append(int(s+str(a[i])))
    a = a[::-1]
    a[-1] = 0
    ans = 0
    for i in range(N):
        t = list(map(rem2019, a))
        ans += Counter(t)[0]-1
        a = list(map(div10, a))
        g = a.pop()
    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 2019 = 3 * 673 

def main():
     s = int(input())
     ans = 0

     while(s >= 2019):
          tgt = s
          while(tgt >= 2019):
               if check_2019(tgt):
                    ans += 1
                    tgt = tgt // 1000

               else:
                    tgt = tgt // 10

          s = int(str(s)[1:])

     print(ans)

def check_2019(n):
     if n % 2019 == 0:
          return True
     else:
          return False

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import re
import sys

s = sys.stdin.buffer.readline().rstrip().decode()
ans = 0

for i in range(2019, 200001*2019, 2019):
    tmp = str(i)
    if tmp in s:
        index = -1
        while True:
            index = s.find(tmp, index + 1)
            if index == -1:
                break
            ans += 1
    if int(tmp) > int(s):
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#d
N = str(input())
a = []
 
def func(string,p):
    count=0
    for x in range(len(string)-len(p)+1):
        if string[x:x+len(p)]==p:
            count+=1
    return count

def fun(a,b):
    ans=0
    for x in range(len(a)-b+1):
        if int(a[x:x+b])%2019==0:
            ans+=1
    return ans
 
for i in range(1,497):
    a.append(str(2019*i))

if len(N)<4:
    print(0)
else:
    ans=0
    for j in a:
        ans+=func(N,j)
    if len(N)>7:
        for x in range(6,len(N)+1):
            ans+=fun(N,x)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

mod = 2019
mods_count = np.zeros(2019, dtype=np.int64)
indexes = list(range(2019))
indexes_10 = [index * 10 % mod for index in indexes]

mod = 2019
ans = 0
S = input()
for s in S:
    num = int(s)
    new = np.roll(mods_count, num)
    new[num] += 1

    ans += new[0]
    mods_count = np.zeros(2019, dtype=np.int64)
    mods_count[indexes_10] += new[indexes]

print(ans)

Submission status: Time Limit Exceeded

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

skip_num = []

if n < 4:
    print('0')
else:
    cnt = 0
    for j in range(n-3):
        if j in skip_num:
            continue

        i = 0
        skip_add = 0
        while i < n-3-j:
            step = int(s[n-4-i-j:n-j])
            if step % 2019 == 0:
                skip_num.append(j+i+4)
                cnt += 1+skip_add
                skip_add += 1
                i += 3
            i += 1
    print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
length = len(s)
count = 0
for i in range(length - 2):
  if int(s[i]) ==0:
    continue
  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:
a=str(input())
ans=0
for i in range(len(a)-3):
  for j in range(i+3,len(a)+1):
    b=int(a[i:j])
    if b%3!=0:
      continue
    if b%2019==0:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
intlist = []
leng = len(S);
for i in range(leng):
    intlist.append(int(S[i]))

for i in range(leng):
    buf = 0
    for j in range(i, leng):
        buf *= 10
        buf += intlist[j]
        buf %= 2019
        if(buf == 0):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

s = input()
l = len(s)

m = 2019
count = 0

mod_list = [0 for i in range(m)]
num_list = [i for i in range(m)]
ten_list = [(i * 10) % m for i in range(m)]


tmp = mod_list.copy()
count=0
for i in range(l):
    for j in range(m):
        tmp[(j*10+int(s[i]))%m] = mod_list[j]
    tmp[int(s[i]) % m] += 1
    mod_list = tmp.copy()
    count+=mod_list[0]
print(count)