Problem:
Sorting Tuples

Write a program which reads $n$ items and sorts them. Each item has attributes $\{value, weight, type, date, name\}$ and they are represented by $\{$ integer, integer, upper-case letter, integer, string $\}$ respectively. Sort the items based on the following priorities.

first by value (ascending)

in case of a tie, by weight (ascending)

in case of a tie, by type (ascending in lexicographic order)

in case of a tie, by date (ascending)

in case of a tie, by name (ascending in lexicographic order)

Input

The input is given in the following format.

$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$

In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.

Output

Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.

Constraints

$1 \leq n \leq 100,000$

$0 \leq v_i \leq 1,000,000,000$

$0 \leq w_i \leq 1,000,000,000$

$t_i$ is a upper-case letter

$0 \leq d_i \leq 2,000,000,000,000$

$1 \leq $ size of $s_i \leq 20$

$s_i \ne s_j$ if $(i \ne j)$

Sample Input 1

5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree

Sample Output 1

100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black

Solution in JAVA (judge verdict: Accepted)

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;


public class Main {
//	入力値
	static Scanner scInputData = new Scanner(System.in);
//	配列
	static ArrayList<Product> arrProduct= new ArrayList<Product>();
	
	public static void main(String[] args) {
		
//		必要なパラメータを用意する処理
//		品物情報を取得する処理
		getProduct();
//		品物を所定の順でソートする処理
		compareProduct();
//		結果を出力する処理
		putResult();
	}
	
	private static void putResult() {
		for(Product pdt : arrProduct) {
			System.out.println(pdt.getPrice() + " " 
					+ pdt.getWeight() + " " 
					+ pdt.getPattern() + " " 
					+ pdt.getDate() + " " 
					+ pdt.getName());
		}
	}
	
	private static void compareProduct() {

		Collections.sort(arrProduct, new Comparator<Product> () {//価格でソート
			public int compare(Product pdt1, Product pdt2) {
				return Integer.compare(pdt1.getPrice(), pdt2.getPrice());
			}
		}.thenComparing(new Comparator<Product>() { //価格が同じ場合、重さでソート 
			public int compare(Product pdt1, Product pdt2) {
				return Integer.compare(pdt1.getWeight(), pdt2.getWeight());
			}
		}).thenComparing(new Comparator<Product>() { //重さが同じ場合、型でソート 
			public int compare(Product pdt1, Product pdt2) {
				return pdt1.getPattern().compareTo(pdt2.getPattern());
			}
		}).thenComparing(new Comparator<Product>() { //型が同じ場合、日時でソート 
			public int compare(Product pdt1, Product pdt2) {
				return Long.compare(pdt1.getDate(), pdt2.getDate());
			}
		}).thenComparing(new Comparator<Product>() { //日時が同じ場合、名前でソート 
			public int compare(Product pdt1, Product pdt2) {
				return pdt1.getName().compareTo(pdt2.getName());
			}
		}));
	}
	private static void getProduct() {
//		 品物の数
		int iProductNum = scInputData.nextInt();
		while(arrProduct.size() < iProductNum) {
			Product pdt = new Product(scInputData.nextInt(), 
					scInputData.nextInt(), 
					scInputData.next(), 
					scInputData.nextLong(), 
					scInputData.next());
			arrProduct.add(pdt);
		}
	}
//	品物情報を扱うクラス
	static class Product{
		int price, weight;
		long date;
		String pattern, name;
		public Product(int price, int weight, String pattern, long date, String name) {
			this.price = price;
			this.weight = weight;
			this.pattern = pattern;
			this.date = date;
			this.name = name;
		}
		int getPrice() {
			return price;
		}
		int getWeight() {
			return weight;
		}
		String getPattern() {
			return pattern;
		}
		long getDate() {
			return date;
		}
		String getName() {
			return name;
		}
	}
}