Counting Graph Intersections
Time limit2sMemory limit1024 MB
Count the distinct points where the graphs of n functions y=e*(ax), y=e/(ax), and y=e^(ax) meet, for integer a and given operators.
Problem
The natural constant is the base of the natural logarithm. It is known that it can be written as follows.
The graph of a function with domain and codomain is the set of ordered pairs of inputs and outputs, . If and are both sets of real numbers, the points of the graph can be drawn on a two-dimensional coordinate plane.
The functions in this problem have the form y=e?(ax). Here ? is one of the multiplication operator *, the division operator /, or the exponentiation operator ^, and a is an integer. If the operator is /, then a is guaranteed not to be 0.
The domain is all real numbers () when ? is * or ^, and all real numbers except 0 () when ? is /. The codomain is the set of real numbers () in every case. So every function in this problem can be drawn on the coordinate plane.
The figure shows graphs of a few functions for different operators ? and integers a.

Write a program that counts the distinct intersection points when the graphs of all the given functions are drawn on the coordinate plane. A point is an intersection if it belongs to at least two of the graphs. If a point belongs to three or more graphs, it is counted once. The figure has 2 intersection points.
Input
The first line contains the number of functions (). Each of the next lines describes one function with an operator ? (one of *, /, ^) and an integer a (), separated by a single space. All given functions are distinct. If ? is /, then a is not 0.
Output
Print the number of intersection points when the graphs of all the given functions are drawn on the coordinate plane.