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:
import math
def naive_cmb(n, r):
    if r < 0 or r > n:
        return 0
    return (math.factorial(n) // math.factorial(r)) // math.factorial(n-r)

S = input()

mod = [0] * (2019+1)

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

ans = mod[0]

for i in range(1, 2020):
    if mod[i] >= 2:
        ans += naive_cmb(mod[i], 2)

print(ans)

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#200426D
S = str(input())
ans = 0
for j in range(200000):
    l = len(S)
    if l < 4:
        break
    else:
        for i in range(l-3):
            #print(int(S[:i+4]))
            if int(S[:i+4])%2019 == 0:
                ans += 1
        S = S[1:]
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):
        a = s[i:j]
        if int(a) % 2019 == 0:
            count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

S=input()
N=len(S)

remainder=[0]*2019
for i in range(1,N+1):
  s=S[-i:]
  s=int(s)
  remainder[s%2019]+=1

ans=remainder[0]
for i in range(2019):
  if remainder[i]<=1:
    continue
  else:
    ans+=comb(remainder[i],2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
l=len(S)
t=0
p=0
mm=[[0] * l for i in range(10)]

for i in range(10):
    for j in range(l):
        mm[i][j]=i*(10**j)%2019




for i in range(l-1,2,-1):

    p=0
    for j in range(i+1):


        p=(p+mm[int(S[i-j])][j])%2019

        if p==0:

            t+=1

print(t)

Submission status: Time Limit Exceeded

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

cum = [0] * N
cum[0] = S_[0]
for i in range(1, N):
    cum[i] = cum[i - 1] + S_[i]

count = 0
for i in range(N - 4):
    for j in range(i + 5, N + 1):
        t = 0 if i == 0 else cum[i - 1]
        if (cum[j - 1] - t) % 3 != 0:
            continue
        if int(S[i:j]) % 2019 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=input()
count=0
if len(n)<=4:
    if int(n)%2019==0:
        count+=1
    
else:
    for i in range(len(n)-4):
        for j in range(i+4,len(n)):
            temp=list(n[i:j+1])
            temp=map(int,temp)
            if sum(temp)%3==0: 
                if int(n[i:j+1])%2019==0:
                    count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:


anslist = []


def solve():

    S = input()

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

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import sys
import os

def file_input():
    f = open('../Beginner_Contest_164/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # A,B,C,D=map(int, input().split())
    S = input()
    val = 0
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if int(S[i:j])%2019==0:
                # print("("+str(i)+","+str(j)+")")
                val+=1

    print(val)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	S = input()
	S = S[:-1]

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

	print(ans)


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 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:
      cnt += 1
    
print(cnt)

Submission status: Time Limit Exceeded

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


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

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

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

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


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

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



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

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

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

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

	return count
			




s=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(start,end)
# print(count)
length=len(s)
for i in range(length):
	start=i
	for j in range(i+1,length):
		end=j
		num=int("".join(s[start:end+1]))
		if num%2019==0:
			count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

j_max = len(S)

count = 0

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

print(count)

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_
  
ans = sum(list( i * (i-1)//2 for i in amari ))
ans += amari[0]

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

s = str(input())
n = len(s)
count = 0

for i in range(1,n+1):
    sen = s[i-1:]
    for j in range(i,n+1):
        if int(sen[:j]) % 2019 == 0:
            count += 1
            sen = sen[j:]
            if sen == '':
                break

print("{}".format(count))

Submission status: Time Limit Exceeded

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

import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

x = 2019
S = input()
l = len(S)

a, b = [],[0]
for i in range(l):
#    a.append(int(S[:i+1]) % x)
#    if S[i] != '0':
    b.append(int(S[i:]) % x)

ans = 0

xx = np.bincount(b)

def a(n):
    return n*(n+1)//2 

for i in range(len(xx)):
    if xx[i] > 1:
        ans += a(xx[i] - 1)

print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
N = int(input())
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

S = input().rstrip()

counter = 0
for l_index in range(len(S) - 4):
    atama = int(S[l_index:l_index+2])
    if atama % 2 != 0:
        continue
    else:
        r_index = 5
        while True:
            saigo = l_index + r_index
            if saigo > len(S):
                break
            kouho = int(S[l_index:saigo])
            if kouho % 2019 == 0:
                counter += 1
            r_index += 1


print(counter)

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = len(S)
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a=input()
b=int(a)

ans=0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    import numpy as np
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    S = input().strip()
    Sn = np.array([int(x) for x in S])
    N = len(S)
    ans = 0
    T = Sn.cumsum()
    if N < 4:
        print(0)
        exit()
    for i in range(N-3):
        # print('i = {}'.format(i))
        NT = len(T)
        for j in range(3, NT):
            # print('  j = {}'.format(j))
            if T[j] % 3 == 0:
                if int(S[i:i+j+1]) % 2019 == 0:
                    # print(S[i:i+j+1])
                    ans += 1

        T = T[1:] - T[0]

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
S = list(map(int,input().rstrip()))
result=0
for i in range(len(S)):
    for j in range(i+1,len(S)+1):
        n = reduce( lambda a,b:10*a+b, S[i:j])
        if n %2019==0:
            result+=1
print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
S=input()
N=len(S)
nums=defaultdict(int)
zero=0
tmp=''
for i in range(N-1,-1,-1):
    tmp=S[i]+tmp
    div=int(tmp)%2019
    if div==0:
        zero+=1
    nums[int(tmp)%2019]+=1
    
ans = zero
for v in nums.values():
    if v<2:
        continue
    ans += v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools

s = input()
c = 0

for i ,j in itertools.product(range(len(s)), range(len(s))):
  if i <= j:
    if int(s[i:j+1]) % 2019 == 0:
      c += 1

print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(map(int, input()))
n = len(s)

ans = 0

for i in range(n):
    for d in range(3,n):
        j = i+d
        if j >= n:
            break
        number = 0
        for k in range(i,j+1):
            number += s[k]*10**(j-k)
        if number % 2019 ==0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=int(input())
sst=str(s)
st=len(str(s))
ans=0
for i in range(st,3,-1): #指定文字数
  for j in range(0,st-i+1):
    if int(sst[j:j+i])%2019==0:
      ans=ans+1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
# s = list(x)

count = 0
# l = []
len = len(s)

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

print(count)

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(200000)

s = list(input())
n = len(s)
t = 2019

cnts = {}


def recur(i, j):
    if i == n-3 and j == n:
        return
    if 0 == int("".join(s[i:j+1])) % t:
        if not (i, j) in cnts:
            cnts[(i, j)] = 0
        cnts[(i, j)] += 1
    if j < n - 1:
        recur(i, j + 1)
    if j - i > 3:
        recur(i + 1, j)
    if j < n - 1 and j - i > 3:
        recur(i + 1, j + 1)


recur(0, 3)
print(len(cnts.keys()))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

cnt=0

for i in range(0, len(s)-2):
    for j in range(i+3, len(s)):
        ns = int(''.join(s[i:j+1]))
        if ns % 2019 == 0:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Sum = 0

for i in range(N+1):
  for j in range(i+5,N+1):
    hoge = S[i:j]
    if int(hoge) % 2019 == 0:
      Sum += 1
      break

print(Sum)

Submission status: Time Limit Exceeded

Solution code:
a = input()
while (int(a) != 0):
    remain = [0for i in range(2019)]
    remain[int(a[0])] = remain[int(a[0])] + 1  ##V0
    n = len(a)
    cnt = 0
    for i in range(1,n):
        copy = remain[:]
        remain = [0for i in range(2019)]
        a_i = int(a[i])
        if (a_i != 0):
            for k in range(2019):
                rem = (k*10 + a_i)%2019
                remain[rem] += copy[k]
            remain[a_i] += 1
        elif (a_i == 0):
            for k in range(2019):
                rem = (k*10 + a_i)%2019
                remain[rem] += copy[k]
        cnt += remain[0]
    print(cnt)
    exit(0)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
MOD = 2019

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()

ans=0

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
Cnt=0
for i in range(0,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 = str(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
s=list(map(int,input()))
cnt=0
for i in range(len(s)-1):
    for j in range(i+1,len(s)):
        S=s[i:j+1]
        n = reduce( lambda a,b:10*a+b,S)
        if n%2019==0:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# ABC164d


def main():
    import sys
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    s = input()

    def prime_factorize(n):  # 素因数分解
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a

    n = len(s)
    c = 0
    # for i in range(4, n + 1):
    #    for j in range(n - i+1):
    #        if int(s[j: j + i]) % 2019 == 0:
    #            c += 1
    import math

    def c_count(n, r):  # 組み合わせ
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    def modinv(a, mod=10**9+7):
        return pow(a, mod - 2, mod)

    # nCr mod m
    # modinvが必要
    # rがn/2に近いと非常に重くなる

    def combination(n, r, mod=10**9+7):
        r = min(r, n-r)
        res = 1
        for i in range(r):
            res = res * (n - i) * modinv(i+1, mod) % mod
        return res

    counter = [0] * 2019
    #counter2 = [0] * 2019
    for i in range(n):
        num = int(s[n - i - 1:])
        # print(num)
        counter[num % 2019] += 1
        #counter2[num % 673] += 1
    counter[0] += 1
    #counter2[0] += 1

    # print(counter)

    for i in range(len(counter)):
        num = counter[i]
        if num >= 2:
            c += combination(num, 2)

    print(c)

    #c2 = 0
    # for i in range(len(counter2)):
    #    num = counter2[i]
    #    if num >= 2:
    #        c2 += c_count(num, 2)

    #print(c, c2)

    # print(prime_factorize(2019))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
for i in range(len(s)-3):
    while True:
        if s[i]  == '0':
            i += 1
        else:
            break
    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:
from collections import defaultdict
def solve(a):
    n=len(a)
    k=2019
    numMultiples = 0
    #seenRemainders = [[] for i in range(n)]
    seenRemainders = defaultdict(list)
    for i in range(0,n):
        remainder = 0
        prefixesFound = 0
        for j in range(i,n):
            remainder = (10 * remainder + int(a[j])) % k
            if remainder in seenRemainders[j]:
                break
            seenRemainders[j].append(remainder)
            #add remainder to seenRemainders[j]
            if remainder == 0:
                prefixesFound+=1
        numMultiples += prefixesFound * (prefixesFound + 1) / 2
    return numMultiples
s=input()
print(int(solve(s)))

Submission status: Time Limit Exceeded

Solution code:
tmp = input().split()
N = list(tmp)
p = 0
L = len(N[0])
for i in range(L-3):
    for j in range(L - i - 3):
        m = int(N[0][i:i+j+4])%2019
        if m == 0:
            p = p + 1

print(p)

Submission status: Time Limit Exceeded

Solution code:
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

S = int(input())
count = 0
l = [0]*2019
l[0] = 1

for i in range(1,len(str(S))+1):
   l[(S%10**i)%2019] += 1

for j in range(2019):
    if l[j] >= 2:
        count += comb(l[j],2)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=input()
count=0
for i in range(4,len(N)+1):
    for j in range(0,len(N)-4):
        if j+i>len(N):
            continue
        temp=int(N[j:j+i])

        if temp%2019==0:
            count+=1

print(count)

Submission status: Time Limit Exceeded

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

if l < 4:
    print(0)
    exit()

mody = 2019
cnt = 0
for i in range(l-3):
    x = int(n[i:i+4])
    x %= mody
    if x == 0:
        cnt += 1
    for j in range(i + 4, l):
        x = 10 * x + int(n[j])
        x %= mody
        if x == 0:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!


d = 2019

def solve(s):
    dp = [0] * (len(s)+1)
    dp[len(s)] = 0
    for i in range(len(s)-1,-1,-1):
        dp[i] = int(s[i:]) % d
    memo = dict()
    count = 0
    for i,v in enumerate(dp):
        if memo.get(v,False):
            count+=1
            memo[v] = memo[v]+1
        else:
            memo[v] = 1
    return count

s = input()
print(solve(s))

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, 200000):
            if len(S) < e: break
            if int(S[s:e]) % 2019 == 0:
                ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

while key < len(s):
    new_key = 0
    for i in range(key+4, len(s)+1):
        val = int(s[key:i])
        if val % 2019 == 0:
            ans += 1
            new_key = i-1
    if new_key == 0:
        key += 1
    else:
        key = new_key
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
ll = []
for i in range(1, 200001//2019+2):
    ll.append(str(2019*i))

cnt = 0
for l in ll:
    if s.count(l) > 0:
        for i in range(0, len(s) - 3):
            for j in range(4, len(s) + 1):
                if s[i:j] == l:
                    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
lst = []
for i in range(len(s)):
  n = int(s[i::])
  lst.append(n%2019)
lst.append(0)
lst.sort()
counter = 1
stock = lst[0]
ans = 0
for i in range(1, len(lst)):
  if stock == lst[i]:
    counter += 1
  else:
    ans += counter*(counter - 1)//2
    counter = 1
    stock = lst[i]
if counter >= 2:
  ans += counter*(counter - 1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import queue
import copy
import math
from collections import deque
import bisect

# そのまま入力文字列の入力
s = input()

# 2019 = 3, 673

ans = 0

for i in range(0, len(s) - 1):
    for j in range(i + 4, len(s) + 1):
        num = int(s[i:j])
        d, m = divmod(num, 2019)
        if m == 0:
            i = j - 1
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = len(s)

from itertools import combinations

ans = [int(s[x[0]:(x[1]+1)])%2019==0 for x in combinations(range(n), 2)]

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
count = 0
int_s = int(S)

for i in range(2019, int_s, 2019):
  count += S.count(str(i))

print(count)

Submission status: Time Limit Exceeded

Solution code:
s_str = input()

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = []
for left in range(len(S)):
    for right in range(left + 5, len(S) + 1):
        temp = int(S[left:right])
        if temp % 2019 == 0:
            ans.append([left, right])

print(len(ans))