#include #include #include using namespace std; using namespace atcoder; using mint = modint1000000007; using ll = long long; bool argsort(const pair& v1, const pair& v2) { auto&[x1, y1] = v1; auto&[x2, y2] = v2; return (x1 * y2 > x2 * y1); } void count(mint& ans, vector >& vectors, ll a_init){ mint last = 0; for(auto[x, y] : vectors){ ll a = a_init; mint s = 0; if(x < 0){ a = -a_init, x = -x; } s += x * last; if(x != 0){ s += floor_sum(x, x, y, 0); } ans += a * s; last += y; } } int main(){ int n; cin >> n; vector > vectors = {}; for(int i = 0; i < n; ++i){ ll x, y; cin >> x >> y; if(x == 0 && y == 0){ continue; } if(y < 0){ x = -x, y = -y; } vectors.push_back({x, y}); } sort(vectors.begin(), vectors.end(), argsort); mint ans = 1; for(auto&[x, y] : vectors){ ans += gcd(x, y); } count(ans, vectors, -1); reverse(vectors.begin(), vectors.end()); count(ans, vectors, 1); cout << ans.val() << endl; return 0; }