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:
# coding: utf-8
# Your code here!


d = 2019

def solve(s):
    dp = [0] * (len(s)+1)
    dp[len(s)] = 0
    for i in range(len(s)-1,-1,-1):
        dp[i] = int(s[i:]) % d
    memo = dict()
    count = 0
    for i,v in enumerate(dp):
        if memo.get(v,False):
            count+=1
        memo[v] = memo[v]+1
    return count

s = input()
print(solve(s))

Submission status: Runtime Error

Solution code:
a=input()
n=len(a)
t=0
for i in range(n-3):
  for j in range(n-3-i):
    if int(a[i:n-j])%2019==0:
      t+=1
prin(t)

Submission status: Runtime Error

Solution code:
s = input()
ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
S = str(input())
arr = []
list = {}
cnt = 0
for i in range(len(S)-3):
    val = int(S[i]) + int(S[i+1]) + int(S[i+2])
    for j in range(i+3, len(S)):
        val += int(S[j])
        if val%3 == 0:
            arr.append(S[i:j+1])

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

'''

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!


d = 2019

def solve(s):
    dp = [0] * (len(s)+1)
    dp[len(s)] = 0
    for i in range(len(s)-1,-1,-1):
        dp[i] = int(s[i:]) % d
    memo = dict()
    count = 0
    for i,v in enumerate(dp):
        if memo.get(v,False):
            count+=1
        memo[v] += 1
    return count

s = input()
print(solve(s))

Submission status: Runtime Error

Solution code:
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)
S = input()
Scount = 0
for i in range(len(S)):
    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)
                sum3 = digitSum(num)
                while sum3 != digitSum(sum3):
                    sum3 = digitSum(sum3)
                if sum3 == 3 or sum3 == 6 or sum3 ==9:
                    Scount += 1
print(Scount)

Submission status: Runtime Error

Solution code:
ret = 0
for i in range(len(S)-3):
    for j in range(i+3, len(S)+1):
        # print(S[i:j])
        if eval(S[i:j]) % 2019 == 0:
            print(i+1, j)
            ret += 1
print(ret)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000)

s = list(input())
n = len(s)
t = 2019

cnts = {}


def recur(i, j):
    if i == n-3 and j == n:
        return
    if 0 == int("".join(s[i:j+1])) % t:
        if not (i, j) in cnts:
            cnts[(i, j)] = 0
        cnts[(i, j)] += 1
    if j < n - 1:
        recur(i, j + 1)
    if j - i > 3:
        recur(i + 1, j)
    if j < n - 1 and j - i > 3:
        recur(i + 1, j + 1)


recur(0, 3)
print(len(cnts.keys()))

Submission status: Runtime Error

Solution code:
N = input()
count = 0
for i in range(len(N) - 3):
    for a in range(len(N)-3):
        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 mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

S = input()
N = len(S) # 2*(10**5)


from collections import deque

ans = 0
fisrt_4cahr = S[:4]
rest_s = S[4:]
l = [fisrt_4cahr]

for c in rest_s:
    l.append(l[-1]+c)
Q = deque(l)
while Q:
    temp = Q.popleft()
    if int(temp)%2019==0:
        ans += 1
    if len(temp) != 4:
        Q.append(temp[1:])

print(ans)

Submission status: Runtime Error

Solution code:
mod_673 = [1] * 672
for i in range(1,672):
    mod_673[i] = (mod_673[i -1] * 10) % 673

S = input()
S = S[::-1]
A = [0] * (len(S) + 1)
B = [0] * (len(S) + 1)
x = 0
Ans = [[0] * 3 for i in range(673)]
for i in range(1, len(S) + 1):
    A[i] = (A[i - 1] + int(S[i - 1]) * mod_673[(i - 1) % 673]) % 673
    B[i] = (B[i - 1] + int(S[i - 1])) % 3

for i in range(len(S) + 1):
    Ans[A[i]][B[i]] += 1

for i in range(673):
    for j in range(3):
        y = Ans[i][j]
        x += y * (y - 1) // 2

print(x)

Submission status: Runtime Error

Solution code:
s = str(input())
ARY = ['12114','14133','16152','18171','24228','26247','28266','34323','36342','38361','42399','44418','46437','48456','52494','54513','56532','58551','62589','66627','68646','72684','76722','78741','82779','84798','86817','88836','92874','94893','96912','98931','119121','123159','125178','127197','129216','131235','133254','135273','137292','139311','143349','145368','147387','151425','153444','155463','157482','163539','165558','167577','169596','171615','173634','175653','177672','179691','183729','185748','187767','189786','193824','195843','197862','199881']
counta=0
for i in ARY:
    flag = True
    tmp = 0
    start = 0
    while tmp>=0:
        tmp = s[start:].find(i)
        print(i,s[start:])
        #print(tmp)
        if tmp >= 0:
            start += tmp + 1
            counta+=1
        else:
            tmp = -1
print(counta)

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
                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:
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:
            Sum += 1
print(Sum)

Submission status: Runtime Error

Solution code:
N = input()
count = 0
for i in range(len(N) - 3):
    for a in range(len(N)-3):
        b = int(N[i:i+4+a]) / 2019
        print(b)
        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()
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 s in S:
  for i in range(len(s)):
    if int(s[i:]) in M_2019:
          cnt += 1
  
print(cnt)

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

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

  now_len -= 1
    

print(n)

Submission status: Runtime Error

Solution code:
S=input()

x=[i for i in range(1,100)]
x=map(lambda i:str(i*2019),x)


ans=0

import re
for i in x:
    t=len(re.findall(?=i,S))
    ans+=t

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
from bisect import bisect

S = input()
if len(S) < 4:
  print(0)
else:
  ans = 0
  d = [deque() for _ in range(3)]
  x = 0
  d[x].append(0)
  for i, s in enumerate(S):
    x = (x+int(s))%3
    d[x].append(i+1)
  for m in range(3):
    for s in d[m]:
      eidx = bisect(d[m], s+4)
      while eidx < len(d[m]):
        e = d[m][eidx]
        ans += 1 if int(S[s:e])%2019 == 0 else 0
        eidx += 1
print(ans)

Submission status: Runtime Error

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

S = input()
l = len(S)
no_zero_dic = {}
dp = [[0 for _ in range(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:
import regex

S = str(input())

count = 0
for i in range(1, 100):
    count += len(regex.findall(str(i * 2019), S, overlapped=True))

print(count)

Submission status: Runtime Error

Solution code:
s = str(input())
i = 0
j = 4
counter = 0
num_length = int(len(s))

start = j 

while True:
    #print(i,j)
    temp = int(s[i:j])
    if temp % 2019 == 0:
        #print(i,j)
        counter += 1
    j = j + 1
    #print(i,j,num_length)
    if j > num_length:
        j = i + 3
        i = i + 1


    if i == num_length - 4 or num_length == 4:
        print(counter)
        exit()

Submission status: Runtime Error

Solution code:
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)
S = input()
Scount = 0
for i in range(len(S)):
    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)
                sum3 = digitSum(num)
                while sum3 != digitSum(sum3):
                    sum3 = digitSum(sum3)
                if sum3 == 3 or sum3 == 6 or sum3 ==9:
                    Scount += 1
print(Scount)

Submission status: Runtime Error

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

ak10k = [(pow(10,n-k-1,m)*int(s[k]))%m for k in range(0,n)]

ruiseki=[0]*n
ruiseki[0]=ak10k[0]
for i in range(1,n):
    ruiseki[i]=(ruiseki[i-1]+ak10k[i])%2019

from collections import Counter
c = Counter(ruiseki)

ans=sum(cc*(cc-1)//2 for cc in c.values()) + list(c.keys()).count(0)

print(ans)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    string = input()
    count = 0
    d = []
    i=1
    while len(str(2019*i))<len(string):
        d.append(2019*i)
        i=i+1

    for item in d:
        for i in range(0, len(string)+1-len(item)):
            if int(str[i:i + len(item)]) == item:
                count = count + 1
    print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

s = input()

# print(s)

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

# print(ans)

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

# print(ans)

print(np.sum(ans))

Submission status: Runtime Error

Solution code:
s = str(input())
l = len(list(s))

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

print(n)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=input()
ans=0
ls=len(s)
if ls=>4:
  s1=[s[i:i+4] for i in range(ls-3)]
  s2=[s[i:i+5] for i in range(ls-4)]
  l1=[2019, 4038, 6057, 8076]
  l2=[10095, 12114, 14133, 16152, 18171, 20190, 22209, 24228, 26247, 28266, 30285, 32304, 34323, 36342, 38361, 40380, 42399, 44418, 46437, 48456, 50475, 52494, 54513, 56532, 58551, 60570, 62589, 64608, 66627, 68646, 70665, 72684, 74703, 76722, 78741, 80760, 82779, 84798, 86817, 88836, 90855, 92874, 94893, 96912, 98931, 100950, 102969, 104988, 107007, 109026, 111045, 113064, 115083, 117102, 119121, 121140, 123159, 125178, 127197, 129216, 131235, 133254, 135273, 137292, 139311, 141330, 143349, 145368, 147387, 149406, 151425, 153444, 155463, 157482, 159501, 161520, 163539, 165558, 167577, 169596, 171615, 173634, 175653, 177672, 179691, 181710, 183729, 185748, 187767, 189786, 191805, 193824, 195843, 197862, 199881]
  for i in l1:
    ans += s1.count(str(i))
  for i in l2:
    ans += s2.count(str(i))
print(ans)

Submission status: Runtime Error

Solution code:
s = input()

ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
S = input()
slist = []
ans = 0
if(len(S)<=3):
  print(ans)
else:
  for i in range(len(S)-3):
    for j in range(i+3, len(S)):
      temp = S[i:j+1]
      slist.append(temp)
  for i in range(len(slist)):
    if(int(slist[i]) % 2019 == 0):
      ans += 1
      #print(slist[i])
  print(ans)

Submission status: Runtime Error

Solution code:
for i in range(100):
    t = i * 2019
    if t > 200000:
        break
    for i in range(len(str(s))):
        for j in range(i+1, len(str(s))+1):
            tmp = s[i:j]
            if int(tmp) == t:
                c += 1


print(c)

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, 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:
def slove(n):
    count = 0
    num = len(n)+1
    memo = {}
    for i in range(num-4):
        for j in range(i+4, num):
            tmp = int(n[i:j])
            if tmp in memo and memo[tmp]:
                count+=1
            else:
                if tmp % 2019 == 0:
                    count += 1
                    dp[tmp] = True

    return count

if __name__ == "__main__":
    n = input()
    print(slove(n))

Submission status: Runtime Error

Solution code:
s = input()
z = int(s) // 2019
x = [str(2019 * (i + 1)) for i in range(z)]
c = 0
for y in x:
  start = 0
  while len(s[start:]) >= len(y):
    a = s[start:].find(y)
    if a == -1:
      break
    if a >= 0:
      c += 1
      start += a + 1
print(len(c))

Submission status: Runtime Error

Solution code:
s = input()
cnt = 0
for l in range(len(s)):
    r = l + 1
    while r < len(s) and int(s[l:r]) % 2019 != 0:
        r += 1
    if int(s[l:r]) % 2019 == 0:
        cnt += 1
        print(i, j, s[i:j])
print(cnt)

Submission status: Runtime Error

Solution code:
def printSubArrays(arr, start, end, count): 
      
    # Stop if we have reached the end of the array     
    if end == len(arr): 
        print(count)
        return
      
    # Increment the end point and start from 0 
    elif start > end: 
        return printSubArrays(arr, 0, end + 1, count) 
          
    # Print the subarray and increment the starting 
    # point 
    else: 
        if int(''.join(arr[start:end + 1])) % 2019 == 0:
            count += 1

        return printSubArrays(arr, start + 1, end, count) 

          
# Driver code 
arr = list(input())
printSubArrays(arr, 0, 0, 0)

Submission status: Runtime Error

Solution code:
A=list(input())
ans=0
s=set()
for i in range(len(A)-1):
  for j in range(i+1,len(A)):
    r=int("".join(A[i:j+1]))
    if r in s:
      ans+=1
    if r%2019==0:
      ans+=1
      s.add(s)
print(ans)

Submission status: Runtime Error

Solution code:
S = str(input())

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

Submission status: Runtime Error

Solution code:
s = input()

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

Submission status: Runtime Error

Solution code:
import numpy as np

s = input()

# print(s)

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

# print(ans)

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

# print(ans)

print(np.sum(ans))

Submission status: Runtime Error

Solution code:
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def factorization(n):
	tmp=n
	count=0
	for i in range(2,int(n**0.5)+2):
		if tmp%i==0:
			cnt=0
			while tmp%i==0:
				cnt+=1
				tmp//=i
			count+=1
	if tmp!=1:
		count+=1

	return count
			




s=list(str(input()))
combi=combinations(int(len(s)),2)
count=0
for i in range(len(s)):
	start=i[0]
	end=i[1]
	if (end-start)<4:
		break
	num=int("".join(s[start:end+1]))
	if num%2019==0:
		count+=1
print(count)

Submission status: Runtime Error

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

def main():
    n = input()
    l = len(n)
    mody = 2019
    cnt = 0
    for i in range(l - 3):
        x = int(n[i:i + 4])
        x %= mody
        if x == 0:
            cnt += 1
        for j in range(i + 4, l):
            x = 10 * x + int(n[j])
            x %= mody
            if x == 0:
                cnt += 1
    print(cnt)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#D
s = input()
count = 0
# print(len(s))
for left in range(len(s) - 3):
    for right in range(left + 3, len(s)):
        print(left + 1, right + 1)
        if int(float(s[left:right + 1])) % 2019 == 0:
            print(s[left:right])
            count += 1
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

inp = input()
n = len(inp)
s = int(inp)

count = 0

for i in range(n):
  if n - i > 3:
    c = math.floor(s / (10 ** i))
    for j in range(i + 1, n + 1):
      ct = c - math.floor(c / 10 ** (j - i)) * (10 ** (j - i))
      if (ct % 2019) == 0:
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
s = input()

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

print(count)

Submission status: Runtime Error

Solution code:
numMultiples=0
S=input()
N=len(S)
seenRemainders=[set()]*(100000)
for i in range(N):
    remainder = 0
    prefixesFound = 0
    for j in range(i,N):
        remainder = (10 * remainder + int (S[j]) ) % 2019
        # if remainder in seenRemainders[j]:
        #     break
        seenRemainders[j].add(remainder)
        if remainder == 0:
            prefixesFound+=1
    numMultiples += prefixesFound * (prefixesFound + 1) / 2
print(int(numMultiples))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
    s = input()
    s_set = set()
    s_len = len(s)
    for i in range(s_len-3):
        for j in range(i+4, s_len+1):
            if int(s[i:j])%6 == 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:
N=int(input())
M=list(str(N))
M=len(M)
sum=0
for i in range(M-3):
  for j in range(M-i-3):
    num=int((N%(10**(M-i))-N%(10**(M-(i+j+4))))/(10**(M-(i+j+4))))
    if num%2019==0:
        sum+=1
print(sum)

Submission status: Runtime Error

Solution code:
import numpy as np
s=input()
n=len(s)
dp=(np.zeros((n+1,n+1))).astype("int8").tolist()
count=0
for i in range(n):
    for j in range(i+1,n+1):
        dp[i][j]=pow(dp[i][j-1]*10+int(s[j-1]),1,2019)
        if dp[i][j]==0:
            count+=1
print(count)

Submission status: Runtime Error

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


S = input()
N = len(S)

sum = 0
for i in range(N+1):
    for j in range(i+1,N+1):
        A = S[i:j]
        A = int(A.replace("",""))
        if A % 2019 == 0:
            sum += 1
print(sum)

Submission status: Runtime Error

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

import sys
import math
import bisect

debug = False

def log(text):
    if debug:
        print(text)


def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    s = lines[0]
    return (s, )


def solve(s, ):

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


    return count


if __name__ == '__main__':

    main()

Submission status: Runtime Error

Solution code:
s = int(input())
    y=0
    t=len(str(s))-3
    f=len(str(s))
def main():
    for i in range(t):
        for j in range(i+3,f):
            p=int(str(s)[i:j+1])
            if p%2019==0:
                y+=1

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def retry(list_S, ans, start_ii=0):
    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
                retry(list_S, ans, last_i)

    return ans


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

    if len(list_S) <= 3:
        print(ans)
        return

    ans = retry(list_S, ans)

    print(ans)


resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()

n = 0
for i in range(len(s)+1):
	for j in range(i):
		x = int(s[j:i])
		if (x / 2019) == (x // 2019):
			n += 1

print(n)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()

if len(s) < 4:
    print(0)
else:
    ans = 0
    for window_size in range(4, len(s)+1):
        for step in range(len(s)+1-window_size):
            window = list(s)[step:step+window_size]
            if int("".join(window))%2019 == 0:
                ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import math
s = input()
l = len(s)
cnt = 0
for i in range(l-1):
    for j in range(i+1, l):
        if eval(s[i:j+1]+'/2019') - math.floor(eval(s[i:j+1]+'/2019')) == 0:
            cnt += 1

print(cnt)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:
import itertools
s = input()
n = [i for i in range(len(s))]
num = list(itertools.combinations(n, 2))
ans = 0
for i in num:
    if int(s[i[0]]:i[1]+1) % 2019 == 0:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
num=input()
counter=0
for y in range(len(num)):
  for x in range(y):
    if int(num[x:y])%2019==0 and
      counter=counter+1
print(counter)

Submission status: Runtime Error

Solution code:
import regex

S = str(input())

l = [
    2019,
    4038,
    6057,
    8076,
    10095,
    12114,
    14133,
    16152,
    18171,
    20190,
    22209,
    24228,
    26247,
    28266,
    30285,
    32304,
    34323,
    36342,
    38361,
    40380,
    42399,
    44418,
    46437,
    48456,
    50475,
    52494,
    54513,
    56532,
    58551,
    60570,
    62589,
    64608,
    66627,
    68646,
    70665,
    72684,
    74703,
    76722,
    78741,
    80760,
    82779,
    84798,
    86817,
    88836,
    90855,
    92874,
    94893,
    96912,
    98931,
    100950,
    102969,
    104988,
    107007,
    109026,
    111045,
    113064,
    115083,
    117102,
    119121,
    121140,
    123159,
    125178,
    127197,
    129216,
    131235,
    133254,
    135273,
    137292,
    139311,
    141330,
    143349,
    145368,
    147387,
    149406,
    151425,
    153444,
    155463,
    157482,
    159501,
    161520,
    163539,
    165558,
    167577,
    169596,
    171615,
    173634,
    175653,
    177672,
    179691,
    181710,
    183729,
    185748,
    187767,
    189786,
    191805,
    193824,
    195843,
    197862,
    199881,
]

count = 0
for i in l:
    count += len(regex.findall(str(i), S, overlapped=True))

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a=[]
for i in range(1,100):
    a.append(str(2019*i))
print(a)
cnt=0
for j in a:
    cnt+=S.count(j)

print(cnt)

Submission status: Runtime Error

Solution code:
S_str=str(input())
S=int(S_str[-1])
N=len(S_str)

mod=[0]*2018
mod[0]=1
now=S%2019
mod[now]+=1

for i in range(N-1)[::-1]:
    #print(i+1,S,S%2019)
    next=pow(10,N-1-i,2019)
    next=(next*int(S_str[i]))%2019
    now=(now+next)%2019
    mod[now]+=1

    

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)

Submission status: Runtime Error

Solution code:
x=input()
list = list(map(int, x))

tmp=0
ans=0
for i in range(len(list)-3):
	tmp=(list[i]*1000+list[i+1]*100+list[i+2]*10+list[i+3])%2019
	if tmp==0:
		ans=ans+1
	if i+4<=len(list):
		for j in range(i+4,len(list)):
			if tmp==0:
				tmp=(list[j]*1000+list[j+1]*100+list[j+2]*10+list[j+3])%2019
				j=j+3
			else:
				tmp=(tmp*10+list[j])%2019
			if tmp==0:
				ans=ans+1
				
print(ans)

Submission status: Runtime Error

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

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

print(cnt)

Submission status: Runtime Error

Solution code:
s = input()
cnt = 0

for i in range(len(s)):
    for j in range(i+3, 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()
res=0
l=len(S)
for i in range(l):
    for j in range(i+4,l+1):
        res += 1 if int(S[i:j])%2019==0
print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S=str(input())
n=0
for i in range(len(S)-3):
  m=int(S[i:N-1])
  while len(str(m))>=4:
    if m%2019==0:
      n+=1
    a=m//10
    m-=a*10
print(n)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
s=input()
n=len(s)
s=s[::-1]
accum=[0]*n
p=2019
d=dict()
for i in range(n):
    accum[i]=int(s[i])*pow(10,i,p)%p
for i in range(n-1):
    accum[i+1]+=accum[i]
    accum[i+1]%=p
accum[-1]%=p
ans=0
#print(accum)
for i in range(n):
    #print(d)
    if accum[i] not in d:
        if accum[i]==0:
            ans+=1
        d[accum[i]]=1
    else:
        if accum[i]==0:
            ans+=1
        ans+=d[accum[i]]
        d[accum[i]]+=1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
num=input()
counter=0
for y in range(len(num)):
  for x in range(y):
    if num[x:y]%2019==0:
      counter=counter+1
print(counter)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
inp = input()

s = 0

for i in range(len(inp)-3):
	num = int(inp[i:-1])
    while num >2019:
		if num % 2019 == 0:
			s += 1
		num = num / 10

print(s)

Submission status: Runtime Error

Solution code:
S_str=str(input())
S_list=list(S_str)
S=int(S_list[-1])
N=len(S_str)

mod=[0]*2018
mod[0]=1
now=S%2019
mod[now]+=1

for i in range(N-1)[::-1]:
    #print(i+1,S,S%2019)
    next=pow(10,N-1-i,2019)
    next=(next*int(S_list[i]))%2019
    now=(now+next)%2019
    mod[now]+=1

    

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=input()
slen=len(s)
count=0
list=[]
for i in range(1e+14):
  a=str(2019*i)
  if "0" not in a:
    list.append(a)
for i in range(slen-3):
  for j in range(i+3,slen):
    if s[i:j+1] in list:
      count+=1
print(count)