TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
# 2019 = 3*673
MOD = 2019
S = input()
N = len(S)
X = [0]*2100
X[0] += 1
tmp = 0
hoge = pow(10,N,2019)

for i in range(N):
    tmp = (tmp*10+int(S[i]))%MOD
    hoge = (hoge*202)%MOD 
    X[(tmp*hoge)%MOD] += 1

ans = 0

for i in X:
    if i >= 2:
        ans += (i*i-1)

print(ans)

# 2019 = 3*673
MOD = 2019
S = input()
N = len(S)
X = [0]*2100
X[0] += 1
tmp = 0
hoge = pow(10,N,2019)

for i in range(N):
    tmp = (tmp*10+int(S[i]))%MOD
    hoge = (hoge*202)%MOD 
    X[(tmp*hoge)%MOD] += 1

ans = 0

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

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter

s = input()[::-1]
n = len(s)
counts = [0] * 2019
counts[0] = 1
current = 0
d = 0

for i in range(n):
    current += int(s[i]) * 10**d
    d += 1
    current %= 2019
    counts[current] += 1

ans = 0
for i, count in enumerate(counts):
    if count > 1:
        print(i)
        ans += count * (count-1) //2
print(ans)


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

# ans = 0
# # count = Counter(res)

# #     ans += (count[i] * (count[i] - 1)) // 2
# print(ans)



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)

#     ans += (count[i] * (count[i] - 1)) // 2
print(ans)



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)

#     ans += (count[i] * (count[i] - 1)) // 2
print(ans)



s = input()[::-1]
n = len(s)
counts = [0] * 2019
counts[0] = 1
current = 0
d = 1

for c in s:
    current += int(c) * d
    d *= 10
    current %= 2019
    d %= 2019
    counts[current] += 1

ans = 0
for count in counts:
    if count > 1:
        # print(i)
        ans += count * (count-1) //2
print(ans)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = list(map(str,input()))

counter = 0

for i in range(len(S)):
    for j in range(1,len(S)-i):
        s = int("".join(S[i:i+j]))
        if s % 2019 == 0:
            counter += 1

print(counter)

S = list(map(int,input()))[::-1] 

counter = 0
amari = [0]*2019
amari[0] = 1

s,d = 0,1

for i in S:
    s += i *d
    amari[s%2019] += 1
    d *= 10
    d %= 2019


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


print(int(counter))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import collections

S=input()
S_int = int(S)
mods_count = collections.Counter([int(S[i:])%2019 for i in range(len(S))])
count = 0
for mod in mods_count:
  c = mods_count[mod]
  if c > 1:
    count += c*(c-1)//2
print(count)

S=input()
dp = [0]*2019
dp[0]+=1

p=0
q=1
for i in reversed(range(len(S)-1)):
  p = (p+int(S[i])*q)%2019
  q = q*10%2019
  dp[p]+=1

c=0
for j in dp:
  c += j*(j-1)//2
print(c)

S=input()

p,q=0,1
dp = {0:1}
mod = 2019

for i in range(len(S)-1,-1,-1):
  p = (p+int(S[i])*q)%mod
  if p not in dp:dp[p]=0
  dp[p]+=1
  q= (q*10)%mod

cnt = 0
for i in dp:
  cnt += dp[i]*(dp[i]-1)//2
print(cnt)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# D - Multiple of 2019

s = input()

count = 0
counter = Counter([0])

suffix = 0
pow = 1
for i in range(len(s) - 1, -1, -1):
    suffix = (int(s[i]) * pow + suffix) % 2019
    pow = pow * 10 % 2019
    count += counter[suffix]
    counter[suffix] += 1

print(count)


# D - Multiple of 2019

from collections import Counter

s = input()

count = 0
counter = Counter([0])

suffix = 0
pow = 1
for i in range(len(s) - 1, -1, -1):
    suffix = (int(s[i]) * pow + suffix) % 2019
    pow = pow * 10 % 2019
    count += counter[suffix]
    counter[suffix] += 1

print(count)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = [int(a) for a in input()[::-1]]

m = 2019
n = len(S)

f = 0

p = 1

X = [0] * 2019

X[0] = 1

q = 0

for a in S:
    f = (f + a * p) % m
    q += X[f]
    
    X[s] += 1
    
    p = p * 10 % m
 

print(q)

n =input()


def judge(x):
  
  if x % 2019 == 0:
    return(1)
  else:
    return(0)

a = 0
for i in range(1,len(n)):
  for j in range(i, len(n)):
    s = n[i:j]
    d = int("s")
    a = a + judge(d)
    
print(a)
    

S = [int(a) for a in input()[::-1]]
m = 2019
N = len(S)
s = 0
p = 1
X = [0] * 2019
X[0] = 1
ans = 0
for a in S:
    s = (s + a * p) % m
    ans += X[s]
    X[s] += 1
    p = p * 10 % m
 
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = list(input())
n = len(s)
mod = 2019

d=[0]*(n+1)
k=1
for i in range(n):
    d[i+1]=d[i]+k*int(s[n-i-1])
    d[i+1]%=mod
    k*=10
    k%=mod

count = [0]*mod
for i in range(n+1):
    count[d[i]] += 1

ans = 0
for i in range(mod):
    c = count[i]
    ans += c*(c-1) / 2

print(ans)


s = list(input())
n = len(s)
mod = 2019

d=[0]*(n+1)
k=1
for i in range(n):
    d[i+1]=d[i]+k*int(s[n-i-1])
    d[i+1]%=mod
    k*=10
    k%=mod

count = [0]*mod
for i in range(n+1):
    count[d[i]] += 1

ans = 0
for i in range(mod):
    c = count[i]
    ans += c*(c-1) // 2

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    s = input()
    s_len = len(s)
    s_rev = reversed(s)
    mod = 2019
    d = [0] * mod
    d[0] = 1
    rev_num = 0
    
    for i in range(l_len):
        rev_num += int(s_rev(i)) * (10**i%mod)
        rev_num %= mod
        d[rev_num] += 1
    
    
    print(sum(i*(i-1)//2 for i in d))

if __name__ == '__main__':
    main()

def main():
    def modpow(x, n, mod):
        res = 1
        while n:
            if n % 2:
                res *= x % mod
            x *= x % mod
            n >>= 1
        return res

    s = input()
    s = s[::-1]
    s_len = len(s)
    mod = 2019
    d = [0] * mod
    d[0] = 1
    rev_num = 0
    
    for i in range(s_len):
        rev_num += int(s[i]) * int(modpow(10, i, mod))
        rev_num %= mod
        d[rev_num] += 1
    
    
    print(sum(i*(i-1)//2 for i in d))
 

def main():
    def modpow(x, n, mod):
        res = 1
        while n:
            if n % 2:
                res *= x % mod
            x *= x % mod
            n >>= 1
        return res

    s = input()
    s = s[::-1]
    s_len = len(s)
    mod = 2019
    d = [0] * mod
    d[0] = 1
    rev_num = 0
    
    for i in range(s_len):
        rev_num += int(s[i]) * int(modpow(10, i, mod))
        rev_num %= mod
        d[rev_num] += 1
    
    
    print(sum(i*(i-1)//2 for i in d))
 
if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
S = input()
print(len(S))
dict_amari = {}
count = 0

henkan = {i: [(10*j+i)%2019 for j in range(2019)] for i in range(1,10)}

def amari_new(dict_amari, s, henkan):
  dict_amari_new = {henkan[k] : v for k,v in dict_amari.items()}
  if s in dict_amari_new.keys():
    dict_amari_new[s] += 1
  else:
    dict_amari_new[s] = 1
  return dict_amari_new

for s in S:
  dict_amari = amari_new(dict_amari, int(s), henkan[int(s)])
  if 0 in dict_amari.keys():
    count += dict_amari[0]

print(count)

# -*- 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)

# -*- coding: utf-8 -*-
S = input()
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

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

print(count)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
count = 0
left = -1
right = 4
for i in range(len(s)-4):
    for j in range(i+4,len(s)):
        if int(s[i:j]) % 2019 == 0:
            left = i
            right = j
            break

if left >= 0:
    while right <= len(s):
        if int(s[left:right]) % 2019 == 0:
            # print(s[left:right])
            count += 1
            left = right - 1
            right = left + 4
        else:
            right += 1
print(count)

mods = [0]*2019
mods[0] = 1
s = input()
t = 0
u = 1
for i in range(1,len(s)+1):
    t = (t + int(s[-i])*u)%2019
    u = u*10%2019
    mods[t] += 1


cnt = 0
for x in mods:
    if x >= 2:
        cnt += x*(x-1)/2
print(int(cnt))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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)

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)

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 rxange(1,p):
  m = cnt[i]
  ans += (m*(m-1))//2
print(ans)

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 +=  (m*(m+1))//2
  else:
    ans += (m*(m-1))//2
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np


def count_multi(s, d):
  m = a = np.array([c for c in s]).astype(np.int)
  keta = 1
  count = np.count_nonzero(m == 0)
  while len(m) > 1:
    m = (m[:-1]*10 + a[keta:]) % d
    keta += 1
    count += np.count_nonzero(m == 0)
  return count
        
print(count_multi(input().strip()*2000, 2019))


import numpy as np


def count_multi(s, d):
  a = np.array([c for c in s]).astype(np.int)
  m = a % d
  keta = 1
  count = np.count_nonzero(m == 0)
  while len(m) > 1:
    m = (10*m[:-1] + a[keta:]) % d
    keta += 1
    count += np.count_nonzero(m == 0)
  return count
        
print(count_multi(input().strip(), 2019))


import numpy as np


def count_multi(s, d):
  a = np.array([int(c) for c in s], dtype=np.uint16)
  
  m = a
  # s not include 0
  count = 0
  while len(m) > 1:
    a = a[1:]
    m = (m[:-1]*10 + a) % d
    count += np.count_nonzero(m == 0)
  return count

print(count_multi(input().strip(), 2019)
      

def main():
    mod = 2019
    count = [0] * 2019
    count[0] = 1
    s = input().strip()
    digit = 1
    current = 0
    for c in s[::-1]:
        current = (current + int(c) * digit) % mod
        count[current] += 1
        digit = digit * 10 % mod
    return sum([n * (n - 1) // 2 for n in count if n > 1])


print(main())


Verdicts: Wrong Answer

Time Limit Exceeded

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# import sys 
# import os
# import numpy as np
# path = os.path.join(os.getcwd(),'input.txt')
# input = open(path).readline

S = input()
cand = np.zeros(2019,dtype=int)
ans = 0
rem = 0
for i,s in enumerate(S[::-1]):
    rem += int(s)*(10**i)
    rem %= 2019
    cand[rem] +=1
ans = cand[0]
cand = cand[cand>1]
for c in cand:
    ans += c*(c-1)/2
print(int(ans))

# import sys 
# import os
# path = os.path.join(os.getcwd(),'input.txt')
# input = open(path).readline

import numpy as np
S = input()
cand = np.zeros(2019,dtype=int)
rem = 0
order = 1
mod = 2019
for s in S[::-1]:
    rem += (int(s)*order)%mod
    rem %= mod
    cand[rem] +=1
    order *= 10
    order %=mod
ans = cand[0]
cand = cand[cand>1]
for c in cand:
    ans += c*(c-1)/2
print(int(ans))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
P = [0 for _ in range(len(S)+1)]
mod = 2019
d = 1
for i in range(len(S), 0, -1):
    P[i-1] = int(S[i-1])*d + P[i]
    P[i-1] = P[i-1] % mod
    d *= 10

for p in P:
    A[p] += 1

ans = 0
for a in A:
    ans += a*(a-1)//2
print(ans)

from collections import Counter
S = input()
P = [0] * (len(S)+1)
mod = 2019
d = 1
for i in range(len(S), 0, -1):
    P[i-1] = int(S[i-1])*d + P[i]
    P[i-1] = P[i-1] % mod
    d *= 10
    d = d % mod

P = Counter(P)
ans = 0
for p in P.values():
    ans += p*(p-1)//2
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
s = input()
y = 2019
dp = np.zeros(y, dtype="int64")
tmp = np.zeros(y, dtype="int64")
k = 1
r = 0
for c in s[::-1]:
    i = int(c)*k%y
    tmp[i:] = dp[:y-i]
    tmp[:i] = dp[-i:]
    tmp[i] += 1
    dp, tmp = tmp, dp
    r += dp[0]
    k *= 10
    k %= y
print(r) 1

from collections import *
s = input()
p = 2019
c = Counter()
c[0] += 1
v = r = 0
k = 1
for i in s[::-1]:
    v += int(i)*k
    v %= p
    r += c[v]
    c[v] += 1
    k *= 10
    k %= p
print(r)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter

S = [int(s) for s in input()]
y = 2019
T = [S[-1]] * len(S)

for i in range(len(S)-2, -1, -1):
  T[i] = (T[i+1] + S[i] * 10) % y

cnt = 0
for c in Counter(T).values():
  cnt += c * (c - 1) // 2
  
print(cnt)

from queue import deque


S = deque(input())
mod = 2019
T = [0] * mod
T[0] = 1
a, b = 0, 1

for _ in range(len(S)):
    s = int(S.pop())
    a = a + s * b
    a = a % mod
    T[a] += 1
    b = b * 10
    b = b % mod
    
print(sum((i * (i - 1) // 2 for i in T)))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = str(input())
L = len(s)
dict = {}
for i in range(L):
  amari = s[i:] % 2019
  if not(amari in dict.keys()):
    dict[amari] = 1
  else:
    dict[amari] += 1
ans = 0
for key in dict.keys():
  ans += (dict[amari]*(dict[amari]-1))/2
print(ans)

s = str(input())
L = len(s)
dict = {}
for i in range(L):
  amari = (int(s[i:])*(10**i)) % 2019
  if not(amari in dict.keys()):
    dict[amari] = 1
  else:
    dict[amari] += 1
dict[0] += 1
ans = 0
for key in dict.keys():
  ans += (dict[key]*(dict[key]-1))/2
print(int(ans))

s = str(input())
L = len(s)
dict = {}
for i in range(L):
  amari = (int(s[i:])*(10**i)) % 2019
  if not(amari in dict.keys()):
    dict[amari] = 1
  else:
    dict[amari] += 1
if not(0 in dict.keys()):
    dict[0] = 1
else:
    dict[0] += 1
ans = 0
for key in dict.keys():
  ans += (dict[key]*(dict[key]-1))/2
print(int(ans))

s = str(input())
L = len(s)
dict = {}
for i in range(L):
  amari = (int(s[i:])*(10**i)) % 2019
  if not(amari in dict.keys()):
    dict[amari] = 1
  else:
    dict[amari] += 1
ans = 0
for key in dict.keys():
  ans += (dict[key]*(dict[key]-1))/2
print(int(ans))

s = str(input())
L = len(s)
dict = {}
for i in range(L):
  amari = int(s[i:]) % 2019
  if not(amari in dict.keys()):
    dict[amari] = 1
  else:
    dict[amari] += 1
ans = 0
for key in dict.keys():
  ans += (dict[key]*(dict[key]-1))/2
print(int(ans))

s = str(input())
L = len(s)
dict = {}
for i in range(L-1):
  amari = int(s[i:]) % 2019
  if not(amari in dict.keys()):
    dict[amari] = 1
  else:
    dict[amari] += 1
ans = 0
for key in dict.keys():
  ans += (dict[key]*(dict[key]-1))/2
print(int(ans))

s = str(input())
L = len(s)
dict = [0] * 2019
dict[0] += 1
num = 0
for i in range(L-1, (-1), (-1)):
    num += (int(s[i]) * pow(10,(L-i-1), 2019))%2019
    amari = num % 2019
    dict[amari] += 1
ans = 0
for j in range(2019):
    ans += (dict[j]*(dict[j]-1))/2
print(int(ans))

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s_inv = str(input())[::-1]
dp = [1]+[0]*2018
ans = 0
num = 0
k = 1 
for i in range(len(s_inv)):
  num+=int(s_inv[i])*k % 2019
  dp[num] += 1
  k = k*10 % 2019
for i in dp:
  ans += i*(i-1)/2

S=int(input())
m=S//2019
ans=0
baisu=[]
for i in range(m):
  baisu.append(2019*(i+1))
for num in basiu:
  if num in str(S):
    ans += 1
print(ans)

s_inv = str(input())[::-1]
dp = [1]+[0]*2018
MOD = 0
k = 1
ans = 0

for i in range(len(s_inv)):
  MOD += s_inv[i]*k%2019
  dp[MOD] += 1
  k*10

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

print(ans)

s_inv = str(input())[::-1]
dp = [1]+[0]*2018
MOD = 0
ans = 0
num = 0
k = 1

for i in range(len(s_inv)):
  num+=int(s_inv[i])*k
  MOD = num % 2019
  dp[MOD] += 1
  k = k*10
  k %= 2019
for i in dp:
  ans += i*(i-1)/2

print(int(ans))


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import collections

S = list(input())
a=[int(x) for x in S] 
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)


print(int(len([i[0] for i in c.items() if i[1] >= 2])) + int(len([i for i in L if i==0])))

S = list(input())
a=[int(x) for x in S] 
a.reverse()
#print(a)
l=[0]*2019
l[0]=1
T=0
d=1

for i in a:
    T+=(int(i)*d)
    T%=2019
    l[T]+=1
    d*=10
    d%=2019
result=0
for n in l:
    result+=n*(n-1)/2
print(int(result))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import defaultdict

def count_substring(s):
    found_remainder = defaultdict(int)
    current_mod = 0
    found_remainder[0] = 1

    output = 0
    for i in range(len(s)-1,-1,-1):
        digit = s[i]
        current_mod =  (int(digit)*10**(len(s)-1-i) % 2019 + current_mod) % 2019
        print(i, current_mod)
        output += found_remainder[current_mod]
        found_remainder[current_mod] += 1

    return output

s = input()
print(count_substring(s))


from collections import defaultdict

def get_modulos():
    modulos = []
    for i in range(224):
        modulos.append(10**i%2019)
    return modulos

def count_substring(s):
    found_remainder = defaultdict(int)
    current_mod = 0
    found_remainder[0] = 1

    output = 0

    modulos = get_modulos()
    for i in range(len(s)-1,-1,-1):
        digit = s[i]
        current_mod =  (int(digit)*modulos[(len(s)-1-i)%224] % 2019 + current_mod) % 2019
        
        output += found_remainder[current_mod]
        found_remainder[current_mod] += 1
    print(dict(found_remainder))

    return output

s = input()
print(count_substring(s))

from collections import defaultdict

def main():
  s = input()
  
  current_mod = 0
  output = 0
  found_remainder = defaultdict(int)
  for i, digit in enumerate(s):
    current_mod = (current_mod*10 + int(digit)) % 2019
    output += found_remainder[current_mod]
    found_remainder[current_mod] += 1
  return output

from collections import defaultdict

def get_modulos():
    modulos = []
    for i in range(224):
        modulos.append(10**i%2019)
    return modulos

def count_substring(s):
    found_remainder = defaultdict(int)
    current_mod = 0
    found_remainder[0] = 1

    output = 0

    modulos = get_modulos()
    for i in range(len(s)-1,-1,-1):
        digit = s[i]
        current_mod =  (int(digit)*modulos[(len(s)-1-i)%224] % 2019 + current_mod) % 2019
        
        output += found_remainder[current_mod]
        found_remainder[current_mod] += 1
    #print(dict(found_remainder))

    return output

s = input()
print(count_substring(s))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
N = len(S)
c
ount = 0
for i in range(N):
    for j in range(i,N):
        if int(S[i:j+1]) % 2019 == 0:
            count = count + 1
        else:
            continue
print(count)

S = input()[::-1]
N = len(S)
l = [0]*2019
l[0] = 1
n = 0
d = 1

for i in range(N):
    n += int(S[i]) * d
    r = n % 2019
    l[r] += 1
    d = 10*d % 2019
    
out = 0    
for m in l:
    out += (m*(m-1))//2 
print(out)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = list(input())
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
for i in range(n):
    kar = kar + int(s[n-1-i])*10**i
    p[kar%2019] += 1

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

s = list(input())
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
dig = 1
for i in range(n):
    kar = (kar + int(s[n-1-i])*dig)%2019
    dig = (dig*10)%2019
    p[kar] += 1

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
S = input()

res = 0
start = 0
min_length = 4
end = start+min_length
max_end = len(S)

while True:
  tmp_s = S[start:end]
  
  if int(tmp_s) % 2019 == 0:
    print(tmp_s)
    res += 1
  
  if end+1 <= max_end:
    end += 1
  elif end-(start+1) >= min_length:
    start += 1
    end = start + min_length
  else:
    break
    
print(res)

s = input()[::-1] 

sum_of_digits = 0 
cnts = [0] * 2019 ごとに余りが同じ値の数を格納する変数。2019で割る場合、余りは0~2018までの2019通りあるので、リストの長さは2019
cnts[0] = 1 
d = 1 


for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10

    cnts[sum_of_digits] += 1


ans = 0
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2

print(ans)

s = input()[::-1] 

sum_of_digits = 0 
cnts = [0] * 2019 ごとに余りが同じ値の数を格納する変数。2019で割る場合、余りは0~2018までの2019通りあるので、リストの長さは2019
cnts[0] = 1 
d = 1 


for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10

    cnts[sum_of_digits] += 1


ans = 0
for cnt in cnts:
    ans += cnt * (cnt - 1) / 2

print(ans)

s = input()[::-1]

sum_of_digits = 0

cnts = [0] * 2019

cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

ans = 0
    
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2

print(ans)


Verdicts: Wrong Answer

Time Limit Exceeded

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s_len = len(s)
ref = [0] * s_len

for i in range(1, s_len + 1):
    ref[-i] = int(s[-i]) * pow(10, i, MOD) % MOD

for i in range(1, s_len):
    ref[-i - 1] += ref[-i]
    ref[-i - 1] %= MOD

ref_cnt = Counter(ref)
ans = sum(ref_cnt.values()) - len(ref_cnt)


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

if 0 in ref:
    ans += ref_cnt[0]

print(ans)

from collections import Counter
s = input()
MOD = 2019

s_len = len(s)
ref = [0] * s_len

for i in range(1, s_len + 1):
    ref[-i] = int(s[-i]) * pow(10, i, MOD) % MOD

for i in range(1, s_len):
    ref[-i - 1] += ref[-i]
    ref[-i - 1] %= MOD

ref_cnt = Counter(ref)
ans = sum(ref_cnt.values()) - len(ref_cnt)


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

if 0 in ref:
    ans += ref_cnt[0]

print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    S = list(input())
    N = len(S)
    ans = 0
    m = 2019
    div_list = [0]*m
    div_list[0] += 1
    num = 0
    print(N)
    for i in range(N):
        num += 10**i*int(S[N-i-1])
        div_list[num%m] += 1

    for item in div_list:
        ans += int(item*(item-1)/2)

    print(ans)

if __name__ == "__main__":
    main()



from sys import stdin
input = stdin.readline

def main():
    S = list(input())
    S.pop()
    m = 2019
    div_list = [0]*m
    num = 0
    for i, l in enumerate(reversed(S)):
        num += pow(10, i, m)*int(l)
        div_list[num%m] += 1

    div_list[0] += 1
    ans = 0
    for item in div_list:
        ans += int(item*(item-1)/2)

    print(ans)

if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
def main():
    A = input()[::-1]
    A = "0" + A
    # lis_num = [int(s) for s in A]

    # print(lis_num)

    # S = [0] * len(lis_num)
    S = [0] * len(A)
    cnt = [0] * 2019
    cnt[0] = 1

    for i in range(len(A) - 1):
        S[i + 1] = S[i] + int(A[i + 1]) * pow(10, i)
        cnt[S[i + 1] % 2019] += 1

    # print(S)


    
    #     cnt[i % 2019] += 1

    ans = 0

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

    print(ans)
    
if __name__ == '__main__':
    main()


def main():
    A = input()[::-1]
    A = "0" + A
    # lis_num = [int(s) for s in A]

    # print(lis_num)

    # S = [0] * len(lis_num)
    S = [0] * len(A)
    cnt = [0] * 2019
    cnt[0] = 1

    for i in range(len(A) - 1):
        S[i + 1] = (S[i] + int(A[i + 1]) * pow(10, i, 2019)) % 2019
        cnt[S[i + 1] % 2019] += 1

    # print(S)

    
    #     cnt[i % 2019] += 1

    ans = 0

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

    print(ans)


if __name__ == "__main__":
    main()


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def main():
  n, d, mods = 0, 1, [1]+[0]*2019
  for i in reversed(input()):
    n = (n+int(i)*d)%2019
    d = d*10
    mods[n] += 1
    print(n,d)
  print(sum([i*(i-1)//2 for i in mods]))
main()


S = list(input())
P = 0
for i in range(len(S)-4):
    for j in range(i+5,len(S)+1):
        M = ''.join(S[i:j])
        N = int(M)
        print(N)
        if N%2019 == 0:
            P += 1
print(P)

def main():
  n, d, mods = 0, 1, [1]+[0]*2019
  for i in reversed(input()):
    n = (n+int(i)*d)%2019
    d = d*10%2019
    mods[n] += 1
  print(sum([i*(i-1)//2 for i in mods]))
main()

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = list(input())
    N = len(S)

    val = [0] * (2019)
    tenfactor = 1
    cur = 0
    for i in range(N):
        cur = (cur + int(S[N - i - 1]) * tenfactor) % 2019
        tenfactor = (tenfactor * 10) % 2019
        val[cur] += 1

    ans = 0
    for p in range(2019):
        ans += val[p] * (val[p] - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()


import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = list(input())
    N = len(S)

    val = [0] * (2019)
    tenfactor = 1
    cur = 0
    val[cur] += 1
    for i in range(N):
        cur = (cur + int(S[N - i - 1]) * tenfactor) % 2019
        tenfactor = (tenfactor * 10) % 2019
        val[cur] += 1

    ans = 0
    for p in range(2019):
        ans += val[p] * (val[p] - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
cnt = 0
for l in range(len(s)):
    r = l + 4
    while r < len(s) and int(s[l:r]) % 2019 != 0:
        r += 1
    if int(s[l:r]) % 2019 == 0:
        cnt += 1
        print(l, r, s[l:r])
print(cnt)       

s = input()
cnt = 0
for l in range(len(s)):
    r = l + 1
    while r < len(s) and int(s[l:r]) % 2019 != 0:
        r += 1
    if int(s[l:r]) % 2019 == 0:
        cnt += 1
        print(i, j, s[i:j])
print(cnt)       

M = 2019
s = input()
tot, ten, ans = 0, 1, 0
cnt = [0] * M
for si in s[::-1]:
    cnt[tot] += 1
    tot += int(si) * ten
    tot %= M
    ans += cnt[tot]
    ten *= 10
    ten %= M
print(ans)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s=input()
m=len(s)
if n<2019:
    print(0)
    exit()
from collections import Counter
c=Counter()
tmp=""
c[0]+=1
for i in s[::-1]:
    tmp=i+tmp
    c[int(tmp)%2019]+=1

ll=c.most_common()
ans=0
for i,j in ll:
    if j>=2:
        ans+=j*(j-1)//2
    else:
        break
print(ans)


s=[int(j) for j in input()][::-1]
c=[0]*2019
tmp=0
c[0]+=1
t=1
import numpy as np
for i in s:
    tmp+=t*i
    c[tmp%2019]+=1
    t=t*10%2019
c=np.array(c)
ans=c*(c-1)//2
print(ans.sum())

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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))

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

import collections
p = 2019
s=input()
n=len(s)
arr=[int(s[i]) for i in range(len(s))] 
if p==2 or p==5: 
 ans=0
 for i in range(n):
   if arr[i]%p==0:
     ans+=i+1
 print(ans)
else: 
 dic=collections.defaultdict(int)
 tmp=0
 for i in range(n-1,-1,-1): 
   tmp+=arr[i]*pow(10,n-1-i,p)
   tmp%=p
   dic[tmp]+=1
 ans=0
 rem=0 
 for i in range(n-1,-1,-1):
   ans+=dic[rem]
   rem+=arr[i]*pow(10,n-1-i,p) 
   rem%=p
   dic[rem]-=1 
 print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = str(input())
N = len(S)
b = [0] * 2019
count = 0
b[0] = 1
t = 0
k = 1

if len(S) < 4:
    print(0)
else:
    t = int(S[-1])
    b[t] += 1
    for i in range(1,N):
        k = k * 10 % 2019
        t = (k * int(S[-i-1]) + t) % 2019 
        b[t] += 1

for i in b:
    count += i*(i-1)//2

S = str(input())
N = len(S)
b = [0] * 2019
count = 0
b[0] = 1
t = 0
k = 1

if len(S) < 4:
    print(0)
else:
    t = int(S[-1])
    b[t] += 1
    for i in range(1,N):
        k = k * 10 % 2019
        t = (k * int(S[-i-1]) + t) % 2019 
        b[t] += 1

    for i in b:
        count += i*(i-1)//2

    print(count)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
s = input()
# K = [2019, 4038, 6057, 8076, 10095, 12114, 14133, 16152, 18171, 20190, 22209, 24228, 26247, 28266, 30285, 32304, 34323, 36342, 38361, 40380, 42399, 44418, 46437, 48456, 50475, 52494, 54513, 56532, 58551, 60570, 62589, 64608, 66627, 68646, 70665, 72684, 74703, 76722, 78741, 80760, 82779, 84798, 86817, 88836, 90855, 92874, 94893, 96912, 98931, 100950, 102969, 104988, 107007,
#      109026, 111045, 113064, 115083, 117102, 119121, 121140, 123159, 125178, 127197, 129216, 131235, 133254, 135273, 137292, 139311, 141330, 143349, 145368, 147387, 149406, 151425, 153444, 155463, 157482, 159501, 161520, 163539, 165558, 167577, 169596, 171615, 173634, 175653, 177672, 179691, 181710, 183729, 185748, 187767, 189786, 191805, 193824, 195843, 197862, 199881]
K = ['2019', '4038', '6057', '8076', '10095', '12114', '14133', '16152', '18171', '20190', '22209', '24228', '26247', '28266', '30285', '32304', '34323', '36342', '38361', '40380', '42399', '44418', '46437', '48456', '50475', '52494', '54513', '56532', '58551', '60570', '62589', '64608', '66627', '68646', '70665', '72684', '74703', '76722', '78741', '80760', '82779', '84798', '86817', '88836', '90855', '92874', '94893', '96912', '98931', '100950', '102969', '104988',
     '107007', '109026', '111045', '113064', '115083', '117102', '119121', '121140', '123159', '125178', '127197', '129216', '131235', '133254', '135273', '137292', '139311', '141330', '143349', '145368', '147387', '149406', '151425', '153444', '155463', '157482', '159501', '161520', '163539', '165558', '167577', '169596', '171615', '173634', '175653', '177672', '179691', '181710', '183729', '185748', '187767', '189786', '191805', '193824', '195843', '197862', '199881']
count = 0
for i, k in enumerate(K):
    num = s.count(k)
    # print(i, num)
    count += num

print(count)


# -*- coding: utf-8 -*-
s = input()
mods = [0]*2019
mods[0] += 1

#     value = int(s[i:])
#     mods[value % 2019] += 1
base = 1
value = 0
for c in map(int, reversed(s)):
    value += (c*base) % 2019
    base = (base * 10) % 2019
    # value = int(s[i:])
    mods[value % 2019] += 1
print(sum([mod*(mod-1)//2 for mod in mods]))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

s = input()

a = np.zeros(len(s)+1, dtype='i8')
res = 0
for i in range(len(s)):
    for k in range(i+4, len(s)+1):
        if int(s[i:k]) % 2019 == 0:
            print(i, k)
            res += a[i] + 1
            a[k] += 1
            break

print(res)


s = input()[::-1]

res = 0
cnt = {0: 1}
now = 0
p = 1
for i in range(len(s)):
    now = (now + int(s[i]) * p) % 2019
    res += cnt.get(now, 0)
    p = (p * 10) % 2019
    cnt[now] = cnt.get(now, 0) + 1

print(res)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()

L = len(S)
d = 1
M = 0
ans = 0
while d <= 10 ** 100:
    if '0' in str(d):
        d *= 2019
        continue
    ds = str(d)
    l = len(ds)
    for i in range(L - l):
        if S[i:i + l] == ds:
            ans += 1
    d *= 2019
print(ans)


S = list(map(int, list(input()[::-1])))

N = len(S)
P = 2019
C = [0] * P
B = 1
t = 0
ans = 0
for i in range(N):
    C[t] += 1
    t = (t + S[i] * B) % P
    ans += C[t]
    B = B * 10 % P
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()

N = len(S)

ans = 0
for i in range(5,N+1):
  for j in range(0,N-i+1):
    Si = S[j:j+i]
    if int(Si) % 2019 == 0:
      ans += 1
      print(Si)

print(ans)

S = input()
counts =[0] * 2019
counts[0] = 1
num, d = 0,1

for s in S[::-1]:
  num += int(s) *d
  d *= 10
  num %= 2019
  d %= 2019
  counts[num] += 1

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
NN =str(N)

q = N // 2019

print(q)

dic = {}

for num in range(1,q+1):
    keta = len(str(2019*num))
    if str(keta) in dic:
        dic[str(keta)].append(str(2019*num).split())
    else:
        dic[str(keta)] = list(str(2019*num).split())

result = 0

for num, s in enumerate(NN):
    if s in ('2', '4', '6', '8'):
        for key in dic:
            keta = int(key)
            if NN[num: num+keta+1] in dic[key]:
                result += 1


print(result)


A = input()

S = 0
lis = [0] * 2019
lis[0] += 1
l = len(A)+1
d = 1

for n in reversed(A):
    S += int(n)*d
    S %= 2019
    lis[S] += 1
    d *= 10
    d %= 2019

result = 0

for n in lis:
    result += (n*(n-1)//2)


print(result)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)


from collections import defaultdict
S = input()
N = len(S)

D=defaultdict()
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)


from collections import defaultdict
S = input()
N = len(S)

D=defaultdict(int)
D[0]=1
ans=0
prev=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)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

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

S = input()
mod_bucket = [0] * 2019
mod_bucket[0] = 1
 
_S = S[::-1]
mod = 0
p = 1
for i in range(len(S)):
    mod = (p * int(_S[i]) + mod) % 2019
    mod_bucket[mod] += 1
    p = p*10%2019

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

from collections import Counter
N = input()
S=0
mod_count=[0]
ans=0
i=0
for X in N[::-1]:
  S = int(X)*pow(10,i,2019) % 2019
  S=mod_count[i]+S
  mod_count.append(S%2019)
  i+=1

c = Counter(mod_count)
ans = sum(Y * (Y-1)/2 for Y in c.values())
print(int(ans))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
l = len(s)
ans = 0
for i in range(l):
  for j in range(i+1, l+1):
    a =int(s[i:j]) % 10**9+7 
    if a % 2019 % 10**9+7 == 0:
      ans +=1
print(ans)

s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
  u=u+(i*d)%2019
  l[u]+=1
  d=d*10%2019
for i in l:
  ans+=i*(i-1)//2
print(ans)


s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
  u=(u+i*d%2019)
  l[u]+=1
  d=d*10%2019
for i in l:
  ans+=i*(i-1)//2
print(ans)


s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
  u=(u+(i*d)%2019)%2019
  l[u]+=1
  d=d*10%2019
for i in l:
  ans+=i*(i-1)//2
print(ans)


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted