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:
from sys import stdin
#import numpy as np


def merge_sort(lst, low, high):
    if low >= high:
        return
    mid = int((low+high)/2)
    merge_sort(lst, low, mid)
    merge_sort(lst, mid+1, high)
    for i in range(low, mid+1):
        tmp_array[i] = lst[i]
    j = high
    for i in range(mid+1, high+1):
        tmp_array[i] = lst[j]
        j -= 1
    i = low
    j = high
    for k in range(low, high+1):
        if tmp_array[i] <= tmp_array[j]:
            lst[k] = tmp_array[i]
            i += 1
        else:
            lst[k] = tmp_array[j]
            j -= 1


S = stdin.readline().rstrip()
N = len(S)
Sp = S

res_map = [0 for _ in range(N)]

aa_list2 = [1]
for i in range(1,N):
    aa_list2.append((aa_list2[i-1]*10)%2019)

tmp_array = [None for _ in range(N)]
res_map[N-1] = int(S[N-1])
index=1
for i in range(N-2,-1,-1):
    res_map[i] = (int(S[i])*aa_list2[index] + res_map[i+1])%2019
    index+=1

res_map.sort()
temp_num=int(res_map[0])
index=1
tot = 0

aa_table = [0 for i in range(2019)]
#for i in range(len(res_map)):
#    aa_table[res_map[i]]+=1

#aa_table[0]+=1

#sort check
for i in range(1,N):
    if res_map[i]<res_map[i-1]:
        aiejfaoijfoa

for i in range(1,N):
    if temp_num==int(res_map[i]):
        index+=1
        continue
    else:
        aa_table[temp_num] = index
        index=1
        temp_num=int(res_map[i])

aa_table[0] += 1 
#        if temp_num==0:
#            tot += int(index*(index+1)/2)
#        elif index>1:
#            tot += int(index*(index-1)/2)
#        index=1
#        temp_num=int(res_map[i])


tot = 0
for i in range(2019):
    tot+=int((aa_table[i]-1)*aa_table[i]/2)



#for i in range(2018):
#    num = np.sum(np.array(res_map)==i)
#    if i ==0:
#        num+=1
#    tot += int(num*(num-1)/2)
    

print(tot)

Submission status: Wrong Answer

Solution code:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10

for i in reversed(range(1,N,1)):
    tmp=tmp*10

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [0] * 2050
for i in range(200010):
  a[N%2019] += 1
  N //= 10
  if N <= 0:
    break
ans = 0
for i in range(2019):
  if i == 0:
    ans += a[i] * (a[i]+1) // 2
  else:
    ans += (a[i]-1) * a[i] // 2
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10

for i in reversed(range(1,N,1)):
    #S_num[i-1] = S_num[i] + (tmp)*S_num[i-1]
    #tmp=tmp*10
    tmp = tmp

Submission status: Wrong Answer

Solution code:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10

for i in reversed(range(1,N,1)):
    #S_num[i-1] = S_num[i] + (tmp)*S_num[i-1]
    tmp=tmp*10

Submission status: Wrong Answer

Solution code:

S = list(map(int, list(input())))

mod = 2019
ctr = [0] * mod
p = 1
t = 0
for i, v in enumerate(reversed(S)):
    t = (t + int(v) * pow(10, i, mod)) % mod
    ctr[t] += 1

ans = ctr[0]
for v in ctr[1:]:
    ans += v * (v - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
#import numpy as np


def merge_sort(lst, low, high):
    if low >= high:
        return
    mid = int((low+high)/2)
    merge_sort(lst, low, mid)
    merge_sort(lst, mid+1, high)
    for i in range(low, mid+1):
        tmp_array[i] = lst[i]
    j = high
    for i in range(mid+1, high+1):
        tmp_array[i] = lst[j]
        j -= 1
    i = low
    j = high
    for k in range(low, high+1):
        if tmp_array[i] <= tmp_array[j]:
            lst[k] = tmp_array[i]
            i += 1
        else:
            lst[k] = tmp_array[j]
            j -= 1


S = stdin.readline().rstrip()
N = len(S)
Sp = S

res_map = [0 for _ in range(N)]

aa_list2 = [1]
for i in range(1,N):
    aa_list2.append((aa_list2[i-1]*10)%2019)

tmp_array = [None for _ in range(N)]
res_map[N-1] = int(S[N-1])
index=1
for i in range(N-2,-1,-1):
    res_map[i] = (int(S[i])*aa_list2[index] + res_map[i+1])%2019
    index+=1

res_map.sort()
temp_num=int(res_map[0])
index=1
tot = 0

for i in range(1,N):
    if temp_num==int(res_map[i]):
        index+=1
        continue
    else:
        if temp_num==0:
            tot += int(index*(index+1)/2)
        elif index>1:
            tot += int(index*(index-1)/2)
        index=1
        temp_num=int(res_map[i])


#for i in range(2018):
#    num = np.sum(np.array(res_map)==i)
#    if i ==0:
#        num+=1
#    tot += int(num*(num-1)/2)
    

print(tot)

Submission status: Wrong Answer

Solution code:


s = 0

def format_input(filename = None):
	global s
	if filename == None:
		s = int(input())

	elif filename == '__random__':
		from random import randint as rng
		from random import choices
		s = int(''.join(choices('123456789', k = rng(1, 2 * 10**5))))
		print(s)

def get_answer():
	s_list = []
	str_s = str(s)
	for i in range(len(str(s))):
		s_list.append(int(str_s[-1]))
		str_s = str_s[:-1]

	cum_sum = [0]
	for i in range(len(str(s))):
		cum_sum.append((s_list.pop() + cum_sum[-1] * 10) % 2019)

	answer = len(cum_sum) - len(set(cum_sum))
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10

for i in reversed(range(1,N,1)):
    S_num[i-1] = S_num[i] + (tmp)*S_num[i-1]
    tmp=tmp*10

Submission status: Wrong Answer

Solution code:
S = input()

n_i_to_j_mod = [0] * (2019+1) # 2019で割った余りがiになるようなSの部分連続文字列の個数
i_to_end_mod = [0] * (len(S)+1) # S[-i:](Sの後方i文字)を2019で割ったときの余り

tmp = ""
for i in range(1, len(S)+1):
    if i == 1:
        i_to_end_mod[1] = int(S[-1]) % 2019
    else:
        i_to_end_mod[i] = (i_to_end_mod[i-1] + int(S[-i]) * pow(10, i-1, 2019)) % 2019
    n_i_to_j_mod[i_to_end_mod[i]] += 1

ans = n_i_to_j_mod[0]
for i in range(1, 2020):
    if n_i_to_j_mod[i] >= 2:
        ans += (n_i_to_j_mod[i] * (n_i_to_j_mod[i]-1)) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
a=0
l=[0]*2019
for i in list(s):
    a=(a*10+int(i))%2019
    l[a]+=1
ans=0
for i in l:
    ans+=(i-1)*i//2
print(ans+l[0])

Submission status: Wrong Answer

Solution code:

S = input()

mod = 2019
ctr = [0] * mod
p = 1
t = 0
for v in reversed(S):
    t = (t + int(v) * p) % mod
    ctr[t] += 1
    p *= 10

ans = ctr[0]
for v in ctr[1:]:
    ans += v * (v - 1) // 2
print(ans)

Submission status: Wrong Answer

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

countdic = {}
mod = 2019

for i in range(1,n+1):
    num = int(s[n-i:n])
    remainder = num%mod
    if remainder in countdic:
        countdic[remainder] += 1
    if remainder not in countdic:
        countdic[remainder] = 1

ans = 0
for key in countdic:
    ans += countdic[key]*(countdic[key]-1)//2
    if 0 in countdic:
        ans += countdic[0]

print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10

for i in range(1,N,1):
    S_num[N-i-1] = S_num[N-i]%2019 + (tmp)*S_num[N-i-1]%2019
    tmp=tmp*10

Submission status: Wrong Answer

Solution code:
a=input()
list1=[]
current_num=int(a[-1])%2019
length=len(a)
list1.append(current_num)
for i in range(2,len(a)) :
    
    current_num=(int(a[-i]) * 10 + current_num) % 2019
    list1.append(current_num)
count=0



count=0
list1.append(0)
import collections
c=collections.Counter(list1)
list2=c.values()
count=0
for item in list2 :
    count+=(int(item*(item-1)/2))


print(count)

Submission status: Wrong Answer

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

l = [0] * 2019
index = 0
temp = 0
for i in range(N-1, -1, -1):
    temp += int(S[i]) * pow(10,index, 2019)
    temp %= 2019
    l[temp] += 1
    index += 1

ans = l[0]

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = input()
n = len(s)

res = [int(s[a:])%2019 for a in range(n)]
res.append(0)

ans = 0
# count = Counter(res)
# for i in range(2019):
#     ans += (count[i] * (count[i] - 1)) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = str(input())
N = len(S)

#smod = [int(S[i:])%2019 for i in range(N)]
smod = [0]
temp = 0
keta = 1
for i in range(N):
    temp = temp + int(S[(N-1)-i])*keta
    #print(temp)
    smod.append(temp%2019)
    keta *= 10


cmod = Counter(smod)
print(cmod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = list(input())
ls = len(s)
T = [0] * (ls+1)
modL = [0]
cnt = 0
pad = 1

for i in reversed(range(0, ls)):
    T[i] = T[i+1] + int(s[i]) * pad
    modL.append(T[i] % 2019)
    pad = pad * 10 % 2019

print(modL)

ans = 0
for c in Counter(modL).values():
    ans += c * (c - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

count=0

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


print(count)

Submission status: Wrong Answer

Solution code:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10

for i in range(1,N,1):
    S_num[N-i-1] = S_num[N-i] + (tmp)*S_num[N-i-1]
    tmp=tmp*10

Submission status: Wrong Answer

Solution code:
S=input()
S=S[::-1]
unko=[0]*2019
tmp=0
num=1
for s in S:
  s=int(s)
  tmp+=num * s
  num=num*10
  unko[tmp%2019]+=1
ans=0
ans+=unko[0]*(unko[0]-1)/2+1
for i in unko[1:]:
  ans+=i*(i-1)/2
print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = input()
n = len(s)

res = [int(s[a:])%2019 for a in range(n)] + [0]

ans = 0
# count = Counter(res)
# for i in range(2019):
#     ans += (count[i] * (count[i] - 1)) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

count=0

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


print(count)

Submission status: Wrong Answer

Solution code:
mod=2019
n=1
A=[1]
for k in range(1, 400):
    n=n*10%mod
    if n in A:
        break
    else:
        A.append(n)
S=input()
count=0
mod2=len(A)
B=[0]
B.append(int(S[-1]))
if len(S)>3:
    for k in range(2,len(S)+1):
        if (B[-1]+int(S[-k])*A[(k-1)%mod2])%mod in B:
            count+=1
        B.append((B[-1]+int(S[-k])*A[(k-1)%mod2])%mod)

    
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = [1] + [0] * 2018
s, p = 0, 1

for i in reversed(input()) :
    s = (s + p * int(i)) % 2019
    p = p * 10 % 2019
    a[s] += 1
    print(i, s, p, a[s])

print(sum(x * (x - 1) // 2 for x in a))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
S = input()
count = 0
list_amari = [0 for i in range(2019)]
amari_prev = 0
X = 1

for i in range(len(S)):
  amari = (int(S[-i-1])*X+amari_prev)%2019
  list_amari[amari] += 1
  amari_prev = amari
  X = (10*X)%2019

for v in list_amari:
  count += v*(v-1)//2

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = str(input())
N = len(S)

#smod = [int(S[i:])%2019 for i in range(N)]
smod = [0]
temp = 0
for i in range(N):
    temp = temp + int(S[(N-1)-i])*pow(10,i)
    print(temp)
    smod.append(temp%2019)


cmod = Counter(smod)
print(cmod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
s=input()
n=len(s)
count=0
a={}
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if n<4:
    print(0)
else:
    for i in range(0,n):
        if int(s[i:])%2019==0:
            count+=1
        if int(s[i:])%2019 in a:
            a[int(s[i:])%2019]+=1
        else:
            a[int(s[i:])%2019]=1
    a1=list(a.values())
    for i in range(len(a1)):
        if a1[i]>=2:
            count+=comb(a1[i],2)
print(count)

Submission status: Wrong Answer

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

for i in range(len(S)-3):
    sumsub = int(S[i])+int(S[i+1])+int(S[i+2])
    sti = i
    for j in range(i+3,len(S)):
        sumsub += int(S[j])
        #print(sumsub)
        if sumsub % 3 == 0:
            #print(S[i:j+1])
            #print(S[sti:j+1])
            if int(S[sti:j+1]) % 673 == 0:
                ans += 1
            sti = j+1
print(ans)

Submission status: Wrong Answer

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

l = [0] * 2019
index = 0
temp = 0
for i in range(N-1, -1, -1):
    temp += int(S[i]) * 10 * index
    l[temp%2019] += 1
    index += 1
 
ans = l[0]
 
for i in range(1, 2019):
    v = l[i]
    ans += v * (v-1) // 2
 
print(ans)

Submission status: Wrong Answer

Solution code:
s=[int(i) for i in input()]
s.reverse()

a=0
l=[0 for i in range(2019)]
for i in range(len(s)):
  a=a+s[i]*(10**i)
  b=a%2019
  l[b]+=1
  
answer=0
for i in range(2019):
  answer+=l[i]*(l[i]-1)/2
  
print(answer)

Submission status: Wrong Answer

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


l = [0] * 2019
m = 1
temp = 0
for i in range(N-1, -1, -1):
    temp += int(S[i]) * m
    temp %= 2019
    l[temp] += 1
    m *= 10
    m %= 2019

ans = l[0]

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
s=input()
n=len(s)
count=0
a={0:1}
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if n<4:
    print(0)
else:
    for i in range(0,n):
        if int(s[i:])%2019 in a:
            a[int(s[i:])%2019]+=1
        else:
            a[int(s[i:])%2019]=1
    a1=list(a.values())
    for i in range(len(a1)):
        if a1[i]>=2:
            count+=comb(a1[i],2)
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=[int(i) for i in input()]
s.reverse()

a=0
l=[0 for i in range(2019)]
for i in range(len(s)):
  a=a+s[i]*(10**i)
  b=a%2019
  l[b]+=1
  
answer=0
for i in range(2019):
  answer+=l[i]*(l[i]-1)
  
print(answer)

Submission status: Wrong Answer

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

c=0
def check2019(S, n):
    global c
    s = int(S)
    if s%2019 ==0 and s>2018:
        c +=1
    else:
        pass
    if s>9999:
        if n ==0:
            return check2019(S[1:],1), check2019(S[:-1], 0)
        else:
            return check2019(S[1:],1)
    else:
        return 0

S = input()


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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 26 22:28:26 2020

@author: Kanaru Sato
"""

s = input()
n = len(s)
dic = {}
mod = 2019
count = 0

for i in range(1,n+1):
    num = int(s[n-i:n])
    num %= mod
    if num in dic:
        dic[num] += 1
    if num not in dic:
        dic[num] = 1

ans = 0
for fact in dic:
    ans += dic[fact]*(dic[fact]-1)/2

print(int(ans))

Submission status: Wrong Answer

Solution code:
from sys import stdin


def merge_sort(lst, low, high):
    if low >= high:
        return
    mid = int((low+high)/2)
    merge_sort(lst, low, mid)
    merge_sort(lst, mid+1, high)
    for i in range(low, mid+1):
        tmp_array[i] = lst[i]
    j = high
    for i in range(mid+1, high+1):
        tmp_array[i] = lst[j]
        j -= 1
    i = low
    j = high
    for k in range(low, high+1):
        if tmp_array[i] <= tmp_array[j]:
            lst[k] = tmp_array[i]
            i += 1
        else:
            lst[k] = tmp_array[j]
            j -= 1


S = stdin.readline().rstrip()
N = len(S)
Sp = S

res_map = [0 for _ in range(N)]

aa_list2 = [1]
for i in range(1,N):
    aa_list2.append((aa_list2[i-1]*10)%2019)

tmp_array = [None for _ in range(N)]
res_map[N-1] = int(S[N-1])
index=1
for i in range(N-2,-1,-1):
    res_map[i] = (int(S[i])*aa_list2[index] + res_map[i+1])%2019
    index+=1
#merge_sort(res_map,0,N-1)
#res_map = list(np.sort(np.array(res_map)))
res_map.sort()
temp_num=res_map[0]
index=1
tot = 0

for i in range(1,N):
    if temp_num==res_map[i]:
        index+=1
        continue
    else:
        if temp_num==0:
            tot += int(index*(index+1)/2)
        elif index>1:
            tot += int(index*(index-1)/2)
            #tot += index/2
        index=1
        temp_num=res_map[i]





print(tot)

Submission status: Wrong Answer

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


l = [0] * 2019
m = 1
temp = 0
for i in range(N-1, -1, -1):
    temp += int(S[i]) * m
    l[temp%2019] += 1
    m *= 10

ans = l[0]

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

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
ret = [0 for _ in range(2019)]
ret[0] = 1
mod = 0

for i in range(len(S)):
    mod = (mod + int(S[-1-i])*10) % 2019
    ret[mod] += 1

ans = 0
for r in ret:
    if r > 1:
        ans += r * (r-1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
mod = 2019
def main():
    s = tuple([int(x) for x in input().rstrip()])
    n = len(s)
    ans = 0
    d = {}
    T = 0
    T1 = 0
    for i in range(n):
        if i == 0:ten = 1
        else: ten *= 10
        T1 = s[n-1-i]*ten+T
        T = T1
        t = T%mod
        if t in d:
            d[t] += 1
        else:
            d[t] = 1
    for k in d:
        if k != 0:
            ans += d[k]*(d[k]-1)//2
        else:
            ans += d[k]
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = str(input())
s = len(S)
c = 0

for i in range(4,7):
    for j in range(s-i+1):
        if int(S[j:i+j])%2019==0:
            c += 1
print(c)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np


def merge_sort(lst, low, high):
    if low >= high:
        return
    mid = int((low+high)/2)
    merge_sort(lst, low, mid)
    merge_sort(lst, mid+1, high)
    for i in range(low, mid+1):
        tmp_array[i] = lst[i]
    j = high
    for i in range(mid+1, high+1):
        tmp_array[i] = lst[j]
        j -= 1
    i = low
    j = high
    for k in range(low, high+1):
        if tmp_array[i] <= tmp_array[j]:
            lst[k] = tmp_array[i]
            i += 1
        else:
            lst[k] = tmp_array[j]
            j -= 1


S = stdin.readline().rstrip()
N = len(S)
Sp = S

res_map = [0 for _ in range(N)]

aa_list2 = [1]
for i in range(1,N):
    aa_list2.append((aa_list2[i-1]*10)%2019)

tmp_array = [None for _ in range(N)]
res_map[N-1] = int(S[N-1])
index=1
for i in range(N-2,-1,-1):
    res_map[i] = (int(S[i])*aa_list2[index] + res_map[i+1])%2019
    index+=1
merge_sort(res_map,0,N-1)
#res_map = list(np.sort(np.array(res_map)))
temp_num=res_map[0]
index=1
tot = 0

for i in range(1,N):
    if temp_num==res_map[i]:
        index+=1
        continue
    else:
        if temp_num==0:
            tot += int(index*(index+1)/2)
        elif index>1:
            tot += int(index*(index-1)/2)
            #tot += index/2
        index=1
        temp_num=res_map[i]





print(tot)

Submission status: Wrong Answer

Solution code:
S = input()

c = [0] * 2019
for i in range(len(S)):
    c[int(S[i:])%2019] += 1

ans = 0
for m in c:
    ans += m * (m - 1) / 2

print(int(ans))

Submission status: Wrong Answer

Solution code:
num=input()
length = len(num)
count=0

bai=list(range(2019,200000,2019))

for i in range(len(bai)):
   if  str(bai[i]) in str(num):
      count+=1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
t = [0]*len(s)
t[-1] = int(s[-1])
for i in range(len(s)-2,0,-1):
    t[i] = int(s[i:len(s)])%2019

u = sorted(t)
ans = 0

if u[0] == 0:
    ans += 1
for i in range(len(s)-1):
    if u[i] == u[i+1]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
s=input()
n=len(s)
count=0
a=[0 for i in range(2019)]
a[0]=1
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if n<4:
    print(0)
else:
    for i in range(0,n):
        a[int(s[i:])%2019]+=1
    for i in range(2019):
        if a[i]>=2:
            count+=comb(a[i],2)
print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

S = stdin.readline().rstrip()
N = len(S)
Sp = S

res_map = [0 for _ in range(N)]

aa_list2 = [1]
for i in range(1,N):
    aa_list2.append((aa_list2[i-1]*10)%2019)


res_map[N-1] = int(S[N-1])
index=1
for i in range(N-2,-1,-1):
    res_map[i] = (int(S[i])*aa_list2[index] + res_map[i+1])%2019
    index+=1
res_map = list(np.sort(np.array(res_map)))
temp_num=res_map[0]
index=1
tot = 0

for i in range(1,N):
    if temp_num==res_map[i]:
        index+=1
        continue
    else:
        if temp_num==0:
            tot += int(index*(index+1)/2)
        elif index>1:
            tot += int(index*(index-1)/2)
            #tot += index/2
        index=1
        temp_num=res_map[i]





print(tot)

Submission status: Wrong Answer

Solution code:
s = input()
t = [0]*len(s)
t[-1] = int(s[-1])
for i in range(len(s)-2,0,-1):
    t[i] = int(s[i:len(s)])%2019

u = sorted(t)
ans = 0
for i in range(len(s)-1):
    if u[0] == 0:
        ans += 1
    if u[i] == u[i+1]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
T = [0]

for i in range(len(S)):
    T.append(int(S[-1-i:])%2019)
print(T)

ret = [0 for _ in range(2019)]
for t in T:
    ret[t] += 1
ans = 0
for r in ret:
    if r > 1:
        ans += r * (r-1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
ans = set([])
for i in range(0, len(s) - 3):
    j = i
    num = s[i : i + 4]
    print(num)
    if int(num) % 2019 == 0 and num != '0':
        #print(i, j)
        if i + 4 not in ans:
            ans.add(i + 4)
            cnt += 1
        elif i in ans:
            cnt += 2
        else:
            cnt += 1
    j += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
ans = set([])
for i in range(0, len(s) - 3):
    j = i
    num = s[i : i + 4]
    print(num)
    if int(num) % 2019 == 0 and num != '0':
        #print(i, j)
        if i + 4 not in ans:
            ans.add(i + 4)
            cnt += 1
        elif i - 1 in ans:
            cnt += 2
        else:
            cnt += 1
    j += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s=input()
l=len(s)
ans=0
p=0
a={}
b=-1
c=-1
d=-1
q=1
for j in range(l)[::-1]:
    p=(p+int(s[j])*q)%2019
    q*=10
    q%=2019
    if b>0:
        if a.get(b)!=None:
            a[b]+=1
        else:
            a[b]=1
    b=c
    c=d
    d=p
    if p==0:
        ans+=1
    if a.get(p)!=None:
        ans+=a[p]
print(ans)

Submission status: Wrong Answer

Solution code:
b=input()
A=0
c=int(len(b))
for i in range(c-3):
    e = b[i:]
    for j in range(c-i-4):
        d=e[j:]
        print(d)
        if int(d)%2019==0:
            A+=1
#print(A)

Submission status: Wrong Answer

Solution code:
from sys import stdin

S = stdin.readline().rstrip()
N = len(S)
Sp = S

res_map = [0 for _ in range(N)]

aa_list2 = [1]
for i in range(1,N):
    aa_list2.append((aa_list2[i-1]*10)%2019)


res_map[N-1] = int(S[N-1])
index=1
for i in range(N-2,-1,-1):
    res_map[i] = (int(S[i])*aa_list2[index] + res_map[i+1])%2019
    index+=1
res_map.sort()
temp_num=res_map[0]
index=1
tot = 0

for i in range(1,N):
    if temp_num==res_map[i]:
        index+=1
        continue
    else:
        if temp_num==0:
            tot += int(index*(index+1)/2)
        elif index>1:
            tot += int(index*(index-1)/2)
            #tot += index/2
        index=1
        temp_num=res_map[i]





print(tot)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
S = input()
N = len(S)

D=defaultdict(int)
prev=0
ans=0
for i,s in enumerate(reversed(S)):
    cur=prev+pow(10,i,2019)*int(s)
    cur %= 2019
    ans+=D[cur]
    D[cur]+=1
    prev=cur
print(ans+1)

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
ans = set([])
for i in range(0, len(s) - 3):
    j = i
    num = s[i : i + 4]
    print(num)
    if int(num) % 2019 == 0 and num != '0':
        #print(i, j)
        if i + 4 - 1 not in ans:
            ans.add(i + 4)
            cnt += 1
        else:
            cnt += 2
    j += 1
print(cnt)

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:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10
for i in range(1,N,1):
    S_num[N-i-1] = S_num[N-i] + (tmp)*S_num[N-i-1]
    tmp=tmp*10

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)
    # print(m10)
    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) - 1):
        M10.append((M10[-1] * m10) % MOD)

    # print(T)
    # print(M10)

    K = [(t * m) % MOD for t, m in zip(T, M10)]
    # print(K)

    cK = Counter(K[1:])
    ans = T.count(0)
    for k in K[1:]:
        cK[k] -= 1
        ans += cK[k]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from collections import defaultdict
    dic = defaultdict(int)

    input = sys.stdin.readline

    s = str(input().rstrip())
    m = 0

    for i in range(1,len(s)+1):
        m_ad = (int(s[-i]) * (10 ** (i - 1))) % 2019
        m = (m_ad + m) % 2019
        dic[m] += 1

    ans1 = 0

    for x in dic.values():
        if x > 1:
            ans1 = x * (x - 1) // 2
    ans2 = dic[0]

    print(ans1 +ans2)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a=input()
list1=[]
for i in range(len(a)) :
  list1.append(int(a[i:])%2019)
count=0
list1.append(int(a[i])%2019)

for i in range(len(list1)):
  for j in range(i+1,len(list1)) :
    if list1[i]==list1[j] :
      count+=1
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
S_l = len(S)
MOD = 2019
l = [set([]) for _ in range(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:
      l[end].add(start)
      if start>=4:
        l[end] = l[start-1]|l[end]
        
for s in l:
  ans+=len(s)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
S = input()
N = len(S)

D=defaultdict(int)
prev=0
ans=0
for i,s in enumerate(reversed(S)):
    cur=prev+pow(10,i,2019)*int(s)%2019
    ans+=D[cur]
    D[cur]+=1
    prev=cur
print(ans)

Submission status: Wrong Answer

Solution code:

def main():
    s = input()
    amari_lst = [0] * len(s)
    for i in range(len(s)):
        temp = int(s[i:])
        amari_lst[i] = temp % 2019

    counter = 0
    for i in range(len(s)):
        counter += amari_lst[i+1:].count(amari_lst[i])

    print(counter)







if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
input=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:
N = list(input())

n = len(N)

cnt = 0

for i in range(n-3):
     for j in range(n-i-3):
            joint = ''.join(N[i:n-j])  
            print(joint,n,i,j)
            if int(joint)%2019 == 0:      
                 cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()
S_l = len(S)
MOD = 2019
l = [set([]) for _ in range(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:
      l[end].add(start)
      if start>=4:
        l[end]|=l[start-1]
        
for s in l:
  ans+=len(s)
print(ans)