Swapnil and the Bubble Game!

3.8

12 votes
Easy-Medium
Problem

Swapnil is playing a game with his friend.This game is about the bubbles.There are many sticky bubbles
kept in a container A.Near that container,there is another container B containing plenty of chocalates.
There are two rounds in the game.The first round is about picking maximum no. of bubbles from the
container A.In this round,each will get one chocalate from container B for each bubble.In the second
round,Swapnil randomly picks some bubbles from the container A.As the bubbles are sticky they get
glued to each other.Now he asks his friend to pick some bubbles.Here the game is that if those bubbles
are sticked same as that of Swapnil then Swapnil's Friend will get 10 chocalates from container B for
each bubble.Otherwise friend has to either pick new bubble and stick it according to Swapnil or remove
any bubble or change any bubble to make it exactly same as that of Swapnil each for a cost of 5 chocalates
to Swapnil from container B.Friend has to ensure that the chocalate's loss from container B will be minimum
in this round.At the end of the game,the winner is having the max chocalates.Given the bubbles picked by
Swapnil and his friend, find how many chocalates Swapnil and his friend will have at the end of game.



Input:-
First line contains t denoting no. of test cases.
First line of each test case contains n1 and n2 denoting no. of bubbles picked by Swapnil and his friend in first round.
Next line contains n denoting no. of bubbles picked by Swapnil in second round.
Next line contains a string denoting bubbles picked by Swapnil in second round.
Next line contains m denoting no. of bubbles picked by Swapnil's Friend in second round.
Next line contains a string denoting bubbles picked by Swapnil's Friend in second round.



Output:-
For each test case output is as
First Line contains p as number of chocalates with Swapnil at the end of game.
Next Line contains q as number of chocalates with Swapnil's Friend at the end of game.
Next Line output as "Swapnil" or "Friend" who wins or "Tie".



Constraints:-
TestCases: 20pts
1<=t<=2000
1<=n<=100
1<=m<=100
1<=n1<=104
1<=n2<=104


TestCases: 30 pts
1<=t<=400
1<=n<=500
1<=m<=500
1<=n1<=105
1<=n2<=105


TestCases: 50 pts
1<=t<=100
1<=n<=1000
1<=m<=1000
1<=n1<=106
1<=n2<=106



Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first round, Swapnil picked 15 bubbles and his friend 10 bubbles.
In the second round,Swapnil has bubbles abcde but his friend has abcd
so friend will pick one bubble e and stick to those bubbles.He will give
5 chocalates to Swapnil from container B.At the end,Swapnil has 20 and
his friend has 10 chocalates so Swapnil wins the game.

Editor Image

?