CodeEff/ECCO huggingface dataset:
# Original solution
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, P = lr()
    S = list(map(int, list(sr())))
    if P == 2 or P == 5:
        ans = 0
        for i in range(N):
            if S[i]%P == 0:
                ans += i+1
        print(ans)
        return
    S = S[::-1]
    lp = [0]*P
    c = 0
    for i in range(N):
        d = S[i]*10**i
        c = (c+d)%P
        lp[c] += 1
    ans = lp[0]
    for i in range(P):
        ans += lp[i]*(lp[i]-1)//2
    print(ans)
resolve()

# Optimized solution
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, P = lr()
    S = list(map(int, list(sr())))
    if P == 2 or P == 5:
        ans = 0
        for i in range(N):
            if S[i]%P == 0:
                ans += i+1
        print(ans)
        return
    S = S[::-1]
    lp = [0]*P
    c = 0
    for i in range(N):
        d = S[i]*pow(10,i,P)
        c = (c+d)%P
        lp[c] += 1
    ans = lp[0]
    for i in range(P):
        ans += lp[i]*(lp[i]-1)//2
    print(ans)
resolve()
# Original solution
def main():
    n, p = list(map(int, input().split()))
    S = input().strip()
    
    if p == 2 or p == 5:
        count = 0
        digits = '02468' if p == 2 else '05'
        for i, x in enumerate(S, 1):
            if x in digits:
                count += i
        print(count)
    else:
        counter = [0]*p
        for i in range(n-1, -1, -1):
            counter[int(S[i:]) % p] += 1
        print((counter[0] + sum(i*(i-1)//2 for i in counter)))

main()

# Optimized solution
n, p = list(map(int, input().split()))
if p in (2, 5):
  c = 0
  for i, x in enumerate(map(int, input()[::-1])):
    if x % p == 0:
      c += n-i
  print(c)
else:
  c = [0] * p
  y = 0
  t = 1
  for x in map(int, input()[::-1]):
    y = (y + t*x) % p
    c[y] += 1
    t = (10 * t) % p
  print((sum(i * (i-1) // 2 for i in c) + c[0]))
# Original solution
N,P = list(map(int,input().split()))
S = str(eval(input()))

if P == 2 or P == 5:
    S = list(map(int,list(S)))
    ans = 0
    for i in range(N):
        if S[i] % P == 0:
            ans += i + 1

else:
    data = [0] * P
    s = int(S)
    for i in range(N):
        data[s%P] += 1
        s -= int(S[i]) * (10**(N-i-1))
    #print(data)
    ans = data[0]
    for i in range(P):
        ans += (data[i]*(data[i]-1))//2

print(ans)

# Optimized solution
N,P = list(map(int,input().split()))
S = str(eval(input()))

if P == 2 or P == 5:
    S = list(map(int,list(S)))
    ans = 0
    for i in range(N):
        if S[i] % P == 0:
            ans += i + 1

else:
    data = [0] * P
    s = int(S)
    x = 1 ##10**iをPで割った数
    y = 0 ##S[i:N]をPで割った数
    for i in range(N):
        y += int(S[N-i-1]) * x
        y %= P
        data[y] += 1
        x *= 10
        x %= P
    #print(data)
    ans = data[0]
    for i in range(P):
        ans += (data[i]*(data[i]-1))//2

print(ans)
# Original solution
import sys 
import collections
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,P = list(map(int,readline().split()))
S = list(map(int,readline().rstrip().decode()))

def solve_2(S):
    cnt = sum(i for i,x in enumerate(S,1) if x % 2 == 0)
    return cnt
def solve_5(S):
    cnt = sum(i for i,x in enumerate(S,1) if x % 5 == 0)
    return cnt
def solve(S):
    if P == 2:
        return solve_2(S)
    if P == 5:
        return solve_5(S)
    mod_cnt = [0]*(len(S))
    S = S[::-1]
    for i in range(len(S)):
        mod_cnt[i] = (mod_cnt[i-1] + S[i] * 10**i) % P
    c = collections.Counter(mod_cnt)
    ans = 0
    ans += mod_cnt.count(0)
    ans += sum( n*(n-1)//2 for n in list(c.values()))
    return ans

print((solve(S)))

# Optimized solution
import sys 
import collections
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,P = list(map(int,readline().split()))
S = list(map(int,readline().rstrip().decode()))

def solve_2(S):
    cnt = sum(i for i,x in enumerate(S,1) if x % 2 == 0)
    return cnt
def solve_5(S):
    cnt = sum(i for i,x in enumerate(S,1) if x % 5 == 0)
    return cnt
def solve(S):
    if P == 2:
        return solve_2(S)
    if P == 5:
        return solve_5(S)
    mod_cnt = [0]*(len(S))
    power = 1
    S = S[::-1]
    for i in range(len(S)):
        power *= 10
        power %= P
        mod_cnt[i] = (mod_cnt[i-1] + S[i] * power) % P
    c = collections.Counter(mod_cnt)
    cnt = sum( n*(n-1)//2 for n in list(c.values())) + c[0]
    return cnt

print((solve(S)))
# Original solution
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N, P = list(map(int, readline().split()))
    S = [int(i) for i in readline().strip()[::-1]]

    ans = 0
    if P == 2 or P == 5:
        for i, s in enumerate(S):
            if s % P == 0:
                ans += N - i
        
        print(ans)
        exit()

    a = [0]
    s = 0
    for i in range(N):
        s += S[i] * pow(10, i, P)
        a.append(s % P)
    
    t = Counter(a)

    ans = 0
    for v in list(t.values()):
        ans += v * (v-1) // 2
    
    print(ans)

    


if __name__ == "__main__":
    main()


# Optimized solution
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N, P = list(map(int, readline().split()))
    S = [int(i) for i in readline().strip()[::-1]]

    ans = 0
    if P == 2 or P == 5:
        for i, s in enumerate(S):
            if s % P == 0:
                ans += N - i
        print(ans)
        exit()

    a = {}
    a[0] = 1
    t = 0
    x = 1
    for s in S:
        t += s * x
        t %= P
        
        if t in a:
            a[t] += 1
        else:
            a[t] = 1

        x *= 10
        x %= P
    
    ans = 0
    for v in list(a.values()):
        ans += v * (v-1) // 2
    
    print(ans)
    

if __name__ == "__main__":
    main()
# Original solution
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list([x-1 for x in MII()])
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    n, p = MII()
    s = list(map(int, IS()))
    if 10%p == 0: # pが2または5の場合
        cnt = 0
        for i, si in enumerate(s):
            if si%p == 0:
                cnt += i+1
        print(cnt)
        return None

    d = {i: 0 for i in range(p)}
    d[0] = 1
    ss = 0
    x = 1
    for si in s[::-1]:
        ss += x*si
        ss %= p
        d[ss] += 1
        x = 10*x
    cnt = 0
    for dv in list(d.values()):
        cnt += dv*(dv-1)//2
    print(cnt)


if __name__ == "__main__":
    main()

# Optimized solution
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list([x-1 for x in MII()])
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    n, p = MII()
    s = list(map(int, IS()))
    if 10%p == 0: # pが2または5の場合
        cnt = 0
        for i, si in enumerate(s):
            if si%p == 0:
                cnt += i+1
        print(cnt)
        return None

    d = {i: 0 for i in range(p)}
    d[0] = 1
    ss = 0
    x = 1
    for si in s[::-1]:
        ss += x*si
        ss %= p
        d[ss] += 1
        x = 10*x%p
    cnt = 0
    for dv in list(d.values()):
        cnt += dv*(dv-1)//2
    print(cnt)


if __name__ == "__main__":
    main()
# Original solution
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,p = inpl()
s = input()[::-1]
res = 0
if p == 2 or p == 5:
    s = s[::-1]
    for i,t in enumerate(s):
        if int(t)%p == 0: 
            res += i+1
    print(res)
    quit()
now = 0
d = [0] * p
d[0] = 1
for i,t in enumerate(s):
    now += int(t) * pow(10,i)
    now %= p
    d[now] += 1
for i in range(p):
    v = d[i]
    res += v*(v-1)//2
print(res)

# Optimized solution
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,p = inpl()
s = input()[::-1]
res = 0
if p == 2 or p == 5:
    s = s[::-1]
    for i,t in enumerate(s):
        if int(t)%p == 0: 
            res += i+1
    print(res)
    quit()
now = 0
d = [0] * p
d[0] = 1
for i,t in enumerate(s):
    now += int(t) * pow(10,i,p)
    now %= p
    d[now] += 1
for i in range(p):
    v = d[i]
    res += v*(v-1)//2
print(res)
# Original solution
from collections import Counter

n, p = list(map(int, input().split()))
s = input().rstrip()

total = 0
if p in [2, 5]:
    for i in range(n-1, -1, -1):
        if int(s[i]) % p == 0:
            total += i + 1
else:
    dp = [0] * (n + 1)
    fac = 1
    for i in range(n-1, -1, -1):
        dp[i] = (dp[i + 1] + int(s[i]) * fac) % p
        fac *= 10 % p

    c = Counter(dp)

    for k, v in list(c.items()):
        if v >= 2:
            total += v * (v - 1) // 2

print(total)


# Optimized solution
from collections import Counter

n, p = list(map(int, input().split()))
s = input().rstrip()

total = 0
if p in [2, 5]:
    for i in range(n-1, -1, -1):
        if int(s[i]) % p == 0:
            total += i + 1
else:
    dp = [0] * (n + 1)
    fac = 1
    for i in range(n-1, -1, -1):
        dp[i] = (dp[i + 1] + int(s[i]) * fac) % p
        fac = (fac * 10) % p

    c = Counter(dp)

    for k, v in list(c.items()):
        if v >= 2:
            total += v * (v - 1) // 2

print(total)
# Original solution
from sys import stdin 
from collections import defaultdict, Counter


N, P = list(map(int, stdin.readline().split()))
S, = stdin.readline().split()

ans = 0 


# 2 cases
if P == 2 or P == 5:
	digitdiv = []
	for i in range(N):
		if int(S[i]) % P == 0:
			ans += i + 1

else:
	#
	count = Counter()
	prefix = []
	ten = 1
	mod = 0
	for i in range(N):
		x = (int(S[N - i - 1])*ten + mod) % P 
		prefix.append(x)
		count[x] += 1
		ten = (ten * 10) % P 
		mod = x
	prefix.append(0)
	count[0] += 1
	for val in list(count.values()):
		ans += val*(val - 1)//2


print (ans)





# Optimized solution
from sys import stdin 
from collections import Counter

N, P = list(map(int, stdin.readline().split()))
S = stdin.readline().strip()

ans = 0
if P in (2, 5):
	for i in range(N):
		if int(S[i]) % P == 0:
			ans += i + 1


else:

	count = Counter()
	ten = 1
	mod = 0
	for i in range(N):
		x = (int(S[N - i - 1])*ten + mod) % P
		ten = ten*10 % P 
		mod = x
		count[x] += 1

	count[0] += 1


	for i in list(count.values()):
		ans += i*(i - 1)//2

print (ans)
# Original solution
import sys
input = sys.stdin.readline
from collections import Counter

N, mod = list(map(int, input().split()))
S = list(input().rstrip())

if mod == 2 or mod == 5:
    ans = 0
    for i, s in enumerate(S):
        if int(s)%mod==0:
            ans += i+1
else:
    dp = [0]
    t = 1
    for s in reversed(S):
        dp.append((dp[-1]+int(s)*t)%mod)
        t = t*10%mod

    ans = 0
    C = Counter(dp)
    for v in list(C.values()):
        ans += v*(v-1)//2

print(ans)

# Optimized solution
import sys
input = sys.stdin.readline

N, P = list(map(int, input().split()))
S = list(input().rstrip())

if P in {2, 5}:
    ans = 0
    for i, s in enumerate(S):
        if int(s) % P == 0:
            ans += i+1
else:
    ans = 0
    T = [0]*P
    T[0] = 1
    tmp = 0
    k = 1
    for s in reversed(S):
        tmp = (tmp + k * int(s)) % P
        k = k * 10 % P
        ans += T[tmp]
        T[tmp] += 1

print(ans)
# Original solution
def main():
	N,P = list(map(int,input().split()))
	S = [int(s) for s in list(input().strip())][::-1]
	num = 0
	ans = 0
	if P == 2 or P == 5:
		for i in range(N):
			if S[i]%P == 0:
				ans += N-i
		print(ans)
		return
	L = [0]*P
	L[0]=1
	t = 0
	s = 1
	for z in S:
		t = (z*s+t)%P	
		L[t]+=1
		s*=10%P
	for l in L:
		ans += l * (l - 1) // 2
	print(ans)

if __name__ == '__main__':
	main()


# Optimized solution
def main():
	N,P = list(map(int,input().split()))
	S = [int(s) for s in list(input().strip())][::-1]
	num = 0
	ans = 0
	if P == 2 or P == 5:
		for i in range(N):
			if S[i]%P == 0:
				ans += N-i
		print(ans)
		return
	L = [0]*P
	L[0]=1
	t = 0
	s = 1
	for z in S:
		t = (z*s+t)%P	
		L[t]+=1
		s=s*10%P
	for l in L:
		ans += l * (l - 1) // 2
	print(ans)

if __name__ == '__main__':
	main()
# Original solution
import sys

n,p=list(map(int,input().split()))
s=[int(x) for x in sys.stdin.readline().strip()]
reslst=[0]*p

cnt=0

if p==2:
    for i in range(n):
        if s[i]%2==0:
            cnt+=i+1
elif p==5:
    for i in range(n):
        if s[i]==5 or s[i]==0:
            cnt+=i+1
else:
    x=0
    for i in range(n-1,-1,-1):
        x=s[i]*(10**(n-1-i))+x
        reslst[x%p]+=1
    reslst[0]+=1

    for i in range(p):
        j=reslst[i]

        cnt+=j*(j-1)//2

print(cnt)

# Optimized solution
import sys

n,p=list(map(int,input().split()))
s=sys.stdin.readline().strip()
reslst=[0]*p

cnt=0

if p==2:
    for i in range(n):
        if int(s[i])%2==0:
            cnt+=i+1
elif p==5:
    for i in range(n):
        if s[i]=='5' or s[i]=='0':
            cnt+=i+1
else:
    reslst[0]+=1
    tmp=1
    now=0
    for i in [int(x) for x in s[::-1]]:
        now+=i*tmp
        now%=p
        reslst[now]+=1
        tmp=(tmp*10)%p
    
    for i in range(p):
        cnt+=reslst[i]*(reslst[i]-1)//2

print(cnt)
# Original solution
#!/usr/bin/env python3
import sys
from collections import defaultdict

def solve(N: int, P: int, S: str):
    if 10%P == 0:
        sum = 0
        for i in range(1,N+1):
            if int(S[-i]) % P == 0:
                sum += (N-i)+1
        print(sum)
        return
    else:
        current = 0
        C = 1
        counts = defaultdict(int)
        for i in range(1,N+1):
            if i == 1:
                current = int(S[-1])%P
            else:
                current = (int(S[-i])*C + current)%P
            counts[current]+=1
            C*=10
        sum = 0
        for k in counts:
            c = counts[k]
            sum += int((c*(c-1)/2))
        sum += counts[0]
        print(sum)

    # sum = 0
    # for i in range(N):
    #     sDiv = 0
    #     coeff = 1
    #     for j in range(i,N):
    #         sDiv= (sDiv*coeff + arr[j])%P
    #         coeff*=10
    #         if sDiv == 0:
    #             sum+=1
    # print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    S = next(tokens)  # type: int
    solve(N, P, S)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys
from collections import defaultdict

def solve(N: int, P: int, S: str):
    if 10%P == 0:
        sum = 0
        for i in range(1,N+1):
            if int(S[-i]) % P == 0:
                sum += (N-i)+1
        print(sum)
        return
    else:
        current = 0
        C = 1
        counts = defaultdict(int)
        for i in range(1,N+1):
            if i == 1:
                current = int(S[-1])%P
            else:
                current = (int(S[-i])*C + current)%P
            counts[current]+=1
            C=C*10%P
        sum = 0
        for k in counts:
            c = counts[k]
            sum += int((c*(c-1)/2))
        sum += counts[0]
        print(sum)

    # sum = 0
    # for i in range(N):
    #     sDiv = 0
    #     coeff = 1
    #     for j in range(i,N):
    #         sDiv= (sDiv*coeff + arr[j])%P
    #         coeff*=10
    #         if sDiv == 0:
    #             sum+=1
    # print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    S = next(tokens)  # type: int
    solve(N, P, S)

if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python3
import sys


def solve(N: int, P: int, S: str):

    if P == 2 or P == 5:
        tot = 0
        for i, c in enumerate(S):
            c = int(c)
            if c % P == 0:
                tot += i+1
        print(tot)
        return

    U = [0]*(N+1)
    a = 0
    for i in range(N-1, -1, -1):
        a += (10**(N-1-i))*int(S[i])
        a %= P
        U[i] = a
    table = [0]*P
    tot = 0
    for i in range(N-1, -1, -1):
        tot += table[U[i]]
        table[U[i]] += 1
    tot += table[0]
    print(tot)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    S = str(next(tokens))  # type: int
    solve(N, P, S)


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(N: int, P: int, S: str):

    if P == 2 or P == 5:
        tot = 0
        for i, c in enumerate(S):
            c = int(c)
            if c % P == 0:
                tot += i+1
        print(tot)
        return

    U = [0]*(N+1)
    a = 0
    beki = 1
    for i in range(N-1, -1, -1):
        a += beki*int(S[i])
        a %= P
        U[i] = a
        beki = (beki * 10) % P
    table = [0]*P
    tot = 0
    for i in range(N-1, -1, -1):
        tot += table[U[i]]
        table[U[i]] += 1
    tot += table[0]
    print(tot)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    S = str(next(tokens))  # type: int
    solve(N, P, S)


if __name__ == '__main__':
    main()
# Original solution
r=list(range(128))
def f():v=min(i for i in r if D[i]);D[v]-=1;D[127-v]+=1;D[127]+=1
for i in[0]*eval(input()):n,d=list(map(int,input().split()));D=[0]*128;D[d]=1;exec("f();"*~-n);print(sum(i*D[i]for i in r))

# Optimized solution
for i in[0]*eval(input()):n,d=list(map(int,input().split()));print(~-n*127+(127*(n+1&1)^d))
# Original solution
from heapq import heappush, heappop
T = int(eval(input()))
A = []
for i in range(T):
    N, D = list(map(int, input().split()))
    ans = D
    h = []
    heappush(h,D)
    for _ in range(N - 1):
        k = heappop(h)
        z = bin(k)[2:].zfill(7)
        u = ['0' if x == '1' else '1' for x in z]
        t = int(''.join(u),2)
        heappush(h,t)
        ans += (127 + t - k)
    A.append(ans)
for i in range(len(A)):
    print((A[i]))


# Optimized solution
from heapq import heappush, heappop
T = int(eval(input()))
A = []
for i in range(T):
    N, D = list(map(int, input().split()))
    ans = D
    h = []
    heappush(h,D)
    for _ in range(N - 1):
        k = heappop(h)
        t = 127 ^ k
        heappush(h,t)
        ans += (127 + t - k)
    A.append(ans)
for i in range(len(A)):
    print((A[i]))
# Original solution
from itertools import combinations
from collections import Counter

N = int(eval(input()))
X = [list(map(int, input().split())) for _ in range(N)]

if N == 1:
    print((1))
    quit()

X.sort()
diff = []
for i, j in combinations(list(range(N)), 2):
    diff.append((X[i][0] - X[j][0], X[i][1] - X[j][1]))
print((N - Counter(diff).most_common()[0][1]))




# Optimized solution

from collections import defaultdict

N = int(eval(input()))
X = [list(map(int, input().split())) for _ in range(N)]

X.sort()
ctr = defaultdict(int)
for i in range(N - 1):
    for j in range(i + 1, N):
        p = X[i][0] - X[j][0]
        q = X[i][1] - X[j][1]
        ctr[(p, q)] += 1
        ctr[(-p, -q)] += 1

if N == 1:
    print((1))
else:
    print((N - max(ctr.values())))
# Original solution
# div2019-2B - Picking Up
from collections import defaultdict

n = int(eval(input()))
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = defaultdict(int)
for i in range(n):
    for j in range(i + 1, n):
        dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
        cnt[dif] += 1
print((n - max(list(cnt.values()), default=0)))

# Optimized solution
n = int(eval(input()))
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = {}
for i, j in arr:
    for k, l in arr:
        if (i, j) == (k, l):
            continue
        dif = (k - i, l - j)
        cnt.setdefault(dif, 0)
        cnt[dif] += 1
print((n - max(list(cnt.values()), default=0)))
# Original solution
n = int(eval(input()))
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = {}
for i, j in arr:
    for k, l in arr:
        if (i, j) == (k, l):
            continue
        dif = (k - i, l - j)
        cnt.setdefault(dif, 0)
        cnt[dif] += 1
print((n - max(list(cnt.values()), default=0)))

# Optimized solution
# diverta2019-2B - Picking Up
def main():
    n = int(eval(input()))
    arr = sorted(tuple(map(int, input().split())) for _ in range(n))
    cnt = {}
    for i in range(n):
        for j in range(i + 1, n):
            dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
            cnt.setdefault(dif, 0)
            cnt[dif] += 1
    print((n - max(list(cnt.values()), default=0)))


if __name__ == "__main__":
    main()
# Original solution
# diverta2019-2B - Picking Up
def main():
    n = int(eval(input()))
    arr = sorted(tuple(map(int, input().split())) for _ in range(n))
    cnt = {}
    for i in range(n):
        for j in range(i + 1, n):
            dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
            cnt.setdefault(dif, 0)
            cnt[dif] += 1
    print((n - max(list(cnt.values()), default=0)))


if __name__ == "__main__":
    main()

# Optimized solution
# diverta2019-2B - Picking Up
import sys
input = sys.stdin.readline

def main():
    n = int(eval(input()))
    arr = sorted(tuple(map(int, input().split())) for _ in range(n))
    cnt = {}
    for i in range(n):
        for j in range(i + 1, n):
            dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
            cnt.setdefault(dif, 0)
            cnt[dif] += 1
    print((n - max(list(cnt.values()), default=0)))


if __name__ == "__main__":
    main()
# Original solution
#!/usr/bin/env python3
from collections import defaultdict

(n, ), *p = [[*list(map(int, i.split()))] for i in open(0)]
d = defaultdict(int)
for i in range(n):
    for j in range(n):
            d[(p[i][0] - p[j][0], p[i][1] - p[j][1])] += i!=j
print((n - max(d.values())))


# Optimized solution
from collections import *
(n,),*p=[[*list(map(int,i.split()))] for i in open(0)]
d=defaultdict(int)
for x, y in p:
    for a, b in p:
        d[(x-a, y-b)]+=(x,y)!=(a,b)
print((n-max(d.values())))