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:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    s = input()
    n = len(s)
    ans = 0
    if n <= 3:
        print(0)
    else:
        for i in range(3,9):
            for j in range(n - i):
                if int(s[j: j + i + 1]) % 2019 == 0:
                    ans += 1
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

Solution code:
import numpy as np

s = input()

a = np.zeros(len(s)+1, dtype='i8')
res = 0
for i in range(len(s)):
    for k in range(i+4, len(s)+1):
        if int(s[i:k]) % 2019 == 0:
            print(i, k)
            res += a[i] + 1
            a[k] += 1
            break

print(res)

Submission status: Wrong Answer

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

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

for i in range(n):
    for j in range(i + 3, i + 100):
        if j >= n:
            continue
        s_ = s[i:j + 1]
        if int(s_) % 2019 == 0:
            ranges.append([i, j + 1])
            g[i].append(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:
def c(n):
  return (n*(n-1)//2)
  
S = int(input())
s = str(S)
a = len(s)
enbas = [0]*(a+1)
puiss = 1
for i in range(a):
  enbas[i]=((int(s[a-i-1])*puiss+enbas[i-1])%2019)
  puiss=(puiss)*10
  puiss=puiss%2019
enbas.sort()
print(enbas)
compte = 0
i = 0
avant = 0
for n in range(a+1):
  if avant==enbas[n]:
    i+=1
  else:
    compte+=c(i)
    avant = enbas[n]
    i = 1
print(compte)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
from functools import reduce

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
    S = input()
    S = str(S)
    #Slist = [int(x) for x in list(str(S))]
    #N = len(Slist)
    ans = 0
    a = [str(2019*xx) for xx in range(1,99)]

    #print(a)
    #print(N)

    for i in a:
        if i in S:
            ans += 1
            S2 = S[S.find(i)+1:]
            #print("S2",S2)
            while True:
                if i in S2:
                    ans += 1
                    S2 = S2[S2.find(i)+1:]
                    #print("S3",S2)
                else:
                    break
            #if S.count(i)>=2:
                #ans = ans + S.count(i) -1
    print(ans)



"""
    for i in range(N-3):
        for j in range(i+3,N):
            num_list = [0]*(j-i+1)
            num_list = [Slist[k] for k in range(i,j+1)]
            num = int(reduce(lambda x, y: x + y, [str(x) for x in num_list]))
            if num % 2019 == 0:
                ans += 1
            #print(num)
    
    print(ans)
"""


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
S = str(input())
ch = [int(x) for x in S]
inS = int(S)
cnt = 0
li_tm =[]

def kan (list_1):
    sei = ''
    global sei_n
    for you in range(len(list_1)):
        sei += str(list_1[you])
    sei_n = int(sei)
    sei =''
for i in range(len(ch)):
    li_tm.append(ch[i])
    if len(li_tm) >= 4:
        for y in range(i+1,len(ch)):
            li_tm.append(ch[y])
            kan(li_tm)
            if sei_n % 2019 == 0:
                cnt += 1
                li_tm = []
                li_tm.append(ch[y])
        
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
start = []
stop = []

for i in range(0, n - 3):
    for j in range(4, 9):
        if i + j <= n and int(s[i:i+j]) % 2019 == 0:
            start.append(i)
            stop.append(i+j)

ans = 0
ls = len(start)
mark = [0 for _ in range(ls)]
for i in range(ls):
    if mark[i] != 0:
        continue
    mark[i] = 1
    flag = True
    while flag:
        j = 0
        flag = False
        while start[i+j] >= stop[i]:
            if start[i+j] == stop[i]:
                mark[i+j] = mark[i] + 1
                i += j
                flag = True
                break
            j += 1
            if i + j >= ls:
                break
    ans += mark[i] * (mark[i] + 1) // 2
print(ans)

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]
    elif CHECK[i]>1:
        ans+=CHECK[i]-1
 
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0
 
if len(S) < 4:
  print(cnt)
  exit()
  
for a in range(len(S) - 3):
  if int(S[a:a+4]) % 2019 == 0:
    cnt += 1
 
for a in range(len(S) - 4):
  d = int(S[a:a+5])
  if d % 2019 == 0:
    cnt += 1
 
print(cnt)

Submission status: Wrong Answer

Solution code:
S = str(int(input()))
n = 0
lst = []
output = 0
while True :
    if n <= len(S) - 5 :
        lst.append(S[n:n+5])
        n += 1
    else :
        break
for i in lst :
    if int(i) % 2019 == 0 :
        output += 1
print(output)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
    N=sys.stdin.readline()
    ans=0
    mathlen=len(str(N))
    strN=str(N)
    for i in range(mathlen-1):
        j=i+1
        while j<mathlen+1:
            if int(strN[i:j])%2019==0:
                ans+=1
            j+=1
        
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
s_num = int(s)
len_s = len(s)
list=[0 for x in range(len_s+1)]
for i in range(len_s-1,-1,-1):
    for j in range(4,min(8,len_s-i+1)):
        if int(s[i:i+j])%2019==0:
            list[i]=list[i+j]+1
print(sum(list))

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, len(s) + 2):
        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:
#!/usr/bin/env python3
import sys


def solve(S: int):
    S =str(S)
    l = len(S)
    elds = [x*2019 for x in range(10000) if "0" not in str(x*2019)]
    # print(elds)
    s = S
    ans = []
    for t in range(5,9):
        for x in range(l-t+1):
            # print(s[x:x+t])           
            if int(s[x:x+t]) in elds:
                ans.append((x,x+t))

    p= [a_[0] for a_ in ans]
    q= [a_[1] for a_ in ans]
    
    print(len(ans)+len(set(p)&set(q)))
    

    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 = int(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#0がない
s = input()
ans = 0
size = len(s)
for i in range(size):
    for j in range(i+5, min(size+1, i+30)):
        if int(s[i:j])%2019==0:
            ans += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=str(input())
list=[]

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

l=len(list)
res=0

for j in range(0,l):
  if(list[j] in S):
    N=S
    while(list[j] in N):
      res+=1
      a=N.find(list[j])
      N=N[a+1:]
print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# input
import sys

read = sys.stdin.buffer.read
# input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

s = input()
n = len(s)
mod = 2019
cum = [0] * (n + 1)
cum[0] = 0
for i in range(n):
    # print(int(s[i]) - 48)
    cum[i + 1] = (cum[i] * 10 + int(s[i])) % mod
# print(cum)
mod_cum = [0] * (n + 1)
for i in range(n + 1):
    mod_cum[i] = (cum[i] * pow(10, n - i, mod)) % mod
# print(pow(10, 15, mod))
mod_cum.sort()
# print(mod_cum)
ans = 0
cnt = 0
tmp = mod_cum[0]
for i in range(n):
    if mod_cum[i + 1] == tmp:
        ans += 1
    else:
        tmp = mod_cum[i + 1]
        cnt = 1
        if cnt > 1:
            ans += cnt * (cnt + 1) // 2
if cnt > 1:
    ans += cnt * (cnt + 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
# print(len(s));
i=0
count=0

for k in range(4,7):
    i=0
    for j in range(k,len(s)+1):

    
        m=s[i:j]
        i=i+1
        # print(m)
    
        # print(int(m))
        if int(m)%2019==0:
            count+=1
        # i=i+1

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
count = 0
for i in range(len(S)):
  if int(S[i]) <= 0:
    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:
    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:
import re
S = input()

c = [re.compile(fr'(?={str(2019 * i)})') for i in range(1, 200000 // 2019 + 1)]
cnt = 0

for c_n in c:
    cnt += len(c_n.findall(S))

print(cnt)

Submission status: Wrong Answer

Solution code:
S=str(input())
ans=0
 
for i in range(2019,2019*99+1,2019):
  for j in range(len(S)+1):
    if str(i) == S[j:j+len(str(i))]:
      ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
s=str(input())
l=[]
t=0
for i in range(1,len(s)):
    g=int(s[0:i+1])
    g=g%2019
    l.append(g)

def framod(n, a=1):
    for i in range(1,n+1):
        a=a * i 
    return a

def comb(n, k):
    a=framod(n)
    b=framod(k)
    c=framod(n-k)
    return (a//(b*c))

for i in range(0,2019):
    z=l.count(i)
    if z>1:
        t+=comb(z,2)
print(t)

Submission status: Wrong Answer

Solution code:
s = input()

cnt = 0
for i in range(len(s),2,-1):
    if int(s[(i-3):i])%19 == 0 and int(s[i-4]) % 2 == 0:
        cnt += 1
        
       


print(cnt)

Submission status: Wrong Answer

Solution code:
import re
from collections import namedtuple
match = namedtuple('match', 'start,end')


s = input()

# パターンを収集
pats = []
s_set = set()
for i in range(1, 10001):
    s_set.add(str(2019*i).rstrip('0'))
for _s in s_set:
    pats.append(re.compile('(?=({})(0*))'.format(_s)))

# マッチを取る
m_set = set()
count = 0
for pat in pats:
#     print(pat)
    read_set = set()
    for m in re.finditer(pat, s):
        print(pat)
        g = m.group
        m_set.add(match(m.start(), m.start()+len(g(1))))
matches = sorted(m_set, key=lambda m: m.start)

# ペアを集計
pairs = []
for i, m in enumerate(matches):
    ind = i + 1
    while (ind<len(matches)) and (m.end >= matches[ind].start):
        ind += 1
    if ind<len(matches):
        _m = matches[ind]
        inter = list(set(s[m.end:_m.start]))
        if inter[0]=='0' and len(inter)==1:
            pairs.append((m, _m))

# 最終的な値を算出
def get_comb(n):
    return n*(n-1)//2

pairs = sorted(pairs, key=lambda p: p[0].start)
ms = []
current_num = 1
res = len(matches)
for i in range(len(pairs)):
    if i+1<len(pairs) and pairs[i][1] == pairs[i+1][0]:
        current_num += 1
    else:
        res += get_comb(current_num)
        current_num = 1

print(res)

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)
    for j in range(i + 3, i + 8):
        if j + 1 > len(S):
            continue
        if int(S[i:j + 1]) % 2019 == 0:
            # print(i, j, S[i:j + 1])
            count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

numMultiples = 0
seenRemainders = [set() for _ in range(n)]

for i in range(n):
    remainder = 0
    prefixesFound = 0

    for j in range(i, n):
        remainder = (10 * remainder + int(s[j])) % k

        if remainder in seenRemainders[j]:
            break

        seenRemainders[j].add(remainder)

        if remainder == 0:
            prefixesFound += 1

    print(prefixesFound)

    numMultiples += prefixesFound * (prefixesFound + 1) // 2

print(numMultiples)

Submission status: Wrong Answer

Solution code:
s = input()
d = [0]

def check(s, r):
    for i in range(0, len(s)-r+1):
        num = int(s[i:i+r])
        if num % 2019 == 0:
            d[0] += 1
            s = s[0:i+1] + s[i+r-1:]
            if len(s) >= r:
                check(s, r)
    if r <= 5:
        print(d[0])
        exit()
    if len(s) >= r:
        check(s, r-1)

check(s, len(s))

Submission status: Wrong Answer

Solution code:
s = str(input())
 
ans = 0
len_s = len(s)
for i in range(4,9):
    for j in range(len_s):
        if j+i > len_s :
            break
        if int(s[j:j+i]) % 2019 == 0:
            ans +=1

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
def main():

    S = input()
    int_S = int(S)
    N = len(S)
    cnt = 0
    pos_l = 0
    pos_r = 0


    while (True):
        pos_r +=  + 1
        
        if (pos_r < N):
            tmp = int(S[pos_l: pos_r + 1])
            if (tmp % 2019 == 0):
                cnt += 1
                pos_l = pos_r
        else:
            pos_l += 1
        
        if (pos_l >= N):
            break


    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#from collections import Counter
import re

S = input()
num = len(S)

data = [0]*100

for i in range(100):
    data[i] = 2019 * (1 + i)

ans = 0


for i in range(100):
    tar = str(data[i])
    if (tar in S):
        tarNum = len(tar)

        for j in range(0, num - tarNum + 1, 3):
            cut = S[j: j + 8]
            if (tar in cut):
                ans += 1
        '''
        res = re.findall(tar, S)
        tarNum = len(res)
        ans += tarNum
        '''
print(ans)

Submission status: Wrong Answer

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

counter = 0

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

print(counter)

Submission status: Wrong Answer

Solution code:
N = input()

A = 0

while True:
    B = ""
    for C in range(len(N)):
        B += N[C]

        if int(int(B) % 2019) == 0:
            print(B)
            A += 1

    if len(N) < 5:
        break

    N = N[1:len(N)]

print(A)

Submission status: Wrong Answer

Solution code:
S=input()

ans=0

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

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
ans = 0

for i in range(len(s)-4):
    for j in range(5,len(s)+1):
        tmp = s[i:j]
        tmp = "".join(tmp)
        if tmp == "":
            continue
        if int(tmp)%2019 == 0:
            ans += 1
            print((i+1,j))
            print(tmp)
            break
            
print(ans)

Submission status: Wrong Answer

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

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

S = input()

ans = 0
i = 0
cnt = 0
prev_j = -1

while True:
    for j in range(i+5, len(S)+1):
        # print(i, j, S[i:j])
        if int(S[i:j]) % 2019 == 0:
            ans += 1
            if prev_j == i:
                cnt += 1
                ans += cnt
            else:
                cnt = 0
            prev_j = j
            i = j - 2
            break
    i += 1
    if i+4 >= len(S):
        break

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
s_num = int(s)
len_s = len(s)
list=[0 for x in range(len_s+1)]
for i in range(len_s-1,-1,-1):
    for j in range(4,min(8,len_s-i+1)):
        print(i,j, s[i:j+i])
        if int(s[i:i+j])%2019==0:
            list[i]=list[i+j]+1
print(sum(list))

Submission status: Wrong Answer

Solution code:
s = input()
sl = len(s)
num = str()
n = 0
ans = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
@lru_cache()
def dfs(i):
    res = 0
    for j in range(5, 9):
        if i-j >= -1:
            try:
                if dic[int(S[i-j+1:i+1])]:
                    res += dfs(i-j) + 1
            except:
                continue
    return res

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 < 20190000:
    if not "0" in str(i*j):
        dic[i * j] = True
    j += 1
ans = 0
for i in range(len(S)-1, -1, -1):
    ans += dfs(i)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    s = input()
    n = len(s)
    s = s[::-1]
    ans = 0
    if n <= 3:
        print(0)
    else:
        for i in range(3,min(n,8)):
            for j in range(n - i):
                if int(s[j: j + i + 1][::-1]) % 2019 == 0:
                    ans += 1
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

Solution code:
S = input()
l = []
c = 0
for i in range(200000):
    c += S.count(str(2019*(i+1)))
print(c)

Submission status: Wrong Answer

Solution code:
s=str(input())
l=[0]
t=0
for i in range(1,len(s)):
    g=int(s[0:i+1])
    g=g%2019
    l.append(g)

def framod(n, a=1):
    for i in range(1,n+1):
        a=a * i 
    return a

def comb(n, k):
    a=framod(n)
    b=framod(k)
    c=framod(n-k)
    return (a//(b*c))

for i in range(0,2019):
    z=l.count(i)
    if z>1:
        t+=comb(z,2)
print(t)

Submission status: Wrong Answer

Solution code:
S=input()
N=len(S)
if N<4:
  print(0)
  exit(0)
M=2019
X=S
ans=0
x=[]
for l in range(N-3):
  for r in range(l+3,N):
    if int(X[l:r+1])%M==0:
      ans+=1
      x.append([l,r])
      break
def search(a,x,j):
  while j<len(x):
    if a[1]==x[j][0]:
      return 1+search(x[j],x,j+1)
    j+=1
  return 0
for i,a in enumerate(x):
  ans+=search(a,x,i+1)
print(ans)

Submission status: Wrong Answer

Solution code:
# 2019 = 3*673
MOD = 2019
S = input()
N = len(S)
X = [0]*2100
X[0] += 1
tmp = 0
hoge = pow(10,N,2019)

for i in range(N):
    tmp = (tmp*10+int(S[i]))%MOD
    hoge = (hoge*202)%MOD 
    X[(tmp*hoge)%MOD] += 1

ans = 0

for i in X:
    if i >= 2:
        ans += ((i*i-1)//2)

print(ans)

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+4, len(S)):
       #print(i, "-", j, S[i:j])
       if j-i >= 200000:
           continue
       if int(S[i:j]) >= div_value \
           and int(S[i:j]) % div_value == 0:
           #print(i, "-", j, int(S[i:j]))
           cnt = cnt+1

print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
import re
from collections import namedtuple
match = namedtuple('match', 'start,end')


s = input()

# パターンを収集
pats = []
s_set = set()
for i in range(1, 10001):
    s_set.add(str(2019*i).rstrip('0'))
for _s in s_set:
    pats.append(re.compile('(?=({})(0*))'.format(_s)))

# マッチを取る
m_set = set()
count = 0
for pat in pats:
#     print(pat)
    read_set = set()
    for m in re.finditer(pat, s):
        print(pat)
        g = m.group
        m_set.add(match(m.start(), m.start()+len(g(1))))
matches = sorted(m_set, key=lambda m: m.start)

# ペアを集計
pairs = []
for i, m in enumerate(matches):
    ind = i + 1
    while (ind<len(matches)) and (m.end >= matches[ind].start):
        ind += 1
    if ind<len(matches):
        _m = matches[ind]
        inter = list(set(s[m.end:_m.start]))
        if inter[0]=='0' and len(inter)==1:
            pairs.append((m, _m))

# 最終的な値を算出
def get_comb(n):
    return n*(n+1)//2

pairs = sorted(pairs, key=lambda p: p[0].start)
ms = []
current_num = 1
res = 0
for i in range(len(pairs)):
    if i+1<len(pairs) and pairs[i][1] == pairs[i+1][0]:
        current_num += 1
    else:
        res += get_comb(current_num)
        current_num = 1

print(res)

Submission status: Wrong Answer

Solution code:
# D - Multiple of 2019

S = input()
cnt = 0

for i in range(200000 // 2019 + 1):
    n = str(2019 * i)
    if n in S:
        for i in range(len(S) - len(n) + 1):
            if S[i:i + len(n)] == n:
                cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import re
S=input()

x=[i for i in range(1,1000)]
x=map(lambda i:str(i*2019),x)



ans=0

for i in x:
    t=len(re.findall("(?={})".format(i),S))
    ans+=t

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

s = input()
ans = 0
same = []
l = [str(i*2019) for i in range(1, 100)]
for i in l:
    if i in s:
        same.append(i)
        ans += 1
for i in same:
    m = s
    ans -= 1
    while True:
        idx = m.find(i)
        m = m[idx+1:]
        if idx==-1:
            break
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
l = len(S)
 
slist = [int(''.join(S[i:j])) for i in range(l-3) for j in range(i+3,l)]
 
cnt = sum([1 for s in slist if s%2019==0])

print(cnt)

Submission status: Wrong Answer

Solution code:
# 2019 = 3*673
MOD = 2019
S = input()
N = len(S)
X = [0]*2100
X[0] += 1
tmp = 0
hoge = pow(10,N,2019)

for i in range(N):
    tmp = (tmp*10+int(S[i]))%MOD
    hoge = (hoge*202)%MOD 
    X[(tmp*hoge)%MOD] += 1

ans = 0

for i in X:
    if i >= 2:
        ans += (i*i-1)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#! env/bin/local python3
# -*- coding:utf-8 -*-

import math

def main():

    inp = input().strip('\n')
    number_of_digit = len(inp)
    n = int(inp)

    print(math.factorial(number_of_digit))

    for i in range(math.factorial(number_of_digit)):
        a = 0


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = str(input())
count = 0
for j in range(3):
  for i in range(len(n) - 3 - j):
    if(int(n[i:4 + i + j]) % 2019 == 0):
      if(abs(int(n[i:4 + i + j])) <= 200000 and abs(int(n[i:4 + i + j])) >= 1 ):
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
s = input()

ans = 0
f = 0
end = [0 for i in range(len(s))]
m = 0
i = 0

while i <len(s)-3:
    st = s[i]+s[i+1]+s[i+2]
    for j in range(len(s)-3-i):
        st += s[i+3+j]
        if int(st)%2019 == 0:
            plus = 1 + m
            ans += plus
            m = plus
            end[i+3+j] += plus
            i = i+j+3-1
            break
        else:
            m = 0
    i += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def solve(S: int):
    # cnt = 0
    # for i in range(len(str(S))):
    #     for j in range(i + 1, len(str(S))):
    #         if not int(str(S)[i:j]) % 2019:
    #             cnt += 1
    # print(cnt)
    cnt = 0
    l = filter(lambda x: '0' not in str(x), range(2019, 200000, 2019))
    l = [str(i) for i in l]
    s = str(S)
    for i in range(len(s)):
        # if 5 + i > len(s) - 1:
        #     continue
        if s[i:4 + i] in l or s[i:5 + i] in l:
            cnt += 1
    print(cnt)
    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 = int(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

S = input()
lenS = len(S)
S = int(S)
rui = [0] * 2019
for i in range(lenS + 1):
    rui[((S % (10 ** i)) % 2019)] += 1

ans = 0
#for i in rui:
#    if i >= 2:
#        ans += (i * (i - 1) // 2)

print(ans)