import java.io.*;
import java.util.*;

/**
 * FindFile の出力形式でファイルのリストを受け取り、
 * 同一内容のファイルの組合せを表示します。
 * ここで使用するデータ構造は次のようになっています。
 *
 * List  同サイズのファイルのリスト
 *   = (List  同一内容のファイルのリスト
 *        = (File  1個のファイル))
 */
public class UniqueFiles {

    /**
     * FindFile の出力したファイルのリストを受け取り、
     * 同一内容のファイルの組合せを表示します。
     * @param args ファイルリスト入力のエンコーディング名
     */
    public static void main(String[] args) {
	BufferedReader reader = null;
	if (args.length > 0) {
	    try {
		reader = new BufferedReader
		    (new InputStreamReader(System.in, args[0]));
	    } catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	    }
	}
	if (reader == null) {
	    reader = new BufferedReader
		(new InputStreamReader(System.in));
	}
	uniqueFiles(reader);
    }

    /**
     * FindFile の出力したファイルのリストを受け取り、
     * 同一内容のファイルの組合せを表示します。
     * @param reader ファイルリスト入力
     */
    private static void uniqueFiles(BufferedReader reader) {
	try {
	    List list = new ArrayList();

	nextLine:
	    for (String line; (line = reader.readLine()) != null; ) {
		if (line.charAt(0) != '\t') {
		    /* 前行までの重複ファイルを表示する。*/
		    print(list);
		    /* ファイルサイズの行。次行から同サイズのファイル。*/
		    list = new ArrayList();
		} else {
		    /* ファイルの行。*/
		    File file = new File(line.substring(1));
		    for (int i = 0; i < list.size(); i++) {
			List unique = (List) list.get(i);
			File other = (File) unique.get(0);
			if (equals(file, other)) {
			    unique.add(file);
			    continue nextLine;
			}
		    }
		    /* 重複ファイルがなければ同サイズのリストに追加する。*/
		    List unique = new ArrayList();
		    unique.add(file);
		    list.add(unique);
		}
	    }
	    print(list);
	} catch (IOException e) {
	    e.printStackTrace();
	}
	try {
	    reader.close();
	} catch (IOException e) {
	    e.printStackTrace();
	}
    }

    /**
     * 同一内容のファイルの組合せを表示します。
     * @param list 同サイズのファイルのリスト
     */
    private static void print(List list) {
	for (int i = 0; i < list.size(); i++) {
	    List unique = (List) list.get(i);
	    if (unique.size() > 1) {
		System.out.println(unique + " are same.");
	    }
	}
    }

    /**
     * 2つのファイルの内容を比較します。
     */
    private static boolean equals(File file1, File file2) {
	if (file1.length() != file2.length()) {
	    //printLength(file1);
	    //printLength(file2);
	    return false;
	}

	BufferedInputStream stream1 = null;
	BufferedInputStream stream2 = null;
	try {
	    stream1 = new BufferedInputStream(new FileInputStream(file1));
	    stream2 = new BufferedInputStream(new FileInputStream(file2));
	    for (long iByte = 0; iByte < file1.length(); iByte++) {
		int input1 = stream1.read();
		int input2 = stream2.read();
		if (input1 != input2) {
		    //System.out.println("only first " + iByte + " bytes are same.");
		    return false;
		}
		if (input1 == -1) {
		    //printReadBytes(file1, iByte);
		    break;
		}
	    }
	    return true;
	} catch (IOException e) {
	    e.printStackTrace();
	    return false;
	} finally {
	    try {
		stream1.close();
	    } catch (NullPointerException e) {
	    } catch (IOException e) {
		e.printStackTrace();
	    }
	    try {
		stream2.close();
	    } catch (NullPointerException e) {
	    } catch (IOException e) {
		e.printStackTrace();
	    }
	}
    }

    /**
     * 読み込んだバイト数を表示します。
     */
    private static void printReadBytes(File file, long bytes) {
	printLength(file);
	System.out.println("but only " + bytes + " bytes can be read.");
    }

    /**
     * ファイルサイズを表示します。
     */
    private static void printLength(File file) {
	System.out.println(file + " is " + file.length() + " bytes.");
    }
}
