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:
initialString = input()
magicNum = 2019

rangeLimit = len(initialString)

resultCount = 0

for pivot in range(4, rangeLimit + 1):
    for index in range(0, rangeLimit + 1 - pivot):
        if(int(initialString[index:pivot+index])%magicNum == 0):
            resultCount+=1
print(resultCount)

Submission status: Time Limit Exceeded

Solution code:
s = input()
si = list(s)
count = len(s)
min = 3
ans =0
for i in range(count-min-1):
    for j in range(i+min, count):
        number= int(''.join(si[i:j+1]))
        if number %2019 == 0:
                ans +=1
print(ans)

Submission status: Time Limit Exceeded

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

remainder=[0]*2019
S=list(map(int,list(S)))
S=S[::-1]
for i in range(N):
  S[i]=S[i]*(10**i)

val=0
for i in range(N):
  val+=S[i]
  remainder[val%2019]+=1

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = input() #1行目のNを取得する
  l = len(n)
  count = 0
  for i in range(l-3):
    for j in range(i+4,l+1):
        if int(n[i:j]) % 2019 == 0:
          count = count + 1
  print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
S = input()
N = len(S)

def co(s, n):
    return [s[i:i+n] for i in range(len(s)-n+1)]

ans = 0
for i in range(4, N+1):
    mem = Counter(co(S, i))
    for key in mem:
        if int(key) % 2019 == 0:
            ans += mem[key]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

# 1<=S<=21

def find2019(s):
    #print(s)
    #for e in range(4, len(s)+1):
    for e in range(5, len(s)+1):
        res = int(s[0:e]) % 2019
        if res == 0:
            #print(s)
            #print(s[0:e])
            return True
    return False

count = 0
#for i in range(0, len(S)+1):
for i in range(0, len(S)-4):
    if find2019(S[i:]):
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
#dp?
ans=0
for l in range(N-4):
    r=l+4
    on=False
    while r<N:
        X=int(S[l:r+1])
        if int(X)%(2019)==0:
            ans+=1
            if not on:
                add=r-l+1
                on=True
        if on:
            r+=add
        else:
            r+=1
print(ans)

Submission status: Time Limit Exceeded

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

while True:
    temp = int(s[i:j])
    if temp % 2019 == 0:
        #print(i,j)
        counter += 1
    j = j + 1
    if j > num_length:
        j = i + 3
        i = i + 1

    if i == num_length - 4 or num_length == 4 or num_length == 1:
        print(counter)
        exit()

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0
for i in range(len(S) - 3):
    for j in range(i + 3, len(S) + 1):
        s = int(S[i : j])
        if s % 3 != 0:
            pass
        elif s % 673 != 0:
            pass
        else:
            ans += 1
            # print(i, j, S[i : j])
    # print(i, j)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

S = input()

deque_0, deque_1, deque_2 = deque(), deque(), deque()
lis = [0] * len(S)

tmp = 0
for i in range(len(S)):
    tmp = (tmp + int(S[i])) % 3
    lis[i] = tmp
    if tmp == 0:
        deque_0.append(i)
    elif tmp == 1:
        deque_1.append(i)
    elif tmp == 2:
        deque_2.append(i)

tmp = 0
num = 0
for i in range(len(S)):
    if tmp == 0:
        for j in range(len(deque_0)):
            var1 = deque_0[j]+1
            var = int(S[i:var1])
            if var % 2019 == 0:
                num += 1
    elif tmp == 1:
        for j in range(len(deque_1)):
            var1 = deque_1[j]+1
            var = int(S[i:var1])
            if var % 2019 == 0:
                num += 1
    elif tmp == 2:
        for j in range(len(deque_2)):
            var1 = deque_2[j]+1
            var = int(S[i:var1])
            if var % 2019 == 0:
                num += 1
    tmp = lis[i]
    if tmp == 0:
        deque_0.popleft()
    elif tmp == 1:
        deque_1.popleft()
    elif tmp == 2:
        deque_2.popleft()

print(num)

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = int(s)
s_mod = set()
count = 0
j = len(s)
for i in range(1, j+1):
  amari = (n % 10**i) % 2019
  if amari == 0:
    count += 1
  else:
    count += (amari in s_mod)
    s_mod.add(amari)
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
len_s = len(s)
res = 0
res_list = [0] * 2019
res_list[0] = 1
for i in range(len_s):
  use_s = int(s[i:])
  m = use_s % 2019
  res_list[m] += 1
for v in res_list:
  if v <= 1:
    continue
  else:
    res += int((v * (v-1)) / 2)
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- 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,150000):
		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()
digitS = [int(c) for c in S]
digitnum = len(S)
ans = 0

for begindigit in range(0, digitnum - 4):
    for enddigit in range(begindigit + 4, digitnum + 1):
        judgeS = int(S[begindigit:enddigit])
        if int(S[begindigit:enddigit]) % 2019 == 0:
            ans = ans + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:

s = input()

count = 0

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

    for i in range(h, len(s)):
        
        temp = '0'

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

        temp = int(temp)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, stdout  
  
def main(): 
	strInput = stdin.readline().rstrip()
	lenn = len(strInput)
	cnt  = 0
	if len(strInput) < 4:
		for y in strInput:
			if y == '0':
				cnt+=1 
		stdout.write( str(cnt)+'\n')
	else:
		for i in range(0, lenn - 3):
			for k in range(i + 4, lenn + 1):
				#print("combination", strInput[i: k] )
				if int(strInput[i: k]) % 2019 == 0 :	
					cnt+=1
					#print(strInput[i: lenn])
				if strInput[i] == '0':
					cnt+=1	
		for j in range(lenn - 3, lenn):
			if strInput[j] == '0':
				cnt+=1	
		stdout.write( str(cnt)+'\n')
if __name__ == "__main__": 
	main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
s = input()
cnt = 0
tmp = []
tmp2 = []
for i in range(len(s)+1):
    for j in range(len(s)+1):
        # print(s[i:j])
        tmp.append(s[i:j])
# print(tmp)
for i in range(len(tmp)):
    if tmp[i] != '':
        tmp2.append(tmp[i])
# print(tmp2)
for i in range(len(tmp2)):
    if int(tmp2[i]) % 2019 == 0:
        cnt += 1
print(cnt)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_len = len(s)
num = ''
ans = 0
j = 0
for i in range(s_len):
  while j < s_len:
    num += s[j]
    if int(num) % 2019 == 0:
      ans += 1
    j += 1
  j = i + 3
  if j > s_len:
    break
  num = s[i+1] + s[i+2]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
number = [ str(x*2019) for x in range(1000)]
count=0
v = []
for i in range(4, len(S)):
    for k in range(i):
        v =[]
        for l in range(0, len(S)//i):
            if len(S[l*i+k: l*i+k+i])==i:
                v.append(S[l*i+k: l*i+k+i])
        for m in v:
            if m in number:
                count+=1

print(count)

Submission status: Time Limit Exceeded

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

keka = 0
cnt = 0

for i in range(len(S) -4):
    for j in range(len(S) -4 -i):
        str_list = S[i:(len(S) - j)]
        keka = ''.join(str_list)
       
        if int(keka) % 2019 == 0:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
s = len(S)
cnt = 0
A = [int(S)%2019]
for i in range(s-1):
    a = int(S[i])*10**(s-i-1)%2019
    A.append((A[-1]-a)%2019)
    y = A.count(A[-1])
    if y >= 2:
      cnt += y-1
cnt += A.count(0)
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 21:27:49 2020

@author: arute
"""

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def toint(data):
    out = ""
    for d in data:
        out += str(d)
    return int(out)
############################################

# read data for n sequences.
N = str(input())

# 1817181712114
data = []
for i in range(len(N)):
    data.append(str(N)[i])

count = 0
for i in range(len(data)-3):
    for j in range(len(data)-3):
        if not i+j+3>=len(data):
            d = data[i : i+j+4]
            o = toint(d)
            if o%2019==0:
                count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = str(input())
tem = int(200000/2019 +1)
possible_nums = [ i*2019 for i in range(tem+1)]

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

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

        if num in possible_nums: n += 1

print(n)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

def main():
# 整数の入力
    
    s = input()
    length = len(s)
    l = []
    for i in range(length):
        if length - i >= 4:

            for j in range(length - i):
                if j + 1 >= 4:
                    slice = s[i:i+j+1]
                     
                    if int(slice) % 2019 == 0:
                        l.append(1)

    # 出力
    print(len(l))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter

S = input()

l = []
c = 0
x = 0
#for x in range(10**(len(S)-4)):
#    s = str(2019*x)
#    if s == 0 or "0" in s:
#        continue
#
#    print (s)
#    if s in S:
#        cc = Counter()
#        print (2019*i,S.count(str(2019*i)))
#        c += S.count(s)
#
for i in range(0,len(S)-3):
    for j in range(i+4,len(S)+1):
        s = S[i:j]
        if int(s)%2019 == 0:
            c += 1
            break
#
#print (l)
print (c)

Submission status: Time Limit Exceeded

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

print(a)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0

for i in range(len(S) - 3):
    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:
from collections import Counter

S = input()

S_i = {}
for i in range(len(S)):
    k = int(S[i:])%2019
    if not(k in S_i.keys()):
        S_i[k] = 1
    else:
        S_i[k] +=1

ans = 0
for k in S_i.keys():
    if k==0:
        ans += S_i[k]
    elif S_i[k]>1:
        ans += S_i[k]*(S_i[k]-1)/2

print(int(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input('')

n=0
for a in s:
    n=n+1

if n>=4:
    p=0
    for i in range(n-4):
        t=s[i]+s[i+1]+s[i+2]+s[i+3]
        for j in range(n-i-4):
            t=t+s[i+j+4]
            if int(t)%2019==0:
                p=p+1
else:
    p=0
print(p)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

from collections import deque

def main():
  d_origin = deque(input())

  ans = 0
  for i in range(len(d_origin)):
    if len(d_origin) < 3:
      print(ans)
      return
    if i != 0:
      d_origin.popleft()
    while len(d_origin) > 2 and int(d_origin[1])%2 != 0:
      d_origin.popleft()
    d = d_origin.copy()
    for j in range(len(d)):
      if int(''.join(d))%2019 == 0:
        ans = ans + 1
      d.pop()
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
s=str(input())
n=len(s)
k=[0]*(n+1)
for i in range (1,n+1):
    k[i]=int(s[i-1])
t=[0]*(n+1)
t[0]=0  
for i in range(1,n+1):
    t[i]=(10*t[i-1]+k[i])%2019

p=1
q=[0]*200000
for z in range(0,200000):
    q[z]=p%2019
    p=10*q[z]

d=0    
for j in range(n+1):
    for l in range (j):
        f=j-l
        if (t[l]*q[f]-t[j])%2019==0:
            d+=1
            
print(d)

Submission status: Time Limit Exceeded

Solution code:
i = list(input())
pattern = int((len(i) * (len(i) + 1)) / 2)
count = 0
a, b = 0, 0
for j in range(pattern):
    if int("".join(map(str, i[a: b + 1]))) % 2019 == 0 and int("".join(map(str, i[a: b + 1]))) != 0:
        count += 1
    if b == len(i) - 1:
        a += 1
        b = a
    else:
        b += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
    N = input()
    l = len(N)
    listt = range(l)
    pl = list(itertools.combinations(listt, 2))
    k = 0
    for i in pl:
        if i[1]-i[0] > 2:
            fig = N[i[0]:i[1]+1]
            if (int(fig)%2019)==0:
                k = k + 1
    print(k)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = input()
lenN = len(N)
cnt = 0
a = set()
for i in range(0,lenN-3):
  for j in range(i + 3,lenN + 1):
    if j - i > 200000:
      break
    p = int(N[i:j])
    if p in a:
      continue
    if p % 2019 == 0:
      cnt += 1
    else:
      a.add(p)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
    
def print_ans(S):
    """Test Case
    >>> print_ans('1817181712114')
    3
    >>> print_ans('14282668646')
    2
    >>> print_ans('2119')
    0
    """
    target_list = []
    itr = 2019
    for i in range(1, 10001):
        tmp = i * itr
        if tmp > int(S):
            break
        elif '0' in list([s for s in str(tmp)]):
            continue
        else:
            target_list.append(tmp)
    ans = 0
    if len(S) <= 3:
        print(0)
    else:
        for i in range(len(S)-2):
            for j in range(i + 2, len(S)):
                tmp = S[i:j+1]
                if int(tmp) in target_list:
                    ans = ans + 1
        print(ans)
            
            

if __name__ == '__main__':
    S = input().rstrip()
    print_ans(S)

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=2019
numMultiples = 0
seenRemainders = []
for i in range(len(s)):
  l=[]
  seenRemainders.append(l)
for i in range(len(s)):
    remainder = 0
    prefixesFound = 0
    for j in range(i,len(s)):
        remainder = (10 * remainder + int(s[j])) % k
        if remainder not in seenRemainders[j]:  
            seenRemainders[j].append(remainder)
        else:
            break
        if remainder == 0:
            prefixesFound+=1
    numMultiples += prefixesFound * (prefixesFound + 1) // 2
print(numMultiples)

Submission status: Time Limit Exceeded

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

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

        if tmp == 0:
            res += 1

        for j in range(i + 4, n):
            tmp = (tmp * 10 + int(s[j])) % 2019

            if tmp == 0:
                res += 1

    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:
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 += 5
                continue
            r_index += 1


print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
from itertools import product
#print(type(s[1]))
#from functools import reduce
#list = [1,2,3]
#n = reduce( lambda a,b:10*a+b, list)
#print(n)
l = len(s) +1
A = [i for i in range(l)]
B = A
#print(A)
#print(B)
cnt = 0
ans = []
"""for i in range(0,l):
    for j in range(1,l+1):
        if i !=j and len(s[i:j])!=0:"""
for i, j in product(A, B):
    if i !=j and len(s[i:j])!=0:
        
        ans = (s[i:j])
        #print(ans)
        #ans = "".join(map(str, ans))
        #ans = int("".join(map(str, ans)))
        #print(ans)
        if int("".join(map(str, ans)))%2019==0:
            cnt +=1
print(cnt)
            #ans = s
            
            #"".join(map(str, s[i:j]))
            #s = int("".join(map(str, s[i:j])))
            
        
#s = "".join(map(str, s[i:j]))
#s = int("".join(map(str, s[i:j])))
#print(s)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def resolve():
  S_string = input()

  if len(S_string) < 4:
    print("0")
    return True

  count = 0
  d_start = 4
  d_end = len(S_string)

  for i in range(0, d_end - 3):
    counter = Counter([int(S_string[i:i + d]) % 2019 for d in range(d_start, d_end + 1 - i)])
    count += counter[0]

  # for i in range(0, d_end - 3):
  #   for d in range(d_start, d_end + 1 - i ):
  #     # print(int(S_string[i: i + d]))
  #     if (int(S_string[i: i + d])%2019==0):
  #       count += 1

  print(count)

if __name__ == "__main__":
  resolve()

Submission status: Time Limit Exceeded

Solution code:
S=input()
l=len(S)
z=0
for x in range(l):
    for y in range(l-x-3):
        T=S[x:x+y+4]
        t=int(T)
        
        if t%3==0:
            if t%2019==0:
                z+=1
            
print(z)

Submission status: Time Limit Exceeded

Solution code:
S= int(input())
Sl=len(str(S))
Sstr=str(S)
n=0
for i in range (0,Sl-1):
    for j in range(i+5,Sl+1):
        y=Sstr[i:j]
        if int(y)%2019==0:
            n+=1
print(n)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
dict_list = {}
no_dict_list = {}
s = input()
if len(s) < 5:
    print(0)
else:
    count = 0
    for i in range(0, len(s) + 1):
        j = i + 5
        temp_i = i
        if temp_i in dict_list:
            while(True):
                count += 1
                temp_i = dict_list[temp_i]
                if temp_i not in dict_list:
                    break
        elif temp_i in no_dict_list:
            continue
        else:
            while(True):
                if len(s) < j:
                    no_dict_list[temp_i] = 1
                    break
                if int(s[temp_i:j]) % 2019 == 0:
                    dict_list[temp_i] = j
                    temp_i = j
                    count += 1
                    j += 5
                else:
                    j += 1
    print(count)

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
si = int(s)
a = 2019
start=0
l=2
findings = []
while(start+l<=len(s)):
    while (start + l <= len(s)):
        if(int(s[start:start+l])%2019==0):
            findings.append([start+1, start+len(s[start:start+l])])
        l+=1
    l=2
    start+=1
print(len(findings))

Submission status: Time Limit Exceeded

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

for i in range(4, len(s) + 1):
    l = 0
    r = l + i
    while r <= len(s):
        if int(''.join(s[l:r])) % 2019 == 0:
            ans += 1
            l = r - 1
            r = l + i
        else:
            l += 1
            r += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = len(s)

k = 0

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = list(S)
count = 0
for i in range(len(s)):
    for j in range(4,len(s)):
        s2 = int(''.join(s[i:i+j]))
        if s2%2019 == 0:
            count += 1
        if i + j + 1 > len(s):
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
s=ss()
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:
from sys import stdin

if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    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 _%2019==0:
                    cnt += 1
                    memo.add(_)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)