Problem:


Score : 400 points

Problem Statement

Given is a string S consisting of digits from 1 through 9.

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Time Limit Exceeded

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

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
counter = 0
#iは切り出す文字列の長さ
for i in range(1,L+1):
    for j in range(L-i+1):
        if int(S[j:i+j]) % 2019 == 0:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
ans=0
N=len(S)
for i in range(N-3):
    for j in range(i+4,N+1):
        X=int(S[i:j])
        if X%2019==0:
            ans=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):
  x = int(S[i:])%2019
  A.append(x)
  y = A.count(x)
  if y >= 2:
    cnt += y-1

cnt += A.count(0)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = input()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0
firstFlag = True

for i in range(len(s)):
    for j in range(len(s)):
        if (i + 2) < j:
            if firstFlag:
                first = int(s[i:j+1]) % 2019
                firstFlag = False
            else:
                first = (first * 10 + int(s[j])) % 2019

            if first == 0:
                cnt += 1
    firstFlag = True

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys

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





print(ans)

Submission status: Time Limit Exceeded

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

ans=0

s_ans=[int(s[i:j+1]) for i in range(n) for j in range(i+3,n)]

print(sum(map(lambda x:x%2019==0,s_ans)))

Submission status: Time Limit Exceeded

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

print(m)

Submission status: Time Limit Exceeded

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

cnt = 0

for i in range(n+1):
  for j in range(i+1, n+1):
    if (int(str[i:j])%2019 == 0):
      cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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]) > 2018 :
            if int(n[a:b])%2019 == 0 :
                result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
l = len(s)
cnt = 0
iend = l-3
jend = l+1
for i in range(iend):
    jstart = i+4
    for j in range(i+4, jend):
        x = int(''.join(s[i:j]))
        if x % 2019 == 0:
            cnt+= 1

print(cnt)

Submission status: Time Limit Exceeded

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

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))
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:
S = input()[::-1]
S_len = len(S)  # <= 200000
ans = 0
for i in range(S_len+1):
    tmp = S[i:i+3]
    j = i + 3
    while j < S_len:
        tmp += S[j]
        if int(tmp[::-1]) % 2019 == 0:
            ans += 1
        j += 1

print(ans)

Submission status: Time Limit Exceeded

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

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(0, len(str(S)), 2):
            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:
S = input()
ret = 0
for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        if j == i + 4:
            sum_num = sum([int(s) for s in S[i:j]])
        else:
            sum_num += int(S[j-1])
        
        if sum_num % 3 == 0:
            test = int(S[i:j]) // 3
            if test % 673 == 0:
                ret += 1
print(ret)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
Yes = lambda boolean: print('Yes') if boolean else print('No')
YES = lambda boolean: print('YES') if boolean else print('NO')
aint = lambda: int(input())
ints = lambda: list(map(int, input().split()))
is_even = lambda x: True if x%2==0 else False
s = input()
n = len(s)
ans = 0
for i in range(0,n-3):
    for j in range(i+3,n):
        if int(s[i:j+1])%2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
S = input()
N = int(len(S))
cnt = 0
for i in range(N):
  for j in range(i+1,N+1):
    str = S[i:j]
    num = int(str)
    if(num % 3 == 0):
      if(num % 673 == 0):
        cnt = cnt + 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    #l：ループ回数減らす　　　h:jの代わり   
    l -= 1
    h = i+2

print(c)

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 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() #sys.stdin.readlineは最後が改行
n =len(s)

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

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

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


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

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

print(count)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import Counter
import itertools
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

S=SR()

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

Submission status: Time Limit Exceeded

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

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()
length = len(s)
n=int(s)
ans=0
if(length<4):
    print(0)
else:
    for i in range(length-3):
        for j in range(i+3,length):
            num=(n%10**(length-i))//10**(length-j-1)
            if num%2019==0:
                ans+=1
                break
    print(ans)

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)+1):
  for j in range(0,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()
ll = []
for i in range(1, 200000//2019+1):
    ll.append(str(2019*i))

cnt = 0
for l in ll:
    if s.count(l) > 0:
        for i in range(0, len(s) - len(l)+1):
            for j in range(len(l), len(s) + 1):
                if s[i:j] == l:
                    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
f = 0
end = [0 for i in range(len(s))]


for i in range(len(s)-3):
    st = s[i]+s[i+1]+s[i+2]
    for j in range(len(s)-3-i):
        st += s[i+3+j]
        if int(st)%2019 == 0:
            plus = 1 + end[i+3+j-1]
            ans += plus
            end[i+3+j] += plus
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#s:str, 2.0e+5
#print(200000//2019)
multiples = [2019*i for i in range(1, 100)]
s = int(input())
length = len(str(s))
ans = 0
for num in multiples:
    if str(num) in str(s):
        leng = len(str(num))
        for i in range(length-leng+1):
            if str(num) == str(s)[i:i+leng]:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
s=input()
count=0
Num=0
for n in range(len(s)-3):
    if s[n]==0:
        continue
    for m in range(len(s)-n-3):
        ss=s[n:n+m+4]
        Num=int(ss)
        #print(Num)
        if Num % 2019==0:
            count=count+1
            #print("Hit!")
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

length = len(S)
for i in range(0,len(S)-4):
  for j in range(i+4,i+4+length//2):
    if int(S[i:j+1]) % 2019 == 0 and j<length:
      cnt += 1

print(cnt)

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())
len_s = len(s)
list_s = []
for i in range(1, len_s + 1):
    for j in range(len_s):
        if j + i <= len_s:
            list_s.append(''.join(s[j:j + i]))
ans = 0
for i in range(1, 101):
    seq = str(2019 * i)
    ans += list_s.count(seq)
print(ans)

Submission status: Time Limit Exceeded

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

S = input().rstrip()

tmp = 0
ans = 0

for j in range(len(S) - 1, 2, -1):
    tmp = 0
    for i in range(j, -1, -1):
        tmp += int(S[i]) * pow(10, len(S) - 1 - i, 2019)
        tmp %= 2019
        if tmp == 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):
        if int("".join(S[i : j+1])) % 2019 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(map(int,input()))#"[1, 2, 3, 4, 5, 6, 7, 8, 9,1,1,2,3,4,5,6,7,8,9,1,2]"

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

print(ans)

Submission status: Time Limit Exceeded

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

# tmp=[]
# for i in range(2019,S+1,2019):
#     label=1
#     for ii in str(i):
#         if ii=='0':
#             label=0
#     if label:
#         tmp.append(i)
#     #tmp.append(2019*i)
# print(tmp)

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

Submission status: Time Limit Exceeded

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

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
S = input()
dp = [0] * (len(S)+1)

if int(S[:4]) % 2019 == 0:
    dp[4] += 1

for i in range(5,len(S)+1):
    for j in range(i-4+1):
        # print("i: {}, j:{}".format(i, j))
        # print("string: {}".format(S[i-4-j:i]))
        if int(S[i-4-j:i]) % 2019 == 0:
            dp[i] += 1
    dp[i] += dp[i-1]

print(dp[len(S)])

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
for k in range(4, len(S)+1):
    l = 0
    while(True):
        r = l+k-1
        if r >= len(S):
            break
        num = int(S[l:r+1])
        if num%2019 == 0:
            count += 1
        l += 1

print(count)

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+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:
s=list(map(int,list(input())))
# print(s)
count=0
s.reverse()
for i in range(len(s)):
	x=1
	f=0
	for j in range(i,len(s)):
		f+=s[j]*x
		x=x*10
		if f%2019==0:
			count+=1
		# print(f)
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(map(int, input()))
ls = len(S)
c = 0
for s in range(ls - 3):
    n = sum(S[s:s+3])
    for e in range(s + 3, ls):
        n += S[e]
        if n % 3 == 0 and int(bytearray(map(lambda x: x + 48, S[s:e+1]))) % 673 == 0:
            c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
input_s = input()
len_s = len(input_s)
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    r = 0
    lens = len(s)
    for i1 in range(lens - 3):
        tint = int(s[i1:])
        while tint >= 2019:
            tint2 = tint//10 - tint%10*1817
            while tint2 >= 18171:
                tint2 = tint2 // 10 - tint2 % 10 * 1817
            r += tint2 % 2019 == 0
            tint = tint //10
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
l = input()
count = 0
m = 2019
be = [0]*2019
new = [0]*2019
seped = []
for i in range(len(l)):
  A = int(l[i])
  be[0] += 1
  for j in range(2019):
    new[(j*10+A)%2019] = be[j]
  for j in range(2019):
    be[j] = new[j]
    new[j] = 0
  count += be[0]
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
end = len(S)
cnt = 0

for i in range(end-3):
    for j in range(i+3, end):
        st = ''.join(S[i:j+1])
        num = int(st)
        if num % 2019 == 0:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
sum = 0

a = []
point = 0
for i in range(100):
  point += 2019
  a.append(point)

for i in range(len(s) - 4):
  element = ''
  if(int(s[i]) != 0):
    element = s[i+1] + s[i+2]  
    for j in range(i+3,len(s)):
      element += s[j]
      if(int(s[i]+element) in a):
        sum += 1 

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#整数の入力
N = input()
N_list = list(N)

count = 0
for i in range(len(N_list)-4+1):
    nagasa = len(N_list)-i
    for j in range(len(N_list)-nagasa+1):
        ans =[]
        #jからj+nagasa
        ans = N_list[j:j+nagasa]
        #ans = [int(s) for s in ans]
        ans = "".join(ans)
        ans = int(ans)
        #print(type(ans))
        
        
        
        if(ans%2019==0):
            count +=1
            
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
##D - Multiple of 2019
S = str(input())
ck = [str(i) for i in range(1,200001) if i % 2019 == 0]
rc = 0
for i in range(len(S) - 4):
    for j in range(4 + i, len(S)+1):
        if S[i:j] in ck:
            rc += 1            
print(rc)

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:
def to10sin(listo):
  retval=0
  for i in listo:
    retval*=10
    retval += i
  return retval

#intarray=input()
intarray=[int(i) for i in input()]

nisennzyuukyuuwarikirecnt=0
#print(intarray)
#print(len(intarray))
#先頭
for i in range(0, len(intarray) - 3):
  #ケツ
  tmp = to10sin(intarray[i:i+3])#←あえて一個少なくしている
  #print(tmpsum)
  for j in range(i+3, len(intarray)):
    tmp *= 10
    tmp+=intarray[j]
    nisennzyuukyuuwarikirecnt+=(tmp%2019==0)
print(nisennzyuukyuuwarikirecnt)

Submission status: Time Limit Exceeded

Solution code:
s=int(input())
sst=str(s)
st=len(str(s))
ans=0
for i in range(st,4,-1): #指定文字数
  for j in range(0,st-i+1):
    if int(sst[j:j+i])%2019==0:
      ans=ans+1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=list(map(str,input()))
#print(S)
p=0;K="0"
for i in range((len(S)-3)):
  for j in range(i,len(S)+1):
    for k in S[i:j]:
      K=K+k
    if int(K)!=0 and int(K)%2019==0:
      p=p+1
    K="0"
print(p)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

s = input()
mod1 = 673
mod2 = 3

num1 = 0
num2 = 0
li1 = []
li2 = []
pw = 10
for i, e in enumerate(s, 1):
    num1 *= 10
    num1 += int(e)
    num1 %= mod1
    inv = pow(pw, mod1 - 2, mod1)
    li1.append(num1 * inv % mod1)

    num2 *= 10
    num2 += int(e)
    num2 %= mod2
    inv = pow(pw, mod2 - 2, mod2)
    li2.append(num2 * inv % mod2)

    pw *= 10

li = [0] + [10 * e1 + e2 for e1, e2 in zip(li1, li2)]
c = Counter(li)

ans = 0
for v in c.values():
    ans += v * (v - 1) // 2

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, stdout

s = stdin.readline() 

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

stdout.write(str(answer))

Submission status: Time Limit Exceeded

Solution code:
import sys
from io import StringIO
import unittest

def resolve():
    s = input()
    len_s = len(s)

    dp = [[0 for i in range(len_s+1)] for j in range(len_s+1)]

    for i in range(len_s):
        for j in range(i, len(s), 1):

            if int(s[i:j+1]) % 2019 == 0:
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j], dp[i][j] + 1)
            else:
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])

    print(dp[len_s][len_s])

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1817181712114"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """14282668646"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2119"""
        output = """0"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

def is_3bai(n):
    if n % 3 == 0:
        return True
    else:
        return False

def is_673bai(n):
    if n % 673 == 0:
        return True
    else:
        return False

def ketawa(string):
    res = 0
    for s in string:
        res += int(s)
    return res

sl = len(s)
res = 0
if sl >= 4:
    for i in range(sl - 4 + 1):
        sum_part = ketawa(s[i:i+3])
        for j in range(i + 3, sl):
            sum_part += int(s[j])
            if is_3bai(sum_part):
                part = s[i:j+1]
                if is_673bai(int(part)):
                    res += 1
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
dp = [ [0]*2020 for _ in range(len(S)+1) ]
dp[0][0] = 1
for i in range(1,len(S)+1):
    for j in range(2019):
        dp[i][(j*10+int(S[i-1]))%2019] += dp[i-1][j]
    if i != 1:
        dp[i][int(S[i-1])] += 1
ans = 0
for i in range(1,len(S)+1):
    ans += dp[i][0]
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]
	queue.append(S[i])

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

print(cnt)

Submission status: Time Limit Exceeded

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

print(res)