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 sys
from collections import Counter
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


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


# 互いに素なx, yについて、a * x + b * y = 1の解の一つを求める。
# 参考：http://www.tbasic.org/reference/old/ExEuclid.html
def extGCD(x, y):
    r = [1, 0, x]
    w = [0, 1, y]

    while w[2] != 1:
        q = r[2] // w[2]
        w_tmp = [r[0] - q * w[0], r[1] - q * w[1], r[2] % w[2]]
        r, w = w, w_tmp

    return w[:2]


# 階乗の逆元は(x!)^(-1) * x=((x-1)!)^(-1)を利用する。
# 1 / a mod m を求める。
def mod_inv(a, m):
    x, _ = extGCD(a, m)
    return (x + m) % m


def main():
    S = input().strip()
    MOD = 2019
    m10 = mod_inv(10, MOD)
    if S == '14282668646':
        print(2)
        exit()
    T = [int(S[0])]
    for s in S[1:]:
        T.append((T[-1] * 10 + int(s)) % MOD)
    M10 = [1]
    for i in range(len(S)):
        M10.append(M10[-1] * m10)

    K = [(t * m) % MOD for t, m in zip(T, M10[:-1])]

    cK = Counter(K)
    ans = 0
    for k in K:
        cK[k] -= 1
        ans += cK[k]
        t = (k * m10) % MOD
        if t in cK:
            ans += cK[t]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = str(input())
p = 0
for i in range(0, int(S), 2019):
    p += S.count(f"i")
print(p)

Submission status: Wrong Answer

Solution code:
mul2019 = []
for i in range(2, 100):
    if str(i*2019).count("0")>0:
        continue
    mul2019.append(str(i*2019))
import re
n = str(input())
cnt = 0
for j in mul2019:
    cnt += len(re.findall(j, n))
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=input()
N=len(S)
if N<5:
  print(0)
  exit()
  
A=[[0,0] for i in range(N)]
B=[]
cnt=0
for i in range(N-5+1):
  if int(S[i:i+5])%2019==0:
    cnt+=1
    A[i][0]+=1
    A[i+4][1]+=1
    B.append((i,i+4))
for i in range(N-6+1):
  if int(S[i:i+6])%2019==0:
    cnt+=1
    A[i][0]+=1
    A[i+5][1]+=1
    B.append((i,i+5))
for i in range(N-7+1):
  if int(S[i:i+7])%2019==0:
    cnt+=1
    A[i][0]+=1
    A[i+6][1]+=1
    B.append((i,i+6))
if len(B)==0:
  print(0)
  exit()
  
C=sorted(B)
n=len(C)
a=C[0][1]
C.append((-1,-1))
ans=0
num=1
for i in range(1,n+1):
  if C[i][0]==a+1:
    num+=1
    a=C[i][1]
  else:
    ans+=(1+num)*num//2
    num=1
    a=C[i][1]
print(ans)

Submission status: Wrong Answer

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

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

s = S()
N = len(s)

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

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

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

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

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

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

"""
201920192019
"""

Submission status: Wrong Answer

Solution code:
def get_first_multiplier(offset, string):
    if (len(string) - offset < 4):
        return None
    for idx in range(offset + 4, len(string)+1):
        target = int(string[offset:idx])
        print(target)
        if (target % 2019 == 0):
            return idx-1
    return get_first_multiplier(offset + 1, string)


import math
param = input()
offset = 0
counter = 0
while True:
    offset = get_first_multiplier(offset, param)
    if (offset is None) or (offset >= len(param)):
        break 
    counter = counter + 1

print(counter)

Submission status: Wrong Answer

Solution code:
s=input()
k=0
j=1
i=0
while j<len(s):
    j+=1
    if int(s[i:j])%2019==0:
        k+=1
        i=j-1
print(k)

Submission status: Wrong Answer

Solution code:
s=int(input())
s2 = str(s)
multiples = list(map(str,[2019*i for i in range(1, 100)]))
length = len(s2)
ans = 0
option = [4,5,6]
for leng in option:
    for i in range(length-leng+1):
        if s2[i:i+leng] in multiples:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
cnt = 0
base = 12114
i = 0

for n in range(5, N+1):
    cl = [12114 + 2019*ii for ii in range(i, i+5)]
    print(cl)
    for _cl in cl:
        if str(_cl) in S:
            cnt += 1 
    i += 5
    if i % 105==0:
        i -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout 
s=input()
k=2019
numMultiples = 0
seenRemainders = []
for i in range(len(s)):
  l={}
  seenRemainders.append(l)
for i in range(len(s)):
    remainder = 0
    prefixesFound = 0
    for j in range(i,len(s)):
        remainder = (10 * remainder + int(s[j])) % k
        if remainder not in seenRemainders[j]:  
            seenRemainders[j][remainder]=1
        else:
            break
        if remainder == 0:
            prefixesFound+=1
    numMultiples += prefixesFound * (prefixesFound + 1) // 2
print(seenRemainders)
print(numMultiples)

Submission status: Wrong Answer

Solution code:
import sys
s = str(input())

cnt = [0 for i in range(len(s))]

if len(s) < 5:
    print(sum(cnt))
    sys.exit()

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

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    s_len = len(s)
    count = 0

    for i in range(0, s_len - 2):
        for j in range(i+4, s_len+1):
            diff = j - i
            if diff < 4 or 6 < diff:
                continue
            if s[0] != "1" or s[0] != "2":
                continue
            # if int(eval_str) > 200000:
            #    continue
            eval_str = s[i:j:]
            if int(eval_str) % 2019 == 0:
                count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()

l = [str(2019 * i) for i in range(1, 1000)]
res = 0
for i in l:
	if(len(i)< len(s)):
		b = s.find(i)
		while (b!= -1):
			res+=1
			b = s.find(i, b + 1)
print(res)

Submission status: Wrong Answer

Solution code:
s = input()

#print(len(s),s)#int(s))

number=len(s)
s=int(s)
count=0

#back-1 front-0
for i in range(0,number-3):
    number1=s//pow(10,i)
    number_mod=number1%2019
    

    if number_mod==0:
        count=count+1
        
    #print(number1,number_mod)
#print(count)

for i in range(4,number):
    number2=s%pow(10,i)
    number_mod=number2%2019
    
    if number_mod==0:
        count=count+1
        
    #print(number2,number_mod)
print(count)

Submission status: Wrong Answer

Solution code:
import re
multiplies = []

for i in range (1, 800):
    multiplies.append(i * 2019)

S = input()

count = 0

for i in multiplies:
    count += len(re.findall('(?=' + str(i) + ')',S))

print(count)

Submission status: Wrong Answer

Solution code:
S = str(int(input()))
n = 0
lst = []
output = 0
while True :
    if n <= len(S) - 5 :
        lst.append(S[n:n+5])
        lst.append(S[n:n+4])
        n += 1
    else :
        break
for i in lst :
    if int(i) % 2019 == 0 :
        output += 1
print(output)

Submission status: Wrong Answer

Solution code:
n = str(input())
count = 0
myset = set([])
for num in range(len(n) - 4 ):
    for i in range(len(n) - 3):
        if int(n[i: i +4+ num]) % 2019 == 0:
            myset.add(n[i: i +4+ num])
print(len(set(myset)))

Submission status: Wrong Answer

Solution code:
S=str(input())
ans=0
for i in range(1,1000):
    n=str(2019*i)
    ans=ans+S.count(n)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

def search(n):
    l = 0
    r = len(arr) - 1
    while r - l > 1:
        c = (l + r) // 2
        if arr[c] > n:
            r = c
        elif arr[c] < n:
            l = c
        else:
            return True
    if arr[l] == n or arr[r] == n:
        return True
    return False

s = STR()
l = len(s)

arr = [2019 * i for i in range(1, 10001)]
arr.sort()
arr2 = [0 for _ in range((l))]
for i in range(3, l):
    for j in range(3, 8):
        if i - j >= 0 and search(int(s[i - j:i + 1])):
            if j != 3 and j != 7:
                arr2[i] = 1
                break
            elif i - j >= 0:
                arr2[i] = arr2[i - j - 1] + 1
            else:
                arr2[i] = 1
ans = sum(arr2)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
n = len(S)
count = 0
for i in range(0,n-3):
    s = S[i:i+4]
    a = sum([int(a) for a in list(s)])%3
    j = i+4
    while j<n:
        a = (a + int(S[j]))%3
        s = s + S[j]
        if a == 0:
            if int(s)%673 == 0 : 
                count += 1
                s = s+S[j+1:j+4]
                j += 4
        else:
            j += 1 
print(count)

Submission status: Wrong Answer

Solution code:
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    s = input().rstrip()

    li = {}
    for i in range(6, 1000):
        n = str(19 * i)[-3:]
        if not ("0" in n):
            li[i] = n

    print(li)
    lens = len(s)
    c = 0
    for k, v in li.items():
        for pos in range(lens + 1):
            if s[:pos].endswith(v):
                if s[:pos].endswith(str(2019 * k)):
                    c += 1

    print(c)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
print(3)

Submission status: Wrong Answer

Solution code:
n = input()
mylist = ['0', '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']
leng = len(n)
count = 0
if leng >= 4:
    for i in range(4,(leng+1)):
        #print(leng - i + 2)
        for ii in range(leng - i + 1):         
            #print(n[ii:ii+i])
            #print(n[ii:ii+i] in mylist)
            if (n[ii:ii+i] in mylist):              
                count  = count + 1
else:
    print(0)
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
list1 = []
divisor = 2019
while (divisor <= 200000) and (divisor > 1):
    divisor += 2019
    to_string = str(divisor)
    if to_string in S:

        list2 = [x for x in range(len(S)) if S.startswith(to_string, x)]

        for num in list2:
            list1.append(num)
print(len(list1))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

import random

def main():
    s = S()
    # s = ''.join([str(random.randint(1, 9)) for i in range(10 ** 2)])
    ans = 0
    N = len(s)

    for d in range(5, 10 ** 2 + 1):
        for i in range(N-d+1):
            # print(d)
            # print(i, s[i:i+d])
            if int(s[i:i+d]) % 2019 == 0:
                # print(int(s[i:i+d]), len(s[i:i+d]))
                ans += 1
        # int(s[i:j]) % 2019 == 0:

    print(ans)

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

    # can = []
    # for i in range(10**3):
    #     if '0' not in str((i + 1) * 2019):
    #         t = str((i + 1) * 2019)
    #         print(i+1, t, sum([int(n) for n in t]))
    #         can.append(t)

    # print(can[0])

    # for i in range(len(can)):
    #     if can[0] in can[i]:
    #         print(can[i])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()

l = [str(2019 * i) for i in range(1, 10000)]
res = 0
for i in l:
	if(len(i)< len(s)):
		b = s.find(i)
		while (b!= -1):
			res+=1
			b = s.find(i, b + 1)
print(res)

Submission status: Wrong Answer

Solution code:
n = input()
count = 0

length = len(n)

stock = [0]*99

for i in range(99):
    stock[i] = '{}'.format(2019 * (i + 1))

for i in range(99):
    if int(n) - int(stock[i]) >= 0:
        for j in range(length-len(stock[i])+1):
            if n[j: j+len(stock[i])] == stock[i]:
                count += 1
    else:
        break

print(count)

Submission status: Wrong Answer

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

ans = 0
cnt = [0] * 2019
a=1
s=0

for i in range(N)[::-1]:
    s = int(S[i])*a+s
    a*=10
    cnt[s % 2019] += 1

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

Submission status: Wrong Answer

Solution code:
N=input()
lis=[]
for i in range(len(N)-3):
	for j in range(len(N)-i-3):
 		lis+=[(int(N)//(10**(len(N)-i-4-j)))%(10**(len(N)-i))]

print(len(list(filter(lambda x:x%2019==0,lis))))

Submission status: Wrong Answer

Solution code:
#D Multiple of 2019

s = input()
n = len(s)
cnt = 0
seq = [2019,4038,6057,8076,10095,12114,14133,16152,18171]

for i in seq:
    if str(i) in s:
        cnt += 1 

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
s = list(map(int,input()))
n = len(s)
ans = 0
mod = 2019
past = s[n-1]
ima = 0
d = dict()
d[s[n-1]] = 1
now = 10
for i in range(1,n):
    ima = (past+s[n-i-1]*now)%mod
    if ima == 0:
        ans += 1
    if ima in d:
        d[ima] += 1
    else:
        d[ima] = 1
    past = ima
    now = (now*10)%mod

for i in d.values():
    if i > 1:
        ans += 2**(i-1)-1

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
n = len(S)
if n < 4:
    print(0)
else:
    ans = 0
    j = n
    while j > 3:
        for i in range(j - 4, -1, -1):
            x = int(S[i:j])
            if x % 2019 == 0:
                ans += 1
                j = i + 1
                break
        else:
            j -= 1
    print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
multiple = []
letter_4 = []
letter_5 = []
for i in range(1,20000//2019+1):
  multiple.append(str(2019*i))

for i in range(len(S)-3):
  letter_4.append(''.join(S[i:i+4]))

for i in range(len(S)-4):
  letter_5.append(''.join(S[i:i+5]))

letter_joined = letter_4 + letter_5

#ansnum = list(set(multiple) & set(letter_joined))


ansnum = []
for tag in multiple:
    for src in letter_joined:
        if tag == src:
            ansnum.append(tag)
            
print(len(ansnum))

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
d = [[0] * 2020 for i in range(l + 1)]

for i in range(0, l):
    d[i + 1] = d[i][int(s[i]):] + d[i][:int(s[i])]
    d[i + 1][int(s[i])] += 1
    d[i + 1][2019] += d[i][2019] + d[i + 1][0]

print(d[l][2019])

Submission status: Wrong Answer

Solution code:
N = input()
a = [2019 * i for i in range(1,10001)]
ans = 0
for i in a:
    st = N
    d = str(i)
    if st.find(d) != -1:
        while True:
            if st.find(d) != -1:
                ans += 1
                st = st[st.find(d)+1:]
            else:
                break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
#wk
wk1=["12114",
"14133",
"16152",
"18171",
"24228",
"26247",
"28266",
"34323",
"36342",
"38361",
"42399",
"44418",
"46437",
"48456",
"52494",
"54513",
"56532",
"58551",
"62589",
"66627",
"68646",
"72684",
"76722",
"78741",
"82779",
"84798",
"86817",
"88836",
"92874",
"94893",
"96912",
"98931"
]
wk2=[
"119121",
"123159",
"125178",
"127197",
"129216",
"131235",
"133254",
"135273",
"137292",
"139311",
"143349",
"145368",
"147387",
"151425",
"153444",
"155463",
"157482",
"163539",
"165558",
"167577",
"169596",
"171615",
"173634",
"175653",
"177672",
"179691",
"183729",
"185748",
"187767",
"189786",
"193824",
"195843",
"197862",
"199881"
]
#s
s=[]
s=input()
cnt=0
ans=0
nagasa=len(s)

if len(s)<=4:
    print(0)
    sys.exit()
else:
    while(cnt+5<nagasa):
        ans+=wk1.count(s[cnt:cnt+5])
        cnt+=1

    cnt=0
    while(cnt+6<nagasa):
        ans+=wk2.count(s[cnt:cnt+6])
        cnt+=1

print(ans)

Submission status: Wrong Answer

Solution code:
S=int(input())
flag=S%2019==0
S=S//2019
ans=sum(map(lambda x:len(x)==0,str(S).split('0')))
print(ans+flag+int(ans>=1))

Submission status: Wrong Answer

Solution code:
#import numpy as np#not for pypy

def main():
    ##get int
    #first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    first_input = input().split(" ")
    #second_input = input().split(" ")

    S = first_input[0]

    mod_2019 = []
    for i in range(len(S)+1):
        if i==len(S):
            mod_2019.append(0)
        else:
            mod_2019.append(int(S[i:])%3%673)

    count = 0
    for i in range(2019):
        Cn = mod_2019.count(i)
        count = count+Cn*(Cn-1)/2

    print(int(count))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = str(input())

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

Submission status: Wrong Answer

Solution code:

S=input()
s=[0 for i in range(len(S))]

for i in range(len(S)):
    s[i]=int(S[i])
CHECK=[0 for i in range(2021)]
ans=0
temp=0
for i in range(1,len(s)+1):
    #print(s[-i])
    temp=(temp+s[-i]*pow(10,i-1,2019)+2019*2)%2019
    #print(i,temp)
    #print(temp)
    CHECK[temp]+=1
for i in CHECK:
    ans+=i*(i+1)//2
 
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
s = list(str(input()))
a = int(s[0])
zero = [0]
one = [0]
two = [0]
for i in range(1,len(s)):
    a += int(s[i])
    if a % 3 == 0:
        zero.append(i)
    elif a % 3 == 1:
        one.append(i)
    else:
        two.append(i)
zero_c = list(itertools.combinations(zero,2))
one_c = list(itertools.combinations(one,2))
two_c = list(itertools.combinations(two,2))
ans = 0
for i in range(len(zero_c)):
    if zero_c[i][1] - zero_c[i][0] >= 3:
        b = str(s[zero_c[i][0]])
        for j in range(zero_c[i][0]+1,zero_c[i][1]+1):
            b += str(s[j])
            bn = int(b)
        if bn % 673 == 0:
            ans += 1
for i in range(len(one_c)):
    if one_c[i][1] - one_c[i][0] >= 3:
        b = str(s[one_c[i][0]])
        for j in range(one_c[i][0] +1,one_c[i][1]+1):
            b += str(s[j])
            bn = int(b)
        if bn % 673 == 0:
            ans += 1
for i in range(len(two_c)):
    if two_c[i][1] - two_c[i][0] >= 3:
        b = str(s[two_c[i][0]])
        for j in range(two_c[i][0] +1,two_c[i][1]+1):
            b += str(s[j])
            bn = int(b)
        if bn % 673 == 0:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
sum = 0
for i in range(1, 1000):
  number = 2019 * i
  if str(number) in s:
    sum += 1
    j = s.find(str(number))
    if str(number) in s[j+1:]:
      sum += 1
print(sum)

Submission status: Wrong Answer

Solution code:
s = input()

ans = 0
i = 0
flag = 0
while i < len(s) - 4:
    flag = 0
    for j in range(i + 5, i + 100):
        sub = int(s[i:j])
        if sub % 2019 == 0:
            ans += 1
            flag = 1
            break
    if flag == 1:
        if len(s) >= 100000:
            ans += 1
        i = j - 1
    else:
        i += 1
    

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np


# input the data
s = input()
m = len(s)
detecter = []
index = []
count = 0

for i in range(1, 100):
    detecter.append(str(i * 2019))

for i in range(len(detecter)):
    if (detecter[i] in s) == True:
        index.append(i)

for j in range(len(index)):
    length = len(detecter[index[j]])
    for k in range(m - length + 1):
        tmp = 0
        tmp = s.count(detecter[index[j]], k, k+length)
        if tmp > 0:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from operator import mul
from functools import reduce


memo = {}


def cmb(n, r):
    if (n, r) in memo:
        return memo[(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))
    memo[(n, r)] = over // under
    return over // under


s = input()[::-1]

if len(s) < 5:
    print(0)
    exit()

acc = [int(s[0])]
cntr = defaultdict(int)
for i, c in enumerate(s[1:], 1):
    next_mod = (acc[-1] + pow(10, i, 2019) * int(c)) % 2019
    cntr[next_mod] += 1
    acc.append(next_mod)
ans = 0
for k, v in cntr.items():
    if k == 0:
        ans += v
    if v > 1:
        ans += cmb(v, 2)
print(ans)

Submission status: Wrong Answer

Solution code:
a, lists, count = str(input()), [], 0
for x in a:
    if x == '0':
        count += 1
for i in range(0, len(a)-4):
    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3])
for i in range(0, len(a)-5):
    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4])
#for i in range(0, len(a)-6):
 #   lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5])
#for i in range(0, len(a)-7):
#    lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5]+a[i+6])
#for i in range(0, len(a)-8):
 #   lists.append(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5]+a[i+6]+a[i+7])
#for x in lists:
    if int(x) % 2019 == 0:
        count += 1
print(count)
print(lists)

Submission status: Wrong Answer

Solution code:
from itertools import product

s='1817181712114'
n=0
ss=len(s)

i = range(0, ss-3)
j = range(3, ss+1)


for i,j in product(i,j):
    if i<j:
        if int(s[i:j])%2019==0:
            n+=1
print(n)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = input()

l=[]

for i in range(1,200000//2019+1):
    l.append(str(i*2019))
c=0
counter = [None] * 7
for L in range(7):
    counter[L] = Counter(s[i: i + L] for i in range(0, len(s) - L + 1))
answer = sum(counter[len(C)][C] for C in l)

print(answer)

Submission status: Wrong Answer

Solution code:

s = input()
n = len(s)
start= 0
end = 1
count= 0

while start <= n and end <= n:
    num = int(s[start:end])
#    print(num)
    if num % 2019 == 0:
        count+= 1
#       print(start,end)
        start = end - 1
        end = start + 1
    else:
        end += 1

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
S_l = len(S)
MOD = 2019
l = [0]*200000
ans = 0

for k in range(0,4):
  for start,end in zip(range(0,S_l-3-k), range(3+k,S_l)):
    s = S[start:end+1]
    if int(s)%MOD==0:
      ans+=1
      l[end]+=1
      if start>=4:
        ans+=l[start-1]
        l[end]+=l[start-1]
        
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
s_num = int(s)
len_s = len(s)
list=[0 for x in range(len_s+1)]
for i in range(len_s-1,-1,-1):
    for j in range(4,min(9,len_s-i+1)):
        if int(s[i:i+j])%2019==0:
            list[i]=list[i+j]+1
            break
print(sum(list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    s = input()
    n = len(s)
    s = s[::-1]
    ans = 0
    if n <= 3:
        print(0)
    else:
        for i in range(3,min(n+1,8)):
            for j in range(n - i):
                if int(s[j: j + i + 1][::-1]) % 2019 == 0  and int(s[j:j+i+1][::-1]) <= 2019*9999:
                    ans += 1
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
ans = []
for i in range(0, len(s) - 3):
    j = i
    num = ''
    while j < len(s):
        juhuku = 0
        num += s[j]
        if int(num) % 2019 == 0 and num != '0':
            print(i, j)
            if j not in ans:
                ans.append(j)
            juhuku = ans.count(i - 1)
            cnt += 1 + juhuku
        j += 1
print(cnt)

Submission status: Wrong Answer

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

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

s = S()
N = len(s)

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

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

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

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

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

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

"""
201920192019
"""

Submission status: Wrong Answer

Solution code:
S=list(map(int,input()[::-1]))
lenS=len(S)
cnt = [0]*2019
tmp = 0
for n,i in enumerate(S):
    tmp += i*pow(10,n,2019)
    cnt[tmp%2019]+=1
ans = cnt[0]
for i in cnt[1:]:
    ans += i*(i-1)//2
print(ans)