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:
import itertools
s = input()
s_li = list(s)
lee = len(s_li)

count = 0
#keta = list(itertools.combinations([i for i in range(lee)], 2))
keta = []
tmp = list(itertools.combinations([i for i in range(lee)], 2))
for t in tmp:
    if t[1] - t[0] >= 3:
        keta.append(t)
for k in keta:
    lk = list(k)
    #print(int(s[lk[0]:lk[1]+1]))
    if int(s[lk[0]:lk[1]+1])%2019 == 0:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

S = input()

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 = list(input().strip())
length = len(S)

def checkValue():
    count = 0
    for i in range(length):
        group = ""
        for j in range(i, length):
            group += S[j]
            if int(group) % 2019 == 0:
                count += 1
    print(count)
checkValue()

Submission status: Time Limit Exceeded

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

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:
str_list = str(input())
length = len(str_list)

cnt = 4
result = 0

for i in range(length-3):
    for j in range(length-cnt+1):
        if int(str_list[j:j+cnt])%2019 == 0:
            result += 1
    cnt += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

counter = 0
for start in range(len(S)):
    for end in range(start+3,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=str(input())
ans=0

for i in range(2019,2019*99+1,2019):
  for j in range(len(S)+1):
    for k in range(j+3, len(S)+1):
      if str(i) == S[j:k]:
        ans+=1
        
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
len_s=len(s)
dic=defaultdict(int)
ans=0
for i in range(len_s):
    if 2019-int(s[i]) in dic:
        ans+=dic[2019-int(s[i])]
    newdic=defaultdict(int)
    for j in dic.keys():
        newdic[(j*10+int(s[i])*10)%2019]+=dic[j]
    dic=newdic
    dic[int(s[i])*10]+=1
    # print(dic)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
#S = str(1817181712114)
ans = 0
 
for a in range(len(S) - 3):
	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 = list(input())
cnt=0
length = len(S)
for i in range(length-3):
    for j in range(i+3,length):
        if S[i] == '0':
            break
        target = int(''.join(S[i:j+1]))
        if target % 2019 == 0:
            cnt+=1
print(cnt)

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 len(k)==4 and int(k[0])%2 !=0:
            continue
        elif len(k)==4 and k[0]=="2" and k[1]!= "0":
            continue
        elif int("".join(map(str, k)))%2019 == 0:
            ans = ans + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    S = input()
    S_list = list(S)

    MIN_LEN = 4
    MAX_LEN = len(S_list) + 1
    count = 0

    for search_len in range(MIN_LEN, MAX_LEN):
        search_times = MAX_LEN - search_len
        for search_index in range(search_times):
            tmp = int("".join(S_list[search_index: search_index + search_len]))
            if tmp % 2019 == 0:
                count += 1

    print(count)

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import queue
import copy
import bisect#2分探索
from collections import deque #popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s): return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

S = int(input())
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=lambda x:x[1],reverse=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入

ss=str(S)
#print(ss)
ls=len(ss)
l=[0]*(ls+1)
for i in range(0,ls):
    l[i]=int(ss[i:ls])%2019
    #print(l[i])
#print(l)
l.sort()
#print(l)

cur=-1
ans=0
for i, li in enumerate(l):
    if cur==-1:
        cur=li
        count=1
    elif li==cur:
        count+=1
    else:
        ans+=count*(count-1)//2
        cur=li
        count=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

    ans_1 = sum(map(lambda x: (x*(x-1))//2, val))
    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:
s = input() #sys.stdin.readlineは最後が改行
n =len(s)

from collections import defaultdict
amari = defaultdict(lambda:0)
amari[0]=1
num=0

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

from math import factorial

ans = 0
for key,val in amari.items():
    if val>1:
        ans +=factorial(val) // factorial(2) // factorial(val - 2)

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
        i = j
        break
      else:
        pass

print(ans)

Submission status: Time Limit Exceeded

Solution code:
aaa = input()

b = 0
ans = []

a = 0
c = 2
for a in range(len(aaa)):
    for c in range(1,len(aaa)+1):
        b = aaa[a:c]
        if len(b) == 0:continue
        if int(b) % 2019 == 0:
            ans.append(b)

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
baisu=set([])

i=1
while 1:
    temp=2019*i
    if "0" not in str(temp):
        baisu.add(str(temp))
    
    if temp>200000:
        break
    i+=1

n=input()
cnt=0
for i in range(len(n)-3):
    for j in range(i+4,len(n)+1):
        if n[i:j] in baisu:
            cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys

def input():
    return sys.stdin.readline().strip()
def main():
    S = input()
    cnt = 0
    tmp = 0
    for i in range(len(S)):
        if i < tmp:
            continue
        for j in range(i+4,len(S)+1):
            if int(S[i:j]) % 2019 == 0:
                cnt += 1
                tmp = j -1
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(count)

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

print(ans)

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 = 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)]
        t = int(''.join(T))
        if t % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
mod = [0]*2019
mod[0] += 1#右端から見たときに2019の倍数がある場合に対応
for i in range(len(s)-1, -1, -1):
  mod[int(s[i:])%2019] += 1
ans =  0
for i in mod:
  ans += i*(i-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

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

while len(str(num)) <= len(s):
    i += 1;
    num = 2019 * i;
    ans += s.count(str(num));
    
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):
      sum=sum+1
      j=j+1
      for k in range(j+4,l+1):
        if(int(s[j:k])%2019 == 0):
          sum=sum+1
      break;

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#D
s = input()
count = 0
for left in range(len(s) - 3):
    for right in range(left + 3, len(s)):
        if int(s[left:right + 1]) % 2019 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
n = len(S)
nums = []
for i in range(n-4):
    for j in range(i+4, n):
        nums.append(int(S[i:j+1]))

hits = [i for i in nums if i % 2019 == 0]
print(len(hits))

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

print(b)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
#print(type(s[1]))
#from functools import reduce
#list = [1,2,3]
#n = reduce( lambda a,b:10*a+b, list)
#print(n)
l = len(s)
#print(l)
cnt = 0
ans = []
for i in range(0,l):
    for j in range(1,l+1):
        if i !=j and len(s[i:j])!=0:
            ans = (s[i:j])
            #print(ans)
            #ans = "".join(map(str, ans))
            #ans = int("".join(map(str, ans)))
            #print(ans)
            if int("".join(map(str, ans)))%2019==0:
                cnt +=1
print(cnt)
            #ans = s
            
            #"".join(map(str, s[i:j]))
            #s = int("".join(map(str, s[i:j])))
            
        
#s = "".join(map(str, s[i:j]))
#s = int("".join(map(str, s[i:j])))
#print(s)

Submission status: Time Limit Exceeded

Solution code:
S = input()
a = len(S)
L_1 = [0]
for i in range(a):
    L_1.append(int(S[:i+1])%3)
L_2 = [0]
for i in range(a):
    L_2.append(int(S[:i+1])%673)
k = 0
M = []
for j in range(a+1):
  M.append(10**j % 673)
#x文字目からy文字目
for x in range(1,a+1):
    for y in range(x,a+1):
        if L_1[y] == L_1[x-1]:
            if (L_2[x-1]*M[y-x+1] - L_2[y]) % 673 == 0:
                k += 1
print(k)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
c=0
for i in range(1100000000):
    if str(2019*i) in S:
        c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
S=input()
n=0
x,y=len(S),int(S)
for i in range(x-3):
    for j in range(i+3,x):
        s=y%10**(x-i)-y%10**(x-j-1)
        if s%2019==0:
            n+=1
print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0
while len(s) > 2:
  ns = int(s)
  while ns > 2019:
    jy = ns % 2019
    if jy == 0:
      cnt += 1
    ns = ns // 10
  s = s[1:]

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

print(count)

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

# 24228
# 2422
# 24228

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:
S = list(input())
len_size = len(S)

queue = []
cnt = 0

for i in range(len_size):

	# キューの更新
	for j in range(len(queue)):
		queue[j] += S[i]

		# 2019で割れるかチェック
		tmp_val = int(queue[j])
		if(tmp_val % 2019 == 0):
			cnt += 1
			queue[j] = ""

	queue.append(S[i])	

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

l=list()
for i in range(0,len(s)+1):
    for j in range(0,len(s)+1):
        if i >= j:
            continue

        l.append(int(s[i:j]))

ans = 0
for num in l:
    if num % 2019 == 0:
        ans+=1

print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
import sys

s = input()
ans = 0
if int(s) < 2019:
    print("0")
    sys.exit()
else :
    length = len(s)
    statement = ""
    for l in range(length):
        r = 0
        while r < (length+1) :
            if r == 0:
                r = l+3
                continue
            if l == r:
                r += 1
            cand = int(s[l:r])

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
s = list(map(int,input()))
n = len(s)
ans = 0
mod = 2019

for i in range(n-3):
    nn = (s[i]*1000+s[i+1]*100+s[i+2]*10+s[i+3])%mod
    if nn == 0:
        ans += 1
    for j in range(i+4,n):
        nn = (nn*10+s[j])%mod
        if nn == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    charlim = len(s)
    total = 0
    unit = 2019
    for charnum in range(5, charlim+1):
        for i in range(charlim-charnum+1):
            cand = int(s[i:i+charnum])
            if cand % 2019 == 0:
                total += 1
    print(total)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
N=len(S)
M = [0 for _ in range(2019)]
# 0は予め右端に一個あるとする
M[0]+=1
for i,s in enumerate(S):
    new = int(S[i:])%2019
    M[new] += 1
count = 0
for m in M:
    count += int(m*(m-1)/2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
def naive_cmb(n, r):
    if r < 0 or r > n:
        return 0
    return (math.factorial(n) // math.factorial(r)) // math.factorial(n-r)

S = input()

mod = [0] * (2019+1)

tmp = ""
for i in range(1, len(S)+1):
    tmp = int(S[-i] + str(tmp))
    mod[tmp % 2019] += 1

ans = mod[0]

for i in range(1, 2020):
    if mod[i] >= 2:
        ans += naive_cmb(mod[i], 2)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a = 0

for i in range(n - 3):
  b = n - i - 4
  e = n - i
  while b >= 0:
    if int(s[b:e]) % 2019 == 0:
      a += 1
    b -= 1

print(a)

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

Submission status: Time Limit Exceeded

Solution code:
#D

#デバッグ
debug=1
def pront(*n):
    if debug==1:
        print(n)
        
#10**9+7を底とした処理

base=10**9+7

def add(a,b):#a+b
    return (a+b)%base

def sub(a,b):#a-b
    return (a-b)%base

def multi(a,b):#a*b
    return (a*b)%base

def exp(a,b):#a**b
    x=1
    c=a
    d=b
    while d!=0:
        if d%2==1:
            x=multi(x,c)
        c=(c**2)%base
        d=d//2
    return x

def div(a,b):#a/b
    return(multi(a,exp(b,base-2)))

#入力

S=input()


#処理
L=len(S)
x=0
for i in range(5,L+1):
    for j in range(L-i+1):
        if int(S[j:j+i])%2019==0:
            x+=1
print(x)

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
#s = '2119'
pair=0

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

print(pair)

Submission status: Time Limit Exceeded

Solution code:
n = input()
count = 0

length = len(n)

if length >= 4:
    for i in range(3, length):# i=3~len-1
        for j in range(i-2):# j=0~i-3       
            if int(n[j: i+1]) % 2019 == 0:
                count = count + 1

print(count)

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, 10001):
        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 = input()

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

bai2019 = []

ans = 0

#for i in range(1,100):
    #bai2019.append(2019*i)

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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input().strip())
length = len(S)
check = ""
for i in range(length):
    check += S[i]

def checkValue():
    count = 0
    for i in range(length):
        group = ""
        for j in range(i, length):
            group += S[j]
            if int(group) % 2019 == 0:
                count += 1
    print(count)
checkValue()
    
def dfs(total, i, j, group):
    if (len(group) != 0 and int(group) % 2019 == 0):
        print(i, j, group)
        return 1
    if i > j:
        return 0
    if (i > length-1 or j > length-1):
        return 0
    if len(group) != 0 and int(group) > int(check):
        return 0    
    return dfs(total, i+1, j, group+S[i]) + dfs(total, i, j+1, group+S[j])

#print(dfs(0, 0, 0, ""))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
a = 0
for i in range(len(s)):
  j = i+3
  flag = 0
  while(j<len(s)):
    nn = int("".join(s[i:j+1]))
    if flag==1 and s[j]!=0:
      break
    if nn%2019==0:
      a+=1
      flag = 1
      #print(nn)
    j+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:

def main():
    S = input()
    cnt = 0

    #d = []
    #for i in range(2019, 10**20000):
    #    if i % 2019 == 0:
    #        d.append(str(i))
    
    #print(d)

    if len(S) < 4:
        return 0
    
    #for i in d:
    #    cnt += S.count(i)
    
    for j in range(4, len(S)):
        for i in range(0, len(S)-j+1):
            num = int(S[i:i+j])
            if num % 2019 == 0:
                cnt += 1
    return cnt
    

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

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
from collections import defaultdict
D = defaultdict(int)
ans=0
for i in range(len(S)):
    d=defaultdict(int)
    d[int(S[i])]=1
    for k,v in D.items():
        d[(k*10+int(S[i]))%2019]+=v
    ans+=d[0]
    D=d
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

checked = {}
count = 0

for i in range(len(S)):
    for j in range(i, len(S)+1):
        s = S[i:j]
        #print(s)
        if s:
            s = int(s)
            #print(s)
            if s in checked:
                count += checked[s]
            else:
                test = s % 3
                if test == 0:
                    t = s // 3
                    if t % 673 == 0:
                        count += 1
                        checked[s] = 1
                        #print(s)
                    else:
                        checked[s] = 0

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = len(s)

ans = 0

su = [0]

for r in range(1, n-2):
	for l in range(r+3, n+1):
		t = int(s[-l:-r]+s[-r])
		if t%673 == 0:
			if t%3 == 0:
				ans += 1

print(ans)

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
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
nums=[0]*200000
zero=0
tmp=''
for i in range(N-1,-1,-1):
    tmp=S[i]+tmp
    div=int(tmp)%2019
    if div==0:
        zero+=1
    nums[div]+=1
    
ans = zero
for v in nums:
    if v<2:
        continue
    ans += v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
S = list(map(int,list(input())))
N = len(S)
ans = 0
pre_d = defaultdict(int)
for i in range(N):
    new_d = defaultdict(int)
    for k, v in pre_d.items():
        new_d[(10 * k + S[i]) % 2019] += v
    new_d[S[i]] += 1
    ans += new_d[0]
    pre_d = new_d
print(ans)

Submission status: Time Limit Exceeded

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

print(sum([int(s[i:j+1])%2019==0 for i in range(n) for j in range(i+3,n)]))

Submission status: Time Limit Exceeded

Solution code:
N=input()
lis=[]
for i in range(len(N)-4):
	for j in range(len(N)-i-3):
		lis+=[int(N[i:i+4+j])]
print(len(list(filter(lambda x:x%2019==0,lis))))

Submission status: Time Limit Exceeded

Solution code:
# ABC164 D

def main():
    s = input()
    count = 0
    #results = []

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
l=len(S)
z=0
for x in range(l):
    for y in range(l-x-3):
        T=S[x:x+y+4]
        t=int(T)
        
        if t%2019==0:
            z+=1
print(z)