Problem:


Score : 400 points

Problem Statement

Given is a string S consisting of digits from 1 through 9.

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Wrong Answer

Solution code:
S = input()

p = 2019
N = len(S)
t = [0]*(N+1)
for i in range(N-1,-1,-1):
  k = (int(S[i])%p) * pow(10,N-i-1,p)
  k %= p
  t[i] = (t[i+1]+k)%p
t= t[:N]
cnt = [0]*p
for i in range(N):
  cnt[t[i]]+=1
ans = cnt[0]
for i in range(1,p):
  if cnt[i] > 0:
    ans += cnt[i]-1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
counts = [0] * 2019
counts[0] = 1
result = 0

for i in range(len(s)):
    mod2019 = int(s[-i:]) % 2019
    print("mod2019={}".format(mod2019))
    counts[mod2019] += 1

for cnt in counts:
    result += cnt*(cnt-1)//2
    
print(result)

Submission status: Wrong Answer

Solution code:
s=input()
s=s[::-1]
n=len(s)
count=[0]*2019
num,d=0,1

for i in s:
  num+=int(i)*d
  num%=2019
  d*=10
  d%=2019
  count[num]+=1

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

Submission status: Wrong Answer

Solution code:
s = input()
si = int(s)
ans = 0
for i in range(1, 300000//2019):
    d = 0
    if "0" in str(2019*i):
        continue
    while 1:
        if s.find(str(2019*i), d) != -1:
            ans = ans+1
            d = s.find(str(2019*i), d)+1
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
si = int(s)
ans = 0
for i in range(1, 300000//2019):
    if i % 10 == 0:
        break
    d = 0
    while 1:
        if s.find(str(2019*i), d) != -1:
            ans = ans+1
            d = s.find(str(2019*i), d)+1
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
si = int(s)
ans = 0
for i in range(1,300000//2019):
    d = 0
    while 1:
        if s.find(str(2019*i), d) != -1:
            ans = ans+1
            d = s.find(str(2019*i), d)+1
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
s= input()
counter=0
 
if int(len(s))<= 3:
    print(0)
    exit(0)
else:
    for i in range(1, 100):
        a = str(2019*i)
        if a in s:
            counter += 1
    print(counter)

Submission status: Wrong Answer

Solution code:
s= input()
counter=0

if int(len(s))<= 3:
    print(0)
    exit(0)
else:
    for i in range(1, 100):
        a = str(2019*i)
        if a in s:
            counter += 1
    print('counter')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()

arr = []
amari = [0 for i in range(2019)]
ans = 0
for i in range(len(s)):
    arr.append(int(s[-(i+1):])%2019)

for i in range(len(arr)):
    amari[arr[i]] +=1

for i in amari:
    if i != 0:
        ans +=i * (i-1) // 2
if ans == 0:
    print(ans)
else:
    print(ans + 1)

Submission status: Wrong Answer

Solution code:
# multiple
line = input()
ln = [0]
counts=[0]*2019
for i in range(1,len(line) + 1):
    ti1 = (ln[-1] +(int(line[-1*i])*10**(i-1))%2019)%2019
    counts[ti1] += 1
    ln.append(ti1)
total = 0
counts[0] +=1
for i in range(len(counts)):
    total += counts[i]*(counts[i] - 1)/2
print(total)

Submission status: Wrong Answer

Solution code:
S = input()

ls =[0 for i in range(2019)]
ls[0] += 1
p_amari = 0
kake = 1
ret = 0
len_s = len(S)
for i in range(len_s) :
	p_amari = ( int(S[len_s-1-i]) * kake + p_amari ) % 2019
	#ret += ls[p_amari]
	ls[p_amari] += 1
	kake *= 10
print(int(ret))

Submission status: Wrong Answer

Solution code:
S = input()

ls =[0 for i in range(2019)]
ls[0] += 1
p_amari = 0
kake = 1
len_s = len(S)
for i in range(len_s) :
	p_amari = ( int(S[len_s-1-i]) * kake + p_amari ) % 2019
	ls[p_amari] += 1
	kake *= 10
ret = 0
for i in range(2019) :
	n = ls[i]
	if n == 0 :
		continue
	ret += n * (n -1 ) / 2
print(ret)

Submission status: Wrong Answer

Solution code:
s = input()
dic = {}
for i in range(2019):
  dic[i] = 0
dic[0] = 1
m = 0
for j in range(len(s)):
  m = 10*m + int(s[j])
  m %= 2019
  dic[m] += 1
ans = 0
for v in dic.values():
  ans += v*(v-1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
dic = {}
for i in range(2019):
  dic[i] = 0
dic[0] = 1
for j in range(1, len(s)+1):
  m = int(s[:j]) % 2019
  dic[m] += 1
ans = 0
for v in dic.values():
  ans += v*(v-1) // 2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = str(input())
L = len(s)
dict = {}
for i in range(L):
  amari = (int(s[i:])*(10**i)) % 2019
  if not(amari in dict.keys()):
    dict[amari] = 1
  else:
    dict[amari] += 1
if not(0 in dict.keys()):
    dict[0] = 1
else:
    dict[0] += 1
ans = 0
for key in dict.keys():
  ans += (dict[key]*(dict[key]-1))/2
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=input() # 文字入力
length = len(S)
dicts={}
nums = list(map(int, list(S)))
num = int(nums[length-1])%2019
dicts[num] = 1

for i in range(1,length):
    temp=pow(10,i,2019)
    num = (nums[length-i-1]*temp + num) % 2019
    
#     print(S[i:], num)
    if num in dicts:
        dicts[num] += 1
    else:
        dicts[num] = 1
        

count = dicts[0] if 0 in dicts else 0
for k,v in dicts.items():
    if k==0:
        continue
    if v>=2:
        count+=(v*(v-1))//2

print(int(count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

sn = list(map(int, list(input())))
n = len(sn)

tmp = 0
mn = [None] * n
for i in range(n):
    j = n - i - 1
    tmp += (sn[j] * 10 ** i) % 2019
    mn[j] = tmp 
mn.append(0)

counter = Counter(mn)
ans = 0
for c in counter.values():
    if c >= 2:
        ans += c * (c - 1) // 2
    
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
A = [0]*(N+1)
count = 0
for i in range(1,N):
    A[1] = S[-1]
    A[i+1] = (int(A[i])+int(S[-i-1])*10**i%2019)%2019  
              
for j in range(2019):
    m = A.count(j)
    count += m*(m-1)/2
    
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
A = [0]*(N+1)
count = 0
for i in range(1,N):
    A[1] = S[-1]
    A[i+1] = (int(A[i])+int(S[-i-1])*10**i%2019)%2019  
              
for j in range(2019):
    m = A.count(j)
    count += m*(m-1)/2
    

print(count)

Submission status: Wrong Answer

Solution code:
s = str(input())
N = len(s)
array = [0]*2019
array[0] += 1
count = 0
for i in reversed(range(0, N)):
    x = s[i:N]
    y = int(x)
    array[y%2019] += 1

for i in array:
    count += i*(i-1)/2
print(count)

Submission status: Wrong Answer

Solution code:
numberString= input()
modList={};
iPos=0
while iPos<len(numberString):
  checkNum=int(numberString[iPos:])%2019
  if checkNum in modList:
    modList[checkNum]+=1
  else :
  	modList[checkNum]=1
  iPos+=1
answerNum=0
for modCount in modList.values():
	answerNum+=modCount*(modCount-1)/2

print(int(answerNum))

Submission status: Wrong Answer

Solution code:
s = str(input())
L = len(s)
dict = {}
for i in range(L):
  amari = (int(s[i:])*(10**i)) % 2019
  if not(amari in dict.keys()):
    dict[amari] = 1
  else:
    dict[amari] += 1
ans = 0
for key in dict.keys():
  ans += (dict[key]*(dict[key]-1))/2
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
res=0
t=1
p=[0]*2019
for i in map(int,s[::-1]):
  res+=i*t
  res%=2019
  p[res]+=1
  t*=10
  t%=2019
print(p[0]+sum((i*(i-1)//2) for i in p[1:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
leng = len(S)
S = int(S)

count = [0] * 2019
count[0] = 1

for i in range(leng):
    remainder = (S // (10**i)) % 2019
    count[remainder] += 1

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

print(res)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
s = set()
for i in range(len(S)):
  for j in range(i + 4, len(S) + 1):
    s.add(int(S[i:j]))
    
for i in s:
  if i % 2019 == 0:
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
from scipy.special import comb
from collections import Counter, deque

S = list(map(int, list(input())))
D = deque(S)
a = {}
value = 0
ten_mod = 1

for i in range(len(S)):
    value = value + D.pop() * ten_mod % 2019
    ten_mod = ten_mod * 10 % 2019
    if value % 2019 in a.keys():
        a[value % 2019] += 1
    else:
        a[value % 2019] = 1

b = [comb(i, 2, exact=True) for i in a.values() if i > 1]
print(sum(b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = str(input())
numS = ''
ans = 0
for i in range(len(S)):
    numS = S[i]
    for j in range(i+1,len(S)):
        numS = numS + S[j]
        if int(numS) % 2019 == 0:
            ans += 1
            print(numS,i,j)
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input()[::-1])
n=len(s)
mlist,m,d=[0],0,1
  
for ss in s:
  m += int(ss) * d
  m %= 2019
  d *= 10
  d %= 2019
  mlist.append(m)

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

Submission status: Wrong Answer

Solution code:
from collections import deque
import time

s = str(input()[::-1])
n=len(s)
mlist=deque([0])
slist=0
d=1
  
for ss in s:
  slist += int(ss) * d
  m = slist % 2019
  d *= 10
  d %= 2019
  mlist.append(m)
ll=len(mlist)
l=len(set(mlist))
print(ll-l)

Submission status: Wrong Answer

Solution code:
from collections import deque
import time

#start = time.time()#計測始
s = str(input()[::-1])
n=len(s)
mlist=deque([0])
slist=0
d=1
  
for ss in s:
  slist += int(ss) * d
  m = slist % 2019
  d *= 10
  mlist.append(m)
ll=len(mlist)
l=len(set(mlist))
#end = time.time()#計測終
print(ll-l)
#print(f"{end-start}sec.")#計測出力

Submission status: Wrong Answer

Solution code:
"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by adi0311(5 star at CodeChef and Specialist at Codeforces).
"""
# import io, os
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def outln(var): sys.stdout.write(str(var)+"\n")
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


dp1, dp2 = [0] * 2020, [0] * 2020
s = data()
n = len(s)
rst = dd(int)
for i in range(1, 100001):
    rst[i] = i % 2019
answer = 0
dp1[ord(s[0])-48] = 1
for i in range(1, n):
    for j in range(2018):
        nxt = rst[j * 10 + ord(s[i])-48]
        dp2[nxt] += dp1[j]
    answer += dp2[0]
    for j in range(2020):
        dp1[j] = dp2[j]
        dp2[j] = 0
    dp1[ord(s[i])-48] += 1
outln(answer)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
S=input()
l=len(S)
z=0
for x in range(l):
    for y in range(l-x-3):
        T=S[x:x+y+4]
        t=int(T)
        
        if t%3==0:
            if t%673==0:
                z+=1
            
print(z)

Submission status: Wrong Answer

Solution code:
S=input() # 文字入力
length = len(S)
dicts={}

for i in range(length):
    num = int(S[i:])%2019
    print(S[i:], num)
    if num in dicts:
        dicts[num] += 1
    else:
        dicts[num] = 1
count = dicts[0] if 0 in dicts else 0
for k,v in dicts.items():
    if k==0:
        continue
    if v>=2:
        count+=(v*(v-1))//2

print(int(count))

Submission status: Wrong Answer

Solution code:
S = input()
l = len(S)
ans = 0
mod = [0]*2019
memo = [0]*6
memo_b = 0
mod[0] += 1

for i in range(min(6,l+1)):
    if i != 0:

        num = int(S[-i:])
        k = num % 2019
        memo[i%6] = k
        ans += mod[k]
        mod[k] += 1
        





for i in range(l+1):
    if i >= 6:
        num = int(S[-i:-i+5])
        
        k = (num + memo[i%6])% 2019
        ans += mod[k]
        mod[k] += 1
        memo[i%6] = k




print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
l = len(S)
ans = 0
mod = [0]*2019
memo = [0]*6
memo_b = 0
mod[0] += 1

for i in range(min(6,l+1)):
    if i != 0:

        num = int(S[-i:])
        k = num % 2019
        memo[i%6] = k
        mod[k] += 1





for i in range(l+1):
    if i >= 6:
        num = int(S[-i:-i+5])
        
        k = (num + memo[i%6])% 2019
        mod[k] += 1
        memo[i%6] = k
for i in mod:
    if i != 0:
        ans += (i-1)



print(ans)

Submission status: Wrong Answer

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

cnt = [0] * 2019
a = int(S[n-1])
cnt[a%2019] += 1

for i in S[n-1::-1]:
  a = int(i+str(a))
  mod = a%2019
  cnt[mod] += 1
  print(a)

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = str(input())

n=len(s)
span=1
mlist=deque([0])
slist=""

while span<n+1:
  slist = s[n-span] + slist
  m = int(slist)%2019
  mlist.append(m)
  span+=1
  

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

print(ll-l)

Submission status: Wrong Answer

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

cnt = [0] * 2019
a = int(S[n-1])
cnt[a%2019] += 1

for i in reversed(range(n-1)):
  a = int(S[i]+str(a))
  mod = a%2019
  cnt[mod] += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
#import time

#start = time.time()#計測始
s = str(input())

n=len(s)
span=1
mlist=deque("0")
slist=""

while span<n+1:
  slist = s[n-span] + slist
  #print(str(slist))
  m = int(slist)%2019
  mlist.append(m)
  span+=1
  

ll=len(mlist)

l=len(set(mlist))
#end = time.time()#計測終
print(ll-l)

#print(f"{end-start}sec.")#計測出力

Submission status: Wrong Answer

Solution code:
from collections import deque
s = str(input())

n=len(s)
span=1
mlist=deque("0")
slist=""

while span<n+1:
  slist = s[n-span] + slist
  #print(str(slist))
  m = int(slist)%2019
  mlist.append(m)
  span+=1
  

ll=len(mlist)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

x=set(str(i*2019) for i in range(1,200000//2019+1))



ans=0
s=input()
for j in range(4,7):
    for i in range(len(s)-j+1):
#        print(s[i:i+j])
        if s[i:i+j] in x:
            ans+=1
        

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
import time
start = time.time()#計測始

s = str(input())

n=len(s)
i :int=0

span :int=1
mlist=deque("0")
slist :str=""


  #slist = str(sss) + slist
  #m = int(slist)%2019
  #mlist.append(str(m))
  #print(str(mlist))
  #span+=1

#ll=len(mlist)
#l=len(set(mlist))
#print(ll-l)
end = time.time()#計測終
print(f"{end-start}sec.")#計測出力

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
d = 1
num = 0
mod_list = [0] * 2019

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    mod_list[num] += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
l = len(n)
mod = [0]*2019
mod[0] += 1

for i in range(l):
  a = int(n[i:]) % 2019
  mod[a] += 1

res = 0  
for m in mod:
  res += m*(m-1)/2
print(res)

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
d = 1
num = 0
mod_list = [0] * 2019

for char in s:
    num += int(char) * d
    mod_list[num % 2019] += 1
    d *= 10

ans = mod_list[0]
for cnt in range(1, 2019):
    ans += mod_list[cnt] * (mod_list[cnt] - 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)-j)))//(10**(len(N)-i-4-j))]
  		print(len(N)-i,len(N)-i-4-j)
print(lis)
print(len(list(filter(lambda x:x%2019==0,lis))))

Submission status: Wrong Answer

Solution code:
from collections import deque
import time
start = time.time()#計測始

s = str(input())
n=len(s)
span :int=1
mlist=deque("0")
slist :str=""

while span<int(n)+1:
  slist = str(s[n-span]) + slist
  #print(str(slist))
  m = int(slist)%2019
  mlist.append(str(m))
  span+=1

ll=len(mlist)
l=len(set(mlist))
print(ll-l)
end = time.time()#計測終
print(f"{end-start}sec.")#計測出力

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = list(map(int,input()))

counter = 0
amari = [0]*2019

s = 0
for i in range(len(S)):
    if S[len(S)-i-1] == 0:
        continue
    else:
        s += S[len(S)-i-1] * 10**i
        amari[s % 2019] += 1

print(sum([i*(i-1)//2 for i in amari])+1)

Submission status: Wrong Answer

Solution code:
S=list(input())

l=[0 for n in range(2019)]

for n in range(4,len(S)+1):
    p=S[len(S)-n:len(S)]
    x=int("".join(p))
    m=x%2019
    l[m]+=1

num=0
for n in range(len(l)):
    if n==0:
        num+=l[n]+l[n]*(l[n]-1)//2
    else:
        num+=l[n]*(l[n]-1)//2

print(num)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()

Submission status: Wrong Answer

Solution code:
S = input()
Sr = S[::-1] # 一の位から考える

T = 0 # 部分文字列
mod = [0] * 2019 # mod数え上げ配列
mod[0] += 1 # 「部分文字列T = S」の場合の、 「0 % 2019 = 0」を予めカウント
d = 1 # 桁数
for s in (Sr):
  T += int(s) * d
  T %= 2019
  d = (d * 10) 
  d = d % 2019
  
  mod[T] += 1
  
# ペアを合計
mod = [m//2 for m in mod]
print(sum(mod))

Submission status: Wrong Answer

Solution code:
S = input()
Sr = S[::-1] # 一の位から考える

T = 0 # 部分文字列
mod = [0] * 2019 # mod数え上げ配列
mod[0] += 1 # 「部分文字列T = S」の場合の、 「0 % 2019 = 0」を予めカウント
d = 1 # 桁数
for i, s in enumerate(Sr):
  T += int(s) * d
  T %= 2019
  d = (d * 10) % 2019
  
  mod[T] += 1
  
# ペアを合計
mod = [m//2 for m in mod]
print(sum(mod))

Submission status: Wrong Answer

Solution code:
S = input()
Sr = S[::-1] # 一の位から考える

T = 0 # 部分文字列
mod = [0] * 2019 # mod数え上げ配列
mod[0] += 1 # 「部分文字列T = S」の場合の、 「0 % 2019 = 0」を予めカウント
d = 1 # 桁数
for i, s in enumerate(Sr):
  T += int(s) * d
  T %= 2019
  d = (d * 10) % 2019
  
  mod[T%2019] += 1
  
# ペアを合計
mod = [m//2 for m in mod]
print(sum(mod))

Submission status: Wrong Answer

Solution code:
S = input()
Sr = S[::-1] # 一の位から考える

T = 0 # 部分文字列
mod = [0] * 2019 # mod数え上げ配列
mod[0] += 1 # 「部分文字列T = S」の場合の、 「0 % 2019 = 0」を予めカウント
d = 1 # 桁数
for i, s in enumerate(Sr):
  T += int(s) * d
  d = (d * 10) % 2019
  
  mod[T%2019] += 1
  
# ペアを合計
mod = [m//2 for m in mod]
print(sum(mod))

Submission status: Wrong Answer

Solution code:
S = input()
Sr = S[::-1] # 一の位から考える

T = 0 # 部分文字列
mod = [0] * 2019 # mod数え上げ配列
mod[0] += 1 # 「部分文字列T = S」の場合の、 「0 % 2019 = 0」を予めカウント
d = 1 # 桁数
for i, s in enumerate(Sr):
  # 10で掛けて2019の余りをとる（桁数爆発してTLEを防ぐ）
  # 剰余の分配法則的なやつで上手くいくんだと思う
  T += int(s) * d
  d = (d * 10) % 2019 
  mod[T%2019] += 1

# ペアを合計
mod = [m//2 for m in mod]
print(sum(mod))

Submission status: Wrong Answer

Solution code:
S = input()
Sr = S[::-1] # 一の位から考える

T = 0 # 部分文字列
mod = [0] * 2019 # mod数え上げ配列
mod[0] += 1 # 「部分文字列T = S」の場合の、 「0 % 2019 = 0」を予めカウント
d = 1 # 桁数
for i, s in enumerate(Sr):
  # 10で掛けて2019の余りをとる（桁数爆発してTLEを防ぐ）
  # 剰余の分配法則的なやつで上手くいくんだと思う
  d = (d * 10) % 2019 
  T += int(s) * d
  mod[T%2019] += 1

# ペアを合計
mod = [m//2 for m in mod]
print(sum(mod))

Submission status: Wrong Answer

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

mod = [0]*2019
mod[0] = 1
ten = 10
index = int(S[0])
for i in range(1, len(S)):
    index += ten*int(S[i])
    index %= 2019
    mod[index] += 1
    ten *= 10
    ten %= 2019

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

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
S = input()[::-1]

mod = [0]*2019
mod[0] = 1
ten = 10
index = int(S[0])
for i in range(1, len(S)):
    index += ten*int(S[i])
    index %= 2019
    mod[index] += 1
    ten *= 10

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

print(ans)

Submission status: Wrong Answer

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

mod = [0]*2019
mod[0] = 1
#num = [int(S[0])]
ten = 10
index = int(S[0])
for i in range(1, len(S)):
    index += ten*int(S[i])
    mod[index%2019] += 1
    ten *= 10

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

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(map(int, list(input())))
n = len(s)

countdic = {}
mod = 2019

num = 0
for i in range(1,n+1):
    num += s[n-i]*(10**(i-1))
    if num in countdic:
        countdic[num] += 1
    if num not in countdic:
        countdic[num] = 1

ans = 0
for key in countdic:
    ans += countdic[key]*(countdic[key]-1)//2

if 0 in countdic:
    ans += countdic[0]

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
S = input()[::-1]

mod = [0]*2019
mod[0] = 1
num = [int(S[0])]
ten = 10
for i in range(1, len(S)):
    num.append(num[i-1] + ten*int(S[i]))
    mod[num[i]%2019] += 1
    ten *= 10

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


print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    S = [int(x) for x in input().strip()]
    N = len(S)
    ans = 0
    l = [0] * (N + 1)
    p = 1
    cumsum = [0] * (N + 1)
    for i in range(N-1, -1, -1):
        l[i] = (S[i] * p) % 2019
        p *= 10
        p %= 2019
    for i in range(N-1, -1, -1):
        cumsum[i] = (l[i] + cumsum[i+1]) % 2019
    cumsum = Counter(cumsum)
    for i in range(0, 2019):
        ans += ((cumsum[i] - 1) + 1) // 2 * (cumsum[i] - 1)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n

for i in range(s_len):
    t = s[i:]
    t_i = int(t)
    m = t_i % n
    #mod_list.append(m)
    mod_list[m] += 1

#c = collections.Counter(mod_list)
#result = sum(i * (i - 1) // 2 for i in c.values())
result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; 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:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
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)]

s = s()

mul_list = [str(i * 2019) for i in range(1, 100) if i * 2019 <= 2 * 10 ** 5]

#print(len(mul_list))

for mul in mul_list:
    if mul in s:
        ans += len(re.findall("{}(?={})".format(mul[0], mul[1:]), s))

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    S = [int(x) for x in input().strip()]
    N = len(S)
    ans = 0
    l = [0] * (N + 1)
    p = 1
    cumsum = [0] * (N + 1)
    for i in range(N-1, -1, -1):
        l[i] = (S[i] * p) % 2019
        p *= 10
        p %= 2019
    cumsum[-2] = l[-2]
    for i in range(N-2, -1, -1):
        cumsum[i] = (l[i] + cumsum[i+1]) % 2019
    cumsum = Counter(cumsum)
    for i in range(0, 2019):
        ans += ((cumsum[i] - 1) + 1) // 2 * (cumsum[i] - 1)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    S = [int(x) for x in input().strip()]
    N = len(S)
    ans = 0
    l = [0] * (N + 1)
    p = 1
    cumsum = [0] * (N + 1)
    for i in range(N-1, -1, -1):
        l[i] = (S[i] * p) % 2019
        p *= 10
        p %= 2019
    cumsum[-1] = l[-1]
    for i in range(N-2, -1, -1):
        cumsum[i] = (l[i] + cumsum[i+1]) % 2019
    cumsum = Counter(cumsum)
    for i in range(0, 2019):
        ans += ((cumsum[i] - 1) + 1) // 2 * (cumsum[i] - 1)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

countdic = {}
mod = 2019

for i in range(1,n+1):
    num = int(s[n-i:n])
    remainder = num
    if remainder in countdic:
        countdic[remainder] += 1
    if remainder not in countdic:
        countdic[remainder] = 1

ans = 0
for key in countdic:
    ans += countdic[key]*(countdic[key]-1)//2

if 0 in countdic:
    ans += countdic[0]

print(ans)

Submission status: Wrong Answer

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

S = input()
N = len(S)

counter = 0
surplus = [0]*2019
surplus[0] += 1

for i in range(N):
    surplus[int(S[i:]) % 2019] += 1

print(sum([i* i-1 in surplus]))

Submission status: Wrong Answer

Solution code:
s = input()
from collections import defaultdict 
t = [0 for i in range(len(s)+1)]
mods = defaultdict(int)
mods[0] += 1
cnt = 0
for i in range(len(s)-1,0,-1):
  cnt += 1
  t[i] = t[i+1] + 10**cnt*int(s[i])
  mods[t[i]%2019] += 1
cnt = 0
for key, value in mods.items():
  cnt += value*(value-1)//2

print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
  n, d, mods = 0, 1, [1]+[0]*2019
  for i in reversed(input()):
    n = (n+int(i)*d)%2019
    d = d*10
    mods[n] += 1
    print(n,d)
  print(sum([i*(i-1)//2 for i in mods]))
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()

d = [0]*2019 
d[0] = 1
for i in range(len(s)):
  r = int(s[i:]) % 2019
  d [r] += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
s=int(input())
l=int(math.log10(s))
T=[]

sum=0

for i in range(l):
  T.append(s%(10**(i+1))%2019)
  if(T[i]==0):
    sum=sum+1
for i in range(l-1):
  for j in range(i+1,l):
    if((T[i]-T[j])==0):
      sum=sum+1
      
print(sum)

Submission status: Wrong Answer

Solution code:
n = input()
nn = len(n)
count = 0
if nn<5:
    pass
elif nn ==5:
    if int(n)%2019 == 0:
        count +=1
else:##nn = 6
    for i in range(2):
        for j in range(i+4,6):
            if int(n[i:j+1])%2019 == 0:
                count +=1
            else:
                pass
print(count)

Submission status: Wrong Answer

Solution code:
n = input()
nn = len(n)
count = 0
if nn<5:
    pass
else:##nn = 5 or 6
    for i in range(nn-4):
        for j in range(i+4,nn-1):
            if int(n[i:j+1])%2019 == 0:
                count +=1
            else:
                pass
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
r = dict()

t = 0
base = 1
for c in S[::-1]:
    t = (t + base * int(c)) % 2019
    base = (base * 10) % 2019

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

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

print(ans)