Problem:


Score : 400 points

Problem Statement

Given is a string S consisting of digits from 1 through 9.

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Runtime Error

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


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


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    s = input()

    cnt = [0] * 2019
    # print(cnt)
    cnt[0] = 1
    ans = 0
    b = 0
    t = 1
    for i in s:
        b = b + int(i) * t
        b % 2019
        cnt[b] += 1
        t *= 10
        t %= 2019

    for i in cnt:
        ans += i * (i - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''

from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


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


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)
"""

def main():
    s = input()

    cnt = [0] * 2019
    # print(cnt)
    cnt[0] = 1
    ans = 0
    b = 0
    t = 1
    for i in s:
        b = b + int(i) * t
        amari = b % 2019
        cnt[amari] += 1
        t *= 10 % 2019

    for i in cnt:
        ans += i * (i - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
c = 0
k = len(str(n))
if k <= 2018:
    c = 0
else:
    for i in range (1, k-2):
        for j in range (i+3 , k+1):
            aa = n // 10 ** (k - i + 1)
            bb = 10 ** (k - i + 1)
            cc = (n * 10)  // (10 ** (k - j + 1))
            if k - j == 0:
                dd = 1
                if ((n - (aa * bb) - (n - (cc * dd))) // dd) % 2019 == 0:
                c = c + 1
            else:
                dd = 10 ** (k - j)
                if ((n - (aa * bb) - (n - (cc * dd))) // dd) % 2019 == 0:
                c = c + 1
print(c)

Submission status: Runtime Error

Solution code:
def resolve():
    s = input()
    n = len(s)
    counter = [0] * 2019
    counter[0] += 1
    temp = ""
    for i, c in enumeate(s[::-1], 1):
        temp = c + temp
        counter[int(temp) % 2019] += 1

    ans = 0
    for i in counter:
        ans += (i * (i - 1)) // 2

    print(ans)
resolve()

Submission status: Runtime Error

Solution code:
n = int(input())
c = 0
k = len(str(n))
for i in range (1, k-2):
    for j in range (i+3 , k+1):
        aa = n // 10 ** (k - i + 1)
        bb = 10 ** (k - i + 1)
        cc = (n * 10)  // (10 ** (k - j + 1))
        if k - j == 0:
            dd = 1
            if (n - (aa * bb) - (n - (cc * dd))) % 2019 == 0:
                c = c + 1
        else:
            dd = 10 ** (k - j)
            if ((n - (aa * bb) - (n - (cc * dd))) // dd) % 2019 == 0:
                c = c + 1
print(c

Submission status: Runtime Error

Solution code:
p=d=2019
z=[0]*p
for i,j in enumerate(input()[::-1]):
	d=d+int(j)*pow(10,i,p)
	z[d%p]+=1
r=z[0]
for i in a:
	r+=i*(i-1)//2
print(r)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
s_int=[0]*n
x=pow(10,n-1)
for i in range(n):
    s_int[i]=int(s[i]*x)%2019

Submission status: Runtime Error

Solution code:
p=2019
s,a,d,z=reversed(input()),0,0,[0]*p
for i in range(len(s)):
	d=(d+(int(s[i])*pow(10,i,p)))%p
	z[d]+=1
r=z[0]
for i in range(p):
	r+=z[i]*(z[i]-1)//2
print(r)

Submission status: Runtime Error

Solution code:
def main():
  n, d, mods = 0, 1, [1]+[0]*2019
  # for i in reversed(input()):
  #   n = (n+int(i)*d)%2019
  #   d = d*10%2019
  #   mods[n] += 1
  for i, j in enumerate(reversed(s)):
  n = (n+int(j)*10**i%2019)%2019
  mods[n] += 1
  print(sum([i*(i-1)//2 for i in mods]))
main()

Submission status: Runtime Error

Solution code:
import math

def readInt():
	return int(input())

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

def readChars():
	return input().split()

s = reversed(input())

ai = 0
si = [0]*len(s)

p = 2019

for i, j in enumerate(s):
	ai = (int(j)*pow(10,i,p))%p
	si[i] = (si[i-1]+ai)%p
countarr = [0]*2019
for i in si:
	countarr[i]+=1

res = countarr[0]
for i in range(p):
	c = countarr[i]
	res += c*(c-1)//2

print(res)

Submission status: Runtime Error

Solution code:
S = input()
ok = 0
bun = 0
for i in range(0, len(S) + 1):
    for j in range(i, len(S) + 1):
        bun = int(S[i:j])
        if bun % 2019 == 0:
            ok += 1

print(ok)

Submission status: Runtime Error

Solution code:
S = input()
ok = 0
bun = ""
for i in range(0, len(S) + 1):
    for j in range(i, len(S) + 1):
        bun = int(S[i:j])
        if bun % 2019 == 0:
            ok += 1

print(ok)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

def readInt():
	return int(input())

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

def readChars():
	return input().split()

s = reverse(input())

ai = [0]*len(s)
si = [0]*len(s)

p = 2019

for i in range(len(s)):
	ai[i] = (int(s[i])*pow(10,i))%p
	si[i] = sum(ai[:i+1])%p
countarr = [0]*2019
for i in si:
	countarr[i]+=1

res = countarr[0]
for i in range(p):
	c = countarr[i]
	res += c*(c-1)//2

print(res)

Submission status: Runtime Error

Solution code:
import math

def readInt():
	return int(input())

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

def readChars():
	return input().split()

s = input().reverse()

ai = [0]*len(s)
si = [0]*len(s)

p = 2019
ee = 0
for i in range(len(s)):
	ee = (int(s[i])*pow(10,i))%p

Submission status: Runtime Error

Solution code:
import math

def readInt():
	return int(input())

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

def readChars():
	return input().split()

s = input().reverse()

ai = [0]*len(s)
si = [0]*len(s)

p = 2019

for i in range(len(s)):
	(int(s[i])*pow(10,i))%p

Submission status: Runtime Error

Solution code:
S = str(input())
N = len(h)
a = [0] * 2019
a[0] = 1
T = 0
r = 1
c = 0
for i in range(N-1, -1, -1):
    T = T + int(S[i]) * r
    r = r * 10
    c += a[T%2019]
    a[T%2019] += 1
print(c)

Submission status: Runtime Error

Solution code:
S = input()
N = len(h)
a = [0] * 2019
a[0] = 1
T = 0
r = 1
c = 0
for i in range(N-1, -1, -1):
    T = T + int(S[i]) * r
    r = r * 10
    c += a[T%2019]
    a[T%2019] += 1
print(c)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def solve(S):
    dp = [0] * 2019
    pow10 = 1
    answer = 0
    for x in S[::-1]:
        dp[0] += 1
        x = x * pow10 % 2019
        newdp = [0] * 2019
        for i in range(x, 2019):
            newdp[x+i] += dp[i]
        for i in range(x):
            newdp[i] += dp[2019-x+i]
        answer += newdp[0]
        pow10 *= 10
        pow10 %= 2019
        dp = newdp
    return answer


S = [x - ord('0') for x in read().rstrip()]
print(solve(S))

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np


def solve(S):
    dp = [0] * 2019
    pow10 = 1
    answer = 0
    for x in S[::-1]:
        dp[0] += 1
        x = x * pow10 % 2019
        newdp = np.zeros_like(dp)
        for i in range(x, 2019):
            newdp[x+i] += dp[i]
        for i in range(x):
            newdp[i] += dp[2019-x+i]
        answer += newdp[0]
        pow10 *= 10
        pow10 %= 2019
        dp = newdp
    return answer


S = [x - ord('0') for x in read().rstrip()]
print(solve(S))

Submission status: Runtime Error

Solution code:
import math

def readInt():
	return int(input())

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

def readChars():
	return input().split()

s = input()

ai = [0]*len(s)
si = [0]*len(s)

p = 2019

for i in range(len(s)):
	ai[i] = (int(s[-1*i-1])

Submission status: Runtime Error

Solution code:
S=input()
n=len(S)
def T(i):
    if i == 0:
        return 0
    else:
        i-=1
        return T(i)+(10**i)*int(S[n-1-i])
s=[0]*2019
s[0]=1
for j in range(1,n+1):
    m=T(j)%2019
    s[m]+=1

c=0

for m in s:
    c += m*(m-1)/2

print(int(c))

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
dp = [0] * 2019
cnt = [0] * 2019
cnt[0] = 1
p = 1

for i in reversed(range(N)):
    dp[i] = (dp[i+1] + A[i]*p) % 2019
    cnt[dp[i]] += 1
    p = 10 * p % 2019
ans = 0

for i in cnt:
    ans += i*(i-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
n = 0
ans = 0
mods = [0]*p
mods[0] = 1
for i, j in enumerate(reversed(s)):
  n += int(j)*pow(10, i, 2019)
  n %= 2019
  mods[n] += 1
for i in mods:
  ans += i*(i-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
s=input()
m=len(s)
if n<2019:
    print(0)
    exit()
from collections import Counter
c=Counter()
tmp=""
c[0]+=1
for i in s[::-1]:
    tmp=i+tmp
    c[int(tmp)%2019]+=1

ll=c.most_common()
ans=0
for i,j in ll:
    if j>=2:
        ans+=j*(j-1)//2
    else:
        break
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
dp = [0] * 2019
cnt = [0] * 2019
cnt[0] = 1
p = 1

for i in reversed(range(N)):
    dp[i] = (dp[i+1] + A[i]*p) % 2019
    cnt[dp[i]] += 1
    p = 10 * p % 2019 

ans = 0
for i in cnt:
    ans += i*(i-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit

@njit('i4[:]')
def solve(S):
    dp = np.zeros(2019, np.int64)
    pow10 = 1
    answer = 0
    for x in S[::-1]:
        dp[0] += 1
        x = x * pow10 % 2019
        newdp = np.zeros_like(dp)
        newdp[x:] += dp[:-x]
        newdp[:x] += dp[-x:]
        answer += newdp[0]
        pow10 *= 10
        pow10 %= 2019
        dp = newdp
    return answer


S = np.array(list(read().rstrip()), dtype=np.int32) - ord('0')
print(solve(S))

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
dp = [0] * 2019
cnt = [0] * 2019
cnt[0] = 1

for i in reversed(range(N)):
    dp[i] = (dp[i+1] + (A[i]*(10**(N-i))%2019)) % 2019
    cnt[dp[i]] += 1

ans = 0
for i in cnt:
    ans += i*(i-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
S=input()
n=len(S)
def T(i):
    if i == 0:
        return 0
    else:
        i-=1
        return T(i)+(10**i)*int(S[n-1-i])
s=[0]*2019
for j in range(1,n+1):
    print(T(j))
    m=T(j)%2019
    s[m]+=1

c=s[0]

for m in s:
    c += m*(m-1)/2

print(int(c))

Submission status: Runtime Error

Solution code:
S=input()
n=len(S)
def T(i):
    if i == 0:
        return 0
    else:
        i-=1
        return T(i)+(10**i)*int(S[n-1-i])
s=[0]*2018
for j in range(1,n+1):
    print(T(j))
    m=T(j)%2019
    s[m]+=1

c=s[0]

for m in s:
    c += m*(m-1)/2

print(int(c))

Submission status: Runtime Error

Solution code:
s = input()
MOD = 2019
r = [0]*MOD
r[0] = 1
z = 0
t = 0
for i in reversed(s):
    z = int(i) * pow(10,t,m) + z
    z %= MOD
    r[z] += 1
    t += 1
print(sum(i*(i-1)//2 for i in r))

Submission status: Runtime Error

Solution code:
from math import pow
n = input()

MOD = 2019
ans = 0
dp = [0]*MOD
dp[0] = 1
temp = 0

for i in range(len(n)):
    temp = (temp+int(n[-i-1])*int(pow(10, i))) % MOD
    dp[temp] += 1

for item in dp:
    if item > 1:
        ans += item*(item-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
S=input()
n=len(S)
def T(i):
    if i == 0:
        return 0
    else:
        i-=1
        return T(i)+(10**i)*int(S[n-1-i])
s=[0]*2019
for j in range(1,n+1):
    m=T(j)%2019
    s[m]+=1

c=s[0]

for m in s:
    c += m*(m-1)/2

print(int(c))

Submission status: Runtime Error

Solution code:
from math import pow
n = input()

MOD = 2019
ans = 0
dp = [0]*MOD
dp[0] = 1
temp = 0

for i in range(len(n)):
    temp = (temp+int(n[-i-1])*int(pow(10, i))) % MOD
    dp[temp] += 1

for item in dp:
    if item != 0:
        ans += item*(item-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
import collections
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * pow(10,i,2019)
  mod.append((now + mod[i]) % 2019)


c = collections.Counter(mod)
hindo = sorted(c.values(),reverse=True)
for i in range(hindo.index(1)):
  n = hindo[i]
  cnt += n*(n-1)//2

print(cnt)

Submission status: Runtime Error

Solution code:
from math import pow
n = input()

MOD = 2019
ans = 0
dp = [0]*MOD
dp[0] = 1
temp = 0

for i in range(len(n)):
    temp = (temp+int(n[-i-1])*pow(10, i)) % MOD
    dp[temp] += 1

for item in dp:
    ans += item*(item-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
S = input()
count = 0
for i in range(len(S)):
  if int(S[i]) <= 0:
    if int(S[i+1]) <= 1:
      for j in range(i+1,i+8):
        if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
          count = count + 1
        if j >= len(S+1):
          break
    if int(S[i+1]) >= 2:
      if int(S[i+1:i+7]) == 200000:
        for j in range(i+1,i+8):
          if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
            count = count + 1
          if j >= len(S+1):
            break
      else:
        for j in range(i+1,i+7):
          if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
            count = count + 1
          if j >= len(S):
            break
  if int(S[i]) <= 1:
    for j in range(i+1,i+7):
      if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
        count = count + 1
      if j >= len(S+1):
        break
  if int(S[i]) >= 2:
    if int(S[i:i+6]) == 200000:
      for j in range(i+1,i+7):
        if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
          count = count + 1
        if j >= len(S+1):
          break
    else:
      for j in range(i+1,i+6):
        if int(S[i:j]) % 2019 == 0 and int(S[i:j]) != 0:
          count = count + 1
        if j >= len(S+1):
          break
print(count)

Submission status: Runtime Error

Solution code:
S=input()
n=len(S)
def T(i):
    if i == 0:
        return 0
    else:
        i-=1
        return T(i)+(10**i)*int(S[n-1-i])
s=[0]*2019
for j in range(1,n+1):

    m=T(j)%2019

    s[m]+=1

c=s[0]

for m in s:
    c += m*(m-1)/2

print(int(c))

Submission status: Runtime Error

Solution code:
import numpy as np
S = input()
S_list = []
for i in range(len(S)):
    S_list.append(int(S[i]))
S_list = np.array(S_list)
num = 0
for i in range(len(S_list)-3):
    sum_temp = np.sum([v * np.power(10, k) for k, v in enumerate(S_list[i:i+3][::-1])])
    #print(i, i+3, sum_temp)
    k = 0
    for j in range(i+3, len(S)):
        #print(S_list[j])
        sum_temp *= 10
        sum_temp += S_list[j]
        if sum_temp % 2019 == 0:
            num += 1
print(num)

Submission status: Runtime Error

Solution code:

S=str(input())
l=len(S)
ans=0

mod=[0]*2019
mod[0]+=1
t=0
for i in range(l):
    t=int(S[l-i:-1:-1])*pow(10,i,2019)
    mod[t%2019]+=1
    
for j in range(len(mod)):
    m=mod[j]
    ans=ans+m*(m-1)//2
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * pow(10,i,2019)
  mod.append((now + mod[i]) % 2019)

c = collections.Counter(mod)
hindo = sorted(c.values(),reverse=True)

for i in range(hindo.index(1)):
  n = hindo[i]
  cnt += n*(n-1)//2

print(cnt)

Submission status: Runtime Error

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

li = [int(s[-1])]

for i in range(n-1):
    t = int(s[-i-2])
    li.append((li[-1] + t * 10 ** (i+1)) % 2019)

dict1 = {}
for i in li:
    if i in dict1:
        dict1[i] += 1
    else:
        dict1[i] = 1

ans = 0

for v in dict1.values():
    ans += v * (v-1) // 2

print(ans + dict1[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * pow(10,i+1,2019)
  mod.append((now + mod[i]) % 2019)

c = collections.Counter(mod)
hindo = sorted(c.values(),reverse=True)
if hindo.index(1) != 0:
  for i in range(hindo.index(1)):
    n = hindo[i]
    cnt += n*(n-1)//2
else:
  cnt = 0

print(cnt)

Submission status: Runtime Error

Solution code:
S = str(input())

r = 0
for i in range(len(S)):
    for j in range(i, len(S) + 1):
        if S[i:j]:
            if str(float(S[i:j]) / 2019.0) == str(int(int(S[i:j]) / 2019.0)) + ".0":
                r += 1
                # print(i, j)

print(r)

Submission status: Runtime Error

Solution code:
S = input()
T = [0]*2019
T[0]=1
t = 0
ans = 0
dig = 1
for i in range(n):
    t = (t + (int(S[-i-1]))*dig)%2019
    dig = (dig*10)%2019
    T[t] += 1
for j in T:
    ans +=int(j*(j-1)/2)
print(ans)

Submission status: Runtime Error

Solution code:
from namba import njit

@njit
def main():
    S = input()
    L = len(S)
    amari = [0] * 2019
    tmp = 0
    for i in range(L):
        tmp += int(S[-i-1])*(10**i)%2019
        tmp %= 2019
        amari[tmp] += 1
    ans = amari[0]
    for i in range(2019):
        ans += amari[i]*(amari[i]-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
S = input()
T = [0]*2019
T[0]=1
t = 0
ans = 0
dig = 1
for i in range(n):
    t = (t + (int(S[-i-1]))*dig)%2019
    dig = dig*10%2019
    T[t] += 1
for j in T:
    ans +=int(j*(j-1)/2)
print(ans)

Submission status: Runtime Error

Solution code:
import collections
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * pow(10,i+1,2019)
  mod.append((now + mod[i]) % 2019)

c = collections.Counter(mod)
hindo = sorted(c.values(),reverse=True)
for i in range(hindo.index(1)):
  n = hindo[i]
  cnt += n*(n-1)//2

print(cnt)

Submission status: Runtime Error

Solution code:
import collections
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
tens = 1
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * tens % 2019
  mod.append((now + mod[i]) % 2019)
  tens *= 10
  tens %= 2019

c = collections.Counter(mod)
hindo = sorted(c.values(),reverse=True)
for i in range(hindo.index(1)):
  n = hindo[i]
  cnt += n*(n-1)//2

print(cnt)

Submission status: Runtime Error

Solution code:
import collections
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
tens = 1
for i in range(len(reverse_S)):
  now = int(reverse_S[i])*tens%2019
  mod.append((now+mod[i])%2019)
  tens *= 10
  tens %= 2019

c = collections.Counter(mod)
hindo = sorted(c.values(),reverse=True)
for i in range(hindo.index(1)):
  n = hindo[i]
  cnt += n*(n-1)/2

print(int(cnt))

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<string>
using namespace std;
string s;
int n;
n=s.length()
cin>>s
int sum=0;
for(int i=0;i<n,i++){
for(int j=i+1;j<n,j++){
string num=str.substr(i,j-i+1);
  int x=stoi(num);
  if(x%2019==0){
  sum+=1;
  }
  
}
}
cout<<sum;

Submission status: Runtime Error

Solution code:
import numpy as np
from numba import jit

@njit
def solve(s):
    n = len(s)
    ans = 0
    now = 0
    mp = np.zeros(2019, np.int)
    mp[0] += 1
    tmp = np.zeros(2019, np.int)

    id = np.zeros(2019, np.int)
    for i in range(2019):
        id[i] = i * 10 % 2019

    for c in s:
        now *= 10;
        now += ord(c) - ord("0")
        now %= 2019

        ans += mp[now]
        mp[now] += 1
        for i in range(2019):
            tmp[id[i]] = mp[i]
        for i in range(2019):
            mp[i] = tmp[i]

    print(ans)

s = input()
solve(s)

Submission status: Runtime Error

Solution code:
import collections
S = input()
cnt = 0

length = len(S)
mod = [0]
reverse_S = S[::-1]
tens = 1
for i in range(len(S)):
  now = int(reverse_S[i])*tens%2019
  mod.append((now+mod[i])%2019)
  tens *= 10
  tens %= 2019

c = collections.Counter(mod)
hindo = sorted(c.values(),reverse=True)
for i in range(hindo.index(1)):
  n = hindo[i]
  cnt += n*(n-1)/2

print(int(cnt))

Submission status: Runtime Error

Solution code:
def main():
    import heapq
    inf = 10**16
    n, m, s = map(int, input().split())
    uvab = [list(map(int, input().split())) for _ in [0]*m]
    cd = [list(map(int, input().split())) for _ in [0]*n]
    g = [[] for _ in [0]*n]
    [g[a-1].append([b-1, c, d]) for a, b, c, d in uvab]
    [g[b-1].append([a-1, c, d]) for a, b, c, d in uvab]
    vertex = [[inf]*2501 for _ in [0]*n]
    h = [(0, 0, min(s, 2500))]  # 時刻、位置、所持金
    heapq.heapify(h)
    while h:
        t, p, money = heapq.heappop(h)
        if vertex[p][money] != inf:
            continue
        vertex[p][money] = t
        newmoney = min(money+cd[p][0], 2500)
        if vertex[p][newmoney] == inf:
            heapq.heappush(h, (t+cd[p][1], p, newmoney))
        for a, b, c in g[p]:  # 行き先、運賃、時間
            if money < b:
                continue
            if vertex[a][money-b] != inf:
                continue
            heapq.heappush(h, (t+c, a, money-b))
    for i in vertex[1:]:
        print(min(i))


main()

Submission status: Runtime Error

Solution code:
S = input()
B = defaultdict(int)
B[0]=1
ans=0

for i in range(len(S)):
    m=int(S[-i-1:])%2019
    ans+=B[m]
    B[m]+=1

print(int(ans))

Submission status: Runtime Error

Solution code:
from collections import deque
s = deque(input())
n = len(s)

temp = [0]*2019
t = 1
num = 0
for i in range(n):
    num += int(s.pop())*t % 2019
    temp[num] += 1
    t *= 10

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

print(int(ans))

Submission status: Runtime Error

Solution code:
import collections
S = input()
cnt = 0

length = len(S)
mod = [0]
reverse_S = S[::-1]
tens = 1
for i in range(len(S)):
  now = int(reverse_S[i])*tens%2019
  mod.append((now+mod[i])%2019)
  tens *= 10
  tens %= 2019;

c = collections.Counter(mod)
hindo = sorted(c.values(),reverse=True)
for i in range(hindo.index(1)):
  n = hindo[i]
  cnt += n*(n-1)/2

print(int(cnt))

Submission status: Runtime Error

Solution code:
from sys import stdin
#import numpy as np


def merge_sort(lst, low, high):
    if low >= high:
        return
    mid = int((low+high)/2)
    merge_sort(lst, low, mid)
    merge_sort(lst, mid+1, high)
    for i in range(low, mid+1):
        tmp_array[i] = lst[i]
    j = high
    for i in range(mid+1, high+1):
        tmp_array[i] = lst[j]
        j -= 1
    i = low
    j = high
    for k in range(low, high+1):
        if tmp_array[i] <= tmp_array[j]:
            lst[k] = tmp_array[i]
            i += 1
        else:
            lst[k] = tmp_array[j]
            j -= 1


S = stdin.readline().rstrip()
N = len(S)
Sp = S

res_map = [0 for _ in range(N)]

aa_list2 = [1]
for i in range(1,N):
    aa_list2.append((aa_list2[i-1]*10)%2019)

tmp_array = [None for _ in range(N)]
res_map[N-1] = int(S[N-1])
index=1
for i in range(N-2,-1,-1):
    res_map[i] = (int(S[i])*aa_list2[index] + res_map[i+1])%2019
    index+=1

res_map.sort()
temp_num=int(res_map[0])
index=1
tot = 0

aa_table = [0 for i in range(2019)]
aa_table2 = [0 for i in range(2019)]
for i in range(len(res_map)):
    aa_table2[res_map[i]]+=1

aa_table2[0]+=1

#sort check
for i in range(1,N):
    if res_map[i]<res_map[i-1]:
        aa = 2/0

for i in range(1,len(res_map)):
    if temp_num==int(res_map[i]):
        index+=1
        continue
    else:
        aa_table[temp_num] = index
        index=1
        temp_num=int(res_map[i])

aa_table[0] += 1 

for i in range(2018):
    if aa_table[i] != aa_table2[i]:
        aa = 2/0
#        if temp_num==0:
#            tot += int(index*(index+1)/2)
#        elif index>1:
#            tot += int(index*(index-1)/2)
#        index=1
#        temp_num=int(res_map[i])


tot = 0
for i in range(2019):
    tot+=int((aa_table[i]-1)*aa_table[i]/2)



#for i in range(2018):
#    num = np.sum(np.array(res_map)==i)
#    if i ==0:
#        num+=1
#    tot += int(num*(num-1)/2)
    

print(tot)

Submission status: Runtime Error

Solution code:
s = input()
mod = 2019
array = [0]*(len(s)+1)

for i in range(len(s)):
    array[i+1] = (array[i] + pow(10,i,mod)*int(s[len(s)-(i+1)])) % mod
        
array.sort()

cnt = 0
w = 1

for i in range(0, len(array)-1):
    if array[i] == array[i+1]:
        w += 1
    else:
        if w >= 2:
            cnt += w*(w-1)/2
            w = 1
            
if w != 1:
    cnt += factorial(w) / (factorial(2)*factorial(w - 2))
    
print(int(cnt))

Submission status: Runtime Error

Solution code:
s = input()
mod = 2019
array = [0]*(len(s)+1)

for i in range(len(s)):
    array[i+1] = (array[i] + pow(10,i,mod)*int(s[len(s)-(i+1)])) % mod
    

    
array.sort()

cnt = 0
w = 1

for i in range(0, len(array)-1):
    if array[i] == array[i+1]:
        w += 1
    else:
        if w >= 2:
            cnt += w*(w-1)/2
            w = 1
            
if w != 1:
    cnt += factorial(w) / (factorial(2)*factorial(w - 2))
    
print(int(cnt))

Submission status: Runtime Error

Solution code:
s=input()
s_list=[]
for i in range(len(s)-3):
    for j in range(i+3,len(s)):
        s_list.append(s[i:j+1])
count=0

for word in s_list:
    tmp_num=int(word)
    if(tmp_num%2019==0):
        count+=1
print(count)

Submission status: Runtime Error

Solution code:
s=[int(i) for i in input()]
s.reverse()

a=0
l=[0 for i in range(2019)]
l[0]=1
for i in range(len(s)):
  a+=s[i]*(10**i)
  a%=2019
  l[b]+=1

answer=0
for i in range(2019):
  answer+=l[i]*(l[i]-1)//2
  
print(answer)

Submission status: Runtime Error

Solution code:
S=input()
N=len(S)
Slis=[]
for i in range(N):
  Slis+=[int(S[i])]
T=[int(S[i:]) for i in range(N)]
MOD=[0 for i i range(2019)]
for i in range(N):
  tmp=T[i]%2019
  MOD[tmp]+=1
ans=0
for i in range(2019):
  tmp=T[i]
  ans+=tmp*(tmp-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
count = [0]*2019
mod = 0

for i in range(len(S))
	mod = int(S[-i]) % 2019
	count[mod] += 1

answer = 0

for k in range(2019)
	answer = answer + count[k]

print(answer)

Submission status: Runtime Error

Solution code:
s = input()
dict = {}
c = 0
dgt = 1
ans = 0
for st in s[::-1]:
    c = c + int(st) * dgt
    dgt *= 10
    mod = c%2019
    if mod in dict:
        dict[mod] += 1
        ans += dict.get(mod)
    else:
        dict[mod] = 0   
    print(dict)
if ans != 0:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
ans = 0
s = input()
size = len(s) + 1
for i in range(size):
    if (i + 4) >= size:
        continue
    for j in rangeuntil(i + 4,  size):
        if ((int(s[i:j]) % 2019) == 0 ):
            ans += 1
print(ans)