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: Wrong Answer

Solution code:
s = input()
si = int(s)
ans = 0


for i in range(1,300000//2019):
    d = 0
    while 1:
        if s.find(str(2019*i), d) != -1:
            ans = ans+1
            d = s.find(str(2019*i), d)+1
        else:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import math
S = input()
l = len(S)
count = (l - 3) * (l - 3 + 1) / 2
base = ''

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

Submission status: Wrong Answer

Solution code:
N = str(input())

#N = str(1817181718171)
#print (len(N))

count = 0
lenN = len(N)+1
for i in range(0, lenN):
    for j in range(i+1, min(i+25, lenN)):
#        print (i, j)
#        print (N[i:j])
        number = int(str(N[i:j]))
        if number%2019 == 0:
            count +=1

print (count)

Submission status: Wrong Answer

Solution code:



S = input()



# S = input()

start = 0

result = 0
while start <= (len(S) - 4):

    end = start + 4

    mm = False
    while end <= len(S):
        q = S[start:end]
        if int(S[start:end]) % 2019 == 0:
            result = result + 1
            start = end - 1
            mm = True
            break
        else:
            end = end + 1

    if mm == False:
        start = start + 1


print(result)

Submission status: Wrong Answer

Solution code:
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    S = int(input())
    SS = str(S)
    ls = len(SS)
    cnt = 0
    i = 0
    js=i+4
    while i < ls - 3:
        for j in range(js, ls + 1):
            if int(SS[i:j]) % 2019 == 0:
                cnt += 1
                i = j - 2
                js=j+(j-i)
                break
        i+=1

    print(cnt)


resolve()

Submission status: Wrong Answer

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

l = [str(i * 2019) for i in range(1, 1000)]
l.sort()

end = [-1] * N


from bisect import *


for i in range(N):
    for j in range(i + 4, i + 8):
        if j > N:
            break

        # print(bisect_left(l, S[i:j]))


        index = bisect_left(l, S[i:j])
        if 0 <= index < len(l) and l[index] == S[i:j]:

            # にぶたんで

            # if S[i:j] in l:
            end[i] = j
            break


ans = 0

# print(end)

for i in range(N):
    a = 1
    j = end[i]
    # print(i, j)
    while j != -1:
        a += 1
        if j >= N:
            break
        t = end[j]
        end[j] = -1
        j = t
        # j, end[j] = end[j], -1

    ans += a * (a - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
for i in range(len(s)):
    if int(s[i:i+4]) % 2019 == 0:
        k = 1
        while int(s[i:i+4+4*k]) % 2019 == 0:
            k += 1
            if i+8+4*k > len(s) - 1:
                break
        cnt += k
    if int(s[i:i+5]) % 2019 == 0:
        k = 1
        while int(s[i:i+5+4*k]) % 2019 == 0:
            k += 1
            if i+9+4*k > len(s) - 1:
                break
        cnt += k

print(max(cnt-1, 0))

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
left = 0
right = 4
while(left <= len(s)-2):
    while(right <= len(s)+1):
        #print(left, right-1)
        right += 1
        num = int(s[left:right])
        if num % 2019 == 0:
            #print(left, right-1)
            ans += 1
            left = right - 2
            break
    left+=1
    right = left + 4
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    s=input()
    #cnt=0
    k=list(s)
    d=[0]*2019
    for i in range(len(k)):
        #d[int(s[i:])%2019]+=1
        d[(int(s)%10**i)%2019]+=1
    
    cnt=d[0]
    for i in range(2019):
        cnt+=d[i]*(d[i]-1)//2
            #print(s[i:j+1])
    print(cnt)
    #print(d)
main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
 
def main():
    S = input()
    N = len(S)
    tmp = 2019
    l = []
    cnt =0
    while True:
        if '0' not in str(tmp):
            l.append(str(tmp))
        tmp += 2019
        if tmp > 2019000:
            break
 
    cnt = 0
    for num in l:
        na = len(num)
        for i in range(0, N-na+1):
            if num == S[i:i+na]:
                cnt += 1
    print(cnt)
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
c = 0

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

for i in range(1, 100):
    t = i * 2019
    if t > 200000:
        break
    # print(t)
    # print(len(str(t)))

    if not str(t) in str(s):
        continue
    else:
        len_t = len(str(t))
        for j in range(len(str(s)) - (len_t - 1)):
            tmp = s[j:j + len_t]
            if int(tmp) == t:
                c += 1
print(c)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    a = input()
    count = 0
    compare = 0
    if int(a)<100000:
        if len(a)<4:
            count = 0
        else:
            for i in range(len(a)-3):
                for j in range(i+3,len(a)):
                    for k in range(i,j+1):
                        compare+=int(a[k])*10**(j-k)
                    if compare%2019==0:
                        count+=1
                    compare = 0;
    else:
        for i in range(1, 101):
            b = str(2019 * i)
            for j in range(len(a) - len(b) + 1):
                if (a[j:j + len(b)] == b):
                    count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D_fix
# CreatedDate:  2020-04-26 22:25:59 +0900
# LastModified: 2020-04-26 22:37:17 +0900
#


import os
import sys
a=[12114,14133,16152,18171,24228,26247,28266,34323,36342,38361,42399,44418,46437,48456,52494,54513,56532,58551,62589,66627,68646,72684,76722,78741,82779,84798,86817,88836,92874,94893,96912,98931,119121,123159,125178,127197,129216,131235,133254,135273,137292,139311,143349,145368,147387,151425,153444,155463,157482,163539,165558,167577,169596,171615,173634,175653,177672,179691,183729,185748,187767,189786,193824,195843,197862,199881]


def main():
    s = str(input())
    count=0
    tmp_count=0
    for A in a:
        if str(A) in s:
#            print(A)
            first=s.find(str(A))
            tmp_count=1
            second=s.find(str(A),first+1)
            if second!=-1:
                tmp_count=2
            third=s.find(str(A),second+1)
            if third!=-1:
                tmp_count=3

        count+=tmp_count
        tmp_count=0
    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

def count_all(text, part):
    t = sum(1 for x in range(len(text)) if text[x:].startswith(part))
    return t

S = input()
I = 2019
count = 0

while I < 200000:
    count += count_all(S,str(I))
    I += 2019
print(count)

Submission status: Wrong Answer

Solution code:
import re
multiplies = []

for i in range (1, 1000):
    multiplies.append(i * 2019)

S = input()

count = 0

for i in multiplies:
    count += len(re.findall('(?=' + str(i) + ')',S))

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    if int(s) % 2019 == 0:
        return 0

    return 1


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

Submission status: Wrong Answer

Solution code:
from collections import Counter

S = input()

ans = 0
mod_list = [0] * len(S)
mod_list[-1] = int(S[-1])
m = 1
for i in range(2, len(S) + 1):
    m = (10 * m) % 2019
    mod_list[-i] = (mod_list[-i + 1] + (int(S[-i]) * m)) % 2019

mod_counter = Counter(mod_list)

ans = mod_counter[0]
mod_counter[0] -= 1
for i in range(1, len(mod_list) + 1):
    num = mod_list[-i]
    cnt = mod_counter[num] - 1
    ans += cnt if cnt > 0 else 0
    mod_counter[num] -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
a=list(map(int,input()))
print(a)
o=len(a)
da=0
cx=0
for i in range(o):
    for j in range(o):
        x=a[i:j+1]
        print(x)
        z=len(x)-1
        for h in x:
            da+=h*(10**(z))
            z = z-1
        print(da)
        if da%2019==0 and da!=0:
            cx+=1
        da=0
print(cx)

Submission status: Wrong Answer

Solution code:
N = str(input())

#N = str(1817181718171)
#print (len(N))

count = 0
lenN = len(N)+1
for i in range(0, lenN):
    for j in range(i+1, min(i+50, lenN)):
#        print (i, j)
#        print (N[i:j])
        number = int(str(N[i:j]))
        if number%2019 == 0:
            count +=1

print (count)

Submission status: Wrong Answer

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

l = [str(i * 2019) for i in range(1, 1000)]
l.sort()

end = [-1] * N


from bisect import *


for i in range(N):
    for j in range(i + 4, i + 8):
        if j > N:
            break

        # print(bisect_left(l, S[i:j]))


        index = bisect_left(l, S[i:j])
        if 0 <= index < len(l) and l[index] == S[i:j]:

            # にぶたんで

            # if S[i:j] in l:
            end[i] = j
            break


ans = 0

print(end)

for i in range(N):
    a = 1
    j = end[i]
    # print(i, j)
    while j != -1:
        a += 1
        if j >= N:
            break
        t = end[j]
        end[j] = -1
        j = t
        # j, end[j] = end[j], -1

    ans += a * (a - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
# s = '14282668646'

length = len(s)

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

Submission status: Wrong Answer

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

for i in range(s_length - 2):
    current_mod = int(a[i:i+4])%2019
    for j in range(i+4, s_length ):



        if  current_mod%2019 == 0:
            counter += 1

        print(current_mod)
        current_mod= (current_mod * 10 + int(a[j]))%2019

print(counter+1)

Submission status: Wrong Answer

Solution code:
# if the remainders (mod 2019) are equal, the difference will be divisible
# x = Q*2019+5 y = R*2019+5 then x-y=(Q-R)*2019
# unless Q-R<=0
# where the substring itself is (Q-R)*2019/10**(something)
# 2019 = 3*673 in prime factorization
# so multiplying by 10 doesn't affect whether a number is divisible by it
from collections import Counter
s = input()
partial = 0
histo = Counter((partial+int(s[i])*10**(len(s)-1-i))%2019 for i in range(len(s)-1, -1, -1))
# for i in range(len(s)-1, -1, -1):
#   partial = (partial+int(s[i])*10**(len(s)-1-i))%2019
#   remainders.append(partial)
# histo = Counter(remainders)
non_single_count = int(sum(count*(count-1)/2 for value, count in histo.items() if value!=0))
single_count = int(sum(count for value, count in histo.items() if value==0))
print(non_single_count+single_count)

Submission status: Wrong Answer

Solution code:
s = input()

ans = 0
i = 0
flag = 0
while i < len(s) - 4:
    flag = 0
    for j in range(i + 5, i + 1000):
        sub = int(s[i:j])
        if sub % 2019 == 0:
            ans += 1
            flag = 1
            break
    if flag == 1:
        i = j - 1
    else:
        i += 1
    

print(ans)

Submission status: Wrong Answer

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])
    print(t)
    if t%2019==0:
      c = c+1
print(c)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
cnt=0
i,j=0,0
while 1:
  if i>n:
    break
  j=i+5
  while 1:
    if j>n:
      break
    ss=s[i:j]
    print(i,j,ss,sep='\t')
    if int(ss)%2019==0:
      print('Yes')
      cnt+=1
      j+=3
    j+=1
  i+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
ans=0
y=0
i=0
pe=[0]*(n+32)
pa=[0]*(n+32)
for i in range(n-3):
    if int(s[i:i+4])%2019==0:
        pe[i+3]+=pe[i]+1
        y+=1
    if int(s[i:i+5])%2019==0 and not(i==n-4):
        pe[i+4]+=pe[i]+1
        y+=1
    if y>=1:
        pe[i]=0 
    y=0
print(sum(pe))

Submission status: Wrong Answer

Solution code:
N=input()
lis=[]
for i in range(len(N)-3):
	for j in range(len(N)-i-3):
 		lis+=[(int(N)//(10**(len(N)-i-4-j)))%(10**(len(N)-i))]
print(len(list(filter(lambda x:x%2019==0,lis))))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

s = input().rstrip()
n = len(s)
ranges = []
g = [[] for _ in range(n + 1)]
ans = 0
j = 0

for i in range(n):
    j = max(i, j)
    while j < n:
        if j >= n:
            continue
        s_ = s[i:j + 1]
        if int(s_) % 2019 == 0:
            ranges.append([i, j + 1])
            g[i].append(j + 1)
            break
        j += 1

visited = set()
ans = 0

for i in range(n):
    if i in visited or len(g[i]) == 0:
        continue
    visited.add(i)
    d = 1
    while True:
        i = g[i][0]
        if len(g[i]) == 0:
            ans += (1 + d) * d // 2
            break
        else:
            d += 1
            visited.add(i)

print(ans)

Submission status: Wrong Answer

Solution code:
S = str(input())
s = len(S)
num = []
c=0
for i in range(1,100):
    num.append(str(2019*i))
for i in range(99):
    n = num[i]
    ln = len(n)
    for j in range(s-ln+1):
        if n in S[j:ln+j]:
            c += 1
print(c)

Submission status: Wrong Answer

Solution code:
import random
print(str(random.randint(1,20)))

Submission status: Wrong Answer

Solution code:
def retry(list_S, len_S, ans=0, start_ii=0):
    if len_S <= 3 or start_ii > len_S - 3:
        return ans

    for start_i in range(start_ii, len_S - 3):
        for last_i in range(start_i + 3, len_S):
            tmp = ''.join(list_S[start_i:last_i + 1])

            if (int(tmp) % 2019) == 0:
                ans += 1
                return retry(list_S, len_S, ans, last_i)

    return ans


def resolve():
    S = list(input())
    len_S = len(S)
    print(retry(list_S=S, len_S=len_S))


# resolve()


import sys
from io import StringIO
import unittest

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)


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

Submission status: Wrong Answer

Solution code:
N = int(input())
NN =str(N)

q = N // 2019

print(q)

dic = {}

for num in range(1,q+1):
    keta = len(str(2019*num))
    if str(keta) in dic:
        dic[str(keta)].append(str(2019*num).split())
    else:
        dic[str(keta)] = list(str(2019*num).split())

result = 0

for num, s in enumerate(NN):
    if s in ('2', '4', '6', '8'):
        for key in dic:
            keta = int(key)
            if NN[num: num+keta+1] in dic[key]:
                result += 1


print(result)

Submission status: Wrong Answer

Solution code:
s = str(input())
s_list = list(map(str, s))
nums = []
const = 2019
times = 1
while const <= 200000:
    times += 1
    nums.append(str(const))
    const += 2019

index = []
for i in range(len(s)):
    for j in range(3, 6):
        if i + j <= len(s) - 1:
            index.append([i, i + j])
# print(index)
cnt = 0
for ind in index:
    if "".join(s_list[ind[0]: ind[-1] + 1]) in nums:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy
import math
import time


def isMaltiple(N):
    if N % 2019 == 0:
        return True
    else:
        return False


def main():
    S = input()
    N = len(S)
    l = 3
    r = 0
    tmp = 0
    ans = 0

    while(r < N - 4):
        #print(l, tmp, r)
        # time.sleep(0.1)
        if(isMaltiple(int(S[N - l - 1:N - tmp]))):
            #print(int(S[N - l - 1:N - tmp]), l, r)
            ans += 1
            tmp = l + 1
            l = tmp + 3
        else:
            if(l - tmp == 8):
                r += 1
                tmp = r
                l = r + 3
            else:
                l += 1
        if(l >= N):
            r += 1
            tmp = r
            l = r + 3

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# s = input()
s = '14282668646'

length = len(s)

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

Submission status: Wrong Answer

Solution code:
import scipy as sp
from collections import Counter

s = input()
ans = 0
s_i_list = list()

for i in range(len(s)):
    s_i_list.append(int(s[i:]) % 2019)

scount = Counter(s_i_list)

for i in scount.values():
    ans += i*(i-1)//2

print(ans+1)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
for i in range(len(s)-4):
    if int(s[i:i+4]) % 2019 == 0:
        ans += 1
    if int(s[i:i+5]) % 2019 == 0:
        ans += 1
    if(i + 6 < len(s) ):
        if int(s[i:i+6]) % 2019 == 0:
            ans += 1
    if(i + 7 < len(s) ):
        if int(s[i:i+7]) % 2019 == 0:
            ans += 1
    if(i + 8 < len(s) ):
        if int(s[i:i+8]) % 2019 == 0:
            ans += 1
    if(i + 9 < len(s) ):
        if int(s[i:i+9]) % 2019 == 0:
            ans += 1
    if(i + 10 < len(s) ):
        if int(s[i:i+10]) % 2019 == 0:
            ans += 1
    if(i + 11 < len(s) ):
        if int(s[i:i+11]) % 2019 == 0:
            ans += 1
    if(i + 12 < len(s) ):
        if int(s[i:i+12]) % 2019 == 0:
            ans += 1
    if(i + 13 < len(s) ):
        if int(s[i:i+13]) % 2019 == 0:
            ans += 1
    if(i + 14 < len(s) ):
        if int(s[i:i+14]) % 2019 == 0:
            ans += 1
    if(i + 15 < len(s) ):
        if int(s[i:i+15]) % 2019 == 0:
            ans += 1
    if(i + 16 < len(s) ):
        if int(s[i:i+16]) % 2019 == 0:
            ans += 1
    if(i + 17 < len(s) ):
        if int(s[i:i+17]) % 2019 == 0:
            ans += 1
    if(i + 18 < len(s) ):
        if int(s[i:i+18]) % 2019 == 0:
            ans += 1
    if(i + 19 < len(s) ):
        if int(s[i:i+19]) % 2019 == 0:
            ans += 1
    if(i + 20 < len(s) ):
        if int(s[i:i+20]) % 2019 == 0:
            ans += 1
    if(i + 21 < len(s) ):
        if int(s[i:i+21]) % 2019 == 0:
            ans += 1
    if(i + 22 < len(s) ):
        if int(s[i:i+22]) % 2019 == 0:
            ans += 1
    if(i + 23 < len(s) ):
        if int(s[i:i+23]) % 2019 == 0:
            ans += 1
    if(i + 24 < len(s) ):
        if int(s[i:i+24]) % 2019 == 0:
            ans += 1
    if(i + 25 < len(s) ):
        if int(s[i:i+25]) % 2019 == 0:
            ans += 1
    if(i + 26 < len(s) ):
        if int(s[i:i+26]) % 2019 == 0:
            ans += 1
    if(i + 27 < len(s) ):
        if int(s[i:i+27]) % 2019 == 0:
            ans += 1
    if(i + 28 < len(s) ):
        if int(s[i:i+28]) % 2019 == 0:
            ans += 1
    if(i + 29 < len(s) ):
        if int(s[i:i+29]) % 2019 == 0:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
# 1<=S<=200000
S = str(input()).rstrip()
# print(len(S))
count = 0
for i in range(len(S) - 3):
    # print(i)
    # 0-4~8までやりたい
    for j in range(i + 4, i + 8):
        if j > len(S):
            continue
        if int(S[i:j]) % 2019 == 0:
            # print(i, j, S[i:j])
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import re
multiplies = []

for i in range (1, 500):
    multiplies.append(i * 2019)

S = input()

count = 0

for i in multiplies:
    count += len(re.findall('(?=' + str(i) + ')',S))

print(count)

Submission status: Wrong Answer

Solution code:
S = list(map(int, input()))
n = len(S)
 
fl = [False]*(n+1)
res = 0
 
for i in range(n-3):
    if fl[i]:
        continue
    
    x = 0
    cnt = 0
    for j in range(i, n):
        x = (x*10+S[j]%2019)
        
        if x == 0:
            cnt += 1
            fl[j+1] = True
            
    
    res += (cnt+1)*cnt//2
 
print(res)

Submission status: Wrong Answer

Solution code:
from random import randrange
print(randrange(0,10,1))

Submission status: Wrong Answer

Solution code:
def d164(n):
    res = 0
    for i in range(1, 200000):
        count = 2019*i
        if n.count(str(count)) != 0:
            res += n.count(str(count))
    return res

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

Submission status: Wrong Answer

Solution code:
s = input()

ans = 0
i = 0
flag = 0
while i < len(s) - 4:
    flag = 0
    for j in range(i + 5, i + 10000):
        sub = int(s[i:j])
        if sub % 2019 == 0:
            ans += 1
            flag = 1
            break
    if flag == 1:
        i = j - 1
    else:
        i += 1
    

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
S = input().rstrip()
dic = {}
if len(S) <= 4:
    print(0)
    sys.exit()
i = 2019
j = 1
while i * j < 1211400000:
    if not "0" in str(i*j):
        dic[i * j] = True
    j += 1
blocks = []
for i in range(len(S)):
    for j in range(5, 10):
        if i+j <= len(S):
            try:
                if dic[int(S[i:i+j])]:
                    blocks.append((i, j))
            except:
                continue
ans = len(blocks)
print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    count = 0
    a = input()
    for i in range(1, 101):
        m = str(2019*i)
        index = 0
        while True:
            if index > (len(a)-len(m)):
                break
            index = a.find(m, index)
            if index != -1:
                count += 1
                index += 1
            else:
                break

    print(count)

Submission status: Wrong Answer

Solution code:
def main():
    s=list(map(int,input()))
    modpow=[1]*len(s)
    for i in range(1,len(s)):
        modpow[i]=(modpow[i-1]*10)%2019
    ans=0
    res=[0]*len(s)
    res[0]=s[-1]%2019
    for i in range(1,len(s)):
        res[i]=(modpow[i]*s[len(s)-1-i]+res[i-1])%2019
    res.sort()
    res.append(2019)
    cnt=0
    for i in range(len(s)-1):
        if res[i]==0:
            ans+=1+cnt
            cnt+=1
        elif res[i]==res[i+1]:
            cnt+=1
        elif i>0 and res[i-1]!=0:
            ans+=cnt
            cnt=0
        else:
            cnt=0
    print(ans)
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = input()
count = 0
for i in range(0,len(S)-2):
  if int(S[i]) == 0:
    if int(S[i+1]) <= 1:
      for j in range(i+1,i+8):
        if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
          count = count + 1
          if j >= len(S):
            break
    if int(S[i+1]) >= 2:
      if int(S[i+1:i+7]) == 200000:
        for j in range(i+1,i+8):
          if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
            count = count + 1
            if j >= len(S):
              break
      else:
        for j in range(i+1,i+7):
          if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
            count = count + 1
            if j >= len(S):
              break
  if int(S[i]) <= 1:
    for j in range(i+1,i+7):
      if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
        count = count + 1
        if j >= len(S):
          break
  if int(S[i]) >= 2:
    if int(S[i:i+6]) == 200000:
      for j in range(i+1,i+7):
        if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
          count = count + 1
          if j >= len(S):
            break
    else:
      for j in range(i+1,i+6):
        if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
          count = count + 1
          if j >= len(S):
            break
print(count)

Submission status: Wrong Answer

Solution code:
a, lists, count = str(input()), [], 0
for x in a:
    if x == '0':
        count += 1
for i in range(0, len(a)-4):
     lists.append(a[i]+a[i+1]+a[i+2]+a[i+3])
for i in range(0, len(a)-5):
    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4])
for i in range(0, len(a)-6):
    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5])
for i in range(0, len(a)-7):
    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5]+a[i+6])
for i in range(0, len(a)-8):
    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5]+a[i+6]+a[i+7])
for x in lists:
    if int(x) % 2019 == 0:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
a = [int(c) for c in s]

b=a
count=0

for i in range(len(a)):
    for j in range(i,len(a)):
        del b[:i]
        #print(i,j,b)
        del b[j+1-i:]
        #print(i,j,b)
        num="".join(map(str,b))
        #print(num)
        if int(num)%2019 == 0:
            count+=1
        b=a

#print(count)

Submission status: Wrong Answer

Solution code:
N = input()
a = [2019 * i for i in range(1,1001)]
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: Wrong Answer

Solution code:
n = input()

m = len(n)

l = list()

c = 0

for i in range(m):
    for j in range(m-i):
        l.append(i)
        l.append(i+j+2)

for k in range(len(l)//2):
    s = n[l[2*k]:l[2*k+1]]
    s = int(s)
    
    if s % 2019 == 0:
        c += 1

print(c-1)

Submission status: Wrong Answer

Solution code:
S = input()

ans = 0
left = 0
right = 1
while left < len(S):
    while right <= len(S) and int(S[left:right]) % 2019 != 0:
        right += 1
    if int(S[left:right]) % 2019 == 0:
        ans += 1
        left = right - 1
        right += 3
    else:
        left += 1
        right = left + 1

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
s=input()
A=0
ans=0
k=s
for i in range(2*100000//2019):
    A+=2019
    while s.count(str(A)) > 0:
        ans+=1
        j=s.find(str(A))
        s=s[:j] + 'X' + s[j+1:]
    s=k
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
s_len = len(s)
total = [0, int(s[0])]

for i in range(1,s_len):
    total.append(total[-1]+int(s[i]))

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

print(count)

Submission status: Wrong Answer

Solution code:
import math
S = input()
l = len(S)
count = (l - 3) * (l - 3 + 1) / 2
base = ''

arr = []
for i in range(l - 3):
    base = ''.join([S[i], S[i + 1], S[i + 2]])
    for j in range(i + 3, l):
        base = ''.join([base, S[j]])
        arr.append(base)
        if int(base) % 2019 != 0:
            count -= 1
print(math.floor(count))

Submission status: Wrong Answer

Solution code:
def get_offset(S):
    for i in range(length - 3):
        for j in range(i+1, length+1):
            num = int(S[i:j])
            if num % 2019 == 0:
                #  print("aa: ", num)
                return i+1, j
    return None, None

def get_offset2(S):
    for i in reversed(range(4, length+1)):
        for j in reversed(range(0, i-3)):
            num = int(S[j:i])
            #  print("bb: ", num)
            if num % 2019 == 0:
                return j+1, i
    return None, None


S = input()

length = len(S)
ans = 0
head = tail = 0
domains = []

head, tail = get_offset(S)
if head != None:
    while tail <= length:
        offset = tail - head
        domains.append((head, tail))
        head += offset
        tail += offset


head, tail = get_offset2(S)
if head != None:
    while tail <= length:
        offset = tail - head
        domains.append((head, tail))
        head += offset
        tail += offset

#  print(domains)
ans = len(set(domains))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    S = input()
    L = len(S)-1
    NUM = [0]*(L+1)
    CNT = 0
    for i in range(1,len(NUM)):
        NUM[i] = NUM[i-1] + int(S[i-1])
    for i in range(L-3):
        for j in range(i+4,L+1):
            if (NUM[j] - NUM[i])%9 == 0:
                # print(NUM[j] - NUM[i])
                # print(int(S[i:j]))
                if int(S[i:j])%2019 == 0:
                    CNT += 1
    # print(NUM)
    print(CNT)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import re
multiplies = []

for i in range (1, 100):
    multiplies.append(i * 2019)

S = input()

count = 0

for i in multiplies:
    count += len(re.findall('(?=' + str(i) + ')',S))

print(count)

Submission status: Wrong Answer

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

skip_num = []

if n < 4:
    print('0')
else:
    cnt = 0
    i = 3
    while i < n:
        for j in range(n-i):
            step = int(s[j:j+i])
            if step%2019 == 0:
                cnt += 1
        i += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
nn = input()
c = 0
i = 1
nnn = 0

import re

while len(str(nnn)) < 6:
    nnn = str(2019 * i)
    if int(nnn) >= int(nn):
        break
    i+=1

    if nnn in nn:
        c+=int(sum(nn.startswith(nnn, i) for i in range(len(nn))))
print(c)

Submission status: Wrong Answer

Solution code:

S=input()
s=[0 for i in range(len(S))]

for i in range(len(S)):
    s[i]=int(S[i])
CHECK=[0 for i in range(2021)]
ans=0
temp=0
for i in range(1,len(s)+1):
    #print(s[-i])
    temp=(temp+s[-i]*pow(10,i-1,2019)+2019*2)%2019
    #print(i,temp)
    #print(temp)
    CHECK[temp]+=1
for i in range(2020):
    if i==0:
        ans+=CHECK[i]
    else:
        ans+=max(0,CHECK[i]-1)
 
print(ans)