using System;
using System.Collections.Generic;
static class Program {
    static void Main(String[] args) {
        List<Pair> plist = new List<Pair>();
        Random rand = new Random();
        for(int i = 0; i < 10; i++) plist.Add(new Pair(rand.Next(5), rand.Next(5)));
        Console.WriteLine("----- 元データ");
        foreach(Pair p in plist) Console.WriteLine(p);
        
        Console.WriteLine("----- 辞書順でソート");
        plist.Sort(delegate(Pair p1, Pair p2) {
            return p1.x != p2.x ? p1.x.CompareTo(p2.x) : p1.y.CompareTo(p2.y);
        });
        foreach(Pair p in plist) Console.WriteLine(p);
        
        Console.WriteLine("----- 距離順でソート");
        plist.Sort(delegate(Pair p1, Pair p2) {
            return (p1.x * p1.x + p1.y * p1.y).CompareTo(p2.x * p2.x + p2.y * p2.y);
        });
        foreach(Pair p in plist) Console.WriteLine(p);
    }
}
class Pair {
    public readonly int x, y;
    public Pair(int x, int y) {
        this.x = x; this.y = y;
    }
    public override string ToString() {
        return "(" + x + ", " + y + ")";
    }
}
