Best gift


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

When the server was in serious trouble, Erfan was a great help. Since Erfan is a fan of palindromes, Amin wanted to gift him a palindrome array. However, Erfan felt discouraged by the complexity of that idea and instead requested just a sorted array as a gift.

Initially, you have an array of length 2n2n that consists of 2n2n integers. In each step, you pick the first n+1n+1 elements of the array and move them to the end of the array in the same order.

For example, if the initial array is [3, 2, 5, 4, 1, 1], after one step,

it transforms into [1, 1, 3, 2, 5, 4].

Now, Amin wants to know if, after some number of steps, he can sort the array and make Erfan happy, or if Erfan will remain frustrated and never help with another server trouble again.

input🔗

the first line consist nn that 2n is the length of the array. the next line consist of 2n2n integers. aia_i the array elements.

1n100,0001 \le n \le 100,000

1ai1000,000,0001 \le a_i \le 1000,000,000

output🔗

your output should consist one string. "happy erfan" if Amin can sort the array after finite number of steps. "sad erfan" if Amin can't sort the array with any number of steps.

example🔗

sample input 1🔗

2
1 2 3 4
Plain text

sample output 1🔗

happy erfan
Plain text

sample input 2🔗

2 
4 3 2 1
Plain text

sample output 2🔗

sad erfan
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.