import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.string; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto AB = N.iota.map!(_ => readln.split.map!(to!long).array).array; auto dp = new long[][](N+1, 2); foreach (i; 0..N+1) dp[i][] = - (1L << 59); dp[0][0] = 0; foreach (i; 0..N) { long tmp = 0; long a = AB[i][0], b = AB[i][1]; if (a >= 0 && b >= 0) { tmp += a * (M - 1) + max(a, b); } else if (a < 0 && b >= 0) { tmp += b; } else if (a >= 0 && b < 0) { tmp += a * M; } else { tmp += max(a * M, b); } dp[i+1][0] = max(dp[i+1][0], dp[i][0] + tmp); dp[i+1][1] = max(dp[i+1][1], dp[i][0] + max(a, b)); dp[i+1][1] = max(dp[i+1][1], dp[i][1] + max(a, b)); } dp[1..$].map!(d => d.reduce!max).reduce!max.writeln; }