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:
N = str(input())
N_len = len(N)
cnt = 0

t_list = []
tmp = 1

while tmp < 100:
    t_list.append(str(2019*tmp))
    tmp += 1

for t in t_list:
    for ind in range(len(N)):
        if N[ind:].startswith(t):
            # print(t)
            cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()
# print(S)

if int(S) < 2019:
    print(0)
    exit()

count = 0
i = 0
while i < len(S) - 3:
# for i in range(0, (len(S) - 3)):
    # print(i)
    found = False

    for j in range(i + 3, len(S)):
        number = int(S[i:j + 1])
        if number % 2019 == 0:
            # print(number, i, j)
            count += 1
            found = True
            break

    if found:
        i = j
    else:
        i += 1
        # break

print(count)

# for i in range(1, 101):
#     print(i, 2019 * i)

# 26247
# 2624
# 26247


# 1 2019
# 2 4038
# 3 6057
# 4 8076
# 5 10095
# 6 12114
# 7 14133
# 8 16152
# 9 18171
# 10 20190
# 11 22209
# 12 24228
# 13 26247
# 14 28266
# 15 30285
# 16 32304
# 17 34323
# 18 36342
# 19 38361
# 20 40380
# 21 42399
# 22 44418
# 23 46437
# 24 48456
# 25 50475
# 26 52494
# 27 54513
# 28 56532
# 29 58551
# 30 60570
# 31 62589
# 32 64608

Submission status: Wrong Answer

Solution code:
S = input()
kumi = 0
count_start = 0
answer = [2019,4038,6057,8076,10095,12114,14133,16152,18171]
while count_start <= len(S) - 4:
    count_end = 4
    while count_end <= len(S):
        if count_start + 2 < count_end:
            check = int(S[count_start:count_end])
            if check in answer:
                kumi += 1
        count_end += 1
    count_start += 1
print(kumi)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=input()
N=len(S)
dp=[0 for i in range(N)]
check=[0 for i in range(N)]

List=[]
moji = ''
kireme=False
for i in range(N):
    moji+=S[i]
    dp[i]=dp[i-1]
    if len(moji)==20:
        moji=moji[1:]
    l=len(moji)
    for j in range(l):
        if int(moji[l-j-1:])%2019==0:
            List.append((i-j,i,int(moji[l-j-1:])))
            check[i]+=1+check[i-j-1]
            dp[i]+=1
            """
            if check[max(i-j-1,0)]:
                #check[i-j-1]+=1
                dp[i]+=check[i-j-1]
            """
            
#print(List)
#print(check)
#print(dp) 
print(dp[N-1])

Submission status: Wrong Answer

Solution code:
S = input()

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

print(cnt)

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

Submission status: Wrong Answer

Solution code:
s=input()
k=673
ans = 0
dp=[[0 for _ in range(k)] for _ in range(len(s))]
dp[0][int(s[0])] = 1
for i in range(1,len(s)):
    t = int(s[i])
    dp[i][t] += 1
    for j in range(k):
        dp[i][((10*j)+t)%k] += dp[i-1][j]
        #dp[i][j] += dp[i-1][j]
    ans += dp[i][0]
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+j]+1
print(sum(list))

Submission status: Wrong Answer

Solution code:
#ABC 164D

def count(text, part):
    return sum(text.startswith(part, i) for i in range(len(text)))

#s = str(input())
#s = '1817181712114'
s = '14282668646'

cnt = 0

for i in range(0, 40):
    cnt += count(s, str(2019*i))

print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()

cnt = 0
for i in range(1,10000):
    tmp = str(i*2019)
    cnt += S.count(tmp)
    cnt += S.count(tmp+tmp[1:])
print(cnt)

Submission status: Wrong Answer

Solution code:
a, lists, count = str(input()), [], 0
for x in a:
    if x == '0':
        count += 1
for i in range(1, len(a)-3):
     lists.append(a[i]+a[i+1]+a[i+2]+a[i+3])
for i in range(1, len(a)-4):
    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4])
#for i in range(1, len(a)-5):
#    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5])
#for i in range(1, len(a)-6):
 #   lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5]+a[i+6])
#for i in range(1, len(a)-7):
 #   lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5]+a[i+6]+a[i+7])
for x in lists:
    if int(x) % 2019 == 0:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math
import functools
import bisect

s = input()
li = [0]
c = 2019
for i in range(1,110):
    li.append(c*i)
li.sort()
cnt = 0
cnt = s.count("0")
for i in range(len(s)-3):
    c = ""
    for j in range(4):
        c += s[i+j]
    if int(c) in li:
        cnt+=1
    
for i in range(len(s)-4):
    c = ""
    for j in range(5):
        c += s[i+j]
    if int(c) in li:
        cnt+=1
for i in range(len(s)-5):
    c = ""
    for j in range(6):
        c += s[i+j]
    if int(c) in li:
        cnt+=1
for i in range(len(s)-6):
    c = ""
    for j in range(7):
        c += s[i+j]
    if int(c) in li:
        cnt+=1
for i in range(len(s)-7):
    c = ""
    for j in range(8):
        c += s[i+j]
    if int(c) in li:
        cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

S = input()

count = 0


def ary():
    a = []
    i = 0
    while True:
        i += 2019
        if i >= 200000:
            break
        a.append(str(i))
    return a


l = ary()
for i in range(len(l)):
    s_count = S.count(l[i])
    count += s_count
    if s_count != 0 and S.count(l[i], S.index(l[i]) + 1):
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    S = int(input())
    SS = str(S)
    ls = len(SS)
    cnt = 0
    i = 0
    while i < ls - 3:
        for j in range(i + 4, ls + 1):
            if int(SS[i:j]) % 2019 == 0:
                cnt += 1
                i = j - 2
                break
        i+=1

    print(cnt)


resolve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

S = read_str()
l = len(S)

def solve():
    ans = 0
    i = 0
    while i < l - 3:
        for j in range(i + 4, l + 1):
            if int(S[i:j]) % 2019 == 0:
                ans += 1
                i += 2
        i += 1
    return ans

if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
s = input()
# list2019 = {i: [] for i in range(5, 11)}
# i = 2019*6
# while i < 1e10:
#     if all(str(i)!=0):
#         list2019[len(str(i))].append()
count = 0
if len(s) <= 4:
    print(0)
else:
    i = 0
    flag = 0
    flag_num = -1
    while i < len(s) - 4:
        j = i + 4
        digit_sum = sum(map(int, list(s[i:j]))) % 3
        mod = int(s[i:j]) % 673
        while j < len(s):
            now_sum = digit_sum + int(s[j]) % 3
            mod = (10*mod+int(s[j])) % 673
            if now_sum == 0 or now_sum == 3:
                if mod == 0:
                    count += 1 + flag
                    i = j
                    j = i + 3
                    flag += 1
                    flag_num = i+1
                    digit_sum = sum(map(int, list(s[i:i + 4]))) % 3
                    mod = int(s[i:i + 4]) % 673
            else:
                digit_sum = now_sum % 3
            j += 1
        i += 1
        if flag_num < i:
            flag = 0
    print(count)

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)-len(i)//2):
		if s[k:k+len(i)//2] == i[0:len(i)//2]:
			if  i == s[k:k+len(i)]:
				# print(i,s[k:k+len(i)])
				cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import re
S=input()

x=[i*2019 for i in range(1,1000)]


ans=0

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

print(ans)

Submission status: Wrong Answer

Solution code:
#import numpy as np#not for pypy

def main():
    ##get int
    #first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    first_input = input().split(" ")
    #second_input = input().split(" ")

    S = first_input[0]

    mod_2019 = []
    for i in range(len(S)):
        mod_2019.append(int(S[i:])%2019)

    count = 0
    for i in range(2019):
        Cn = mod_2019.count(i)
        count = count+Cn*(Cn-1)/2

    if int(count)==0:
        print("0")
    else:
        print(int(count)+1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def get_offset(S):
    for i in range(length - 3):
        for j in range(i+1, length+1):
            num = int(S[i:j])
            if num % 2019 == 0:
                return i+1, j
    return None, None

def get_offset2(S):
    for i in reversed(range(4, length)):
        for j in reversed(range(0, i-3)):
            num = int(S[j:i])
            if num % 2019 == 0:
                return j+1, i
    return None, None


S = input()

length = len(S)
ans = 0
head = tail = 0
domains = []

head, tail = get_offset(S)
if head != None:
    while tail <= length:
        offset = tail - head
        domains.append((head, tail))
        head += offset
        tail += offset


head, tail = get_offset2(S)
if head != None:
    while tail <= length:
        offset = tail - head
        domains.append((head, tail))
        head += offset
        tail += offset

#  print(domains)
ans = len(set(domains))
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
# S = '1817181712114'
# S = '14282668646'
# S= '2119'

cnt = 0
for i in range(len(S)):
    for length in range(4, len(S) - 4):
        window = S[i:i + length]
        if len(window) == length:
            if int(window) % 2019 == 0:
                # print('baisu found', int(window))
                cnt += 1

print(cnt)

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 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:
N = str(input())

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

count = 0
lenN = len(N)+1
for i in range(0, lenN):
    for j in range(i+4, 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:
import functools
def solve():
    s = int(input())
    t = [int(x) for x in list(str(s))]

    l = []
    for i in range(1, 600):
        num = [int(x) for x in list(str(i*2019))]
        if 0 not in num:
            l.append(num)

    cnt = 0
    n= len(t)
    for i in range(len(l)):
        m = len(l[i])
        for j in range(n-m+1):
            if l[i] == t[j:j+m]:
                    cnt += 1

    return cnt
    
print(solve())

Submission status: Wrong Answer

Solution code:
#A,B,C,D=map(int,input().split(" "))

mod=2019
a=input()

N=len(a)
t=[]
ans=0

for i in range(N-2):
  for j in range(i+3,N+1):
    u=int(a[i:j])
    print(u)
    if (u % mod)==0:
      ans+=1
      #print(i+1,j)
      break
print(ans)

Submission status: Wrong Answer

Solution code:
#d
N = str(input())
a = []
 
def func(string,p):
    count=0
    for x in range(len(string)-len(p)+1):
        if string[x:x+len(p)]==p:
            count+=1
    return count

def fun(a,b):
    ans=0
    for x in range(len(a)-b+1):
        if int(a[x:x+b])%2019==0:
            ans+=1
    return ans
 
for i in range(1,100):
    a.append(str(2019*i))
    
if len(N)<4:
    print(0)
else:
    ans=0
    for j in a:
        ans+=func(N,j)
    print(ans)

Submission status: Wrong Answer

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

for i in range(5):
    num5 = []
    sum_num = 0
    serict = 0
    j = 0
    while 5*(j+1)+i <= n:
        num = int(s[5*j+i:5*(j+1)+i])
        if num % 2019 == 0:
            num5.append(1)
        else:
            num5.append(0)
        j+=1
    # print(num5)
    for j in range(len(num5)):
        if num5[j] == 1:
            sum_num+=1
            serict+=1
        else:
            if serict > 1:
                sum_num += int(serict*(serict-1)/2)

            serict = 0
    
    if serict > 1:
        sum_num+= int(serict*(serict-1)/2)
    
    sum += sum_num

print(sum)

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 + 4

while(i <= N-2):
  j = i + 4
  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:
s = input()
si = int(s)
ans = 0


for i in range(200000//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:
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)-3):
    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))

Submission status: Wrong Answer

Solution code:
from math import log

s = input()
cnt = 0

found = []
l, r = 0, 0
cur = 0
while l < len(s):
    if r == len(s):
        r = l + 1
        l = l + 1
        cur = 0
        continue

    cur = cur * 10 + int(s[r])
    # print(s[l:r+1], cur)

    if cur % 2019 == 0:
        found.append((l, r))
        l = l + 1
        r = r + 1
        cur = cur - int(s[l - 1]) * (10 ** int(log(cur, 10)))
    else:
        r = r + 1

if found == []:
    cnt = 0
else:
    n = 1
    prev = found[0]
    for i in range(1, len(found)):
        if prev[1] == found[i][0] - 1:
            n += 1
        else:
            cnt += (n * (n + 1) // 2)
            n = 1
    cnt += (n * (n + 1) // 2)

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

S=input()
A=0

SL=list(S)
for i in range(len(SL)):
    SL[i]=int(SL[i])

SL_sum=SL.copy()
for i in range(1, len(SL_sum)):
    SL_sum[i] += SL_sum[i-1]
#SL_sum=np.array(SL_sum)
    
while len(S)>3:
    print(SL_sum)
    for i in range(len(SL_sum)):
        if SL_sum[i]%3 == 0 :
            if int(S[:i+1])%673 ==0 :
                A+=1
    S=S[1:]
    SL_sum=(np.array(SL_sum)-SL_sum[0]).tolist()
    SL_sum=SL_sum[1:]
    SL=SL[1:]
    
print(A)

Submission status: Wrong Answer

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

l = [str(i * 2019) for i in range(1, 1000)]
l.sort()

end = [-1] * N


from bisect import *


for i in range(N):
    for j in range(i + 4, i + 8):
        if j > N:
            break

        # print(bisect_left(l, S[i:j]))


        index = bisect_left(l, S[i:j])
        if 0 <= index < len(l) and l[index] == S[i:j]:

            # にぶたんで

            # if S[i:j] in l:
            end[i] = j
            break


ans = 0

# print(end)

for i in range(N):
    a = 1
    j = end[i]
    while j != -1:
        a += 1
        if j == N:
            break
        j, end[j] = end[j], -1

    ans += a * (a - 1) // 2

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:
    if int(S[i]) != 0 or int(S[i:i + 4]) == 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+4]) != 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()

cnt = 0
d = []
for i in range(1,1000):
    tmp = str(i*2019)
    cnt += S.count(tmp)
    cnt += S.count(tmp+tmp[1:])
print(cnt)

Submission status: Wrong Answer

Solution code:
S = str(input())
S_int = int(S)

count = 0
  
if S_int < 2019:
  print(0)
else:
  for i in range(len(S)-3):
    for j in range(i+4,len(S)+1):
      test = S[i:j]
      test_int = int(test)
      if test_int % 2019 == 0:
        count = count + 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

def search(n):
    l = 0
    r = len(arr) - 1
    while r - l > 1:
        c = (l + r) // 2
        if arr[c] > n:
            r = c
        elif arr[c] < n:
            l = c
        else:
            return True
    if arr[l] == n or arr[r] == n:
        return True
    return False

s = STR()
l = len(s)

arr = [2019 * i for i in range(1, 10001)]
arr.sort()
arr2 = [0 for _ in range((l))]
for i in range(3, l):
    for j in range(3, 8):
        if i - j >= 0 and search(int(s[i - j:i + 1])):
            arr2[i] = arr2[i - j - 1] + 1 if i - j - 1 >= 0 else 1
            break
ans = sum(arr2)
print(ans)

Submission status: Wrong Answer

Solution code:
N = str(input())

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

count = 0
lenN = len(N)+1
for i in range(0, lenN):
    for j in range(i+5, 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:
import sys
S = input()
N = len(S)

if N < 5:
    sys.exit()

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:
s = str(input())

#ans = 0
#for i in range(len(s)):
#    for j in range(i+1,len(s)+1):
#        num = int(s[i:j])
#        #print(num)
#        if num% 2019 == 0:
#            #print(num)
#            ans += 1

#def Base_10_to_n(X, n):
#    X_dumy = X
#    out = ''
#    while X_dumy>0:
#        out = str(X_dumy%n)+out
#        X_dumy = int(X_dumy/n)
#    return out

#print(2019*2019)
#for i in range(6,50000):
#    print(2019*i)
#x2 = Base_10_to_n(int(s), 2)
#print(x2)

#x3 = Base_10_to_n(int(s), 3)
#print(x3)
#x673 = Base_10_to_n(int(s), 673)
#print(x673)
#x2019 = Base_10_to_n(int(s), 2019)
#print(x2019)
#x2019 = Base_10_to_n(int(s), 2019)
#print(x2019)
tmp_num = 0
tmp = ''
ans_2 = 0

while ans_2 == 0:
    tmp = ''
    for i in range(tmp_num,len(s)):
        tmp += s[i]
        #print(tmp)
        if int(tmp) % 2019 == 0:
            #print('割り切れた')
            #print(tmp)
            ans_2 += 1
            tmp = s[i]
    
    tmp_num += 1

    if tmp_num == len(s):
        break


#print(ans)

print(ans_2)

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()
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:
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
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 numpy as np
import math

s = input()

# print(s)

ans = np.zeros((len(s)), dtype = np.int)

# print(ans)

if len(s) >= 4:
  for i in range (0, len(s) - 3):
    for j in range (i + 3, len(s)):
      num = int(s[i:j+1])
      bnum = int(s[:j+1])
      if math.gcd(num, bnum) != 1:
        # print(num)
        if num % 2019 == 0:
          ans[i] += 1

# print(ans)

print(np.sum(ans))

Submission status: Wrong Answer

Solution code:
import functools
def solve():
    s = int(input())
    t = [int(x) for x in list(str(s))]

    l = []
    for i in range(1, 300):
        num = [int(x) for x in list(str(i*2019))]
        if 0 not in num:
            l.append(num)

    cnt = 0
    n= len(t)
    for i in range(len(l)):
        m = len(l[i])
        for j in range(n-m+1):
            if l[i] == t[j:j+m]:
                    cnt += 1

    return cnt
    
print(solve())

Submission status: Wrong Answer

Solution code:
S = input()
l = len(S)
ans=0
for i in range(l-4):
    for j in range(i+4,i+10):
        m = int(S[i:j])
        if m%673 ==0:
            if m%3 ==0:
                ans+=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 == 10:
                    break
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a, lists, count = str(input()), [], 0
for x in a:
    if x == '0':
        count += 1
for i in range(1, len(a)-3):
     lists.append(a[i]+a[i+1]+a[i+2]+a[i+3])
for i in range(1, len(a)-4):
    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4])
for i in range(1, len(a)-5):
    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5])
for i in range(1, len(a)-6):
    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5]+a[i+6])
for i in range(1, len(a)-7):
    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5]+a[i+6]+a[i+7])
for x in lists:
    if int(x) % 2019 == 0:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
i, j = 0, len(s)-1
cnt = 0
while i < j:
    num = int(s[i:j+1])
    if num % 2019 == 0:
        cnt += 1
        j = i
        i = 0
    else:
        i += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = str(input())

i = 0
def dfs(st, ed):
    global i
    bonus = 0
    while ed <= num:
        if len(n[st:ed]) > 8:
            break
        elif int(n[st:ed]) % 2019 == 0:
            i += 1 + bonus
            st = ed + 1
            ed = ed + 4
            bonus +=1
        ed += 1

num = len(n)
for _ in range(num):
    if _ + 5 <= num:
        dfs(_, _+5)
    else:
        break
print(i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
ls = []
for i in range(0, len(S)):
    ls.append(S[i:i+4])
    ls.append(S[i:i+5])
x = []
for i in ls:
    if len(i) >= 4:
        x.append(int(i))
a = 0
for i in x:
    if i % 2019 == 0:
        a += 1
print(a)

Submission status: Wrong Answer

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math
import functools
import bisect

s = input()
li = [0]
c = 2019
for i in range(1,110):
    li.append(c*i)
li.sort()
cnt = 0
cnt = s.count("0")
for i in range(len(s)-3):
    c = ""
    for j in range(4):
        c += s[i+j]
    if int(c) in li:
        cnt+=1
    
for i in range(len(s)-4):
    c = ""
    for j in range(5):
        c += s[i+j]
    if int(c) in li:
        cnt+=1
for i in range(len(s)-5):
    c = ""
    for j in range(6):
        c += s[i+j]
    if int(c) in li:
        cnt+=1
for i in range(len(s)-6):
    c = ""
    for j in range(7):
        c += s[i+j]
    if int(c) in li:
        cnt+=1
for i in range(len(s)-7):
    c = ""
    for j in range(8):
        c += s[i+j]
    if int(c) in li:
        cnt+=1
for i in range(len(s)-8):
    c = ""
    for j in range(9):
        c += s[i+j]
    if int(c) in li:
        cnt+=1
print(cnt)

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))]
    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:
        if c == 0:
            ans += 1
        ans += (s[c]) * (s[c] - 1) // 2
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import functools
def solve():
    s = int(input())
    t = [int(x) for x in list(str(s))]

    l = []
    for i in range(1, 150):
        num = [int(x) for x in list(str(i*2019))]
        if 0 not in num:
            l.append(num)

    cnt = 0
    n= len(t)
    for i in range(len(l)):
        m = len(l[i])
        for j in range(n-m+1):
            if l[i] == t[j:j+m]:
                    cnt += 1

    return cnt
    
print(solve())

Submission status: Wrong Answer

Solution code:
S = list(input())
Count = 0
if len(S)<=4:
    print(0)
else:
    for w in range(5,len(S)+1):
        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:
S = input()
l = len(S)
ans=0
for i in range(l-4):
    for j in range(i+4,i+8):
        m = int(S[i:j])
        if m%673 ==0:
            if m%3 ==0:
                ans+=1
print(ans)

Submission status: Wrong Answer

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

c=0
d =0
S = input()
len_s = len(S)
for i in range(len_s-3):
    for j in range(len_s-i-3):
        s = int(S[j:])
        if s%2019 ==0:
            c +=1
            if i == 0:
                d = 1
        else:
            pass

    S = S[:len_s-i]

print(c-d)

Submission status: Wrong Answer

Solution code:
s = input()
len_s = len(s)

ans = 0
i = 0
l = 0

while True:
    l += 1
    for y in range(i, len_s):
        if int(s[i:y+1]) % 2019 == 0:
            ans += 1
            i = y
            l = y
            break
    else:
        i += 1
    if l >= len_s:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
S = str(input())

count = 0
for i in range(0, len(S)):
    for j in range(i+4, len(S)+1):
        s = int(S[i:j])
        if s > 200000:
            break
        if s % 2019 == 0:
            count += 1

print(count)

Submission status: Wrong Answer

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

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

l=len(list)
res=0
j=0

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

Submission status: Wrong Answer

Solution code:
a = input()
b = 0
if int(a) < 2019:
    print(0)
else:
    for i in range(len(a)-3):
        c = a
        if int(c) % 2019 == 0:
            b += 1
        for j in range(len(a)-4):
            c = a[:-j-1]
            if int(c) % 2019 == 0:
                b += 1
        a = a[1:]
print(b)