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:
def main():
    S = input()
    N = len(S)
    ans = 0
    left = N-1
    right = left + 1
    while 0 <= left:
        v = int(S[left:right])
        while 0 < left and v % 2019 != 0:
            left -= 1
            v = int(S[left:right])
        # print(v, left, right)
        if v % 2019 == 0:
            ans += 1
        right = left + 1
        left = right - 1
        if left == 0 and right == 1:
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = list(input())

ans = 0
l=""
for i in s[::-1]:
    l = i + l
    if int(l) % 2019 == 0:
        ans += 1

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from collections import Counter

S = list(input())
S = list(map(int, S))
s = [0] * len(S)
mod = 2019
s[-1] = S[-1]
d = 1
for i in range(len(s) - 2, -1, -1):
    d = (d * 10) % mod
    s[i] = (S[i] * d) % mod

acc = list(accumulate(s[::-1]))[::-1] + [0]
acc = [i % mod for i in acc]
answer = sum(i - 1 for i in Counter(acc).values())
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = str(input())

count = 0

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

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 = 6
	ans = 0
	for i in range(target,len(S)):
		for j in range(len(S)):
			if i+j > len(S):
				break
			tmp = int(S[j:j+i])
			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

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

Submission status: Wrong Answer

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

def main():
    S = input()
    ans = 0
    for i in range(0, 200000, 2019):
        ind = -1
        stri = str(i)
        while True:
            ind = S.find(stri, ind + 1)
            if ind >= 0:
                ans += 1
            else:
                break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

print(cnt)

Submission status: Wrong Answer

Solution code:
S = str(input())

cnt = 0
div_value = 2019

for i in range(0, len(S)-3):
   #print(i, S[i:i+4])
   for j in range(i+3, 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:
def main():
    s = list(input())
    s = s[::-1]

    l = [[] for i in range(673)]
    l[0].append(0)
    mo = [0]
    ten = 1
    mod = 673
    now = 0
    for i in range(len(s)):
        a = int(s[i])*ten
        mo.append((mo[-1]+a)%3)
        now = (now+a)%mod
        l[now].append(i+1)
        ten *= 10
    ans = 0
    
    for i in l:
        if len(i) >= 2:
            for j in range(len(i)-1):
                for k in range(j+1,len(i)):
                    if mo[j] == mo[k-1]:
                        ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# 文字列を一つ入力
S = input()

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

print(res)

Submission status: Wrong Answer

Solution code:
def main(S=None):
    if not S:
        S = input()
    count = 0
    candidates = [str(i) for i in range(2019, 200000, 2019)]
    s_len = len(S)
    for candidate in candidates:
        candidate_len = len(candidate)
        for i in range(s_len):
            if i+candidate_len > s_len:
                break
            if S[i:i+candidate_len] == candidate:
                print(S[i:i+candidate_len], candidate)
                count += 1
    print(count)


if __name__ == "__main__":
    # main("1817181712114")
    # main("14282668646")
    main()

Submission status: Wrong Answer

Solution code:

def resolve():
    import sys
    input = sys.stdin.readline
    S = input().rstrip()

    result = 0
    length = len(S)
    if length < 4:
        return result

    for keta in range(4, length+1):
        for i in range(length - keta + 1):
            j = i + keta
            if int(S[i:j]) != 0 and int(S[i:j]) % 2019 == 0:
                result += 1
    
    print(result)



if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
digits = input()
possilist = []
for i in range(4,len(digits)):
	for j in range(0,len(digits)):
		tmp = int(digits[j:j+i])
		if tmp > 2019:
			possilist.append(tmp)
listtosettolist = list(set(possilist))
ctr = 0
for i in range(len(listtosettolist)):
	if listtosettolist [i] % 2019 == 0:
		ctr += 1
print(ctr)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = input()
# K = [2019, 4038, 6057, 8076, 10095, 12114, 14133, 16152, 18171, 20190, 22209, 24228, 26247, 28266, 30285, 32304, 34323, 36342, 38361, 40380, 42399, 44418, 46437, 48456, 50475, 52494, 54513, 56532, 58551, 60570, 62589, 64608, 66627, 68646, 70665, 72684, 74703, 76722, 78741, 80760, 82779, 84798, 86817, 88836, 90855, 92874, 94893, 96912, 98931, 100950, 102969, 104988, 107007,
#      109026, 111045, 113064, 115083, 117102, 119121, 121140, 123159, 125178, 127197, 129216, 131235, 133254, 135273, 137292, 139311, 141330, 143349, 145368, 147387, 149406, 151425, 153444, 155463, 157482, 159501, 161520, 163539, 165558, 167577, 169596, 171615, 173634, 175653, 177672, 179691, 181710, 183729, 185748, 187767, 189786, 191805, 193824, 195843, 197862, 199881]
K = ['2019', '4038', '6057', '8076', '10095', '12114', '14133', '16152', '18171', '20190', '22209', '24228', '26247', '28266', '30285', '32304', '34323', '36342', '38361', '40380', '42399', '44418', '46437', '48456', '50475', '52494', '54513', '56532', '58551', '60570', '62589', '64608', '66627', '68646', '70665', '72684', '74703', '76722', '78741', '80760', '82779', '84798', '86817', '88836', '90855', '92874', '94893', '96912', '98931', '100950', '102969', '104988',
     '107007', '109026', '111045', '113064', '115083', '117102', '119121', '121140', '123159', '125178', '127197', '129216', '131235', '133254', '135273', '137292', '139311', '141330', '143349', '145368', '147387', '149406', '151425', '153444', '155463', '157482', '159501', '161520', '163539', '165558', '167577', '169596', '171615', '173634', '175653', '177672', '179691', '181710', '183729', '185748', '187767', '189786', '191805', '193824', '195843', '197862', '199881']
count = 0
for i, k in enumerate(K):
    num = s.count(k)
    # print(i, num)
    count += num

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
count = 0
seped = [[],[]]
for i in range(len(S)-3):
  pp = 0
  if i in seped[0]:
    for j in range(len(seped[0])):
      if i == seped[0][j]:
        pp = seped[1][j]
  for j in range(i+4,min(i+9,len(S)+1)):
    t = int(S[i:j])
    if t % 2019 == 0:
      seped[0].append(j)
      seped[1].append(1+pp)
      count += 1+pp
      break
print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

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


def cmb(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))
    return over // under


s = input()[::-1]
acc = [int(s[0])]
for i, c in enumerate(s[1:], 1):
    print(10 ** i)
    acc.append((acc[-1] + pow(10, i, 2019) * int(c)) % 2019)

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

Submission status: Wrong Answer

Solution code:
S = input()

# global ans
ans=0
# Python program for KMP Algorithm 
def KMPSearch(pat, txt): 
    M = len(pat) 
    N = len(txt) 
  
    # create lps[] that will hold the longest prefix suffix  
    # values for pattern 
    lps = [0]*M 
    j = 0 # index for pat[] 
  
    # Preprocess the pattern (calculate lps[] array) 
    computeLPSArray(pat, M, lps) 
  
    i = 0 # index for txt[] 
    global ans
    while i < N: 
        if pat[j] == txt[i]: 
            i += 1
            j += 1
  
        if j == M: 
            # print("Found pattern at index " + str(i-j) )
            ans += 1
            j = lps[j-1] 
  
        # mismatch after j matches 
        elif i < N and pat[j] != txt[i]: 
            # Do not match lps[0..lps[j-1]] characters, 
            # they will match anyway 
            if j != 0: 
                j = lps[j-1] 
            else: 
                i += 1
  
def computeLPSArray(pat, M, lps): 
    len = 0 # length of the previous longest prefix suffix 
  
    lps[0] # lps[0] is always 0 
    i = 1
  
    # the loop calculates lps[i] for i = 1 to M-1 
    while i < M: 
        if pat[i]== pat[len]: 
            len += 1
            lps[i] = len
            i += 1
        else: 
            # This is tricky. Consider the example. 
            # AAACAAAA and i = 7. The idea is similar  
            # to search step. 
            if len != 0: 
                len = lps[len-1] 
  
                # Also, note that we do not increment i here 
            else: 
                lps[i] = 0
                i += 1

for i in range(200):
    if 2019*i > int(S): break
    pattern = str(2019*i)
    if '0' in pattern:
        continue
    
    index = KMPSearch(pattern, S)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
nisenjuq = [
    '2019', '4038', '6057', '8076', '10095', '12114', '14133', '16152',
    '18171', '20190', '22209', '24228', '26247', '28266', '30285', '32304',
    '34323', '36342', '38361', '40380', '42399', '44418', '46437', '48456',
    '50475', '52494', '54513', '56532', '58551', '60570', '62589', '64608',
    '66627', '68646', '70665', '72684', '74703', '76722', '78741', '80760',
    '82779', '84798', '86817', '88836', '90855', '92874', '94893', '96912',
    '98931', '100950', '102969', '104988', '107007', '109026', '111045',
    '113064', '115083', '117102', '119121', '121140', '123159', '125178',
    '127197', '129216', '131235', '133254', '135273', '137292', '139311',
    '141330', '143349', '145368', '147387', '149406', '151425', '153444',
    '155463', '157482', '159501', '161520', '163539', '165558', '167577',
    '169596', '171615', '173634', '175653', '177672', '179691', '181710',
    '183729', '185748', '187767', '189786', '191805', '193824', '195843',
    '197862', '199881'
]

ans = 0
for n in nisenjuq:
    for i in range(len(s) - len(n) + 1):
        if s[i:i + len(n)] == n:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import defaultdict
from operator import mul
from functools import reduce


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def solve(S: str):
    if len(S) < 4:
        print(0)
        exit()
    prev = int(S[len(S)-4:])
    digit = 10000
    count = defaultdict(int)
    for i in range(4,len(S)+1):
        k = prev % 2019
        count[k]+=1
        if i == len(S):
            break
        prev = (prev + digit*int(S[-i-1]))%2019
        digit=digit*10%2019
    sum = 0
    for k in count:
        if k == 0:
            sum += count[k]
            continue
        if count[k] < 2:
            continue
        sum += combinations_count(count[k],2)
    print(sum)
    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: Wrong Answer

Solution code:
import itertools


def run():
    n_str = input()
    n_len = len(n_str)

    res = 0
    for i, j in itertools.combinations(range(0, n_len+1), 2):
        if j - i <= 3:
            continue

        target = int(n_str[i:j])

        if target % 2019 == 0:
            print(f'{i}_{j}: {target}')

            res = res + 1

    print(res)


if __name__ == '__main__':
    run()

Submission status: Wrong Answer

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

l=[str(2019*i) for i in range(1,200000//2019+1) if 2019*i<=200000 and not '0' in str(2019*i)]

for i in range(n-4):
  s1=s[i:i+5]
  s2=s[i:i+6]
  if s1 in l:
    cnt+=1
  if s1!=s2 and s2 in l:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()
mod_list = [str(i * 2019) for i in range(1, 497)]

count = 0
for s in mod_list:
    ps = 0
    while True:
        temp = S[ps:].find(s)

        if temp == -1:
            break
        else:
            ps += temp + len(s) - 1
            count += 1


print(count)

Submission status: Wrong Answer

Solution code:
S = input()
ans=0

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():

    from bisect import bisect_left as bl, bisect_right as br, insort
    import sys
    import heapq
    # from math import *
    from collections import defaultdict as dd, deque
    def data(): return sys.stdin.readline().strip()
    def mdata(): return map(int, data().split())
    out = sys.stdout.write
    # sys.setrecursionlimit(100000)

    s=input()
    ans=0
    for i in range(0,len(s)-3):
        k=int(s[i:])
        d=str(k//2019)
        if k%2019==0:
            ans+=1
        cnt=0
        for j in d:
            if j=='0':
                cnt+=1
            else:
                ans+=max(0,cnt-2)
                cnt=0
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
baisu = [2019, 4038, 6057, 8076, 10095, 12114, 14133, 16152, 18171, 20190, 22209, 24228, 26247, 28266, 30285, 32304, 34323, 36342, 38361, 40380, 42399, 44418, 46437, 48456, 50475, 52494, 54513, 56532, 58551, 60570, 62589, 64608, 66627, 68646, 70665, 72684, 74703, 76722, 78741, 80760, 82779, 84798, 86817, 88836, 90855, 92874, 94893, 96912, 98931, 100950, 102969, 104988, 107007, 109026, 111045, 113064, 115083, 117102, 119121, 121140, 123159, 125178, 127197, 129216, 131235, 133254, 135273, 137292, 139311, 141330, 143349, 145368, 147387, 149406, 151425, 153444, 155463, 157482, 159501, 161520, 163539, 165558, 167577, 169596, 171615, 173634, 175653, 177672, 179691, 181710, 183729, 185748, 187767, 189786, 191805, 193824, 195843, 197862, 199881]

S = input()
ans = 0
N = len(S)
for i in range(N-3):
    if int(S[i:i+4]) % 2019 == 0:
        ans += 1
        print(S[i:i+4])
    if int(S[i:i+5]) % 2019 == 0 and i < N-4:
        ans += 1
        print(S[i:i+5])
    if int(S[i:i+6]) % 2019 == 0 and i < N-5:
        ans += 1
        print(S[i:i+6])
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
U = [0 for i in range(2019)]
mod = 2019
sum_i_to_n = int(s[-3:]) % mod
for i in range(len(s)-4,-1,-1):
    sum_i_to_n += int(s[i])* pow(10,len(s)-i-1,mod)
    sum_i_to_n %= mod
    if sum_i_to_n % mod == 0:
        ans += 1
    ans += U[sum_i_to_n]
    U[sum_i_to_n] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
z = 200000 // 2019
x = [str(2019 * (i + 1)) for i in range(z)]
# print(s)
s = input()
count = 0
for y in x:
  start = 0
  while len(s[start:]) >= len(y):
    a = s[start:].find(y)
    if a == -1:
      break
    if a >= 0:
      count += 1
      start += a + 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

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

print(ans)

Submission status: Wrong Answer

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

S = readline().strip()
S = list(map(int, S))
N = len(S)
P = 2019

rems = [0] * N
a = 1
b = 0
for i in range(N):
    b = (b + (a * S[N - i - 1]) % P) % P
    rems[N - i - 1] = b
    a = a * 10 % P

rems = rems + [0]

counts = [0] * P


for i in range(len(rems)):
    counts[rems[i]] += 1
print(rems)

ans = 0
for c in counts:
    ans += c * (c - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

baisu = [2019, 4038, 6057, 8076, 10095, 12114, 14133, 16152, 18171, 20190, 22209, 24228, 26247, 28266, 30285, 32304,
         34323,
         36342, 38361, 40380, 42399, 44418, 46437, 48456, 50475, 52494, 54513, 56532, 58551, 60570, 62589, 64608, 66627,
         68646,
         70665, 72684, 74703, 76722, 78741, 80760, 82779, 84798, 86817, 88836, 90855, 92874, 94893, 96912, 98931,
         100950,
         102969, 104988, 107007, 109026, 111045, 113064, 115083, 117102, 119121, 121140, 123159, 125178, 127197, 129216,
         131235,
         133254, 135273, 137292, 139311, 141330, 143349, 145368, 147387, 149406, 151425, 153444, 155463, 157482, 159501,
         161520,
         163539, 165558, 167577, 169596, 171615, 173634, 175653, 177672, 179691, 181710, 183729, 185748, 187767, 189786,
         191805,
         193824, 195843, 197862, 199881]
cnt = 0
for su in baisu:
    for index in range(100000):
        if index + len(str(su)) - 1 > len(s):
            break
        # print(s[index:index + len(str(su))])
        if int(s[index:index + len(str(su))]) == su:
            cnt += 1
            # print(s[index:index + len(str(su))])
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input()
result_list = []
for i in range(len(S)-3):
    result_list += [int(S[i:j]) for j in range(i+4, len(S)+1)]
result_list = np.array(result_list)
result_list = result_list%2019==0

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
result = 0
S = str(input())
if int(S)<2019:
    print(0)
    quit()
    
def mod(n:int)-> bool:
    print(n%2019,end=":")
    return True if n%2019 ==0 else False

for window_size in range(4,len(S)+1):
    for x in range(len(S)-window_size+1):
        result += 1 if mod(int(S[x:x+window_size])) else 0
        print(S[x:x+window_size])

print(result)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = list(map(int,list(input())))

N = len(S)
A = [0]
base = 1
for i in range(N):
	A.append((A[-1] + S[N-1-i] * base) % 2019)
	base = base * 10 % 2019
A.sort()

ans = 0
cnt = 1
for i in range(N):
	if i < N-1 and A[i] == A[i+1]:
		cnt += 1
	else:
		ans += (cnt * (cnt - 1)) // 2
		cnt = 1
print(ans)

Submission status: Wrong Answer

Solution code:
z = 200000 // 2019
x = [str(2019 * (i + 1)) for i in range(z)]
# print(s)
s = input()
count = 0
for y in x:
  start = 0
  while len(s[start:]) > len(y):
    a = s[start:].find(y)
    if a == -1:
      break
    if a >= 0:
      count += 1
      start += a + 1
print(count)

Submission status: Wrong Answer

Solution code:
N = str(input())
x = 0
count = 0
for i in range(len(N)):
    for j in range(3,6):
        if i + j > len(N):
            pass
        else:
            x = int(N[i:i+j])
            if x % 2019 == 0:
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
def solve():
    S = input()
    dig = len(S)
    S = int(S)
    count = 0

    for i in range(dig):
        for j in range(i+1,dig):
            if (S % (10**(dig-i)) //(10 ** (dig-j-1) ))%2019 ==0:
                print(i,j)
                print(S % (10**(dig-i+1)) //(10 ** (dig-j)))
                count += 1
    print(count)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

def resolve():
    import sys
    input = sys.stdin.readline
    S = input().rstrip()

    result = 0
    length = len(S)
    if length < 4:
        return result

    for keta in range(4, length+1):
        for i in range(length - keta + 1):
            j = i + keta
            if int(S[i:j]) % 2019 == 0:
                result += 1
    
    print(result)



if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
S=input()
N=len(S)
A=[]
cnt=0

for n in range(1,100):
    if '0' not in str(2019*n): 
        A.append(n*2019)

for st in A:
    st=str(st)
    for i in range(N-len(st)+1):
        if S[i:i+len(st)]==st:
            cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0
for i in range(891):
    tmp = str(i*2019)
    idx = s.find(tmp)
    while idx != -1:
        count += 1
        idx = s.find(tmp, idx+len(list(tmp))-1)

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    count=0
    for diff in range(4,len(S)-4):
        for i in range(len(S)-diff+1):
            s = S[i:i+diff]
            int_s = int(s)
            if int_s%2019==0:
                count = count+1
    print(count)

Submission status: Wrong Answer

Solution code:
S = input()

# global ans
ans=0
# Python program for KMP Algorithm 
def KMPSearch(pat, txt): 
    M = len(pat) 
    N = len(txt) 
  
    # create lps[] that will hold the longest prefix suffix  
    # values for pattern 
    lps = [0]*M 
    j = 0 # index for pat[] 
  
    # Preprocess the pattern (calculate lps[] array) 
    computeLPSArray(pat, M, lps) 
  
    i = 0 # index for txt[] 
    global ans
    while i < N: 
        if pat[j] == txt[i]: 
            i += 1
            j += 1
  
        if j == M: 
            # print("Found pattern at index " + str(i-j) )
            ans += 1
            j = lps[j-1] 
  
        # mismatch after j matches 
        elif i < N and pat[j] != txt[i]: 
            # Do not match lps[0..lps[j-1]] characters, 
            # they will match anyway 
            if j != 0: 
                j = lps[j-1] 
            else: 
                i += 1
  
def computeLPSArray(pat, M, lps): 
    len = 0 # length of the previous longest prefix suffix 
  
    lps[0] # lps[0] is always 0 
    i = 1
  
    # the loop calculates lps[i] for i = 1 to M-1 
    while i < M: 
        if pat[i]== pat[len]: 
            len += 1
            lps[i] = len
            i += 1
        else: 
            # This is tricky. Consider the example. 
            # AAACAAAA and i = 7. The idea is similar  
            # to search step. 
            if len != 0: 
                len = lps[len-1] 
  
                # Also, note that we do not increment i here 
            else: 
                lps[i] = 0
                i += 1

for i in range(100):
    pattern = str(2019*i)
    # print(pattern, S)
    
    index = KMPSearch(pattern, S)
print(ans)

Submission status: Wrong Answer

Solution code:
#n = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))
s = list(input())
#print(s)
ans = 0
n = len(s)
for i in range(n-1):
    for j in range(n-i):
        tmp = s[i:j+1]
        tmp = "".join(tmp)

        #tmp = int("".join(tmp))
        try:
            if int(tmp)%2019 ==0:
                ans += 1
        except:
            pass

print(ans+1)

Submission status: Wrong Answer

Solution code:
s = input()
L = [str(2019 * i) for i in range(1, 100)]
r = 0
for l in L:
    r += sum(s.startswith(l, i) for i in range(len(s)))
print(r)

Submission status: Wrong Answer

Solution code:
s = input()
li4 = [2019*i for i in range(1, 100) if 0 < 2019*i < 10000]
li5 = [2019*i for i in range(1, 100) if 10000 < 2019*i < 100000]
li6 = [2019*i for i in range(1, 100) if 100000 < 2019*i < 1000000]

ans = 0

for x in range(len(s)-3):
    if int(s[x:x+4]) in li4:
        ans += 1

for x in range(len(s)-4):
    if int(s[x:x+5]) in li5:
        ans += 1

for x in range(len(s)-5):
    if int(s[x:x+6]) in li4:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = 200000 // 2019
nums = [2019*num for num in range(1, n+1)]

num = input()
count = 0

for _ in range(len(num)-4+1):
    s = num[_:_+4]
    if int(s) in nums:
        count += 1

for _ in range(len(num)-5+1):
    s = num[_:_+5]
    if int(s) in nums:
        count += 1

for _ in range(len(num)-6+1):
    s = num[_:_+6]
    if int(s) in nums:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
X = [0]*2100
X[0] = 1
tmp = 0
p = 10
for i in range(len(S)):
    tmp = (tmp*10+int(S[i]))%2019
    p = (p*202)%2019
    X[(tmp*p)%2019] += 1
ans = 0
for i in range(len(X)):
    if X[i] >= 2:
        ans += X[i]-1

print(ans)