1 #include <iostream> 2 #include <cstdio> 3 #include <stdlib.h> 4 using namespace std; 5 6 int seq[3001], diff[3001]; 7 8 int main() 9 { 10 int n, i, j, flag, min_index; 11 while(scanf("%d", &n) != EOF) 12 { 13 for (i = 1; i <= n; i++) // initial 14 scanf("%d", &seq[i]); 15 16 for (i = 1; i <= n-1; i++) // the difference 17 diff[i] = abs(seq[i+1] - seq[i]); 18 19 for(i = 1; i < n-1; i++) // select_sort 20 { 21 min_index = i; 22 for (j = i+1; j <= n-1; j++) 23 { 24 if (diff[j] < diff[min_index]) 25 { 26 min_index = j; 27 } 28 } 29 swap(diff[i], diff[min_index]); 30 } 31 32 flag = 1; 33 for (i = 1; i <= n-1; i++) 34 { 35 if (diff[i] != i) 36 { 37 cout << "Not jolly" << endl; 38 flag = 0; 39 break; 40 } 41 } 42 if(flag) 43 cout << "Jolly" << endl; 44 } 45 46 return 0; 47 }