Rock-Scissors-Paper is a game played with hands and often used for random choice of a person for some purpose. Today, we have got an extended version, namely, Hyper Rock-Scissors-Paper (or Hyper RSP for short).
In a game of Hyper RSP, the players simultaneously presents their hands forming any one of the following 15 gestures: Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water, Dragon, Devil, Lightning, and Gun.
Figure 1: Hyper Rock-Scissors-Paper
The arrows in the figure above show the defeating relation. For example, Rock defeats Fire, Scissors, Snake, Human, Tree, Wolf, and Sponge. Fire defeats Scissors, Snake, Human, Tree, Wolf, Sponge, and Paper. Generally speaking, each hand defeats other seven hands located after in anti-clockwise order in the figure. A player is said to win the game if the player’s hand defeats at least one of the other hands, and is not defeated by any of the other hands.
Your task is to determine the winning hand, given multiple hands presented by the players.
Input
The input consists of a series of data sets. The first line of each data set is the number N of the players (N < 1000). The next N lines are the hands presented by the players.
The end of the input is indicated by a line containing single zero.
Output
For each data set, output the winning hand in a single line. When there are no winners in the game, output “Draw” (without quotes).
Example
Input
8
Lightning
Gun
Paper
Sponge
Water
Dragon
Devil
Air
3
Rock
Scissors
Paper
0
Output
Sponge
Draw
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We need to parse this problem. It's a game with 15 gestures. Each gesture defeats the next 7 gestures in anti-clockwise order. According to the figure, we need to understand the circular order. The figure shows 15 gestures arranged in a circle. The arrows show defeating relation. The description: "each hand defeats other seven hands located after in anti-clockwise order". That means if we list the gestures in clockwise order, each defeats the next 7 in that order? Actually: "located after in anti-clockwise order" might mean that if you go anti-clockwise from a given hand, you encounter those that it defeats. But let's interpret: The arrows in the figure show the defeating relation. For example, Rock defeats Fire, Scissors, Snake, Human, Tree, Wolf, and Sponge. Fire defeats Scissors, Snake, Human, Tree, Wolf, Sponge, and Paper. So the order must be something like: Starting from Rock, going clockwise or anti-clockwise? Need to deduce the ordering.
Let's list the 15 gestures:
Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water, Dragon, Devil, Lightning, Gun.
Given example: Rock defeats: Fire, Scissors, Snake, Human, Tree, Wolf, Sponge. So these 7 are the ones it defeats. So the set of defeated by Rock is {Fire, Scissors, Snake, Human, Tree, Wolf, Sponge}. It does not defeat Paper, Air, Water, Dragon, Devil, Lightning, Gun? Actually there are 14 others. So it defeats exactly 7, loses to 7. So what does Rock lose to? Since the relation is cyclic and each defeats exactly 7 and loses to the other 7 (i.e., the ones that defeat it). So the 7 that defeat Rock are the ones that have Rock in their defeat list? Actually we can deduce from the order.
Now Fire defeats: Scissors, Snake, Human, Tree, Wolf, Sponge, Paper. So Fire defeats the same set as Rock except Rock is replaced by Paper? Actually Rock defeated Fire, but Fire defeats Paper. So Fire defeats Paper, while Rock does not defeat Paper (maybe Paper defeats Rock?). So the cycle.
From these two lists, we see Rock defeats Fire, but Fire does not defeat Rock. So Rock beats Fire. Fire beats Scissors, Snake, Human, Tree, Wolf, Sponge, Paper. So Fire beats Paper, but Rock doesn't beat Paper. So Paper must be after Fire in the order? But we need to determine the exact circular order.
The problem says: each hand defeats other seven hands located after in anti-clockwise order. So if we go anti-clockwise from a hand, the next 7 are defeated by it. Alternatively, if we go clockwise, those are the ones that defeat it? Let's define.
Assume the hands are arranged in a circle. Direction: Let's define the order as they appear in the figure. Without figure, we need to derive ordering from example.
Given the two lists:
Rock defeats: Fire, Scissors, Snake, Human, Tree, Wolf, Sponge.
Fire defeats: Scissors, Snake, Human, Tree, Wolf, Sponge, Paper.
Comparing: both defeat Scissors, Snake, Human, Tree, Wolf, Sponge. So those six are common. The seventh for Rock is Fire (which is not in Fire's list because it's itself? Actually Fire's list includes Paper instead of Fire). So from Rock's perspective, it defeats Fire, and Fire does not defeat Rock. So Fire is in the anti-clockwise direction from Rock?
Maybe the ordering is something like: Rock, then going anti-clockwise we meet Fire, then Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water, Dragon, Devil, Lightning, Gun. But let's test: If the order is in that sequence (clockwise maybe). Actually we need to decide.
I could also think: Since there are 15, each defeats 7. So the directed graph is such that for each hand, its "defeat set" is the next 7 in a fixed circular order.
Thus there exists a cyclic permutation of the 15 elements such that for each element, it defeats the next 7 elements (wrapping around). The losing set is the previous 7 elements (i.e., those that defeat it). So the key is to know the order. But we can deduce from the example inputs/outputs.
We have an example input:
8
Lightning
Gun
Paper
Sponge
Water
Dragon
Devil
Air
3
Rock
Scissors
Paper
0
Output: Sponge and Draw.
We need to verify our ordering. The first data set: players with those 8 hands, and output is "Sponge". So Sponge is the unique winner.
We need to check which hand wins according to the rules: "A player is said to win the game if the player’s hand defeats at least one of the other hands, and is not defeated by any of the other hands." So winner is a hand that beats at least one other hand and is not beaten by any other hand (i.e., it either ties or beats all others; but ties? The definition: defeats at least one, and is not defeated by any. It doesn't mention ties. If two same hands, presumably neither defeats the other (draw?). The problem likely considers that same hand does not defeat. So for a hand to win, it must be such that for all other hands, either it defeats them or it is the same? But it says "is not defeated by any of the other hands". So if there is another hand that defeats it, it's out. Also it must defeat at least one other hand. So winner is a hand that is not beaten by anyone and beats at least one.
If multiple such hands? Possibly there can be multiple winners? The problem says "determine the winning hand" implying there can be only one? Or maybe output the first? But likely there is at most one winner, as they said "output the winning hand" singular. But it could be that there are zero or one winners. Might be that there is exactly one if any, due to cyclic nature? But not necessarily, e.g., if all same, then no one defeats any other, so no winner (draw). Could there be two distinct hands that both are not defeated by any other? For that to happen, each of them must not be defeated by the other. That means either they are the same or neither defeats the other, i.e., a tie? But in this game, given two distinct hands, one always defeats the other? Because it's a tournament-like directed graph. With 15 elements, each pair is either one defeats the other or the other defeats it, because it's a total order? Actually it's a directed cycle? Wait, if each hand defeats exactly 7 others and loses to 7 others, then for any two distinct hands, one defeats the other. Since the set of defeated hands for a given hand is exactly 7 specific hands; the other 7 are those that defeat it. So any other hand is either in its defeat set or in its lose set. So for any two distinct hands, exactly one defeats the other. So there are no ties except when hands are equal. Therefore, in a set of N players, if there are multiple distinct hands, only one can be undefeated? Not necessarily; consider a set with two hands: A defeats B, then A is undefeated, B is defeated by A, so only A undefeated. If we have three hands A, B, C where A defeats B, B defeats C, C defeats A (rock-paper-scissors like cycle). In this extended game, is there a cycle? The relation is not transitive necessarily, but does it produce cycles? With a circular defeat relation (each defeats next 7), the graph is not transitive but it's a tournament? Actually the graph is such that if we label the hands in order 0..14 in a circle, then hand i defeats hands i+1,...,i+7 (mod 15). Then for any two hands i and j, we can compute whether i defeats j: if the clockwise distance from i to j (mod 15) is between 1 and 7 inclusive, then i defeats j; if the distance is between 8 and 14 (i.e., 15-7=8 to 14), then j defeats i. So it's a total order? Actually it's a circular order with a direction; it's not a linear order because there is a cycle: i defeats i+1, i+1 defeats i+2, ..., i+7 defeats i+8, but i+8 defeats i? Let's check: distance from i to i+8 is 8, which is >7, so i does NOT defeat i+8; rather i+8 defeats i (since distance from i+8 to i is 15-8=7? Actually careful: If we consider i to j, i defeats j if j is within the next 7 positions clockwise. So if j = i+8 (mod 15), then distance clockwise from i to j is 8, which is >7, so i does NOT defeat j. Now consider j = i+8, what's the clockwise distance from j to i? That would be 15-8=7, so j defeats i. So indeed there is a cycle of length 3? Let's see: i defeats i+1. i+1 defeats i+2. But i+2 might defeat i? Check distance from i+2 to i: clockwise from i+2 to i is (15-2)=13, which is >7, so i+2 does NOT defeat i; i defeats i+2? distance from i to i+2 is 2, so i defeats i+2. So no cycle of length 3; but can there be a cycle of length 2? No. So is the relation transitive? Not exactly but it's a "comparability" like a tournament with a special structure called a "circular tournament". In a circular tournament, there is a unique "king" maybe. But could there be more than one undefeated hand in a set of multiple hands? Suppose we have three distinct hands: A, B, C. Since for any pair, one defeats the other, the directed graph among these three is a tournament. In a tournament, there can be more than one vertex with outdegree >0 and indegree 0? Actually indegree 0 means no one defeats it. In a tournament (complete oriented graph), there cannot be two vertices with indegree 0 because if two vertices both had indegree 0, then there is no edge entering either, meaning the edge between them must be directed both ways? Actually in a tournament, for any two distinct vertices, exactly one directed edge exists. So for two vertices u and v, if indegree(u)=0, that means no other vertex has an edge to u, so specifically v does not have an edge to u, meaning the edge u->v must exist. Then v has an incoming edge from u, so indegree(v)>=1. So only one vertex can have indegree 0 (a "king" or "source"). Similarly, there can be only one vertex with outdegree 0. So in a set of distinct hands, there is exactly one undefeated hand (no one beats it). But if there are duplicates, it's more complicated: if multiple players show the same hand, then that hand as a type, if it appears multiple times, then among those identical hands, none defeats the other? Since they are the same, do they defeat each other? The rule says "the player's hand defeats at least one of the other hands". Usually in rock-paper-scissors, same gestures result in a tie, not defeat. So for identical hands, we consider that they do not defeat each other. So if we have multiple players with the same hand, that hand might be undefeated if no other hand beats it. But does the presence of multiple copies affect "defeats at least one"? For a player to win, his hand must defeat at least one other hand. If there are multiple identical hands, a player with that hand might not defeat any other if all others are the same hand. But if there is at least one hand of a different type that it defeats, then it can defeat that one. But also it must not be defeated by any hand. So if a hand type appears multiple times and it's undefeated, then all players with that hand are winners? Possibly multiple winners? But the problem says "determine the winning hand", implying we output the hand (type) that wins. If there are multiple players with the winning hand, they all win? But output is just the hand name. So probably the definition is: Among the set of hands presented, we want a hand that meets: (1) There exists at least one other hand that it defeats. (2) There is no hand that defeats it. If there are multiple such hands (distinct types) meeting these conditions? But as argued, in a set of distinct hand types, only one can be undefeated. But could there be two distinct hand types such that neither defeats the other? No, because for any two distinct types, one defeats the other. So at most one distinct type can be undefeated. So if there is an undefeated type, it's unique. However, if there are duplicates of that type, then all players with that type are undefeated. But the winning hand is that type. So output that hand name.
Thus for each data set, we need to find the hand H such that:
For every other hand G present in the list, either G == H or H defeats G.
And there exists at least one hand G != H in the list (i.e., H defeats at least one other hand).
If no such H, output "Draw".
Thus we need to know the defeat relation among the 15 gestures. So we must reconstruct the cyclic order.
Let's derive the order from the given information. We have 15 names. Let's list them in some order such that each defeats the next 7. The direction: "located after in anti-clockwise order". That phrase: "each hand defeats other seven hands located after in anti-clockwise order". If we imagine the circle, with hands placed around. If we go anti-clockwise from a hand, we encounter some hands. The ones "after" (i.e., following) in anti-clockwise direction are those it defeats. So if we list the hands in clockwise order, then each hand would defeat the previous 7? Need to be careful.
Define: Suppose we have a circle and we place the hands in some order around it, say clockwise. If we pick a hand, then moving anti-clockwise (i.e., opposite to clockwise) we go to the previous hand in the clockwise order. So "after in anti-clockwise order" means if you go anti-clockwise, the ones you meet after the current are the ones it defeats. So if we label positions 0..14 in clockwise order, then anti-clockwise direction is decreasing indices (mod 15). So a hand at index i defeats those at indices i-1, i-2, ..., i-7 (mod 15). That is equivalent to: a hand at index i is defeated by those at indices i+1,...,i+7. Alternatively, if we list the order in a clockwise order, then each hand defeats the previous 7, and loses to the next 7.
Alternatively, if we list the order in anti-clockwise order, then each hand defeats the next 7. It's easier to define an ordered list L such that for each index i (0..14), L[i] defeats L[(i+1) mod 15], L[(i+2) mod 15], ..., L[(i+7) mod 15]. That is the typical representation: if you go clockwise (increasing index) then each defeats the next 7? Actually that would be: at index i, defeats i+1..i+7. That would be if we say the list is arranged in clockwise order and the "after in clockwise" are the ones it defeats. But the description says "after in anti-clockwise order". So I'm leaning towards the list being in anti-clockwise order. Let's not get confused; we can deduce by the example lists.
If we assume there is an order (say clockwise) such that each defeats the next 7 (clockwise), then Rock would defeat the 7 that follow it in clockwise order. That would be some sequence: after Rock comes X1, X2,...X7; these are the ones Rock defeats. And Fire would defeat the 7 after it. So if Rock's list includes Fire, that means Fire is one of the 7 after Rock in clockwise order. And Fire's list includes Paper, so Paper is one of the 7 after Fire. And Fire's list does not include Rock, so Rock is not among the 7 after Fire, meaning Rock is either before Fire or more than 7 ahead? Actually if Fire defeats the 7 after it, then Rock would be among those only if Rock is after Fire in the order. Since it's not, Rock is not after Fire, so Rock must be before Fire (or exactly at distance >7). Similarly, Rock's list does not include Paper, so Paper is not among the 7 after Rock, so Paper is either before Rock or more than 7 after.
So let's hypothesize a clockwise order such that each defeats the next 7 clockwise. Then we can derive constraints.
Let positions 0..14 clockwise. For each hand h, define its index i. Then h defeats hands at indices (i+1) mod 15, ..., (i+7) mod 15. And loses to hands at (i+8) mod 15,..., (i+14) mod 15.
Now from Rock's defeats: Fire, Scissors, Snake, Human, Tree, Wolf, Sponge. So these must be the next 7 after Rock. So in clockwise order, immediately after Rock we have these 7 in some order. The order among them we don't know yet. But they are exactly the set S_R = {Fire, Scissors, Snake, Human, Tree, Wolf, Sponge}.
Fire's defeats: Scissors, Snake, Human, Tree, Wolf, Sponge, Paper. So these are the next 7 after Fire. So S_F = {Scissors, Snake, Human, Tree, Wolf, Sponge, Paper}.
Notice S_R = {Fire} ∪ {Scissors, Snake, Human, Tree, Wolf, Sponge} = {Fire} plus the other six (which are also in S_F). So S_R contains Fire, but not Paper; S_F contains Paper, but not Fire. This suggests that in the clockwise order, after Rock we have Fire and then the other six (in some order), and after Fire we have the other six and then Paper. Possibly the order is: Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper,...? Let's test.
If the order is: Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, ... then Rock's next 7: positions 1 through 7: Fire, Scissors, Snake, Human, Tree, Wolf, Sponge. That matches Rock's defeat set exactly! Fire's next 7: positions after Fire (index 1) would be indices 2-8: Scissors, Snake, Human, Tree, Wolf, Sponge, Paper. That matches Fire's defeat set! Good! So this order works: Rock (0), Fire (1), Scissors (2), Snake (3), Human (4), Tree (5), Wolf (6), Sponge (7), Paper (8), ... and then the remaining 6 hands: Air, Water, Dragon, Devil, Lightning, Gun, in some order for indices 9-14. We need to determine their order from other clues maybe? Also need to confirm that the defeat sets for other hands match this pattern. But we might not need the full order for the problem, only need to compute defeat relations between any two given hands. If we can deduce the cyclic order, we can compute distance. So we need to know the exact order of all 15. Let's see if we can deduce the rest from the example output to confirm.
The example output "Sponge" for the first data set suggests that among the set of hands: Lightning, Gun, Paper, Sponge, Water, Dragon, Devil, Air, Sponge is the winner. Let's compute using our partial order: indices so far: 0:Rock,1:Fire,2:Scissors,3:Snake,4:Human,5:Tree,6:Wolf,7:Sponge,8:Paper, then 9-14 unknown: Air, Water, Dragon, Devil, Lightning, Gun. We need to assign positions 9-14 such that the defeat relations among these hands yield Sponge as the only undefeated hand. Let's test.
Given hands list: Lightning, Gun, Paper, Sponge, Water, Dragon, Devil, Air. We need to compute for each hand whether it is undefeated.
We need to assign indices for these 8 hands plus the others. Since we don't have Rock etc, we need the full circle. Possibly the order continues: after Paper comes Air, Water, Dragon, Devil, Lightning, Gun, then back to Rock? Or some other order.
We can try to find the full order by looking at known relationships among other pairs if any. But we might also search online: This problem is from some contest; I recall a problem "Hyper Rock-Scissors-Paper" with 15 gestures; the order is known. Or we can deduce from typical "rock-paper-scissors-lizard-Spock" but this is extended. However, I think the order is as per the figure; we might need to reconstruct from the image description. The problem statement includes an image, but we don't have it. However, we can infer the order from the given defeat lists for Rock and Fire, and perhaps from other clues like the naming: maybe it's based on the classic "rock, paper, scissors, lizard, Spock"? Actually that's 5. This has 15. Possibly it's from a known Japanese game "Janken" with 15? Hmm.
But we can use the example to determine the correct ordering. Let's attempt to deduce positions for Air, Water, Dragon, Devil, Lightning, Gun.
We have the partial order: indices 0-8 known: 0:Rock,1:Fire,2:Scissors,3:Snake,4:Human,5:Tree,6:Wolf,7:Sponge,8:Paper.
Now we need to place the remaining six: Air, Water, Dragon, Devil, Lightning, Gun. There are 6! possible orders. However, we can constrain using the example: we need Sponge to be the winner among that set. Let's define indices. Let's denote the indices modulo 15. We'll compute for each candidate hand H among the set, whether it is undefeated (i.e., for all other hands G in the set, H defeats G or H==G). Actually undefeated means H is not defeated by any other hand in the set. That is, there is no G in the set such that G defeats H. So H is undefeated if for all G ≠ H, it is not the case that G defeats H; equivalently, H defeats G or G is same? But because distinct hands always have a defeat relation, it means H defeats all other hands in the set. Wait, check: For H to be undefeated, there must be no G that defeats H. Since for any distinct G, either H defeats G or G defeats H (but not both). So if there is no G that defeats H, then for all G distinct, H defeats G. So an undefeated hand must defeat all other hands present. Additionally, it must defeat at least one (automatically if there is at least one other hand). So the winner is a hand that defeats every other distinct hand in the set. That is a necessary and sufficient condition (given distinctness). However, if there are duplicates of the winning hand, then for each occurrence, it defeats all other distinct hands. But also the condition "defeats at least one" holds if there is at least one hand of a different type. So the winning hand type is the one that beats all other types present. So it's the "dominant" hand among the set.
Thus in a set of hands (with possible duplicates), the winning hand is the hand type that beats every other distinct type present. If such a type exists, it's the winner. If there are multiple types that beat all others? Impossible because if A beats B, then B does not beat A. So at most one type can beat all others. But could there be a type that beats all others but does not appear? That's irrelevant. So we need to find if there is a type H such that for every other type G present in the set, H defeats G. If yes, output H; else "Draw".
Now back to example: set S = {Lightning, Gun, Paper, Sponge, Water, Dragon, Devil, Air}. We need to check if Sponge beats all others. So we need the defeat relation such that Sponge defeats Lightning, Gun, Paper, Water, Dragon, Devil, Air. According to our partial order, Sponge is at index 7. For any other hand X at index i, we need to determine if Sponge defeats X. In our model (clockwise order and defeats next 7 clockwise), Sponge defeats hands with indices (7+1) mod 15 =8, (7+2)=9, ..., (7+7)=14. That is indices 8,9,10,11,12,13,14. Those are the next 7 clockwise. So Sponge defeats exactly the hands at positions 8 through 14. It loses to positions 0 through 6 (since those are the previous 7? Actually loses to indices (7+8) mod 15 =0? Let's compute: It loses to indices (7+8) mod 15 =15 mod15=0, (7+9)=1,... up to (7+14)=21 mod15=6. So yes, it loses to indices 0-6). So Sponge's defeat set is the set of hands that are in positions 8-14 (inclusive) in the clockwise order.
Thus for Sponge to beat all other hands in S, all other hands must lie in positions 8-14. That is, none of the other hands can be in positions 0-6. And also note that if any hand is at position 7 (Sponge itself) that's fine. So we need the positions of the other 7 hands: Lightning, Gun, Paper, Water, Dragon, Devil, Air to be all within positions 8-14. Also note that position 8 is Paper (we already have Paper at index 8 from earlier). That matches: Paper is at 8, and Sponge (7) defeats Paper? Since 8 is in 8-14, yes Sponge defeats Paper. Good. So we need to assign positions for Air, Water, Dragon, Devil, Lightning, Gun such that they are all in 8-14 (i.e., indices 8,9,10,11,12,13,14). But note that indices 8 is already occupied by Paper, so the remaining positions are 9,10,11,12,13,14. There are exactly six remaining hands, perfect. So if we assign Air, Water, Dragon, Devil, Lightning, Gun to positions 9-14 in some order, then Sponge will defeat all of them. And also Sponge defeats Paper (position 8). So Sponge would beat all others. But we must also check whether any other hand in the set also beats all others. For instance, what about Paper? Paper is at index 8. Paper defeats indices 9-15? Actually 8 defeats 9-15? 8+7=15 -> indices 9,10,11,12,13,14,0? Wait, 8 defeats positions 9,10,11,12,13,14,0 (since (8+7) mod15 =15 mod15=0). So Paper defeats positions 9-14 and also 0. Which includes some of the others if they are in 9-14, but also possibly Rock (0) but Rock is not present. However, Paper also loses to positions 1-7? Actually loses to indices 10? Let's systematically compute: For any hand at index i, it defeats indices i+1..i+7 (mod15) and loses to i+8..i+14. So for Paper (8), it defeats 9,10,11,12,13,14,0. It loses to 1,2,3,4,5,6,7. So among the set S, we have Sponge at 7, which is in Paper's losing set (since 7 is in 1..7). So Paper would lose to Sponge, so Paper is not undefeated. Good.
What about other hands like Water? Suppose Water is at some index, say 9. Then Water defeats 10-16? Actually 9 defeats 10,11,12,13,14,0,1. It loses to 2,3,4,5,6,7,8. So it would lose to Sponge (7) and maybe others. So not undefeated.
Thus if we assign all remaining hands to positions 9-14, Sponge beats them all and is the only undefeated. That matches output.
But we need to verify that the assignment is consistent with the known order of the whole circle. So far we have indices: 0 Rock,1 Fire,2 Scissors,3 Snake,4 Human,5 Tree,6 Wolf,7 Sponge,8 Paper. And we need to place Air, Water, Dragon, Devil, Lightning, Gun at 9-14. So the full order would be:
0: Rock
1: Fire
2: Scissors
3: Snake
4: Human
5: Tree
6: Wolf
7: Sponge
8: Paper
9: ?
10: ?
11: ?
12: ?
13: ?
14: ?
(and then back to 0)
Thus the clockwise order after Paper is the six remaining in some order. The figure likely shows a specific order. We need to decide which order is correct. But maybe the exact order of the last six is not important for the solution as long as we know the defeat relations. However, to determine if a hand defeats another, we need to know the indices; but we can compute the cyclic distance if we have the full ordering. But we could also deduce the order from other clues: maybe the full order is given by the list of 15 in the problem statement? The problem statement lists the 15 gestures in a specific order: "Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water, Dragon, Devil, Lightning, and Gun." That list might be in the order they appear clockwise or anti-clockwise. Let's test: The list they gave: Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water, Dragon, Devil, Lightning, Gun. This is exactly the order we have up to index 8: Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper. Then continues with Air, Water, Dragon, Devil, Lightning, Gun. That matches the order we hypothesized for positions 9-14: Air, Water, Dragon, Devil, Lightning, Gun. That gives a complete ordering: indices 0-14 as given. And this ordering produced the correct example. So it's highly likely that the list provided in the problem statement is the clockwise order (or maybe anti-clockwise, but we need to confirm defeat direction). But we already used the assumption that each defeats the next 7 in clockwise order to match Rock and Fire's defeat lists. Let's verify that with the full list.
List L:
0: Rock
1: Fire
2: Scissors
3: Snake
4: Human
5: Tree
6: Wolf
7: Sponge
8: Paper
9: Air
10: Water
11: Dragon
12: Devil
13: Lightning
14: Gun
Now check another one for sanity: According to this ordering, what does Paper defeat? indices 9 Air,10 Water,11 Dragon,12 Devil,13 Lightning,14 Gun,0 Rock? Actually 8+7=15 -> 0, so Paper defeats 9,10,11,12,13,14,0: Air, Water, Dragon, Devil, Lightning, Gun, Rock. That seems plausible? Not given, but we can check if it's consistent with the figure? Not necessary.
Check Sponge's defeat: indices 8 Paper,9 Air,10 Water,11 Dragon,12 Devil,13 Lightning,14 Gun. That's Paper, Air, Water, Dragon, Devil, Lightning, Gun. That's 7 items. And in the example, Sponge is winner and we assumed it defeats all others, which include Paper, Air, Water, Dragon, Devil, Lightning, Gun. That's exactly Sponge's defeat set. So all good.
Thus the ordering is clear: The list given in the problem statement is the order (presumably clockwise) and each hand defeats the next seven hands in that order (wrapping around). However, the phrase "located after in anti-clockwise order" might indicate that if you go anti-clockwise, you find the ones it defeats. But in our model, if you go clockwise, you find the ones it defeats? Let's see: In our model, Rock defeats Fire, Scissors,... which are next in the list after Rock. That list is in clockwise order? Or anti-clockwise? The figure might show arrows pointing from a hand to those it defeats; maybe the arrows go anti-clockwise. If the list we have is in clockwise order, then the anti-clockwise direction would be backwards in the list. But Rock defeats Fire which is after Rock in the list (index+1). So if the list is clockwise, then Rock defeats the next one clockwise, which is opposite to "after in anti-clockwise". So maybe the list is actually in anti-clockwise order. Let's think: The problem says "located after in anti-clockwise order". Suppose we have the circle with the hands placed. If we label them in the order they appear when going anti-clockwise, then each hand defeats the next 7 in that order (i.e., following it anti-clockwise). In that case, the list they gave might be in anti-clockwise order. In that case, Rock defeats Fire, Scissors, etc., which are the next ones in that list. So it's consistent: they gave the order in which if you go anti-clockwise, you encounter Rock, then Fire, then Scissors, ... So that is exactly the order we used. So our list is the anti-clockwise order. But we don't need to care: we just need to know that for any two hands, we can compute defeat by checking the cyclic distance in this list. Specifically, define an array of 15 in the given order: Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water, Dragon, Devil, Lightning, Gun. Then for two hands A and B (distinct), we need to determine whether A defeats B. According to the rule: each hand defeats the 7 hands that follow it in this order (with wrap-around). So if B is among the next 7 after A in this list (circular), then A defeats B. Conversely, if B is among the previous 7 (i.e., A is among the next 7 after B), then B defeats A.
Thus we can implement: assign each hand an index 0..14. Then given two distinct indices i and j, compute the forward distance from i to j: (j - i + 15) % 15. If that distance is between 1 and 7 inclusive, then i defeats j. If it is 8 to 14, then j defeats i (or i loses). Since 0 means same hand.
This matches our earlier analysis.
Now we must verify the second example: 3 players: Rock, Scissors, Paper. In standard RPS, Paper beats Rock, Rock beats Scissors, Scissors beats Paper. But in this extended game, does the same hold? Let's compute using our order. Indices: Rock=0, Scissors=2, Paper=8.
Distances: From Rock (0) to Scissors (2): (2-0)=2 -> 1-7, so Rock defeats Scissors. From Rock to Paper (8): distance (8-0)=8 -> 8-14, so Paper defeats Rock. So Rock loses to Paper. From Scissors to Paper: (8-2)=6 -> 1-7, so Scissors defeats Paper. So we have a cycle: Rock beats Scissors, Scissors beats Paper, Paper beats Rock. That is classic RPS (though the ordering of classic RPS is Rock, Scissors, Paper? Actually classic: Rock beats Scissors, Scissors beats Paper, Paper beats Rock. Yes). So this set yields a cycle, no hand beats all others. So no winner, output "Draw". That matches example output.
Thus our ordering is correct.
Now we can solve the problem.
Algorithm:
Read N until N=0.
For each dataset, read N lines, each a hand name (string). We'll store them as list.
We need to determine if there exists a hand type H such that for every other hand type G present (distinct types), H defeats G.
Because duplicates don't affect the condition: if H appears multiple times, it's still the same type; the condition must hold for all other distinct types. Also, there must be at least one other hand (distinct) that H defeats; but if H is the only type present, then there is no other hand; but then does it defeat at least one? It defeats none because no other hand. So no winner -> Draw. Also if there is only one hand? Actually N could be 1? Input says N<1000, but could be 1? Then there is only one hand. According to rules: "A player is said to win the game if the player’s hand defeats at least one of the other hands, and is not defeated by any of the other hands." With no other hands, the condition "defeats at least one of the other hands" is false. So no winner -> Draw. So we need to handle that.
Implementation: We'll have a set of distinct hand types present. For each distinct hand type, we check if it defeats all other distinct types. If we find exactly one such, output that hand name. If none, output "Draw". Since at most one can satisfy (due to tournament property), we can just loop.
To compute defeat: map each hand name to an index (0..14). We'll define an array order = ["Rock","Fire","Scissors","Snake","Human","Tree","Wolf","Sponge","Paper","Air","Water","Dragon","Devil","Lightning","Gun"].
For two indices i and j (i != j), i defeats j if (j - i + 15) % 15 is in {1,2,...,7}.
Alternatively, we could precompute a 15x15 boolean matrix defeats[i][j] (true if i defeats j). Since N is small (max 1000), we can just compute on the fly.
Complexity: O(N^2) per dataset? But N<1000, distinct types <=15, so we can reduce by using distinct types only. Actually we can count frequencies of each hand. Then for each distinct hand type, check against all other distinct types. That's at most 15*14 = 210 checks, trivial.
Edge cases: If there is only one distinct type but multiple players, then there is no other distinct hand; does it defeat at least one? No, because it doesn't defeat any (since all others are same type, not defeating). So no winner -> Draw. That's correct.
Also if there are two distinct types A and B, then one defeats the other. So the one that defeats the other will be the winner if there are no other types? Check condition: The winner must defeat at least one (it does, the other type) and not be defeated by any. Since only two, if A defeats B, then A is undefeated and defeats at least one -> winner. So output A. That matches intuition.
If three or more distinct types, we need to see if any type defeats all others.
Thus solution straightforward.
But we must be careful about the definition: "defeats at least one of the other hands" means the player's hand defeats at least one other player's hand. If there are multiple players with the same winning hand, each such player wins? But the problem asks "determine the winning hand". So we just output the hand type. So our approach is correct.
Now let's double-check with the example: first dataset, distinct types: Lightning, Gun, Paper, Sponge, Water, Dragon, Devil, Air -> 8 distinct types. Sponge defeats all others? According to our order: Sponge (7) defeats indices 8-14: Paper(8), Air(9), Water(10), Dragon(11), Devil(12), Lightning(13), Gun(14). Indeed all others are in that set. So yes.
We could test a scenario where there is a tie: if there are multiple types that are undefeated? Not possible as argued, but we'll trust.
Now we should implement.
Implementation steps:
Define mapping name->index: use dictionary/hash.
While True: read N.
if N==0: break.
read N lines, collect list hands.
Build set of distinct hand types (strings). Optionally we could also count frequencies to check condition for duplicates? But distinct types only needed.
If distinct count == 0? No, N>0 implies at least one. But if N=0, we exit.
Initialize winner = None.
For each candidate hand C in distinct set:
For each other hand O in distinct set:
if O != C:
Check if C defeats O: using indices.
if not, break (C fails).
If loop completes (C defeats all others):
Additionally, we must check that there is at least one other hand (i.e., distinct count >=2). But if distinct count ==1, then the for loop over others is empty, and we would incorrectly mark C as winner. So we need to explicitly handle that: C can be winner only if there exists at least one other hand distinct from C. So if len(distinct) >= 2 and C defeats all other distinct types, then winner = C; break (since at most one, we can break after found).
After loop, if winner is not None: print winner; else print "Draw".
We need to be careful: duplicates of the same hand do not count as "other" if they are same? The condition "defeats at least one of the other hands" means there must be at least one other player (not necessarily distinct type?) Actually if there are multiple players with the same hand, and no other type, does any player defeat another? No, because same hand does not defeat. So no winner. So our condition of at least one distinct other type is correct. However, consider scenario: distinct types =2, but one type appears multiple times and the other appears once. The winning hand type must defeat the other type; that's enough. So distinct count >=2 ensures there is at least one other type. So our condition is fine.
But what if distinct count >=2 but the candidate hand C defeats all other distinct types, but there exists another hand of same type as C? That's fine, they don't affect defeat. So winner is C.
Thus algorithm done.
Now, we must ensure that the input reading is correct. Input lines contain hand names exactly as given (case-sensitive? The sample shows capitalized first letter and rest lower? Actually sample: Lightning, Gun, Paper, Sponge, Water, Dragon, Devil, Air. So first letter uppercase, rest lowercase. The list given: Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water, Dragon, Devil, Lightning, Gun. Some are capitalized first letter. So we should match exactly. So mapping keys must match exactly.
One more thing: Are there any spaces or punctuation? No.
Now produce output for each dataset.
Testing with sample:
First dataset: 8 hands -> winner Sponge.
Second dataset: 3 hands -> no winner, Draw.
Works.
We should test a few more scenarios manually.
Test 1: N=2, Rock, Scissors -> winner Rock? Rock defeats Scissors, so winner Rock. Output Rock.
Test 2: N=2, Rock, Paper -> winner Paper.
Test 3: N=1, Rock -> Draw.
Test 4: N=3, Rock, Paper, Scissors -> Draw (cycle).
Test 5: N=4: Rock, Fire, Scissors, Snake. Distinct: Rock(0), Fire(1), Scissors(2), Snake(3). Check each: Rock defeats Fire, Scissors, Snake? Distance to Fire=1, to Scissors=2, to Snake=3, all <=7, so Rock defeats all three. So winner Rock. Indeed Rock beats them.
Test 6: N=4: Fire, Scissors, Snake, Human? Fire defeats Scissors,Snake,Human, and also Tree,Wolf,Sponge,Paper but not Rock. So among those, Fire defeats Scissors(2), Snake(3), Human(4) -> all three. So winner Fire. Good.
Thus the solution works.
Now we should consider potential pitfalls: The mapping must be correct. The order: Rock (0), Fire (1), Scissors (2), Snake (3), Human (4), Tree (5), Wolf (6), Sponge (7), Paper (8), Air (9), Water (10), Dragon (11), Devil (12), Lightning (13), Gun (14). Confirm that the list as provided: "Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water, Dragon, Devil, Lightning, and Gun." Yes.
One more nuance: In the problem statement, the example input has "Lightning" "Gun" "Paper" "Sponge" "Water" "Dragon" "Devil" "Air". The order of reading doesn't matter.
Thus solution.
Now implementation in code: We'll write a function to check if i defeats j: (j - i + 15) % 15 in 1..7.
We'll use Python.
Pseudo:
order = ["Rock","Fire","Scissors","Snake","Human","Tree","Wolf","Sponge","Paper","Air","Water","Dragon","Devil","Lightning","Gun"]
index = {name: i for i,name in enumerate(order)}
Then for each dataset:
N = int(input())
if N==0: break
hands = [input().strip() for _ in range(N)]
distinct = set(hands)
if len(distinct) < 2:
print("Draw")
continue
winner = None
for cand in distinct:
cand_idx = index[cand]
wins_all = True
for other in distinct:
if other == cand: continue
if not defeats(cand_idx, index[other]):
wins_all = False
break
if wins_all:
winner = cand
break
if winner:
print(winner)
else:
print("Draw")
Make sure input reading stops at 0.
Now, are there any edge cases where there could be two winners? Let's think: If there are duplicates, suppose we have two distinct types A and B where both defeat each other? impossible. So only one.
But what if there are two players with the same hand that is the winner? That's fine.
Now consider scenario: There are three distinct types A, B, C such that A defeats B, A defeats C, but B defeats C and C defeats A? That would be a cycle, but if A defeats both B and C, then A is winner (since no one defeats A). In a circular tournament, it's possible for a hand to defeat all others? Let's check: For a hand to defeat all other 14, it would need that all others are within its next 7 positions. But there are 14 others, but it only defeats 7. So it cannot defeat all other hands. Wait, this is important: In this game, each hand only defeats exactly 7 of the 14 other hands. So no hand can defeat all other 14 distinct types. However, in a given subset of hands (not all 15), it is possible that a hand defeats all other types present, as we saw with Rock in a subset {Fire,Scissors,Snake,Human,Tree,Wolf,Sponge}. That's all within its next 7. So it can beat up to 7 other distinct types. So in a dataset, the winner must be a hand that defeats all other distinct types present; that is possible only if the set of other types is a subset of its defeat set. So that condition is plausible if the set is chosen appropriately, as in the example.
Thus our algorithm is correct.
One more nuance: The problem might consider that a player wins if his hand defeats at least one other hand and is not defeated by any. If there are multiple players with the same winning hand, each wins, but output the hand. That's fine.
Now verify with a small test: Suppose dataset: N=2, both "Rock". Distinct = {"Rock"}. len<2 -> Draw. Indeed no one defeats anyone else. So output Draw. That seems correct.
Suppose dataset: N=2, "Rock" and "Fire". Distinct = {Rock,Fire}. Rock defeats Fire? Yes, Rock beats Fire. So winner Rock. Output Rock.
Now, what about case where there are multiple distinct but the winner condition might be satisfied by multiple? Not possible as argued due to tournament property.
Edge case: Input might contain hand names not in the list? According to problem, only those 15 are valid. So we trust input.
Now we can code.
But before finalizing, let's double-check the direction: We assumed that each hand defeats the next 7 in the given list order. However, the phrase "located after in anti-clockwise order" suggests that if we go anti-clockwise from a hand, we find the ones it defeats. In our list, if we go forward in the list, is that anti-clockwise? We need to confirm with the figure. But the example matches. So it's consistent.
Thus we can implement.
Now, consider potential pitfalls with reading input: The input lines might have trailing spaces. Use strip().
Also, note that the input size is small.
Now we produce final answer.
We'll provide a Python solution with mapping and defeat function.
Add comment about reasoning.
Will also consider alternative approach: Precompute defeats matrix.
Now final code.
But wait: The sample output for first dataset is "Sponge". That matches.
Let's test with some more cases to ensure no off-by-one.
Check: For Sponge (7) to defeat Gun (14): diff = (14-7)%15 = 7 -> within 1-7 inclusive. Yes.
For Sponge to defeat Paper (8): diff = 1 -> yes.
For Sponge to defeat Air (9): diff=2, etc.
Now check: For Paper (8) to defeat Rock (0): diff = (0-8)%15 = 7 -> 7, so Paper defeats Rock. That's good.
For Paper to defeat Sponge? diff = (7-8)%15 = 14 -> not in 1-7, so Sponge defeats Paper. That matches.
Thus correct.
Now we can finalize.
One more: What about the hand "Scissors"? Index 2. According to classic RPS, Scissors defeats Paper? In our order, Scissors (2) vs Paper (8): diff = 6 -> yes, Scissors defeats Paper. And Paper defeats Rock, Rock defeats Scissors. So classic cycle holds. So all good.
Now let's implement.
But we need to be careful about the modulo operation: (j - i) % 15 yields a number in 0..14. If it's 0, same hand. So defeats if 1..7.
Now finalize code.
Now we think about possible performance: No issues.
Now answer.
But maybe there is a nuance: The problem says "Your task is to determine the winning hand, given multiple hands presented by the players." Could it be that we need to output the hand that wins for the specific players? If there are multiple winning players with different hands? As argued impossible. So fine.
Thus final solution.
I'll now produce final answer in code.
But the problem asks to output for each dataset the winning hand or "Draw". So we'll do that.
Now write final code.
I'll also include a main guard.
Now produce answer.
But the conversation asks: "Write a solution in python." So we provide code.
We'll also add explanation in comments.
Now final. ```python
import sys
The order given in the problem statement (anti-clockwise order)
def defeats(i: int, j: int) -> bool:
"""
Returns True if the gesture with index i defeats the gesture with index j.
i defeats j iff j is among the next 7 gestures after i in the circular order.
"""
# forward distance from i to j (mod 15)
dist = (j - i) % 15
# distance 0 means same gesture; 1..7 means i defeats j
return 1 <= dist <= 7
def solve() -> None:
data = sys.stdin.read().strip().splitlines()
it = iter(data)
out_lines = []
for line in it:
n = int(line.strip())
if n == 0:
break
hands = [next(it).strip() for _ in range(n)]
distinct = set(hands)
code
# Need at least two distinct gestures to have a possible winner
if len(distinct) < 2:
out_lines.append("Draw")
continue
winner = None
for cand in distinct:
cand_idx = INDEX[cand]
wins_all = True
for other in distinct:
if other == cand:
continue
if not defeats(cand_idx, INDEX[other]):
wins_all = False
break
if wins_all:
winner = cand
break
out_lines.append(winner if winner else "Draw")
sys.stdout.write("\n".join(out_lines))