Problem:


Score : 400 points

Problem Statement

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

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

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

Constraints

1 ≤ |S| ≤ 200000

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

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

1817181712114

Sample Output 1

3

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

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    slen = len(S)
    visited = set()
    ans = 0
    for i in range(0, slen):
        if i in visited:
            continue
        start = i
        end = i + 4
        point = 1
        while end <= slen:
            if (int(S[start:end])) % 2019 == 0:
                visited.add(start)
                start = end + 1
                end = start + 4
                ans += point
                point += 1
            else:
                end += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
ret = 0
for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        if j == i + 4:
            if i == 0:
                sum_num0 = sum([int(s) for s in S[i:j]])
            else:
                sum_num0 = sum_num0 - int(S[i-1]) + int(S[j-1])
            sum_num = sum_num0
            if int(S[i:j]) != 2019:
                continue
        else:
            sum_num += int(S[j-1])
        
        if sum_num % 3 == 0:
            test = int(S[i:j]) // 3
            if test % 673 == 0:
                ret += 1
print(ret)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
S = input()
N = len(S)

def co(s, n):
    return Counter([int(s[i:i+n])%2019 == 0 for i in range(len(s)-n+1)])[True]

ans = 0
for i in range(4, N+1):
    ans += co(S, i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = list(input())
# Ns = ''.join(N)
M = list(map(str, list(range(len(N)))))
S = list(itertools.combinations(M,2))
count = 0
for _, combi in enumerate(S):
    if int(combi[1])+1 - int(combi[0]) >= 4:
        A = N[int(combi[0]):int(combi[1])+1]
        B = ''.join(A)
        if int(B)%2019 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
s=sys.stdin.readline().rstrip()
c=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:
            c+=1
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
b = [0]
k = 0
n = 0
for i in range(len(s))[::-1]:
    n += int(s[i])*(10**k)
    n%=2019
    b.append(n)
    k+=1

import collections

c = collections.Counter(b)
ans = 0

for j in c.values():
    if j > 1:
        ans += j*(j-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#coding:UTF-8

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

Submission status: Time Limit Exceeded

Solution code:
Ss=input()
order=len(Ss);
S=int(Ss)
N=0
if(S<2019):
    print(N)
else:
    for i in range(0,order-3):#1 to N-3
        for j in range(i+3,order):
            ij=int(Ss[i:j+1])
            if(ij%2019==0):
                N+=1
    print(N)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
s = input() #sys.stdin.readlineは最後が改行
s = s[:-1]
n =len(s)

num=0
tmp=0

amari= [0]

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

from collections import Counter
ctr = Counter(amari)
ans = 0
for val in ctr.values():
        ans += val*(val-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0

used = {}

start = 0
end = len(s)

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


print(count)

Submission status: Time Limit Exceeded

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    S = input()
    LIST = []
    for i in range(40):
        LIST.append(2019*i)
    start = 0
    cnt = 0
    while start+4 < len(S):
        for i in range(start+4,len(S)+1):
            #print(S[start:i])
            if int(S[start:i]) in LIST:
                cnt += 1
        start += 1
    print(cnt)
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count = 0
for i in range(l):
  for j in range(l):
    if i < (j-3):
      new_s = int(S[i:j+1])
      if new_s % 2019 == 0:
        count += 1
      else:
        continue
    else:
      continue
print(count)

Submission status: Time Limit Exceeded

Solution code:
s=list(map(int,input()))
l=len(s)
if l<=4:
    print(0)
else:
    count=0
    for i in range(l-4):
        for j in range(i+3,l):
            a=0
            for k in range(j-i+1):
                a+=s[j-k]*10**(k)
            if a%2019==0:
                count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(20000*20000)

S = str(input())
ans = set()

def dfs(i, j):
    if int(S[i:j+1])%2019 == 0:
        ans.add((i, j))
    if j == len(S)-1:
        return

    dfs(i, j+1)

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

else:
    for i in range(len(S)-3):
        dfs(i, i+3)
    print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
s=input()
# print(len(s));
i=0
count=0

for k in range(4,len(s)):
    i=0
    for j in range(k,len(s)+1):

    
        m=s[i:j]
        i=i+1
        # print(m)
    
        # print(int(m))
        if int(m)%2019==0:
            count+=1
        # i=i+1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

S = input()

ss = len(S)

count = 0
for a in range(ss):
    for b in range(a+1, ss+1):
        if int(S[a:b]) % 2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
s.reverse()
sa=0
sum_2019=0
sum_2019_list=[]
for i in range(0,len(s),1):
    for j in range(i+3,len(s)):
        sum_2019=0
        for k in range(i,j+1):
            sa=k-i
            sum_2019+=int(s[k])*10**sa
        if(sum_2019%2019==0):
            sum_2019_list.append(sum_2019)
                
    if(len(s)==i+3):
        break
print(len(list(sum_2019_list)))

Submission status: Time Limit Exceeded

Solution code:
N = input()

A = 0

while True:
    B = ""
    for C in range(len(N)):
        B += N[C]

        if int(int(B) % 2019) == 0:
            A += 1

    if len(N) < 5:
        break

    N = N[1:len(N)]

print(A)

Submission status: Time Limit Exceeded

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

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,3,-1):
    for j in range(i-4,-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:
import math

S=int(input())
n=int(math.log10(S))+1
cnt=0

for i in range(4,6):
  for j in range(n-i+1):
    if (S//(10**(n-i-j))%(10**(i)))%2019==0:
      cnt+=1
      
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

def main():
  N = int(input()) # 1行, 単数

  S = str(N)
  count = 0
  for i in range(len(S) - 3):
    x = int(i)
    for j in range(int(i+3) , len(S)+1):
      y = int(j)
      A = int(S[x:y])
      if A % 2019 == 0:
        count+=1

  print(count)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input().rstrip()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(map(int, input()))
n = len(s)

ans = 0

for i in range(n):
    for d in range(3,n-i):
        j = i+d

        num = [s[i] for i in range(i, j+1)]
        num_str = map(str, num)
        num_num = ''.join(num_str)
        number = int(num_num)
        if number % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def resolve():
  S_string = input()

  if len(S_string) < 4:
    print("0")
    return True

  d_start = 5
  d_end = len(S_string)

  counter = Counter([int(S_string[i:i + d]) % 2019 for i in range(0, d_end - 4) for d in range(d_start, d_end + 1 - i)])
  count = counter[0]
  # count = 0
  # for i in range(0, d_end - 4):
  #   for d in range(d_start, d_end + 1 - i ):
  #     # print(int(S_string[i: i + d]))
  #     if (int(S_string[i: i + d])%2019==0):
  #       count += 1

  print(count)

if __name__ == "__main__":
  resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

s = input()

a = np.zeros(len(s)+1, dtype='i8')
res = 0
for i in range(len(s)):
    for k in range(i+4, len(s)+1):
        if int(s[i:k]) % 2019 == 0:
            res += a[i] + 1
            a[k] += 1
            break

print(res)

Submission status: Time Limit Exceeded

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

    simo5 = set()
    for i in range(5,1000001):
        s = str(2019*i)
        if '0' not in s:
            simo5.add(s[-5]+s[-4]+s[-3]+s[-2]+s[-1])

    l = len(S)
    ans = 0
    for i in range(l-1,3,-1):
        tmp = ''.join([S[i-4],S[i-3],S[i-2],S[i-1],S[i]])
        if tmp not in simo5:
            continue
        else:
            if int(tmp)%2019 == 0:
                ans += 1
                i -= 5
            for j in range(i,-1,-1):
                tmp = ''.join([S[j],tmp])
                if int(tmp)%2019 == 0:
                    ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()

x = 2019
s = set()

for i in range(1, 200):
    s.add(str(x * i)[-3:-1])

cnt = 0

for x in range(len(S) - 3):
    j = len(S) - x
    if (S[j - 2:j]) not in s:
        continue
    i = j - 4
    while i >= 0:
        if int(S[i:j]) % 2019 == 0:
            cnt += 1
        i -= 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

si = []
for i in range(len(s)):
  for j in range(i+4,len(s)+1):
    si.append(s[i:j])
    
cnt=0
for num in set(si):
  if int(num)%2019 == 0:
    cnt+=si.count(num)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

a = 0
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        if j - i < 4: continue
        if sum(list(map(int, str(s[i:j])))) % 3 != 0: continue
        if int(s[i:j]) % 2019 == 0:
            a += 1

print(a)

Submission status: Time Limit Exceeded

Solution code:
import itertools
s = input()

a = [i for i in range(len(s))]
c = 0
for v in itertools.combinations(a,2):
	x,y = v[0],v[1]
	if y-x < 4:
		continue
	#print (s[x:y+1],x,y)
	if int(s[x:y+1]) %2019 == 0:
		c += 1
print (c)

Submission status: Time Limit Exceeded

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

a = 0
r = [0 for _ in range(m+1)]
r[0] = 1
for i in range(n):
    z = int(s[i:])%m
    a += r[z]
    r[z] += 1

print(a)

Submission status: Time Limit Exceeded

Solution code:
S = input()

mod = []
count = 0

for s in S:
  mod.append(int(s)%3)
  
for i in range(len(S)-3):
  m = (mod[i]+mod[i+1]+mod[i+2])%3
  for j in range(i+3, len(S)):
    m += mod[j]
    if m%3 == 0:
      if int(S[i:j+1])%2019 == 0:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
s=ss()
ans=0
for i in range(len(s)-4):
    for j in range(i+4,len(s)):
        if int(s[i:j+1])%2019==0:
            ans+=1
            continue
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
res = 0
left = 0
right = 4
while left <= len(s) - 3:
  right = left + 4
  if int(s[left:right]) % 2019 == 0:
    res += 1
    while s[right+1] == '0' and right <= len(s):
      res += 1
      right += 1
    right += 1
    left += 1
  else:
    while right < len(s):
      right += 1
      if int(s[left:right]) % 2019 == 0:
        res += 1
#        while s[right+1] == '0' and right < len(s):
#          res += 1
#          right += 1
    left += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
S = input()
dict_amari = {}
count = 0

henkan = {i: [(10*j+i)%2019 for j in range(2019)] for i in range(1,10)}

def amari_new(dict_amari, s, henkan):
  dict_amari_new = {henkan[k] : v for k,v in dict_amari.items()}
  if s in dict_amari_new.keys():
    dict_amari_new[s] += 1
  else:
    dict_amari_new[s] = 1
  return dict_amari_new

for s in S:
  dict_amari = amari_new(dict_amari, int(s), henkan[int(s)])
  if 0 in dict_amari.keys():
    count += dict_amari[0]

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
    
def print_ans(S):
    """Test Case
    >>> print_ans('1817181712114')
    3
    >>> print_ans('14282668646')
    2
    >>> print_ans('2119')
    0
    """
    target_list = []
    itr = 2019
    for i in range(1, 9906):
        tmp = i * itr
        if tmp > int(S):
            break
        elif '0' in list([s for s in str(tmp)]):
            continue
        else:
            target_list.append(tmp)
    ans = 0
    if len(S) <= 3:
        print(0)
    else:
        for i in range(len(S)-2):
            for j in range(i + 2, len(S)):
                tmp = S[i:j+1]
                if len(tmp) > 8:
                    break
                if int(tmp) in target_list:
                    ans = ans + 1
        print(ans)

if __name__ == '__main__':
    S = input().rstrip()
    print_ans(S)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

S_i = {}
for i in range(2019):
    S_i[i]=0

for i in range(len(S)):
    k = int(S[i:])%2019
    S_i[k] +=1

ans = 0
for k in S_i.keys():
    if k==0:
        ans += S_i[k]
    elif S_i[k]>1:
        ans += S_i[k]*(S_i[k]-1)/2

print(int(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
for i in range(len(s)-1):
  for j in range(i+1, len(s)):
    a = j-i;
    sum = 0;
    for k in range(a+1):
      sum += (10**k) * int(s[j-k])
    if sum%2019 == 0:
      cnt += 1;
  
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = 0
e = s + 4
ans = 0
loop = False

while True:
    
    if loop == False:
        index = int(S[s:e])
        if index % 2019 == 0:
            ans += 1
            loop = True
            s_cp = s
            e_cp = e
        else:
            e += 1
    else:
        s2 = e_cp
        e2 = s2+e_cp-s_cp
        if S[s:e] == S[s2:e2]:
            ans += 1
            s_cp = s2
            e_cp = e2
        else:
            loop = False
            e += 1
    if e > len(S) :
        s += 1
        e = s + 4
        if e > len(S): break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def hoge(n):
    count = 0
    i = 0
    while count < n:
        if "0" not in str(2019*i):
            count += 1
            print(2019*i)
        i += 1


s = input()
X = list(map(int, list(s)))
n = len(s)


ans = 0
for i in range(n):
    x = 0
    for j in range(i, n):
        x = 10*x + X[j]
        if x%2019 == 0:
            ans += 1
            log(x)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
str=input()
gap_len=4
flag=0
count=0
for gap_len in range(4,200000):
    for i in list(range(len(str)-gap_len+1)):
        sub_str=str[flag:flag+gap_len]

        num=int(sub_str)
        if(num%2019==0):
            count+=1
        flag+=1
    flag =0
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())  #文字列の一文字ずつリストに

ans = 0
for j in range(len(S) - 4):
    if len(S) + 1 - j <= 200000:
        for i in range(4, len(S) + 1 - j):
            A = (''.join(S[j: j + i]))
            if int(A) % 2019 == 0:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 21:27:49 2020

@author: arute
"""


from sys import stdin

import time
import numpy as np
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def toint(data):
    out = ""
    for d in data:
        out += str(d)
    return int(out)
############################################

# read data for n sequences.
temp = stdin.readline().split()
N = str(temp[0])

# 1817181712114
data = []
for i in range(len(N)):
    data.append(str(N)[i])

count = 0
for i in range(len(data)-3):
    o = []
    for j in range(len(data)-3):
        if not i+j+3>=len(data):
            d = data[i : i+j+4]
            o.append(toint(d))
    o = np.asarray(o)
    count += np.sum(o%2019==0)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# Sの入力
S = input()

# j番目の初期化
j_s = 4

# 条件を満たす個数の初期化
cnt = 0

for i in range(1,len(S)-2):
    for j in range(j_s,len(S)+1):
        S_ij = S[i-1:j]
        S_ij_int = int(S_ij)
        baisu = S_ij_int % 2019
        if baisu == 0:
            cnt += 1
    j_s += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=input('')

n=0
for a in s:
    n=n+1

if n>=4:
    p=0
    for i in range(n-4):
        t=s[i]+s[i+1]+s[i+2]+s[i+3]
        j=0
        while i+j+4<n:
            t=t+s[i+j+4]
            if int(t)%2019==0:
                p=p+1
                if i+j+5<n:
                    j=j+1
                    t=t+s[i+j+4]
                if i+j+5<n:
                    j=j+1
                    t=t+s[i+j+4]
                if i+j+5<n:
                    j=j+1
                    t=t+s[i+j+4]
                if i+j+5<n:
                    j=j+1
                    t=t+s[i+j+4]
            else:
                j=j+1
else:
    p=0
print(p)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
f_can = itertools.combinations(range(len(str(N))+1),2)
s_can = [str(N)[int(f):int(b)] for f,b in f_can if int(b)-int(f)>3]
print(len([i for i in s_can if int(i)%2019==0]))

Submission status: Time Limit Exceeded

Solution code:
m = 2019
div_list = [0]*m
div_list[0] += 1
S = list(input())
num = 0
for i, l in enumerate(reversed(S)):
    num += 10**i*int(l)
    div_list[num%m] += 1

ans = 0
for item in div_list:
    ans += int(item*(item-1)/2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
def floor1(x,i):
  return x//(10**i)
S = input()
s = int(S)
res = 0
ress = [floor1(s,i[0])- floor1(s,i[1]+1)*(10**(i[1]+1-i[0])) for i in combinations(range(len(S)),2)]
print(sum(x %2019 == 0 for x in ress))

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    # si = tuple(int(c) for c in s)  # integers of one digit
    # ms = {2019 * x for x in range(10 ** 200000 - 1 // 2019)}
    ans = 0
    lg = len(s)
    # to slice till the last letter, +1 is needed.
    for i in range(lg + 1):
        for j in range(i + 4, lg + 1):
            j2 = j
            # 2019 = 673 * 3
            # if sum(si[i:j2]) % 3 != 0:
            #     continue
            if int(s[i:j2]) % 2019 == 0:
                ans += 1

    return ans


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
kumi = []
count_start = 0
while count_start <= len(S) - 1:
    count_end = 4
    while count_end <= len(S):
        if count_start + 2 < count_end:
            check = int(S[count_start:count_end])
            if check % 2019 == 0:
                kumi.append(check)
        count_end += 1
    count_start += 1
print(len(kumi))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    count=np.zeros(2019,dtype=int)
    ans=0
    count_t=np.zeros(2019,dtype=int)
    for i in range(len(s)):
        count_t[int(s[i])]+=1
        for k in range(2019):
            if count[k]==0:
                continue
            else: 
                t=(k*10+int(s[i]))%2019
                count_t[k]-=count[k]
                count_t[t]+=count[k]
                if t==0:
                    ans+=count[k]
        #print(count[0:20])
        #print(count_t[0:20])
        count=count+count_t
        count_t-=count_t
    print(ans)
                
if __name__ == '__main__':
    do()

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    #s = input().rstrip().split(' ')
    s = input()
    numstr = [int(elem) for elem in s]
    ans = []

    for i in range(len(numstr)):
        rest = 0
        for j in range(i, len(numstr)):
            rest = (rest * 10 + numstr[j]) % 2019
            if rest == 0:
                ans.append((i,j))
                break

    count = 0
    temp = 0

    ans.append(('end', 'end'))

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

    print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ll = len(s)
dat = list(map(int, list(s)))
#print(dat)
if len(s) < 4:
    print(0)
else:
    res = 0
    for l in range(0, ll - 4):
        v = int(s[l:l + 4])
        #print(v)
        v = v % 2019
        if v == 0:
            res += 1
        for r in range(l+4, ll):
            v = (v * 10 + dat[r]) % 2019
            if v == 0:
                res += 1
    print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
s=input()
n=len(s)
N=defaultdict(int)
x=0
for i in reversed(range(n)):
    x+=int(s[i])*(10**(n-i-1))
    x%=2019
    N[x%2019]+=1
ans=N[0]
for j in N.values():
    ans+=j*(j-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
si = int(s)
a = 2019
start=0
l=2
findings = []
while(start+l<=len(s)):
    while (start + l <= len(s)):
        if(int(s[start:start+2])%2!=0):
            break
        elif(int(s[start:start+l])%2019==0):
            findings.append([start+1, start+len(s[start:start+l])])
        l+=1
    l=2
    start+=1
print(len(findings))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# input
S = input()

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

# output
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(l):
  for j in range(l):
    if i < (j-2):
      new_s = int(S[i:j+1])
      if new_s % 2019 == 0:
        count += 1
      else:
        continue
    else:
      continue
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
S = str(input())

ans = 0
for i,j in itertools.combinations(range(len(S)), 2):
  if int(S[i:j+1]) % 2019 == 0:
    ans += 1
      
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:


N = int(input()) # 1行, 単数

S = str(N)
count = 0
list1 = [[y,x] for y in range(len(S) - 3) for x in range(int(y+3) , len(S)+1)]
list1 = len(list(filter(lambda A: int(S[A[0]:A[1]])%2019 == 0, list1)))

print(list1)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
S = input()
N = len(S)

def co(s, n):
    return [int(s[i:i+n])%2019 == 0 for i in range(len(s)-n+1)]

ans = 0
for i in range(4, N+1):
    ans += Counter(co(S, i))[True]
print(ans)