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:
#!/usr/bin/env python3

s = input()
count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

cnt = 0
for i in range(0, len(S)-3):
    for j in range(3, len(S)):
        sij = S[i:j+1]
        if len(sij) > 3 and len(sij) <= 200000:
            sij = int(sij)
            if sij % 2019 == 0 and i <= j:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

def main():
    s = input().rstrip()

    s_nums = list(range(len(s)+1))

    ans = 0

    for i_1 in range(len(s)-2):
        for i_2 in range(i_1+1, len(s)+1):
            if int(s[i_1:i_2]) % 2019 == 0:
                # print(i_1, i_2)
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict

S = input().strip()
l = len(S)
dp = [[0 for _ in range(2019)] for i in range(l)]
for i in range(l):
    s = int(S[i])
    for j in range(2019):
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
    dp[i][s] += 1

ans = 0
for i in range(l):
    ans += dp[i][0]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
l = list(input())
amari = [0]*len(l)
mod = 2019
import math
for i in range(len(l)):
    amari[i] = int(l[i])*(10**(len(l)-1-i)) % mod
rui = [0]*len(l)
rui[len(l)-1] = amari[-1]
for i in range(len(l)-2,-1,-1):
    rui[i] = (rui[i+1] + amari [i])%mod
count = [0]*2020
for i in range(len(l)):
    count[rui[i]] += 1
ans = 0
for i in range(1,2020):
    if count[i] == 0 or count[i] == 1:
        continue
    ans += count[i] * (count[i]-1)//2
ans += count[0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
l = len(S) 
dic = [int(S[i]) for i in range(l)]
result = 0
for i in reversed(range(0,l)):
  res = 0
  ad = 1
  for x in reversed(range(0,i+1)):
    res += dic[x]*ad
    ad = ad*10
    if res % 2019 == 0:
      result += 1
print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a = 0
count = 0

for i in range(l-2):
    a = int(S[l-i-1])
    for j in range(i+1,l):
        a += int(S[l-j-1])*10**(j-i)
        if j-i > 3:
            if a != 0 and a % 2019 == 0:
                count += 1
            
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
S = input()

res = 0
start = 0
min_length = 4
end = start+min_length
max_end = len(S)

if len(S) < 4:
  pass
else:
  while True:
    tmp_s = S[start:end]

    if int(tmp_s) % 2019 == 0:
      res += 1

    if end+1 <= max_end:
      end += 1
    elif end-(start+1) >= min_length:
      start += 1
      end = start + min_length
    else:
      break
    
print(res)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
counter = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

res = 0

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

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

s = input()
num = len(s)
# print(int(s[1:5]))
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
s = len(S)
cnt = 0
A = []
for i in range(s):
  A.append(int(S[i:])%2019)

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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
counter = 0
for i in range(4,len(s)):

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

Submission status: Time Limit Exceeded

Solution code:
S=input()

def sf(X):
    SL=len(S)
    A=0
    for i in range(SL-3):
        for j in range(SL-3-i):
            if int(S[i:(i+j+4)])%2019==0:
                A=A+1
    print(A)

sf(S)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections
s = map(int,raw_input())


dp = collections.Counter()
count = 0
for j in range(len(s)):
    ndp = collections.Counter()
    ndp[s[j]] += 1
    for k in dp:
        ndp[(10*k + s[j]) % 2019] += 1
    count += ndp[0]
    dp = ndp

print count

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

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

Submission status: Time Limit Exceeded

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


Ans = 0

for i in range(N):
    for j in range(4,N-i+1):
        SSS = int(S[i:i+j])
        kari = SSS % 2019
        if kari ==0:
            Ans = Ans +1
   


print(Ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans=0

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

S_len = len(S)
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())

s = load(str)
d = dict()
for i in range(1, 10):
    d[str(i)] = i
cnt = 0
for i in range(len(s)):
    target = 0
    for j in range(i, len(s)):
        target =  target * 10 + d[s[j]]
        if target % 2019 == 0:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


# input the data
s = input()
m = len(s)
count = 0

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

Submission status: Time Limit Exceeded

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

count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = list(str(s))
n = len(l)

c = 0
for i in range(n):
    for j in range(i,n):
        t = ''.join(l[i:j+1])
        if int(t)%2019 == 0:
            c = 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(i+4,len(S)):
        if int(S[i:j+1])%2019==0:
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

num = 0
for i in range(0, len(s)-4):
  for j in range(i+4, len(s)):
    tmp = s[i:j+1]
    tmp_str = ""
    for k in tmp:
      tmp_str+=k
    if not tmp_str == "":
      if int(tmp_str)%2019==0:
        num+=1
      
print(num)

Submission status: Time Limit Exceeded

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

for i in i_list:
  s_num = s[i]*100 + s[i+1]*10 + s[i+2]
  for j in range(3,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:
#import numpy as np#not for pypy

def main():
    ##get int
    #first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    first_input = input().split(" ")
    #second_input = input().split(" ")

    S = first_input[0]

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

    print(baisu_count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def Sol(st):
    count = 0
    for i in range(len(st)):
        for j in range(i+3,len(st)):
            if int(st[i:j+1])%2019 == 0:
                count += 1
    print(count)
    return

    

#for t in range(int(input())):
#n,k,d,c = map(int,input().split())
#n = int(input())
#arr = []
#for i in range(n):
#    arr.append(input())
#arr = list(map(int,input().split()))
k = input()
#n = int(input())
Sol(k)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
d = {}



ans = 0
for i in range(l):
    m = int(S) % 2019
    if m in d:
        d[m] += 1
    else:
        d[m] = 1
    S = S[1:]

for k, v in d.items():
    if v >= 2:
        ans += int(v * (v-1)/2)
    if k == 0:
        ans += v
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(len(S)-3):
    for j in range(i+4,len(S)+1):
        s = S[i:j]
        #print([i,j])
        suji = sum([s[-k]*(10**(k-1)) for k in range(1,len(s)+1)])
        if suji%2019 == 0:
            #print(i,j)
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

ans = 0
len_s = len(s)
for i in range(4,len(s)+1):
    for j in range(len_s):
        if j+i > len_s :
            break
        if s[j:j+i] != '':
            if int(s[j:j+i]) % 2019 == 0:
                ans +=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  s=input()
  l=len(s)
  mod=2019
  x=[0]*l
  x[0]=(int(s[0])*(pow(10,l-1)))%mod
  for i in range(1,l):
    x[i]=((int(s[i])*(pow(10,l-i-1)))%mod+x[i-1])%mod
  cnt=x.count(0)
  print(l-len(set(x))+cnt)
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
num = list(str(input()))
cnt = 0

for i in range(len(num)):
    if i == 0:
        pass
    if i+3 > len(num):
        break
    else:
        for j in range(i+4, len(num)+1):
            check = ''.join(num[i:j])
            if int(check) % 2019 == 0:
                cnt += 1
            

print(cnt)

Submission status: Time Limit Exceeded

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = input()
num = len(N)
ans = 0
for i in range(0,num-3):
  for j in range(i+3,num):
    if j == i + 3:
      s = int(N[i:j+1])
    else:
      s = t*10 + int(N[j])
    t = s% 2019
    if t == 0:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input().rstrip()

ans = 0
c = 0
while c < len(s) - 3:
    e = 0
    if s[c] == '1':
        e = c + 5
    else:
        e = c + 4
    
    while not(int(s[c:e]) % 2019 == 0) and e < len(s):
        e += 1
    
    if int(s[c:e]) % 2019 == 0:
        ans += 1
    
    c += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import fractions
import collections
import itertools
from collections import deque
d=collections.deque()
S=list(input())
N=len(S)
cnt=0

amari=[0]*(N+1)
num=0
for i in range(N):
    d.append(int(S[i]))
#print(d)
for i in range(N):
    n=d.pop()
    num=(num+pow(10,i)*n)%2019
    amari[i+1]=num
#print(amari)
#c=collections.Counter(amari)
#values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
amari.sort()
#for i in range(len(key)):
#    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#xprint(l)
buf=0
#print(amari)
for i in range(N-1):
    if amari[i]==amari[i+1]:
        buf=buf+1
    else:
        cnt=cnt+((buf+1)*buf)//2
        buf=0
    #print(buf)
cnt=cnt+(buf*(buf+1))//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
strS = input()
maxlength = len(strS)
count = 0

for i in range(maxlength):
  #print("i:{}".format(i))
  for j in range(maxlength - (i+3)):
    #print("j:{}".format(j))
    trynum = int(strS[i:i+4+j])
    if ( trynum % 2019 == 0 ):
      count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
S = input()
start_index = 0
counter = 0
while start_index < len(S) - 4:
    temp_counter = 0
    temp_start_index = start_index
    end_index = start_index + 5
    while end_index <= len(S):
        if int(S[temp_start_index:end_index]) % 2019 == 0:
            temp_counter += 1
            temp_start_index = end_index
            end_index += 5
        else:
            end_index += 1
    if temp_counter != 0:
        a = 1
        for i in range(temp_counter):
            a *= (i+1)
        counter += a
    start_index += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
S = input()

S = S[::-1]
N = len(S)
cnt = [0] * 2019
mod = 2019
m = 0
cnt[0] += 1
for i in range(N):
    s = int(S[i]) * ((10 ** i) % mod)
    s %= mod
    m += s
    m %= mod
    cnt[m] += 1


ans = 0
for i in cnt:
    ans += (i * (i-1)) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
S = list(map(int, S))
cnt = 0
for w in range(4, len(S) + 1):
  for i in range(len(S) + 1 - w):
    num = 0
    for j in range(w):
      num *= 10
      num += S[i+j]
    #print(num)
    if num % 2019 == 0:
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
counter = 0

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

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

Submission status: Time Limit Exceeded

Solution code:

from collections import defaultdict

def submit():
    s = [int(c) for c in input()]
    modp = 2019

    curr = 0
    modp_count = defaultdict(int)
    modp_count[0] = 1
    ans = 0
    base = 1
    for c in reversed(s):
        curr += base * c
        curr_mod = curr % modp
        ans += modp_count[curr_mod]
        modp_count[curr_mod] += 1
        base *= 10
    
    print(ans)
    

submit()

Submission status: Time Limit Exceeded

Solution code:
S=input()

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0
if  len(s) < 4:
    print(0)
else:
    for i in range(len(s) -4 + 1):
        for j in range(len(s) - 4 + 1 - i):
#             print(i, j + 4, s[i : j + 4 + i])
            if sum(list(map(int, s[i : j + 4 + i]))) % 3 != 0:continue
            if int(s[i : j + 4 + i]) % 2019 == 0:
                count+=1
#                 print(s[i : j + 4 + i])
    print(count)

Submission status: Time Limit Exceeded

Solution code:


anslist = []


def solve():

    S = input()

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

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
s = input()

count=0
for i in range(len(s)):
  k=int(s[i])
  r = int(k)
  if(r==0): count+=1
    
  for j in range(i+1,len(s)):
    r=(10*r+int(s[j])) % 2019
    if(r==0):
      count+=1
       
print(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)+1):
        b=int(s[i:j])
        if b%2019==0:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
count = 0

for i in range(1,len(str(S))+1):
    for j in range(i+4,len(str(S))+1):
        N = S%10**(len(str(S))-i+1)-S%10**(len(str(S))-j)
        if N%2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#TLE
S = input()
l = int(S)
count = 0
for i in range(0, l):
    for k in range(0, l):
        S = S[i:k]
        if len(S)!=0:
            s = int(S)
            if s%2019 == 0:
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def atoi(s):
    num = 0
    for i in s:
        num = num*10 + ord(i) - ord('0')
    return num

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

Submission status: Time Limit Exceeded

Solution code:
s=[int(x) for x in list(str(input()))]
ans=0
for i in range(1,len(s)+1):
    for j in range(i+2,len(s)+1):
        figure=0
        if(sum(s[-i:-j-1:-1])%3==0):
            for k in range(j-i+1):
                figure+=s[-(i+k)]*10**k
                
            if(figure%673==0):
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

length = len(s)
count = 0
for i in range(1, len(s)):
  l = length - i
  if l < 3:
    break;
  for j in range(i):
    if int(s[j:l+j+1]) % 2019 == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

res = [0 for i in range(2019)]
res[0] += 1
for i in range(len(s)):
    res[int(s[i:])%2019] += 1

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  S=input()
  S_num=int(S)
  S_len=len(S)
  s_count=0
  for i in range(0,S_len):
    for j in range(i+3,S_len):
      tgtS=S[i:j+1]
      int_tgtS=int(tgtS)
      if(int_tgtS%2019==0):
        s_count=s_count+1
  print(s_count)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

count = 0
for l in range(0, len_s-3):
    t = int(s[l:l+4]) % 2019
    if t == 0:
        count += 1
    for r in range(l+4, len_s):
        t = (t*10 + int(s[r])) % 2019
        if t == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

def make_num(x,y):
    return int(s[x:y])
l = [make_num(i,j) for i in range(len(s)-3) for j in range(i+4, len(s)+1) if make_num(i,j)%2019 ==0]
print(len(l))

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
for i in range(0, 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:
s = input()

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)

s = input()

long = len(s)

ans = 0

for i in range(long - 3):
    for j in range(i + 4, long+ 1):
        
        s_list = [int(i) for i in s[i:j]]
        
        if sum(s_list) % 3 != 0:
            continue
        else:
            if int(s[i:j]) % 673 == 0:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()

l=len(s)

count=0
for i in range(l-2):
    cu=[]
    cu.append(s[i])
    cu.append(s[i+1])
    cu.append(s[i+2])
    for j in range(i+3,l):
        cu.append(s[j])
        test = ''.join(cu)
        test=int(test)
        if test % 2019 ==0:
            count=count+1

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

Submission status: Time Limit Exceeded

Solution code:
n = input()
n_len = len(list(n))
n_list = list(n)


count = 0
for i in range(n_len):
  for j in range(i+1,n_len+1):
    if int("".join(n_list[i:j]))%2019 == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
S_int = int(S)
S_len = len(S)
ans = 0

for i in range(0, S_len - 3):
    for j in range(4+i, S_len+1):
        S_ta = S[i:j]
        # print(S_ta)
        if int(S_ta) % 2019 == 0:
            ans += 1
            #print(i, j)
        else:
            pass
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = []
c = 0
for i in range(4,len(S)+1):
    # print(i,"=======")
    for j in range(len(S)-i+1):

        a = S[j:j+i]
        if int(a)%2019 == 0:
            # print(a)
            c+=1
print(c)

Submission status: Time Limit Exceeded

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

while(i+3<=N):
    j = i+3
    num = int(S[i-1:j])
    while(j<N):
        r = num % 2019
        if r == 0:
            cnt += 1
        num = r * 10 + int(S[j])
        j += 1
    r = num % 2019
    if r == 0:
        cnt += 1
    i += 1

print(cnt)

Submission status: Time Limit Exceeded

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

s = input()
length = len(s)

counter = 0

for i in range(length):
    for j in range(length - i):
        target = s[i:i+j+1]
        # print(i, j, target, int(target) % 2019)
        if int(target) % 2019 == 0:
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

S = tuple(map(int, list(input())))
MOD = 2019
dp = [defaultdict(int) for _ in range(len(S) + 1)]
for i in range(len(S)):
    dp[i + 1][S[i]] += 1
    for j in dp[i]:
        dp[i + 1][(j * 10 + S[i]) % MOD] += dp[i][j]

print(sum(dp[i][0] for i in range(len(S) + 1)))

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
for i in range(len(S)):
    total = 0
    for j in range(i + 1, len(S) + 1):
        total += int(S[j - 1])

        if total % 3 != 0:
            continue

        if int(S[i:j]) % 2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

res = 0

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