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. SQL Server实现用户注册

    用SQL Server注册用户,通过页面输入注册信息,存储到数据库. <form action="zhuChe.jsp" method="post" on ...

  2. 《Java编程思想》学习笔记(一)

    1——面向对象和JVM基础  1.java中的4种访问制权限: (1).public:最大访问控制权限,对所有的类都可见. (2).protect:同一包可见,不在同一个包的所有子类也可见. (3). ...

  3. SLAM: Ubuntu14.04_Kylin安装ROS-Indigo

    参考连接:ROS-Indigo版在Ubuntu上的安装第一步: 软件源配置 1. 增加下载源(增加ubuntu版的ros数据仓库,即下载源)(通用指令适合任何版本的ros) sudo sh -c 'e ...

  4. python3:语法变动 及新特性

    python3.0 对python2.x 升级后重大语法变动,幸好留下2.7.6及后续2版本,保持一些语法兼容. 原始地址:http://hi.baidu.com/jxq61/item/3a24883 ...

  5. PHP安装环境搭建

    一. 安装PHP运行服务器 xampps-x64 二.安装PHP程序编辑软件(Zend Studo需要破解) 安装后打开,再关闭 把com.zend.php.core_10.6.0.v20140128 ...

  6. js 获取属性名称,再根据这个属性名获取值

    if (result.success) { var obj = JSON.parse(result.data); var sltObj = document.getElementById(" ...

  7. 三种“BIOS设置光驱第一启动的图解”

    除特殊机器类型一般都是“开机按DEL进入BIOS界面,当然还有AMD主板有按F2的进入” 第一种.AWARD BIOS设置光驱启动方法: 进入Bios界面,选第二项——>回车 选中此项,按PAG ...

  8. Commons IO

    Common IO 是一个工具库,用来帮助开发IO功能 它包括6个主要部分 Utility classes – 包括一些静态方法来执行常用任务 Input – InputStream 和 Reader ...

  9. MongoDB简介、特点、原理、使用场景、应用案例

    简介 MongoDB[1] 是一个基于分布式文件存储的数据库.由C 语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB[2] 是一个介于关系数据库和非关系数据库之间的产品, ...

  10. (13)处理静态资源(自定义资源映射)【从零开始学Spring Boot】

    上面我们介绍了Spring Boot 的默认资源映射,一般够用了,那我们如何自定义目录? 这些资源都是打包在jar包中的,然后实际应用中,我们还有很多资源是在管理系统中动态维护的,并不可能在程序包中, ...