Under construction

Still being built. Things may change

Counting Graph Intersections

Time limit2sMemory limit1024 MB

Summary
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.
Level

Medium7 of 10

Topics
Math, Hash map, Sorting
Solved
No attempts yet

Problem

The natural constant e=2.7182818284590452353602874⋯e = 2.7182818284590452353602874\cdots is the base of the natural logarithm. It is known that it can be written as follows.

e=lim⁡t→∞(1+1t)t=∑k=0∞1k!e = \lim_{t \rightarrow \infty} \left(1+\frac{1}{t}\right)^t = \sum_{k=0}^{\infty} \frac{1}{k!}

The graph of a function f:X→Yf : X \rightarrow Y with domain XX and codomain YY is the set of ordered pairs of inputs and outputs, {(x,f(x)):x∈X}\{(x, f(x)) : x \in X\}. If XX and YY 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 (R\mathbb{R}) when ? is * or ^, and all real numbers except 0 (R∖{0}\mathbb{R} \setminus \{0\}) when ? is /. The codomain is the set of real numbers (R\mathbb{R}) 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.

img

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 nn (1≤n≤300,0001 \le n \le 300{,}000). Each of the next nn lines describes one function with an operator ? (one of *, /, ^) and an integer a (−106≤a≤106-10^6 \le a \le 10^6), 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.

Examples2

  1. Example 1

    Input
    3
    * 2
    / -3
    ^ -1
    
    Expected output
    2
    
  2. Example 2

    Input
    5
    * 1
    * 2
    * 3
    * 4
    * 5
    
    Expected output
    1