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)

modlist = [0] * 2019
num = 0
mods = 1

for i in range(n):
    fig = int(S[n - i - 1])
    mods = mods % 2019
    num = (num + fig * mods) % 2019
    modlist[num] = modlist[num] + 1
    mods = mods * 10

result = 0
if modlist[0] > 0:
    result += 1

for i in range(2019):
    m = modlist[i]
    if m != 0:
        result += m * (m - 1) / 2

print(int(result))

Submission status: Wrong Answer

Solution code:
S = input()

n = len(S)

modlist = [0] * 2019
num = 0
mods = 1

for i in range(n):
    fig = int(S[n - i - 1])
    mods = mods % 2019
    num = (num + fig * mods) % 2019
    modlist[num] = modlist[num] + 1
    mods = mods * 10

result = 0
if modlist[0] > 0:
    result += 1

for i in range(2019):
    m = modlist[i]
    if n != 0:
        result += m * (m - 1) / 2

print(int(result))

Submission status: Wrong Answer

Solution code:
from collections import Counter

# print('input >>')

S = input()
S = S[::-1]

mods = [0] * (len(S)+1)
mods[0] = int(S[0]) % 2019

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

print(mods)

ans = 0

counter = Counter(mods)

for c, n in counter.most_common():
    if n > 1:
        ans += (n * (n-1)) // 2

# print('-----output-----')

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = sys.stdin.readline()

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

print(cnt)

Submission status: Wrong Answer

Solution code:
s_str = input()
# print(s_str)
# print(type(s_str))
# print()

s_int = int(s_str)
# print(s_int)
# print(type(s_int))
# print()

s_len = len(s_str)
# print(s_len)
# print(type(s_len))
# print()

list = []

for i in range(len(s_str)):
  s_new = s_str[0]
  while i < len(s_str):
    if int(s_new) % 2019 == 0:
      # print('i=' + str(i))
      # print(s_new)
      # print('2019 * n number.')
      list.append(s_new)
    i = i + 1
    if i == s_len:
      break
    else:
      s_new = s_new + s_str[i]

# print(list)
print(len(list))

Submission status: Wrong Answer

Solution code:

s=list(input())[::-1] # 10進数で位を上げていくために反転させる
n=len(s)
amari_lis=[0]*2019 # 
amari_lis[0]=1 # 2019で割り切れる場合、組合せ総数は (n+1)C2 となるため（その他はnC2でOK）

num=0
kurai=1
for keta in s:
    num+=int(keta)*kurai
    num%=2019
    amari_lis[num]+=1
    kurai*=10
    kurai%=2019 # amari_lisが 0~2019 のため、位の数も 2019 で割った余りで考える

ans=0
for i in amari_lis:
    ans+=i*(i-1)/2 # nC2の計算, 余りが同じものを引けば 0⇒2019で割れると言える（組合せ数を逐次追加することで総数算出）

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

len_S = len(S)

ans_count = 0

if len_S <= 4:
    if int(S)%2019 == 0:
        ans_count += 1
else:
    for i in range(0, len_S+1):
        pass_flag = False
        for j in range(i+4, len_S+1):
            if not pass_flag:
                if int(S[i:j])%2019 == 0:
                    ans_count += 1
                else:
                    pass_flag = True

print(ans_count)

Submission status: Wrong Answer

Solution code:
S = input()
from collections import defaultdict
d = defaultdict(int)

for i in range(1, 1+len(S)):
  d[int(S[-i:]) % 2019] += 1

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
t = [0] * l
t[l - 1] = int(s[l - 1])
m = [0] * 2019
m[0] = 1
ten = 10
ans = 0

for i in range(l - 1, 0, -1):
    t[i - 1] = (t[i] + int(s[i - 1]) * ten) % 2019
    ten = ten * 10 % 2019
    m[t[i - 1]] += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
t = [0] * l
t[l - 1] = int(s[l - 1])
m = [0] * 2019
m[0] = 1
ten = 10
ans = 0

for i in range(l - 1, 0, -1):
    t[i - 1] = (t[i] + int(s[i - 1]) * ten) % 2019
    ten = ten * 10 % 2019
    ans += m[t[i - 1]]
    m[t[i - 1]] += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
t = [0] * l
t[l - 1] = int(s[l - 1])
m = [0] * 2019
ten = 10
ans = 0

for i in range(l - 1, 0, -1):
    t[i - 1] = (t[i] + int(s[i - 1]) * ten) % 2019
    ten = ten * 10 % 2019
    ans += m[t[i - 1]]
    m[t[i - 1]] += 1
    if t[i - 1] == 0:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
t = [0] * l
t[l - 1] = int(s[l - 1])
m = [0] * 2019
ten = 10
ans = 0

for i in range(l - 1, 0, -1):
    t[i - 1] = (t[i] + int(s[i - 1]) * ten) % 2019
    ten = ten * 10 % 2019
    ans += m[t[i - 1]]
    m[t[i - 1]] += 1
    if t[i - 1] == 0:
        ans += 1

print(t, ans)

Submission status: Wrong Answer

Solution code:
def main():
  a = input()
  res = 0
  
  for i in range(1, (len(a)+1)):
    if int(a[len(a)-i:]) % 2019 == 0:
      res += 1
  print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = list(input()[::-1])
mod = 2019
tot = [0]
for i in range(len(s)):
    tot.append((tot[i] + (int(s[i])*(10**i))%mod)%mod)
dp = [0 for _ in range(2020)]
ans = 0
for t in tot[1:]:
    ans += dp[t]
    dp[t]+= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def get_modulos():
    modulos = []
    for i in range(224):
        modulos.append(10**i%2019)
    return modulos

def count_substring(s):
    found_remainder = defaultdict(int)
    current_mod = 0
    found_remainder[0] = 1

    output = 0

    modulos = get_modulos()
    for i in range(len(s)-1,-1,-1):
        digit = s[i]
        current_mod =  (int(digit)*modulos[(len(s)-1-i)%224] % 2019 + current_mod) % 2019
        # print(i, current_mod)
        output += found_remainder[current_mod]
        found_remainder[current_mod] += 1
    print(dict(found_remainder))

    return output

s = input()
print(count_substring(s))

Submission status: Wrong Answer

Solution code:
import re
from collections import Counter
S = input()
res = []
for i in range(1, len(S)+1):
    res.append(int(S[-i:]) % 2019)
counter = Counter(res)
ans = 0
for value, c in counter.items():
    ans += c * (c-1)/2
print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def count_substring(s):
    found_remainder = defaultdict(int)
    current_mod = 0
    found_remainder[0] = 1

    output = 0
    for i in range(len(s)-1,-1,-1):
        digit = s[i]
        current_mod =  (int(digit)*10**(len(s)-1-i) % 2019 + current_mod) % 2019
        print(i, current_mod)
        output += found_remainder[current_mod]
        found_remainder[current_mod] += 1

    return output

s = input()
print(count_substring(s))

Submission status: Wrong Answer

Solution code:
# ABC164 D - Multiple of 2019 - numpy ver. 更に改良ver.
import numpy as np

s = input()[::-1]
length = len(s)
a = np.zeros(length, dtype=int)
d = np.zeros(length, dtype=int)
ans = np.zeros(2019, dtype=int)
x = 1

a[0] = int(s[0])
d[0] = a[0]
ans[0] = 1
ans[d[0]] += 1

for i in range(1, length):
    a[i] = int(s[i]) * x % 2019
    d[i] = (d[i-1] + a[i]) % 2019
    ans[d[i]] += 1
    x = x * 10 % 2019

print(int(sum([ans[i] * (ans[i]-1) for i in range(2019)]) / 2))

Submission status: Wrong Answer

Solution code:
# 解説AC
S = input()
N = len(S)

cnt = [0] * 2019

ans = 0
for i in range(N - 1, -1, -1):
    ans += cnt[int(S[i:N]) % 2019]
    cnt[int(S[i:N]) % 2019] += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
a = int(s)%2019
mods = [0]*2019
mods[a] += 1
d = 10**(len(s)-1)
for i in s:
  a = (a-int(i)*d)%2019
  d = d//10%2019
  mods[a] += 1
ans = 0
for i in mods:
  ans += i*(i-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def main():
  s = input()
  
  current_mod = 0
  output = 0
  found_remainder = defaultdict(int)
  for i, digit in enumerate(s):
    current_mod = (current_mod*10 + int(digit)) % 2019
    output += found_remainder[current_mod]
    found_remainder[current_mod] += 1
  return output

Submission status: Wrong Answer

Solution code:
s = input()
a = int(s)
mod_N = [0]*2019
mod_N[a%2019] += 1
for i in range(len(s)):
  a = a-int(s[i])*10**(len(s)-i-1)
  mod_N[a%2019] += 1
ans = 0
for i in mod_N:
  ans += mod_N[i]*(mod_N[i]-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
a = int(s)
mod_N = [0]*2019
mod_N[a%2019] += 1
for i in range(len(s)):
  a = a-int(s[i])*10**(len(s)-i-1)
  mod_N[a%2019] = 1
ans = 0
for i in mod_N:
  ans += mod_N[i]*(mod_N[i]-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

n = len(S)
m = 2019

S_ = S[::-1]

x = 1
total = 0
modlis = [0 for i in range(m)]

ans = 0
for i in range(n):
    modlis[total] += 1
    print("S_[i]:", S_[i])
    print("int(S_[i])*x:", int(S_[i])*x)
    print("total:", total)
    total += int(S_[i])*x
    print("total:", total)
    total %= m
    print("total:", total)
    ans += modlis[total]
    print("x:", x)
    x = x * 10 % m
    print("x:", x)

print(ans)

Submission status: Wrong Answer

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

for i in range(0, n+1):
  ss =  int(s[i:n+1]) if s[i:n+1].isdigit() else 0
  print(ss)
  m.append(ss % 2019)

u = set()
ct = 0
for mm in m:
  if mm not in u:
    u.add(mm)
  else:
    ct += 1
    
print(ct)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

s = input()[::-1]
length = len(s)
a = np.zeros(length, dtype=int)
d = np.zeros(length, dtype=int)
ans = np.zeros(2019, dtype=int)

for i in range(length):
    if i == 0:
        a[i] = int(s[i])
        d[i] = a[i]
    else:
        a[i] = int(s[i]) * pow(10, i) % 2019
        d[i] = (d[i-1] + a[i]) % 2019
        ans[d[i]] += 1

print(int(sum([ans[i] * (ans[i]-1) for i in range(1, ans.shape[0])]) // 2))

Submission status: Wrong Answer

Solution code:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit


@njit()
def loof(S,N):
    M = np.zeros(2019,dtype=np.int16)
    M[0] += 1
    T = 0
    r = 1
    for i in range(N):
        T = S[N-i-1] * r + T
        a = T % 2019
        M[a] += 1
        r *= 10
    return M


def main():
    S = input().rstrip()
    S = list(map(int,list(S)))
    S = np.array(S)

    N = len(S)

    M = loof(S,N)

    res = 0

    for m in M:
        res += m * (m-1) // 2


    print(res)


# print(S)

main()

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
mod = 2019
cnt = [0] * mod
x = 1
cnt[0] = 1
total = 0
for s in s:
    total = int(s) * x
    total %= mod
    cnt[total] += 1
    x *= 10

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

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
m = 2019
ans = 0
x = 1
tot = 0
cnt = [0] * m
for s in s:
    cnt[tot] += 1
    tot += int(s) * x
    tot %= m
    #ans += cnt[tot]
    x *= 10
    x %= m

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

Submission status: Wrong Answer

Solution code:
s=list(map(int,list(input())))[::-1]

n=len(s)
D=[0]*(n+1)
c=[0]*(n+1)
c[0] = D[0]
# print(s)
for e,i in enumerate(s):
    D[e]= i*pow(10,e)%2019
    if e==0:continue
    c[e] = (c[e-1] + D[e])%2019

ans = 0
f = 0
dp = [0]*(2020)
for e,i in enumerate(c):
    ans +=dp[i]
    dp[i]+=1
print(ans)

Submission status: Wrong Answer

Solution code:
s=list(map(int,list(input())))[::-1]

n=len(s)
D=[0]*(n+1)
c=[0]*(n+1)

# print(s)
# print(D)
S = s[0]
c[0] = S
for e,i in enumerate(s):
    if e==0:continue
    c[e] = (S)%2019
    S = i*pow(10,e)+S
# print(c)
ans = 0
f = 0
dp = [0]*(2020)
for e,i in enumerate(c):
    ans +=dp[i]
    dp[i]+=1
print(ans)

Submission status: Wrong Answer

Solution code:
number = str(input())[::-1]
remainderDictionary = {0: 1}
digitDictionary = {'1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}

sum = 0
x = 1
for i in number:
  x = (x * 10) % 2019
  sum = (sum + digitDictionary[i] * x) % 2019 
  remainderDictionary[sum] = remainderDictionary.get(sum,0) + 1

ansDictionary = {} # dictionary with the number of occurences and the corresponding N combinations of 2
ans = 0
for i in remainderDictionary:
  remainderOccurences = remainderDictionary[i]
  value = ansDictionary.get(remainderOccurences,-1)
  if value == -1:
    value = remainderOccurences * (remainderOccurences - 1) // 2 # N combinations of 2
    ansDictionary[i] = value
  ans += value
print(ans)

Submission status: Wrong Answer

Solution code:
number = str(input())[::-1]
remainderDictionary = {0: 1}
digitDictionary = {'1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}

sum = 0
x = 1
for i in number:
  x = (x * 10) % 2019
  sum = (sum + digitDictionary[i] * x) % 2019 
  remainderDictionary[sum] = remainderDictionary.get(sum,0) + 1

ansDictionary = {} # dictionary with the number of occurences and the corresponding N combinations of 2
ans = 0
for i in remainderDictionary:
  remainderOccurences = remainderDictionary[i]
  value = ansDictionary.get(remainderOccurences,-1)
  if value == -1:
    ansDictionary[i] = remainderOccurences * (remainderOccurences - 1) // 2 # N combinations of 2
    value = ansDictionary[i]
  ans += value
print(ans)

Submission status: Wrong Answer

Solution code:
number = str(input())[::-1]
remainderDictionary = {0: 1}
digitDictionary = {'1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}

sum = 0
x = 1
for i in number:
  x = (x * 10) % 673
  sum = (sum + digitDictionary[i] * x) % 673 
  remainderValue = remainderDictionary.get(sum,0) + 1
  remainderDictionary[sum] = remainderValue
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  if value > 1:
    ans += value * (value - 1) // 2 # N C 2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,bisect,math
sys.setrecursionlimit(15000)

s = sys.stdin.readline().rstrip()
cum = [0]*(len(s)+1)#cumulative sum
import collections
d = collections.defaultdict(int)
d[0] = 1
ret = 0
dig = 1
for i in range(len(s))[::-1]:
    cum[i]=(int(s[i])*dig+cum[i+1])%2019
    dig == (dig*10)%2019
    #cum[i+1]=int(s[i:])%2019
    if cum[i] in d:
        ret += d[cum[i]]
    d[cum[i]] += 1
#print(d,cum,ret)
print(ret)

Submission status: Wrong Answer

Solution code:
number = str(input())[::-1]
remainderDictionary = {}
    
sum = 0
x = 1
for i in number:
  sum += int(i) * x
  remainder = sum % 2019
  remainderValue = remainderDictionary.get(remainder,0) + 1
  remainderDictionary[remainder] = remainderValue
  x = (x * 10) % 2019
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  ans += value * (value - 1) // 2 # N C 2
print(ans)

Submission status: Wrong Answer

Solution code:
S = str(input())
Surpus = [0] * 2019
Surpus[0] = 1

sum = 0
x = 1
for i in S:
  sum += int(i) * x
  Surpus[sum % 2019] += 1
  x *= 10
  x %= 2019

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

Submission status: Wrong Answer

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

S=[0,]
cnt=[0]*2019
cnt[0]=1
d=1
num=0
for i in range(len(s)):
    num += int(s[i])*d
    num %= 2019
    d *= 10
    d%= 2019
    # S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[num]+=1

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

Submission status: Wrong Answer

Solution code:
S = str(input())
remainderDictionary = {0: 1}
    
sum = 0
x = 1
for i in S:
  sum += int(i) * x
  remainder = sum % 2019
  remainderValue = remainderDictionary.get(remainder,0) + 1
  remainderDictionary[remainder] = remainderValue
  x *= 10
  x %= 2019
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  ans += value * (value - 1) // 2 # N C 2
print(ans)

Submission status: Wrong Answer

Solution code:
S = str(input())
remainderDictionary = {}
    
sum = 0
x = 1
for i in S:
  sum += int(i) * x
  remainder = sum % 2019
  remainderValue = remainderDictionary.get(remainder,0) + 1
  remainderDictionary[remainder] = remainderValue
  x *= 10
  x %= 2019
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  ans += value * (value - 1) // 2 # N C 2
print(ans)

Submission status: Wrong Answer

Solution code:
S = str(input())
remainderDictionary = {}
    
sum = 0
x = 1
for i in S:
  sum += int(i) * x
  remainder = sum % 2019
  remainderValue = remainderDictionary.get(remainder,0) + 1
  remainderDictionary[remainder] = remainderValue
  x = (x * 10) % 2019
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  ans += value * (value - 1) // 2 # N C 2
print(ans)

Submission status: Wrong Answer

Solution code:
S = str(input())
n = int(S) // 10 + 1
count = 0
list_a = [str(2019 * i) for i in range(1,101)]
if n < 4 : 
  print(count)
else:
  for i in range(n-3):
    for j in range(i+4, n+1):
      if S[i:j] in list_a : count += 1
print(count)

Submission status: Wrong Answer

Solution code:
S = str(input())
n = int(S) // 10 + 1
count = 0
list_a = [str(2019 * i) for i in range(1,101)]
if n < 4 : 
  print(count)
else:
  for i in range(n-2):
    for j in range(i+4, n+2):
      if S[i:j] in list_a : count += 1
print(count)

Submission status: Wrong Answer

Solution code:
S = int(input())
print(S//2019)

Submission status: Wrong Answer

Solution code:
string = str(input())
n = 0
limit = len(string)-4
secondLimit = len(string)
size = len(string)-1
potencys = [0] * 1500 
potencys.append(1)
thirdLimit = size
for i in range(size, 2, -1):
  intValue = int(string[i])
  potencyIndex = 0
  thirdLimit -= 1
  for j in range(thirdLimit, -1, -1):
    potencyIndex += 1
    if potencyIndex >= len(potencys):
      potencys.append(potencys[-1]*10)
    intValue += int(string[j])* potencys[potencyIndex]
    if i-j > 2 and intValue % 673 == 0:
      n += 1
print(n)

Submission status: Wrong Answer

Solution code:
S = input()

X = [0]*2019
X[0] = 1
d = 1
a = 0

for s in reversed(S):
    a = ((ord(s) - ord('0'))*d + a)%2019
    d = d*10%2019
    print(a)
    X[a] += 1

ans = sum(x*(x-1)//2 for x in X)
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
a = ""
count = 0
for i in range(len(s)):
    a += s[i]
    if int(a) % 2019 == 0:
        count += 1
        a = s[i]

print(count)

Submission status: Wrong Answer

Solution code:
S = list(map(str,input().split()))
counter = 0
for i in range(len(S)-4):
  for j in  range(i+4,len(S)):
    part_S = list[S[i]:S[j]]
    ps = "".join(part_S)
    if int(ps) % 2019 ==0:
           counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
s = input()
table = [0 for i in range(len(s)+1)]
i = 1
d = 1
for c in s[::-1]:
    table[i] = (d * int(c) + table[i-1]) % 2019
    i += 1
    d *= 10

ans =  len(s) + 1 - len(set(table))
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def naive(s):
	cnt = 0
	for i in range(len(s)):
		for j in range(i + 1, len(s) + 1):
			k = int(s[i:j])
			if k % 2019 == 0 and k != 0:
				#print(i, j)
				cnt += 1
	return cnt

def main(s):
	nums = [(int(s[len(s) - i - 1]) * (10 ** i)) % 2019 for i in range(len(s))]
	# nums = [0] + [x % 2019 for x in np.cumsum(nums)]
	# d = dict(collections.Counter(nums))
	# a = [val for key, val in d.items() if val >= 2]
	# return sum([comb(x, 2) for x in a])

s = input()
print(main(s))

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def naive(s):
	cnt = 0
	for i in range(len(s)):
		for j in range(i + 1, len(s) + 1):
			k = int(s[i:j])
			if k % 2019 == 0 and k != 0:
				#print(i, j)
				cnt += 1
	return cnt

def main(s):
	nums = [(int(s[len(s) - i - 1]) * (10 ** i)) % 2019 for i in range(len(s))]
	# nums = [0] + [x % 2019 for x in np.cumsum(nums)]
	# d = dict(collections.Counter(nums))
	# a = [val for key, val in d.items() if val >= 2]
	# return sum([comb(x, 2) for x in a])

s = input()
print(main(s))

Submission status: Wrong Answer

Solution code:
def comb(S ,div=2019):
    
    result = set()
    length = len(str(div))
    divs = []
    times = 0
    while True:
        tmp = div * times
        divs.append(tmp)
        if len(str(tmp)) >= length * 2:
            break
        times += 1

    for div in divs:
        sdiv = str(div)
        i = S.find(sdiv)        
        while 0 <= i < len(S):
            result.add((i+1, i + len(sdiv)+ 1))
            for j in range(1, length + 1):    
                s = S[i+j]
                if s == "0":
                    result.add((i+1, i + len(sdiv) + 1 + j))
                else:
                    break
            i = S.find(sdiv, i+1)

    return result

def slow_comb(S, div=2019):
    result = set()
    i = 0
    for i in range(len(S)):
        for j in range(len(S[i:])):
            s = int(S[i:i+j+1])
            if s % div == 0:
                result.add((i+1,i+j+1))
            j += 1

    return result


def main():
    S = input()

    pairs = comb(S)

    print(len(pairs))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def isMultipleOf2019(s):
    return 0 == int(s) % 2019


def cal(s):
    if s not in memo:
        memo[s] = isMultipleOf2019(s)
    return memo[s]


# def inMemo(s):
#     return s in ok


def main():
    S = input().strip()
    count = 0
    for j in range(len(S)+1):
        for i in range(j-3):
            count += 1 if cal(S[i:j]) else 0
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

s = input()
n = len(s)
t = defaultdict(int)
f = 0
t[0] = 1
for i in range(n, -1, -1):
	v = (f + (10**((n-i)%2019) * int(s[i-1]))%2019) % 2019
	t[v] += 1
	f = v
	
res = 0
for v in t.values():
	res += (v * (v - 1) // 2)

print(res)

Submission status: Wrong Answer

Solution code:
s = input()
c = 0
if int(s) <= 2019:
  print(c)
else:
  for i in range(len(s) + 1):
    for j in range(len(s) + 1):
      if i < j:
        if int(s[i:j]) > 2019:
          if int(s[i:j]) % 2019 == 0:
            c = c + 1
print(c)

Submission status: Wrong Answer

Solution code:
S = str(input())
dp = [0]*len(S)#dp[i]がTiのmod2019の値（インデックスで見る)
dp[-1]=float('inf')
dp[len(S)-2] = int(S[-1])
for i in range(len(S)-2,0,-1):
    dp[i-1] = (dp[i] + int(S[i])*(10**(len(S)-1-i)))%2019
dp.insert(0,int(S)%2019)#0番目以降までで0番目を含んだのが上の定義ではない
ans = 0
for ii,i in enumerate(dp):
    if i==0:
        ans += 1
    for j in dp[ii+1:]:
        if (i==j) :
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

s = int(stdin.readline().rstrip())

sl = len(str(s))
cnt = 0

for i in range(sl - 3):
    for j in range(i + 3, sl):
        num = s % (10 ** (sl - i)) // (10 ** (sl - j - 1))
        print(i, j, num)
        if num % 2019 == 0 and num > 0:
            cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import math

def P(n):
  return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))

N = input()
a = 0
#N2 = [int(N[-1 * _]) for _ in range(1, len(N) + 1)] #各桁ずつ取り出し
N3 = [0 for i in range(len(N))] #i番目には(i + 1)桁目までの数字の2019の剰余が保存
for i in range(len(N)):
  num = int(N[len(N) - i -1:])
  N3[i] = num % 2019

l = 0
for i in range(len(N)):
  if N3[i] == -1:
    continue
  if N3[i] == 0:
    l += 1
  else:
    k = 1
    """for j in range(i + 1, len(N)):
      if N3[i] == N3[j]:
        N3[j] = -1
        k += 1"""
    if k >= 2:
      l += int(P(k))
print(l)

Submission status: Wrong Answer

Solution code:
s = list(input())
n = len(s)
mod = 2019

d=[0]*(n+1)
k=1
for i in range(n):
    d[i+1]=d[i]+k*int(s[n-i-1])
    d[i+1]%=mod
    k*=10
    k%=mod

count = [0]*mod
for i in range(n+1):
    count[d[i]] += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np


def count_multi(s, d):
  m = a = np.array([c for c in s]).astype(np.int)
  keta = 1
  count = np.count_nonzero(m == 0)
  while len(m) > 1:
    m = (m[:-1]*10 + a[keta:]) % d
    keta += 1
    count += np.count_nonzero(m == 0)
  return count
        
print(count_multi(input().strip()*2000, 2019))

Submission status: Wrong Answer

Solution code:
# D - Multiple of 2019

s = input()

# pow[k] = 10 ** k % 2019
pow = [1]
while len(pow) <= 1 or pow[-1] > 1:
    pow.append(pow[-1] * 10 % 2019)
n = len(pow) - 1  # 10 ** n == 1 mod 2019

# memo[i % n][m] = (int(s[:i+1]) % 2019 == mであるiの個数)
memo = [{} for i in range(n)]
memo[n - 1][0] = 1  # memo[-1][0] = 1

count = 0  # int(s[i:j+1]) == 0 mod 2019 である(i,j)の個数
mod = 0
for j, c in enumerate(s):
    mod = (mod * 10 + int(c)) % 2019  # mod = int(s[:j+1]) % 2019
    for i in range(1, n + 1):
        inv = pow[n - i]  # inv == 10 ** (-i) mod 2019
        if mod * inv % 2019 in memo[(j - i + n) % n]:
            count += 1
    if mod not in memo[j % n]:
        memo[j % n][mod] = 0
    memo[j % n][mod] += 1

print(count)

Submission status: Wrong Answer

Solution code:
S=str(input())
n=len(S)
list2019=[]
ans=0

for i in range(1,100):
    a=i*2019
    b=str(a)
    if int(S)<a:
        break
    if '0' not in b:
        list2019.append(b)


for tgt in list2019:
    for i in range(n-len(tgt)+1):
        if S.find(tgt,i,i+len(tgt))==i:
            ans=ans+1
      

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
count=0
index=1
value=0
Hashmap=dict()
while index*2019<=999999:
    value=str(index*2019)
    Hashmap[value]=1
    index+=1     

#    print(Hashmap)
for i in range(n):
    if i+6<=n:
        if Hashmap.get(s[i:i+6])!=None :
            count+=1
    if i+5<=n:        
        if Hashmap.get(s[i:i+5])!=None:
            count+=1
    if i+4<=n:
        if Hashmap.get(s[i:i+4])!=None:
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:


s=input()
n=len(s)
count=0
index=1
value=0
Hashmap=dict()
while index*2019<=999999:
    value=str(index*2019)
    Hashmap[value]=1
    index+=1     

for i in range(n):
    if i+6<=n:
        if Hashmap.get(s[i:i+4])!=None or Hashmap.get(s[i:i+5])!=None or Hashmap.get(s[i:i+6])!=None :
            count+=1
    elif i+5<=n:        
        if Hashmap.get(s[i:i+4])!=None or Hashmap.get(s[i:i+5])!=None:
            count+=1
    elif i+4<=n:
        if Hashmap.get(s[i:i+5])!=None:
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:


s=input()
n=len(s)
count=0
index=1
value=0
Hashmap=dict()
while index*2019<=999999:
    value=str(index*2019)
    Hashmap[value]=1
    index+=1     

#print(Hashmap) 
for i in range(n):
    if i+7<=n:
        if Hashmap.get(s[i:i+5])!=None or Hashmap.get(s[i:i+6])!=None or Hashmap.get(s[i:i+7])!=None :
            count+=1
    elif i+6<=n:        
        if Hashmap.get(s[i:i+5])!=None or Hashmap.get(s[i:i+6])!=None:
            count+=1
    elif i+5<=n:
        if Hashmap.get(s[i:i+5])!=None:
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
def substring(s1, s2):
    j = 0
    ans = 0
    while j < len(s2):
        b = j
        i = 0
        c = 0
        while i<len(s1) and b < len(s2) and s1[i] == s2[b]:
            c+=1
            i+=1
            b+=1
        if c == len(s1):
            ans+=1
        j+=1

    return ans


mult = []
a = 0
while a * 2019 <= 200003:
    mult.append(str(a * 2019))
    a += 1

s = input()

i = 0
ans = 0

while i < len(mult):
    ans += substring(mult[i],s)
    i += 1


print(ans)

Submission status: Wrong Answer

Solution code:
def substring(s1, s2):
    j = 0
    ans = 0
    while j < len(s2):
        b = j
        i = 0
        c = 0
        while i<len(s1) and b < len(s2) and s1[i] == s2[b]:
            c+=1
            i+=1
            b+=1
        if c == len(s1):
            ans+=1
        j+=1
    return ans


mult = []
a = 1
while a * 2019 <= 200000:
    mult.append(str(a * 2019))
    a += 1

s = input()

i = 0
ans = 0

while i < len(mult):
    ans += substring(mult[i],s)
    i += 1


print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

n = input()
l = [int(x) for x in list(n)]

leng = len(l)
liste = []
sum = 0

x = 0
for i in range(leng):
  x += l[leng-i-1]*pow(10,i)
  #print(x)
  a = x % 2019
  liste.append(a)
print(liste)
for i in range(len(liste)):
  if liste[i] == 0:
    sum += 1

c = collections.Counter(liste)
m = list(c.values())
#print(m)

for i in range(len(m)):
  if m[i] != 1:
    sum += (m[i]-1)
print(sum)

Submission status: Wrong Answer

Solution code:
import collections

n = input()
l = [int(x) for x in list(n)]

leng = len(l)
liste = []

x = 0
for i in range(leng):
  x += l[leng-i-1]*pow(10,i)
#  print(x)
  a = x % 2019
  liste.append(a)
#  print(a)

c = collections.Counter(liste)
m = list(c.values())
sum = 0
for i in range(len(m)):
  if m[i] != 1:
    sum += (m[i]-1)
print(sum)

Submission status: Wrong Answer

Solution code:
import collections

n = input()
l = [int(x) for x in list(n)]

leng = len(l)
liste = []

for j in range(leng):
  x = 0
  for i in range(j):
  		x += l[leng-i-1]*pow(10,i)
  a = x % 2019
  liste.append(a)

c = collections.Counter(liste)
m = list(c.values())
sum = 0
for i in range(len(m)):
  if m[i] != 1:
    sum += (m[i]-1)
print(sum)

Submission status: Wrong Answer

Solution code:
original = input()

target = 2019

results = {}
countOfMod = {0:1}
s = reversed(original)

digit = 1
mod = 0
for c in s:
    val = int(c) * digit
    currentMod = val % target
    mod = (currentMod + mod) % target
    digit *= 10

    count = countOfMod.get(mod, 0) + 1
    countOfMod[mod] = count
    if countOfMod[mod] > 1:
        results.setdefault(mod, int(count*(count-1)/2))

print(sum(results.values()))

Submission status: Wrong Answer

Solution code:
n = input()
k = len(n)
count = 0
s = set()
for r in range(k):
  num = int(n[-(r+1):])
  rem = num % 2019
  if rem not in s:
    s.add(rem)
  else:
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

if int(s) < 2019:
    print(0)
else:
    for i in range(4, len(s)):
        for j in range(len(s) - i + 1):
            if int(s[j:i+j]) % 2019 == 0:
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

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