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()
n = len(s)

l = [0]
for i in range(n):
    l.append(int(s[i:n]) % 2019)

from collections import Counter
dic = Counter(l)

ans = 0
for i in dic.values():
    ans += i * (i - 1) // 2
print(ans)

print(dic)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

  mod = 2019

  counts = [0] * mod

  prev = int(s[-1])
  counts[prev] += 1
  for i in range(2, n + 1):
    t = prev + int(s[-i]) * 10 ** (i - 1)
    counts[t % mod] += 1
    prev = t

  ans = 0
  for count in counts:
    if count > 1:
      ans += count * (count - 1) // 2

  print(ans)

main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

  mod = 2019

  counts = [0] * mod

  prev = int(s[-1])
  counts[prev] += 1
  for i in range(2, n + 1):
    t = prev + int(s[-i]) * 10 ** (i - 1)
    print(t)
    counts[t % mod] += 1
    prev = t

  ans = 0
  for count in counts:
    if count > 1:
      ans += count * (count - 1) // 2

  print(ans)

main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

  mod = 2019

  counts = [0] * mod

  prev = int(s[-1])
  for i in range(2, n + 1):
    t = prev + int(s[-i]) * 10 ** (i - 1)
    counts[t % mod] += 1
    prev = t

  ans = 0
  for count in counts:
    if count > 1:
      ans += count * (count - 1) // 2

  print(ans)

main()

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
A = [str(2019*i) for i in range(1,100)]       
 
count = 0
for j in range(99):
    for i in range(N):
        count += S[i:i+len(A[j])].count(A[j])
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
A = [str(2019*i) for i in range(1,100)]       

count = 0
for j in range(99):
    for i in range(N):
        count += S[i:i+len(A[j])].count(A[j])
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
def solve():
    S = input()
    data = [1] + [0]*2019
    num = 0
    dig = 1

    for i in reversed(S):
        num += int(i)*dig
        num %= 2019
        dig *= 10
        data[num] += 1

    print(sum(i*(i-1)//2) for i in data)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
S = input()

r = 0
_start = 0
_len = len(S)

while _start <= _len:
    f = False
    for i in range(_start + 1, _len + 1):
        t = int(S[_start:i])
        if 1 <= t <= 200000:
            if t % 2019 == 0:
                _start = i  - 1
                r += 1
                f = True
                break
    if not f:
        _start += 1

print(r)

Submission status: Wrong Answer

Solution code:
import numpy as np
def solve():
    S = input()
    dig = len(S)
    data = [1] + [0]*2019

    for i in reversed(range(dig)):
        print(S[i:])
        x = int(S[i:])%2019
        data[x] +=1
    npdata = np.array(data, dtype=np.int32)
    print(np.sum(npdata*(npdata-1)//2))

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
s = input()
u = [0]
for i in range(len(s)):
    u.append((u[i]+int(s[::-1][i])*10**i)%2019)
import collections
u2 = collections.Counter(u)
print(sum([int(i*(i-1)/2) for i in u2.values()]))
print(u)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
r = {}

for i in range(len(S)):
    t = int(S[i:]) % 2019

    if t in r:
        r[t] += 1
    else:
        r[t] = 1

for k in r:
    ans += r[k]*(r[k]-1)//2

print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
t = len(n)
count= 0
for i in range(t):
    for j in range(t+1):
        if(i<j):
            if(int(n[i:j]) % 2019 == 0):
                print(n[i:j])
                count+= 1
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0

for a in range(2019, 200000,2019):
    d = len(str(a))
    if d > len(S):
        break
    for i in range(0, len(S) - d + 1):
        j = i + d
        if int(S[i:j]) == a:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
s = list(S)
for i in range(len(s)):
    s[i] = int(s[i])
p = []
p.append(s[len(s)-1])
for i in range(1,len(s)):
    p.append((p[i-1]+s[len(s)-i-1]*pow(10,i,2019))%2019)
p.sort()
u = 0
for i in range(len(p)):
    if p[i] == 0:
        u = u+1
    else:
        break
r = 1
q = []
for i in range(len(p)-1):
    if p[i] == p[i+1]:
        r = r+1
    else:
        if r > 1:
            q.append(r)
            r = 1
w = 0
for i in range(len(q)):
    w = w + int(q[i]*(q[i]-1)/2)
print(w+u)

Submission status: Wrong Answer

Solution code:
s = str(input())
n=len(s)
left :int=1
mlist=[0]
while left<int(n)+1:
  m = int(s[n-left:n])%2019
  mlist.append(m)
  left+=1

#ll=len(mlist)
#l=len(set(mlist))
print(len(mlist))

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
list=[]
for i in range(n-3):
    for j in range(i+3,n):
        if int(s[i:j])%2019==0:
            list.append(s[i:j])
print(len(list))

Submission status: Wrong Answer

Solution code:
S = str(input())

def main(S):
    count = 0
    a = len(S)
    
    for i in range(a):
        for j in range(i,a):
            if int(S[i:])%2019 == int(S[j:])%2019:
                count += 1
    print(count)
if __name__ == '__main__':
    main(S)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def main():
    from functools import reduce
    import collections
     
    S = list(map(int,input().rstrip()))
    N=len(S)
    mod_list = [0]
    for i in range(1,N+1):
        new1 =pow(10,i-1,2019)
        new = (new1*S[-i]+mod_list[-1])%2019
        print(new)
        mod_list.append(new)
        
    count = collections.Counter(mod_list)
    ans =0
    for j in range(2019):
        n = count[j]
        ans+= n*(n-1)/2
    print(int(ans))
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

if __name__ == '__main__':
    MOD = 2019
    strS = input()
    S = [int(s) for s in strS]
    N = len(S)

    mods = defaultdict(int)
    pow10_mod = 1
    prv_mod = 0
    for idx, s in enumerate(S[::-1]):
        tmp_mod = (prv_mod + s * pow10_mod) % MOD

        mods[tmp_mod] += 1
        pow10_mod = (pow10_mod * 10) % MOD
        prv_mod = tmp_mod

    ans = 0
    for key, value in mods.items():
        if value >= 2:
            ans += value * (value - 1) // 2
        elif key == 0:
            ans += 1

    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
S = input()
a = []
num = 0
for i,j in enumerate(S[::-1]):
    num += int(j)*(pow(10,i,2019))
    a.append(num%2019)

print(a)
A = collections.Counter(a)
print(A)

ans = 0
for i in A.values():
    if i>=2:
        ans += int(i*(i-1)/2)

ans += A[0]
print(ans)

Submission status: Wrong Answer

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

mod = 2019
t = 0
dic = defaultdict(int)
ans = 0
for l in range(L+1):
    t += pow(10, l)*int(S[-l])
    i = t%mod
    dic[i] += 1
    if i==0:
        ans += 1

for k in dic.keys():
    num = dic[k]
    ans += num*(num-1)//2

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from collections import defaultdict

if __name__ == '__main__':
    MOD = 2019
    strS = input()
    S = [int(s) for s in strS]
    N = len(S)

    mods = defaultdict(int)
    pow10 = 1
    for idx, s in enumerate(S[::-1]):
        if idx == 0:
            tmp_mod = s ** pow10 % MOD
        else:
            tmp_mod = (prv_mod + s * pow10) % MOD
        mods[tmp_mod] += 1

        pow10 = (pow10 * 10) % MOD
        prv_mod = tmp_mod

    ans = 0
    for key, value in mods.items():
        if value >= 2:
            ans += value * (value - 1) // 2
        elif key == 0:
            ans += 1
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

MOD = 18001

def solve(S):
    dp = np.zeros(MOD, np.int64)
    temp = np.empty_like(dp)
    pow10 = 1
    answer = 0
    for x in S[::-1]:
        dp[0] += 1
        x = x * pow10 % MOD
        temp[x:] = dp[:-x]
        temp[:x] = dp[-x:]
        dp, temp = temp, dp
        answer += dp[0]
        pow10 *= 10
        pow10 %= MOD
    return answer


def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i4[:],)')(solve)
    cc.compile()


try:
    from my_module import solve
except:
    cc_export()
    exit()

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

Submission status: Wrong Answer

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

MOD = 20001

def solve(S):
    dp = np.zeros(MOD, np.int64)
    temp = np.empty_like(dp)
    pow10 = 1
    answer = 0
    for x in S[::-1]:
        dp[0] += 1
        x = x * pow10 % MOD
        temp[x:] = dp[:-x]
        temp[:x] = dp[-x:]
        dp, temp = temp, dp
        answer += dp[0]
        pow10 *= 10
        pow10 %= MOD
    return answer


def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i4[:],)')(solve)
    cc.compile()


try:
    from my_module import solve
except:
    cc_export()
    exit()

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

Submission status: Wrong Answer

Solution code:
import numpy as np

Submission status: Wrong Answer

Solution code:
s = input()

div = int(200000/2019)

ret = 0
for i in range(1, div+1):
    l = len(str(i*2019))
    for j in range(len(s)):
        if j+l == len(s)+1:
            break
        if s[j:j+l] == str(i*2019):
            ret += 1
print(ret)

Submission status: Wrong Answer

Solution code:
s = str(input())
sum_of_digits = 0
cnt = 0
for c in s:
    sum_of_digits *= 10
    sum_of_digits += int(c)
    sum_of_digits %= 2019
    if sum_of_digits == 0:
        cnt += 1
        sum_of_digits = int(c)
        
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
S = input()
N = len(S)
M = [0]
for i in range(N):
  M.append(int(S[:i+1] + '0' * (N-1-i)) % 2019)
count = collections.Counter(M)
print(count)
print(sum([c*(c-1)//2 for c in count.values()]))

Submission status: Wrong Answer

Solution code:
s = input()

div = int(200000/2019)

ret = 0
for i in range(1, div+1):
    l = len(str(i*2019))
    for j in range(len(s)-l+1):
        if s[j:j+l] == str(i*2019):
            ret += 1
print(ret)

Submission status: Wrong Answer

Solution code:
S = list(input())
S.reverse()
amari = []
A = 0
c = 0
for i in range(len(S)):
    a = (int(A) + int(S[i]) *(10 ** i)) % 2019
    amari.append(a)
    A = a
print(c + len(amari) - len(set(amari)))

Submission status: Wrong Answer

Solution code:
s = input()

div = int(200000/2019)

ret = 0
for i in range(1, div+1):
  if str(i*2019) in s:
    ret += 1
print(ret)

Submission status: Wrong Answer

Solution code:
S = input()

mods = [0 for _ in range(2019)]

num = 0
for itr, s in enumerate(S[::-1]):
  num = int(s) * 10 ** itr + num
  mo = num % 2019
  mods[mo] += 1

ans = 0
for m in mods:
  ans += m * (m - 1) // 2

print(ans)

Submission status: Wrong Answer

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

count=[0]*2019
t=int(s[0])%2019
count[t]+=1

gh=0
for i in range(0,len(s)):
    gh+=int(s[i])*(10**i)
    count[gh%2019]+=1

ans=0

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

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

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

print(m)

Submission status: Wrong Answer

Solution code:
s = list(input())

count = 0
for i in range(1,len(s)):
    for j in range(i+3,len(s)):
        if int(''.join(s[i:j]))%2019==0 and int(''.join(s[i:j])) > 2019:
            count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
s = list(input())

count = 0
for i in range(1,len(s)):
    for j in range(i+3,len(s)):
        if int(''.join(s[i:j]))%2019==0:
            count += 1
        
print(count)

Submission status: Wrong Answer

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

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

s = S()
N = len(s)

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

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

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

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

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

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

"""
201920192019
"""

Submission status: Wrong Answer

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

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

s = S()
N = len(s)

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

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

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

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

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

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

"""
201920192019
"""

Submission status: Wrong Answer

Solution code:
s = input()

ch = 0
x = 1

rem = [0] * 2019

for c in reversed(s):
    ch += int(c) * x
    x = x * 10 % 2019
    rem[ch % 2019] += 1

print(sum(a * (a - 1) // 2 for a in rem) + 1)

Submission status: Wrong Answer

Solution code:
from queue import deque
 
    
S = deque(input())
y = 2019
U = [0] * y
t = int(S.pop())
U[0] = 1
k = 10

for s in reversed(S):
    t = t + int(s) * k
    t %= y
    U[t] += 1
    k *= 10
    k %= y

cnt = 0
for u in U:
    cnt = cnt + u * (u - 1) // 2

print(cnt)

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
b = {}
b[0] = 1
c_ = 0
ans = 0
s.reverse()
for i in s:
  c = (c_+int(i))%2019
  if c in b:
    ans += b[c]
    b[c] += 1
  else:
    b[c] = 1
  c_ = c
print(ans)

Submission status: Wrong Answer

Solution code:
#create date: 2020-04-26 21:06

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    s = ns()
    n = len(s)
    now = 0
    m = [0] * 2019
    for i in range(n):
        now = (now + int(s[n-i-1]) * pow(10, i, 2019)) % 2019
        #print(now)
        m[now] += 1
    ans = m[0]
    for mi in m[1:]:
        ans += (mi-1) * mi //2
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
a = [0]
b = [0]*2019
for num,i in enumerate(reversed(s)):
  a.append(a[num]+int(i)*10**num)
  b[(a[num]+int(i)*10**num)%2019] += 1
ans = 0
for i in b:
  ans += i*(i-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
data = [0]
l = len(s)
T = 0
for i in reversed(range(l)):
  T += int(l)
  data.append(T%2019)
  T *= 10
 
print(data)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
p = 2019
s = input()
n = len(s)
dd = defaultdict(int)
digits = 0
remainder = 0
for i in reversed(range(n)):
    x = (remainder+int(s[i])*pow(10, digits, p)) % p
    dd[x] += 1
    remainder = x
    digits += 1
ans = 0
for k, v in dd.items():
    if k == 0 and v == 1:
        ans += 1
    else:
        ans += v*(v-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

n = len(s)
amari = [0] * 2019
amari[0] += 1
tmp = ""
for i in range(1, n + 1):
    tmp = s[-i] + tmp
    amari[int(tmp) % 2019] += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()

n = len(s)
amari = [0] * 2019
amari[0] += 1

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

Submission status: Wrong Answer

Solution code:
S = input()
n = len(S)
res = 0
pre = 0
dp = [0] * 2019
dp[0] = int(S[0])
for i in range(1, n):
    d = int(S[i])
    tdp = [0] * 2019
    tdp[d] = 1
    for j in range(2019):
        if dp[j] > 0:
            rem = (10 * j + d) % 2019
            if rem == 0:
                res += dp[j]
            tdp[rem] += dp[j]
    for j in range(2019):
        dp[j] = tdp[j]

print(res)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 0
T = []
for i in range(N):

    T.append(int(S[i : N]) % 2019)
T.sort()
t = set(T)
counted = []
for i in t:
    a = T.count(i)
    if a > 1:
        counted.append(a)
for i in counted:
    ans += i * (i - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s = input()

l = [int(s[-1])]
d = 10
for i in range(len(s)-1, -1, -1):
  l.append((l[-1] + int(s[i])*d) % 2019)
  d *= 10
  d %= 2019

d = collections.Counter(l)
count = 0  
for i in d:
  count += d[i]*(d[i]-1)//2

count += d[0]

print(count)

Submission status: Wrong Answer

Solution code:
import collections
s = input()

l = [int(s[-1])]
d = 1
for i in range(len(s)-1, -1, -1):
  l.append((l[-1] + int(s[i])*d) % 2019)
  d *= 10
  d %= 2019

d = collections.Counter(l)
count = 0  
for i in d:
  count += d[i]*(d[i]-1)//2

count += d[0]

print(count)

Submission status: Wrong Answer

Solution code:
import collections
s = input()

l = [int(s[-1])]
d = 1
for i in range(len(s)-1, -1, -1):
  print(i)
  l.append((l[-1] + int(s[i])*d) % 2019)
  d *= 10
  d %= 2019

d = collections.Counter(l)
count = 0  
for i in d:
  count += d[i]*(d[i]-1)//2

count += d[0]

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

S = input()
N = len(S)

dp = [0] * N
dp[N-1] = int(S[N-1])
times = 10
for i in reversed(range(N-1)):
    dp[i-1] = (dp[i] + times * int(S[i-1])) % 2019
    times *= 10
    times %= 2019

T = Counter(dp)
ans = T[0]
for t in T.values():
    ans += t*(t-1)//2

print(ans)

Submission status: Wrong Answer

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

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
        t %= 2019

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
S = list(input())[::-1]
n = len(S)
d = defaultdict(int)
d[0] += 1
res = 0
for i, s in enumerate(S):
    res += int(s)*pow(10, i, 2019)
    res %= 2019
    d[res] += 1
print(d)

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
S = list(input())[::-1]
n = len(S)
d = defaultdict(int)
d[0] += 1
res = 0
for i, s in enumerate(S):
    res += int(s)*pow(10, i, 6)
    res %= 6
    d[res] += 1

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

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

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

Solution code:
s = input()
n = len(s)
s_cu = [0] * (n+1)
counter = [0] * 2019
counter[0] += 1

for i in range(n):
    s_cu[i+1] = (int(s[n-i-1]) + s_cu[i]) % 2019
    counter[s_cu[i] % 2019] += 1

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

print(ans)

Submission status: Wrong Answer

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
        else:
            dd = 10 ** (k - j)
            if ((n - (aa * bb) - (n - (cc * dd))) // dd) % 2019 == 0:
                    c = c + 1
print(c)

Submission status: Wrong Answer

Solution code:
t=1;p=0;m=2019;c=[0]*m;r=0
for x in (input()+'0')[::-1]:p=(int(x)*t+p)%m;r+=c[p];c[p]+=1;t=t*10%m
print(r%m)

Submission status: Wrong Answer

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

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=x//10

Submission status: Wrong Answer

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])

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
s_cu = [0] * n
counter = [0] * 2019

for i in range(1, n+1):
    s_cu[i-1] = int(s[n-i:]) 
    counter[int(s[n-i-1:]) % 2019] += 1
print(s_cu)

#diff
counter[0]+=1
#diff end


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

#print([i for i in counter if i>1])
#print(counter[0])

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
s_int=[0]*n
x=pow(10,n-1)

Submission status: Wrong Answer

Solution code:
print(len(set(open(0).read().split()))-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
d = {}
ans = 0
cnts = [0] * 2019
digit = int(s) % 2019
cnts[0] = 1
for i in range(len(s)):
    digit = int(s[i:]) % 2019
    cnts[digit] += 1
    # print(cnts[digit])
for cnt in cnts:
    ans += cnt

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
s_cu = [0] * n
counter = [0] * 2019

for i in range(1, n+1):
    s_cu[i-1] = int(s[n-i:]) 
    counter[int(s[n-i-1:]) % 2019] += 1

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
string=input()
length=len(string)
mod=[0]*2019
while length > 0:
  mod[int(string[length-1:])%2019]+=1
  length-=1
print(int(sum([(i*(i-1))/2 for i in mod])))