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:
#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,497):
    a.append(str(2019*i))

if len(N)<4:
    print(0)
else:
    ans=0
    for j in a:
        ans+=func(N,j)
    if len(N)>6:
        for x in range(5,len(N)+1):
            ans+=fun(N,x)
    print(ans)

Submission status: Wrong Answer

Solution code:
s=str(input())
l=[]
t=0
for i in range(1,len(s)):
    g=int(s[0:i+1])
    g=g%2019
    l.append(g)
ll=set(l)
for i in set(l):
    z=l.count(i)
    if z>1:
        t+=(z*(z-1))%2
print(t)

Submission status: Wrong Answer

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

ans = 0
i = 0
l = 0

while l < len_s:
    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
print(ans)

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:
N = input()
a = [2019 * i for i in range(1,101)]
ans = 0
for i in a:
    st = N
    d = str(i)
    if st.find(d) != -1:
        print(st)
        while True:
            if st.find(d) != -1:
                ans += 1
                st = st[st.find(d)+1:]
            else:
                break
print(ans)

Submission status: Wrong Answer

Solution code:
a=input()

#b=int(a)

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

Submission status: Wrong Answer

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

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(1, 100):
    if count(s, str(2019*i)) > 0:
#        print(i*2019)
#        print(count(s, str(2019*i)))
        cnt += count(s, str(2019*i))

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
def main():
    s=list(map(int,input()))
    modpow=[1]*len(s)
    for i in range(1,len(s)):
        modpow[i]=(modpow[i-1]*10)%2019
    ans=0
    res=[0]*len(s)
    res[0]=s[-1]%2019
    for i in range(1,len(s)):
        res[i]=(modpow[i]*s[len(s)-1-i]+res[i-1])%2019
    cnt=collections.Counter(res).most_common()
    for i in range(len(cnt)):
        ans+=cnt[i][1]-1
        if cnt[i][0]==0:
            ans+=1
    print(ans)
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
if len(s) <= 3:
  print(0)
  exit()

chk = [str((i+1)*2019) for i in range(1000)]
ans = 0
for i in chk:
    if s.count(i) > 0:
      ans += s.count(i[1:])
      k = i[0]
      for j in range(1,10):
        if j == int(k):
          continue
        ans -= s.count(str(j)+i[1:])
    
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

left = 0
right = 4

l = len(s) - 4
r = len(s)

ans = 0
anst = 0

while right <= len(s):
    if int(s[left:right]) % 2019 == 0:
        ans += 1
        left = right - 1
        right += 3
    else:
        right += 1

while l >= 0:
    if int(s[l:r]) % 2019 == 0:
        anst += 1
        r = l + 1
        l -= 3
    else:
        l -= 1

print(max(ans, anst))

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
ans = 0
for i in range(l):
  for j in range(i+1, l+1):
    a =int(s[i:j]) % 10**9+7 
    if a % 2019 % 10**9+7 == 0:
      ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
lenS = len(S)
rui = [0] * 2019
for i in range(lenS):
    rui[(int(S[-i - 1:]) % 2019)] += 1

ans = 0
for i in rui:
    if i >= 2:
        ans += (i * (i - 1) // 2)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
if len(s) <= 4:
    print(1 if int(s) % 2019 == 0 else 0)
    
else:
    st = 0
    ed = 5
    cnt = 0
    for i in range(len(s)+1):
        n = s[st:ed]
        print(n, st, ed)
        if int(n) % 2019 == 0:
            cnt += 1
            st = ed - 1
            ed += 3
                
        else:
            if ed - st < len(s) // 2:
                ed += 1
            else:
                st += 1
        if st >= len(s):
            break
    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] - 1)
    print(ans)

main()

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
    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
                    i = j
                    j = i + 3
                    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
    print(count)

Submission status: Wrong Answer

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

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


S = input()

length = len(S)
ans = 0
head = tail = 0

head, tail = get_offset(S)
domains = []
while tail <= length:
    offset = tail - head
    domains.append((head, tail))
    head += offset
    tail += offset


head, tail = get_offset2(S)
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=list(input())
l=len(s)
ans=0
for i in range(l-3):
    sum_keta=int(s[i])
    num=s[i]
    index=i+1
    j=1
    while sum_keta<=100:
        if l-1<index:
            break
        num+=s[i+j]
        if int(num)%2019==0:
            ans+=1
        index+=1
        sum_keta+=int(s[i+j])
        j+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
st = input()
ans = 0
n = len(st)
dic = {
    4 : ['2019', '4038', '6057', '8076'],
    5 : ['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'],
    6 : [ '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 key,val in dic.items():
    p = key
    for value in val:
        x = 0
        i = 0
        for i in range(n):
            if st[i:i + p] == value:
                x += 1
                i += p-1
        ans += x
print(ans)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

Solution code:
s = list(input())

count = 0

for i in range(0, len(s)-4):
  for j in range(i+4,len(s)+1):
    numbers = "".join(s[i:j])
    
    print(numbers, count)
    
    if int(numbers) % 2019 == 0:
      count += 1

print(count)

Submission status: Wrong Answer

Solution code:
s=input()
count=0
if len(s)<=3:
  print(0)
  exit()
if len(s)==4:
  if int(s)%2019==0:
    print(1)
    exit()
  else:
    print(0)
    exit()
for i in range(0,len(s)-3):
  for j in range(i+3,len(s)):
    s_tmp=s[i:j+1]
    if int(s_tmp)>=200001:
      break
    if int(s_tmp)%2019==0:
      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 True:
        if i>=ls-3:
            break
        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:
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
    if n <= 3:
        print(0)
    else:
        for i in range(3,min(n+1,8)):
            for j in range(n - i + 1):
                if int(s[j: j + i]) % 2019 == 0:
                    ans += 1
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

Solution code:
import itertools
N = list(input())
# Ns = ''.join(N)
M = list(map(str, list(range(len(N)))))
S = list(itertools.combinations(M,2))
count = 0
for _, combi in enumerate(S):
    if int(combi[1]) - int(combi[0]) > 2:
        A = N[int(combi[0]):int(combi[1])+1]
        B = ''.join(A)
        print(A,B)
        if int(B)%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, 100):
        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 = str(input())
count = 0
for i in range (len(S)-4):
    for n in range (4, len(S)+1-i):
        j = i + n
        num = int(S[i:j])
        print(num)
        if(num % 2019 == 0):
            count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque
import copy

l = deque(list(input()))
now = deque([])
ans = 0

for _ in range(min(3, now.__len__())):
  now.append(l.popleft())
  
while l:
  now.append(l.popleft())
  nxt = deque([])
  while now:
    if int("".join(now)) % 2019 == 0:
      ans += 1
      now.popleft()
      nxt = copy.deepcopy(now)
    nxt.append(now.popleft())
  now = copy.deepcopy(nxt)

print(ans)

Submission status: Wrong Answer

Solution code:


anslist = []


def solve():

    S = input()

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

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
s = list(map(int, list(input())))

n = len(s)

ans = 0
i = 0
while i < n - 3:
    a = s[i] * 100 + s[i + 1] * 10 + s[i + 2]

    for j in range(i + 3, n):
        a = a * 10 + s[j]

        if a % 2019 == 0:
            ans += 1
            i = j - 1
            break

    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
count = 0

length = len(n)

stock = [0]*99

for i in range(99):
    stock[i] = '{}'.format(2019 * (i + 1))

for i in range(99):
    if length - len(stock[i]) >= 0:
        for j in range(length-len(stock[i])+1):
            if n[j: j+len(stock[i])] == stock[i]:
                count += 1

print(count)

Submission status: Wrong Answer

Solution code:
s = input()

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

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

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
count=0
if(int(N)>=1 and int(N)<=200000):
    for i in range(0,len(N)):
        for j in range(i+4,len(N)):
            if(int(N[i: j+1])%2019==0):
                print(i,j)
                count+=1
print(count)

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):
    if str(2019 * i) in x:
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:
N = input()
a = [2019 * i for i in range(1,101)]
ans = 0
for i in a:
    st = N
    d = str(i)
    if st.find(d) != -1:
        print(st)
        while True:
            if st.find(d) != -1:
                ans += 1
                st = st[st.find(d)+len(d)-1:]
            else:
                break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
ans=0
lra=len(s)-4
rla=len(s)+1
for l in range(lra):
    for r in range(l+4,rla):
        tmp=int(s[l:r])
        if tmp%2019==0:
            ans+=1
            l=r-1 
print(ans)

Submission status: Wrong Answer

Solution code:
S=str(input())
i=6
S_1=int(S)
a=S_1//2019
b=0
if 1<=len(S)<=200000:
    if S_1<12114:
        print(0)
    for i in range(6,a+1):
        c=i*2019
        c=str(c)
        if "0" in c:
            continue
        b+=S.count(c)
        i+=1
    print(b)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
start = []
stop = []

for i in range(0, n - 3):
    for j in range(4, 9):
        if i + j <= n and int(s[i:i+j]) % 2019 == 0 and int(s[i:i+j]) // 2019 < 10000:
            start.append(i)
            stop.append(i+j)

ans = 0
ls = len(start)
mark = [0 for _ in range(ls)]
for i in range(ls):
    if mark[i] != 0:
        continue
    mark[i] = 1
    flag = True
    while flag:
        j = 0
        flag = False
        while start[i+j] >= stop[i]:
            if start[i+j] == stop[i]:
                mark[i+j] = mark[i] + 1
                i += j
                flag = True
                break
            j += 1
            if i + j >= ls:
                break
    ans += mark[i] * (mark[i] + 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
P = 0
for i in range(len(S)-4):
    for j in range(i+5,len(S)+1):
        M = ''.join(S[i:j])
        N = int(M)
        print(N)
        if N%2019 == 0:
            P += 1
print(P)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
wa = [0] * (n + 1)
wa[1] = int(s[0])
for i in range(n - 1):
    wa[i + 2] = wa[i + 1] + int(s[i + 1]) 
res = [0] * (n + 1)

i = n - 4
while i >= 0:
    m = 4
    while (i + m < n) and (m < 9):
        if (wa[i + m + 1] - wa[i]) % 3 == 0:
            if int(s[i:i+m+1]) % 673 == 0:
                res[i] = res[i] + res[i + m + 1] + 1
                break
        m = m + 1
    i = i - 1    

print(sum(res))

Submission status: Wrong Answer

Solution code:
S = list(map(int, input()))
n = len(S)

fl = [False]*(n+1)
res = 0

for i in range(n-3):
    if fl[i]:
        continue
    
    x = 0
    cnt = 0
    for j, v in enumerate(S[i:n]):
        x *= 10
        x += v
        x %= 2019
        if x == 0:
            cnt += 1
            fl[j+1] = True
            
    
    res += (cnt+1)*cnt//2

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# input
import sys

read = sys.stdin.buffer.read
# input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

s = input()
n = len(s)
mod = 2019
cum = [0] * (n + 1)
cum[0] = 0
for i in range(n):
    # print(int(s[i]) - 48)
    cum[i + 1] = (cum[i] * 10 + int(s[i])) % mod
# print(cum)
mod_cum = [0] * (n + 1)
for i in range(n + 1):
    mod_cum[i] = (cum[i] * pow(10, n - i, mod)) % mod
# print(pow(10, 15, mod))
mod_cum.sort()
# print(mod_cum)
ans = 0
cnt = 0
tmp = mod_cum[0]
for i in range(n):
    if mod_cum[i + 1] == tmp:
        ans += 1
    else:
        tmp = mod_cum[i + 1]
        cnt = 1
        if cnt > 1:
            ans += cnt * (cnt - 1) // 2
if cnt > 1:
    ans += cnt * (cnt - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
memo = {}

def main():
    global S

    def main0(acc, s):
        if len(s) <= 3:
            return acc

        if s in memo:
            return memo(acc + memo[s], s[1:])

        for i in range(4, len(s)+1):
            a = int(s[0:i])
        
            if a in memo:
                acc += memo[a]
                break

            if a < 2019:
                continue
       
            if a % 2019 == 0:
                memo[a] = acc
                acc += 1

        return main0(acc, s[1:])

    return main0(0, S)

print(main())

Submission status: Wrong Answer

Solution code:
s = input()

def make_z_list(s):
    n = len(s)

    z_list = [0] * n
    z_list[0] = n
    
    i = 1
    j = 0
    
    while i < n:
        while i + j < n and s[j] == s[i + j]:
            j += 1
    
        z_list[i] = j
        
        if j == 0:
            i += 1
            continue
    
        k = 1
        while i + k < n and k + z_list[k] < j:
            z_list[i + k] = z_list[k]
            k += 1
    
        i += k
        j -= k
    
    return z_list

ans = 0
for i in range(len(s)):
    z_list = make_z_list(s[i:])
    for z in z_list:
        if z >= 4 and int(s[i:i+z]) % 2019 == 0:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import re

s = input()

n = 999
ans = 0

for i in range(n):
  w = str(2019 * (i+1))
  w_l = len(w)
  # print(w)
  w_last_index = len(s)-w_l+1
  for j in range(w_last_index):
    j_end = j+w_l
    t = s[j:j_end]
    if w == t:
      ans += 1
      # 0が何個続くか
      z_c = 0
      for k in range(j_end, w_last_index):
        if s[k] == '0':
          z_c += 1
        else:
          break
      # z_c が4つでans+1
      ans += z_c // 4
      
      # print(w)


print(ans)

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:
s = input()
li = []
i = 2019
while int(i) < 200000:
    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)
    i += 2019
print(len(li))

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 n > 1:
                sum_num += int(serict*(serict-1)/2)

            serict = 0
    
    sum += sum_num

print(sum)

Submission status: Wrong Answer

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

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

if len(s) < 4:
    print(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:
s = str(input())
 
ans = 0
len_s = len(s)
ans_pos = []
str_pos = []
end_pos = []
for i in range(4,9):
    for j in range(len_s):
        if j+i > len_s :
            break
        if int(s[j:j+i]) % 2019 == 0:
            ans +=1
            str_pos.append(j)
            end_pos.append(j+i-2)
            ans_pos.append([j,j+i-1])

for st in str_pos:
    if st in end_pos:
        ans += 1


print(ans)

Submission status: Wrong Answer

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

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+3,len(S)):
      test = S[i+1:j+1]
      mojiretsu = ''.join(test)
      if len(mojiretsu) >= 4:
        test_int = int(mojiretsu)
        if test_int % 2019 == 0:
          count = count + 1

print(count)

Submission status: Wrong Answer

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

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] = j + 1
            break
ans = 0
for i in range(l):
    if arr2[i]:
        tmp = 0
        j = i
        while j >= 0 and arr2[j]:
            j -= arr2[j]
            tmp += 1
        ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
N=['0']*10000
count=0
j=12114
for i in range(0,10000):
    while True:
        if str(j).count('0')==0:
            N[i]=str(j)
            j+=2019
            break
        else:
            j+=2019
for i in range(0,10000):
    count+=S.count(N[i])
    if S.count(N[i])>0:
        if N[i][0]==N[i][-1]:
            count+=S.count(N[i][1:])-S.count(N[i])
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
c=0
t=[0]*(len(s)+1)
for i in [str(i*2019) for i in range(1,10000) if '0' not in str(2019*i)]:
  l=s
  while l.count(i)>0:
    idx=l.find(i)
    t[idx+len(i)]+=1
    c+=1
    c+=t[idx]
    l=l[idx+1:]
print(c)

Submission status: Wrong Answer

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