#include #define pb emplace_back #define fst first #define scd second #define mkp make_pair #define mems(a, x) memset((a), (x), sizeof(a)) using namespace std; typedef long long ll; typedef double db; typedef unsigned long long ull; typedef long double ldb; typedef pair pii; namespace IO { const int maxn = 1 << 20; char ibuf[maxn], *iS, *iT, obuf[maxn], *oS = obuf; inline char gc() { return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), (iS == iT ? EOF : *iS++) : *iS++); } template inline T read() { char c = gc(); T x = 0; bool f = 0; while (c < '0' || c > '9') { f |= (c == '-'); c = gc(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c ^ 48); c = gc(); } return f ? ~(x - 1) : x; } inline int reads(char *s) { char c = gc(); int len = 0; while (isspace(c)) { c = gc(); } while (!isspace(c) && c != -1) { s[len++] = c; c = gc(); } return len; } inline void flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; } struct Flusher { ~Flusher() { flush(); } } AutoFlush; inline void pc(char ch) { if (oS == obuf + maxn) { flush(); } *oS++ = ch; } template inline void write(T x) { static char stk[64], *tp = stk; if (x < 0) { x = ~(x - 1); pc('-'); } do { *tp++ = x % 10; x /= 10; } while (x); while (tp != stk) { pc((*--tp) | 48); } } template inline void writesp(T x) { write(x); pc(' '); } template inline void writeln(T x) { write(x); pc('\n'); } } using IO::read; using IO::reads; using IO::write; using IO::pc; using IO::writesp; using IO::writeln; const int maxn = 3000100; int n, f[maxn], g[maxn], N; struct node { int a, b; } a[maxn]; void solve() { n = read(); int cnt = 0; for (int i = 1; i <= n; ++i) { a[i].a = read(); a[i].b = read(); ++f[a[i].a]; --f[a[i].b]; if (a[i].a > a[i].b) { --f[a[i].a - a[i].b]; } else if (a[i].a < a[i].b) { ++g[a[i].b - a[i].a]; } cnt += (a[i].a < a[i].b); N = max({N, a[i].a, a[i].b}); } for (int i = 1; i <= N; ++i) { f[i] += f[i - 1]; g[i] += g[i - 1]; } int mx = cnt; for (int x = 1; x <= N; ++x) { ll t = 0; for (int i = 0, j, k = 0; i <= N; i = j + 1, ++k) { j = min(i + x - 1, N); t += 1LL * (f[j] - (i ? f[i - 1] : 0)) * k; } for (int i = 1, j, k = 1; i <= N; i = j + 1, ++k) { j = min(i + x - 1, N); t += 1LL * (g[j] - g[i - 1]) * k; } mx = max(mx, (int)t); } printf("%d\n", mx); } int main() { int T = 1; // scanf("%d", &T); while (T--) { solve(); } return 0; }