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 -*-
"""
Created on Sun Apr 26 22:28:26 2020

@author: Kanaru Sato
"""

s = input()
n = len(s)
dic = {}
mod = 2019
count = 0

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

ans = 0
for fact in dic:
    if fact != 0:
        ans += dic[fact]*(dic[fact]-1)/2

print(int(ans)+dic[0])

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
m = 2019
a = 0
r = [0 for _ in range(m+1)]
r[0] = 1
for i in range(0,n):
    z = (int(s[n-i-1])*pow(10,i,m) + z)%m
    a += r[z]
    r[z] += 1
print(a)

Submission status: Runtime Error

Solution code:
S = str(input())

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

Submission status: Runtime Error

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

c=0
d=0
def check2019(S, n):
    global c
    global d
    s = int(S)
    if s%2019 ==0　and s >2018:
        c +=1
    else:
        pass
    if s>9999:
        if n ==0:
            return check2019(S[1:],1), check2019(S[:-1], 0)
        else:
            return check2019(S[1:],1)
    else:
        return 0
S = input()


if len(S) >= 4:
    check2019(S, 0)
else:
    pass
print(c)

Submission status: Runtime Error

Solution code:
from sys import stdin


def get_result(data):
    S = data[0]
    int_S = int(S)
    mod_all_bit = [0] * 2018
    mod_all_bit[0] = 1
    for i in range(len(S)):
        _, mod = divmod(int_S % (10**(i+1)), 2019)
        mod_all_bit[mod] += 1
    ans = 0
    for val in mod_all_bit:
        if val >= 2:
            ans += val * (val-1) * 0.5
    return int(ans)


if __name__ == '__main__':
    data = list(map(str, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

Submission status: Runtime Error

Solution code:
S=input()
N=len(S)
if N<5:
  print(0)
  exit()
A={}
for i in range(N-4+1):
  a=int(S[i:])%2019
  A.setdefault(a,0)
  A[a]+=1

ans=0
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

for i in A.values():
  if i>1:
    ans+=cmb(i,2)
ans+=A[0]
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin


def get_result(data):
    S = data[0]
    int_S = int(S)
    mod_all_bit = [0] * 2018
    mod_all_bit[0] = 1
    for i in range(len(S)):
        mod = int_S % (10**(i+1)) % 2019
        mod_all_bit[mod] += 1
    ans = 0
    for val in mod_all_bit:
        if val >= 2:
            ans += val * (val-1) * 0.5
    return int(ans)


if __name__ == '__main__':
    data = list(map(str, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

Submission status: Runtime Error

Solution code:
S=input()
N=len(S)
if N<5:
  print(0)
  exit()
A={}
for i in range(N-4+1):
  a=int(S[i:])%2019
  A.setdefault(a,0)
  A[a]+=1

ans=0
import math
def comb(n,r):
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
for i in A.values():
  if i>1:
    ans+=comb(i,2)
ans+=A[0]
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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


modul = np.ones(n)

modul[0] = int(s[-1]) % 2019


if n>1: 
    dig = 1
    for i in range(1,n):
        dig = dig*10 %2019
        modul[i] = (modul[i-1] + int(s[n-1-i])*(dig))%2019
        
dic = {}

for i in range(n):
    if dic.get(modul[i]) is None:
        dic[modul[i]] = 1
    else:
        dic[modul[i]] += 1
dic[0] +=1        
ans = 0
for i in list(dic.values()):
    ans += i*(i-1)/2
    
print(int(ans))

Submission status: Runtime Error

Solution code:
def main(S=None):
    if not S:
        S = input()
    r = [0]*2019
    r[0] = 1
    tmp = 0
    base = 1
    for s in S[::-1]:
        s = int(s) * base
        base *= 10
        # base %= 2019
        tmp += s
        # tmp %= 2019
        r[tmp] += 1
    count = 0
    for v in r:
        count += v*(v-1)//2
    print(count)
    return count


if __name__ == "__main__":
    # assert main("1817181712114") == 3
    # assert main("14282668646") == 2
    # assert main("2119") == 0
    main()

Submission status: Runtime Error

Solution code:
mod=2019
n=1
A=[1]
for k in range(1, 400):
    n=n*10%mod
    if n in A:
        break
    else:
        A.append(n)
S=input()
count=0
B=[0]
B.append(int(S[-1]))
if len(S)>3:
    for k in range(2,len(S)+1):
        B.append((B[-1]+int(S[-k])*A[k-1])%mod)
    for k in range(len(B)-1):
        for j in range(k+1,len(B)):
            if B[k] == B[j]:
                count+=1
print(count)

Submission status: Runtime Error

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

@author: Kanaru Sato
"""

s = input()
n = len(s)
s = list(s)
dic = {}
mod = 2019
count = 0

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

if 0 in dic:
    count += 1

print(count)

Submission status: Runtime Error

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

dp = [0]*num
temp = [0]*2019
for i in range(num):
    temp[i] += 1

ans = temp[0]
for t in temp:
    if t > 1:
        ans += t*(t-1)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
def lengthcal(length):
    if length == 4:
        return cal(4,0)
    else:
        return lengthcal(length-1) + cal(length,0)

def cal(length,index):
    if index == totallength - length:
        if int(str[index:index+length]) %2019 ==0:
            return 1
        else:
            return 0
    else:
        if int(str[index:index+length]) %2019 ==0:
            tmp = 1
        else:
            tmp = 0
        return cal(length,index+1) +tmp
str = input()
totallength = len(str)
result = lengthcal(totallength)
print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
c
ount = 0
for i in range(N):
    for j in range(i,N):
        if int(S[i:j+1]) % 2019 == 0:
            count = count + 1
        else:
            continue
print(count)

Submission status: Runtime Error

Solution code:
S = input()
cnt = 0
for i in range(int(S)//2019+1):
  cnt += sum([1 for j in range(len(S)-len(str(2019*(i+1)))+1) \
             if S[j:j+len(str(2019*(i+1)))]==str(2019*(i+1))) 
print(cnt)

Submission status: Runtime Error

Solution code:
def lengthcal(length):
    if length == 4:
        return cal(4)
    else:
        return lengthcal(length-1) + cal(length,0)

def cal(length,index):
    if index == totallength - length:
        if int(str[index:index+length]) %2019 ==0:
            return 1
        else:
            return 0
    else:
        if int(str[index:index+length]) %2019 ==0:
            tmp = 1
        else:
            tmp = 0
        return cal(length,index+1) +tmp
str = input()
totallength = len(str)
result = lengthcal(totallength)
print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S=str(input())
#S=str(1817181712114)
ans=0
num=[i for i in range(2019,2019*100,2019)] 

for i in range(len(S)+1):
    for k in range(i+len(str(j))-1, len(S)+1):
        if int(S[i:k]) in num:
            ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
MOD =2019
count = [0]*MOD
r = 0
t = 1
for i in reversed(S):
    r += int(i) * t
    r %= MOD
    t *= 10
    t %= MOD
    count[r] += 1

d[0] += 1
print(sum(i*(i-1)/2 for i in count))

Submission status: Runtime Error

Solution code:
S = input()
MOD =2019
count = [0]*MOD
r = 0
t = 1
for i in reversed(S):
    r += int(i) * t
    r %= MOD
    t *= 10
    t %= MOD
    d[r] += 1

d[0] += 1
print(sum(i*(i-1)/2 for i in count))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

n,m,s=l_in()

uvab=[]
edges = [[] for _ in range(n)]
for _ in range(m):
    u,v,a,b = l_in()
    edges[u-1].append((v-1,a,b))
    edges[v-1].append((u-1,a,b))

cd = [l_in() for _ in range(n)]

# dp[i][g] city i で g まいの銀貨をもつための最小時間
m = 101
#m = 4
dp = [[-1]*m for _ in range(n)]


from heapq import heappush,heappop
h = []

for g in range(min(s+1,m+3)):
    heappush(h, (0,-g,0))

while len(h) > 0:
    t,g,i = h[0]
    g = -g
#    print("t,g,i", t,g,i)
    # 
    heappop(h)

    if dp[i][min(g,m-1)] != -1:
        dp[i][min(g,m-1)] = min(t, dp[i][min(g,m-1)])
    else:
        dp[i][min(g,m-1)] = t
    
    for v,a,b in edges[i]:
        if g-a >= 0 and dp[v][min(g-a,m-1)] == -1:
            heappush(h,(t+b,-(g-a),v))
#            print("push", t+b,-g+a,v)

    c,d = cd[i]
    if dp[i][min(g+c,m-1)] == -1:
        heappush(h,(t+d,-(g+c),i))

for d in dp:
    pass
#    print(d)


for i in range(1, n):
    res = -1
    for v,a,b in edges[i]:
        min_t = -1
        for g in range(a,m):
            t = dp[v][g]
            if t == -1:
                continue
            if min_t == -1 or min_t > t:
                min_t = t
#                print("min_t", v,g,min_t)

        if res == -1 or res > min_t+b:
            res = min_t+b

#    print(dp[i])
    for t in dp[i]:
        if t == -1:
            continue
        if res == -1  or t < res:
            continue
            res = t
            
    print(res)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
S = input()
N = len(S)

D=defaultdict()
prev=0
ans=0
for i,s in enumerate(reversed(S)):
    cur=prev+pow(10,i,2019)*int(s)%2019
    ans+=D[cur]
    D[cur]+=1
    prev=cur
print(ans)

Submission status: Runtime Error

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

m = 2019
n = len(S)

f = 0

p = 1

X = [0] * 2019

X[0] = 1

q = 0

for a in S:
    f = (f + a * p) % m
    q += X[f]
    
    X[s] += 1
    
    p = p * 10 % m
 

print(q)

Submission status: Runtime Error

Solution code:
S = input()
l = len(S)
noCount = 0
fourDigi = {'2019', '4038', '6057', '8076'}
fiveDigi = {'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'}
fiveD2nd = {'0','2','4','6','8'}
sixDigi = {'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 j in range(1,l):
    for k in range(l - j + 1):
        segment = str(int(S[k:k + j]))
        if segment % 2019 == 0:
            noCount += 1
 
print(noCount)

Submission status: Runtime Error

Solution code:
S = input()
l = len(S)
noCount = 0
fourDigi = {'2019', '4038', '6057', '8076'}
fiveDigi = {'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'}
fiveD2nd = {'0','2','4','6','8'}
sixDigi = {'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'}
# if l == 4:
#     for i in range(l-3):
#         if S[i:i+4] in fourDigi:
#             noCount += 1
# elif l == 5:
#     for i in range(l-3):
#         if S[i:i+4] in fourDigi:
#             noCount += 1
#     for i in range(l-4):
#         if S[i+1] in fiveD2nd:
#             if S[i:i+5] in fiveDigi:
#                 noCount += 1
# elif l >= 6:
#     for i in range(l-3):
#         if S[i:i+4] in fourDigi:
#             noCount += 1
#
#     for i in range(l-4):
#         if S[i:i+5] in fiveDigi:
#             noCount += 1
#         elif str(int(S[i:i+5])) in fourDigi:
#             noCount += 1
#
#     for i in range(l-5):
#         if S[i] == 1:
#             if S[i:i+6] in sixDigi:
#                 noCount += 1
#         elif S[i] == 0:
#             if str(int(S[i:i+6])) in fiveDigi:
#                 noCount += 1
#             elif str(int(S[i:i+6])) in fourDigi:
#                 noCount += 1
if l >= 4:
    for j in range(4,l):
        for k in range(l - j + 1):
            segment = str(int(S[k:k + j]))
            if segment%2019==0:
                    noCount += 1

print(noCount)

Submission status: Runtime Error

Solution code:
S = input()
l = len(S)
noCount = 0
fourDigi = {'2019', '4038', '6057', '8076'}
fiveDigi = {'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'}
fiveD2nd = {'0','2','4','6','8'}
sixDigi = {'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'}
# if l == 4:
#     for i in range(l-3):
#         if S[i:i+4] in fourDigi:
#             noCount += 1
# elif l == 5:
#     for i in range(l-3):
#         if S[i:i+4] in fourDigi:
#             noCount += 1
#     for i in range(l-4):
#         if S[i+1] in fiveD2nd:
#             if S[i:i+5] in fiveDigi:
#                 noCount += 1
# elif l >= 6:
#     for i in range(l-3):
#         if S[i:i+4] in fourDigi:
#             noCount += 1
#
#     for i in range(l-4):
#         if S[i:i+5] in fiveDigi:
#             noCount += 1
#         elif str(int(S[i:i+5])) in fourDigi:
#             noCount += 1
#
#     for i in range(l-5):
#         if S[i] == 1:
#             if S[i:i+6] in sixDigi:
#                 noCount += 1
#         elif S[i] == 0:
#             if str(int(S[i:i+6])) in fiveDigi:
#                 noCount += 1
#             elif str(int(S[i:i+6])) in fourDigi:
#                 noCount += 1
if l >= 4:
    for j in range(4,l):
        for k in range(l - j + 1):
            segment = str(int(S[k:k + j]))
            if segment%2019:
                    noCount += 1

print(noCount)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    s = input()

    ans_list = []
    """
    for i in range(len(s)):
        jump = 4
        start = 0
        for j in range(0, len(s)):

            start = start
            end = start + j

            if start >= end:
                continue

            print(start, end)
            int_s = int(s[start:end])

            if int_s % 2019 == 0:
                ans_list.append((start, end))

            jump += 1
    """

    count = 0
    if len(s) < 5:
        if int(s) % 2019 == 0:
            print("1")
            exit()
        else:
            print("0")
            exit()

    for i in range(0, 5):
        for j in range(4, len(s)):

            one_num = int(s[i])
            if j == 4:
                if one_num in (1, 3, 5, 6, 7, 9):
                    continue


            for k in range(0, len(s), j):
                start = i + k
                end = start + j

                if end >= len(s):
                    continue

                # print(start, end)
                int_s = int(s[start:end])

                if int_s % 2019 == 0:
                    count += 1
    print(count)



if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

dp = [0]*N
if N < 4:
    print(0)
    exit(0)

ans = 0

D = [0]*2019
D[0] = 1
for i in range(1, N):
    D[i] = D[i-1]*10 % 2019
t = collections.defaultdict(int)
tmp = 0
t[0] += 1
for i in range(N):
    tmp += S[N-1-i]*D[i]
    tmp %= 2019
    t[tmp] += 1

for x in t:
    ans += t[x]*(t[x]-1) // 2

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

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    s = input()

    ans_list = []
    """
    for i in range(len(s)):
        jump = 4
        start = 0
        for j in range(0, len(s)):

            start = start
            end = start + j

            if start >= end:
                continue

            print(start, end)
            int_s = int(s[start:end])

            if int_s % 2019 == 0:
                ans_list.append((start, end))

            jump += 1
    """

    count = 0
    for i in range(0, 5):
        for j in range(4, len(s)):
            if i // j >= 2:
                continue
            one_num = int(s[i])
            if j == 4:
                if one_num in (1, 3, 5, 6, 7, 9):
                    continue


            for k in range(0, len(s), j):
                start = i + k
                end = start + j

                if end >= len(s):
                    continue

                # print(start, end)
                int_s = int(s[start:end])

                if int_s % 2019 == 0:
                    count += 1
    print(count)



if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
from collections import Counter
N, P = map(int, input().split())
S=list(map(int,input()))
P=2019
N=len(S)
if P not in [2,5]:
  pt = [1]
  for i in range(N):
    pt.append(pt[-1]*10%P)
  dp = [(S[0]*pt[N-1])%P]
  for i in range(1,N):
    dp.append((dp[-1]+S[i]*pt[N-1-i])%P)

  c = Counter(dp)
  ans = sum(u*(u-1)//2 for u in c.values())
  print(ans+c[0])
elif P==2:
  S = [int(c) for c in input()]
  ans = 0
  for i in range(N):
    if S[i]%2==0:
      ans += i+1
  print(ans)
else:
  ans = 0
  S = [int(c) for c in input()]
  for i in range(N):
    if S[i]%5==0:
      ans += i+1
  print(ans)

Submission status: Runtime Error

Solution code:
S = input()
S.split(',')
mojisu = len(S)

count = 0

i = 1
j = 4
for k in range(i-1,j,1):
  S_new = []
  S_new.append(S[k]) 
  S_new = ''.join(S_new)
  print(S_new)
  #if int(S_new) % 2019 == 0:
    #count += 1

#print(count)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

#define rep(i, n) for(lli i = 0; i < (lli)(n); i++)

const lli MOD = 2019;

lli modpow(lli a, lli n){
    lli res = 1;

    for(lli ai = a; n; n>>=1){
        if(1&n) res = (res*ai)%MOD;
        ai=(ai*ai)%MOD;
    }
    return res;
}

lli inv(lli n){
    return modpow(n, MOD-2);
}

lli modperm(lli n, lli k){
    lli res = 1;
    rep(i, k){
        res = (res*(n-i))%MOD;
    }
    return res;
}

lli modcomb(lli n, lli k){
    return (modperm(n, k)*inv(modperm(k, k)))%MOD;
}

lli posmod(lli n){
    lli res = n;
    res %= MOD;
    if(res < 0) res += MOD;
    return res;
}

string s;
unordered_map<int, int> m;
lli res;

int main(void){
    cin >> s;

    reverse(s.begin(), s.end());
    int r=0;
    rep(i, s.size()){
        r = ((s[i]-'0')*modpow(10, i) + r)%2019;
        m[r]++;
    }

    res = m[0];
    for(auto i : m){
        res += i.second*(i.second-1)/2;
        //cout << i.second << endl;
    }

    cout << res << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
n=int(input())
k=2019
s=list(map(int,list(input())))
ans=0
if k==2 or k==5:
    for i,p in enumerate(s):
        if p%k==0:
            ans+=i+1
else:
    inv10=pow(10,k-2,k)
    inv=10
    total=0
    S=[0]*k
    S[0]=1
    for i,p in enumerate(s):
        inv*=inv10
        inv%=k
        total+=p*inv
        total%=k
        ans+=S[total]
        S[total]+=1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(500*500)
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:
from collections import defaultdict
s=input()
d=defaultdict(int)
l.insert(0,0)
for i in range(1,len(s)+1):
    d[int(s[-i:])%2019] += 1
ans=0
for v in d.values():
    ans += v*(v-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

S=input()
A=0

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

SL_sum=SL.copy()
for i in range(1, len(SL_sum)):
    SL_sum[i] += SL_sum[i-1]

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

Submission status: Runtime Error

Solution code:
n=int(input())
k=2019
s=list(input())
ans=0
if k==2 or k==5:
    for i,p in enumerate(s):
        if p%k==0:
            ans+=i+1
else:
    inv10=pow(10,k-2,k)
    inv=10
    total=0
    S=[0]*k
    S[0]=1
    for i,p in enumerate(s):
        inv*=inv10
        inv%=k
        total+=p*inv
        total%=k
        ans+=S[total]
        S[total]+=1
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
sys.setrecursionlimit(10**9)
S = input()

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

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

Submission status: Runtime Error

Solution code:
S = list(input())
multiple = []
letter_4 = []
letter_5 = []
for i in range(1,200000//2019+1):
  multiple.append(str(2019*i))

for i in range(len(S)-3):
  letter_4.append(''.join(S[i:i+4]))
for i in range(len(S)-4):
  letter_5.append(''.join(S[i:i+5]))
for i in range(len(S)-5):
  letter_6.append(''.join(S[i:i+6]))  

letter_joined = letter_4 + letter_5+letter_6

ansnum = []
for i in multiple:
    for j in letter_joined:
        if i == j:
            ansnum.append(i)
print(len(ansnum))

'''
print(multiple)
print(letter_joined)
print(ansnum)
'''

Submission status: Runtime Error

Solution code:
import numpy as np

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


S=input()
A=0

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

SL_sum=SL.copy()
for i in range(1, len(SL_sum)):
    SL_sum[i] += SL_sum[i-1]

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

Submission status: Runtime Error

Solution code:
n=int(input())
k=2019
s=map(int,list(input()))
ans=0
if k==2 or k==5:
    for i,p in enumerate(s):
        if p%k==0:
            ans+=i+1
else:
    inv10=pow(10,k-2,k)
    inv=10
    total=0
    S=[0]*k
    S[0]=1
    for i,p in enumerate(s):
        inv*=inv10
        inv%=k
        total+=p*inv
        total%=k
        ans+=S[total]
        S[total]+=1
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std ;
#define printshosu(a) cout << fixed << setprecision(15) << a << endl;
int main(){
  string S;
  cin >>S;
  int N = S.size();
  vector<int> R;
  for(int i = 0;i<N;i++){
    if(i==0){
      R.push_back(int(S.at(i))%3);
    }else{
      R.push_back((R.at(i-1)+int(S.at(i)))%3);
    }
  }
  int ans = 0;
  for(int i = 0;i<N;i++){
    if( i == 0){
      int j = 3;
      while(j<N){
        if(R.at(j)==0&&atoi(S.substr(0,j+1).c_str())%2019==0){
          ans++;
        }
        j++;
      }
    }else{
      int j = i + 3;
      while(j<N){
        if(R.at(j)-R.at(i-1)==0&&atoi(S.substr(i,j-i+1).c_str())%2019==0){
          ans++;
        }
        j++;
      }
    }
  }
  cout<<ans<<endl;
}

Submission status: Runtime Error

Solution code:
S=input()
l=len(S)
s=int(S)
t=int(s/2019)
v=0
for x in range(t):
    r=2019*(x+1)
    R=str(r)
    u=S.count(R)
    v+=u
print(v)

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:
INT_MAX=10**11+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#=======================================================================
# Python 3 implementation of the approach

# Function to return the count of sub-strings
# of str that are divisible by k
def countSubStr(str, l, k):
	count = 0

	for i in range(l):
		n = 0

		# Take all sub-strings starting from i
		for j in range(i, l, 1):
			n = n * 10 + (ord(str[j]) - ord('0'))

			# If current sub-string is divisible by k
			if (n % k == 0):
				count += 1
            n=n%2019



	# Return the required count

	return count

# Driver code
if __name__ == '__main__':
	str = input()
	l = len(str)
	k = 2019
	print(countSubStr(str, l, k))

# This code is contributed by
# Sanjit_Prasad

Submission status: Runtime Error

Solution code:
from itertools import accumulate as AC
S = list(input())
L = len(S)
ans = 0
for i in range(L-3):
  L = list(AC(S))
  ans += len([i for i in L if int(i) % 2019 == 0])
  S.pop(0)
print(ans)

Submission status: Runtime Error

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

print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np

S = input()
size_S = len(S)

initial = np.arange(0, size_S-3, 1)
last = np.arange(3, size_S, 1)

count = 0
for i in range(len(initial)):
  for j in range(len(last)):
    if initial[i] <= last[j]-3:
      number = int(S[initial[i]:last[j]+1])
      if number % 2019 == 0:
        count += 1
    last = last.deleat(min(last))
print(count)

Submission status: Runtime Error

Solution code:
n =input()


def judge(x):
  
  if x % 2019 == 0:
    return(1)
  else:
    return(0)

a = 0
for i in range(1,len(n)):
  for j in range(i, len(n)):
    s = n[i:j]
    d = int("s")
    a = a + judge(d)
    
print(a)

Submission status: Runtime Error

Solution code:
s = list(input())
count = 0
len_s = len(s)+1
for i in range(1, len_s):
  if i != 1:
    s.pop(0)
  num = ''
  for j in range(1, len_s):
    num += s[j-1]
    if int(num) % 2019 == 0:
      count += 1
print(count)