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 collections import deque

s = list(input())
lsts = [0]*2019
kai = 1
cou = 0
for i in range(len(s)):
  s[i] = int(s[i])
s.reverse()
s = deque(s)
cou = 0
le = len(s)
st = 0
 
for i in s:
  st += i * kai
  amari = st % 2019
  if amari == 0:
    cou += 1
  else:
    cou += lsts[amari]
    lsts[amari] += 1  
  kai = (kai * 10)%2019

print(cou)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def main():
    S = [int(s) for s in input()]
    N = len(S)
    K = 2019

    V = [0] * (N+1)
    count = [0] * 2020
    count[0] = 1
    ans = 0
    for i in reversed(range(N)):
        rev_i = (N-1)-i
        v = V[rev_i] + S[i] * pow(10,rev_i+1,K)
        V[rev_i+1] = v
        u = v % K

        count[u] += 1
        cnt = count[u]
        ans -= (cnt-1) * (cnt-2)
        ans += cnt * (cnt-1)

    ans //= 2
    ans %= K
    print(ans)

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
MAX = 600000
MOD = int(1e9) + 7
fac = [0] * MAX
ifac = [0] * MAX
fac[0] = 1
for i in range(1,MAX):
    fac[i] = (fac[i-1] * i) % MOD
ifac[MAX-1] = pow(fac[MAX-1],MOD-2,MOD)
for i in reversed(range(1,MAX)):
    ifac[i-1] = (ifac[i] * i) % MOD

def combinations(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return (fac[n] * ifac[k] * ifac[n-k]) % MOD
MOD2 = 2019
s = list(input())
s.reverse()
n = len(s)
ans = 0
lis = [0] * 2020
x = 1
cnt = 0
for i in range(n):
    cnt += int(s[i]) * x
    cnt %= MOD2
    lis[cnt] += 1

    x *= 10
    x %= MOD2
for i in lis:
    ans += combinations(i,2)
# for i in lis:
#     if i >= 2:
#         print(i)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
s=str(input())
s1=len(s)
k=0
a=0
p=list()
if s1<4:
    print(0)
    sys.exit()
for i in range(s1):
    b=(int(s[s1-i-1])*10**i)%2019
    a=a+b
    p.append(a%2019)
for i in range(1,2019):
    l=p.count(i)
    if l>=2:
        k=k+l-1
print(k+math.factorial(p.count(0)))

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
nd = 1
mod1 = 0
listmod = [0]*2019
for i in S[::-1]:
    mod1 = (int(i)*nd + mod1)%2019
    listmod[mod1] += 1
    nd = (nd*10)%2019
for i in range(2019):
    n = listmod[i]
    if(i == 0):
        if(n == 1):
            ans += 1
        elif(n >= 2):
            ans += ((n-1)*n)/int(2)
    else:
        if(n > 1):
            ans += ((n-1)*n)//2
print(ans)

Submission status: Wrong Answer

Solution code:
def cal(S):
    N = len(S)
    num,cnt = 0,0
    mod = 2019
    rem = [0 for _ in range(mod)]
    for i in range(N):
        num = (num + int(S[N-1-i]) * pow(10,i,mod)) % mod
        rem[num] += 1

    output = (rem[0] * rem[0] + 1) // 2
    for i in range(1,mod):
        output += rem[i] * (rem[i]-1) // 2

    return output

def main():
    S = input()

    print(cal(S))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def cal(S):
    N = len(S)
    num,cnt = 0,0
    mod = 2019
    rem = [0 for _ in range(mod)]
    for i in range(N):
        num = (num + int(S[N-1-i]) * pow(10,i,mod)) % mod
        rem[num] += 1

    output = rem[0]
    for i in range(1,mod):
        output += rem[i] * (rem[i]-1) // 2

    return output

def main():
    S = input()

    print(cal(S))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
nd = 1
mod1 = 0
listmod = [0]*2019
for i in S[::-1]:
    mod1 = (int(i)*nd + mod1)%2019
    listmod[mod1] += 1
    nd = (nd*10)%2019
for i in range(2019):
    n = listmod[i]
    if(n>0):
        ans += ((n-1)*n)//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
nd = 1
mod1 = 0
listmod = [0]*2019
for i in S[::-1]:
    mod1 = (int(i)*nd + mod1)%2019
    listmod[mod1] += 1
    nd = (nd*10)%2019
for i in range(2019):
    n = listmod[i]
    ans += int((n-1)*n/2)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
nd = 1
mod2 = 0
listmod = [0]*2019
for i in S[::-1]:
    mod1 = (int(i)*nd + mod2)%2019
    listmod[mod1] += 1
    mod2 = mod1
    nd = (nd*10)%2019
for i in range(2019):
    n = listmod[i]
    if(i == 0):
        ans += int(n*(n+1))/2
    else:
        ans += int((n-1)*n/2)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
nd = 1
mod2 = 0
listmod = [0]*2019
for i in S[::-1]:
    mod1 = (int(i)*nd + mod2)%2019
    listmod[mod1] += 1
    mod2 = mod1
    nd = (nd*10)%2019
for i in range(2019):
    if(i == 0):
        ans += listmod[0]
    else:
        n = listmod[i]
        ans += int((n-1)*n/2)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
from collections import deque
z = deque([])
for i in range(len(s)):
    z.append(int(s[i:])%2019)

from collections import Counter
q = Counter(z)

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

Submission status: Wrong Answer

Solution code:
import itertools
s = input()
count = 0

for i,j in itertools.combinations(range(0,len(str(s))+1),2):
    if int(s[i:j]) % 2019 ==0:
        count +=1
    print(s[i:j])
print(count)

Submission status: Wrong Answer

Solution code:
S=list(input())
N=len(S)
mod=[0 for i in range(2019)]
s=0
ans=0
for i in range(2019):
  k=mod[i]
  if i==0:
    if k>=2:
      ans+=k*(k-1)//2+k
    else:
      ans+=k
  else:
    if k>=2:
      ans+=k*(k-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
S=list(input())
N=len(S)
mod=[0 for i in range(2019)]
s=0
for i in range(N-1,-1,-1): 
  s+=int(S[i])*(10**(N-1-i))
  mod2=s%2019
  mod[mod2]+=1
ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
from scipy.special import comb
S=input()
N=len(S)
mod=[0 for i in range(2019)]
for i in range(N):
  s=S[i:N+1]
  mod2=int(s)%2019
  mod[mod2]+=1
ans=0
for i in range(2019):
  k=mod[i]
  if i==0:
    if k>=2:
      ans+=comb(k,2)+k
    else:
      ans+=k
  else:
    if k>=2:
      ans+=comb(k,2)
print(ans)

Submission status: Wrong Answer

Solution code:
s = (input()[::-1]) # 入力文字列を逆順でsに格納
n = len(s)
counts = [0]*2019
counts[0]=1
b = 1
num = 0
for i in range(n):
    num += int(s[i])*b
    num %=2019
    b *=10
    b %2019
    counts[num]+=1

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
# print(counts)
ans = 0
for j in counts:
    ans +=j*(j-1)/2


print(ans)

Submission status: Wrong Answer

Solution code:
import math
s = (input()[::-1]) # 入力文字列を逆順でsに格納
n = len(s)
counts = [0]*2019
counts[0]=1
b = 1
num = 0
for i in range(n):
    num += int(s[i])*b
    num %=2019
    b *=10
    b %2019
    counts[num]+=1

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
# print(counts)
ans = 0
for j in counts:
    if j>=2:
        ans +=combinations_count(j, 2)

Submission status: Wrong Answer

Solution code:
s = str(input())
n = len(s)
count = 0
for i in range(1,n-2):
    for k in range(3,6):
        j = i+k
        if (j<=n):
            st = int(s[i-1:j])
            if int(st)%2019==0:
                count +=1
print(count)

Submission status: Wrong Answer

Solution code:
s=str((input()))
k=2019
list=[]
while(k<=200000):
    list.append(str(k))
    k+=2019
ans=0
for x in range(len(s)):
    aa=min(len(s)+1,x+5)
    bb=min(len(s)+1,x+6)
    t=s[x:aa]
    u=s[x:bb]
    if (t in list and len(t)==5):
        ans+=1
        print(t)
    if (u in list and len(u)==6):
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
s=str((input()))
k=2019
list=[]
while(k<=200000):
    list.append(str(k))
    k+=2019
ans=0
for x in range(len(s)):
    for y in range(x,min(x+6,len(s))):
        t=s[x:y+1]
        if t in list:
            ans+=1
print(ans)

Submission status: Wrong Answer

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

s = str(input())
count = 0

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

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

print(count)

Submission status: Wrong Answer

Solution code:
s = str(input())

num = [int(s[-1])]
mod = [1] + [0] * 2018
ans = 0
for i in range(1, len(s)):
    tmp = (num[-1] + pow(10, i, 2019) * int(s[-i - 1])) % 2019
    ans += mod[tmp]
    mod[tmp] += 1
    num.append(tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())

num = [int(s[-1])]
for i in range(1, len(s)):
    num.append(num[-1] + pow(10, i) * int(s[-i - 1]))

mod = [1] + [0] * 2018
ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
S = list(map(int, (list(input()))))
S.reverse()
T = [0] * len(S)
j = 1
for i in range(len(S)):
    if i == 0:
        T[i] += S[i] * j
        j = j*10 % 2019
    else:
        T[i] += (T[i - 1] + S[i] * j) % 2019
        j = j * 10 % 2019
ans = T.count(0)
k = 1
while k < 2019:
    x = T.count(k)
    ans += x * (x - 1) // 2
    k += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
int_s = 10**7

ans = 0
mul = 2019
while mul < int_s:
    sub_s = s
    f = sub_s.find(str(mul))
    while f != -1:
        ans += 1
        sub_s = sub_s[f+1:]
        f = sub_s.find(str(mul))
    mul += 2019

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
int_s = 10**8

ans = 0
mul = 2019
while mul < int_s:
    sub_s = s
    f = sub_s.find(str(mul))
    while f != -1:
        ans += 1
        sub_s = sub_s[f+1:]
        f = sub_s.find(str(mul))
    mul += 2019

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
int_s = 1000000

ans = 0
mul = 2019
while mul < int_s:
    sub_s = s
    f = sub_s.find(str(mul))
    while f != -1:
        ans += 1
        sub_s = sub_s[f+1:]
        f = sub_s.find(str(mul))
    mul += 2019

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
int_s = 1000000

ans = 0
mul = 2019
while mul < int_s:
    i = 0
    j = len(str(mul))
    while j < len(s):
        if s[i:j] == str(mul):
            ans += 1
        i += 1
        j += 1
    mul += 2019

ans += ans > 0

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

muls = [str(2019 * i) for i in range(1000)]

ans = 0
for mul in muls:
    i = 0
    j = len(mul)
    while j < len(s):
        if s[i:j] == mul:
            ans += 1
        i += 1
        j += 1

ans += ans > 0

print(ans)

Submission status: Wrong Answer

Solution code:
str_S = input()
#S = int(str(S))
P = list()
for i in range(len(str_S)):
    for j in range(len(str_S)):
        if j<i:
            continue
        else:
            B = str_S[i : j+1]
            #print(B)
            C = int(B)
            if C % 2019 == 0:
                print(B)
                P.append(B)
                #print(P)
            else:
                continue
#print(P)
print(len(P))

Submission status: Wrong Answer

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


MOD = 2019
dp = [0] * MOD

rem = 0
base = 1
for i in range(n):
    d = int(s[n-i-1])
    rem = (rem + base * d) % MOD
    # print((i, d, rem))
    dp[rem] += 1
    base *= 10
    base %= MOD

ans = 0
for i in range(MOD):
    ans += (dp[i]*(dp[i]-1)) // 2

if dp[0] > 0:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

s2019 = []

for n in range(200000 // 2019):
    s2019.append(n * 2019)

count = 0
for fs2019 in s2019:
    count += s.count(str(fs2019))

print(count)

Submission status: Wrong Answer

Solution code:
s = int(input())
ss = len(str(s))

count = 0
for i in range(ss):
    for j in range(i,ss):
        sa = s // (10**i)
        sb = sa % (10**(j+1-i))
        if (sb % 2019 == 0):
            count += 1
            print(i,j,sb)

print(count)

Submission status: Wrong Answer

Solution code:
import collections
S=input()
l=len(S)
T=0
A=[0]*2019
A[0]=1
for i in range(l):
    T+=int(S[l-i-1])*(10**i)
    A[T%2019]+=1
ans = 0
for cnt in A:
    ans += cnt * (cnt - 1) // 2
print(cnt)

Submission status: Wrong Answer

Solution code:
S = list(input())
mod_list = []

for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        num = int(''.join(S[i:j]))
        mod_list.append(num % 2019)

print('test')

Submission status: Wrong Answer

Solution code:
S=input()
ls=len(S)
ans=0
modlist=[]
for i in range(ls-3):
    smod=int(S[i:])%2019
    modlist.append(smod)
mlist=list(set(modlist))
for value in mlist:
    m=modlist.count(value)
    ans+=m*(m-1)/2
ans+=modlist.count(0)
print(int(ans))

Submission status: Wrong Answer

Solution code:
s = int(input())
ss = str(s)
n = len(ss)

i = 0
m = list()
while i<=n:
    m.append((s%(10**i))%2019)
    i+=1

def merge(x):
    if len(x)==1:
        return
    
    p, q = divmod(len(x), 2)
    l = [x.pop() for t in range(p)]
    r = [x.pop() for t in range(p+q)]
    merge(l)
    merge(r)
    l.reverse()
    r.reverse()
    while l and r:
        if l[-1]<=r[-1]:
            x.append(l.pop())
        else:
            x.append(r.pop())
    while l:
        x.append(l.pop())
    while r:
        x.append(r.pop())

i = 0
ans = 0
merge(m)
x = -1
y = 1
while i <= n:
    if x == m[i]:
        y+=1
    else:
        ans+=(y*(y-1))/2
        x = m[i]
        y = 1
    i+=1

print(ans)

Submission status: Wrong Answer

Solution code:
s = int(input())
ss = str(s)
n = len(ss)

i = 0
m = list()
while i<=n:
    m.append((s%(10**i))%2019)
    i+=1

i = 0
ans = 0
jud = 0
while i<n:
    j = 1
    while i+j<n:
        if m[i] == m[i+j]:
            ans += 1
        j+=1
    if m[i] == 0 and jud == 0 and i==n-1:
        ans += 1
        jud += 1
    i+=1

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
p=0
i=1
j=1
while j<=len(s):
    while i<=j:
        t=int(s[i-1:j])
        if t%2019==0:
            p+=1
            continue
        else:
            i+=1
            p=p
            continue
    else:
        j+=1
        continue
else:
    print(p)

Submission status: Wrong Answer

Solution code:
s=input()
p=0
i=1
j=1
while j<=len(s):
    while i<=j:
        t=int(s[i-1:j])
        if t%2019==0:
            p+=1
        else:
            i+=1
            p=p
    j+=1
print(p)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
P = 2019


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

    N = len(S)
    count = [0] * P
    count[0] += 1
    T = 0
    for i in range(N):
        T = (T + int(S[(N - 1) - i]) * pow(10, i, mod=P)) % P
        count[T] += 1

    ans = 0
    for k in count:
        ans = (ans + k * (k - 1) // 2) % P
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s=input()
a=0
m={}
for i in range(len(s)):
  b=int(s[len(s)-1-i])*10**i+a
  b=b%2019
  a=b
  if b in m:
    m[b]+=1
  else:
    m[b]=1
sum=0
for i in m:
  sum+=m[i]*(m[i]-1)/2
print(int(sum))

Submission status: Wrong Answer

Solution code:
S = input()
amari = [0]*2019
ans = 0
amari[0] = 1
A = 0
for i in range(len(S)):
    A += pow(10, i, 2019)*(int(S[len(S)-1-i]))
    amari[A % 2019] += 1
for i in amari:
    if i >= 2:
        ans += i*(i-1)/2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
amari = [0]*2019
ans = 0
amari[0] = 1
for i in range(len(S)):
    amari[int(S[len(S)-1-i:]) % 2019] += 1
for i in amari:
    if i >= 2:
        ans += i*(i-1)/2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
amari = [0]*2019
ans = 0
for i in range(len(S)):
    amari[int(S[len(S)-1-i:]) % 2019] += 1
for i in amari:
    if i >= 2:
        ans += i*(i-1)/2
print(ans)

Submission status: Wrong Answer

Solution code:
# int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字
s = input()
n = len(s)
dp = [0] * n
mod = 2019
for i in range(n):
    m = int(s[i]) * pow(10, n - i - 1, mod) % mod
    dp[i] = m

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        total = sum(dp[i:j + 1])
        if total % mod == 0:
            ans += 1
            print(i, j)
print(ans)

Submission status: Wrong Answer

Solution code:
n = list(input())
n.reverse()

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = list(input())
n.reverse()
x = [0]*(len(n))
a=0
for i in range(len(n)):
    a+=int(n[i])*10**i
    x[i]=a%2019

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=1
    for i in range(len(s)-1):
        if res[i]==0:
            ans+=1
        if res[i]==res[i+1]:
            cnt+=1
        else:
            ans+=cnt*(cnt-1)//2
            cnt=1
    print(ans)
if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

j = 0
if n > 4:
    for i in range(n-3):
        nn = int(S[i:i+4])
        if nn%2019 == 0:
            j += 1
print(j)

Submission status: Wrong Answer

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


print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
l=len(s)
se=dict()
k=0
for i in range(l-1,-1,-1):
    k+=(pow(10,l-1-i,2019)*int(s[i]))
    k%=2019
    if k in se:
        se[k]+=1
    else:
        se[k]=1

ans=0
for j in se:
    if se[j]>1:
        ans+=(i*(i-1)//2)
    if j==0:
        ans+=se[j]
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
l=len(s)
se=dict()
k=0
for i in range(l-1,-1,-1):
    k+=(pow(10,l-1-i,2019)*int(s[i]))
    k%=2019
    if k in se:
        se[k]+=1
    else:
        se[k]=1

ans=0
for j in se:
    if se[j]>1:
        ans+=(i*(i-1)//2)
    if j==0:
        ans+=i
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

for i in range(10**9):
  s = 1 + 1

Submission status: Wrong Answer

Solution code:
S = input()

for i in range(10 ** 8):
  a = 1+1

Submission status: Wrong Answer

Solution code:
S = input()

N = len(S)

if N <= 3:
    print(0)

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

print(count)

Submission status: Wrong Answer

Solution code:
# D
# Multiple of 2019
import itertools

s = input()[::-1]

d = len(s)

# _list = [None]*d
_map = [0]*2019

ans = 0
j,_ = 1,0

for i in s:
    _ += int(i) * j
    _tmp = _ % 2019
    j = (j*10)%2019
    if _tmp == 0:
        ans += 1
    elif _map[_tmp] ==1:
        ans += 1
        continue
    _map[_tmp] = 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
S_len = len(S)
S = int(S)
count = 0

for i in range(S_len):
  for j in range(i+2,S_len):
    pass
  
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
start, digit, count = 0, 1, 0
while digit <= len(str(s)):
  if int(str(s)[start:digit]) % 2019 != 0:
    digit += 1
  else:  
    start = digit - 1  
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
start, digit, count = 0, 1, 0
while digit <= len(str(s)):
  if int(str(s)[start:digit]) % 2019 != 0:
    digit += 1
  start = digit - 1  
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
start, digit, count = 0, 1, 0
while digit < len(s):
  if int(str(s)[start:digit]) % 2019 != 0:
    digit += 1
  start = digit - 1  
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

S = input().rstrip()
n = len(S)
l = [0]*2019
d = 10

t = int(S[n-1])

l[0] += 1

for i in range(n-2, -1, -1):
    t = t + int(S[i])*d
    l[t%2019] += 1 
    d *= 10

ans = 0

for i in l:
    ans += i*(i-1)//2

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
n = len(S)
l = [0]*2019
d = 10

t = int(S[n-1])

l[0] += 1

for i in range(n-2, -1, -1):
    t = t + int(S[i])*d
    l[t%2019] += 1 
    d *= 10

print(sum(map(lambda x: x*(x-1)//2, l)))

Submission status: Wrong Answer

Solution code:
S = input()
n = len(S)
t = [0]*(n+1)
l = [0]*2019

t[n] = 0
t[n-1] = int(S[n-1])

l[0] += 1

for i in range(n-2, -1, -1):
    t[i] = int(S[i]+str(t[i+1]))
    l[t[i]%2019] += 1 

# print(sum(map(lambda x: x*(x-1)//2, l)))

print(t)

Submission status: Wrong Answer

Solution code:
from collections import Counter

S = input()
n = len(S)
a = [int(S)]
cnt = 0

for i in range(n):
    a.append(a[i] - int(S[i])*(10**(n-i-1)))

a = Counter(list(map(lambda x: x%2019, a)))

for k, v in a.items():
    if v == 1:
        break
    cnt += v*(v-1)//2

print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    s = list(input()[:-1])[::-1]
    N = len(s)
    p10 = [1]
    tmp = 1
    for _ in range(N - 1):
        tmp = tmp * 10 % 2019
        p10.append(tmp)
    mod = []
    tmp = 0
    for num, p in zip(s, p10):
        tmp = (tmp + int(num) * p) % 2019
        mod.append(tmp)

    mod.sort()
    mod.insert(0, 0)

    ans = 0
    count = 1
    for i in range(1, N + 1):
        if mod[i] == mod[i - 1]:
            count += 1
        else:
            ans += count * (count - 1) // 2
            count = 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    s = list(input()[:-1])[::-1]
    N = len(s)
    p10 = [1]
    tmp = 1
    for _ in range(N - 1):
        tmp = tmp * 10 % 2019
        p10.append(tmp)
    mod = []
    tmp = 0
    for num, p in zip(s, p10):
        tmp = (tmp + int(num) * p) % 2019
        mod.append(tmp)

    mod.sort()

    ans = 0
    count = 1
    for i in range(1, N):
        if mod[i] == mod[i - 1]:
            count += 1
        else:
            if mod[i - 1] == 0:
                count += 1
            ans += count * (count - 1) // 2
            count = 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    s = list(input()[:-1])[::-1]
    N = len(s)
    p10 = [1]
    tmp = 1
    for _ in range(N - 1):
        tmp = tmp * 10 % 2019
        p10.append(tmp)
    mod = []
    tmp = 0
    for num, p in zip(s, p10):
        tmp = (tmp + int(num) * p) % 2019
        mod.append(tmp)

    mod.sort()
    ans = 0
    count = 1
    for i in range(1, N):
        if mod[i] == mod[i - 1]:
            count += 1
        elif mod[i - 1] == 0:
            ans += 1
        else:
            ans += count * (count - 1) // 2
            count = 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    s = list(input()[:-1])[::-1]
    N = len(s)
    p10 = [1] * N
    for i in range(N - 1):
        p10[i + 1] = p10[i] * 10
    mod = []
    tmp = 0
    for num, p in zip(s, p10):
        tmp = (tmp + int(num) * p) % 2019
        mod.append(tmp)

    mod.sort()
    ans = 0
    count = 1
    for i in range(1, N):
        if mod[i] == mod[i - 1]:
            count += 1
        elif mod[i - 1] == 0:
            ans += 1
        else:
            ans += count * (count - 1) // 2
            count = 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit
import collections


def main():
    input = stdin.readline
    s = list(input()[:-1])[::-1]
    N = len(s)
    p10 = [1] * N
    for i in range(N - 1):
        p10[i + 1] = p10[i] * 10
    mod = []
    tmp = 0
    for num, p in zip(s, p10):
        tmp = (tmp + int(num) * p) % 2019
        mod.append(tmp)

    mod.sort()
    ans = 0
    count = 1
    for i in range(1, N):
        if mod[i] == mod[i - 1]:
            count += 1
        elif mod[i - 1] == 0:
            ans += 1
        else:
            ans += count * (count - 1) // 2
            count = 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit
import collections


def main():
    input = stdin.readline
    s = list(input()[:-1])
    s = list(map(int, s))
    N = len(s)
    p10 = [1] * (N + 1)
    for i in range(N):
        p10[i + 1] = p10[i] * 10
    mod = [0] * N
    mod[-1] = s[-1] % 2019
    for i in reversed(range(N - 1)):
        mod[i] = (mod[i + 1] + s[i] * p10[N - i - 1]) % 2019

    mod.sort()
    ans = 0
    count = 1
    for i in range(N):
        if mod[i] == mod[i - 1]:
            count += 1
        elif mod[i] == 0:
            ans += 1
        else:
            ans += count * (count - 1) // 2
            count = 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
s = input()[::-1]

lst = []
num = 1
pow10 = [1]
for _ in range(len(s) - 1):
    num = num * 10 % 2019
    pow10.append(num)

num = 0
for s_num, p10 in zip(s, pow10):
    num = (num + (int(s_num) * p10)) % 2019
    lst.append(num)
lst.sort()

Submission status: Wrong Answer

Solution code:
S = input()
A = [0 for i in range(2019)]
x = 0
for i in range(len(S)):
    p = i + 1
    a = (int(S[-p]))*10**i % 2019
    x = (x+a) % 2019
    A[x] += 1
ans = A[i]
for i in range(2019):
    ans += A[i]*(A[i]-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
mod = 2019
s = input().rstrip()
n = len(s)
mod_list = [0]
for i in range(n - 1, -1, -1):
    print(s[i])
    mod_list.append((mod_list[-1] + int(s[i]) * 10**(n - 1 - i) ) % mod)
from collections import Counter
c = Counter(mod_list)
ans = 0
for i in c.keys():
    ans += c[i] * (c[i] - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
count=0
for i in range(len(N)+1):
  for j in range(i+1,len(N)+1):
    if(int(N[i:j])%3==0):
      continue
    if(int(N[i:j])%673==0):
      count+=1

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

S = input()
MOD = 2019
dp = np.zeros(MOD, dtype=np.int64)
dp[0] = 1

def hoge(dp, s):
    T = dp.copy()
    dp[s:] = T[:-s]
    dp[:s] = T[-s:]

def huga(dp, s):
    for i in range(MOD):
        dp[i] = dp[(i - s) % MOD]

ans = 0
for i, s in enumerate(S[::-1]):
    huga(dp, (int(s) * pow(10, i, MOD)) % MOD)
    ans += dp[0]
    dp[0] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

dp = [0] * (len(S) + 1)
for i, c in enumerate(S):
    dp[i + 1] = (10 * dp[i] + int(c)) % 2019
for i, _ in enumerate(dp):
    dp[i] *= pow(10, -i%2019, 2019)
    dp[i] %= 2019

counts = [0] * 2019
for c in dp:
    counts[c] += 1

result = 0
for count in counts:
    result += count * (count - 1) // 2

print(result)

Submission status: Wrong Answer

Solution code:
S = input()

dp = [0] * (len(S) + 1)
for i, c in enumerate(S):
    dp[i + 1] = 10 * dp[i] + int(c) % 2019
for i, _ in enumerate(dp):
    dp[i] *= pow(10, -i%2019, 2019)
    dp[i] %= 2019

counts = [0] * 2019
for c in dp:
    counts[c] += 1

result = 0
for count in counts:
    result += count * (count - 1) // 2

print(result)

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
n=len(s)
beki=[0 for i in range(n+1)]
beki[0]=1
for i in range(n):
    beki[i+1]=(beki[i]*10)%2019
#print(beki)

#k=int(s)
dp=[0 for i in range(n)]
dp[-1]=int(s[-1])
for i in range(n):
    j=n-i-1
    dp[j-1]=(dp[j]+int(s[j-1])*beki[i+1])%2019
#print(dp)
ans=0
u=Counter(dp)
#print(u)
for i in u:
    if i==0:
        ans+=(u[i]*(u[i]+1))//2
    else:
        ans+=(u[i]*(u[i]-1))//2
print(ans)

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
n=len(s)
beki=[0 for i in range(n+1)]
beki[0]=1
for i in range(n):
    beki[i+1]=(beki[i]*10)%2019
#print(beki)

#k=int(s)
dp=[0 for i in range(n)]
dp[-1]=int(s[-1])
for i in range(n):
    j=n-i-1
    dp[j-1]=(dp[j]+int(s[j-1])*beki[i+1])%2019
#print(dp)
ans=0
u=Counter(dp)
for i in u:
    ans+=(u[i]*(u[i]-1))//2
print(ans)