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:
num = input()
counter = 0
for i in range(len(num) - 4):
    for k in range(i + 4, len(num)):
        if int(num[i:k]) % 2019 == 0:
            counter += 1
print(counter + 1)

Submission status: Wrong Answer

Solution code:
s = list(input())
n = len(s)

c = 0
for i in range(n-4):
  t = ''
  for j in range(i,n):
    t = t + s[j]
    k = int(t)
    if k%2019 == 0:
      print(i,j,k)
      i = j-1
      
      c += 1
      
print(c)

Submission status: Wrong Answer

Solution code:

def main():
    S = input()
    # S = '1817181712114'

    isFinish = False
    count = 0
    
    bar = 0
    while not isFinish:
        isPath = False
        for j in range(bar+1, len(S)+1):
            # print(bar, j, int(S[bar:j]))
            t = int(S[bar:j]) % 2019

            if t == 0.0:
                # print('OK:', bar, j, int(S[bar:j]))
                bar = j-1
                count += 1
                isPath = True
                break
        if isPath == False:
            bar += 1
        # print(bar)
        if bar >= len(S)-2:
            isFinish = True
            break
    print(count)
        

main()

Submission status: Wrong Answer

Solution code:
def get_offset(S):
    result = []
    for i in range(length):
        for j in range(i+1, length):
            num = int(S[i:j])
            if num % 2019 == 0:
                has_found = True
                return i+1, j
    print(0)
    exit(0)

S = input()
length = len(S)

head, tail = get_offset(S)

ans = 0
offset = tail - head
ans += (length - head) // offset

print(ans)

Submission status: Wrong Answer

Solution code:
str=input("")
count=0;

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

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
    for i in range(len(str(s))):
        for j in range(i+1, len(str(s))+1):
            tmp = s[i:j]
            if int(tmp) == t:
                print(t)
                c += 1


print(c)

Submission status: Wrong Answer

Solution code:
# 2019 = 3 * 673
# pow(10,671,673) = 202

S = input()
X = [[0]*1000 for _ in range(3)]
X[0][0] = 1
tmp = 0
ttmp = 0
p = 1
for c in S:
    tmp = (tmp*10 + int(c))%673
    ttmp = (ttmp+int(c))%3
    X[ttmp][(tmp*p)%673] += 1
    p = (p*202)%673

ans = 0

for i in X:
    for j in i:
        if j >= 2:
            ans += j-1

print(ans)

Submission status: Wrong Answer

Solution code:
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = collections.Counter(l)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))

c = 0
s =input()
l = len(s)

if l < 4:
	print(0)
else:
	for i in range(l-3):
		for j in range(3,l-3):
			if int(s[i:i+j])%2019==0:
				c+=1
				break
print(c)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
right = n-1
ans = 0

def count(s,i):
    counta = 0
    for left in range(n-i-3):
        k = int(s[left:n-i+1])
        print("k:",k)
        if k%2019==0:
            counta += 1
            print("plus")
    return counta


for i in range(2,n-2):
    ans += count(s,i-1)
print(ans)

Submission status: Wrong Answer

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

list_2019 = [str(n * 2019) for n in range(1, 100)]

count = 0
for s in list_2019:
    if s in S:
        for i in range(N):
            if s in S[i:]:
                if S[i:i + len(s)] == s:
                    count += 1
            else:
                break
            

print(count)

Submission status: Wrong Answer

Solution code:
S = input()

start = 0

result = 0
while start <= (len(S) - 4):
    if int(S[start:start+4]) % 2019 == 0:
        result = result + 1
        start = start + 3
        continue

    if int(S[start:start+5]) % 2019 == 0:
        result = result + 1
        start = start + 4
        continue

    start = start + 1
    continue

print(result)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
total = 0
bais = ['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 i in bais:
    total += s.count(i)

print(total)

Submission status: Wrong Answer

Solution code:
s=input()
b=0
m=len(s)
c=0
for i in range(m-1,2,-1):
    a=s[i-2]+s[i-1]+s[i]
    for j in range(i-3,-1,-1):
        # if c==1 and int(s[j])%3!=0:
        #     c=0
        #     continue
        a=str(a)
        a=int(s[j]+a)
        # print(a)
        # c=0
        # if a%3!=0:
        #     continue
        # c=1
        if a%2019==0:
            # print(b)
            b+=1
            break
        if len(str(a))>=6:
            break

print(b)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
ans=0
ls=len(s)
if ls>=4:
  s1=[s[i:i+4] for i in range(ls-3)]
  s2=[s[i:i+5] for i in range(ls-4)]
  l1=[2019, 4038, 6057, 8076]
  l2=[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 i in l1:
    ans += s1.count(str(i))
  for i in l2:
    ans += s2.count(str(i))
print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    count = 0
    while i < N - 2:
        for j in range(i+2,N+1):
            if int(S[i:j]) % 2019 == 0:
                count += 1
                break
        i = j - 1
    if count > 0:
        break

print(count)

Submission status: Wrong Answer

Solution code:
s=input()
count=0
Num=0
for n in range(len(s)-3):
    for m in range(len(s)-n-3):
        ss=s[n:n+m+4]
        ss.lstrip("0")
        Num=int(ss)
        print(Num)
        if Num % 2019==0:
            count=count+1
            print("Hit!")
print(count)

Submission status: Wrong Answer

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

a = 0
count = 0

for i in range(l):
    a = int(S[l-i-1])
    for j in range(i+1,l):
        if int(S[l-j-1]) != 0:
            a += int(S[l-j-1])*10**(j-i)
            if j-i > 2:
                print(a)
                if a != 0 and a % 2019 == 0:
                    count += 1
            
print(count)

Submission status: Wrong Answer

Solution code:

S=str(input())
ans=0
list_2019=[]


for i in range(1,10**6):
    list_2019.append(i*2019)

for i in list_2019:
    ans=ans+S.count(str(i))

print(ans)

Submission status: Wrong Answer

Solution code:
S = str(input())

baisu = [str(2019 * i) for i in range(1, 99)]

cnt=0
for i in baisu:
    if i in S:
        for j in range(0, len(S)-len(i)+1):
            # print([S[j:j+len(i)]])
            if i==[S[j:j+len(i)]][0]:
                cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
def f(s):
    pl = [str(2019*i) for i in range(1,51000) if "0" not in str(2019*i)]
    res = 0
    for p in pl:
        start = 0
        pos = s.find(p, start)
        while pos>=0:
            res += 1
            start = pos + 1
            pos = s.find(p, start)
    return res

if __name__ == "__main__":
    # from string import digits
    # from random import randint
    # import time
    # s = "".join([digits[randint(1,9)] for _ in range(200000)])
    # start = time.time()
    # print(f(s))
    # print(time.time()-start)
    print(f(input()))

Submission status: Wrong Answer

Solution code:
import sys
# sys.stdin = open('input.txt')

s = input()
ans = 0

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

Submission status: Wrong Answer

Solution code:
s = input()
four_list = set()
five_list = set()
six_list = set()

a = 1
while True:
    check_int = 2019 * a
    if check_int > 200000:
        break
    str_len = len(str(check_int))
    if str_len == 4:
        four_list.add(str(check_int))
    elif str_len == 5:
        five_list.add(str(check_int))
    elif str_len == 6:
        six_list.add(str(check_int))
    a += 1
"""
print(four_list)
print(five_list)
print(six_list)
"""
if len(s) <= 3:
    print(0)
    exit()

result_sum = 0
for i in range(len(s)-3):
    # print(s[i:4+i])
    if s[i:4+i] in four_list:
        result_sum += 1

if len(s) <= 4:
    print(result_sum)
    exit()

for i in range(len(s)-4):
    if s[i:5+i] in five_list:
        result_sum += 1

if len(s) <= 5:
    print(result_sum)
    exit()

for i in range(len(s)-5):
    if s[i:6+i] in four_list:
        result_sum += 1

print(result_sum)

Submission status: Wrong Answer

Solution code:
s=input()
lis=[]
for i in range(1,500):
    if '0' in str(2019*i):
        pass
    else:
        lis.append(2019*i)
        
ngram=[]
for i in range(5,7):
    l=[]
    for j in range(len(s)-i+1):
        l.append(s[j:j+i])
    ngram.append(l)
    
print(ngram)

ans=0
for i in lis:
    ans+=ngram[len(str(i))-5].count(str(i))
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
count = 0
try:
    for i in range(0, len(S) - 3):
        if len(S[i:]) <= 4:
            break
        for l in range(i + 3, len(S)):
            if int(S[i]) == 0:
                continue
            elif int(S[i:l]) % 2019 == 0:
                count += 1
except IndexError:
    pass
print(count)

Submission status: Wrong Answer

Solution code:
inp = input()

s = 0

for i in range(len(inp)-3):
	num = int(inp[i:])
	while num > 2019:
		print(num)
		if num % 2019 == 0:
			s += 1
		num = num // 10

print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
i = 0

while i < len_s-3:
    for y in range(i+3, len_s+1):
        if int(s[i:y+1]) % 2019 == 0:
            ans += 1
            i = y
            break
        if y+1 == len_s:
            i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
count = 0
for i in range(len(S)):
  for j in range(i+1,i+7):
    if int(S[i:j]) % 2019 == 0:
      count = count + 1
      if j >= len(S):
        break
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ans=0
for i in range(len(s)+1):
    for j in range(i + 1, len(s)+1):
        if int(s[i:j]) % 2019 == 0:
            ans += 1
            print(s[i:j])
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)==9:
        moji=moji[1:]
    l=len(moji)
    for j in range(l):
        if int(moji[l-j-1:])%2019==0:
            List.append((i-j,i))
            check[i]+=1
            dp[i]+=1
            if check[i-j-1]==1:
                dp[i]+=dp[i-j-1]
            
#print(List)
#print(check)
#print(dp) 
print(dp[N-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = str(input())
l = [2019]*10**5
count = 0
for i in range(10**5):
  l[i] *= (i+1)
for j in range(10**5):
  if str(l[j]) in S:
    count += 1
print(count)

Submission status: Wrong Answer

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


memo = {}


def cmb(n, r):
    if (n, r) in memo:
        return memo[(n, r)]
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    memo[(n, r)] = over // under
    return over // under


s = input()[::-1]
acc = [int(s[0])]
cntr = defaultdict(int)
for i, c in enumerate(s[1:], 1):
    if c == '0':
        continue
    next_mod = (acc[-1] + pow(10, i, 2019) * int(c)) % 2019
    cntr[next_mod] += 1
    acc.append(next_mod)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

baisu = [str(2019 * m) for m in range(1, 99)]

# print(baisu)

cnt = 0
for b in baisu:
    # 開始位置
    s = 0
    while True:
        # 見つけた位置
        pos = S.find(b, s)
        if pos > -1:
            # 次の開始位置を1文字後にする
            s = pos + 1
            cnt += 1
        else:
            break

print(cnt)

Submission status: Wrong Answer

Solution code:
A=list(input())
ans=0
s=set()
for i in range(len(A)-1):
  for j in range(i+1,len(A)):
    if sum(map(int,A[i:j+1]))%3!=0:
      continue
    r=int("".join(A[i:j+1]))
    if r in s:
      ans+=1
    if r%2019==0:
      ans+=1
      s.add(r)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    ret = 0
    for s in range(len(S)-4):
        if int(S[s:s+5]) % 2019 == 0:
            ret += 1
    for s in range(len(S)-3):
        if len(S) < s+6: break
        if int(S[s:s+6]) % 2019 == 0:
            ret += 1
    for s in range(len(S)-2):
        if len(S) < s + 7: break
        if int(S[s:s+7]) % 2019 == 0:
            ret += 1
    for s in range(len(S)-1):
        if len(S) < s + 8: break
        if int(S[s:s+8]) % 2019 == 0:
            ret += 1
    for s in range(len(S)):
        if len(S) < s + 9: break
        if int(S[s:s+9]) % 2019 == 0:
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = list(input())  #文字列の一文字ずつリストに

nums = []

for i in range(1,200000 // 2019 + 1):
    nums.append(2019*i)
        
print(nums)

ans = 0
for j in range(len(S) - 4):
    for i in range(4, len(S) + 1 - j):
#        print(j,j + i)
#        print(S[j:j + i])
        A = (''.join(S[j: j + i]))
        #print(A)
        if int(A) in nums:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
length = len(s)
n=int(s)
ans=0
if(length<4):
    print(0)
else:
    for i in range(length-3):
        for j in range(i+3,length):
            num=(n%10**(length-i-1))//10**j
            if num%2019==0:
                ans+=1
                break
    print(ans)

Submission status: Wrong Answer

Solution code:
import re
S = input()
num = 2019
i = 1
ans = 0
while num*i <= 2000000:
    ans += len(re.findall(f'(?=({str(num*i)}))', str(S)))
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

count = 0
i = 0

while i < len(S) - 3:
    done = False
    for j in range(i + 1, len(S) + 1):
        if int(S[i:j]) % 2019 == 0:
            count += 1
            i = j - 1
            break
        if j == len(S):
            done = True
    if done:
        i += 1

print(count)

Submission status: Wrong Answer

Solution code:
s=input()
a=0
b=''

for i in range(len(s)-4):
    b+=(s[i]+s[i+1]+s[i+2]+s[i+3])
    for j in range(i+4,i+5):
        b+=s[j]
        if int(b)%2019==0:
            a+=1
        
    b=''
    
        
print(a)

Submission status: Wrong Answer

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

s = input().rstrip()
n = len(s)
ranges = []
g = [[] for _ in range(n + 1)]
ans = 0

for i in range(n):
    for j in range(i + 3, i + 7):
        if j >= n:
            continue
        s_ = s[i:j + 1]
        if int(s_) % 2019 == 0:
            ranges.append([i, j + 1])
            g[i].append(j + 1)

visited = set()
ans = 0

for i in range(n):
    if i in visited or len(g[i]) == 0:
        continue
    visited.add(i)
    d = 1
    while True:
        i = g[i][0]
        if len(g[i]) == 0:
            ans += (1 + d) * d // 2
            break
        else:
            d += 1
            visited.add(i)

print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
S = input()
cum = []
for i in range(len(S)-1, -1, -1):
    n = int(S)
    n = n % 10**(i+1)
    cum.append(n % 2019)
print(cum)
cum = sorted(cum)
print(cum)
prev = cum[0]
ans = 0
cnt = 0
for c in cum:
    if c != prev:
        if prev == 0:
            ans += cnt
        ans += cnt * (cnt-1) // 2
        cnt = 1
    else:
        cnt += 1
    prev = c

if cnt > 1:
    if prev == 0:
        ans += cnt
    ans += cnt * (cnt-1) // 2
    cnt = 1

print(ans)

Submission status: Wrong Answer

Solution code:
# 2019 = 3 * 672
# pow(10,670,672) = 202

S = input()
X = [[0]*1000 for _ in range(3)]
X[0][0] = 1
tmp = 0
ttmp = 0
p = 1
for c in S:
    tmp = (tmp*10 + int(c))%672
    ttmp = (ttmp+int(c))%3
    X[ttmp][(tmp*p)%672] += 1
    p = (p*202)%672

ans = 0

for i in X:
    for j in i:
        if j >= 2:
            ans += j-1

print(ans)

Submission status: Wrong Answer

Solution code:
# python 3.8.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
from math import gcd
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def lcm(a,b):return (a*b) // gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

S = input()

MAX = 200000

iv = 2019
multiple = {}
multiple[len(str(iv))] = set()
multiple[len(str(iv))].add(str(iv))
cnt = 2
while True:
    tmp = iv * cnt
    if tmp <= MAX:
        if len(str(tmp)) not in multiple.keys():
            multiple[len(str(tmp))] = set()
        multiple[len(str(tmp))].add(str(tmp))
        cnt += 1
    else:
        break
ans = 0

for k, v in multiple.items():
    for i in range(len(S)):
        if i+k < len(S)+1:
            if S[i:i+k] in v:
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
x = 2019
check = []
while x < 200000:
    check.append(str(x))
    x += 2019

s = input()

ans = 0
for m in check:
    if m[0] == m[-1]:
        cnt = s.count(m[1:])
        for i in range(cnt, 0, -1):
            m_new = m[0] + m[1:] * cnt
            tmp = s.count(m_new)
            if tmp > 0:
                ans += tmp * cnt
                break
    else:
        ans += s.count(m)
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
slice_num=4
cnt=0
if int(s)<2019:
    print(0)
while slice_num < 7:
    for i in range(0,len(s)-slice_num+1):
        if(int(s[i:i+slice_num])%2019==0 and int(s[i:i+slice_num]) <=200000):
            cnt+=1
    slice_num+=1
print(cnt)

Submission status: Wrong Answer

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

ans=0

for i in range(n):
  for j in range(i+3,n):
    s_ans=s[i:j+1]
    s_ans=int("".join(s_ans))
    print(s_ans)
    if s_ans%2019==0:
      ans+=1
      
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
target_list = []
itr = 2019
i = 1
for i in range(1, 200000):
    tmp = i * itr
    if tmp > 200000:
        break
    else:
        target_list.append(tmp)
    
def print_ans(S):
    """Test Case
    >>> print_ans('1817181712114')
    3
    >>> print_ans('14282668646')
    2
    >>> print_ans('2119')
    0
    """
    ans = 0
    if len(S) <= 3:
        print(0)
    else:
        for i in range(len(S)):
            for j in range(i + 2, len(S)):
                tmp = S[i:j+1]
                if len(tmp) >= 7:
                    break
                if int(tmp) in target_list:
                    ans = ans + 1
        print(ans)
            
            

if __name__ == '__main__':
    S = input().rstrip()
    print_ans(S)

Submission status: Wrong Answer

Solution code:
s=input()
ans=0
ls=len(s)
if ls>4:
  s1=[s[i:i+4] for i in range(ls-3)]
  s2=[s[i:i+5] for i in range(ls-4)]
  l1=[2019, 4038, 6057, 8076]
  l2=[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 i in l1:
    ans += s1.count(str(i))
  for i in l2:
    ans += s2.count(str(i))
print(ans)

Submission status: Wrong Answer

Solution code:
import re

S = input()

candidates = []
s = 2019
i = 1
result = 0

while s * i <= 200000:
    candidates.append(str(i*s))
    i += 1

for c in candidates:
    start = 0
    while True:
        temp = S.find(c, start)
        if temp == -1:
            break
        else:
            result += 1
            start = temp+1

print(result)

Submission status: Wrong Answer

Solution code:
# import math
# import numpy as np
# import itertools
# import heapq
# =map(int,input().split())
a=input()
n=len(a)
ans=0
# for i in range(n-4):
#     for j in range(i+4,n):
#         x=a[i:j+1]
#         v=int(x)
#         if v%2019==0:
#             ans+=1
            # print(v)
x=200000//2019
for i in range(1,x+1):
    q=2019*i
    w=str(q)
    count = sum([a[k:k+len(w)]==w for k in range(0, n-len(w)+1)])
    ans+=count
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    N = len(S)
    ans = 0
    right = N
    left = N-4
    while 0 <= left:
        v = int(S[left:right])
        while 0 < left and v % 2019 != 0:
            left -= 1
            v = int(S[left:right])
        if v % 2019 == 0:
            ans += 1
        right = left + 1
        left = right - 4
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
inls = [str(2019*i) for i in range(1,101)]
ans = 0
def counts(text, part):
    return sum(text.startswith(part, i) for i in range(len(text)))
for j in range(len(inls)):
    ans += counts(s, inls[j])
print(ans)

Submission status: Wrong Answer

Solution code:
#d
N = int(input())
s  = str(N)
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

for i in range(1,1000):
    a.append(str(2019*i))
if len(s)<4:
    print(0)
else:
    ans=0
    for j in a:
        ans+=func(s,j)
    print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
i=0
j=1
count=0
while i<j and i<len(n)-1:
    
    if int(n[i:j+1])%2019==0:
        #print(n[i:j+1])
        count+=1
        i+=1
        if j==len(n)-1:
            i+=1
            j=i+1
        else:
            j+=1
    else:
        if j==len(n)-1:
            i+=1
            j=i+1
        else:
            j=j+1
print(count)

Submission status: Wrong Answer

Solution code:
import sys

s = str(input())
tisa = []
for i in range(1,100):
  tisa.append(str(2019*i))
#ok
#print(s)
#print(tisa)
ans = 0
for c in tisa:
  ans += s.count(c)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

L = len(S)
d = 1
M = 0
ans = 0
while d <= 10 ** 100:
    if '0' in str(d):
        d *= 2019
        continue
    ds = str(d)
    l = len(ds)
    for i in range(L - l):
        if S[i:i + l] == ds:
            ans += 1
    d *= 2019
print(ans)

Submission status: Wrong Answer

Solution code:
def power_func(a,n,p):
    bi=str(format(n,"b"))
    res=1
    for i in range(len(bi)):
        res=(res*res) %p
        if bi[i]=="1":
            res=(res*a) %p
    return res



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

print(ans)

Submission status: Wrong Answer

Solution code:
s = int(input())
x = str(s)
n = len(x)
a = list("")
c = 0
for i in range(1, 100):
    a.append(str(2019 * i))
for i in range(n - 3):
    if x[i : i + 4] in a:
        c += 1
for i in range(n - 4):
    if x[i : i + 5] in a:
        c += 1
for i in range(n - 5):
    if x[i : i + 6] in a:
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:
num=input()
counter=0
for y in range(len(num)):
  for x in range(y):
    if int(num[x:y])%2019==0:
      counter=counter+1
print(counter)

Submission status: Wrong Answer

Solution code:
#d
N = int(input())
s  = str(N)
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

for i in range(1,100):
    a.append(str(2019*i))
if len(s)<4:
    print(0)
else:
    ans=0
    for j in a:
        ans+=func(s,j)
    print(ans)

Submission status: Wrong Answer

Solution code:
def sol():
    s = input()
    ans = 0
    for i in range(len(s)):
        for j in range(i + 1, len(s) + 1):
            tmp = s[i:j]
            print(tmp)
            if int(tmp) % 2019 == 0:
                ans += 1
    print(ans)


if __name__ == '__main__':
    sol()

Submission status: Wrong Answer

Solution code:
s = input()
c = 0
for n in range(1, 100):
    p = str(2019 * n)
    i = -1
    while True:
        i = s.find(p, i + 1)
        if i == -1:
            break
        c += 1
print(c)