Problem description

A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.

The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:

  • Is it true that y is strictly larger than number x?
  • Is it true that y is strictly smaller than number x?
  • Is it true that y is larger than or equal to number x?
  • Is it true that y is smaller than or equal to number x?

On each question the host answers truthfully, "yes" or "no".

Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the signis:

  • ">" (for the first type queries),
  • "<" (for the second type queries),
  • ">=" (for the third type queries),
  • "<=" (for the fourth type queries).

All values of x are integer and meet the inequation  - 109 ≤ x ≤ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").

Consequtive elements in lines are separated by a single space.

Output

Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation  - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).

Examples

Input

4
>= 1 Y
< 3 N
<= -3 N
> 55 N

Output

17

Input

2
> 100 Y
< -100 Y

Output

Impossible
解题思路:题意比较简单,就是找出符合要求的区间,然后输出其中任意一个值。如果不满足构成区间的条件,则输出"Impossible"。
AC代码:
 #include<bits/stdc++.h>
using namespace std;
const int INF = 2e9;
int main(){
int n,x,left=-INF,right=INF;char ch;string eq;//初始值区间满足-2*10^9<=[left,right]<=2*10^9
cin>>n;
while(n--){
getchar();
cin>>eq>>x>>ch;
if(ch=='N'){//修改其值
if(eq==">=")eq="<";
else if(eq=="<=")eq=">";
else if(eq==">")eq="<=";
else eq=">=";
}
if(eq=="<")right=min(right,x-);//取右端点的最小值
else if(eq=="<=")right=min(right,x);
else if(eq==">")left=max(left,x+);//取左端点的最大值
else left=max(left,x);
}
if(left>right)cout<<"Impossible"<<endl;//不满足条件
else cout<<left<<endl;//直接输出左端点值(任意值)
return ;
}

B - Guess a number!的更多相关文章

  1. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  2. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  3. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  4. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  5. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  6. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

  7. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  8. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  9. [LeetCode] Number of Boomerangs 回旋镖的数量

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  10. [LeetCode] Number of Segments in a String 字符串中的分段数量

    Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...

随机推荐

  1. 去除安卓apk中的广告

    一般来说,安卓应用很多免费的apk都是有广告的.尽管我们要坚持尊重开发者,帮帮他们点击广告赚钱来可持续发展,但是有的时候,很多游戏中游戏实在是太影响感觉了,当找不到汉化破解版本的时候,也许需要亲自把它 ...

  2. 使用脚本卸载.net framework for mac

    官方只提供了安装包,没提供卸载

  3. printf 打印较长字符

  4. 微信小程序中的iPhone X适配问题

    微信小程序中的iPhone X适配问题 小程序中下方的导航会被iPhone X下面的那条黑线盖住[微笑脸],所以要专门为了iPhone X做样式上的适配[微笑脸] wx.getSystemInfo({ ...

  5. PS CC2018 命令大全

    1.图像: 设置图像大小:图像->图像大小->设置宽高 约束比例: 解除约束比例: 2.设置大小像素图片不模糊: 双击当前图层->新建图层样式->输入名称->确定-> ...

  6. XML文件读取加上 Ajax请求

    #region XML文件处理 XmlDocument doc = new XmlDocument(); XmlReaderSettings settings = new XmlReaderSetti ...

  7. 【剑指Offer】34、第一个只出现一次的字符

      题目描述:   在一个字符串(0<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置, 如果没有则返回 -1(需要区分大小写).   解题思路: ...

  8. 微信小程序-蓝牙连接

    最近的项目需要使用小程序的蓝牙功能与硬件设备进行连接相互传送数据指令,联调过程中发现一些问题,于是想着记录下来,方便以后查看! 1.0一般使用蓝牙功能肯定是想连接某一个蓝牙设备,所以需要知道这个蓝牙设 ...

  9. salt 批量添加route路由

    安装net-tools包 因为其余机器没有网络,使用rpm包安装,并添加缺省路由. [root@web1 base]# tree . ├── add-route.sls ├── files │   └ ...

  10. nginx下部署showdoc

    1. 安装nginx服务器sudo apt-get install nginx -y 2. 启动服务sudo service nginx start 3. 安装php环境 sudo apt-get i ...