/************************************************
Grundlegende Algorithmen mit Java,
http://algorithmen-und-problemloesungen.de/
Copyright @2007-2009 by Doina Logofatu
************************************************/

import java.io.*;
import java.util.*;

public class P14StocksFluctuation {
  private static final String FileInputName = "arbitrage.in";
  private static final String FileOutputName = "arbitrage.out";

  private static void recoverPath(PrintStream out, int pred[][], int i, int j) {
    int t = pred[i][j];
    if (i != t) {
      recoverPath(out, pred, i, t);
      out.print(" -> ");
      out.print(t + 1);
    }
  }

  static boolean find(PrintStream out, int n, float table[][], int pred[][]) {
    int i, j, k;
    for (k = 0; k < n; k++)
      for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
          if (table[i][k] * table[k][j] > table[i][j]) {
            pred[i][j] = pred[k][j];
            table[i][j] = table[i][k] * table[k][j];
            if (i == j && table[i][j] >= 1.01) {
              out.print(" Waehrung ");
              out.println(i + 1);
              out.print(' ');
              out.print(i + 1);
              recoverPath(out, pred, i, i);
              out.print(" -> ");
              out.println(i + 1);
              out.printf(Locale.ENGLISH, " %.3f%n", table[i][i]);
              ;
              return true;
            }
          }
    return false;
  }

  public static void main(String[] args) throws IOException {
    Scanner scanner = null;
    PrintStream out = null;
    try {
      scanner = new Scanner(new File(FileInputName)).useLocale(Locale.ENGLISH);
      out = new PrintStream(new File(FileOutputName));

      int numCase = 0;

      while (scanner.hasNextInt()) {
        int n = scanner.nextInt();
        float table[][] = new float[n][n];
        int pred[][] = new int[n][n];
        for (int i = 0; i < n; i++) {
          table[i][i] = 1.0f;
          for (int j = 0; j < n; j++)
            if (i != j) {
              table[i][j] = scanner.nextFloat();
              pred[i][j] = i;
            }
          pred[i][i] = -1;
        }
        out.printf("Fall %d: %n", ++numCase);
        if (!find(out, n, table, pred))
          out.println(" Es gibt keine Loesung!");
      }

    } finally {
      if (scanner != null) {
        scanner.close();
      }
      if (out != null) {
        out.close();
      }
    }
  }
}

