#include <iostream>
#include <algorithm>
using namespace std;
struct Node
{
int x,y;
}interval[101];
bool cmp(Node a,Node b)
{
if(a.y != b.y)
return a.y > b.y;
return a.x < b.x;
}
void init(int n)
{
string s;
for(int i = 0;i < n;i++)
{
cin>>interval[i].x>>interval[i].y;
getline(cin,s);
}
sort(interval,interval+n,cmp);
}
void Judge(int n)
{
bool flag = false;
int ans = interval[0].x;
for(int i = 1;i < n;i++)
{
if(ans-interval[i].y>1){
flag = true;
break;
}else
{
if(interval[i].x<ans)
ans = interval[i].x;
}
}
if(flag)
cout<<ans-1<<endl;
else
cout<<"Badly!"<<endl;
}
int main()
{
int n;
while(cin>>n)
{
int s,e;
cin>>s>>e;
init(n);
if(interval[0].y < e)
cout<<e<<endl;
else
Judge(n);
}
return 0;
}
For each test case, first input one integer N(1<= N <= 100), then two integers p and q (-6000000 <= p <= q <= 6000000) represent the starting year and the ending year in this case. Followed by N wars.
Each war described as follows:
A i B i N i (A,B is integer, p <= A, B <= q, N i is a String which is the ith war's name )
Represent that the ith War took place between year A and year B.
Each war described as follows:
A i B i N i (A,B is integer, p <= A, B <= q, N i is a String which is the ith war's name )
Represent that the ith War took place between year A and year B.
Output
Output one number represent which year there was no war in the range p and q, if there are not only one year, output the maximum year which there was no war. If all the year had war, just output "Badly!".
Sample Input
3 100 200 100 120 RtWar 110 140 WeWar 141 199 QqWar 1 -600 600 -600 600 Cool War
Sample Output
200 Badly!