public static void main(String[] args) {
		BufferedReader cIn = new BufferedReader(new InputStreamReader(System.in));
		
		if(args.length > 0) {
			if(args[0].equals("verify")) {
				try {
					int result = verify(System.in);
					if(result == 0) {
						System.err.println("Chain is valid.");
						System.exit(0);
					} else {
						System.err.println("Chain is NOT valid (bad hash at line " + result + ").");
						System.exit(1);
					}
				} catch(IOException e) {
					System.err.println("Verification failed: I/O error.");
					System.exit(-1);
				}
			}
		}
		
		try(Chain chain = new Chain(System.out)) {
			while(true) {
				String line = cIn.readLine();
				if(line == null) break;
				chain.println(line);
				
			}
		} catch(Exception e) {
			System.err.println(e);
		}

	}