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 = input()
sl = len(S)
x = 0
for i in range(sl):
    for j in range(i+1, sl + 1):
        if int(S[i:j]) % 2019 == 0:
            x +=1

print(x)

Submission status: Time Limit Exceeded

Solution code:
S=input()
lis=[]
Z=0
for i in range(1,100):
        Z=2019*i
        lis.append(Z)
cnt=0
for i in range(len(S)-4):
    for j in range(i+4,len(S)):
        if int(S[i:j+1]) in lis:
            cnt+=1
        else:
            continue
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

c = 0
"""
for i in range(len(s)-3):
    for j in range(i+4,len(s)+1):
        print(int(s[i:j]))
        if (int(s[i:j])%2019)==0:
            c += 1
            print("a")
"""
i = 0
while i < (len(s)-3):
    j = i+4
    while j < (len(s)+1):
        #print(int(s[i:j]))
        if (int(s[i:j])%2019)==0:
            c += 1
            #print("a")
            j += 3
        j += 1
    i += 1
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def Count(s,sub):
    j=len(sub)
    n=len(s)
    index=0
    count=0
    while index+j<=n:
        if s[index:index+j]==sub:
            count+=1
        index+=1
    return count         


s=input()
n=len(s)
count=0
index=1
value=0

while index*2019<=999999:
    value=str(index*2019)
    count+=Count(s,str(value))
    index+=1     
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
res = 0
m = 3

while n - m >= 1:
    for i in range(n - m):
        if int(s[i:i+m+1]) % 2019 == 0:
            res = res + 1
    m = m + 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    S = input().rstrip()

    result = 0
    length = len(S)
    if length < 4:
        print(result)
        return

    for keta in range(4, length+1):
        for i in range(length - keta + 1):
            j = i + keta
            if int(S[i:j]) % 2019 == 0:
                result += 1
    
    print(result)



if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())[::-1]
N = len(S)
M = [(int(S[i])*10**i)%2019 for i in range(N)]
SS = [M[0]]
for i in range(1,N):
    
    SS.append((SS[-1]+M[i])%2019)
count = [0]*2019
for i in range(N):
    count[SS[i]] += 1

ans = 0
for c in range(len(count)):
    if c==0:
        ans += (count[c] * (count[c] + 1)) // 2
    ans += (count[c] * (count[c] - 1)) // 2

print(ans)

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()
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])%2019==0:
            cnt+=1

        
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
multi_2019 = [str(2019 * a) for a in range(s//2019 +1)]
ans = 0
s=str(s)
for i in multi_2019:
    if i in s:
       ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S0 = int(input())
total = 0
S = []
while S0 > 0:
    S.append(S0%10)
    S0 //= 10
S.reverse()
for i in range(len(S)-2):
  n = S[i]*100 + S[i+1]*10 + S[i+2]
  #count = S[i] + S[i+1] + S[i+2]
  for j in range(i+3,len(S)):
    n = n*10 + S[j]
    #print(n)
    if n % 2019 == 0:
      total += 1
print(total)

Submission status: Time Limit Exceeded

Solution code:
S = input()

dp = [0 for i in range(2019)]

ans = 0
for i in S:
  d = int(i)
  temp = [0 for i in range(2019)]
  for j in range(2019):
    next_j = (10 * j + d) % 2019
    temp[next_j] += dp[j]
  temp[d] += 1
  ans += temp[0]
  ## Add new letter
  for j in range(2019):
    dp[j] = temp[j]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    n = len(S)
    if n < 4:
        print(0)
        return
    ans = 0
    for i in range(n-3):
        s  = int(S[i])
        for j in range(i+1, n):
            s += int(S[j])
            if s % 3 == 0:
                if int(S[i:j+1]) % 673 == 0:
                    ans += 1
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
S=input()

N=len(S)
count=0

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
d = [0] * l

for i in range(2, l - 1):
    cnt = 0
    for j in range(i):
        if int(s[j:i+2]) % 2019 == 0:
            cnt += 1
    d[i + 1] += d[i] + cnt

print(d[l - 1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
s = input()
tmp = []
num = ["0"]
for char in s:
    tmp.append(char)
    num.append("".join(tmp))

c = 0
for m, n in combinations(num, 2):
    if m == "0":
        check = int(n)
    else:
        check = int(n) - int(m) * 10 ** (len(n) - len(m))
    if check % 2019 == 0:
        c += 1

print(c)

Submission status: Time Limit Exceeded

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

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

print(answer)

Submission status: Time Limit Exceeded

Solution code:
N=input()
count=0
for i in range(len(N)-4):
    for j in range(4,len(N)+1):
        if len(N[i:j])<4:
            continue

        temp=int(N[i:j])
        if temp%2019==0:
            count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0

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

Submission status: Time Limit Exceeded

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

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

print(res)

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):
  #ケツ
  tmpsum = sum(intarray[i:i+3])#←あえて一個少なくしている
  #print(tmpsum)
  for j in range(i+3, len(intarray)):
    tmpsum+=intarray[j]
    #print(tmpsum)
    if tmpsum % 3 == 0:
      #print(to10sin(intarray[i:j+1]))
      #print(intarray[i:j+1])
      nisennzyuukyuuwarikirecnt+=(to10sin(intarray[i:j+1])%2019==0)
print(nisennzyuukyuuwarikirecnt)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
for i in range(0, 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:
n=''
count = 0
s = input()
for i in range(len(s)+1):
    for j in range(i+1,len(s)+1,4):
        n = s[i:j]
        if(int(n)%2019 == 0):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0

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

print( cnt )

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S= str(input())
S = S +"0"
ans = 0
for i in range(len(S)):
    for j in range(len(S)-i):
        T = S[i:(-1*j)]
        if len(T) >0 :
            T = int(T)
            if T % 2019 ==0:
                ans = ans+1

print(ans)

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

			cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()

from collections import defaultdict
d=defaultdict(int)

for i in range(len(S)):
    a=S[i:]
    b=int(a)
    d[b%2019]+=1

ans=0

for k,v in d.items():
    if k==0:
        ans+=v
    else:
        ans+=v*(v-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s) 
ls = [0]*2019
ls[0]+=1
for i in range(n):
  ls[int(s[i:]) % 2019] += 1

ans = 0
for a in ls:
  ans += a*(a-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

keta = len(s)

count = 0

for i in range(keta - 3):
  for j in range(i + 3, keta):
    N = 0
    for k in range(j - i + 1):
      N += int(s[i + k]) * (10 ** (j - i - k))
    if (N % 2019 == 0):
      count += 1
      
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
S.reverse()
N=len(S)
R=[0]*N
m=2019
K=0

for i in range(N):
    K+=int(S[i])*10**i
    R[i]=K%m
d={}
for i in range(2019):
    d[i]=0

for i in range(N):
    d[R[i]]+=1
ans=0
for i in range(2019):
    if i == 0:
        ans += d[i]
        ans +=d[i]*(d[i]-1)//2
    else:
        ans +=d[i]*(d[i]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = tuple(input())

ans = 0
tmp = 10**9
for i in range(len(s)-3):
    if i == tmp:
        pass
    for y in range(i+3, len(s)):
        if int("".join(s[i:y+1])) % 2019 == 0:
            ans += 1
            tmp = y+1
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=[str(x) for x in input()]

sum=0
for i in range(len(s)-4):
    for j in range(i+4,len(s)):
        t=''.join(s[i:j+1])
        if int(t)%2019==0:
            sum+=1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
s = input()
keta = len(s)
if keta < 4:
    print(0)
    exit()
ans = 0
list_s = list(s)

for i in range(keta-3):
    for j in range(3,keta):
        tmp = s[i:j+1]
        if tmp!='' and int(tmp) % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
digits = input()
ctr = 0
for i in range(4,len(digits)):
	for j in range(0,len(digits)):
		tmp = digits[j:j+i]
		tmpint = int(tmp)
		if tmpint > 2019 and len(tmp) >= i and tmpint % 2019 == 0:
			ctr += 1
print(ctr)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = list(input())
    n = len(s)
    for i in range(n):
        s[i] = int(s[i])
    dp = [[[0 for _ in range(2019)] for _ in range(2)] for _ in range(n+1)]
    for i in range(n):
        for j in range(2019):
            dp[i+1][1][j] += dp[i][0][j]
            dp[i+1][1][j] += dp[i][1][j]
            dp[i+1][0][((j*10)+s[i])%2019] += dp[i][0][j]
        dp[i+1][0][s[i]] += 1
    print(dp[n][0][0]+dp[n][1][0])
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
x=input()
list = list(map(int, x))

tmp=0
ans=0
for i in range(len(list)-3):
	tmp=(list[i]*1000+list[i+1]*100+list[i+2]*10+list[i+3])%2019
	if tmp==0:
		ans=ans+1
	if i+4<=len(list):
		for j in range(i+4,len(list)):
			tmp=(tmp*10+list[j])%2019
			if tmp==0:
				ans=ans+1
				
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_int = int(s)
ans = 0


def is_2019(num):
    if num % 2019 == 0:
        return 1
    else:
        return 0


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
l = list(input())
amari = [0]*len(l)
mod = 2019
import math
for i in range(len(l)):
    amari[i] = int(l[i])*(10**(len(l)-1-i)) % mod
rui = [0]*len(l)
rui[len(l)-1] = amari[-1]
for i in range(len(l)-2,-1,-1):
    rui[i] = (rui[i+1] + amari [i])%mod
count = [0]*2020
for i in range(len(l)):
    count[rui[i]] += 1
ans = 0
for i in range(1,2020):
    if count[i] == 0 or count[i] == 1:
        continue
    ans += math.factorial(count[i]) // (math.factorial(count[i]-2)*2)
ans += count[0]
print(ans)

Submission status: Time Limit Exceeded

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

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

     for i in range(3, l):
          checker = list()
          for j in range(l-i):
               # print('({}, {})'.format(j+1, j+i+1))
               check = s[j:j+i+1]
               if check in checker:
                    ans += 1
               else:
                    check_int = int(check)
                    if check_int % 2019 == 0:
                         ans += 1
                         checker.append(check)

     print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
n = len(S)
if n < 4:
    print(0)
else:
    Ss = []
    for i in range(0,n-3):
        for j in range(i+3,n):
            Ss.append(int(S[i:j+1])%2019 == 0)
    print(sum(Ss))

Submission status: Time Limit Exceeded

Solution code:

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

l = len(s)
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = [int(s[0])]
for i in range(1,len(s)):
    l.append(l[-1]+int(s[i]))
c=0
for i in range(3,len(l)):
    s1 = l[i]
    if(l[i]%3==0 and l[i]>=12 and l[i]<=21):
        c+=1
    j=0
    while((i-j)!=3):
        s1-=l[j]
        j+=1
        if(s1%3==0 and s1>=12 and s1<=21):
            c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ansl = [0]*2019
for i in range(len(S)):
    ansl[int(S[-i-1:])%2019]+=1
ans = (ansl[0]+1)*ansl[0]/2
for i in range(1, 2019):
    ans+=ansl[i]*(ansl[i]-1)/2

print(int(ans))

Submission status: Time Limit Exceeded

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    from collections import Counter
    S=sys.stdin.readline().strip()
    L=[0]*len(S)

    now=0
    for i in range(len(S)):
        now+=int(S[-i-1])*10**i
        L[-i-1]=now%2019

    dic=Counter(L)
    
    output=0
    for val in dic.values():
        if val!=1:
            output+=val*(val-1)//2
    
    output+=dic[0]
    print(output)

main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
count = 0
N = (l-1)*(l-2)*(l-3)/6
for i in range(0,l-3):
  for j in range(i+4,l+1):
    st = int(S[i:j])
    if st%2019 == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
cnt=0
for i in range(0,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:
def number(S, a ,b):
    number =0
    for i in range(b- a+1):
        number += 10**(b- a - i)*int(S[a+i])
    return number


S = input()
N=len(S)
ans =0
for i in range(N):
    for j in range(i ,N):
        if number(S, i ,j) %2019==0:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
counter = 0

if len(S) < 4:
  print(0)
  exit()
"""
for left in range(len(S)-3):
  for right in range(left+4,len(S)+1):
    if int(S[left:right])%2019==0:
      counter += 1
print(counter)
"""
from collections import defaultdict
dic = defaultdict(int)
for left in range(len(S)-3):
  for right in range(left+4,len(S)+1):
    dic[S[left:right]] += 1
for key in dic:
  if int(key)%2019==0:
    counter += dic[key]
print(counter)

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0
for i in range(len(s)):
    for j in range(len(s)):
        if (i + 2) < j:
            num = int(s[i:j+1])
            if num % 2019 == 0:
                cnt += 1
                break

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
Scount = 0
for i in range(len(S)):
    for j in range(1,len(S)):
        if (i+j)<=len(S):
            part_S = S[i:i+j]
            num = int(part_S)
            if num % 3 == 0:
                if num % 673 ==0:
                    Scount += 1
print(Scount)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a = input()
b = int(a) // 2019
c = 0
for i in range(1,b+1):
    d_str = str(i * 2019)
    if d_str in a:
        c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
N = len(S)
l = 0
r = 0


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

from collections import Counter
c_ = Counter(amari)
c = c_.most_common()

ans = 0
for i in c:
  if i[1] != 0:
    ans += i[1] * (i[1]-1) // 2
  else:
    break

ans += c_[0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=int(input())
n=len(str(s))
t=0
for j in range(n):
    j+=1
    for i in range(j):
        i+=1
        k=s
        k//=10**(n-j)
        k%=10**(j-i+1)
        if k==0:
            k=1
        if k%2019==0:
            t+=1
print(t)

Submission status: Time Limit Exceeded

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

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

    s_nums = list(range(len(s)+1))

    ans = 0

    for i_1 in range(len(s)):
        for i_2 in range(i_1+1, len(s)+1):
            if int(s[i_1:i_2]) % 2019 == 0:
                # print(i_1, i_2)
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
X = [int(i) for i in S]
amari = {i:0 for i in range(2019)}
Y = {i:0 for i in range(2019)}
ans = 0
for i in X:
    nextamari = dict(Y)
    nextamari[i] += 1
    for j in amari.keys():
        x = (j * 10 + i) % 2019
        nextamari[x] += amari[j]
    ans += nextamari[0]
    amari = nextamari
#    for i in nextamari.keys():
#        if nextamari[i] != 0:
#            print(nextamari[i])
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:
S=input()
n=len(S)
count=0

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

print(count)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = input()
l = len(n)
key = [0]*2019
mod = 1
judge = 0
for i in range(l):
  judge += ((mod%2019)*int(n[l-i-1]))%2019
  judge %= 2019
  k = judge%2019
  key[k] += 1
  mod *= 10

ans = key[0]
for i in range(2019):
  if key[i] >= 2:
    ans += key[i]*(key[i]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
problemInput = input()
count = 0

if len(problemInput)>3:
    for i in range(3, len(problemInput)):
        for j in range(0, i - 3):
            temp_str = problemInput[j: i + 1]
            tempNum = int(temp_str)

            if tempNum % 2019 == 0:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = len(s)

ans = 0

from itertools import combinations

for x in combinations(range(n), 2):
    if int(s[x[0]:(x[1]+1)]) % 2019 == 0:
        ans += 1
    else:
        pass

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    ss = str(s)
    s_l = len(s)
    s = int(s)
    print(len([0 for x in range(s_l) for y in range(x+3, s_l+1) if not int(ss[x:y]) % 2019]))
main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = [int(i) for i in input()]
from collections import Counter
def solve(S):
    n = len(S)
    cum = [0]*(n+1)
    for i in range(n):
        cum[i+1] = (cum[i]+S[n-1-i]*10**i)%2019
    c = [0]*2019
    for i in range(n+1):
        c[cum[i]] += 1
    ans = 0
    for v in c:
        ans += v*(v-1)//2
    return ans
print(solve(S))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
S = list(map(str,input()))

counter = 0

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

print(counter)

Submission status: Time Limit Exceeded

Solution code:
S=int(input())
m=S//2019
ans=0
baisu=[]
for i in range(m):
  baisu.append(2019*(i+1))
for num in baisu:
  if str(num) in str(S):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = list(input())
    s = s[::-1]

    l = [[[] for j in range(3)] for i in range(673)]
    l[0][0].append(0)
    mo = 0
    ten = 1
    mod = 673
    now = 0
    ans = 0
    for i in range(len(s)):
        a = int(s[i])*ten
        mo = (mo+a)%3
        now = (now+a)%mod
        if l[now][mo]:
            ans += len(l[now][mo])
        l[now][mo].append(i+1)
        ten *= 10
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    s_set = set()
    s_len = len(s)
    for i in range(s_len-3):
        for j in range(i+4, s_len+1):
            if int(s[i:j])%2019 == 0:
                s_set.add((i, j))

    return len(s_set)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
S = sys.stdin.readline().rstrip()
ans = 0
for i in range(0, 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 = str(input())
N = len(S)
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(c)