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):
def main():
    S = list(map(str,input().rstrip()))
    l = len(S)
    result=0   
    
    for i in range(l):
        for j in range(1,l-i+1):
            print(S[i,i+j+1])
            n = int("".join(map(str, St)))
            print(S)
            if n %2019==0:
                result+=1
    print(result)
    
if __name__ == "__main__":
    main()  
    

# coding: utf-8
# Your code here!
def main():
    from functools import reduce
    import collections
     
    S = list(map(int,input().rstrip()))
    N=len(S)
    mod_list = [0]
    for i in range(1,N+1):
        new1 =pow(10,i-1,2019)
        new = (new1*S[-i]+mod_list[-1])%2019
        print(new)
        mod_list.append(new)
        
    count = collections.Counter(mod_list)
    ans =0
    for j in range(2019):
        n = count[j]
        ans+= n*(n-1)/2
    print(int(ans))
if __name__ == "__main__":
    main()

# coding: utf-8
# Your code here!
def main():
    from functools import reduce
    import collections
     
    S = list(map(int,input().rstrip()))
    N=len(S)
    mod_list = [0]
    for i in range(1,N+1):
        new1 =pow(10,i-1,2019)
        new = (new1*S[-i]+mod_list[-1])%2019
        #print(new)
        mod_list.append(new)
        
    count = collections.Counter(mod_list)
    ans =0
    for j in range(2019):
        n = count[j]
        ans+= n*(n-1)/2
    print(int(ans))
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):
S = input()
count = 0
for i in range(i, len(S) - 4):
    for j in range(i+4, len(S)):
        if int(S[i:j]) // 2019 == 0:
            count += 1
print(count)

S = input()
mod = 2019

cs_mods = {0:1}
cumsum = 0
count = 0
for i, s in enumerate(S[::-1]):
    cumsum = (cumsum + int(s) * pow(10, i, mod)) % mod
    cs_mods.setdefault(cumsum, 0)
    # count += cs_mods[cumsum]
    cs_mods[cumsum] += 1

# count = 0
for k, v in cs_mods.items():
    count += v*(v-1)//2

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 = input()
answer = 0
for i in range(int(int(S))//2019 + 1):
    f = 2019 * i
    if f in S:
        answer += 1

print(answer)

S = input()
answer = 0
for i in range(-int(-int(S))//2019):
    f = 2019 * i
    if f in S:
        answer += 1
        
print(answer)

S = input()
answer = 0
for i in range(int(S)//2019 + 1):
    f = 2019 * i
    if f in S:
        answer += 1

print(answer)

S = input()
count = [0] * 2019
N = len(S)
mod = 0
for i in range(N):
    mod += 10*int(S[-i])
    if mod >= 2019:
        mod %= 2019
        
    count[mod] += 1

answer = count.pop(0)

for k in range(2018):
    if count[k] > 1:
        answer = answer + count[k]*(count[k] - 1)/2

print(int(answer))

S = input()
count = [0]*2019
mod = 0

for i in range(len(S))
	mod = int(S[-i]) % 2019
	count[mod] += 1

answer = 0

for k in range(2019)
	answer = answer + count[k]

print(answer)

S = input()
answer = 0
for i in range(int(S)//2019 + 1):
    f = 2019 * i
    if str(f) in S:
        answer += 1

print(answer)

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

pops = 0
digi = 1
cnt = [0] * 2019
cnt[0] = 1

while S:
    s = S.pop()

    pops = (pops + s * digi) % 2019
    digi = (10 * digi) % 2019

    cnt[pops] += 1

ans = 0

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

print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Time Limit Exceeded

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 gen_10exp_mod(n, mod):
    a = 1
    yield a
    for _ in range(1, n):
        a = (a*10) % mod
        yield a

def main():
    MOD = 2019
    S = input()[::-1]
    
    A = [int(s)*n % MOD for s, n in zip(S, gen_10exp_mod(len(S), MOD))]
    
    ACC = [0]
    for a in A:
        ACC.append((ACC[-1] + a) % MOD)
    
    print(ACC)
    d = defaultdict(int)
    for acc in ACC:
        d[acc] += 1
    ans = sum(v*(v-1)//2 for v in d.values())
    print(ans)


main()




from collections import defaultdict

def gen_10exp_mod(n, mod):
    a = 1
    yield a
    for _ in range(1, n):
        a = (a*10) % mod
        yield a

def main():
    MOD = 2019
    S = input()[::-1]
    
    A = [int(s)*n % MOD for s, n in zip(S, gen_10exp_mod(len(S), MOD))]
    
    ACC = [0]
    for a in A:
        ACC.append((ACC[-1] + a) % MOD)
    
    d = defaultdict(int)
    for acc in ACC:
        d[acc] += 1
    ans = sum(v*(v-1)//2 for v in d.values())
    print(ans)


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

length = len(S)
for i in range(0,len(S)-4):
  for j in range(i+4,i+4+length//100):
    if int(S[i:j+1]) % 2019 == 0 and j<length:
      cnt += 1

print(cnt)

S = input()
cnt = 0

for i in range(0,len(S)-2):
  for j in range(i+1,len(S)):
    if int(S[i:j+1]) % 2019 == 0:
      cnt += 1
      print(i, j)
      
print(cnt)

S = input()
cnt = 0

length = len(S)
for i in range(0,len(S)-4):
  for j in range(i+4,length//2):
    if int(S[i:j+1]) % 2019 == 0 and j<length:
      cnt += 1

print(cnt)

import collections
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * pow(10,i,2019)
  mod.append((now + mod[i]) % 2019)


c = collections.Counter(mod)
hindo = sorted(c.values(),reverse=True)
for i in hindo:
  if i != 1:
    cnt += i*(i-1)//2


print(cnt)

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()
dic = {}
for i in range(2019):
  dic[i] = 0
dic[0] = 1
for j in range(1, len(s)+1):
  m = int(s[:j]) % 2019
  dic[m] += 1
ans = 0
for v in dic.values():
  ans += v*(v-1) // 2
print(ans)


s = input()
dic = {}
for i in range(2019):
  dic[i] = 0
dic[0] = 1
m = 0
for j in range(len(s)):
  m = 10*m + s[j]
  m %= 2019
  dic[m] += 1
ans = 0
for v in dic.values():
  ans += v*(v-1) // 2
print(ans)


s = input()
dic = {}
for i in range(2019):
  dic[i] = 0
dic[0] = 1
for j in range(1, len(s)+1):
  m = s[:j] % 2019
  dic[m] += 1
ans = 0
for v in dic.values():
  ans += v*(v-1) // 2
print(ans)

s = input()
dic = {}
for i in range(2019):
  dic[i] = 0
dic[0] = 1
m = 0
for j in range(len(s)):
  m = 10*m + int(s[j])
  m %= 2019
  dic[m] += 1
ans = 0
for v in dic.values():
  ans += v*(v-1) // 2
print(ans)


s = input()
dic = {}
for i in range(2019):
  dic[i] = 0
dic[0] = 1
m = 0
decimal = 1
for j in range(1, len(s)+1):
  m += int(s[-j]) * decimal
  m %= 2019
  dic[m] += 1
  decimal *= 10
  decimal %= 2019

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


Verdicts: Wrong Answer

Runtime Error

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):
S=input()
i=2019
x = 0
while i <= int(S):
    for j in range(1,len(S)-len(str(i))+2,1):
        if int(S[j-1:j-1+len(str(i))]) == i:
            x += 1
    i += 2019
print(x)


S = input()[::-1]

S_mod = [0] * (len(S)+1)
S_mod[0] = int(S[0])

d = 10

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

mod_count = [0] * 2019
for i in range(len(S_mod)):
    mod_count[S_mod[i]] += 1
    
count = 0
for i in range(2019):
    count += mod_count[i] * (mod_count[i] - 1) / 2

print(int(count))

Verdicts: Time Limit Exceeded

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):
use std::io::stdin;
fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let s:Vec<char> = st.trim().chars().collect();
    let mut ten = 1;
    let mut c:usize = 0;
    let mut r:[i64;2020] = [0;2020];
    let m = s.len() as usize;
    for i in 1..m+1 {
        let mut x = s[m-i] as usize;
        x -= 48;
        c = (c+(x*ten)%2019)%2019;
        r[c] += 1;
        ten = (ten*10)%2019;
    };
    let mut result:i64 = 0;
    for i in 0..2019 {
        if &1 < &r[i] {
            result += (r[i]-1)*r[i]/2
        };
    };
    result += r[0];
    println!("{}", result);
}

s = input()
x = list(map(int, list(s)))
x = x[::-1]
dic = [0 for _ in range(2020)]
ten = 1
y = 0
for i in range(len(s)):
    y = (y+ten*x[i])%2019
    dic[y] += 1
    ten = (ten*10)%2019
result = 0
for i in range(2019):
    result += max([dic[i]*(dic[i]-1)//2, 0])
result += dic[0]
print(result)


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 = input()
    n = len(S)
    p = 2019 
    
    
    
    
    
    
    
    # ...
    
    
    
    
    
    
    
    
    

    
    S = [S[i] for i in range(n-1,-1,-1)]
    
    modp_counter = [0 for _ in range(p)]
    modp_tmp = int(S[0])%p
    modp_counter[modp_tmp] = 1
    pair_count = 0
    for i in range(1,n):
        modp = (int(S[i])*pow(10,i)%p+modp_tmp)%p
        modp_tmp = modp
        pair_count += modp_counter[modp]
        modp_counter[modp] += 1
    print(pair_count)


main()


def main():
    S = input()
    n = len(S)
    p = 2019 
    
    
    
    
    
    
    
    # ...
    
    
    
    
    
    
    
    
    

    
    S = [S[i] for i in range(n-1,-1,-1)]
    
    modp_counter = [0] * p
    modp = 0
    modp_counter[0] = 1 
    pair_count = 0
    d = 1
    for s in S:
        modp = (int(s)*d%p+modp)%p
        pair_count += modp_counter[modp]
        modp_counter[modp] += 1
        d *= 10
        d %= p 
    print(pair_count)


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

import numpy as np

s = input().strip()
t = 0
counts = np.array([0] * 2019)
counts[0] += 1
m = 1

for a  in reversed(s):
    t = (t + m * int(a)) % 2019
    counts[t] += 1
    m = m * 10 % 2019
    
print(int(np.sum(counts * (counts - 1) /2)))

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):
a = [1] + [0] * 2018
s, p = 0, 1

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

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

S = input()
P =2019
ans = 0

count = [0] * P
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
    u = (int(s) * pow(10, i, P) + u) % P
    ans += count[u]
    count[u] += 1
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()
s = list(reversed(s))
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
counitng[0] += 1
dp1[0] = 1
dp2[0] = int(s[0])
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
#print(counting)
sm = 0
for j in range(2019):
    sm += int(counting[j]*(counting[j]-1)/2)
print(sm)

s = input()
s = list(reversed(s))
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
dp1[0] = 1
dp2[0] = int(s[0])
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
sm = 0
for j in range(2019):
    sm += counting[j]*(counting[j]-1)
print(sm)

s = input()
s = list(reversed(s))
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
dp1[0] = 1
dp2[0] = int(s[0])
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
sm = 0
for j in range(2019):
    sm += int(counting[j]*(counting[j]-1)/2)
print(sm)

s = input()
s.reverse()
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
dp1[0] = 1
dp2[0] = s[0]
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
sm = 0
for j in range(2019):
    sm += counting[j]*(counting[j]-1)
print(sm)

s = input()
s = list(reversed(s))
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
dp1[0] = 1
dp2[0] = int(s[0])
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
sm = 0
for j in range(2019):
    sm += counting[j]*(counting[j]-1)/2
print(sm)

s = input()
s = list(reversed(s))
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
counting[0] += 1
dp1[0] = 1
dp2[0] = int(s[0])
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
#print(counting)
sm = 0
for j in range(2019):
    sm += int(counting[j]*(counting[j]-1)/2)
print(sm)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

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):
S = input()

r = 1
arr = [0]
for c in S[::-1]:
  arr.append((arr[-1] + int(c) * r) % 2019)
  r *= 10
  r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
  ans += v*v(v-1)//2
print(ans)

S = input()

r = 1
 arr = [0]
 for c in S[::-1]:
   arr.append((arr[-1] + int(c) * r) % 2019)
   r *= 10
   r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
  ans += v*v(v-1)//2
print(ans)

S = input()
r = 1
arr = [0]

for c in S[::-1]:
  arr.append((arr[-1] + int(c) * r) % 2019)
  r *= 10
  r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
  ans += v*(v-1)//2
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):
import sys
sys.setrecursionlimit(10000000)
S = input()
ans = 0

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


s = input()[::-1]
length = len(s)
a = [0] * length
d = [0] * length
ans = [0] * 2019
x = 10

a[0] = int(s[0])
d[0] = a[0]
ans[d[0]] += 1

for i in range(1, length):
    a[i] = int(s[i]) * x % 2019
    d[i] = (d[i-1] + a[i]) % 2019
    ans[d[i]] += 1
    x = x * 10 % 2019

ans_c = [i for i in ans if i != 0]

print(int(sum([ans_c[i] * (ans_c[i]-1) for i in range(len(ans_c))]) / 2) + ans[0])


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):
# if the remainders (mod 2019) are equal, the difference will be divisible
# x = Q*2019+5 y = R*2019+5 then x-y=(Q-R)*2019
# unless Q-R<=0
# where the substring itself is (Q-R)*2019/10**(something)

# so multiplying by 10 doesn't affect whether a number is divisible by it
from collections import Counter
s = input()
partial = 0
histo = Counter((partial+int(s[i])*10**(len(s)-1-i))%2019 for i in range(len(s)-1, -1, -1))

#   partial = (partial+int(s[i])*10**(len(s)-1-i))%2019
#   remainders.append(partial)

non_single_count = int(sum(count*(count-1)/2 for value, count in histo.items() if value!=0))
single_count = int(sum(count for value, count in histo.items() if value==0))
print(non_single_count+single_count)

# if the remainders (mod 2019) are equal, the difference will be divisible
# x = Q*2019+5 y = R*2019+5 then x-y=(Q-R)*2019
# unless Q-R<=0
# where the substring itself is (Q-R)*2019/10**(something)
from collections import Counter
s = input()[::-1]
partial = 0
remainders = list()
num = (int(character) for character in s)
for i, int_char in enumerate(num):
  partial = (partial+(int_char*pow(10,i,2019))%2019)%2019
  remainders.append(partial)
histo = Counter(remainders)
non_single_count = int(sum(count*(count-1)/2 for value, count in histo.items() if value!=0))
single_count = int(sum(count+count*(count-1)/2 for value, count in histo.items() if value==0))
print(non_single_count+single_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):
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline

from numba import njit


@njit
def loof(a):
    N = len(a)
    M = np.zeros(2019,dtype=np.int16)
    M[0] += 1
    T = 0
    memo = pow_mod(10,N,2019)
    for i in range(N-1,-1,-1):
        T = a[i] * memo[N-i-1] + T
        m = T % 2019
        M[m] += 1
        # print(m)
    return M


@njit
def pow_mod(a,n,mod):
    memo = np.array([1])
    if n >= 1:
        for i in range(n-1):
            memo = np.append(memo,memo[-1]*a%mod)
        return memo


def main():
    S = input().rstrip()
    S = list(map(int,list(S)))
    a = np.array(S)

    M = loof(a)
    # print(M)

    res = 0
    ans = np.array([res])

    flag = True
    cnt = 0

    for m in M:
        res += m * (m-1) // 2
        ans = np.append(ans,res)
        if (res == 3) & (flag):
            # print(m,cnt)
            flag = False
        cnt += 1

    # print(M[1164:1167])
    # print(ans)
    print(res)


# print(S)

# np.set_printoptions(threshold=2030)
main()


import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline

from numba import njit


@njit
def loof(a,N,memo):
    M = np.zeros(2019,dtype=np.int16)
    M[0] += 1
    T = 0
    for i in range(N-1,-1,-1):
        T = a[i] * memo[N-i-1] + T
        m = T % 2019
        M[m] += 1
    return M


@njit
def pow_mod(a,n,mod):
    memo = np.array([1])
    if n >= 1:
        for i in range(n-1):
            memo = np.append(memo,memo[-1]*a%mod)
        return memo


def main():
    S = input().rstrip()
    S = list(map(int,list(S)))
    a = np.array(S)

    N = len(a)

    memo = pow_mod(10,N,2019)
    M = loof(a,N,memo)

    res = 0

    for m in M:
        res += m * (m-1) // 2

    print(res)


main()


import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline

from numba import njit, i8



@njit
def loof(a,N):
    M = np.zeros(2019,dtype=np.int16)
    M[0] += 1
    T = 0
    r = 1
    T += a[-1] * r
    T %= 2019
    M[T] += 1
    for i in range(N-2,-1,-1):
        r *= 10
        r %= 2019
        T += a[i] * r
        T %= 2019
        M[T] += 1
    return M



# def pow_mod(a,n,mod):

#     if n >= 1:


#         return memo
#     else:
#         return memo[0]


def main():
    S = input().rstrip()
    S = list(map(int,list(S)))
    a = np.array(S)

    N = len(a)

    
    M = loof(a,N)

    res = 0

    for m in M:
        res += m * (m-1) // 2

    print(res)


main()


Verdicts: Time Limit Exceeded

Time Limit Exceeded

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 re

s = input()
ary = []
for i in range(10000):
  if not '0' in str(2019*i):
    ary.append(2019*i)

result = 0
for val in ary:
  result += len(re.findall(str(val), s))

print(result)


import re

s = input()
ary = []
for i in range(10000):
  if not '0' in str(2019*i):
    ary.append(2019*i)

print(re.findall('('+'|'.join(map(str, ary))+')+', s))


S = input()[::-1]

modCount = [1]+[0]*2018
mod = 0
dig = 1
result = 0

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

print(result)

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):
N = int(input())
S = [ input() for _ in range(N) ]
print(len(set(S)))

S = str(input())
N = len(S)
l = 0
r = 0


follow = 0
amari = [0] * N
for i in range(N):
  Kazu = int(S[N-i-1]) * pow(10, i)
  Amari_ = (int(Kazu) + follow) % 2019
  amari[i] = Amari_
  follow = Amari_

from collections import Counter
c_ = Counter(amari)
c = c_.most_common()

ans = 0
for i in c:
  if i[1] != 0:
    ans += i[1] * (i[1]-1) // 2
  else:
    break

ans == c_[0]
print(ans)

S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))

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):
def main(S=None):
    if not S:
        S = input()
    count = 0
    candidates = [str(i) for i in range(2019, 200000, 2019)]
    s_len = len(S)
    for candidate in candidates:
        candidate_len = len(candidate)
        for i in range(s_len):
            if i+candidate_len > s_len:
                break
            if S[i:i+candidate_len] == candidate:
                print(S[i:i+candidate_len], candidate)
                count += 1
    print(count)


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




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


if __name__ == "__main__":
    
    
    
    
    
    main()


def main(S=None):
    if not S:
        S = input()
    r = [0]*2019
    r[0] = 1
    tmp = 0
    base = 1
    for s in S[::-1]:
        s = int(s) * base
        base *= 10
        # base %= 2019
        tmp += s
        # tmp %= 2019
        r[tmp] += 1
    count = 0
    for v in r:
        count += v*(v-1)//2
    print(count)
    return count


if __name__ == "__main__":
    
    
    
    main()


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


if __name__ == "__main__":
    
    
    main()


def main(S=None):
    if not S:
        S = input()
    r = [0]*2019
    r[0] = 1
    tmp = 0
    base = 1
    for s in S[::-1]:
        s = int(s) * base
        base *= 10
        base %= 2019
        tmp += s
        tmp %= 2019
        r[tmp] += 1
    count = 0
    for v in r:
        count += v*(v-1)//2
    print(count)
    return count


if __name__ == "__main__":
    
    
    
    main()


Verdicts: Wrong Answer

Wrong Answer

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):
s = input()
l = len(s)
mod = [1] + [0 for _ in range(2017)]
ml = [0 for _ in range(l + 1)]
ans = 0

tmp = 0
for idx, degit in s[::-1]:
    m = (int(degit) * (10 ** idx) + tmp) % 2019
    tmp = m
    ans += mod[m]
    mod[m] += 1

print(ans)


s = input()
l = len(s)
mod = [1] + [0 for _ in range(2019)]
ml = [0 for _ in range(l + 1)]
ans = 0

tmp = 0
for idx, degit in enumerate(s[::-1]):
    m = int(degit) * pow(10, idx, 2019)
    m = (m + tmp) % 2019
    tmp = m
    ans += mod[m]
    mod[m] += 1

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):
s=input()
c=0
t=[0]*(len(s)+1)
for i in [str(i*2019) for i in range(1,10000) if '0' not in str(2019*i)]:
  idx=-1
  while s[idx+1:].count(i)>0:
    idx=s[idx+1:].find(i)
    t[idx+len(i)]+=1+t[idx]
    c+=1
    c+=t[idx]
print(c)

s=input()
n=len(s)
mod=2019
d=0
p=1
ml=[0]*mod
for i in range(1,n+1):
  k=int(s[-i])
  d+=p*k
  d%=mod
  ml[d]+=1
  p*=10
  p%=mod
ans=0
for i in ml:
  ans+=i*(i-1)//2
print(ans+ml[0])

Verdicts: Time Limit Exceeded

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 sys import stdin

input = stdin.readline


def main():
    s = list(input())
    s.reverse()
    MOD = 2019
    tot = 0
    ans = 0
    d = [0 for _ in range(MOD)]
    for i in range(len(s)):
        d[tot] += 1
        x = (10 ** i) % MOD
        p = int(s[i]) * x
        p %= MOD
        tot = (tot + p) % MOD
        ans += d[tot]
    return ans


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


def main():
    s = list(input())
    s.reverse()
    MOD = 2019
    tot = 0
    ans = 0
    d = [0 for _ in range(MOD)]
    for i in range(len(s)):
        d[tot] += 1
        x = pow(10, i, MOD)
        p = int(s[i]) * x
        p %= MOD
        tot = (tot + p) % MOD
        ans += d[tot]
    return ans


if __name__ == '__main__':
    print(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):
s=input()
n=len(s)
MOD=2019
from collections import defaultdict
d=defaultdict(int)
for i in range(n-1,-1,-1):
  d[int(s[i:n])%2019]+=1
ans=0
for i,v in enumerate(d):
  if i==0:
    ans+=v
else:
  ans+=v*(v-1)//2
print(ans)


s=input()
n=len(s)
l=[0]*2019
l[0]=1
k=0
mod=2019
r=1
for i in range(n-1,-1,-1):
  k+=s[i]*r
  r*=10
  r%=mod
  l[k]+=1
ans=0
for i in l:
  ans+=i*(i-1)//2
print(ans)

s=input()
n=len(s)
l=[0]*2019
l[0]=1
k=0
mod=2019
r=1
for i in range(n-1,-1,-1):
  k+=int(s[i])*r
  r*=10
  r%=mod
  l[k]+=1
ans=0
for i in l:
  ans+=i*(i-1)//2
print(ans)


s=input()
n=len(s)
l=[0]*2019
l[0]=1
k=0
mod=2019
r=1
for i in range(n-1,-1,-1):
  k+=int(s[i])*r
  k%=mod
  r*=10
  r%=mod
  l[k]+=1
ans=0
for i in l:
  ans+=i*(i-1)//2
print(ans)


Verdicts: Wrong Answer

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):
#D
s = input()
count = 0
# print(len(s))
for left in range(len(s) - 3):
    for right in range(left + 3, len(s)):
        print(left + 1, right + 1)
        if int(float(s[left:right + 1])) % 2019 == 0:
            print(s[left:right])
            count += 1
print(count)

s = input()
ans = 0
a = [0] * 2019
a[0] = 1
k = 0
mod = 1
for i in range(len(s) - 1, -1, -1):
    k = (k + int(s[i]) * mod) % 2019
    mod = (mod * 10) % 2019
    a[k] += 1
for i in a:
    ans += i * (i - 1) * 0.5
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()
N = len(S)
ans = 0
T = []
for i in range(N):

    T.append(int(S[i : N]) % 2019)
T.sort()
t = set(T)
counted = []
for i in t:
    a = T.count(i)
    if a > 1:
        counted.append(a)
for i in counted:
    ans += i * (i - 1) // 2
print(ans)


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


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


S = input()[::-1]
N = len(S)
amari = [0 for i in range(2019)]
before = int(S[0])
amari[before] += 1
S = S[1::]
keta = 1
for i in S:
    i = int(i)
    keta = (keta * 10) % 2019
    x = (keta * i + before) % 2019
    amari[x] += 1
    before = x
ans = amari[0]
for i in amari:
    ans += i * (i - 1) // 2
print(ans)


Verdicts: Wrong Answer

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=input()

ans=0
dd=[]

fir=int(s[0])*1000+int(s[1])*100+int(s[2])*10+int(s[3])
dd.append(fir%673)
for i in range(4,len(s)):
    tmp=(dd[i-4]*10+int(s[i]))%673
    dd.append(tmp)

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

bit=Bit(len(dd))
for i in range(1,len(dd)+1):
    bit.add(i,dd[i-1])
#print(dd)
for i in range(1,len(dd)):
    for j in range(i+1,len(dd)+1):
        if (bit.sum(j)-bit.sum(i))%673==0 and (bit.sum(j)-bit.sum(i))%3==0 :
            ans+=1


print(ans)



s=input()[::-1]

count=[0]*2019
count[0]+=1
sd=0
d=1
for c in s:
   sd+=int(c)*d
   sd%=2019
   d*=10
   d%=2019
   count[sd]+=1

ans=0
for cnt in count:
    ans+=cnt*(cnt-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):
def main():
    s = input()
    # si = tuple(int(c) for c in s)  # integers of one digit
    # ms = {2019 * x for x in range(10 ** 200000 - 1 // 2019)}
    ans = 0
    lg = len(si)
    # to slice till the last letter, +1 is needed.
    for i in range(lg + 1):
        for j in range(i + 4, lg + 1):
            j2 = j
            # 2019 = 673 * 3
            # if sum(si[i:j2]) % 3 != 0:
            #     continue
            if int(s[i:j2]) % 2019 == 0:
                ans += 1

    return ans


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


def main():
    s = input()
    if int(s) % 2019 == 0:
        return 0

    return 1


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


def main():
    s = input()
    rem = [0] * 2019  # the count of the each remainder: 0 ~ 2018
    rem[0] = 1  

    temp = 0
    for i, c in enumerate(s[::-1]):
        temp += pow(10, i, 2019) * int(c)
        rem[temp % 2019] += 1

    return sum(c * (c - 1) // 2 for c in rem)


if __name__ == '__main__':
    print(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):
S = input()
cnt = [0]*2019
cnt[0] = 1
n = 0
t = 1
for i in reversed(S):
    n += i*t
    n %= 2019
    cnt[n] += 1
    t *= 10
    t %= 2019
print(sum(i*(i-1)//2 for i in cnt))

S = input()
mod = 2019
cnt = [0]*mod
cnt[0] = 1
n = 0
t = 1
for i in map(int,n[::-1]):
    n += i*t
    cnt[n%mod] += 1
    t *= 10
print(sum(i*(i-1)//2 for i in cnt))


S = input()
cnt = [0]*2019
cnt[0] = 1
n = 0
t = 1
for i in reversed(S):
    n += int(i)*t
    n %= 2019
    cnt[n] += 1
    t *= 10
    t %= 2019
print(sum(i*(i-1)//2 for i in cnt))

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=input()
n=len(s)
s_int=[0]*n
x=pow(10,n-1)
for i in range(n):
    s_int[i]=int(s[i])
    x=x//10


s=input()
n=len(s)
s_int=[0]*n
x=pow(10,n-1)

s=input()
n=len(s)
s_int=[0]*n
x=pow(10,n-1)
for i in range(n):
    s_int[i]=(int(s[i])*x)%2019


s=input()
n=len(s)
s_int=[0]*n
x=pow(10,n-1)
for i in range(n):
    s_int[i]=int(s[i])

s=input()
n=len(s)
s_int=[0]*n
x=pow(10,n-1)
for i in range(n):
    s_int[i]=int(s[i]*x)%2019


s=input()
n=len(s)
s_int=[0]*n
x=(pow(10,n-1))%2019
for i in range(n):
    s_int[i]=(int(s[i])*x)%2019
    x=(x*202)%2019
t=[0]*(n+1)
t[0]=int(s)%2019
for i in range(1,n):
    t[i]=t[i-1]-s_int[i-1]
    t[i]%=2019
t.sort()
t_set=sorted(list(set(t)))
tcnt=[0]*len(t_set)
num=0
for i in range(n+1):
    if t_set[num]==t[i]:
        tcnt[num]+=1
    else:
        num+=1
        tcnt[num]+=1
sum=0
for i in range(len(tcnt)):
    sum+=(tcnt[i]*(tcnt[i]-1))//2
print(sum)


Verdicts: Wrong Answer

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):
s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
d=1
num=0
for i in range(len(s)):
    num += int(s[i])*d
    num %= 2019
    d *= 10
    d%= 2019
    # S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[num]+=1

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

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

S=[0,]
cnt=[0]*2019
cnt[0]=1
d=1
num=0
for i in range(len(s)):
    num += int(s[i])*d
    num %= 2019
    d *= 10
    d%= 2019
    # S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[num]+=1

ans=0
for i in cnt:
    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):
def main():
    import heapq
    inf = 10**16
    n, m, s = map(int, input().split())
    uvab = [list(map(int, input().split())) for _ in [0]*m]
    cd = [list(map(int, input().split())) for _ in [0]*n]
    g = [[] for _ in [0]*n]
    [g[a-1].append([b-1, c, d]) for a, b, c, d in uvab]
    [g[b-1].append([a-1, c, d]) for a, b, c, d in uvab]
    vertex = [[inf]*2501 for _ in [0]*n]
    h = [(0, 0, min(s, 2500))]  
    heapq.heapify(h)
    while h:
        t, p, money = heapq.heappop(h)
        if vertex[p][money] != inf:
            continue
        vertex[p][money] = t
        newmoney = min(money+cd[p][0], 2500)
        if vertex[p][newmoney] == inf:
            heapq.heappush(h, (t+cd[p][1], p, newmoney))
        for a, b, c in g[p]:  
            if money < b:
                continue
            if vertex[a][money-b] != inf:
                continue
            heapq.heappush(h, (t+c, a, money-b))
    for i in vertex[1:]:
        print(min(i))


main()


def main():
    s = input()
    d = [0]*2019
    d[0] += 1
    now = 0
    for j, i in enumerate(s[::-1]):
        now = (int(i)*pow(10, j, 2019)+now) % 2019
        d[now] += 1
    print(sum([i*(i-1)//2 for i in d]))


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):
s=input()[::-1]
n=len(s)
p=2019
S=[0 for i in range(n+1)]
ans=[0]*p

x10=1
for j, i in enumerate(s):
  S[j+1]=(S[j]+(x10*int(i)))%p
  x10=10**j
  x10%=p
  ans[S[j+1]]+=1

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


s=input()[::-1]
n=len(s)
p=2019
S=[0 for i in range(n+1)]
ans=[0]*p

x10=1
for j, i in enumerate(s):
  S[j+1]=(S[j]+(x10*int(i)))%p
  x10*=10
  x10%=p
  ans[S[j+1]]+=1

cnt=ans[0]
for a in ans:
  cnt+=(a*(a-1))//2
  
print(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()
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)


S = list(reversed(input()))
print(S)
length = len(S)

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

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

print(ans)

S = list(reversed(input()))

length = len(S)

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

b = [0]*(length+1)
for i in range(1, length+1):
    b[i] = (b[i-1] + a[i-1]) % 2019
cnt, ans = [0] * 2019, 0
for x in b:
    ans += cnt[x]
    cnt[x] += 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):
N,M=map(int,input().split())

li=list(range(N+1))
count=0

#print(li)
for i in range(M,N+2):
    small=(i*(i-1))//2
    large=small+li[-i]*i
    count+=large-small+1

print(count%(pow(10,9)+7))

S=input()

N=len(S)
count=0
tot=[0]*2019
S=S[::-1]
base=0
#print(S)
for i,s in enumerate(S):
    base+=int(s)*pow(10,i,2019)
    base%=2019
    #tot[base]+=1
    #print(base)
    if base==0:
        count+=1
    count+=tot[base]
    #print(tot[base],i,base)
    tot[base]+=1
#print(tot)    

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 = 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)

s = input()
from collections import Counter
x = 1
mod = 2019
total = 0
ans = 0
cnt = Counter()
for i in range(len(s)-1,-1,-1):
    cnt[total] += 1
    total = total + int(s[i])*x
    total %= mod
    ans += cnt[total]
    x = x*10%2019
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()
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)

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)

S = input()
A = [0 for i in range(2019)]
x = 0
q = 1
for i in range(len(S)):
    p = i + 1
    a = (int(S[-p]))
    b = a*q%2019
    x = (x+b) % 2019
    A[x] += 1
    q = q*10%2019
ans = A[0]
for i in range(2019):
    ans += A[i]*(A[i]-1)//2
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 = list(input())

a = ''
count = 0
i = 0
while(i < len(S)):
    for j in range(i,len(S)):
        a += S[j]
        if(int(a) % 2019 == 0):
            count += 1
    a = ''
    for j in range(i,len(S) - i):
        a += S[j]
        if(int(a) % 2019 == 0):
            count += 1
    i += 1
    a = ''
print(count)

S = input()
P =2019
ans = 0
 
count = [0] * P
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
    u = (int(s) * pow(10, i, P) + u) % P
    ans += count[u]
    count[u] += 1
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)

cnt = [0] * 2019

ans = 0
for i in range(N - 1, -1, -1):
    ans += cnt[int(S[i:N]) % 2019]
    cnt[int(S[i:N]) % 2019] += 1

print(ans)


S = input()
N = len(S)

cnt = [0] * 2019

cnt[0] = 1

ans = 0
e = 1; cur = 0
for s in reversed(S):
    cur = (cur + int(s) * e) % 2019

    ans += cnt[cur]

    e = (e * 10) % 2019
    cnt[cur] += 1

print(ans)

Verdicts: Wrong Answer

Accepted