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())
cnt=0
for i in range(len(s)):
  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())
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = int(S)
list = []
for i in range(1, 10**100000):
    num = 2019*i
    if num <= int(s):
        list.append(2019*i)
    else:
        break
        
count = 0
for i in list:
    if str(i) in S:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s_str = input()
s = list(s_str)

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

Submission status: Time Limit Exceeded

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

# 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 += S.count(b)
#     if S.count(b) != 0:
#         print(b)
#         print(S.count(b))

for i in range(N-3):
    for j in  range(i+3,N):
        s = S[i:j+1]
        if s in baisuu:
            counter += 1


print(counter)

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
length = len(S)
for i in range(length):
    seq = S[i]
    for k in range(i+1, length):
        seq += S[k]
        if int(seq) % 2019 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
x=0
for j in range(len(s)):
    count=0
    for i in range(len(s)-j-4):
        a="".join(s[j:j+count+5])
        if int(a) % 2019 ==0:
            x+=1
            count+=1
        else:
            count+=1
print(x)

Submission status: Time Limit Exceeded

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



if __name__ == '__main__':
    main2()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

S = input()
N = len(S)

S_i = []
for i in range(len(S)):
    S_i.append(int(S[i:])%2019)

S_cnt = Counter(S_i)

ans = 0
for k in S_cnt.keys():
    if k==0:
        ans += S_cnt[k]
    elif S_cnt[k]>1:
        ans += S_cnt[k]*(S_cnt[k]-1)/2

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
S=input()

ans=0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
k=2019
numMultiples = int(0)
seenRemainders = [0]*n
for i in range(n):
    remainder = int(0)
    prefixesFound = int(0)
    for j in range(i,n):
        remainder = (10 * remainder + int(s[j])) % k
        if remainder == 0:
            prefixesFound+=1
        if seenRemainders[j] == remainder:
            break
        seenRemainders[j]=remainder
        
    numMultiples += (prefixesFound * (prefixesFound + 1)) // 2
print(numMultiples)

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
if N<4:
  print(0)
  exit(0)
M=2019
X=[0]+[int(S[i])*pow(10,N-1-i)%M for i in range(N)]
import itertools
X = list(itertools.accumulate(X))
ans=0
x=[]
def search(l,r,X,N):
  _=0
  while r<N+1:
    if (X[l]-X[r])%M==0:
      _+=1
    r+=1
  return _
  
for l in range(N-2):
  if l in x:
    continue
  for r in range(l+4,N+1):
    if (X[l]-X[r])%M==0:
      x.append(r)
      _=search(r,r+4,X,N)
      ans+=(1+_+_)
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

for i in range(len(S) - 4):
  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:
#MLE注意！ not は使わず !=
#0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    n = input().rstrip()
    n = n[::-1]
    res = [0]*2019
    res[0] += 1
    b = 0
    for i in range(len(n)):
        a = int(n[i])
        b += a*(10**i)%2019
        b %= 2019
        res[b] += 1
    ans = 0
    for i in res:
        if i>=2:
            ans += i*(i-1)//2
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
number = str(input())
keta = len(number)

match = 0

for start in range(1, keta):
  for end in range(start, keta+1):
    kazu = int(number[start-1:end])
    if kazu % 2019 == 0:
      match += 1
print(match)

Submission status: Time Limit Exceeded

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

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

print(N)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc164/tasks/abc164_d
# -*- coding: utf-8 -*-
S = list(input())
ans = 0
for i in range(len(S)-3):
  for j in range(i+4,len(S)+1):
    number = [S[k] for k in range(i,j)]
    if  int("".join(number)) % 2019 == 0:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
num = input()
lnum = len(num) + 1
nums = []
for i in range(0, lnum):
	for j in range(i + 1, lnum):
		nnum = ""
		for k in range(i, j):
			nnum += num[k]
		if(int(nnum) % 2019 == 0):
			nums.append(nnum)
print(len(nums))

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count=0
for i in range(N-3):
    for j in range(i+3,N):
        dammy = int(''.join(S[i:j+1]))
        if dammy%2019==0:
            count+=1

print(count)

Submission status: Time Limit Exceeded

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

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])
    r = num % 2019
    while(j<N):
        if r >= 10000:
            r = r % 2019
        if r in [0, 2019, 4038, 6057, 8076]:
            cnt += 1
        r = r * 10 + int(S[j])
        j += 1
    if r % 2019 == 0:
        cnt += 1
    i += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
i = 0
j = 0
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = list(S)
count = 0
for i in range(len(s)):
    j = 4
    while i+j <= len(s):
        s2 = int(''.join(s[i:i+j]))
        if s2%2019 == 0:
            count += 1
            j += 5
        else:
            j += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
N = int(input())
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

S = input().rstrip()

counter = 0
for l_index in range(len(S) - 4):
    atama = int(S[l_index:l_index+2])
    if atama % 2 != 0:
        continue
    else:
        r_index = 4
        while True:
            saigo = l_index + r_index
            if saigo > len(S):
                break
            kouho = int(S[l_index:saigo])
            if kouho % 2019 == 0:
                counter += 1
            r_index += 1


print(counter)


# def main():

# if __name__ == '__main__':
#     main()

Submission status: Time Limit Exceeded

Solution code:
a = input()

def int2019(s):
    modTable = [0] * 2019
    total = 0
    for i in range(len(s)):
        nextTable = [0] * 2019
        for j in range(2019):
            nextTable[(j * 10 + int(s[i])) % 2019] = modTable[j]

        nextTable[int(s[i]) % 2019] += 1
        total += nextTable[0]
        modTable = nextTable

    return total


print(int2019(a))

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
# s = list(x)

count = 0
# l = []

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

print(count)
# print(l)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

cnt = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#create date: 2020-04-26 21:06

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    s = ni()
    n = len(str(s))
    now = 0
    m = [0] * 2019
    for i in range(n):
        now = (s % 10**(i+1)) % 2019
        #print(now)
        m[now] += 1
    ans = m[0]
    for mi in m[1:]:
        ans += (mi-1) * mi //2
    print(ans)

    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

li = [0]
for i in range(L):
    li.append(li[-1]+int(S[i]))

li.append(li[-1])

for i in range(0,L-3):
    for j in range(i+4,L+1):
        if (li[j]-li[i]) % 3 == 0:
            integer = int(S[i:j])
            if integer % 673 == 0:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    import collections
    def input():
        return sys.stdin.readline()[:-1]
    S=input()
    result=0
    for i in range(len(S)-3):
        for j in range(i+4,len(S)+1):
            a=S[i:j]
            if int(S[i:j])%2019==0:
                result+=1
    print(result)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
cnt = 0
for i in range(N):
    for j in range(i+1, 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:
test=input();
#print(int(test[0:21])/10)
ans=0;
for i in range(len(test)-3):
    for j in range(len(test)-3-i):
        if(int(test[i:i+4+j])%2019==0):
            ans=ans+1;
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10
for i in range(1,N,1):
    S_num[N-i-1] = S_num[N-i] + (tmp)*S_num[N-i-1]
    tmp=tmp*10
for i in range(0,N,1):
    X = S_num[N-i-1] % 2019
    if X==0:
        counter+=1
    counter += mem_mod[X]
    mem_mod[X] += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------

S = input()
N=len(S)

#l=0
#r=4
#print(S[l:r])

ans=0
for l in range(N):
	for r in range(l+4,N+1):
		i = int(S[l:r])
		if i<2019: continue
		if (i % 2019) == 0:
			ans += 1
#			p("l,r =", l,r)


print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
S=input()
N=len(S)
pos=set()
nums=defaultdict(int)
tmp=''
for i in range(N-1,-1,-1):
    tmp=S[i]+tmp
    div=int(tmp)%2019
    pos.add(div)
    nums[int(tmp)%2019]+=1
    
ans = nums[0]
for p in pos:
    if nums[p]<2:
        continue
    ans += nums[p]*(nums[p]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#d
N = int(input())
s  = str(N)
a =[]

def func(string,p):
    count=0
    for x in range(len(string)-len(p)+1):
        if string[x:x+len(p)]==p:
            count+=1
    return count

for i in range(1,100000):
    a.append(str(2019*i))
if len(s)<4:
    print(0)
else:
    ans=0
    for j in a:
        ans+=func(s,j)
    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+3, len(S)):
        if int(S[i:j+1]) % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    N = len(S)

    res = 0

    for d in range(4,N):
        for i in range(N-d+1):
            temp = S[i:i+d]
            temp = int(temp)
            if temp % 2019 == 0:
                res += 1

    print(res)



main()

Submission status: Time Limit Exceeded

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

s = input()
length = len(s)

counter = 0

for i in range(length):
    if length - i < 4 and s[-4:] != '0000' and s[-3:] != '000' and s[-2:] != '00' and s[-1:] != '0':
        continue
    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:
cnt = 0
S = input()  
for left in range(len(S)-3):
    int_s = int(S[left:left+4])
    
    if int_s % 2019 == 0:
        cnt += 1
    for right in range(left+4,len(S)):
        int_s = int_s * 10 + int(S[right])
        if int_s % 2019 == 0:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
  s = list(input())
  count = 0
  for j in range(4,len(s)+1):
    for i in range(len(s) - j + 1):
      if int(''.join(s[i:i + j])) % 2019 == 0:
        count += 1
      if len(s) - j < 4:
        break

  print(count)




if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0

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

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

print(ans)

Submission status: Time Limit Exceeded

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

N = len(s)
ans = 0
S =""
for i in range(N):
    S += s[i]
    n = len(S)
    if n > 3:
        for k in range(n-1):
            n3 = S[k:]
            n2 = len(n3)
            if  n2 > 3:
                if int(n3) %2019 == 0:
                    ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():

    S = input()

    rem = [0 for _ in range(2019)]
    ans = 0
    for i in range(len(S)):

        temp = [0 for _ in range(2019)]
        temp[int(S[i])] += 1

        for j in range(2019):
            temp[(j*10 + int(S[i])) % 2019] += rem[j]

        rem = temp
        ans += temp[0]

    return ans


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

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):
    num = 0
    for j in range(i+3, n):
        if not num:
            num = atoi(s[i:j+1])
        else:
            num = num*10 + ord(s[j]) - ord('0')
        if num % 2019 == 0:
            c += 1
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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


def solve(S: int):
    # cnt = 0
    # for i in range(len(str(S))):
    #     for j in range(i + 1, len(str(S))):
    #         if not int(str(S)[i:j]) % 2019:
    #             cnt += 1
    # print(cnt)
    cnt = 0
    l = filter(lambda x: '0' not in str(x), range(2019, 200000, 2019))
    for i in l:
        for j in range(len(str(S))):
            if len(str(i)) - 1 + j > len(str(S)) - 1:
                continue
            if str(S)[j:len(str(i)) + j] == str(i):
                cnt += 1
    print(cnt)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    s = input()

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


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=int(input())
n=len(str(s))
 
ans=0
for L in range(5,n+1):
  for i in range(n-L+1):
    if ((s//(10**(n-L-i)))%(10**L))%2019==0:
      ans+=1
 
print(ans)

Submission status: Time Limit Exceeded

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

c = 0
for i in range(n-4):
  t = ''
  for j in range(i,n):
    t = t + s[j]
    k = int(t)
    if k%2019 == 0:

      c += 1
      
print(c)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

s = str(input())
n = len(s)
count = 0

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
CHECK=[0 for i in range(2021)]
ans=0
S=int(s)
for i in range(len(s)):
    temp=(S%pow(10,i+1))%2019
    if temp==0:
        ans+=1
    elif CHECK[temp]==0:
        CHECK[temp]=1
    else:
        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)

cnt += A.count(0)
for i in range(s):
  if A.count(A[i]) == 2:
    cnt += 0.5
print(int(cnt))

Submission status: Time Limit Exceeded

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

dic = { 0: True }
ans = 0
for i in range(L):
  x = int(S[i:])%2019
  if x in dic: ans += 1
  else: dic[x] = True

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans=0
a=[s[i:] for i in range(len(s)-3)]

for i in a:
    while len(i)>=4:
        if int(i)%2019==0:
            ans+=1
        i=i[:-1]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
c = 0

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ll = []
for i in range(1, 200001//2019+2):
    ll.append(str(2019*i))

cnt = 0
for i in range(0, len(s)-3):
    for j in range(4, len(s)+1):
        for l in ll:
            if s[i:j] == l:
                cnt += 1
                # print(cnt, s[i:j])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
dp=[[0] * (n+1) for i in range(n+1)]
count=0
for i in range(n):
    for j in range(i+1,n+1):
        dp[i][j]=pow(dp[i][j-1]*10+int(s[j-1]),1,2019)
        if dp[i][j]==0:
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
temp = []
for i in range(len(S)+1):
    for j in range(len(S)+1):
        if i!=j and i <= j:
           # print(S[i:j])
            if int(S[i:j]) % 2019 == 0:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

S = str(input())

n = len(S)

cnt = 0
for i in range(n+1):
    for j in range(i+3, n+1):
        s = S[i:j]

        if int(s) % 2019 == 0:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def D():
    S = input()
    length = len(S) 
    numMultiples = 0
    seenRemainders = [set() for i in range(length)]
    for i in range(length):
        remainder = 0
        prefixesFound = 0
        for j in range(i, length):
            remainder = (10 * remainder + int(S[j])) % 2019
            if remainder in seenRemainders[j]:
                break
            seenRemainders[j].add(remainder)
            if remainder == 0:
                prefixesFound += 1
        numMultiples += prefixesFound * (prefixesFound + 1) // 2
    print(numMultiples)
D()

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):
        roop_num_end = roop_num - start
        for end in range(roop_num_end-4):
            end += start
            end += 4
            num = int(inputs[start:end+1])

            if num % 2019 == 0:
                cnt += 1


    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
a = 0
for i in range(n):
  for j in range(i+4,n+1):
    x = s[i:j]
    y = int(x)
    if y % 2019 == 0:
       a += 1

print(a)

Submission status: Time Limit Exceeded

Solution code:
import collections
def main():
    s=input()
    ans=0
    res=[0]*len(s)
    for i in range(len(s)):
        res[i]=int(s[len(s)-1-i:])%2019
    cnt=collections.Counter(res)
    for i in range(len(cnt)):
        ans+=cnt.most_common()[i][1]-1
        if cnt.most_common()[i][0]==0:
            ans+=1
    print(ans)
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
s = input()
ans = 0
prev = 0

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

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

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

Submission status: Time Limit Exceeded

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

sum=0

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

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
l=len(S)
t=0
p=0
m=[[0] * l for i in range(l)]

for i in range(l):
    for j in range(l-i):
        m[i][j]=int(S[i])*(10**j)%2019

for i in range(l-1,2,-1):

    p=0
    for j in range(i+1):
        p=(p+m[i-j][j])%2019

        if p==0:

            t+=1

print(t)

Submission status: Time Limit Exceeded

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