#include typedef uint32_t u32; typedef uint64_t u64; typedef int32_t s32; typedef int64_t s64; s32 ri() { s32 n; scanf("%" SCNd32, &n); return n; } #define INF 1000000000000000000 int main() { #define int WHOOOO // 脱int訓練中につき許して s32 n = ri(), m = ri(); s32 a[n][m]; for (auto &i : a) for (auto &j : i) j = ri(); s32 profit[n][n]; for (s32 i = 0; i < n; i++) for (s32 j = 0; j < n; j++) { profit[i][j] = 0; for (s32 k = 0; k < m; k++) profit[i][j] += a[i][k] * a[j][k] * (1 + (i != j)); } bool used[n]; memset(used, 0, sizeof(used)); s64 res[2] = { 0 }; std::vector r0, r1; for (s32 i = 0; i < n; i++) { s64 plus[n]; for (s32 j = 0; j < n; j++) { if (used[j]) { plus[j] = -INF; continue; } plus[j] = 0; // used[j] = true; for (s32 k = 0; k < n; k++) plus[j] += profit[j][k] * (1 + !used[k]); // used[j] = false; } auto &use = (i & 1) ? r1 : r0; s32 tmp = std::max_element(plus, plus + n) - plus; use.push_back(tmp); used[tmp] = true; for (auto k : use) res[i & 1] += profit[tmp][k]; } printf("%" PRId64 "\n", res[0] - res[1]); return 0; }