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
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(440000):
    if bool (toString(2019*(i+1)) in toString(num_s) ):
        count += 1
    
print(count)

Submission status: Runtime Error

Solution code:
s = input()
num = ['2019', '4038', '6057', '8076', '10095', '12114', '14133', '16152', '18171']
ans = 0
for n in num:
    a += s.count(n)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

def np_combinations(arr):
    r, c = np.triu_indices(len(arr), 1)
    return np.stack((arr[r], arr[c]), 1)

s = input()

a = np.append(0, np.cumsum(np.array(list(s), dtype=np.int64))%3)
x = np_combinations(np.where(a==0)[0])
y = np_combinations(np.where(a==1)[0])
z = np_combinations(np.where(a==2)[0])

ans = 0
for k in x:
    i, j = k
    if i+3 > j:
        continue
    if s[i] == '0':
        continue
    if eval(s[i:j] + " % 2019") == 0:
            ans += 1
for k in y:
    i, j = k
    if i+3 > j:
        continue
    if s[i] == '0':
        continue
    if eval(s[i:j] + " % 2019") == 0:
            ans += 1
for k in z:
    i, j = k
    if i+3 > j:
        continue
    if s[i] == '0':
        continue
    if eval(s[i:j] + " % 2019") == 0:
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


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

            ans += 1
    print(ans)
    return


# Solve
if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
count = 0
for x in range(input()):
    if int(x) % 2019:
        count +=1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

s = str(int(input()))
leng = len(s)


if leng <4:
    ans = 0
else:
    cout = np.zeros(len(s))
    rest = leng - 4
    
    if int(s[leng-4:leng])%2019 == 0:
        cout[3] = 1
    if leng ==4:
        ans = cout[3]
    else:
        for j in range(4,leng):
            add = 0
            for i in range(4,j+2):
                check = s[leng-j-1:leng-j-1+i]

                if int(check)%2019 == 0:
                    add = 1 + (cout[j-i] -  cout[int(abs(j-i-1))])
            cout[j] = cout[j-1] + add
    


ans = int(cout[-1])

print(ans)

Submission status: Runtime Error

Solution code:
S = input()
r, ans = 3, 0
for l in range(len(S)):
    while r < len(S):
        if int(S[0:l]) % 2019 == 0:
            ans += 1
            break
        if int(S[l:r+1]) % 2019 == 0:
            ans += 1
            break
        if int(S[r+1:len(S)]) % 2019 == 0:
            ans += 1
            break
        r += 1
    r = l + 3
print(ans)

Submission status: Runtime Error

Solution code:
import math
s = input()
S = int(s)
ans = 0
p = 0

for i in range(1,len(s)+1):
	for j in range(0,i-1):
		p = math.floor((S - pow(10,i)*math.floor(S/pow(10,i)))/pow(10,j))
		if p % 2019 == 0:
			ans += 1
		p = 0
print(ans)

Submission status: Runtime Error

Solution code:
import functools
def solve():
    s = int(input())

    t = [int(x) for x in list(str(s))]

    cnt = 0
    n= len(t)
    for i in range(n):
        new = int(functools.reduce(lambda x, y: x + y, [str(x) for x in t]))
        if new%2019 ==0:
            cnt += 1
        t.remove([-1])

    return cnt
    
print(solve())

Submission status: Runtime Error

Solution code:
from math import ceil #切り上げ
import numpy as np

def inp(): return int(input()) #一個だけ読み取り
def inpm(): return map(int,input().split()) #mapオブジェクトで呼び出し
def inpl(): return list(map(int, input().split())) #数字リストをintで
def inpls(): return list(input().split()) #リストをstrで

def judge(n):
  return True if n%3==0 else False
  
S = input()
l = len(S)
ok_list = []
cnt = 0

if l <= 4:
  print("0")
else:
  for i in range(0,l):
    sum = []
    for j in range(0,l):
      if i==j:
        sum.append(int(S[j]))
      elif j<i:
        sum.append(1)
      else:
        sum.append(sum[j-1]+int(S[j]))
    	sum_c = list(map(judge,sum))
    	try:
    		ok_list.append([i,sum_c.index(True)+1])
    	except:
        	pass
      

    	for i,j in ok_list:
      		ss = int(S[i:j])
      		if ss%673 == 0:
        		cnt = cnt +1
      		else:
        		pass

	print(cnt)

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


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

                print(i, j)
                ans += 1
    print(ans)
    return


# Solve
if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
import math

s = input()
count = 0

lst = []
for i in range(len(s)):
    lst.append(int(s[(-i- 1):])%2019)
count += lst.count(0)
a = [x for x in set(l) if lst.count(x) > 1]
for j in a:
    b = lst.count(j)
    c = math.factorial(b)/math.factorial(2)/math.factorial(b-2)
    count += c

print(count)

Submission status: Runtime Error

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

def count_all(text, part):
    t = sum(1 for x in range(len(text)) if text[x:].startswith(part))
    return t

S = input()
I = 2019
count = 0

while I < 200000:
    if '0' in str(I)
        continue
    count += count_all(S,str(I))
    I += 2019
print(count)

Submission status: Runtime Error

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

c=0

def check2019(S):
    global c
    global d
    s = int(S)
    if s%2019 ==0:
        c +=1
    else:
        pass
    if s>10000:
            return check2019(S[1:])
    else:
        return 0
S = input()


for i in range(len(S)-3):
    check2019(S[:-i])

else:
    pass
if i == 0 and c >0:
    c-=1
print(c)

Submission status: Runtime Error

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

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

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(int(count+count2))

Submission status: Runtime Error

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

ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
S = input()
r, ans = 3, 0
for l in range(len(S)):
    while r < len(S):
        if int(S[0:l]) % 2019 == 0:
            ans += 1
            break
        if int(S[l:r+1]) % 2019 == 0:
            ans += 1
            break
        if int(S[r+1:len(S)) % 2019 == 0:
            ans += 1
            break
        r += 1
    r = l + 3
print(ans)

Submission status: Runtime Error

Solution code:
N = list(input())

n = len(N)
cnt = 0

for i in range(n-3):
    for j in range(n-i):
            joint = ''.join(N[i:n-i-j])  
            if int(joint)%2019 == 0:      
                 cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
S = input()
answer = 0
for i in range(int(S)//2019 + 1):
    f = 2019 * i
    if f in S:
        answer += 1

print(answer)

Submission status: Runtime Error

Solution code:
ans=0
def occurrences(string, sub):
    count = start = 0
    while True:
        start = string.find(sub, start) + 1
        if start > 0:
            count+=1
        else:
            return count

for i in range(199997):
    ans+= occurrences(S,str(2019*(i+1)))
print(ans)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
	S = input()
	LEN = len(S)
	r = LEN
	l = LEN-1
	count = 0
	lst = []
	amari = 0
	while(l >= 0):
		amari = (amari + S[l]*10**(l-1)%2019)%2019
		
		if amari in lst:
			count += 1
		elif amari == 0:
			count += 1
			lst.append(count)
		else:
			lst.append(amari)
		l -= 1

	print(count)

Submission status: Runtime Error

Solution code:
s = input()

ans = 0
i = 0
flag = 0
while i < len(s) - 4:
    flag = 0
    for j in range(i + 5, i + 10):
        sub = int(s[i:j])
        if sub % 2019 == 0:
            ds = len(s) // len(sub)
            ans += ds
            flag = 1
            break
    if flag == 1:
        i = j - 1
    else:
        i += 1
    

print(ans)

Submission status: Runtime Error

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

def main():
    s=input()
    #cnt=0
    k=list(s)
    d=[0]*2019
    for i in range(len(k)):
        d[int(s[i:])%2019]+=1
    
    cnt=d[0]
    for i in range(2019):
        cnt+=d[i]*(d[i]-1)//2
            #print(s[i:j+1])
    print(cnt)
    #print(d)
main()

Submission status: Runtime Error

Solution code:
s = input('')
max_s = int(int(s)/2019)
rec = 0
for m in range(max_s+1):
    ms=str(2019*m)
    if not '0' in ms:
        idx=s.find(ms)
        while idx >= 0:
            rec+=1
            idx=s.find(ms,idx+1)
#            print("{} {}".format(ms,idx))
print(rec)

Submission status: Runtime Error

Solution code:
cnt = 0
ans = []
for i in range(0, len(s) - 3):
    j = i
    num = ''
    while j < len(s):
        juhuku = 0
        num += s[j]
        if int(num) % 2019 == 0 and num != '0':
            print(i, j)
            if j not in ans:
                ans.append(j)
            juhuku = ans.count(i - 1)
            cnt += 1 + juhuku
        j += 1
cnt, ans

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

def np_combinations(arr):
    r, c = np.triu_indices(len(arr), 1)
    return np.stack((arr[r], arr[c]), 1)

s = input()

a = np.append(0, np.cumsum(np.array(list(s), dtype=np.int64))%3)
x = np_combinations(np.where(a==0)[0])
y = np_combinations(np.where(a==1)[0])
z = np_combinations(np.where(a==2)[0])

ans = 0
for k in x:
    i, j = k
    if i+3 > j:
        continue
    if s[i] == '0':
        continue
    if eval(s[i:j] + " % 2019") == 0:
            ans += 1
for k in y:
    i, j = k
    if i+3 > j:
        continue
    if s[i] == '0':
        continue
    if eval(s[i:j] + " % 2019") == 0:
            ans += 1
for k in z:
    i, j = k
    if i+3 > j:
        continue
    if s[i] == '0':
        continue
    if eval(s[i:j] + " % 2019") == 0:
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
#D
S = str(input())
dict = {}
cnt = 0
tot = 0

sum = {}
sum[0] = 0
for i in range(len(S)):
    tot += int(S[i])
    sum[i+1] = tot
#print(sum)


for i in range(len(S)-3):
    for j in range(i+3, len(S)):
        if (sum[j+1]-sum[i])%3 == 0:
                dict[S[i:j+1]] += 1

for ele in dict:
    if int(ele)%2019 == 0:
        cnt += dict[ele]
#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:
a = input()
i = 0
j = 0
l = len(a)
ans = []
while True:
    while j < l:

        s = int(a[i:j])
        

        if s%2019 == 0:
            ans.append(s)

        j += 1
    i += 1
    if i < l:
        print(ans)
        break

Submission status: Runtime Error

Solution code:
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

S = input()
N = int(S)
lenS = len(S)
num = 2019

dp = [[0]*2020 for _ in range(lenS)]
dp[0][0] = 1
dp[3][int(S[0:3])] = 1
dp[3][int(S[1:3])] = 1
dp[3][int(S[2:3])] = 1

for i in range(3, lenS-1):
    moji = int(S[i])
    dp[i+1][moji] += 1
    for j in range(2019):
        dp[i+1][(j*10 + moji)%2019] += dp[i][j]
#pri(dp)

cnt = 0 
for i in range(3, lenS):
    cnt += dp[i][0]
print(cnt+1)

Submission status: Runtime Error

Solution code:
import math

s = input()
count = 0

lst = []
for i in range(len(s)):
    lst.append(int(s[(-i- 1):])%2019)
lst.count(0)
a = [x for x in set(l) if lst.count(x) > 1]
for j in a:
    b = lst.count(j)
    c = math.factorial(b)/math.factorial(2)/math.factorial(b-2)
    count += c

print(count)

Submission status: Runtime Error

Solution code:
s = input()
s_l = len(s)
si = int(s)
r = 0
a = 2019
while n <= 200000:
    if si < 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
        elif s[i - 1:i + a_l - 1] == a_s:
            r += 1
    a += 2019
print(r)

Submission status: Runtime Error

Solution code:
def main():
    s = input()
    s_len = len(s)
    count = 0

    for i in range(0, s_len - 2):
        for j in range(i+4, s_len+1):
            diff = j - i
            if diff < 4 or 6 < diff:
                continue
            if int(eval_str) > 200000:
                continue
            eval_str = s[i:j:]
            if int(eval_str) % 2019 == 0:
                count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    S = list(map(str,input().rstrip()))
    l = len(S)
    result=0   
    
    for i in range(l):
        for j in range(1,l-i+1):
            print(S[i,i+j+1])
            n = int("".join(map(str, St)))
            print(S)
            if n %2019==0:
                result+=1
    print(result)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
a = [int(c) for c in s]

x=()
y=()
count = 0

b=0
b=(1000*a[0]+100*a[0+1]+10*a[2]+a[3])%2019
for j in range(4,len(a)):
    if b==0:
        count +=1
        y.append(j-1)
    b = (b*10 + a[j])%2019
ans=0
for i in range(count):
    ans+=i
print(ans)

Submission status: Runtime Error

Solution code:

N = int(input())

N = str(N)

a = 0

for i in range(N-3):
    for j in range(N):

# 候補が１つ見つかればいいので、if文で脱出するルールを作る
        n = N[i:j]
            if n % 2019 == 0 :
                a += 1
    print(a)

Submission status: Runtime Error

Solution code:
s=input()

ans=0
dd=[]

fir=int(s[0])*1000+int(s[1])*100+int(s[2])*10+int(s[3])
dd.append(fir%673)
for i in range(4,len(s)):
    tmp=(dd[i-4]*10+int(s[i]))%673
    dd.append(tmp)

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

bit=Bit(len(dd))
for i in range(1,len(dd)+1):
    bit.add(i,dd[i-1])
#print(dd)
for i in range(1,len(dd)):
    for j in range(i+1,len(dd)+1):
        if (bit.sum(j)-bit.sum(i))%673==0 and (bit.sum(j)-bit.sum(i))%3==0 :
            ans+=1


print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
s = input()
l = np.array([s[i:j] for i in range(0,len(s)-3) for j in range(j+4,len(s)+1)])
p = l % 2019
print(p.count(0))

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(450000):
    if bool (toString(2019*i) in toString(num_s) ):
        count += 1
    
print(count)

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)
        new_int_s = int_s[:-4] + [int(c) for c in str(subb)]
        checker(new_s, n-1, new_int_s)
    

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 = input()
ans = 0
l = []
r = len(s)

for i in range(1, r):
    for j in range(i, r):
        num = s[0:j]
        l.append(num)
        l_i = [int(p) for p in l]

for k in l_i:
    if k % 2019 == 0:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
from collections import defaultdict
D = defaultdict(int)
p=input()
s=list(p)
d=deque()
d.append(p)
n=len(s)
D[0]=0
if n<5:
    print(0)
else:

    x=int(p[0:5])%2019
    D[x]+=1
    for i in range(5,n):
        x=(10*x+int(d.popleft))%2019
        D[x]+=1
    m=D[0]
    for i in D.values():
        m+=i-1
print(m)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
ans = 1
r, l = 3, 0
while l < n:
    if int(s[l:r+2]) % 2019:
        if r < n-1:
            r += 1
        else:
            l += 1
            r = l + 4
    elif int(s[l:r+2]) % 2019 ==0:
        ans += 1
        l += r
if ans != 1:
    print(ans)
else:
    print(0)

Submission status: Runtime Error

Solution code:
s=input()
cnt=0
l=[i for i in i%2019==0]
print(s.count(l))

Submission status: Runtime Error

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

def main():
    str = input()
    n = len(str)
    dp = [-1 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:
import re
import sys

s = sys.stdin.buffer.readline().rstrip().decode()
ans = 0

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

Submission status: Runtime Error

Solution code:
S = int(input())
L = len(str(S))
SS = str(S)

def calc2(start):
    i = 4
    ct = 0
    while start + i < L:
        # print('S', S, start, i, S[start,i])
        if int(SS[start:i]) % 2019 == 0:
            ct += 1
        i += 1
    return ct


# l = 4
count = 0
start = 0
while start + 4 <= L:
    count += calc2(start)
    start += 1
print(count)

Submission status: Runtime Error

Solution code:
S = input()
answer = 0
for i in range(int(int(S))//2019 + 1):
    f = 2019 * i
    if f in S:
        answer += 1

print(answer)

Submission status: Runtime Error

Solution code:
import math
s = input()
S = int(s)
ans = 0
p = 0

for i in range(1,len(s)+1):
    for j in range(0,i-1):
        p = math.floor((S - pow(10,i)*math.floor(S/pow(10,i)))/pow(10,j))
        if p % 2019 == 0:
            ans += 1
        p = 0
print(ans)

Submission status: Runtime Error

Solution code:
def count1(st):
  if len(st)<4:
    return 0
  else:
    st2=st[:-1]
    co1=count1(st2)
    co2=count2(st)
    return co1+co2
  
def count2(st):
  if len(st)<4:
    return 0
  else:
    st3=st[1:]
    co3=count2(st3)
    if int(st)%2019==0:
      return co3+1
    else:
      return co3

a=input()
print(count1(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = int(input())
s = str(S)
N = len(s)
count = 0
list = ['s' for _ in range(int((N+1)*N/2))]

for i in range(N):
  for j in range(N-i):
    list[i + N - (j-1)] += s[i + (j - 1)] 
ln = len(list)
listN = [None for _ in range(ln)]
for i in range(ln):
  listN[i] = int(list[i])
  if listN[i] % 2019 == 0:
    count += 1
print(count)
   
"""  
for i in range(N):
  list[i] = s[i+0]
for i in range(N-1):
  list[i+N] = s[i+0]+s[i+1]
for i in range(N-2):
  list[i+N+(N-1)] = s[i+0]+s[i+1]+s[i+2]
ln = len(list)
listN = [None for _ in range(ln)]
for i in range(ln):
  listN[i] = int(list[i])
  if listN[i] % 3 == 0:
    count += 1
print(listN)
print(count)
"""

Submission status: Runtime Error

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

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:
S = input()
answer = 0
for i in range(-int(-int(S))//2019):
    f = 2019 * i
    if f in S:
        answer += 1
        
print(answer)

Submission status: Runtime Error

Solution code:
S = str(input())
p = 0
for i in range(0, int(S), 2019):
    p += S.count(i)
print(p)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
s = input()
l = np.array([s[i:j] for i in range(0.len(s)-3) forj in range(j+4,len(s)+1)])
p = l % 2019
print(p.count(0))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
s = input()
n = len(s)
ans = 0
cs = [0] * (n + 1)
cs[1] = cs[0] + int(s[0])
cs[2] = cs[1] + int(s[1])
cs[3] = cs[2] + int(s[2])
for i in range(n):
    for j in range(i + 3, n + 1):
        if i == 0 and j < n:
            cs[j + 1] = cs[j] + int(s[j])
        if (cs[j] - cs[i]) % 3 != 0:
            continue
        k = int(s[i:j])
        if k % 2019 == 0:
            ans += 1
print(ans)

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:
x=int(input())
count=0
n=len(x)
for i in range n:
  a=x%(10**i)
  for j in range n:
    b=a//(10**j)
    if b!=0 and b%2019==0:
      count=count+1
print(count)

Submission status: Runtime Error

Solution code:
S = str(int(input()))
n = 0
lst = []
output = 0
while True :
    if n <= len(S) - 5 :
      	for i in range(0,len(S)+1):
        	lst.append(S[i:i+5])
        n += 1
    else :
        break
for i in lst :
    if int(i) % 2019 == 0 :
        output += 1
print(output)

Submission status: Runtime Error

Solution code:
def dfs(str, dp,n, x):
    if x>=n:
        return 0
    if dp[x]!=0:
        return dp[x]
    dig=0
    for i in range(x, n):
        num=int(str[i])
        dig=dig*10+num
        if dig%2019==0:
            dp[x]=dfs(str, dp, n, i+1)+1
            return dp[x]
        else:
            dig=dig%2019
    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:
#D Multiple of 2019

s = input()
n = len(s)
cnt = 0
seq = [2019,4038,6057,8076,10095,12114,14133,16152,18171]

for i in seq:
    if i in s:
        cnt += 1 

print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np

def np_combinations(arr):
    r, c = np.triu_indices(len(arr), 1)
    return np.stack((arr[r], arr[c]), 1)

s = input()

a = np.append(0, np.cumsum(np.array(list(s), dtype=np.int64))%3)
x = np_combinations(np.where(a==0)[0])
y = np_combinations(np.where(a==1)[0])
z = np_combinations(np.where(a==2)[0])

ans = 0
for k in x:
    i, j = k
    if i+3 > j:
        continue
    if eval(s[i:j] + " % 2019") == 0:
            ans += 1
for k in y:
    i, j = k
    if i+3 > j:
        continue
    if eval(s[i:j] + " % 2019") == 0:
            ans += 1
for k in z:
    i, j = k
    if i+3 > j:
        continue
    if eval(s[i:j] + " % 2019") == 0:
            ans += 1

print(ans)

Submission status: Runtime Error

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

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

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 countDivisibleSubseq(str, n): 
    l = len(str)  
    dp = [[0 for x in range(l)] 
             for y in range(n)] 
    dp[0][(ord(str[0]) - ord('0')) % n] += 1
  
    for i in range(1, l): 
        dp[i][(ord(str[i]) - ord('0')) % n] += 1
  
        for j in range(n): 
            dp[i][j] += dp[i - 1][j] 
            dp[i][(j * 10 + (ord(str[i]) - 
                             ord('0'))) % n] += dp[i - 1][j] 
  
    return dp[l - 1][0]

if __name__=='__main__':
    S = input()
    countDivisibleSubseq(S,2019)

Submission status: Runtime Error

Solution code:
a = int(input())

for i in list(str(a)):
  for i in range(len(str(b))):
    print(b)
    if a % 2019 == 0:
      print("ok")
      print(b)
    b = b / 10
    b = int(b)

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import deque
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(n, nn):
  global ans
  if len(edge[n]) == 0:
    if nn <= 1:
      pass
    else:
      ans += 1
  else:
    for x in edge[n]:
      tami(x, nn+1)

s = S()
N = len(s)

data = [[] for i in range(10)]
ID = []

for i in range(1,1000):
  if i*2019 >= 200010:
    break
  else:
    tmp = str(i*2019)
    data[int(tmp[0])].append(tmp)

i = -1
while i != N:
  i += 1
  for j in range(i+1, N+1):
    num = s[i:j]
    f = 0
    for k in data[int(num[0])]:
      if k == num:
        ID.append((i,j))
        i = j - 1
        break
      elif k[:j-i] == num:
        f = 1
    else:
      if f == 1:
        continue
      else:
        break
#print(ID)

"""
dd = []
cnt = 1
if len(ID) == 0:
  pass
else:
  for i in range(len(ID)-1):
    if ID[i][1] +1 == ID[i+1][0]:
      cnt += 1
    else:
      dd.append(cnt)
      cnt = 1
  else:
      dd.append(cnt)
print(dd)
"""

ans = 0
edge = [[] for i in range(20010)]
for i,j in ID:
  edge[i].append(j)

for i in range(20010):
  if len(edge[i]) == 0:
    continue
  else:
    tami(i, 0)
print(ans + len(ID))

"""
201920192019
"""

Submission status: Runtime Error

Solution code:
S =input()
answer = 0
for i in range(0,N-3):
         for j in range(4,N+1):
            N ="".join(S[i:j])
            if int(N)%2019 == 0:
                answer +=1
print(answer)

Submission status: Runtime Error

Solution code:
S=str(input())
n=len(S)
u=0
for i in range(n):
    a=int(S[i])
    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:
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
        y+=1
    if int(s[i:i+5])%2019==0 and not(i=n-4):
        pe[i+4]+=pe[i]+1
        y+=1
    if y>=1:
        pe[i]=0 
    y=0
print(sum(pe))