Problem:
カフェオレ
問題
$N$ 個のカフェオレがあります。
$i$ 番目のカフェオレは、コーヒー $c_i$ グラムとミルク $m_i$ グラムが混ざった $c_i + m_i$ グラムのカフェオレです。
これらを混ぜ合わせることで、コーヒー $x$ グラムとミルク $y$ グラムが混ざった $x + y$ グラムのカフェオレを作ることを考えます。
具体的には、 $i$ 番目のカフェオレを $p_i$ ($0 \leq p_i \leq 1$) の割合だけ使用した場合、
$\displaystyle \sum_{i=1}^N p_i c_i = x$
$\displaystyle \sum_{i=1}^N p_i m_i = y$
として、コーヒーが $x$ グラム、ミルクが $y$ グラムのカフェオレが作られます。
このようなカフェオレを作れる $1$ 以上の整数の組 $(x, y)$ の個数を $10^9 + 7$ で割った余りを出力してください。
制約
$1 \leq N \leq 10^5$
$1 \leq c_i, m_i \leq 10^9$ ($1 \leq i \leq N$)
入力
$N$
$c_1$ $m_1$
$\vdots$
$c_N$ $m_N$
出力
作れるカフェオレのうち、コーヒーの量とミルクの量が $1$ 以上の整数となるようなものの個数を $10^9 + 7$ で割った余りを $1$ 行で出力してください。
入力例 1
2
1 1
1 3
出力例 1
4
あり得るコーヒーの量 $x$ とミルクの量 $y$ の組み合わせ $(x, y)$ を全て列挙すると、下記のようになります。
$(x, y) = (1, 1), (1, 2), (1, 3), (2, 4)$
入力例 2
3
1 1
1 3
3 1
出力例 2
15
入力例 3
3
1 1
2 2
3 3
出力例 3
6

Submitted solutions:

code_snippet: // AOJ #3217 Cafe au lait
// 2025.5.28

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {
	int n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) {
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int gcd(int a, int b) {
	int r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

bool upper(const pair<int, int>& v){
    return (v.second > 0) || (v.second == 0 && v.first > 0);
}

int main(){
    int N = Cin();
    vector<pair<int, int>> v(N);
    for(int i = 0; i < N; i++){
        int c = Cin(), m = Cin();
        v[i] = {c, m};
    }

    ll sum = 0;
    for(auto &p : v) sum = (sum + gcd(p.first, p.second)) % MOD;

    sort(v.begin(), v.end(), [](auto &a, auto &b){
        bool ua = upper(a), ub = upper(b);
        if(ua != ub) return ua;
        return (ll)a.first * b.second - (ll)a.second * b.first > 0;
    });

    ll A = 0, sc = 0, sm = 0;
    for(int i = 0; i < N; i++){
        int x = v[i].first, y = v[i].second;
        A = (A + (sc * y % MOD) - (sm * x % MOD)) % MOD;
        if (A < 0) A += MOD;
        sc = (sc + x) % MOD;
        sm = (sm + y) % MOD;
    }
    Cout((A + sum) % MOD);
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3772
final_rank: 1

code_snippet: // AOJ #3217 Cafe au lait
// 2025.5.28

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {
	int n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) {
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

bool upper(const pair<ll,ll>& v){
    return (v.second > 0) || (v.second == 0 && v.first > 0);
}

int main(){
    int N = Cin();
    vector<pair<ll,ll>> v(N);
    for(int i=0;i<N;i++){
        int c = Cin(), m = Cin();
        v[i] = {c, m};
    }

    ll sum_g = 0;
    for(auto &p : v) sum_g = (sum_g + __gcd(p.first, p.second)) % MOD;

    sort(v.begin(), v.end(), [](auto &a, auto &b){
        bool ua = upper(a), ub = upper(b);
        if(ua != ub) return ua;
        return a.first * b.second - a.second * b.first > 0;
    });

    ll A = 0;
    ll sc = 0, sm = 0;
    for(int i=0;i<N;i++){
        ll x = v[i].first % MOD;
        ll y = v[i].second % MOD;
        A = (A + (sc * y % MOD) - (sm * x % MOD) + MOD) % MOD;
        sc = (sc + x) % MOD;
        sm = (sm + y) % MOD;
    }
    Cout((A + sum_g) % MOD);
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4512
final_rank: 2

code_snippet: //
// floor sum
//
// verified
//   Yosupo Library Checker - Sum of Floor of Linear
//     https://judge.yosupo.jp/problem/sum_of_floor_of_linear
//
//   AtCoder ABC 283 Ex - Popcount Sum
//     https://atcoder.jp/contests/abc283/tasks/abc283_h
//
//   AOJ 3217 Cafe au lait (OUPC 2020 I)
//     https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3217
//
//   yukicoder No.2066 Simple Math !
//     https://yukicoder.me/problems/no/2066
//


#include <bits/stdc++.h>
using namespace std;

/*
 sum_{i=0}^{n-1} floor((a * i + b) / m)
 O(log(n + m + a + b))
 
 __int128 can be used for T
 */

// sum_{i=0}^{n-1} floor((a * i + b) / m)
template<class T> T floor_sum(T n, T a, T b, T m) {
    assert(n >= 0 && m >= 1);
    T res = 0;
    if (a < 0) {
        T a2 = (a % m + m) % m;
        res -= n * (n - 1) / 2 * ((a2 - a) / m);
        a = a2;
    }
    if (b < 0) {
        T b2 = (b % m + m) % m;
        res -= n * ((b2 - b) / m);
        b = b2;
    }
    
    while (true) {
        if (a >= m) {
            res += n * (n - 1) / 2 * (a / m);
            a %= m;
        }
        if (b >= m) {
            res += n * (b / m);
            b %= m;
        }
        T y_max = a * n + b;
        if (y_max < m) break;
        n = y_max / m;
        b = y_max % m;
        swap(m, a);
    }
    return res;
}

// #lp under (and on) the segment (x1, y1)-(x2, y2)
// not including y = 0, x = x2
template<class T> T num_lattice_points(T x1, T y1, T x2, T y2) {
    T dx = x2 - x1;
    return floor_sum(dx, y2 - y1, dx * y1, dx);
}


// often use
struct i128 {
    // inner value
    __int128 val;
    
    // constructor
    constexpr i128() : val(0) {}
    constexpr i128(long long v) : val(v) {}
    i128(const string &s) : val(0) {
        parse(s);
    }
    void parse(const string &s) {
        val = 0;
        for (auto c : s) {
            if (isdigit(c)) val = val * 10 + (c - '0');
        }
        if (s[0] == '-') val *= -1;
    }
    constexpr __int128 get() const {
        return val;
    }
    constexpr i128 abs() {
        if (val < 0) return -val;
        else return val;
    }
    
    // comparison operators
    constexpr bool operator == (const i128 &r) const {
        return this->val == r.val;
    }
    constexpr bool operator != (const i128 &r) const {
        return this->val != r.val;
    }
    constexpr bool operator < (const i128 &r) const {
        return this->val < r.val;
    }
    constexpr bool operator > (const i128 &r) const {
        return this->val > r.val;
    }
    constexpr bool operator <= (const i128 &r) const {
        return this->val <= r.val;
    }
    constexpr bool operator >= (const i128 &r) const {
        return this->val >= r.val;
    }
    
    // arithmetic operators
    constexpr i128& operator += (const i128 &r) {
        val += r.val;
        return *this;
    }
    constexpr i128& operator -= (const i128 &r) {
        val -= r.val;
        return *this;
    }
    constexpr i128& operator *= (const i128 &r) {
        val *= r.val;
        return *this;
    }
    constexpr i128& operator /= (const i128 &r) {
        val /= r.val;
        return *this;
    }
    constexpr i128& operator %= (const i128 &r) {
        val %= r.val;
        return *this;
    }
    constexpr i128 operator + () const {
        return i128(*this);
    }
    constexpr i128 operator - () const {
        return i128(0) - i128(*this);
    }
    constexpr i128 operator + (const i128 &r) const {
        return i128(*this) += r;
    }
    constexpr i128 operator - (const i128 &r) const {
        return i128(*this) -= r;
    }
    constexpr i128 operator * (const i128 &r) const {
        return i128(*this) *= r;
    }
    constexpr i128 operator / (const i128 &r) const {
        return i128(*this) /= r;
    }
    constexpr i128 operator % (const i128 &r) const {
        return i128(*this) %= r;
    }
    
    // other operators
    constexpr i128& operator ++ () {
        ++val;
        return *this;
    }
    constexpr i128& operator -- () {
        --val;
        return *this;
    }
    constexpr i128 operator ++ (int) {
        i128 res = *this;
        ++*this;
        return res;
    }
    constexpr i128 operator -- (int) {
        i128 res = *this;
        --*this;
        return res;
    }
    friend istream& operator >> (istream &is, i128 &x) {
        string s;
        is >> s;
        x.parse(s);
        return is;
    }
    friend ostream& operator << (ostream &os, const i128 &x) {
        auto tmp = x.val < 0 ? -x.val : x.val;
        char buffer[128];
        char *d = end(buffer);
        do {
            --d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (x.val < 0) {
            --d;
            *d = '-';
        }
        int len = end(buffer) - d;
        if (os.rdbuf()->sputn(d, len) != len) {
            os.setstate(ios_base::badbit);
        }
        return os;
    }
};



/*/////////////////////////////*/
// Examples
/*/////////////////////////////*/

// Library Checker
void YosupoSumOfFloorOfLinear() {
    int T;
    cin >> T;
    while (T--) {
        long long N, M, A, B;
        cin >> N >> M >> A >> B;
        cout << floor_sum(N, A, B, M) << endl;
    }
}

// AOJ 3217
void AOJ_3217() {
    const int MOD = 1000000007;
    struct mint {
        long long val;
        mint(long long v = 0) : val(v % MOD) {
            if (val < 0) val += MOD;
        }
        int getmod() const { return MOD; }
        mint operator - () const {
            return val ? MOD - val : 0;
        }
        mint operator + (const mint& r) const { return mint(*this) += r; }
        mint operator - (const mint& r) const { return mint(*this) -= r; }
        mint operator * (const mint& r) const { return mint(*this) *= r; }
        mint operator / (const mint& r) const { return mint(*this) /= r; }
        mint& operator += (const mint& r) {
            val += r.val;
            if (val >= MOD) val -= MOD;
            return *this;
        }
        mint& operator -= (const mint& r) {
            val -= r.val;
            if (val < 0) val += MOD;
            return *this;
        }
        mint& operator *= (const mint& r) {
            val = val * r.val % MOD;
            return *this;
        }
        mint& operator /= (const mint& r) {
            long long a = r.val, b = MOD, u = 1, v = 0;
            while (b) {
                long long t = a / b;
                a -= t * b, swap(a, b);
                u -= t * v, swap(u, v);
            }
            val = val * u % MOD;
            if (val < 0) val += MOD;
            return *this;
        }
        bool operator == (const mint& r) const {
            return this->val == r.val;
        }
        bool operator != (const mint& r) const {
            return this->val != r.val;
        }
    };

    int N;
    cin >> N;
    vector<long long> X(N), Y(N);
    for (int i = 0; i < N; ++i) cin >> X[i] >> Y[i];
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) {
        return Y[i]*X[j] < Y[j]*X[i];
    });
    mint res = 0;
    long long sy = 0;
    for (auto i : ids) {
        res -= mint(X[i]) * mint(sy);
        res -= num_lattice_points(0LL, 0LL, X[i], Y[i]);
        res += gcd(X[i], Y[i]);
        sy += Y[i];
    }
    reverse(ids.begin(), ids.end());
    sy = 0;
    for (auto i : ids) {
        res += mint(X[i]) * mint(sy);
        res += num_lattice_points(0LL, 0LL, X[i], Y[i]);
        sy += Y[i];
    }
    cout << res.val << endl;
}

/* yukicoder No.2066 */
// calc #n that can be expressed n =  Px + Qy (P, Q is coprime)
// 0 <= n <= M
i128 calc_num(i128 P, i128 Q, i128 M) {
    i128 mp = M / P;
    i128 N = min(mp + 1, Q);
    i128 a = P, b = M + Q - a * (N - 1);
    return floor_sum(N, a, b, Q) - 1;
}

void Yukicoder_2066() {
    int CASE;
    cin >> CASE;
    while (CASE--) {
        long long P, Q, K;
        cin >> P >> Q >> K;

        long long G = gcd(P, Q);
        P /= G, Q /= G;

        long long low = -1, high = 1LL<<50;
        while (high - low > 1) {
            long long M = (low + high) / 2;
            if (calc_num(P, Q, M) >= K) high = M;
            else low = M;
        }
        cout << high * G << endl;
    }
}


int main() {
    //YosupoSumOfFloorOfLinear();
    AOJ_3217();
    //Yukicoder_2066();
}
accuracy: 1
time_ms: 110
memory_kb: 4920
final_rank: 6

code_snippet: //
// floor sum
//
// verified
//   Yosupo Library Checker - Sum of Floor of Linear
//     https://judge.yosupo.jp/problem/sum_of_floor_of_linear
//
//   AtCoder ABC 283 Ex - Popcount Sum
//     https://atcoder.jp/contests/abc283/tasks/abc283_h
//
//   AOJ 3217 Cafe au lait (OUPC 2020 I)
//     https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3217
//
//   yukicoder No.2066 Simple Math !
//     https://yukicoder.me/problems/no/2066
//


#include <bits/stdc++.h>
using namespace std;

/*
 sum_{i=0}^{n-1} floor((a * i + b) / m)
 O(log(n + m + a + b))
 
 __int128 can be used for T
 */

// sum_{i=0}^{n-1} floor((a * i + b) / m)
template<class T> T floor_sum(T n, T a, T b, T m) {
    assert(n >= 0 && m >= 1);
    T res = 0;
    if (a < 0) {
        T a2 = (a % m + m) % m;
        res -= n * (n - 1) / 2 * ((a2 - a) / m);
        a = a2;
    }
    if (b < 0) {
        T b2 = (b % m + m) % m;
        res -= n * ((b2 - b) / m);
        b = b2;
    }
    
    while (true) {
        if (a >= m) {
            res += n * (n - 1) / 2 * (a / m);
            a %= m;
        }
        if (b >= m) {
            res += n * (b / m);
            b %= m;
        }
        T y_max = a * n + b;
        if (y_max < m) break;
        n = y_max / m;
        b = y_max % m;
        swap(m, a);
    }
    return res;
}

// #lp under (and on) the segment (x1, y1)-(x2, y2)
// not including y = 0, x = x2
template<class T> T num_lattice_points(T x1, T y1, T x2, T y2) {
    T dx = x2 - x1;
    return floor_sum(dx, y2 - y1, dx * y1, dx);
}


// often use
struct i128 {
    // inner value
    __int128 val;
    
    // constructor
    constexpr i128() : val(0) {}
    constexpr i128(long long v) : val(v) {}
    constexpr i128(const string &s) : val(0) {
        parse(s);
    }
    void parse(const string &s) {
        val = 0;
        for (const char c : s) {
            if (c >= '0' && c <= '9') val = val * 10 + (c - '0');
        }
        if (s[0] == '-') val *= -1;
    }
    constexpr __int128 get() const {
        return val;
    }
    constexpr i128 abs() {
        if (val < 0) return -val;
        else return val;
    }
    
    // comparison operators
    constexpr bool operator == (const i128 &r) const {
        return this->val == r.val;
    }
    constexpr bool operator != (const i128 &r) const {
        return this->val != r.val;
    }
    constexpr bool operator < (const i128 &r) const {
        return this->val < r.val;
    }
    constexpr bool operator > (const i128 &r) const {
        return this->val > r.val;
    }
    constexpr bool operator <= (const i128 &r) const {
        return this->val <= r.val;
    }
    constexpr bool operator >= (const i128 &r) const {
        return this->val >= r.val;
    }
    
    // arithmetic operators
    constexpr i128& operator += (const i128 &r) {
        val += r.val;
        return *this;
    }
    constexpr i128& operator -= (const i128 &r) {
        val -= r.val;
        return *this;
    }
    constexpr i128& operator *= (const i128 &r) {
        val *= r.val;
        return *this;
    }
    constexpr i128& operator /= (const i128 &r) {
        val /= r.val;
        return *this;
    }
    constexpr i128& operator %= (const i128 &r) {
        val %= r.val;
        return *this;
    }
    constexpr i128 operator + () const {
        return i128(*this);
    }
    constexpr i128 operator - () const {
        return i128(0) - i128(*this);
    }
    constexpr i128 operator + (const i128 &r) const {
        return i128(*this) += r;
    }
    constexpr i128 operator - (const i128 &r) const {
        return i128(*this) -= r;
    }
    constexpr i128 operator * (const i128 &r) const {
        return i128(*this) *= r;
    }
    constexpr i128 operator / (const i128 &r) const {
        return i128(*this) /= r;
    }
    constexpr i128 operator % (const i128 &r) const {
        return i128(*this) %= r;
    }
    
    // other operators
    constexpr i128& operator ++ () {
        ++val;
        return *this;
    }
    constexpr i128& operator -- () {
        --val;
        return *this;
    }
    constexpr i128 operator ++ (int) {
        i128 res = *this;
        ++*this;
        return res;
    }
    constexpr i128 operator -- (int) {
        i128 res = *this;
        --*this;
        return res;
    }
    friend istream& operator >> (istream &is, i128 &x) {
        string s;
        is >> s;
        x.parse(s);
        return is;
    }
    friend ostream& operator << (ostream &os, const i128 &x) {
        auto tmp = x.val < 0 ? -x.val : x.val;
        char buffer[128];
        char *d = end(buffer);
        do {
            --d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (x.val < 0) {
            --d;
            *d = '-';
        }
        int len = end(buffer) - d;
        if (os.rdbuf()->sputn(d, len) != len) {
            os.setstate(ios_base::badbit);
        }
        return os;
    }
};



/*/////////////////////////////*/
// Examples
/*/////////////////////////////*/

// Library Checker
void YosupoSumOfFloorOfLinear() {
    int T;
    cin >> T;
    while (T--) {
        long long N, M, A, B;
        cin >> N >> M >> A >> B;
        cout << floor_sum(N, A, B, M) << endl;
    }
}

// AOJ 3217
void AOJ_3217() {
    const int MOD = 1000000007;
    struct mint {
        long long val;
        mint(long long v = 0) : val(v % MOD) {
            if (val < 0) val += MOD;
        }
        int getmod() const { return MOD; }
        mint operator - () const {
            return val ? MOD - val : 0;
        }
        mint operator + (const mint& r) const { return mint(*this) += r; }
        mint operator - (const mint& r) const { return mint(*this) -= r; }
        mint operator * (const mint& r) const { return mint(*this) *= r; }
        mint operator / (const mint& r) const { return mint(*this) /= r; }
        mint& operator += (const mint& r) {
            val += r.val;
            if (val >= MOD) val -= MOD;
            return *this;
        }
        mint& operator -= (const mint& r) {
            val -= r.val;
            if (val < 0) val += MOD;
            return *this;
        }
        mint& operator *= (const mint& r) {
            val = val * r.val % MOD;
            return *this;
        }
        mint& operator /= (const mint& r) {
            long long a = r.val, b = MOD, u = 1, v = 0;
            while (b) {
                long long t = a / b;
                a -= t * b, swap(a, b);
                u -= t * v, swap(u, v);
            }
            val = val * u % MOD;
            if (val < 0) val += MOD;
            return *this;
        }
        bool operator == (const mint& r) const {
            return this->val == r.val;
        }
        bool operator != (const mint& r) const {
            return this->val != r.val;
        }
    };

    int N;
    cin >> N;
    vector<long long> X(N), Y(N);
    for (int i = 0; i < N; ++i) cin >> X[i] >> Y[i];
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) {
        return Y[i]*X[j] < Y[j]*X[i];
    });
    mint res = 0;
    long long sy = 0;
    for (auto i : ids) {
        res -= mint(X[i]) * mint(sy);
        res -= num_lattice_points(0LL, 0LL, X[i], Y[i]);
        res += gcd(X[i], Y[i]);
        sy += Y[i];
    }
    reverse(ids.begin(), ids.end());
    sy = 0;
    for (auto i : ids) {
        res += mint(X[i]) * mint(sy);
        res += num_lattice_points(0LL, 0LL, X[i], Y[i]);
        sy += Y[i];
    }
    cout << res.val << endl;
}

/* yukicoder No.2066 */
// calc #n that can be expressed n =  Px + Qy (P, Q is coprime)
// 0 <= n <= M
i128 calc_num(i128 P, i128 Q, i128 M) {
    i128 mp = M / P;
    i128 N = min(mp + 1, Q);
    i128 a = P, b = M + Q - a * (N - 1);
    return floor_sum(N, a, b, Q) - 1;
}

void Yukicoder_2066() {
    int CASE;
    cin >> CASE;
    while (CASE--) {
        long long P, Q, K;
        cin >> P >> Q >> K;

        long long G = gcd(P, Q);
        P /= G, Q /= G;

        long long low = -1, high = 1LL<<50;
        while (high - low > 1) {
            long long M = (low + high) / 2;
            if (calc_num(P, Q, M) >= K) high = M;
            else low = M;
        }
        cout << high * G << endl;
    }
}


int main() {
    //YosupoSumOfFloorOfLinear();
    AOJ_3217();
    //Yukicoder_2066();
}
accuracy: 1
time_ms: 110
memory_kb: 4944
final_rank: 7

code_snippet: //
// floor sum
//
// verified
//   AtCoder ABC 283 Ex - Popcount Sum
//     https://atcoder.jp/contests/abc283/tasks/abc283_h
//
//   OUPC 2020 I - Cafe au lait
//     https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3217
//
//   yukicoder 2066 No.2066 Simple Math !
//     https://yukicoder.me/problems/no/2066
//


#include <bits/stdc++.h>
using namespace std;


// sum_{i=0}^{n-1} floor((a * i + b) / m)
// O(log(n + m + a + b))
// __int128 can be used for T
template<class T> T floor_sum(T n, T a, T b, T m) {
    if (n == 0) return 0;
    T res = 0;
    if (a >= m) {
        res += n * (n - 1) * (a / m) / 2;
        a %= m;
    }
    if (b >= m) {
        res += n * (b / m);
        b %= m;
    }
    if (a == 0) return res;
    T ymax = (a * n + b) / m, xmax = ymax * m - b;
    if (ymax == 0) return res;
    res += (n - (xmax + a - 1) / a) * ymax;
    res += floor_sum(ymax, m, (a - xmax % a) % a, a);
    return res;
}

// #lp under (and on) the segment (x1, y1)-(x2, y2)
// not including y = 0, x = x2
template<class T> T num_lattice_points(T x1, T y1, T x2, T y2) {
    T dx = x2 - x1;
    return floor_sum(dx, y2 - y1, dx * y1, dx);
}


/////////////////////////////////////////
// Solvers
/////////////////////////////////////////

// calc #n that can be expressed n =  Px + Qy (P, Q is coprime)
// 0 <= n <= M
long long calc_num(__int128 P, __int128 Q, __int128 M) {
    __int128 mp = M / P;
    __int128 N = min(mp + 1, Q);
    __int128 a = P, b = M + Q - a * (N - 1);
    return floor_sum(N, a, b, Q) - 1;
}

void solveYukicoder2066() {
    int CASE;
    cin >> CASE;
    while (CASE--) {
        long long P, Q, K;
        cin >> P >> Q >> K;

        long long G = gcd(P, Q);
        P /= G, Q /= G;

        long long low = -1, high = 1LL<<50;
        while (high - low > 1) {
            long long M = (low + high) / 2;
            if (calc_num(P, Q, M) >= K) high = M;
            else low = M;
        }
        cout << high * G << endl;
    }
}



// modint
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() const { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept {
        is >> x.val;
        x.val %= MOD;
        if (x.val < 0) x.val += MOD;
        return is;
    }
    friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD>& r, long long n) noexcept {
        if (n == 0) return 1;
        if (n < 0) return modpow(modinv(r), -n);
        auto t = modpow(r, n / 2);
        t = t * t;
        if (n & 1) t = t * r;
        return t;
    }
    friend constexpr Fp<MOD> modinv(const Fp<MOD>& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        return Fp<MOD>(u);
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

long long GCD(long long x, long long y) {
    return y ? GCD(y, x % y) : x;
}

int main() {
    int N;
    cin >> N;
    vector<long long> X(N), Y(N);
    for (int i = 0; i < N; ++i) cin >> X[i] >> Y[i];
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) {
        return Y[i]*X[j] < Y[j]*X[i];
    });
    mint res = 0;
    long long sy = 0;
    for (auto i : ids) {
        res -= mint(X[i]) * mint(sy);
        res -= num_lattice_points(0LL, 0LL, X[i], Y[i]);
        res += GCD(X[i], Y[i]);
        sy += Y[i];
    }
    reverse(ids.begin(), ids.end());
    sy = 0;
    for (auto i : ids) {
        res += mint(X[i]) * mint(sy);
        res += num_lattice_points(0LL, 0LL, X[i], Y[i]);
        sy += Y[i];
    }
    cout << res << endl;
}

/*
int main() {
    solveYukicoder2066();
}
*/
accuracy: 1
time_ms: 200
memory_kb: 4932
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=2167167167167167167;
const int INF=2100000000;
const ll mod=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}
template<class T> T min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T sum(vector<T> &a){assert(!a.empty());T ans=a[0]-a[0];for(auto &x:a) ans+=x;return ans;}

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N;
	cin>>N;
	vector<ll> X(N),Y(N);
	vector<int> order(N);
	rep(i,N) cin>>X[i]>>Y[i],order[i]=i;
	sort(all(order),[&](int l,int r){
		return X[l]*Y[r]<X[r]*Y[l];
	});
	ll ans=0;
	ll R=(mod+1)/2;
	auto f=[&]()->ll{
		ll val=0;
		ll S=0;
		rep(i,N){
			int a=order[i];
			val=(val+S*X[a])%mod;
			ll tmp=((X[a]+1)*(Y[a]+1))%mod;
			tmp=(tmp+(__gcd(X[a],Y[a])))*R;
			tmp%=mod;
			val=(val+tmp)%mod;
			S=(S+Y[a])%mod;
		}
		return val;
	};
	ans=f();
	reverse(all(order));
	ans-=f();
	rep(i,N) ans=(ans+__gcd(X[i],Y[i]))%mod;
	cout<<(ans+mod)%mod<<"\n";
}
accuracy: 1
time_ms: 70
memory_kb: 5196
final_rank: 5

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
using ull = long long;
#define endl "\n"
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(x) begin(x), end(x)
#define all(s) (s).begin(),(s).end()
//#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
//#define rep(i, n) rep2(i, 0, n)
#define PB push_back 
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define fi first
#define se second
#define pb push_back
#define P pair<ll,ll>
#define NP next_permutation
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 4500000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}}
template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;}
void yes(bool a){cout<<(a?"yes":"no")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; }
void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; }
void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; }
template<class T>auto min(const T& a){ return *min_element(all(a)); }
template<class T>auto max(const T& a){ return *max_element(all(a)); }
template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<typename T,typename ...Args>auto make_vector(T x,int arg,Args ...args){if constexpr(sizeof...(args)==0)return vector<T>(arg,x);else return vector(arg,make_vector<T>(x,args...));}
ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; }
template<class T>
struct Sum{
  vector<T> data;
  Sum(const vector<T>& v):data(v.size()+1){
    for(ll i=0;i<v.size();i++) data[i+1]=data[i]+v[i];
  }
  T get(ll l,ll r) const {
    return data[r]-data[l];
  }
};
template<class T>
struct Sum2{
  vector<vector<T>> data;
  Sum2(const vector<vector<T>> &v):data(v.size()+1,vector<T>(v[0].size()+1)){
    for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]=data[i][j+1]+v[i][j];
    for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]+=data[i+1][j];
  }
  T get(ll x1,ll y1,ll x2,ll y2) const {
    return data[x2][y2]+data[x1][y1]-data[x1][y2]-data[x2][y1];
  }
};

void cincout(){
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(20);
}

int main() {
  cincout();
  ll n;
  cin>>n;
  vector<P> a(n);
  for(int i=0;i<n;i++) cin>>a[i].fi>>a[i].se;
  sort(all(a),[&](P x,P y){
    return x.se*y.fi<y.se*x.fi;
  });
  ll ans=0;
  vector<P> t;
  t.pb({0,0});
  for(int i=0;i<n;i++){
    ll x=t[i].fi,y=t[i].se;
    t.pb({x+a[i].fi,y+a[i].se});
  }
  for(int i=0;i<n-1;i++){
    ll x=t[n+i].fi,y=t[n+i].se;
    t.pb({x-a[i].fi,y-a[i].se});
  }
  ll menseki=0;
  ll u=t.size();
  for(int i=0;i<t.size();i++){
    menseki+=(t[i].fi%mod)*(t[(i+1)%u].se%mod)-(t[i].se%mod)*(t[(i+1)%u].fi%mod);
    menseki%=mod;
    menseki+=mod;
    menseki%=mod;
  }
  ll hen=0;
//  cout<<menseki<<endl;
  for(int i=0;i<t.size();i++){
    hen+=gcd(abs(t[i].fi-t[(i+1)%u].fi),abs(t[i].se-t[(i+1)%u].se));
    hen%=mod;
  }
 // cout<<hen<<" "<<menseki<<" "<<u<<endl;
  cout<<(hen+menseki)%mod*modPow(2,mod-2,mod)%mod<<endl;
}
accuracy: 1
time_ms: 60
memory_kb: 10548
final_rank: 11

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
using ull = long long;
#define endl "\n"
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(x) begin(x), end(x)
#define all(s) (s).begin(),(s).end()
//#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
//#define rep(i, n) rep2(i, 0, n)
#define PB push_back 
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define fi first
#define se second
#define pb push_back
#define P pair<ll,ll>
#define NP next_permutation
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 4500000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}}
template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;}
void yes(bool a){cout<<(a?"yes":"no")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; }
void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; }
void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; }
template<class T>auto min(const T& a){ return *min_element(all(a)); }
template<class T>auto max(const T& a){ return *max_element(all(a)); }
template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<typename T,typename ...Args>auto make_vector(T x,int arg,Args ...args){if constexpr(sizeof...(args)==0)return vector<T>(arg,x);else return vector(arg,make_vector<T>(x,args...));}
ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; }
template<class T>
struct Sum{
  vector<T> data;
  Sum(const vector<T>& v):data(v.size()+1){
    for(ll i=0;i<v.size();i++) data[i+1]=data[i]+v[i];
  }
  T get(ll l,ll r) const {
    return data[r]-data[l];
  }
};
template<class T>
struct Sum2{
  vector<vector<T>> data;
  Sum2(const vector<vector<T>> &v):data(v.size()+1,vector<T>(v[0].size()+1)){
    for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]=data[i][j+1]+v[i][j];
    for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]+=data[i+1][j];
  }
  T get(ll x1,ll y1,ll x2,ll y2) const {
    return data[x2][y2]+data[x1][y1]-data[x1][y2]-data[x2][y1];
  }
};

void cincout(){
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(20);
}

int main() {
  cincout();
  ll n;
  cin>>n;
  vector<P> a(n);
  for(int i=0;i<n;i++) cin>>a[i].fi>>a[i].se;
  sort(all(a),[&](P x,P y){
    return x.se*y.fi<y.se*x.fi;
  });
  ll ans=0;
  vector<P> t;
  t.pb({0,0});
  for(int i=0;i<n;i++){
    ll x=t[i].fi,y=t[i].se;
    t.pb({x+a[i].fi,y+a[i].se});
  }
  for(int i=0;i<n-1;i++){
    ll x=t[n+i].fi,y=t[n+i].se;
    t.pb({x-a[i].fi,y-a[i].se});
  }
  ll menseki=0;
  ll u=t.size();
  for(int i=0;i<t.size();i++){
    menseki+=(t[i].fi%mod)*(t[(i+1)%u].se%mod)-(t[i].se%mod)*(t[(i+1)%u].fi%mod);
    menseki%=mod;
    menseki+=mod;
    menseki%=mod;
  }
  ll hen=0;
//  cout<<menseki<<endl;
  for(int i=0;i<t.size();i++){
    hen+=gcd(abs(t[i].fi-t[(i+1)%u].fi),abs(t[i].se-t[(i+1)%u].se));
    hen%=mod;
  }
 // cout<<hen<<" "<<menseki<<" "<<u<<endl;
  cout<<(hen+menseki)%mod*modPow(2,mod-2,mod)%mod<<endl;
}
accuracy: 1
time_ms: 60
memory_kb: 10540
final_rank: 10

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
using ull = long long;
#define endl "\n"
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(x) begin(x), end(x)
#define all(s) (s).begin(),(s).end()
//#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
//#define rep(i, n) rep2(i, 0, n)
#define PB push_back 
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define fi first
#define se second
#define pb push_back
#define P pair<ll,ll>
#define NP next_permutation
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 4500000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}}
template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;}
void yes(bool a){cout<<(a?"yes":"no")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; }
void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; }
void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; }
template<class T>auto min(const T& a){ return *min_element(all(a)); }
template<class T>auto max(const T& a){ return *max_element(all(a)); }
template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<typename T,typename ...Args>auto make_vector(T x,int arg,Args ...args){if constexpr(sizeof...(args)==0)return vector<T>(arg,x);else return vector(arg,make_vector<T>(x,args...));}
ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; }
template<class T>
struct Sum{
  vector<T> data;
  Sum(const vector<T>& v):data(v.size()+1){
    for(ll i=0;i<v.size();i++) data[i+1]=data[i]+v[i];
  }
  T get(ll l,ll r) const {
    return data[r]-data[l];
  }
};
template<class T>
struct Sum2{
  vector<vector<T>> data;
  Sum2(const vector<vector<T>> &v):data(v.size()+1,vector<T>(v[0].size()+1)){
    for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]=data[i][j+1]+v[i][j];
    for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]+=data[i+1][j];
  }
  T get(ll x1,ll y1,ll x2,ll y2) const {
    return data[x2][y2]+data[x1][y1]-data[x1][y2]-data[x2][y1];
  }
};

void cincout(){
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(20);
}

int main() {
  cincout();
  ll n;
  cin>>n;
  vector<P> a(n);
  for(int i=0;i<n;i++) cin>>a[i].fi>>a[i].se;
  sort(all(a),[&](P x,P y){
    return x.se*y.fi<y.se*x.fi;
  });
  ll ans=0;
  vector<P> t;
  t.pb({0,0});
  for(int i=0;i<n;i++){
    ll x=t[i].fi,y=t[i].se;
    t.pb({x+a[i].fi,y+a[i].se});
  }
  for(int i=0;i<n-1;i++){
    ll x=t[n+i].fi,y=t[n+i].se;
    t.pb({x-a[i].fi,y-a[i].se});
  }
  ll menseki=0;
  ll u=t.size();
  for(int i=0;i<t.size();i++){
    menseki+=t[i].fi*t[(i+1)%u].se-t[i].se*t[(i+1)%u].fi;
    menseki%=mod;
    menseki+=mod;
    menseki%=mod;
  }
  ll hen=0;
  for(int i=0;i<t.size();i++){
    hen+=gcd(abs(t[i].fi-t[(i+1)%u].fi),abs(t[i].se-t[(i+1)%u].se));
    hen%=mod;
  }
 // cout<<hen<<" "<<menseki<<" "<<u<<endl;
  cout<<(hen+menseki)%mod*modPow(2,mod-2,mod)%mod<<endl;
}
accuracy: 0.2
time_ms: 50
memory_kb: 10708
final_rank: 14

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
using ull = long long;
#define endl "\n"
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(x) begin(x), end(x)
#define all(s) (s).begin(),(s).end()
//#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
//#define rep(i, n) rep2(i, 0, n)
#define PB push_back 
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define fi first
#define se second
#define pb push_back
#define P pair<ll,ll>
#define NP next_permutation
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 4500000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}}
template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;}
void yes(bool a){cout<<(a?"yes":"no")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; }
void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; }
void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; }
template<class T>auto min(const T& a){ return *min_element(all(a)); }
template<class T>auto max(const T& a){ return *max_element(all(a)); }
template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<typename T,typename ...Args>auto make_vector(T x,int arg,Args ...args){if constexpr(sizeof...(args)==0)return vector<T>(arg,x);else return vector(arg,make_vector<T>(x,args...));}
ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; }
template<class T>
struct Sum{
  vector<T> data;
  Sum(const vector<T>& v):data(v.size()+1){
    for(ll i=0;i<v.size();i++) data[i+1]=data[i]+v[i];
  }
  T get(ll l,ll r) const {
    return data[r]-data[l];
  }
};
template<class T>
struct Sum2{
  vector<vector<T>> data;
  Sum2(const vector<vector<T>> &v):data(v.size()+1,vector<T>(v[0].size()+1)){
    for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]=data[i][j+1]+v[i][j];
    for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]+=data[i+1][j];
  }
  T get(ll x1,ll y1,ll x2,ll y2) const {
    return data[x2][y2]+data[x1][y1]-data[x1][y2]-data[x2][y1];
  }
};

void cincout(){
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(20);
}

int main() {
  cincout();
  ll n;
  cin>>n;
  vector<P> a(n);
  for(int i=0;i<n;i++) cin>>a[i].fi>>a[i].se;
  sort(all(a),[&](P x,P y){
    return x.se*y.fi<y.se*x.fi;
  });
  ll ans=0;
  vector<P> t;
  t.pb({0,0});
  for(int i=0;i<n;i++){
    ll x=t[i].fi,y=t[i].se;
    t.pb({x+a[i].fi,y+a[i].se});
  }
  for(int i=0;i<n;i++){
    ll x=t[n+i].fi,y=t[n+i].se;
    t.pb({x-a[i].fi,y-a[i].se});
  }
  ll menseki=0;
  ll u=t.size();
  for(int i=0;i<t.size();i++){
    menseki+=t[i].fi*t[(i+1)%u].se-t[i].se*t[(i+1)%u].fi;
    menseki%=mod;
    menseki+=mod;
    menseki%=mod;
  }
  ll hen=0;
  for(int i=0;i<t.size();i++){
    hen+=gcd(abs(t[i].fi-t[(i+1)%u].fi),abs(t[i].se-t[(i+1)%u].se));
    hen%=mod;
  }
//  cout<<hen<<" "<<menseki<<" "<<u<<endl;
  cout<<(hen+menseki)%mod*modPow(2,mod-2,mod)%mod<<endl;
}
accuracy: 0.2
time_ms: 50
memory_kb: 9688
final_rank: 12

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
using ull = long long;
#define endl "\n"
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(x) begin(x), end(x)
#define all(s) (s).begin(),(s).end()
//#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
//#define rep(i, n) rep2(i, 0, n)
#define PB push_back 
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define fi first
#define se second
#define pb push_back
#define P pair<ll,ll>
#define NP next_permutation
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 4500000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}}
template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;}
void yes(bool a){cout<<(a?"yes":"no")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; }
void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; }
void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; }
template<class T>auto min(const T& a){ return *min_element(all(a)); }
template<class T>auto max(const T& a){ return *max_element(all(a)); }
template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<typename T,typename ...Args>auto make_vector(T x,int arg,Args ...args){if constexpr(sizeof...(args)==0)return vector<T>(arg,x);else return vector(arg,make_vector<T>(x,args...));}
ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; }
template<class T>
struct Sum{
  vector<T> data;
  Sum(const vector<T>& v):data(v.size()+1){
    for(ll i=0;i<v.size();i++) data[i+1]=data[i]+v[i];
  }
  T get(ll l,ll r) const {
    return data[r]-data[l];
  }
};
template<class T>
struct Sum2{
  vector<vector<T>> data;
  Sum2(const vector<vector<T>> &v):data(v.size()+1,vector<T>(v[0].size()+1)){
    for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]=data[i][j+1]+v[i][j];
    for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]+=data[i+1][j];
  }
  T get(ll x1,ll y1,ll x2,ll y2) const {
    return data[x2][y2]+data[x1][y1]-data[x1][y2]-data[x2][y1];
  }
};

void cincout(){
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(20);
}

int main() {
  cincout();
  ll n;
  cin>>n;
  vector<P> a(n);
  for(int i=0;i<n;i++) cin>>a[i].fi>>a[i].se;
  sort(all(a),[&](P x,P y){
    return x.se*y.fi<y.se*x.fi;
  });
  ll ans=0;
  vector<P> t;
  t.pb({0,0});
  for(int i=0;i<n;i++){
    ll x=t[i].fi,y=t[i].se;
    t.pb({x+a[i].fi,y+a[i].se});
  }
  for(int i=0;i<n;i++){
    ll x=t[n+i].fi,y=t[n+i].se;
    t.pb({x-a[i].fi,y-a[i].se});
  }
  ll menseki=0;
  ll u=t.size();
  for(int i=0;i<t.size();i++){
    menseki+=t[i].fi*t[(i+1)%u].se-t[i].se*t[(i+1)%u].fi;
    menseki%=mod;
    menseki+=mod;
    menseki%=mod;
  }
  ll hen=0;
  for(int i=0;i<t.size();i++){
    hen+=gcd(abs(t[i].fi-t[(i+1)%u].fi),abs(t[i].se-t[(i+1)%u].se));
  }
//  cout<<hen<<" "<<menseki<<" "<<u<<endl;
  cout<<(hen+menseki)%mod*modPow(2,mod-2,mod)%mod<<endl;
}
accuracy: 0.2
time_ms: 60
memory_kb: 10300
final_rank: 13

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    struct Point {
        ll x, y;
    };
    int N;
    cin >> N;
    vector<Point> bases(N);
    rep(i,0,N) cin >> bases[i].x >> bases[i].y;
    sort(all(bases), [](const Point& a, const Point& b){
        // ya / xa > yb / xb <=> ya * xb > yb * xa
        return a.y * b.x > b.y * a.x;
    });
    vector<Point> points = {{0, 0}};
    rep(i,0,N) {
        points.emplace_back(Point{points.back().x + bases[i].x, points.back().y + bases[i].y});
    }
    rep(i,0,N) {
        points.emplace_back(Point{points.back().x - bases[i].x, points.back().y - bases[i].y});
    }
    assert(points.back().x == 0 && points.back().y == 0);
    // S = i + b / 2 - 1
    ll S = 0, s = 0;
    rep(i,0,points.size()-1) {
        ll add = abs(points[i].x * points[i+1].y - points[i+1].x * points[i].y);
        if (add % 2 == 1) {
            s++;
            add--;
        }
        S += add / 2;
        S %= MOD;
    }
    assert(s % 2 == 0);
    S += s / 2;
    S %= MOD;
    ll b = 2 * N;
    rep(i,0,points.size()-1) {
        ll dx = abs(points[i].x - points[i+1].x), dy = abs(points[i].y - points[i+1].y);
        b += gcd(dx, dy) - 1;
    }
    assert(b % 2 == 0);
    ll i = (S + 1 - b / 2 + points.size() * MOD) % MOD;
    cout << (b + i + MOD - 1) % MOD << endl;
    return 0;
}
accuracy: 0.2
time_ms: 80
memory_kb: 9668
final_rank: 16

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    struct Point {
        ll x, y;
    };
    int N;
    cin >> N;
    vector<Point> bases(N);
    rep(i,0,N) cin >> bases[i].x >> bases[i].y;
    sort(all(bases), [](const Point& a, const Point& b){
        // ya / xa > yb / xb <=> ya * xb > yb * xa
        return a.y * b.x > b.y * a.x;
    });
    vector<Point> points = {{0, 0}};
    rep(i,0,N) {
        points.emplace_back(Point{points.back().x + bases[i].x, points.back().y + bases[i].y});
    }
    rep(i,0,N) {
        points.emplace_back(Point{points.back().x - bases[i].x, points.back().y - bases[i].y});
    }
    assert(points.back().x == 0 && points.back().y == 0);
    // S = i + b / 2 - 1
    ll S = 0, s = 0;
    rep(i,0,points.size()-1) {
        ll add = abs(points[i].x * points[i+1].y - points[i+1].x * points[i].y);
        if (add % 2 == 1) {
            s++;
            add--;
        }
        S += add / 2;
        S %= MOD;
    }
    assert(s % 2 == 0);
    S += s / 2;
    S %= MOD;
    ll b = 2 * N;
    rep(i,0,points.size()-1) {
        ll dx = abs(points[i].x - points[i+1].x), dy = abs(points[i].y - points[i+1].y);
        b += gcd(dx, dy) - 1;
    }
    assert(b % 2 == 0);
    ll i = (S + 1 - b / 2 + MOD) % MOD;
    cout << (b + i + MOD - 1) % MOD << endl;
    return 0;
}
accuracy: 0.2
time_ms: 80
memory_kb: 10360
final_rank: 17

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    struct Point {
        ll x, y;
    };
    int N;
    cin >> N;
    vector<Point> bases(N);
    rep(i,0,N) cin >> bases[i].x >> bases[i].y;
    sort(all(bases), [](const Point& a, const Point& b){
        // ya / xa > yb / xb <=> ya * xb > yb * xa
        return a.y * b.x > b.y * a.x;
    });
    vector<Point> points = {{0, 0}};
    rep(i,0,N) {
        points.emplace_back(Point{points.back().x + bases[i].x, points.back().y + bases[i].y});
    }
    rep(i,0,N) {
        points.emplace_back(Point{points.back().x - bases[i].x, points.back().y - bases[i].y});
    }
    assert(points.back().x == 0 && points.back().y == 0);
    // S = i + b / 2 - 1
    ll S = 0, s = 0;
    rep(i,0,points.size()-1) {
        ll add = abs(points[i].x * points[i+1].y - points[i+1].x * points[i].y);
        if (add % 2 == 1) {
            s++;
            add--;
        }
        S += add / 2;
        S %= MOD;
    }
    assert(s % 2 == 0);
    S += s / 2;
    S %= MOD;
    ll b = 2 * N;
    rep(i,0,points.size()-1) {
        ll dx = abs(points[i].x - points[i+1].x), dy = abs(points[i].y - points[i+1].y);
        b += gcd(dx, dy) - 1;
    }
    assert(b % 2 == 0);
    ll i = (S + 1 - b / 2 + MOD) % MOD;
    cout << (b + i - 1) % MOD << endl;
    return 0;
}
accuracy: 0.2
time_ms: 80
memory_kb: 9552
final_rank: 14

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    struct Point {
        ll x, y;
    };
    int N;
    cin >> N;
    vector<Point> bases(N);
    rep(i,0,N) cin >> bases[i].x >> bases[i].y;
    sort(all(bases), [](const Point& a, const Point& b){
        // ya / xa > yb / xb <=> ya * xb > yb * xa
        return a.y * b.x > b.y * a.x;
    });
    vector<Point> points = {{0, 0}};
    rep(i,0,N) {
        points.emplace_back(Point{points.back().x + bases[i].x, points.back().y + bases[i].y});
    }
    rep(i,0,N) {
        points.emplace_back(Point{points.back().x - bases[i].x, points.back().y - bases[i].y});
    }
    assert(points.back().x == 0 && points.back().y == 0);
    // S = i + b / 2 - 1
    ll S2 = 0;
    rep(i,0,points.size()-1) {
        S2 += abs(points[i].x * points[i+1].y - points[i+1].x * points[i].y);
        S2 %= MOD;
    }
    ll b = 2 * N;
    rep(i,0,points.size()-1) {
        ll dx = abs(points[i].x - points[i+1].x), dy = abs(points[i].y - points[i+1].y);
        b += gcd(dx, dy) - 1;
        b %= MOD;
    }
    ll i = (S2 - b) / 2 + 1;
    cout << (b + i - 1) % MOD << endl;
    return 0;
}
accuracy: 0.05714285714285714
time_ms: 40
memory_kb: 8908
final_rank: 19

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    struct Point {
        ll x, y;
    };
    int N;
    cin >> N;
    vector<Point> bases(N);
    rep(i,0,N) cin >> bases[i].x >> bases[i].y;
    sort(all(bases), [](const Point& a, const Point& b){
        // ya / xa > yb / xb <=> ya * xb > yb * xa
        return a.y * b.x > b.y * a.x;
    });
    vector<Point> points = {{0, 0}};
    rep(i,0,N) {
        points.emplace_back(Point{points.back().x + bases[i].x, points.back().y + bases[i].y});
    }
    rep(i,0,N) {
        points.emplace_back(Point{points.back().x - bases[i].x, points.back().y - bases[i].y});
    }
    assert(points.back().x == 0 && points.back().y == 0);
    // S = i + b / 2 - 1
    ll S = 0;
    rep(i,0,points.size()-1) {
        S += abs(points[i].x * points[i+1].y - points[i+1].x * points[i].y);
        S %= MOD;
    }
    assert(S % 2 == 0);
    S /= 2;
    ll b = 2 * N;
    rep(i,0,points.size()-1) {
        ll dx = abs(points[i].x - points[i+1].x), dy = abs(points[i].y - points[i+1].y);
        b += gcd(dx, dy) - 1;
        b %= MOD;
    }
    assert(b % 2 == 0);
    ll i = S + 1 - b / 2;
    cout << b + i - 1 << endl;
    return 0;
}
accuracy: 0.05714285714285714
time_ms: 40
memory_kb: 8780
final_rank: 18

code_snippet: #include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
#include <sstream>
#include <bitset>
#include <complex>
#include <chrono>
#include <cassert>

using namespace std;

constexpr long long int MOD = 1000'000'007;
struct Vector {
	long long int x, y;
	Vector operator+(const Vector other) const {
		return Vector{ (x + other.x) % MOD, (y + other.y) % MOD };
	}
	Vector operator-(const Vector other)const {
		return Vector{ (x - other.x) % MOD, (y - other.y) % MOD };
	}

};

long long int gcd(const long long int a, const long long int b) {
	return b == 0 ? a : gcd(b, a % b);
}
long long int power(const long long base, const int exp) {
	switch (exp) {
	case 0: return 1ll;
	case 1: return base % MOD;
	default: return power(base * base % MOD, exp >> 1) * power(base, exp & 1) % MOD;
	}
}
int main() {
	int n; cin >> n;
	vector<Vector> vec(n);
	for (auto& [x, y] : vec) cin >> x >> y;
	sort(vec.rbegin(), vec.rend(), [](const Vector a, const Vector b) {return a.y * b.x < b.y* a.x; });
	Vector last_pos{ 0, 0 };
	long long int on_line{ 0 };
	long long int area{ 0 };
	for (const auto v : vec) {
		const auto next = last_pos + v;
		area += (last_pos.y + next.y) * (next.x - last_pos.x) % MOD;
		on_line += gcd(v.x, v.y);
		last_pos = next;
		area %= MOD;
		on_line %= MOD;
	}
	for (const auto v : vec) {
		const auto next = last_pos - v;
		area += (last_pos.y + next.y) * (next.x - last_pos.x) % MOD;
		on_line += gcd(v.x, v.y);
		last_pos = next;
		area %= MOD;
		on_line %= MOD;
	}
	const auto in = ((area + on_line) % MOD + MOD) * power(2, MOD - 2) % MOD;
	cout << in << '\n';
}
accuracy: 1
time_ms: 80
memory_kb: 4616
final_rank: 4

code_snippet: #include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
#include <sstream>
#include <bitset>
#include <complex>
#include <chrono>
#include <cassert>

using namespace std;

struct Vector {
	long long int x, y;
	Vector operator+(const Vector other) const {
		return Vector{ x + other.x, y + other.y };
	}
	Vector operator-(const Vector other)const {
		return Vector{ x - other.x, y - other.y };
	}

};

long long int gcd(const long long int a, const long long int b) {
	return b == 0 ? a : gcd(b, a % b);
}
constexpr long long int MOD = 1000'000'007;
long long int power(const long long base, const int exp) {
	switch (exp) {
	case 0: return 1ll;
	case 1: return base % MOD;
	default: return power(base * base % MOD, exp >> 1) * power(base, exp & 1) % MOD;
	}
}
int main() {
	int n; cin >> n;
	vector<Vector> vec(n);
	for (auto& [x, y] : vec) cin >> x >> y;
	sort(vec.rbegin(), vec.rend(), [](const Vector a, const Vector b) {return a.y * b.x < b.y* a.x; });
	Vector last_pos{ 0, 0 };
	long long int on_line{ 0 };
	long long int area{ 0 };
	for (const auto v : vec) {
		const auto next = last_pos + v;
		area += (last_pos.y + next.y) * (next.x - last_pos.x) % MOD;
		on_line += gcd(v.x, v.y);
		last_pos = next;
		area %= MOD;
		on_line %= MOD;
	}
	for (const auto v : vec) {
		const auto next = last_pos - v;
		area += (last_pos.y + next.y) * (next.x - last_pos.x) % MOD;
		on_line += gcd(v.x, v.y);
		last_pos = next;
		area %= MOD;
		on_line %= MOD;
	}
	const auto in = (area + on_line) * power(2, MOD - 2) % MOD;
	cout << in << '\n';
}
accuracy: 0.02857142857142857
time_ms: 40
memory_kb: 4028
final_rank: 20

code_snippet: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
using namespace std;
typedef long long int LL;
typedef pair<LL,LL> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}


long long int gcd(long long int a,long long int b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    return gcd(b,a%b);
}

int main(){
    LL n,m;
    int i,j,k;
    LL a,b,c;
    vector<P> v1;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;
        v1.push_back(make_pair(a,b));
    }
    sort(v1.begin(),v1.end(),[](P pa,P pb){
        return pa.first*pb.second<pa.second*pb.first;
    });
    LL s=0,s2=0;
    c=0;
    for(i=0;i<n;i++){
        a=v1[i].first,b=v1[i].second;
        s2+=c*b%MAX;
        s2+=((a+1)*(b+1)-gcd(a,b)-1)/2%MAX;
        c+=a;
        c%=MAX;
    }
    s2%=MAX,a=0,b=0;
    for(i=0;i<n;i++){
        a+=v1[i].first,b+=v1[i].second;
    }
    s=(a%MAX+1)*(b%MAX+1)-s2*2-1;
    if(s<0)s+=MAX*3;
    s%=MAX;
    cout<<s<<endl;
}
accuracy: 1
time_ms: 70
memory_kb: 4892
final_rank: 3

code_snippet: //
// floor sum
//
// verified
//   OUPC 2020 I - カフェオレ
//     https://onlinejudge.u-aizu.ac.jp/beta/room.html#OUPC2020/problems/I
//


#include <bits/stdc++.h>
using namespace std;


// sum_{i=0}^{n-1} floor((a * i + b) / m)
// O(log(n + m + a + b))
long long floor_sum(long long n, long long a, long long b, long long m) {
    if (n == 0) return 0;
    long long res = 0;
    if (a >= m) {
        res += n * (n - 1) * (a / m) / 2;
        a %= m;
    }
    if (b >= m) {
        res += n * (b / m);
        b %= m;
    }
    if (a == 0) return res;
    long long ymax = (a * n + b) / m, xmax = ymax * m - b;
    if (ymax == 0) return res;
    res += (n - (xmax + a - 1) / a) * ymax;
    res += floor_sum(ymax, m, (a - xmax % a) % a, a);
    return res;
}

// #lp under (and on) the segment (x1, y1)-(x2, y2)
// not including y = 0, x = x2
long long num_lattice_points(long long x1, long long y1, long long x2, long long y2) {
    long long dx = x2 - x1;
    return floor_sum(dx, y2 - y1, dx * y1, dx);
}


// modint
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() const { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept {
        is >> x.val;
        x.val %= MOD;
        if (x.val < 0) x.val += MOD;
        return is;
    }
    friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD>& r, long long n) noexcept {
        if (n == 0) return 1;
        if (n < 0) return modpow(modinv(r), -n);
        auto t = modpow(r, n / 2);
        t = t * t;
        if (n & 1) t = t * r;
        return t;
    }
    friend constexpr Fp<MOD> modinv(const Fp<MOD>& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        return Fp<MOD>(u);
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

long long GCD(long long x, long long y) {
    return y ? GCD(y, x % y) : x;
}

int main() {
    int N;
    cin >> N;
    vector<long long> X(N), Y(N);
    for (int i = 0; i < N; ++i) cin >> X[i] >> Y[i];
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) {
        return Y[i]*X[j] < Y[j]*X[i];
    });
    mint res = 0;
    long long sy = 0;
    for (auto i : ids) {
        res -= mint(X[i]) * mint(sy);
        res -= num_lattice_points(0, 0, X[i], Y[i]);
        res += GCD(X[i], Y[i]);
        sy += Y[i];
    }
    reverse(ids.begin(), ids.end());
    sy = 0;
    for (auto i : ids) {
        res += mint(X[i]) * mint(sy);
        res += num_lattice_points(0, 0, X[i], Y[i]);
        sy += Y[i];
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 200
memory_kb: 4932
final_rank: 8