#P7923. Solving a System of Linear Inequalities

    ID: 21108 Type: Default 1000ms 256MiB

Solving a System of Linear Inequalities

Solving a System of Linear Inequalities

In this problem, you are given a system of nn linear inequalities in one variable. Each inequality is in its simplest form and is given as an expression like x<tix<t_i, xtix\le t_i, x>tix>t_i, or xtix\ge t_i, where xx is a lowercase English letter representing the unknown, and tit_i is an integer constant. Note that in the input, the operators \le and \ge are represented as <= and >=, respectively.

Your task is to compute the solution set of the entire system, which is the intersection of the solution sets of all the individual inequalities. If the intersection is empty, output empty. If the solution set is the entire set of real numbers, output all. If the intersection reduces to a single point, output it in the form x = c (which is equivalent to x ≥ c and x ≤ c). Otherwise, if one or both bounds are finite, output the result using the same format as the input (for the lower bound, use x > c or x ≥ c, and for the upper bound, use x < c or x ≤ c). For a bounded solution with both a lower and an upper bound, output the answer as lower_condition and upper_condition (for example, x ≥ 1 and x < 5).

inputFormat

The first line contains an integer nn (1n1051 \le n \le 10^5), the number of inequalities. Each of the next nn lines contains a string representing an inequality. Each inequality is of the form x<value, x>value, x<=value, or x>=value, where x is a lowercase letter (all inequalities use the same variable) and value is an integer (which may be negative). There are no spaces in the input.

outputFormat

Output a single line string representing the solution set of the system. Use the following rules:

  1. If the solution set is empty, output empty.
  2. If the solution set is the set of all real numbers, output all.
  3. If there is only a single point (i.e. x=cx=c), output it as x = c.
  4. Otherwise, if a lower bound exists, output it as x > c or x ≥ c depending on whether the inequality is strict or not; similarly for an upper bound with x < c or x ≤ c. If both bounds exist, join them with and .

sample

3
x>=1
x0
x>=1 and x<5