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
input = sys.stdin.readline

def EachSumStr(x):
    Len = len(x)
    sum = 0
    for i in range(Len):
        sum += int(x[i])
    #print(sum)

S = str(input())
Slen = len(S) - 1
if (Slen < 4):
    print(0)

else:
    ans = 0
    for i in range(Slen - 3):
        for j in range(i+3, Slen):
            Slice = S[i:j+1]
            if ( int(Slice) != 0 and int(Slice) % 2019 == 0):
                ans += 1
                #print(i, j)
    print(ans)
    #print(Slen)

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

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

s = input()
if len(s) < 4:
    print('0')
    sys.exit()
cnt = 0

for h in range(len(s)-4):
    for e in range(h+4, len(s)+1):
        if int(s[h:e]) % 2019 == 0:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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):
        for j in range(1, len_s + 1):
            if not (i < j):
                continue
            if int(S[i:j]) % 2019 == 0:
                answer += 1
    return answer


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

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

if len(S) <= 3:
  print(cnt)
  exit()

for i in range(len(S)-3):
  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 = list(input())

ans = 0
for i in range(len(s)-3):
    for y in range(i+3, len(s)):
        if int("".join(s[i:y+1])) % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections as c

S = input()
N = len(S)
MOD = 2019
dp = [0] * (len(S))
for i in range(N):
    dp[i] = int(S[-(i+1):]) % 2019

D = c.Counter(dp)
ans = 0
for k,v in zip(D.keys(),D.values()):
    if k == 0:
        ans += v
        ans += v * (v - 1) //2
    elif v >= 2:
        ans += v * (v - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = input()
n_len = len(n)
count = 0
for cut_length in range(4,n_len + 1):
    for first in range(0,n_len - cut_length + 1):
        cuted_num = int(n[first:first + cut_length])
        if(cuted_num % 2019 == 0):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
inf = float('inf')

s = input()
n = len(s)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
sm = [0]
for i in range(len(s)):
    sm.append(sm[-1] + int(s[i]))
#2 * 10 ** 5
n = len(s)
cnt = 0
if n < 4:
    print(cnt)
else:
    for i in range(4,n+1):
        for j in range(n-i+1):
            if (sm[j+i] - sm[j]) % 3 == 0:
                if int(s[j:j+i]) % 673 == 0:
                    cnt += 1
    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):
        n = s[i:j]
        if int(n) % 2019 == 0:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

count = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    L = list(range(2019, 2 * (10 ** 5), 2019))
    n = len(s)

    cnt = 0
    for i in range(n):
        for j in range(i, n):
            for k in L:
                S = "".join(s[i:j + 1])
                if str(k) == S:
                    cnt += 1
    print(cnt)


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
# import math
# import numpy as np
# import itertools
# import heapq
# =map(int,input().split())
a=input()
n=len(a)
ans=0
for i in range(n-4):
    for j in range(i+4,n):
        x=a[i:j+1]
        v=int(x)
        if v%2019==0:
            ans+=1
            # print(v)
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(1,l+1):
    for j in range(0,l-i+1):
        ss=s[j:j+i]
        ss_n=int(ss)
        if ss_n%2019==0:
            k+=1

print(k)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def main():
    s = input().rstrip()
    n = len(s)
    ans = 0
    for l in range(4,n):
        for i in range(n-l+1):
            if int(s[i:i+l])%2019 == 0:
                ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    S = input()
    list_S = list(S)
    len_S = len(list_S)
    ans = 0

    if len(list_S) <= 3:
        print(ans)
        return

    for start_i in range(0, len_S - 3):
        for last_i in range(3, len_S):
            tmp = ''.join(list_S[start_i:last_i + 1])
            if tmp:
                tmp_ans = int(tmp) % 2019

                if tmp_ans == 0:
                    ans += 1

    print(ans)


resolve()

Submission status: Time Limit Exceeded

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

S = input()
n = len(S)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#2019の倍数は
Next = [i*10 % 2019 for i in range(2019)]
S = input()
DP = [[0 for j in range(2019)]for i in range(len(S))]#DP[l][d] l桁目(0-index)まで見た時に、余りがdであるような数
ans = 0
for l,s in enumerate(S):
    n = int(s)
    DP[l][n] += 1
    for am,d in enumerate(DP[l-1]):
        DP[l][(10*am + n) % 2019] += d
    ans += DP[l][0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def get_2019():
    all = input()
    total = 0

    for n in range(len(all)):
        i=4
        x=total
        while n+i<=len(all):
            cut = int(all[n:n+i])
            if cut%2019 == 0:
                total+=1
                break
            else:
                i+=1
    print(total)

    return None
get_2019()

Submission status: Time Limit Exceeded

Solution code:
S=input()
length=len(S)
S=int(S)
count={}

for i in range(length+1):
    mod=(S%(10**i))%2019
    count[mod]=count.get(mod,0)+1


retval=0
for key in count:
    retval+=count[key]*(count[key]-1)//2

print(retval)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()

def is_multiple(s):
    return int(s) % 2019 == 0
print(sum([is_multiple(S[i:i+j+4]) for i in range(len(S)) for j in range(len(S)-(i+3))]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
numbers = []
current_num = 2019

while current_num < 200000:
    numbers.append(str(current_num))
    current_num += 2019

ans = 0

for i in range(len(s)+1):
    for j in range(i+3, len(s)+1):
        focus = s[i:j]
        if focus in numbers:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0

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

Submission status: Time Limit Exceeded

Solution code:
# D - Multiple of 2019

s = str(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
l=len(s)
se=dict()
for i in range(l):
    k=int(s[i:l])%2019
    if k in se:
        se[k]+=1
    else:
        se[k]=1

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
count = 0
for i in range(len(s)):
    for j in range(i+3,len(s)+1):
        ans = int(s[i:j])
        if ans % 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+2,len(s)):
        sa=int(s[i:j+1])
        if sa%2019==0:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def d164(n):

    ans = 0
    s = list(map(str, n))

    for i in range(len(s)-3):
        count = ""
        for w in range(i, len(s)):
            count += s[w]
            if int(count)%2019 == 0:
                ans += 1
    return ans

def main():
    n = str(input())
    print(d164(n))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import time
import math
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
S=list(reversed(input()))
lst=[0 for i in range(len(S))]
num=0
z=1
for i in range(len(S)):
    num+=int(S[i])*z
    num%=2019
    z*=10
    lst[i]=num
lst=Counter(lst)
lst[0]+=1
count=0
for l in lst:
    n=lst[l]
    count+=n*(n-1)//2
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
s = input()
ans = 0
a = [i for i in range(len(s))]
for j,k in itertools.combinations(a,2):
    if j<k:
        if int(s[j:k+1]) % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc164/tasks/abc164_d

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

Submission status: Time Limit Exceeded

Solution code:


s = input()


starti = 0
endi = 3
ans = 0

while True:
    num = int(s[starti:endi+1])
    if num % 2019 == 0:
        ans += 1
    
    if endi+1 < len(s):
        endi += 1
    else:
        starti += 1
        endi = starti + 3
        if endi >= len(s):
            print(ans)
            break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
S = input()
ans = 0
for i in range(len(S)-3):
    for j in range(i+3,len(S)+1):
        p = int(S[i:j])
        if p % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# input
S = input()

# process
ans = 0
for j in reversed(range(len(S), 0, -1)):
    i = j-1
    flg = False
    while i >= 0:
        if flg and S[i] == 0:
            ans += 1
        else:
            flg = False
            if int(S[i:j])%2019 == 0:
                ans += 1
                flg = True
        i -= 1

# output
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
result = 0
for i in range(len(S)):
    for j in range(3+i,len(S)):#4桁後から
        if int(S[i:j+1]) % 2019 == 0:
            result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
s = list(str(input()))

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = '0' + input()
n = len(s)
cnt = 0

dp = []

for i in range(1, n-2):
	for j in range(i+3, n+1):
		tmp = int(s[i:j])
		if tmp in dp:
			cnt += 1
		elif tmp % 2019 == 0:
			dp.append(tmp)
			cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()

l=len(s)

count=0
for i in range(l):
    for j in range(i,l):
        cu=s[i:j+1]
        test=int(cu)
        if test % 2019 ==0:
            count=count+1

print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
s = input()
if int(s) < 2019:
    print(0)
else:
    count = 0
    for i in range(4, len(s) + 1):
        for j in range(0, len(s) + 1 - i):
            if int(s[j:(j+i)]) % 2019 == 0:
                count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
s=[str(x) for x in input()]

sum=0
for i in range(len(s)-3):
    for j in range(i+3,len(s)):
        t=''.join(s[i:j+1])
        if int(t)%2019==0:
            sum+=1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

s = input()
num = len(s)
nums = [_ for _ in range(0, num)]
# print(nums)
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n_list = list(input())
x = len(n_list)
counter = 0
for L in range(4, x+1):
    for j in range(x+1-L):
        temp = eval("".join(n_list[j:j+L]))
        if temp % 2019 == 0:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import fractions
import collections
import itertools
from collections import deque
S=input()
N=len(S)
cnt=0
l=[]
"""
cnt=0
p=10**9+7
for i in range(K,N+2):
    cnt=(cnt+((N-i+1)*i)+1)%p
    #print(((N-i+1)*i)+1)
print(cnt)
"""
amari=[0]*(N+1)
num=0
for i in range(N):
    num=num+pow(10,i)*int(S[N-1-i])
    amari[i+1]=num%2019
#print(amari)
c=collections.Counter(amari)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
#for i in range(len(key)):
#    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#xprint(l)
for i in range(len(values)):
    cnt=cnt+(values[i]*(values[i]-1))//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys

s = sys.stdin.readline()

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

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    MOD = 2019

    S = [int(s) for s in input()]
    N = len(S)
    dp = [[float('inf') for _ in range(N + 1)] for _ in range(N + 1)]

    dp[0][0] = S[0] % MOD

    for i in range(N):
        for j in range(i, N):
            if i == j:
                dp[i][j] = S[i] % MOD
            else:
                dp[i][j] = (dp[i][j - 1] * 10 + S[j]) % MOD

    print(sum([row.count(0) for row in dp]))

Submission status: Time Limit Exceeded

Solution code:
cnt = 0
S = input()  
for left in range(len(S)-3):
    for right in range(left+3,len(S)):
        if int(S[left:right+1]) < 2019:
            continue
        if int(S[left:right+1]) % 2019 == 0:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

if N < 4:
    ans=0
else:
    ans = 0
    for i in range(N-3):
        for j in range(i+3,N):
            n=int(S[i:j+1])
            if n%2019==0:
                ans +=1
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(i+1, j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 1<=S<=200000
S = str(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
# input処理を高速化する
input = sys.stdin.readline

S=input()
N=len(S)

number=''
cnt=0
for i in range(N-2):
    for j in range(i+4,N):
        number=S[i:j]
        if int(number)%2019 ==0:
            cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
N = len(S)
l = 0
r = 0

amari = [0] * N
for i in range(1, N+1):
  kazu = S[N-i:N]
  amari_ = int(kazu) % 2019
  amari[i-1] = amari_

from collections import Counter
c = Counter(amari).most_common()

ans = 0
for i in c:
  if i[1] != 0:
    ans += i[1] * (i[1]-1) // 2
  if i[0] == 0:
    ans += i[1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s_l = list(input())

ans = 0
for i in range(len(s_l)-1):
    for j in range(i+3,len(s_l)):
        val = int(''.join(s_l[i:j+1]))
        if val%2019 == 0 and val != 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math

s = input()

# a = [
#     0, 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
# ]

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()

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
#input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    S = input()
    
    l = []
    base = 1
    for st in S[::-1]:
        l.append((int(st)*base)%2019)
        base *= 10
        
    cum = 0
    d = defaultdict(int)
    d[0] = 1
    
    ans = 0
    for num in l:
        cum += num
        ans += d[cum%2019]
        d[cum%2019] += 1

    print(ans)
    
if __name__ == "__main__":
    main()

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 a[0]==1:
            continue
        if int(a)%2019==0:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools
import heapq
#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    s=list(map(str,input()))
    dp=[0 for _ in range(len(s)+2)]
    for i in range(len(s)+1):
        for j in range(i):
            temp=int("".join(s[j:i]))
            if temp%2019==0:
                dp[i]+=1
        if i>=1:
            dp[i]+=dp[i-1]
    print(max(dp))




if __name__ == "__main__":

    main()

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
numbers = []
current_num = 2019

while current_num < 200000:
    numbers.append(str(current_num))
    current_num += 2019

ans = 0

for i in range(len(s)+1):
    for j in range(i+1, len(s)+1):
        focus = s[i:j]
        if focus in numbers:
            ans += 1

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
for i in range(len(S)-4):
    for j in range(i+4, len(S)):
        x = int(S[i:j+1])
        if x % 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):
        for j in range(1, len_s + 1):
            if not (i < j):
                continue
            answer += int(int(S[i:j]) % 2019 == 0)
    return answer


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

Submission status: Time Limit Exceeded

Solution code:
s=input()

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

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
			#print(s[i:j+1])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = str(input())

#N = str(1817181712114)

count = 0
for i in range(len(N)+1):
    for j in range(i+4, len(N)+1):
        number = int(N[i:j])
        if number%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(i+3, len(S)):
        total=0
        for k in range(i,j+1):
            total += int(S[k])*10**(j-k)
        if total%2019==0:
            count+=1
print(count)

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(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)