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=input()
N=len(S)
dp=[0 for i in range(N)]
check=[0 for i in range(N)]

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

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
for i in range(1, 101):
    t = str(i * 2019)
    for j in range((len(s) - len(t)) // (len(t) - 1)):
        if t in s:
            ans += 1
        u = list(t)
        u.pop(0)
        u = "".join(u)
        t = t + u
print(ans)

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

print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    S = input()

    result = 0
    for i in range(2019, 2019 * 100, 2019):
        length = len(str(i))
        for j in range(len(S) - length + 1):
            if str(i) == S[j:j + length]:
                result += 1
    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = int(input())

leng = len(str(S))
count = 0

for j in range(leng-3):
    for i in range(leng, 1, -1):
        partial = S // (10 ** j)
        partial = partial % (10 ** i)
        if partial == 0:
            continue
        if partial % 2019 == 0:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
for i in range(len(S)):
    for j in range(20):
        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:
# cook your dish here
s = str(input())
n = len(s)
ans = 0
i = 0
st = 0
nm = 0
while i<n:
    nm*=10
    nm+=int(s[i])
    if(nm>=2019):
        if(nm%2019==0):
           # print(nm)
            ans+=1
        else:
            x = i-st;
            while(st<=i):
                nm-=(int(s[st]))*(10**x)
                if((nm%2019==0)):
                   # print(nm)
                    ans+=1
                else:
                    st+=1
                    break
                x-=1
                st+=1
    i+=1

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

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

print(count)

Submission status: Wrong Answer

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

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) % 673]) % 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()
l = len(s)
ans = 0

for i in range(1, l - 3):
    for j in range(4, l+1):
        string_j = int(s[:j])
        string_i = int(s[:i]) 
        if (string_j - string_i) % 2019 == 0:
            ans += 1

print(ans // 2)

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

print(cnt)

Submission status: Wrong Answer

Solution code:
s=list(input())
count=0
if len(s)<=3:
    print(0)
for i in range(len(s)-3):
    for j in range(i+3,len(s)):
        a="".join([str(n) for n in s[i:j+1]])
        if int(a)%2019==0:
            count+=1
        else:
            pass
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
for i in range(len(S)):
    for j in range(30):
        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:
l = []
for i in range(1, 99):
    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(len(ans))

Submission status: Wrong Answer

Solution code:
s = input().strip()
MOD = 2019
n = list(filter(lambda x: x != '', str(int(s) // MOD).split('0')))
if len(n) == 1:
    if int(s) % MOD == 0:
        print(1)
    else:
        print(0)
else:
    if int(s) % MOD == 0:
        print(len(n) + 1)
    else:
        print(len(n))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=(input())
num=[0]*len(N)

for i in range(len(N)-3):
    if int(N[i:i+4])%2019==0:
        num[i+3]+=1+num[i-1]

for i in range(len(N)-4):
    if int(N[i:i+5])%2019==0:
        num[i+4]+=1+num[i-1]


#print(num)
print(sum(num))

Submission status: Wrong Answer

Solution code:
# %%time
s = input()
c = 0
mod = 2019
s_int = list(map(int, list(s)))

i = 0
ms = []
m = int(s[i:i+4])
m = m%mod
if m == 0:
    c += 1
ms.append(m)
for k in range(i+4, len(s)):
    m = (m * 10 + s_int[k]) % mod
#         print(m)
    if m == 0:
        c += 1
    ms.append(m)

tens = [1]
for k in range(len(ms)):
    tens.append((tens[-1] * 10)%mod )
for k in range(len(ms)):
    for i in range(k + 1, len(ms)):
        m = (ms[i] - ms[k] * (tens[(i - k)]))%mod
        if m == 0:
            c += 1

print(c)

Submission status: Wrong Answer

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

S = input()

MAX = 200000

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

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

Submission status: Wrong Answer

Solution code:
S = input()
s = list(S)
print(s)
count = 0
for i in range(len(s)-2):
  for j in range(i+3,len(s)+1):
    if int("".join(s[i:j])) % 2019 == 0:
      count += 1
print(count)

Submission status: Wrong Answer

Solution code:
y = 2019
S = [s for s in input()]
T = [0] * len(S)
cnt = 0

right = len(S)
index = right - 1
while index >= 0:
    f = int(''.join(S[index:right])) % y == 0
    cnt += f
    if f:
        right = index + 1
        index = right - 1
        continue
    index -= 1
    
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
mods = []
crt = 0
if len(s) <= 4:
    print(0)
    exit()
# for i in range(len(s)):
#     crt = crt*10+int(s[i])
#     crt %= 2019
#     mods.append(crt)
# print(mods)
for i in range(len(s)-1,-1,-1):
    crt = crt+int(s[i])*pow(10, (len(s)-i-1), 2019)
    crt %= 2019
    mods.append(crt)
# print(mods)
ans = 0
ans += mods.count(0)
modst = set(mods)
ans += len(mods) - len(modst)
if mods[-1] == 0:
    print(ans+1-(mods.count(0)-1))
else:
    print(ans-(mods.count(0)-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 0
for i in range(N):
    amari = int(S[i])
    amaretu = []
    for j in range(i+1,N):
        amari = (10*amari + int(S[j]))%2019
        if amari == 0:
            ans += 1
        else:
            if amari in amaretu:
                break
            else:
                amaretu.append(amari)
print(ans)

Submission status: Wrong Answer

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

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

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()
ans=0
tmp=0
for i in range(len(S)):
    if i<tmp:
        continue
    for j in range(i+3,len(S)):
        if int(S[i:j+1]) %2019==0:
            ans+=1
            tmp=j
            break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

possible2 = []

for i in range(1, 99):
    possible2.append(int(str(i  * 2019)[0:2]))

possible2 = set(possible2)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s_n = str(n)
lenn = len(str(n))+1
res = []
for i in range(0,lenn):
    memo = 0
    for j in range(i+1,lenn):
        memo += int(s_n[j-1])
        if memo % 3 != 0:
            continue
        if int(s_n[i:j]) % 2019 == 0:
            res.append([i,j])
print(res)
print(len(res))

Submission status: Wrong Answer

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

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

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    S = input()

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

    # length = len(S)
    # l, r = 0, 4
    # while l < length-4:
    #     test = S[l:r]
    #     if int(test) % 2019 == 0:
    #         cnt += 1
    #     if r < length:
    #         r += 1
    #     else:
    #         l += 1
    #         r = l + 4

    length = len(S)
    l, r = 0, 4
    while l < length - 4:
        test = S[l:r]
        if int(test) % 2019 == 0:
            cnt += 1
        if l < r-4:
            l += 1
        else:
            r += 1

    
    # 出力
    print(cnt)

Submission status: Wrong Answer

Solution code:
s=input()
st=0
sums=0
for i in range(99):
    a=str(2019*(i+1))
    for j in range(len(s)-len(a)+1):
        for k in range(len(a)):
            if s[j+k]==a[k]:
                g=k
                if g==len(a)-1:
                    
                    st=st+1
            else:
                break
            
    
print(st)

Submission status: Wrong Answer

Solution code:
import sys

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

  

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 0
for i in range(N):
    amari = int(S[i])
    amaretu = []
    for j in range(i+1,N):
        amari = (10*amari + int(S[j]))%2019
        if amari == 0:
            print(i,j)
            ans += 1
        else:
            if amari in amaretu:
                break
            else:
                amaretu.append(amari)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
c = 0

# for i in range(len(str(s))):
#     for j in range(i+1, len(str(s))+1):
#         tmp = s[i:j]
#         if int(tmp) % 2019 == 0:
#             c += 1

for i in range(1, 100):
    t = i * 2019
    if t > 200000:
        break
    # print(t)
    # print(len(str(t)))
    len_t = len(str(t))
    for i in range(len(str(s)) - (len_t - 1)):
        tmp = s[i:i + len_t]
        if int(tmp) == t:
            c += 1
print(c)

Submission status: Wrong Answer

Solution code:
S = input()
l = len(S)
noCount = 0
fourDigi = {'2019', '4038', '6057', '8076'}
fiveDigi = {'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'}
fiveD2nd = {'0','2','4','6','8'}
sixDigi = {'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'}
if l == 4:
    for i in range(l-3):
        if S[i:i+4] in fourDigi:
            noCount += 1
elif l == 5:
    for i in range(l-3):
        if S[i:i+4] in fourDigi:
            noCount += 1
    for i in range(l-4):
        if S[i+1] in fiveD2nd:
            if S[i:i+5] in fiveDigi:
                noCount += 1
elif l >= 6:
    for i in range(l-3):
        if S[i:i+4] in fourDigi:
            noCount += 1
    for i in range(l-4):
        if S[i+1] in fiveD2nd:
            if S[i:i+5] in fiveDigi:
                noCount += 1
    for i in range(l-5):
        if S[i] == 1:
            if S[i:i+6] in sixDigi:
                noCount += 1

print(noCount)

Submission status: Wrong Answer

Solution code:
s=input()
num=int(s)
n=len(s)
count=0
for j in range(n-3):
	for i in range(4,n+1-j):
		nu = int(s[j:i+j])
		print(nu)
		if nu<2019:
			continue 
		if nu%2019==0:
			count+=1
			break
			
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
"""
2019 4038 6057 8076 10095
12114 14133 16152 18171
"""

s = input()
count = 0

ends = []

for i in range(len(s)-4):
  for j in range(4, len(s)-4):
    if int(s[i:i+j+1])%2019 == 0:
      count += 1
      c = 0
      for (k, l) in ends:
        if i == k:
          c += l
      ends.append((i+j+1, c+1))
      count += c
      break
  

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
S = list(input())
Count = 0
if len(S)<=4:
    print(0)
elif len(S)==5:
    if int("".join(S))%2019==0:
        print(1)
    else:
        print(0)
else:
    for w in (5,len(S)):
        for i in range(0,len(S)+1-w):
            if int("".join(S[i:i+w]))%2019==0:
                Count+=1
    print(Count)

Submission status: Wrong Answer

Solution code:
# cook your dish here
s = str(input())
n = len(s)
ans = 0
i = 0
st = 0
nm = 0
while i<n:
    nm*=10
    nm+=int(s[i])
    if(nm>=2019):
        if(nm%2019==0):
           # print(nm)
            ans+=1
        else:
            x = i-st;
            while(st<i):
                nm-=(int(s[st]))*(10**x)
                if((nm%2019==0)):
                   # print(nm)
                    ans+=1
                else:
                    st+=1
                    break
                x-=1
                st+=1
    i+=1

print(ans)

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

Solution code:
S=input()
ans=0
tmp=0
for i in range(len(S)):
    if i<tmp:
        continue
    for j in range(i+3,len(S)):
        if int(S[i:j+1]) %2019==0:
            ans+=1
            tmp=j
            break
    print(i,"i")
print(ans)

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

print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
s = int(input())
len = len(str(s))
s_list = list(str(s))
ans = 0
for i in range(len - 3):
    for j in range(i + 3, len):
        num_wk = s_list[i:i+j]
        num = ''.join(num_wk)
        if int(num) % 2019 == 0:
                ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
a = []
count = 0
for n in range(len(S)):
    a.append(10**n%2019)
for n in range(len(S)-3):
    z = int(S[-n-1])*a[0]+int(S[-n-2])*a[1]+int(S[-n-3])*a[2]+int(S[-n-4])*a[3]
    if z%2019 == 0:
        count += 1
    for m in range(len(S)-n-4):
        z += int(S[-m-5])*a[m+4]
        if z%2019 == 0:
            count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
        
ngram=[]
for i in range(5,7):
    for j in range(len(s)-i+1):
         ngram.append(s[j:j+i])

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

Submission status: Wrong Answer

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

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:
        digit_sum = sum(map(int, list(s[i:i+4]))) % 3
        j = i + 4
        while j < len(s):
            now = digit_sum + int(s[j]) % 3
            if now == 0 or now == 3:
                if int(s[i:j+1]) % 673 == 0:
                    # print(s[i:j+1], i, j)
                    count += 1
                    i = j
                    j = i + 3
                    digit_sum = sum(map(int, list(s[i:i + 4]))) % 3
            else:
                digit_sum = now % 3
            j += 1
        i += 1
    print(count)

Submission status: Wrong Answer

Solution code:
def main():
  s=input()
  l,mod=len(s),2019
  x=[0]*l
  x[0]=(int(s[0])*(pow(10,l-1)))%mod
  y=pow(10,l-2)
  for i in range(1,l):
    x[i]=((int(s[i])*y)%mod+x[i-1])%mod
    y//=10
  cnt=x.count(0)
  print(l-len(set(x))+cnt)
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
N = len(S)
sub_s = ""

total = 0

for l in range(N):  # 200000
    if l % 2 == 0:
        # 左から右に伸ばしていく
        sub_s = S[l]

        if int(sub_s) % 2019 == 0:
            total += 1
        r = l + 1
        while r < N:  # 末尾N-1まで
            sub_s += S[r]
            if int(sub_s) % 2019 == 0:
                total += 1
                # print((l, r))
                # print(sub_s)
            r += 1
    else:
        # 右を縮めていく
        # r = N  # 末尾から
        r = 1
        # while r > l:
        while r < (N - l):
            # sub_s = S[l:r]  # ここが重いはず
            sub_s = sub_s[:-r] # ここが重いはず

            if not sub_s:
                break
            if int(sub_s) % 2019 == 0:
                total += 1
                # print((l, r))
                # print(sub_s)
            # r -= 1
            r += 1
    # print("--------")

ans = total

print(ans)

Submission status: Wrong Answer

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

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

ans = 0
for search in s_list:
    start = -1
    while True:
        start = s.find(search, start + 1)
        if start != -1:
            ans += 1
        else:
            break

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, 100)]
ans = 0

for i in range(99):
    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)