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:
# if the remainders (mod 2019) are equal, the difference will be divisible
# x = Q*2019+5 y = R*2019+5 then x-y=(Q-R)*2019
# unless Q-R<=0
# where the substring itself is (Q-R)*2019/10**(something)
# 2019 = 3*673 in prime factorization
# so multiplying by 10 doesn't affect whether a number is divisible by it
from collections import Counter
s = input()[::-1]
partial = 0
remainders = list()
for i, character in enumerate(s):
  partial = (partial+int(character)*pow(10, i, 2019))%2019
  remainders.append(partial)
histo = Counter(remainders)
non_single_count = int(sum(count*(count-1)/2 for value, count in histo.items() if value!=0))
single_count = int(sum(count for value, count in histo.items() if value==0))
print(non_single_count+single_count)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
Flag = []

for i in range(5,9):
    for j in range(len(S) + 1 - i):
        if int(S[j:j + i]) % 2019 == 0:
            Flag.append(j)
            ans += 1
num = 0
while len(Flag) > 0:
    i = Flag.pop(0)
    num += 1
    for j in range(4 * num + 5,4 * num + 9):
        if i + j > len(S):
            continue
        if int(S[i:i + j + 1]) % 2019 == 0:
            Flag.append(j)
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
S_str =input().strip()

#2019の倍数を定義　＜200000
baisu_2019 =[str(i*2019) for i in range(1,100)]

#
count=[]

for i in baisu_2019:
    indx=-1
    while True: 
        index_S =S_str.find(i,indx+1) #S_strの中に倍数があるか、あったら次はその隣から探す
        if index_S ==-1: #なかったら次の倍数
            break
        else:
            if indx != index_S: #同じindexはカウントしない
                count.append(i)
                indx = index_S
            else:
                break
print(len(count))

Submission status: Wrong Answer

Solution code:
def main(S=None):
    if not S:
        S = input()
    r = {k: 0 for k in range(0, 2019)}
    r[0] = 1
    tmp = 0
    base = 1
    for i, s in enumerate(S[::-1]):
        s = int(s) * base
        base *= 10
        tmp += s
        tmp %= 2019
        r[tmp] += 1
    count = 0
    for k, v in r.items():
        if v > 1:
            print(k, v)
        count += v*(v-1)//2
    print(count)
    return count


if __name__ == "__main__":
    # assert main("1817181712114") == 3
    # assert main("14282668646") == 2
    main()

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 my_index(l, x, default=False):
    if x in l:
        return [n for n, v in enumerate(l) if v == x]
    else:
        return []


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

    l = []
    for i in range(len(s) - 2):
        l.append(s[i : i + 3])

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

    c = 0
    for k, v in d.items():
        index = my_index(l, v)
        if len(index) != 0:
            for i in index:
                if s[: i + 3].endswith(str(2019 * k)):
                    c += 1

    print(c)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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 S[i:j] in l:
        if bisect_right(l, S[i:j]) - bisect_left(l, S[i:j]) > 0:
            end[i] = j
            break


ans = 0

for i in range(N):
    a = 1
    e = end[i]
    while e != -1:
        a += 1
        if e >= N:
            break

        t = end[e]
        end[e] = -1
        e = t

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

print(ans)

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 i in range(1,100):
    n = str(2019*i)
    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()
S_l = len(S)
MOD = 2019
l = [0]*200000
ans = 0


for start in range(0,S_l-3):
  for k in range(0,4):
    end = start+3+k
    if end>=S_l:
      break
    
    s = S[start:end+1]
    if int(s)%MOD==0:
      ans+=1
      l[end]+=1
      if start>=4:
        ans+=l[start-1]
        l[end]+=l[start-1]
        
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
s=input()
total=0
for i in range(0,len(s)-2):
  for j in range(i+4,len(s)+1):
    d=int(s[i:j])
    if d%2019==0:
      total+=1
print(total)

Submission status: Wrong Answer

Solution code:
# if the remainders (mod 2019) are equal, the difference will be divisible
# x = Q*2019+5 y = R*2019+5 then x-y=(Q-R)*2019
# unless Q-R<=0
# where the substring itself is (Q-R)*2019/10**(something)
# 2019 = 3*673 in prime factorization
# so multiplying by 10 doesn't affect whether a number is divisible by it
from collections import Counter
s = input()[::-1]
partial = 0
remainders = list()
for i, character in enumerate(s):
  if character == "3" or character == "6":
    partial = (partial+int(character)*10**i)%2019
  else:
    partial = (partial+int(character)*pow(10, i, 2019))%2019
  remainders.append(partial)
histo = Counter(remainders)
non_single_count = int(sum(count*(count-1)/2 for value, count in histo.items() if value!=0))
single_count = int(sum(count for value, count in histo.items() if value==0))
print(non_single_count+single_count)

Submission status: Wrong Answer

Solution code:
S=input()
cnt=0

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

for n in range (4,len(S)):
    for m in range((len(S)//2)-1):
        if int(S[m:m+n])%2019==0:
            cnt+=1
        else:
            cnt+=0
        
        if int(S[(-n-m):(-1-m)])%2019==0:
            cnt+=1
        else:
            cnt+=0

print(cnt)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

counter = 0
for n in range(4, l):
    for i in range(l-3):
        try:
            if (i+n) < l:
                if int(S[i:i+n+1]) % 2019 == 0:
                    counter += 1
                    print(S[i:i+n+1])
        except:
            pass

print(counter)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
s=input()
total=0
for i in range(0,len(s)-2):
  for j in range(i+4,len(s)+1):
    d=int(s[i:j])
    if d%2019==0:
      total+=1
print(total)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

l = [int(s[i:]) % 2019 for i in range(len(s))]
d = {}

for i in l:
  d[i] = d.get(i, 0) + 1
  
for i in d:
  count += d[i]*(d[i]-1)//2

print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

S = input()
P = 2019
N = len(S)
num = [0] * P
num[0] = 1
c = 0
ans = 0
dgt = 0
for i in range(N-1, -1, -1):
    c = (c + int(S[i]) * 10**dgt) % P
    dgt += 1
    dgt %= P
    ans += num[c]
    num[c] += 1
 
print(ans)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

Solution code:
#いけそう
#atcoder 
import itertools
s = input();
ans = 0;

list_ = range(len(s));
a = list(itertools.permutations(list_, 2))

for c,d in a:
    if d > c:
        if int(s[c:d]) % 2019 == 0 :
            ans += 1;
      
print(ans)

Submission status: Wrong Answer

Solution code:
#D - Multiple of 2019
S = str(input())
cnt =0
DP =[]
DP2 = []
n = 2019
m = 1

for i in range(99):
    DP.append(2019*(i+1))



for j in range(len(DP)):
    DP2.append(S.count(str(DP[j])))


print(sum(DP2))

Submission status: Wrong Answer

Solution code:
import collections

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

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

c = collections.Counter(l)

values, counts = zip(*c.most_common())
counts = list(counts)

ans = 0
for i in range(len(counts)):
    if counts[i] != 1:
        ans += cmb(counts[i], 2)
        
    
'''
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:
#D - Multiple of 2019
S = str(input())
cnt =0
DP =[]
DP2 = []
n = 2019
m = 1

for i in range(99):
    DP.append(2019*(i+1))
print(DP)



for j in range(len(DP)):
    DP2.append(S.count(str(DP[j])))


print(sum(DP2))

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
    a = a%2019
    cnt[s % 2019] += 1
    s=s%2019

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

S = input()

ans = 0
mod_list = [0] * len(S)
mod_list[-1] = int(S[-1])
m = 1
for i in range(2, len(S) + 1):
    m = (10 * m) % 2019
    mod_list[-i] = (mod_list[-i + 1] + (int(S[-i]) * m)) % 2019

mod_counter = Counter(mod_list)

ans = mod_counter[0]
mod_counter[0] -= 1
for i in range(1, len(mod_list) + 1):
    num = mod_list[-i]
    mod_counter[num] -= 1
    cnt = mod_counter[num]
    ans += cnt if cnt > 0 else 0


print(ans)

Submission status: Wrong Answer

Solution code:

k=2019
s=list(map(int,list(input())))
ans=0
if k==2 or k==5:
    for i,p in enumerate(s):
        if p%k==0:
            ans+=i+1
else:
    inv10=pow(10,k-2,k)
    inv=10
    total=0
    S=[0]*k
    S[0]=1
    for i,p in enumerate(s):
        inv*=inv10
        inv%=k
        total+=p*inv
        total%=k
        ans+=S[total]
        S[total]+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
st = input()
ans = 0
n = len(st)
dic = {
    4 : ['2019', '4038', '6057', '8076'],
    5 : ['10095', '12114', '14133', '16152', '18171', '20190', '22209', '24228', '26247', '28266', '30285', '32304', '34323', '36342', '38361', '40380', '42399', '44418', '46437', '48456', '50475', '52494', '54513', '56532', '58551', '60570', '62589', '64608', '66627', '68646', '70665', '72684', '74703', '76722', '78741', '80760', '82779', '84798', '86817', '88836', '90855', '92874', '94893', '96912', '98931'],
    6 : [ '100950', '102969', '104988', '107007', '109026', '111045', '113064', '115083', '117102', '119121', '121140', '123159', '125178', '127197', '129216', '131235', '133254', '135273', '137292', '139311', '141330', '143349', '145368', '147387', '149406', '151425', '153444', '155463', '157482', '159501', '161520', '163539', '165558', '167577', '169596', '171615', '173634', '175653', '177672', '179691', '181710', '183729', '185748', '187767', '189786', '191805', '193824', '195843', '197862', '199881']

}
dic_st = {
    4 : [st[:4]],
    5 : [st[:5]],
    6 : [st[:6]]
}
temp_st1 = st[:4]
temp_st2 = st[:5]
temp_st3 = st[:6]

for i,v in enumerate(st[4:],4):
    temp_st1 = temp_st1[1:]+st[i]
    dic_st[4].append(temp_st1)
for i,v in enumerate(st[5:],5):
    temp_st2 = temp_st2[1:] + st[i]
    dic_st[5].append(temp_st2)
for i,v in enumerate(st[6:],6):
    temp_st3 = temp_st3[1:] + st[i]
    dic_st[6].append(temp_st3)


#print(dic_st)
for key,val in dic.items():
    p = key
    for value in val:
        x = 0
        i = 0
        for i in range(n-p+1):
            #print(p,i,dic_st[p][i],value)
            if dic_st[p][i] == value:
                x += 1
                i += p-1
        ans += x
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    L = len(S)
    amari = [0] * L
    for i in range(L):
        amari[i] = int(S[i:])%2019
    c = Counter(amari)
    ans = 0
    for n in c.values():
        ans += n*(n-1)//2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
A =str(input())


N = int(len(A))

S = 0

for i in range(N):
      
      x = (A[-(i+0)])
      
      y = int(x)
      
      if y % 2019 == 0:
            
            S += 1

print(int(S))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
s=input()
d=defaultdict(int)
for i in range(1,len(s)+1):
    d[int(s[-i:])%2019] += 1
ans=0
for v in d.values():
    ans += v*(v-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
count = 0
for i in range(len(S)):
  if int(S[i]) <= 1:
    for j in range(i+1,i+7):
      if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
        count = count + 1
        if j >= len(S):
          break
  if int(S[i]) >= 2:
    if int(S[i:i+6]) == 200000:
      for j in range(i+1,i+7):
        if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
          count = count + 1
          if j >= len(S):
            break
    else:
      for j in range(i+1,i+6):
        if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
          count = count + 1
          if j >= len(S):
            break
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

for i in range(len(s)- 3):
  if (int(s[0]) == 2 or int(s[0]) == 4 or int(s[0]) == 6 or int(s[0]) == 8) or (int(s[0:2]) == 10 or int(s[0:2]) == 12 or int(s[0:2]) == 14 or int(s[0:2]) == 16 or int(s[0:2]) == 18):
    for j in range(len(s) - 3 - i):
      sli = s[i:i + j + 4]
      if((int(sli) % 2019) == 0):
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
S = list(input())
multiple = []
letter_4 = []
letter_5 = []
letter_6 = []
for i in range(1,200000//2019+1):
  multiple.append(str(2019*i))

for i in range(len(S)-3):
  letter_4.append(''.join(S[i:i+4]))
for i in range(len(S)-4):
  letter_5.append(''.join(S[i:i+5]))
for i in range(len(S)-5):
  letter_6.append(''.join(S[i:i+6]))  

letter_joined = letter_4 + letter_5+letter_6

ansnum = []
for i in multiple:
    for j in letter_joined:
        if i == j:
            ansnum.append(i)
print(len(ansnum))

'''
print(multiple)
print(letter_joined)
print(ansnum)
'''

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

j=[[[] for k in range(10)] for i in range(3)]
for i in range(50):
    jjj=2019*i
    if "0" not in str(jjj):
        j[0][jjj%10].append(str(jjj))
for i in range(50,552):
    jjj=2019*i
    if "0" not in str(jjj):
        j[1][jjj%10].append(str(jjj))
for i in range(552,1000):
    jjj=2019*i
    if "0" not in str(jjj):
        j[2][jjj%10].append(str(jjj))
s=ns()
co=0
if len(s) > 4:
    jc=[s[0:5],s[1:6],s[0:6]]
    jp=int(s[4])
    if jc[0] in j[0][jp]:
       co += 1
    jp=int(s[5])
if len(s)>5:
    if jc[1] in j[0][jp]:
        co += 1
    if jc[2] in j[1][jp]:
     co += 1
if len(s)>6:
    for i in range(len(s)-6):
        jp=int(s[i+6])
        jc=[s[i+2:i+7],s[i+1:i+7],s[i:i+7]]
        for k in range(3):
            if jc[k] in j[k][jp]:
                co+=1
print(co)

Submission status: Wrong Answer

Solution code:
def main():
    s=list(map(int,input()))
    modpow=[1]*len(s)
    for i in range(1,len(s)):
        modpow[i]=(modpow[i-1]*10)%2019
    ans=0
    res=[0]*len(s)
    res[0]=s[-1]%2019
    for i in range(1,len(s)):
        res[i]=(modpow[i]*s[len(s)-1-i]+res[i-1])%2019
    res.sort()
    res.append(2019)
    cnt=0
    for i in range(len(s)-1):
        if res[i]==0:
            ans+=1+cnt
            cnt+=1
        elif res[i]==res[i+1]:
            cnt+=1
        elif i>0 and res[i-1]!=0:
            ans+=cnt*(cnt+1)//2
            cnt=0
        else:
            cnt=0
    print(ans)
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = int(input())
P = 2019

N = len(str(S))

li = [(S % pow(10, (N - i))) for i in range(N)]
li2 = [0 for i in range(P)]

for i in li:
  li2[i % P] += 1

t = 0
for i in li2:
  if i == 0 or i == 1:
    pass
  else:
    t += i * (i -1) // 2

print(t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

if __name__ == '__main__':
    MOD = 2019
    strS = input()
    S = [int(s) for s in strS]
    N = len(S)

    dp1 = [float('inf') for _ in range(N)]

    for i in range(N):
        if i == 0:
            dp1[0] = S[0] % MOD
        else:
            dp1[i] = (dp1[i - 1] * 10 + S[i]) % MOD

    dp2 = [float('inf') for _ in range(N)]
    for i in range(N - 1, -1, -1):
        if i == N - 1:
            dp2[i] = S[i] % MOD
        else:
            dp2[i] = (dp2[i + 1] + S[i] * 10 ** (N - 1 - i)) % MOD

    # print(dp1)
    # print(dp2)

    ans_idx = set()

    for i, mod_val in enumerate(dp1):
        if mod_val == 0:
            tmp_idx = 0
            while tmp_idx <= N - 1:
                if tmp_idx + i > N - 1:
                    print(tmp_idx + i)
                    break
                ans_idx.add((tmp_idx, tmp_idx + i))
                tmp_idx += i

    for i, mod_val in enumerate(dp2):
        if mod_val == 0:
            tmp_idx = i

            while tmp_idx >= 0:
                ans_idx.add((tmp_idx, tmp_idx + N - i - 1))
                tmp_idx -= (N - i - 1)

    print(len(ans_idx))

Submission status: Wrong Answer

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

def count_all(text, part):
    t = sum(1 for x in range(len(text)) if text[x:].startswith(part))
    return t

S = input()
I = 2019
count = 0

while I < 200000:
    if '0' in str(I):
        pass
    else:
        count += count_all(S,str(I))
    I += 2019
print(count)

Submission status: Wrong Answer

Solution code:
S = list(input())
count =0
mark =[]
ct=0
st =0
end =1
while end < len(S)-1:
    
    T =S[st:end]
    #print(T)
    #print(''.join(T))
    tmp=''.join(T)
    n = int(tmp)
#ct += int(S[end -1])
    if n % 3 == 0:
        mark.append(end)
        st = end+1
        end = st+1
    else:
        end += 1

for i in range(len(mark)):
    for j in range(i, len(mark)):
        T=S[mark[i]-1 :mark[j]]
        tmp=''.join(T)
        n = int(tmp)
        if n % 673 ==0:
            count +=1
            
print(count)

Submission status: Wrong Answer

Solution code:
ins = input()

from functools import lru_cache
@lru_cache(maxsize=None)
def binary(n):
    return bin(n)[2:]

@lru_cache(maxsize=None)
def pow_by_binary_exponentiation(a, x, n): # a^x mod n
    if x == 0:
      return 1
    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

s_mod = set()
count = 0
pre_amari = 0
for i, s in enumerate(reversed(ins)):
  amari = (int(s) * pow_by_binary_exponentiation(10, i, 2019) + pre_amari) % 2019
  pre_amari = amari
  if amari == 0:
    count += 1
  else:
    if amari in s_mod:
      count += 1
    else:
      s_mod.add(amari)

print(count)

Submission status: Wrong Answer

Solution code:


def main(S=None):
    if not S:
        S = input()
    r = {x: 0 for x in range(0, 2019)}
    r[0] = 1
    tmp = 0
    base = 1
    for i, s in enumerate(S[::-1]):
        s = int(s) * base
        base *= 10
        tmp += s
        tmp %= 2019
        if s != 0:
            r[tmp] += 1
    count = 0
    for k, v in r.items():
        count += v*(v-1)//2
    return count


if __name__ == "__main__":
    # assert main("1817181712114") == 3
    # assert main("14282668646") == 2
    # assert main("2019") == 1
    # assert main("20190") == 2
    # assert main("10") == 0
    main()

Submission status: Wrong Answer

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

ans = 0
count = [0] * P
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
  print(i,s)
  u = (int(s) * pow(10, i, P) + u) % P
  ans += count[u]
  count[u] += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

ans = 0

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


print(ans)

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%2019)*10
enbas.sort()
compte = 0
i = 0
avant = 0
zero = 0
for n in range(a+1):
  if enbas[n]==0:
    zero+=1
  if avant==enbas[n]:
    i+=1
  else:
    compte+=c(i)
    avant = enbas[n]
    i = 1
print(compte+zero)

Submission status: Wrong Answer

Solution code:
S = input()
if len(S) < 4:
    print(0)
    exit(0)
dp = [0]*2019
dp[0] = 1
s = int(S[-1])
dp[s] = 1
ans = 0
for k in range(len(S)-2,-1,-1):
    s = int(S[k])*(pow(10,len(S)-k-1,2019)) + s
    s %= 2019
    if dp[s] > 0:
        ans += 1
    else:
        dp[s] = 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
from functools import lru_cache
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())

@lru_cache(maxsize=None)
def temp(n):
    return 10**i%2019

s = list(map(int,list(input())[:-1]))
n=len(s)
right = [0] * (n + 1)
for i in range(n):
    right[-i - 2] = (right[-i - 1] + s[-i-1] * temp(i)) % 2019
log = defaultdict(lambda: 0)
ans=0
# for i in range(n + 1):
#     log[right[-i - 1]] += 1
#     value = log[right[-i - 1]]
#     if value!=1:
#         ans+=2*(value-1)-1
print(ans)

Submission status: Wrong Answer

Solution code:
lst = []
for i in range(100):
    if "0" in str(i*2019):
        continue
    else:
        lst.append(str(i*2019)) 

S = str(input())

res = 0
for j in lst:
    if j in S:
        res += S.count(j)
        print(j)

print(res)

Submission status: Wrong Answer

Solution code:
S = input()
# 逆
S_reversed = S[::-1]
# print(S_reversed)

count = 0

i = 0
while len(S_reversed) > i:
    if int((S_reversed[:i+1])[::-1]) % 2019 == 0:
        count += 1
        # print(i)
        # print(int(S_reversed[:i+1][::-1]))
        S_reversed = S_reversed[i:]
        # print(S_reversed)
        i = 0
    else:
        i += 1

print(count)

Submission status: Wrong Answer

Solution code:
# D - Multiple of 2019

S = input()
N = len(S)
cnt = 0

for i in range(N):
    for j in range(i + 3, i + 5):
        if int(S[i:j + 1]) % 2019 == 0:
            cnt += 1

print(cnt)

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


ans+=ruiseki.count(0)
for i in range(2019):
    o=ruiseki.count(i)
    if o>=2:
        ans+=o-1
print(ans)

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

Submission status: Wrong Answer

Solution code:
S = list(input())
multiple = []
letter_4 = []
letter_5 = []
for i in range(1,200000//2019+1):
  multiple.append(str(2019*i))

for i in range(len(S)-3):
  letter_4.append(''.join(S[i:i+4]))

for i in range(len(S)-4):
  letter_5.append(''.join(S[i:i+5]))

letter_joined = letter_4 + letter_5
ansnum = []
for i in multiple:
    for j in letter_joined:
        if i == j:
            ansnum.append(i)

print(len(ansnum))

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)-4):
  tail = i + 5

  while tail <= i + 10 and tail <= len(S):
    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:
ins = input()

from functools import lru_cache
@lru_cache(maxsize=None)
def binary(n):
    return bin(n)[2:]

@lru_cache(maxsize=None)
def pow_by_binary_exponentiation(a, x, n): # a^x mod n
    if x == 0:
      return 1
    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

#n = int(s)
#ln = [n % 10**i for i in range(1, j+1)]
s_mod = set()
count = 0
pre_amari = 0
for i, s in enumerate(reversed(ins)):
  amari = (int(s) * pow_by_binary_exponentiation(10, i, 2019) + pre_amari) % 2019
  pre_amari = amari
  if amari == 0:
    count += 1
  else:
    if amari in s_mod:
      count += 1
    s_mod.add(amari)

print(count)

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    N = len(S)
    M = len(S)

    res = 0

    i = 0
    test = True

    while test:
        for d in range(4,N-i+1):
            temp = S[i:i+d]
            # print(temp,i,d)
            temp = int(temp)
            if temp % 2019 == 0:
                res += 1
                i = i + d - 1
                break
            elif d == N - i:
                i += 1
                break
            if i >= N-3:
                test = False
        if i >= N-3:
            test = False

    print(res)



main()

Submission status: Wrong Answer

Solution code:
S = input()
ret = 0
iS = [int(s) for s in S]

flag = False
for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        if j == i + 4:
            if i == 0:
                sum_num0 = sum(iS[i:j])
            else:
                sum_num0 = sum_num0 - iS[i-1] + iS[j-1]
            sum_num = sum_num0
            if int(S[i:j]) != 2019:
                continue
        else:
            sum_num += iS[j-1]
        if flag:
            if iS[j-1] % 3 == 0:
                test = int(S[i:j]) // 3
                if test % 673 == 0:
                    ret += 1
            else:
                flag = False
        if sum_num % 3 == 0:
            flag = True
            test = int(S[i:j]) // 3
            if test % 673 == 0:
                ret += 1
print(ret)