description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
The only difference with E2 is the question of the problem.. Vlad built a maze out of $n$ rooms and $n-1$ bidirectional corridors. From any room $u$ any other room $v$ can be reached through a sequence of corridors. Thus, the room system forms an undirected tree. Vlad invited $k$ friends to play a game with them. Vlad starts the game in the room $1$ and wins if he reaches a room other than $1$, into which exactly one corridor leads. Friends are placed in the maze: the friend with number $i$ is in the room $x_i$, and no two friends are in the same room (that is, $x_i \neq x_j$ for all $i \neq j$). Friends win if one of them meets Vlad in any room or corridor before he wins. For one unit of time, each participant of the game can go through one corridor. All participants move at the same time. Participants may not move. Each room can fit all participants at the same time. Friends know the plan of a maze and intend to win. Vlad is a bit afraid of their ardor. Determine if he can guarantee victory (i.e. can he win in any way friends play). In other words, determine if there is such a sequence of Vlad's moves that lets Vlad win in any way friends play. -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. The input contains an empty string before each test case. The first line of the test case contains two numbers $n$ and $k$ ($1 \le k < n \le 2\cdot 10^5$) — the number of rooms and friends, respectively. The next line of the test case contains $k$ integers $x_1, x_2, \dots, x_k$ ($2 \le x_i \le n$) — numbers of rooms with friends. All $x_i$ are different. The next $n-1$ lines contain descriptions of the corridors, two numbers per line $v_j$ and $u_j$ ($1 \le u_j, v_j \le n$) — numbers of rooms that connect the $j$ corridor. All corridors are bidirectional. From any room, you can go to any other by moving along the corridors. It is guaranteed that the sum of the values $n$ over all test cases in the test is not greater than $2\cdot10^5$. -----Output----- Print $t$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be "YES" if Vlad can guarantee himself a victory and "NO" otherwise. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" will all be recognized as positive answers). -----Examples----- Input 4 8 2 5 3 4 7 2 5 1 6 3 6 7 2 1 7 6 8 3 1 2 1 2 2 3 3 1 2 1 2 1 3 3 2 2 3 3 1 1 2 Output YES NO YES NO -----Note----- In the first test case, regardless of the strategy of his friends, Vlad can win by going to room $4$. The game may look like this: The original locations of Vlad and friends. Vlad is marked in green, friends — in red. Locations after one unit of time. End of the game. Note that if Vlad tries to reach the exit at the room $8$, then a friend from the $3$ room will be able to catch him.
for t in range(int(input())): input() n, k = map(int, input().split()) pos = set(map(int, input().split())) adj = [set() for i in range(n + 1)] for i in range(n - 1): u, v = map(int, input().split()) adj[u].add(v) adj[v].add(u) player = set([1]) friends = set() | pos vis = set() forb = set() | pos ok = False while 1: if not player: break player_nxt = set() for i in player: vis.add(i) if len(adj[i]) == 1 and i != 1: ok = True break for j in adj[i]: if j not in vis and j not in forb: player_nxt.add(j) if ok == True: break friends_nxt = set() for i in friends: for j in adj[i]: if j not in vis: vis.add(j) forb.add(j) friends_nxt.add(j) player = player_nxt - friends_nxt friends = friends_nxt if ok == True: break print("YES" if ok == True else "NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING
The only difference with E2 is the question of the problem.. Vlad built a maze out of $n$ rooms and $n-1$ bidirectional corridors. From any room $u$ any other room $v$ can be reached through a sequence of corridors. Thus, the room system forms an undirected tree. Vlad invited $k$ friends to play a game with them. Vlad starts the game in the room $1$ and wins if he reaches a room other than $1$, into which exactly one corridor leads. Friends are placed in the maze: the friend with number $i$ is in the room $x_i$, and no two friends are in the same room (that is, $x_i \neq x_j$ for all $i \neq j$). Friends win if one of them meets Vlad in any room or corridor before he wins. For one unit of time, each participant of the game can go through one corridor. All participants move at the same time. Participants may not move. Each room can fit all participants at the same time. Friends know the plan of a maze and intend to win. Vlad is a bit afraid of their ardor. Determine if he can guarantee victory (i.e. can he win in any way friends play). In other words, determine if there is such a sequence of Vlad's moves that lets Vlad win in any way friends play. -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. The input contains an empty string before each test case. The first line of the test case contains two numbers $n$ and $k$ ($1 \le k < n \le 2\cdot 10^5$) — the number of rooms and friends, respectively. The next line of the test case contains $k$ integers $x_1, x_2, \dots, x_k$ ($2 \le x_i \le n$) — numbers of rooms with friends. All $x_i$ are different. The next $n-1$ lines contain descriptions of the corridors, two numbers per line $v_j$ and $u_j$ ($1 \le u_j, v_j \le n$) — numbers of rooms that connect the $j$ corridor. All corridors are bidirectional. From any room, you can go to any other by moving along the corridors. It is guaranteed that the sum of the values $n$ over all test cases in the test is not greater than $2\cdot10^5$. -----Output----- Print $t$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be "YES" if Vlad can guarantee himself a victory and "NO" otherwise. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" will all be recognized as positive answers). -----Examples----- Input 4 8 2 5 3 4 7 2 5 1 6 3 6 7 2 1 7 6 8 3 1 2 1 2 2 3 3 1 2 1 2 1 3 3 2 2 3 3 1 1 2 Output YES NO YES NO -----Note----- In the first test case, regardless of the strategy of his friends, Vlad can win by going to room $4$. The game may look like this: The original locations of Vlad and friends. Vlad is marked in green, friends — in red. Locations after one unit of time. End of the game. Note that if Vlad tries to reach the exit at the room $8$, then a friend from the $3$ room will be able to catch him.
def f(): input() n, k = map(int, input().split()) visv = set([(i - 1) for i in map(int, input().split())]) g = [set() for i in range(n)] for i in range(n - 1): a, b = map(int, input().split()) g[a - 1].add(b - 1) g[b - 1].add(a - 1) qv = set() | visv qh = set([0]) vish = set() while 1: if not qh: return "NO" nqh = set() for i in qh: vish.add(i) if len(g[i]) == 1 and i: return "YES" for j in g[i]: if j not in vish and j not in visv: nqh.add(j) nqv = set() for i in qv: for j in g[i]: if j not in visv: nqv.add(j) visv.add(j) qh = nqh - nqv qv = nqv for _ in range(int(input())): print(f())
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR WHILE NUMBER IF VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR RETURN STRING FOR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
The only difference with E2 is the question of the problem.. Vlad built a maze out of $n$ rooms and $n-1$ bidirectional corridors. From any room $u$ any other room $v$ can be reached through a sequence of corridors. Thus, the room system forms an undirected tree. Vlad invited $k$ friends to play a game with them. Vlad starts the game in the room $1$ and wins if he reaches a room other than $1$, into which exactly one corridor leads. Friends are placed in the maze: the friend with number $i$ is in the room $x_i$, and no two friends are in the same room (that is, $x_i \neq x_j$ for all $i \neq j$). Friends win if one of them meets Vlad in any room or corridor before he wins. For one unit of time, each participant of the game can go through one corridor. All participants move at the same time. Participants may not move. Each room can fit all participants at the same time. Friends know the plan of a maze and intend to win. Vlad is a bit afraid of their ardor. Determine if he can guarantee victory (i.e. can he win in any way friends play). In other words, determine if there is such a sequence of Vlad's moves that lets Vlad win in any way friends play. -----Input----- The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. The input contains an empty string before each test case. The first line of the test case contains two numbers $n$ and $k$ ($1 \le k < n \le 2\cdot 10^5$) — the number of rooms and friends, respectively. The next line of the test case contains $k$ integers $x_1, x_2, \dots, x_k$ ($2 \le x_i \le n$) — numbers of rooms with friends. All $x_i$ are different. The next $n-1$ lines contain descriptions of the corridors, two numbers per line $v_j$ and $u_j$ ($1 \le u_j, v_j \le n$) — numbers of rooms that connect the $j$ corridor. All corridors are bidirectional. From any room, you can go to any other by moving along the corridors. It is guaranteed that the sum of the values $n$ over all test cases in the test is not greater than $2\cdot10^5$. -----Output----- Print $t$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be "YES" if Vlad can guarantee himself a victory and "NO" otherwise. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" will all be recognized as positive answers). -----Examples----- Input 4 8 2 5 3 4 7 2 5 1 6 3 6 7 2 1 7 6 8 3 1 2 1 2 2 3 3 1 2 1 2 1 3 3 2 2 3 3 1 1 2 Output YES NO YES NO -----Note----- In the first test case, regardless of the strategy of his friends, Vlad can win by going to room $4$. The game may look like this: The original locations of Vlad and friends. Vlad is marked in green, friends — in red. Locations after one unit of time. End of the game. Note that if Vlad tries to reach the exit at the room $8$, then a friend from the $3$ room will be able to catch him.
def solve(): input() n, k = map(int, input().split()) f = list(enumerate(list(map(lambda x: int(x) - 1, input().split())))) g = {i: [] for i in range(n)} for i in range(n - 1): a, b = map(int, input().split()) a -= 1 b -= 1 g[a].append(b) g[b].append(a) needed = {} vlad = [0] visited = [False] * n friends = [-1] * n while len(vlad): nf = [] for i, f1 in f: if friends[f1] != -1: continue friends[f1] = i for e in g[f1]: nf.append((i, e)) f = nf new_vlad = [] for v in vlad: if friends[v] != -1: needed[friends[v]] = True continue if visited[v] == True: continue visited[v] = True if len(g[v]) == 1 and v != 0: return -1 for e in g[v]: new_vlad.append(e) vlad = new_vlad return len(needed) n = int(input()) for i in range(n): print("YES" if solve() == -1 else "NO")
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER STRING STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
questions = int(input()) lower_limit, upper_limit = -2000000000, 2000000000 inequalities = {">": 2, ">=": 1, "<": -1, "<=": -2} gt, geq, lt, leq = 2, 1, -1, -2 for i in range(questions): inequality, number, answer = input().split() inequality = ( inequalities[inequality] * -1 if answer != "Y" else inequalities[inequality] ) number = ( int(number) - 1 if inequality == lt else int(number) + 1 if inequality == gt else int(number) ) if inequality < 0 and upper_limit > number: upper_limit = number elif inequality > 0 and lower_limit < number: lower_limit = number if lower_limit <= upper_limit: print(lower_limit) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l = -2000000000 r = 2000000000 for _ in range(n): s = input().split() x = int(s[1]) if s[0] == ">" and s[2] == "Y": l = max(l, x + 1) elif s[0] == ">" and s[2] == "N": r = min(r, x) elif s[0] == ">=" and s[2] == "Y": l = max(l, x) elif s[0] == ">=" and s[2] == "N": r = min(r, x - 1) elif s[0] == "<" and s[2] == "Y": r = min(r, x - 1) elif s[0] == "<" and s[2] == "N": l = max(l, x) elif s[0] == "<=" and s[2] == "Y": r = min(r, x) elif s[0] == "<=" and s[2] == "N": l = max(l, x + 1) if r - l >= 0: print(l) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
line = int(input()) questions = [] answer = None a_range = ["inf", "inf"] def shorten_sec(num): if a_range[1] == "inf": return num elif a_range[1] > num: return num return a_range[1] def shorten_first(num): if a_range[0] == "inf": return num elif a_range[0] < num: return num return a_range[0] for i in range(line): newLine = input() newLine = newLine.split() newLine[1] = int(newLine[1]) questions.append(newLine) for i in questions: if i[0] == ">=" and i[2] == "Y": a_range[0] = shorten_first(i[1]) elif i[0] == ">=" and i[2] == "N": a_range[1] = shorten_sec(i[1] - 1) elif i[0] == "<=" and i[2] == "Y": a_range[1] = shorten_sec(i[1]) elif i[0] == "<=" and i[2] == "N": a_range[0] = shorten_first(i[1] + 1) elif i[0] == "<" and i[2] == "Y": a_range[1] = shorten_sec(i[1] - 1) elif i[0] == "<" and i[2] == "N": a_range[0] = shorten_first(i[1]) elif i[0] == ">" and i[2] == "Y": a_range[0] = shorten_first(i[1] + 1) elif i[0] == ">" and i[2] == "N": a_range[1] = shorten_sec(i[1]) if a_range[0] == "inf" and a_range[1] == "inf": print("Impossible") elif "inf" == a_range[1] and a_range[0] < -2000000000: print("Impossible") elif "inf" == a_range[0] and a_range[1] > 2000000000: print("Impossible") elif "inf" not in a_range and a_range[0] > a_range[1]: print("Impossible") elif a_range[1] == "inf": print(a_range[0]) else: print(a_range[1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NONE ASSIGN VAR LIST STRING STRING FUNC_DEF IF VAR NUMBER STRING RETURN VAR IF VAR NUMBER VAR RETURN VAR RETURN VAR NUMBER FUNC_DEF IF VAR NUMBER STRING RETURN VAR IF VAR NUMBER VAR RETURN VAR RETURN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING IF STRING VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF STRING VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF STRING VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) y = [-2 * 10**9, 2 * 10**9] k = [] f = 0 for i in range(n): k.append(list(map(str, input().split()))) for i in range(n): x = int(k[i][1]) if k[i][2] == "N": if k[i][0] == ">": k[i][0] = "<=" elif k[i][0] == ">=": k[i][0] = "<" elif k[i][0] == "<": k[i][0] = ">=" else: k[i][0] = ">" if k[i][0] == ">": y[0] = max(x + 1, y[0]) elif k[i][0] == "<": y[1] = min(x - 1, y[1]) elif k[i][0] == "<=": y[1] = min(x, y[1]) else: y[0] = max(x, y[0]) if y[0] > y[1]: f = 1 break if f: print("Impossible") else: print(y[0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST BIN_OP NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING ASSIGN VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING ASSIGN VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING ASSIGN VAR VAR NUMBER STRING ASSIGN VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l = [] less = [] grt = [] for i in range(n): l = [x for x in input().split()] if l[2] == "N": l[2] = "Y" if l[0] == ">=": l[0] = "<" elif l[0] == ">": l[0] = "<=" elif l[0] == "<": l[0] = ">=" else: l[0] = ">" if l[0] == "<" or l[0] == "<=": less.append(int(l[1])) if l[0] == "<": less[-1] -= 1 elif l[0] == ">" or l[0] == ">=": grt.append(int(l[1])) if l[0] == ">": grt[-1] += 1 less.sort() grt.sort() if len(less) > 0 and len(grt) > 0: v1 = less[0] v2 = grt[-1] if v1 >= v2: print(v2) else: print("Impossible") elif len(less) == 0 and len(grt) > 0: print(grt[-1]) elif len(grt) == 0 and len(less) > 0: print(less[0]) elif len(less) == 0 and len(grt) == 0: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) maxmin = -2000000000 minmax = 2000000000 for x in range(n): query = [str(x) for x in input().split()] op = query[0] num = int(query[1]) flag = query[2] if op == ">": if flag == "Y": maxmin = max(maxmin, num + 1) else: minmax = min(minmax, num) elif op == "<": if flag == "Y": minmax = min(minmax, num - 1) else: maxmin = max(maxmin, num) elif op == ">=": if flag == "Y": maxmin = max(maxmin, num) else: minmax = min(minmax, num - 1) elif op == "<=": if flag == "Y": minmax = min(minmax, num) else: maxmin = max(maxmin, num + 1) if maxmin > minmax: print("Impossible") else: print(maxmin)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) simbolo = [] num = [] yn = [] for j in range(n): s, x, y = input().split() simbolo.append(s) num.append(int(x)) yn.append(y) maximo = float("inf") minimo = -float("inf") for i in range(n): ismax = False if yn[i] == "N": if simbolo[i] == "<": simbolo[i] = ">=" elif simbolo[i] == ">": simbolo[i] = "<=" elif simbolo[i] == "<=": simbolo[i] = ">" elif simbolo[i] == ">=": simbolo[i] = "<" if simbolo[i] == "<" or simbolo[i] == "<=": ismax = True if len(simbolo[i]) == 1: if ismax: num[i] -= 1 else: num[i] += 1 if ismax == True: if num[i] < maximo: maximo = num[i] elif num[i] > minimo: minimo = num[i] if minimo == -float("inf"): minimo = maximo if maximo >= minimo: print(minimo) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR STRING ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
list1 = ["", "", "", ""] n = int(input()) for _ in range(n): list2 = [x for x in input().split()] val = int(list2[1]) if list2[2] == "N": if list2[0] == ">=": list2[0] = "<" elif list2[0] == ">": list2[0] = "<=" elif list2[0] == "<=": list2[0] = ">" elif list2[0] == "<": list2[0] = ">=" if list2[0] == ">=": if list1[1] == "": list1[0] = "[" list1[1] = val elif list1[1] <= val: list1[1] = val list1[0] = "[" elif list2[0] == ">": if list1[1] == "": list1[0] = "(" list1[1] = val elif list1[1] <= val: list1[1] = val list1[0] = "(" elif list2[0] == "<=": if list1[2] == "": list1[3] = "]" list1[2] = val elif list1[2] >= val: list1[2] = val list1[3] = "]" elif list2[0] == "<": if list1[2] == "": list1[3] = ")" list1[2] = val elif list1[2] >= val: list1[2] = val list1[3] = ")" if list1[0] == "(": list1[1] += 1 if list1[3] == ")": list1[2] -= 1 if list1[0] == "" or list1[3] == "": if list1[0] == "": print(list1[2]) else: print(list1[1]) elif list1[1] > list1[2]: print("Impossible") else: print(list1[1])
ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER VAR IF VAR NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER VAR IF VAR NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER VAR IF VAR NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER VAR IF VAR NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER STRING IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) low = None high = None for i in range(n): l = input().split() if l[0] == ">" and l[2] == "Y" or l[0] == "<=" and l[2] == "N": low = max(int(l[1]) + 1, low == None and -1000000000.0 or low) elif l[0] == "<" and l[2] == "Y" or l[0] == ">=" and l[2] == "N": high = min(int(l[1]) - 1, high == None and 1000000000.0 or high) elif l[0] == ">=" and l[2] == "Y" or l[0] == "<" and l[2] == "N": low = max(int(l[1]), low == None and -1000000000.0 or low) elif l[0] == "<=" and l[2] == "Y" or l[0] == ">" and l[2] == "N": high = min(int(l[1]), high == None and 1000000000.0 or high) if high != None and low != None: if high < low: print("Impossible") else: print(low) elif high == None: print(low) else: print(high)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NONE NUMBER VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NONE NUMBER VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NONE NUMBER VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NONE NUMBER VAR IF VAR NONE VAR NONE IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NONE EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) low = -2 * 10**9 high = 2 * 10**9 for i in range(n): sign, x, answer = input().split() x = int(x) if sign == ">=": if answer == "Y": low = max(low, x) else: high = min(high, x - 1) elif sign == ">": if answer == "Y": low = max(low, x + 1) else: high = min(high, x) elif sign == "<=": if answer == "Y": high = min(high, x) else: low = max(low, x + 1) elif answer == "Y": high = min(high, x - 1) else: low = max(low, x) if low <= high: print(low) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) MAX = 1000000000 minimum, maximum, temp_max, temp_min = [0] * 4 i = 0 while i < n: question = [x for x in input().split()] if question[2] == "Y": if question[0] == ">=": minimum = int(question[1]) maximum = MAX elif question[0] == ">": minimum = int(question[1]) + 1 maximum = MAX elif question[0] == "<=": minimum = -MAX maximum = int(question[1]) else: minimum = -MAX maximum = int(question[1]) - 1 elif question[0] == ">=": minimum = -MAX maximum = int(question[1]) - 1 elif question[0] == ">": minimum = -MAX maximum = int(question[1]) elif question[0] == "<=": minimum = int(question[1]) + 1 maximum = MAX else: minimum = int(question[1]) maximum = MAX if i == 0: temp_max = maximum temp_min = minimum else: temp_max = min(temp_max, maximum) temp_min = max(temp_min, minimum) if temp_max < temp_min and abs(temp_min) <= MAX and abs(temp_max) <= MAX: print("Impossible") exit() i += 1 if minimum != -MAX: print(temp_min) else: print(temp_max)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
list1 = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"] list2 = [">", "<", "=", "N", "Y"] n = int(input()) ans = [] low = 10000000000 max = -1001317593 str1 = "" str2 = "" for i in range(n): k = input() str1 = "" str2 = "" for j in k: if j in list2: str1 += j if j in list1: str2 += j z = int(str2) if str1[0] == ">" and str1[len(str1) - 1] == "Y": if str1[1] == "=": if z > max: max = z elif z >= max: max = z + 1 if str1[0] == ">" and str1[len(str1) - 1] == "N": if str1[1] == "=": if z <= low: low = z - 1 elif z < low: low = z if str1[0] == "<" and str1[len(str1) - 1] == "Y": if str1[1] == "=": if z < low: low = z if z == low: low = z elif z <= low: low = z - 1 if str1[0] == "<" and str1[len(str1) - 1] == "N": if str1[1] == "=": if z >= max: max = z + 1 elif z > max: max = z temp = 0 for i in range(max, low + 1): print(i) temp = 1 break if temp == 0: print("Impossible")
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF VAR NUMBER STRING IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF VAR NUMBER STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF VAR NUMBER STRING IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF VAR NUMBER STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) p1, p2 = int(2 * -1000000000.0), int(2 * 1000000000.0) for i in range(n): q, x, a = map(str, input().split()) if a == "Y": if q == ">=" and int(x) >= p1: p1 = int(x) elif q == ">" and int(x) >= p1: p1 = int(x) + 1 elif q == "<=" and int(x) <= p2: p2 = int(x) elif q == "<" and int(x) <= p2: p2 = int(x) - 1 elif a == "N": if q == ">=" and int(x) <= p2: p2 = int(x) - 1 elif q == ">" and int(x) <= p2: p2 = int(x) elif q == "<=" and int(x) >= p1: p1 = int(x) + 1 elif q == "<" and int(x) >= p1: p1 = int(x) if p1 > p2: print("Impossible") else: print(p1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l = float("-inf") r = float("inf") for i in range(n): exp, no, ans = input().split() if ans == "Y": if exp == "<=": if r > int(no): r = int(no) elif exp == ">=": if l < int(no): l = int(no) elif exp == "<": if r > int(no) - 1: r = int(no) - 1 elif exp == ">": if l < int(no) + 1: l = int(no) + 1 elif ans == "N": if exp == "<=": if l < int(no) + 1: l = int(no) + 1 elif exp == ">=": if r > int(no) - 1: r = int(no) - 1 elif exp == "<": if l < int(no): l = int(no) elif exp == ">": if r > int(no): r = int(no) if l > r: print("Impossible") elif l == float("-inf"): if r == float("inf"): print(0) else: print(r) else: print(l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING IF VAR STRING IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING IF VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
def inverse(str): val = "" if str == ">": val = "<=" elif str == "<": val = ">=" elif str == ">=": val = "<" else: val = ">" return val min_ = -2000000000 max_ = 2000000000 n = int(input()) for i in range(n): sign, num, yn = input().split() num = int(num) if yn == "N": sign = inverse(sign) if sign == "<=": max_ = min(max_, num) elif sign == "<": max_ = min(max_, num - 1) elif sign == ">=": min_ = max(min_, num) else: min_ = max(min_, num + 1) if min_ <= max_: print(min_) else: print("Impossible")
FUNC_DEF ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
def main(): n = int(input()) small_less = int(2000000000.0) + 1 big_great = int(-2000000000.0) - 1 flip = {">": "<", "<": ">"} for _ in range(n): kind, num, ans = input().split() num = int(num) if ans == "N": had_eq = len(kind) == 2 kind = flip[kind[0]] if not had_eq: kind += "=" if kind == "<=": kind = "<" num += 1 elif kind == ">=": kind = ">" num -= 1 if kind == "<": small_less = min(small_less, num) else: big_great = max(big_great, num) if small_less - 1 <= big_great: print("Impossible") else: print(small_less - 1) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR STRING IF VAR STRING ASSIGN VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
u, v = -2000000000, 2000000000 for i in range(int(input())): a, b, c = input().split() k = int(b) if a == ">=": if c == "Y": u = max(u, k) else: v = min(v, k - 1) elif a == ">": if c == "Y": u = max(u, k + 1) else: v = min(v, k) elif a == "<=": if c == "Y": v = min(v, k) else: u = max(u, k + 1) elif c == "Y": v = min(v, k - 1) else: u = max(u, k) print("Impossible" if u > v else u)
ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) i, j = -1000000001, 1000000001 for k in range(n): e, x, a = input().split() x = int(x) if (e, a) in [(">=", "Y"), ("<", "N")]: i = max(i, x) elif (e, a) in [(">", "Y"), ("<=", "N")]: i = max(i, x + 1) elif (e, a) in [("<=", "Y"), (">", "N")]: j = min(j, x) elif (e, a) in [("<", "Y"), (">=", "N")]: j = min(j, x - 1) if i > j: print("Impossible") else: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR LIST STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR LIST STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR LIST STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR LIST STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l = [] for i in range(n): l.append(list(input().split())) L = -2 * 10**9 h = 2 * 10**9 for i in range(n): if l[i][2] == "Y": if l[i][0] == "<": h = min(int(l[i][1]) - 1, h) elif l[i][0] == "<=": h = min(int(l[i][1]), h) elif l[i][0] == ">": L = max(int(l[i][1]) + 1, L) elif l[i][0] == ">=": L = max(int(l[i][1]), L) elif l[i][2] == "N": if l[i][0] == "<": L = max(int(l[i][1]), L) elif l[i][0] == "<=": L = max(int(l[i][1]) + 1, L) elif l[i][0] == ">": h = min(int(l[i][1]), h) elif l[i][0] == ">=": h = min(int(l[i][1]) - 1, h) if h < L: print("Impossible") else: print((L + h) // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) top = 2 * 10**9 bottom = -top for i in range(n): line = input().split(" ") simb = line[0] num = int(line[1]) answer = line[2] if answer == "N": if simb == ">=": simb = "<" elif simb == "<=": simb = ">" elif simb == ">": simb = "<=" elif simb == "<": simb = ">=" if simb == ">=": bottom = max(bottom, num) elif simb == "<=": top = min(top, num) elif simb == ">": bottom = max(bottom, num + 1) elif simb == "<": top = min(top, num - 1) if bottom > top: print("Impossible") else: print(top)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
import sys queries = int(sys.stdin.readline()) opp = {">": "<=", ">=": "<", "<": ">=", "<=": ">"} lower = -2000000000 upper = 2000000000 for i in range(queries): oper, num, judge = sys.stdin.readline().rstrip().split(" ") if judge == "N": oper = opp[oper] if oper == ">": lower = max(int(num) + 1, lower) elif oper == ">=": lower = max(int(num), lower) elif oper == "<": upper = min(int(num) - 1, upper) elif oper == "<=": upper = min(int(num), upper) if lower > upper: break if lower > upper: print("Impossible") else: print(lower)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR STRING ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) left = None right = None for i in range(n): st = input() op, num, ans = st.split(" ") num = int(num) if ans == "N": if op == ">=": op = "<" elif op == ">": op = "<=" elif op == "<=": op = ">" else: op = ">=" if op == ">=": if left == None: left = num else: left = max(left, num) elif op == ">": if left == None: left = num + 1 else: left = max(left, num + 1) elif op == "<=": if right == None: right = num else: right = min(right, num) elif right == None: right = num - 1 else: right = min(right, num - 1) if left == None and right == None: print(0) elif left == None: print(right) elif right == None: print(left) elif left > right: print("Impossible") else: print(left)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR STRING IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING IF VAR NONE ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NONE VAR NONE EXPR FUNC_CALL VAR NUMBER IF VAR NONE EXPR FUNC_CALL VAR VAR IF VAR NONE EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) low = -2000000001 high = 2000000001 i = 0 flag = 0 while i < n: i = i + 1 lis = input().split() if lis[2] == "N": if lis[0] == ">": lis[0] = "<=" elif lis[0] == "<": lis[0] = ">=" elif lis[0] == "<=": lis[0] = ">" elif lis[0] == ">=": lis[0] = "<" if lis[0] == ">": if low < int(lis[1]) + 1: low = int(lis[1]) + 1 elif lis[0] == ">=": if low < int(lis[1]): low = int(lis[1]) elif lis[0] == "<": if high > int(lis[1]) - 1: high = int(lis[1]) - 1 elif lis[0] == "<=": if high > int(lis[1]): high = int(lis[1]) if low > high: flag = 1 break if flag == 1: print("Impossible") else: ans = low + high ans = ans // 2 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l, r = -1000000001, 1000000001 for i in range(n): s = input().split() if s[2] == "Y": if s[0] == ">": l = max(l, int(s[1]) + 1) elif s[0] == ">=": l = max(l, int(s[1])) elif s[0] == "<": r = min(r, int(s[1]) - 1) else: r = min(r, int(s[1])) elif s[0] == "<=": l = max(l, int(s[1]) + 1) elif s[0] == "<": l = max(l, int(s[1])) elif s[0] == ">=": r = min(r, int(s[1]) - 1) else: r = min(r, int(s[1])) if r < l: print("Impossible") elif r == 1000000001 and l == -1000000001: print(1) elif r == 1000000001: print(l) elif l == -1000000001: print(r) else: print(r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) a, b, c, d = -pow(10, 9) - 10, pow(10, 9) + 10, -pow(10, 9) - 10, pow(10, 9) + 10 for _ in range(n): s = list(map(str, input().split())) if s[0] == "<" and s[2] == "Y" or s[0] == ">=" and s[2] == "N": b = min(int(s[1]), b) if s[0] == ">" and s[2] == "Y" or s[0] == "<=" and s[2] == "N": a = max(int(s[1]), a) if s[0] == ">=" and s[2] == "Y" or s[0] == "<" and s[2] == "N": c = max(int(s[1]), c) if s[0] == "<=" and s[2] == "Y" or s[0] == ">" and s[2] == "N": d = min(int(s[1]), d) l = max(a + 1, c) r = min(b - 1, d) if ( a == -pow(10, 9) - 10 and b == pow(10, 9) + 10 and c == -pow(10, 9) - 10 and d == pow(10, 9) + 10 ): print("Impossible") elif l > r: print("Impossible") else: print(l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l, r = -2000000000, 2000000000 for i in range(n): s = input().split() if s[2] == "N": if s[0] == ">": s[0] = "<=" elif s[0] == "<": s[0] = ">=" elif s[0] == ">=": s[0] = "<" elif s[0] == "<=": s[0] = ">" if s[0] == ">": l = max(l, int(s[1]) + 1) elif s[0] == "<": r = min(r, int(s[1]) - 1) elif s[0] == ">=": l = max(l, int(s[1])) elif s[0] == "<=": r = min(r, int(s[1])) if l <= r: print(l) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l = 0 fl = True r = 0 fr = True for i in range(n): t, x, ans = input().split() x = int(x) if t == ">=" and ans == "Y": if x > l or fl: l = x fl = False elif t == ">=" and ans == "N": if x - 1 < r or fr: r = x - 1 fr = False elif t == "<=" and ans == "Y": if x < r or fr: r = x fr = False elif t == "<=" and ans == "N": if x + 1 > l or fl: l = x + 1 fl = False elif t == ">" and ans == "Y": if x + 1 > l or fl: l = x + 1 fl = False elif t == ">" and ans == "N": if x < r or fr: r = x fr = False elif t == "<" and ans == "Y": if x - 1 < r or fr: r = x - 1 fr = False elif t == "<" and ans == "N": if x > l or fl: l = x fl = False if fl == True and fr == True: print(0) elif fl == True and fr != True: print(r) elif fl != True and fr == True: print(l) elif r < l: print("Impossible") else: print(l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR STRING IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR STRING IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR STRING IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR STRING IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR STRING IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR STRING IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR STRING IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) maxnum = 10000000000 minnum = maxnum * -1 for _ in range(n): s = input().strip().split() if s[0] == ">": if s[2] == "Y": minnum = int(s[1]) + 1 if minnum < int(s[1]) + 1 else minnum else: maxnum = int(s[1]) if maxnum > int(s[1]) else maxnum elif s[0] == ">=": if s[2] == "Y": minnum = int(s[1]) if minnum < int(s[1]) else minnum else: maxnum = int(s[1]) - 1 if maxnum > int(s[1]) - 1 else maxnum elif s[0] == "<": if s[2] == "Y": maxnum = int(s[1]) - 1 if maxnum > int(s[1]) - 1 else maxnum else: minnum = int(s[1]) if minnum < int(s[1]) else minnum elif s[0] == "<=": if s[2] == "Y": maxnum = int(s[1]) if maxnum > int(s[1]) else maxnum else: minnum = int(s[1]) + 1 if minnum < int(s[1]) + 1 else minnum if minnum > maxnum: print("Impossible") elif minnum == maxnum: print(minnum) elif maxnum < 0: print(maxnum) elif minnum > 0: print(minnum) else: print(0)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
greater = -2000000000 smaller = 2000000000 n = int(input()) for _ in range(n): a, b, c = input().split() if a == ">=": if c == "Y": greater = max(greater, int(b)) else: smaller = min(smaller, int(b) - 1) elif a == "<=": if c == "Y": smaller = min(int(b), smaller) else: greater = max(greater, int(b)) elif a == ">": if c == "Y": greater = max(greater, int(b) + 1) else: smaller = min(int(b), smaller) elif a == "<": if c == "Y": smaller = min(int(b) - 1, smaller) else: greater = max(greater, int(b)) if smaller < greater: print("Impossible") else: print(smaller)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) ma = "a" mi = "b" for i in range(n): linha = input() linha = linha.split() if linha[0] == "<=" and linha[2] == "Y" or linha[0] == ">" and linha[2] == "N": maior = int(linha[1]) if ma == "a": ma = maior else: ma = min(ma, maior) elif linha[0] == "<" and linha[2] == "Y" or linha[0] == ">=" and linha[2] == "N": maior = int(linha[1]) - 1 if ma == "a": ma = maior else: ma = min(ma, maior) elif linha[0] == ">" and linha[2] == "Y" or linha[0] == "<=" and linha[2] == "N": menor = int(linha[1]) + 1 if mi == "b": mi = menor else: mi = max(mi, menor) elif linha[0] == ">=" and linha[2] == "Y" or linha[0] == "<" and linha[2] == "N": menor = int(linha[1]) if mi == "b": mi = menor else: mi = max(mi, menor) if ma == "a": print(mi) elif mi == "b": print(ma) elif mi > ma: print("Impossible") else: print(mi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) t = ["", ""] for i in range(n): l = list(input().split()) l[1] = int(l[1]) if l[2] == "N": if t[0] == "": if l[0] == ">": t[0] = l[1] elif l[0] == ">=": t[0] = l[1] - 1 elif l[0] == ">": if t[0] > l[1]: t[0] = l[1] elif l[0] == ">=": if t[0] >= l[1]: t[0] = l[1] - 1 if t[1] == "": if l[0] == "<": t[1] = l[1] elif l[0] == "<=": t[1] = l[1] + 1 elif l[0] == "<": if t[1] < l[1]: t[1] = l[1] elif l[0] == "<=": if t[1] <= l[1]: t[1] = l[1] + 1 else: if t[1] == "": if l[0] == ">": t[1] = l[1] + 1 elif l[0] == ">=": t[1] = l[1] elif l[0] == ">": if t[1] <= l[1]: t[1] = l[1] + 1 elif l[0] == ">=": if t[1] < l[1]: t[1] = l[1] if t[0] == "": if l[0] == "<": t[0] = l[1] - 1 elif l[0] == "<=": t[0] = l[1] elif l[0] == "<": if t[0] >= l[1]: t[0] = l[1] - 1 elif l[0] == "<=": if t[0] > l[1]: t[0] = l[1] if t[0] == "": print(t[1]) elif t[1] == "": print(t[0]) elif t[0] < t[1]: print("Impossible") else: print(t[0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
def ugaday(lst): l, r = -2000000000, 2000000000 for elem in lst: if elem[0] == ">": if elem[2] == "N": r = min(r, int(elem[1])) else: l = max(l, int(elem[1]) + 1) if elem[0] == "<": if elem[2] == "N": l = max(l, int(elem[1])) else: r = min(r, int(elem[1]) - 1) if elem[0] == ">=": if elem[2] == "Y": l = max(l, int(elem[1])) else: r = min(r, int(elem[1]) - 1) if elem[0] == "<=": if elem[2] == "Y": r = min(r, int(elem[1])) else: l = max(l, int(elem[1]) + 1) if l <= r: return l return "Impossible" n = int(input()) a = list() for i in range(n): s, x, ans = [i for i in input().split()] a.append([s, x, ans]) print(ugaday(a))
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR RETURN VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
class InputHandlerObject(object): inputs = [] def getInput(self, n=0): res = "" inputs = self.inputs if not inputs: inputs.extend(input().split(" ")) if n == 0: res = inputs[:] inputs[:] = [] while n > len(inputs): inputs.extend(input().split(" ")) if n > 0: res = inputs[:n] inputs[:n] = [] return res InputHandler = InputHandlerObject() g = InputHandler.getInput n = int(input().strip()) mn = -2 * 10**9 mx = 2 * 10**9 repl = [(">", "<="), (">=", "<"), ("<=", ">"), ("<", ">=")] for i in range(n): a = g() a[1] = int(a[1]) if a[2] == "N": for qq, qqq in repl: if qq == a[0]: a[0] = qqq break if a[0] == ">": a[1] += 1 if a[0] == "<": a[1] -= 1 if a[0][0] == ">": mn = max(mn, a[1]) if a[0][0] == "<": mx = min(mx, a[1]) if mn <= mx: print(mn) else: print("Impossible")
CLASS_DEF VAR ASSIGN VAR LIST FUNC_DEF NUMBER ASSIGN VAR STRING ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR LIST RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR IF VAR NUMBER STRING VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER NUMBER IF VAR NUMBER NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) lewo = -2 * 10**9 prawo = 2 * 10**9 for i in range(n): buf = input().split(" ") liczba = int(buf[1]) wynik = buf[2] if buf[0] == ">=" and wynik == "Y" or buf[0] == "<" and wynik == "N": lewo = max(lewo, liczba) if buf[0] == "<=" and wynik == "Y" or buf[0] == ">" and wynik == "N": prawo = min(prawo, liczba) if buf[0] == "<" and wynik == "Y" or buf[0] == ">=" and wynik == "N": prawo = min(prawo, liczba - 1) if buf[0] == ">" and wynik == "Y" or buf[0] == "<=" and wynik == "N": lewo = max(lewo, liczba + 1) if lewo > prawo: print("Impossible") else: print(lewo)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING VAR STRING VAR NUMBER STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING VAR STRING VAR NUMBER STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING VAR STRING VAR NUMBER STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING VAR STRING VAR NUMBER STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) li = [] for i in range(n): s = list(input().split(" ")) li.append(s) mx = 2 * 10**9 mi = -mx for i in range(n): if li[i][2] == "Y": if li[i][0] == ">": mi = max(mi, int(li[i][1]) + 1) elif li[i][0] == ">=": mi = max(mi, int(li[i][1])) elif li[i][0] == "<": mx = min(mx, int(li[i][1]) - 1) else: mx = min(mx, int(li[i][1])) elif li[i][0] == ">": mx = min(mx, int(li[i][1])) elif li[i][0] == ">=": mx = min(mx, int(li[i][1]) - 1) elif li[i][0] == "<": mi = max(mi, int(li[i][1])) else: mi = max(mi, int(li[i][1]) + 1) if mi > mx: print("Impossible") else: print(mx)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) s = [] for i in range(n): ef, fr, efw = list(map(str, input().split())) fr = int(fr) s.append([ef, fr, efw]) ODZmax = 2 * 10**9 ODZmin = -(2 * 10**9) for i in range(n): if s[i][0] == ">=" and s[i][2] == "Y": if ODZmin < s[i][1]: ODZmin = s[i][1] elif s[i][0] == ">=" and s[i][2] == "N": if ODZmax > s[i][1] - 1: ODZmax = s[i][1] - 1 elif s[i][0] == ">" and s[i][2] == "N": if ODZmax > s[i][1]: ODZmax = s[i][1] elif s[i][0] == ">" and s[i][2] == "Y": if ODZmin < s[i][1] + 1: ODZmin = s[i][1] + 1 elif s[i][0] == "<" and s[i][2] == "N": if ODZmin < s[i][1]: ODZmin = s[i][1] elif s[i][0] == "<" and s[i][2] == "Y": if ODZmax > s[i][1] - 1: ODZmax = s[i][1] - 1 if s[i][0] == "<=" and s[i][2] == "Y": if ODZmax > s[i][1]: ODZmax = s[i][1] elif s[i][0] == "<=" and s[i][2] == "N": if ODZmin < s[i][1] + 1: ODZmin = s[i][1] + 1 if ODZmin > ODZmax: print("Impossible") else: print(ODZmin)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER STRING VAR VAR NUMBER STRING IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER STRING VAR VAR NUMBER STRING IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER STRING VAR VAR NUMBER STRING IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER STRING VAR VAR NUMBER STRING IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER STRING VAR VAR NUMBER STRING IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER STRING VAR VAR NUMBER STRING IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER STRING VAR VAR NUMBER STRING IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER STRING VAR VAR NUMBER STRING IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input().strip()) r = 2 * 10**9 l = -r def opp(ineq): if ineq == "<": return ">=" elif ineq == "<=": return ">" elif ineq == ">": return "<=" return "<" for i in range(n): ineq, val, ans = input().strip().split(" ") if val[0] == "-": val = -1 * int(val[1:]) else: val = int(val) if ans == "N": ineq = opp(ineq) if ineq == "<": r = min(r, val - 1) elif ineq == "<=": r = min(r, val) elif ineq == ">": l = max(l, val + 1) else: l = max(l, val) if l > r: print("Impossible") else: print(l + r >> 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_DEF IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER STRING ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) ft = [">=", ">", "<=", "<"] sn = -2 * 10**9 mn = -sn for i in range(n): c, num, flag = input().split() cindex = ft.index(c) num = int(num) if flag == "N": cindex = 3 - cindex if cindex == 1: cindex = 0 num += 1 elif cindex == 3: cindex = 2 num -= 1 if cindex == 0 and sn < num: sn = num elif cindex == 2 and mn > num: mn = num if sn <= mn: print(sn) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
t = int(input()) l = -2000000000 r = 2000000000 while t > 0: zn, n, fl = map(str, input().split()) n = int(n) if fl == "Y": if zn == ">": l = max(l, n + 1) elif zn == "<": r = min(r, n - 1) elif zn == ">=": l = max(l, n) elif zn == "<=": r = min(r, n) elif zn == ">": r = min(r, n) elif zn == "<": l = max(l, n) elif zn == ">=": r = min(r, n - 1) elif zn == "<=": l = max(l, n + 1) if r < l: print("Impossible") exit() t -= 1 print((l + r) // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) ma = 2 * 10**9 mi = -2 * 10**9 for i in range(n): x = input() if x[len(x) - 1] == "Y": if x[0] == "<" and x[1] == "=": ma = min(ma, int(x[3 : len(x) - 2])) elif x[0] == "<" and x[1] == " ": if int(x[2 : len(x) - 2]) >= 0: ma = min(ma, int(x[2 : len(x) - 2]) - 1) else: ma = min(ma, int(x[2 : len(x) - 2]) + 1) elif x[0] == ">" and x[1] == "=": mi = max(mi, int(x[3 : len(x) - 2])) elif x[0] == ">" and x[1] == " ": mi = max(mi, int(x[2 : len(x) - 2]) + 1) if x[len(x) - 1] == "N": if x[0] == "<" and x[1] == "=": mi = max(mi, int(x[2 : len(x) - 2]) + 1) elif x[0] == "<" and x[1] == " ": mi = max(mi, int(x[2 : len(x) - 2])) elif x[0] == ">" and x[1] == "=": if int(x[2 : len(x) - 2]) >= 0: ma = min(ma, int(x[2 : len(x) - 2]) - 1) else: ma = min(ma, int(x[2 : len(x) - 2]) + 1) elif x[0] == ">" and x[1] == " ": ma = min(ma, int(x[2 : len(x) - 2])) if ma < mi: print("Impossible") else: print(mi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) i = -2000000000 j = 2000000000 grt = [">", ">="] lwr = ["<", "<="] for _ in range(n): sna = input().split(" ") sign = sna[0] num = int(sna[1]) ans = True if sna[2] == "Y" else False if sign == ">": if ans: i = num + 1 if i < num + 1 else i else: j = num if j > num else j elif sign == ">=": if ans: i = num if i < num else i else: j = num - 1 if j > num - 1 else j elif sign == "<": if ans: j = num - 1 if j > num - 1 else j else: i = num if i < num else i elif sign == "<=": if ans: j = num if j > num else j else: i = num + 1 if i < num + 1 else i if j >= i: print(i) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING ASSIGN VAR LIST STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER STRING NUMBER NUMBER IF VAR STRING IF VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR IF VAR STRING IF VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR STRING IF VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR IF VAR STRING IF VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
nop = {"<": ">=", ">": "<=", "<=": ">", ">=": "<"} vmin, vmax = -(10**9 + 1), 10**9 + 1 for i in range(int(input())): q = input().split() op, x = q[0] if q[2] == "Y" else nop[q[0]], int(q[1]) if op[0] == "<": if op[-1] != "=": x -= 1 vmax = min(vmax, x) elif op[0] == ">": if op[-1] != "=": x += 1 vmin = max(vmin, x) print(vmin if vmin <= vmax else "Impossible")
ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER STRING VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING IF VAR NUMBER STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) left = -(10**9) - 5 right = 10**9 + 5 for i in range(n): op, x, ans = input().split() x = int(x) if op == ">" and ans == "Y": left = max(x + 1, left) elif op == ">": right = min(x, right) if op == "<" and ans == "Y": right = min(x - 1, right) elif op == "<": left = max(x, left) if op == ">=" and ans == "Y": left = max(x, left) elif op == ">=": right = min(x - 1, right) if op == "<=" and ans == "Y": right = min(x, right) elif op == "<=": left = max(x + 1, left) if right < left: print("Impossible") else: print(left)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
def revOP(op): if op == "<": return ">=" if op == "<=": return ">" if op == ">": return "<=" if op == ">=": return "<" n = int(input()) left = -2 * 10**9 right = 2 * 10**9 for i in range(n): arr = list(map(str, input().split())) num = int(arr[1]) oper = arr[0] if arr[2] == "N": oper = revOP(oper) if oper == ">=": if left < num: left = num elif oper == ">": if left < num + 1: left = num + 1 elif oper == "<=": if right > num: right = num elif oper == "<": if right > num - 1: right = num - 1 if left <= right: print(left) else: print("Impossible")
FUNC_DEF IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
import sys n = int(input()) lower = -2 * 10**9 upper = 2 * 10**9 for i in range(n): sign, x, ans = input().split() x = int(x) if ans == "Y" and sign == ">=" or ans == "N" and sign == "<": lower = max(lower, x) elif ans == "Y" and sign == ">" or ans == "N" and sign == "<=": lower = max(lower, x + 1) elif ans == "Y" and sign == "<=" or ans == "N" and sign == ">": upper = min(upper, x) else: upper = min(upper, x - 1) if lower > upper: print("Impossible") sys.exit() print(lower)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l = -2 * 10**9 r = 2 * 10**9 for i in range(n): s = input().split() s[1] = int(s[1]) if s[2] == "Y": if s[0] == ">=": l = max(l, s[1]) elif s[0] == ">": l = max(l, s[1] + 1) elif s[0] == "<=": r = min(r, s[1]) else: r = min(r, s[1] - 1) elif s[0] == ">=": r = min(r, s[1] - 1) elif s[0] == ">": r = min(r, s[1]) elif s[0] == "<=": l = max(l, s[1] + 1) else: l = max(l, s[1]) if l > r: print("Impossible") else: print(l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) low_border = -(10**9) * 2 max_border = 10**9 * 2 def replace_eq_if_nop(eq): return {">": "<=", ">=": "<", "<": ">=", "<=": ">"}[eq] for i in range(n): eq, num, ans = input().split() num = int(num) if ans == "N": eq = replace_eq_if_nop(eq) if eq == ">": low_border = max(low_border, num + 1) elif eq == ">=": low_border = max(low_border, num) elif eq == "<": max_border = min(max_border, num - 1) elif eq == "<=": max_border = min(max_border, num) if low_border > max_border: print("Impossible") else: print(low_border)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN DICT STRING STRING STRING STRING STRING STRING STRING STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) lt = lte = 2 * 10**9 gt = gte = -2 * 10**9 for _ in range(n): t1, t2, t3 = input().split() t2 = int(t2) if t3 == "Y": if t1 == ">=": gte = max(gte, t2) elif t1 == ">": gt = max(gt, t2) elif t1 == "<=": lte = min(lte, t2) else: lt = min(lt, t2) elif t1 == ">=": lt = min(lt, t2) elif t1 == ">": lte = min(lte, t2) elif t1 == "<=": gt = max(gt, t2) else: gte = max(gte, t2) m1 = min(lt - 1, lte) m2 = max(gt + 1, gte) if m1 < m2: print("Impossible") else: print((m1 + m2) // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l, r = -1998638045, 11**11 for _ in range(n): lr, x, yn = input().split() x = int(x) if yn == "Y": if lr == ">": if x + 1 > l: l = x + 1 elif lr == "<": if x - 1 < r: r = x - 1 elif lr == ">=": if x > l: l = x elif x < r: r = x elif lr == ">": if x < r: r = x elif lr == "<": if x > l: l = x elif lr == ">=": if x - 1 < r: r = x - 1 elif x + 1 > l: l = x + 1 if l > r: print("Impossible") else: print(l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
minimum = -2000000000 maximum = 2000000000 n = int(input()) while n > 0: n -= 1 entrada = input().split() q = entrada[0] num = int(entrada[1]) result = entrada[2] if q == ">" and result == "Y": minimum = max(minimum, num + 1) elif q == ">" and result == "N": maximum = min(maximum, num) elif q == ">=" and result == "Y": minimum = max(minimum, num) elif q == ">=" and result == "N": maximum = min(maximum, num - 1) elif q == "<" and result == "Y": maximum = min(maximum, num - 1) elif q == "<" and result == "N": minimum = max(minimum, num) elif q == "<=" and result == "Y": maximum = min(maximum, num) elif q == "<=" and result == "N": minimum = max(minimum, num + 1) if minimum <= maximum: print(minimum) else: print("Impossible")
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
left, right = -2000000000, 2000000000 for _ in range(int(input())): guess, x, answer = input().split() x = int(x) if answer == "N": guess = {">": "<=", "<": ">=", "<=": ">", ">=": "<"}[guess] if guess == ">": if right <= x: print("Impossible") break elif left <= x: left = x + 1 elif guess == ">=": if right < x: print("Impossible") break elif left < x: left = x elif guess == "<": if left >= x: print("Impossible") break elif right >= x: right = x - 1 elif guess == "<=": if left > x: print("Impossible") break elif right > x: right = x else: if left <= right: print(left) else: print("Impossible")
ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING VAR IF VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l = -2 * 10**9 r = 2 * 10**9 for i in range(n): s, v, f = input().split() v = int(v) if f == "N": s = {"<": ">", ">": "<"}[s[0]] + s[1:] if len(s) == 1: s += "=" else: s = s[0] if s[0] == "<": if len(s) != 2: v -= 1 r = min(r, v) else: if len(s) != 2: v += 1 l = max(l, v) if l <= r: print(l) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP DICT STRING STRING STRING STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l = -(10**9) - 3 r = 10**9 + 3 for i in range(n): sign, x, ans = map(str, input().split()) x = int(x) if sign == ">" and ans == "Y" or sign == "<=" and ans == "N": if l <= x: l = x + 1 elif sign == "<" and ans == "Y" or sign == ">=" and ans == "N": if r >= x: r = x - 1 elif sign == ">=" and ans == "Y" or sign == "<" and ans == "N": if x > l: l = x elif sign == "<=" and ans == "Y" or sign == ">" and ans == "N": if x < r: r = x if l <= r: print(l) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
a, b = -(1 << 30), 1 << 30 n = int(input()) for i in range(n): s = input().split() if s[0] == ">" and s[2] == "Y" or s[0] == "<=" and s[2] == "N": a = max(int(s[1]) + 1, a) elif s[0] == ">=" and s[2] == "Y" or s[0] == "<" and s[2] == "N": a = max(int(s[1]), a) elif s[0] == "<" and s[2] == "Y" or s[0] == ">=" and s[2] == "N": b = min(int(s[1]) - 1, b) else: b = min(int(s[1]), b) if a > b: print("Impossible") else: print(a)
ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) lis = [] for i in range(n): lis.append(input().split()) lis1 = [] lis2 = [] for i in range(n): if lis[i][0] == ">=": if lis[i][2] == "Y": lis1.append(int(lis[i][1])) else: lis2.append(int(lis[i][1]) - 1) if lis[i][0] == "<=": if lis[i][2] == "Y": lis2.append(int(lis[i][1])) else: lis1.append(int(lis[i][1]) + 1) if lis[i][0] == ">": if lis[i][2] == "Y": lis1.append(int(lis[i][1]) + 1) else: lis2.append(int(lis[i][1])) if lis[i][0] == "<": if lis[i][2] == "Y": lis2.append(int(lis[i][1]) - 1) else: lis1.append(int(lis[i][1])) if lis1 == []: print(min(lis2)) elif lis2 == []: print(max(lis1)) else: a = max(lis1) b = min(lis2) if a <= b: print(a) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER STRING IF VAR VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
def main(): lo, hi = -2000000000, 2000000001 for _ in range(int(input())): s, x, yn = input().split() if yn == "N": s = {"<": ">=", ">": "<=", "<=": ">", ">=": "<"}[s] x = int(x) + 1 if s in ("<=", ">") else int(x) if s[0] == "<": if hi > x: hi = x elif lo < x: lo = x print((lo + hi) // 2 if lo < hi else "Impossible") main()
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING VAR ASSIGN VAR VAR STRING STRING BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER STRING IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
N = int(input()) lb = float("-inf") ub = float("+inf") def flip(sign): if sign == ">=": return "<" if sign == "<": return ">=" if sign == ">": return "<=" if sign == "<=": return ">" for _ in range(N): sign, x, ans = input().split(" ") x = int(x) if ans == "N": sign, ans = flip(sign), "Y" assert ans == "Y" if sign == ">=": lb = max(lb, x) if sign == ">": lb = max(lb, x + 1) if sign == "<=": ub = min(ub, x) if sign == "<": ub = min(ub, x - 1) if lb <= ub: if lb == float("-inf"): print(ub) else: print(lb) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR STRING VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
def trocaSinal(s): if s == ">=": return "<" if s == "<=": return ">" if s == ">": return "<=" if s == "<": return ">=" n = int(input()) s = [0] * n for i in range(n): s[i] = input() u = 2 * 10**9 l = -2 * 10**9 for i in range(n): t = s[i].split(" ") sinal = t[0] x = int(t[1]) if t[2] == "N": sinal = trocaSinal(sinal) if sinal == ">=": l2 = x l = max(l, l2) elif sinal == ">": l2 = x + 1 l = max(l, l2) elif sinal == "<=": u2 = x u = min(u, u2) elif sinal == "<": u2 = x - 1 u = min(u, u2) if u >= l and abs(l) <= 2 * 10**9: print(l) else: print("Impossible")
FUNC_DEF IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) lower_range, upper_range = -1000000001, 1000000001 for i in range(n): operation, num, correct = input().split(" ") num = int(num) if operation[0] == ">": if correct == "Y": if num >= lower_range: if len(operation) > 1: lower_range = num else: lower_range = num + 1 elif num < upper_range: if len(operation) > 1: upper_range = num - 1 else: upper_range = num if operation[0] == "<": if correct == "Y": if num <= upper_range: if len(operation) > 1: upper_range = num else: upper_range = num - 1 elif num > lower_range: if len(operation) > 1: lower_range = num + 1 else: lower_range = num if lower_range > upper_range: print("Impossible") else: print(lower_range)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING IF VAR STRING IF VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER STRING IF VAR STRING IF VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
def main(): li = -10000000000.0 ul = 10000000000.0 n = int(input()) for _ in range(n): sym, guess, ans = input().split() if sym == ">=": if ans == "Y" and int(guess) > li: li = int(guess) elif ans == "N" and int(guess) < ul: ul = int(guess) - 1 elif sym == ">": if ans == "Y" and int(guess) >= li: li = int(guess) + 1 elif ans == "N" and int(guess) < ul: ul = int(guess) elif sym == "<=": if ans == "Y" and int(guess) < ul: ul = int(guess) elif ans == "N" and int(guess) > li: li = int(guess) + 1 elif sym == "<": if ans == "Y" and int(guess) <= ul: ul = int(guess) - 1 elif ans == "N" and int(guess) > li: li = int(guess) if li <= ul: if abs(li - 0) < abs(ul - 0): print(int(li)) else: print(int(ul)) else: print("Impossible") main()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
l, r = -2000000000, 2000000000 for x in range(int(input())): t, n, a = input().split() if t[0] == ">": n = int(n) + (len(t) == 1) if a == "Y": l = max(l, n) else: r = min(r, n - 1) else: n = int(n) - (len(t) == 1) if a == "Y": r = min(r, n) else: l = max(l, n + 1) if l <= r: print((l + r) // 2) else: print("Impossible")
ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) Q = [] for i in range(0, n): Q.append(list(input().split())) least = -1998638045 max = 1998638045 for q in Q: if q[0] is ">": num = int(q[1]) if q[2] is "Y": if least <= num: least = num + 1 elif max >= num: max = num elif q[0] is "<": num = int(q[1]) if q[2] is "Y": if max >= num: max = num - 1 elif least <= num: least = num elif q[0] == ">=": num = int(q[1]) if q[2] is "Y": if least <= num: least = num elif max >= num: max = num - 1 elif q[0] == "<=": num = int(q[1]) if q[2] is "Y": if max >= num: max = num elif least <= num: least = num + 1 if least <= max: print(least) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) min_y = -2000000000 max_y = 2000000000 Impossible = False def opposite(sign): if sign == ">": return "<=" if sign == "<": return ">=" if sign == "<=": return ">" if sign == ">=": return "<" for i in range(n): sign, number, ans = input().split(" ") if ans == "N": sign = opposite(sign) if sign == ">": min_y = max(min_y, int(number) + 1) if sign == "<": max_y = min(max_y, int(number) - 1) if sign == ">=": min_y = max(min_y, int(number)) if sign == "<=": max_y = min(max_y, int(number)) if max_y < min_y: Impossible = True break if Impossible == True: print("Impossible") else: print(min_y)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l1 = [-2 * 10**9, 2 * 10**9] for i in range(n): inp = list(input().split()) if inp[0] == ">": x = int(inp[1]) if inp[2] == "Y": l1[0] = max(l1[0], x + 1) else: l1[1] = min(l1[1], x) elif inp[0] == "<": x = int(inp[1]) if inp[2] == "N": l1[0] = max(l1[0], x) else: l1[1] = min(l1[1], x - 1) elif inp[0] == "<=": x = int(inp[1]) if inp[2] == "N": l1[0] = max(l1[0], x + 1) else: l1[1] = min(l1[1], x) elif inp[0] == ">=": x = int(inp[1]) if inp[2] == "Y": l1[0] = max(l1[0], x) else: l1[1] = min(l1[1], x - 1) if l1[0] <= l1[1]: print(l1[0]) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST BIN_OP NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) u = 10**9 + 1 l = -u for i in range(n): s = input().split() if s[0] == ">=": if s[2] == "Y": l = max(l, int(s[1])) else: u = min(u, int(s[1]) - 1) if s[0] == ">": if s[2] == "Y": l = max(l, int(s[1]) + 1) else: u = min(u, int(s[1])) if s[0] == "<=": if s[2] == "N": l = max(l, int(s[1]) + 1) else: u = min(u, int(s[1])) if s[0] == "<": if s[2] == "N": l = max(l, int(s[1])) else: u = min(u, int(s[1]) - 1) if l > u: print("Impossible") else: print(u)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) r = [-(10**9 + 7), 10**9 + 7] for _ in range(0, n): s, x, a = map(str, input().split()) if a == "Y": if s == ">=": r[0] = max(r[0], int(x)) elif s == ">": r[0] = max(r[0], int(x) + 1) elif s == "<=": r[1] = min(r[1], int(x)) elif s == "<": r[1] = min(r[1], int(x) - 1) if a == "N": if s == ">=": r[1] = min(r[1], int(x) - 1) elif s == ">": r[1] = min(r[1], int(x)) elif s == "<=": r[0] = max(r[0], int(x) + 1) elif s == "<": r[0] = max(r[0], int(x)) if r[0] <= r[1]: print(r[0]) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) operations = [">=", "<=", ">", "<"] NO = "N" M = 2 * 10**9 greater = [] less = [] for i in range(n): inp = input().split(" ") if inp[0] == operations[0] and inp[2] == NO: inp[0] = operations[3] elif inp[0] == operations[1] and inp[2] == NO: inp[0] = operations[2] elif inp[0] == operations[2] and inp[2] == NO: inp[0] = operations[1] elif inp[0] == operations[3] and inp[2] == NO: inp[0] = operations[0] if inp[0] == operations[0]: greater.append(int(inp[1]) - 1) elif inp[0] == operations[2]: greater.append(int(inp[1])) elif inp[0] == operations[1]: less.append(int(inp[1]) + 1) elif inp[0] == operations[3]: less.append(int(inp[1])) upper = 0 if len(greater) == 0: upper = -1 * M else: upper = greater[0] for i in range(1, len(greater)): if greater[i] > upper: upper = greater[i] lower = 0 if len(less) == 0: lower = M else: lower = less[0] for i in range(1, len(less)): if less[i] < lower: lower = less[i] if upper < -1 * M: upper = -1 * M if lower > M: lower = M if upper > lower - 2: print("Impossible") else: print(upper + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
t = int(input()) u = [] l = [] for j in range(t): x = input().split() if x[0] == ">=" and x[2] == "Y" or x[0] == "<" and x[2] == "N": l.append(int(x[1])) elif x[0] == "<=" and x[2] == "Y" or x[0] == ">" and x[2] == "N": u.append(int(x[1])) elif x[0] == ">" and x[2] == "Y" or x[0] == "<=" and x[2] == "N": l.append(int(x[1]) + 1) else: u.append(int(x[1]) - 1) u.sort() l.sort(reverse=True) if u == []: print(l[0]) elif l == []: print(u[0]) elif l[0] <= u[0]: print(l[0]) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER IF VAR LIST EXPR FUNC_CALL VAR VAR NUMBER IF VAR LIST EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) k = 0 a = [] r = [] h = 0 for i in range(n): a.append(list(map(str, input().split()))) for i in range(n): for j in range(1): if a[i][j] == ">=" and a[i][j + 2] == "Y": if k < int(a[i][j + 1]): k = int(a[i][j + 1]) if a[i][j] == ">=" and a[i][j + 2] == "N": if k >= int(a[i][j + 1]): k = int(a[i][j + 1]) - 1 if a[i][j] == ">" and a[i][j + 2] == "Y": if k <= int(a[i][j + 1]): k = int(a[i][j + 1]) + 1 if a[i][j] == ">" and a[i][j + 2] == "N": if k > int(a[i][j + 1]): k = int(a[i][j + 1]) if a[i][j] == "<=" and a[i][j + 2] == "Y": if k > int(a[i][j + 1]): k = int(a[i][j + 1]) if a[i][j] == "<=" and a[i][j + 2] == "N": if k <= int(a[i][j + 1]): k = int(a[i][j + 1]) + 1 if a[i][j] == "<" and a[i][j + 2] == "Y": if k >= int(a[i][j + 1]): k = int(a[i][j + 1]) - 1 if a[i][j] == "<" and a[i][j + 2] == "N": if k < int(a[i][j + 1]): k = int(a[i][j + 1]) for i in range(n): for j in range(1): if a[i][j] == ">=" and a[i][j + 2] == "Y": if k >= int(a[i][j + 1]): r.append("+") else: r.append("-") if a[i][j] == ">=" and a[i][j + 2] == "N": if k < int(a[i][j + 1]): r.append("+") else: r.append("-") if a[i][j] == ">" and a[i][j + 2] == "Y": if k > int(a[i][j + 1]): r.append("+") else: r.append("-") if a[i][j] == ">" and a[i][j + 2] == "N": if k <= int(a[i][j + 1]): r.append("+") else: r.append("-") if a[i][j] == "<=" and a[i][j + 2] == "Y": if k <= int(a[i][j + 1]): r.append("+") else: r.append("-") if a[i][j] == "<=" and a[i][j + 2] == "N": if k > int(a[i][j + 1]): r.append("+") else: r.append("-") if a[i][j] == "<" and a[i][j + 2] == "Y": if k < int(a[i][j + 1]): r.append("+") else: r.append("-") if a[i][j] == "<" and a[i][j + 2] == "N": if k >= int(a[i][j + 1]): r.append("+") else: r.append("-") for i in range(len(r)): if r[i] == "-": print("Impossible") h = 0 break else: h += 1 if h != 0: print(k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l = -(10**9) - 1 r = 10**9 + 1 while n > 0: n -= 1 s = input().split() if len(s[0]) == 1: if s[0] == ">": if s[2] == "Y": l = max(l, int(s[1]) + 1) else: r = min(r, int(s[1])) elif s[2] == "Y": r = min(int(s[1]) - 1, r) else: l = max(int(s[1]), l) elif s[0] == ">=": if s[2] == "Y": l = max(l, int(s[1])) else: r = min(r, int(s[1]) - 1) elif s[2] == "Y": r = min(int(s[1]), r) else: l = max(int(s[1]) + 1, l) if l <= r: print(l) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
left_border_inclusive = float("-inf") right_border_inclusive = float("inf") inverse_signs = {">": "<=", "<=": ">", ">=": "<", "<": ">="} NUMBERS = int(input()) EXTRA_FINISH = False sign, value = None, None for _ in range(NUMBERS): sign, value, answer = input().split(" ") value = int(value) if answer == "N": sign = inverse_signs[sign] if sign == ">": if value >= right_border_inclusive: EXTRA_FINISH = True break left_border_inclusive = max(left_border_inclusive, value + 1) elif sign == ">=": if value > right_border_inclusive: EXTRA_FINISH = True break left_border_inclusive = max(left_border_inclusive, value) elif sign == "<": if value <= left_border_inclusive: EXTRA_FINISH = True break right_border_inclusive = min(right_border_inclusive, value - 1) elif sign == "<=": if value < left_border_inclusive: EXTRA_FINISH = True break right_border_inclusive = min(right_border_inclusive, value) if not EXTRA_FINISH: if left_border_inclusive == float("-inf"): print(right_border_inclusive) else: print(left_border_inclusive) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NONE NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
bAnswer = True minv = -2000000000 maxv = 2000000000 for _ in range(int(input())): s, d, c = input().split() if s == ">=" and c == "Y": if int(d) >= minv: minv = int(d) elif s == ">=" and c == "N": if int(d) - 1 < maxv: maxv = int(d) - 1 elif s == ">" and c == "Y": if int(d) + 1 >= minv: minv = int(d) + 1 elif s == ">" and c == "N": if int(d) <= maxv: maxv = int(d) elif s == "<=" and c == "Y": if int(d) <= maxv: maxv = int(d) elif s == "<=" and c == "N": if int(d) + 1 >= minv: minv = int(d) + 1 elif s == "<" and c == "Y": if int(d) - 1 <= maxv: maxv = int(d) - 1 elif s == "<" and c == "N": if int(d) >= minv: minv = int(d) if minv > maxv: print("Impossible") bAnswer = False break if bAnswer: print(minv)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING VAR STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input("")) x = 999999999999999999 y = -999999999999999999 p = 0 q = 0 for i in range(0, n): s, v, a = input().split() v = int(v) if a == "Y": if s == ">=": y = max(v, y) p = 1 elif s == ">": v += 1 y = max(v, y) p = 1 elif s == "<=": x = min(v, x) q = 1 elif s == "<": v -= 1 x = min(v, x) q = 1 if a == "N": if s == "<": y = max(v, y) p = 1 elif s == "<=": v += 1 y = max(v, y) p = 1 elif s == ">": x = min(v, x) q = 1 elif s == ">=": v -= 1 x = min(v, x) q = 1 if p == 1 and q == 1: if x >= y: print(y) else: print("Impossible") elif p == 1: print(y) elif q == 1: print(x) elif p == 0 and q == 0: print("1")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) mn = -2000000000 mx = 2000000000 for i in range(n): sign, ber, ans = input().split() num = int(ber) if ans == "N": if sign == "<": sign = ">=" elif sign == "<=": sign = ">" elif sign == ">": sign = "<=" elif sign == ">=": sign = "<" if sign == "<": sign = "<=" num -= 1 if sign == ">": sign = ">=" num += 1 if sign == "<=": mx = min(mx, num) else: mn = max(mn, num) if mx < mn: print("Impossible") else: print(mn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR STRING VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ queries = int(input()) MAX_L = -2000000000 MAX_R = 2000000000 start = MAX_L end = MAX_R for i in range(queries): query = input() operator, n, res = query.split() number = int(n) result = False if res == "Y": result = True if result: if operator == ">": start = max(start, number + 1) elif operator == ">=": start = max(start, number) elif operator == "<": end = min(end, number - 1) else: end = min(end, number) elif operator == ">": end = min(end, number) elif operator == ">=": end = min(end, number - 1) elif operator == "<": start = max(start, number) else: start = max(start, number + 1) possible = True if start > end or end < MAX_L or start > MAX_R: possible = False start = max(MAX_L, start) end = min(MAX_R, end) if not possible: print("Impossible") else: print(start)
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
import sys f = 0 st = -sys.maxsize end = sys.maxsize for _ in range(int(input())): s = input() import sys a, b, c = s.split() if c == "N": if a == ">": a = "<=" elif a == "<": a = ">=" elif a == ">=": a = "<" elif a == "<=": a = ">" c = "Y" if a == "<": end = min(end, int(b) - 1) elif a == "<=": end = min(end, int(b)) elif a == ">": st = max(st, int(b) + 1) elif a == ">=": st = max(st, int(b)) if st > end: f = 1 if f == 1: print("Impossible") else: print((st + end) // 2)
IMPORT ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input("")) z = {} ch = {} tf = {} for i in range(0, n): z[i], ch[i], tf[i] = map(str, input("").split()) ch[i] = int(ch[i]) if z[i] == "<": z[i] = int(1) if z[i] == "<=": z[i] = int(2) if z[i] == ">": z[i] = int(3) if z[i] == ">=": z[i] = int(4) if tf[i] == "N": if z[i] == 1: z[i] = 4 elif z[i] == 2: z[i] = 3 elif z[i] == 3: z[i] = 2 elif z[i] == 4: z[i] = 1 if z[i] == 1: tf[i] = ch[i] - 1 if z[i] == 3: tf[i] = ch[i] + 1 if z[i] == 2 or z[i] == 4: tf[i] = ch[i] def proverka(x, znak, oo): if znak == 1: if x < oo: return 1 else: return 0 elif znak == 2: if x <= oo: return 1 else: return 0 elif znak == 3: if x > oo: return 1 else: return 0 elif znak == 4: if x >= oo: return 1 else: return 0 for i in range(0, n): l = 1 for j in range(0, n): l *= proverka(tf[i], z[j], ch[j]) if l == 0: break if l == 1: print(tf[i]) exit(0) print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
T = int(input()) l = -2000000001 r = 2000000001 while T > 0: T -= 1 A, B, C = input().split() b = int(B) if C == "N": if A == ">=": A = "<" elif A == "<=": A = ">" elif A == ">": A = "<=" else: A = ">=" if A == ">=": b -= 1 if A == "<=": b += 1 if A[0] == ">": l = max(l, b) else: r = min(r, b) if l + 1 >= r: print("Impossible") else: print(l + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
lp = -2 * 10**9 rp = 2 * 10**9 n = int(input()) for i in range(n): s = input() a = s.find(" ") b = s.find(" ", a + 1) sign = s[0:a] value = int(s[a + 1 : b]) ans = s[b + 1 :] if sign == ">": if ans == "Y": lp = max(lp, value + 1) else: rp = min(rp, value) if sign == ">=": if ans == "Y": lp = max(lp, value) else: rp = min(rp, value - 1) if sign == "<": if ans == "Y": rp = min(rp, value - 1) else: lp = max(lp, value) if sign == "<=": if ans == "Y": rp = min(rp, value) else: lp = max(lp, value + 1) if lp <= rp: print((lp + rp) // 2) else: print("Impossible")
ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
d = { "> Y": (0, 1, max), ">= Y": (0, 0, max), "< N": (0, 0, max), "<= N": (0, 1, max), "< Y": (1, -1, min), "<= Y": (1, 0, min), "> N": (1, 0, min), ">= N": (1, -1, min), } ran = [-2000000000, 2000000000] possible = True def analyse(s): ls = s.split(" ") op = d.get(" ".join((ls[0], ls[2]))) ran[op[0]] = op[2](int(ls[1]) + op[1], ran[op[0]]) n = int(input()) for i in range(n): s = input() if possible: analyse(s) if ran[0] > ran[1]: possible = False if possible: print(ran[0]) else: print("Impossible")
ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) questions = [] for _ in range(n): sign, x, answer = list(map(str, input().split())) questions.append((sign, x, answer)) y_min = -1998638045 y_max = +1998638045 for question in questions: sign = question[0] x = int(question[1]) answer = question[2] if sign == ">=" and answer == "Y" or sign == "<" and answer == "N": if x > y_min: y_min = x elif sign == ">" and answer == "Y" or sign == "<=" and answer == "N": if x + 1 > y_min: y_min = x + 1 elif sign == "<=" and answer == "Y" or sign == ">" and answer == "N": if x < y_max: y_max = x elif sign == "<" and answer == "Y" or sign == ">=" and answer == "N": if x - 1 < y_max: y_max = x - 1 if y_max < y_min: print("Impossible") else: print(y_min)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) li = -2 * 10**9 ls = 2 * 10**9 originales = [">", "<", ">=", "<="] inversos = ["<=", ">=", "<", ">"] for i in range(n): condi = input().split() if condi[2] == "Y": if originales.index(condi[0]) % 2 == 0: if condi[0] == ">": if li <= int(condi[1]): li = int(condi[1]) + 1 elif li < int(condi[1]): li = int(condi[1]) elif condi[0] == "<": if ls >= int(condi[1]): ls = int(condi[1]) - 1 elif ls > int(condi[1]): ls = int(condi[1]) elif originales.index(condi[0]) % 2 == 0: if condi[0] == ">": if ls > int(condi[1]): ls = int(condi[1]) elif ls >= int(condi[1]): ls = int(condi[1]) - 1 elif condi[0] == "<": if li < int(condi[1]): li = int(condi[1]) elif li <= int(condi[1]): li = int(condi[1]) + 1 if ls >= li: print(li) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) k = -2000000000 l = 2000000000 for x in range(n): a, z, b = input().split() a = a z = int(z) b = b if a == ">" and b == "Y" and k < z + 1: k = z + 1 elif a == ">=" and b == "Y" and k < z: k = z elif a == ">" and b == "N" and l > z: l = z elif a == ">=" and b == "N" and l > z - 1: l = z - 1 elif a == "<" and b == "Y" and l > z - 1: l = z - 1 elif a == "<=" and b == "Y" and l > z: l = z elif a == "<" and b == "N" and k < z: k = z elif a == "<=" and b == "N" and k < z + 1: k = z + 1 if k <= l: print(k) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR STRING VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING VAR VAR ASSIGN VAR VAR IF VAR STRING VAR STRING VAR VAR ASSIGN VAR VAR IF VAR STRING VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING VAR VAR ASSIGN VAR VAR IF VAR STRING VAR STRING VAR VAR ASSIGN VAR VAR IF VAR STRING VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) m, M = -2000000000, 2000000000 def than(a, more, eq): global m, M if more: m = max(m, a + 1 - eq) else: M = min(M, a - 1 + eq) for i in range(n): _a, _b, _c = input().split() sign = _a number = int(_b) response = _c a = number eq = "=" in sign more = ">" in sign if response == "N": eq = not eq more = not more than(a, more, eq) if m <= M: print(m) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING VAR ASSIGN VAR STRING VAR IF VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l = -float("inf") r = float("inf") kt = True for i in range(n): temp = input().split() if temp[0] == ">": if temp[2] == "Y": l = max(int(temp[1]) + 1, l) else: r = min(int(temp[1]), r) if temp[0] == "<": if temp[2] == "Y": r = min(int(temp[1]) - 1, r) else: l = max(int(temp[1]), l) if temp[0] == ">=": if temp[2] == "Y": l = max(int(temp[1]), l) else: r = min(int(temp[1]) - 1, r) if temp[0] == "<=": if temp[2] == "Y": r = min(int(temp[1]), r) else: l = max(int(temp[1]) + 1, l) if l > r: kt = False if kt == True: if l == float("-inf"): print(r) else: print(l) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) m = 2 * 10**9 d = [-m, m] for i in range(n): a, b, c = input().split() b = int(b) if a == ">=": if c == "Y": d[0] = max(d[0], b) else: d[1] = min(d[1], b - 1) elif a == "<": if c == "Y": d[1] = min(d[1], b - 1) else: d[0] = max(d[0], b) elif a == "<=": if c == "Y": d[1] = min(d[1], b) else: d[0] = max(d[0], b + 1) elif a == ">": if c == "Y": d[0] = max(d[0], b + 1) else: d[1] = min(d[1], b) if d[0] > d[1]: print("Impossible") else: print(int(d[0]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR IF VAR STRING IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) left = -2 * 1000 * 1000 * 1000 right = 2 * 1000 * 1000 * 1000 for i in range(n): s = input().split() r = s[0] x = int(s[1]) a = s[2] if "Y" == a: if ">=" == r: left = max(left, x) if ">" == r: left = max(left, x + 1) if "<=" == r: right = min(right, x) if "<" == r: right = min(right, x - 1) else: if "<" == r: left = max(left, x) if "<=" == r: left = max(left, x + 1) if ">" == r: right = min(right, x) if ">=" == r: right = min(right, x - 1) if left <= right: print(left) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF STRING VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) l = -1000000001 r = 1000000001 for i in range(n): s, x, otv = input().split() x = int(x) if s == ">": if otv == "Y" and l <= x: l = x + 1 elif x <= r and otv == "N": r = x if s == "<": if otv == "Y" and x <= r: r = x - 1 elif x >= l and otv == "N": l = x if s == "<=": if otv == "Y" and x <= r: r = x elif x >= l and otv == "N": l = x + 1 if s == ">=": if otv == "Y" and x >= l: l = x elif x <= r and otv == "N": r = x - 1 if l + 1 <= r and r != -1000000000: print(l + 1) elif l == r and abs(l) != 1000000000: print(l) elif l == -1000000000 and r == 1000000000: print(r - 5) elif r == -1000000000: print(l - 5) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR IF VAR STRING IF VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR IF VAR STRING IF VAR STRING VAR VAR ASSIGN VAR VAR IF VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING VAR VAR ASSIGN VAR VAR IF VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
_ = int(input()) mini = -(10**9) - 1 maxi = 10**9 + 1 for i in range(_): s, n, a = input().split() n = int(n) if a == "Y": if s == ">=": mini = max(mini, n) elif s == ">": mini = max(mini, n + 1) elif s == "<=": maxi = min(maxi, n) elif s == "<": maxi = min(maxi, n - 1) elif s == ">=": maxi = min(maxi, n - 1) elif s == ">": maxi = min(maxi, n) elif s == "<=": mini = max(mini, n + 1) elif s == "<": mini = max(mini, n) if maxi >= mini: print(mini) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
l, h = -2000000000, 2000000000 for _ in range(int(input())): x, y, z = [_ for _ in input().split()] y = int(y) if x == "<=": if z == "Y": if h > y: h = y elif l < y: l = y + 1 if x == "<": if z == "Y": if h > y - 1: h = y - 1 elif l < y: l = y if x == ">=": if z == "Y": if l < y: l = y elif h > y - 1: h = y - 1 if x == ">": if z == "Y": if l < y + 1: l = y + 1 elif h > y: h = y if l > h: print("Impossible") else: print(l)
ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR STRING IF VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
__author__ = "Lipen" def ModeReverse(mode): if mode == ">": return "<=" elif mode == "<": return ">=" elif mode == ">=": return "<" elif mode == "<=": return ">" def main(): n = int(input()) ymin = -2000000000 ymax = 2000000000 for i in range(n): mode, x, ans = input().split() x = int(x) if ans == "N": mode = ModeReverse(mode) if mode == ">": ymin = max(ymin, x + 1) elif mode == "<": ymax = min(ymax, x - 1) elif mode == ">=": ymin = max(ymin, x) elif mode == "<=": ymax = min(ymax, x) if ymin > ymax: print("Impossible") else: print(ymin) main()
ASSIGN VAR STRING FUNC_DEF IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
m, M = -2000000000, 2000000000 n = int(input()) for i in range(n): a, b, c = map(str, input().split()) b = int(b) if c == "Y": if a == ">": m = max(b + 1, m) elif a == ">=": m = max(b, m) elif a == "<": M = min(b - 1, M) elif a == "<=": M = min(M, b) elif a == ">": M = min(b, M) elif a == ">=": M = min(b - 1, M) elif a == "<": m = max(m, b) else: m = max(b + 1, m) if m > M: print("Impossible") else: print(m)
ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
left = -2000000000 right = 2000000000 for _ in range(int(input())): temp = input().split() sign = temp[0] n = int(temp[1]) tf = temp[2] if tf == "Y": if sign == ">" and left <= n: left = n + 1 elif sign == ">=" and left < n: left = n elif sign == "<" and right >= n: right = n - 1 elif sign == "<=" and right > n: right = n elif tf == "N": if sign == ">" and right > n: right = n elif sign == ">=" and right >= n: right = n - 1 elif sign == "<" and left < n: left = n elif sign == "<=" and left <= n: left = n + 1 if left <= right: print(left) else: print("Impossible")
ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING IF VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR VAR ASSIGN VAR VAR IF VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR VAR ASSIGN VAR VAR IF VAR STRING IF VAR STRING VAR VAR ASSIGN VAR VAR IF VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR VAR ASSIGN VAR VAR IF VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) _min = -2 * 10**9 _max = 2 * 10**9 for q in range(n): t, n, ans = input().split() if t == ">": if ans == "Y": _min = max(_min, int(n) + 1) elif ans == "N": _max = min(_max, int(n)) elif t == ">=": if ans == "Y": _min = max(_min, int(n)) elif ans == "N": _max = min(_max, int(n) - 1) elif t == "<": if ans == "Y": _max = min(_max, int(n) - 1) elif ans == "N": _min = max(_min, int(n)) elif t == "<=": if ans == "Y": _max = min(_max, int(n)) elif ans == "N": _min = max(_min, int(n) + 1) if _min > _max: print("Impossible") else: print(_min)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) p = -1000000001 l = 1000000001 for x in range(n): s = input().split() r = int(s[1]) if s[2] == "Y": if s[0] == ">=": p = max(p, r) if s[0] == ">": p = max(p, r + 1) if s[0] == "<=": l = min(l, r) if s[0] == "<": l = min(l, r - 1) else: if s[0] == "<": p = max(p, r) if s[0] == "<=": p = max(p, r + 1) if s[0] == ">": l = min(l, r) if s[0] == ">=": l = min(l, r - 1) if p <= l: print(p) else: print("Impossible")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) i = -2 * 10**9 j = 2 * 10**9 while n > 0: sign, x, ans = input().split() x = int(x) if sign == ">": if ans == "Y": if i < x + 1: i = x + 1 elif j > x - 1: j = x elif sign == ">=": if ans == "Y": if i < x: i = x elif j > x: j = x - 1 elif sign == "<": if ans == "Y": if j > x - 1: j = x - 1 elif i < x + 1: i = x elif ans == "Y": if j > x: j = x elif i < x: i = x + 1 if i > j: break n -= 1 if i > j: print("Impossible") else: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR STRING IF VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
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 sign is: ">" (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 - 10^9 ≤ x ≤ 10^9. 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·10^9 ≤ y ≤ 2·10^9. 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
n = int(input()) questions = [] for _ in range(n): questions.append(input()) lower_bound, upper_bound = None, None for q in questions: bound = int(q.split()[1]) if q.startswith(">") and q.endswith("Y") or q.startswith("<") and q.endswith("N"): if "Y" in q and "=" not in q or "N" in q and "=" in q: bound += 1 lower_bound = bound if lower_bound == None else max(bound, lower_bound) else: if "Y" in q and "=" not in q or "N" in q and "=" in q: bound -= 1 upper_bound = bound if upper_bound == None else min(bound, upper_bound) if lower_bound != None and upper_bound != None and lower_bound > upper_bound: print("Impossible") else: print(lower_bound if lower_bound != None else upper_bound)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NONE NONE FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF STRING VAR STRING VAR STRING VAR STRING VAR VAR NUMBER ASSIGN VAR VAR NONE VAR FUNC_CALL VAR VAR VAR IF STRING VAR STRING VAR STRING VAR STRING VAR VAR NUMBER ASSIGN VAR VAR NONE VAR FUNC_CALL VAR VAR VAR IF VAR NONE VAR NONE VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NONE VAR VAR