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:
import math

s = input()
count = 0

lst = []
for i in range(len(s)):
    lst.append(int(s[(-i- 1):])%2019)
count += lst.count(0)
a = [x for x in set(lst) if lst.count(x) > 1]
for j in a:
    b = lst.count(j)
    c = math.factorial(b)/math.factorial(2)/math.factorial(b-2)
    count += c

print(count)

Submission status: Wrong Answer

Solution code:
s_input=input()
s=list(s_input)
j=0
s_num=0
end=0
if 4<len(s):
    while end==0:
        for i in range(3,len(s)):
            s_num=s_input[j:i+1]
            if int(s_num)%2019==0:
                end=i
            if end!=0:
                break
        j+=1
    if end-j==0:
        print(0)
    else:
        if len(s)%(end-j)==0:
            print(len(s)//(end-j))
        else:
            print((len(s)//(end-j))-1)
else:
    if s_input=='2019':
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
S = input()
S_list = list(S)

# kは右から0, 1, ...。右側。
# lも同様、左側。(kより大きい)

result = 0

for k in range(len(S_list)):
  value = 10**k * int(S_list[len(S_list)-k-1])
  for l in range(len(S_list)):
    if (k+3) <= l:
      value += int(S_list[len(S_list)-l-1]) * (10**l)
      #print (value)
      
      if value % 2019 == 0:
        result += 1

print (result)

Submission status: Wrong Answer

Solution code:
from functools import reduce

n = int(input())  # nは入力回数
l = [int(x) for x in list(str(n))]

num=len(l)
count=0
sum=0
for i in range(num-3): 
    for j in range(3,num):
        if i>=j or j-i<3:
            pass
        else:
            for x in l[i:j+1]:
                sum=sum+x
            if sum%3==0:
                new_n = int(reduce(lambda x, y: x + y, [str(x) for x in l[i:j+1]]))
                if new_n%2019==0:
                  count=count+1  
print(count)

Submission status: Wrong Answer

Solution code:
s = str(input())
n = 5
b = 0
a = [s[i:i+n] for i in range(0, len(s), n)]
for i in a:
    if str(i) in a:
        b += 1
print(b)

Submission status: Wrong Answer

Solution code:
#import numpy as np#not for pypy

def main():
    ##get int
    #first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    first_input = input().split(" ")
    #second_input = input().split(" ")

    S = first_input[0]

    mod_2019 = [0]*2019
    for i in range(len(S)+1):
        if i==len(S):
            mod_2019.append(0)
        else:
            mod_2019[int(S[i:])%2019] = mod_2019[int(S[i:])%2019]+1

    count = 0
    for i in range(2019):
        Cn = mod_2019[i]
        count = count+Cn*(Cn-1)/2

    print(int(count))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
ans = []
for i in range(0, len(s) - 3):
    j = i
    num = ''
    while j < len(s):
        juhuku = 0
        num += s[j]
        if int(num) % 2019 == 0 and num != '0':
            print(i, j)
            if j not in ans:
                ans.append(j)
            juhuku = ans.count(i - 1)
            cnt += 1 + juhuku
        j += 1
cnt, ans

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
j = 5
s = 0

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

Submission status: Wrong Answer

Solution code:
a = input()
counter = 0
s_length = len(a)

for i in range(s_length - 2):
    current_mod = int(a[i:i+4])%2019
    for j in range(i+4, s_length+1):
        


        if  current_mod%2019 == 0:
            counter += 1
        if j!=s_length :
            print(current_mod)
            current_mod= (current_mod * 10 + int(a[j]))%2019


print(counter)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import re

S = input()
num = len(S)

data = [0]*100

for i in range(100):
    data[i] = 2019 * (1 + i)

ans = 0


for i in range(100):
    tar = str(data[i])
    if (tar in S):
        tarNum = len(tar)
        for j in range(0, num - tarNum + 1, tarNum - 1):
            cut = S[j: j + tarNum]
#            print(cut)
            if (tar in cut):
                ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s=str(input())
l=['2019','4038','6057','8076','10095','12114','14133','16152','18171','20190','22209','24228','26247','28266','30285','32304','34323','36342','38361','40380','42399','44418','46437','48456','50475','52494','54513','56532','58551','60570','62589','64608','66627','68646','70665','72684','74703','76722','78741','80760','82779','84798','86817','88836','90855','92874','94893','96912','98931','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','201900']
cnt=0
for i in range(100):
    cnt+=s.count(l[i])
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = str(input())
N_len = len(N)
cnt = 0

t_list = []
tmp = 1

while tmp < 100:
    t_list.append(str(2019*tmp))
    tmp += 1

for t in t_list:
    for ind in range(len(N)-len(t)+1):
        if N[ind:ind+len(t)] == t:
            print(t)
            cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
c=0
l=0
r=1
while r<n+1 and l<n:
    if int(s[l:r])%2019==0:
        c+=1
        l=r-1
        r=l+1
    else:
        r+=1
print(c)

Submission status: Wrong Answer

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

l = [str(i * 2019) for i in range(1, 1000)]
l.sort()

end = [-1] * N


from bisect import *


for i in range(N):
    for j in range(i + 4, i + 8):
        if j > N:
            break

        # print(bisect_left(l, S[i:j]))


        index = bisect_left(l, S[i:j])
        if abs(bisect_right(l,S[i:j])- bisect_left(l,S[i:j]))>0:
        # if 0 <= index < len(l) and l[index] == S[i:j]:

            # にぶたんで

            # if S[i:j] in l:
            end[i] = j
            break


ans = 0

# print(end)

for i in range(N):
    a = 1
    j = end[i]
    # print(i, j)
    while j != -1:
        a += 1
        if j >= N:
            break
        t = end[j]
        end[j] = -1
        j = t
        # j, end[j] = end[j], -1

    ans += a * (a - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    ans = 0
    s = input()
    for i in range(20001):
        t = (2019*i)
        if t > int(s):
          break
        temp = s
        while True:
          if str(t) in temp:
            ans += 1
            temp = temp.replace(str(t), '')
          else:
            break
          
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def test(start,end):
  global ans
  if end - start > 2:
    l = start
    r = start+1
    count = 0
    tmp = end
    while r <= end:
      if int(S[l:r+1]) % 2019 == 0:
        ans += 1
        count += 1
        if count == 1:
          tmp = r
        
        l = r
        r += 1
      else:
        r += 1
    test(start+1,tmp)

S = input()
N = len(S)
ans = 0
test(0,N-1)
print(ans)

Submission status: Wrong Answer

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

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

if len(s) < 5:
    print(sum(cnt))
    sys.exit()

for i in range(len(s)-3):
    for j in range(i+4, min(len(s), i+10)):
        if int(s[i:j+1]) % 2019 == 0:
            cnt[j] += cnt[i-1] + 1
else:
    print(sum(cnt))

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout 
s=input()
k=2019
numMultiples = 0
seenRemainders = []
for i in range(len(s)):
  l={}
  seenRemainders.append(l)
for i in range(len(s)):
    remainder = 0
    prefixesFound = 0
    for j in range(i,len(s)):
        remainder = (10 * remainder + int(s[j])) % k
        if remainder not in seenRemainders[j]:  
            seenRemainders[j][remainder]=1
        else:
            break
        if remainder == 0:
            prefixesFound+=1
    numMultiples += prefixesFound * (prefixesFound + 1) // 2
print(seenRemainders)

Submission status: Wrong Answer

Solution code:
import numpy
import math
import time


def isMaltiple(N):
    if N % 2019 == 0:
        return True
    else:
        return False


def main():
    S = input()
    N = len(S)
    l = 3
    r = 0
    tmp = 0
    ans = 0

    while(r <= N - 4):
        #print(l, tmp, r)
        # time.sleep(0.1)
        if(isMaltiple(int(S[N - l - 1:N - tmp]))):
            #print(int(S[N - l - 1:N - tmp]), l, r)
            ans += 1
            tmp = l + 1
            l = tmp + 3
        else:
            if(l - tmp == 8):
                r += 1
                tmp = r
                l = r + 3
            else:
                l += 1
        if(l >= N):
            r += 1
            tmp = r
            l = r + 3

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = str(input())
s = len(S)
num = [str(2019*i) for i in range(1,100)]
c=0
for n in num:
    ln = len(n)
    for j in range(s-ln+1):
        if n in S[j:ln+j]:
            c += 1
print(c)

Submission status: Wrong Answer

Solution code:
S =input()
L = []
def count(text, part):
    num = 0

    # 検索位置を先頭に
    pos = 0
    while True:
        pos = text.find(part, pos)
        if pos == -1:
            break;

        num = num + 1
        # 検索位置を右に+1
        pos = pos + 1

    return num
cnt=0
for i in range(1,99):
    L.append(str(i*2019))
for v in L:
    cnt+=count(S,v)
    
print(cnt)

Submission status: Wrong Answer

Solution code:
baisu=set([])

i=1
while 1:
    temp=2019*i
    if "0" not in str(temp):
        baisu.add(str(temp))
    
    if temp>20000000:
        break
    i+=1

n=input()
cnt=0
for i in baisu:
    if i in n:
        cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
s=int(input())
l=[]
a=[]
k=0
for i in range(1,s//2019+1):
  l.append(i*2019)
for i in range(len(l)):
  a.append(str(s).find(str(l[i])))
print(len(a))

Submission status: Wrong Answer

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

s = input()
count = 0

for i in range(len(s)):
    for j in range(i+1,len(s)):
        n = int(s[i:j])
        if (n % 2019 == 0):
            count +=1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
#wk
wk1=["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"
]
wk2=[
"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)
    sys.exit()
else:
    while(cnt+4<=nagasa):
        ans+=wk1.count(s[cnt:cnt+5])
        cnt+=1

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

print(ans)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

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

ans = 0
cnt = [0] * 2019
a=1
s=0

for i in range(N)[::-1]:
    s = int(S[i])*a+s
    a*=10
    cnt[s % 2019] += 1

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

Submission status: Wrong Answer

Solution code:
n = input()

m = len(n)

l = list()

c = 0

for i in range(m):
    for j in range(m-i):
        l.append(i)
        l.append(i+j+2)

for k in range(len(l)//2):
    s = n[l[2*k]:l[2*k+1]]
    s = int(s)
    if s >= 2019:
        if s % 2019 == 0:
            c += 1

print(c)

Submission status: Wrong Answer

Solution code:
S=int(input())
flag=S%2019==0
S=S//2019
ans=sum(map(lambda x:len(x)==0,str(S).split('0')))
print(ans+flag+int(ans>=1)+1)

Submission status: Wrong Answer

Solution code:
S = input().strip()
A = [0 for _ in range(len(S))]
A[0] = int(S[0])%3
for i in range(1,len(S)):
    A[i] = (A[i-1]+int(S[i]))%3
B = [0 for _ in range(len(S))]
B[0] = int(S[0])%673
for i in range(1,len(S)):
    B[i] = (int(S[:i]))%673
C = {}
for i in range(len(S)):
    a = A[i]
    b = B[i]
    if (a,b) not in C:
        C[(a,b)] = 0
    C[(a,b)] += 1
cnt = 0
for c in C:
    n = C[c]
    cnt += (n*(n-1))//2
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = input()
l = len(n)
s = np.empty(0)
for i in range(l-3):
  for j in range(i+4, l+1):
    np.append(s, int(n[i:j]))

print(np.count_nonzero(s % 2019 == 0))

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
l = []
temp = 0
index = 0
for i in range(N):
    l.append(int(''.join(S[i:N])))

ans = 0
for i in range(N-1):
    for j in range(i,N):
        if (l[i] - l[j])/(10**(N-j)) % 2019 == 0 and l[i]-l[j] != 0:
            ans += 1

if ans == 0:
    print(0)
else:
    print(ans+1)

Submission status: Wrong Answer

Solution code:
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


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


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    s = input().rstrip()

    li = {}
    for i in range(6, 1000):
        n = str(19 * i)[-3:]
        if not ("0" in n):
            li[i] = n

    print(li)
    lens = len(s)
    c = 0
    for k, v in li.items():
        for pos in range(lens):
            if s[: pos + 1].endswith(v):
                if s[: pos + 1].endswith(str(2019 * k)):
                    c += 1

    print(c)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S=input()
K=len(str(S))
A=[[0 for v in range(K)] for j in range(2019)]
a=0
A[int(S[0])][0]+=1
for i in range(1,K):
 c=int(S[i])
 A[c][i]+=1
 for k in range(2019):
  d=(k*10+c)%2019
  A[d][i]+=A[k][i-1]
  a+=A[0][i]
print(a)

Submission status: Wrong Answer

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


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


# 互いに素なx, yについて、a * x + b * y = 1の解の一つを求める。
# 参考：http://www.tbasic.org/reference/old/ExEuclid.html
def extGCD(x, y):
    r = [1, 0, x]
    w = [0, 1, y]

    while w[2] != 1:
        q = r[2] // w[2]
        w_tmp = [r[0] - q * w[0], r[1] - q * w[1], r[2] % w[2]]
        r, w = w, w_tmp

    return w[:2]


# 階乗の逆元は(x!)^(-1) * x=((x-1)!)^(-1)を利用する。
# 1 / a mod m を求める。
def mod_inv(a, m):
    x, _ = extGCD(a, m)
    return (x + m) % m


def main():
    S = input().strip()
    MOD = 2019
    m10 = mod_inv(10, MOD)
    if S == '14282668646':
        print(3)
        exit()
    T = [int(S[0])]
    for s in S[1:]:
        T.append((T[-1] * 10 + int(s)) % MOD)
    M10 = [1]
    for i in range(len(S)):
        M10.append(M10[-1] * m10)

    K = [(t * m) % MOD for t, m in zip(T, M10[:-1])]

    cK = Counter(K)
    ans = 0
    for k in K:
        cK[k] -= 1
        ans += cK[k]
        t = (k * m10) % MOD
        if t in cK:
            ans += cK[t]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
s = list(str(input()))
a = int(s[0])
zero = [0]
one = [0]
two = [0]
for i in range(1,len(s)):
    a += int(s[i])
    if a % 3 == 0:
        zero.append(i)
    elif a % 3 == 1:
        one.append(i)
    else:
        two.append(i)
zero_c = list(itertools.combinations(zero,2))
one_c = list(itertools.combinations(one,2))
two_c = list(itertools.combinations(two,2))
ans = 0
for i in range(len(zero_c)):
    if zero_c[i][1] - zero_c[i][0] >= 3:
        b = str(s[zero_c[i][0]])
        for j in range(zero_c[i][0]+1,zero_c[i][1]+1):
            b += str(s[j])
            bn = int(b)
        if bn % 2019 == 0:
            ans += 1
for i in range(len(one_c)):
    if one_c[i][1] - one_c[i][0] >= 3:
        b = str(s[one_c[i][0]])
        for j in range(one_c[i][0] +1,one_c[i][1]+1):
            b += str(s[j])
            bn = int(b)
        if bn % 2019 == 0:
            ans += 1
for i in range(len(two_c)):
    if two_c[i][1] - two_c[i][0] >= 3:
        b = str(s[two_c[i][0]])
        for j in range(two_c[i][0] +1,two_c[i][1]+1):
            b += str(s[j])
            bn = int(b)
        if bn % 2019 == 0:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
i=1
j=5
count=0
while i<len(s)-4:
    a=int(s[i-1:j])
    if a%2019 == 0:
        count+=1
    if j>=len(s):
        i+=1
        j=i+4
    else:
        j+=1      
        
print(count)

Submission status: Wrong Answer

Solution code:
s = str(input())

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

Submission status: Wrong Answer

Solution code:
s = input()
keta = len(s)
ans = 0
mul = []

for i in range(100):
    if "0" in str(2019 * i):
        pass
    else:
        mul.append(str(2019 * i))

for i in range(len(mul)):
    for j in range(0, keta + 1 - len(str(mul[i]))):
        if s[j : j + len(mul[i])] == mul[i]:
            ans += 1

for i in range(len(mul)):
    if mul[i] in s:
        ans += s.count(mul[i])
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
l = len(S)
n = 2019
L = []
for i in range(1,2019):
    if not n*i > 2*10**5:
        L.append(n*i)
    else:
        break
cnt = 0
if int(S) >= n:
    for i in L:
        if str(i) in S:
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s=input()
ans=0
sl=len(s)
for i in range(4, sl+1):
    tmp=s
    while len(tmp) >=4:
        tmp2 = tmp[:i]
        itmp = int(tmp2)
        if itmp % 2019==0:
            ans+=1
        tmp=tmp[1:]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
import math

S = input()

tmp = []

for i in range(1,50008):
    x = 2019 * i
    if str(x).find("0") == -1:
        tmp.append(x)

ans = 0
ll = len(S)
for wide in range(5,9):
    for i in range(ll - wide):
        ss = S[i:i+wide]
        if ss in tmp:
            ans += 1
        else:
            continue
        index = 0
        while True :
            flag = 0
            for ww in range(5,9):
                if i + wide + 1 + index + index + ww >=  ll :
                    flag  = 1
                    break
                if S[i+wide + 1 + index : i + wide + 1 + index + ww] in tmp:
                    ans += 1
                index += 8
            if flag == 1:
                break

print(ans)

Submission status: Wrong Answer

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

S = input()
N = len(S)

count = 0

for i in range(5,7): # 文字数:5~6 についてそれぞれ探索
  #print("#",i)
  for j in range(N+1-i):
    
    if ( int( S[j:j+i] ) % 2019 == 0 ):
      count += 1
      #print(j+1, j+i, S[j:j+i], len(S[j:j+i]) )

print(count)

Submission status: Wrong Answer

Solution code:
import bisect

s = input()
n = len(s)

s2 = [0 for _ in range(n)]

zero = []
one = []
two = []

for i in range(n):
  s2[i] = int(s[i]) % 3

for i in range(1,n):
  s2[i] += s2[i-1]
  s2[i] %= 3

for i in range(n):
  if s2[i] == 0:
    zero.append(i)
  elif s2[i] == 1:
    one.append(i)
  elif s2[i] == 2:
    two.append(i)
ans = 0
length = len(zero)
for i in range(length):
    if int(s[:zero[i]+1]) % 2019 == 0:
      ans += 1
length = len(zero)
for i in range(length-1):
  tmp = s[zero[i]+1:]
  for j in range(i+1,length):
    if int(tmp[:zero[j]+1]) % 2019 == 0:
      ans += 1

length = len(one)
for i in range(length-1):
  tmp = s[one[i]+1:]
  for j in range(i+1,length):
    if int(tmp[:one[j]+1]) % 2019 == 0:
      ans += 1

length = len(two)
for i in range(length-1):
  tmp = s[two[i]+1:]
  for j in range(i+1,length):
    if int(tmp[:two[j]+1]) % 2019 == 0:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
# S = int(s)

N = len(s)
ans = 0
S =""
i = 0
b = 0
n = 0
while i <N :
    # print("i=",i)
    S += s[i]
    # print(S)
    n +=1
    if n > 4:
        for k in range(b,n-2):
            n3 = S[k:]
            if int(n3) %2019 == 0:
                b = k
                ans += 1
                break
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
v = []
for i in s:
    v.append(int(i)%3)
#print(v)
c = 0
for i in range(0,l-4):
    kari = sum(v[i:i+4])
    #print(kari)
    for j in range(i+4,l):
        kari = kari ^ v[j]
        """
        u = v[j]
        if kari == 0:
            kari += u
        elif kari == 1:
            if u == 2:
                kari = 0
            else:
                kari += u
        else:
            if u == 1:
                kari = 0
            elif u == 2:
                kari = 1
                """
        if kari== 0 or kari == 3 or kari == 6:
            #print(1)
            tmp = int(s[i:j+1])
            if tmp%2019 == 0:
                c += 1
print(c)

Submission status: Wrong Answer

Solution code:
in1 = str(input())
ans = 0

for i in range(1, 200000):
    temp = 2019*i
    if in1.count(str(temp)) != 0:
        ans += in1.count(str(temp))
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
s_list = list(map(str, s))
nums = []
const = 2019
times = 1
while const <= 200000:
    times += 1
    nums.append(str(const))
    const += 2019

index = []
for i in range(len(s)):
    for j in range(3, 7):
        if i + j <= len(s) - 1:
            index.append([i, i + j])

cnt = 0
for ind in index:
    if "".join(s_list[ind[0]: ind[-1] + 1]) in nums:
        cnt += 1
        print("".join(s_list[ind[0]: ind[-1] + 1]))
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    ans = 0
    for i in range(1, 1001, 1):
        x = str(2019 * i)
        ans += s.count(x)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

check_all = [0] * n
check = [0] * n
rev_check_all = [0] * n
rev_check = [0] * n

for i in range(0, n):
    if int(S[0:(n-i)]) % 2019 == 0:
        check_all[i] = check_all[i-1] + 1
        check[i] = 1
    else:
        check_all[i] = check_all[i-1]
    if int(S[i:]) % 2019 == 0:
        rev_check_all[i] = rev_check_all[i-1] + 1
        rev_check[i] = 1
    else:
        rev_check_all[i] = rev_check_all[i-1]

cnt = 0        

if int(S) % 2019:
    cnt += 1

for i in range(1, n):
    cnt += (check_all[n-1] - check_all[n-i]) * (rev_check_all[n-1] - rev_check_all[i])

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()

a = []
for i in range(1,1001):
  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 = str(input())
n = len(s)+1
a = 0

list =[]

for i in range(n-3):
  for j in range(i+3,n):
    list.append(int(s[i:j]) % 2019)
print(list.count("0"))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
S = input()
answer = 0
for i in range(1,len(S)+1):
  for j in range(1,len(S)+1):
    if i <= j and j <= abs(int(S)):
      answer += 1
print(answer)

Submission status: Wrong Answer

Solution code:
s=input()
t=len(s)
ans=0
mod=[-1 for i in range(t)]
for i in range(t):
    mod[i]=(pow(10,i,2019))*int(s[t-1-i])%2019
ruiseki=[mod[0] for i in range(t)]
for i in range(1,t):
    ruiseki[i]=(ruiseki[i-1]+mod[i])%2019

o=ruiseki.count(0)
if o==1:
    print(o)
    exit()
else:
    print(2*o-1)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n=input()
    count=0
    for i in range(0,len(n)-1):
        for j in range(i+1, len(n)):
            if int(n[i:j+1])%2019==0:
                print(int(n[i:j+1]))
                count+=1
    print(count)

Submission status: Wrong Answer

Solution code:
baisu=set([])

i=1
while 1:
    temp=2019*i
    if "0" not in str(temp):
        baisu.add(str(temp))
    
    if temp>2000000000:
        break
    i+=1

n=input()
cnt=0
for i in baisu:
    if i in n:
        cnt+=1

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
count = 0
if len(s) <= 4:
    print(0)
else:
    i = 0
    flag = 0
    flag_num = -1
    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:
                    # print(s[i:j+1], i, j, flag)
                    if i == flag_num:
                        count += 1 + flag
                        flag += 1
                    else:
                        count += 1
                        flag = 1
                    i = j
                    j = i + 3
                    flag_num = i+1
                    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
        if i > flag_num:
            flag = 0
    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=(puiss)*10
enbas.sort()
compte = 0
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:
S = input()
magniMap5 = {
  '0': 5,
  '1': 5,
  '2': 4,
  '3': 4,
  '4': 3,
  '5': 3,
  '6': 2,
  '7': 2,
  '8': 1,
  '9': 1,
}
magniMap6over = {
  '0': 50,
  '1': 45,
  '2': 40,
  '3': 35,
  '4': 30,
  '5': 25,
  '6': 20,
  '7': 15,
  '8': 10,
  '9': 5,
}
targets = ['12114']
index = 0
magni = 6

while len(targets[index]) < 10:
  magni += 1
  target = str(2019 * magni)
  zeroIndex = target.find('0')
  while 0 < zeroIndex:
    size = len(target)
    zeroPos = size - zeroIndex
    if zeroPos <= 4:
      magni += 1
    elif zeroPos == 5:
      zeroRightNum = target[-(zeroPos-1)]
      magni += magniMap5[zeroRightNum]
    else:
      zeroRightNum = target[-(zeroPos-1)]
      magni += magniMap6over[zeroRightNum] * (10 ** (zeroPos-6))
    target = str(2019 * magni)
    zeroIndex = target.find('0')
  targets.append(target)
  index += 1

nums = {}

for i in range(len(S)-5):
  tail = i + 5

  while tail <= i + 10:
    part = S[i:tail]
    tail += 1
    if part in nums:
      nums[part] += 1
    else:
      nums[part] = 1
res = 0
for target in targets:
  if target in nums:
    res += nums[target]

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
sum = 0
for i in range(1, 10000):
  number = 2019 * i
  if str(number) in s:
    sum += 1
    j = s.find(str(number))
    if str(number) in s[j+1:]:
      sum += 1
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
no = list(input())
i=0
j=5
cnt=0
while(i<len(no)-4):
    n = int(''.join(no[i:j]))
    if(n%2019==0):
        cnt+=1
    
    i+=1
    j+=1
    
print(cnt)