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:
def search(S):
    cnt = 0
    N = len(S)
    for i in range(N+1):
        for j in range(i+1, N+1):
            num = S[i:j]
            if int(num)%2019==0:
                print(num)
                cnt += 1
            
    return cnt 

if __name__ == "__main__":
    S = input()
    cnt = search(S)
    print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import mul
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 2019


def cmb(n, r):
    if n < r:
        return 'Error n < r'
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


s = readline().decode().rstrip()
s = s[::-1]
n = len(s)
d = [0] * (n)
d[0] = int(s[0]) % mod

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

c = Counter(d)
ans = 0
for k, v in c.items():
    if k == 0:
        ans += v
    elif v >= 2:
        ans += cmb(v, 2)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = input()
S = S[::-1]
N = len(S)
counter = Counter()
counter[0] = 1
prev = 0
MOD = 2019
ans = 0
for i in range(N):
  c = (int(S[i]) * pow(10, i, MOD) )%MOD
  prev = (prev+c)%MOD
  if prev in counter:
    ans += 1
  counter[prev] += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
S = input()[::-1]
remainder = [0] * 2019
d = 1
num = 0
for s in S:
  num += int(s) * d
  remainder[num % 2019] += 1
  d *= 10
  
  # numが大きくなりすぎると計算量が膨大になってしまうのを防ぐ
  # num%2019を計算するので、先に%2019で計算しても結果は変わらない
  d %= 2019
ans = 0
for i in range(2019):
  if i == 0:
      ans += remainder[i]
  else:
    if remainder[i] > 1:
      # 組み合わせ
      ans += (math.factorial(remainder[i]) // (math.factorial(remainder[i] - 2) * math.factorial(2)))
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
S = input()[::-1]
remainder = [0] * 2019
d = 1
num = 0
for s in S:
  num += int(s) * d
  remainder[num % 2019] += 1
  d *= 10
ans = 0
for i in range(2019):
  if i == 0:
      ans += remainder[i]
  else:
    if remainder[i] > 1:
      # 組み合わせ
      ans += (math.factorial(remainder[i]) // (math.factorial(remainder[i] - 2) * math.factorial(2)))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = input()
n = len(s)
digits = [int(c) for c in s[::-1]]
a = [0] * (n + 1)
p = 2019

for i, digit in enumerate(digits):
    a[i + 1] = (digit * pow(10, i, p) + a[i]) % p

counter = Counter(a)
ans = 0
for count in counter.values():
    ans += count * (count - 1) // 2
    ans %= p

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

S = input().strip()
#-----
num = 0
cnt_mod = {}
mod = 2019
base_pow = 1

for i in range(len(S)):
    digit = int( S[len(S)-1-i] )
    
    num += (digit * base_pow) % mod
    num %= mod
    
    remainder = num % mod
    base_pow = (base_pow * 10) % mod
    
    cnt_mod.setdefault(remainder, 0)
    cnt_mod[remainder] += 1


ans = 0

for r,c in cnt_mod.items():
    # r: remainder
    # c: count
    if r == 0:
        ans += c
    elif c >= 2:
        ans += c*(c-1)//2

print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc164/tasks/abc164_d

from operator import mul
from functools import reduce
from collections import defaultdict

def combination(n, r):
    if not 0 <= r <= n: return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

S = input()

res = 0

T = [0]
x = 0
L = len(S)
for i, s in zip(range(L),reversed(S)):
    """ 累積和 """
    x = int(s)*pow(10,i) + x
    T.append(x)
exit()

reminder = [0]*2019
for i in range(L+1):
    reminder[T[i]%2019] += 1

for c in reminder:
    res += combination(c,2)

print(res)

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

s = list(sr())
s.reverse()
dp = [0 for i in range(len(s)+1)]
tmod = 1
for i,c in enumerate(s):
    now = int(c)
    dp[i+1] = (dp[i]+now*tmod)%2019
    tmod = (tmod*10)%2019
ans = 0
print(collections.Counter(dp))
for _,v in collections.Counter(dp).items():
    ans+=(v*(v-1)//2)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
L = len(S)
res = 0
i = L - 1
while i>=3:
    for j in range(i-3, -1, -1):
        if not int(S[j:i+1])%2019:
            res += 1
            i = j + 1
            break
    i -= 1
print(res)

Submission status: Wrong Answer

Solution code:
s = input()
mul = set(str(2019*i) for i in range(1,100))
ans = 0

for i in range(len(s)-3):
  p = 4
  while p<=6 and i+p<=len(s):
    if s[i:i+p] in mul:
      ans += 1
    p += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
mul = set(str(2019*i) for i in range(1,100))
ans = 0
for m in mul:
  ans += s.count(m)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
from operator import mul

INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 組合せnCr
def combinations_count(n, r):
    if n < r:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]



# ここから書き始める
s = input()
n = len(s)

# 愚直解(n^2)
# ans_stupid = 0
# for i in range(n):
#     for j in range(i, n):
#         if int(s[i : j + 1]) % 2019 == 0:
#             print(s[i : j + 1])
#             ans_stupid += 1
# print("ans_stupid =", ans_stupid)

ans = 0
s2 = s[::-1]
for i in range(n):
    now = int(s2[i])
    if s[i] == 0:
        continue
    multiplier = 10 - now
    multiple_of_2019 = str(2019 * multiplier)
    # print("multiple_of_2019 =", multiple_of_2019)
    # print("s2[i : i + len(multiple_of_2019) - 1] =", s2[i : i + len(multiple_of_2019) - 1])
    if s2[i : i + len(multiple_of_2019)] == multiple_of_2019[::-1]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    mod = 2019
    mod_count = {i: 0 for i in range(mod)}
    now_num = 0
    base = 1
    for i in range(len(s) - 1, -1, -1):
        now_num += int(s[i]) * base
        now_num %= mod
        mod_count[now_num] += 1
        base *= 10
        base %= mod
    ans = 0
    for i in range(mod):
        ans += mod_count[i] * (mod_count[i] - 1) // 2
    print(ans + 1 if ans else 0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    mod = 2019
    mod_count = {i: 0 for i in range(mod)}
    now_num = 0
    for i in range(len(s) - 1, -1, -1):
        now_num += pow(10, len(s) - i - 1) * int(s[i])
        now_num %= mod
        mod_count[now_num] += 1
    ans = 0
    for i in range(mod):
        ans += mod_count[i] * (mod_count[i] - 1) // 2
    print(ans + 1 if ans else 0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    mod = 2019
    mod_count = {i: 0 for i in range(mod)}
    now_num = 0
    for i in range(len(s) - 1, -1, -1):
        now_num += pow(10, len(s) - i - 1) * int(s[i])
        mod_count[now_num % mod] += 1
    ans = 0
    for i in range(mod):
        ans += mod_count[i] * (mod_count[i] - 1) // 2
    print(ans + 1 if ans else 0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = str(input())
li = [0] * 2019
ans = 0

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  if s == 0:
    ans += 1
  else:
    li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
S = str(input())
li = []
dic = {}
ans = 0

s = 0
d = 1
for i in range(len(S)):
  s += int(S[len(S)-1-i]) * d
  s = s % 2019
  if s == 0:
    ans += 1
  elif s not in li:
    li.append(s)
  elif s not in dic:
    dic[s] = 2
  else:
    dic[s] += 1
  d *= 10
  d = d % 2019
  
li = list(dic.values())
for l in li:
  ans += l * (l-1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = input()
L = len(list(S))
dp = [0] * L
dp[0] = 1
T = [0] * L
T[0] = int(S[-1])
for i in range(1, L):
    dp[i] =  dp[i - 1] * 10
    dp[i] %= 2019
    T[i] = int(S[-(i+1)]) * dp[i] + T[i - 1]
    T[i] %= 2019
ans = 0
for k, v in Counter(T).items():
    if k == 0:
        ans += v
    else:
        ans += v * (v - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s=input()
l=[]
n=len(s)
for i in range(n):
  l.append(int(s[i:])%2019)
c=collections.Counter(l)
ans=0
for cc in c:
  ans+=cc*(cc-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

l_2019 =[i*2019 for i in range(1,100)]

ans = 0
for i in l_2019:
    ans += S.count(str(i))

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

l_2019 =[i*2019 for i in range(1,100)]

ans = 0
for i in l_2019:
    print(ans,i)
    ans += S.count(str(i))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

s=int(input())
n=len(str(s))
lis=[0]*n
#for i in range(n): lis[i]=s%(10**(i+1))%2019
lis=lis[::-1]
lis.append(0)
dic=dict(Counter(lis))
ans=0
for val in dic.values(): ans+=val*(val-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
mod2019 = [0]*len(S)

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

mod2019.extend([0])

answer = 0
count = [0 for _ in range(2020)]


for i in range(len(S)):
    answer += count[mod2019[i]]
    count[mod2019[i]] += 1
print(answer)

Submission status: Wrong Answer

Solution code:
S = input()
mod2019 = [0]*(len(S)+1)

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

answer = 0
count = [0 for _ in range(2020)]


for i in range(len(S)):
    answer += count[mod2019[i]]
    count[mod2019[i]] += 1
print(answer)

Submission status: Wrong Answer

Solution code:
S = input()
mod2019 = [0]*(len(S)+1)

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

answer = 0
count = [0 for _ in range(2020)]


for i in range(len(S)):
    answer += count[mod2019[i]]
    count[mod2019[i]] += 1
print(answer)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    count = 0

    if len(S)<=200000:
        for i in range(len(S)-4):

            for j in range(i+4, len(S)+1):
                tmp = int(S[i:j])
                print(tmp)
                if tmp%2019==0:
                    count += 1

    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

S = input()
count = 0

if len(S)<=200000:
    for i in range(len(S)-4):

        for j in range(i+4, len(S)+1):
            tmp = int(S[i:j])
            print(tmp)
            if tmp%2019==0:
                count += 1

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
count = 0

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

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
count = 0

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

print(count)

Submission status: Wrong Answer

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+1
        s(start+1, end)
        return
    

        s(start, end+1)

S = input()
s(0, 0)
print(cnt)

Submission status: Wrong Answer

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])

    try:
        if(numS%2019==0 and numS!=0):
            cnt += 1
    except:    
        if(end==len(S)-1):
            end = start+1
            s(start+1, end)
            return
    

        s(start, end+1)

S = input()
s(0, 0)
print(cnt)

Submission status: Wrong Answer

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    try:

        if(numS%2019==0 and numS!=0):
            cnt += 1
        if(end==len(S)-1):
            end = start+1
            s(start+1, end)
            return
    except:

        s(start, end+1)

S = input()
s(0, 0)
print(cnt)

Submission status: Wrong Answer

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
        
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        print(numS)
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

S = input()
try:
    s(0, 1)
except:
    print("hey")
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()

n = len(s)
b = 0
t = 1
cnt = 1
mod = [0]*(n+1)
for i in reversed(s):
    b += int(i)*t
    mod[cnt] = b % 2019
    t *= 10
    cnt += 1

cnt = n+1 - len(set(mod))
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np
import time
import math
import re

sys.setrecursionlimit(10**7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    s = input()

    tmp_list = []
    tmp = 2019
    while tmp <= 2000000:
        tmp_list.append(str(tmp))
        tmp += 2019

    counter = 0
    for i in tmp_list:
        a = [m.span() for m in re.finditer(i, s)]
        a = np.array(a)
        a += 1
        print(len(a))
        counter += len(a)
    print(counter)



if __name__ == "__main__":
    main()
    pass

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np
import time
import math
import re

sys.setrecursionlimit(10**7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    s = input()

    tmp_list = []
    tmp = 2019
    while tmp <= 200000:
        tmp_list.append(str(tmp))
        tmp += 2019

    counter = 0
    for i in tmp_list:
        a = [m.span() for m in re.finditer(i, s)]
        a = np.array(a)
        a += 1
        counter += len(a)
    print(counter)



if __name__ == "__main__":
    main()
    pass

Submission status: Wrong Answer

Solution code:
S=int(input())
s=str(S)
ans=0
for a in range(len(s)-3):
  for b in range(len(s)-a-3):
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = int(input())
n = len(str(s))
count=0
for i in range(n+1):
  for j in range(i):
    print(s%(10**i)//(10**j))
    if((s%(10**i)//(10**j))%2019==0):
      count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = input()

    cnt = [0 for _ in range(2019)]
    cnt[0] += 1
    dec = 1
    num = 0
    for i in reversed(s):
        num += int(i) * dec
        num %= 2019
        dec *= 10
        dec %= 10
        cnt[num] += 1

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	s = inp().strip();
	dic = defaultdict(int); dic[0] = 1
	# sett.add(0)
	ans = 0; cum = 0
	for i in range(len(s)-1, -1, -1):
		cum += (int(s[i])*pow(10, (len(s)-i-1), 2019)) % 2019
		cum %= 2019
		dic[cum] += 1
	# print(dic)
	for i in dic:
		ans += dic[i]-1
	print(ans)






if __name__ == "__main__":
	solve()

Submission status: Wrong Answer

Solution code:
import sys
from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	s = inp().strip();
	sett = set(); sett.add(0)
	ans = 0; cum = 0
	for i in range(len(s)-1, -1, -1):
		cum += (int(s[i])*pow(10, (len(s)-i-1), 2019)) % 2019
		cum %= 2019
		if cum in sett:
			ans += 1
		sett.add(cum)
	print(ans)






if __name__ == "__main__":
	solve()

Submission status: Wrong Answer

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

T=[0]*n
for i in range(n):
    T[i]=int(S[i:])

Submission status: Wrong Answer

Solution code:
from collections import Counter
S=input()
n=len(S)

T=[0]*n
DP=[0]*n
for i in range(n):
    T[i]=int(S[i:])

Submission status: Wrong Answer

Solution code:
S = input()
 
dic = dict()
cnt = 0
for i in range(len(S)-1, -1, -1):
  if int(S[i:])%2019 not in dic:
    dic[int(S[i:])%2019] = 1
  else:
    cnt += dic[int(S[i:])%2019]
    dic[int(S[i:])%2019] += 1
  
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
len_s = len(s)
ls = []
x = 2019
index = {}
for i in range(len(s)+1 - 4):
    if index.get(s[i:i+4]) is None:
        index[s[i:i+4]] = []
    index[s[i:i+4]].append(i)

for i in range(10000):
    ls.append(str(x))
    x += 2019

cnt = 0
for l in ls:
    len_l = len(l)
    res =  index.get(l[:4])
    if res is None:
        continue
    for ind in res:
        if ind + len_l > len_s:
            continue
        if s[ind:ind+len_l] == l:
            cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
a = input()[::-1]
add = 0
ans = [1] + [0] * 2018
ans_int = 0
d = 1

for i in range(len(a)):
    add = (add + int(a[i]) * d) % 2019
    d = (10 * d) %2019
    ans[add] += 1

for i in range(len(ans)):
    if ans[i] > 1:
        ans_int += (ans[i] - 1)

print(ans_int)

Submission status: Wrong Answer

Solution code:
a = input()[::-1]
add = 0
ans = [1] + [0] * 2018
ans_int = 0
d = 1

for i in range(len(a)):
    add = (add + int(a[i]) * d) % 2019
    d = (10 * d) %2019
    if ans[add] == 1:
        ans_int += 1
        continue
    else:
        ans[add] = 1

print(ans_int)

Submission status: Wrong Answer

Solution code:
a = list(input())
a.reverse()
add = 0
ans = [1] + [0] * 2018
ans_int = 0
d = 1

for i in range(len(a)):
    add = (add + int(a[i]) * d) % 2019
    d = (10 * d)
    if ans[add] == 1:
        ans_int += 1
        continue
    else:
        ans[add] = 1

print(ans_int)

Submission status: Wrong Answer

Solution code:
a = list(input())
a.reverse()
add = 0
ans = [1] + [0] * 2018
ans_int = 0

for i in range(len(a)):
    add = (add + int(a[i]) * 10 ** i) %2019
    if ans[add] == 1:
        ans_int += 1
        continue
    else:
        ans[add] = 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
s = list(reversed(s))
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
dp1[0] = 1
dp2[0] = int(s[0])
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
sm = 0
for j in range(2019):
    sm += int(counting[j]*(counting[j]-1)/2)
print(sm)

Submission status: Wrong Answer

Solution code:
s = input()
s = list(reversed(s))
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
dp1[0] = 1
dp2[0] = int(s[0])
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
sm = 0
for j in range(2019):
    sm += counting[j]*(counting[j]-1)/2
print(sm)

Submission status: Wrong Answer

Solution code:
s = input()
s = list(reversed(s))
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
dp1[0] = 1
dp2[0] = int(s[0])
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
sm = 0
for j in range(2019):
    sm += counting[j]*(counting[j]-1)
print(sm)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
from collections import deque
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
s=input()
n=len(s)
ten=[1]
mod=2019
for i in range(n-1):
  ten.append((ten[i]*10)%mod)
modls=[0]*n
modls[n-1]=int(s[n-1])
dic=defaultdict(int)
dic[0]=1
for i in range(n-2,-1,-1):
  modls[i]=int(s[i])*ten[n-1-i]+modls[i+1]
  modls[i]%=mod
  dic[modls[i]]+=1
ans=0
#print(modls)
for num in dic.values():
	ans+=num*(num-1)//2
#ans+=dic[0]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
from collections import deque
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
s=input()
n=len(s)
ten=[1]
mod=2019
for i in range(n-1):
  ten.append((ten[i]*10)%mod)
modls=[0]*n
modls[n-1]=int(s[n-1])
dic=defaultdict(int)
for i in range(n-2,-1,-1):
  modls[i]=int(s[i])*ten[n-1-i]+modls[i+1]
  modls[i]%=mod
  dic[modls[i]]+=1
ans=0
#print(dic)
for num in dic.values():
	ans+=num*(num-1)//2
ans+=dic[0]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
from collections import deque
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
s=input()
n=len(s)
ten=[1]
mod=2019
for i in range(n-1):
  ten.append((ten[i]*10)%mod)
modls=[0]*n
modls[n-1]=int(s[n-1])
dic=defaultdict(int)
for i in range(n-2,-1,-1):
  modls[i]=int(s[i])*ten[n-1-i]+modls[i+1]
  modls[i]%=mod
  dic[modls[i]]+=1
ans=0
#print(modls)
for num in dic.values():
	ans+=num*(num-1)//2
ans+=dic[0]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
num=2019
count=0
for i in range(len(s)):
    for j in range(i+3,i+3+2):
        target=int(s[i:j+1])
        if target%num==0:
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
right = [int(s[i:])%2019 for i in range(l)]
right.append(0)
count = {}
for r in right:
    count.setdefault(r, 0)
    count[r] += 1
ans = 0
for v in count.values():
    ans += v * (v-1) / 2
print(ans)

Submission status: Wrong Answer

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