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()
l=len(S)
z=0
for x in range(l):
    for y in range(l-x):
        T=S[x:x+y+1]
        t=int(T)
        
        if t%2019==0:
            z+=1
print(z)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!


d = 2019

def solve(s):
    dp = [0] * (len(s)+1)
    dp[len(s)] = 0
    for i in range(len(s)-1,-1,-1):
        dp[i] = int(s[i:]) % d
    memo = [0]*2019
    count = 0
    for i,v in enumerate(dp):
        if memo[v] != 0:
            count+=1
        memo[v] += 1
    return count

s = input()
print(solve(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if __name__=='__main__':
    main()

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))):
    #         if not int(str(S)[i:j]) % 2019:
    #             cnt += 1
    # print(cnt)
    cnt = 0
    l = filter(lambda x: '0' not in str(x), range(2019, 200000, 2019))
    for i in l:
        for j in range(len(str(S))):
            if len(str(i)) - 1 + j > len(str(S)) - 1:
                continue
            if str(S)[j:len(str(i)) + j] == str(i):
                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=0
for i in range(len(S)):
   for j in range(i+3,len(S)):
    n=int(S[i:j+1])
    if n%2019==0:
      s+=1
print(s)

Submission status: Time Limit Exceeded

Solution code:
a=input()
counter = 0
s_length = len(a)
turn = False

for i in range(s_length - 2):
    current_num = 0
    for j in range(i + 3, s_length + 1):
        if turn==True :
            if j - current_num == 4:
                if int(a[i:j]) % 2019 == 0:
                    current_num = j
                    counter += 1
                    turn = True
                else:
                    turn = False


        elif int(a[i:j]) % 2019 == 0:
            current_num = j
            counter += 1
            turn = True

print(counter)

Submission status: Time Limit Exceeded

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

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

    else:
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

ans = 0
tot = [str(0)]

for i in range(len(S)-1):
  for j in range(i+3,len(S)):
    if int(''.join(tot)) % 2019 == 0 and int(''.join(tot)) >= 2019:
      ans += 1
    tot = [str(0)]
    for k in range(i,j+1):
      tot.append(S[k])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
res = 0

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
s = input()

match = 0
end = len(s)
for i in range(end - 3):
    for j in range(i + 3, end + 1):
        val = int(s[i:j])
        if val >= 2019 and val % 2019 == 0:
            match += 1

print(match)

Submission status: Time Limit Exceeded

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

	

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
num=0
res=0
if int(S)<2019:
    res =0
else:
    for i in range(len(S)-1):
        for n in range(i+3,len(S)+1):
            num=int(S[i:n])
            if num%2019==0:
                res = res+1
print(res)

Submission status: Time Limit Exceeded

Solution code:
s = input()
# s = list(x)

count = 0
# l = []

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
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 math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
S = int(input())
count = 0
l = [0]*2019

for i in range(1,len(str(S))+1):
   l[(S%10**i)%2019] += 1

count += l[0]
for j in range(1,len(l)):
    if l[j] >= 2:
        count += comb(l[j],2)

print(count)

Submission status: Time Limit Exceeded

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

i = 0
while i < len(s):
    j = i + 4
    while j <= len(s):
        if int(s[i:j]) % 2019 == 0:
            ans += 1
            break
        j += 1
    
    i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def sol():
    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)


if __name__ == '__main__':
    sol()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    simo4 = set()
    for i in range(1,100001):
        s = str(2019*i)
        if '0' not in s:
            simo4.add(''.join([s[-4],s[-3],s[-2],s[-1]]))

    l = len(S)
    ans = 0
    for i in range(l-1,2,-1):
        tmp = ''.join([S[i-3],S[i-2],S[i-1],S[i]])
        if tmp not in simo4:
            continue
        else:
            if int(tmp)%2019 == 0:
                ans += 1
            for j in range(i-4,-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:
def get_offset(S):
    result = []
    for i in range(length):
        has_found = False
        for j in range(i+1, length):
            num = int(S[i:j])
            if num % 2019 == 0:
                has_found = True
                result.append((i+1, j))
        if has_found:
            return result
    print(0)
    exit(0)

S = input()
length = len(S)

offsets = get_offset(S)

ans = 0
for head, tail in offsets:
    offset = tail - head
    ans += (length - head) // offset

print(ans)

Submission status: Time Limit Exceeded

Solution code:

S = str(input())

n = len(S)

cnt = 0
for i in range(n-3):
    for j in range(i+3, n+1):
        s = S[i:j]

        if int(s) % 2019 == 0:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:


def main():
    S = input()

    count = 0

    for i in range(len(S)):
        for b in range(i+4,len(S)+1):
            # print(S[i:b])

            if int(S[i:b]) % 2019 == 0:
                # print("THATS : {}".format(S[i:b]))
                count += 1
            else:
                continue


    print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

L = []
for i in range(len(S)+1):
  for j in range(len(S)+1):
    if i<j:
      L.append(S[i:j])
B = list(map(int,L))
A = list(filter(lambda x:x%2019==0,B))
print(len(A))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

length = len(S)

cnt = 0
temp = int(S[ : 4])
for x in range(length):
    first = temp
    for i in range(x + 4, length + 1):
        if temp % 2019 == 0:
            cnt += 1
        #print(temp, cnt)

        if i < length:
            temp = temp * 10 + int(S[i])
        else:
            if x + 4 < length:
                temp = (first - (int(S[x]) * 1000))
                temp = temp * 10 + int(S[x + 4])



print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from typing import Dict, List, Optional, Set, Tuple


def solve(s: str) -> int:
    # remainders = defaultdict(int, {0: 1})
    modulo = 2019
    curr = 0
    result = 0
    for i, c in enumerate(s):
        curr = 10 * curr + int(c)
        # values_from_start.append(curr)
        # LOG.debug(("curr:", curr))
        for j in range(i - 3 + 1):
            # LOG.debug((i, j, s[j : i + 1]))
            if int(s[j : i + 1]) % modulo == 0:
                # LOG.debug(("found: ", s[j : i + 1]))
                result += 1
    return result


def do_job():
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    S = input()
    # values = list(map(int, input().split()))
    # values = []
    # for _ in range(N):
    #     values.append(input().split())
    result = solve(S)
    print(result)


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))
    # 6 digits float precision {:.6f} (6 is the default value)
    # print("Case #{}: {:f}".format(testcase + 1, result))


def configure_log() -> None:
    "Configure the log output"
    log_formatter = logging.Formatter("%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            # uncachable -- for instance, passing a list as an argument.
            # Better to not cache than to blow up entirely.
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
counter = 0
#iは切り出す文字列の長さ
for i in range(1,L+1):
    for j in range(L-i+1):
        if int(S[j:i+j]) % 3 == 0:
            if int(S[j:i+j]) % 673 == 0:
                counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    S = input()

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


main()

Submission status: Time Limit Exceeded

Solution code:
nb = input()

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    # 2019 = 3 * 673
    S = input()
    length = len(S)
    count = 0
    for start in range(0, length-3):
        s = int(S[start:])
        while s >= 2019:
            if s % 2019 == 0:
                count += 1
            s //= 10
    
    print(count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
mods = [0 for i in range(2019)]
mods[0] = 1
res = 0
cnt = 0
ss = 0

for i in range(n - 1, -1, -1):
    ss = int(s[i]) * (10 ** cnt) + ss
    cnt += 1
    curr = ss % 2019
    res += mods[curr]
    mods[curr] += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
import math


#計算量を無視して愚直に実装してみる
S = input() #文字列型で受け取る
N = len(S)
#print(len(S))

#5桁以上しか探索しないコード
sg = []
for i in range(N):
    j = 5
    while i+j <= N:
        sg.append([i, i+j])
        j += 1
#print(sg)
counter = 0
for i in range(len(sg)):
    s = S[sg[i][0]:sg[i][1]]
    if(int(s)%2019==0):
        counter += 1
print(counter)



'''
index = [i for i in range(len(S))]
combi = list(combinations(index, 2))
#print(combi)

counter = 0
for i in range(len(combi)):
    #print()
    #print('start:{},goal:{}'.format(combi[i][0], combi[i][1]+1))
    s = S[combi[i][0]:combi[i][1]+1]
    #print('s:{},s%2019:{}'.format(s, int(s)%2019))
    #print()
    if(int(s) % 2019 == 0):
        #print('hit')
        counter += 1
print(counter)
'''


'''
#実験1
def is_there_0(K):
    #文字列入力
    ret = 'No'
    for i in range(len(K)):
        if(K[i] == '0'):
            ret = 'Yes'
    return ret

for i in range(1000):
    if(is_there_0(str(2019*i)) == 'No'):
        print('i:{}, 2019*i:{}'.format(i, 2019*i))
'''




















'''
#実験2
l = []
for i in range(10000):
    l.append( (2019*i)%10000 )

l = sorted(l)
#print(l)
print(len(l))
'''

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
si = int(s)
a = 2019
cnt=2
start=0
c=0
findings = []
while(a<si):
    if(str(a) in s):
        c = s.find(str(a), start)
        while(c>=0):
            findings.append([c+1,c+len(str(a))])
            start+=c+1
            c=s.find(str(a), start)
        start=0
    a=2019*cnt
    cnt+=1
print(len(findings))

Submission status: Time Limit Exceeded

Solution code:
S=input()
length=len(S)
if length<=3:
    print(0)
else:
    ans=[]
    for i in range(length):
        for j in range(4,length-i+1):
            if int(S[length-i-j:length-i])%2019==0:
                ans.append([i,j])
                break
    print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
# I = INT()
I = int(S)
N = len(S)
left = 0
l = []
dp = [0] * (N + 1)
ans = 0
for right in range(N):
    for left in range(right):
        # if left < right:
        # l.append(S[right])
        # s_str = "".join(l)
        s_str = S[left:right+1]
        tmp = int(s_str)
        # print(tmp)
        if tmp % 2019 == 0:
            # print(tmp // 2019)
            # print(tmp)
            # dp[right] += 1
            ans += 1
print(ans)
    





exit()
L = len(n)
K = 10
# dp[i][j][k]
# j その地点で持っている2019の数
#
dp = [[[0] * 2 for i in range(K)] for i in range(L+1)]
# K+1のところKにした

dp[0][0][0] = 1

for i in range(L):
    for j in range(1, K):
        for k in range(2):
            nd = int(n[i])
            for d in range(1, 10):
                ni = i + 1
                nj = j
                nk = k
                
                if d == 1:
                    nj += 1
                # 10 ** 9 より大きくなることはない
                if nj > 9:
                    continue
                #    
                if k == 0:
                    if d == nd:
                        nk = 0
                    if d > nd:
                        continue
                    if d < nd:
                        nk = 1

                dp[ni][nj][nk] += dp[i][j][k]
# ans = dp[L][K][0] + dp[L][K][1]

print(dp)
# ans = 0
# # iをかけた(?)
# for i in range(1, 10):
#     ans += i * (dp[L][i][0] + dp[L][i][1])
# # print(dp)
# print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0
is_end = [False] * (len(S) + 1)
for i in range(len(S)):
    if is_end[i]:
        continue
    is_end[i] = True
    bingo = [i]
    for j in range(i+1, len(S)+1):
        if int(S[i:j]) % 2019 == 0:
            is_end[j] = True
            bingo.append(j)
    l = len(bingo)
    if l >= 2:
        cnt += int(l*(l-1)/2)
print(cnt)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
S = input()
cum = []
for i in range(len(S)-1, -1, -1):
    n = int(S)
    n = n % 10**(i+1)
    cum.append(n % 2019)
cum = sorted(cum)

prev = cum[0]
ans = 0
cnt = 0
for c in cum:
    if c != prev:
        if prev == 0:
            ans += cnt
        ans += cnt * (cnt-1) // 2
        cnt = 1
    else:
        cnt += 1
    prev = c

if cnt > 1:
    if prev == 0:
        ans += cnt
    ans += cnt * (cnt-1) // 2
    cnt = 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def slove(n):
    count = 0
    num = len(n)+1
    memo = {}
    for i in range(num-4):
        for j in range(i+4, num):
            tmp = int(n[i:j])
            if tmp in memo and memo[tmp]:
                count+=1
            else:
                if tmp % 2019 == 0:
                    count += 1
                    memo[tmp] = True

    return count

if __name__ == "__main__":
    n = input()
    print(slove(n))

Submission status: Time Limit Exceeded

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

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

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s= list(input())
n= len(s)
count=0
for i in range(0,n):
    p= (int(s[i])*(10**(n-1-i)))%2019
    s[i]=p


for j in range(0,n-4):
    tem=s[j]
    for k in range(j+1,n):
        tem+=s[k]
        if tem % 2019==0:
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

from collections import deque

def main():
  d_origin = deque(input())

  ans = 0
  for i in range(len(d_origin)):
    if i != 0:
      d_origin.popleft()
    d = d_origin.copy()
    for j in range(len(d)):
      if int(''.join(d))%2019 == 0:
        ans += 1
      d.pop()
  print(ans)

if __name__ == '__main__':
  main()

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
			#print(i,j)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

l = len(s)
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#d
N = int(input())
s  = str(N)
a =[]

def func(string,p):
    count=0
    for x in range(len(string)-len(p)+1):
        if string[x:x+len(p)]==p:
            count+=1
    return count

for i in range(1,10000):
    a.append(str(2019*i))
if len(s)<4:
    print(0)
else:
    ans=0
    for j in a:
        ans+=func(s,j)
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

dp = [0] * (n + 1)

for i in range(3, n):
	cnt = 0
	j = 0
	while i - j >= 3:
		sub = s[j:i+1]
		if int(sub) % 2019 == 0:
			cnt += 1
		j += 1
	dp[i] = dp[i - 1] + cnt

print(dp[n-1])

Submission status: Time Limit Exceeded

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

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

print(cnt)

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = int(len(S))
S = int(S)
A = 0

for i in range(N-3):
    S1 = S //(10**i)
    for j in range(N-3-i):
        S2 = S1 % (10**int(N - i - j))
        if S2 % 2019 == 0:
            A = A + 1

print(A)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = []
for i in range(1, 101):
    e = 2019 * i
    if e > 200000:
        break
    l.append(str(e))

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

print(ans)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(l - 3):
    for j in range(i + 4,l + 1):
        str = s[i:j]
        #print("str is " + str)
        if int(str) % 2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    result = 0
    L = len(S)
    for i in range(L-3):
        j = i + 3
        for _ in range(10**6):
            if j >= L:
                break
            if int(S[i:j+1]) % 2019 == 0:
                result += 1
                j += 3
            j += 1
    print(result)
main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=[int(x) for x in list(str(input()))]
ans=0
for i in range(1,len(s)+1):
    for j in range(i+2,len(s)+1):
        figure=0
        if(sum(s[-i:-j-1:-1])%3==0):
            for k in range(j-i+1):
                figure+=s[-(i+k)]*10**k
            if(figure%673==0):
                ans+=1
                i+=3
                break
print(ans)

Submission status: Time Limit Exceeded

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)

def printSubArrays(arr, start, end, count): 
      
    # Stop if we have reached the end of the array     
    if end == len(arr): 
        print(count)
        return
      
    # Increment the end point and start from 0 
    elif start > end: 
        return printSubArrays(arr, 0, end + 1, count) 
          
    # Print the subarray and increment the starting 
    # point 
    else: 
        if int(''.join(arr[start:end + 1])) % 2019 == 0:
            count += 1

        return printSubArrays(arr, start + 1, end, count) 

          
# Driver code 
arr = list(input())
printSubArrays(arr, 0, 0, 0)

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
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
li = []
ans = 0

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

print(ans)