This page is still under construction.

Parts of this page are still being built. What you see may change.

Rational Dimasik

Time limit2sMemory limit512 MB

Summary
Given n fractions, compute the product, over all pairs, of the denominator of their difference written in lowest terms, modulo 998244353.
Level

Hard9 of 10

Topics
Number theory, Math, Combinatorics, Sorting
Solved
No attempts yet

Problem

Little Dimasik is a fan of rational numbers. He has nn rational numbers xiyi\frac{x_i}{y_i}. Recently Dimasik learned how to subtract rational numbers.

Every rational number can be written uniquely as an irreducible fraction ab\frac{a}{b}, where aa and bb are coprime integers and b>0b > 0.

Define the function d(xiyi)d \left( \frac{x_i}{y_i} \right) as the denominator of the rational number xiyi\frac{x_i}{y_i} in irreducible form. For example, d(146)=d(73)=3d(\frac{14}{6}) = d(\frac{7}{3}) = 3.

Now Dimasik wants to compute ∏1≤i<j≤nd(∣xiyi−xjyj∣).\prod\limits_{1 \le i < j \le n} d \left( \left| \frac{x_i}{y_i} - \frac{x_j}{y_j} \right| \right)\text{.} But he soon realized that this problem is too hard for him. Dimasik asks you to help him. The value may be very large, so find it modulo 998 244 353998\,244\,353.

Input

The first line contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5), the number of rational numbers Dimasik has.

Each of the following nn lines contains two integers xix_i and yiy_i (0≤xi≤1090 \le x_i \le 10^{9}, 1≤yi≤1061 \le y_i \le 10^6), the numerator and denominator of the ii-th rational number.

Output

Print a single integer: the answer to the problem modulo 998 244 353998\,244\,353.

Examples2

  1. Example 1

    Input
    2
    1 3
    3 7
    
    Expected output
    21
    
  2. Example 2

    Input
    3
    3 2
    7 15
    5 12
    
    Expected output
    7200