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:
#


def main():
    s = input()
    length = len(s)
    count = 0
    # 愚直な方法ではTLE
    for i in range(length - 3):
        for j in range(i + 4, length + 1):
            n = int(s[i:j])
            if n % 2019 == 0:
                count += 1
    print(count)


if __name__ == '__main__':
    main()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

def main():
    d = {}
    s = input()
    l = len(s)
    ans = 0
    for i in range(0,l-4):
        tj = min(l-i+1, 200)
        for j in range(4, tj):
            t = int(s[i:i+j])
            if t in d:
                ans += d[t]
            else:
                if t%2019==0:
                    d[t] = 1
                    ans+=1
                else:
                    d[t] = 0
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
m=0
a=[0,201]
for i in range(len(s)-3):
    for j in range(len(s)-i-3):
        if a[1]<201 and a[0]==i:
            a[1]=a[1]*10+int(s[i+j+3])
            continue
        #print(s[i:i+4+j],int(s[i:i+4+j])%2019)
        if int(s[i:i+4+j])%2019==0:
            m+=1
        a=[i,int(s[i:i+4+j])%2019]
print(m)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    cnt = 0
    for i in range(len(S)):
        for j in range(4, len(S)):
            if i + j <= len(S):
                if int(S[i:i+j]) % 2019 == 0:
                    cnt += 1
            else:
                break
    print(cnt)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:

s = input('')
max_s = 200000
rec = 0
for m in (range(max_s+1)):
    ms=str(2019*m)
    idx=s.find(ms)
    while idx >= 0:
        rec+=1
        idx=s.find(ms,idx)+1
print(rec)

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)):
		x=n[i:j+1]
		while len(x)>4:
			x=str(int(x[:-1])+202*int(x[-1]))
		if int(x)%2019==0:
			count+=1
			#print(	i,j)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

S = list(map(str,input()))

counter = 0

set = list(itertools.combinations(range(len(S)),2))

for i in range(len(set)):
    s = int("".join(S[int(set[i][0]):int(set[i][1])+1]))
    if s % 2019 == 0:
        counter += 1

print(counter)

Submission status: Time Limit Exceeded

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

import sys
#import numpy as np

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

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

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

ans = 0

xx = [0 for _ in range(2019)]
for i in range(len(b)):
    xx[b[i]] += 1

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
d = {}
for i in range(len(s)):
  r = int(s[i:])%2019
  if r in d:
    d[r] += 1
  else:
    d[r] = 1
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:
S=input()
N=len(S)
a=[]
num=0
ans=0
for i in range(N-1):
  for j in range(i+1,N):
    a.append((i,j))
for i in a:
  num=int("".join(S[i[0]:i[1]+1]))
  if num%2019==0:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0

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

Submission status: Time Limit Exceeded

Solution code:

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

print(sum(ans))

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
num = 0
sr = set()
k = 2019
n = len(s)
for i in range(n):
    rem = 0
    pf = 0
    for j in range(i,n):
        rem =  (10*rem + int(s[j])) % k

        if(rem in sr):
            break

        if(rem == 0):
            pf += 1

    num += (pf * (pf+1))//2


print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()

DP=[[0 for k in range(len(S))] for l in range(len(S))]

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
count=0
a=[0 for i in range(n)]
for i in range(3,n):
    a[i]=10**i%2019
if n<4:
    print(0)
else:
    for i in reversed(range(2,n)):
        k=int(s[i-2:i+1])
        h=3
        for j in reversed(range(0,i-2)):
            k=k+a[h]*int(s[j])
            h+=1
            if k%2019==0:
                count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
s=str(input())
a=[]
ans=0
target=list(str(2019*i) for i in range(1,100))

for i in range(len(s)):
    for j in range(len(s[i+3:])):
      	if s[i:4+j+i] in target:
          ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
C = [0 for i in range(2019)]
C[0] = 1
now = 0
for i in range(N):
    now += int(S[-i-1])*(10**i)
    now %= 2019
    C[now] += 1
ans = 0
for i in range(2019):
    ans += C[i]*(C[i]-1)//2
print(ans)

Submission status: Time Limit Exceeded

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


ans = 0
amari = [0] * 2019
follow = 0

for i in range(N):
  Amari_ = (int(S[N-i-1]) * pow(10, i) + follow) % 2019
  amari[Amari_] += 1
  follow = Amari_
  
ans = sum(list( i * (i-1)//2 for i in amari ))
ans += amari[0]

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
si = [int(i) for i in list(str(input()))]
a = 0
for i in range(1,len(si)+1):
    if len(si)-i < 3:
        break
    for j in range(i+3,len(si)+1):
        b = 0
        for ix,k in enumerate(reversed(si[i-1:j])):
            b += k * (10**ix)
        if b % 2019 == 0:
            a +=1
print(a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
cnt = [0] * 2019
for i in range(1, N+1):
    cnt[(t % (10)**i) % 2019] += 1
ans += cnt[0]
for i in range(1, 2019):
    if cnt[i] >= 2:
        ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
#S = str(1817181712114)
ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

possible2 = []

for i in range(1, 99):
    possible2.append(int(str(i  * 2019)[0:2]))

possible2 = set(possible2)

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

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    s = kwargs["s"]
    n = len(s)
    res = 0

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

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["s"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    #kwargs["n"] = [int(i) for i in cin][0]
    #kwargs["n"], kwargs["k"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
s = int(S)
n = len(S)
count = 0
for i in range(1,n+1):
    for j in range(i,n+1):
        si = s%10**(n-i+1)
        sij = si//10**(n-j)
        if sij!= 0 and sij % 2019 == 0:
            count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s=input()

nagasa=len(s)
num=0
check=dict()

for i in range(nagasa-3):
    co=4
    target=s[i:i+4]
    while(1):
        #print(target)
        if(target in check):
            num+=check[target]
        else:
            if(int(target)%2019==0):
                num+=1
                check[target]=1
            else:
                check[target]=0

        
        if(i+co>=nagasa):
            break
        target+=s[i+co]
        co+=1

    
print(num)

Submission status: Time Limit Exceeded

Solution code:

n = input()
t = len(n)
total = 0
for i in range(t-4):
    for j in range(i+4,t):
        k = (n[i:j+1])
        l = int(k)
        #print(l)
        if l%2019 == 0:
            total += 1

print(total)

Submission status: Time Limit Exceeded

Solution code:
s=input()
if len(s)<5:
  print(0)
  exit()
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
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def count(text, part):
    return sum(text.startswith(part, i) for i in range(len(text)))

s = input()
ans = 0
for i in range(1,892):
    if i*2019 > int(s):
        break
    if str(2019*i) in s:
        ans += count(s,str(2019*i))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

N = 0

while len(S)>0:
    for i in range(len(S)):
        s = int(S[0:i+1])
        if s % 2019 == 0:
            N += 1
    S = S[1:]

print(N)

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
"""
"""i = 0
j = len(S)
while True:
    if int(S[i:j]) % 2019 == 0:
        count += 1
    else:
"""

j = 4
for i in range(0, len(S)-4):
    k = j
    A = 0
    if int(S[i:j+1]) % 3 == 0:
        if int(S[i:j+1]) % 673 == 0:
            count += 1
        while j < len(S)-1:
            A += int(S[j+1])
            if A % 3 == 0:
                if int(S[i:j+1]) % 673 == 0:
                    count += 1
            j += 1
    j = k + 1



print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    count=np.zeros(2019,dtype=int)
    temp=set([])
    ans=0
    for i in range(len(s)):
        count_t=np.zeros(2019,dtype=int)
        count_t[int(s[i])]+=1
        for k in range(2019):
            t=(k*10+int(s[i]))%2019
            count_t[k]-=count[k]
            count_t[t]+=count[k]
            if t==0:
                ans+=count[k]
        #print(count[0:20])
        #print(count_t[0:20])
        count=count+count_t
    print(ans)
                
if __name__ == '__main__':
    do()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

c=0
d=0
def check2019(S, n):
    global c
    global d
    if int(S)%2019 ==0:
        c +=1
        if n ==2:
            d =1
    else:
        pass
    if len(S)>4:
        if n ==0:
            return check2019(S[1:],1), check2019(S[:-1], 0)
        else:
            return check2019(S[1:],2)
    else:
        return 0
S = input()


if len(S) >= 4:
    check2019(S, 0)
else:
    pass
print(c-d)

Submission status: Time Limit Exceeded

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

print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = list(str(n))

ans = 0

for i in range(len(a)-3):
    for j in range(len(a)-3-i):
        k = a[i:i+4+j]
        if int("".join(map(str, k)))%2019 == 0:
            ans = ans + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
S.split()
ans=0


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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
def get_ij(ij, S, rem_i):
    length = len(rem_i)
    for i in range(length):
        for j in range(i+1, length):
            ij.append([rem_i[i], rem_i[j]])
    
    return 0

S = input()
length = len(S)
ruiseki_sum = [0]*length
ruiseki_sum[0] = int(S[0])
for i in range(length):
    if i != 0:
        ruiseki_sum[i] = ruiseki_sum[i-1] + int(S[i])

ruiseki_rem = [0]*length
for i in range(length):
    ruiseki_rem[i] = ruiseki_sum[i] % 3

rem_0_i = list()
rem_1_i = list()
rem_2_i = list()

for i in range(length):
    if ruiseki_rem[i] == 0:
        rem_0_i.append(i)
    elif ruiseki_rem[i] == 1:
        rem_1_i.append(i)
    else:
        rem_2_i.append(i)
    
ij = list()
get_ij(ij, S, rem_0_i)
get_ij(ij, S, rem_1_i)
get_ij(ij, S, rem_2_i)

# print(rem_0_i)
# print(rem_1_i)
# print(rem_2_i)
# print(ij)

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
# input処理を高速化する
input = sys.stdin.readline

S=input()
N=len(S)

number=''
cnt=0
for i in range(N-2):
    for j in range(i+4,N):
        number=S[i:j]
        if int(number)%2019 ==0:
            cnt+=1
            break

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
c=int(len(list(str(a))))
A=0

for i in range(c-3):
    for j in range(4,c+1-i):
        b=list(str(a))
        b=b[i:j+i]
        pg = ''.join(b)
        pg=int(pg)
        if pg%2019==0:
            A+=1
print(A)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
for i in range(len(S)):
    try:
        for n in range(4,len(S)+1):
            j = i + n
            number = int(S[i:j])
            if number % 2019 == 0:
                if j == len(S)+1:
                    break
                else:
                    count += 1
            else:
                pass
    except IndexError:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
mods = [0 for i in range(2019)]
mods[0] = 1
res = 0
cnt = 0
ss = 0

nums = []
curr10 = 1

for i in range(n):
    nums.append(curr10)
    curr10 *= 10

for i in range(n - 1, -1, -1):
    ss = int(s[i]) * nums[cnt] + ss
    cnt += 1
    curr = ss % 2019
    res += mods[curr]
    mods[curr] += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
s=[int(x) for x in list(str(input()))]
ans=0
bc=0;
loop=0
for i in range(1,len(s)+1):
    for j in range(i+2,len(s)+1):
        figure=0
        if(bc>0):
            bc-=1
            break
        
        loop+=1
        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
                bc=4
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    n = 0
    count = 0

    for i in range(len(s)-3):
        for j in range(i, len(s)):
            if i > j:
                continue

            n = s[i:j+1]

            # print(n)
            if int(n) % 2019 == 0:
                count += 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

counter = 0
for start in range(len(S)):
    for end in range(start,len(S)+1):
        target = S[start:end]
        if start < end and (int(target) % 2019) == 0:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
c = 0
for i in range(len(s)):
    for j in range(i+4,len(s)+1):
        a = int(s[i:j])
        if a>=2019 and a%3==0 and a%673==0:
            c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
line = input()
size = len(line)
num = [int(x) for x in list(str(line))]
i = 0
count = 0
if int(line)==2019:
    print("1")
else:
    while i<size-4:
        j = i + 4
        while j<=size:
            x = num[i:j]
            s = ""
            for k in range(len(x)):
                s = s + str(x[k])
            if int(s)%2019 == 0:
                count = count+1
            j = j + 1
        i = i + 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
# ABC164d


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

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

    s = input()

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

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

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

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

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

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

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

    # print(counter)

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

    print(c)

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

    #print(c, c2)

    # print(prime_factorize(2019))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_l = len(s)
r = 0
n = 1
while n <= 200000:
    a = 2019 * n
    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
        elif s[i - 1:i + a_l - 1] == a_s:
            r += 1
    n += 1
print(r)

Submission status: Time Limit Exceeded

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

a = 0
count = 0

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 標準入力の取得
S = input()

# 求解処理
size = len(S)
result = 0
for i in range(size-3):
    sub_S = S[i:]
    for j in range(i+3, size):
        number = int(sub_S[:i+j+1])
        if number % 2019 == 0:
            result += 1

# 結果出力
print(result)

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
        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)

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

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
C = [0 for i in range(2019)]
C[0] = 1
now = 0
for i in range(N):
    now += int(S[-i-1])*(10**i)
    C[now%2019] += 1
ans = 0
for i in range(2019):
    ans += C[i]*(C[i]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#D
import itertools

s = input()
s_n = [int(i) for i in s]
        
acc = list(itertools.accumulate(s_n))
acc.insert(0,0)
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
length = len(s)
count_dict = {}

num = int(s)%2019
count_dict[num] = 1

for i in range(1,length):
    num = (num-int(s[-i])*10**(i-1))%2019
    if num not in count_dict:
        count_dict[num] = 1
    else:
        count_dict[num] += 1

count = 0
for k,v in count_dict.items():
    count += v*(v-1)/2
    if k == 0:
        count += v

print(int(count))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

input = sys.stdin.readline


def main():
    s = input().rstrip()
    n = len(s)
    cs = [0] * (n + 1)
    for i, x in enumerate(s):
        cs[i + 1] = cs[i] + int(x)
    ans = 0
    for i in range(n):
        for j in range(i + 3, n + 1):
            if (cs[j] - cs[i]) % 3 != 0:
                continue
            if int(s[i:j]) % 2019 == 0:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
wa = [0] * (n + 1)
wa[1] = int(s[0])
for i in range(n - 1):
    wa[i + 2] = wa[i + 1] + int(s[i + 1]) 
res = 0

for i in range(n - 3):
    m = 3
    while i + m < n:
        if (wa[i + m + 1] - wa[i]) % 3 == 0:
            if int(s[i:i+m+1]) % 673 == 0:
                res = res + 1
        m = m + 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
S = input()

cnt=0
n = len(S)
'''
for i in range(n):
  for j in range(i+4,n+1):

    if( int(S[i:j]) % 2019 == 0 ):
      cnt+=1
      break
      #print( i,j )
'''
for i in range(n):
  num = int(S[i:])
  for j in range(i+4,n+1):
    if( num % 2019 == 0 ):
      cnt+=1
    
    num //= 10 

print( cnt )

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = []
c = 0
for i in range(5,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)+1
count = 0
for i in range(5,n):
    for j in range(0,n-i):
        s = S[j:j+i]
        if sum([int(a) for a in list(s)])%3==0:
            if (int(s))%673==0 : count+=1
print(count)

Submission status: Time Limit Exceeded

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

for i in range(0, size-3):
    for j in range(i+3, size):
        #if j >= size:
            #break
        N = int(S[i:j+1])
        if (N % 2019) == 0:
            count += 1
            break
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)):
    itoj = s[i:j+1]
    if (int(itoj) %  2019 ==0):
      ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s_n = str(n)
lenn = len(str(n))+1
res = []
for i in range(0,lenn):
    memo = 0
    for j in range(i+1,lenn):
        memo += int(s_n[j-1])
        if memo % 3 != 0:
            continue
        if int(s_n[i:j]) % 2019 == 0:
            res.append([i,j])
print(len(res))

Submission status: Time Limit Exceeded

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

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 current sub-string is divisible by k 
			if (n % k == 0): 
				count += 1
	
	# Return the required count 
	return count 

# Driver code 
if __name__ == '__main__': 
	str = input()
	l = len(str) 
	k = 2019
	print(countSubStr(str, l, k))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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