Problem:


Score : 400 points

Problem Statement

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

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

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

Constraints

1 ≤ |S| ≤ 200000

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

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

1817181712114

Sample Output 1

3

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

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Runtime Error

Solution code:
import itertools
N = int(input())
Moji_List =['a','b','c']
Kumi_List = list(itertools.product(Moji_List, repeat=N)) 
for i in range(len(Kumi_List)):
    print(''.join(Kumi_List[i]))

Submission status: Runtime Error

Solution code:
#! python3
# coding:utf-8
 
def main():
    s = input()
    cnt = 0
    
    for i in range(1,len(s)):
        if s[i-1] <= 1:
            continue
        for j in range(i+3,len(s)+1):
            if int(s[i-1:j])%2019 == 0:
                cnt+=1
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
count = 0
DP = [[None for i in range(N)] for i in range(N)]
if N <= 3: print(0)
DP[3][0] = int(S[0:4]) % 2019
for i in range(4, N):
    for j in range(0, i-3):
        if DP[i-1][j] != None:
            DP[i][j] = (DP[i-1][j]*10 + int(S[i])) % 2019
            if DP[i][j] == 0:
                count += 1
        else:
            DP[i][j] = int(S[i-3:i+1]) % 2019
            if DP[i][j] == 0:
                count += 1
print(count)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
count = 0
DP = [[None for i in range(N)] for i in range(N)]
DP[3][0] = int(S[0:4]) % 2019
for i in range(4, N):
    for j in range(0, i-3):
        if DP[i-1][j] != None:
            DP[i][j] = (DP[i-1][j]*10 + int(S[i])) % 2019
            if DP[i][j] == 0:
                count += 1
        else:
            DP[i][j] = int(S[i-3:i+1]) % 2019
            if DP[i][j] == 0:
                count += 1
print(count)

Submission status: Runtime Error

Solution code:
cnt = 0
base = 0
MOD = 2019
s = open(0).read().rstrip()

for d in s:
    base *= 10
    base += int(d)
    tmp = base
    while tmp:
        if tmp % MOD == 0:
            cnt += 1
        tmp //= 10
print(ans)

Submission status: Runtime Error

Solution code:
cnt = 0
base = 0
MOD = 2019
s = input()

for d in s:
    base *= 10
    base += int(d)
    tmp = base
    while tmp:
        if tmp % MOD == 0:
            cnt += 1
        tmp //= 10
print(ans)

Submission status: Runtime Error

Solution code:
cnt = 0
base = 0
MOD = 2019

for d in input().rstrip():
    base *= 10
    base += int(d)
    tmp = base
    while tmp:
        if tmp % MOD == 0:
            cnt += 1
        tmp //= 10
print(ans)

Submission status: Runtime Error

Solution code:
cnt = 0
base = 0
MOD = 2019

for d in input():
    base *= 10
    base += int(d)
    tmp = base
    while tmp:
        if tmp % MOD == 0:
            cnt += 1
        tmp //= 10
print(ans)

Submission status: Runtime Error

Solution code:
cnt = 0
base = 0
MOD = 2019
# inv = pow(10,-1,MOD)

for d in input():
    base *= 10
    base += int(d)
    tmp = base
    while tmp:
        if tmp % MOD == 0:
            cnt += 1
        tmp //= 10
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [-1] * len(S)
r = 0
d = 1
for i,s in enumerate(S[::-1]):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[i] = r

ans = 0
c = Counter(p)
for k,n in c.most_common():
  if n > 1 ans n%2 == 0:
    ans += n//2
  else:break
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
N = (int(s)//2019) + 1
ans = 0
P = [0] * N
for i in range(N):
  P[i] = str(i*2019)

for p in P:
  k = s.find(p)
  if k != -1:
    ans += 1
    while k >= 0:
      k = s[k+1:].find(p)
      if k != -1:ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
n = (int(s)//2019) + 1
ans = 0
p = [0] * (n+1)
for i in range(1,n+1):
  p[i] = (2019 * i)

for j in p:
  ss = s
  while len(ss) > 0:
    idx = ss.find(str(j))
    if idx == -1:
      break
    else:
      ans += 1
      ss = ss[idx+1:]

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
n = (int(s)//2019) + 1
ans = 0
p = [0] * (n+1)
for i in range(n+1):
  p[i] = (2019 * i)

for j in p:
  ss = s
  while len(ss) > 0:
    idx = ss.find(str(j))
    if idx == -1:
      break
    else:
      ans += 1
      ss = ss[idx+1:]


print(ans)

Submission status: Runtime Error

Solution code:
from numba import jit
import numpy as np

@jit
def solve():
    
    s = np.array(list(input())[::-1])
    num = len(s)
    #print(s, num)
    
    l = np.array([])
    for i in range(1,num+1):
        l.append(int(''.join(s[:i][::-1])))
    #print(l)
    
    mod = []
    for j in range(num):
        mod.append(l[j] % 2019)
    mod = np.array(mod)
    
    ans = 0
    for p in range(num):
        if mod[p] == 0:
            ans += 1
        tmp = 1
        for q in range(p+1,num):
            if mod[p] == mod[q]:
                tmp += 1
        ans += (tmp-1)*tmp//2
    
    print(ans)

solve()

Submission status: Runtime Error

Solution code:
import collections
s=input()
l=[0]
n=len(s)
for i in range(n):
  if s[i]=='0':
    continue
  l.append(int(s[i:])%2019)
c=collections.Counter(l)
ans=0
v=c.values()
for vv in v:
  ans+=vv*(vv-1)//2
print(ans

Submission status: Runtime Error

Solution code:
S = input()
mod2019 = [0]*len(S)

for i in range(len(S)):
    mod2019[i] = int(S[i:])%2019

mod2019.extend(0)

answer = 0
count = [0 for _ in range(2020)]


for i in range(len(S)):
    answer += count[mod2019[i]]
    count[mod2019[i]] += 1
print(answer)

Submission status: Runtime Error

Solution code:
S = input()
mod2019 = [0]*(len(S)+1)

for i in range(len(S)):
    mod2019[i] = int(S[i:len(S)-1])%2019

answer = 0
count = [0 for _ in range(2020)]


for i in range(len(S)):
    answer += count[mod2019[i]]
    count[mod2019[i]] += 1
print(answer)

Submission status: Runtime Error

Solution code:
S = input()
mod2019 = [0]*(len(S)+1)

for i in range(len(S)):
    mod2019[i] = int(S[i:-1])%2019

answer = 0
count = [0 for _ in range(2020)]


for i in range(len(S)):
    answer += count[mod2019[i]]
    count[mod2019[i]] += 1
print(answer)

Submission status: Runtime Error

Solution code:
import collections
import sys
S = input()[::-1]
    
MOD=2019
X = [0]
for i, s in enumerate(S):
    X.append((X[-1]+int(s)*pow(10,i,MOD))%MOD)
    
c = collections.Counter(X)
ans = 0
for v in C.values():
    ans += v * (v - 1) // 2
print(ans)

Submission status: Runtime Error

Solution code:
import collections
import sys
S = input()[::-1]
if len(S)<=4:
    print(0)
    sys.exit()
    
MOD=2019
X = [0]
for i, s in enumerate(S):
    X.append((X[-1]+int(s)*pow(10,i,MOD))%MOD)
    
c = collections.Counter(X)
ans = 0
for v in C.values():
    ans += v * (v - 1) // 2
print(ans)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and not(numS == 0)):
        print(numS)
        cnt += 1
    if(end==len(S)-1):
        end = start+1
        s(start+1, end)
        return
    
    s(start, end+1)

S = input()
s(0, 1)
print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        cnt += 1
    if(end==len(S)-1):
        end = start+1
        s(start+1, end)
        return
    s(start, end+1)

S = str(input())
s(0, 0)
print cnt

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
        
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        cnt += 1
    if(end==len(S)-1):
        end = start+1
        s(start+1, end)
        return
    s(start, end+1)

S = input()
s(0, 0)
print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    try:
        numS = int(S[start:end+1])
    except:
        numS = 0
    if(numS%2019==0 and numS!=0):
        print(numS)
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

S = input()
s(0, 1)
print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

S = input()
s(0, 0)
print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)
S = input()
s(0, 1)
print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        print(numS)
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    try:
        numS = int(S[start:end+1])
    except:
        numS = 0
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return cnt
    numS = int(S[start:end+1])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    print(start, end)
    global cnt
    if(start==len(S)-1):
        return cnt
    numS = int(S[start:end+1])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return cnt
    numS = int(S[start:end])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return cnt
    numS = int(S[start:end])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)



if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Submission status: Runtime Error

Solution code:

cnt = 0

def s(start, end):
    global cnt
    if(start==len(S)-1):
        return cnt
    numS = int(S[start:end])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)



if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import defaultdict
INF = float('inf')

def main():
    S = readline().decode('utf-8')
    L = len(S)
    d = defaultdict(int)

    for i in range(L):
        s = int(S[i:])
        a = s%2019
        d[a] += 1

    ans = 0

    for key, value in d.items():
        ans += value*(value-1)//2
        if key == 0:
            ans += value

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = sys.stdin.readline()

    cnt = [0 for _ in range(2019)]
    cnt[0] += 1
    dec = 1
    num = 0
    for i in reversed(s):
        num += int(i) * dec
        num %= 2019
        dec *= 10
        cnt[num] += 1

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    # MODを使わない普通のComb
    def choose(n, r):
        res = 1
        fac = 1
        for i in range(r):
            res *= n - i
            fac *= i + 1
        return res // fac

    s = input()

    l = len(s)

    cnt = dict()

    for i in range(l + 1):
        tmp = s[i:]
        if len(tmp)==0:
            tmp = '0'
        tmp = int(s[i:])
        tmp %= 2019
        if tmp in cnt.keys():
            cnt[tmp] += 1
        else:
            cnt[tmp] = 1

    ans = 0
    for v in cnt.values():
        ans += choose(v, 2)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations
from bisect import bisect

input = lambda: sys.stdin.readline().rstrip("\r\n")
read = lambda: list(map(int, input().strip().split(" ")))

# sys.setrecursionlimit(10**5)



def solve():
    n = int(input()); arr = read()
    mex = 0; curr = 1
    ans = []
    last = 0
    for i in arr:
        # if i > last+2:
        #     print(-1, last, i);
        #     exit()
        # else:
        #     last = i
        if curr < i:
            print(-1);exit()
        if i == mex:
            ans.append(curr)
        else:
            ans.append(mex)
            mex = curr
            curr += 1
        

    print(*ans)






        

if __name__ == "__main__":
	solve()

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
S = input()

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

print(cnt)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
return 1

Submission status: Runtime Error

Solution code:
S = input()[::-1]
cur = 0
mods = Counter()
mods[0] += 1
MOD = 2019
for i,d in enumerate(S):
  cur += int(d) * pow(10, i, MOD)
  mods[cur%MOD] += 1

res = 0
for k,v in mods.items():
  res += (v * (v-1) // 2)

print(res)

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import deque
from collections import Counter

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    S = SI()
    l = len(S)
    T = [0] * (l+1)
    for i in range(l):
        T[i] = int(S[i:]) % 2019
    C = Counter(Counter(T).values())
    ans = 0
    for n, x in C.items():
        if n == 1: continue
        ans += cmb(n, 2) * x
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

cnt = [0]*2019
s[0] = 1
number = 0
d = 1

for i in s:
  number += int(i)*d
  cnt[number % 2019] += 1
  d *= 10
  d = d % 2019

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

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = readline().decode()
n = list(reversed(n))

x = 1
count = [0 for _ in range(2019)]
MOD = 2019
acc = 0

count[0] = 1
ans = 0

for c in n:
    a = x * int(c)
    acc += a
    acc %= MOD
    ans += count[acc]
    count[acc] += 1
    x = (x * 10) % MOD

print(ans)

Submission status: Runtime Error

Solution code:
a=0
S=int(input())
for i in range(N-3):
  for j in range(i+3,N+1):
    A=int(float(S[i:j+1]))
    if A%2019==0:
      a=a+1
print(a)

Submission status: Runtime Error

Solution code:
N = str(input())
list =[]
for i in range(len(N)-3):
    for j in range(i+3,len(N)+1):
        if int(N[i:j])%3!=0:
            continue
        if int(N[i:j])%673=0:
            list.append((i+1,j))

print(len(list))

Submission status: Runtime Error

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

## 余りを0~2018で総数保持
counts = [0]*2019
## 0桁の余りは0
counts[0] = 1

num, d = 0, 1

for c in s:
  ## 右から~桁の数字
  num += int(c) * d
  num %= 2019
  
  ## 次の桁
  d *= 10
  #d %= 2019
  
  counts[num] += 1
  
ans = 0
for cnt in counts:
  ## nC2の計算
  ans += cnt * (cnt-1) //2
  
print(ans)

Submission status: Runtime Error

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    s = list(map(int,ipt()))[::-1]
    d = defaultdict(int)
    ans = 0
    ni = 0
    mod = 2019
    d[0] = 1
    n10 = 1
    for i in s:
        ni = (ni+i*n10)%mod
        d[ni] += 1
        n10 = (n10*10)%mod
    for i in d.values():
        ans += i*(i-1)//2
    print(ans)

    return

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = input()
count = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
S=input()
N=len(S)
mod=[0 for i in range(2019)]
mod2=0
for i in range(N-1,-1,-1): 
  s=int(S[i])*(10**(N-1-i))
  mod2+=np.mod(s,2019)
  mod2=np.mod(mod2,2019)
  mod[mod2]+=1
ans=0
for i in range(2019):
  k=mod[i]
  if i==0:
    if k>=2:
      ans+=k*(k-1)//2+k
    else:
      ans+=k
  else:
    if k>=2:
      ans+=k*(k-1)//2
print(ans)

Submission status: Runtime Error

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

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


print(ans)

Submission status: Runtime Error

Solution code:
s = str(input())

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

mod = [1] + [0] * 2018
ans = 0
for i in num:
    ans += mod[m]
    mod[m] += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import collections
tmp=sys.stdin.readline()
def main():
   cnt=[0]*2019
   cnt[0]+=1
   for i in reversed(range(len(tmp))):
      cnt[int(tmp[i:])%2019] += 1
   cnt=collections.Counter(cnt).items()
   ans=0
   for i,j in cnt:
      if i > 1:
         ans+=i*(i-1)//2*j
   print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
tmp=sys.stdin.readline()
def main():
   cnt=[0]*2019
   cnt[0]+=1
   for i in reversed(range(len(tmp))):
      cnt[int(tmp[i:])%2019] += 1
   import collections
   cnt=collections.Counter(cnt).items()
   ans=0
   for i,j in cnt:
      if i > 1:
         ans+=i*(i-1)//2*j
   print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter
S = input()[::-1]
MOD = 2019

X = [0]

for i, s in enumerate(S):
    X.append((X[-1] + int(s) * pow(10, i, MOD)) %MOD)
    print(X)

C = Counter(X)
ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
#import numpy as np
#import bisect
S=input()
l=len(S)
p=0
#lock=np.arange(1,100)*2019
for i in range(0,l-3):
  for j in range(i+3,l+1):
    se=int(s[i:j])
    #index=bisect.bisect_left(lock, se)
    if se%2019==0:
      p+=1
    else:
      pass
print(p)

Submission status: Runtime Error

Solution code:
import numpy as np
import bisect
S=input()
l=len(S)
p=0
#lock=np.arange(1,100)*2019
for i in range(0,l-3):
  for j in range(i+3,l+1):
    se=int(s[i:j])
    #index=bisect.bisect_left(lock, se)
    if se%2019==0:
      p+=1
    else:
      pass
print(p)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
ans= 0
dp = [0]*(n+1)
A = [0]*2018
A[0] = 1
T = 0
for i in range(n):
  t = 10**(i)*int(s[n-i-1])
  T += t
  dp[i+1] = (dp[i]+ t%2019)%2019
  A[dp[i+1]] += 1

for i in range(2018):
  m = A[i]
  ans += m*(m-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
ans= 0
dp = [0]*(n+1)
A = [0]*2018
A[0] = 1
T = 0
for i in range(n):
  t = 10**(i)*int(s[n-i-1])
  T += t
  dp[i+1] = (dp[i]+ t%2019)%2019
  A[dp[i+1]] += 1

for i in range(2018):
  m = A[i]
  ans += m*(m-1)/2
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
s.reverse()
l = len(s)
se = dict()

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

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

Submission status: Runtime Error

Solution code:
s = str(input())
j = len(s)
l = []
for i in range(j):
    for ii in range(i, j):
        ss = int(s[i:ii + 1])
        if not ss:
            continue
        sss = ss / 2019
        if sss.is_integer():
            l.append(ss)

print(len(l))

Submission status: Runtime Error

Solution code:
s = str(input())
j = len(s)
l = []
for i in range(j):
    for ii in range(i, j):
        ss = int(s[i:ii + 1])
        sss = ss / 2019
        if sss.is_integer():
            l.append(ss)

print(len(l))

Submission status: Runtime Error

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

a[0] = int(S)
l[a[0]%2019] += 1

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

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

Submission status: Runtime Error

Solution code:
n = len(S)
a = [0]*n
l = [0]*2019

a[0] = int(S)
l[a[0]%2019] += 1

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter

S = str(input())

memo = [0]
d = 0
mod = 2019


for s in S[::-1]:
    tmp = int(s) * pow(10, d, mod) % mod
    tmp = memo[-1] + tmp
    memo.appemd(tmp%mod)
    d += 1

c = Counter(memo)
ans = sum(v * (v-1)/2 for v in c.values())
print(ans)

Submission status: Runtime Error

Solution code:
num = input()
count = 0
for i in range(0,len(num)-1):
  for j in range(1,len(num)):
    a = int(num[i:j])
    if a % 2019 == 0:
      count+=1
print(count)

Submission status: Runtime Error

Solution code:
num = input()
count = 0
for i in range(len(num)-1):
  for j in range(1,len(num)):
    a = int(num[i:j])
    if a % 2019 == 0:
      count+=1
print(count)