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 = list(input())
Count = 0
if len(S)<=4:
    print(0)
else:
    for w in (5,len(S)+1):
        for i in range(0,len(S)+1-w):
            if int("".join(S[i:i+w]))%2019==0:
                # print("".join(S[i:i+w]))
                Count+=1
    print(Count)

Submission status: Wrong Answer

Solution code:

def resolve():
    s = input()
    a = {}
    b = {}
    ans = 0
    aa = [[(i + j * 10) % 3 for j in range(5)] for i in range(10)]
    bb = [[(i + j * 10) % 673 for j in range(680)] for i in range(10)]
    for c in map(int, s):
        if 0 not in a:
            a[0] = 0
        a[0] += 1
        a = {aa[c][k]: v for k,v in a.items()}
        if 0 not in b:
            b[0] = 0
        b[0] += 1
        b = {bb[c][k]: v for k,v in b.items()}
        # print(a)
        # print(b)
        # print()
        if 0 in a and 0 in b:
            ans += min(a[0], b[0])
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
skip = -9999999
for i in range(len(s)):
    if i < skip:
        continue
    for j in range(int(i)+1 , len(s)+1):

        if int(s[i:j]) % 2019 == 0:
            ans += 1
            skip = j -1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
s = str(input())

list = deque()
count = 0
for i in range(1,101):
    list.append(str(i*2019))

for li in list:
    for j in range(0,len(s) - len(li) + 1):
        if s[j:j+len(li)] == li:
            count += 1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input("")
l = ['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',]
res = []
for i in range(len(s)):
	s2 = s[i:]
	for i in l:
		b = s2.find(i)
		if b!= -1:
			e = b+ len(i)
			b = b +1
			res.append((b, e))
#print(res)
print(len(res))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0

if len(S) < 4:
  print(cnt)
  exit()
  
if len(S) == 4:
  if int(S) % 2019 == 0:
  	print(int(S)//2019)
  	exit()
  else:
    print(0)
    exit()

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

print(cnt)

Submission status: Wrong Answer

Solution code:
def check(s,i,c):
    if i >= len(s):
        return c
    if int(s[i:i+4]) % 2019 == 0:
        c += 1
        return check(s,i+4,c)
    elif int(s[i:i+5]) % 2019 == 0:
        c += 1
        return check(s,i+5,c)
    else:
        return c

s = input()
cnt = 0
li = []
for i in range(0,len(s)-3):
    a = int(s[i:i+4])
    b = int(s[i:i+5])
    if a % 2019 == 0:
        cnt += 1
        cnt += check(s,i+4,0)
    if b % 2019 == 0:
        cnt += 1
        cnt += check(s,i+5,0)
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
li = []
i = 2019
while int(i) < 200000:
    i += 2019
    c = str(i)
    if c in s:
        a = [x for x in range(len(s)) if s.startswith(c, x)] 
        for b in a:
            li.append(b)
print(len(li))

Submission status: Wrong Answer

Solution code:
S = input().rstrip()
r = 0
ret = 0
length = 4
# chk_num = 0
d = {}
while r < len(S) - 4:
    # print(S[r:r+length], length)
    # chk_num += 1
    str_num = S[r:r + length]
    # print(str_num)
    if d.get(str_num, -1) == -1:
        if eval(str_num) % 2019 == 0:
            # print(r, r+length)
            d[str_num] = 1
        else:
            d[str_num] = 0

    ret += d[str_num]

    if d[str_num] == 1:
        r = r + length - 1
        length = 4
    else:
        length += 1
        if length > len(S):
            r += 1
            length = 4
print(ret)
# print(chk_num)

Submission status: Wrong Answer

Solution code:
s=input()

multple19=list()
for i in range(int(1000/19)+1):
    multple19.append(19*i)

ansCondidate=list()
for mlt in multple19:
    if s.count(str(mlt)) > 0:
        ansCondidate.append(mlt)

for i in range(len(ansCondidate)):
    ansCondidate[i]+=int(2000*ansCondidate[i]/19)

sum=0
for cnddt in ansCondidate:
    sum+=s.count(str(cnddt))

print(sum)

Submission status: Wrong Answer

Solution code:
from sys import stdin

S = stdin.readline().rstrip()
N = len(S)
Sp = S

res_map = [0 for _ in range(N)]

aa_list2 = [1]
for i in range(1,N):
    aa_list2.append((aa_list2[i-1]*10)%2019)


res_map[N-1] = int(S[N-1])
index=1
for i in range(N-2,-1,-1):
    res_map[i] = (int(S[i])*aa_list2[index] + res_map[i+1])%2019
    index+=1

res_map.sort()
temp_num=res_map[0]
index=1
if temp_num==0:
    index+=1
tot = 0
for i in range(1,N):
    if temp_num==res_map[i]:
        index+=1
        continue
    else:
        if index>1:
            #tot += index*(index-1)/2
            tot += index/2
        index=1
        temp_num=res_map[i]





print(int(tot))

Submission status: Wrong Answer

Solution code:
s = input()

ans = 0
n = len(s)
for i in range(4, n+1):
    d, m = divmod(int(s[i-3:i]), 19)
    if m == 0:
        x1 = str(2019 * d)
        x2 = str(2019 * 100 * d)
        x3 = str(2019 * 1000 * d)
        n1 = len(x1)
        if n1 <= i+1 and s[i-n1:i] == str(x1):
            ans += 1
        n2 = len(x2)
        if n2 <= i+1 and s[i-n2:i] == str(x2):
            ans += 1
        n3 = len(x3)
        if n3 <= i+1 and s[i-n3:i] == str(x3):
            ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
S = input()
ans = 0
for i in range(len(S)-3):
    n = 0
    for j in range(i+3,len(S)+1):
        p = int(S[i:j])
        if p % 2019 == 0:
            ans += 1
            n = 0
        else:
            n += 1
        
        if n == 9:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
# function to print the first m multiple 
# of a number n without using loop. 
def multiple(m, n,str1): 
    count=0
    a = range(n, (m * n)+1, n) 
    for i in a:
        if str(i) in str1:
            count+=1
    return count
	
# driver code 
m = 200000
n = 2019
str1=input()
print(multiple(m, n,str1))

Submission status: Wrong Answer

Solution code:
def main():
  s=input()
  l,mod=len(s),2019
  x,c=[0]*l,0
  x[0]=(int(s[0])*(pow(10,l-1,mod)))%mod
  for i in range(1,l):
    x[i]=((int(s[i])*(pow(10,l-i-1,mod)))+x[i-1])%mod
    c+=0 if x[i]>0 else 1
  ll=len(set(x))
  print(l-ll+c)
if __name__=='__main__':
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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


main()

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0

length = len(S)
for i in range(0,len(S)-4):
  for j in range(i+4,i+4+25):
    if int(S[i:j+1]) % 2019 == 0 and j<length:
      cnt += 1

print(cnt)

Submission status: Wrong Answer

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

S = input()
N = len(S)
i = 0
j = 4
c = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
si=input()
sa = []
sss = []

for i in range(5,len(si)+1):
    ss = int(si[(i-5):i])
    if ss % 2019 == 0 and ss <= 200000:
        sa.append(i)
        sss.append(ss)
    ss = int(si[(i-4):i])
    if ss % 2019 == 0 and ss <= 200000:
        sa.append(i)
        sss.append(ss)
    if i>=6:
        ss = int(si[(i-6):i])
        if ss % 2019 == 0 and ss <= 200000:
            sa.append(i)
            sss.append(ss)

#print(sa)
#print(sss)
print(len(sa))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = str(input())

ans = 0

for x in range(1, 100) :
  num = str(2019 * x)
  if num in S :
    for i in range(0, len(S) - len(num) + 1) :
      if num == S[i:i + len(num)] : 
        ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
N=len(S)
if N<4:
  print(0)
  exit()
  
B=[]
cnt=0
for i in range(N-4+1):
  if int(S[i:i+4])%2019==0:
    B.append((i,i+3))
for i in range(N-5+1):
  if int(S[i:i+5])%2019==0:
    B.append((i,i+4))
for i in range(N-6+1):
  if int(S[i:i+6])%2019==0:
    B.append((i,i+5))
for i in range(N-7+1):
  if int(S[i:i+7])%2019==0:
    B.append((i,i+6))

if len(B)==0:
  print(0)
  exit()
  
C=sorted(B)
n=len(C)
a=C[0][1]
C.append((-1,-1))
ans=0
num=1
for i in range(1,n+1):
  if C[i][0]==a+1:
    num+=1
    a=C[i][1]
  else:
    ans+=(1+num)*num//2
    num=1
    a=C[i][1]
print(ans)

Submission status: Wrong Answer

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

import re

while len(str(nnn)) < 6:
    nnn = 2019 * i
    if int(nnn) >= int(nn):
        break
    i+=1
    if str(nnn) in str(nn):
        nnn = str(nnn)
        c+=len(re.findall(nnn[0]+"(?="+nnn[1:]+")", str(nn)))
print(c)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0
l = len(s)
for i in range(l-4):
    tmp = int(s[i:i+5])
    tmp2 = int(s[i:i+4])
    if tmp%2019==0:
        count +=1
    if tmp2%2019==0:
        count +=1

print(count)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0

length = len(S)
for i in range(0,len(S)-4):
  for j in range(i+4,i+4+20):
    if int(S[i:j+1]) % 2019 == 0 and j<length:
      cnt += 1

print(cnt)

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

def fun(a,b):
    ans=0
    for x in range(len(a)-b):
        if int(a[x:x+b])%2019==0:
            ans+=1
    return ans

for i in range(1,496):
    a.append(str(2019*i))
if len(s)<4:
    print(0)
else:
    ans=0
    for x in range(3,len(s)):
        fun(s,x)
    print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    S = list(input())
    N = len(S)
    ans = 0
    m = 2019
    div_list = [0]*m
    div_list[0] += 1
    num = 0
    print(N)
    for i in range(N):
        num += 10**i*int(S[N-i-1])
        div_list[num%m] += 1

    for item in div_list:
        ans += int(item*(item-1)/2)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0
lis = []
for i in range(1,1000):
    n = 2019*i
    cnt += S.count(str(n))
    cnt += lis.count(S.find(str(n)))
    lis.append(S.find(str(n))+len(str(n)))
print(cnt)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

S = input()
S_int = int(S)
S_len = len(S)

patterns = [[]]

last_pattern_len = 4
for cnt in range(1, 200001):
    pattern = 2019 * cnt
    pattern_len = len(str(pattern))
    if pattern > S_int:
        break
    else:
        if pattern_len > last_pattern_len:
            last_pattern_len = pattern_len
            patterns.append([])
        patterns[-1].append(str(pattern))
patterns = [set(el) for el in patterns]

ans = 0
for digit_idx, pattern_set in enumerate(patterns):
    for idx in range(S_len - (3 + digit_idx)):
        if S[idx:idx + 4 + digit_idx] in pattern_set:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

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

ans = 0

for i in X:
    if i >= 2:
        ans += 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, 100)]
for i in l:
    if i in s:
        same.append(i)
        ans += 1
for i in same:
    j = 0
    m = s
    ans -= 1
    for _ in range(len(s)):
        idx = m.find(i)
        m = m[idx+1:]
        if idx==-1:
            break
        ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=str(input())

total=0
count=0

for i in range(100):
  if str(i*2019) in s:
    total+=1
    if str(i*2019) in s[s.find(str(i*2019))+1:len(s)]:
      total+=1
print(total)

Submission status: Wrong Answer

Solution code:
def solve():
    S = int(input())
    S_1 = str(S)
    length_S = len(S_1)
    n = 1
    counting = 0
    result = 0
    while n < length_S:
        tempNum = n * 2019
        tempString = str(tempNum)
        counting = S_1.count(tempString)
        result += counting
        n += 1
    print('{}'.format(result))


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0

length = len(S)
for i in range(0,len(S)-4):
  for j in range(i+4,i+4+10):
    if int(S[i:j+1]) % 2019 == 0 and j<length:
      cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
s = str(input())
ans = 0
for i in range(len(s[:-3])):
    for j in range(len(s)+1):
        if j > i and j-i > 4:
            num = int(s[i:j])
            print(num)
            if num % 2019 == 0:
                ans = ans + 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, 10)]
for i in l:
    if i in s:
        same.append(i)
        ans += 1
for i in same:
    j = 0
    m = s
    ans -= 1
    for _ in range(len(s)):
        idx = m.find(i)
        m = m[idx+1:]
        if idx==-1:
            break
        ans += 1

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

Submission status: Wrong Answer

Solution code:
S = input()

N = len(S)

ans = 0
for i in range(5,N+1):
  for j in range(0,N-i+1):
    Si = S[j:j+i]
    if int(Si) % 2019 == 0:
      ans += 1
      print(Si)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


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


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    S = input()
    N = len(S)
    lis = [str(2019 * i) for i in range(1, 100)]

    ans = 0

    # print(lis)

    for x in lis:
        n = len(x)
        ind = S.find(x)
        ans += S.count(x)
        if ind > -1:
            # print("ind:", ind, "x:", x)
            if ind + 2*n < N:
                # print("yay")
                for i in range(ind+1, ind+n):
                    # print(S[i:i+n])
                    ans += S[i:i+n].count(x)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

l=len(list)
res=0

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

Submission status: Wrong Answer

Solution code:
S=input()
L=list(S)
print(L)
length=len(L)

def cal(i):
	total=0
	y=L[i]
	for j in range(i+1,length):
		x=int(str(y)+L[j])
		if x%2019==0:
			total+=1
			y=x
		else:
			y=x
	return total
    

Total=0
for i in range(0,length-3):
	Total+=cal(i)

print(Total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

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

ans_list = ['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']

count = 0
s_len = len(S)

for a in ans_list:
    l = len(a)
    if l > s_len:
        break
    i = 0
    if S.count(a) > 0:
        while True:
            if i+l > s_len:
                break 
            if S.count(a, i, i+l) > 0:
                count += 1
            i += 1

print(count)

Submission status: Wrong Answer

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

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
        pe[i]=0
        y=1
    if int(s[i:i+5])%2019==0 and i!=n-3:
        pe[i+4]+=pe[i]+1
        pe[i]=0
    y=0
for i in range(n):
    if pe[i]>0:
        ans+=(pe[i])
print(ans)

Submission status: Wrong Answer

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

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

S = input()

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
# input処理を高速化する
input = sys.stdin.readline

S=input()
N=len(S)

number=''
cnt=0

a = [str(2019*i) for i in range(1,10000000)]

for k in a:
    if k in S:
        cnt+=1

# for i in range(N-2):
#     for j in range(i+4,N):
#         number=S[i:j]
#         if int(number)%2019 ==0:
#             print(i,j)
#             cnt+=1
#             break

print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()
ret = 0
for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        if j == i + 4:
            sum_num = sum([int(s) for s in S[i:j]])
            if int(S[i:j]) != 2019:
                continue
        else:
            sum_num += int(S[j-1])
        test = int(S[i:j]) // 3
        if test % 673 == 0:
            ret += 1
print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S= input()
N = len(S)
if N < 4:
    print(0)
elif N == 4:
    ans = 0 + 1*(int(S)%2019 == 0)
    print(ans)
else:
    ans = 0
    for n1 in range(N-3):
        num = S[n1:n1+4]
        num2 = S[n1:n1+4]
        
        temp = int(S[n1]) + int(S[n1+1]) + int(S[n1+2]) + int(S[n1+3])

        
        if not int(num) == 0:
            if int(num)%2019== 0:
                ans += 1
        for n2 in range(n1+4,N):
            num2 += S[n2]
            temp += int(S[n2])
            if not int(num2) == 0:
                if temp%3 == 0:
                    if int(num2)%673== 0:
                        ans += 1
            print(num2)
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
number = [ str(x*2019) for x in range(1000)]
count=0
v = []
for i in range(4, len(S)):
    for k in range(i):
        v =[]
        for l in range(0, len(S)//i):
            if len(S[l*i+k: l*i+k+i])==i:
                v.append(S[l*i+k: l*i+k+i])
                for m in v:
                    if m in number:
                        print(v)
                        count+=1

print(count)

Submission status: Wrong Answer

Solution code:
s = input()

t = 0
for i in range(len(s)):
  for ii in range(i+1,len(s)):
    if int(s[i:ii]) % 2019 ==0:
      t += 1

print(t)

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0

if len(S) < 4:
  print('x')
  print(cnt)
  exit()
  
if len(S) == 4:
  print(int(S)//2019)
  exit()

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

print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0

length = len(S)
if length < 20000:
  for i in range(0,len(S)-4):
    for j in range(i+4,i+4+30):
      if int(S[i:j+1]) % 2019 == 0 and j<length:
        cnt += 1
  print(cnt)
else:
  print(1)

Submission status: Wrong Answer

Solution code:
import re
S=input()

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


ans=0

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

print(ans)

Submission status: Wrong Answer

Solution code:
import re
import sys

s = sys.stdin.buffer.readline().rstrip().decode()
ans = 0

for i in range(1, 200001):
    tmp = str(2019*i)
    if tmp in s:
        index = -1
        while True:
            index = s.find(tmp, index + 1)
            if index == -1:
                break
            ans += 1
    if int(tmp) > int(s):
        exit()
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
S = input()
cum = []
heapq.heapify(cum)
for i in range(len(S)-1, -1, -1):
    n = int(S)
    n = n % 10**(i+1)
    heapq.heappush(cum, n % 2019)

print(cum)
prev = cum[0]
ans = 0
cnt = 0
for i in range(len(cum)):
    c = heapq.heappop(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:
S=list(input())
N = len(S)
arr = []

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

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

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

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

Submission status: Wrong Answer

Solution code:
d = {0: 1}
s, p = 0, 1
for c in reversed(input()):
  s = (s + p * int(c)) % 2019
  d[s] = d.get(s, 0) + 1
  p = p * 10 % 2019
print(sum(x * (x - 1) // 2 for x in d))

Submission status: Wrong Answer

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

for s in slist:
  if s % 2019 == 0:
    cnt += 0
    
print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 0
front, back = 0, 0
t = ""
while back < N:
    t += S[front]
    # print(t)
    if int(t) % 2019 == 0:
        # print(back + 1, front + 1)
        ans += 1
        back = front + 1
        t = S[front]
    front += 1
    if front == N:
        back += 1
        front = back
        t = ""
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()

len_s = len(s)
target_number = 2019
count = 0

pattern = [str(2019 * i) for i in range(1, 10000)]
#print(pattern)
for p in pattern:
#    print("patter: {}, count: {}".format(p, s.count(p, 0, len_s)))
    count += s.count(p)

print(count)

Submission status: Wrong Answer

Solution code:
N = input()
lenN = len(N)
cnt = 0
  
for i in range(0,lenN-3):
  for j in range(i + 3,lenN + 1):
    if j - i > 200000:
      break
    p = int(N[i:j])
    if p % 2019 == 0:
      print("{}:{}".format(i,j))
      cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
# baisu = []
baisu = ['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']

# n = 2019
# while n <= 200000:
#     baisu.append(str(n))
#     n += 2019

ans = 0

for i in baisu:
    suffix = 0
    
    if i in s:
        tmp = ""
        for j in range(suffix, len(s)):
            tmp += s[j]
            suffix = j
            
            if i in tmp:
                ans += 1
                tmp = tmp[-1]
print(ans)