554. Stack Possibility Checker

0

Medium

Given two sequences called pushed and popped with distinct values, determine if it is possible to obtain the second sequence by performing a series of push and pop operations on an initially empty stack.

Input Format

The first line of the input should contain an integer n, which represents the size of the sequences. The second line of the input should contain n space-separated integers representing the elements of the pushed sequence. The last line of the input should contain n space-separated integers representing the elements of the popped sequence.

Output Format

Print 'true' if it is possible to obtain the second sequence by performing a series of push and pop operations on an initially empty stack. Otherwise, print 'false'.

Example

Input

5 1 2 3 5 6 5 6 3 2 1

Output

true

Constraints

1<=n<=1000
Loading...

View Submissions

Console