Problem:


Score : 400 points

Problem Statement

Given is a string S consisting of digits from 1 through 9.

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

lenS = len(S)

sweep = 4
flag = 0
ans = 0
mem = 0
step = 1

if lenS < 3:
    print(0)
else:
    while sweep <= len(S):
        step = 1
        for i in range(mem, lenS - sweep + 1, step):
            if int(''.join(S[i:i + sweep])) % 2019 == 0:
                ans += 1
                step = sweep - 1
            if i > (lenS // 2) and step == 1:
                break
        sweep += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
from sys import stdin


def get_result(data):
    S = data[0]
    int_S = int(S)
    mod_all_bit = [0]
    for i in range(len(S)):
        mod_all_bit.append(int_S % (10**(i+1)) % 2019)
    couter = {}
    for key in mod_all_bit:
        couter[key] = 0
    for key in mod_all_bit:
        couter[key] += 1
    ans = 0
    for key, val in couter.items():
        if val >= 2:
            ans += int(val * (val-1) * 0.5)
    return ans


if __name__ == '__main__':
    data = list(map(str, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

for i in range(4,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 = str(input())
dp = [[0 for _ in range(2019)] for _ in range(len(S)+1)]
ans = 0
for i in range(1, len(S)+1):
    x = int(S[i-1])
    dp[i][x] += 1
    for j in range(2019):
        dp[i][(j*10+x)%2019] += dp[i-1][j]
    ans += dp[i][0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

dp = [0 for i in range(2019)]
temp = [0 for i in range(2019)]

ans = 0
for i in S:
  d = int(i)
  for j in range(2019):
    next_j = (10 * j + d) % 2019
    temp[next_j] += dp[j]
  temp[d] += 1
  ans += temp[0]
  ## Add new letter
  for j in range(2019):
    dp[j] = temp[j]
    temp[j] = 0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
su = 0
right = 0
if l<=3:
  print(0)
  exit()
for i in range(4,l+1):
  right = i
  left = 0
  while right<=l:
    if int(s[left:right])%2019==0:
      su += 1
      left = right-1
      right += i-1
    else:
      right += 1
      left += 1
  while left<l-i:
    if int(s[left:])%2019==0:
      su += 1
      break
      left += 1
    else:
      left += 1
print(su)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

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

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
  res += res_list[m] - 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
str1=input("")
count=0;
for i in range(len(str1)-4):
  if str1[i]=="0":
    continue
  for j in range(i+3,len(str1)+1):
    if eval(str1[i:j]) % 2019==0:
      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
    X=S[l:r+1]
    on=False
    while r<N:
        T=int(X)
        if T%(2019)==0:
            ans+=1
            if not on:
                add=r-l+1
                on=True
        if on:
            
            X+=S[r+1:r+add+1]
            r+=add
        else:
            r+=1
            X+=S[min(r,N-1)]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as cmb
s=input()
g=0
for i,j in cmb(range(len(s)+1),r=2):
    if int(str(s[i:j]))%2019==0:
        g+=1
print(g)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sys.setrecursionlimit(10**7)
INF = 10**10

N = 2019
cnt = [0] * N
#print (cnt)

def dec(cnt,s):
    new = [0] * N
    for n in range(N):
        idx = (10 * n + s) % N
        new[idx] += cnt[n]
    return new


S = input()[:-1]
ans = 0
for s in S:
    s = int(s)
    cnt = dec(cnt,s)
    cnt[s] += 1
    ans += cnt[0]
    # if cnt[0] != 0:
    #     print (cnt[0])
print (ans)

Submission status: Time Limit Exceeded

Solution code:
n = input()

count = 0

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

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

S = input()
N = len(S)
if N < 5:
  print(0)
  sys.exit()
l = []
for i in range(N):
  l.append(int(S[i]))
ans = 0
for i in range(N-4):
  t = l[i]
  for j in range(i+1, N):
    t = (t * 10 + l[j]) % 2019
    if t == 0:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

n = len(s)

ans = 0
for i in range(n - 3):
    a = s[i] * 100 + s[i + 1] * 10 + s[i + 2]
    for j in range(i + 3, n):
        a = a * 10 + s[j]
        if a % 2019 == 0:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
if int(s) < 2019:
    print(0)
else:
    ruiseki = [0]*(len(s)+1)
    a = 0
    for i in range(len(s)):
        t = int(s[i])
        ruiseki[i+1] = a+t
        a = ruiseki[i+1]

    count = 0
    for i in range(n-3):
        for j in range(i+4, n+1):
            b = ruiseki[j]-ruiseki[i]
            if b % 3 == 0:
                c = int(s[i:j])
                if c % 2019 == 0:
                    count += 1
                    # print(s[i:j])

    # print(ruiseki)
    # print(n)
    print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

s_len = len(s)
cnt=0
for i in range(0, s_len-3):

    for j in range(0, s_len-3-i):

        if int(s[i:i+j+4]) % 2019 == 0:
            cnt +=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S=input()
L=list(S)
length=len(L)    

total=0
for i in range(0,length-3):
	y=L[i]
	for j in range(i+1,length):
		x=int(str(y)+L[j])
		if x%2019==0:
			total+=1
			y=x
		else:
			y=x
print(total)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
S = str(S)
long = len(S)
count = 0
for i in range(1,long):
  for j in range(i+1,long-1):
    judge = 0
    cut = S[(i-1):(j+2)]
    for k in range(j-i+3):
      judge += int(cut[k])*10**(j-i+2-k)
    if judge%2019 == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    ans = 0
    m = 2019
    div_list = [0]*m
    div_list[0] += 1
    S = list(input())
    N = len(S)

    num = 0
    for i in range(N):
        num += 10**i*int(S.pop())
        div_list[num%m] += 1

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

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

# import numpy as np
from itertools import *
# from collections import *

# S = input().split()
# N = int(input().split())
# K, N = [int(x) for x in input().split()]

N = input()
c = 0
for n in range(len(N)):
    for k in range(n+4, len(N)+1):
        if int(N[n:k]) % 2019 == 0:
            c += 1

print(c)

Submission status: Time Limit Exceeded

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

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

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

print(count)

# for i in range(1, 101):
#     print(i, 2019 * i)

# 26247
# 2624
# 26247


# 1 2019
# 2 4038
# 3 6057
# 4 8076
# 5 10095
# 6 12114
# 7 14133
# 8 16152
# 9 18171
# 10 20190
# 11 22209
# 12 24228
# 13 26247
# 14 28266
# 15 30285
# 16 32304
# 17 34323
# 18 36342
# 19 38361
# 20 40380
# 21 42399
# 22 44418
# 23 46437
# 24 48456
# 25 50475
# 26 52494
# 27 54513
# 28 56532
# 29 58551
# 30 60570
# 31 62589
# 32 64608

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0
leng = len(s)
how = 1
for i in reversed(range(4, leng+1)):
    for j in range(how):
        n = s[j:j+i]
        if int(n) % 2019 == 0:
            cnt += 1
    how += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
S = str(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from math import pow
def get_table():
    table = []
    for i in range(50):
        a = int(pow(10, i))
        table.append(a % 2019)
    return table

table = get_table()
# print(table)

def get_power_2019(idx):
    if (idx < len(table)):
        return table[idx]
    else:
        j = int(idx/2)
        i = idx - j
        return (get_power_2019(i) * get_power_2019(j)) % 2019

s = input()
mod_dict = {}

last_mod = 0
for i in range(len(s)-1, -1, -1):
    current_lowest_digit = int(s[i])
    current_mod = ((current_lowest_digit * get_power_2019(len(s)-1-i))% 2019 + last_mod) % 2019
    if (current_mod not in mod_dict.keys()):
        mod_dict[current_mod] = [i]
    else:
        mod_dict[current_mod].append(i)
    last_mod = current_mod

# print(mod_dict)

count = 0
for k in mod_dict.keys():
    n = len(mod_dict[k])
    count += int(n*(n-1)/2)
    if (k == 0):
        count += n
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans=0
lra=len(s)-3
rra=len(s)+1
for l in range(lra):
    for r in range(l+3,rra):
        tmp=int(s[l:r])
        if tmp%2019==0:
            ans+=1 
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(l):
  for j in range(l):
    if i < j:
      new_s = int(S[i:j+1])
      if new_s % 2019 == 0:
        count += 1
      else:
        continue
    else:
      continue
print(count)

Submission status: Time Limit Exceeded

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

# -- submit ----

import sys
sys.setrecursionlimit(4100000)


def main():

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

    def check(window_width, cou):

        if window_width < 4:
            print(cou)
            return None

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

        check(window_width - 1, cou)

    check(max_n, 0)


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

Submission status: Time Limit Exceeded

Solution code:
s = input() #sys.stdin.readlineは最後が改行
n =len(s)

num=0
tmp=0

amari= [0]

for i in range(n):
    num = tmp + int(s[-1-i])*(10**(i))
    tmp = num%2019
    amari.append(tmp)

from collections import Counter
ctr = Counter(amari)
ans = 0
for val in ctr.values():
        ans += val*(val-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count_start = 0
count_end = 1
kumi = []
while count_start <= len(S) - 1:
    count_end = 1
    while count_end <= len(S):
        if count_start + 2 < count_end:
            if int(S[count_start:count_end]) % 2019 == 0:
                kumi.append(int(S[count_start:count_end]))
        count_end += 1
    count_start += 1
print(len(kumi))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque

S = input()

L = deque()
D1 = defaultdict(set)
D2 = {}
for i in range(len(S)-3):
  ii = i
  j = i + 4
  r = 0
  while j <= len(S):
    X = r + int(S[ii:j])
    r = X % 2019
    ii = j
    if r == 0:
      L.append(i)
      D1[i].add(j)
      D2[j] = i
      break
    elif r < 2:
      j += 4
      r *= 10000
    elif r < 20:
      j += 3
      r *= 1000
    elif r < 201:
      j += 2
      r *= 100
    else:
      j += 1
      r *= 10

for x in reversed(L):
  if x in D2:
    D1[D2[x]] += D1[x]
print(sum(len(x) for x in D1.values()))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
num = str(N)
s=len(num)
ans=0
for i in range(4,s+2):
    for u in range(1,s-i+2):#hajimenobanngou
        a=int("".join((map(str,num[u-1:u+i-1]))))
        if  a%2019==0:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
nums=[0]*200000
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[div]+=1
    
ans = zero
for v in nums:
    if v<2:
        continue
    ans += v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

input = sys.stdin.readline
s = input()
n = len(s)
# se = {i * 2019 for i in range(1000)}
# count = 0
b = []
for i in range(n - 3):
    for j in range(i + 3, n):
        a = int(s[i:j])
        b.append(a)

c = np.array(b)

print(np.count_nonzero(c % 2019 == 0))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = list(input())
Ns = ''.join(N)
M = list(map(str, list(range(len(N)))))
# print(M)
S = list(itertools.combinations(M,2))
count = 0
for _, combi in enumerate(S):
    # print(combi)
    A = N[int(combi[0]):int(combi[1])+1]
    B = ''.join(A)
    # print(B)
    if int(B)%2019 == 0:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
# S = int(s)

N = len(s)
ans = 0
S =""
i = 0
b = 0
while i <N :
    # print("i=",i)
    S += s[i]
    # print(S)
    n = len(S)
    if n > 4:
        for k in range(b,n):
            n3 = S[k:]
            n2 = len(n3)
            if  n2 > 4:
                if int(n3) %2019 == 0:
                    ans += 1
                    break
    i += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
len_s = len(s)
list_s = []
list_2019 = ['2019', '4038', '6057', '8076', '10095', '12114', '14133', '16152', '18171', '20190', '22209', '24228',
             '26247', '28266', '30285', '32304', '34323', '36342', '38361', '40380', '42399', '44418', '46437',
             '48456', '50475', '52494', '54513', '56532', '58551', '60570', '62589', '64608', '66627', '68646',
             '70665', '72684', '74703', '76722', '78741', '80760', '82779', '84798', '86817', '88836', '90855',
             '92874', '94893', '96912', '98931', '100950', '102969', '104988', '107007', '109026', '111045',
             '113064', '115083', '117102', '119121', '121140', '123159', '125178', '127197', '129216', '131235',
             '133254', '135273', '137292', '139311', '141330', '143349', '145368', '147387', '149406', '151425',
             '153444', '155463', '157482', '159501', '161520', '163539', '165558', '167577', '169596', '171615',
             '173634', '175653', '177672', '179691', '181710', '183729', '185748', '187767', '189786', '191805',
             '193824', '195843', '197862', '199881']
ans = 0
for i in range(4, len_s):
    for j in range(len_s):
        if j + i <= len_s:
            list_s.append(''.join(s[j:j + i]))

for k in list_2019:
    ans += list_s.count(k)
print(ans)

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):
            break
        if i==4 and N[j]=="1":
            continue
        temp=int(N[j:j+i])

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

print(count)

Submission status: Time Limit Exceeded

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

r = [0 for _ in range(m+1)]
r[0] = 1
for i in range(n):
    z = int(s[i:])%m
    r[z] += 1
a = 0
for i in range(m+1):
    a += r[i]*(r[i]-1)//2

print(a)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import math

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


for i in range(n):
    num = s % (10 ** (n - i))
    for j in range(1,n+1):
        if num == 0:
            break
        elif num % 2019 == 0:
            count += 1
            break
        num = num // 10

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
count = 0
l = [0]*2019
key = range(2019)
l[0] = 1
d = dict(zip(key,l))

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

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

print(count)

Submission status: Time Limit Exceeded

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

for i in range(len(S)+1):
    for j in range(i+1,len(S)+1):
        K = S[i:j]
        L = [int(s) for s in K]
        n = 0
        for k in range(len(L)):
            n = n + L[k]*(10**(len(L)-k-1))
            k = k + 1
        if n % 2019 == 0:
            ans += 1
        j = j + 1
    i = i + 1
        

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
ans = 0
for i in range(len(S)-4):
    k=5
    while k-(len(S)-i) < 1:
        if int(S[i:i+k]) % 2019 != 0:
            k+=1
        else:
            ans +=1
            k+= len(S[i:i+k])-4
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# coding: utf-8
S=list(map(int,input()))
N=len(S)
MAX=2100
MOD=10**9+7

fac=[None for i in range(MAX)]
finv=[None for i in range(MAX)]
inv=[None for i in range(MAX)]

def COMinit(num):
    global fac
    global finv
    global inv
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1

    for i in range(2,num):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n,k):
    if n<k:
        return 0
    elif n<0 or k<0:
        return 0
    else:
        return int(fac[n] * (finv[k] * finv[n - k] % MOD) % MOD)


COMinit(MAX)

M=[[0 for j in range(10)] for i in range(2019)]

ans=0
num=0
for i in range(N):
    num+=S[-(1+i)]*(10**(1+i))
    I=num%2019
    if I==0:
        ans+=1
    syou=num//2019
    J=syou%10
    M[I][J]+=1

for i in range(2019):
    for j in range(10):
        if M[i][j]>=2:
            ans+=COM(M[i][j],2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
l = []
for i in range(1, 1000000):
    l.append(str(2019*i))

s = input()
ans = dict()
for i in l:
    if i in s:
        for j in range(len(s)-len(i)+1):
            if s[j:j+len(i)] == i:
                ans[str(j+1)+"-"+str(j+len(i))] = 1

# print(l)
print(len(ans))
# print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

S = input()

"""
counts = Counter()
total = 0
for d in S:
    d = int(d)
    nextCounts = Counter()
    nextCounts[d] += 1
    for k, v in counts.items():
        nextCounts[(10 * k + d) % 2019] += v

    counts = nextCounts
    total += counts[0]
    #print(counts)

print(total)

"""


def modInverse(a, m):
    m0 = m
    y = 0
    x = 1

    if m == 1:
        return 0

    while a > 1:

        # q is quotient
        q = a // m

        t = m

        # m is remainder now, process
        # same as Euclid's algo
        m = a % m
        a = t
        t = y

        # Update x and y
        y = x - q * y
        x = t

    # Make x positive
    if x < 0:
        x = x + m0

    return x


div10 = modInverse(10, 2019)
m = 1
mInv = 1

off = 0
counts = Counter()
total = 0
for d in S:
    d = int(d)
    off = 10 * off + d
    m *= 10
    mInv = (mInv * div10) % 2019
    #assert modInverse(m, 2019) == mInv
    counts[((d - off) * mInv) % 2019] += 1
    total += counts[((0 - off) * mInv) % 2019]

print(total)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
l = [0]* len(S)
for i in range(len(S)):
    T = S[i:]
    t = int(T)
    l[i] = t%2019
l.sort()
m = [0] * len(S)
k = 1
for i in range (len(S) - 1):
    if l[i] != l[i + 1]:
        m[i] = int(k*(k-1)/2)
        k = 1
    else:
        m[i] = 0
        k += 1
if k != 1:
    m[len(S) - 1] = int(k*(k-1)/2)
print(sum(m) + l.count(0))

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

s = input()

# print(s)

ans = np.zeros((len(s)), dtype = np.int)

# print(ans)

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

# print(ans)

print(np.sum(ans))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def main():
    S = list(str(input()))
    ans = 0
    for i in range(len(S)):
        S2 = ''
        S2 += S[i]
        if (i+3) > len(S)-1:
            break
        S2 += S[i+1]+S[i+2]
        for j in range(i+3,len(S)):
            S2 += S[j]
            #print(S2)
            if (int(S2)%2019) == 0:
                ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import log10
n = int(input())

ans = 0

for i in range(4, int(log10(n))+2):
    s = n % (10**i)
    while s >= 2019:
        if s % 2019 == 0:
            ans += 1
        s //= 10

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())

i = 0
j = 3
t = 0
cnt = 0
b = 2019

while(j!=len(s)):
    if(not (int(''.join(map(str,s[i:j+t+1]))) % b)):
        cnt = cnt + 1
    t = t + 1
    if (j+t == len(s)):
        t= 0
        i = i +1
        j = j+1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
memo = []

def main():
    global S

    def main0(acc, s):
        if len(s) <= 3:
            return acc

        if s in memo:
            return 

        for i in range(4, len(s)+1):
            a = int(s[0:i])

            memo.append(a)
            if a < 2019:
                continue
       
            if a % 2019 == 0:
                acc += 1

        memo.append(a)

        return main0(acc, s[1:])

    return main0(0, S)

print(main())

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s=input()
ans=0
for j in range(len(s)-3):
    a=[1 for i in range(len(s)-3-j) if int(s[i:i+4+j])%2019==0]
    ans+=sum(a)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def mul2019(num):
    return 1 if num % 2019 == 0 else 0


S = str(input())
p = 0
num_list = []
for i in range(0, len(S)):
    for j in range(len(S), i, -1):
        if len(S[i:j]) >= 4 and int(S[i:j]) >= 2019:
            num_list.append(int(S[i:j]))

for x in num_list:
    p += mul2019(x)
print(p)

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=0
sij0=0
#sij1=0
l=len(s)
for i in range(l-3):
  sij0=int(s[i:i+4])
  #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+=int(s[j])
    sij0 = sij0 % 2019
    if sij0 == 0:
      k=k+1
print(k)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = list(str(input()))
    A = [k * 2019 for k in range(1,100)]
    cnt = 0
    if len(S) >= 4: # ToDo 4桁でカウント
        for keta in range(4,len(S)):
            for i in range(0,len(S)-keta+1):    # i ＝ idxの場所
                NUM = ""
                for h in range(i,keta+i): NUM += S[h]
                if int(NUM) in A: cnt+=1

    print(cnt)


main()

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
l = len(s)
ans = 0
a = set(2019*i for i in range(1, 99))
        
for i in range(l):
    for j in range(i+4, l+1):
        if int(s[i:j]) in a:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0

for i in range(0,len(S)-4):
    for j in range(3,len(S)+1,2):
        s = S[i:j]
        if s == '':
            pass
        else:
            int_s = int(s)

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

print(count)