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()
n = len(s)
res = 0
for i in range(n):
    for j in range(i+1, n+1):
        s_i = int(s[i:j])
        if s_i % 2019 == 0:
            res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
start = time.time()
N = input()
num = 0
for i in range(len(N)+1):
    for j in range(i+4, len(N)+1):
        if sum(map(int, list(N[i:j]))) % 3 == 0:
            if int(N[i:j]) % 673 == 0:
                num += 1

print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(r)

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

Submission status: Time Limit Exceeded

Solution code:
a=input()
b=int(a)

ans=0

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

print(ans)

Submission status: Time Limit Exceeded

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

ans = []
for i in range(length):
    for j in range(i, length):
        n = int(str(s)[i:j+1])
        if n % 2019 == 0:
            ans.append(n)

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
# 文字列を一つ入力
S = input()

slen = len(S)
res = 0
for j in range(slen-1,3,-1):
    x1 = 10-int(S[j])
    for x0 in range(200000):
        xx = 2019 * (x0*10+x1)
        if j-len(str(xx))+1 < 0:
            break
        yy = int(S[j-len(str(xx))+1:j+1])
        if xx == yy:
            res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
s=input() 
cnt = 0
t = 0
e = 5

for i in range(len(s)-e+1):
    for j in range(len(s)-e+1):
        tmp = int(s[t:e])
        e = e + 1
        if tmp % 2019 == 0:
                cnt = cnt + 1
    t = t + 1
    e = t + 5
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
ans = 0
for i in range(len(S)+1):
    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 = input()
count = 0

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

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

print(count)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
r = 0
m = []
for i in range(3,l):
    num = int(s[i])
    m = [(x*10+num) % 2019 for x in m]
    m.append(int(s[i-3:i+1])%2019)
    r += m.count(0)
print(r)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
Sint = int(S)
i = 1
ans = 0
while i * 2019 <= Sint:
    now = str((i * 2019))
    if not now.__contains__("0"):
        ans += S.count(now)
        i += 1

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+3,len(s)):
        s_num=s_input[i:j+1]
        if int(s_num)%2019==0:
            cnt+=1
            i=j-1
            break
print(cnt)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline


def main():
    s = input().strip()
    i = 0
    cnt = 0
    while i <= len(s):
        j = i + 4
        while j <= len(s):
            if int(s[i:j]) % 2019 == 0:
                cnt += 1
                break
            j += 1
        i += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S=input()

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

Submission status: Time Limit Exceeded

Solution code:
S = list(str(input()))
S = [int(s) for s in S]
n = len(S)

S.reverse()

cum1 = [-1]*(n+1)
cum1[0] = 0
for i in range(n):
    temp = cum1[i]+S[i]*10**i
    cum1[i+1] = temp%673
#print(cum1)

cum2 = [-1]*(n+1)
cum2[0] = 0
for i in range(n):
    temp = cum2[i]+S[i]*10**i
    cum2[i+1] = temp%3
#print(cum2)

d = {}
ans = 0
for i in range(n+1):
    c1 = cum1[i]
    c2 = cum2[i]
    if (c1, c2) in d:
        ans += d[(c1, c2)]
        d[(c1, c2)] += 1
    else:
        d[(c1, c2)] = 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
lS = len(S)
ans = 0
li_s = []
li_g = []

def f(s):
    ss = s[-4:]
    #print(ss)
    
    for i in range(len(s)-3):
        if int(ss) % 2019 != 0:
            if len(s)+1 > 5+i:
                ss = s[-5-i] + ss
                #print(ss)
        else:
            return i
    else:
        return -1

#or j in range():

for j in range(lS-3):
    s = S[:lS-j]
    #print(s)
    i = f(s)
    #print(i)
    if i != -1:
        li_s.append(lS-4-i-j+1)
        li_g.append(lS-1-j+1)
        
#print(li_s)
#print(li_g)

for v_s in li_s:
    x = 1
    while True:
        if v_s-1 in li_g:
            v_s = li_s[li_g.index(v_s-1)]
            x += 1
        else:
            break
    ans += x

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from operator import mul
from functools import reduce


memo = {}


def cmb(n, r):
    if (n, r) in memo:
        return memo[(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))
    memo[(n, r)] = over // under
    return over // under


s = input()[::-1]
acc = [int(s[0])]
cntr = defaultdict(int)
for i, c in enumerate(s[1:], 1):
    if c == '0':
        continue
    next_mod = (acc[-1] + 10 ** i * int(c)) % 2019
    cntr[next_mod] += 1
    acc.append(next_mod)

ans = 0
for k, v in cntr.items():
    if k == 0:
        ans += v
    if v > 1:
        ans += cmb(v, 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
DIGIT = 4
ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
all_s = []
for i in range(len(s)-3):
    for j in range(i+4,len(s)+1):
        all_s.append(int(s[i:j]))

count = 0
for i in all_s:
    if i%2019 == 0:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
S = input()

num_s = int(S)
num_list = list(S)

count = 0

def run(num):
    global count
    for index, value in enumerate(num_list):
        if not index + num >= len(num_list):
            check_list = num_list[index:index + num+1]
            if int(''.join(check_list)) % 2019 == 0:
                count += 1
        else:
            break

for i in range(4, len(S)):
    run(i)

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def main():
    S = list(str(input()))
    ans = 0
    for i in range(len(S)):
        S2 = []
        S2 = [S[i]]
        for j in range(i+1,len(S)):
            S2[0] += S[j]
            #print(S2)
            if (int(S2[0])%2019) == 0:
                ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
str_len = len(S)
X = 0

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

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

print(X)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input().strip()
s = len(S)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
count = 0

for i in range(101):
    tag = 2019 * i
    #print(tag)
    if tag <= n :
        if str(tag) in str(n):
            count += sum(str(n).startswith(str(tag), i) for i in range(len(str(n))))
    else:
        break

print(count)

Submission status: Time Limit Exceeded

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

a = 0
count = 0

for i in range(l):
    a = int(S[l-i-1])
    for j in range(i+1,l):
        if int(S[l-j-1]) != 0:
            a += int(S[l-j-1])*10**(j-i)
            if j-i > 2:
                if a != 0 and a % 2019 == 0:
                    count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
A = [i for i in range(2019, int(s) + 2019, 2019)]
ans = 0
for a in A:
    di = len(str(a))
    for i in range(l - di + 1):
        # print(s[i:i + di], a)
        if s[i:i + di] == str(a):
            ans +=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
tmp = 0
result = 0
for p in range(0, len(S) - 3):
    for q in range(p + 3, len(S)):
        tmp = int(''.join(S[p:q + 1]))
        if tmp % 2019 == 0:
            result += 1
            
print(result)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def solve():
    s = input()

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


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

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

print(ans)
# and (int(itoj) % 2019 ==0)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

moji = ''
cnt = 0

lst = [0] * 2020
lst[0] = 1

for s in S[::-1]:
    moji = s + moji
    r = int(moji) % 2019
    cnt += lst[r]
    lst[r] += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    import numpy as np
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    S = input().strip()
    Sn = np.array([int(x) for x in S])
    N = len(S)
    ans = 0
    if N < 4:
        print(0)
        exit()
    for i in range(N-3):
        # print('i = {}'.format(i))
        T = Sn[i:].cumsum()
        NT = len(T)
        for j in range(3, NT):
            # print('  j = {}'.format(j))
            if T[j] % 3 == 0:
                if int(S[i:i+j+1]) % 2019 == 0:
                    # print(S[i:i+j+1])
                    ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
slen=len(s)
count=0
list=[]
for i in range(slen-4):
  for j in range(i+4,slen):
    targ=int(s[i:j+1])
    if targ in list:
      count+=1
      continue
    if targ%2019==0:
      count+=1
      list.append(targ)
print(count)

Submission status: Time Limit Exceeded

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

count = 0

for i in range(M):
    temp_num = 0
    temp_str = ""
    for j in range(i + 2, M):
        temp_num += int(N[i])
        if temp_num % 3 == 0:
            temp_str = N[i:j+1]
            if int(temp_str) % 673 == 0:
                count += 1
                
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
num = 0
i = 0
while True:
  for k in range(i, len(s)):
#    print(i,k+1, int(s[i:k+1]))
    if int(s[i:k+1]) % 2019 == 0:
      num += 1
#      print("OK")
  i += 1
  if i == len(s)-1:
    break
print(num)

Submission status: Time Limit Exceeded

Solution code:
inp = input()

s = 0

for i in range(len(inp)-3):
	num = int(inp[i:])
	while num > 2019:
		if num % 2019 == 0:
			s += 1
		num = num // 10

print(s)

Submission status: Time Limit Exceeded

Solution code:
n = input()
count = 0

length = len(n)

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

print(count)

Submission status: Time Limit Exceeded

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

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

     for start in range(l):
          end = start + 4
          while(end <= l):
               # print('check: ({}, {})'.format(start+1, end))
               target = s[start:end]
               target_int = int(target)
               if check_2019(target_int):
                    # print('({}, {}) is answer'.format(start+1, end))
                    ans += 1
                    end += 4
               else:
                    end += 1

     print(ans)

def check_2019(n):
     if n % 2019 == 0:
          return True
     else:
          return False

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# ABC164d


def main():
    import sys
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    s = input()

    def prime_factorize(n):  # 素因数分解
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a

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

    def c_count(n, r):  # 組み合わせ
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    counter = [0] * 2019
    counter2 = [0] * 2019
    for i in range(n):
        num = int(s[n - i - 1:])
        # print(num)
        counter[num % 2019] += 1
        #counter2[num % 673] += 1
    counter[0] += 1
    #counter2[0] += 1

    # print(counter)

    for i in range(len(counter)):
        num = counter[i]
        if num >= 2:
            c += c_count(num, 2)

    print(c)

    c2 = 0
    for i in range(len(counter2)):
        num = counter2[i]
        if num >= 2:
            c2 += c_count(num, 2)

    #print(c, c2)

    # print(prime_factorize(2019))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

counter = 0
for start in range(len(S)):
    for end in range(len(S)+1):
        if start < end:
            target = S[start:end]
            if int(target) != 0:
                if (int(target) % 2019) == 0:
                    counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import sys
 
def input():
    return sys.stdin.readline().strip()
def main():
    S = input()
    cnt = 0
    for i in range(len(S)):
        for j in range(i+4,len(S)+1):
            if int(S[i:j]) % 2019 == 0:
                cnt += 1
    print(cnt)
 
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
S_list = list(S)

keka = 0
cnt = 0

for i in range(len(S) -3):
    for j in range(len(S) -3 -i):
        str_list = S[i:(len(S) - j)]
        keka = ''.join(str_list)
       
        if int(keka) % 2019 == 0:
            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)):
        s = int(S[i:j+1])
        if s % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:

S = input()

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

Submission status: Time Limit Exceeded

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

    return cnt

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
S = input()

num_s = int(S)
num_list = list(S)

count = 0

def run(num):
    global count
    for index, value in enumerate(num_list):
        if not index + num >= len(num_list):
            check_list = num_list[index:index + num+1]
            if int(''.join(check_list)) % 2019 == 0:
                count += 1
        else:
            break

for i in range(4, len(S)+1):
    run(i)

print(count)

Submission status: Time Limit Exceeded

Solution code:
# A,B,C,D=map(int,input().split())

def main():
    S=list(input())
    count=0
    if len(S)<4:
        print(0)
        exit()
    for i in range(4,len(S)):
        for j in range(len(S)-(i-1)):
            if int("".join(S[j:j+i]))%2019==0:
                count+=1
    print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ans = 0
flag = -1
for i in range(n-1,-1,-1):
    for j in range(i,-1,-1):
        if flag > 0:
            flag -= 1
            continue
        val = int(''.join(s_l[j:i+1]))
        if val%2019 == 0 and val != 0:
            ans += 1
            flag = 4
        else:
            flag = -1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
l=list(str(input()))
val=0
ct=0
lim=len(l)
for i in range(0,lim-3):
    for j in range(i+3,lim):
        if(i!=j)and((j-i)>2):
            val=int("".join(l[i:j+1]))
            if(val%2019==0):
                ct+=1
print(ct)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
t = N
ans = 0
while t > 0:
  tt = t
  while tt > 0:
    if tt % 2019 == 0:
      ans += 1
    tt //= 10
  t = t % pow(10, len(str(t))-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
#x文字目からy文字目
for x in range(1,a+1):
    for y in range(x,a+1):
        if (L[x-1]*(10**(y-x+1)) - L[y]) % 2019 == 0:
            k += 1
print(k)

Submission status: Time Limit Exceeded

Solution code:
line = input()
size = len(line)
num = [int(x) for x in list(str(line))]
i = 0
count = 0
while i<size-4:
    j = i + 4
    while j<=size:
        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:
def abc(S):
    # 答えの準備
    ans = 0
    
    # 二重ループ
    #print(len(S))
    # 桁数を縮める
    for l in range (len(S), 3, -1):
        # 開始位置
        for i in range(0, len(S)):
            if i + l > len(S):
                break
            num = int(S[i:l+i])
            #print(i, 'l', l, 'num', num)
            if num % 2019 == 0:
                ans += 1
    
    # 答え
    return(ans)


# バッチスタート
if __name__ == "__main__":
    # 標準入力処理
    # 1行目の入力を文字列として扱う
    S = input()
    
    # 関数呼び出し
    f = abc(S)
    
    # 答えの出力
    print(f)

Submission status: Time Limit Exceeded

Solution code:
S=input()
p=0
ans=set()
while(p!=(len(S)//2+1)):
    for i in range(p+3,len(S)+1):
        if int(S[p:i])%2019==0:
            ans.add((p,i))
        if int(S[len(S)-i:len(S)-p])%2019==0:
            ans.add((len(S)-i,len(S)-p))
    p+=1
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
start = 0

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

    start += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = input()
n_len = len(n)
count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

ans = 0
cnt = [0] * 2019
for i in range(N):
    cnt[int(S[i:]) % 2019] += 1
ans+=cnt[0]
for i in range(1, 2019):
    if cnt[i]>=2:   
        ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
s = input()
n = len(s)
cs = [0] * (n + 1)
for i, x in enumerate(s):
    cs[i + 1] = cs[i] + int(x)
ans = 0
for i in range(n):
    for j in range(i + 3, n + 1):
        if (cs[j] - cs[i]) % 3 != 0:
            continue
        k = int(s[i:j])
        if k % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
a = [int(c) for c in s]
count = 0
for i in range(len(a)-3):
    b=0
    b=(1000*a[i]+100*a[i+1]+10*a[i+2]+a[i+3])%2019
    for j in range(1,len(a)-(i+3)):
        if b%2019==0:
            count +=1
        b = (b*10 + a[i+3+j])%2019
    if b%2019==0:
            count +=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
for l in range(len(s)):
    r = l + 1
    while r < len(s) and int(s[l:r]) % 2019 != 0:
        r += 1
    if int(s[l:r]) % 2019 == 0:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

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

ans = 0
judge = 0

#iは始点を指定
for i in range(0,l-3):
  #jは終点を指定
  if(i + 3 < l):
    for j in range(i+3,l):
      #kでi~jを探索
      for k in range(i,j+1):
        p = j - k
        judge += int(S[k]) * (10 ** p)
        judge = int(judge)
      if judge > 2000 and judge % 2019 == 0:
      	ans += 1
      judge = 0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
dp = [[0]*(len(s)+1) for _ in range(2019)]
mod = 2019
num = 0
for i in s:
    num += 1
    for j in range(2019):
        dp[(j*10+int(i))%mod][num] = dp[j][num-1]
    dp[int(i)][num] += 1
    
print(sum(dp[0]))

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    from collections import Counter

    input = sys.stdin.readline

    s = str(input().rstrip())
    num = ""
    li = []
    f = 0
    mi = 0
    li_append = li.append

    for i in range(1, len(s) + 1):
        num = s[-i] + num
        li_append(int(num) % 2019)
        if num[0] == "0":
            f += 1
        else:
            if f > 0:
                mi += ((f + 1) * f) // 2
                f = 0

    co = Counter(li)
    val = co.values()
    ans_1 = 0

    for i in val:
        if i > 1:
            ans_1 += (i * (i - 1)) // 2
        else:
            continue
    ans2 = 0
    if 0 in co:
        zero = co[0]
        ans2 = zero
    print(ans_1 + ans2 - mi)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0

for i in range(1, 10000000):
  if str(2019*i) in s:
    ans += 1
  if int(s) <= 2019*i:
    break
    
print(ans)