//
// Created by travel on 2024/10/15.
//
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using vec = array<LL, 2>;
constexpr LL M1 = 1145140019, M2 = 1145140033, pw = 23333;
// a * x % b == gcd(a, b)
void exgcd(LL a, LL b, LL &x, LL &y)
{
if (b == 0)
{
x = 1, y = 0;
return;
}
exgcd(b, a % b, y, x);
y -= a / b * x;
}
LL arr[100020];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
LL n, m;
cin >> n >> m;
LL n2 = n, m2 = m;
LL s = 0;
for (int i = 1; i <= n; ++i)
{
cin >> arr[i];
s += arr[i];
s %= m;
}
LL ss, dd;
if (n % 2)
{
LL g = gcd(n, m);
LL ans = s % g;
n /= g;
m /= g;
s /= g;
LL x, y;
exgcd(n, m, x, y);
// n * x % m == 1
ss = (x * (m - s) % m + m) % m;
ss = 0;
cout << ans << "\n";
dd = 0;
}
else
{
LL nn = n;
n /= 2;
LL g = gcd(n, m);
LL ans = s % g;
n /= g;
m /= g;
s /= g;
LL x, y;
exgcd(n, m, x, y);
ss = x * (m - s);
cout << ans << "\n";
if (ss % 2)
{
ss = ((ss - (nn + 1)) / 2 % m + m) % m;
dd = 1;
}
else
{
ss = (ss / 2 % m + m) % m;
dd = 0;
}
}
cout << ss << " " << dd;
/*LL jxy = 0;
for (int i = 1; i <= n2; ++i)
{
jxy += arr[i] + ss + dd * i;
jxy %= m2;
}
cout << '\n' << jxy;*/
}