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:
S = list(input())
N = len(S)
# N 文字の文字列 S から、長さ N+1 の ---累積和--- s[0], s[1], ..., s[N] を作る
# これを 2019 で割ったあまりで分類する (具体的には counter[ r ] := あまりが r のやつが何個あるか)
# 各 r ごとに、counter[r] 個から 2 個選ぶ方法の数を、足し上げる

counter = [0] * 2019
indices = []
k = 10
for i in range(N + 1):
    if i == 0:
        sub = 0
        counter[i] = 0
    elif i == 1:
        sub = int(S[N - 1])
        counter[i] = sub % 2019
    else:
        # sub = int(S[N - i] + str(sub))
        sub += int(S[N - i]) * k
        k *= 10

        counter[i] = counter[i-1] + sub
        counter[i] %= 2019
        k %= 2019

    # rest = sub % 2019  # N桁のあまりを求めるのにO(N)かかる．前の桁を有効活用する(dp)
    # counter[rest] += 1

ans = 0
for r in counter:
    ans += r * (r - 1) // 2
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())
 
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
 
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
 
INF = float('inf')
 
def solve():
    S = list(map(int, list(input())))
 
    S = S[::-1]
    # print(S)
    n = len(S)
    mod = 2019
 
    #
    A = [0] * (n)
    a = 1
    for i in range(n):
        A[i] = S[i] * a
        a = a * 10 % mod
    # print(A)
 
    # 累積和
    R = [0] * (n+1)
    for j in range(n):
        R[j+1] = (R[j] + A[j]) % mod
    # print(R)
 
    # 個数を数える
    cnt = {}
    ans = 0
    for l in range(0, n+1):
        r = R[l]
        ans = ans + cnt.get(r, 0)
        cnt[r] = cnt.setdefault(r, 0) + 1
    print(ans)
 
if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    S = list(map(int, list(input())))

    S = S[::-1]
    # print(S)
    n = len(S)
    mod = 2019

    #
    A = [0] * (n)
    a = 1
    for i in range(n):
        A[i] = S[i] * a
        a = a * 10 % mod
    # print(A)

    # 累積和
    R = [0] * (n+1)
    for j in range(n):
        R[j+1] = (R[j] + A[j]) % mod
    # print(R)

    # 個数を数える
    cnt = {}
    ans = 0
    for l in range(0, n+1):
        r = R[l]
        ans = ans + cnt.get(r, 0)
        cnt[r] = cnt.setdefault(r, 0) + 1
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
strS = input()
S = int(S)
lenS = len(strS)

ans = 0
for i in range(lenS):
    if i+3 <= lenS:
        for j in range(i+3, lenS):
            if int(strS[i:j+1])%2019 == 0:
                ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
strS = input()
S = int(S)
lenS = len(str(S))

ans = 0
for i in range(lenS):
    if i+3 <= lenS:
        for j in range(i+3, lenS):
            if int(strS[i:j+1])%2019 == 0:
                ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = input()
s = [0] * 2020
m = [0] * 2020
m[0] = 1
s[0] = 1
for i in range(1, 2020):
    m[i] = (m[i-1]*10) % 2019
tmp = 0
for i in range(len(n)):
    #print(i, n[-1-i], m[i])
    tmp = (tmp + int(n[-1-i])*m[i]) % 2019
    # print(tmp)
    s[tmp] += 1
su = 0
for i in s:
    if i > 1:
        # print("#", i)
        su += i * (i - 1)//2
print(su)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()

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

Submission status: Runtime Error

Solution code:
# D

def this(S, t):
    res = 19 * t
    res_str = str(res)
    _S = int(S[2:2+len(res_str)])
    if res > _S:
        return False
    elif res == _S:
        return True
    else:
        diff = res - _S
        _next = str(diff) + S[2+len(res_str):]
        if int(_next[0:2])%2 !=0:
            return False
        else:
            this(_next, int(int(_next[0:2])/2))
            
start = 0
ind = [[i, int(int(S[i:i+2])/2)] for i in range(N-3) if int(S[i:i+2])%2 == 0]
res = [this(S[elem[0]:],elem[1]) for elem in ind]
c = len([1 for r in res if r])
print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

tmp_amari = [0]*2019

#amari = 0
num = 0
order = 1
for i in s:
    num += int(i)*order
    num %= 2019
    #print(num)
    tmp_amari[num] += 1
    order *= 10

#tmp_print = [i for i in tmp_amari if i > 0]
#print(tmp_print)

ans = 0
ans += tmp_amari[0]

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

print(ans)

Submission status: Runtime Error

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

tmp_amari = [0]*2019

#amari = 0
num = 0
order = 1
for i in s:
    num += int(i)*order
    num %= 2019
    print(num)
    tmp_amari[num] += 1
    order *= 10

#tmp_print = [i for i in tmp_amari if i > 0]
#print(tmp_print)

ans = 0
ans += tmp_amari[0]

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

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	S = input()
	S = S[:-1]
	S = S[::-1]

	dol = {}
	tmptmp = 0
	ans = 0
	kinou = 0
	for i,val in enumerate(S):
		
		if tmptmp == 0:
			tmptmp = 1
		else:
			tmptmp = tmptmp * 10
		#tmp = (int(val) * tmptmp) % 2019
		tmp = tmp + kinou % 2019
		kinou = tmp

		if tmp in dol:
			ans += 1
		else:
			dol[tmp] = 1

	print(ans)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Runtime Error

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


    # for i in 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()

Submission status: Runtime Error

Solution code:
import numpy as np
s = input()
s = np.array([int(d) for d in s[::-1]])
m = 2019
t = 1
ans = 0
c = np.zeros(2019, dtype=np.int64)
c[0] = 1
r = 0
for d in s:
  r = (d * t + r) % m
  ans += c[r]  # ここまでであまりが同じものを探す.
  c[r] += 1
  t *= 10

print(ans)

Submission status: Runtime Error

Solution code:
S=str(input())

list2019=[]
ans=0

for i in range(1,int(int(S)/2019)+1):
    a=i*2019
    list2019.append(str(a))

#print(' '.join(list2019))

for i in list2019:
    ans = ans+S.count(i)

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

def solve(S):
	M = 2019
	t = 1
	ans = 0
	c = np.zeros(M, dtype=np.int64)
	c[0] = 1
	r = 0
	for d in S:
		r = (d * t + r) % M
		ans += c[r]
		c[r] += 1
		t = t * 10 % M
	return ans



def cc_export():
	from numba.pycc import CC
	cc = CC('my_module')
    S = np.array([], dtype=np.int32)
	cc.export('solve', numba.i8(numba.typeof(S)))(solve)
	cc.compile()

if __name__ == '__main__':
	import sys
	if sys.argv[-1] == 'ONLINE_JUDGE':
		cc_export()
		exit(0)
	from my_module import solve
	S = sys.stdin.buffer.readline().decode('utf-8').rstrip()
	S = np.array([int(d) for d in S[::-1]], dtype=np.int32)
	print(solve(S))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
S = sys.stdin.buffer.readline().decode('utf-8').rstrip()
S = np.array([int(d) for d in S[::-1]], dtype=np.int32)

def solve(S):
	M = 2019
	t = 1
	ans = 0
	c = np.zeros(M, dtype=np.int64)
	c[0] = 1
	r = 0
	for d in S:
		r = (d * t + r) % M
		ans += c[r]
		c[r] += 1
		t = t * 10 % M
	return ans



def cc_export():
	from numba.pycc import CC
	cc = CC('my_module')
	cc.export('solve', numba.i8(numba.typeof(S)))(solve)
	cc.compile()

if __name__ == '__main__':
	import sys
	if sys.argv[-1] == 'ONLINE_JUDGE':
		cc_export()
		exit(0)
	from my_module import solve
	print(solve(S))

Submission status: Runtime Error

Solution code:
s=input()
r=set()
last=0
power=1
d={0:0}
total=0
for i in range(len(s)-1,-1,-1):
    n=int(s[i])*power+rem
    power*=10
    power=power%2019
    rem=n%2019
    if rem in r:
        d[rem]+=1
        total+=d[rem]-1
    else:
        r.add(rem)
        d[rem]=1
if d[0]==1:
    print(total+1)
else:
    print(total)

Submission status: Runtime Error

Solution code:
s=input()
r=set()
last=0
power=0
d={}
total=0
for i in range(len(s)-1,-1,-1):
    n=int(s[i])*(10**(power))+last
    power+=1
    last=n%2019
    rem=n%2019
    if rem==0:
        total+=1
        r.add(rem)
    if rem in r:
        d[rem]+=1
        total+=d[rem]-1
    else:
        r.add(rem)
        d[rem]=1
        
print(total)

Submission status: Runtime Error

Solution code:
s = str(input())

count = 0

if len(s) < 4:
    print(0)
    return

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

Submission status: Runtime Error

Solution code:
import collections
s = [int(c) for c in input()]
tmp = 1
prev = mod
count = collections.defaultdict(int)
for i,num in enumerate(s[::-1]):
    mod = (tmp * num + mod) % 2019
    count[mod] += 1
    tmp *= 10
print(sum((item*(item-1)//2 for item in count.values())))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = input()
def main()
count = 0
for i in range(len(S)):
    for j in range(i+3, len(S)):
        A = S[i:j+1]
        int_join_A = int(''.join(A))
        if int_join_A % 2019 == 0:
            count += 1
print(count)
main()

Submission status: Runtime Error

Solution code:
s = input()

target = 2019
max_mul = int('9'*(len(s)-1)) // target
cnt = 0
for i in range(max_mul+1):
    srch = str(i*target)
    if srch in s:
        cnt += s.count(srch)
print(cnt)

Submission status: Runtime Error

Solution code:
S = str(input())

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

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

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

Submission status: Runtime Error

Solution code:
S =  int(input())
a = str(S)
li = list(a)
r = len(li)
for i in range(r):
    for a in range(r): 
        v = li[i:a+1]
        if len(v)!= 0:
            d = "".join(v)
            b = int(d)
            if b%2019 == 0:
                c += 1
print(c)

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = input()

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

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

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

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = str(lines[0])

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

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

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

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = str(lines[0])

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

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

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

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = str(lines[0])

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

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

X.sort()
flag =1
n = 0

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

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []
A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019

a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []
A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019

a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)

X.sort()

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []
A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019

a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)

X.sort()
flag =1
n = 0
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += flag*(flag-1)//2
    flag = 1
print(n)

Submission status: Runtime Error

Solution code:
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)

X.sort()
flag =1
n = 0

Submission status: Runtime Error

Solution code:
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)

X.sort()
flag =1
n = 0
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += flag*(flag-1)//2
    flag = 1

Submission status: Runtime Error

Solution code:

a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)

X.sort()
flag =1
n = 0
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += flag*(flag-1)//2
    flag = 1
print(n)

Submission status: Runtime Error

Solution code:
inputText = input()

if int(inputText) < 2019:
    input("0")
    exit

cnt = 0
for i in range(len(inputText) - 3):
    for ii in range(3,len(inputText)):
        
        targetStr = inputText[i:ii + 1]

        if int(targetStr or 0) < 2019:
            continue
        elif int(targetStr) % 2019 == 0:
            cnt += 1

print(str(cnt))

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []
A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019

a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)

X.sort()
flag =1
n = 0
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += flag*(flag-1)//2
    flag = 1
 
print(n)

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []
A =[]
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019

a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)

X.sort()
flag =1
n = 0
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += flag*(flag-1)//2
    flag = 1
 
print(n)

Submission status: Runtime Error

Solution code:
inputText = input()

if int(inputText) < 2019:
    input("0")
    exit

cnt = 0
for i in range(len(inputText) - 3):
    for ii in range(4,len(inputText)):
        
        targetStr = inputText[i:ii + 1]

        if int(targetStr or 0) == 0:
            continue
        elif int(targetStr) % 2019 == 0:
            cnt += 1

print(str(cnt))

Submission status: Runtime Error

Solution code:
inputText = input()

if int(inputText) < 2019:
    input("0")
    exit

cnt = 0
for i in range(len(inputText) - 3):
    for ii in range(3,len(inputText)):
        
        targetStr = inputText[i:ii + 1]

        if int(targetStr or 0) == 0:
            continue
        elif int(targetStr) % 2019 == 0:
            cnt += 1

print(str(cnt))

Submission status: Runtime Error

Solution code:
inputText = input()

if int(inputText) < 2019:
    input("0")
    exit

cnt = 0
for i in range(len(inputText) - 3):
    for ii in range(3,len(inputText)):
        
        targetStr = inputText[i:ii + 1]

        if targetStr == "":
            continue
        elif int(targetStr) % 2019 == 0:
            cnt += 1

print(str(cnt))

Submission status: Runtime Error

Solution code:
import re
S = input()

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

count = []
for i in s:
    count += len(re.findall(S, i))

print(count)

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []

a = 0
for i in range(len(S)):
  a += int(S[len(S)-1-i])*10**i %2019
print(X)

Submission status: Runtime Error

Solution code:
S = input()

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

print(count)

Submission status: Runtime Error

Solution code:
/Users/10222/atcorder/ABC164/D.py

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []

for i in range(len(S)):
  a = int(S[i:])
  c = a-(a//2019)*2019
  X.append(c)
print(c)

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []

for i in range(len(S)):
  a = int(S[i:])
  c = a-(a//2019)*2019
  X.append(c)

X.sort()
flag =1
n = 0
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += flag*(flag-1)//2
    flag = 1
 
print(n)

Submission status: Runtime Error

Solution code:
import sys
import math
lines = sys.stdin.readlines()

S = str(lines[0])
X = []

for i in range(len(S)):
  a = int(S[i:])
  c = a-(a//2019)*2019
  X.append(c)

X.sort()
flag =1
n = 0
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += int(flag*(flag-1)/2)
    flag = 1
 
print(n)

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []

for i in range(len(S)):
  a = int(S[i:])
  c = a-int(a/2019)*2019
  X.append(c)

X.sort()
flag =1
n = 0
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += int(flag*(flag-1)/2)
    flag = 1
 
print(n)

Submission status: Runtime Error

Solution code:
import sys

lines = sys.stdin.readlines()

S = str(lines[0])
X = []

for i in range(len(S)):
  a = int(S[i:])
  c = a-int(a/2019)*2019
  X.append(c)

X.sort()
flag =1
n = 0
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag = flag +1
  else:
    n += int(flag*(flag-1)/2)
    flag = 1
 
print(n)

Submission status: Runtime Error

Solution code:
import sys

lines = sys.stdin.readlines()

S = str(lines[0])
X = []

for i in range(len(S)):
  a = int(S[i:])
  c = a-int(a/2019)*2019
  X.append(c)

X.sort()
print(X)
flag =1
n = 0
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag = flag +1
  else:
    n += int(flag*(flag-1)/2)
    flag = 1
 
print(n)

Submission status: Runtime Error

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

def main():
    MOD = 2019
    S = input()[::-1]
    n = 0
    x = 1
    c = Counter()
    ans = 0
    
    for s in S:
        c[n] += 1
        n += int(s) * x
        n %= MOD
        ans += c[n]
        x = x * 10 % MOD
                
    print(ans)
        
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import collections
s = input()
n = len(s)
mod_list = [0]

T = 0
for i in range(n):
    T += int(s[-1-i])*pow(10, i, 2019)%2019
    T = T%2019
    mod_list.append(T)

res = collections.Counter(mod_list)
cnt = 0
for d in res.values:
    cnt += int(d*(d-1)/2)
print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()

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

Submission status: Runtime Error

Solution code:
S = "1817181712114"
N = len(S)
ans = 0
x = 1
# 累積和を格納
tot = 0
# 累積和のmod 2019をカウントする
cnt = [0] * 2019

for i in range(N)[::-1]:
  cnt[tot] += 1

  tot += int(S[i]) * x
  tot %= 2019
  if cnt[tot] > 0:
    import pdb; pdb.set_trace()
  ans += cnt[tot]
  x *= 10

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import factorial
S=list(map(int,input()))
S.reverse()
# print(S)
count2019 = [0]*2019
count2019[0]=1

for i in range(len(S)):
    mod2019 =(mod2019+S[i]*10**i)%2019
    count2019[mod2019] +=1

ans =0
for i in count2019:
    if(i>=2):
        ans += factorial(i) // factorial(i) // factorial(i - 2)
print(ans)
# print(count2019)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
in_str = input()

rev_str = in_str[::-1]
mod = 2019

S = [0] * (len(in_str) + 1)
S[0] = 0

for i in range(1, len(in_str) + 1):
  S[i] = (S[i - 1] + int(rev_str[i - 1]) * pow(10, i, mod)) % mod

count = 0
for j in range(1, len(in_str)):
  count += S[j:].count(S[j - 1])

print(count)

Submission status: Runtime Error

Solution code:

s = input()
mod_list = [0]*2019
mod_list[0] = 1

for i in range(len(s)):
    mod_list[int(s[-(i+1):])%2019] += 1


print(sum([i*(i-1)//2 for i in mod_list])

Submission status: Runtime Error

Solution code:
import numpy as np
from collections import deque
s = input()

s = [int(s[-(i+1):]) for i in range(len(s))]
s = deque(s)
s.appendleft(0)
s = list(s)
s = list(np.array(s) % 2019)

from collections import Counter
c = Counter(s)
values = list(c.values)
print(sum([i*(i-1)//2 for i in values]))

Submission status: Runtime Error

Solution code:
S=input()
def d(i,j):
  if i==1:
    return int(j==int(S[0]))
  else:
    return d(i-1,(202*(j-int(S[i-1])))%2019)+int(j==int(S[i-1]))

ans=0
for i in range(1,len(S)+1):
  ans+=d(i,0)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S=input()
def d(i,j):
  def d1(i,j):
    if i==1 and j==int(S[0]):
      return 1
    if i==1 and j!=int(S[0]):
      return 0
    if i!=1 and j==int(S[i-1]):
      return d1(i-1,(202*(j-int(S[i-1])))%2019)+1
    else:
      return d1(i-1,(202*(j-int(S[i-1])))%2019)
  def d2(i,j):
    if i==1:
      return 0
    else:
      return d1(i-1,j)+d2(i-1,j)
  return d1(i,j)+d2(i,j)
print(d(len(S),0))

Submission status: Runtime Error

Solution code:
input()
s=s[::-1]
n=len(s)
 
count=[0]*2019
count[0]=1
num,d=0,1
 
for i in s:
  num+=int(i)*d
  num%=2019
  d*=10
  d%=2019
  count[num]+=1
 
ans=0
for i in count:
  ans+=i*(i-1)//2
  
print(ans)

Submission status: Runtime Error

Solution code:
nput()
s=s[::-1]
n=len(s)
 
count=[0]*2019
count[0]=1
num,d=0,1
 
for i in s:
  num+=int(i)*d
  num%=2019
  d*=10
  d%=2019
  count[num]+=1
 
ans=0
for i in count:
  ans+=i*(i-1)//2
  
print(ans)

Submission status: Runtime Error

Solution code:
S=input()
def d(i,j):
  def d1(i,j):
    if i==1 and j==int(S[0]):
      return 1
    if i==1 and j!=int(S[0]):
      return 0
    else:
      return d1(i-1,(202*(j-int(S[i-1])))%2019)+(j==int(S[i-1]))
  def d2(i,j):
    if i==1:
      return 0
    else:
      return d1(i-1,j)+d2(i-1,j)
  return d1(i,j)+d2(i,j)
print(d(len(S),0))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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 enumerate(s[::-1]):
    m = (int(degit) * (10 ** idx) + tmp) % 2019
    tmp = m
    ans += mod[m]
    mod[m] += 1

print(ans)

Submission status: Runtime Error

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