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

print(ans)

Submission status: Runtime Error

Solution code:
import math

N = input()
T = {}
for j in range(len(N), -1, -1):
    if j == len(N):
        T[j] = 0
    else:
        T[j] = (T[j + 1] + math.pow(10, len(N) - j - 1) * int(N[j])) % 2019
result = 0
for m in range(2019):
    a = 0
    for k, v in T.items():
        if v == m:
            a += 1
    if a >= 2:
        result += (a - 1) * a // 2
print(result)

Submission status: Runtime Error

Solution code:
N = input()
T = {}
for j in range(len(N), -1, -1):
    if j == len(N):
        T[j] = 0
    else:
        T[j] = (T[j + 1] + math.pow(10, len(N) - j - 1) * int(N[j])) % 2019
result = 0
for m in range(2019):
    a = 0
    for k, v in T.items():
        if v == m:
            a += 1
    if a >= 2:
        result += (a - 1) * a // 2
print(result)

Submission status: Runtime Error

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

ans = [0]*2019
ans[0] = 1

t= 0
d = 1

for i in S:
    num += int(i) * d
    num %= 2019
    ans[num] += 1
    d *= 10

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

print(t)

Submission status: Runtime Error

Solution code:
S = input()[::-1]
s = len(S)
ans = [0]*2019
ans[0] = 1
num =0
t= 0
d = 1
for i in s:
    num += int(i) * d
    num %= 2019
    d *= 10
    ans[num] += 1

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

print(t)

Submission status: Runtime Error

Solution code:
S = input()[::-1]
ans = [0]*2019
ans[0] = 1
num , t= 0
d = 1
for i in S:
    num += int(i) * d
    num %= 2019
    d *= 10
    ans[num] += 1

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

print(t)

Submission status: Runtime Error

Solution code:
s=input()



"""
◆エッセンス1：割り切れるとは、二つに分けた数字のmodが一緒
例)
1817181712114の
18171が2019で割り切れるかどうかを判断する。

18171は(181712114-2114)/10000となるので、
181712114mod2019＝2114mod2019の時、2019で割り切れる。

1817181712114mod2019
 817181712114mod2019
  17181712114mod2019
   7181712114mod2019
    181712114mod2019
     81712114mod2019
      1712114mod2019
       712114mod2019
    　　・・・・
とmodを調べていき、値が同じペアは割り切れる。
"""

"""
◆エッセンス2：大きい数字は都度modを取る

これだけでもループは1回になるんだけど、
|S|が長すぎてTLEとなってしまう（|S|は10**5）
1234567 mod 2019
=(1*10**7)mod2019 + (234567mod2019)
=(1*10mod2019 * 10**6mod2019)+ (234567mod2019)

10**nを毎回modを取ることで、計算する数字の長さを短くする。

"""



#modの値を保持する配列
cnt=[0]*2019
#mod2019 =0 は、それ一つで割り切れるので。引き算をする必要が無い。
cnt[0]=1

#10の倍数を保持する
fac=1

for i in range(len(s)):
    #後ろの数字から順番にとってくる
    ss = int(s[len(s)-i-1])*fac
    ss%=2019
    fac=fac*10
    fac%=2019
    cnt[ss]+=1

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

print(result)

Submission status: Runtime Error

Solution code:
S=input()
l=len(S)
t=0
p=0
m=[0] * l

for i in range(l):
    m[i]=int(S[i])*(10**(l-1-i))%2019

for i in range(l):
    p=0
    for j in range(l-i):
        p=(p+m[i+j])%2019
        if p==0:
            t+=1
print(t)

S=input()
l=len(S)
t=0
p=0
m=[0] * l

for i in range(l):
    m[i]=int(S[i])*(10**(l-1-i))%2019

for i in range(l):
    p=0
    for j in range(l-i):
        p=(p+m[i+j])%2019
        if p==0:
            t+=1
print(t)

Submission status: Runtime Error

Solution code:
S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i]) * pow(10,N-i-1,p))%p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1 
ans = cnt[0]
for i in rxange(1,p):
  m = cnt[i]
  ans += (m*(m-1))//2
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
counter = 0

if len(s) <= 3:
    print(0)
    exit(0)
 
for i in range(0, len(s)-3):
    for j in range(i+3, len(s)):
        if int(s[i, j] ) % 2019 == 0:
            counter += 1
 
print(counter)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
counter = 0

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

print(counter)

Submission status: Runtime Error

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main2():
	#a = int(input())
	#b , c = IN()
	s =  input()
	#s='1'*3000
	s=[int(c) for c in s]
	ll=len(s)
	ret_count=0
	for i in range(1):#ll-2):
		v = s[i]
		vs=[v]
		for c in s[i+1:]:
			v = (v * 10 + c) % 2019
			vs.append(v)
			if v == 0:
				ret_count += 1
		else:
			pa(vs)	
	print(ret_count)
				
def main():
	#a = int(input())
	#b , c = IN()
	s =  input()
	#s='1'*3000
	s=[int(c) for c in s]
	s=s[::-1]
	ll=len(s)
	cc=[0]*2018
	p=0
	tt=1
	cc[0]=1
	for i, v in enumerate(s):
		tt *= 10
		tt %= 2019
		p += tt*v
		p %= 2019
		cc[p] += 1
	
	ret = 0
	for v in cc:
		ret += v *(v-1)//2
	print(ret)	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Runtime Error

Solution code:
s = input()

mod = [1] + [0]*2018
t = 0
a = 0
n = len(s)
s = reversed(s)
for i in range(n):
    t += int(s[i]) * (10 ** a)
    a += 1
    mod[t%2019] += 1
    print(t,t%2019)
ans = 0
for i in range(2019):
    ans += mod[i]*(mod[i]-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
nS = reversed(S)

temp = [0 for i in range(len(S))]

for i in range(len(nS)):
  if i == 0:
    temp[i] = int(nS[i]) % 2019
  else:
    temp[i] = ( temp[i-1] * 10 + int(nS[i]) ) % 2019

ans = 0
for i in range(2019):
  m = temp.count(i)
  ans += m*(m-1) // 2
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
l = len(s)
te = [1] * 20000
c = 2019
for i in range(1, len(te)):
    te[i] = te[i-1]*10 % c

ans = 0
for i in range(l-1, -1, -1):
    t = int(s[i])
    if t == 0:
        ans += 1
    for j in range(1, i+1):
        t = t + int(s[i-j])*te[j]
        t = t%c
        if t == 0:
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
M=2019
a,i,*d=[0]*M
p=1
for j in input():d[i%M]+=1;i+=int(j)*p;a+=d[i%M];p=p*202%M
print(a)

Submission status: Runtime Error

Solution code:
numberString= input()
modList={};
modList[0]=1;
iPos=0
answerNum=0

while iPos<len(numberString):
  checkNum=int(numberString[iPos:])%2019
  if checkNum in modList:
	answerNum+=modList[checkNum]
    modList[checkNum]+=1
  else :
  	modList[checkNum]=1
  iPos+=1

print(int(answerNum))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import deque
S=str(input())
n=len(S)
u=0
d=deque([int(s) for s in S])
for i in range(n):
    a=d[0]
    for j in range(1,n):
        a=10*a+d[j]
        if a%2019==0:
            u+=1
    d.popleft()
print(u)

Submission status: Runtime Error

Solution code:
n = input()
l = len(n)
mod = [0]*2019
mod[0] += 1
T = 0
d = 1 # 桁数
for i, s in enumerate(Sr):
  T += int(s) * d
  T %= 2019
  d = (d * 10) % 2019
  
res = 0  
for m in mod:
  res += m*(m-1)/2
print(int(res))

Submission status: Runtime Error

Solution code:
s = input()[::-1]
d = 1
num = 0
mod_list = [0] * 2019

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

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

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    S = input()
    N = len(S)
    S = int(S)
    work, temp = 0, [0] * 2019, 0
    for i in range(N+1): work[(S % 10**i) % 2019] += 1
    print(sum([w*(w-1)//2 for w in work]))
main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
s=input()
b=0
m=len(s)
c=[0 for i in range(2019)]
c[0]=c[0]+1
a=""
e=0
for i in range(m-1,-1,-1):
    a=str(a)
    a=int(s[i]+a)
    d=a%2019
    c[d]=c[d]+1
e = sum(i * (i - 1) // 2 for i in c)
print(e)

Submission status: Runtime Error

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

countdic = {}
mod = 2019

for i in range(1,n+1):
    num = s[n-i:n]
    remainder = num%mod
    if remainder in countdic:
        countdic[remainder] += 1
    if remainder not in countdic:
        countdic[remainder] = 1

ans = 0
for key in countdic:
    ans += countdic[key]*(countdic[key]-1)//2

if 0 in countdic:
    ans += countdic[0]

print(ans)

Submission status: Runtime Error

Solution code:
S = input()
a = [0,int(S)%2019]
init = 0
for i in range(len(S)-1):
    S = S[1:]
    a.append(int(S)%2019)
b = [kv*(kv-1)//2 for kv in Counter(a).values() if kv > 1]
print(sum(b))

Submission status: Runtime Error

Solution code:
S = input()
l = [int(n) for n in list(S)]
a = [0,int(S)%2019]
init = 0
for i in range(len(S)-1):
    S = S[1:]
    a.append(int(S)%2019)
b = [kv*(kv-1)//2 for kv in Counter(a).values() if kv > 1]
print(sum(b))

Submission status: Runtime Error

Solution code:
s=input()

a=[""]*(len(s)+1)

for i in range(len(s)):
    a[i+1]=a[i]+s[i]

a.pop(0)
ans=0
for i in range(len(s)):
    for j in a:
        if j[i:]!="":
            b=int(j[i:])
            if b%2019==0:
                ans+=1
                
print(ans)

Submission status: Runtime Error

Solution code:
s = input()[::-1]
p = 0
dp = [0] * 2019
dp[0] = 1
for i in s:
    p = (p + (int(s) * (10 ** (i)))) % 2019
    dp[p] += 1
ans = 0
for i in dp:
    ans += i * (i - 1) // 2
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
from collections import defaultdict 
t = [0 for i in range(len(s))+1]
mods = defaultdict(int)
mods[0] += 1
cnt = 0
for i in range(len(s)-1,-1,-1):
  cnt += 1
  t[i] = t[i+1] + 10**cnt*int(s[i])
  mods[t[i]%2019] += 1
cnt = 0
for key, value in mods.items():
  cnt += value*(value-1)//2

print(cnt)

Submission status: Runtime Error

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

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

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

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

Submission status: Runtime Error

Solution code:
s = input()
from collections import defaultdict 
t = [0 for i in range(len(s))]
mods = defaultdict(int)
for i in range(0, len(s)):
  mods[int(s[i+1:])%2019] += 1
cnt = 0
for key, value in mods.items():
  cnt += value*(value-1)//2

print(cnt)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
s=input()
s=s[::-1]
md=[0]
ex10=1
tmp=0
mod=2019
for i in range(len(s)):
    tmp+=ex10*int(s[i])
    tmp%=mod
    md.append(tmp)
    ex10*=10
    ex10%=mod
from collections import Counter

sc= Counter(md)
ans=0
for k in sc:
    sck=sc[k]
    ans+= sck*(sck-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
s = input()

mod = [0] * 2019
mod[0] = 1
d = 1
n = 0
ans = 0

for i in reversed(s):
    n += int(i) * d
    n %= 2019
    d *= 10
    d %= 2019
    mod[n % 2019] += 1

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

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

s=str(input())
l=len(s)
T={}

sum=0

for i in range(l):
  tmp=int(s[i:])%2019
  if(tmp in T):
    sum=sum+T[tmp]
    T[tmp]=T[tmp]+1
  else:
    T[tmp]=1
print(sum+T[0])

Submission status: Runtime Error

Solution code:
s=list(input())
s=s[::-1]
l=len(s)
mod=2019
count=[0]*2019
count[0]=1
num=0
seki=1
for i in range(l):
    num+=(int(s[i])*(seki))%mod
    count[num]+=1
    seki=(seki*10)%mod
ans=0
for i in range(2019):
    N=count[i]
    ans+=N*(N-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
#D

import math

s = input()
n = math.ceil(int(s)/2019)
ans = 0

for i in range(n):
    word = str(2019*(i+1))
    if "0" not in word:
        ans += s.count(word)

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import itertools

S = input()
cnt = 0

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

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

print(cnt)

Submission status: Runtime Error

Solution code:
import sys

def calc(S):
    N = len(S)
    r = 0
    d = [0] * 2019
    d[0] = 1
    for i in range(N):
        r = (r + int(S[N - 1 - i]) * 10 ** i) % 2019
        d[r] += 1
    ans = 0
    for c in d:
        ans += c * (c - 1) // 2
    return ans


S = sys.stdin.readline() # input()
print(calc(S))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
list=[]
for i in range(1,n):
    for j in range(1,n):
        if int(s[i-1:j])%2019==0:
            list.append(s[i-1:j])
print(len(list))

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
list=[]
for i in range(1,n):
    for j in range(1,n):
        if int(s[i-1,j-1])%2019==0:
            list.append(s[i-1,j-1])
print(len(list))

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
list=[]
for i in range(1,n-3):
    for j in range(i+3,n):
        if int(s[i-1,j-1]) %2019==0:
            list.append(s[i-1,j-1])
print(len(list))

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
list=[]
for i in range(1,n-3):
    for j in range(i+3,n):
        if int(s[i-1,j-1])%2019==0:
            list.append(s[i-1,j-1])
print(len(list))

Submission status: Runtime Error

Solution code:
s = list(input())
s = s[::-1]
s = ''.join(s)
n = len(s)
dp = [0]*2018
now = 0

dp[0] = 1
for i in range(n):
    now += 10**i * int(s[i])
    tmp = now % 2019
    dp[tmp] += 1

ans = sum([i*(i-1)/2 for i in dp if i > 1])
print(int(ans))

Submission status: Runtime Error

Solution code:
s = input()[::-1]
n = len(s)
dp = [0]*2018
now = 0

dp[0] = 1
for i in range(n):
    now += 10**i * int(s[i])
    tmp = now % 2019
    dp[tmp] += 1

ans = sum([i*(i-1)/2 for i in dp if i > 1])
print(int(ans))

Submission status: Runtime Error

Solution code:
s = input()[::-1]
n = len(s)
dp = [0]*2018
now = 0

dp[0] = 1
for i in range(n):
    now += 10**i * int(s[i])
    tmp = now % 2019
    dp[tmp] += 1

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

print(int(ans))

Submission status: Runtime Error

Solution code:
S = list(input())[::-1]
L = len(S)
from collections import defaultdict

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L+1):
    t += pow(10, l)*int(S[l])
    i = t%mod
    ans += dic[i]
    dic[i] += 1

print(ans)

Submission status: Runtime Error

Solution code:
S = str(input())
"""
def solution(S):
    a = len(S)
    b = list(0 for j in range(4, a+1)
        for i in range(a-j+1)
            if int(S[i:i+j])%2019==0)
    print(len(b))
solution(S)
"""

S = str(input())

def solution(S):
    a = len(S)
    b = list(0 for j in range(4, a+1)
        for i in range(a-j+1)
            if int(S[i:i+j])%3==0 and int(S[i:i+j])%673==0)
    print(len(b))
solution(S)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = input()

N = len(S)

mod2019 = []
ans = 0

for _ in range(N+1):
  mod2019.append(0)


count = []
for _ in range(2019):
  count.append(0)



for i in range(1,N+1):
  Smod = mod2019[i-1] + int(S[N-i])*10**(i-1)
  mod2019.append(Smod%2019)
  count[Smod%2019] += 1


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



print(ans)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter 
def main():
    s = input() 
    s = ''.join(reversed(s))
    n = len(s)
    T = ['0']
    for i in range(n):
        T.append(s[i]+T[i])
    mod_kind = []
    for i in T:
        mod_kind.append(int(i)%2019)
    d = Counter(mod_kind)
    ans = 0
    for i in d.values():
        ans += i*(i-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = input()

if len(s) <= 3:
  print(0)
else:
  ct = 0
  for i in range(len(s) - 3):
    k = i
    x = int(s[i: i + 3])
    for j in range(i + 3, len(s)):
      x = (10 * x + int(s[j])) % 2019
      if x == 0:
        ct += 1

print(ct)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
 
s = input()
counter = 0

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
 
s = input()
counter = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# input
S = input

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

print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
s.reverse()
MOD = 2019
a =[0]*MOD
a[0] = 1
c_ = 0
ans = 0
t = 1
for i in s:
  c = (c_+int(i)*t)%MOD
  a[c] += 1
  t *= 10
  t %= MOD
  c_ = c
for i in a:
  ans += i*(i-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
s.reverse()
MOD = 2019
b = {}
a =[0]*MOD
a[0] = 1
c_ = 0
ans = 0
t = 1
for i in s:
  c = (c_+int(i)*t)%MOD
  b[c] += 1
  t *= 10
  t %= MOD
  c_ = c
for i in a:
  ans += i*(i-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
s = list(str(input()))
b = {}
b[0] = 1
c_ = 0
ans = 0
s.reverse()
for i in s:
  c = (c_+int(i))%2019
  if c in b:
    ans += b[c]
    b[c] += 1
    ans += 
  else:
    b[c] = 1
  c_ = c
print(ans)

Submission status: Runtime Error

Solution code:
s = list(str(input()))
b = {}
b[0] = 1
c_ = 0
s = s.reverse()
for i in s:
  c = (c_+int(i)*10**num)%2019
  if c in b:
    b[c] += 1
  else:
    b[c] = 1
  c_ = c
ans = 0
for i in b.values():
  ans += i*(i-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
s=input()
mojisuu = len(s)
count=0

for i in range(mojisuu-4):
    for k in range(mojisuu,3+i,-1):
        check=int(s[i:k])
        if(check%2019==0):
            count+=1
           
print(count)

Submission status: Runtime Error

Solution code:
s=input()
mojisuu = len(s)
count=0

for i in xrange(mojisuu-4):
    for k in xrange(mojisuu,3+i,-1):
        check=int(s[i:k])
        if(check%2019==0):
            count+=1
           
print(count)

Submission status: Runtime Error

Solution code:
S = input()
MOD = 2019
cnt = [0]*MOD
cur = 0 # 現在考えている部分文字列
cnt[cur] = 1 # 部分文字列'0'も作れると考える
d = 1 # 位を表す
for s in for S[::-1]:
    cur += int(s)*d # 新たな桁を追加
    r %= MOD
    cnt[cur] += 1
    # 後処理
    d *= 10 # 位を上げる
    d %= MOD # ただし数が巨大になるため、剰余をとる
ans = 0
for c in cnt:
    ans += c*(c-1)//2
print (ans)

Submission status: Runtime Error

Solution code:
# TODO NG
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

s = input()

cnt = 0
s_n = np.ones(200000*200//1000, dtype='int64')

for i in range(len(s)-3):
    for j in range(i+3, len(s)):
        s_n[cnt] = int(s[i:j+1])
        cnt += 1
n_2019 = s_n[s_n % 2019 == 0]
print(len(n_2019))

Submission status: Runtime Error

Solution code:

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())


directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


def serch(x, count):
    # print("top", x, count)

    for d in directions:
        nx = d+x
        # print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)

    return count


class Node:
    def __init__(self):
        pass


class Edge:
    def __init__(self, edge, cost=1):
        self.node_from = edge[0]
        self.node_to = edge[1]
        self.cost = cost

    def add_node(self, node):
        self.nodes.append(node)


class myGraph:

    def __init__(self, V=False):
        self.adj = {}
        self.nodes = {}

        if V > 0:
            for v in range(0, V):
                self.nodes[v] = {}
                self.adj[v] = {}

    def add_edge(self, edge, cost):
        if len(edge) == 1:
            edge = list(edge)

        u, v = edge[0], edge[1]

        if u not in self.nodes:
            self.adj[u] = {}
            self.nodes[u] = {}

        if v not in self.nodes:
            self.adj[v] = {}
            self.nodes[v] = {}

        # add the edge
        self.adj[u][v] = cost
        self.adj[v][u] = cost

    def add_directed_edge(self, edge, cost):
        if len(edge) == 1:
            edge = list(edge)

        u, v = edge[0], edge[1]

        if u not in self.nodes:
            self.adj[u] = {}
            self.nodes[u] = {}

        if v not in self.nodes:
            self.adj[v] = {}
            self.nodes[v] = {}

        self.adj[u][v] = cost

    def get_edges_from(self, node):
        return [(self.adj[node][nn], node, nn) for nn in self.adj[node]]

    def WarshallFloyd(self):
        return 0

    def is_nibu(self):
        return False

    def makeEdgeobj(self):
        edges = []
        for sn in self.nodes:
            for e in self.get_edges_from(sn):
                edges.append(Edge([e[1], e[2]], e[0]))

        return edges

    def _add(self, edges, add_edges):
        for e in add_edges:
            hq.heappush(edges, e)
        return edges

    def bermn_ford(self, start, init=0):

        nodes = self.nodes
        dists = {}
        for n in nodes:
            dists[n] = float("inf")

        dists[start] = init
        edges = self.makeEdgeobj()

        for i in range(len(nodes)):
            update = False
            for k in range(len(edges)):
                e = edges[k]
                if dists[e.node_from] != float("inf") and dists[e.node_to] > dists[e.node_from]+e.cost:
                    dists[e.node_to] = dists[e.node_from]+e.cost
                    update = True

            if i == len(nodes)-1:
                return False

            if not update:
                break

        return dists
    
    def dijkstra(self, start, goal=None):
        import heapq
        '''
            get minimum cost
        '''

        N = len(self.nodes)          # グラフのノード数
        # dist = [float('inf') for i in range(N)] # 始点から各頂点までの最短距離を格納する
        
        dist = {k: float('inf') for k in self.nodes}
        # prev = [float('inf') for i in range(N)]

        dist[start] = 0
        # print(self.nodes)
        if N == 0:
            return dist
        visited = []

        koho = []
        heapq.heappush(koho, (0, start))

        # vtx=list(self.nodes)
        # vtx.remove(start)

        ginka=self.S
        while len(koho) != 0:
            d, mini = heapq.heappop(koho)
            if dist[mini] < d:
                continue
            
            adjs=self.dadj(mini)
            for k in range(len(adjs)):
                #cost = self.adj[mini][k]
                cost=self.dadj(mini,ginka)
                # and not(k in visited):
                if cost != float('inf') and dist[k] > dist[mini]+cost:
                    dist[k] = dist[mini]+cost
                    heapq.heappush(koho, (dist[k], k))
                    # prev[k]=mini

        return dist

    #def dadj(self,n):
    #    self.
        
    def show(self):
        import networkx as nx
        import matplotlib.pyplot as plt
        G=nx.Graph()

        for u in self.adj:
            for v in self.adj[u]:

                # G.add_edge(e.node_from,e.node_to,weight=e.cost)
                G.add_edge(u,v,weight=self.adj[u][v])
                # print(e.node_from,e.node_to,e.cost)

        pos=nx.spring_layout(G)
        # nx.draw_networkx_edges(G,pos=pos,edgelist=G.edges())
        edge_weight=dict([((u,v,),int(d['weight'])) for u,v,d in G.edges(data=True)])

        nx.draw_networkx_edge_labels(G,pos,edge_labels=edge_weight)
        # nx.draw_networkx_labels(G, pos)
        nx.draw_networkx_nodes(G,pos)
        nx.draw_networkx_edges(G,pos)
        nx.draw_networkx_labels(G,pos)
        # plt.axis('off')
        # nx.draw(G,with_labels=True)
        plt.show()

def search(x):
    global g,N,nodenum
    queue=[(x,1)]
    wnum=2
    nodenum=[-1]*N
    nodenum[x]=1
    visited=[0]*N
    while True:
        nqueue=[]
        for node,k in queue:
            for snode in g[node]:
                if nodenum[snode]<0:                    
                    nodenum[snode]=wnum
                    nqueue.append((snode,wnum))
                else:
                    if (not visited[snode]) and nodenum[snode]!=wnum:
                        return -1
            visited[node]=1

        queue=nqueue
        if len(queue)==0:
            return wnum-1
        wnum+=1
        


def acinput():
    s=input()
    if len(s)==0:
        return False

    return list(map(int,s.split(" ")))
    

if __name__=="__main__":
    # a=spaceinput()
    N,M,S=acinput()
    g=myGraph()
    g.S=S

    d=[]
    for i in range(M):
        tmp=acinput()
        d.append(tmp)
        g.add_edge((tmp[0],tmp[1]),1)

    cost=[]
    for i in range(N):
        cost.append(acinput())

    for i in range(N):
        self.nodes.append(i+1)
        
    res=g.dijkstra(1)
    print(res)
    '''
    mint=10*9
    for k in range(1,n+1):
        dd=g.dijkstra(k)
        v=max(dd.values())
        if mint>v:
            mint=v


    print(mint)
    '''

'''
1 2 7
2 3 8
1 4 5
2 4 9
2 5 7
3 5 5
4 5 15
4 6 6
5 6 8
5 7 9
6 7 11

'''