#include"bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; using pii = pair; using pll = pair; #define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++) #define REP(i,n) FOR((i),0,(n)) #define WAITING(str) int str;std::cin>>str; #define DEBUGING(str) cout<< #str << " " str<> N >> M; vector> abs(N); REP(i, N) { ll a, b; cin >> a >> b; abs[i] = { a,b }; } vector imos(N); // collection border REP(i, N) { auto ab = abs[i]; ll a = ab.first; ll b = ab.second; if (a < 0 && b < 0) { if (a*M < b)imos[i] = b; else imos[i] = a * M; } else if (a >= 0 && b < 0) { imos[i] = a * M; } else if (a < 0 && b >= 0) { imos[i] = b; } else { imos[i] = a * (M - 1) + max(a, b); } } REP(i, N - 1)imos[i + 1] += imos[i]; vector mid(N); REP(i, N)mid[i] = max(abs[i].first, abs[i].second); REP(i, N - 1)mid[i + 1] += mid[i]; ll maxv = mid.back(); vector imos2(N, 0); for (int i = N - 2; i >= 0; i--) { maxv = max(maxv, mid[i]); imos2[i] = maxv - mid[i]; } ll res = -INFL;; REP(i, N)res = max(res, imos[i] + imos2[i]); cout << res << endl; return 0; }