public void solve() throws IOException {
    String nextline;
    while ((nextline = nextLine()) != null && nextline.length() > 0) {
      int input = Integer.parseInt(nextline);
      Set<Integer> seen = new HashSet<Integer>();
      seen.add(input);
      boolean happy = true;
      int count = 0;
      while (input != 1) {
        count++;
        input = transform(input);
        if (seen.contains(input)) {
          happy = false;
          break;
        }
        seen.add(input);
      }
      System.out.format("%s %d%n", happy ? "happy" : "unhappy", count);
    }
  }