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())
k = len(S)
m = 0
for i in range (k-3):
    j = 0
    while (j <= (k - i - 3 )):
        a = ''.join(S[j:j+i+4])
        s = int(a)
        if (s % 2019) == 0:
            m +=1
            j +=(i+3)
        else:
            j += ((j+4)//4)

print(m)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

input_line = input()

iLen = len(input_line)
jLen = len(input_line)

prev = 0
cnt = 0


for i in range(0, len(input_line)):
    for j in range(i + 4, len(input_line)) :
        
        string = input_line[i:j]
        # print(string)
        
        string = int(string)
        if string == prev : break
        
        if string % 2019 == 0 : cnt += 1
        
        prev = string
        
print(cnt)

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

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

def main():
    s = ns()
    ans = 0
    for i in range(0,len(s)-3):
        tmp = (int(s[i])%2)*1000 + int(s[i+1:i+4])
        if tmp%19 == 0:
            n = str((tmp//19)*2019)
            nsize =len(n)
            flag = True
            if i-nsize+4>=0 and n[:-3] == s[i-nsize+4:i+1]:
                ans +=1
    print(ans)
    return
  
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()

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

Submission status: Wrong Answer

Solution code:

s = input('')
max_s = int(200000/2019)
rec = 0
for m in (range(max_s+1)):
    ms=str(2019*m)
    idx=0
    idx=s.find(ms)
#    if idx>0:
#        print("{} {}".format(ms,idx))
    while idx >= 0:
        rec+=1
        idx=s.find(ms,idx+1)
#        print("{} {}".format(ms,idx))
print(rec)

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]
        if int(n) % 2019 == 0:
            cnt += 1
            st = ed - 1
            ed += 3
                
        else:
            if len(n) > 4:
                st += 1
            else:
                ed += 1
            
    print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  s=input()
  n=len(s)
  ans=0
  for i in range(n-3):
    for j in range(i+3,n+1):
      if int(s[i:j])%2019==0:
        ans+=1
  print(ans)
main()

Submission status: Wrong Answer

Solution code:
S = input()

s = []
for j in range(3, len(S)+1):
    for i in range(0, j-3):
        s.append(S[i : j])
print(s)

flg = 0
for k in range(len(s)):
    if int(s[k]) % 2019 == 0:
        flg += 1

print(flg)

Submission status: Wrong Answer

Solution code:
s=input()
# print(len(s));
i=0
count=0

for k in range(4,len(s)+1):
    i=0
    for j in range(k,len(s)+1):

    
        m=s[i:j]
        i=i+1
        print(m)
    
        # print(int(m))
        if int(m)%2019==0:
            count+=1
        # i=i+1

print(count)

Submission status: Wrong Answer

Solution code:
S=input()
full=[]
cnt=0
kaisuu=2*10**7//2019+1
 
for i in range(1,kaisuu+1):
  full.append(str(i*2019))
 
 
def occurrences(string, sub):
    count = start = 0
    while True:
        start = string.find(sub, start) + 1
        if start > 0:
            count+=1
        else:
            return count
  
for s in full:
  cnt+=occurrences(S,s)
print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    S = input()
    len_S = len(S)
    counter = 0
    for i in range(1, 100):
        multiple = str(2019*i)
        len_m = len(multiple)
        for j in range(len_S - len_m + 1):
            if S[j:j+len_m] == multiple:
                counter += 1
    print(counter)
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = input()

ls = [0for i in range(len(S))]

for i in range(len(S)):
    # 4~7桁で見たときの2019の倍数の区間
    for j in range(4,8):
        if i+j <= len(S):
            x = int(S[i:i+j])
            if x % 2019 == 0:
                # 今調べている区間につながる倍数の数＋自身
                ls[i+j-1] += 1
                if i > 0:
                    ls[i+j-1] += ls[i-1]

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

print(count)

Submission status: Wrong Answer

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

# 前処理
end = 1
while end <= N:
  if int(S[:end+1]) % 2019 == 0:
    break
  else:
    end += 1

ans = set()
for i in range(end):
  start = i
  end = i+1
  while end <= N:
    if int(S[start:end+1]) % 2019 == 0:
      ans.add((start,end))
      start = end
      end += 1
    else:
      end += 1
print(len(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
c = 0
# 4
# 5
if int(s) >= 12114:
    for i in range(l - 4):
        n = int(s[i:i + 5])
        if n % 2019 == 0:
            c += 1
# 6
if int(s) >= 119121:
    for i in range(l - 5):
        n = int(s[i:i + 6])
        if n % 2019 == 0:
            c += 1
print(c)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
C = [0 for i in range(2019)]
C[0] = 1
now = 0
for i in range(N):
    now += int(S[-i-1])*(10**(i%2019))
    now %= 2019
    C[now] += 1
ans = 0
for i in range(2019):
    ans += C[i]*(C[i]-1)//2
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(1,min(16,len_s-i+1)):
        if int(s[i:i+j])%2019==0:
            list[i]=list[i+j]+1
print(sum(list))

Submission status: Wrong Answer

Solution code:
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, 101)]
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()
num = len(S)

pair = 0

if num < 5:
    print(0)
else:
    for i in range(5,num):
        for j in range(num-i+1):
            temp = int(S[j:j+i+1])
            if temp % 2019 == 0:
                pair += 1

    print(pair)

Submission status: Wrong Answer

Solution code:
S=str(input())
n=0
for i in range(len(S)-3):
  j=i+3
  m=S[i:j]
  while j<=len(S)-2:
    m=S+str(S[j+1])
    if int(m)%2019==0:
      n+=1
    else:
      pass
    j+=1
print(n)

Submission status: Wrong Answer

Solution code:
S = str(input())

cnt = 0
div_value = 2019

for i in range(0, len(S)-4):
   #print(i, S[i:i+4])
   for j in range(i+4, len(S)):
       #print(j, S[i:j])
       if j-i >= 200000:
           continue
       if int(S[i:j]) >= div_value \
           and int(S[i:j]) % div_value == 0:
           cnt = cnt+1

print(cnt)

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+50):
    if int(S[i:j+1]) % 2019 == 0 and j<length:
      cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
L = [2019*k for k in range(10*10)]
for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j+2]
    if int(a) in L and int(a) != 0:
      ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s= int(input())
a=len(str(s))
s=str(s)
import itertools
List = list(itertools.combinations(range(a), 2))

cnt =0
for i in List:
    b=int(i[0])
    e=int(i[1])
    
    if (int(s[b:e])%2019)==0:
        cnt +=1
  
    

print(cnt)

Submission status: Wrong Answer

Solution code:
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def binary(n):
    return bin(n)[2:]

# バイナリ法
def pow_by_binary_exponentiation(a, x, n): # a^x mod n
    x = [int(b) for b in binary(x)]
    y = a
    for i in range(1, len(x)):
        y = (y**2) % n
        if x[i] == 1:
            y = (y * a) % n
    return y

# モンゴメリ冪乗法
def pow_by_montgomery_ladder(a, x, n): # a^x mod n
    x = [int(b) for b in binary(x)[::-1]]
    k = len(x)
    a1 = a
    a2 = a**2
    for i in range(k - 2, -1, -1):
        if x[i] == 0:
            a2 = (a1 * a2) % n
            a1 = (a1**2) % n
        else:
            a1 = (a1 * a2) % n
            a2 = (a2**2) % n
    return a1

def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res
#a,b,c,d=list(map(int,input().split()))
s=input()
#s="3"*20000
su=[0 for _ in range(len(s))]
su[0]=int(s[-1])
for i in range(1,len(s)):
    ii=len(s)-i-1
    o=int(s[ii])*pow(10,i,2019)
    #su[i]=su[i-1]+(int(s[ii])*(10**i))
    #su[i]=su[i-1]+pow(int(s[ii]),10**i,2019)
    su[i]=(su[i-1]+o)

    su[i]%=2019
a_dic=Counter(su)
ans=0
if 0 in a_dic.keys():
    ans+=a_dic[0]
    del a_dic[0]

for i in a_dic.keys():
    if a_dic[i]<2:
        continue
    ans+=combinations_count(a_dic[i],2)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

c=0
d=0
def check2019(S, n):
    global c
    global d
    if int(S)%2019 ==0:
        c +=1
    else:
        pass
    if len(S)>4:
        if n ==0:
            return check2019(S[1:],1), check2019(S[:-1], 0)
        else:
            return check2019(S[1:],2)
    else:
        return 0
S = input()


if len(S) >= 4:
    check2019(S, 0)
else:
    pass
print(c-d)

Submission status: Wrong Answer

Solution code:
#s:str, 2.0e+5
#print(200000//2019)
multiples = list(map(str, [2019*i for i in range(1, 100)]))
s = input()
length = len(str(s))
ans = 0
for num in multiples:
    if num in s:
        leng = len(num)
        for i in range(length-leng+1):
            if num == s[i:i+leng]:
                ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

count = 0
now = 0
flag = False
while True:
    for i in range(now, len(S)):
        s = S[now:i+1]
        tmp = 0
        for k in range(len(s)):
            tmp = (tmp*10 + int(s[k])) % 2019
        if tmp == 0:
            count += 1
            now = i
    if count == 0:
        now += 1
    else:
        break
            
print(count)

Submission status: Wrong Answer

Solution code:
import math
import fractions
import collections
import itertools
from collections import deque
d=collections.deque()
S=list(input())
N=len(S)
cnt=0

amari=[0]*(N+1)
num=0
for i in range(N):
    d.append(int(S[i]))
#print(d)
for i in range(N):
    n=d.pop()
    num=(num+pow(10,i,2019)*n)%2019
    amari[i+1]=num
#print(amari)
#c=collections.Counter(amari)
#values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
amari.sort()
#for i in range(len(key)):
#    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#xprint(l)
buf=0
#print(amari)
for i in range(N-1):
    if amari[i]==amari[i+1]:
        buf=buf+1
    else:
        cnt=cnt+((buf+1)*buf)//2
        buf=0
    #print(buf)
cnt=cnt+(buf*(buf+1))//2
print(cnt)

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

Submission status: Wrong Answer

Solution code:
N = input()
nagasa = len(N)
count = 0
for a in range(1, nagasa+1):
    for b in range(a+1, nagasa+2):
        c = 0
        keta = b - a + 1
        for k in range(1,keta):
            c += int(N[a - 2 + k]) * 10 ** (keta-k-1)
        if c % 2019 == 0  and c != 0:
            count += 1
print("count=",count)

Submission status: Wrong Answer

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

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

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

print(count)

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

# 24228
# 2422
# 24228

Submission status: Wrong Answer

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    S = input()
    cnt = 0
    start = 0
    LIST = []
    while start+4 < len(S):
        for i in range(start+4,len(S)+1):
            if S[i-1] == 0:
                start += 4
                continue
            if int(S[start:i]) % 2019 == 0:
                cnt += 1
                start += 4
        start += 1
    print(cnt)
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
l = []
for i in range(1, 100):
    l.append(str(2019*i))

s = input()
ans = dict()
for i in l:
    if i in s:
        for j in range(len(s)-len(i)+1):
            if s[j:j+len(i)] == i:
                ans[str(j+1)+"-"+str(j+len(i))] = 1

# print(l)
print(len(ans))

Submission status: Wrong Answer

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

def count_all(text, part):
    num = 0
    pos = 0
    while True:
        pos = text.find(part, pos)
        if pos == -1:
            break;
        num = num + 1
        pos = pos + 1
    return num


S = input()
I = 2019
l = []
count = 0

while I < 200000:
    count += count_all(S,str(I))
    I += 2019

print(count)

Submission status: Wrong Answer

Solution code:
S = input()

ls = [0for i in range(len(S))]

for i in range(len(S)-4):
    # 4~7桁で見たときの2019の倍数の区間
    for j in range(4,8):
        if i+j <= len(S):
            x = int(S[i:i+j])
            if x % 2019 == 0:
                # 今調べている区間につながる倍数の数＋自身
                ls[i+j-1] += 1
                if i > 0:
                    ls[i+j-1] += ls[i-1]

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

print(count)

Submission status: Wrong Answer

Solution code:
S=input()
n=len(S)
mod=2019

T=[]
now=1
for i in range(n):
    T.append(now*int(S[-i-1])%mod)
    now=now*10%mod
C=[]
now=0
for i in range(n):
    now+=T[i]
    now%=mod
    C.append(now)
C.sort()

now=0
cnt=1
A=[]
for i in range(n):
    if now==C[i]:
        cnt+=1
    else:
        if cnt>=2:
            A.append(cnt)
        now=C[i]
        cnt=1
ans=0
for a in A:
    ans+=a*(a-1)//2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def solve(S: int):
    # cnt = 0
    # for i in range(len(str(S))):
    #     for j in range(i + 1, len(str(S))):
    #         if not int(str(S)[i:j]) % 2019:
    #             cnt += 1
    # print(cnt)
    cnt = 0
    l = filter(lambda x: '0' not in str(x), range(2019, 200000, 2019))
    s = str(S)
    for i in l:
        for j in range(0, len(s), 2):
            if len(str(i)) - 1 + j > len(s) - 1:
                continue
            if s[j:len(str(i)) + j] == str(i):
                cnt += 1
    print(cnt)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
baisu = []

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)

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):
    test = S[i]
    for j in range(i+1,len(S)):
      test = test + S[j]
      if len(test) >= 4:
        test_int = int(test)
        if test_int % 2019 == 0:
          count = count + 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())

s = load(str)
d = dict()
for i in range(1, 10):
    d[str(i)] = i
cnt = 0
for i in range(len(s)):
    target = 0
    for j in range(i + 3, len(s)):
        target =  target * 10 + d[s[j]]
        if target % 2019 == 0:
            cnt += 1
print(cnt)

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+100):
    if int(S[i:j+1]) % 2019 == 0 and j<length:
      cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import re

S = str(input())

def count_o(sub, string):
    # via https://www.geeksforgeeks.org/python-count-overlapping-substring-in-a-given-string/
    count = 0
    start = 0
    while start < len(string):
        pos = string.find(sub, start)
        if pos != -1:
            start = pos + 1
            count += 1
        else:
            break
    return count

count = 0
for i in range(1, 100):
    count += count_o(str(i * 2019), S)

print(count)

Submission status: Wrong Answer

Solution code:
import re

x=[]
l=2019
while l<200000:
    if not '0' in str(l):
        x.append(str(l))
    l+=2019

S=input()

res=0
for n in x:
    l=0
    while not S.find(n,l)==-1:
        l=S.find(n,l)+1
        res+=1

print(res)

Submission status: Wrong Answer

Solution code:
s = input()
li = []
for i in range(1, 100):
    i *= 2019
    i = str(i)
    if i in s:
        a = [x for x in range(len(s)) if s.startswith(i, x)] 
        for b in a:
            li.append(b)
print(len(li))

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
        index=1
        temp_num=res_map[i]





print(int(tot))

Submission status: Wrong Answer

Solution code:
mod_673 = [1] * 672
for i in range(1,672):
    mod_673[i] = (mod_673[i -1] * 10) % 672

S = input()
S = S[::-1]
A = [0] * (len(S) + 1)
B = [0] * (len(S) + 1)
x = 0
Ans = [[0] * 3 for i in range(673)]
for i in range(1, len(S) + 1):
    A[i] = (A[i - 1] + int(S[i - 1]) * mod_673[(i - 1) % 672]) % 673
    B[i] = (B[i - 1] + int(S[i - 1])) % 3

for i in range(len(S) + 1):
    Ans[A[i]][B[i]] += 1

for i in range(673):
    for j in range(3):
        y = Ans[i][j]
        x += y * (y - 1) // 2

print(x)

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

Submission status: Wrong Answer

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

count = 0
if n < 4 or int(s) < 2019:
	print(0)
else:
	for i in range(n-3):
		for j in range(n)[i+3:]:
			if int(s[i:j+1]) % 2019 ==0:
			  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import re

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)
    i = 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:
import re
#A, B, C, D = list(map(int, input().strip().split()))
S = input()
A = [str(i * 2019) for i in range(100) if '0' not in str(i * 2019)]
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
string=input()
count=0
times=0
length=4
while len(string) >= length:
  target=int(string[:length])
  if target <= 200000 and target % 2019 == 0:
    count+=1
  times+=1
  length+=1
  if times != 0 and times % 3 == 0:
    length=4
    string=string[1:]
print(count)

Submission status: Wrong Answer

Solution code:
def c(n):
  return (n*(n-1)//2)
S = int(input())
s = str(S)
a = len(s)
enbas = [0]*(a+1)
puiss = 1
for i in range(a):
  enbas[i]=((int(s[a-i-1])*puiss+enbas[i-1])%2019)
  puiss*=10
compte = 0
enbas.sort()
i = 0
avant = 0
for n in range(a+1):
  if avant==enbas[n]:
    i+=1
  else:
    compte+=c(i)
    avant = enbas[n]
    i = 1
print(compte)

Submission status: Wrong Answer

Solution code:
import re
import sys

s = str(sys.stdin.buffer.readline().rstrip())
c = [2019*i for i in range(1, 1000)]
ans = 0

for i in range(999):
    tmp = str(c[i])
    if tmp in s:
        index = -1
        while True:
            index = s.find(tmp, index + 1)
            if index == -1:
                break
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0
is_end = [False] * (len(S) + 1)
for i in range(len(S)):
    if is_end[i]:
        continue
    is_end[i] = True
    bingo = [i]
    s = 0
    for j in range(i+1, len(S)+1):
        if is_end[j]:
            continue
        s += int(S[j-1])
        if s % 3 != 0:
            continue
        if int(S[i:j]) % 673 == 0:
            is_end[j] = True
            bingo.append(j)
    l = len(bingo)
    if l >= 2:
        cnt += int(l*(l-1)/2)
print(cnt)

Submission status: Wrong Answer

Solution code:
s=input()
l=0
r=4
ans=0
while r<=len(s) and l<len(s):
    if l==len(s)-3:
        break
    if int(s[l:r])%2019==0:
        ans+=1
        l+=1 
        r+=1
    elif r==len(s):
        l+=1
        r=l+1
    else:
        r+=1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import re
import sys

s = str(sys.stdin.buffer.readline().rstrip())
c = [2019*i for i in range(1, 10000)]
ans = 0

for i in range(9999):
    tmp = str(c[i])
    if tmp in s:
        index = -1
        while True:
            index = s.find(tmp, index + 1)
            if index == -1:
                break
            ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
a = input().strip().split()
clist = collections.Counter(a)
print(len(clist))

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0

if len(S) < 4:
  print(cnt)
  exit()

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

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
ls = [str((i+1) * 2019) for i in range(int(200000 // 2019))]
c = 0
for i in ls:
    for pos in range(len(s)):
        if s[pos:].startswith(i):
            c += 1
print(c)

Submission status: Wrong Answer

Solution code:
S = input()


def check_3(txt):
  print(txt)
  goukei = sum(list(map(int,txt)))
  if goukei % 3 == 0:
    return True
  else:
    return False

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

N = len(S)

ans = 0

for i in range(0, N-2):
  for j in range(i+4, N+1):
    # print(S[i:j])
    if check_3(S[i:j]):
      if check_2019(S[i:j]):
        ans += 1
        i = j
        break
      else:
        pass

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    S = input()
    len_S = len(S)
    counter = 0
    # 0について調べる。
    search_0_state = True
    number_counter_0 = 0
    # Trueなら最初の0を探す。Falseなら連続する0の個数を数える。
    for i in range(len_S):
        if search_0_state:
            if S[i] == "0":
                search_0_state = False
                number_counter_0 = 1
        else:
            if S[i] == "0":
                number_counter_0 += 1
            else:
                search_0_state = True
                counter += (number_counter_0 * (number_counter_0 + 1))//2
                number_counter_0 = 0
    counter += (number_counter_0 * (number_counter_0 + 1))//2
    # 2019以上の倍数について。
    for i in range(1, 100):
        multiple = str(2019*i)
        len_m = len(multiple)
        for j in range(len_S - len_m + 1):
            if S[j:j+len_m] == multiple:
                # 0が連続する回数を数える。
                successive_0_no = 1
                while j - successive_0_no >= 0 and S[j - successive_0_no] == "0":
                    successive_0_no += 1
                counter += successive_0_no
    print(counter)

if __name__ == "__main__":
    main()

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
for j in range(100):
  if str(j*2019) in s[j:len(s)]:
    count+=1
    
print(total+count)

Submission status: Wrong Answer

Solution code:
S=str(input())
n=0
for i in range(len(S)-3):
  j=i+3
  m=S[i:j]
  a=int(S[i])+int(S[i+1])+int(S[i+2])
  r=a%3
  while j<=len(S)-2:
    m=S+str(S[j+1])
    r=(r+int(S[j+1]))%3
    if r==0:
      if int(m)%2019==0:
        n+=1
      else:
        pass
    j+=1
print(n)