Problem:


Score : 400 points

Problem Statement

Given is a string S consisting of digits from 1 through 9.

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Wrong Answer

Solution code:
s = input()
c = 0

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

for i in range(1, 100):
    t = i * 2019
    if t > 200000:
        break
    # print(t)
    # print(len(str(t)))
    len_t = len(str(t))
    p = str(s).find(str(t))
    if p == -1:
        continue
    for j in range(p, len(str(s)) - (len_t - 1)):
        tmp = s[j:j + len_t]
        if int(tmp) == t:
            c += 1
print(c)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    k = 2019
    tens = [1 for _ in range(len(s)+1)]
    for i in range(1, len(s)+1):
        tens[i] = tens[i-1] * 10 % k

    mods0toi = [0 for _ in range(len(s)+1)]
    cur = 0
    for i in range(len(s))[::-1]:
        j = len(s) - i - 1
        mods0toi[i] = (cur + int(s[i]) * tens[j]) % k
        cur = mods0toi[i]
    s = collections.Counter(mods0toi)
    ans = 0
    t = s.keys()
    for c in t:
        ans += (s[c] - 1)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
S = str(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 counter(str, l, k): 
	count=0
	i=0
	while i<=l:
		n=0
		j=i+2
		while j<l:
			n = n * 10 + (ord(str[j]) - ord('0'))
			if n%k==0:
				count+=1
			j+=1
		i+=1
	return count



if __name__ == '__main__': 
	str = input()
	l = len(str) 
	k = 2019
	print(counter(str, l, k))

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
cnt = [0]*N
ans = 0
flg = False
for i in range(N):
    cnt = [0]*N
    for k in range(i,N):
        cnt[k] = (cnt[k-1]*10 + int(S[k]))%2019
        if cnt[k] == 0:
            flg = True
            cnt[k] = int(S[k])
            ans += 1
    if flg:
        print(ans)
        exit()
print(0)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
S = input()
i = 0
j = 1
ans = 0
while(j <= len(S)):
    if i == j:
        j += 1
        continue
    tmp = int(S[i:j]) % 2019
    if tmp == 0:
        ans += 1
        i += 1
        continue
    tmp_ = int(S[i:j+1]) % 2019
    if tmp < tmp_ or tmp_ == 0:
        j += 1
        continue
    else:
        i += 1
        continue
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

DEBUG = False

dp = [0] * (len(S)+1)

if int(S[:4]) % 2019 == 0:
    dp[4] += 1

count = 0
for i in range(5,len(S)+1):
    for j in range(i-4+1):
        count += 1
        if DEBUG:
            print("i: {}, j:{}".format(i, j))
            print("string: {}".format(S[i-4-j:i]))
        if int(S[i-4-j:i]) % 2019 == 0:
            if DEBUG:
                print("find!!")
            dp[i] += 1
            dp[i] += dp[i-4]
            break
    # dp[i] += dp[i-1]
if DEBUG:
    print("count: {}".format(count))
    print("dp: {}".format(dp))
print(dp[len(S)])

Submission status: Wrong Answer

Solution code:
str=input("")
count=0;
for i in range(len(str)-4):
  if i==0:
    continue
  for j in range(i+3,len(str)+1):
    if eval(str[i:j]) % 2019==0:
      count+=1
print(count)

Submission status: Wrong Answer

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = int(input())
total = 0
S1 = str(S)
for i in range(0,S,2019):
  print(i)
  j = str(i)
  if j in S1:
    total+=1
print(total)

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

Submission status: Wrong Answer

Solution code:
S=input()
N=len(S)
S=int(S)
nums=[0]*200000
maxi=0
zero=0
tmp=S
ite=10**(N-1)
for i in range(N):
    div=tmp%2019
    if div==0:
        zero+=1
    nums[div]+=1
    maxi=max(div,maxi)

    tmp%=ite
    ite//=10
    
ans = zero
for i in range(1,maxi):
    if nums[i]<2:
        continue
    ans += nums[i]*(nums[i]-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())

a = ''
count = 0
i = 0
while(i < len(S)):
    for j in range(i,len(S)):
        a += S[j]
        if(int(a) % 2019 == 0):
            count += 1
    a = ''
    for j in range(i,len(S) - i):
        a += S[j]
        if(int(a) % 2019 == 0):
            count += 1
    i += 1
    a = ''
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
# 2*10**5 以下の2019の倍数
x2019 = [str(2019*i)[::-1] for i in range(1, 100)]
ans = 0
dic = {}
# ex. {09: (09102, 5)}
for x in x2019:
    dic[x[:2]] = (x, len(x))

for n in range(0, len(s)-1):
    two = s[n] + s[n+1]
    cand = dic[two]
    index = n + cand[1]
    if index < len(s)+4:
        if cand[0] == s[n:index]:
            ans += 1
print(ans)

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 + tarNum - 1]
            if (cut == tar):
                ans += 1
        '''
        res = re.findall(tar, S)
        tarNum = len(res)
        ans += tarNum
        '''
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=(10*puiss)%2019
enbas.sort()
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:
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):
        count += 1

print(count)

Submission status: Wrong Answer

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

import re

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

    if nnn in nn:
        c+=len(re.findall(nnn[0]+"(?="+nnn[1:]+")", nn))
print(c)

Submission status: Wrong Answer

Solution code:
S = input()


count = 0

for i in range(len(S)):
    for j in range(i + 3,len(S)):
        print(S[i:j+1])

        x = int(S[i:j+1])
        

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

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
count = 0
S_len = len(S)
for i in range(S_len*5):
    countstr = i * 2019
    count += S.count(str(countstr))
print(count)

Submission status: Wrong Answer

Solution code:
st = input()
ans = 0
n = len(st)
ls = ['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']
for val in ls:
    p = len(val)
    x = 0
    i = 0
    while i<n:
        if st[i:i + p] == val:
            x += 1
            i += p-1
        else:
            i += 1
    ans += x
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
if len(s) < 4:
    print(0)
count = 0
sLength = len(s)
for i in range(sLength):
    for j in range(int(sLength/2)):
        if i + j + 4 <= sLength - j:
            if int("".join(s[i:i + j + 4]))%2019 == 0:
                count += 1
            if i + j + 4 != sLength - j:
                if int("".join(s[i:sLength - j]))%2019 == 0:
                    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

l = [str(i*2019) for i in range(1,200000//2019+1)]

for i in l:
  j = 0
  while True:
    k = s.find(i, j)
    if k != -1:
      count += 1
      j = k+1
    else:
      break

print(count)

Submission status: Wrong Answer

Solution code:
import sys

s = str(input())
tisa = []
for i in range(1,100):
  ww = str(2019*i)
  if '0' not in ww:
    tisa.append(ww)
#ok
#print(s)
#print(len(tisa))
#重複　count methodは無理
ans = 0
for c in tisa:
  for i in range(0,len(s)-len(c)+1):
    if s[i:i+len(c)]==c:
      ans += 1

  

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
cnt = [0]*N
ans = 0
flg = False
for i in range(N):
    cnt = [0]*N
    for k in range(i,N):
        cnt[k] = (cnt[k-1]*10 + int(S[k]))%2019
        if cnt[k] == 0:
            flg = True
            cnt[k] = int(S[k])
            ans += 1
    if flg:
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
import re

S = str(input())

def count_o(sub, string):
    # via https://www.geeksforgeeks.org/python-count-overlapping-substring-in-a-given-string/
    count = 0
    start = 0
    while start < len(string):
        pos = string.find(sub, start)
        if pos != -1:
            start = pos + 1
            count += 1
        else:
            break
    return count

count = 0
for i in range(1, 1000):
    j = str(i * 2019)
    if '0' in j:
        continue
    if j not in S:
        continue
    count += count_o(j, S)

print(count)

Submission status: Wrong Answer

Solution code:
s = str(input())
ans = 0
key = 0

while key < len(s)-4:
    old_key = key
    for i in range(5+key,len(s)+1):
        local_count = 0
        val = int(s[key:i])
        if val % 2019 == 0:
            local_count += 1
            key = i-1
        ans += local_count * (local_count+1) // 2
    if key == old_key:
        key = key + 1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  S=input()
  S_len=len(S)
  s_count=0
  i=0
  while(i<=S_len-3):
    for j in range(i+3,S_len):
      tgtS=S[i:j+1]
      int_tgtS=int(tgtS)
      if(int_tgtS%2019==0):
        s_count=s_count+1
        i=i+3
    i=i+1
  print(s_count)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S =  int(input())
a = str(S)
li = a.split()
c = 0
b=0
for i in range(len(li)):
    for a  in range(len(li)):
        
        v = li[i:a+i+1]
        d = "".join(v)
        b = int(d)
        if b%2019 == 0:
            c += 1

print(c)

Submission status: Wrong Answer

Solution code:
s=list(input())
l=len(s)
ans=0
for i in range(l-3):
    num=s[i]
    index=i+1
    for j in range(1,82):
        num+=s[i+j]
        if int(num)%2019==0:
            ans+=1
        index+=1
        if l-1<index:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
if len(s)<=4:
  if int(s)%2019==0:
    print(1)
  else:
    print(0)

else:
  from collections import deque
  count=0
  for i in range(4,7):
    sub=deque()
    j=0
    while True:
      if len(sub)>=i:
        break
      sub.append(s[j])
      j+=1
    
    for k in range(i-1,len(s)):
      # print("k=",k)
      if k>=i:
        sub.popleft()
        sub.append(s[k])
      tmp="".join(sub)
      # print("tmp=",tmp)
      if int(tmp)%2019==0:
        count+=1
        # print("ktkr")
  print(count)

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)

# 最小の区間は得られた
# 最小の区間同士がくっつくときが厄介しかもオーバーラップしてる
# i,jをグラフとしてみると深さから通りの数が計算できそう

graph = defaultdict(lambda: [])
for i, j in candi:
    graph[i].append(j)

ans = 0

# print(graph)
is_visited = [False] * (len(S) + 1)


def dfs(u, d):
    # print(u)
    is_visited[u] = True
    if len(graph[u]) == 0:  # 終了条件
        global ans
        ans += d * (d - 1) // 2
        return
    for nu in graph[u]:
        dfs(nu, d + 1)


for i in range(len(S)):
    # print(i)
    if is_visited[i]:
        continue
    dfs(i, 1)


print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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


main()

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
# 1<=S<=200000
S = str(input()).rstrip()
# print(len(S))
count = 0
for i in range(len(S) - 3):
    # print(i)
    for j in range(i + 3, i + 7):
        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)
count = 0
for i in range(0,n-3):
    s = S[i:i+4]
    for j in range(i+4,n):
        s = s + S[j]
        print(s)
        if int(s)%2019 == 0 : count += 1
print(count)

Submission status: Wrong Answer

Solution code:
s=input()
l=0
r=4
ans=0
a=[]
while r<=len(s) and l<len(s):
    if l==len(s)-4:
        break
    if int(s[l:r])%2019==0:
        ans+=1
        l=r-1
        r+=3
        a.append(l)
        a.append(r)
    elif r==len(s):
        l+=1
        r=l+1
    else:
        r+=1
for i in range(len(a)//2-1):
    tmp=0
    if a[2*i+1]==a[2*i+2]:
        tmp+=(tmp+1)
    else:
        ans+=tmp
        tmp=0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = sys.stdin.readline()

N = len(S)

count = 0

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

print(count)

Submission status: Wrong Answer

Solution code:
S = list(input())
Count = 0
if len(S)<=4:
    print(0)
else:
    for w in (5,len(S)):
        for i in range(0,len(S)+1-w):
            if int("".join(S[i:i+w]))%2019==0:
                Count+=1
    print(Count)

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 + 7):
        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()
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(7,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('')
max_s = 20000
rec = 0
for m in (range(max_s+1)):
    ms=str(2019*m)
    if not '0' in ms:
        idx=0
        idx=s.find(ms)
        while idx >= 0:
            rec+=1
            idx=s.find(ms,idx+1)
#            print("{} {}".format(ms,idx))
print(rec)

Submission status: Wrong Answer

Solution code:
l = []
for i in range(1, 1000000):
    l.append(str(2019*i))

s = input()
ans = dict()
for i in l:
    if i in s:
        for j in range(len(s)-len(i)+1):
            if s[j:j+len(i)] == i:
                ans[str(j+1)+"-"+str(j+len(i))] = 1

# print(l)
print(len(ans))
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

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

for i in range(len(S)):
    # 4~7桁で見たときの2019の倍数の区間
    if int(S[i]) == 0:
        continue
    for j in range(4,8):
        if i+j <= len(S):
            x = int(S[i:i+j])
            if x % 2019 == 0:
                # 今調べている区間につながる倍数の数＋自身
                ls[i+j-1] += 1
                if i > 0:
                    ls[i+j-1] += ls[i-1]

count = 0
for i in ls:
    count += i

print(count)

Submission status: Wrong Answer

Solution code:
import sys

s = str(input())
tisa = []
for i in range(1,100):
  ww = str(2019*i)
  if '0' not in ww:
    tisa.append(ww)
#ok
#print(s)
print(len(tisa))
#重複　count methodは無理
ans = 0
for c in tisa:
  for i in range(0,len(s)-len(c)+1):
    if s[i:i+len(c)]==c:
      ans += 1

  

print(ans)

Submission status: Wrong Answer

Solution code:
num = 2019
ls = []
for i in range(2018,2*10**5):
    if i%num==0:
        ls.append(str(i))

st = input()
ans = 0
n = len(st)
for val in ls:
    p = len(val)
    x = 0
    i = 0
    while i<n:
        if st[i:i + p] == val:
            x += 1
            i += p-1
        else:
            i += 1
    ans += x
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np


# input the data
s = input()
m = len(s)
detecter = []
count = 0

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

for i in range(len(detecter)):
    if (detecter[i] in s) == True:
        detected = len(detecter[i])
        tmp = s.count(detecter[i])
        count += tmp
print(count)

Submission status: Wrong Answer

Solution code:
s = input('')
max_s = 20000
rec = 0
for m in (range(max_s+1)):
    ms=str(2019*m)
    if not '0' in ms:
        idx=0
        idx=s.find(ms)
        while idx >= 0:
            rec+=1
            idx=s.find(ms,idx+1)
            print("{} {}".format(ms,idx))
print(rec)

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(7,len_s-i+1)):
        if int(s[i:i+j])%2019==0:
            list[i]=list[i+j]+1
print(list)
print(sum(list))

Submission status: Wrong Answer

Solution code:
# D - Multiple of 2019

S = input()
cnt = 0

for i in range(200000 // 2019):
    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:
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(int(n[i:4 + i + j]) <= 200000):
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
L = len(S)
count = 0
j = 4
for i in range(0, L-4):
    k = j
    A = 0
    if int(S[i:j+1]) % 3 == 0:
        if int(S[i:j+1]) % 673 == 0:
            count += 1
    else:
        if j == L - 1:
            j = i + 5
            continue
    if j == L - 1:
        j = i + 5
        continue
    j += 1
    i -= 1
print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
s = input("")
l = ['2019', '4038', '6057', '8076', '10095', '12114', '14133', '16152', '18171']
res = []
for i in range(len(s)):
	s2 = s[i:]
	for i in l:
		b = s2.find(i)
		if b!= -1:
			e = b+ len(i)
			b = b +1
			res.append((b, e))
#print(res)
print(len(res))

Submission status: Wrong Answer

Solution code:
str=input()
gap_len=4
flag=0
count=0
for gap_len in range(4,20):
    for i in list(range(len(str)-gap_len+1)):
        sub_str=str[flag:flag+gap_len]

        num=int(sub_str)
        if(num%2019==0):
            count+=1
        flag+=1
    flag =0
print(count)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
count=0
index=1
value=0
arr=[]
while index*2019<=999999:
    value=str(index*2019)
    arr.append(value)
    index+=1     

for i in range(n):
    if i+5<=n:
        if s[i:i+5] in arr or s[i:i+6] in arr or s[i:i+7] in arr:
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
input_str = input()

output_cnt = 0
slice_size = 2019
to_i = len(input_str) - 3
to_j = len(input_str) + 1
value_set = set()

for i in range(to_i):
  from_j = 3 + i
  for j in range(from_j, to_j):
    value_set.add(int(input_str[i : j]))

for s in value_set:
  if s % slice_size == 0:
    output_cnt += 1

print(output_cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
s = input()
N = len(s)
#print(N)

i = 0
j = 4

ans=0

while(i < N-3):
    while(j<N+1):
        print(s[i:j])
        #print(int(s[i:j])%2019)
        if int(s[i:j])%2019 == 0:
            ans=ans+1
        j=j+1
        #elif (int(s[i:j])%2019)%1000 == 201:
            #j=j+1
        #elif (int(s[i:j])%2019)%100 == 20:
            #j=j+2
        #elif (int(s[i:j])%2019)%10 == 2:
            #j=j+3
        #else:
            #j=j+4

    i=i+1
    j=i+4

print(ans)

Submission status: Wrong Answer

Solution code:
S=list(input())
N = len(S)
arr = []

for i in range(N):
  a = int(int(S[i]) *(10**(N-i-1))%2019)
  arr.append(a)

arr.reverse()
def cumsum(xs):
  result = [xs[0]]
  for x in xs[1:]:
    result.append(result[-1] + x)
  return result
res = cumsum(arr)

ans = [0 for i in range(2020)]
cnt0 = 0
for i in range(N):
  a = res[i]%2019
  res[i] = a
  ans[a] += 1
  if a == 0:
    cnt0 += 1

cnt = 0
for i in range(1,1010):
  cnt += ans[i] * ans[2019-i]
  

cnt = int(cnt + (cnt0+1)*cnt0/2)
print(cnt)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
ans=0
y=0
cnt=0
i=0
pe=[0]*(n+32)
pa=[0]*(n+32)
for i in range(n-3):
    if int(s[i:i+4])%2019==0:
        pe[i+3]+=pe[i]+1
        cnt+=1
        y=1
    if int(s[i:i+5])%2019==0 and i!=n-4:
        pe[i+4]+=pe[i]+1
        cnt+=1
    if cnt>0:
        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:
import re
S = input()
num = 2019
i = 1
ans = 0
while num*i < 800000:
    ans += len(re.findall(f'(?=({str(num*i)}))', str(S)))
    i += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()

m = []

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


cnt = 0


for i in m:
	for k in range(len(s)):
		if s[k] == i[0]:
			if  i == s[k:k+len(i)]:
				# print(i,s[k:k+len(i)])
				cnt += 1

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

S = input()
P = 2019
N = len(S)
num = [0] * P
num[0] = 1
c = 0
ans = 0
dgt = 1
for i in range(N-1, -1, -1):
    c = (c + int(S[i]) * 10**dgt) % P
    dgt += 1
    dgt %= P
    ans += num[c]
    num[c] += 1
 
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
i = 0
j = 4
counter = 0
num_length = int(len(s))

while True:
    temp = int(s[i:j])
    if temp % 2019 == 0:
        print(i,j)
        counter += 1
    j = j + 1
    if j > num_length:
        j = i + 3
        i = i + 1

    if i == num_length - 4 or num_length == 4 or num_length == 1:
        print(counter)
        exit()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

#d = defaultdict(int)
#for i in rui:
#    d[i] += 1
#ans = 0

#for v, m in d.items():
#    if m >= 2:
#        ans += (m * (m - 1) // 2)

#print(ans)

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):
      count += 1

print(count)

Submission status: Wrong Answer

Solution code:
s = input()

if len(s) <= 4:
    print(1 if int(s) % 2019 == 0 else 0)
    
else:
    st = 0
    ed = 5
    cnt = 0
    for i in range(len(s)+1):
        n = s[st:ed]
        print(n)
        if int(n) % 2019 == 0:
            cnt += 1
            st = ed - 1
            ed += 3
                
        else:
            if len(n) > 4:
                st += 1
            else:
                ed += 1
        if ed > len(s):
            break
    print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
# s = int(input())
s = input()
MOD = 2019

s_len = len(s)
ref = [0] * s_len

for i in range(1, s_len + 1):
    ref[-i] = int(s[-i]) * pow(10, i, MOD) % MOD

for i in range(1, s_len):
    ref[-i - 1] += ref[-i]
    ref[-i - 1] %= MOD

ref_cnt = Counter(ref)
ans = sum(ref_cnt.values()) - len(ref_cnt)
if 0 in ref:
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
length = len(s)
count = 0
even = [2, 4, 6, 8]
odd = [1, 3, 5, 7, 9]
for i in range(length - 2):
  if int(s[i]) == 0:
    continue
  if int(s[i])%2 == 0:
    for j in range(i+2, length + 1, 2):
      if int(s[i:j])%2019 == 0:
        count += 1
  if int(s[i])%2 == 1:
    for j in range(i+3, length + 1, 2):
      if int(s[i:j])%2019 == 0:
        count += 1

print(count)