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:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

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

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

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

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

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

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

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

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

inf = float('inf')
mod = 1000000007

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

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

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

	print(ans)


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

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

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

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

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

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

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

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

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
S=input()
n=len(S)
ans=0
dp=[]
dp2=[]
for i in range(2019):
  dp.append(0)
  dp2.append(0)
dp[int(S[0])]=1
lookup=[]
for i in range(1,n):
  r=int(S[i])
  if i%2==0:
    for j in range(2019):
      dp2[(10*j+r)%2019]=dp[j]
    dp2[r]+=1
    ans+=dp2[0]
  else:
    for j in range(2019):
      dp[(10*j+r)%2019]=dp2[j]
    dp[r]+=1
    ans+=dp[0]
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
  S_string = input()

  if len(S_string) < 4:
    print("0")

  count = 0
  d_start = 4
  d_end = len(S_string)

  for i in range(0, len(S_string) - 3):
    for d in range(d_start, d_end + 1 - i ):
      # print(int(S_string[i: i + d]))
      if (int(S_string[i: i + d])%2019==0):
        count += 1
  print(count)

if __name__ == "__main__":
  resolve()

Submission status: Wrong Answer

Solution code:
S = list(input())  #文字列の一文字ずつリストに

nums = []


for i in range(1,200000 // 2019 + 1):
    nums.append(2019*i)
        
#print(nums)

ans = 0
for j in range(len(S) - 4):
    for i in range(4, len(S) + 1 - j):
#        print(j,j + i)
#        print(S[j:j + i])
        A = (''.join(S[j: j + i]))
        #print(A)
        if int(A) > 199881:
            break
        if int(A) in nums:
            ans += 1

print(ans)

Submission status: Wrong Answer

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

ans = 0
i = 0
while i <= N-5:
    Flag = False
    j = i+4
    while j < N:
        temp = int(S[i:j+1])
        if temp%2019 == 0:
            ans += 1
            Flag = True
            print(temp)
            j += 5
        else:
            j += 1
    if Flag:
        i += 4
    else:
        i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n=14282668646
if n<10000:
  if n%2019 == 0:
    print(1)
  else:
    print(0)
else:
  x=str(n)
  c=0
  for i in range(len(x)):
    for j in range(i+4, len(x)):
      if int(x[i:j+1]) % 2019 == 0:
        c+=1
  print(c)

Submission status: Wrong Answer

Solution code:
N = input()
lenN = len(N)
cnt = 0
  
for i in range(0,lenN-3):
  for j in range(i + 3,i + 3 + 6):
    if j > lenN :
      break
    p = int(N[i:j])
    if p > 200000:
      continue
    if p % 2019 == 0:
      print("{}:{}".format(i,j))
      cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0

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

print(cnt)

Submission status: Wrong Answer

Solution code:
# cook your dish here
s = str(input())
n = len(s)
ans = 0
i = 0
st = 0
nm = 0
while i<n:
    nm*=10
    nm+=int(s[i])
    if(nm>=2019):
        if(nm%2019==0):
           # print(nm)
            ans+=1
        else:
            x = i-st;
            while(st<i):
                nm-=(int(s[st]))*(10**x)
                if(nm>=2019 and (nm%2019==0)):
                   # print(nm)
                    ans+=1
                else:
                    st+=1
                    break
                x-=1
                st+=1
    i+=1

print(ans)

Submission status: Wrong Answer

Solution code:
string=input()
count=0
times=1
length=4
while len(string) >= length:
  target=int(string[:length])
  if target % 2019 == 0:
    count+=1
  times+=1
  length+=1
  if times % 3 == 0:
    length=4
    string=string[1:]
print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from operator import mul
from functools import reduce


memo = {}


def cmb(n, r):
    if (n, r) in memo:
        return memo[(n, r)]
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    memo[(n, r)] = over // under
    return over // under


s = input()[::-1]
acc = [int(s[0])]
cntr = defaultdict(int)
tens = 10
for i, c in enumerate(s[1:], 1):
    if c == '0':
        continue
    next_mod = (acc[-1] + tens * int(c)) % 2019
    cntr[next_mod] += 1
    acc.append(next_mod)
    tens *= 10

ans = 0
for k, v in cntr.items():
    if k == 0:
        ans += v
    if v > 1:
        ans += cmb(v, 2)
print(ans)

Submission status: Wrong Answer

Solution code:
#coding:utf-8

s = str(input())
n = len(s)
count = 0
cal = 0

for i in range(1,n+1):
    sen = s[i-1:]
    for j in range(i,n+1):
        cal += 1
        if sen[:j] == '':
            break
        if int(sen[:j]) % 2019 == 0:
            count += 1
            sen = sen[j:]
            if sen == '':
                break

print("{}:{}".format(count,cal))

Submission status: Wrong Answer

Solution code:
str=input()
gap_len=4
flag=0
count=0
for i in list(range(len(str)-gap_len)):
    sub_str=str[flag:flag+gap_len+1]
    num=int(sub_str)
    if(num%2019==0):
        count+=1
    flag+=1
print(count)

Submission status: Wrong Answer

Solution code:
S = list(input())
end = len(S)
cnt = 0

for i in range(end-3):
    for j in range(i+3, end):
        st = ''.join(S[i:j+1])
        num = int(st)
        if num % 2019 == 0:
            print(num)
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    s = input()
    ans = 0
    for i in range(len(s)):
        ss = s[i]
        for j in range(i+1, min(len(s)-1, i+30)):
            ss += s[j]
            if int(ss) % 2019 == 0:
                ans += 1
    print(ans)


main()

Submission status: Wrong Answer

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


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


def INT(): return int(input())


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


def LIST(): return list(map(int, input().split()))


def ZIP(n): return zip(*(MAP() for _ in range(n)))


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


def main():
    S = input()
    N = len(S)
    lis = [str(2019 * i) for i in range(1, 100)]

    ans = 0

    # print(lis)

    for x in lis:
        n = len(x)
        ind = S.find(x)
        ans += S.count(x)
        if ind > -1:
            # print("ind:", ind, "x:", x)
            if ind + n < N:
                # print("yay")
                for i in range(ind+1, ind+n):
                    # print(S[i:i+n+1])
                    ans += S[i:i+n].count(x)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

Solution code:
s = input()

ans = 0
n = len(s)
for i in range(4, n+1):
    d, m = divmod(int(s[i-3:i]), 19)
    if m == 0:
        x1 = str(2019 * d)
        x2 = str(2019 * 100 * d)
        n1 = len(x1)
        if n1 <= i+1 and s[i-n1:i] == str(x1):
            ans += 1
        n2 = len(x2)
        if n2 <= i+1 and s[i-n2:i] == str(x2):
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input().rstrip()
ret = 0
for i in range(len(S)-3):
    for j in range(i+3, len(S)+1):
        # print(S[i:j])
        if eval(S[i:j]) % 2019 == 0:
            print(i+1, j)
            ret += 1
print(ret)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    N = len(S)
    ans = set()
    for i in range(4):
        right = N-i
        left = N-4
        while 0 <= left:
            v = int(S[left:right])
            v_len = 4
            while 0 < left and v % 2019 != 0:
                left -= 1
                add = int(S[left])
                v += add*10**v_len
                v_len += 1
            if v % 2019 == 0:
                ans.add((left, right))
            right = left + 1
            left = right - 4
    print(len(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = str(input())
ARY = ['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']
counta=0
for i in ARY:
    flag = True
    tmp = 0
    start = 0
    while tmp>=0:
        tmp = s[start:].find(i)
        #print(i,s[start:])
        #print(tmp)
        if tmp >= 0:
            start += tmp + 1
            counta+=1
        else:
            tmp = -1
print(counta)

Submission status: Wrong Answer

Solution code:
from collections import deque

l = deque(list(input()))
now = deque([])
ans = 0

for _ in range(min(3, now.__len__())):
  now.append(l.popleft())
  
while l:
  now.append(l.popleft())
  next = deque([])
  while now:
    if int("".join(now)) % 2019 == 0:
      ans += 1
      while now.__len__() > 1:
        now.popleft()
    next.append(now.popleft())
  now = next
      
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
lenN = len(N)
cnt = 0
  
for i in range(0,lenN-3):
  for j in range(i + 3,i + 3 + 6):
    if j > lenN :
      break
    p = int(N[i:j])
    if p > 200000:
      break
    if p % 2019 == 0:
      print("{}:{}".format(i,j))
      cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
S=input()
full=[]
cnt=0
kaisuu=2*10**5//2019+1

for i in range(1,kaisuu+1):
  full.append(str(i*2019))


def count_Occurrences(string, sub):
    count=0
    for i in range(0, len(string)-len(sub)+1):
        if sub in string[i:i+len(sub)]:
            count=count+1
    return count
  
for s in full:
  cnt+=count_Occurrences(S,s)
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    s = list(input())
    h = [[] for i in range(10)]
    for i in range(1,100):
        a = 2019 * i
        sa = str(a)
        if '0' in sa:
            continue
        ha = int(sa[0])

        h[ha].append(list(sa))
    ans = 0
    if len(s) < 5:
        print(0)
        return
    for i, s_top in enumerate(s):
        if i + 4 == len(s):break
        s5 = []
        s6 = []
        if i + 5 < len(s):
            s5 = s[i:i+5]
        elif i + 5 == len(s):
            s5 = s[i:]

        if i + 6 < len(s):
            s6 = s[i:i+6]
        elif i + 6 == len(s):
            s6 = s[i:]
        # print(s5)
        # print(s6)
        for j, hh in enumerate(h[int(s_top)]):
            flg = False


            # print('aaaaa')
            # print(hh)
            if len(hh) == 5 and len(s5) != 0:
                if s5 == hh:
                    ans += 1
                    # print(s5)
            elif len(hh) == 6  and len(s6) != 0:
                if s6 == hh:
                    ans += 1
                    # print(s6)
        # print('bbb')
        # print(ans)

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

Submission status: Wrong Answer

Solution code:
s = input()
si = len(s)
n = 2019
i = 2
a = {}
while n + 2019 <= 200000:
	a[str(n)] = 1
	n+= 2019

res = 0
for i in range(si - 4 + 1):
	tmp = s[i]+s[i+1]+s[i+2]+s[i+3]
	if a.get(tmp, 0) == 1:
		res+=1
	if i + 4 < si:
		tmp+=s[i+4]
		if a.get(tmp, 0) == 1:
			res+=1
	if i + 5 < si:
		tmp+=s[i+5]
		if a.get(tmp, 0) == 1:
			res+=1
print(res)

Submission status: Wrong Answer

Solution code:
# D - Multiple of 2019

S = input()
n = 0
cnt = 0
while n <= 200000:
    n += 2019
    if str(n) in S:
        for i in range(len(S) - len(str(n)) + 1):
            if S[i:i + len(str(n))] == str(n):
                cnt += 1

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#coding:utf-8

s = str(input())
n = len(s)
count = 0
cal = 0

for i in range(1,n+1):
    sen = s[i-1:]
    for j in range(i,n+1):
        cal += 1
        if int(sen[:j]) % 2019 == 0:
            count += 1
            sen = sen[j:]
            if sen == '':
                break

print("{}:{}".format(count,cal))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from math import gcd

S = read()[:-1]

# 2019の倍数である
# 2019 は 10000倍ごとにサイクルが存在する
# →最小の区間はすぐわかる, 連続するときにやっかい
# 連続するときは何回連続したか数えておけば良いのでは？
# 一回最小の区間で置換しよう あと0000とかもやっかいだけどどうしよう→1→9のみなので大丈夫
# 10000のなかで重複するのはない？

x = 2019
multi_x = set()
for i in range(1, 10000):
    tmp = str(x * i)
    if tmp.count('0'):
        continue
    multi_x.add(str(x * i))
# print(multi_x)
# print(len(multi_x))

# 2019の倍数になる最小の区間を
# 5桁から8桁見ておけばいいのは重要なヒント
# 8桁切り出しておいてスライド？#中で8桁まで見る

candi = []
for i in range(len(S)):
    for j in range(i + 5, i + 8):
        if j > len(S):
            continue
        if S[i:j] in multi_x:
            candi.append((i, j))

# print(candi)

# print(len(candi))
# idxの連続によって答えが変化する
#(i,j),(l,r)でj==lになっているjを探し個数をカウント
if len(candi) <= 1:
    print(len(candi))
    exit()
stock = 2
ans = 0
pre_j = -1
for (i, j), (l, r) in zip(candi, candi[1:]):
    if j == l:
        stock += 1
    else:
        ans += stock * (stock - 1) // 2
        stock = 2
ans += stock * (stock - 1) // 2


# for i, j in candi[1:]:
#     print(i, j)
#     if pre_j == i:
#         stock += 1
#     else:
#         ans += stock * (stock - 1) // 2
#         stock = 2
#     pre_j = j
# ans +=


print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

YEAR = 2019
str_num_list = []
i = 1
ans = 0

while YEAR*i <= 200000:
    if str(YEAR*i).find('0') == -1:
        str_num_list.append(str(YEAR*i))
    i += 1

for item in str_num_list:
    start = 0
    if len(s) < len(item):
        break
    while True:
        idx = s[start:].find(item)
        if idx == -1:
            break
        else:
            start += idx+1
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
_len = len(s)
ans = 0
head = 0
while head < _len - 3:
  tail = head + 4
  while tail < _len+1:
    print(int(s[head:tail]))
    if int(s[head:tail]) % 2019 == 0:
      ans += 1
    tail += 1
  head += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    ret = 0
    for s in range(len(S)):
        for e in range(s + 1, 21):
            if len(S) < e: break
            if int(S[s:e]) % 2019 == 0:
                ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
MAX=256 
  
def compare(arr1, arr2): 
    for i in range(MAX): 
        if arr1[i] != arr2[i]: 
            return False
    return True

def Count(pat,txt): 
  
    M = len(pat) 
    N = len(txt)   
    countP = [0]*MAX
    countTW = [0]*MAX
    count=0  
    if M<=N:
        for i in range(M): 
            (countP[ord(pat[i])])+= 1
            (countTW[ord(txt[i])])+= 1  
        for i in range(M,N): 
            if compare(countP, countTW): 
                count+=1
            (countTW[ ord(txt[i]) ]) += 1
            (countTW[ ord(txt[i-M]) ]) -= 1
        
    return count    


s=input()
n=len(s)
count=0
index=1
value=0

while index*2019<=999999:
    value=str(index*2019)
    count+=Count(str(value),s)
    index+=1     
print(count)

Submission status: Wrong Answer

Solution code:
from math import log10
n = int(input())

ans = 0
max_e = int(log10(n)) + 1

for s in range(max_e-3):
    for e in range(s+4, max_e+1):
        print((n%(10**e)) // (10**s))

        if ((n%(10**e)) // (10**s)) % 2019 == 0:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:

s = input('')
max_s = int(200000/2019)
rec = 0
for m in (range(max_s+1)):
    ms=str(2019*m)
    idx=0
    while s.find(ms,idx) >= 0:
        rec+=1
        idx=s.find(ms,idx)+1
print(rec)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

list_2019_multiple = defaultdict(int)
N = 2019
while N < 20190000:
    if "0" not in list(str(N)):
        list_2019_multiple[str(N)] = 1
    N += 2019

S = input()
DP = [[0 for _ in range(2)] for _ in range(len(S))]
if len(S) < 5:
    print(0)
else:
    for i in range(4, len(S)):
        if list_2019_multiple[S[i - 4:i + 1]] == 1:
            if i > 4:
                DP[i][1] = 2 ** DP[i - 5][1]
            else:
                DP[i][1] += 1
        if i >= 5 and list_2019_multiple[S[i - 5:i + 1]] == 1:
            if i > 5:
                DP[i][1] = 2 ** DP[i - 6][1]
            else:
                DP[i][1] += 1
        if i >= 6 and list_2019_multiple[S[i - 6:i + 1]] == 1:
            if i > 6:
                DP[i][1] = 2 ** DP[i - 7][1]
            else:
                DP[i][1] += 1
        if i >= 7 and list_2019_multiple[S[i - 7:i + 1]] == 1:
            if i > 7:
                DP[i][1] = 2 ** DP[i - 8][1]
            else:
                DP[i][1] += 1
        DP[i][0] = DP[i - 1][0] + DP[i - 1][1]
    print(sum(DP[-1]))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=(input())
num=[0]*len(N)

for i in range(len(N)-4):
    if int(N[i:i+5])%2019==0:
        num[i+4]+=1+num[i-1]
    
print(sum(num))

Submission status: Wrong Answer

Solution code:
s=input()

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

Submission status: Wrong Answer

Solution code:
S = list(input())
n = len(S)

if n <= 3:
    print(0)
    exit()

ans = 0
r, l = 3, 0
number = S[0]+S[1]+S[2]

while r < n:
    if int(number + S[r]) % 2019 == 0:
        number += S[r]
        r += 1
        ans += 1
    elif r == l+3:
        number += S[r]
        r += 1
    else:
        number = number[1:]
        l += 1

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
count = 0
for i in range(len(S)):
  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
print(count)

Submission status: Wrong Answer

Solution code:
S = input()

ans = 0
tmp = []
for i in range(99):
    tmp.append(2019 * (i + 1))
# print(tmp)

# flag = False
for t in tmp:
    s = S
    t = str(t)
    # tmp = S.count(t)
    tmp = S.find(t)

    if tmp != -1:
        flag = True
        ans += 1

        while flag:
            s = s[tmp+1:]
            tmp = s.find(t)

            if tmp == -1:
                flag = False
            else:
                ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
a=len(s)
b=a-4
c=0
mod=2019
for i in range(b):
  t=int(s[i:i+5])
  if t%mod==0:
    c=c+1
print(c)

Submission status: Wrong Answer

Solution code:
import re

S = input()

candidates = []
s = 2019
i = 1
result = 0

while s * i <= 200000:
    temp = str(i*s)
    if "0" not in temp:
        candidates.append(temp)
    i += 1

# print(candidates)

for c in candidates:
    start = 0
    while True:
        temp = S.find(c, start)
        if temp == -1:
            break
        else:
            result += 1
            start = temp + 1

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = list(input())

count = 0

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

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

          count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = input()
lenN = len(N)
cnt = 0
  
for i in range(0,lenN-3):
  for j in range(i + 3,i + 3 + 6):
    if j > lenN :
      break
    p = int(N[i:j])
    if p % 2019 == 0:
      cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
a=input()
ct=0
for i in range(100):
    key=str((i+1)*2019)
    b=a
    while key in b:
        ct+=1
        b=b.replace(key,key[1:],1)
print(ct)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

Solution code:
S = str(input())

cnt = 0
div_value = 2019

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

print(cnt)

Submission status: Wrong Answer

Solution code:
s=input()
ans=[2019]
cnt=0

for i in range(2,100):
  ans.append(2019*i)

def all_count(text, part):
  return sum(text.startswith(part, i) for i in range(len(text)))
  
for j in ans:
  cnt+=all_count(s,str(j))
#  print('j:',j,'cnt+:',s.count(str(j)),'cnt_sum:',cnt)
print(cnt)

Submission status: Wrong Answer

Solution code:
string=input()
count=0
times=0
length=4
while len(string) >= length:
  target=int(string[:length])
  if target % 2019 == 0:
    count+=1
  times+=1
  length+=1
  if times % 3 == 0:
    length=4
    string=string[1:]
print(count)

Submission status: Wrong Answer

Solution code:
S = input().rstrip()
r = 0
ret = 0
length = 3
while r < len(S) - 3:
    # print(S[r:r+length], length)
    if eval(S[r:r+length]) % 2019 == 0:
        # print(r, r+length)
        r = r+length-1
        length = 3
        ret += 1
    else:
        length += 1
    if length > len(S):
        r += 1
        length = 3
print(ret)

Submission status: Wrong Answer

Solution code:
S = input()
L = len(S)
count = 0
"""for i in range(0, L-4):
    for j in range(i+4, L):
        if int(S[i:j+1]) % 2019 == 0:
            count += 1
            break
"""
"""i = 0
j = len(S)
while True:
    if int(S[i:j]) % 2019 == 0:
        count += 1
    else:
"""

j = 4
for i in range(0, len(S)-4):
    k = j
    A = 0
    if int(S[i:j+1]) % 3 == 0:
        if int(S[i:j+1]) % 673 == 0:
            count += 1
        while j < len(S)-1:
            A += int(S[j+1])
            if A % 3 == 0:
                break
            j += 1
    j = k + 1



print(count)

Submission status: Wrong Answer

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

ak10k = [(pow(10,n-k-1,m)*int(s[k]))%m for k in range(0,n)]

ruiseki=[0]*n
ruiseki[0]=ak10k[0]
for i in range(1,n):
    ruiseki[i]=(ruiseki[i-1]+ak10k[i])%2019

from collections import Counter
c = Counter(ruiseki)

ans=sum(cc*(cc-1)//2 for cc in c.values()) + list(c.keys()).count(0)

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
t = []
for i in range(1, 1000):
    t.append(str(2019 * i))
c = 0
for i in t:
    if S.count(i):
        a = len(i)
        for j in range(len(S) - a + 1):
            if S[j:j + a] == i:
                c += 1

print(c)

Submission status: Wrong Answer

Solution code:
S=input()
full=[]
cnt=0
kaisuu=2*10**5//2019+1

for i in range(1,kaisuu+1):
  full.append(str(i*2019))


def occurrences(string, sub):
    count = start = 0
    while True:
        start = string.find(sub, start) + 1
        if start > 0:
            count+=1
        else:
            return count
  
for s in full:
  cnt+=occurrences(S,s)
print(cnt)