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()
mod = 2019
ls = len(s)
cnt = 0
for i in range(ls-3):
    for j in range(i+3,ls):
        c = int(s[i:j+1])
        if c%mod ==0:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
m=2019
s_int=[]
ans=0
for i in range(n):
  s_int.append(int(s[i]))

for i in range(n-1):
  x=s_int[i]
  for j in range(i+1,n):
    x=(x*10+s_int[j])%m
    if x==0:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
S = int(input())

str_S = str(S)
count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
usr_iput_int = int(input())
usr_inpt_str = str(usr_iput_int)

ans = 0

for n in range(4, len(usr_inpt_str) + 2, 1):
    for i in range(0, len(usr_inpt_str) - n + 1, 1):
        if int(usr_inpt_str[i:i+n]) % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
prefix_base = list(map(int, S))
for i in range(1, len(S)):
    prefix_base[i] += prefix_base[i-1]
prefix = [0] + prefix_base

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0
if  len(s) < 4:
    print(0)
else:
    for i in range(len(s) -4 + 1):
        for j in range(len(s) - 4 + 1 - i):
#             print(i, j + 4, s[i : j + 4 + i])
            if int(s[i : j + 4 + i]) % 2019 == 0:
                count+=1
#                 print(s[i : j + 4 + i])
    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):
        a += int(S[l-j-1])*10**(j-i)
        if a % 2019 == 0:
            count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
CONST = 2019

def main():
    S = input()
    # S = '1817181712114'
    # print(int(S[0:5]), int(S[0:5]) / CONST)
    # print(int(S[5-1:9]), int(S[5-1:9]) / CONST)
    # print(int(S[9-1:13]), int(S[9-1:13]) / CONST)
    
    isFinish = False
    bar = 0
    count = 0
    # while not isFinish:
    
    for i in range(bar, len(S)):
        
        # tmp_bar = copy.copy(bar)
        for j in range(i+1, len(S)+1):
            t = int(S[i:j]) % 2019

            if t == 0.0:
                # print(i, j)
                bar = j
                count += 1
                # break
            else:
                continue
        # if tmp_bar != bar:
        #     break
    print(count)
    

main()

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
N = len(str(S)) - 1
ans = 0
s = S
while N > 2:
    while s >= 2019:
        if s % 2019 == 0:
           ans += 1
        s //= 10
    s = S % (10**N)
    N -= 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()

ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0

for i in range(0, len(S)):

    tmp = int(S[i:i+4]) % 2019

    if tmp == 0:
        count += 1

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
"""
2019 4038 6057 8076 10095
12114 14133 16152 18171
"""

s = input()
count = 0

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

if int(s[-4:])%2019 == 0:
  count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))



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

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
for i in range(len(S) + 1):
    for j in range(len(S) -i +1):
        s = S[i:i + j]
        if s != '' and eval(s) % 2019 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
#D

#デバッグ
debug=1
def pront(*n):
    if debug==0:
        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()


#処理
L=len(S)
#明らかに時間超過しそう
x=0
for i in range(L+1):
    for j in range(i):
       # pront(i,j,S[j:i])
        if int(S[j:i])%2019==0:
            pront(j,i)
            x+=1
print(x)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
c = 0

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
n=str(input())
k=len(n)
ans=0

for i in range(4,k+1):
  for j in range(k-i):
    tmp = int(n[j:j+i+1])
    if tmp % 2019 == 0:
      ans += 1
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
dictmap = {
'0' : 0,
'1' : 1,
'2' : 2,
'3' : 3,
'4' : 4,
'5' : 5,
'6' : 6,
'7' : 7,
'8' : 8,
'9' : 9
}


strnum = input()
count = 0
n = len(strnum)
if int(strnum) < 2019 :
    print("0")
elif n >= 4 :
    for i in range(n - 3) :
        numtillnow = ""
        numtillnow += strnum[i]
        for j in range(i+1,n) :
            numtillnow += strnum[j]
            #print(numtillnow)
            if int(numtillnow)%2019 == 0 :
                count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N = list(input())
N_len = len(N)
cnt = 0
a_list = []
t_list = []
for i in range(N_len+1):
    for j in range(i+1, N_len+1):
        a_list.append(N[i:j])
tmp = 1
while tmp < 100:
    t_list.append(list(str(2019*tmp)))
    tmp += 1

for a in a_list:
    if a in t_list:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0
#for c in range( int(s) // 2019 ):
#    d = ( c + 1 ) * 2019
#    print( d )
#    for n in range( len( str(s) ) - len( str(d) ) ):
#        if str( d ) in str( s )[n:]:
#            cnt += 1

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

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    memo = set()
    cnt = 0
    for i in range(len(S)):
        for j in range(i+3,len(S)):
            _ = int(S[i:j+1])
            if _ in memo:
                cnt += 1
            elif _%2019==0:
                cnt += 1
                memo.add(_)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Time Limit Exceeded

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

MOD = 2019
T = []
S.reverse()
cnt = 0
temp = 0
for i in S:
    temp += i*10**cnt % MOD
    temp %= MOD
    T.append(temp)
    cnt += 1

T.reverse()
T.append(0)

ans = [0]*2019

for i in T:
    ans[i-1] += 1

ans2 = 0
for i in ans:
    ans2 += i*(i-1)//2
print(ans2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline


def solve():
    S = input().strip()
    len_s = len(S)
    answer = 0
    for i in range(len_s - 3):
        for j in range(i + 3, len_s + 1):

            number = S[i:j]

            if sum(map(int, number)) % 3 != 0:
                continue

            if int(number) % 673 == 0:
                answer += 1
    return answer


if __name__ == '__main__':
    answer = solve()
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
s = input()

answers = [(start, end) for start in range(len(s)-3)  for end in range(start+4, len(s)+1)
           if int(s[start:end]) % 2019 == 0]
print(len(answers))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
 
def main():
    s = list(map(int,input()[::-1]))
 
    t = []
    m = 0
    for i,s_i in enumerate(s):
        m = m+s_i*10**i
        t.append(m%2019)
    
    c = Counter(t)
    ans = c[0]
    for i in c.values():
 
        ans += i*(i-1)//2
    print(ans)
 
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	S = input()
	S = S[:-1]

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

	print(ans)


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
def solve():
    s = input()
    n = len(s)
    
    if int(s) < 2019:
        return 0
    
    c = 0

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

print(solve())

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    cnt = 0
    for i in range(len(s)-3):
        for j in range(i+3, len(s)+1, ):
            if i == j : continue
            tmp = s[i:j]
            if int(tmp) % 2019 == 0:
                cnt += 1
    print(cnt)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(len(ij))

Submission status: Time Limit Exceeded

Solution code:
S = input()

N = len(S)
if N < 4:
    print(0)
elif N == 4:
    ans = 0 + 1*(int(S)%2019 == 0)
    print(ans)
    
else:
    ans = 0
    for n1 in range(N-3):
        for n2 in range(n1+4, N+1):
            num = S[n1:n2]
            L = len(num)
            temp = 0
            temp2 = int(num)
            if not temp2 == 0:
                for l in range(L):
                    temp += int(num[l])

                if temp%3 == 0:
                    temp2 = int(num)//3
                    
                    if temp2%673 == 0:
                        ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    

s=input()

l=len(s)
cnt=0



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

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    S = input()

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s = input()
ls = len(s)
ans = 0
d = deque()
for i in range(ls-3):
    for j in range(i+3, ls+1):
        d.append(int(s[i:j]))
d2 = list(filter(lambda x: x//2019>0 and x % 2019==0, d))
print(len(d2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

N = 0
for Num1 in range(0, Len-2):
    #0-> 3
    #Len-4 -> Len-1
    for Num2 in range(Num1+4, Len+1):
        Num = int(S[Num1:Num2])
        if(Num%2019 ==0):
            N+= 1
print(N)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = str(input())
x = 0
count = 0
for i in range(len(N)):
    for j in range(3,len(N)):
        if i + j > len(N):
            pass
        else:
            x = int(N[i:i+j])
            if x % 2019 == 0:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
# print(S)

if int(S) < 2019:
    print(0)
    exit()

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
	s = int(input())
	l = []
	length = 0
	ans = 0
	for i in range(sum(range(1,len(str(s))-2))):
		for l in range(len(str(s))-3):
			if len(str(s)[i:(l+4)]) >= 4:
				if int(str(s)[i:(l+4)]) % 2019 == 0:
					ans += 1

	print(ans)

	

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
# n = int(input())
# s = input()
# a = list()
s = input()
# a, b, c, d = map(int, input().split())
count = 0
for i in range(len(s)):
    for j in range(i+4,len(s)+1):
        val = int(s[i:j])
        if val % 2019 == 0:
            count+=1
            j +=3
print(count)

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = len(s)

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

j_max = len(S)

count = 0

for i in range(j_max):
    for j in range(j_max):
        if j - i < 4:
            continue
        target = int(S[i:j + 1])
        if (target % 2019 == 0):
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
rst=[0 for j in range(2019)]
x=0
ans=0
for i in range(n):
    y=(int(s[n-1-i])*(10**i))%2019
    x+=y
    if x>=2019:
        x%=2019
    #print(x,y)
    ans+=rst[x]
    rst[x]+=1
if rst[0]==1:
    ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    print(ans)

solve()

Submission status: Time Limit Exceeded

Solution code:

S = str(input())
L = len(S)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=str(input())

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

Submission status: Time Limit Exceeded

Solution code:
import math

s = input()

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

N = len(s)

cnt = 0

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

print(cnt)