import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner s=new Scanner(System.in);
StringBuilder sb = new StringBuilder("");
while (s.hasNext()) {
int size=s.nextInt();
int[] arr=new int[size];
for(int i=0;i<arr.length;i++){
arr[i]=s.nextInt();
}
if(size ==1){
sb.append("Jolly").append("\n");
continue;
}
boolean jolly=true;
ArrayList<Integer> col=new ArrayList<Integer>();
int dist=Math.abs(arr[1]-arr[0]);
if(dist>size-1 || dist==0){
sb.append("Not jolly").append("\n");
continue;
}
col.add(dist);
for(int i=1;i<arr.length-2;i++){
int aft=Math.abs(arr[i+1]-arr[i]);
if(col.contains(aft) ||aft==0 || aft>size-1){
jolly=false;
break;
}
col.add(aft);
dist=aft;
}
if(jolly)
sb.append("Jolly").append("\n");
else
sb.append("Not jolly").append("\n");
}
System.out.print(sb);
}
}
No comments:
Post a Comment