Under construction

Still being built. Things may change

Jolly Jumpers

Interview

Time limit1sMemory limit128 MB

Summary
For each sequence, check whether the absolute differences of adjacent elements are exactly the set 1 to n-1.
Level

Easy3 of 10

Topics
Array, Hash map, Implementation, Math
Solved
No attempts yet

Problem

Determine whether an integer sequence is a Jolly jumper.

  • A sequence of length 11 is always a Jolly jumper.
  • A sequence of length n≥2n \ge 2 is a Jolly jumper if the absolute values of the differences between adjacent numbers include every integer from 11 to n−1n-1 exactly once. (There are exactly n−1n-1 adjacent pairs.)

For example, the sequence 1 4 2 3 is a Jolly jumper because the absolute differences of its adjacent numbers are 3,2,13, 2, 1, which cover all of 11 through 33.

Given several sequences, decide for each one whether it is a Jolly jumper.

Input

The input consists of several lines. Each line starts with the length nn (1≤n<30001 \le n < 3000) of a sequence, followed by nn integers separated by spaces. Lines are given until the end of input.

Output

For each sequence, print Jolly if it is a Jolly jumper and Not jolly otherwise, one result per line.

Examples3

  1. Example 1

    Input
    4 1 4 2 3
    5 1 4 2 -1 6
    
    Expected output
    Jolly
    Not jolly
    
  2. Example 2

    Input
    1 5
    
    Expected output
    Jolly
    
  3. Example 3

    Input
    2 3 3
    
    Expected output
    Not jolly