OFFSIDE - He is offside!

Hemisphere Network is the largest television network in Tumbolia, a small country located east of South America (or south of East America). The most popular sport in Tumbolia, unsurprisingly, is soccer; many games are broadcast every week in Tumbolia.

Hemisphere Network receives many requests to replay dubious plays; usually, these happen when a player is deemed to be offside by the referee. An attacking player is offside if he is nearer to his opponents’ goal line than the second last opponent. A player is not offside if

  • he is level with the second last opponent or

  • he is level with the last two opponents.

Through the use of computer graphics technology, Hemisphere Network can take an image of the field and determine the distances of the players to the defending team’s goal line, but they still need a program that, given these distances, decides whether a player is offside.

Input

The input file contains several test cases. The first line of each test case contains two integers A and D separated by a single space indicating, respectively, the number of attacking and defending players involved in the play (2 <= A,D <= 11). The next line contains A integers Bi separated by single spaces, indicating the distances of the attacking players to the goal line (1 <= Bi <= 104). The next line contains D integers Cj separated by single spaces, indicating the distances of the defending players to the goal line (1 <= Cj <= 104). The end of input is indicated by A = D = 0.

Output

For each test case in the input print a line containing a single character: “Y” (uppercase) if there is an attacking player offside, and “N” (uppercase) otherwise.

Example

Input:
2 3
500 700
700 500 500
2 2
200 400
200 1000
3 4
530 510 490
480 470 50 310
0 0

Output:
N
Y
N

Added by:Camilo Andrés Varela León
Date:2007-12-02
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:The 2007 ACM South American Programming Contest

hide comments
2020-02-05 11:50:19
1st defender is not at all important, that's the catch :')
Only work with 1st attacker and 2nd defender
2019-12-22 13:36:51
@abhiladdha ever heard of sorting??
2019-07-31 15:57:50
All you have to do is to compare every attacking players with second last defender(sort and get defender[1]) ,if attacking player's distance is less than second last defender,then raise flag and break;he is offside else not offside(if flag variable not raised) .

Last edit: 2019-07-31 15:58:07
2019-07-10 10:16:21
check the two defender which are close to line. if any of the attacker is ahead of them then print Y otherwise N
2019-05-19 12:15:42
very poor statement ..if you do not understand please checkout in comments!
2019-02-07 22:41:21
Problem statement written very poorly :/

He will not be offside:-
1)If their are at least 2 opponents(Defenders) which are more closer to the goal or equally closer to the goal when compared to the last attacker (that is the attacker which is closest to the goal).
2)If the last second defender is equally closer or more closer to the goal than the last attacker.
2018-12-07 10:04:48 Joeffison [UFCG]
Exact same code got TLE with python 2/pypy and was accepted with time 0.00 using python2/cpython.
2018-10-25 22:34:33
Clarification:
If at least two defenders are closer or at level with attacker to goal line, then attacker is not offline
2018-06-01 16:07:40
AC in one go!!
2018-03-16 15:40:49
If you get the ques, its a waste of time.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.