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=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%2019==0 and k!=0:
            t+=1
print(t)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
from functools import reduce

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
    S = II()
    Slist = [int(x) for x in list(str(S))]
    N = len(Slist)
    ans = 0

    #print(Slist)
    #print(N)

    for i in range(N-3):
        for j in range(i+3,N):
            num_list = [0]*(j-i+1)
            num_list = [Slist[k] for k in range(i,j+1)]
            num = int(reduce(lambda x, y: x + y, [str(x) for x in num_list]))
            if num % 2019 == 0:
                ans += 1
            #print(num)
    
    print(ans)



if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
ans=0

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

s = input()
s_len = len(s)
n = 2019
n_len = len(str(n))
result = 0


@lru_cache(maxsize=128)
def is_multiple(x):
    return x % n == 0


for i in range(s_len - n_len):
    for j in range(i + n_len, s_len + 1):
        m = int(s[i:j])
        if is_multiple(m):
            result += 1
print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0

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

print(ans)

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:
            r += tint % 2019 == 0
            tint = tint //10
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len( S )
l = [ str( 2019 * i )  for i in range( 200000 ) ]
cnt = 0
for i in l:
    if len(i) > N:
        break
    Sd = S[0: ]
    add = Sd.find( i )
    while add != -1:
        cnt += 1
        Sd = Sd[ add + 1: ]
        add = Sd.find( i )
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

l = len(s)
ans = 0

for i in range(l-3):
    left = i
    right = left + 4
    while (right < l+1):
        now = int(s[left:right])
        if (now % 2019 == 0):
            right += 4
            ans += 1
        else:
            right += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
for i in range(len(S)):
    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()
length = len(s)
count = 0

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
if len(s) <= 4 and s != '2019':
    print(0)
    exit()

M_2019 = [2019*i for i in range(1, 200001)]
cnt = 0
for i in range(len(s)):
    for j in range(i+4, len(s)+1):
        if int(s[i:j]) in M_2019:
          cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

def is_multiple(s):
    return int(s) % 2019 == 0
#print(sum([is_multiple(S[i:i+j+4]) for i in range(len(S)) for j in range(len(S)-(i+3))]))

c = 0
for i in range(len(S)):
    for j in range(len(S) - (i+3)):
        if is_multiple(S[i:i+j+4]):
            c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input()
c = 0

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
cnt = 0
for i in range(L-3):
    memo = S[i:i+3]
    for j in range(i+3,L):
        new = memo+S[j]
        if int(new)%2019 == 0:
            cnt += 1
            memo = new
        else:
            memo = new
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
st = len(s) - 3
en = len(s) + 1

lst = [[start,end] for start in range(st) for end in range(start + 4, en) if int(s[start:end]) % 2019 == 0]
print(len(lst))

Submission status: Time Limit Exceeded

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
L = len(S)
a = 0
for i in range(L):
    for j in range(L):
        k = ''.join(S[i:j+1])
        if k != '' and int(k) % 2019 ==0:
            a += 1
print(a)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

Submission status: Time Limit Exceeded

Solution code:
S= str(input())
T=S
ans = 0
for i in range(len(S)):
    S= T[i:]
    S = int(S)
    while True:
        if S % 2019 ==0:
            ans = ans+1
        S = S // 10
        if S < 2019:
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

n = len(s)

cnt = 0

if n < 4:
    print(0)
else:
    for i in range(n-3):
        for j in range(i+3,n):
            ss = list(map(int,s[i:(j + 1)]))
            x = 0
            for k in range(j-i + 1):
                x += ss[k] * (10 ** (j-i - k))
            if x % 2019 == 0:
                cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

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

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


if n <= 3:
    print(0)
else:
    slove(n)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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


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


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


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


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


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

    for i in range(len(s) + 1):
        for j in range(i + 4, len(s) + 1):
            if sum(map(int, s[i:j])) % 3 == 0 and int(s[i:j]) % check == 0:
                ret += 1

    return ret


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

Submission status: Time Limit Exceeded

Solution code:
S = input().strip()
l = len(S)
def test(x):
    if x < 2019:
        return 0
    elif x % 2019 == 0:
        return 1
    else:
        return 0

ans = 0
for d in range(4, l+1):
    for i in range(l - d+1):
        if test(int(S[i:i+d])):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
s=[int(i) for i in input()]

answer=0
for n in range(4,len(s)): #n桁の数について考える
  for i in range(len(s)-n+1): #i番目から始まる
    a=0
    for l in range(n):
      a=a+s[i+l]*(10**(n-1-l))
    if a%2019==0:
      answer=answer+1
        
print(answer)

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def CountOccurrences(string, substring):
    count = 0
    start = 0
    while start < len(string):
        pos = string.find(substring, start)
        if pos != -1:
            start = pos + 1
            count += 1
        else:
            break
    return count
l2019=[i*2019 for i in range(1,2*10**5)]
s=input()
cnt=0
for i in l2019:
    cnt+=CountOccurrences(s,str(i))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
  S = input()
  count = 0
  for width in range(4, len(S)+1):
      for p in range(len(S)+1-width):
          if int(S[p:p+width]) % 2019 == 0:
              count += 1
  #         print(p, p+width)
  print(count)
  
if __name__ == "__main__":
  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+3,n):
        m = int(s[i:j+1])
        if m % 2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

ans=0
for L in range(4,n+1):
  for i in range(n-L+1):
    if ((s//(10**(n-L-i)))%(10**L))%2019==0:
      ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

s = stdin.readline().rstrip()
ans = 0
start = 0
goal = 4
keta = 4

while start <= len(s) - 3:
    while goal <= len(s):
        check = int(s[start:goal])
        if check % 2019 == 0:
            ans += 1
        goal += 1
    start += 1
    goal = start + 4

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections
s = map(int,raw_input())

h = {}
for jj in range(2019+1):
    for d in range(0,10):
        h[jj,d] = (10 * jj + d) % 2019

dp = collections.Counter()
count = 0
for j in range(len(s)):
    ndp = collections.Counter()
    ndp[s[j]] += 1
    for k in dp:
        ndp[h[(k,s[j])]] +=1
        #ndp[(10*k + s[j]) % 2019] += 1
    count += ndp[0]
    dp = ndp

print count

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(i,N):
        
        letter=S[i:j+1]
        if letter!="":
            number=int(letter)
        #print(number)
        
        if number%2019==0:
            answer+=1
            #print("find!")
            
print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = tuple(input())
len_s = len(s)

ans = 0
tmp = 10**9
for i in range(len_s-3):
    if i == tmp:
        pass
    for y in range(i+3, len_s):
        #print(i,y)
        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()

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

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 len(''.join(S[i:j])) == 4 and int(S[i]) < 2: continue
        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:
from collections import defaultdict

s = input()

n = len(s)

dp = [defaultdict(int) for i in range(n+1)]

for i in range(n):
    a = int(s[i])
    for j in dp[i].keys():
        dp[i+1][(j*10+a)%2019] = dp[i][j]
    dp[i+1][a]+=1

ans = 0
for i in range(n+1):
    ans += dp[i][0]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import 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)-3):
        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()
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
            i=j
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
R = [0]*2019
s = input()

res = 0
for d in map(int, s):
    new = [0]*2019
    for i in range(2019):
        new[(i*10 + d)%2019] += R[i]
    new[d] += 1
    res += new[0]
    R = new
print(res)

Submission status: Time Limit Exceeded

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

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

print(flag)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=[0 for i in range(2019)]
_S=S[::-1]
_S=_S+'0'
base=1
S=0
for i,s in enumerate(_S):
    S+=base*int(s)
    mod=(S%base)%2019
    count[mod]+=1
    base*=10



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)

s = input()

long = len(s)

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
def main():
    s = list(input())
    dic1 = defaultdict(int)
    dic2 = defaultdict(int)
    n = len(s)
    for i in range(n):
        s[i] = int(s[i])
    for i in range(n):
        dic3 = defaultdict(int)
        for e in dic1:
            dic3[(e*10+s[i])%2019] = dic1[e]
            dic2[e] += dic1[e]
        dic1 = dic3
        dic1[s[i]] += 1 
    print(dic1[0]+dic2[0])
    
if __name__ == "__main__":
    main()

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

Submission status: Time Limit Exceeded

Solution code:
aa=input()


le=len(aa)

co=0

for i in range(le):
    for j in range(i+1,le):
        if int(aa[i:j+1])%2019==0:
            co+=1
print(co)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

possible_foot = [0,1,3,4,5,6,7,8,9]
    
count = 0
    
for i in range(3, len(S)):
  # print(S[i])
  if int(S[i]) in possible_foot:
    for j in range(0, i - 2):
      # print(int(S[j:i+1]))
      if int(S[j:i+1]) % 2019 == 0:
        # print(j,i)
        count += 1
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
l = len(S) 
dic = [int(S[i]) for i in range(l)]
result = 0
for i in reversed(range(3,l)):
  res = 0
  ad = 1
  for x in reversed(range(0,i+1)):
    res += dic[x]*ad
    ad = ad*10
    if res % 2019 == 0:
      result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
S = input()

rem = {}
rem[0] = 1

moji = ''
MOD = 2019
cnt = 0

for s in S[::-1]:
    moji = s + moji

    r = int(moji) % 2019
    if r in rem:
        cnt += rem[r]

    if r not in rem:
        rem[r] = 1
    else:
        rem[r] += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
s = len(S)
cnt = 0
A = []
for i in range(s):
  A.append(int(S[i:])%2019)

for i in range(s-1):
  for j in range(i+1,s):
    if (A[i]-A[j])%2019 == 0:
      cnt += 1
cnt += A.count(0)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
ss = str(s)
l=len(ss)
count = 0
for i in range(4,l+1):
    for j in range(0,l-i+1):
        #print(i,end=" ")
        #print(j)
        if int(ss[j:j+i]) % 2019 == 0:
            #print(ss[j:j+i+1])
            count += 1   
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

s = input()
n = len(s)
ans = 0
for i in range(0, n):
    for j in range(i+3, n):
        if int(s[i:j+1])%3 != 0:
            continue
        if int(s[i:j+1])%673 != 0:
            continue
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
line = input()
num = [int(x) for x in list(str(line))]
i = 0
count = 0
while i<len(line)-3:
    j = i + 3
    while j<=len(line):
        x = num[i:j]
        s = ""
        for k in range(len(x)):
            s = s + str(x[k])
        if int(s)%2019 == 0:
            count = count+1
        j = j + 1
    i = i + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

i, j = 1, 4

if len(S) <= 4:
    print(0)
    exit()

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

print(result)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  keta = len(str(n))
  count = 0
  for i in range(0, keta-2):
    for j in range(i+2, keta+1):
        if ((n % (10**(keta-i))) // (10**(keta-j))) % 2019 == 0:
          count += 1
  print(count)
main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


# input the data
s = input()
m = len(s)
count = 0

for i in range(m):
    for j in range(i, m):
        if j - i < 4:
            pass
        elif int(s[i:j+1]) % 2019 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

ans = 0
amari = [0] * 2019
follow = 0
for i in range(N):
  Amari_ = (int(int(S[N-i-1]) * pow(10, i)) + follow) % 2019
  amari[Amari_] += 1
  follow = Amari_
  if Amari_ == 0:
    ans += 1
  
for a in amari:
  ans += a * (a - 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
for i in range(len(S)-4):
    for j in range(i, len(S)):
        s = S[i:j+1]
        tmp = 0
        for k in range(len(s)):
            tmp = (tmp*10 + int(s[k])) % 2019
        if tmp == 0:
            count += 1
            
print(count)

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import queue
import copy
import math
from collections import deque
import bisect

# そのまま入力文字列の入力
s = input()

# 2019 = 3, 673

ans = 0

for i in range(0, len(s) - 1):
    for j in range(i + 4, len(s) + 1):
        num = int(s[i:j])
        d, m = divmod(num, 2019)
        if m == 0:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#MLE注意！ not は使わず !=
#0や1のケースに注意

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

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
num = list(str(input()))
cnt = 0

for i in range(len(num)):
    if i+3 > len(num):
        break
    elif num[i] != '0':
        for j in range(i+4, len(num)+1):
            check = ''.join(num[i:j])
            if int(check) % 2019 == 0:
                cnt += 1
            

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = len(s)
res = 0
for i in range(n-3):
    for j in range(i+3,n):
        num = int(s[i:j+1])

        # print(num)
        if num % 2019 == 0:
            res += 1
        # if i == 0 and j == 4:
        #     print(num % 2019)

print(res)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
ok = 0
test = str()

for i in range(1, len(S) + 2):
    for j in range(i, len(S) + 2):
        test = "".join((S[i - 1:j - 1]))
        if len(test) == 0:
            pass
        else:
            test = int(test)
            if test % 2019 == 0:
                ok += 1

print(ok)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
Sl = []
pre = 0
answer = 0
for i, s in enumerate(S):
    if i ==0:
        Sl.append(pre)
        Sl.append(pre+int(s))
        pre += int(s)
    else:
        Sl.append(pre+int(s))
        pre += int(s)
suuretu =  ''

for i in range(len(S)-2):
    for j in range(i+4,len(S)+1):
        
        if (Sl[j]-Sl[i]) %3 ==0:
            for ii in range(i,j):
                suuretu += S[ii]
            
            
            if int(suuretu) % 673 ==0:
                answer += 1
             
            suuretu = ''
print(answer)

Submission status: Time Limit Exceeded

Solution code:

n = input()

ans = 0

for i in range(len(n)):
	num = 0
	for j in range(i, len(n)):
		num = num * 10 + ord(n[j]) - ord('0')
		if num % 2019 == 0:
			ans += 1

print(str(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 len(str(num)) < 4:
      continue
    if num % 2019 == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

print(count)