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 numpy as np

def digit_sum(n):
    ans = 0
    while n > 0:
        ans += n % 10
        n //= 10
    return ans


S=input()
A=0

SL=list(S)
for i in range(len(SL)):
    SL[i]=int(SL[i])

SL_sum=SL.copy()
for i in range(1, len(SL_sum)):
    SL_sum[i] += SL_sum[i-1]
#SL_sum=np.array(SL_sum)
    
while len(S)>3:
    for i in range(len(SL_sum)):
        if digit_sum(SL_sum[i])%3 == 0 :
            X=int(int(S[:i+1])/3)
            if X%673 == 0 :
                A+=1
    S=S[1:]
    SL_sum=(np.array(SL_sum)-SL_sum[0]).tolist()
    SL_sum=SL_sum[1:]
    SL=SL[1:]
    
print(A)

Submission status: Runtime Error

Solution code:
S = input()

count = 0

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

Submission status: Runtime Error

Solution code:
import numpy as np
S = input()
ans = 0
leng = len(S);
intlist = list(map(int,list(S)))

for i in range(leng):
    buf = 0
    for j in range(i, leng):
        buf *= 10
        buf += intlist[j]
        buf %= 2019
        if(buf == 0):
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

from collections import deque

def main():
  d_origin = [i for i in input()]                                                                                                                                ans = 0
  for i in range(len(d_origin)):
    if len(d_origin) < 3:
      print(ans)
      return
    if i != 0:
      d_origin.pop(0)

    while (len(d_origin) > 2 and int(d_origin[1])%2 != 0):
      d_origin.pop(0)
    while (len(d_origin) >= 3 and (int(d_origin[2]) != int(d_origin[0]) and int(d_origin[2]) != (int(d_origin[0])-1))):                                              d_origin.pop(0)
    d = d_origin.copy()
    for j in range(len(d)):
      if int(''.join(d))%2019 == 0:
        ans = ans + 1
      d.pop()
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import itertools
S = input()

count = 0
part_S = []

for i in range(0,len(S)):
    part_S.append(list(itertools.accumulate(S[i:])))



for j in range(len(part_S)):
    for i in part_S[j]:
        int_s = int(i)

        if int_s % 2019 == 0:
            count += 1
      

print(count)

Submission status: Runtime Error

Solution code:
import sys

s = input()
ans =0
num=0
for i in range(len(s)):
    num=int(s[i])
    for j in range(i+3,len(s)):
        num=num+int(s[j])
        if num%3==0:
            nums = int(s[i:j+1])
            if nums%673==0:
                ans+=1
                #print(i,j)
 print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
S = input()

num_s = int(S)
num_list = list(S)
count = 0

def toString(num):
    tmp = list(str(num))
    for i, value in  enumerate(tmp):
        if value == '1':
            tmp[i] = 'a'
        elif value == '2':
            tmp[i] = 'b'
        elif value == '3':
            tmp[i] = 'c'
        elif value == '4':
            tmp[i] = 'd'
        elif value == '5':
            tmp[i] = 'e'
        elif value == '6':
            tmp[i] = 'f'
        elif value == '7':
            tmp[i] = 'g'
        elif value == '7':
            tmp[i] = 'h'
        elif value == '8':
            tmp[i] = 'i'
        elif value == '9':
            tmp[i] = 'j'
            
    return ''.join(tmp)
    
length = int(num_s/ 2019)
for i in range(length):
    if bool (toString(2019*i) in toString(num_s) ):
        count += 1
    
print(count)

Submission status: Runtime Error

Solution code:
import sys
s = sys.stdin.readline
b=int(s)
total=0
for i in range(0,len(s)-2):
  for j in range(i+4,len(s)+1):
    d=int(s[i:j])
    if d%2019==0:
      total+=1
print(total)

Submission status: Runtime Error

Solution code:
s = input()
s_len = len(s)
total = [0, int(s[0])]

for i in range(1,s_len):
    total.append(total[-1]+int(s[i]))

count=0
for i in range(s_len):
    for j in range(i+4,s_len):
        if s[j-3]%2==0:
            continue
        if (total[i] - total[j+1])%3==0:
            if int(s[i:j+1])%2019==0:
                count += 1

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(200000)
N = input()
count = 0
for i in range(len(N) - 3):
    for a in range(len(N)-3):
        if N[i:i+4+a][0:1] == "0":
            break
        b = int(N[i:i+4+a]) / 2019
        if b.is_integer() and not b == 0.0:
            count += 1
        if i+4+a == len(N):
            break
print(count)

Submission status: Runtime Error

Solution code:
S = input()

flg = 0
for j in range(3, len(S)+1):
    for i in range(0, j-3):
        s = int(S[i : j])
        if s != 0 and s % 3 == 0:
            if s/3 % 673 == 0:
                flg += 1
print(flg)

Submission status: Runtime Error

Solution code:
S = list(map(int, list(input())))
N = len(S)

dp = [[0]*N for i in range(N)]
if N < 4:
    print(0)
    exit(0)

D = [[0]*N for i in range(9)]
for i in range(9):
    D[i][i] = (i+1)
    for j in range(i+1, N):
        D[i][j] = D[i][j-1]*10 % 2019


print(D)
ans = 0

dp[0] = S[0]
for i in range(1, N):
    dp[i] = (dp[i-1]*10 + S[i]) % 2019
    if dp[i] == 0:
        ans += 1

for i in range(1, N):
    for j in range(i+1, N):
        dp[i] -= D[S[i-1]][j]
        dp[i] %= 2019
        if dp[i] == 0:
            ans += 1

# print(N)
# print(*dp, sep='\n')
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000)
N = input()
count = 0
for i in range(len(N) - 3):
    for a in range(len(N)-3):
        if N[i:i+4+a][0:1] == "0":
            break
        b = int(N[i:i+4+a]) / 2019
        if b.is_integer() and not b == 0.0:
            count += 1
        if i+4+a == len(N):
            break
print(count)

Submission status: Runtime Error

Solution code:
S=input()
S_len=len(S)
count1=0
count2=0
for width in range(4,S_len//2):
    for start in range(S_len-width+1):
        if int(S[start:start+width])%2019==0:
            count1+=1

for width in range(S_len//2,S_len):
    for start in range(S_len-width+1):
        if int(S[start:start+width])%2019==0:
            count2+=1

print(count1+count2)

Submission status: Runtime Error

Solution code:
in1 = input()
ans = 0

for i in range(1, 200000):
    temp = 2019*i
    if in1.count(str(temp)) != 0:
        ans += in1.count(temp)
print(ans)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <cstring>
using namespace std;

int main(){
  string num;
  cin >> num;
  int i,j;
  int counter=0;
  int length=0;
  while(num[length]){
    length++;
  }
  for(j=0;j<length;j++){
    for(i=0;i<j;i++){
      if(atoi(num.c_str())%2019==0){
        counter++;
      }
    }
  }
  return 0;
}

Submission status: Runtime Error

Solution code:
S=str(input())
n=len(S)
u=0
for i in range(n):
    for j in range(i+1,n+1):
        a=10*a+int(S[j])
        if a%2019==0:
            u=u+1
print(u)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000)
input = sys.stdin.readline
N = input()
count = 0
for i in range(len(N) - 3):
    for a in range(len(N)-3):
        if N[i:i+4+a][0:1] == "0":
            break
        b = int(N[i:i+4+a]) / 2019
        if b.is_integer() and not b == 0.0:
            count += 1
        if i+4+a == len(N):
            break
print(count)

Submission status: Runtime Error

Solution code:
s = input()
s_len = len(s)
total = [0, int(s[0])]

for i in range(1,s_len):
    total.append(total[-1]+int(s[i]))

count=0
for i in range(s_len):
    if s[i]%2!=0:
        continue
    for j in range(i+4,s_len):
        if (total[i] - total[j+1])%3==0:
            if int(s[i:j+1])%2019==0:
                count += 1

print(count)

Submission status: Runtime Error

Solution code:
l = len(n)
count = 0
for i in range(l-3):
  x = 0
  for j in range(i+3, l):
    if j == i+3:
      x = int(n[i]) + int(n[i+1]) + int(n[i+2]) + int(n[i+3])
    else:
      x += int(n[j])
    
    if x % 3 != 0:
      continue
    else:
      integer = int(n[i:j+1])
      if integer % 2019 == 0:
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
def dfs(str, dp,n, x):
    if x>=n:
        return 0
    if dp[x]!=0:
        return dp[x]
    tmp=''
    for i in range(x, n):
        tmp=tmp+str[i]
        num=int(tmp)
        if num%2019==0:
            dp[x]=dfs(str, dp, n, i+1)+1
            return dp[x]
    return dp[x]

def main():
    str = input()
    n = len(str)
    dp = [0 for i in range(n)]
    for i in range(n):
        dfs(str, dp, n, i)
    ans=0;
    for i in range(n):
        ans+=dp[i]
    print(ans)




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

Submission status: Runtime Error

Solution code:
x=int(input())
count=0
n=len(x)
for i in range n:
  a=x//(10**i)
  for j in range n-i:
    b=a%(10**j)
    if b%2019==0:
      count=count+1
print(count)

Submission status: Runtime Error

Solution code:
s = sys.stdin.readline()
n = len(s)
k = 2019
cnt = 0
seenRem = []
for i in range(n):
    seenRem.append(set())
for i in range(n):
    rem = 0
    f = 0
    for j in range(i, n):
        rem = (10 * rem + int(s[j])) % k
        if rem in seenRem[j]:
            break
        seenRem[j].add(rem)
        if rem == 0:
            f += 1
    cnt += (f * ( f + 1) // 2)
sys.stdout.write(str(cnt))

Submission status: Runtime Error

Solution code:
S = str(input())
n = len(S)

if n <= 4:
    print(0)

l = 0
r = 4
rem_div_3 = int(S[l:r+1]) % 3
cnt = 0

while True:
    if rem_div_3 == 0:
        num = int(S[l:r+1])
        if num % 673 == 0:
            cnt += 1
    if r == n - 1:
        if r - l == 4: 
            break
        else:
            l += 1
            r = l + 4
            rem_div_3 = int(S[l:r+1]) % 3
    else:
        rem_div_3 = (rem_div_3 + int(S[r+1])) % 3
        r += 1
print(cnt)

Submission status: Runtime Error

Solution code:
S=input()
N=len(S)

U=[]
for i in range(N):
    U.append(S[i:])
ans=0
for i in range(N):
    l=U[len(U)-1-i]
    cnt=5
    while(1):
        if (cnt)>len(l):
            break
        tmp=l[:cnt]
        if int(tmp)%2019==0:
            ans+=1
        cnt+=1

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
S = input()

num_s = int(S)
num_list = list(S)
count = 0

def toString(num):
    tmp = list(str(num))
    for i, value in  enumerate(tmp):
        if value == '1':
            tmp[i] = 'a'
        elif value == '2':
            tmp[i] = 'b'
        elif value == '3':
            tmp[i] = 'c'
        elif value == '4':
            tmp[i] = 'd'
        elif value == '5':
            tmp[i] = 'e'
        elif value == '6':
            tmp[i] = 'f'
        elif value == '7':
            tmp[i] = 'g'
        elif value == '7':
            tmp[i] = 'h'
        elif value == '8':
            tmp[i] = 'i'
        elif value == '9':
            tmp[i] = 'j'
            
    return ''.join(tmp)
    

length = int(num_s/ 2019)
for i in range(length):
    if bool (toString(2019*i) in toString(num_s) ):
        count += 1
    
print(count)

Submission status: Runtime Error

Solution code:
S = input()

flg = 0
for j in range(3, len(S)+1):
    for i in range(0, j-3):
        s = int(S[i : j])
        if s % 3 == 0:
            if s/3 % 673 == 0:
                flg += 1
print(flg)

Submission status: Runtime Error

Solution code:
s=input()
slen=len(s)
count=0
ri=slen-4
for i in range(5,slen):
  list=[]
  a=1e+i
  a/=2019
  b=1e+(i+1)
  b/=2019
  for j in range(a+1,b+1):
    list.append(2019*j)
  for j in range(ri):
    targ=int(s[j:j+i])
    if targ in list:
      count+=1
print(count)

Submission status: Runtime Error

Solution code:
s = input()

left = 0
right = 4

l = len(s) - 4
r = len(s)

ans = 0
anst = 0

while right < len(s):
    if int(s[left:right]) % 2019 == 0:
        ans += 1
        left = right - 1
        right += 3
    else:
        right += 1

while l >＝ 0:
    if int(s[l:r]) % 2019 == 0:
        anst += 1
        r = l + 1
        l -= 3
    else:
        l -= 1

print(max(ans, anst))

Submission status: Runtime Error

Solution code:
import numpy as np

S = input()
#S = '2019' * 500
lS = len(S)
ans = 0
li_st = []
li_go = []
#li_x = []


for j in range(lS-3):
    s = S[:lS-j]
        
    #print(s)
    
    ls = len(s)
    ss = s[-4:]
    #print(ss)
    
    
    for i in range(ls-3):
        if int(ss) % 2019 != 0:
            if ls+1 > 5+i:
                ss = s[-5-i:]
                #print(ss)
        else:
            li_st.append(lS-4-i-j+1)
            li_go.append(lS-1-j+1)
            break
        
#print(li_s)
#print(li_g)

for v_s in li_st:
    x = 1
    while True:
        if v_s-1 in li_go:
            v_s = li_st[li_go.index(v_s-1)]
            x += 1
        else:
            break
    ans += x

print(ans)

Submission status: Runtime Error

Solution code:
def digitSum(n):
    # １文字ずつ数値化し配列にする。
    array = list(map(int, n))
    # 合計値を返す
    return sum(array)

S = input()
ans = 0
# print(len(S))
lS = len(S)

if int(S) < 2019:
     ans = 0
else:
    　for i in range(lS-3):
          for j in range(lS-3-i):
               obj = S[j:j+4+i]
               # if digitSum(obj)%3 == 0:
               if int(obj)%2019==0:
                    ans+=1
               # print(S[j:j+4+i])

print(ans)

Submission status: Runtime Error

Solution code:
S = input()

n = int(int(S)/2019)

a = 0

for i in range(1, n+1):
  a += S.count(str(2019*i))
  
print(a)

Submission status: Runtime Error

Solution code:
from collections import deque
S=str(input())
n=len(S)
d=deque(S)
u=0
while n>0:
    a = ''
    for i in d:
        a+=i
        if int(a)%2019==0:
            u=u+1
    d.popleft()
print(u)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
S = input()

num_s = int(S)
num_list = list(S)
count = 0

def toString(num):
    tmp = list(str(num))
    for i, value in  enumerate(tmp):
        if value == '1':
            tmp[i] = 'a'
        elif value == '2':
            tmp[i] = 'b'
        elif value == '3':
            tmp[i] = 'c'
        elif value == '4':
            tmp[i] = 'd'
        elif value == '5':
            tmp[i] = 'e'
        elif value == '6':
            tmp[i] = 'f'
        elif value == '7':
            tmp[i] = 'g'
        elif value == '7':
            tmp[i] = 'h'
        elif value == '8':
            tmp[i] = 'i'
        elif value == '9':
            tmp[i] = 'j'
            
    return ''.join(tmp)
    

length = int(num_s/ 2019)
for i in range(100000):
    if bool (toString(2019*i) in toString(num_s) ):
        count += 1
    
print(count)

Submission status: Runtime Error

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

print(count)

Submission status: Runtime Error

Solution code:
S = input()
count = 0
count2 = 0
bubun = []
U = []

for i in range(0, len(S)):
  bubun.append(S[i:len(S)])

bubun.reverse()

for num in bubun:
  U.append(int(num)%2019)

count = U.count(0)
for num in U:
  if num !=0:
    count2 = count2 + U.count(num) - 1

count2 = count2//2
print(count+count2)

Submission status: Runtime Error

Solution code:
def checker(s, n, int_s):
#    print(s)
    su = sum(int_s)
    if su%3 != 0:
        return False
    if n <= 10:
        i = int("".join(s))
        return i%673 == 0
    else:
        sub = int(s[-1])*2
        suba = int("".join(s[-4:-1]))
        subb = suba - sub
        new_s = s[:-4] + str(subb)
        checker(new_s, n-1)
    

def Main(S):
    le = len(S)
    int_s = [int(c) for c in S]
    if(0 <= le <= 3):
        return 0
    ans = 0
    for i in range(le-3):
        for j in range(i+4, le+1):
            s = S[i:j]
            lee = len(s)
            if checker(s, lee, int_s[i:j]):
                ans += 1
    return ans
            


def main():
    S = str(input())
    print(Main(S))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
S = str(input())
n = len(S)
b % 2 == 1
print(sum(int(S[a:b+1]) % 2019 == 0 for a in range(0,n-3)  for b in range(a+3,n)))

Submission status: Runtime Error

Solution code:
def get_offset(S):
    for i in range(length - 3):
        for j in range(i+1, length+1):
            num = int(S[i:j])
            if num % 2019 == 0:
                return i+1, j
    return None, None

def get_offset2(S):
    for i in reversed(range(4, length)):
        for j in reversed(range(0, i-3)):
            num = int(S[j:i])
            if num % 2019 == 0:
                return j+1, i
    return None, None


S = input()

length = len(S)
ans = 0
head = tail = 0

head, tail = get_offset(S)
if head != None:
    domains = []
    while tail <= length:
        offset = tail - head
        domains.append((head, tail))
        head += offset
        tail += offset


head, tail = get_offset2(S)
if head != None:
    while tail <= length:
        offset = tail - head
        domains.append((head, tail))
        head += offset
        tail += offset

#  print(domains)
ans = len(set(domains))
print(ans)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
ans=0
y=0
i=0
pe=[0]*(n+32)
pa=[0]*(n+32)
for i in range(n-3):
    if int(s[i:i+4])%2019==0:
        pe[i+3]+=pe[i]+1
        pe[i]=0
        y=1
    if int(s[i:i+5])%2019==0 and i!=n-4:
        pe[i+4]+=pe[i]+1
        pe[i]=0
    y=0
print(sume(pe))

Submission status: Runtime Error

Solution code:
S = input()
n = len(S)
prefix = [''] * (n + 1)
for i, c in enumerate(S, start=1):
    prefix[i] = prefix[i - 1] + c
res = 0
count = [0] * 2020
for i in range(1, n + 1):
    num = int(prefix[i])
    if num % 2019 == 0:
        res += 1
    temp = (num * 10 ** (n - i)) % 2019
    res += count[temp]
    count[temp] += 1
print(res)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <cstring>
using namespace std;

int main(){
  string num;
  cin >> num;
  int i,j;
  int counter=0;
  int length=0;
  while(num[length]){
    length++;
  }
  for(j=0;j<length+1;j++){
    for(i=0;i<j;i++){
      if(stoi(num.substr(i,j))%2019==0){
        counter++;
      }
    }
  }
  return 0;
}

Submission status: Runtime Error

Solution code:
S = str(input())
n = len(S)

l = 0
r = 4
rem_div_3 = int(S[:r+1]) % 3
cnt = 0

while True:
    if rem_div_3 == 0:
        num = int(S[l:r+1])
        if num % 673 == 0:
            cnt += 1
    if r == n - 1:
        if r - l == 4: 
            break
        else:
            l += 1
            r = l + 4
            rem_div_3 = int(S[l:r+1]) % 3
    else:
        rem_div_3 = (rem_div_3 + int(S[r+1])) % 3
        r += 1
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
a = input()
b = int(a) // 2019
c = 0
l = 2019 * (np.arange(1,b+1))
for i in range(b):
    if str(l[i]) in a:
        c += 1
print(c)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
S = input()

num_s = int(S)
num_list = list(S)
count = 0
def toString(num):
    tmp = list(str(num))
    for i, value in  enumerate(tmp):
        if value == '1':
            tmp[i] = 'a'
        elif value == '2':
            tmp[i] = 'b'
        elif value == '3':
            tmp[i] = 'c'
        elif value == '4':
            tmp[i] = 'd'
        elif value == '5':
            tmp[i] = 'e'
        elif value == '6':
            tmp[i] = 'f'
        elif value == '7':
            tmp[i] = 'g'
        elif value == '7':
            tmp[i] = 'h'
        elif value == '8':
            tmp[i] = 'i'
        elif value == '9':
            tmp[i] = 'j'
            
    return ''.join(tmp)
    

length = int(num_s/ 2019)
for i in range(100000):
    if bool (toString(2019*i) in toString(num_s) ):
        count += 1
    
print(count)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
S = input()

num_s = int(S)
num_list = list(S)
count = 0
def toString(num):
    tmp = list(str(num))
    for i, value in  enumerate(tmp):
        if value == '1':
            tmp[i] = 'a'
        elif value == '2':
            tmp[i] = 'b'
        elif value == '3':
            tmp[i] = 'c'
        elif value == '4':
            tmp[i] = 'd'
        elif value == '5':
            tmp[i] = 'e'
        elif value == '6':
            tmp[i] = 'f'
        elif value == '7':
            tmp[i] = 'g'
        elif value == '7':
            tmp[i] = 'h'
        elif value == '8':
            tmp[i] = 'i'
        elif value == '9':
            tmp[i] = 'j'
            
    return ''.join(tmp)
    

length = int(num_s/ 2019)
for i in range(10000):
    if bool (toString(2019*i) in toString(num_s) ):
        count += 1
    
print(count)

Submission status: Runtime Error

Solution code:
S = input()

flg = 0
for j in range(3, len(S)+1):
    for i in range(0, j-3):
        if int(S[i : j]) % 3 == 0:
            if int(S[i : j])/3 % 673 == 0:
                flg += 1
print(flg)

Submission status: Runtime Error

Solution code:
s = input()
s_l = len(s)
r = 0
n = 0
while True:
    a += 2019
    if int(s) < a:
        break
    a_l = len(str(a))
    a_s = str(a)
    for i in range(1,s_l + 1):
        if i + a_l - 1 > s_l:
            break
        r += s.count(a_s,i - 1, i + a_l - 1)
print(r)

Submission status: Runtime Error

Solution code:
S = input()
import numpy as np
arr = np.array([int(S[i:j]) for i in range(0,length-3) for j in range(i+4, length+1)])
arr2 = arr % 2019
print(len(arr2)- np.count_nonzero(arr2))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

def main():
    import sys
    input = sys.stdin.readline
    s = input().rstrip("\n")
    #print(s[-5:])
    #print(s[-5:0])
    j=0
    cnt=0
    flg=True

    if len(s)<=4:
        flg=False
        if int(s)%2019==0:
            print("1")
        else:
            print("0")

    if flg:
        h=0
        if s[-1]==0:
            h=1
        
        for i in range(h,len(s)):
            #print(s[-i-1:])
            if int(s[-i-1:])%2019==0:
                cnt+=1
                j-=i
                break

        #print(cnt)
        if j==-len(s)+1:
            print(1)
            flg=False

        if flg:
            for i in range(-j,len(s)):
                #print(-i-1,j)
                if int(s[-i-1:j])%2019==0:
                    cnt+=1
                    j=-i
            print(cnt)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
s=input()
length = len(s)
ans = 0
option = [4,5,6]
for leng in option:
    for i in range(length-leng+1):
        if s[i:i+leng] in multiples:
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
S =input()
count =0
for i in range(len(S)):
    for j in range(len(S)+1):
        num= S[i]
        for k in range(i+1,j+1):
            num+=S[k]
        n=int(num)
        if n ==2019*int(n / 2019) :
            count=count+1
print(count)

Submission status: Runtime Error

Solution code:
a=list(map(int,input()))
print(a)
o=len(a)
da=0
cx=0
for i in range(o):
    for j in range(o):
        x=a[i:j+1]
        x1=len(x)-1
        for h in x:
            da+=h*(10**(x1)
            x1=x1-1
        if da%2019==0:
            cx+=1
print(cx)

Submission status: Runtime Error

Solution code:
def main():
    s = input()
    s_set = set()
    s_len = len(s)
    s_len1 = s_len-3
    s_len2 = s_len+1
    for i in range(s_len1):
      i_ = i+4
        for j in range(i_, s_len2):
            if int(s[i:j])%3 == 0: 
            	if int(s[i:j])%673 == 0:
              		s_set.add((i, j))

    return len(s_set)

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

Submission status: Runtime Error

Solution code:
S=input()
N=len(S)

U=[]
for i in range(N):
    U.append(S[i:])
ans=0
for i in range(N):
    l=U[len(U)-1-i]
    cnt=4
    while(1):
        if cnt>=len(l):
            break
        tmp=l[:cnt+1]
        if int(tmp)%2019==0:
            ans+=1
        cnt+=1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

def main():
    import sys
    input = sys.stdin.readline
    s = input().rstrip("\n")
    print(s[-5:])
    print(s[-5:0])
    j=0
    cnt=0
    flg=True

    if len(s)<=4:
        flg=False
        if int(s)%2019==0:
            print("1")
        else:
            print("0")

    if flg:
        h=0
        if s[-1]==0:
            h=1
        
        for i in range(h,len(s)):
            print(s[-i-1:])
            if int(s[-i-1:])%2019==0:
                cnt+=1
                j-=i
                break

        #print(cnt)
        if j==-len(s)+1:
            print(1)
            flg=False

        if flg:
            for i in range(-j,len(s)):
                #print(-i-1,j)
                if int(s[-i-1:j])%2019==0:
                    cnt+=1
                    j=-i
            print(cnt)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
s = input()
keta = len(s)
ans = 0
mul = []

for i in range(100):
    if "0" in str(2019 * i):
        pass
    else:
        mul.append(str(2019 * i))

# for i in range(len(mul)):
#     for j in range(0, keta + 1 - len(str(mul[i]))):
#         if s[j : j + len(mul[i])] == mul[i]:
#             ans += 1


for j in range(0, keta + 1 - len(str(mul[i]))):
    if s[j : j + len(mul[i])] in mul:
        ans += 1

print(ans)


# for i in range():

# print(ans)

Submission status: Runtime Error

Solution code:
s=list(input())
n=len(s)
a=''
t=0
for i in range(len(s)):
    a+=s[i]
    b=int(a)
for i in range(n*(n-1)//2):
    for j in range(i,n*(n-1)//2):
        k = int(a[i:j+1])
        if i<=j<=b and k%2019==0 or 2019%k==0:
            t+=1
print(t)

Submission status: Runtime Error

Solution code:
S = input()
S = S[::-1]
L = [0]
i = 0
for x in S:
    tmp = L[-1] + 10 ** i * int(x) % 2019
 #   print(tmp % 2019)
    L.append(tmp % 2019)
    i += 1
L = sorted(L[1::])
def counter(array):
    from collections import Counter
    return list(Counter(array).most_common())
c = counter(L)
from math import factorial
def comb(n,r):
    if n == 1: return 0
    return  return n * (n - 1) // 2
ans = 0
for x in c:
    if x[0] == 0: ans += x[1]
    ans += comb(x[1],2)
#print(L,c)
print(int(ans))

Submission status: Runtime Error

Solution code:
S = input()
count = 0
for i in range(len(S)):
    if int(S[i]) % 2 == 0:
    else:
        for j in range(i+1,len(S)):
            B = int(''.join(S[i:j+1]))
            if B % 2019 == 0:
                count += 1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

s = input()
l = len(s)

m = 2019
count = 0

mod_list = np.array([0 for i in range(m)])
num_list = np.array([i for i in range(m)])
ten_list = np.array([(i * 10) % m for i in range(m)])


tmp = mod_list.copy()
count=0
for i in range(l):
    for j in range(m):
        tmp[(j*10+int(s[i]))%m] = mod_list[j]
    tmp[int(s[i]) % m] += 1
    mod_list = tmp.copy()
    count+=mod_list[0]
print(count)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
N = input()
count = 0
for i in range(len(N) - 3):
    for a in range(len(N)-3):
        if N[i:i+4+a][0:1] == "0":
            break
        b = int(N[i:i+4+a]) / 2019
        if b.is_integer() and not b == 0.0:
            count += 1
        if i+4+a == len(N):
            break
print(count)

Submission status: Runtime Error

Solution code:
def main():
    import sys
    S = sys.stdin.readline()[:-1]

    S = input()
    int_S = int(S)
    N = len(S)
    cnt = 0
    pos_l = 0
    pos_r = 0


    while (True):
        pos_r +=  + 1
        
        if (pos_r < N):
            tmp = int(S[pos_l: pos_r + 1])
            if (tmp % 2019 == 0):
                cnt += 1
                pos_l = pos_r
        else:
            pos_l += 1
        
        if (pos_l >= N):
            break


    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

S = str(input())

amari = []
for i in range(len(S)+1):
    for j in range(i+4, len(S)+1):
        amari_tmp = int(S[i:j]) % 2019
        amari.append(amari_tmp)
        kosu = amari.count(0)

print(kosu)

Submission status: Runtime Error

Solution code:
S = input()
S = S[::-1]
L = [0]
i = 0
for x in S:
    tmp = L[-1] + 10 ** i * int(x) % 2019
 #   print(tmp % 2019)
    L.append(tmp % 2019)
    i += 1
L = sorted(L[1::])
def counter(array):
    from collections import Counter
    return list(Counter(array).most_common())
c = counter(L)
from math import factorial
def comb(n,r):
    if n == 1: return 0
    return  return n * (n - 1) // 
ans = 0
for x in c:
    if x[0] == 0: ans += x[1]
    ans += comb(x[1],2)
#print(L,c)
print(int(ans))

Submission status: Runtime Error

Solution code:
s=str(input())
n=len(s)
k=[0]*(n+1)
for i in range (1,n+1):
    k[i]=int(s[i-1])
t=[0]*(n+1)
t[0]=0  
for i in range(1,n+1):
    t[i]=(10*t[i-1]+k[i])%2019

p=1
q=[0]*448
for z in range(0,448):
    q[z]=p%2019
    p=10*q[z]

d=[0]*n   
for j in range(1,n+1):
    f=j%448
    d[j-1]=q[n-f]*t[j]%2019
ds=sorted(d)
ct=0
ans=0
if ds[0]==0:
    ct=1
    ans=1
for i in range(n-1):
    if ds[i+1]==ds[i]:
        ct+=1
        ans+=ct
    else:
        ct=0
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 26 22:06:14 2020

@author: Masataka Amau
"""
import numpy as np
S = input()
ans = 0
intlist = []
leng = len(S);
for i in range(leng):
    intlist.append(int(S[i]))

for i in range(leng):
    buf = 0
    for j in range(i, leng):
        buf *= 10
        buf += intlist[j]
        buf %= 2019
        if(buf == 0):
            ans += 1
print(ans)