PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000335. Xóa ít phần tử nhất để mảng đẹp (Strange Beauty)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xóa ít phần tử nhất để mảng đẹp (Strange Beauty)

Strange Beauty

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

An array of NN positive integers is called beautiful if, for every pair of different positions i≠ji\ne j, their values are comparable by divisibility: either Ai∣AjA_i\mid A_j or Aj∣AiA_j\mid A_i.

You may delete any elements without changing the remaining values. Find the minimum number of deletions that makes the array beautiful. Equal values are always compatible, since any integer divides itself.

Each Phuoc Hung OJ input file contains one test case, not an initial test-count tt.

Input

The first line contains NN; the second contains NN positive integers AiA_i.

Output

Print the minimum number of elements to delete.

Subtasks

  • Subtask 1 (20 points): 1≤N≤161\le N\le16, 1≤Ai≤1001\le A_i\le 100.
  • Subtask 2 (30 points): 1≤N≤50001\le N\le 5000, 1≤Ai≤50001\le A_i\le5000.
  • Subtask 3 (50 points): 1≤N≤2⋅1051\le N\le 2\cdot10^5, 1≤Ai≤2⋅1051\le A_i\le 2\cdot10^5.

Examples

Example 1

Input

5
7 9 3 14 63

Output

2

Explanation

Remove 77 and 1414, leaving 9,3,639,3,63: these are comparable since 3∣9∣633\mid9\mid63. One deletion is insufficient.

Example 2

Input

3
2 14 42

Output

0

Explanation

The array 2,14,422,14,42 is already beautiful because 2∣14∣422\mid14\mid42.

Example 3

Input

4
45 9 3 18

Output

1

Explanation

Removing 1818 leaves 45,9,345,9,3; removing 4545 leaves 9,3,189,3,18. Either uses one deletion.

Example 4

Input

3
2 2 8

Output

0

Explanation

The equal elements 2,22,2 are compatible and both divide 88, so no deletion is needed.

Note: Each input file contains one case using the specified format.