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:
"""
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()[::-1]

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=[int(j) for j in input()][::-1]
m=len(s)
from collections import Counter
c=Counter()
tmp=0
c[0]+=1
t=1
for i in range(m):
    tmp=tmp*10+s[i]
    c[tmp%2019]+=1
ll=c.most_common()
ans=0
for i,j in ll:
    if j>=2:
        ans+=j*(j-1)//2
    else:
        break
print(ans)

Submission status: 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 main(S):

    N = len(S)

    M = [0 for i in range(2019)]
    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

    res = 0

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


    print(res)



S = input().rstrip()
S = list(map(int,list(S)))
# print(S)

main(S)

Submission status: Wrong Answer

Solution code:
import math

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

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

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

s = input()[::-1]

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

p = 2019

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

Submission status: Wrong Answer

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

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 main(S):
    # S = input().rstrip()

    N = len(S)

    M = [0 for i in range(2019)]
    M[0] += 1

    T = 0
    r = 1
    for i in range(N):
        T = S[N-i-1] * r + T
        T = T % 2019
        M[T] += 1
        r *= 10

    res = 0

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


    print(res)



S = input().rstrip()
S = list(map(int,list(S)))

main(S)

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
ss = []
nums = [(i+1)*2019 for i in range(200000//2019) if not "0" in str((i+1)*2019)]
for start in range(len(s)):
  end = start + 3
  while(end+1<=len(s)):
    if s[start:end+1] in nums:
      cnt += 1
    end += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stderr
from functools import reduce
import re

def debug(*args):
    print(*args, file=stderr)

s = input()

def count(text, sub):
    # https://stackoverflow.com/a/28915551
    ln = len(sub)
    return sum(sub == text[i:i+ln] for i in range(len(text)-(ln-1)))

multiples = filter(lambda  x: '0' not in x, [str(i) for i in range(200000) if i % 2019 == 0 and i != 0])
result = sum(map(lambda m: count(s, m), multiples))

print(result)

# echo "1817181712114" | python3 d.py && echo "14282668646" | python3 d.py && echo "2119" | python3 d.py

Submission status: Wrong Answer

Solution code:
import math

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

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

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

s = input()

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

p = 2019

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import collections
s = (input())

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

n = len(s)
ans = 0
l = 0
#r = l
num = int(s)

tmp = [0 for _ in range(n+1)]
ten = [0 for _ in range(n)]
tmp1 = 0
val = 1
for i in range(0,n):
    ten[i] = val
    tmp1 += (int(s[n-i-1]) * val)
    tmp[i+1] = tmp1 % 2019
    val = (val * 10)
#print(tmp)

c = collections.Counter(tmp)
#print(c)
for i in range(0, 2020):
    if c[i] > 0:
        ans += ((2 * c[i] - 1) // 2)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

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

s = input()

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

p = 2019

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

Submission status: Wrong Answer

Solution code:
from sys import stderr
from functools import reduce
import re

def debug(*args):
    print(*args, file=stderr)

s = input()

def count(text, sub):
    # https://stackoverflow.com/a/28915551
    ln = len(sub)
    return sum(sub == text[i:i+ln] for i in range(len(text)-(ln-1)))

multiples = [str(i) for i in range(200000) if i % 2019 == 0 and i != 0]
result = sum(map(lambda m: count(s, m), multiples))

print(result)

# echo "1817181712114" | python3 d.py && echo "14282668646" | python3 d.py && echo "2119" | python3 d.py

Submission status: Wrong Answer

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

for i in range(1,20000000//2019+1):
    l.append(str(i*2019))

import collections

len_text = len(s)
dic = collections.defaultdict(int)
for i in range(1,7):
    for j in range(len_text-i+1):
        dic[s[j:j+i]] += 1
total = 0
for i in l:
    total += dic[i]
print(total)

Submission status: Wrong Answer

Solution code:
import math

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

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

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

s = input()

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

p = 2019

Submission status: Wrong Answer

Solution code:
import math

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

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

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

s = input()

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

p = 2019

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

S = [int(s) for s in input()]
y = 2019
T = [S[-1]] * len(S)

for i in range(len(S)-2, -1, -1):
  T[i] = (T[i+1] + S[i] * 10) % y

cnt = 0
for c in Counter(T).values():
  cnt += c * (c - 1) // 2
  
print(cnt)

Submission status: Wrong Answer

Solution code:
import math

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

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

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

s = input()

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

p = 2019

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

Submission status: Wrong Answer

Solution code:
# 初期入力
#import sys
#input = sys.stdin.readline
S_str =input().strip()

#2019の倍数を定義　＜200000
baisu_2019 =[str(i*2019) for i in range(1,100)]

#
count=[]

for i in baisu_2019:
    indx=-1
    index_S=0
    while len(S_str) >= indx+1+len(i) or index_S!=-1: 
        if i in S_str: #なかったら次の倍数
            index_S =S_str.find(i,indx+1) #S_strの中に倍数があるか、あったら次はその隣から探す
            if indx != index_S and index_S !=-1: #同じindexはカウントしない
                count.append((i,index_S))
                indx = index_S
            else:
                break
        else:
            break
print(len(count))

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
MOD=2019
from collections import defaultdict
d=defaultdict(int)
for i in range(n-1,-1,-1):
  d[int(s[i:n])%2019]+=1
ans=0
for i,v in enumerate(d):
  if i==0:
    ans+=v
else:
  ans+=v*(v-1)//2
print(ans)

Submission status: Wrong Answer

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

for i in range(1,200000//2019+1):
    l.append(str(i*2019))

import collections

len_text = len(s)
dic = collections.defaultdict(int)
for i in range(1,7):
    for j in range(len_text-i+1):
        dic[s[j:j+i]] += 1
total = 0
for i in l:
    total += dic[i]
print(total)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math
s = input()
n = len(s)
count = 0
a = [0 for i in range(2019)]
a[0] = 1
k = 0
b = [0 for i in range(n)]
b[0] = 1
for i in range(1, n):
    b[i] = b[i-1]*10 % 2019

print(b)
for i in reversed(range(0, n)):
    print((b[n-i-1])*int(s[i]) % 2019)
    k += (b[n-i-1])*int(s[i]) % 2019
    print(k, k % 2019)
    a[k % 2019] += 1

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

Submission status: Wrong Answer

Solution code:
# from sys import stderr
from functools import reduce
import re

def debug(*args):
    print(*args, file=stderr)

s = input()

# multiples_re = ['(?={})'.format(str(i)) for i in range(200000) if i % 2019 == 0 and i != 0]
multiples_re = ['(?=2019)', '(?=4038)', '(?=6057)', '(?=8076)', '(?=10095)', '(?=12114)', '(?=14133)', '(?=16152)', '(?=18171)', '(?=20190)', '(?=22209)', '(?=24228)', '(?=26247)', '(?=28266)', '(?=30285)', '(?=32304)', '(?=34323)', '(?=36342)', '(?=38361)', '(?=40380)', '(?=42399)', '(?=44418)', '(?=46437)', '(?=48456)', '(?=50475)', '(?=52494)', '(?=54513)', '(?=56532)', '(?=58551)', '(?=60570)', '(?=62589)', '(?=64608)', '(?=66627)', '(?=68646)', '(?=70665)', '(?=72684)', '(?=74703)', '(?=76722)', '(?=78741)', '(?=80760)', '(?=82779)', '(?=84798)', '(?=86817)', '(?=88836)', '(?=90855)', '(?=92874)', '(?=94893)', '(?=96912)', '(?=98931)', '(?=100950)', '(?=102969)', '(?=104988)', '(?=107007)', '(?=109026)', '(?=111045)', '(?=113064)', '(?=115083)', '(?=117102)', '(?=119121)', '(?=121140)', '(?=123159)', '(?=125178)', '(?=127197)', '(?=129216)', '(?=131235)', '(?=133254)', '(?=135273)', '(?=137292)', '(?=139311)', '(?=141330)', '(?=143349)', '(?=145368)', '(?=147387)', '(?=149406)', '(?=151425)', '(?=153444)', '(?=155463)', '(?=157482)', '(?=159501)', '(?=161520)', '(?=163539)', '(?=165558)', '(?=167577)', '(?=169596)', '(?=171615)', '(?=173634)', '(?=175653)', '(?=177672)', '(?=179691)', '(?=181710)', '(?=183729)', '(?=185748)', '(?=187767)', '(?=189786)', '(?=191805)', '(?=193824)', '(?=195843)', '(?=197862)', '(?=199881)']
result = sum(map(len, map(lambda re_pattern: re.findall(re_pattern, s), multiples_re)))

print(result)


# echo "1817181712114" | python3 d.py && echo "14282668646" | python3 d.py && echo "2119" | python3 d.py

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


s = input()
n = len(s)

dd = defaultdict(int)

d = [0] * 2019
dd[0] = 1
tmp = 0
_10 = 1
# print(s, n)
for i in range(n - 1, -1, -1):
    # print(i, s[i])
    tmp = tmp + int(s[i]) * _10
    _10 *= 10
    # print(tmp, tmp % 2019)
    d[tmp % 2019] += 1


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

# print(dd)
# print(sum(v*(v-1)//2 for v in dd.values()))

Submission status: Wrong Answer

Solution code:
def main():
    S = '1817181712114'
    S_list = []
    for i in range(len(S)):
        S_list.append(int(S[i]))
    num = 0
    for i in range(len(S_list)-3):
        sum_temp = 0
        k = 0
        for v in range(i, i+3)[::-1]:
            sum_temp += 10**k*S_list[v]
            k += 1
        for j in range(i+3, len(S)):
            #print(S_list[j])
            sum_temp *= 10
            sum_temp += S_list[j]
            if sum_temp % 2019 == 0:
                num += 1
    print(num)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = str(input())
h = [int(x) for x in list(S)]
N = len(h)
a = []
T = 0
r = 1
for i in range(N-1, -1, -1):
    T = T + h[i] * r
    r = r * 10
    a.append(T%2019)
b = []
for j in range(0, N):
    if a[j] not in b:
        b.append(a[j])
c = 0
for k in range(0, len(b)):
    d = a.count(b[k])
    c += d * (d-1) /2
c += a.count(0)
print(c)

Submission status: Wrong Answer

Solution code:
s1=input()
s=int(s1)

s_sor=s1[::-1]
keta=len(s1)

mod=[]
for i in range(4,keta+1):
    num=s_sor[:i]
    num=int(num[::-1])
    print(num)
    mod.append(num%2019)
modt=set(mod)
print(mod)
print(modt)
a=0
for i in modt:
    print(i)
    if mod.count(i)>1:
        a+=mod.count(i)
print(a)

Submission status: Wrong Answer

Solution code:
s=int(input())
n=len(str(s))
t=[]
for i in range(n):
    k=s%10**(n-i)
    k%=2019
    t.append(k)
w=[]
for i in range(2019):
    w.append(0)
for i in t:
    w[i]+=1
a=0
for i in w:
    if i>=2:
        a+=int(i*(i-1)/2)
print(a)

Submission status: Wrong Answer

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

mod = 2019

s = input().rstrip()
n = len(s)

t = [int(s[n - 1])]

mul = 10
for i in range(n - 2, -1, -1):
    t.append((t[-1] + int(s[i])*mul) % mod)
    mul *= 10
t.append(0)

Submission status: Wrong Answer

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

    reminder = [0]*mod
    pre_rem = 0

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

    ans = reminder[0]
    for rem_num in reminder[1:]:
        if rem_num >= 2:
            ans += (rem_num * (rem_num -1))//2
    print(ans)
    
solve()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

    reminder = [0]*mod
    pre_rem = 0

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

    ans = reminder[0]
    for rem_num in reminder[1:]:
        if rem_num >= 2:
            ans += (rem_num * (rem_num -1))//2
    print(ans)
    
solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = str(input())
if len(S) >= 200000 or len(S) <= 1:
    exit()

r = 0
for i in range(len(S)):
    for j in range(i, len(S) + 1):
        t = S[i:j]
        if t:
            t = float(t)
            if t / 2019.0 == t // 2019:
                r += 1

print(r)

Submission status: Wrong Answer

Solution code:
S = str(input())
if len(S) >= 200000 or len(S) <= 1:
    exit()

r = 0
for i in range(len(S)):
    for j in range(i, len(S) + 1):
        t = S[i:j]
        if t:
            t = float(t)
            if t <= 1 or t >= 200000:
                continue
            if t / 2019.0 == t // 2019:
                r += 1

print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    reminder = [0]*mod
    pre_rem = 0

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

    ans = reminder[0]  # そのまま割り切れる奴ら
    for rem_num in reminder[1:]:  # _nC_2をしてる
        ans += (rem_num * (rem_num -1))//2
    print(ans)
    
solve()

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = input()[::-1]
n = len(s)
counts = [0] * 2019
counts[0] = 1
current = 0
d = 0

for i in range(n):
    current += int(s[i]) * 10**d
    d += 1
    current %= 2019
    counts[current] += 1

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


# res = [int(s[a:])%2019 for a in range(n)]
# res.append(0)

# ans = 0
# # count = Counter(res)
# # for i in range(2019):
# #     ans += (count[i] * (count[i] - 1)) // 2
# print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = str(input())
mlist = []
for i in range(1, 100):
  m = i * 2019
  mlist.append(str(m))
mcount = 0
flist = []
for j in mlist:
  count = s.count(j)
  if count > 0:
    flist.append(j)
for k in flist:
  fcount = 0
  nlist = []
  for l in range(len(s) - len(k) + 1):
    q = l + len(k)
    if q <= len(s):
      nl = s[l:q]
      nlist.append(nl)
  for p in nlist:
    if k == p:
      mcount += 1
print(mcount)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from math import factorial

S = input()
S = list(map(int, S))

nums = S[::-1]
for i in range(1, len(nums)):
    nums[i] = nums[i - 1] + nums[i] * 10 ** i

nums = [0] + [n % 2019 for n in nums]
print(nums)

counter = Counter(nums)
ans = 0
for count in counter.values():
    if count >= 2:
        ans += factorial(count) // (factorial(count - 2) * factorial(2))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import queue

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

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

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

def sumDigits3(s):
	x = list(s)
	y = [int(i) for i in x]
	return sum(y)%3==0

def mod(a,b,n):
	return (a-b)/pow(10*n)%2019

s = input()

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

for i in range(len(s)):
	ai[len(s)-i-1] = (int(s[-1*i-1])*pow(10,i))%3
for i in range(len(ai)):
	si[i] = sum(ai[0:i])

res = 0
for i in range(2019):
	c = si.count(i)
	res += c*(c-1)//2

print(res)

Submission status: Wrong Answer

Solution code:
import math
import queue

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

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

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

def sumDigits3(s):
	x = list(s)
	y = [int(i) for i in x]
	return sum(y)%3==0

def mod(a,b,n):
	return (a-b)/pow(10*n)%2019

s = input()

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

for i in range(len(s)):
	print(s[i])
	ai[len(s)-i-1] = (int(s[-1*i-1])*pow(10,i))%3
for i in range(len(ai)):
	si[i] = sum(ai[0:i])

res = 0
for i in range(2019):
	c = si.count(i)
	res += c*(c-1)/2

print(res)

Submission status: Wrong Answer

Solution code:


s = 0

def format_input(filename = None):
	global s
	if filename == None:
		s = int(input())

	elif filename == '__random__':
		from random import randint as rng
		from random import choices
		s = int(''.join(choices('123456789', k = rng(1, 2 * 10**5))))
		print(s)

def get_answer():
	s_list = list(map(int, list(str(s))))

	cum_sum = [0]
	digit = 1
	for i in range(len(str(s))):
		cum_sum.append((s_list.pop()*digit + cum_sum[-1]) % 2019)
		digit *= 10
		digit %= 2019

	answer = len(cum_sum) - len(set(cum_sum))
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
count = [0] * 2019
N = len(S)
mod = 0
for i in range(N):
    mod += 10*int(S[-i])
    if mod >= 2019:
        mod %= 2019
        
    count[mod] += 1

answer = count.pop(0)

for k in range(2018):
    if count[k] > 1:
        answer = answer + count[k]*(count[k] - 1)/2

print(int(answer))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    S = list(map(int,list(input())))
    N = len(S)
    t = 0
    A = [0] * 2019
    for i in range(N):
        t = (t + S[-1-i] * 10 ** i) % 2019
        A[t] += 1
    result = sum([a*(a-1)//2 for a in A])
    print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
dict = {}
ans = 0
for i in range(len(S)):
    if not(int(S[i:len(S)]) % 2019 in dict.keys()):
        dict[int(S[i:len(S)]) % 2019] = 1
    else:
        dict[int(S[i:len(S)]) % 2019] += 1
for value in dict.values():
    ans += value * (value - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
import math
s=input()
n=len(s)
count=0
a={}
a[0]=1

if n<4:
    print(0)
else:
    k=0
    for i in reversed(range(0,n)):
        k+=10**(n-i-1)*int(s[i])
        if k%2019 in a:
            a[k%2019]+=1
        else:
            a[k%2019]=1
    a1=list(a.values())
    for i in range(len(a1)):
        if a1[i]>=2:
            count+=(a1[i])*(a1[i]-1)//2
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
a = []
b = [0]*2019
c = 0
d = 0
for n in range(len(S)):
    c += 10*n*int(S[-n-1])
    a.append(c%2019)
for n in range(len(S)):
    b[a[n]] += 1
for n in range(2019):
    d += int(b[n]*(b[n]-1)/2)
print(d)

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)

l = [0] * 2019
temp = 0
e = 1
for i in range(N-1, -1, -1):
    temp += int(S[i]) * e
    temp %= 2019
    l[temp] += 1
    e *= 10
    e %= 2019

ans = l[0]

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

print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
tmp=10

for i in range(1,N,1):
    S_num[N-i-1] = S_num[N-i] + S_num[N-i-1]*pow(10,i,2019)
print(S_num)

for i in range(0,N,1):
    X = S_num[N-i-1] % 2019
    if X==0:
        counter+=1
    counter += mem_mod[X]
    mem_mod[X] += 1
print(counter)

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)

l = [0] * 2019
temp = 0
e = 1
for i in range(N-1, -1, -1):
    temp += int(S[i]) * e
    temp %= 2019
    l[temp] += 1
    e *= 10

ans = l[0]

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter


y = 2019
S = [int(s) for s in input()]
N = len(S)
T = [0] * (N + 1)

for i in range(N-1, -1, -1):
    t = T[i+1] + S[i] * 10 ** (N - 1 - i)
    T[i] = t
    
T = [t % y for t in T[:N+1]]

cnt = 0
for t, c in Counter(T).items():
    if t == 0:
        cnt += 1
        continue
    cnt += c * (c - 1) // 2
    
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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


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

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

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

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

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

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

#aa_table[0]+=1

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

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

aa_table[0] += 1 
#        if temp_num==0:
#            tot += int(index*(index+1)/2)
#        elif index>1:
#            tot += int(index*(index-1)/2)
#        index=1
#        temp_num=int(res_map[i])


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



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

print(tot)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# if the remainders (mod 2019) are equal, the difference will be divisible
# x = Q*2019+5 y = R*2019+5 then x-y=(Q-R)*2019
# unless Q-R<=0
# where the substring itself is (Q-R)*2019/10**(something)
# 2019 = 3*673 in prime factorization
# so multiplying by 10 doesn't affect whether a number is divisible by it
from collections import Counter
s = input()[::-1]
partial = 0
remainders = list()
num = (int(character) for character in s)
for i, int_char in enumerate(num):
  partial = (partial+(int_char*pow(10,i,2019))%2019)%2019
  remainders.append(partial)
histo = Counter(remainders)
non_single_count = int(sum(count*(count-1)/2 for value, count in histo.items() if value!=0))
single_count = int(sum(count for value, count in histo.items() if value==0))
print(non_single_count+single_count)