Problem:


Score : 400 points

Problem Statement

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

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

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

Constraints

1 ≤ |S| ≤ 200000

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

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

1817181712114

Sample Output 1

3

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

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Wrong Answer

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

    ans = 0
    for i in range(n-4):
        tmp = int(S[i:i+5])
        if tmp % 2019 == 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()

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

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
print(N)
cnt = 0

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

Submission status: Wrong Answer

Solution code:
S = str(input())

cnt = 0
div_value = 2019

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

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    ret = 0
    for n in range(50001):
        if str(n*2019) in S:
            ret += 1
        if str(n*2019) in S[::-1]:
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S=input()
l = 0
r = 4
ans = 0
lenS=len(S)
while l <lenS-3:
    if not (l==0 and r == 4):
        l += 1
        r = l+4
    while r<=lenS:
        if int(S[l:r])%2019==0:
            ans += 1
            l = r-1
            r = l+4
        else:
            r += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# S = input()
S = '2119'

baisu = [str(2019 * m) for m in range(1, 100)]

# print(baisu)

c = 0
for b in baisu:
    s = 0
    while True:
        pos = S.find(b, s)
        if pos > -1:
            # print(pos, b)
            s = pos + 1
            c += 1
        else:
            break

    # print(b,c)

# print('answer', c)

print(c)

Submission status: Wrong Answer

Solution code:
S = input()

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

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

ans = 0
X = 2019
for i in range(10000):
    Y = str(X)
    
    
    if S.count(Y) > 0:
        for j in range(len(S) - len(Y)+1):
            s = S[j:j+len(Y)]
            if s == Y:
                ans += 1
    
    X += 2019
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

c = 0
N = input()
for n in list(range(2019, 200000))[::2019]:
    c += N.count(str(n))
print(c)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    S = input().rstrip("\r\n")
    a = ["0"]
    num = 2019
    d = 1
    while num <= 200000:
        num = 2019 * d
        if num > 200000:break
        a.append(str(num))
        d += 1
    ans = 0
    for i in range(len(S)):
        if S[i] == "0":ans += 1
    for x in a:
        for i in range(0, len(S)-len(x)+1):
            if x == S[i:i+len(x)]:ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
import math

def bin1(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=k**mid
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin1(mid+1,r,k,t,b,val,ans)
		else:
			return bin1(l,mid-1,k,t,b,val,ans)
		
def bin2(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=t*(k**mid)+b*(mid)
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin2(l,mid-1,k,t,b,val,ans)
		else:
			return bin2(mid+1,r,k,t,b,val,ans)

def SieveOfEratosthenes(n): 
      
    # Create a boolean array "prime[0..n]" and initialize 
    #  all entries it as true. A value in prime[i] will 
    # finally be false if i is Not a prime, else true. 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
          
        # If prime[p] is not changed, then it is a prime 
        if (prime[p] == True): 
              
            # Update all multiples of p 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    l=[]
    for i in range(2,n+1):
    	if(prime[i]):
    		l.append(i)
    return l
def bin(l,r,ll,val):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		if(val>=ll[mid][0] and val<=ll[mid][1]):
			return mid
		elif(val<ll[mid][0]):
			return bin(l,mid-1,ll,val)
		else:
			return bin(mid+1,r,ll,val)
def deci(n):
	s=""
	while(n!=0):
		if(n%2==0):
			n=n//2
			s="0"+s
		else:
			n=n//2
			s="1"+s
	return s
def diff(s1,s2):
	if(len(s1)<len(s2)):
		v=len(s1)
		while(v!=len(s2)):
			s1="0"+s1
			v=v+1
	else:
		v=len(s2)
		while(v!=len(s1)):
			s2="0"+s2
			v=v+1
	c=0
	for i in range(len(s1)):
		if(s1[i:i+1]!=s2[i:i+1]):
			c=c+1
	return c
from sys import stdin, stdout 
def fac(a,b):
	v=a
	while(a!=b):
		v*=a-1
		a=a-1
	return v
def bino(l,r,n):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		val1=math.log((n/mid)+1,2)
		val2=int(val1)
		if(val1==val2):
			return val1
		elif(val1<1.0):
			return bino(l,mid-1,n)
		else:
			return bino(mid+1,r,n)

def binary(l,r,ll,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		if(val%ll[mid]==0):
			ans=ll[mid]
			return binary(l,mid-1,ll,val,ans)
		else:
			return binary(l,mid-1,ll,val,ans)
def odd(n,ans,s):
	if(n%2!=0 or n in s):
		return ans
	else:
		s.add(n)
		return odd(n//2,ans+1,s)

if __name__ == '__main__':
	l=[]
	c=1
	val=2019
	while(val*c<=200000):
		l.append(val*c)
		c+=1
	s=str(input())
	count=0
	for i in range(len(l)):
		s1=str(l[i])
		v=len(s1)
		if(v>len(s)):
			break
		else:
			for j in range(len(s)-v+1):
				if(s[j:j+v]==s1):
					count+=1
	print(count)

Submission status: Wrong Answer

Solution code:
import sys, math
from pprint import pprint
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

S = rs()

import collections
h = collections.defaultdict(list)
i = 1
while True:
	n = 2019*i
	s = str(n)
	if len(s) > 6: break
	flag = True
	for c in s:
		if c == '0':
			flag = False
	if flag:
		h[len(s)].append(s)
	i += 1
#pprint(h)

cnt = 0
for l, nums in h.items():
	for i in range(len(S)-l+1):
		#print(S[i:i+l])
		if S[i:i+l] in nums:
			cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    S = input()
    CNT = 0
    for i in range(len(S)-3):
        for j in range(i+3, len(S)):
            N = int(S[i:j+1])
            if N%2019 == 0:
                CNT += 1
    print(CNT-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
U = [0 for i in range(2019)]
mod = 2019
sum_i_to_n = int(s[-4:]) % mod
U[sum_i_to_n] += 1
for i in range(len(s)-5,-1,-1):
    if sum_i_to_n % mod == 0:
        ans += 1
    sum_i_to_n += int(s[i])* pow(10,len(s)-i-1,mod)
    sum_i_to_n %= mod
    ans += U[sum_i_to_n]
    U[sum_i_to_n] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

s = LS()
ans = 0
for i in range(len(s)-3):
    for j in range(i+1, len(s)+1):
        if int(''.join(s[i:j]))%2019==0:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
mod_list = [str(i * 2019) for i in range(1, 100)]

count = 0
for s in mod_list:
    ps = 0
    while True:
        temp = S[ps:].find(s)

        if temp == -1:
            break
        else:
            ps += temp + len(s) - 1
            count += 1


print(count)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":

    s = input().strip()
    dp = [0] * (len(s) + 1)
    mod = 2019
    for i in range(4, len(s)+1):
        if int(s[i-4:i]) % mod == 0:
            dp[i] += 1 + dp[i-4]
        if i >= 5 and int(s[i-5:i]) % mod == 0:
            dp[i] += 1 + dp[i-5]
        if i >= 6 and int(s[i-6:i]) % mod == 0:
            dp[i] += 1 + dp[i-6]
        if i >= 7 and int(s[i-7:i]) % mod == 0:
            dp[i] += 1 + dp[i-7]
    print(sum(dp))

Submission status: Wrong Answer

Solution code:
k=[str(2019*(i+1))for i in range(99)]
s=input()
n=len(s)
p=0
for i in k:
    if len(i)>len(s):
        break
    for j in range(n-len(i)+1):
        if i==s[j:j+len(i)]:
            p+=1
print(p)

Submission status: Wrong Answer

Solution code:
s = input()

match = 0
for i in range(len(s)):
    for j in range(i + 4, len(s) - 3):
        val = int(s[i:j])
        if val >= 2019 and val % 2019 == 0:
            match += 1

print(match)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    ans = set()
    for i in range(2019, 200000, 2019):
        ind = -1
        stri = str(i)
        while True:
            ind = S.find(stri, ind + 1)
            if ind >= 0:
                ans.add((ind, ind + len(stri) - 1))
            else:
                break
    print(len(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
for i in range(len(s)-1):
    for j in range(i+1,len(s)):
        #print(i,j)
        num = int(s[i:j+1])

        if num % 2019 == 0:
            print(i,j, num)
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0

for i in range(0,len(s)-3):
    for j in range(i+4,len(s)+1):
        a = s[i:j]
        if a[0]=='1':
            continue
        elif int(a)%2019==0:
            cnt += 1

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
count = 0
for i in range(891):
    tmp = i*2019
    idx = s.find(str(tmp))
    while idx != -1:
        count += 1
        idx = s.find(str(tmp), idx+1)
  
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    ret = 0
    for n in range(200001):
        if str(n*2019) in S:
            ret += 1
        if str(n*2019) in S[::-1]:
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

import itertools

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

    s_l = len(s)

    s_nums = list(range(len(s)+1))

    ans = 0

    for i_1, i_2 in itertools.combinations(s_nums,2):
        if int(s[i_1:i_2]) % 2019 == 0:
            ans += 1
            print(i_1,i_2)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def input():
    return sys.stdin.readline().strip()
def main():
    S = input()
    cnt = 0
    for i in range(len(S)):
        for j in range(i+4,len(S)+1):
            print(S[i:j])
            if int(S[i:j]) % 2019 == 0:
                cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
#print(200001//2019) 100
li = []
for i in range(100):
    tmp = 2019*i
    str_tmp = str(tmp)
    #print(str_tmp)
    if '0' not in list(str_tmp):
        li.append(tmp)
#print(li)

count = 0
for l in li:
    lee = len(list(str(l)))
    for i in range(len(s)-lee+1):
        if s[i:i+lee] == str(l):
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0
for a in range(200000):
  if a % 2019 == 0:
    n = str(a)
    pos = 0
    while True:
      if n in s[pos:]:
        count += 1
        pos = pos + s[pos:].index(n) + 1
      else:
        break
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

ans = 0
num = 2019

for i in range(1000):
    s_num = str(num)
    begin = S.find(s_num)
    while begin >= 0:
        ans += 1
        begin = S.find(s_num, begin + 1)
    num += 2019

print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())

ans = 0
mm = 2019
for i in range(1,101):
    a = 2019*i
    A = len(list(str(a)))
    for j in range(len(S)-A+1):
        if S[j:j+A]==list(str(a)):
            ans += 1
            # print(S[j:j+A])
print(ans)

Submission status: Wrong Answer

Solution code:
#author: raghav_0901
from math import *

mod = 998244353


def CountOccurrences(string, substring):

    # Initialize count and start to 0
    count = 0
    start = 0

    # Search through the string till
    # we reach the end of it
    while start < len(string):

        pos = string.find(substring, start)

        if pos != -1:
            start = pos + 1

            # Increment the count
            count += 1
        else:
            # If no further substring is present
            break
    # return the value of count
    return count


def _in():
    return [int(x) for x in input().split(' ')]


if __name__ == "__main__":
    s = input()
    ans = 0
    for i in range(1, 101):
        ans += CountOccurrences(s, str(2019 * i))
    print(ans)

Submission status: Wrong Answer

Solution code:
def judge(long):
    global n, count
    for j in range(len(n)-long+1):

        if int(n[j:j+long+1]) % 2019 == 0:
            count += 1


n = input()
count = 0
for i in range(4, len(n)+1):
    judge(i)
if count > 0:
    print(count-1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
S=input()
count=0
for i in range(len(S)):
    for j in range(i+3, len(S)):
        total=0
        if int(S[j])%2==1:
            continue
        for k in range(i,j+1):
            total += int(S[k])*10**(j-k)
        if total%2019==0:
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0
for i in range(89):
    tmp = i*2019
    idx = s.find(str(tmp))
    while idx != -1:
        count += 1
        idx = s.find(str(tmp), idx+1)
  
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
box = [2019]
n = 2
while True:
    if n*2019 > 200000:
        break
    else:
        box.append(n*2019)
    n += 1

ans = 0
for mod in box:
    s = S
    if len(str(mod)) > len(s):
        break
    mae = 0
    ato = len(str(mod))
    while True:
        if ato > len(S):
            break
        if s[mae:ato] == str(mod):
            ans += 1
            mae += 1
            ato += 1
        else:
            mae += 1
            ato += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
A = []
for i in range(100):
    A.append(str(2019*i))

ans = 0
for a in A:
    for i in range(n):
        if i+len(a) <= n:
            if a == s[i:i+len(a)]:
                ans += 1
print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    multi = 2019
    multis = []
    i = 1
    cnt = 0
    while multi*i <= 200000:
        multis.append(str(multi*i))
        i += 1
    for m in multis:
        if len(m) <= len(S): 
            for i in range(0, len(S) - len(m) + 1):
                if S[i:i+len(m)] == m:
                    cnt += 1
    print(cnt)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
l = [ str( 2019 * i )  for i in range(200000) ]

cnt = 0
for i in l:
    cnt += S.count(i)
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()

ans = 0
st = ""
for i in s:
    st += i
    n = int(st)
    if n < 2019: continue
    if n % 2019 == 0:
        st = st[-1]
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    ans = 0
    for i in range(2019, 200000, 2019):
        ind = -1
        stri = str(i)
        while True:
            ind = S.find(stri, ind + 1)
            if ind >= 0:
                ans += 1
            else:
                break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()

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

print(ans)

Submission status: Wrong Answer

Solution code:
a = [str(i) for i in range(2019, 200000, 1) if i % 2019 == 0]
s = input()
ans = 0
for i in a:
    s_1 = s
    while (i in s_1):
        s_1 = s_1[s_1.find(i) + 1:]
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
n = len(s)
ans = 0

for i in range (n):
    tmp = s[i:i+5];
    test = int(tmp)
    if(test%2019==0):
      ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

def main():
    S = input()
    N = len(S)
    tmp = 2019
    l = []
    while True:
        l.append(str(tmp))
        tmp += 2019
        if tmp > 2*(10**5):
            break

    cnt = 0
    for num in l:
        na = len(num)
        for i in range(N-na+1):
            if num == S[i:i+na]:
                cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
c = []
i = 1
while 2019 * i < 2 * 10**5:
    c.append(2019 * i)
    i += 1

ans = 0
for i in range(3):
    for j in range(N - 3 - i):
        if int(S[j:j + 4 + i]) in c:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
s = list(SI())
le = len(s)
l = []
count = 0
for i in range(100):
	l.append(list(str((i+1)*2019)))
for i in l:
	aa = len(i)
	for j in range(le-aa+1):
		if s[j:j+aa] == i:
			count+=1
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
N = len(S)
if N >= 4:
    for i in range(N-3):
        s = S[i:i+4]
        if int(s) % 2019 == 0:
            ans += 1
if N >= 5:
    for i in range(N-4):
        s = S[i:i+5]
        if int(s) % 2019 == 0:
            ans += 1
if N >= 6:
    for i in range(N-5):
        s = S[i:i+6]
        if int(s) % 2019 == 0:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    S = input()
    cnt = 0
    start = 0
    while start+4 < len(S):
        for i in range(start+4,len(S)+1):
            if S[i-1] == 0:
                continue
            if int(S[start:i]) % 2019 == 0:
                cnt += 1
                start += 3
        start += 1
    print(cnt)
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

s = input()
l = len(s)
cnt = 0

for i in range(3,l):
    for j in range(i):
        num = int(s[j:i+1])
        if num % 2019 == 0:
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s = str(input())
r = []
ans = 0
for i in range(len(s)):
    r.append(s[i])
if len(r) < 4:
    print("No")
    exit()
else:
    for i in range(len(r)-3):
        for j in range(i+3,len(r)+1):
            if int("".join(r[i:j]))%2019 == 0:
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

S = input()
n = len(S)

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l_sum = [0]
for i in range(n):
    x = (l_sum[-1] + int(s[n-i-1]) * (10 ** i)) % 2019
    l_sum.append(x)

#print(l_sum)
l_sum.sort()
ans = 0
tmp = 0
cnt = 1
for i in range(1, len(l_sum)):
    if l_sum[i] == tmp:
        cnt += 1
    else:
        ans += cnt * (cnt - 1) // 2
        cnt = 1
        tmp = l_sum[i]

ans += cnt * (cnt - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
cnt = 0

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

    mset = set()
    for i in range(200000 // 2019):
        mset.add(str(2019 * (i + 1)))
    c = 0
    for m in mset:
        p = -1
        while True:
            p = s.find(m, p + 1)
            if p < 0:
                break
            c += 1
    print(c)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
s=input()
n=len(s)
a=[]
x=0
p=1
for i in range(n):
	j = n-1-i
	c = int(s[j])
	p %= 2019
	x += (p*c)%2019
	p *= 10
	x %= 2019
	a.append(x)
c=collections.Counter(a)
ans = 0
for k,v in c.items():
	if k==0:
		ans += v
	else:
		ans += v*(v-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = input()
n = len(S)
mod = 2019
s = [0]*(n+1)
X = [1]*n
for i in range(n-1):
    X[i+1] = X[i]*10%mod
for i in range(n):
    s[i+1] = (s[i]+int(S[n-i-1])*X[i])%mod
c = Counter(s)
ans = 0
for x in c.values():
    ans += x-1
print(ans)

Submission status: Wrong Answer

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

    ans = 0
    for i in range(n-3):
        tmp = int(S[i:i+4])
        if tmp % 2019 == 0:
            ans += 1
    for i in range(n-4):
        tmp = int(S[i:i+5])
        if tmp % 2019 == 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
s = list(SI())
l = []
count = 0
for i in range(100):
	l.append(list(str((i+1)*2019)))
for i in l:
	for j in range(len(s)-len(i)+1):
		if s[j:j+len(i)] == i:
			count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
N = len(S)
tmp = 2019
l = []
while True:
    l.append(str(tmp))
    tmp += 2019
    if tmp > 10**5:
        break
cnt = 0
for num in l:
    na = len(num)
    for i in range(N-na+1):
        if num == S[i:i+na]:
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:

S = input()
N = len(S)
primes = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 100]
cnt = 0
for p in range(1, 101):
    target = 2019 * p
    length = len(str(target))
    for i in range(N-length+1):
        s = int(S[i:i+length])
        if target == s:
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s = str(input())
r = []
ans = 0
for i in range(len(s)):
    r.append(s[i])
if len(r) < 4:
    print("No")
    exit()
else:
    for i in range(len(r)-3):
        for j in range(i+1,len(r)+1):
            if int("".join(r[i:j]))%2019 == 0:
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
n = len(s)
mod = [0]*(n+1)
pow10 = 1
for i in range(n):
    mod[i+1] = (mod[i] + int(s[-1-i])*pow10)%2019
    pow10 *= 10
mod = sorted(mod) + [2020]
cnt = 0
ans = 0
for i in range(n):
    if mod[i] == mod[i+1]:
        cnt += 1
    else:
        ans += cnt*(cnt+1)//2
        cnt = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s=input()
n=len(s)
a=[]
x=0
p=1
for i in range(n):
	j = n-1-i
	c = int(s[j])
	p *= 10
	p %= 2019
	x += (p*c)%2019
	x %= 2019
	a.append(x)
c=collections.Counter(a)
ans = 0
for k,v in c.items():
	if k==0:
		ans += v
	else:
		ans += v*(v-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
l = len(S)
T = [0]
for i in range(1, l+1):
    T.append((T[-1]+int(S[-i])*10**(i-1)) % 2019)
print(T)
C = {}
for t in T:
    try:
        C[t] += 1
    except:
        C[t] = 1
ans = 0
for c in C.values():
    ans += c*(c-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

S = rs()

import collections
h = collections.defaultdict(list)
i = 1
while True:
	n = 2019*i
	if n > 200000: break
	s = str(n)
	h[len(s)].append(s)
	i += 1

cnt = 0
for l, nums in h.items():
	for i in range(len(S)-l+1):
		#print(S[i:i+l])
		if S[i:i+l] in nums:
			cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
A = []
for i in range(100):
    A.append(str(2019*i))

ans = 0
for a in A:
    for i in range(len(s)):
        if a == s[i:i+len(a)]:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = list(input())
count = 0
for i in range(len(s)):
    for j in range(i+4, len(s)+1):
        x = int(''.join(s[i:j]))
        if x%2019 == 0:
            count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
n = len(s)
a = []
b = 2019
for i in range(100):
    b+=2019
    c = str(b)
    if '0' not in c:
        a.append(c)

ans = 0
for i in range(n):
    k = [4,5,6]
    for j in k:
        if i+j <= n:
            ss = s[i:i+j]
            if ss in a:
                ans += 1

print(ans)