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 sys
N=sys.stdin.readline().strip()
ans=0

length=len(N)

for r in range(1,length+1):
    for l in range(r):
        n=int(N[l:r])
        if n%2019==0:
            ans+=1
print ans

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = len(S)
A = []
count = 0
for i in range(1,1000):
    a = 2019*i
    if "0" in str(a):
        continue
    else:
        A.append(str(a-(a//1000)*1000))

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
d = [[0] * 2020 for i in range(l + 1)]

for i in range(0, l):
    for j in range(2019):
        if d[i][j] != 0:
            d[i + 1][(j * 10 + int(s[i])) % 2019] = d[i][j]
    d[i + 1][int(s[i])] += 1
    d[i + 1][2019] += d[i][2019] + d[i + 1][0]

print(d[l][2019])

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    s_len = len(s)
    count = 0

    for i in range(0, s_len - 2):
        for j in range(i+4, s_len+1):
            diff = j - i
            if diff < 4 or 6 < diff:
                continue
            eval_str = s[i:j:]
            if int(eval_str) > 200000:
                continue
            if int(eval_str) % 2019 == 0:
                count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

S = input()
N = len(S)

count = 0

for i in range(5,N+1): # 文字数:5~N についてそれぞれ探索
  # print("#",i)
  for j in range(N+1-i): # 
    
    if ( int( S[j:j+i] ) % 2019 == 0 ):
      count += 1
      # print(j+1, j+i, S[j:j+i], len(S[j:j+i]) )

print(count)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

import random

def main():
    s = S()
    # s = ''.join([str(random.randint(1, 9)) for i in range(10 ** 3)])
    ans = 0
    N = len(s)

    for d in range(5, N+1):
        for i in range(N-d+1):
            # print(d)
            # print(i, s[i:i+d])
            if int(s[i:i+d]) % 2019 == 0:
                # print(int(s[i:i+d]))
                ans += 1
        # int(s[i:j]) % 2019 == 0:

    print(ans)

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

    # can = []
    # for i in range(10**3):
    #     if '0' not in str((i + 1) * 2019):
    #         t = str((i + 1) * 2019)
    #         print(i+1, t, sum([int(n) for n in t]))
    #         can.append(t)

    # print(can[0])

    # for i in range(len(can)):
    #     if can[0] in can[i]:
    #         print(can[i])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=0
sij0=0
#sij1=0
l=len(s)
a=list(map(int,list(s)))
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=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)<2019:
            continue
        elif int(ss)%n==0:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
sum = 0
for i in range(1, 1000):
  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:
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):
        R = N[0][i:i+j+4]
        E = int(R[-3:])
        if E%19 == 0:
            m = int(R)%2019
            if m == 0:
                p = p + 1

print(p)

Submission status: Time Limit Exceeded

Solution code:
import heapq
S = input()
cum = [0 for _ in range(len(S))]
dict = {}
length = len(S)
n = 0
for i in range(1,length+1):
    n = n + int(S[-i]) * 10**(i-1)
    cum[i-1] = n % 2019
    dict[cum[i-1]] = 0


for c in cum:
    dict[c] += 1
ans = 0
for k, v in dict.items():
    if k == 0:
        ans += v
    ans += v * (v-1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

S=int(input())
n=int(math.log10(S))+1
cnt=0

for i in range(5,n+1):
  for j in range(n-i+1):
    if (S//(10**(n-i-j))%(10**(i)))%2019==0:
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S=input()
ans = 0
for i in range(len(S)-4):
    K = str(int(S[i:])//2019)
    ans += K.count('000')
    if int(S[i:])%2019==0:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import sys
S = input()
count = 0
lenS = len(S)
for i in range(0,lenS-3):
  for j in range(i+3,lenS):
    if int(S[i:j+1])%2019 == 0:
      count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = list(map(int,sys.stdin.readline().split()))
# a = [sys.stdin.readline() for _ in range(n)]
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
import sys,bisect,math
sys.setrecursionlimit(15000)

s = sys.stdin.readline().rstrip()
cum = [0]*(len(s)+1)#cumulative sum
import collections
d = collections.defaultdict(list)
for i in range(len(s)):
    cum[i+1]=cum[i]+int(s[i])
for i in range(len(s)+1):
    d[cum[i]%3].append(i)
ret = 0
#print(cum,d)
for l in d.values():
    #print(l)
    n = len(l)
    can = [[l[i],l[j]] for i in range(n) for j in range(i,n) if l[j] > l[i]+3]
    #print(can)
    #print([[i,j,int(s[i:j])] for i,j in can if int(s[i:j])>2019 and int(s[i:j])%2019==0])
    #print([1 for i,j in can if int(s[i:j])>2019 and int(s[i:j])%2019==0])
    ret += sum(1 for i,j in can if int(s[i:j])>2019 and math.gcd(int(s[i:j]),2019)==2019)
print(ret)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
MOD = 2019
dlist = dict()
for i in range(5):
    dlist[i] = (10**i) % MOD
if N > 5:
    for i in range(5,N):
        d = i
        l = list()
        while d > 0:
            l.append(d % 2)
            d //= 2
        num_N_ = 1
        for j in range(len(l)):            
            if l[j] == 1:
                val = 2**j
                if val in dlist.keys():
                    num_N_ *= dlist[val] 
                    num_N_ = num_N_ % MOD
                else:
                    temp_ = (dlist[2] * j) % MOD
                    num_N_ *= temp_
                    num_N_ = num_N_ % MOD
                    dlist[val] = temp_
        dlist[i] = num_N_
ret = 0
S_REV = ''
for i in range(N):
    S_REV += S[N - i - 1]
for i in range(N ):
    sums = 0
    for j in range(i ,N):
        sums += (int(S_REV[j]) * dlist[j-i]) 
        sums = sums % MOD
        if sums == 0:
            ret += 1
print(ret)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    for n in range(1,1000):
        if '0' not in str(2019*n): 
            A.append(str(2019*n))
    
    for n in range(1000,1000000,2):
        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:
s = input()
n = len(s)

if n<5: ans = 0
else:
    ans = 0
    for i in range(n):
        for j in range(i+5, n+1):
            num = int(s[i:j])
            if int(num)%2019==0: ans += 1 ; continue

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0
is_end = [False] * (len(S) + 1)
for i in range(len(S)):
    if is_end[i]:
        continue
    is_end[i] = True
    bingo = [i]
    last_j = i
    for j in range(i+4, len(S)+1):
        if (j-last_j) < 4 or is_end[j]:
            continue
        if int(S[i:j]) % 2019 == 0:
            is_end[j] = True
            last_j = j
            bingo.append(j)
    l = len(bingo)
    if l >= 2:
        cnt += int(l*(l-1)/2)
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def countSubStr(str, l, k): 
	count = 0
	for i in range(l): 
		n = 0
		for j in range(i, l, 1): 
			n = n * 10 + (ord(str[j]) - ord('0')) 
			if (n % k == 0): 
				count += 1
	return count 

str = input()
l = len(str) 
k = 2019
print(countSubStr(str, l, k))

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
number = str(input())
match = 0
for start in range(1, len(number)):
  for end in range(start+3, len(number)+1):
    if int(number[start-1:end]) % 2019==0:
      match += 1
print(match)

Submission status: Time Limit Exceeded

Solution code:
s = input()

dic = {}
for i in range(6, 50):
    if not 2019 * i in dic:
        dic[str(2019 * i)] = 0

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
#n = 1817181712114


from functools import reduce
n = int(input())
#文字列にバラす
l = [int(x) for x in list(str(n))]
N = len(l)
con = 0 

for s, e in itertools.combinations(range(N+1), 2):
    #print(l[s:e])
    new_n = int(reduce(lambda x, y: x + y, [str(x) for x in l[s:e]]))
    if new_n % 2019 == 0:
        con +=1

        
            
            #print("Yes")    
print(con)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(cnt)

Submission status: Time Limit Exceeded

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

print(count)

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len( S )
l = [ str( 2019 * i )  for i in range( 1, 100000 ) if i % 10 != 0 ]
cnt = 0
for i in l:
    if len( i ) > N:
        break
    if i in S:
        Sd = S
        add = Sd.find( i )
        while add != - 1:
            cnt += 1
            Sd = Sd[ add + 1: ]
            add = Sd.find( i )
print( cnt )

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

S = input()

if len(S) < 5:
    print(0)
    exit()

check_str = deque()
first = 0
end = 4
check_str.append([first, end])

ans = deque()
while len(check_str) > 0:
    now_first, now_end = check_str.popleft()
    now_str = S[now_first:now_end+1]
    if int(now_str) % 2019 == 0 and [now_first, now_end] not in ans:
        ans.append([now_first, now_end])
    
    if len(now_str) > 5:
        check_str.append([now_first+1, now_end])

    if now_end < len(S)-1:
        check_str.append([now_first, now_end+1])

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=['0']*30000
count=0
j=12114
for i in range(0,30000):
    while True:
        if str(j).count('0')==0:
            N[i]=str(j)
            j+=2019
            break
        else:
            j+=2019
for i in range(0,30000):
    count+=S.count(N[i])
    if S.count(N[i])>0:
        if N[i][0]==N[i][-1]:
            count+=S.count(N[i][1:])-S.count(N[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
S = str(input())

len_str = len(S)
dp_list = [-1 for _ in range(len_str)]

ans = 0
for i in range(len_str):
    for j in range(i + 4, len_str + 1):
        temp_ans = int(S[i:j]) if i == 0 or j == i + 4 else (dp_list[j - 2] * 10 + int(S[j - 1]))
        temp_ans %= 2019
        dp_list[j - 1] = temp_ans
        if temp_ans == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

S = str(input())
N = len(S)


counter = 0
for i in range(N-4):
    for j in  range(i+4,N):
        s = int(S[i:j+1])
        m = s % 2019
        if m == 0:
            counter += 1



print(counter)

Submission status: Time Limit Exceeded

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

#jが来てあまりがiとなった時に元々のあまりはいくつか
dic = [[[] for j in range(10)] for i in range(2019)]

for i in range(2019):
    for j in range(1,9):
        tmp = (i*10+j)%mod
        dic[tmp][j].append(i)

# i桁までみたとき、あまりがjの物の個数
dp_sub = [[0 for j in range(2019)]for i in range(n+1)]
dp_sub[1][int(s[0])] = 1

# i桁までみたとき、あまりがjの物の個数
dp = [[0 for j in range(2019)]for i in range(n+1)]
dp[1][int(s[0])] = 1
for i in range(1,n):
    dp_sub[i+1][int(s[i])] = 1
    for j in range(2019):
        dp[i+1][j] = dp[i][j]
        for ind in dic[j][int(s[i])]:
            dp_sub[i+1][j] += dp_sub[i][ind]
            dp[i+1][j] += dp_sub[i][ind]
print(dp[n][0])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

S = list(input().strip())
length = len(S)
op = np.asarray(S)
x = -1
count = 0
for i in op:
    y = -1
    x += 1
    group = ""
    for j in op:
        y += 1
        if x > y:
            continue
        group += j
        if int(group) % 2019 == 0:
            count += 1
print(count)

def checkValue():
    count = 0
    for i in range(length):
        group = ""
        for j in range(i, length):
            group += op[j]
            if int(group) % 2019 == 0:
                count += 1
    print(count)
#checkValue()

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
# print(len(S))
lS = len(S)

if int(S) < 2019:
     ans = 0
else:
     for i in range(lS-3):
          for j in range(lS-3-i):
               obj = S[j:j+4+i]
               # if digitSum(obj)%3 == 0:
               if int(obj)%2019==0:
                    ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
res = 0
for i in range(N-3):
	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()
Sn = [0] * 2019
Sn[0] = 1
ans = 0
for i in range(len(S)-1, -1, -1):
  S_i = int(S[i:])
  p = S_i%2019
  ans += Sn[p]
  Sn[p] += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    s = input()

    ans_list = []
    """
    for i in range(len(s)):
        jump = 4
        start = 0
        for j in range(0, len(s)):

            start = start
            end = start + j

            if start >= end:
                continue

            print(start, end)
            int_s = int(s[start:end])

            if int_s % 2019 == 0:
                ans_list.append((start, end))

            jump += 1
    """

    count = 0
    for i in range(0, 5):
        for j in range(4, len(s)):
            if i // j >= 2:
                continue

            for k in range(0, len(s), j):
                start = i + k
                end = start + j

                if end >= len(s):
                    continue

                # print(start, end)
                int_s = int(s[start:end])

                if int_s % 2019 == 0:
                    count += 1
    print(count)



if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0

dp = [[0]*2019 for i in range(len(S)+1)]

for i in range(len(S)):
    n = S[i]
    # print(n)
    res = 0
    m = int(n)
    dp[i + 1][m] += 1
    for j in range(2019):
        dp[i + 1][(j * 10 + m) % 2019] += dp[i][j]
    count += dp[i + 1][0]
# print(dp[:][0])

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
cnt = [0]*N
ans = 0
for i in range(N):
    cnt = [0]*N
    for k in range(i,N):
        cnt[k] = (cnt[k-1]*10 + int(S[k]))%2019
        if cnt[k] == 0:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
Count = 0
if len(S)<=4:
    print(0)
else:
    for w in range(5,100):
        for i in range(0,len(S)+1-w):
            if int("".join(S[i:i+w]))%2019==0:
                Count+=1
    print(Count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
limit = len(S)
count = 0

def check(n):
  global count
  if (n % 2019 == 0):
    count += 1

for i in range(0,limit - 3):
  for j in range(i+3,limit):
    check(int(S[i:j+1]))

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

S = input()
N = len(S)


def order(N):
    ans = []
    for i in range(N-1):
        for j in range(i+1,N):
            ans.append([i,j])
    return ans

def order2(N):
    s = []
    for i in range(N):
        s.append(i)
    return list(itertools.combinations(s,2))

c = 0
for o in order2(N):
    if int(S[o[0]:(o[1]+1)])%2019 == 0:
        c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
import math
S=input()
Z=len(S)
V=[0 for i in range(2019)]
S=S[::-1]
ans=0
for i in range(Z):
    V[int(S[0:i+1][::-1])%2019]+=1
for i in range(2019):
    ans+=V[i]*(V[i]-1)/2
ans+=V[0]
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
# if the remainders (mod 2019) are equal, the difference will be divisible
# x = Q*2019+5 y = R*2019+5 then x-y=(Q-R)*2019
# unless Q-R<=0
# where the substring itself is (Q-R)*2019/10**(something)
# 2019 = 3*673 in prime factorization
# so multiplying by 10 doesn't affect whether a number is divisible by it
from collections import Counter
s = input()
partial = 0
remainders = list()
for i in range(len(s)-1, -1, -1):
  partial = (partial+int(s[i])*10**(len(s)-1-i))%2019
  remainders.append(partial)
histo = Counter(remainders)
non_single_count = int(sum(count*(count-1)/2 for value, count in histo.items() if value!=0))
single_count = int(sum(count for value, count in histo.items() if value==0))
print(non_single_count+single_count)

Submission status: Time Limit Exceeded

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

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:
s = input()
n = len(s)
ans=0
ss=list(map(int, s))
sss=[n%3 for n in ss]

for i in range(0,n-3):
    for j in range(i+4,n+1):
        s3=sum(list(map(int, sss[i:j])))
        if ((s3 % 3) == 0):
            kazu = int(s[i:j])
#            print (s3, kazu)
            if ((kazu % 2019) == 0): ans = ans+1

print (ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
lS = len(S)
ans = 0
li_st = []
li_go = []
#li_x = []


for j in range(lS-3):
    s = S[:lS-j]
    #print(s)
    
    ls = len(s)
    ss = s[-4:]
    #print(ss)
    
    for i in range(ls-3):
        if int(ss) % 2019 != 0:
            if ls+1 > 5+i:
                ss = s[-5-i:]
                #print(ss)
        else:
            li_st.append(lS-4-i-j+1)
            li_go.append(lS-1-j+1)
            break

for v_s in li_st:
    x = 1
    while True:
        if v_s-1 in li_go:
            v_s = li_st[li_go.index(v_s-1)]
            x += 1
        else:
            break
    ans += x

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if n <= 4:
    print(0)
else:
    l = 0
    r = 4
    rem_div_3 = int(S[l:r+1]) % 3
    cnt = 0

    while True:
        if rem_div_3 == 0:
            num = int(S[l:r+1])
            if num % 673 == 0:
                cnt += 1
        if r == n - 1:
            if r - l == 4: 
                break
            else:
                l += 1
                r = l + 4
                rem_div_3 = int(S[l:r+1]) % 3
        else:
            rem_div_3 = (rem_div_3 + int(S[r+1])) % 3
            r += 1
    print(cnt)

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 = sum(floor1(s,i[0],i[1]) % 2019 == 0 for i in combinations(range(len(S)),2))
print(ress)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(20000*20000)

S = str(input())
ans = set()
check = set()

def dfs(i, j):
    if (i, j) in check:
        return
    else:
        check.add((i, j))
    if int(S[i:j+1])%2019 == 0:
        ans.add((i, j))
    if j == len(S)-1:
        return

    dfs(i+1, j+1)
    dfs(i, j+1)

if len(S) < 4:
    print(0)

else:
    dfs(0, 3)
    print(len(ans))

Submission status: Time Limit Exceeded

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

    cnt = 0
    for i in range(0, len(s)):
        nr = int(s[0:i]) if i else -1
        nl = int(s[i:])
        # print(nr, nl)
        if nr % 2019 == 0:
            # print('&')
            cnt = cnt + 1
        if nl % 2019 == 0:
            # print('s')
            cnt = cnt + 1

        if len(str(nr)) > 4:
            for j in range(i-4, 0, -1):
                # print('  ', s[j:i])
                nt = int(s[j:i])
                if nt % 2019 == 0:
                    cnt = cnt + 1

    print(cnt)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
n = len(S)
def c(n):
    a = n
    co = 0
    while a%2019 == 0:
        co += 1
        a /= 2019
    return co
count = 0
for i in range(0,n-3):
    s = 1
    for j in range(i+3,n):
        s *= int(S[i:j+1])
    count += c(s)
print(count)

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 = ''

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

        if len(temp) >= 4 :
            temp = int(temp)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_l = len(s)
r = 0
n = 0
a = 0
while True:
    a += 2019
    if int(s) < a:
        break
    a_l = len(str(a))
    a_s = str(a)
    for i in range(1,s_l + 1):
        if i + a_l - 1 > s_l:
            break
        r += s.count(a_s,i - 1, i + a_l - 1)
print(r)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import itertools

S = input()

count = 0

n = len(S)
for left in range(n+1):
    right = left+1

    while right <= n:
        s_num = int(S[left:right])
        if s_num%2019 == 0:
            count+=1
        right += 1


print(count)

Submission status: Time Limit Exceeded

Solution code:
s = list(map(int, list(input())))
s_num = 0
ans = 0
 
i_list = range(len(s)-4)
 
for i in i_list:
  s_num = s[i]*1000 + s[i+1]*100 + s[i+2]*10 + s[i+3]
  for j in range(4,len(s)-i):
    s_num = s_num*10 + s[i+j]
    if s_num%2019 == 0:
      ans += 1
 
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
si=[int(ii) for ii in list(s)]
#print(si)
ls=len(si)
r=0
if ls<=3:
  print(r)
  exit()
import numpy as np
r=[]
sumij=[[False]*(ls) for ii in range(ls-3)]

def find0000(s):
	ls=len(s)
	if ls<4:
		return(0)
	for ii in range(ls-3):
		for jj in np.arange(ii+3,ls+1):
    			if s[ii:jj]=="0000":
    				for kk in np.arange(jj,ls+1):
    					if s[kk]!="0":
    					    return(find0000(s[0:ii])+find0000(s[kk:ls]))
	n=0
	for ii in range(ls-3):
    		for jj in np.arange(ii+4,ls+1):
    			if sum(si[ii:jj])%3==0:
    			    if s[ii:jj] in r:
    			        n+=1
    			    else:
    			        ints=int(s[ii:jj])
    			        if ints%673==0:
        			        n+=1
        			        r.append(s[ii:jj])

	return(n)

print(find0000(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()

N = len(S)

answer = 0

for start in range(N-4):
    for end in range(start+4,N+1):
        if int(S[start:end]) % 2019 == 0:
            answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = tuple(input())
    m = 2019
    div_list = [0]*m
    num = 0
    for i, l in enumerate(reversed(S)):
        num += 10**i*int(l)
        div_list[num%m] += 1

    div_list[0] += 1
    ans = 0
    for item in div_list:
        ans += int(item*(item-1)/2)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
a = input()
ans = 0
n = len(a)
for Len in range(1,n + 1): 
        for i in range(n - Len + 1):  
            j = i + Len - 1
            temp = ""
            for k in range(i,j + 1): 
                temp += a[k]
            if(len(temp) >= 4 and int(temp) % 2019 == 0):
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
shou = int(S)//2019
ans = 0
for i in range(shou+1):
  ans += S.count(str(2019*i)) 
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:

S = input()
l = [i*2019 for i in range(1,200000) if i*2019 <= int(S)]
m = [str(i) for i in l if str(i).find('0') == -1]
c = 0
st = str(S)
mls = len(S)

sl = [S[mls-i:mls] for i in range(5,mls+1)]

for i in m:
    for j in sl:
        if j.startswith(i):
            c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

S = input()
lis_2019 = [str(2019 * i) for i in range(1, 99)]
cnt = 0
S_len = len(S)
cnt_1 = 0
S_lis = [S]

for i in range(4, S_len):
    while cnt_1 != S_len - i + 1:
        if S[cnt_1:cnt_1+i] in lis_2019:
            cnt += 1
        cnt_1 += 1
    cnt_1 = 0

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
r, ans = 3, 0
for l in range(len(S)):
    while r < len(S):
        if int(S[l:r+1]) % 2019 == 0:
            ans += 1
            break
        r += 1
    r = l + 3
print(ans)

Submission status: Time Limit Exceeded

Solution code:

S = input()
lenS = len(S)
rui = [0] * 2019
rui[0] += 1
for i in range(lenS):
    a = int(S[-i - 1:]) % 2019
    rui[a] += 1

ans = 0
for i in rui:
    if i >= 2:
        ans += (i * (i - 1) // 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s=input()
    #cnt=0
    k=list(s)
    d=[0]*2019
    for i in range(len(k)):
        d[int(s[i:])%2019]+=1
    
    cnt=d[0]
    for i in range(2019):
        cnt+=d[i]*(d[i]-1)//2
            #print(s[i:j+1])
    print(cnt)
    #print(d)
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
r = 0
b = [0]*2019
m = b[:]
for i in range(3,l):
    m2 = b[:]
    for j in range(1,2019):
        j2 = (j*10+int(s[i])) % 2019
        m2[j2] += m[j]
    m2[int(s[i-3:i+1]) % 2019] += 1
    r += m2[0]
    m = m2[:]
print(r)

Submission status: Time Limit Exceeded

Solution code:
s=input()
d_n=0
i=5
for e in range(len(s)):
  for e2 in range(len(s[e:])):
    if len(s)<i+e+e2:
      break
    if int(s[e:e+i+e2])%2019==0:
      d_n+=1
print(d_n)