We need to write a program that reads three lines: gestures of Uncle Fyodor, Matroskin, and Sharic, respectively. Each gesture is one of "rock", "paper", "scissors". The winner is determined: If someone shows a gesture that wins over the other two players (i.e., beats both of the others), then that player wins. If there is no such player (either because all three are same, or two are same and third loses? Actually need to examine cases), then it's a tie, and we output "?". The problem says: "If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required." So we output the winner's initial letter: F for Uncle Fyodor, M for Matroskin, S for Sharic. If no unique winner, print "?".
We need to consider the winning relationships: rock beats scissors, scissors beats paper, paper beats rock. So for a player to win, his gesture must beat the gestures of both other players. Note that it's possible that two players have same gesture, and the third has a different one. For example: F: paper, M: rock, S: rock. Paper beats rock, so F beats both M and S, so F wins. That matches example 2. Example 1: all rock -> no one beats both others because rock ties rock, so no winner -> "?".
Example 3: scissors, rock, rock. Scissors loses to rock, so scissors does not beat rock. So F loses. M and S both have rock; rock beats scissors? Actually rock beats scissors, but rock ties rock. So for M: rock beats F's scissors? Yes, but against S: rock ties rock. So does rock beat rock? No. So M does not beat both (since rock does not beat rock). Similarly S does not beat both. So no winner -> "?". That matches.
Example 4: scissors, paper, rock. Let's analyze: F: scissors beats paper (M) but loses to rock (S). So not both. M: paper beats rock (S) but loses to scissors (F). So not both. S: rock beats scissors (F) but loses to paper (M). So no one beats both, so "?".
Thus our logic: for each player, check if his gesture beats the other two. If exactly one does, output his initial. If none, output "?". But could there be more than one? Since if two players have same gesture that beats the third, then each would beat the third but not the other (since same gesture ties). So they wouldn't beat both. If all three same, none beats both. If two are same and that gesture loses to the third? For example: F: rock, M: paper, S: paper. Then M and S have paper, which beats rock? Paper beats rock, yes. So M beats F (since paper beats rock), but M vs S is tie (paper ties paper). So M does not beat both. Similarly S does not beat both. F: rock loses to paper, so not beating. So no winner. If two have rock and third has scissors, then rock beats scissors, but rock ties rock, so no one beats both. So unique winner only possible when the three gestures are all different? Let's consider: three different gestures: rock, paper, scissors. In that case, each gesture beats one and loses to another, so no one beats both. So no winner. So unique winner only possible when two players have the same gesture and the third has a gesture that is beaten by that same gesture? Actually we need to examine: For a player to beat both others, his gesture must be superior to the other two gestures. The other two gestures could be the same or different. For him to beat both, his gesture must be such that it beats each of the other gestures. Since there are only three possible gestures, and the winning relationship is a cycle, a gesture can beat only one other gesture. For example, rock beats scissors only, not paper. So in order for a gesture to beat two different gestures, those two gestures must both be the one that it beats (i.e., both must be the same losing gesture). Because rock can beat scissors, but cannot beat paper. So the only way rock beats both others is if both others are scissors. Similarly, paper beats both others only if both others are rock. Scissors beats both others only if both others are paper. So unique winner occurs exactly when two players have the same gesture, and the third player has the gesture that is beaten by that same gesture? Wait careful: Suppose winner is F with gesture G. For F to win, G must beat the gestures of M and S. So both M and S must have the gesture that is beaten by G. Since each G beats exactly one specific gesture. That means M and S must both have that specific losing gesture. So the condition: (F gesture = rock and M,S both = scissors) OR (F gesture = paper and M,S both = rock) OR (F gesture = scissors and M,S both = paper). However note that M and S could be in any order. Also could M and S both have the same losing gesture? Yes.
But what if M and S have the losing gesture but are not both the same? Actually they must be the same because the only gesture that G beats is a single type; so they both must be that type, thus they are same. So condition is: two players have the same gesture L, and the third player has a gesture that beats L. But careful: If third player has gesture that beats L, then third beats both? Wait: if third player has gesture G that beats L, then yes G beats both if both others have L. So winner is the one with G. So the condition can be described as: There is a gesture X such that exactly one player shows X, and the other two show the same gesture Y, where X beats Y. In that case, the player with X wins. That's the only scenario for a winner. In all other cases: either all three same, or all three different (the cycle), or two same but the third loses to that same gesture? Actually if two same and third beats that same? For example two rock, third paper: paper beats rock, so paper beats both? But paper only beats rock, and both others are rock, so yes paper beats both? Wait: paper beats rock, so if two others are rock, then paper beats both? Because rock is beaten by paper. So paper beats rock, so it beats both rocks. So in that case paper would win. But earlier we had example: paper, rock, rock -> output F. That matches: F paper, others rock -> paper beats rock, so F wins. So condition: Exactly one player shows a gesture that beats the gesture shown by the other two (who must show the same gesture, the one that is beaten). But is it possible that the two others show different gestures? Then the one cannot beat both, because his gesture beats only one of them, not the other. So that's impossible. So unique winner occurs when the three gestures are such that two are identical and the third is the one that beats that gesture. Conversely, if two are identical and the third is the one that loses to that gesture (e.g., two rock, third scissors), then the two with rock do not beat both because they tie each other. And the scissors loses to rock, so no winner. So indeed the only winning scenario is when there is a gesture X (winner's) that beats Y, and the other two have Y.
Thus algorithm: Read three strings: f, m, s. Determine who wins: Check if f beats both m and s. That is: (f == "rock" and m == "scissors" and s == "scissors") or (f == "paper" and m == "rock" and s == "rock") or (f == "scissors" and m == "paper" and s == "paper"). Similarly for m: check if m beats both f and s. Similarly for s. If exactly one of these conditions true, output corresponding letter. If none true, output "?". Actually if more than one could be true? Could it happen that two players both satisfy beating both others? Let's analyze: Suppose f beats m and s, then m and s are both the losing gesture. For m also to beat both, m's gesture would need to beat f and s. But if m's gesture is the losing gesture (say scissors) then it cannot beat f's gesture (rock). So impossible. If f beats both, then m and s are the same losing type; they cannot beat f because they lose. So only one can be true. So we can just check each player.
Edge cases: Input may have leading/trailing spaces? Probably not, but we can strip. We'll assume exact lower-case "rock","paper","scissors".
Thus simple solution.
Implementation: In Python, read three lines, strip newline. Define a function beats(a,b): returns True if a beats b: a=="rock" and b=="scissors", a=="scissors" and b=="paper", a=="paper" and b=="rock". Then for each player, check beats(player, other1) and beats(player, other2). If true, set winner. At the end, if winner determined, output letter; else "?".
But careful: If two players have same gesture and third has the gesture that beats them, then winner condition is satisfied for that third player only. So our logic works.
Double-check: Input: "rock\nscissors\nscissors". Then f beats m? rock beats scissors yes. beats s? yes. So f wins. Output "F". That's correct.
Input: "scissors\npaper\npaper". f beats both? scissors beats paper yes. So F wins. Output "F". Works.
Input: "paper\nrock\nrock". f wins.
Input: "rock\npaper\npaper"? rock loses to paper, so f does not beat both. m: paper beats rock? yes, but paper beats rock? Paper beats rock, but paper does not beat paper. So fails. s same. So no winner.
Input: "rock\nrock\nscissors"? f: rock beats rock? no -> fails. m: same as f -> fails. s: scissors beats? scissors beats paper, but not rock. So fails -> "?".
Input: "rock\nscissors\npaper"? f: rock beats scissors? yes, but rock beats paper? no -> fails. m: scissors beats paper? yes, but scissors beats rock? no -> fails. s: paper beats rock? yes, but paper beats scissors? no -> fails. "?".
Thus done.
Now we need to produce final answer: a Python program.
Also note: The problem likely expects reading from stdin and printing output.
Let's produce solution.
But as ChatGPT, we need to output the program. Usually we produce a code block.
Edge: Might be multiple test cases? No, seems single case.
Thus final.
We should also consider using a dictionary mapping gestures to their winning over, but simple if statements.
Implementation:
def beats(a,b):
return (a == 'rock' and b == 'scissors') or (a == 'scissors' and b == 'paper') or (a == 'paper' and b == 'rock')
def main():
import sys
lines = [line.strip() for line in sys.stdin.readlines()]
if len(lines) < 3:
return
f, m, s = lines[0], lines[1], lines[2]
winner = None
if beats(f, m) and beats(f, s):
winner = 'F'
elif beats(m, f) and beats(m, s):
winner = 'M'
elif beats(s, f) and beats(s, m):
winner = 'S'
else:
winner = '?'
print(winner)
if name == 'main':
main()
That's it.
But we should also account for possible extra whitespace. Use strip.
Thus final answer.
Since we are to "write a program that will determine the winner", we can present this code.
Now, are there any tricky points? Not really. But we might also consider that the input might have multiple test cases? The problem statement doesn't mention multiple test cases, so just one.
So I'll output the Python code.
But also note: The problem might be from some contest with language restrictions. But we can choose Python.
Alternatively, we could use C++, but Python is fine.
Thus final. ```python
import sys
def beats(a: str, b: str) -> bool:
"""Return True if gesture a beats gesture b."""
return (a == "rock" and b == "scissors") or
(a == "scissors" and b == "paper") or
(a == "paper" and b == "rock")
def main() -> None:
lines = [line.strip() for line in sys.stdin.readlines()]
if len(lines) < 3:
return
f, m, s = lines[0], lines[1], lines[2]
winner = None
if beats(f, m) and beats(f, s):
winner = "F"
elif beats(m, f) and beats(m, s):
winner = "M"
elif beats(s, f) and beats(s, m):
winner = "S"
else:
winner = "?"
print(winner)
if name == "main":
main()