Points in Segments

You are given a set of nn segments on the axis OxOx, each segment has integer endpoints between 11 and mm inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers lili and riri (1≤li≤ri≤m1≤li≤ri≤m) — coordinates of the left and of the right endpoints.

Consider all integer points between 11 and mm inclusive. Your task is to print all such points that don't belong to any segment. The point xx belongs to the segment [l;r][l;r]if and only if l≤x≤rl≤x≤r.

Input

The first line of the input contains two integers nn and mm (1≤n,m≤1001≤n,m≤100) — the number of segments and the upper bound for coordinates.

The next nn lines contain two integers each lili and riri (1≤li≤ri≤m1≤li≤ri≤m) — the endpoints of the ii-th segment. Segments may intersect, overlap or even coincide with each other. Note, it is possible that li=rili=ri, i.e. a segment can degenerate to a point.

Output

In the first line print one integer kk — the number of points that don't belong to any segment.

In the second line print exactly kk integers in any order — the points that don't belong to any segment. All points you print should be distinct.

If there are no such points at all, print a single integer 00 in the first line and either leave the second line empty or do not print it at all.

Examples

Input

3 5
2 2
1 2
5 5

Output

2
3 4 

Input

1 7
1 7

Output

0

Note

In the first example the point 11 belongs to the second segment, the point 22 belongs to the first and the second segments and the point 55 belongs to the third segment. The points 33 and 44 do not belong to any segment.

In the second example all the points from 11 to 77 belong to the first segment.

在OxOx轴上给出一组nn个段,每个段的整数端点在11和mm之间(包括11和mm)。段可以相互交叉,重叠或甚至重合。每个片段的特征在于两个整数lili和riri(1≤li≤ri≤m1≤li≤ri≤m) - 左端点和右端点的坐标。

考虑11和mm之间的所有整数点。您的任务是打印所有不属于任何细分的点。当且仅当l≤x≤rl≤x≤r时,点xx属于段[l; r] [l; r]。

输入
输入的第一行包含两个整数nn和mm(1≤n,m≤1001≤n,m≤100) - 段的数量和坐标的上限。

接下来的nn行包含两个整数,每个lili和riri(1≤li≤ri≤m1≤li≤ri≤m) - 第ii个段的端点。段可以相互交叉,重叠或甚至重合。注意,有可能li = rili = ri,即一个段可以退化到一个点。

产量
在第一行中打印一个整数kk - 不属于任何段的点数。

在第二行中,以任何顺序打印完全kk整数 - 不属于任何段的点。您打印的所有点都应该是不同的。

如果根本没有这样的点,则在第一行中打印一个整数00,并将第二行留空或根本不打印。

例子
输入
3 5
2 2
1 2
5 5
产量
2
3 4
输入
1 7
1 7
产量
0

注意
在第一示例中,点11属于第二段,点22属于第一段和第二段,点55属于第三段。点33和44不属于任何段。

在第二个例子中,从11到77的所有点都属于第一个段。

#include<iostream>
using namespace std;
bool a[100];
int main()
{   int n,m;
    while(cin>>n>>m) 
    { 
    int x[n],y[n];
    int count=0;
	   for(int i=0;i<n;i++)
	   {
	   	cin>>x[i]>>y[i];
	   	for(int j=x[i];j<=y[i];j++)
	   	  {  if(!a[j])
			 {
		   
	   	   a[j]=true;
	   	   count++;
		     }
		   }
	   }
	   cout<<m-count<<endl;
	   for(int q=1;q<=m;q++)
	   {
	   	if(!a[q])
		   {
	     	  if(q!=(m-count))
			   {
	   			cout<<q<<" ";
		       }
		      else  
		      cout<<q<<endl;
		      }
	   
	   }
    	
	
	  
	
	
	}
	return 0;
 } 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值