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()

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
s = str(input())

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

if len(s) < 5:
    print(sum(cnt))
    sys.exit()

for i in range(len(s)-3):
    for j in range(i + 4, min(len(s), i+7)):
        if int(s[i:j+1]) % 2019 == 0:
            cnt[j] += cnt[i-1] + 1
else:
    print(sum(cnt))

Submission status: Wrong Answer

Solution code:
s = input()
count=0
count1=0
temp = ""
i = 0
while(i<len(s)):
    temp+=s[i]
    if(int(temp)%2019==0):  
        # print(temp)
        count+=1
        temp = ""
        continue
    i+=1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    S = list(input())
    N = len(S)

    val = [0] * (2019)
    tenfactor = 1
    cur = 0
    for i in range(N):
        cur = (cur + int(S[N - i - 1]) * tenfactor) % 2019
        tenfactor = (tenfactor * 10) % 2019
        val[cur] += 1

    ans = 0
    for p in range(2019):
        ans += val[p] * (val[p] - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def d164(n):

    ans = 0
    for i in range(1, 200000):
        count = 2019*i
        if n.count(str(count)) != 0:
            ans += n.count(str(count))
    return ans

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

Submission status: Wrong Answer

Solution code:
in1 = input()
ans = 0

for i in range(1, 200000):
    temp = 2019*i
    if in1.count(str(temp)) != 0:
        ans += in1.count(str(temp))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = input()

l=[]

for i in range(1,200000//2019+1):
    l.append(str(i*2019))
c=0
counter = [None] * 11
for L in range(11):
    counter[L] = Counter(s[i: i + L] for i in range(0, len(s) - L + 1))
answer = sum(counter[len(C)][C] for C in l)

print(answer)

Submission status: Wrong Answer

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

S = input()
l = len(S)

count = 0
for i in range(0, l-3):
  for j in range(3, l):
    if i < (j-3):
      new_s = int(S[i:j+1])
      if new_s % 2019 == 0:
        count += 1
      else:
        continue
    else:
      continue
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()

    simo5 = set()
    for i in range(5,1000001):
        s = str(2019*i)
        if '0' not in s:
            simo5.add(s[-5]+s[-4]+s[-3]+s[-2]+s[-1])

    l = len(S)
    ans = 0
    for i in range(l-1,3,-1):
        tmp = ''.join([S[i-4],S[i-3],S[i-2],S[i-1],S[i]])
        if tmp not in simo5:
            continue
        else:
            if int(tmp)%2019 == 0:
                ans += 1
            cnt = 0
            for j in range(i-5,-1,-1):
                tmp = ''.join([S[j],tmp])
                if int(tmp)%2019 == 0:
                    ans += 1
                cnt += 1
                if cnt == 20:
                    break
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
count = 0
for i in range(len(s)-4):
    if int(s[i] + s[i+1]) % 2 == 1:
        continue
    else:
        bai = int(s[i] + s[i+1]) // 2
        x = str(19*bai)
        len_x = len(x)
        if i + 1 + len_x < len(s):
            for k in range(1, len_x+1):
                if s[i+1 + k] != x[k-1]:
                    break
            else:
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans=0
mathlen=len(str(N))
strN=str(N)
i=0
while i<mathlen-1:
    j=i+1
    while j<mathlen+1:
        check=strN[i:j]
        if int(check)%2019==0:
            tobasi=len(check)-2
            #print(tobasi)
            i+=tobasi
            ans+=1
        j+=1
    #print(i)
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
nums = []
ans = 0

for i in range(4,len(S)):
    nums_tmp = [S[j: j+i] for j in range(len(S)-i)]
    nums.extend(nums_tmp)

for i in nums:
    if int(i) % 2019 == 0:
        ans += 1
    else:
        continue
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
l = [i*2019 for i in range(1,100)]
count = 0
for i in range(99):
    count += s.count(str(l[i]))
print(count)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = str(input())

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

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

print (count)

Submission status: Wrong Answer

Solution code:
from functools import lru_cache
@lru_cache()
def dfs(i):
    res = 0
    for j in range(5, 11):
        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 < 11211400000:
    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:
s = input().rstrip()

s_nums = list(range(len(s)+1))

ans = 0

li = [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 l in li:
  s_i = s.find(str(l))
  if s_i == -1:
    continue
  else:
    s_c = 0
    i = 0
    while s_i > -1:
      i += s_i+1
      s_c += 1
      s_i = s[i:].find(str(l))

    ans += s_c

print(ans)

Submission status: Wrong Answer

Solution code:


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

print(cnt)

Submission status: Wrong Answer

Solution code:
input_str = input()

output_cnt = 0
slice_size = 2019
to_i = len(input_str) - 3
for i in range(to_i):
  from_j = 3 + i
  to_j = min([len(input_str) + 1, from_j + 10])
  for j in range(from_j, to_j):
    sliced_value = int(input_str[i : j])
    if sliced_value % slice_size == 0:
      output_cnt += 1

print(output_cnt)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0
for i in range(len(s)):
    for j in range(len(s)):
        if j-i >= 3:
            ss = s[i:j+1]
            if int(ss) % 2 == 0:
                break
            if int(ss) % 2019 == 0:
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import re
multiplies = []

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

S = input()

count = 0

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

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

def check_2019(txt):
  amari = int(txt) % 2019
  if amari == 0:
    return True
  else:
    return False

N = len(S)

ans = 0

i = 0
j = i + 3

while(i <= N):
  j = i+1
  while(j <= N):
    if check_2019(S[i:j]):
      ans += 1
      i = j
      break
    j += 1
  i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    inputs = input()

    roop_num = len(inputs)
    if roop_num >= 100000:
        cnt = 0

    else:
        cnt = 0
        flag = False
        for start in range(roop_num-3):
            roop_num_end = roop_num - start
            ans_list = []
            ans_list = [int(inputs[start:end+start+4]) for end in range(roop_num_end-3) if int(inputs[start:end+start+4]) % 2019 == 0]

            cnt += len(ans_list)

    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

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

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

Submission status: Wrong Answer

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


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


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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = str(input())
    ans = 0
    for i in range(1, 200000):
        count = 2019*i
        if n.count(str(count)) != 0:
            ans += n.count(str(count))
    print(ans)

Submission status: Wrong Answer

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


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

print(ans)

Submission status: Wrong Answer

Solution code:

s = input()

count = 0

for h in range(2, len(s)):

    for i in range(h, len(s)):
        
        temp = ''

        # 各要素を足す
        for j in range(h, i + 1):
            temp = temp + s[j]

        if len(temp) >= 4 :
            temp = int(temp)

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

print(count)

Submission status: Wrong Answer

Solution code:
S=input()
N = len(S)
arr = []
ans = [0 for i in range(2020)]
cnt0 = 0
for i in range(N):
  a = int(S[N-i-1:N])%2019
  ans[a] += 1
  arr.append(a)
  if a == 0:
    cnt0 += 1

cnt = 0
for i in range(1,2020):
  if i < 1010:
    cnt += ans[i] * ans[2019-i]
  if ans[i] > 1:
    cnt = int(cnt + (ans[i]-1)*ans[i]/2)
  
cnt = int(cnt + (cnt0+1)*cnt0/2)
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
t = 2019
l = []
c = 0
while t <= 2 * (10**5):
    l.append(str(t))
    t += 2019
for i in range(len(l)):
    s_c = s
    pattern = l[i]
    while True:
        fd = s_c.find(pattern)
        if fd != -1:
            s_c = s_c[fd + 1:]
            c += 1
        else:
            break
print(c)

Submission status: Wrong Answer

Solution code:
s = input()

a = []
for i in range(1,101):
  a.append(str(i * 2019))
ans = 0
for i in a:
    count = s.count(i)
    ans += count
      
print(ans)

Submission status: Wrong Answer

Solution code:
def combinations_count(n):
  return n*(n-1)//2
s = input()
l = len(s)
lis = []
for i in reversed(range(l)):
  if i == l-1:
    lis.append(int(s[l-1])%2019)
    tem = int(s[l-1])
    tem2 = 1
  else:
    tem2 = (10*tem2)%2019
    kk = (int(s[i])*tem2+tem)%2019
    tem = kk
    lis.append(kk)
lis.append(0)
lis.sort()
ll = len(lis)
ans = 0
tem = 1
for i in range(1, ll):
  if lis[i-1] == lis[i]:
    tem += 1
  elif tem >= 2:
    ans += combinations_count(tem)
    tem = 1
print(ans)

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

Submission status: Wrong Answer

Solution code:
S=input()
N=len(S)
Cnt=0
for i in range(0,N-3):
    for j in range(i+3,i+3+3):
        if i+2>N+1:
            break
        if int(S[i:j])%2019==0:
            Cnt+=1
print(Cnt)

Submission status: Wrong Answer

Solution code:
S = input()

ans = 0
left = 0
while left < len(S):
    right = left + 1
    while right <= len(S) and int(S[left:right]) % 2019 != 0:
        right += 1
    if int(S[left:right]) % 2019 == 0:
        ans += 1
        left = right - 1
    else:
        left += 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):
      int_tgtS=int(S[i:j+1])
      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=input()
multiples = [2019*i for i in range(1, 100)]
length = len(s)
ans = 0
option = [4,5,6]
for leng in option:
    for i in range(length-leng+1):
        if int(s[i:i+leng]) in multiples:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
moji = input()
nagasa = len(moji)
counter = 0
for i in range(nagasa-4):
    for j in range(i+4,nagasa):
        suretsu = int(moji[i:j])
        if suretsu%2019 == 0:
            counter +=1
print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
for i in range(len(s)-4):
    if int(s[i:i+4]) % 2019 == 0:
        ans += 1
    if int(s[i:i+5]) % 2019 == 0:
        ans += 1
    if(i + 6 < len(s) ):
        if int(s[i:i+6]) % 2019 == 0:
            ans += 1
    if(i + 7 < len(s) ):
        if int(s[i:i+7]) % 2019 == 0:
            ans += 1
    if(i + 8 < len(s) ):
        if int(s[i:i+8]) % 2019 == 0:
            ans += 1
    if(i + 9 < len(s) ):
        if int(s[i:i+9]) % 2019 == 0:
            ans += 1
    if(i + 10 < len(s) ):
        if int(s[i:i+10]) % 2019 == 0:
            ans += 1
    if(i + 11 < len(s) ):
        if int(s[i:i+11]) % 2019 == 0:
            ans += 1
    if(i + 12 < len(s) ):
        if int(s[i:i+12]) % 2019 == 0:
            ans += 1
    if(i + 13 < len(s) ):
        if int(s[i:i+13]) % 2019 == 0:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def combinations_count(n):
  return n*(n-1)//2
s = input()
l = len(s)
print(l)
lis = []
for i in reversed(range(l)):
  if i == l-1:
    lis.append(int(s[l-1])%2019)
    tem = int(s[l-1])
    tem2 = 1
  else:
    tem2 = (10*tem2)%2019
    kk = (int(s[i])*tem2+tem)%2019
    tem = kk
    lis.append(kk)
lis.append(0)
lis.sort()
ll = len(lis)
ans = 0
tem = 1
for i in range(1, ll):
  if lis[i-1] == lis[i]:
    tem += 1
  elif tem >= 2:
    ans += combinations_count(tem)
    tem = 1
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import lru_cache

s = input()
s_len = len(s)
n = 2019
n_len = len(str(n))
result = 0
a = 202


@lru_cache(maxsize=128)
def reduce_number(s):
    left = int(s[:-1])
    right = a * int(s[-1])
    result = str(left + right)
    return result


@lru_cache(maxsize=128)
def is_multiple(s):
    _s = s
    while True:
        _s = reduce_number(_s)
        _s_int = int(_s)
        if _s_int == n:
            return True
        elif _s_int < n:
            return False


#for i in range(s_len - n_len):
i = 0
while i < s_len - n_len:
    for j in range(i + n_len, s_len + 1):
        m = s[i:j]
        if is_multiple(m):
            result += 1
            i += j - i - 2
            #i += 1
            break
    i += 1
print(result)

Submission status: Wrong Answer

Solution code:
S =input()
L = []
def count(text, part):
     return sum(text.startswith(part, i) for i in range(len(text)))
cnt=0
for i in range(1,99):
    L.append(str(i*2019))
for v in L:
    cnt+=count(S,v)
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
s = list(map(int,input()))
n = len(s)
ans = 0
mod = 2019
past = s[n-1]
ima = 0
d = dict()
d[s[n-1]] = 1
for i in range(1,n):
    ii = i
    now = 10
    aaa = 1
    while ii > 0:
        if ii%2 == 1:
            aaa = (aaa*now)%mod
        now = (now**2)%mod
        ii //= 2
    ima = (past+s[n-i-1]*aaa)%mod
    if ima == 0:
        ans += 1
    if ima in d:
        d[ima] += 1
    else:
        d[ima] = 1
    past = ima

for i in d.values():
    if i>1:
        ans += 2**(i-1)-1

print(ans)

Submission status: Wrong Answer

Solution code:
S=str(input())
ans=0
for i in range(1,20000):
    if str(2019*i) in S:
        ans+=S.count(str(2019*i))
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

def check_2019(txt):
  amari = int(txt) % 2019
  if amari == 0:
    return True
  else:
    return False

N = len(S)

ans = 0

i = 0
j = i + 3

while(i <= N):
  j = i + 3
  while(j <= N):
    if check_2019(S[i:j]):
      ans += 1
      i = j
      break
    j += 1
  i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    #s = input().rstrip().split(' ')
    s = input()
    numstr = [int(elem) for elem in s]
    ans = []

    mem = 0

    for i in range(len(numstr)):
        rest = 0
        for j in range(max(i,mem), len(numstr)):
            rest = (rest * 10 + numstr[j]) % 2019
            if rest == 0:
                ans.append((i,j))
                mem = j
                break

    count = 0
    temp = 0

    ans.append(('end', 'end'))

    for i in range(len(ans)-1):
        if (ans[i][1] + 1 == ans[i+1][0]):
            temp += 1
        else:
            count += int((temp+1)*(temp+2)/2)
            temp = 0

    print(count)

Submission status: Wrong Answer

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

if left >= 0:
    while right <= len(s):
        if int(s[left:right]) % 2019 == 0:
            # print(s[left:right])
            count += 1
            left = right - 1
            right = left + 4
        else:
            right += 1
print(count)

Submission status: Wrong Answer

Solution code:
import re
import sys

#A, B, C, D = list(map(int, input().strip().split()))
S = input()
#maximum = sys.maxsize
maximum = 10**3
A = [str(i * 2019) for i in range(maximum) if '0' not in str(i * 2019)]
ans = 0

for a in A:  
  pattern_ex = '(?=(' + a + '))'
  tmp = len(re.findall(pattern_ex, S))
  #if tmp != 0:
  #  print(a, tmp)
  ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
Flag = [0] * len(S)

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

flag = True
while flag:
    flag = False
    for i in range(len(S)):
        if not Flag[i]:
            continue
        if Flag[i]:
            if i + Flag[i] >= len(S):
                continue
            if Flag[i + Flag[i]]:
                Flag[i] = Flag[i + Flag[i]]
                ans += 1
                flag = True

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:
    for j in range(4,8):
        if i+j <= len(S):
            x = int(S[i:i+j])
            if x % 2019 == 0:
                if int(S[i:i+j]) != 0:
                    ls[i+j-1] += 1
                if i > 0:
                    ls[i+j-1] += ls[i-1]
                # if S[i+j-1] == '0' and i+j < len(S):
                #     ls[i+j] += ls[i+j-1]

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

print(count)

Submission status: Wrong Answer

Solution code:
s = [input() for i in range(1)] 
li = list(map(int, s[0].split()))
l = len(s[0])
count = 0
if l < 4:
    print(0)
else:
    if li[0] % 2019 == 0:
        count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
import sys
#wk
wk1=["12114",
"14133",
"16152",
"18171",
"24228",
"26247",
"28266",
"34323",
"36342",
"38361",
"42399",
"44418",
"46437",
"48456",
"52494",
"54513",
"56532",
"58551",
"62589",
"66627",
"68646",
"72684",
"76722",
"78741",
"82779",
"84798",
"86817",
"88836",
"92874",
"94893",
"96912",
"98931"
]
wk2=[
"119121",
"123159",
"125178",
"127197",
"129216",
"131235",
"133254",
"135273",
"137292",
"139311",
"143349",
"145368",
"147387",
"151425",
"153444",
"155463",
"157482",
"163539",
"165558",
"167577",
"169596",
"171615",
"173634",
"175653",
"177672",
"179691",
"183729",
"185748",
"187767",
"189786",
"193824",
"195843",
"197862",
"199881"
]
#s
s=[]
s=input()
cnt=0
ans=0
nagasa=len(s)

if len(s)<=4:
    print(0)
    sys.exit()
else:
    while(cnt+5<=nagasa):
        ans+=wk1.count(s[cnt:cnt+5])
        cnt+=1

    cnt=0
    while(cnt+6<=nagasa):
        ans+=wk2.count(s[cnt:cnt+6])
        cnt+=1

print(ans)

Submission status: Wrong Answer

Solution code:
a=input()
ans = 0

for i in range(len(a)):
        if int(a[i:i+5])%2019 == 0:
            ans += 1

print(ans)

Submission status: Wrong Answer

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

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

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

main()

Submission status: Wrong Answer

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

ans = 0
for i in range(N):
    for j in range(i + 5, N + 1):
        print(S[i:j])
        if int(S[i:j]) % 2019 == 0:
            ans += 1
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%2019)*10
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:
S = input().strip()
A = [0 for _ in range(len(S))]
A[0] = int(S[0])%3
for i in range(1,len(S)):
    A[i] = (A[i-1]+int(S[i]))%3
B = [0 for _ in range(len(S))]
B[0] = int(S[0])%673
for i in range(1,len(S)):
    B[i] = (B[i-1]+int(S[i]))%673
C = {}
for i in range(len(S)):
    a = A[i]
    b = B[i]
    if (a,b) not in C:
        C[(a,b)] = 0
    C[(a,b)] += 1
cnt = 0
for c in C:
    n = C[c]
    cnt += (n*(n-1))//2
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
keta = len(s)
ans = 0
mul = []

for i in range(100):
    if "0" in str(2019 * i):
        pass
    else:
        mul.append(str(2019 * i))

# for i in range(len(mul)):
#     for j in range(0, keta + 1 - len(str(mul[i]))):
#         if s[j : j + len(mul[i])] == mul[i]:
#             ans += 1


for j in range(0, keta + 1 - 5):
    if s[j : j + 5] in mul:
        ans += 1

print(ans)


# for i in range():

# print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = sys.stdin.readline().rstrip()
cnt = 0
def f(i, num):
  global cnt
  if int(n[i:i+num+1]) % 2019 == 0:
    cnt += 1
a = 0
b = 4
l = len(n)
while b <= l:
  while a <= l - b:
    f(a, b)
    a += 1
  b += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    S = input()

    simo5 = set()
    for i in range(5,1000001):
        s = str(2019*i)
        if '0' not in s:
            simo5.add(s[-5]+s[-4]+s[-3]+s[-2]+s[-1])

    l = len(S)
    ans = 0
    for i in range(l-1,3,-1):
        tmp = ''.join([S[i-4],S[i-3],S[i-2],S[i-1],S[i]])
        if tmp not in simo5:
            continue
        else:
            if int(tmp)%2019 == 0:
                ans += 1
            cnt = 0
            for j in range(i-5,-1,-1):
                tmp = ''.join([S[j],tmp])
                if int(tmp)%2019 == 0:
                    ans += 1
                cnt += 1
                if cnt == 50:
                    break
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def solve(n):

    ans = 0
    for i in range(1, 200000):
        count = 2019*i
        if n.count(str(count)) != 0:
            ans += n.count(str(count))
    return ans

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

Submission status: Wrong Answer

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

    print(count)

Submission status: Wrong Answer

Solution code:
S = list(input())
Count = 0
if len(S)<=4:
    print(0)
else:
    for w in range(5,10):
        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
S=sys.stdin.readline()
ans=0
for i in range(len(S)+1):
  for j in range(i+3,len(S)+1):
    #print(S[i:j])
    if int(S[i:j])%2019==0:
      #print(int(S[i:j]))
      ans+=1
    
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

def check_2019(txt):
  amari = int(txt) % 2019
  if amari == 0:
    return True
  else:
    return False

N = len(S)

ans = 0

i = 0
j = i + 3

while(i <= N-2):
  j = i + 3
  while(j <= N+1):
    if check_2019(S[i:j]):
      ans += 1
      i = j
      break
    j += 1
  i += 1

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, 1000000)]
for i in l:
    if i in s:
        same.append(i)
for i in same:
    m = s
    while True:
        idx = m.find(i)
        m = m[idx+1:]
        print(i, m)
        if idx==-1:
            break
        ans += 1
# print(l[-1])

print(ans)

Submission status: Wrong Answer

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

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

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

main()

Submission status: Wrong Answer

Solution code:
import sys
s = str(input())

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

if len(s) < 4:
    print(sum(cnt))
    sys.exit()

for i in range(len(s)-2):
    for j in range(i + 3, min(len(s), i+7)):
        if int(s[i:j+1]) % 2019 == 0:
            cnt[j] += cnt[i-1] + 1
else:
    print(sum(cnt))