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 (Python):
n = int(input())
items = []
for i in range(n):
    val, weight, type, date, name = input().split(' ')
    items.append([int(val), int(weight), type, int(date), name])

items = sorted(items)
for item in items:
    print(' '.join(list(map(str, item))))

Solution (Python):


N = int(input())
goods = []
for i in range(N):
    a, b, c, d, e = input().split()
    goods.append((int(a), int(b), c, int(d), e))
goods.sort()
[print(' '.join(map(str, x))) for x in goods]

Solution (Python):

from heapq import heapify, heappop


def sort(xs):
    heapify(xs)
    return [heappop(xs) for _ in range(len(xs))]


def run():
    n = int(input())
    elements = []
    for _ in range(n):
        v, w, t, d, s = input().split()
        elements.append((int(v), int(w), t, int(d), s))

    for e in sort(elements):
        print("{} {} {} {} {}".format(*e))


if __name__ == '__main__':
    run()

Solution (Python):



tbl = []
n = int(input())
for i in range(n):
	a = input().split()
	tbl.append((int(a[0]), int(a[1]), a[2], int(a[3]), a[4]))
tbl.sort()
for i in tbl: print(*i)

Solution (Python):
n=int(input())
lis=[]
for i in range(n):
    v,w,t,d,s=input().split()
    vv=int(v)
    ww=int(w)
    dd=int(d)
    lis.append((vv,ww,t,dd,s))
lis.sort()
for i in lis:
    print(*i)

Solution (Python):
readline = open(0).readline

N = int(readline())
P = [readline().split() for i in range(N)]

P = [(int(v), int(w), t, int(d), s) for v, w, t, d, s in P]
P.sort()

open(1, 'w').writelines(["%d %d %s %d %s\n" % e for e in P])

Solution (Python):
def resolve():
    n = int(input())
    xxyy = [list(map(str, input().split())) for _ in range(n)]
    xxyy = sorted(xxyy, key=lambda x: (int(x[0]), int(x[1]), x[2], int(x[3]), x[4]))
    for xy in xxyy:
        print(*xy)


resolve()

Solution (Python):
tmp = []
n = int(input())
for i in range(n):
    a,b,c,d,e = input().split()
    tmp.append([int(a),int(b),c,int(d),e])
tmp.sort()
for i in range(n):
    print(*tmp[i])

Solution (Python):
n = int(input())
arr = []
for i in range(n):
    s = input().split()
    arr.append([int(s[0]), int(s[1]), s[2], int(s[3]), s[4]])
arr.sort()
for i in range(n):
    print(*arr[i])

Solution (Python):
tbl = []
n = int(input())
for i in range(n):
    a = input().split()
    tbl.append((int(a[0]),int(a[1]),a[2],int(a[3]),a[4]))
tbl.sort()
for i in tbl: print(*i)

Solution (Python):
n = int(input())
l = []
for i in range(n):
    a = input().split()
    l.append((int(a[0]), int(a[1]), a[2], int(a[3]), a[4]))
l.sort()
for i in l:
    print(*i)

Solution (Python):
def main():
    n = int(input())
    A = []
    for _ in range(n):
        a,b,c,d,e = input().split()
        A.append([int(a),int(b),c,int(d),e])
    A.sort()
    for a,b,c,d,e in A:print(a,b,c,d,e)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
I = [input().split() for _ in range(N)]

for i in range(N):
    I[i][0] = int(I[i][0])
    I[i][1] = int(I[i][1])
    I[i][3] = int(I[i][3])

I.sort()

for i in I:
    print(*i)

Solution (Python):
n = int(input())

L = []
for i in range(n):
    v, w, t, d, s = input().split()
    L.append([int(v), int(w), t, int(d), s])

L = sorted(L)

[print(*L[i]) for i in range(len(L))]

Solution (Python):
n = int(input())
v = []
[v.append((lambda a:[int(a[0]), int(a[1]), a[2], int(a[3]), a[4]])(input().split())) for _ in range(n)]
[print(" ".join(map(str,a))) for a in sorted(v)]

Solution (Python):
class Tuple():
    def __init__(self, v, w, t, d, s):
        self.v = v
        self.w = w
        self.t = t
        self.d = d
        self.s = s

def main():
    n = int(input())
    Tuples = list()

    for _ in range(n):
        v, w, t, d, s = input().split()
        p = Tuple(int(v), int(w), t, int(d), s)
        Tuples.append(p)

    Tuples.sort(key=lambda x : x.s)
    Tuples.sort(key=lambda x : x.d)
    Tuples.sort(key=lambda x : x.t)
    Tuples.sort(key=lambda x : x.w)
    Tuples.sort(key=lambda x : x.v)

    for t in Tuples:
        print(str(t.v) + " " + str(t.w) + " " + t.t + " " + str(t.d) + " " + t.s )
        
main()

Solution (Python):
n=int(input())

tuples=[]

for _ in range(n):
    obj=input().split(" ")
    obj[0]=int(obj[0])
    obj[1]=int(obj[1])
    obj[3]=int(obj[3])
    tuples.append(obj)

tuples=sorted(tuples)

for t in tuples:
    print(t[0],t[1],t[2],t[3],t[4])

Solution (Python):
n = int(input())
a = []
for _ in range(n):
    (v, w, t, d, s) = tuple(input().split())
    a.append((int(v), int(w), t, int(d), s))

a.sort()
for i in a:
    print(*i)

Solution (Python):
tuples=[]
n=int(input())
for i in range(n):
	v,w,t,d,s=input().split()
	tuples.append((int(v),int(w),t,int(d),s))
tuples.sort()

for x in tuples:
    print(*x)

Solution (Python):
def solve():
    from sys import stdin
    f_i = stdin
    
    n = int(f_i.readline())
    
    items = (f_i.readline().split() for i in range(n))
    items = [(int(v), int(w), t, int(d), n) for v, w, t, d, n in items]
    items.sort()
    items = (' '.join(map(str, i)) for i in items)
    
    print('\n'.join(items))

solve()

Solution (Python):
class Items:
    def __init__(self, v, w, t, d, s):
        self.value = v
        self.weight = w
        self.type = t
        self.date = d
        self.name  = s


    def __lt__(self, other):
        if self.value < other.value:
            return True
        elif self.value == other.value:
            if self.weight < other.weight:
                return True
            elif self.weight == other.weight:
                if self.type < other.type:
                    return True
                elif self.type == other.type:
                    if self.date < other.date:
                        return True
                    elif self.date == other.date:
                        if self.name < other.name:
                            return True
                        else:
                            return False
                    else:
                        return False

                else:
                    return False
            else:
                return False
        else:
            return False

    def __str__(self):
        return "{} {} {} {} {}".format(self.value, self.weight, self.type, self.date, self.name)



num = int(input())

L = []

for _ in range(num):
    v, w, t, d, s = input().split()
    L.append(Items(int(v), int(w), t, int(d), s))

L.sort()


for i in L:
    print(i)

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    items = []  

    for _ in range(n):
        v, w, t, d, s = input().split()
        v, w, d = map(lambda x: int(x), [v, w, d])  
        items.append((v, w, t, d, s))

    items = sorted(items, key=lambda x: (x[0], x[1], x[2], x[3], x[4]))

    for elem in items:
        print(f"{elem[0]} {elem[1]} {elem[2]} {elem[3]} {elem[4]}")

Solution (Python):


n = int(input())
P = []
for _ in range(n):
    p = list(map(str, input().split( )))
    P.append(p)
for _ in range(n):
    for i in range(2):
        P[_][i] = int(P[_][i])
    P[_][3] = int(P[_][3])
P.sort()
P.sort()
for _ in range(n):
    print(*P[_])

Solution (Python):
tbl = []
n = int(input())
for i in range(n):
	a = input().split()
	tbl.append((int(a[0]), int(a[1]), a[2], int(a[3]), a[4]))
tbl.sort()
for i in tbl: print(*i)

Solution (Python):

"""
Permutation - Sorting Tuples
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_5_B&lang=jp

"""
n = int(input())
ans = []
for _ in range(n):
    v, w, t, d, s = input().split()
    ans.append((int(v), int(w), t, int(d), s))

for a in sorted(ans):
    print(*a)

Solution (Python):
import sys
if __name__ == '__main__':

	n = int(input())

	A = [sys.stdin.readline().split() for _ in range(n)]

	B = sorted(A,key=lambda x:(int(x[0]),int(x[1]),x[2],int(x[3]),x[4]))

	for i in range(n):
		print(*B[i])

Solution (Python):
n = int(input())

list_items = []

for _ in range(n):

    v, w, t, d, s = input().split()

    list_items.append([int(v), int(w), t, int(d), s])



for item in sorted(list_items):
    print(*item)

Solution (Python):
n = int(input())
ans = []
for i in range(n):
    a, b, c, d,e = input().split()
    ans += [(int(a), int(b), c, int(d),e )]
    
ans.sort()
for a in ans:
    print(*a)

Solution (Python):
n = int(input())
tbl = []
for i in range(n):
    a = input().split()
    tbl.append((int(a[0]), int(a[1]), a[2], int(a[3]), a[4]))
tbl.sort()
for i in tbl:
    print(*i)

Solution (Python):
n=int(input())
A=[]

for i in range(n):
    X=list(map(str,input().split()))
    X[0]=int(X[0])
    X[1]=int(X[1])
    X[3]=int(X[3])
    A.append(X)

A=sorted(A)
for i in range(n):
    print(str(A[i][0])+" "+str(A[i][1])+" "+A[i][2]+" "+str(A[i][3])+" "+A[i][4])

Solution (Python):
n = int(input())
T = []

for i in range(n):
    t = [x for x in input().split()]
    t[0] = int(t[0])
    t[1] = int(t[1])
    t[3] = int(t[3])
    T.append(t)

T.sort()

for t in T:
    print(' '.join(str(x) for x in t))

Solution (Python):




import sys
input = sys.stdin.readline

def main():
    l = []
    for i in range(int(input())):
        (a,b,c,d,e) = map(str,input().split())
        l.append((int(a),int(b),c,int(d),e))
    for a,b,c,d,e in sorted(l):
        print (a,b,c,d,e)
if __name__ == '__main__':
    main()

Solution (Python):
import sys
n = int(input())
goods = [None] * n
for i, line in enumerate(sys.stdin.readlines()):
    value, weight, serial, date, name = line.split()
    goods[i] = (int(value), int(weight), serial, int(date), name)

goods.sort() 
print('\n'.join(map(lambda x: " ".join(map(str, x)), goods)))

Solution (Python):
n = int(input())
mat = []

for i in range(n):
    v, w, t, d, s = map(str, input().split())
    mat.append([int(v), int(w), t, int(d), s])

mat.sort()

for i in range(n):
    print(' '.join(str(m) for m in mat[i]))

Solution (Python):
readline = open(0).readline
N = int(readline())
P = [readline().split() for i in range(N)]
P = [(int(v), int(w), t, int(d), s) for v, w, t, d, s in P]
P.sort()
open(1, 'w').writelines(["%d %d %s %d %s\n" % e for e in P])

Solution (Python):
for item in sorted([[int(a[0]), int(a[1]), a[2], int(a[3]), a[4]] for a in [input().split() for _ in [0]*int(input())]]): print(*item)

Solution (Python):
A = []
n = int(input())
for i in range(n):
    a,b,c,d,e = input().split()
    A.append([int(a),int(b),c,int(d),e])
A = list(sorted(A, key=lambda x: (x[0],x[1],x[2],x[3],x[4])))
for i in range(n):
    for j in range(4):
        print(str(A[i][j])+" ", end="")
    print(A[i][4])

Solution (Python):
n = int(input())
a = [input().split() for i in range(n)]

for i in range(4, -1, -1):
  if i==4 or i==2:
    a.sort(key=lambda x:x[i])
  else:
    a.sort(key=lambda x:int(x[i]))
for ele in a:
  print(" ".join(map(str, ele)))