#include #include #include #define rep(i, l, n) for (int i = (l); i < (n); i++) #define all(x) x.begin(), x.end() using namespace std; using ll = long long; template using V = vector; template using VV = V >; const ll mod = 1000000007; ll floor_sum(ll n, ll m, ll a, ll b) { if (m == 0) { return 0; } ll res = 0; while (true) { if (a >= m or a < 0) { res += n * (n - 1) * (a / m) / 2; a %= m; } if (b >= m or b < 0) { res += n * (b / m); b %= m; } ll y_max = a * n + b; if (y_max < m) { break; } n = y_max / m; b = y_max % m; m = a; a = m; } return res; } ll gcd(ll a, ll b) { a = abs(a); b = abs(b); while (b != 0) { ll r = a % b; a = b; b = r; } return a; } bool arg_sort(const V& v1, const V& v2) { ll x1 = v1[0], y1 = v1[1]; ll x2 = v2[0], y2 = v2[1]; return (x1 * y2 > x2 * y1); } int main(void) { int tmp, n = 0; cin >> tmp; VV v(tmp, V(2)); rep(i, 0, tmp) { ll x, y; cin >> x >> y; if (x == 0 and y == 0) { continue; } if (y < 0) { x = -x; y = -y; } v[n] = { x,y }; n++; } v.resize(n); sort(all(v), arg_sort); ll ans = 1; for (auto& p : v) { ans += gcd(p[0], p[1]); ans %= mod; } ll last = 0; for (auto itr = rbegin(v); itr != rend(v); ++itr) { ll x = (*itr)[0], y = (*itr)[1]; ll a = 1; ll s = 0; if (x < 0) { a = -1; x = -x; } s += floor_sum(x, x, y, 0) % mod + x * last % mod; s %= mod; ans += mod + a * s; ans %= mod; last += mod + y; last %= mod; } last = 0; for (auto& p : v) { ll x = p[0], y = p[1]; ll a = -1; ll s = 0; if (x < 0) { a = 1; x = -x; } s += floor_sum(x, x, y, 0) % mod + x * last % mod; s %= mod; ans += mod + a * s; ans %= mod; last += mod + y; last %= mod; } cout << ans << endl; return 0; }