public static bool IsPerfect(int[] arr) {
for (int i = 0; i < arr.Length; ++i)
if (arr[i] < 0 || arr[i] >= arr.Length)
for (int i = 0; i >= 0 && i < arr.Length; )
(i, arr[i]) = (arr[i], -1);
for (int i = 0; i < arr.Length; ++i)
public static void Main() {
int[] arr = { 3, 0, 1, 4, 2 };
Console.Write(IsPerfect(arr) ? "Perfect" : "NOT Perfect");