using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("4");
WillReturn.Add("1 4");
WillReturn.Add("2 3");
WillReturn.Add("3 1");
WillReturn.Add("4 2");
}
else if (InputPattern == "Input2") {
WillReturn.Add("7");
WillReturn.Add("6 4");
WillReturn.Add("4 3");
WillReturn.Add("3 5");
WillReturn.Add("7 1");
WillReturn.Add("2 7");
WillReturn.Add("5 2");
WillReturn.Add("1 6");
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
struct XYInfoDef
{
internal long No;
internal long X;
internal long Y;
}
static void Main()
{
List<string> InputList = GetInputList();
long[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => long.Parse(pX)).ToArray();
var XYInfoList = new List<XYInfoDef>();
for (long I = 1; I <= InputList.Count - 1; I++) {
SplitAct(InputList[(int)I]);
XYInfoDef WillAdd;
WillAdd.No = I;
WillAdd.X = wkArr[0];
WillAdd.Y = wkArr[1];
XYInfoList.Add(WillAdd);
}
XYInfoList.Sort((A, B) => A.X.CompareTo(B.X));
var InsUnionFindMinYInfo = new UnionFindMinYInfo();
foreach (XYInfoDef EachXYInfo in XYInfoList) {
InsUnionFindMinYInfo.MakeSet(EachXYInfo.Y);
}
var AppearYDict = new SortedDictionary<long, object>();
foreach (XYInfoDef EachXYInfo in XYInfoList) {
bool WillAdd = true;
foreach (long EachKey in AppearYDict.Keys) {
if (EachXYInfo.Y <= EachKey) {
break;
}
long MinY = InsUnionFindMinYInfo.GetMinY(EachKey);
InsUnionFindMinYInfo.Unite(EachXYInfo.Y, MinY);
WillAdd = false;
}
if (WillAdd) {
AppearYDict[EachXYInfo.Y] = null;
}
}
var sb = new System.Text.StringBuilder();
foreach (XYInfoDef EachXYInfo in XYInfoList.OrderBy(pX => pX.No)) {
sb.AppendLine(InsUnionFindMinYInfo.GetSize(EachXYInfo.Y).ToString());
}
Console.Write(sb.ToString());
}
}
// UnionFindMinYInfoクラス
internal class UnionFindMinYInfo
{
private class NodeInfoDef
{
internal long ParentNode;
internal long Rank;
internal long Size;
internal long MinY;
}
private Dictionary<long, NodeInfoDef> mNodeInfoDict =
new Dictionary<long, NodeInfoDef>();
// 要素が1つである木を森に追加
internal void MakeSet(long pNode)
{
NodeInfoDef WillAdd = new NodeInfoDef();
WillAdd.ParentNode = pNode;
WillAdd.Rank = 0;
WillAdd.Size = 1;
WillAdd.MinY = pNode;
mNodeInfoDict[pNode] = WillAdd;
}
// 合併処理
internal void Unite(long pX, long pY)
{
long XNode = FindSet(pX);
long YNode = FindSet(pY);
// 既に同じ木の場合
if (XNode == YNode) return;
long XRank = mNodeInfoDict[XNode].Rank;
long YRank = mNodeInfoDict[YNode].Rank;
long MinY = Math.Min(mNodeInfoDict[XNode].MinY, mNodeInfoDict[YNode].MinY);
if (XRank > YRank) {
mNodeInfoDict[YNode].ParentNode = XNode;
mNodeInfoDict[XNode].Size += mNodeInfoDict[YNode].Size;
mNodeInfoDict[XNode].MinY = MinY;
}
else {
mNodeInfoDict[XNode].ParentNode = YNode;
mNodeInfoDict[YNode].Size += mNodeInfoDict[XNode].Size;
mNodeInfoDict[XNode].MinY = MinY;
if (XRank == YRank) {
mNodeInfoDict[YNode].Rank++;
}
}
}
// ノードを引数として、木の根を取得
internal long FindSet(long pTargetNode)
{
// 根までの経路上のノードのList
var PathNodeList = new List<long>();
long CurrNode = pTargetNode;
while (CurrNode != mNodeInfoDict[CurrNode].ParentNode) {
PathNodeList.Add(CurrNode);
CurrNode = mNodeInfoDict[CurrNode].ParentNode;
}
// 経路圧縮 (親ポインタの付け替え)
foreach (long EachPathNode in PathNodeList) {
NodeInfoDef wkNodeInfo = mNodeInfoDict[EachPathNode];
wkNodeInfo.ParentNode = CurrNode;
mNodeInfoDict[EachPathNode] = wkNodeInfo;
}
return CurrNode;
}
// ノードを引数として、木の中の最小のYを取得
internal long GetMinY(long pNode)
{
long RootNode = FindSet(pNode);
return mNodeInfoDict[RootNode].MinY;
}
// ノードを引数として、木のサイズを取得
internal long GetSize(long pNode)
{
long RootNode = FindSet(pNode);
return mNodeInfoDict[RootNode].Size;
}
internal void DebugPrint()
{
foreach (var EachPair in mNodeInfoDict.OrderBy(pX => pX.Key)) {
Console.WriteLine("mNodeInfoDict[{0}].ParentNode={1},Size={2},MinY={3}",
EachPair.Key, EachPair.Value.ParentNode, EachPair.Value.Size, EachPair.Value.MinY);
}
}
}