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:
count = 0
for i in range(len(S)):
    if i+4 == len(S):
        j = i + 4
        number = int(S[i:j])
        if number == 2019:
            count += 1
        break
    try:
        for n in range(4,len(S)+1):
            j = i + n
            number = int(S[i:j])
            if number % 2019 == 0:
                if j == len(S)+1:
                    break
                else:
                    count += 1
            else:
                pass
    except IndexError:
        break
print(count)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
def search2019(x):
    """
    i: 始める場所
    x: 数字のみからなる文字列
    """
    xLen = len(x)
    if xLen < 4:
        return 0
    else:
        ans = 0

        for i in range(3,xLen):
                Slice = int(x[0:i+1])
                if (Slice != 0 and Slice % 2019 == 0):
                    #print(i)
                    #print(S,Slice)
                    ans += 1 + search2019(x[i+1:xLen])
                    break
        return ans

S = str(input())
S = S[0:len(S)-1]
#print(S)
#print(search2019(S))


Slen = len(S)
if (Slen < 4):
    print(0)

else:
    ans = 0
    for i in range(Slen - 3):
        for j in range(i+3, Slen):
            Slice = S[i:j+1]
            if ( int(Slice) != 0 and int(Slice) % 2019 == 0):
                ans += 1 + search2019(S[j+1:Slen])
                break
                #print(i, j)
    print(ans)
    #print(Slen)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
S=int(input())
K=len(str(S))
lst= [x for x in list(str(S))]
A=[[0 for v in range(2016)] for j in range(2019)]
A[int(lst[0])][0]+=1
for i in range(1,K):
 c=int(lst[i])
 A[c][i]+=1
 for k in range(2019):
  d=(k*10+c)%2019
  A[d][i]+=A[k][i-1]
print(sum(A[0]))

Submission status: Runtime Error

Solution code:
str = input()
x = int(str) // 2019
times = 0
for i in range(1,x):
    times += str.count(str(2019 *x))
print(times)

Submission status: Runtime Error

Solution code:
S=input()
c=0
for i in range(len(S)):
  for j in range(len(S)):
    s=S[i:j+1]
    if eval(s)%2019==0:
      c+=1
print(c)

Submission status: Runtime Error

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

if n < 4:
    print('0')
else:
    cnt = 0
    for j in range(n-3):
        i = 0
        while i < n-3-j:
            step = int(s[n-4-i-j:n-j])
            if step % 2019 == 0:
                cnt += 1
                i += 3
            i += 1

print(cnt)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
lis2019 = [0]*4
 
lis2019.append([str(2019*i) for i in range(1,5)])
lis2019.append([str(2019*i) for i in range(5,50)])
lis2019.append([str(2019*i) for i in range(50,100)])
lis2019.append([str(2019*i) for i in range(100,496)])
lis2019.append([str(2019*i) for i in range(496,4953)])
count = 0
for i in range(0,N):
    for k in range(i+3,N):
        if S[i:k+1] in lis2019[k-i+1]:
            count += 1
print(count)

Submission status: Runtime Error

Solution code:
def solve(s):
    N = int(int(s)/ 2019)
    ans = 0
    for i in range(1, N+1):
        ans += s.count(str(2019*i))
    return ans

# def solve(s):
#     N = len(s)
#     ans = 0
#     if N < 4:
#         return 0

#     for i in range(4,N+1):
#         for j in range(N-i+1):
#             ans += 1 if int(s[j:j+i])%2019==0 else 0
#     return ans


S = str(input())
print(solve(S))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = str(input())
ans = set()

def dfs(i, j):
    if int(S[i:j+1])%2019 == 0:
        ans.add((i, j))
    if j == len(S)-1:
        return

    dfs(i, j+1)
    dfs(i+1, j+1)

if len(S) < 4:
    print(0)

else:
    dfs(0, 3)
    if not ans:
        print(0)
    else:    
        print(len(ans))

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
s = int(S)
count = 0
for j in range(1,N+1):
    for i in range(1,j):
        if i==1:
            t=0
        else:
            t = (s//(10**(N-i+1)))*(10**(N-i+1))
        t = s-t
        t = t//(10**(N-j))
        if t % 2019 == 0 and t != 0:
            count += 1
            l.append((i,j))
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = input()
number = [ str(x*2019) for x in range(1000)]
count=0
v = []
for i in range(4, len(S)):
    for k in range(i):
        v =[]
        for l in range(0, len(S)//i):
            if len(S[l*i+k: l*i+k+i])==i:
                v.append(S[l*i+k: l*i+k+i])
        for m in v:
            print(v)
            if m in number:
                count+=1

print(count)

Submission status: Runtime Error

Solution code:
S = input()

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

def main():
# 整数の入力
    
    s = input()
    length = len(s)
    l = []
    for i in range(length):
        if length - i >= 4:

            for j in range(length - i):
                if j + 1 >= 4:
                    slice = s[i:i+j+1]
                     
                    if int(slice) % 2019 == 0:
                        l.append(n)

    # 出力
    print(len(l))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    s = input()
    s_len1 = len(s)-3
    s_len2 = len(s)+1
    s_tuple = ((i,j) for i in range(s_len1) for j in range(i+4, s_len2) if int(s[i:j])%2019==0)

    return len(s_tuple)

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

Submission status: Runtime Error

Solution code:
from itertools import combinations
s=input()
res = [s[x:y] for x, y in combinations(range(len(s) + 1), r = 2)] 
ans=0
for i in res:
    num=int(i)
    if num%2019==0:
        ans=ans+1
print(ans)

Submission status: Runtime Error

Solution code:
S = list(input())
l = len(S)

slist = [int(''.join(S[i:j])) for i in range(l-3) for j in range(i+4,l)]
 
cnt = sum([1 for s in slit if s%2019==0])
    
print(cnt)

Submission status: Runtime Error

Solution code:
import math
s = input()
ans = 0
for i in range(len(s)):
	for j in range(i+3, len(s)):
		if math.ceil(int(s[i:j+1])/2019) == math.floor(int(s[i:j+1])/2019): 
			ans+=1
			#print(s[i:j+1])
print(ans)

Submission status: Runtime Error

Solution code:
si=input()
sa = []
sss = []

for i in range(5,len(si)+1):
    ss = int(si[(i-5):i])
    if ss % 2019 == 0 and ss <= 200000:
        sa.append(i)
        sss.append(ss)
    ss = int(si[(i-4):i])
    if ss % 2019 == 0 and ss <= 200000:
        sa.append(i)
        sss.append(ss)
    if i>=6:
        ss = int(si[min((i-6):i])
        if ss % 2019 == 0 and ss <= 200000:
            sa.append(i)
            sss.append(ss)   
#print(sa)
#print(sss)
print(len(sa))

Submission status: Runtime Error

Solution code:
S = list(input())
l = list()
cnt = 0
for i in range(len(S)):
    for j in range(i,len(S)):
        S1 = S[i:j+1]
        s = "".join(S1)
        s = int(float(s))
        if s % 2019 == 0:
            cnt +=1
print(cnt)

Submission status: Runtime Error

Solution code:
from collections import Counter

S = input()

S_i = {}
for i in range(len(S)):
    v = int(S[i:])%2019
    if not(v in S_i.keys()):
        S_i[v] = 1
    else:
        S_i[v] +=1

ans = 0
for k in S_i.keys():
    if k==0:
        ans += S_cnt[k]
    elif S_cnt[k]>1:
        ans += S_cnt[k]*(S_cnt[k]-1)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
S = str(input())
ans = set()

def dfs(i, j):
    if int(S[i:j+1])%2019 == 0:
        ans.add((i, j))
    if j == len(S)-1:
        return

    dfs(i, j+1)
    dfs(i+1, j+1)

if len(S) < 4:
    print(0)

else:
    dfs(0, 3)
    print(len(ans))

Submission status: Runtime Error

Solution code:
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:
tmp = input().split()
N = list(tmp)
p = 0
L = len(N[0])

for i in range(L-3):
    for j in range(L - i - 3):
        if int(N[0][i+3:i+j+1]) == 1 or int(N[0][i+3:i+j+1]) == 9:
            m = int(N[0][i:i+j+4])%2019
            if m == 0:
                p = p + 1

print(p)

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

s = input().rstrip("\n")
j=0
cnt=0
if len(s)<=4:
    if int(s)%2019==0:
        print("1")
        sys.exit()
    else:
        print("0")
        sys.exit()

for i in range(len(s)):
    #print(s[-i-1:])
    if int(s[-i-1:])%2019==0:
        cnt+=1
        j-=i
        break
#print(cnt)
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)

Submission status: Runtime Error

Solution code:
string = input()
test_str = string
str_list = [test_str[i: j] for i in range(len(test_str)) 
          for j in range(i + 1, len(test_str) + 1)] 
int_list = map(lambda x: int(x), str_list)
int_list = list(map(lambda x:x%2019, int_list))
int_list.count(0)
print(int_list.count(0))

Submission status: Runtime Error

Solution code:
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
        print(int(N[i:i+4+a]))
        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:
c=0
import math
a=int(input())
l=math.ceil(math.log10(a+1))
for i in range(l-3):
    for j in range(0,l-3-i):
        if (math.floor((a%10**(l-i))/10**j))%2019==0:
            c+=1
print(c)

Submission status: Runtime Error

Solution code:
from queue import deque
def judge(t):
    if t>=2019:
        if t%2019==0:
            l.append(t)
        return judge(t//10)
    else: return 0
    

s = deque(input())
# print(s)
l = []
for i in range(len(s)):
    t = int(''.join(s))
    # print(t)
    # while t>0:
    judge(t)
    s.popleft()
print(len(l))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)
S = input()
ans = 0
i = 0
while i < len(S)-3:
    for j in range(i+4, len(S)+1):
        if int(S[i:j]) % 2019 == 0:
            ans += 1
            i += j-5
    i += 1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from collections import deque

s=input()
n=len(s)
dd = defaultdict(int)
q = deque()
ans=0
for i in range(4):
    q.append(s[i])
if(int(''.join(q))%2019)==0:
    ans+=1

for i in range(0, n-3):
    for j in range(5, n+1, 3):
        if i+j<n+1:
            dd[(i,i+j)]+=1
            if(int(s[i:i+j])%2019==0) and dd[(i,i+j)]==1:
                ans+=1
            if j>n-4:
                for k in range(3):
                    if i+j+k<n:
                        dd[(i,i+j+k)]+=1
                        if int(s[i:i+j+k])%2019==0 and dd[(i,i+j+k)]==1:
                            ans+=1

print(ans)

Submission status: Runtime Error

Solution code:
s_input=input()
s=list(s_input)
cnt=0
u_num=0
s_num=0
for i in range(len(s)-3):
    for j in range(i+3,len(s)):
        s_num=s_input[i:j+1]
        if int(s_num)%2019==0:
            u_num=j-1
            break
    if u_num!=0:
        break
if u_num-i==0:
    print(0)
    exit()
if len(s)%(u_num-i)==0:
    print(len(s)//(u_num-i))
else:
    print((len(s)//(u_num-i))-1)

Submission status: Runtime Error

Solution code:
s = list(input())
start = 0
finish = 3
cnt = 0


while True:
    num = ''
    for i in range(start, finish+1):
        num += s[i]
    num = int(num)
    if num % 2019 == 0:
        cnt += 1

    if finish != len(s) - 1:
        finish += 1
    elif finish == len(s) - 1 and start != len(s) - 4:
        start += 1
        finish = start + 3
    else:
        break

print(cnt)

Submission status: Runtime Error

Solution code:
from sys import stdin, stdout  
  
def main(): 
	strInput = stdin.readline().rstrip()
	lenn = len(strInput)
	cnt  = 0
	for i in range(0, lenn - 3):
		for k in range(i + 4, lenn + 1):
			#print("combination", strInput[i: k] )
			if int(strInput[i: k]) % 2019 == 0 :	
				cnt+=1
				#print(strInput[i: lenn])
			if strInput[i] == '0':
				cnt+=1	
	for j in range(lenn - 3, lenn):
		if strInput[j] == '0':
			cnt+=1	
	stdout.write( str(cnt)+'\n')
if __name__ == "__main__": 
	main()

Submission status: Runtime Error

Solution code:

import sys
s = input().rstrip("\n")
j=0
cnt=0
if len(s)==4:
    if int(s)%2019==0:
        print("1")
        sys.exit()
    else:
        print("0")
        sys.exit()

for i in range(len(s)):
    #print(s[-i-1:])
    if int(s[-i-1:])%2019==0:
        cnt+=1
        j-=i
        break
#print(cnt)
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)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = str(input())
ans = 0

if len(S) <= 3:
    print(0)
else:   
    for i in range(len(S)-3):
        if S[i:i+3] % 2019 == 0:
            ans+=1
    print(ans)

Submission status: Runtime Error

Solution code:
n = input() #1行目のNを取得する
l = len(n)
count = 0

list = [n[i:j] for i in range(l-3) for j in range(i+4,l+1) ]
for k in range(len(list)):
               if int(list[k]) % 2019 == 0:
                 count +=1
print(count)

Submission status: Runtime Error

Solution code:
c=0
import math
a=int(input())
l=math.ceil(math.log10(a+1))
for i in range(l-3):
    for j in range(0,l-3-i):
        print(math.floor((a%10**(l-i))/10**j))
            c+=1
print(c)

Submission status: Runtime Error

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

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))
l1 = list(filter(lambda i:True if str(i) in a else False, l))
print(len(l1))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
cnt = 0

if len(s) > 3:
    for i in range(len(s)-2):
        for j in range(i+2, len(s)):
            s_a = s[i:j+1]

            if int(float(s_a))%2019 == 0:
                cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
S=input()
N=len(S)
counter=0
for i in range(N):
    a=4+i
    while a < LS+1:
        #print(a)
        b=int(S[i:a])
        print(b)
        if b%2019 == 0:
            counter += 1
        a+=1
print(counter)

Submission status: Runtime Error

Solution code:
S=int(input())
c=0
for i in range(len(S)):
  for j in range(len(S)):
    if int(float(S[i:j+1]))%2019=0:
      c+=1
print(c)

Submission status: Runtime Error

Solution code:
s = int(input())
ss = str(s)
l2019=["2019"]
tmp = 2019
i = 2
count = 0
while(1):
    if tmp * i > s:
        break
    l2019.append(tmp*i)
    i += 1
for i in range(0,len(l2019)):
    if l2019[i] in ss:
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
S = input()

count = 0
i = 0
j = len(S)
while True:
    if int(S[i:j]) % 2019 == 0:
        count += 1
    j -=1
    if i + 4 > j:
        i += 1
        j = len(S)
    if i + 3 == len(S):
        break
    
print(count)

Submission status: Runtime Error

Solution code:
s = input()
l = len(s)
cnt = 0
for i in range(l-1):
    for j in range(i+1, l):
        a = sum([int(i) for i in s])
        if not a % 3 ==0:
            continue;
        if eval(s[i:j+1]+'/2019') == 0:
            cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
S = input()
Scount = 0
for i in range(len(S)-1):
    for j in range(1,len(S)):
        if (i+j)<=len(S):
            part_S = S[i:i+j]
            num = int(part_S)
            if num % 673 == 0:
                num = int(num/673)
                if num % 3 ==0:
                    Scount += 1
print(Scount)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
a = input()
while (int(a) != 0):
    remain = [0for i in range(2019)]
    remain[int(a[0])] = remain[int(a[0])] + 1  ##V0
    n = len(a)
    cnt = 0
    for i in range(1,n):
        copy = remain[:]
        remain = [0for i in range(2019)]
        a_i = int(a[i])
        if (a_i != 0):
            for k in range(2019):
                rem = (k*10 + a_i)%2019
                remain[rem] += copy[k]
            remain[a_i] += 1
        elif (a_i == 0):
            for k in range(2019):
                rem = (k*10 + a_i)%2019
                remain[rem] += copy[k]
        cnt += remain[0]
    print(cnt)
    exit(0)

Submission status: Runtime Error

Solution code:
S = input()

magic = 2019
max_val = int(int(S) / magic)
max_len = len(str(max_val*magic))
len_S = len(S)
len_magic = len(str(magic))

now_val = max_val*magic
now_len = max_len

n = 0
tmp_len = now_len
for i in range(now_len, len_magic, -1):
  for j in range(len_S-i+1):
    k = j + tmp_len
    # print("now_len: "+str(now_len))
    # print("{} {}".format(j,k))
    if int(S[j:k]) % magic == 0:
      # print("{} {}".format(j,k))
      n += 1

  tmp_len -= 1
    

print(n)

Submission status: Runtime Error

Solution code:
s = input()
s_num = int(s)
len_s = len(s)
list=[0 for x in range(len_s+1)]
for i in range(len_s-1,-1,-1):
    for j in range(1,9):
        if int(s[i:i+j])%2019==0:
            list[i]=list[i+j]+1
print(sum(list))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=input()

count=0
res=0

N=N[::-1]

while True:
    res=N[:-6:-1]
    if int(res)%2019==0:
        count+=1
        print(N)
    N=N[4:]


    if int(len(N))<=4:
        break    

print(count)

Submission status: Runtime Error

Solution code:
#d
N = int(input())
s  = str(N)
a =[]

def func(string,p):
    count=0
    for x in range(len(string)-len(p)+1):
        if string[x:x+len(p)]==p:
            count+=1
    return count

for i in range(1,496):
    a.append(str(2019*i))
if len(s)<4:
    print(0)
else:
    ans=0
    for j in a:
        ans+=func(s,j)
    for x in range(N):
        for y in range(x+6,N):
            if int(s[x:y])%2019==0:
                ans+=1
    print(ans)

Submission status: Runtime Error

Solution code:
S = list(input())
L = len(S)
Sum = 0
def fa(x,y):
    A = 0
    for i in range(x,y+1):
        A += int(S[i])
        A *= 10
    return A
for j in range(0,L):
    for k in range(j,L):
        if (fa(j,k)/10) % 2019 == 0:
            Sum += 1
print(Sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
arr = int(input())
array = 0
count = 0

for i in range(int(len(a)) + 1):
  for j in range(int(len(a)) + 1):
  array = int(a[i : j])
  if array % 2019 == 0 and array != 0:
    count ++
print(count)

Submission status: Runtime Error

Solution code:
from functools import lru_cache
from tqdm import tqdm



S=input()
count=[0 for i in range(2019)]
length=len(S)
#S=int(S)
S=S+'0'
S=S[::-1]
_S=0

base=1
for i,s in enumerate(S):
    _S=base*int(s)+_S
    count[_S%2019]+=1
    base*=10
    base=base%2019
    _S=_S%2019



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)

Submission status: Runtime Error

Solution code:
a=input()
b=int(a)

ans=0

for i in range(1,int(b/2019)+1):
  ans += a.count(str(2019*i))

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
if len(s) <= 4 and s != '2019':
    print(0)
    exit()

M_2019 = [2019 * i for i in range(1, 200001)]
S = [s[:i] for i in range(4, len(s) + 1)]
cnt = 0
for i_s in S:
    for j in range(len(i_s)-4):
        if int(i_s[j:]) in M_2019:
            cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
S = input()

n = len(S)

l = [val for val in range(n)]

p = itertools.permutations(l, 2)

s = 0

for val in p:
  num_1 = val[0]
  num_2 = val[1]
  if int(S[num_1:num_2])%2019 == 0:
    s += 1

print(s)

Submission status: Runtime Error

Solution code:
S = input()

magic = 2019
max_val = int(int(S) / magic)
max_len = len(str(max_val*magic))
len_S = len(S)

now_val = max_val*magic
now_len = max_len

n = 0
tmp_len = now_len
for i in range(now_len, 0, -1):

  for j in range(len_S-i+1):
    k = j + tmp_len
    # print("now_len: "+str(now_len))
    # print("{} {}".format(j,k))
    if int(S[j:k]) % magic == 0:
      # print("{} {}".format(j,k))
      n += 1
      
  tmp_len -= 1
    

print(n)

Submission status: Runtime Error

Solution code:
s = input()
ans = 0
af = 0
for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j+3]
    if len(a) <= 200000:
      af = 0
    else int(a) % 2019 == 0:
      ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
a = input()
while (int(a) != 0):
    remain = [0for i in range(2019)]
    remain[int(a[0])] = remain[int(a[0])] + 1  ##V0
    n = len(a)
    cnt = 0
    for i in range(1,n):
        copy = remain[:]
        remain = [0for i in range(2019)]
        a_i = int(a[i])
        if (a_i != 0):
            for k in range(2019):
                rem = (k*10 + a_i)%2019
                remain[rem] += copy[k]
            remain[a_i] += 1
        elif (a_i == 0):
            for k in range(2019):
                rem = (k*10 + a_i)%2019
                remain[rem] += copy[k]
        cnt += remain[0]
    print(cnt)
    exit(0)

Submission status: Runtime Error

Solution code:
s=input()
# print(len(s));
i=0
count=0

for k in range(4,len(s)+1):

    for j in range(k,len(s)+1):

    
        m=s[i:j]
    
        # print(int(m))
        if int(m)%2019==0:
            count+=1
        i=i+1

print(count)

Submission status: Runtime Error

Solution code:
s = input()
c = 0
for i in range(len(s)):
    for j in range(i+4,len(s)+1):
        a = int(s[i:j])
        if a>=2019 and a%3==0 a%673==0:
            c += 1
print(c)

Submission status: Runtime Error

Solution code:
s=input()
        
ngram=[]
for i in range(4,len(s)):
    for j in range(len(s)-i+1):

ans=0
for i in range(len(ngram)):
    if int(ngram[i])%2019==0:
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n = input()
count = 0

length = len(n)

if length > 4:
	for i in range(3, length): # i=3~len-1
    	for j in range(i-2): # j=0~i-3
        	if int(n[j: i+1]) % 2019 == 0:
            	count = count + 1

print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
M=list(str(N))
P=len(M)
sum=0
if P-3<=0:
    print(0)
else:
    for i in range(P-3):
      for j in range(P-i-3):
        num=int((N%(10**(P-i))-N%(10**(P-i-j-4)))/(10**(P-i-j-4)))
        if num%2019==0:
            sum+=1
    print(sum)

Submission status: Runtime Error

Solution code:

import sys
input=sys.stdin.readline()
a = input()
while (int(a) != 0):
    remain = [0for i in range(2019)]
    remain[int(a[0])] = remain[int(a[0])] + 1  ##V0
    n = len(a)
    cnt = 0
    for i in range(1,n):
        copy = remain[:]
        remain = [0for i in range(2019)]
        a_i = int(a[i])
        if (a_i != 0):
            for k in range(2019):
                rem = (k*10 + a_i)%2019
                remain[rem] += copy[k]
            remain[a_i] += 1
        elif (a_i == 0):
            for k in range(2019):
                rem = (k*10 + a_i)%2019
                remain[rem] += copy[k]
        cnt += remain[0]
    print(cnt)
    exit(0)

Submission status: Runtime Error

Solution code:
c=0
import math
a=int(input())
l=math.ceil(math.log10(a+1))
for i in range(l-3):
    for j in range(0,l-3-i):
        if int((a%10**(l-i))/10**j)%2019==0:
            c+=1
print(c)

Submission status: Runtime Error

Solution code:
S = list(input())
L = len(S)
Sum = 0
def fa(x,y):
    A = 0
    for i in range(x,y+1):
        A += int(S[i])
        A *= 10
    return A
for j in range(0,L-1):
    for k in range(j+1,L):
        if (fa(j,k)/10) % 2019 == 0:
            if fa(j,k) != 0:
                Sum += 1
print(Sum)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
lis2019 = [0]*4

lis2019.append([str(2019*i) for i in range(1,5)])
lis2019.append([str(2019*i) for i in range(5,50)])
lis2019.append([str(2019*i) for i in range(50,100)])
count = 0
for i in range(0,N):
    for k in range(i+3,N):
        if S[i:k+1] in lis2019[k-i+1]:
            count += 1
print(count)

Submission status: Runtime Error

Solution code:
def retry(list_S, ans, start_ii=0):
    if start_ii > len(list_S) - 3:
        return ans

    for start_i in range(start_ii, len(list_S) - 3):
        for last_i in range(start_i + 3, len(list_S)):
            tmp = ''.join(list_S[start_i:last_i + 1])

            if (int(tmp) % 2019) == 0:
                ans += 1
                return retry(list_S, ans, last_i)

    return ans


def resolve():
    S = input()
    list_S = list(S)
    ans = 0

    print(retry(list_S, ans))


resolve()

Submission status: Runtime Error

Solution code:
def subCount(arr, n, k): 
  
    # create auxiliary hash 
    # array to count frequency 
    # of remainders 
    mod =[] 
    for i in range(k + 1): 
        mod.append(0) 
    
    # Traverse original array 
    # and compute cumulative 
    # sum take remainder of this 
    # current cumulative 
    # sum and increase count by 
    # 1 for this remainder 
    # in mod[] array 
    cumSum = 0
    for i in range(n): 
        cumSum = cumSum + arr[i] 
           
        # as the sum can be negative, 
        # taking modulo twice 
        mod[int(((cumSum % k)+k)% k)]= mod[int(((cumSum % k)+k)% k)] + 1
      
    
    result = 0  # Initialize result 
       
    # Traverse mod[] 
    for i in range(k): 
    
        # If there are more than 
        # one prefix subarrays 
        # with a particular mod value. 
        if (mod[i] > 1): 
            result = result + (mod[i]*(mod[i]-1))//2
       
    # add the elements which 
    # are divisible by k itself  
    # i.e., the elements whose sum = 0 
    result = result + mod[0] 
       
    return result 


s = input()
n = len(s)
a = []
k = pow(10, n-1)
for i in range(0, n):
    a.append(int(s[i])*k)
    k/=10

print(subCount(a, n, 2019))

Submission status: Runtime Error

Solution code:
n=input()
count=0 

a=[]
for i in range(len(n)):
    for j in range(i+1,len(n)+1):
        a.append(n[i:j])

for x in a:
    if int(x)%2019==0:
        count+=1 
        
print(count)

Submission status: Runtime Error

Solution code:
s=str(input())
a=[]
ans=0
for i in range(len(s)):
    for j in range(len(s[i+3:])):
        a+=[s[i:4+j+i]]
        
target =list(str(2019*i) for i in range(1,100))
for i in a:
    if str(i) in target:
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
# for i in range(10):
# 	print( 10 ** i % 2019)



s = list(map(int, list(input())))
n = len(s)
MODULO = 2019

power = 1a
prefix_ = [0 for _ in range(n+1)]
for i in range(n-1, -1, -1):
	prefix_[i] = (prefix_[i+1] + power*s[i]) % MODULO
	power *= 10
	power %= MODULO

seen = {}
ans = 0
for item in prefix_:
	ans += seen.get(item, 0)
	seen[item] = seen.get(item, 0) + 1

# print(s)
# print("prefix_", prefix_)
# print("unique", len(set(prefix_)))
# print("all", len(prefix_))
print(ans)

Submission status: Runtime Error

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

S = input()
l = len(S)
no_zero_dic = {}
dp = [[0] * (2019) for i in range(l)]
ans = 0
for i in range(l):
    s = int(S[i])
    no_zero_dic[s] = 1
    _x = set(no_zero_dic.keys())
    for j in _x:
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
        if dp[i-1][j] > 0:
            no_zero_dic[k] = 1
        if k == 0:
            ans += dp[i][k]
    dp[i][s] += 1


print(ans)

Submission status: Runtime Error

Solution code:
#create date: 2020-04-26 21:06

import sys
stdin = sys.stdin

from numba import njit

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    s = ni()
    n = len(str(s))

    @njit
    def d(s, n):
        m = [0] * 2019
        now = 0
        for i in range(n):
            now = (s % 10**(i+1)) % 2019
            #print(now)
            m[now] += 1
        return m
    m = d(s, n)

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

    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
ans = 0;

def is2019x(i,j,check,s) :
    x_p = int(s[i:j+1]);
    if j<len(s) and x_p % 2019 == 0 :
        global ans
        ans += 1;
        is2019x(i,j+4,0,s);
    elif j<len(s) and check > 4 :
        return;
    elif j<len(s) :
        is2019x(i,j+1,check+1,s);
    else :
        return;

s = str(input().rstrip('\n'));

for i in range(len(s)-3) :
    is2019x(i,i+3,0,s);

print(ans);

Submission status: Runtime Error

Solution code:
import numpy as np

s = input()

# print(s)

ans = np.zeros((len(s), len(s)), dtype = np.int)

# print(ans)

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

# print(ans)

print(np.sum(ans))