This page is still under construction.

Parts of this page are still being built. What you see may change.

Doki Doki Snack Handout

Interview

Time limit1sMemory limit128 MB

Summary
Given a queue of numbered students, check whether they can be passed out in order 1 to N using one last-in-first-out holding spot.
Level

Medium5 of 10

Topics
Stack, Simulation
Solved
No attempts yet

Problem

Every exam season the student council hands out snacks to classmates worn out by studying. Seunghwan arrives at the announced place on time, heart pounding at the thought of a snack. Every other student is already there, so Seunghwan gets the last number tag. Worse, a few students cut in line over and over until the order of the queue is a mess. Ingyu, who is handing out the snacks, tells the complaining crowd that he can only hand out snacks in number tag order.

Only then do the students try to line up in order, but the place is so cramped that nobody can move freely. There is one narrow spot to the left of the queue where people can stand single file. Used well, that spot may let everyone get a snack in number tag order.

The snack handout area works like this.

  1. The students stand in a single line, and only the person at the head of the queue can move.
  2. The line Ingyu set up lets students through in number tag order only, that is 11 first, then 22, up to NN.
  3. Between that line and the head of the queue there is a holding spot that people enter single file, one at a time. The person at the head of the queue can step into the holding spot, but nobody in the holding spot can go back to the queue.
  4. The holding spot is open on one side only. The person who entered the holding spot last is the first one to leave it for the line.

The snack handout area

Given the order of the number tags, decide whether everyone can get a snack in number tag order.

Input

The first line contains NN, the number of students standing in front of Seunghwan. (1≤N≤1,0001 \le N \le 1{,}000)

The second line contains the number tags of those students, listed from the head of the queue to the back. The tags are the integers from 11 to NN, each appearing once.

Output

Print Nice if everyone can get a snack in number tag order, and Sad otherwise.

Examples5

  1. Example 1

    Input
    5
    5 4 1 3 2
    
    Expected output
    Nice
    
  2. Example 2

    Input
    1
    1
    
    Expected output
    Nice
    
  3. Example 3

    Input
    4
    1 2 3 4
    
    Expected output
    Nice
    
  4. Example 4

    Input
    4
    4 3 2 1
    
    Expected output
    Nice
    
  5. Example 5

    Input
    3
    2 3 1
    
    Expected output
    Sad