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

#SP0000234. Chia dãy không có tích chính phương (bản khó) (Square-Free Division (hard version))

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chia dãy không có tích chính phương (bản khó) (Square-Free Division (hard version))

Square-Free Division (hard version)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array of positive integers a1,a2,…,ana_1,a_2,\ldots,a_n. Before splitting it, you may perform at most kk changes. In each change, choose an array position and replace its value with any positive integer.

Then partition the entire array into nonempty, consecutive, nonoverlapping segments. Within any segment, there must not be two distinct positions whose values multiply to a perfect square. A perfect square is the square of a nonnegative integer.

Find the minimum possible number of segments after choosing the changes optimally. Equal values at different positions still represent distinct positions.

Input

Line 1 contains n,kn,k. Line 2 contains exactly nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print one integer: the minimum number of consecutive segments after at most kk changes.

Subtasks

  • Subtask 1 (20 points): 1≤n≤141\le n\le14; 0≤k≤30\le k\le3; 1≤ai≤1001\le a_i\le100 for all ii.

  • Subtask 2 (30 points): 1≤n≤40001\le n\le4000; 0≤k≤100\le k\le10; 1≤ai≤1051\le a_i\le10^5 for all ii.

  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5; 0≤k≤200\le k\le20; 1≤ai≤1071\le a_i\le10^7 for all ii.

Examples

Input

5 2
18 6 2 4 1

Output

1

Explanation

Here a=[18,6,2,4,1]a=[18,6,2,4,1] and k=2k=2. Change position 11 from 1818 to 33, and position 55 from 11 to 55, obtaining [3,6,2,4,5][3,6,2,4,5]. No product of values at two different positions is a perfect square (for example, 3⋅6=183\cdot6=18, 6⋅2=126\cdot2=12, and 2⋅4=82\cdot4=8 are not squares; the remaining pairs also pass). Thus the entire array forms one valid segment. A nonempty array cannot use fewer than one segment, so the answer is 11.