#B3800. Safe Spot in Bullet Hell

    ID: 11457 Type: Default 1000ms 256MiB

Safe Spot in Bullet Hell

Safe Spot in Bullet Hell

In this problem, you are given a bullet-hell game scenario where the boss emits several "bullet patterns" that may hit the player. There are ( n ) bullets in the air and each bullet is described by a triple ( (a_i, b_i, c_i) ). The player is located on a one-dimensional axis labelled from ( 0, 1, 2, \dots, 10^6 ) and can only stand on integer positions.

The bullet ( i ) will hit the player if and only if, when the player is at position ( x ), the following equation holds: [ x^3 + a_i x^2 + b_i x + c_i = 0. ] Your task is to find any integer ( x ) in the range ( [0, 10^6] ) such that the player is not hit by any of the bullets, i.e. for every ( i ) (( 1 \le i \le n )): [ x^3 + a_i x^2 + b_i x + c_i \ne 0. ] It is guaranteed that at least one such position exists.

inputFormat

The first line contains a single integer ( n ), representing the number of bullets. Each of the next ( n ) lines contains three space-separated integers ( a_i ), ( b_i ), and ( c_i ), which are the parameters of the ( i )-th bullet.

outputFormat

Output a single integer ( x ) (where ( 0 \le x \le 10^6 )) such that for all ( 1 \le i \le n ), the condition ( x^3 + a_i x^2 + b_i x + c_i \ne 0 ) holds.

sample

1
0 0 -1
0