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
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


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

    li = {}
    for i in range(6, 1000):
        n = str(19 * i)[-3:]
        if not ("0" in n):
            li[i] = n

    lens = len(s)
    c = 0
    for k, v in li.items():
        for pos in range(lens):
            if s[: pos + 1].endswith(v):
                if s[: pos + 1].endswith(str(2019 * k)):
                    c += 1

    print(c)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=0
sij0=0
#sij1=0
l=len(s)
a=list(map(int,list(s)))
for i in range(l-3):
  sij0=a[i]*1000+a[i+1]*100+a[i+2]*10+a[i+3]
  #print(sij0)
  sij0=sij0 % 2019
  if sij0 == 0:
    k=k+1
    for j in range(i+7,l):
    #sij1=int(s[j])
      sij0*=10
      sij0+=a[j]
      sij0 = sij0 % 2019
      if sij0 == 0:
        k=k+1
        j+=3
  for j in range(i+4,l):
    #sij1=int(s[j])
    sij0*=10
    sij0+=a[j]
    sij0 = sij0 % 2019
    if sij0 == 0:
      k=k+1
      j+=3
print(k)

Submission status: Time Limit Exceeded

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

    input = sys.stdin.readline

    s = int(input())
    li = []
    f = 0
    mi = 0
    li_append = li.append

    cm = {}
    for i in range(1,2*(10 ** 5)):
        cm[i] = i * (i - 1) // 2
    cm[0] = 0
    num_old = -1



    for i in range(1, len(str(s))+1):
        num = s % (10 ** i)
        li_append(int(num) % 2019)

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

    for x in co_1.keys():
        if x != 1:
            ans_1 += cm[x]* co_1[x]
    ans2 = 0
    if 0 in co:
        ans2 = co[0]
    print(ans_1 + ans2 - mi)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
ans = 0
check = []
check2 = []

for i in range(len(s)):
    for j in range(len(check)):
        check[j] = int(check[j]) * 10 + int(s[i])
        if check[j]%2019 == 0:
            ans += 1
        
    check.append(int(s[i]))
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
di = len(s)
s = int(s)
l = [0]*2019

for i in range(di):
    num = s%10**(di-i)
    l[num%2019] += 1
#    print(l[0])
ans = l[0]
for i in l[1:]:
    if i > 1:
        ans += (i*i-i)//2
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

S = input()

s = []
for i in S:
    s.append(int(i))
count = 0

if (len(s) < 4 ):
    print(0)
    sys.exit()

for i in range(len(s)):
    j = i
    target = s[i]
    for k in range(len(s)-i):
        j += 1
        if(j >= len(s)):
            break
        target = target*10
        target += s[j]
        if ( target%2019 == 0):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0

dp = [[0]*2019 for i in range(len(S)+1)]

for i, s in enumerate(S):
    n = S[i]
    m = int(n)
    dp[i + 1][m] += 1
    for j in range(2019):
        dp[i + 1][(j * 10 + m) % 2019] += dp[i][j]
    count += dp[i + 1][0]

print(count)

Submission status: Time Limit Exceeded

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

anya = 100
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
        if flag == 0:
            anya = 0
    if anya == 0:
        break


print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0
num = []
l = len(s)

for i in range(l):
    for j in range(l-i):
        num = ()
        num = s[i:i+j+1]
        if int(''.join(num))%2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

def main():
  d_origin = [i for i in input()]
  ans = 0
  for i in range(len(d_origin)):
    if len(d_origin) < 3:
      print(ans)
      return
    if i != 0:
      d_origin.pop(0)

    while (len(d_origin) > 2 and int(d_origin[1])%2 != 0):
      d_origin.pop(0)
    while (len(d_origin) >= 3 and (int(d_origin[2]) != int(d_origin[0]) and int(d_origin[2]) != (int(d_origin[0])-1))):
      d_origin.pop(0)
    d = d_origin.copy()
    for j in range(len(d)):
      if int(''.join(d))%2019 == 0:
        ans = ans + 1
      d.pop()
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

#jが来てあまりがiとなった時に元々のあまりはいくつか
dic = [[0 for j in range(10)] for i in range(2019)]

for i in range(2019):
    for j in range(1,9):
        tmp = (i*10+j)%mod
        dic[tmp][j] = i

# i桁までみたとき、あまりがjの物の個数
dp_sub = [[0 for j in range(2019)]for i in range(n+1)]
dp_sub[1][int(s[0])] = 1

# i桁までみたとき、あまりがjの物の個数
dp = [[0 for j in range(2019)]for i in range(n+1)]
dp[1][int(s[0])] = 1
for i in range(1,n):
    c = int(s[i])
    dp_sub[i+1][c] = 1
    for j in range(2019):
        dp[i + 1][j] = dp[i][j]
        if dic[j][c] != 0:
            dp_sub[i+1][j] += dp_sub[i][dic[j][c]]
            dp[i+1][j] += dp_sub[i][dic[j][c]]
print(dp[n][0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
P = 2019

N = len(str(S))

li = []

for i in range(N+1):
  li.append(S % pow(10, (N - i)))


li2 = []

for i in range(P):
  li2.append(0)

for i in li:
  li2[i % P] += 1

t = 0
for i in li2:
  if i == 0 or i == 1:
    pass
  else:
    t += i * (i -1) // 2

print(t)

Submission status: Time Limit Exceeded

Solution code:
s=input()
cnt=0

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

len_s = len(s)
count = 0
keta = 0
for keta in range(4, len_s+1):
    for l in range(len_s):
        check = s[l:keta+l]
        if int(check) % 2019 == 0:
            count += 1
        if keta+l >= len_s:
            break

print(count)

Submission status: Time Limit Exceeded

Solution code:
t = input()

List = [int((t)[i:j]) for i in range(len(t)) for j in range(i+1,len(t)+1)]
print(len(list(filter(lambda x:x % 2019 == 0,List))))

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
count = 0
base = ''

for i in range(l - 3):
    base = ''.join([S[i], S[i + 1], S[i + 2]])
    for j in range(i + 3, l):
        base = ''.join([base, S[j]])
        if int(base) % 3 == 0 and int(base) % 673 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
#D

#デバッグ
debug=0
def pront(*n):
    if debug==1:
        print(n)
        
#10**9+7を底とした処理

base=10**9+7

def add(a,b):#a+b
    return (a+b)%base

def sub(a,b):#a-b
    return (a-b)%base

def multi(a,b):#a*b
    return (a*b)%base

def exp(a,b):#a**b
    x=1
    c=a
    d=b
    while d!=0:
        if d%2==1:
            x=multi(x,c)
        c=(c**2)%base
        d=d//2
    return x

def div(a,b):#a/b
    return(multi(a,exp(b,base-2)))

#入力

S=input()

#処理
import math
L=len(S)
x=[int(S[-i-1:])%2019 for i in range(L)]
x=[0]+x
xx={}
pront(x)
for i in x:
    if i in xx:
        xx[i]+=1
    else:
        xx[i]=1
y=0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i,j in xx.items():
    if j>1:
        pront(i,j)
        y+=combinations_count(j, 2)
print(y)

Submission status: Time Limit Exceeded

Solution code:
s=input()
l=len(s)
mod=2019
cnt=0

i=0
while -3-i!=-l:
    if int(s[-3-i:])%mod==0:
        cnt+=1
    i+=1

k=1
while -k!=-(l-3):
    j=1
    while -3-k-j!=-l-1:
        if int(s[-3-k-j:-k])%mod==0:
            cnt+=1
        j+=1

    k+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10000000)
S = input()
ans = 0
# for i in range(len(S)-3):
i = 0
while i < len(S)-3:
    flag = False
    li = []
    # for j in range(i+4, len(S)+1):
    j = i+4
    while j < len(S)+1:
        if int(S[i:j]) % 2019 == 0:
            ans += 1
            li.append(j)
            j += j-i
            flag = True
        j += 1
    if flag:
        i += max(1, min(li)-5)
    else:
        i += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
n = input()
n_num = int(n)
how = 2019
cnt=0
lists =[]

for i in range(len(n)-3):
  for j in range(i+4,len(n)+1):
    lists.append(int(n[i:j]))

for i in lists:
  if i%2019 ==0:
    cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
res = []
for i in range(4,len(S)):
  for j in range(len(S)-i):
    if sum(map(int, list(S[j:j+i+1]))) % 3 == 0 and int(S[j:j+i+1]) % 673 == 0:
      res.append((j+1,j+i+1))
print(len(res))

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
    else:
        for j in range(i+4, (len(num)) + 1):
            check = ''.join(num[i:j])
            if len(num)-j >= 4:
                check2 = ''.join(num[i:len(num)-j+4])
            else:
                check2 = 1
            # print(check, check2)
            if (int(check) % 2019 == 0) or (int(check2) % 2019 == 0):
                cnt += 1
                break
            

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
s = input()
ans = 0
if len(s) < 5:
	print(0)
	sys.exit()
for i in range(len(s)):
	for j in range(5, len(s)):
		if i + j > len(s):
			break
		x = s[i:i+j]
		x = int(x)
		if x % 2019 == 0:
			ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
def main():
    S = input()
    s = 0
    S_sum = deque([0])
    for i in range(len(S)):
        S_sum.append(s + int(S[len(S) - i - 1]) * 10**i)
        s += int(S[len(S) - i - 1]) * 10**i

    ans = 0
    for i in range(len(S_sum) - 1):
        for j in range(i + 4, len(S_sum)):
            if ((S_sum[j] - S_sum[i]) // 10**i) % 2019 == 0:
                ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
str_num = input().strip()
keta = len(str_num)
count = 0
for start in range(keta-3):
    for end in range(start+5, keta+1):
        num = int(str_num[start:end])
        if num % 2019 == 0:
            count += 1
            break

print(count)

Submission status: Time Limit Exceeded

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

U = set([0])
s = int(S[-1])
U.add(s)
ans = 0
for k in range(len(S)-2,-1,-1):
    s = int(S[k])*(10**(len(S)-k-1)) + s
    s %= 2019
    if s in U:
        ans += 1
    else:
        U.add(s)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# import sys
# s = input()
# n = len(s)

# if n < 4:
#     print(0)
#     sys.exit()

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

# count = 0
# s = input()
# a = int(s) // 2019
# print(a)
# for i in range(a):
#     if str(i*2019) in s:
#         print(str(i*2019))
#         count += 1
# print(count)

import sys
s = input()
n = len(s)
import numpy as np
import math

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

res = [int(s[a:])%2019 for a in range(n)]
num, count = np.unique(res, return_counts=True)
ans = 0
for n, a in zip(num, count):
    if n == 0:
        ans += a
    else:
        if a > 1:
            ans += combinations_count(a, 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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 - d_start - 1) for d in range(d_start, d_end + 1 - i)])
  # count = counter[0]
  count = 0
  # for i in range(0, d_end - d_start + 1):
  #   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
  for d in range(d_start, len(S_string) + 1):
    for i in range(0, len(S_string) - d  + 1 ):
      # 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:
import sys


input = sys.stdin.readline
s = input()
n = len(s)
count = 0
a = [str(2019 * i) for i in range(1, 1000)]
for i in range(len(a)):
    for j in range(len(s)):
        if n<len(a[i]):
            break
        if s[j] == a[i][0]:
            if s[j : j + len(a[i])] == a[i]:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
S = str(S)
long = len(S)
count = 0
for i in range(1,long):
  for j in range(i+1,long-1):
    judge = 0
    cut = S[(i-1):(j+2)]
    if sum(list(map(int, cut)))%3==0:
      judge = "".join(cut)
      if int(judge)%2019 == 0:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
len_s = len(s)
ans = 0
for i in range(len_s - 4):
    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()
l = len(S)

a = 0
count = 0

for i in range(l-3):
    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 % 2019 == 0:
                    count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
indexs = []
count = 0
for i in reversed(range(3,N)):
    check_num = int(S[i-2]+S[i-1]+S[i])
    if (check_num % 19 == 0): 
        indexs.append(i)        
for i in indexs:
    for j in reversed(range(i)):
        if int(S[j:i+1]) % 2019 == 0 :
            count = count + 1
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
hoge = ['0095', '0190', '0285', '0380', '0475', '0570', '0665', '0760', '0855', '0950', '1045', '1140', '1235', '1330', '1425', '1520', '1615', '1710', '1805', '1900', '2019', '2114', '2209', '2304', '2399', '2494', '2589', '2684', '2779', '2874', '2969', '3064', '3159', '3254', '3349', '3444', '3539', '3634', '3729', '3824', '4038', '4133', '4228', '4323', '4418', '4513', '4608', '4703', '4798', '4893', '4988', '5083', '5178', '5273', '5368', '5463', '5558', '5653', '5748', '5843', '6057', '6152', '6247', '6342', '6437', '6532', '6627', '6722', '6817', '6912', '7007', '7102', '7197', '7292', '7387', '7482', '7577', '7672', '7767', '7862', '8076', '8171', '8266', '8361', '8456', '8551', '8646', '8741', '8836', '8931', '9026', '9121', '9216', '9311', '9406', '9501', '9596', '9691', '9786', '9881']
ind = []
for i in range(len(s)-3):
  if s[i:i+4] in hoge:
    ind.append(i)
ans = 0
for i in range(len(ind)):
    for j in range(ind[i],-1,-1):
        if int(s[j:ind[i]+4]) % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
max=len(S)
count=0

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

Submission status: Time Limit Exceeded

Solution code:
def count_dup(src, sub):
    cnt, pos = 0, 0
    while True:
        pos = src.find(sub, pos)
        if pos < 0:
            break
        cnt += 1
        pos += 1
    return cnt
s = input()
ls = [str(2019*i) for i in range(1, 100001)]
cnt = 0
for l in ls:
    cnt += count_dup(s, l)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
kumi = 0
count_start = 0
answer = "2019	4038	6057	8076	10095	12114	14133	16152	18171	20190	22209	24228	26247	28266	30285	32304	34323	36342	38361	40380	42399	44418	46437	48456	50475	52494	54513	56532	58551	60570	62589	64608	66627	68646	70665	72684	74703	76722	78741	80760	82779	84798	86817	88836	90855	92874	94893	96912	98931	100950	102969	104988	107007	109026	111045	113064	115083	117102	119121	121140	123159	125178	127197	129216	131235	133254	135273	137292	139311	141330	143349	145368	147387	149406	151425	153444	155463	157482	159501	161520	163539	165558	167577	169596	171615	173634	175653	177672	179691	181710	183729	185748	187767	189786	191805	193824	195843	197862	199881	201900"
answer = answer.split("\t")
while count_start <= len(S) - 4:
    count_end = 4
    while count_end <= len(S):
        if count_start + 2 < count_end:
            check = S[count_start:count_end]
            if check in answer:
                kumi += 1
        count_end += 1
    count_start += 1
print(kumi)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
S = str(input())

len_str = len(S)

ans = 0
for i in range(len_str):
    for j in range(i + 4, len_str + 1):
        temp_ans = int(S[i:j]) if j == i + 4 else (before_m * 10 + int(S[j - 1]))
        temp_ans %= 2019
        before_m = temp_ans
        if temp_ans == 0:
            ans += 1
print(ans)

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-4) for j in range(i+4,n)]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
MOD = 2019
dlist = dict()
for i in range(5):
    dlist[i] = (10**i) % MOD
if N > 5:
    for i in range(5,N):
        d = i
        l = list()
        while d > 0:
            l.append(d % 2)
            d //= 2
        num_N_ = 1
        for j in range(len(l)):            
            if l[j] == 1:
                val = 2**j
                if val in dlist.keys():
                    num_N_ *= dlist[val] 
                    num_N_ = num_N_ % MOD
                else:
                    temp_ = (dlist[2] * j) % MOD
                    num_N_ *= temp_
                    num_N_ = num_N_ % MOD
                    dlist[val] = temp_
        dlist[i] = num_N_
ret = 0
S_REV = S[::-1]

for i in range(N ):
    sums = 0
    for j in range(i ,N):
        sums += (int(S_REV[j]) * dlist[j-i]) 
        sums = sums % MOD
        if sums == 0:
            ret += 1
print(ret)

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = [0]*200000

r = 0
tmp = 0
for l in range(len(S)):
    r = l + 4
    while r <= len(S):
        s = S[l:r]
        tmp = int(s)
        if tmp % 2019 == 0:
            ans[r] += 1
            #print("{}{}".format("!!!",tmp))
            break;
        else:
            #print(tmp)
            r += 1

l = r
ans[l] = ans[l]*ans[r]
print(sum(ans))

Submission status: Time Limit Exceeded

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

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

    for i in range(len_s):
        # xx = max(dp[i])
        # for j in range(max(i, dp[i].index(xx)+1), len(s), 1):
        for j in range(i, len(s), 1):
            if int(s[i:j+1]) % 2019 == 0:
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j], dp[i][j] + 1)
            else:
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])

    print(dp[len_s][len_s])

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = int(S)
l = len(S)
n0_min = 0
n0_max = l - 4
n1_min = 4
n1_max = l + 1

ll = []
ans = 0
for x in range(n0_min, n0_max):
    for y in range(n0_min + 4, n1_max):
        ss = S[x:y]
        if (len(ss) > 4):
            n = int(ss)
            if (n % 2019) == 0:
                ans += 1
            ll.append(str)
print (ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
 
 
def solve(S: int):
    cnt = 0
    for i in range(len(str(S))):
        for j in range(i + 1, len(str(S))):
            s = str(S)[i:j+1]
            if '0' in s:
                continue
            if not int(str(S)[i:j+1]) % 2019:
                cnt += 1
    print(cnt)
    # cnt = 0
    # l = filter(lambda x: '0' not in str(x), range(2019, 200000, 2019))
    # l = [str(i) for i in l]
    # s = str(S)
    # for i in range(len(s)):
    #     if 5 + i > len(s) - 1:
    #         continue
    #     if s[i:4 + i] in l or s[i:5 + i] in l:
    #         cnt += 1
    # print(cnt)
    return
 
 
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    solve(S)
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import Counter
def div10(d):
    return d//10
def rem2019(d):
    return d%2019
def resolve():
    S = sr()
    N = len(S)
    # a = ['']
    # for i in range(N):
    #     s = S.pop()
    #     a.append(int(s+str(a[i])))
    # a = a[::-1]
    # a[-1] = 0
    # ans = 0
    # for i in range(N):
    #     t = list(map(rem2019, a))
    #     ans += Counter(t)[0]-1
    #     a = list(map(div10, a))
    #     g = a.pop()
    ans = 0
    for i in range(N-3):
        for j in range(i+3, N):
            if int(S[i:j+1])%2019 == 0:
                ans += 1
    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
import itertools
s = input()
s_li = list(s)
lee = len(s_li)

count = 0
keta = list(itertools.combinations([i for i in range(lee)], 2))
for k in keta:
    lk = list(k)
    #print(s_li[lk[0]:lk[1]+1])
    if int(''.join(s_li[lk[0]:lk[1]+1]))%2019 == 0:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
s=input()
n=len(s)
if n<=4:
  print(0)
  sys.exit()  
cnt=0
for i in range(n-3):
  left=i
  right=n-1
  mid=(right+left)//2
  if int(s[i:i+4])%2019==0:
    cnt+=1
    continue
  if int(s[i:i+5])%2019==0:
    cnt+=1
    continue
  if int(s[i:i+6])%2019==0:
    cnt+=1
    continue
  if int(s[i:i+7])%2019==0:
    cnt+=1
    continue  
  while right-left>5:
    if int(s[left:mid+1])%2019==0:
      cnt+=1
      break
    else:
      right=mid
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = input()
a = 0

for i in range(len(N)):
  if int(N[i]) == 0:
    continue
  for j in range(len(N)):
    if i > j:
      continue
    if int(N[i:j + 1]) == 0:
      continue
    if int(N[i:j + 1]) % 2019 == 0:
      a += 1
      

print(a)

Submission status: Time Limit Exceeded

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

    for i in range(0,l-4):
        n = int(s[i])*1000 + int(s[i+1])*100 + int(s[i+2])*10 + int(s[i+3])
        t = n%2019
        for j in range(i+4,l):
            t = t*10 + int(s[j])
            if t % 2019 == 0:
                ans += 1
            
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
a=2019
i=1
ans=0
while a<1e18-2018:
    ss=""
    ss=str(a)
    ans+=s.count(ss)
    i+=1
    a=2019*i
print(ans)

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:
            cnt+=1
            continue


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

S = list(input())

mod = [0] * (2019+1)

tmp = deque([])
for i in range(1, len(S)+1):
    tmp.appendleft(S[-i])
    mod[int("".join(tmp)) % 2019] += 1

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(N-3):
    for j in range(i+4,N):
        if j == i+4:
            temp = int(S[i:j+1])
        else:
            temp = temp*10 + int(S[j])
        #rint(temp)
        if temp%2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s=input()
c=0
t=[0]*(len(s)+1)
for i in [str(i*2019) for i in range(1,10000) if '0' not in str(2019*i)]:
  idx=-1
  while s[idx+1:].count(i)>0:
    idx=s[idx+1:].find(i)
    t[idx+len(i)]+=1+t[idx]
    c+=1
    c+=t[idx]
print(c)

Submission status: Time Limit Exceeded

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

#jが来てあまりがiとなった時に元々のあまりはいくつか
dic = [[0 for j in range(10)] for i in range(2019)]

for i in range(2019):
    for j in range(1,9):
        tmp = (i*10+j)%mod
        dic[tmp][j] = i

# i桁までみたとき、あまりがjの物の個数
dp_sub = [[0 for j in range(2019)]for i in range(n+1)]
dp_sub[1][int(s[0])] = 1

# i桁までみたとき、あまりがjの物の個数
dp = [[0 for j in range(2019)]for i in range(n+1)]
dp[1][int(s[0])] = 1
for i in range(1,n):
    dp_sub[i+1][int(s[i])] = 1
    for j in range(2019):
        dp[i + 1][j] = dp[i][j]
        if dic[j][int(s[i])] != 0:
            dp_sub[i+1][j] += dp_sub[i][dic[j][int(s[i])]]
            dp[i+1][j] += dp_sub[i][dic[j][int(s[i])]]
print(dp[n][0])

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])%673 == 0: 
            	if int(s[i:j])%3 == 0:
              		cnt +=1

    return cnt

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

Submission status: Time Limit Exceeded

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