Problem:


Score : 400 points

Problem Statement

Given is a string S consisting of digits from 1 through 9.

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Wrong Answer

Solution code:
s = input()
s_len = len(s)
count = 0

for i in range(s_len - 3):
    for j in map(lambda num: num + (i + 3), range(s_len - (i + 3))):
        if int(s[i:j]) % 2019 == 0:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
S = str(input())

#10**nのmod計算
A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019

#左からi文字以降の数字列のmod計算
X = []
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)
X.sort()
flag =1
n = 0

#modが同じになる組み合わせ、またはもともとmodが0になる数字列の個数の総和計算
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += int(flag*(flag-1)/2)
    flag = 1
if X[len(X)-1]==0:
  n +=1
print(n)

Submission status: Wrong Answer

Solution code:
S = str(input())

#10**nのmod計算
A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019

#左からi文字以降の数字列のmod計算
X = []
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)
X.sort()
flag =1
n = 0

#modが同じになる組み合わせ、またはもともとmodが0になる数字列の個数の総和計算
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += int(flag*(flag-1)/2)
    flag = 1
print(n)

Submission status: Wrong Answer

Solution code:
S = str(input())

#10**nのmod計算
A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019

#左からi文字以降の数字列のmod計算
X = []
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)
X.sort()
flag =1
n = 0

#modが同じになる組み合わせ、またはもともとmodが0になる数字列の個数の総和計算
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += flag*(flag-1)/2
    flag = 1
print(n)

Submission status: Wrong Answer

Solution code:
S = str(input())

#10**nのmod計算
A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019

#左からi文字以降の数字列のmod計算
X = []
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)
X.sort()
flag =1
n = 0

#modが同じになる組み合わせ、またはもともとmodが0になる数字列の個数の総和計算
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += flag*(flag-1)//2
    flag = 1
print(n)

Submission status: Wrong Answer

Solution code:
s = input()

li = []
mod = 2019
tmp = 0

for i in range(len(s)):
    li.append(tmp)
    tmp += int(s[i])*pow(10,len(s)-i-1,mod)
    #tmp += int(s[i]) * 10 ** (len(s)-i-1)
    tmp %= mod
    #print(len(s)-i-1,s[i])

li.append(tmp)

li.sort()
#print(li)

tmp = li[0]
t_num = 1
ans = 0

for i in range(1,len(li)):
    if tmp == li[i]:
        t_num += 1
    else:
        ans += t_num*(t_num-1)//2
        t_num = 1
        tmp = li[i]

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
from collections import Counter
x = 1
mod = 2019
total = 0
ans = 0
cnt = Counter()
for i in range(len(s)-1,0,-1):
    cnt[total] += 1
    total = int(s[i::])%mod
    ans += cnt[total]
print(ans)

Submission status: Wrong Answer

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

a = [0]*length
for i in range(length):
    pickup = int(S[length - i - 1])
    a[i] = pickup*pow(10, i, 2019)


b = [0]*length
b[0] = a[0]
for i in range(1, length):
    b[i] = (b[i-1] + a[i]) % 2019

cnt, ans = [0] * 2019, 0
for x in b:
  ans += cnt[x]
  cnt[x] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import re
S = input()
#print(type(S))

s = []
for i in range(10000):
    s.append(str(i*2019))

count = 0
for i in s:
    S_ = S
    while re.search(i, S_):
        #print(i)
        S_ = S_[:re.search(i, S_).start()] + "," + S_[re.search(i, S_).start()+1:]
        count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
import re
S = input()
#print(type(S))

s = []
for i in range(10000):
    s.append(str(i*2019))

count = 0
for i in s:
    S_ = S
    while re.search(i, S_):
        print(i)
        S_ = S_[:re.search(i, S_).start()] + "," + S_[re.search(i, S_).start()+1:]
        count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
import re
S = input()
#print(type(S))

s = []
for i in range(1000):
    s.append(str(i*2019))

count = 0
for i in s:
    S_ = S
    while re.search(i, S_):
        print(i)
        S_ = S_[:re.search(i, S_).start()] + "," + S_[re.search(i, S_).start()+1:]
        count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
S = input()

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

print(count)

Submission status: Wrong Answer

Solution code:
S = input()

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

print(count)

Submission status: Wrong Answer

Solution code:
S = input()

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

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
res = 0
Pow2019 = 2019**10
for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        num = int(S[i:j])
        if num % 2019 == 0:
            res += 1
        if num > Pow2019:
            break
print(res)

Submission status: Wrong Answer

Solution code:
S = input()
res = 0
Pow2019 = 2019**10
print(Pow2019)
for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        num = int(S[i:j])
        print(num)
        if num % 2019 == 0:
            res += 1
        if num > Pow2019:
            break
print(res)

Submission status: Wrong Answer

Solution code:
import collections
S = input()
N = len(S)
mod = 2019
div = [0]*(N+1)
temp = 0
for i in range(N):
    temp = div[i] + int(S[N-1-i])*pow(10,i,mod)
    div[i+1] = temp%mod
d = collections.Counter(div[1::])
print(sum(d.values())-len(d)+d[0])

Submission status: Wrong Answer

Solution code:
import collections
S = input()
N = len(S)
mod = 2019
div = [0]*N
temp = 0
for i in range(N):
    temp = temp + int(S[N-1-i])*pow(10,i,mod)
    div[i] = temp%mod
d = collections.Counter(div)
print(sum(d.values())-len(d)+d[0])

Submission status: Wrong Answer

Solution code:
S=input()
T=len(S)
a=0
d=1
mod=[0]*2019
mod[0]+=1
for i in range(T):
 a+=(int(S[T-i-1])*(d))%2019
 b=a%2019
 mod[b]+=1
 d*=10
 d%=2019
c=0
for i in range(2019):
 if mod[i]>=2:
  c+= mod[b]*(mod[b]-1)/2
print(int(c))

Submission status: Wrong Answer

Solution code:
S=input()
a=0
d=0
mod=[0]*2019
mod[0]+=1
for s in S[::-1]:
 a+=(int(s)*(10**d))%2019
 b=a%2019
 mod[b]+=1
 d+=1
c=0
for i in range(2019):
 if mod[i]>=2:
  c+= mod[b]*(mod[b]-1)/2
print(int(c))

Submission status: Wrong Answer

Solution code:
S=input()
L=list(S)
T=len(L)
a=0
mod=[0]*2019
mod[0]+=1
for i in range(T):
 a+=(int(L[T-i-1])*(10**i))%2019
 b=a%2019
 mod[b]+=1
c=0
for i in range(2019):
 if mod[i]>=2:
  c+= mod[b]*(mod[b]-1)/2
print(int(c))

Submission status: Wrong Answer

Solution code:
import sys

s = input()

count = 0

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

Submission status: Wrong Answer

Solution code:
S = input()
S = S[::-1]
leng = len(S)
S = int(S)

count = [0] * 2019
count[0] = 1

for i in range(leng):
    remainder = i % 2019

res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2

print(res)

Submission status: Wrong Answer

Solution code:
S = input()
S = S[::-1]
leng = len(S)
S = int(S)

count = [0] * 2019
count[0] = 1

for i in range(leng):
    remainder = (S // (10**i)) % 2019

res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2
    
res

Submission status: Wrong Answer

Solution code:
S = input()
S = S[::-1]
leng = len(S)
S = int(S)

count = [0] * 2019
count[0] = 1

for i in range(leng):
    remainder = (S // (10**i)) % 2019
    print(S//(10**i), remainder)
    count[remainder] += 1

res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2

print(res)

Submission status: Wrong Answer

Solution code:
s = input()

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

Submission status: Wrong Answer

Solution code:
s = input()[::-1] # 右からn桁の数についてループを回していきたいので、文字列を反転させる

sum_of_digits = 0 # 余りの値
cnts = [0] * 2019 # 余りの値ごとに余りが同じ値の数を格納する変数。2019で割る場合、余りは0~2018までの2019通りあるので、リストの長さは2019
cnts[0] = 1 # for文はn回しか回らないが、余りを計算したい桁数は0~n桁のn+1個ある。そこで0桁の余はfor文の前に計算しておく。0桁の値を2019で割った余りは0なので、cnts[0]に1を代入しておく
d = 1 # sum_of_digitsの計算に使う10の累乗値

# まず余りの値ごとに余りが同じ値の数を数える
for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
#    d %= 2019 # オーバーフローを避けるために2019の剰余を取る。後述
    cnts[sum_of_digits] += 1

# 次に余りの値ごとにその組み合わせを計算し、足し合わせる
ans = 0
for cnt in cnts:
    ans += cnt * (cnt - 1) / 2

print(ans)

Submission status: Wrong Answer

Solution code:
#A,B,C,D=map(int,input().split(" "))

import collections

mod=2019
a=input()

N=len(a)
t=[]
ans=0

for i in range(N):
  u=int(a[i::])
  v=u % mod
  t.append(v)
  
tt = collections.Counter(t)
for i in tt.values():
  #print(i)
  if i==0:
    ans+=1
  else:
    ans += (i-1)*i//2
print(ans)

Submission status: Wrong Answer

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

modlist=[]

for i in range(n):
  modlist.append(int(s[i:])%2019)

modlist.append(0)
 
result = 0
  
for i in range(2019):
  c = modlist.count(i)
  result += c*(c-1)/2

print(result)

Submission status: Wrong Answer

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

modlist=[]

for i in range(n):
  modlist.append(int(s[i:])%2019)

modlist.append(0)
 
result = 0
  
for i in range(2019):
  c = modlist.count(i)
  if c<=1:
    result += 0
  else:
    result += c*(c-1)/2

print(result)

Submission status: Wrong Answer

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

modlist=[]

for i in range(n):
  modlist.append(int(s[i:])%2019)
  
result = 0
  
for i in range(2019):
  c = modlist.count(i)
  if c<=1:
    result += 0
  else:
    result += c*(c-1)/2

print(result)

Submission status: Wrong Answer

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

map_ = [0] * 2019
map_[0] = 1
ans = 0
now = 0
for i in range(0, N + 1):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1

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

print(ans)

Submission status: Wrong Answer

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

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N + 1):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)

Submission status: Wrong Answer

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


def powmod(a: int, p: int, mod: int) -> int:
    # return a**p (mod MOD) O(log p)
    if p == 0:
        return 1
    if p % 2 == 0:
        half = powmod(a, p // 2, mod)
        return half * half % mod
    else:
        return a * powmod(a, p - 1, mod) % mod


map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N + 1):
    now = (now + int(S[N - i - 1]) * powmod(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)

Submission status: Wrong Answer

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


def powmod(a: int, p: int, mod: int) -> int:
    # return a**p (mod MOD) O(log p)
    if p == 0:
        return 1
    if p % 2 == 0:
        half = powmod(a, p // 2, mod)
        return half * half % mod
    else:
        return a * powmod(a, p - 1, mod) % mod


map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N + 1):
    now = (now + int(S[N - i - 1]) * powmod(10, i, 2019)) % 2019
    map_[now % 2019] += 1
    ans += map_[now % 2019]

print(ans)

Submission status: Wrong Answer

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


def powmod(a: int, p: int, mod: int) -> int:
    # return a**p (mod MOD) O(log p)
    if p == 0:
        return 1
    if p % 2 == 0:
        half = powmod(a, p // 2, mod)
        return half * half % mod
    else:
        return a * powmod(a, p - 1, mod) % mod


map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N + 1):
    now += (int(S[N - i - 1]) * powmod(10, i, 2019)) % 2019
    map_[now % 2019] += 1
    ans += map_[now % 2019]

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce
import numpy as np
#def ConZ(i):
    #z_num = i+int(i*(i-1)/2)
    #return z_num
#def ConN(i):
    #n_num = int(i*(i-1)/2)
    #return n_num

def cmb(n):
    over = reduce(mul, range(n, n - 2, -1))
    under = reduce(mul, range(1,2 + 1))
    return over // under


S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = np.array([0]*2019)
mod[0] += 1
for i in range(len(S)):
    A_num += int(S[i:i+1])*keta
    if A_num >= 2019:
        A_num = A_num%2019
    mod[A_num] +=1
    #keta*=10
    keta = keta * 10 % 2019
print(mod)
#x += ConZ(mod[0])
#del mod[0]

#for j in range(len(mod)):
    #x+=cmb(mod[j])
#print(x)
print(int(np.sum(mod* (mod - 1) /2)))

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
#def ConN(i):
    #n_num = int(i*(i-1)/2)
    #return n_num

def cmb(n):
    over = reduce(mul, range(n, n - 2, -1))
    under = reduce(mul, range(1,2 + 1))
    return over // under


S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = [0]*2019
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod[A_num] +=1
    keta*=10
    
print(mod)
x += ConZ(mod[0])
del mod[0]

for j in range(len(mod)):
    x+=cmb(mod[j])
print(x)

Submission status: Wrong Answer

Solution code:
import collections

S = list(input())
a=[int(x) for x in S] #int型のリストに変換
a.reverse()
print(a)

n=len(a)
T=[0]*n

T[0]=a[0]

for i in range(1,n):
    T[i]=T[i-1]+(a[i]*10**i)
    


print(T)
L=list()
for i in range(n):
    L.append(T[i]%2019)
   

print(L)
c = collections.Counter(L)

#出現回数が2回以上のものの出現数 + 0の出現回数
print(int(len([i[0] for i in c.items() if i[1] >= 2])) + int(len([i for i in L if i==0])))

Submission status: Wrong Answer

Solution code:
import collections

def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
def ConN(i):
    n_num = int(i*(i-1)/2)
    return n_num

S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = [0]*2019
modcount = []
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod[A_num] +=1
    keta*=10
print(mod[0])
x += ConZ(mod[0])
del mod[0]
c = collections.Counter(mod)
print(mod)
modcount = list(c.items())
print(modcount)
for j in range(len(modcount)):
    if modcount[j][0]>=2:
        x+=ConN(modcount[j][0])*modcount[j][1]
print(x)

Submission status: Wrong Answer

Solution code:
import collections

def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
def ConN(i):
    n_num = int(i*(i-1)/2)
    return n_num

S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = [0]*2019
modcount = []
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod[A_num] +=1
    keta*=10
    
c = collections.Counter(mod)
x += ConZ(mod[0])
#print(mod)

modcount = list(c.items())
for j in range(len(modcount)):
    if modcount[j][0]>=2:
        x+=ConN(modcount[j][0])*modcount[j][1]
print(x)

Submission status: Wrong Answer

Solution code:
import collections

def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
def ConN(i):
    n_num = int(i*(i-1)/2)
    return n_num

S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = [] 
modcount=[]
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod.append(A_num) 
    keta*=10

c = collections.Counter(mod)
x += ConZ(mod.count(0))
modcount=list(c.values())
#print(mod)
#print(modcount)
k = 0

for j in range(len(modcount)):
    if modcount[j] >=2:
        x+=ConN(modcount[j])
print(x)

Submission status: Wrong Answer

Solution code:
import collections

def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
def ConN(i):
    n_num = int(i*(i-1)/2)
    return n_num

S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = [] 
modcount=[]
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod.append(A_num) 
    keta*=10

c = collections.Counter(mod)
x += ConZ(mod.count(0))
modcount=list(c.values())
print(mod)
print(modcount)
k = 0

for j in range(len(modcount)):
    if modcount[j] >=2:
        x+=ConN(modcount[j])
print(x)

Submission status: Wrong Answer

Solution code:
import collections

def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
def ConN(i):
    n_num = int(i*(i-1)/2)
    return n_num

S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = [0]*len(S) 
modcount=[]
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod[i] = A_num 
    keta*=10
    
c = collections.Counter(mod)
x += ConZ(mod.count(0))
modcount=list(c.values())
#print(mod)
#print(modcount)
k = 0

for j in range(len(modcount)):
    if modcount[j] >=2:
        x+=ConN(modcount[j])
print(x)

Submission status: Wrong Answer

Solution code:
import collections

def ConZ(i):
    z_num = i+int(i*(i-1)/2)
    return z_num
def ConN(i):
    n_num = int(i*(i-1)/2)
    return n_num

S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = [0]*len(S) 
for i in range(len(S)):
    A_num += (int(S[i:i+1])*keta)%2019
    if A_num >= 2019:
        A_num = A_num%2019
    mod[i] = A_num 
    keta*=10
    
c = collections.Counter(mod)
x += ConZ(mod.count(0))
for j in range(len(c)):
    if c.most_common()[j][1]>=2:
        x += ConN(c.most_common()[j][1])
print(x)

Submission status: Wrong Answer

Solution code:
import  collections

s = input().strip()
t = []
for i in range(len(s)):
    t.append(int(s[i:]) % 2019)
    
t.append(0)
count = dict(collections.Counter(t))
print(count)
tot = 0
for c in count.values():
    tot += c*(c-1)/2
print(int(tot))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
S = input()
N = len(S)
p = []
for i in range(N-3):
    p.append(int(S[i:])%2019)
c  = Counter(p)
t = 0
if(not c[0]==0):
    t = t + c[0]*(c[0]+1)//2
for i in range(2018):
    if(not c[i+1]==0 and not c[i+1]==1):
        t = t + c[i+1]*(c[i+1]-1)//2
print(t)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
S = input()
N = len(S)
p = []
for i in range(N-3):
    p.append(int(S[i:])%2019)
c  = Counter(p)
t = 0
if(not c[0]==0 and not c[0]==1 and not c[0]==2):
    t = t + c[0]*(c[0]-1)//2
elif(c[0]==1 or c[0]==2):
    t = t + c[0]
for i in range(2018):
    if(not c[i+1]==0 and not c[i+1]==1):
        t = t + c[i+1]*(c[i+1]-1)//2
print(t)

Submission status: Wrong Answer

Solution code:
S = input()
res = 0
v = 2019 / 1e9
for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        num = float(S[i:j]) / 1e9
        print(num % v)
        if num % v < 0.000000003:
            res += 1
print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
S = input()
N = len(S)
p = []
for i in range(N-3):
    p.append(int(S[i:])%2019)
c  = Counter(p)
t = 0
if(not c[0]==0 and not c[0]==1):
    t = t + c[0]*(c[0]-1)//2
elif(c[0]==1):
    t = t + 1
elif(c[0]==0):
    t = t
for i in range(2018):
    if(not c[i+1]==0 and not c[i+1]==1):
        t = t + c[i+1]*(c[i+1]-1)//2
print(t)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial
S = input()
N = len(S)
p = []
for i in range(N-3):
    p.append(int(S[i:])%2019)
c  = Counter(p)
t = 0
if(not c[0]==0 and not c[0]==1):
    t = t + c[0]*(c[0]-1)//2
elif(c[0]==1):
    t = t + 1
elif(c[0]==0):
    t = t
for i in range(2018):
    if(c[i+1]==0 or c[i+1]==1):
        t = t
    else:
        t = t + c[i+1]*(c[i+1]-1)//2
print(t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
## coding: UTF-8

S = input()[::-1] #文字列型で受け取る
N = len(S)
#print(S)

remainder = [0] * 2019
tmp = 0
rad = 1 # *10**(i) % 2019
for i in range(N):
    r = int(S[i])
    tmp += r*rad
    tmp %= 2019
    #print(tmp)
    remainder[tmp] += 1
    rad *= 10
    rad %= 2019

    #print(S[i:], int(S[i:])%2019)
    #remainder[int(S[i:])%2019]+= 1
remainder[0] += 1
print(-1)


'''
answer = 0
for i in range(2019):
    p = remainder[i]
    answer += p*(p-1)/2
print(int(answer))
'''

Submission status: Wrong Answer

Solution code:
## coding: UTF-8

S = input()[::-1] #文字列型で受け取る
N = len(S)
#print(S)

remainder = [0] * 2019
tmp = 0
for i in range(N):
    r = int(S[i])
    tmp += r*10**(i)
    #print(tmp%2019)
    #remainder[tmp%2019] += 1
    tmp %= 2019

    #print(S[i:], int(S[i:])%2019)
    #remainder[int(S[i:])%2019]+= 1
remainder[0] += 1
print(-1)


'''
answer = 0
for i in range(2019):
    p = remainder[i]
    answer += p*(p-1)/2
print(int(answer))
'''

Submission status: Wrong Answer

Solution code:
## coding: UTF-8

S = input()[::-1] #文字列型で受け取る
N = len(S)
#print(S)

remainder = [0] * 2019
tmp = 0
for i in range(N):
    r = int(S[i])
    tmp += r*10**(i)
    #print(tmp%2019)
    remainder[tmp%2019] += 1
    tmp %= 2019

    #print(S[i:], int(S[i:])%2019)
    #remainder[int(S[i:])%2019]+= 1
remainder[0] += 1
print(-1)


'''
answer = 0
for i in range(2019):
    p = remainder[i]
    answer += p*(p-1)/2
print(int(answer))
'''

Submission status: Wrong Answer

Solution code:
## coding: UTF-8

S = input()[::-1] #文字列型で受け取る
N = len(S)
print(S)

remainder = [0] * 2019
tmp = 0
for i in range(N):
    r = int(S[i])
    tmp += r*10**(i)
    print(tmp%2019)
    remainder[tmp%2019] += 1
    tmp %= 2019

    #print(S[i:], int(S[i:])%2019)
    #remainder[int(S[i:])%2019]+= 1
remainder[0] += 1
print(-1)


'''
answer = 0
for i in range(2019):
    p = remainder[i]
    answer += p*(p-1)/2
print(int(answer))
'''

Submission status: Wrong Answer

Solution code:
## coding: UTF-8

S = input() #文字列型で受け取る
N = len(S)

remainder = [0] * 2019

for i in range(N):
    #print(S[i:], int(S[i:])%2019)
    remainder[int(S[i:])%2019]+= 1
remainder[0] += 1
print(-1)
'''
answer = 0
for i in range(2019):
    p = remainder[i]
    answer += p*(p-1)/2
print(int(answer))
'''

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    len_S = len(S)
    cnt = 0
    for i in range(len_S):
        for j in range(i+3,len_S):
            if j == i+3:
                mod = int(S[len_S-j-1:len_S-i])%3
            else:
                mod = (mod+int(S[len_S-j-1]))%3
            if mod == 0:
                _ = int(S[len_S-j-1:len_S-i])
                if _%673==0:
                    cnt += 1
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


if __name__ == "__main__":
    #main()

    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    len_S = len(S)
    cnt = 0
    mod_arr = [0] * 2019
    mod_arr[0] += 1

    num, dec = 0, 1
    for i in range(0,len_S+1):
        num += int(S[len_S-i-1])*dec
        num %= 2019
        dec *= 10
        dec %= 2019
        mod_arr[num] += 1

    for i in range(2019):
        if mod_arr[i] > 0:
            cnt += mod_arr[i]*(mod_arr[i]-1)//2
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    len_S = len(S)
    cnt = 0
    for i in range(len_S):
        for j in range(i+3,len_S):
            if j == i+3:
                mod = int(S[len_S-j-1:len_S-i])%3
            else:
                mod = (mod+int(S[len_S-j-1]))%3
            if mod == 0:
                _ = int(S[len_S-j-1:len_S-i])
                if _%673==0:
                    cnt += 1
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


if __name__ == "__main__":
    #main()

    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    len_S = len(S)
    cnt = 0
    mod_arr = [0 for i in range(2019)]
    mod_arr[0] += 1

    num, dec = 0, 0
    for i in range(0,len_S+1):
        num += int(S[len_S-i-1])*10**dec
        num %= 2019
        dec += 1
        dec %= 2019
        mod_arr[num] += 1

    for i in range(2019):
        if mod_arr[i] > 0:
            cnt += mod_arr[i]*(mod_arr[i]-1)//2
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
n = len(s)
cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1
for i in range(n):
    total += int(s[i]) * x
    total %= 2019
    x *= 10 % 2019
    ans += cnt[total]
    cnt[total] += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
s=str(input())
a=0
b=0
for i in range(200000):
	if str(a) in s:
		b+=1
	if len(str(a))>len(s):
		exit()
	print(a)
	print(str(a) in s)
	a+=2019
print(b)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        temp = (int(s[-(1+i)])*pow(10,i,2019)) % 2019
        r[i] = (temp+r[i-1])%2019

    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    if cts[0]>0:
        ans+=1

    print(ans)
main()

Submission status: Wrong Answer

Solution code:
S = input()[::-1]
ans = [0]*2019
ans[0] = 1
num =0
t= 0
d = 1
for i in S:
    num += int(i) * d
    num %= 2019
    d *= 10
    ans[num] += 1

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

print(t)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        temp = int(s[-(1+i)])*pow(10,i,2019)
        r[i] = (temp+r[i-1])%2019

    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    if cts[0]>0:
        ans+=1

    print(ans)
main()

Submission status: Wrong Answer

Solution code:
S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i]) * pow(10,N-i-1,p))%p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1
ans = 0
for i in range(p):
  m = cnt[i]
  if i == 0 and m > 0:
    ans += 1 + (m*(m-1))//2
  else:
    ans += (m*(m-1))//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

p = 7
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i]) * pow(10,N-i-1,p))%p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1 
ans = 0
for i in range(p):
  m = cnt[i]
  if i == 0:
    ans = 1 + (m*(m-1))//2
  else:
    ans += (m*(m-1))//2
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import collections as c
    s = input()
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        r[i] = int(s[-(1+i)])*pow(10,i,2019)+ r[i-1]
        r[i]%=2019

    rc = c.Counter(r)
    rl = list(rc.values())
    sum = 0
    for i in rl:
        sum += int(i*(i-1)/2)

    if 0 in rc:
        sum+=1

    print(sum)

main()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from collections import defaultdict
S = list(input().rstrip())
r = 1
i=len(S)
acc=0
dd = defaultdict(int)
for s in S[::-1]:
    acc+=r*int(s)
    acc%=2019
    r%=2019
    r*=10
    dd[acc]+=1
    i-=1
ans=0
for i in dd.values():
    ans+=(i*(i-1))//2
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from collections import defaultdict
S = list(input().rstrip())
r = 1
i=len(S)
acc=0
dd = defaultdict(int)
for s in S[::-1]:
    acc+=r*int(s)
    acc%=2019
    r%=2019
    r*=10
    dd[acc]+=1
    i-=1
ans=0
for i in dd.values():
    ans+=(i*(i-1))/2
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from collections import defaultdict
S = list(input().rstrip())
r = 1
i=len(S)
acc = [0]*(i+1)
for s in S[::-1]:
    acc[i]+=r*int(s)
    acc[i]%=2019
    r%=2019
    r*=10
    i-=1
tm=(list(accumulate(acc)))[::-1]
dd=defaultdict(int)
ans=0
for t in tm:
    dd[t%2019]+=1
    ans+=dd[t%2019]*(dd[t%2019]-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

target = int(input())
rem = defaultdict(list)
for i in range(4,len(str(target))):
    rem[(target%(10**i))%2019].append(target%(10**i))
answer = 0
for i in range(2019):
    answer += len(rem[i])*(len(rem[i])-1)
answer += len(rem[0])
print(answer)
#1817181712114

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from collections import defaultdict
S = list(input().rstrip())
r = 1
i=len(S)
acc = [0]*(i+1)
for s in S[::-1]:
    acc[i]=r*int(s)
    acc[i]%=2019
    r%=2019
    r*=10
    i-=1
tm=(list(accumulate(acc)))[::-1]
dd=defaultdict(int)
ans=0
for t in tm:
    dd[t%2019]+=1
    ans+=dd[t%2019]*(dd[t%2019]-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i]) * pow(10,N-i-1,p))%p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1 
ans = cnt[0]
for i in range(1,p):
  m = cnt[i]
  ans += (m*(m-1))//2
print(ans+1)

Submission status: Wrong Answer

Solution code:
S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i]) * pow(10,N-i-1,p))%p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1 
ans = cnt[0]
for i in range(1,p):
  m = cnt[i]
  ans += (m*(m-1))//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i]) * pow(10,N-i-1,p))%p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1 
ans = 0
for i in range(p):
  m = cnt[i]
  ans += (m*(m-1))
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i]) * pow(10,N-i-1,p))%p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1
ans = cnt[0]
for i in range(1,p):
  m = cnt[i]
  ans += (m*(m-1))//2
print(ans)