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

Submission status: Time Limit Exceeded

Solution code:
S = input()


def check_3(txt):
  goukei = sum(list(map(int,txt)))
  if goukei % 3 == 0:
    return True
  else:
    return False

def check_2019(txt):
  amari = int(txt) % 2019
  if amari == 0:
    return True
  else:
    return False

N = len(S)

ans = 0

for i in range(0, N-2):
  for j in range(i+4, N+1):
    # print(S[i:j])
    if check_3(S[i:j]):
      if check_2019(S[i:j]):
        ans += 1
        break
      else:
        pass

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(4100000)
n=input()
s=0
x=0
ans=0
for i in range(len(n)-3):
  for j in range(4,len(n)+1):
    s=len(n[i:j])
    if s>=4:
      x=int(n[i:j])
      if x%2019==0:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
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:
inputLine = input()

if len(inputLine) <= 3 : print('0')
elif len(inputLine) == 4 : print('1' if int(inputLine) % 2019 == 0 else '0')
else :

	count = 0

	# 長度從 4 ~ inputLine 的長度
	for indexLen in range(4, len(inputLine) + 1) :

		# 各種長度的可能
		for indexStart in range(0, len(inputLine) - indexLen + 1) :

			thisNum = inputLine[indexStart: indexStart + indexLen]
			count = count + 1 if (int(thisNum) % 2019) == 0 else count


	print(count)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

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

Submission status: Time Limit Exceeded

Solution code:

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

slist = [S[i:j+1] for i in range(N-3) for j in range(i+3,N) ]

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

baisuu = [str(2019*i) for i in range(1,101)]
counter = 0
for b in baisuu:

    counter += slist.count(b)





print(counter)

Submission status: Time Limit Exceeded

Solution code:
S = input()

possible4 = []

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

possible4 = set(possible4)

# print(possible2)
    
count = 0
    
for i in range(0, len(S)-3):
  # print(S[i])
  if int(S[i:i+4]) in possible4:
    # 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:
a=input()
b=[0]
for i in range(0,len(a)):
    b.append(b[i])
    for j in range(0,i):
        if(int(a[j:i+1])%2019==0):
            b[i+1]+=1
print(b[len(a)])

Submission status: Time Limit Exceeded

Solution code:
str_num = input().strip()
keta = len(str_num)
count = 0
for start in range(keta-3):
    for end in range(start+4, keta+1):
        num = int(str_num[start:end])
        if num % 2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    N = len(S)
    ans = 0
    m = 2019
    div_list = [0]*2019
    div_list[0] += 1
    for i in range(N):
        num = int(S[i:])
        div_list[num%m] += 1


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

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
count = 0
l = [0]*2019
l[0] = 1

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

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math;
s = input();

ans = 0;
num = 1;
i = 0;

while math.log10(num) <= len(s):
    i += 1;
    num = 2019 * i;
    ans += s.count(str(num));
    
print(ans);

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
S=list(input())
N=len(S)

MAX=10**5
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
for i in range(N):
    num=int("".join(S[i:N]))
    I=num%2019
    if I==0:
        ans+=1
    syou=num//2019
    J=int(str(syou)[-1])
    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(1817181712114%2019)
# print(1817181712114//2019)
# print(81712114%2019)
# print(81712114//2019)
# print(18171%2019)
print(ans)

Submission status: Time Limit Exceeded

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

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(0,l-3):
    for j in range(i+4,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:
s = list(input())
s=[int(i) for i in s]

from collections import defaultdict
import copy
d=defaultdict(int)
ans=0
for i in range(len(s)):
    newd=defaultdict(int)
    now=s[i]
    for k in d.keys():
        newd[(k*10+now)%2019]+=d[k]
    newd[now]+=1
    ans+=newd[0]
    d=copy.deepcopy(newd)

print(ans)

Submission status: Time Limit Exceeded

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

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
            j += 3
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
NN = 2019
ll = []
for i in range(N):
    l = [0 for i in range(NN)]
    k = int(S[i])
    if i > 0:
        for j in range(NN):
            l[(10*j+k)%NN] = ll[-1][j]
    l[k] += 1
    ll.append(l)

print(sum([ll[i][0] for i in range(N)]))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
S = list(map(str,input()))
answers = []
if len(S) < 4:
    print(0)
    exit()

for i in range(len(S)):
    for j in range(i+4, len(S)+1):
        if int(''.join(S[i:j])) % 2019 == 0:
            answers.append(int(''.join(S[i:j])))
            break
print(len(answers))

Submission status: Time Limit Exceeded

Solution code:
import re
s = input()
ans=0
x = [str(2019*i) for i in range(1,101)]
for i in range(len(s)+1):
    for j in range(i,len(s)+1):
        sij= s[i:j]
        if sij in x:
            ans+=1
        """print(sij in x)
        if sij=="":
            pass
        else:
            sij=int(sij)
            if sij%2019==0:
                ans+=1"""
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = input()
result = 0
for a, b in itertools.combinations(range(len(n)+1), 2) :
    if b - a > 3 :
        if int(n[a:b])%2019 == 0 :
            result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

s = str(input())

ans = 0
for k in range(4, len(s) + 1):
    for i in range(0, len(s) - k + 1):
        x = 0;
        for j in range(0, k):
            idx = i + j
            x += int(s[idx]) * (10 ** (k - j - 1))
        if x % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
k = len(str(S))
a = []
for j in range(1,k+1):
  for i in range(1,j+1):
    l = S % 10**(k-i+1)
    m = l // 10**(k-j)
    if m % 2019 == 0:
      a.append(i)
      
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
ans = 0
c = []
#good = []
#j = 4
m = 0

for i in range(l-4):
    good = []
    if i in c:
        continue
    j = max(i + 4, m)
    while 1:
        x = S[i:j]
        #print(x, (int(x) % 2019 == 0), i, j)
        if int(x) % 2019 == 0:
            good.append(j)
            j += 4
        else:
            j += 1
        if j > l:
            n = len(good)
            ans += (n ** 2 + n) // 2
            if n > 0:
                m = good[-1]
            c += good
            break
print(ans)

"""
for i in range(l-4):
    if i in c:
        continue
    if m != 0:
        j = m
        if i > m:
            j = 4
    good = []
    while 1:
        x = S[i:i+j]
        print(x, (int(x) % 2019 == 0), i, j)
        if j == 4 and x[0] == '1':
            j += 1
        elif int(x) % 2019 == 0:
            good.append(i+j)
            j += 4
        else:
            j += 1
        if i + j > l:
            print(good)
            n = len(good)
            ans += (n ** 2 + n) // 2
            c += good
            j = 4
            if n > 0:
                m = good[-1] - i
            
            break 
"""
#print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(res)

Submission status: Time Limit Exceeded

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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    s = input()
    check = 2019
    ret = 0

    for i in range(1, len(s) + 1):
        pre = ""
        if i == 1:
            pre = s[-(i + 2):]
        else:
            pre = s[-(i + 2):-(i - 1)]
        for j in range(i + 3, len(s) + 1):
            pre = s[-j] + pre

            if int(pre) % 3 == 0 and int(pre) % check == 0:
                ret += 1
    return ret


if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    roop_num = len(inputs)

    cnt = 0
    flag = False
    for start in range(roop_num-3):
        roop_num_end = roop_num - start
        ans_list = []
        ans_list = [int(inputs[start:end+start+4]) for end in range(roop_num_end-3) if int(inputs[start:end+start+4]) % 2019 == 0]

        cnt += len(ans_list)

    print(cnt)

if __name__ == '__main__':
    main()

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
d = {}
x = 0
for i in range(len(s)):
  x += int(s[-i-1])*10**i
  r = x%2019
  #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)
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
"""   




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

print(Ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from collections import deque
    import sys
    s=list(input())
    n,ans=len(s),0
    num=deque()
    scashe=[]
    if n<=3:
        print(0)
        sys.exit()
    for i in range(n-2):
        for j in range(i,i+3):
            num.append(s[j])
        for j in range(i+3,n):
            num.append(s[j])
            numj=int(''.join(num))
            if numj in scashe:
                ans+=1
            elif numj%2019==0:
                ans+=1
                scashe.append(numj)
            if j==n-1:
                num.clear()
    print(ans)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
count=0
Num=0
nagasa=len(s)
for n in range(nagasa-3):
    if s[n]==0:
        continue
    for m in range(nagasa-n-3):
        Num=int(s[n:n+m+4])
        #print(Num)
        if Num % 2019==0:
            count=count+1
            #print("Hit!")
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 int(s[i:j]) % 2019 == 0:
      res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
import functools
def solve():
    s = int(input())
    t = [int(x) for x in list(str(s))]

    l = []
    for i in range(1, 100):
        num = [int(x) for x in list(str(i*2019))]
        if 0 not in num:
            l.append(i*2019)

    cnt = 0
    n = len(t)
    for i in range(n-4):
        for j in range(i+4, n):
            new = int(functools.reduce(lambda x, y: x + y, [str(x) for x in t[i:j+1]]))
            if new in l:
                cnt += 1

    return cnt
    
print(solve())

Submission status: Time Limit Exceeded

Solution code:
s_str = input()

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
num = list(input())
ketasuu = 4
counter = 0
warukazu = ''

while(len(num)-ketasuu >= 0):
  for i in range(len(num)-ketasuu+1):
      for j in range(ketasuu):
          warukazu += num[i+j]
      if(int(warukazu)%2019 == 0):
        counter = counter + 1
        warukazu = ''
      else:
        warukazu = ''
  ketasuu = ketasuu + 1

print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
A = []
ans = 0
for i in range(len(S) - 3):
    for j in range(3,len(S)-i):
        T = [S[a] for a in range(i,i+j+1)]
        A.append(int(''.join(T)))
for i in A:
    if i % 2019 == 0:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = abs(int(input()))
# S = abs(int(1817181712114))
length = len(str(S))

multiple = 0

for i in range(0, length-3) :
    for j in range(i+4, length+1) :
        num = str(S)[i:j:1]
        if int(num) <= 200000 and int(num) % 2019 == 0 :
            multiple += 1

print(multiple)

Submission status: Time Limit Exceeded

Solution code:
S=input()
S1=int(S)
#print(len(S))
S_count=len(S)
sum=0
sum1=0
ii=0
jj=1
SSSS=int(S_count)
for i in range(S_count+1):
  sum1+=i
#print(sum1)
for i in range(sum1):
  SS=S[ii:jj]
  #print(SS)
  SSS=int(SS)
  if SSS%2019==0:
    sum+=1
  jj+=1
  if jj==int(S_count+1):
    ii+=1
    jj=ii+1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
def solve(a):
    n=len(a)
    k=673
    k2=3
    numMultiples = 0
    #seenRemainders = [[] for i in range(n)]
    seenRemainders = defaultdict(list)
    seenRemainders2 = defaultdict(list)
    for i in range(0,n):
        remainder = 0
        remainder2=0
        prefixesFound = 0
        for j in range(i,n):
            remainder = (10 * remainder + int(a[j])) % k
            remainder2 = (10 * remainder2 + int(a[j])) % k2
            if remainder in seenRemainders[j] and remainder2 in seenRemainders2[j]:
                break
            seenRemainders[j].append(remainder)
            seenRemainders2[j].append(remainder2)
            #add remainder to seenRemainders[j]
            if remainder == 0 and remainder2==0 :
                prefixesFound+=1
        numMultiples += prefixesFound * (prefixesFound + 1) / 2
    return numMultiples
s=input()
print(int(solve(s)))

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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:
            if a%3==0:
                if a%673==0:
                    c += 1
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt=0

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

print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(l - 3):
    if int(s[i:i+2]) % 2 != 0: continue
    for j in range(i + 4, l + 1):
        sub_s = int(s[i:j])
        if sub_s % 2019 == 0: ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    from collections import Counter

    input = sys.stdin.readline

    s = str(input().rstrip())
    num = ""
    li = []
    f = 0
    mi = 0
    li_append = li.append

    for i in range(1, len(s) + 1):
        num = s[-i] + num
        li_append(int(num) % 2019)
        if num[0] == "0":
            f += 1
        else:
            if f > 0:
                mi += ((f + 1) * f) // 2
                f = 0
            else:
                continue

    co = Counter(li)
    val = [i for i in co.values() if i > 1]
    ans_1 = 0

    for i in val:
        ans_1 += (i * (i - 1)) // 2
    ans2 = 0
    if 0 in co:
        ans2 = co[0]
    print(ans_1 + ans2 - mi)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
i = input()
ans = 0
for ii in range(len(i)-1):
	for i2 in range(1, len(i)+1):
		tmp = i[ii:i2]
		if ii < i2 and int(tmp) % 2019 == 0:
			ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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]) % 673 == 0:
            res.append([i,j])
print(len(res))

Submission status: Time Limit Exceeded

Solution code:
a = input()
a = list(a)

s = a[0]
r = 1
cnt = 0
for l in range(len(a)):
    r =1
    s= a[l:l+r]
    s = "".join(s)

    while int(s)%2019 != 0 and r<=len(a)-1:
        s= a[l:l+r]
        s = "".join(s)
        if int(s)%2019 == 0:
            cnt +=1
            
        r += 1
    if l == r:
        r +=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 2019 = 3 * 673 

def main():
     s = input()
     l = len(s)
     ans = 0

     for start in range(l):
          end = start + 4
          if end > l:
               break

          base = int(s[start:end])

          while(True):
               # print('check: ({}, {})'.format(start+1, end))
               if check_2019(base):
                    ans += 1
                    # print('({}, {}) is answer'.format(start+1, end))
                    next_end = end + 4
                    if next_end > l:
                         break
                    base = base * 1000 + int(s[end:next_end])
                    end = next_end

               else:
                    next_end = end + 1
                    if next_end > l:
                         break
                    base = base * 10 + int(s[end:next_end])
                    end = next_end

     print(ans)

def check_2019(n):
     if n % 2019 == 0:
          return True
     else:
          return False

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

S = input()
size_S = len(S)

initial = np.arange(0, size_S-3, 1)

count = 0
for i in range(len(initial)):
  last = np.arange(i+3, size_S, 1)
  for j in range(len(last)):
    number = int(S[initial[i]:last[j]+1])
    if number % 2019 == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

L = 0
for i in range(len(S)+1):
  for j in range(len(S)+1):
    if i<j:
      if int(S[i:j])>2018:
        if int(S[i:j])%2019==0:
          L += 1
print(L)

Submission status: Time Limit Exceeded

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import sys
import math

#S = int(input())
S = input()


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

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

print(count)

Submission status: Time Limit Exceeded

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

            if i>=3:
                c=int(s[i-3]+s[i-2]+s[i-1]+s[i])
                if c%2019==0:

                    b+=1
                    break

print(b)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    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:
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
        
ngram=[]
for i in range(4,len(s)):
    for j in range(len(s)-i+1):
         ngram.append(s[j:j+i])

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as C

S = input()
S_l = len(S)

count = 0
k = list(C(list(range(S_l)), 2))

for i in k:
    if abs(i[0] - i[1]) <= 2:
        pass
    else:
        n = int(S[i[0] : i[1] + 1])
        if n % 2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
chk_list = [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
n = len(s)
for i in range(0, n-3):
    for j in range(i+1, n+1):
        chk = s[i:j]
        chk = int(chk)
        if chk in chk_list:
            ans += 1
            #print(chk)
        else:
            pass

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s=input()
    cnt=0
    k=list(s)
    d=[0]*2019
    for i in range(len(k)):
        d[int(s[i:])%2019]+=1

    for i in range(2019):
        if i==0:
            cnt+=d[0]*(d[0]+1)//2
        if d[i]>1:
            cnt+=d[i]*(d[i]-1)//2
            #print(s[i:j+1])
    print(cnt)
    #print(d)
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
b=int(s)
a = [int(c) for c in s]
#print(len(a))
total=0
for i in range (0,len(a)-3):
  for j in range(4,len(a)+1):
    c=a[i:j]
    if(len(c)>3):
    	d=int("".join(map(str,c)))
    	if d%2019==0:
          total+=1
          
print(total)

Submission status: Time Limit Exceeded

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