(Analysis by Nick Wu)

In this problem, we have a series of games where two cows have made various gestures in Hoof, Paper, Scissors. We do not know which gestures map to which items, and we would like to figure out the maximum number of games that the first cow could have won.

Instead of thinking about all the possible ways that the numbers map to the items, we can just directly establish which number wins when two different numbers are paired up. For example, one way to pair up the numbers is to have 1 beat 2, 2 beat 3, and 3 beat 1. The other way to pair up the numbers is to have 2 beat 1, 3 beat 2, and 1 beat 3.

We can count for each of these pairings how many games the first cow wins, and report the maximum.

import java.io.*;
import java.util.*;
public class hps {
public static void main(String[] args) throws IOException {
// initialize file I/O
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("hps.out")));

// read in the number of games
int n = Integer.parseInt(br.readLine());

// initialize a 2D array to store the number of each ordered pair that shows up
int[][] matches = new int;
for(int i = 0; i < n; i++) {
// read in one game
StringTokenizer st = new StringTokenizer(br.readLine());
int first = Integer.parseInt(st.nextToken());
int second = Integer.parseInt(st.nextToken());
matches[first][second]++;
}

// compute the maximum number of wins
int maximumWins = matches + matches + matches;
if(matches + matches + matches > maximumWins) {
maximumWins = matches + matches + matches;
}

// print the answer
pw.println(maximumWins);

// close the file
pw.close();
}
}