Form the Maximal Set

아직 제출이 없습니다시간 제한5초메모리 제한512 MB

문제

Consider nn points placed around a circumference so that they form a regular polygon. Points are enumerated in clockwise order by sequential integers between 11 and nn. The number of points is even.

Each point is connected with exactly one other point, so n/2n / 2 chords are formed. You may replace kk of those chords with arbitrary chords (even if they don't end in any of the given points), and then select set of chords such that each pair of chords in the set is intersecting. Your goal is to replace the chords and and select the set in such a way that the size of the set is maximum possible.

입력

The first line of input contains two integers nn and kk (2n80002 \le n \le 8000, nn is even, 0kmin(n/2,20)0 \le k \le \min (n / 2, 20)).

The second line contains a permutation PP of the first nn integers denoting the connection. If P_i=jP\_i = j, it means that points ii and jj are connected by a chord. It is guaranteed that if P_i=jP\_i = j then P_j=iP\_j = i, and that P_iiP\_i \ne i.

출력

Print one integer: the maximal size of a set of intersecting chords which may be selected after changing kk of the given chords.

힌트

In the second example, you may replace the chord (1,7)(1, 7) to obtain a set of three intersecting chords: for example, all chords except (2,4)(2, 4) form a pairwise intersecting set.