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: Wrong Answer

Solution code:
s = input()
ln = len(s)
d = [int(i) for i in s]
count = 0
for i in range(ln - 3):
    total = sum(d[i:i+3])
    for j in range(i + 3, ln):
        total += d[j]
        if total % 3 == 0 and int(s[i:j+1]) % 673 == 0:
            print(i, j, int(s[i:j+1]))
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
s=list(map(int,input()))
c=0
cnt=[0]*2019
for r in s:
	c=(c*10+r)%2019
	cnt[c]+=1
print(sum(x*(x-1)//2 for x in cnt))

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list -- START --
def summarizeList(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res
# Summarize count of factor within list --- END ---

def main():
  s=S()
  n=len(s)

  l=[]
  mul=1
  for x in s[::-1]:
    l.append(mul*int(x)%2019)
    mul*=10
    mul%=2019

  for i in range(n-1):
    l[i+1]+=l[i]
    l[i+1]%=2019

  sl=summarizeList(l)
  # print(sl)

  ans=0
  for x,c in sl:
    if x==0:
      ans+=c
    elif c>1:
      ans+=c*(c-1)//2

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
S = list(map(int, list(input())))
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
for i in range(N):
    num = num * 10 + S[i]
    CNT[num * pow(10, N-i)%2019] += 1
ans = 0 
CNT.sort()
for cnt in CNT:
    if cnt==0: break 
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
def egcd(a, b):
    """Returns a triple (g, x, y), such that ax + by = g = gcd(a,b).
       Assumes a, b >= 0, and that at least one of them is > 0.
       Bounds on output values: |x|, |y| <= max(a, b)."""
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m) 
    if g != 1:
        return None
    else:
        return x % m

def main():
    s = input()
    n = len(s)
    h = [0]
    for i in range(n):
        h.append((h[-1] * 10 + int(s[i])) % 2019)
    p = [1]
    for i in range(n):
        p.append((p[-1] * 10) % 2019)
    lk = {0 : 1}
    cnt = 0
    for i in range(1, len(h)):
        curr = h[i] % 2019
        # print(i, curr)
        if curr in lk:
            cnt += lk[curr]
            lk[curr] += 1
        else:
            lk[curr] = 1 
    print(cnt)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def egcd(a, b):
    """Returns a triple (g, x, y), such that ax + by = g = gcd(a,b).
       Assumes a, b >= 0, and that at least one of them is > 0.
       Bounds on output values: |x|, |y| <= max(a, b)."""
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m) 
    if g != 1:
        return None
    else:
        return x % m

def main():
    s = input()
    n = len(s)
    h = [0]
    for i in range(n):
        h.append((h[-1] * 10 + int(s[i])) % 2019)
    p = [1]
    for i in range(n):
        p.append((p[-1] * 10) % 2019)
    lk = {0 : 1}
    cnt = 0
    for i in range(1, len(h)):
        curr = (h[i] * modinv(p[i], 2019)) % 2019
        # print(i, curr)
        if curr in lk:
            cnt += 1
            lk[curr] += 1
        else:
            lk[curr] = 1 
    print(cnt)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S=input()
s=int(S)
c=0
for i in range(100):
  C=str(2019*i)
  if '0' in C:
    continue
    #print(S.count(C))
  for j in range(len(S)):
    if C in S[j:j+len(C)]:
      c+=S.count(C)
      #print(C)
      #print(S.count(C))

print(c)


exit()




c=0;s=[]
for i in range(0,len(S)+1):
  for j in range(i,len(S)):
    s.append(S[i:j+1])
del s[0]
ss = [int(i) for i in s]    
#print(ss)
sss = list(map(lambda x: x %2019, ss))

#print(sss)
print(sss.count(0))

Submission status: Wrong Answer

Solution code:
S=input()
s=int(S)
c=0
for i in range(200):
  C=str(2019*i)
  if '0' in C:
    continue
    #print(S.count(C))
  for j in range(len(S)):
    if C in S[j:j+len(C)]:
      c+=S.count(C)
      #print(C)
      #print(S.count(C))

print(c)


exit()




c=0;s=[]
for i in range(0,len(S)+1):
  for j in range(i,len(S)):
    s.append(S[i:j+1])
del s[0]
ss = [int(i) for i in s]    
#print(ss)
sss = list(map(lambda x: x %2019, ss))

#print(sss)
print(sss.count(0))

Submission status: Wrong Answer

Solution code:
S = input()
sum = 0

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

lenS = len(S)

for i in range(4,lenS+1):
  for j in range(0,lenS+1-i):
    if (int(S[j:i+j]) % 2019) == 0:
      sum += 1

print(sum)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections as cl
import sys


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


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    S = input()

    mods = [0] * 2019

    ttl = 0
    pows = 1

    for i in range(len(S)-1, -1, -1):
        ttl += (int(S[i]) * pows) % 2019
        ttl %= 2019
        pows *= 10
        pows %= 2019
        mods[ttl] += 1

    ans = mods[0]
    for i in range(1, 2019):
        ans += mods[i] * (mods[i] - 1) / 2

    print(int(ans))


main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections as cl
import sys


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


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    S = input()

    mods = [0] * 2019

    ttl = 0
    pows = 1

    for i in range(len(S)-1, -1, -1):
        ttl += (int(S[i]) * pows) % 2019
        pows *= 10 % 2019
        ttl = ttl % 2019
        mods[ttl] += 1

    ans = mods[0]
    for i in range(1, 2019):
        ans += mods[i] * (mods[i] - 1) / 2

    print(int(ans))


main()

Submission status: Wrong Answer

Solution code:
S = input()
if int(S) < 2019:
  print(0)
  
else:
  count = 0
  while len(S) > 4:
    if int(S) % 2019 == 0:
      count += 1
    if int(S[-4:]) % 2019 == 0:
      count += 1
    S = S[:-1]
    
  if int(S) % 2019 == 0:
    count += 1
    
  print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [0]*2019
m = 0
for i in range(l):
    m = (int(s[l-1-i])*pow(10,i,2019) + m)%2019
    mod[m] += 1

cnt += mod[0]

for i in range(1,2019):
    if mod[i] > 1:
        cnt += (mod[i]*(mod[i]-1))/2
print(int(cnt))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    s = input()
    lens = len(s)

    d1 = defaultdict(int)
    ss = int(s[-4:]) % 2019
    k = 5
    while k <= lens:
        d1[ss] += 1
        ss += (int(s[-k]) * (10 ** (k - 1))) % 2019
        ss = ss % 2019
        k += 1
    d1[ss] += 1
    r = d1[0]
    for v in d1.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
from math import log10, ceil

def main():
    s = int(input())
    w = 10 ** (ceil(log10(s)) - 1)
    d1 = defaultdict(int)
    while s > 2018:
        d1[s % 2019] += 1
        s %= w
        w //= 10
    r = d1[0]
    for v in d1.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
from math import log10, ceil

def main():
    s = int(input())
    w = 10 ** (ceil(log10(s)) - 1)
    d1 = defaultdict(int)
    while s > 2018:
        d1[s % 2019] += 1
        s %= w
        w //= 10
    r = 0
    for v in d1.values():
        r += v * (v - 1) // 2
    print(r)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
A = A[::-1]

MOD = 2019

p10 = [1] * N
for i in range(1, N):
	p10[i] = (p10[i - 1] * 10) % MOD

for i in range(N):
	A[i] = (A[i] * p10[i]) % MOD

cumsum = [A[0]] * N
for i in range(1, N):
	cumsum[i] = (cumsum[i - 1] + A[i]) % MOD

cnt = [0] * MOD
for i in range(N):
	cnt[cumsum[i]] += 1

ans = cnt[0] * (cnt[0] + 1) // 2 + cnt[0] - 1
if cnt[0] == 0:
	ans = 0
for i in range(1, MOD):
	ans += cnt[i] * (cnt[i] - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
dp = [0 for _ in range(n)]
dp[-1] = int(s[-1])
memo = dp[-1]
cnt_dic = {}
tmp = 1
ans = 0
cnt_dic[0] = 1
for i in range(n-2, -1, -1):
    memo = (memo + int(s[i]) * pow(10, n-i-1, 2019)) % 2019
    if not memo in cnt_dic:
        cnt_dic[memo] = 0
    ans += cnt_dic[memo]
    cnt_dic[memo] += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
dp = [0 for _ in range(n)]
dp[-1] = int(s[-1])
cnt_dic = {}
tmp = 1
ans = 0
cnt_dic[0] = 1
for i in range(n-2, -1, -1):
    dp[i] = (dp[i+1] + int(s[i]) * pow(10, n-i-1, 2019)) % 2019
    if not dp[i] in cnt_dic:
        cnt_dic[dp[i]] = 0
    ans += cnt_dic[dp[i]]
    cnt_dic[dp[i]] += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
dp = [0 for _ in range(n)]
dp[-1] = int(s[-1])
tmp = 1
for i in range(n-2, -1, -1):
    dp[i] = (dp[i+1] + int(s[i]) * pow(10, (n-i-1), 2019)) % 2019

cnt_dic = {}

for i in dp:
    if not i in cnt_dic:
        cnt_dic[i] = 0

    cnt_dic[i] += 1

# print(dp)
ans = 0
# print(cnt_dic)
for i, j in cnt_dic.items():
    if i == 0:
        ans += j
    else:
        ans += j * (j - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    def modpow(x, n, mod):
        res = 1
        while n:
            if n % 2:
                res *= x % mod
            x *= x % mod
            n >>= 1
        return res

    s = input()
    s = s[::-1]
    s_len = len(s)
    mod = 2019
    d = [0] * mod
    d[0] = 1
    rev_num = 0
    # 2以上なら共通するmodがあったということになる
    for i in range(s_len):
        rev_num += int(s[i]) * int(modpow(10, i, mod))
        rev_num %= mod
        d[rev_num] += 1
    # 2以上同じmodがあったらそこから2つ選ぶ選び方
    # それを全てのmodで
    print(sum(i*(i-1)//2 for i in d))

Submission status: Wrong Answer

Solution code:
S=str(input())
N=len(S)
s=[0]*(N+1)
s[0]=0
counter={0:0}
ans=0
for i in range(1,N+1):
    s[i]=S[-i:]
    r=int(s[i])%2019
    if r in counter:
        counter[r]+=1
    else:
        counter[r]=1
for i in counter.values():
    ans += i*(i-1)//2
print(ans+1)

Submission status: Wrong Answer

Solution code:
import sys

S = input()[::-1]

c = [0] * 2019
c[0] = 1

num = 0
d = 1

for a in S:
    num += int(a) * d
    num %= 2019
    d *= 10
    d %= 2019
    c[num] += 1

a = 0
for i in c:
    a += i * (i - 1) // 2

Submission status: Wrong Answer

Solution code:
# s = list(input())
s = list(str(10**200000))
n = len(s)
ans = 0
s.reverse()
# print(s)
x = 1
tot = 0
count = [0]*2019
for i in range(n):
    count[tot]+=1
    tot += int(s[i])*x
    # print(tot)
    tot %= 2019
    ans += count[tot]
    x = x*10%2019
print(ans)

Submission status: Wrong Answer

Solution code:
# s = list(input())
s = list(str(10**200000))
n = len(s)
ans = 0
s.reverse()
print(s)
x = 1
tot = 0
count = [0]*2019
for i in range(n):
    count[tot]+=1
    tot += int(s[i])*x
    # print(tot)
    tot %= 2019
    ans += count[tot]
    x = x*10%2019
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
A = A[::-1]

MOD = 2019

p10 = [1] * N
for i in range(N):
	p10[i] = (p10[i - 1] * 10) % MOD

for i in range(N):
	A[i] = (A[i] * p10[i]) % MOD

cumsum = [A[0]] * N
for i in range(1, N):
	cumsum[i] = (cumsum[i - 1] + A[i]) % MOD

cnt = [0] * MOD
for i in range(N):
	cnt[cumsum[i]] += 1

ans = cnt[0] * (cnt[0] + 1) // 2 + cnt[0] - 1
if cnt[0] == 0:
	ans = 0
for i in range(1, MOD):
	ans += cnt[i] * (cnt[i] - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]

MOD = 2019

p10 = [1] * N
for i in range(N):
	p10[i] = (p10[i - 1] * 10) % MOD
p10 = p10[::-1]

for i in range(N):
	A[i] = (A[i] * p10[i]) % MOD

cumsum = [A[0]] * N
for i in range(1, N):
	cumsum[i] = (cumsum[i - 1] + A[i]) % MOD

cnt = [0] * MOD
for i in range(N):
	cnt[cumsum[i]] += 1

ans = cnt[0] * (cnt[0] + 1) // 2 + cnt[0] - 1
if cnt[0] == 0:
	ans = 0
for i in range(1, MOD):
	ans += cnt[i] * (cnt[i] - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
#D
from itertools import combinations
from sys import stdin
def main():
    readline = stdin.readline
    S=input()
    len_S=len(S)

    if len_S <4:
        print(0)

    else:
        comb=list(combinations(range(len_S+1),2))
        count=0
        for i in comb:
            i_0=i[0]
            i_1=i[1]
            if int(S[i_0:i_1])%2019==0:
                count+=1
        print(count)

Submission status: Wrong Answer

Solution code:
#D
from itertools import combinations
from sys import stdin
def main():
    readline = stdin.readline
    S=input()
    len_S=len(S)

    if len_S <4:
        print(0)

    else:
        comb=list(combinations(range(len_S+1),2))
        count=0
        for i in comb:
            i_0=i[0]
            i_1=i[1]
            if int(S[i_0:i_1])%2019==0:
                count+=1
        print(count)

Submission status: Wrong Answer

Solution code:
#D
from sys import stdin
def main():
    readline = stdin.readline
    S=readline()
    len_S=len(S)
    count=0
    for i in range(len_S-3):
        for j in range(i+3,len_S+1):
            if int(S[i:j])%2019==0:
                count+=1
    print(count)
main()

Submission status: Wrong Answer

Solution code:
s = input()

a = [str(2019*i) for i in range(1,101)]
ans = 0
for i in a:
    if i in s:
        t = len(i)
        for j in range(len(s)-t+1):
            if s[j:j+t] == i:
                ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

a = [str(2019*i) for i in range(1,100)]
ans = 0
for i in a:
    if i in s:
        t = len(i)
        for j in range(len(s)-t+1):
            if s[j:j+t] == i:
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#coding = SJIS

s = str(input())
ans = 0

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()[::-1]
n=len(s)
p=2019
S=[0 for i in range(n+1)]
ans=[0]*p

x10=1
for j, i in enumerate(s):
  S[j+1]=(S[j]+(x10*int(i)))%p
  x10=10**j
  x10%=p
  ans[S[j+1]]+=1

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from collections import Counter


def solve(n):
    return n * (n - 1) // 2


s = input()[::-1]
MOD = 2019

# 事前計算
rest = []
for i, x in enumerate(s):
    # 1, 10, 100, 1000...の剰余を順に計算し、各桁までの剰余を計算
    if i == 0:
        tmp = 1
    else:
        tmp = tmp * 10 % MOD
    rest.append(int(x) * tmp % MOD)

result = [x % MOD for x in list(accumulate(rest))]

# 0は単独で2019の倍数
zero = result.count(0)

result = [x for x in result if x != 0]

# 他はコンビネーションの結果
c = Counter(result)
c = list(c.values())

# 足して出力
print(sum([solve(x) for x in c if x >= 2]) + zero)

Submission status: Wrong Answer

Solution code:
import sys

S = sys.stdin.readline().strip()
ls = len(S)

ans = 0
mod = 2019
for i in range(ls - 4):
    if int(S[i:i+5]) % mod == 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()[::-1]
n=len(s)
p=2019
ans=[0]*p

x10=1
S=0
for i in range(n):
  S=(S+(x10*int(s[i])))%p
  x10=(x10*10)%p
  ans[S]+=1

cnt=ans[0]
for i, a in enumerate(ans):
  if i:
  	cnt+=(a*(a-1))//2
  
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
s = s[::-1]
n = len(s)


rem2019_cnts = [0]*2019
rem2019_cnts[0] = 1
curr_rem = int(s[0])
curr_10_rem = 1
ans = 0
for i,si in enumerate(s[1:]):
    sint = int(si)
    next_10_rem = (curr_10_rem*10)%2019
    next_rem = (next_10_rem*sint + curr_rem)%2019
    ans += rem2019_cnts[next_rem]
    rem2019_cnts[next_rem] += 1
    curr_rem = next_rem
    curr_10_rem = next_10_rem

print(ans)

Submission status: Wrong Answer

Solution code:
s=list(map(int,list(input())))
#print(s)
#modで考える
# 2019100を
# 2019100%2019 と100%1019
#同じmodの組み合わせ

#右から見ていく

mod=[0]*2019

tmp=0
ten=1

#hoge=""

for ii in range(len(s)):
    i=len(s)-ii-1
    if ii==0:
        ten=1
    else:
        ten=(ten*10)%2019

    tmp=((tmp+s[i]*ten)%2019)
    #hoge=str(s[i])+hoge
    #print(tmp,int(hoge)%2019,hoge)
    mod[tmp]+=1

ans=0
for i in range(1,2019):
    ans+=((mod[i]*(mod[i]-1))//2)

ans+=mod[0]

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()[::-1]
n=len(s)
p=2019
ans=[0]*p

x10=1
S=0
for i in range(n):
  S=(S+(x10*int(s[i])))%p
  x10*=10%p
  ans[S]+=1

cnt=ans[0]
for i, a in enumerate(ans):
  if i:
  	cnt+=(a*(a-1))//2
  
print(cnt)

Submission status: Wrong Answer

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

ans = 0
i = 0
while i < l:
    for j in range(i+4, l+1):
        tmp = int(s[i:j])
        print(tmp)
        if tmp % 2019 == 0:
            ans += 1
            i = j-2
            break
    i += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0
i = 0
while i <= l:
    for j in range(i+1, l+1):
        tmp = int(s[i:j])
        if tmp % 2019 == 0:
            ans += 1
            i = j-2
            break
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
ss = str(input())

lenss = len(ss)
if ss[0] == '-':
    ss = ss[1:lenss]

nofcheck = int(200000/2019)
db = [""]*nofcheck

for i in range(nofcheck):
    d = (str(2019*(i+1)))
    db[i] = d
#print(db)

nofmatch = 0
for i in range(nofcheck):
    for j in range(len(ss)-len(db[i])+1):
        if ss[j:j+len(db[i])] == db[i]:
            nofmatch += 1

print(nofmatch)

Submission status: Wrong Answer

Solution code:
ss = str(input())

lenss = len(ss)
if ss[0] == '-':
    ss = ss[1:lenss]

nofcheck = int(200000/2019)
db = [""]*nofcheck

for i in range(nofcheck):
    d = (str(2019*(i+1)))
    db[i] = d
print(db)

nofmatch = 0
for i in range(nofcheck):
    for j in range(len(ss)-len(db[i])+1):
        if ss[j:j+len(db[i])] == db[i]:
            nofmatch += 1

print(nofmatch)

Submission status: Wrong Answer

Solution code:
ss = str(input())

nofcheck = int(200000/2019)
db = [""]*nofcheck

for i in range(nofcheck):
    d = (str(2019*(i+1)))
    db[i] = d

nofmatch = 0
for i in range(nofcheck):
    for j in range(len(ss)-len(db[i])+1):
        if ss[j:j+len(db[i])] == db[i]:
            nofmatch += 1

print(nofmatch)

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

S=input().rstrip()
list2019 =set(range(2019,200001,2019))
cnt = 0
for k in range(4,7):
    for i in range(len(S)-k+1):
        if int(S[i:i+k]) in list2019:
            cnt += 1  
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
S = input()
l = len(S)
d = {0:0}
mod10n = 1
for i in range(1, len(S)+1):
    s = int(S[l-i])
    d[i] = (d[i-1] + s * mod10n) %2019
    mod10n = (mod10n * 10) % 2019
count_d = defaultdict(int)
for key in d.keys():
    count_d[d[key]] += 1
counter = 0
for key in count_d.keys():
    counter += count_d[key] - 1

print(counter)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
S = input()
l = len(S)
d = {0:0}
mod10n = 1
for i in range(1, len(S)+1):
    s = int(S[l-i])
    d[i] = (d[i-1] + s%2019 * mod10n) %2019
    mod10n = (mod10n * 10) % 2019
count_d = defaultdict(int)
for i in range(len(S)+1):
    count_d[d[i]] += 1
counter = 0
for key in count_d.keys():
    counter += count_d[key] - 1
print(counter)

Submission status: Wrong Answer

Solution code:
S = str(input())
N = len(S)
b = [0] * 2019
count = 0
b[0] = 1
t = 0
k = 1

if len(S) < 4:
    print(0)
else:
    t = int(S[-1])
    b[t] += 1
    for i in range(1,N):
        k = k * 10 % 2019
        t = (k * int(S[-i-1]) + t) % 2019 
        b[t] += 1

for i in b:
    count += i*(i-1)//2

print(count)

Submission status: Wrong Answer

Solution code:
S = str(input())
N = len(S)
b = [0] * 2019
count = 0
b[0] = 1
t = 0
k = 1

if len(S) < 4:
    print(0)
else:
    t = int(S[-1])
    b[t] += 1
    for i in range(1,N):
        k = k * 10 % 2019
        t = (k * int(S[-i-1]) + t) % 2019 
        b[t] += 1

for i in b:
    count += i*(i-1)//2

Submission status: Wrong Answer

Solution code:
S = str(input())
N = len(S)
b = [0] * 2019
count = 0
b[0] = 1

for i in range(3,N):
    a = int(S[-i-1:])
    b[a % 2019] += 1

for i in b:
    count += i*(i-1)//2

print(count)

Submission status: Wrong Answer

Solution code:
S = str(input())
N = len(S)
score = 0
itrcounter = 0 # 4桁送り用
firstjAfter = -1 # 最初のjの一個後ろ。ここまでiが来たら走査完了

# if N < 4:
#     print(0)
# else:
#     for i in range(N-3):
#         r = int(S[i:i+4])%2019 
#         if r == 0:
#             count += 1
#         if N > 4:
#             for j in range(i+4, N):
#                 r = (r*10 + int(S[j])) % 2019
#                 if r == 0:
#                     count += 1

if N < 4:
    print(0)
else:
    for reali in range(N-3):
        count = 0
        itrcounter = 0
        # if reali == firstjAfter:
        #     break
        for i in range(reali, N-3):
            if itrcounter > 0:
                itrcounter -= 1
                continue
            r = int(S[i:i+4])%2019 
            if r == 0:
                count += 1
                itrcounter = 3
                if firstjAfter == -1:
                    firstjAfter = i+4 
                continue
            if N > 4:
                for j in range(i+4, N):
                    r = (r*10 + int(S[j])) % 2019
                    if r == 0:
                        count += 1
                        itrcounter = j - i
                        if firstjAfter == -1:
                            firstjAfter = j+1
                        break
                if j == N-1:
                    break            
        score += count*(count+1)//2
            
print(score)

Submission status: Wrong Answer

Solution code:
S = str(input())
N = len(S)
count = 0

if N < 4:
    print(0)
else:
    for i in range(N-3):
        r = int(S[i:i+4])%2019 
        if r == 0:
            count += 1
        if N > 4:
            for j in range(i+4, N):
                r = (r*10 + int(S[j])) % 2019
                if r == 0:
                    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = copy.deepcopy(cnt[0])
for i in range(1,MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * n
cnt = [0] * (MOD)
t = 1
tmp = 0
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    tmp = (tmp + m[i]) % MOD
    msum[i] = copy.deepcopy(tmp)
    cnt[tmp] += 1
    t = t * 10 % MOD

ans = copy.deepcopy(cnt[0])
for i in range(1,MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

ans=0
s=s[::-1]
t=1
ketame=0
amari10=1
kosuu=[1]+[0]*2020
for i in s:
    ketame=(ketame+(int(i)*amari10)%2019)%2019
    amari10*=10
    amari10%=2019
    kosuu[ketame]+=1

for i in range(len(kosuu)):
    if kosuu[i]>0:
        ans+=kosuu[i]*(kosuu[i]-1)/2
    
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0
T = []
for i in range(100):
    t = str(2019 * i)
    T.append(t)
def count(text, part):
    return sum(text.startswith(part, i) for i in range(len(text) + 1))

for t in T:
    cnt += count(S, t)

print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0
T = []
for i in range(100):
    t = str(2019 * i)
    T.append(t)
def count(text, part):
    return sum(text.startswith(part, i) for i in range(len(text)))

for t in T:
    cnt += count(S, t)

print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
l_2019_5 = set()
l_2019_6 = set()

for i in range(6, 50):
    if "0" not in str(2019 * i):
        l_2019_5.add(str(2019 * i))
for i in range(59, 100):
    if "0" not in str(2019 * i):
        l_2019_6.add(str(2019 * i))

ls = len(s)
if ls < 5:
    print(0)
else:
    cnt = sum(s[i : i + 5] in l_2019_5 for i in range(ls - 4))
    cnt += sum(s[i : i + 6] in l_2019_6 for i in range(ls - 5))
    print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
list = []

i = 2019
while i < 200000:
    list.append(str(i))
    i += 2019

a = 0
for i in list:
    if i in s:
        idx = 0
        while idx <= len(s):
            f = s.find(i, idx)

            if f >= 0:
                a += 1
                idx = f + 1
            else:
                break

print(a)

Submission status: Wrong Answer

Solution code:
import collections
s = input()
s_keta = len(s)
dp = [0 for i in range(s_keta+1)]
for i in range(1,s_keta+1):
  dp[i] =  (dp[i-1] + (10 ** (i-1)) * int(s[s_keta - i])) % 2019
print(dp)
#c = collections.Counter(dp)
#result = 0
#for v in c.values():
#  result += v * (v-1) //2
#print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [-1] * len(S)
r = 0
d = 1
for i,s in enumerate(S[::-1]):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[i] = r

ans = 0
c = Counter(p)
for k,n in c.most_common():
  if n > 1:
    ans += 1
  else:break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [-1] * len(S)
r = 0
d = 1
for i,s in enumerate(S[::-1]):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[i] = r

ans = 0
c = Counter(p)
for k,n in c.most_common():
  if n > 1:
    ans += n//2
  else:break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in S[::-1]:
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

ans = 0
c = Counter(p)
for k,n in c.most_common()[::-1]:
  if k > 1 and k%2 == 0:
    ans += n
  else:break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in S[::-1]:
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

ans = 0
c = Counter(p)
for k,n in c.most_common()[::-1]:
  if k > 1:
    ans += n
  else:break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = input()
#S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in S[::-1]:
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

p.append(0)
ans = 0
c = Counter(p)
for k,n in c.most_common():
  if n > 1:
    ans += 1
  else:break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in S[::-1]:
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

p.append(0)
ans = 0
c = Counter(p)
for k,n in c.most_common():
  if n > 1:
    ans += 1
  else:break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = (int(s)%2019) + 1
ans = 0
p = [0] * (n+1)
for i in range(n+1):
  p[i] = (2019 * i)

for j in p:
  ss = s
  while len(ss) > 0:
    idx = ss.find(str(j))
    if idx == -1:
      break
    else:
      ans += 1
      ss = ss[idx+1:]

print(ans)

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list -- START --
def summarizeList(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res
# Summarize count of factor within list --- END ---

def main():
  s=S()
  n=len(s)
  s=s[::-1]

  rl=[0]*(n+1)
  for i,x in enumerate(s):
    rl[i+1]=(int(x)*pow(10,i,2019))%2019

  for i in range(n):
    rl[i+1]+=rl[i]
    rl[i+1]%=2019

  # print(rl[1:])

  sl=summarizeList(rl[1:])

  ans=0
  for x,c in sl:
    if x==0:
      ans+=c

    elif c>1:
      ans+=(c+c-1)//2

  return ans

# main()
print(main())