Problem:
Sorting Pairs Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria.  first by $x$-coordinate  in case of a tie, by $y$-coordinate  Input The input is given in the following format. $n$
$x_0 \; y_0$
$x_1 \; y_1$
:
$x_{n-1} \; y_{n-1}$ In the first line, the number of points $n$ is given. In the following $n$ lines, coordinates of each point are given. Output Print coordinate of given points in order. Constraints  $1 \leq n \leq 100,000$  $-1,000,000,000 \leq x_i, y_i \leq 1,000,000,000$  Sample Input 1 5
4 7
5 5
2 3
6 8
2 1 Sample Output 1 2 1
2 3
4 7
5 5
6 8

Solution (Python):
n = int(input())
points = []
for i in range(n):
    x, y = list(map(int, input().split(' ')))
    points.append([x, y])

points = sorted(points, key=lambda x: x[1])
points = sorted(points, key=lambda x: x[0])

for x, y in points:
    print(x, y)

Solution (Python):

N = int(input())

A = [list(map(int, input().split())) for i in range(N)]

A.sort()

[print(' '.join(map(str, x))) for x in A]

Solution (Python):

from collections import namedtuple


Point = namedtuple('Point', ['x', 'y'])


def sort(li):
    """Sort a list of Point(x, y) ascending order

    >>> sort([Point(x=2, y=1), Point(x=1, y=0)])
    [Point(x=1, y=0), Point(x=2, y=1)]
    >>> sort([Point(x=1, y=4), Point(x=1, y=3)])
    [Point(x=1, y=3), Point(x=1, y=4)]
    """
    li = sorted(li, key=lambda p: p.y)
    return sorted(li, key=lambda p: p.x)


def run():
    n = int(input())
    ps = []
    for _ in range(n):
        x, y = [int(i) for i in input().split()]
        ps.append(Point(x, y))

    for p in sort(ps):
        print("{} {}".format(p.x, p.y))


if __name__ == '__main__':
    run()

Solution (Python):



ps = []
n = int(input())
for i in range(n):
	x, y = map(int, input().split())
	ps.append((x, y))
a = sorted(ps, key=lambda x:(x[0], x[1]))
for i in range(n): print(*a[i])

Solution (Python):



ps = []
n = int(input())
for i in range(n):
	x, y = map(int, input().split())
	ps.append((x, y))
ps.sort()
for i in ps: print(*i)

Solution (Python):
n=int(input())
s=[]
for i in range(n):
    x,y=map(int,input().split())
    s.append((x,y))
s.sort()
for i in range(n):
    print(s[i][0],s[i][1])

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

P = [tuple(map(int, readline().split())) for i in range(N)]
P.sort()
open(1, 'w').writelines(["%d %d\n" % e for e in P])

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


resolve()

Solution (Python):
n = int(input())
A = list([0, 0] for i in range(n))
for i in range(n) :
    A[i][0], A[i][1] = map(int, input().split())
A.sort()
for i in range(n) :
    print(A[i][0], A[i][1])

Solution (Python):

from sys import stdin

n = int(stdin.readline())
l = []
for i in range(n):
    a,b = map(int,stdin.readline().split())
    l.append([a,b])

l.sort()

for i in range(n):
    print(f'{l[i][0]} {l[i][1]}')

Solution (Python):
a = []
for i in range(int(input())):
    a.append(list(map(int,input().split())))
a.sort()
for i,j in a:
    print(i,j)

Solution (Python):
n = int(input())
points = []
for i in range(n):
    points.append(list(map(int, input().split())))
points.sort()
for i in range(n):
    print(*points[i])

Solution (Python):
ps = []
n = int(input())
for i in range(n):
    x,y = map(int,input().split())
    ps.append((x,y))
ps.sort()
for i in ps:
    print(*i)

Solution (Python):
n = int(input())
l = []
for i in range(n):
    l.append(list(map(int, input().split())))
l.sort()
for i in range(n):
    print(*l[i])

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


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
P = [tuple(map(int,input().split())) for _ in range(N)]

P.sort()

for p in P:
    print(*p)

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

L = []
for i in range(n):
    L.append(list(map(int, input().split())))

L = sorted(L)

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

Solution (Python):
n = int(input())
v = []
[v.append(list(map(int, input().split()))) for _ in range(n)]
[print(" ".join(map(str,a))) for a in sorted(v)]

Solution (Python):
class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y

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

    for _ in range(n):
        x, y = map(int, input().split())
        p = Point(x, y)
        Points.append(p)

    Points.sort(key=lambda x : x.y)
    Points.sort(key=lambda x : x.x)

    for p in Points:
        print(str(p.x) + " " + str(p.y))

main()

Solution (Python):
b = int(input())
a = sorted([list(map(int,input().split())) for i in range(b)])
for c in a:
    print(c[0],c[1])

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

pairs=[]

for _ in range(n):
    xy=[int(i) for i in input().split(" ")]
    pairs.append(xy)

pairs=sorted(pairs)

for p in pairs:
    print(p[0],p[1])

Solution (Python):
n = int(input())
a = []
for _ in range(n):
    
    x = tuple(map(int,input().split()))
    a.append(x)

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

Solution (Python):
pairs=[]
n=int(input())
for i in range(n):
	x,y=map(int, input().split())
	pairs.append((x,y))
pairs.sort()

for i in pairs:
    print(*i)

Solution (Python):
def solve():
    from sys import stdin
    f_i = stdin
    
    n = int(f_i.readline())
    
    c = []
    for i in range(n):
        c.append(tuple(map(int, f_i.readline().split())))
    
    c.sort()
    
    ans = (' '.join(map(str, c_i)) for c_i in c)
    print('\n'.join(ans))
    
    
solve()

Solution (Python):
class Pairs:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __lt__(self, other):
        if self.x < other.x:
            return True
        elif self.x == other.x:
            return self.y < other.y
        else:
            return False

    def __str__(self):
        return "{} {}".format(self.x, self.y)


n = int(input())
L = []
for i in range(n):
    x, y = [int(x) for x in input().split() ]
    L.append(Pairs(x,y))
L.sort()

for i in L:
    print(i)

Solution (Python):
from typing import List, Tuple


if __name__ == "__main__":
    n = int(input())
    coordinates: List[Tuple[int, int]] = []

    for _ in range(n):
        (x, y) = tuple(map(lambda x: int(x), input().split()))
        coordinates.append((x, y))

    coordinates = sorted(coordinates, key=lambda x: (x[0], x[1]))

    for elem in coordinates:
        print(f"{elem[0]} {elem[1]}")

Solution (Python):

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

Solution (Python):
ps = []
n = int(input())
for i in range(n):
	x, y = map(int, input().split())
	ps.append((x, y))
ps.sort()
for i in ps: print(*i)

Solution (Python):

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

"""
n = int(input())
for p in sorted([[int(a) for a in input().split()] for _ in range(n)]):
    print(*p)

Solution (Python):
ps = []
n = int(input())
for i in range(n):
    x, y = map(int, input().split())
    ps.append((x, y))
ps.sort()
for i in ps: print(*i)

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])))

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

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

list_2d = [list(map(int, input().split())) for _ in range(n)]


list_2d.sort()

for list_xy in list_2d:
    print(*list_xy)

Solution (Python):
n = int(input())
ans = []
for i in range(n):
    x, y = map(int, input().split())
    ans += [(x,y)]
    
ans.sort()
for a in ans:
    print(*a)

Solution (Python):
n = int(input())
a = []
for i in range(n):
    x, y = map(int, input().split())
    a.append((x, y))
a.sort()
for i in a: print(*i)

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

for i in range(n):
    x=list(map(int,input().split()))
    A.append(x)

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

Solution (Python):


n = int(input())
P = []

for i in range(n):
    x, y = (int(x) for x in input().split())
    P.append((x, y))

P.sort(key=lambda p: (p[0], p[1]))

for p in P:
    print(p[0], p[1])

Solution (Python):



import sys
input = sys.stdin.readline

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

Solution (Python):
import sys
n = int(input())
pts = [None] * n
for i, line in enumerate(sys.stdin.readlines()):
    x, y = map(int, line.split())
    pts[i] = (x, y)
pts.sort(key=lambda x: (x[0], x[1]))
print('\n'.join(map(lambda x: f'{x[0]} {x[1]}', pts)))

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

for i in range(n):
    x, y = map(int, input().split())
    mat.append([x, y])

ans = sorted(mat, key=lambda x: (x[0], x[1]))

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

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

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

for i in range(n):
    l = list(map(int, input().split()))
    li.append(l)

li = sorted(li)

for i in li:
    print(" ".join(map(str, i)))

Solution (Python):
coordinates = [list(map(int, input().split())) for _ in [0]*int(input())]
for c in sorted(coordinates): print(*c)

Solution (Python):
n = int(input())
A = []
for i in range(n):
    A.append(list(map(int, input().split())))
A = sorted(A, key = lambda x: (x[0],x[1]))
for i in range(n):
    print(str(A[i][0]) + " " + str(A[i][1]))

Solution (Python):
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
xy.sort(key=lambda x:x[1])
xy.sort(key=lambda x:x[0])
for ele in xy:
  print(ele[0], ele[1])