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()
si=[int(ii) for ii in list(s)]
#print(si)
ls=len(si)
r=0
if ls<=3:
  print(r)
  exit()
import numpy as np
r=[]
sumij=[[False]*(ls) for ii in range(ls-3)]

def find0000(s):
	ls=len(s)
	if ls<4:
		return(0)
	for ii in range(ls-3):
		for jj in np.arange(ii+3,ls+1):
    			if s[ii:jj]=="0000":
    				for kk in np.arange(jj,ls+1):
    					if s[kk]!="0":
    					    return(find0000(s[0:ii])+find0000(s[kk:ls]))
	n=0
	for ii in range(ls-3):
    		for jj in np.arange(ii+4,ls+1):
    			if sum(si[ii:jj])%3==0:
			        ints=int(s[ii:jj])
			        if ints%673==0:
			            if ints in r:
        			        n+=1
        			    else:
        			        n+=1
        			        r.append(ints)

	return(n)

print(find0000(s))

Submission status: Time Limit Exceeded

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

    input = sys.stdin.readline

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

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



    for i in range(1, len(str(s))+1):
        num = s % (10 ** i)
        li_append(int(num) % 2019)
        if num_old == num:
            f += 1
        else:
            mi += cm[f+1]
            f = 0
        num_old = num

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

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

answer = 0

Li = len(S)
for i in range(Li):
  Lj = Li - i
  for j in range(Lj):
    Sij = S[i:i+j+1]
    Sij_int = int("".join(map(str,Sij)))
    if Sij_int % 2019 == 0:
      answer += 1

print(answer)

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=int(s)
m=len(s)
if n<2019:
    print(0)
    exit()
from collections import Counter
c=Counter()
for i in range(m+1):
    c[(n%(10**i))%2019]+=1

ll=c.most_common()
ans=0
for i,j in ll:
    if j>=2:
        ans+=j*(j-1)//2
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
n=[]
ans=0
for i in range(len(s)):
  a=int(s[i])
  n.append(a)
for j in range(len(n)-3):
  for k in range(j+3,len(n)):
    #if n[k]==0 or n[k]==2 or n[k]==4 or n[k]==5 or n[k]==6 or n[k]==8:
    #  break
    sum=0
    for l in range(j,k+1):
      sum=sum+n[l]
    if sum%3==0:
     
     # print(k)
      num=0
      for m in range(k-j,-1,-1):
        num=num+n[k-m]*(10**(m))
      #print(num)
      if num%2019==0:
        ans=ans+1
#print(len(n))
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=2019
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    A=list(map(int,list(input())))
    N=len(A)
    d=[0]*2019
    for i in range(2019):
        d[i]=(i*10)%MOD
    dp=[defaultdict(int) for _ in range(N+1)]
    ans=0
    for i,x in enumerate(A):
        for j in dp[i]:
            dp[i+1][(d[j]+x)%MOD]+=dp[i][j]
        dp[i+1][x]+=1
        ans+=dp[i+1][0]
    print(ans)

    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
X = [int(S[i:j]) for i in range(0, len(S) - 4) for j in range(i + 4, len(S) + 1)]
Y = list(map(lambda x: x % 2019, X))
print(Y.count(0))

Submission status: Time Limit Exceeded

Solution code:
problemInput = input()
count = 0

for i in range(1, len(problemInput)):
    for j in range(0, i):
        temp_str = problemInput[j: i+1]
        tempNum = int(temp_str)

        if tempNum % 2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0

for i in range(0, 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=list(input())
S=[]
for i in range(len(s)):
    S.append(int(s[i]))
from collections import defaultdict
D = defaultdict(int)
ans=0
for i in range(len(S)):
    d=defaultdict(int)
    d[S[i]]=1
    for k,v in D.items():
        d[(k*10+S[i])%2019]+=v
    ans+=d[0]
    D=d
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

s = input()
count = 0

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

Submission status: Time Limit Exceeded

Solution code:
s_input=input()
s=list(s_input)
j=0
s_num=0
end=0
if 4<len(s):
    while end==0:
        for i in range(3,len(s)):
            s_num=s_input[j:i+1]
            if int(s_num)%2019==0:
                end=i
        j+=1
    if end-j==0:
        print(0)
    else:
        if len(s)%(end-j)==0:
            print(len(s)//(end-j))
        else:
            print((len(s)//(end-j))-1)
else:
    if s_input=='2019':
        print(1)
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
from itertools import product, permutations,combinations


#l = len(s) +1
#A = [i for i in range(len(s)+1)]

cnt = 0
ans = []

for i in combinations([i for i in range(len(s)+1)],2):
    
    ans = s[i[0]:i[1]]
    if int("".join(map(str, ans)))%2019==0:
            cnt +=1
    
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
num = int(S[0])
check = 1
count = 0
for i in range(len(S)):
    while True:
        if num % 2019 == 0 :
            count += 1
        #print(num)
        try:
            num = num*10 + int(S[i+check])
        except:
            break
        check += 1
        #print(count)
    try:
        num = int(S[i+1])
    except:
        break
    check = 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
keta = len(s)
if keta < 4:
    print(0)
    exit()
ans = 0

for i in range(keta-3):
    for j in range(i + 3,keta):
        tmp = s[i:j+1]
        if tmp!='' and int(tmp) % 2019 == 0:
            ans += 1
            j += 3
# j = 0
# for i in range(keta-3):
#     while j <keta:
#         tmp = s[i:j+1]
#         print(tmp)
#         print(i,j)
#         if tmp!='' and int(tmp) % 2019 ==0:
#             ans +=1
#             if j <keta-3:
#                 j +=3
#         j+=1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def main():
    # 標準入力の取得
    S = input()

    # 求解処理
    size = len(S)
    result = 0
    for i in range(size-3):
        for j in range(i+3, size):
            number = int(S[i:j+1])
            if number % 2019 == 0:
                result += 1

    # 結果出力
    print(result)

main()

Submission status: Time Limit Exceeded

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

# j番目の初期化
j_s = 4

i_e = len(S)-2
j_e = len(S)+1

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

for i in range(1,i_e):
    for j in range(j_s,j_e):
        if int(S[i-1:j]) <= 200000:
            baisu = int(S[i-1:j]) % 2019
            if baisu == 0:
                cnt += 1
    j_s += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

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

    dfs(i+1, j+1)
    dfs(i, j+1)

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

else:
    dfs(0, 3)
    print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
S = input()

ret = 0
mod = [[],[],[]]
mod[int(S[0])%3].append(0)
idx = list(range(3))
for j in range(1,len(S)):
    mod3 = int(S[j])%3
    for i in mod[idx[(3-mod3)%3]]:
        s = int(S[i:j+1])
        if s % 673 == 0:
            ret += 1
    tmp = [(i+mod3)%3 for i in range(3)]
    tmp2 = [None,None,None]
    for i in range(3):
        tmp2[tmp[i]] = idx[i]
    idx = tmp2
    mod[idx[mod3]].append(j)
print(ret)

Submission status: Time Limit Exceeded

Solution code:
#D
S = str(input())
dict = {}
cnt = 0
tot = 0

sum = {}
sum[0] = 0
for i in range(len(S)):
    tot += int(S[i])
    sum[i+1] = tot
#print(sum)


for i in range(len(S)-3):
    for j in range(i+3, len(S)):
        if (sum[j+1]-sum[i])%3 == 0:
            if S[i:j+1] in dict:
                dict[S[i:j+1]] += 1
            else:
                dict[S[i:j+1]] = 1

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

'''

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
ans=0
ss=list(map(int, s))
sss=[n%3 for n in ss]

for i in range(0,n-3):
    for j in range(i+4,n+1):
        s3=sum(list(map(int, sss[i:j])))
        if ((s3 % 3) == 0):
            kazu = int(s[i:j])
#            print (s3, kazu)
            if ((kazu % 673) == 0): ans = ans+1

print (ans)

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
count=0

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

print(count)

Submission status: Time Limit Exceeded

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

    ans = 0
    if len(s) >= 5:
        for i in range(5, len(s)):
            for j in range(i):
                for k in range((len(s)-j)//i):
                    if int(s[i*k+j:i*(k+1)+j]) % 2019 == 0:
                        ans += 1
                        #print(i*k+j, i*(k+1)+j)
                        #print(s[i*k+j:i*(k+1)+j])
    print(ans)
    
solve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(S: str):
    c = 0

    for i in range(4,len(S)):
        for j in range(len(S)-i+1):
            s = S[j:j+i]
            n3 = sum(map(int,list(s)))
            if n3%3==0:
                if int(s)%2019==0:
                    c+=1
    print(c)
    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 = next(tokens)  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from io import StringIO
import unittest


def resolve():
    S = list(input())
    lens = len(S)

    # l = []
    # tmp = 1
    #
    # while 1:
    #     l.append(str(tmp * 2019))
    #     tmp += 1
    #     if tmp * 2019 > 200000:
    #         break
    #
    # set_l = set(l)
    #
    # ans = 0
    #
    # for i in range(lens - 3):
    #     for j in range(i + 3, lens):
    #         if ''.join(s[i:j+1]) in set_l:
    #             ans += 1

    q = [(1, 5)]
    ans = 0

    l = []
    tmp = 1

    for i in range(1, 10000):
        l.append(str(i * 2019)[-5:-1])

    set_l = set(l)

    for e in range(lens, 3, -1):
        if e - 4 >= 0 and ''.join(S[e - 4:e]) in set_l:
            for s in range(e - 4, -1, -1):
                if int(''.join(S[s:e])) % 2019 == 0:
                    # print('attta', s, e, int(''.join(S[s:e])))
                    ans += 1
        else:
            continue

    print(ans)



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1817181712114"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """14282668646"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2119"""
        output = """0"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

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()
L = len(S)
counter = 0
baisuu = {}
#iは切り出す文字列の長さ
for i in range(1,L+1):
    for j in range(L-i+1):
        if S[j:i+j] in baisuu:
            counter += 1
        elif int(S[j:i+j]) % 2019 == 0:
            baisuu[S[j:i+j]] = 1
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
input = raw_input

M = 2019
s = input()
n = len(s)
s = list(s)

#X = {}
counts = [0] * M
counts_tmp = [0] * M

inv10 = 202

out = 0
for i in range(n):
    c = int(s[i])

    new_counts = [0] * M
    for j in range(M):
        j2 = (j * 10 + c) % M
        new_counts[j2] += counts[j]
    counts = new_counts
    
    c = int(s[i])
    counts[c] += 1
    out += counts[0]

#print(counts, sum(counts))

print(out)

Submission status: Time Limit Exceeded

Solution code:

def main():
    S = input()
    cnt = 0

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

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = len(S)
A = []
count = 0
for i in range(1,1000):
    a = 2019*i
    if "0" in str(a):
        continue
    else:
        A.append(str(a-(a//1000)*1000))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
count=0
for i in range(100):
  for j in range(n-3):
    for k in range(j,n+1):
      if s[j:k]==str(2019*i):
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    n = len(S)
    if n < 4:
        print(0)
        return
    ans = 0
    for i in range(n-3):
        s  = int(S[i:i+4])
        for j in range(i+4, n):
            s = 10*s+int(S[j])
            s %= 2019
            if s == 0:
                ans += 1  
    print(ans)
main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = input()
a = [2019 * i for i in range(1,100001)]
ans = 0
for i in a:
    st = N
    d = str(i)
    if st.find(d) != -1:
        while True:
            if st.find(d) != -1:
                ans += 1
                st = st[st.find(d)+1:]
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def get_result(data):
    S = data[0]
    int_S = int(S)
    mod_all_bit = [0] * 2019
    mod_all_bit[0] = 1
    length = len(S)
    for i in range(length):
        mod = int_S % (10**(i+1)) % 2019
        mod_all_bit[mod] += 1
    ans = 0
    for val in mod_all_bit:
        if val >= 2:
            ans += val * (val-1) * 0.5
    return int(ans)


if __name__ == '__main__':
    data = list(map(str, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

Submission status: Time Limit Exceeded

Solution code:
n = input()

A = []

for i in n:
    A.append(i)

ans = 0
n = int(n)
for i in range(len(A)):
    B = A[i:]
    for j in range(1, 50000):
        if 2019 * j > n or int("".join(B)) < 2019 * j:
            break
        else:
            t = 0
            for k in range(len(str(2019 * j))):
                if B[k] == str(2019 * j)[k]:
                    continue
                else:
                    t = 1
                    break
            if t == 0:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())


s = list(map(int,list(input())[:-1]))
n=len(s)
right = [0] * (n + 1)
for i in range(n):
    right[-i - 2] = (right[-i - 1] + s[-i-1] * 10**i) % 2019
log = defaultdict(lambda: 0)
ans=0
for i in range(n + 1):
    log[right[-i - 1]] += 1
    value = log[right[-i - 1]]
    if value!=1:
        ans+=2*(value-1)-1
# ans=0
# for value in log.values():
#     if value > 1:
#         ans += value * (value - 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

S = None

def main():
    global S
    S = input()
    if len(S) < 4:
        return 0
    count = 0

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

def check(i,j):
    cur = j-3
    a = int(S[i:cur])
    #n = a // 2
    n = (53*a)//107
    #print(a, n)
    if a != (2*n+n//53):
        return False
    print("hoge")
    return int(S[i:j])%2019==0
    #b = int(S[cur:cur+2])
    #cur += 2
    #c = int(S[cur])
    #return (c == (10-n)%10) and (b == (2*n-1+n//10)%100)

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=['0']*30000
count=0
j=12114
for i in range(0,30000):
    while True:
        if str(j).count('0')==0:
            N[i]=str(j)
            j+=2019
            break
        else:
            j+=2019
for i in range(0,30000):
    if S.count(N[i])>0 and N[i][0]==N[i][-1]:
        count+=S.count(N[i][1:])
    else:
        count += S.count(N[i])

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
# S = int(s)

N = len(s)
ans = 0
S =""
i = 0
b = 0
n = 0
while i <N :
    # print("i=",i)
    S += s[i]
    # print(S)
    n +=1
    if n > 4:
        for k in range(n-2):
            n3 = S[k:]
            if int(n3) %2019 == 0:
                # b = k
                ans += 1
                break
    i += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
S = [str(s) for s in S]
if len(S) <=3:
    print("0")
    exit()
counter = 0
i = 0
for r in range(len(S)):
    for j in range(4, len(S)+1):
        if i + j > len(S):
            break
        target = S[r:r+j]
        test= ''.join(target)
        if int(test) % 2019 == 0:
            counter+=1
            break
    i +=1
print(str(counter))

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    sum_2019 = 0
    for i in range(len(s)-3):
        for j in range(i+3, len(s)):
            s_int = int(s[i:j+1])
            if s_int % 2019 == 0 and s_int != 0:
                sum_2019 += 1
    print(sum_2019)

main()

Submission status: Time Limit Exceeded

Solution code:
s=int(input())
multiples = list(map(str,[2019*i for i in range(1, 100)]))
length = len(str(s))
ans = 0
option = [4,5,6]
for leng in option:
    for i in range(length-leng+1):
        if str(s)[i:i+leng] in multiples:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = [i*2019 for i in range(1,200000) if i*2019 <= int(S)]
m = [str(i) for i in l if str(i).find('0') == -1]
c = 0
st = str(S)
mls = len(S)

sl = [S[mls-i:mls] for i in range(5,mls+1)]

for j in sl:
    for i in m:
        if j.startswith(i):
            c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
INT_MAX=10**11+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#=======================================================================
# Python 3 implementation of the approach

# Function to return the count of sub-strings
# of str that are divisible by k
def countSubStr(str, l, k):
	count = 0

	for i in range(l):
		n = 0

		# Take all sub-strings starting from i
		for j in range(i, l, 1):
			n = n * 10 + (ord(str[j]) - ord('0'))

			# If current sub-string is divisible by k
			if (n % k == 0):
				count += 1

	# Return the required count
	return count

# Driver code
if __name__ == '__main__':
	str = input()
	l = len(str)
	k = 2019
	print(countSubStr(str, l, k))

# This code is contributed by
# Sanjit_Prasad

Submission status: Time Limit Exceeded

Solution code:
s = input()

l = [str(2019 * i) for i in range(1, 100000)]
res = 0
for i in l:
	if(len(i)< len(s)):
		b = s.find(i)
		while (b!= -1):
			res+=1
			b = s.find(i, b + 1)
print(res)

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from bisect import bisect

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

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import Counter
import itertools
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

S=SR()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count = 0
sta = 0
tp = 0
#kaisuu = 0

for i in range(sta,len(s)+1):
    tp = 0
    for j in range(i+1,len(s)+1):
        # kaisuu += 1
        # print('回数：',kaisuu)
        slice_s = s[i:j]
        if len(slice_s) <= 4:
            continue
        else:
            num = int(''.join(slice_s))
            if num % 2019 == 0:
                #print('i=',i)
                count += 1
                tp = 1
            if tp == 1:
                continue
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time


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


def S(): return input()


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


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

import random

def main():
    s = S()
    # s = ''.join([str(random.randint(1, 9)) for i in range(10 ** 2)])
    ans = 0
    N = len(s)

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

    print(ans)

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

    # can = []
    # for i in range(10**3):
    #     if '0' not in str((i + 1) * 2019):
    #         t = str((i + 1) * 2019)
    #         print(i+1, t, sum([int(n) for n in t]))
    #         can.append(t)

    # print(can[0])

    # for i in range(len(can)):
    #     if can[0] in can[i]:
    #         print(can[i])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
# S = '1817181712114'
# S = '14282668646'
# S= '2119'

cnt = 0
for length in range(4, len(S) + 1):
    for i in range(len(S) - length + 1):
        window = S[i:i + length]
        # print(window)
        if int(window) % 2019 == 0:
            # print('baisu found', int(window))
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!python3

from collections import defaultdict
iim = lambda: map(int, input().rstrip().split())

def resolve():
    S = [int(c) for c in input()]
    mod = 2019

    ans = 0
    d0 = defaultdict(int)
    for i, j in enumerate(S):
        d1 = defaultdict(int)
        for k, v in d0.items():
            val = (k*10+j) % mod
            d1[val] += v

        d1[j] += 1

        if 0 in d1:
            ans += d1[0]
        d0 = d1
    print(ans)

if __name__ == "__main__":
    resolve()