using System.Collections.Generic;
public static void Main()
var hands = input.Split('\n')
.Select(line => line.Split(' '))
.Select(parts => new { Hand = parts[0], Bid = int.Parse(parts[1]) })
var handStrengths = new Dictionary<char, int>();
handStrengths.Add('2', 1);
handStrengths.Add('3', 2);
handStrengths.Add('4', 3);
handStrengths.Add('5', 4);
handStrengths.Add('6', 5);
handStrengths.Add('7', 6);
handStrengths.Add('8', 7);
handStrengths.Add('9', 8);
handStrengths.Add('T', 9);
handStrengths.Add('J', 10);
handStrengths.Add('Q', 11);
handStrengths.Add('K', 12);
handStrengths.Add('A', 13);
var handTypes = new Dictionary<string, int>();
handTypes.Add("High card", 1);
handTypes.Add("One pair", 2);
handTypes.Add("Two pair", 3);
handTypes.Add("Three of a kind", 4);
handTypes.Add("Full house", 5);
handTypes.Add("Four of a kind", 6);
handTypes.Add("Five of a kind", 7);
.OrderBy(hand => handTypes[GetHandType(hand.Hand)])
.ThenBy(hand => GetHandValueAtCardPosition(hand.Hand, handStrengths, 0))
.ThenBy(hand => GetHandValueAtCardPosition(hand.Hand, handStrengths, 1))
.ThenBy(hand => GetHandValueAtCardPosition(hand.Hand, handStrengths, 2))
.ThenBy(hand => GetHandValueAtCardPosition(hand.Hand, handStrengths, 3))
.ThenBy(hand => GetHandValueAtCardPosition(hand.Hand, handStrengths, 4))
Console.WriteLine("Sorted Hands");
for (var i = 0; i < sortedHands.Count; i++)
Console.WriteLine(sortedHands[i].Hand + " - " + sortedHands[i].Bid + " - " + GetHandType(sortedHands[i].Hand));
totalWinnings += sortedHands[i].Bid * (i + 1);
Console.WriteLine("Total winnings: " + totalWinnings);
static string GetHandType(string hand)
var groupedCards = hand.GroupBy(c => c).OrderByDescending(group => group.Count()).ToList();
switch (groupedCards[0].Count())
case 5: return "Five of a kind";
case 4: return "Four of a kind";
case 3: return groupedCards[1].Count() == 2 ? "Full house" : "Three of a kind";
case 2: return groupedCards[1].Count() == 2 ? "Two pair" : "One pair";
default: return "High card";
static int GetHandValueAtCardPosition(string hand, Dictionary<char, int> handStrengths, int cardPosition)
return handStrengths[hand[cardPosition]];