#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> a;
#define sz(x) ((int)(x).size())
const int MAX_E = 17, MAX_M = 1e5 + 3;
int freq[MAX_M];
vector<int> freqMod[MAX_E + 1], ind[MAX_M];
vector<int> S, F;
int minF, sIdx, sIdxSol, sIdxSolutionMin, sumF;
int jump(int x)
{
return (1<<x);
}
const int MOD = 1000000007;
int add(int x, int y)
{
x += y;
x -= MOD * (x >= MOD);
return x;
}
int sumVec(const vector<int> &v)
{
int ret = 0;
for (int x : v)
ret = add(ret, x);
return ret;
}
int minVec(const vector<int> &v)
{
int ret = INT_MAX;
for (int x : v)
ret = min(ret, x);
return ret;
}
void clear()
{
for (int i = 0; i < sz(a); ++i)
{
int x = a[i];
freq[x]--;
if (x <= MAX_E)
freqMod[x][i%jump(x)]--;
ind[x].clear();
}
a.clear();
}
vector<int> getDiff(const vector<int> &v, int k)
{
vector<int> ans(k);
vector<int> modPos(MAX_E + 1, sz(v));
for (int i = 0; i < sz(v); ++i)
modPos[v[i]] = min(modPos[v[i]], i);
for (int x = 1; x <= MAX_E; ++x)
{
int curMod = modPos[x];
if (curMod == sz(v))
continue;
int j = jump(x);
for (int shift = 0; shift < k; )
{
if (curMod < 0)
curMod += j;
if (curMod >= n)
{
int minus = curMod - (n - 1);
curMod -= minus;
shift += minus;
continue;
}
int freqHere = ((n - 1 - curMod) / j) + 1;
ans[shift] += freqHere - freqMod[x][curMod];
++shift;
curMod--;
}
}
return ans;
}
void calcS()
{
sIdx = 1;
S.clear();
S.push_back(1);
while(sz(S) < n - 1) {
int T = sz(S);
sIdx++;
S.push_back(sIdx);
for (int i = 0; i < T; ++i)
{
int x = S[i];
S.push_back(x);
}
}
vector<int> ans = getDiff(S, sz(S) - sz(a) + 1);
sIdxSol = sumVec(ans);
sIdxSolutionMin = minVec(ans);
}
void calcF()
{
vector<int> temp(S.begin() + sz(S) - n + 1, S.end());
F = getDiff(temp, n);
sumF = sumVec(F);
minF = minVec(F);
}
int solveSum(int cur)
{
return add(sumF, n - freq[cur]);
}
int sum(int mx)
{
int ret = sIdxSol;
for (int cur = sIdx + 1; cur <= mx; ++cur)
ret = add(add(ret, ret), solveSum(cur));
return ret;
}
int solveMin(int cur) {
int ret = minF + 1;
for (int i : ind[cur])
{
ret = min(ret, F[n - i - 1]);
}
return ret;
}
int mn(int mx)
{
int ret = sIdxSolutionMin;
for (int cur = sIdx + 1; cur <= mx; ++cur)
ret = min(ret, solveMin(cur));
return ret;
}
void myMain()
{
a.resize(n);
for (int i = 0; i < n; ++i)
scanf("%d", &a[i]);
for (int i = 0; i < sz(a); ++i)
{
freq[a[i]]++;
if (a[i] <= MAX_E)
freqMod[a[i]][i%jump(a[i])]++;
ind[a[i]].push_back(i);
}
calcS();
calcF();
printf("%d %d\n", mn(m), sum(m));
clear();
}
int main()
{
freopen("input.txt", "r", stdin);
S.reserve(1<<MAX_E);
for (int x = 0; x <= MAX_E; ++x)
freqMod[x].resize(jump(x));
while(scanf("%d %d", &n, &m) != EOF)
myMain();
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbiwgbTsKdmVjdG9yPGludD4gYTsKCiNkZWZpbmUgc3ooeCkgKChpbnQpKHgpLnNpemUoKSkKCmNvbnN0IGludCBNQVhfRSA9IDE3LCBNQVhfTSA9IDFlNSArIDM7CmludCBmcmVxW01BWF9NXTsKdmVjdG9yPGludD4gZnJlcU1vZFtNQVhfRSArIDFdLCBpbmRbTUFYX01dOwoKdmVjdG9yPGludD4gUywgRjsKaW50IG1pbkYsIHNJZHgsIHNJZHhTb2wsIHNJZHhTb2x1dGlvbk1pbiwgc3VtRjsKCmludCBqdW1wKGludCB4KQp7CiAgICByZXR1cm4gKDE8PHgpOwp9Cgpjb25zdCBpbnQgTU9EID0gMTAwMDAwMDAwNzsKaW50IGFkZChpbnQgeCwgaW50IHkpCnsKICAgIHggKz0geTsKICAgIHggLT0gTU9EICogKHggPj0gTU9EKTsKICAgIHJldHVybiB4Owp9CgppbnQgc3VtVmVjKGNvbnN0IHZlY3RvcjxpbnQ+ICZ2KQp7CiAgICBpbnQgcmV0ID0gMDsKICAgIGZvciAoaW50IHggOiB2KQogICAgICAgIHJldCA9IGFkZChyZXQsIHgpOwogICAgcmV0dXJuIHJldDsKfQoKaW50IG1pblZlYyhjb25zdCB2ZWN0b3I8aW50PiAmdikKewogICAgaW50IHJldCA9IElOVF9NQVg7CiAgICBmb3IgKGludCB4IDogdikKICAgICAgICByZXQgPSBtaW4ocmV0LCB4KTsKICAgIHJldHVybiByZXQ7Cn0KCgp2b2lkIGNsZWFyKCkKewogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzeihhKTsgKytpKQogICAgewogICAgICAgIGludCB4ID0gYVtpXTsKICAgICAgICBmcmVxW3hdLS07CiAgICAgICAgaWYgKHggPD0gTUFYX0UpCiAgICAgICAgICAgIGZyZXFNb2RbeF1baSVqdW1wKHgpXS0tOwogICAgICAgIGluZFt4XS5jbGVhcigpOwogICAgfQogICAgYS5jbGVhcigpOwp9Cgp2ZWN0b3I8aW50PiBnZXREaWZmKGNvbnN0IHZlY3RvcjxpbnQ+ICZ2LCBpbnQgaykKewogICAgdmVjdG9yPGludD4gYW5zKGspOwogICAgdmVjdG9yPGludD4gbW9kUG9zKE1BWF9FICsgMSwgc3oodikpOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzeih2KTsgKytpKQogICAgICAgIG1vZFBvc1t2W2ldXSA9IG1pbihtb2RQb3NbdltpXV0sIGkpOwogICAgZm9yIChpbnQgeCA9IDE7IHggPD0gTUFYX0U7ICsreCkKICAgIHsKICAgICAgICBpbnQgY3VyTW9kID0gbW9kUG9zW3hdOwogICAgICAgIGlmIChjdXJNb2QgPT0gc3oodikpCiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIGludCBqID0ganVtcCh4KTsKICAgICAgICBmb3IgKGludCBzaGlmdCA9IDA7IHNoaWZ0IDwgazsgKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKGN1ck1vZCA8IDApCiAgICAgICAgICAgICAgICBjdXJNb2QgKz0gajsKICAgICAgICAgICAgaWYgKGN1ck1vZCA+PSBuKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpbnQgbWludXMgPSBjdXJNb2QgLSAobiAtIDEpOwogICAgICAgICAgICAgICAgY3VyTW9kIC09IG1pbnVzOwogICAgICAgICAgICAgICAgc2hpZnQgKz0gbWludXM7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpbnQgZnJlcUhlcmUgPSAoKG4gLSAxIC0gY3VyTW9kKSAvIGopICsgMTsKICAgICAgICAgICAgYW5zW3NoaWZ0XSArPSBmcmVxSGVyZSAtIGZyZXFNb2RbeF1bY3VyTW9kXTsKICAgICAgICAgICAgKytzaGlmdDsKICAgICAgICAgICAgY3VyTW9kLS07CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIGFuczsKfQoKdm9pZCBjYWxjUygpCnsKICAgIHNJZHggPSAxOwogICAgUy5jbGVhcigpOwogICAgUy5wdXNoX2JhY2soMSk7CiAgICB3aGlsZShzeihTKSA8IG4gLSAxKSB7CiAgICAgICAgaW50IFQgPSBzeihTKTsKICAgICAgICBzSWR4Kys7CiAgICAgICAgUy5wdXNoX2JhY2soc0lkeCk7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBUOyArK2kpCiAgICAgICAgewogICAgICAgICAgICBpbnQgeCA9IFNbaV07CiAgICAgICAgICAgIFMucHVzaF9iYWNrKHgpOwogICAgICAgIH0KICAgIH0KICAgIHZlY3RvcjxpbnQ+IGFucyA9IGdldERpZmYoUywgc3ooUykgLSBzeihhKSArIDEpOwogICAgc0lkeFNvbCA9IHN1bVZlYyhhbnMpOwogICAgc0lkeFNvbHV0aW9uTWluID0gbWluVmVjKGFucyk7Cn0KCnZvaWQgY2FsY0YoKQp7CiAgICB2ZWN0b3I8aW50PiB0ZW1wKFMuYmVnaW4oKSArIHN6KFMpIC0gbiArIDEsIFMuZW5kKCkpOwogICAgRiA9IGdldERpZmYodGVtcCwgbik7CiAgICBzdW1GID0gc3VtVmVjKEYpOwogICAgbWluRiA9IG1pblZlYyhGKTsKfQoKaW50IHNvbHZlU3VtKGludCBjdXIpCnsKICAgIHJldHVybiBhZGQoc3VtRiwgbiAtIGZyZXFbY3VyXSk7Cn0KCmludCBzdW0oaW50IG14KQp7CiAgICBpbnQgcmV0ID0gc0lkeFNvbDsKICAgIGZvciAoaW50IGN1ciA9IHNJZHggKyAxOyBjdXIgPD0gbXg7ICsrY3VyKQogICAgICAgIHJldCA9IGFkZChhZGQocmV0LCByZXQpLCBzb2x2ZVN1bShjdXIpKTsKICAgIHJldHVybiByZXQ7Cn0KCmludCBzb2x2ZU1pbihpbnQgY3VyKSB7CiAgICBpbnQgcmV0ID0gbWluRiArIDE7CiAgICBmb3IgKGludCBpIDogaW5kW2N1cl0pCiAgICB7CiAgICAgICAgcmV0ID0gbWluKHJldCwgRltuIC0gaSAtIDFdKTsKICAgIH0KICAgIHJldHVybiByZXQ7Cn0KCmludCBtbihpbnQgbXgpCnsKICAgIGludCByZXQgPSBzSWR4U29sdXRpb25NaW47CiAgICBmb3IgKGludCBjdXIgPSBzSWR4ICsgMTsgY3VyIDw9IG14OyArK2N1cikKICAgICAgICByZXQgPSBtaW4ocmV0LCBzb2x2ZU1pbihjdXIpKTsKICAgIHJldHVybiByZXQ7Cn0KCnZvaWQgbXlNYWluKCkKewogICAgYS5yZXNpemUobik7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkKICAgICAgICBzY2FuZigiJWQiLCAmYVtpXSk7CgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzeihhKTsgKytpKQogICAgewogICAgICAgIGZyZXFbYVtpXV0rKzsKICAgICAgICBpZiAoYVtpXSA8PSBNQVhfRSkKICAgICAgICAgICAgZnJlcU1vZFthW2ldXVtpJWp1bXAoYVtpXSldKys7CiAgICAgICAgaW5kW2FbaV1dLnB1c2hfYmFjayhpKTsKICAgIH0KCiAgICBjYWxjUygpOwogICAgY2FsY0YoKTsKICAgIHByaW50ZigiJWQgJWRcbiIsIG1uKG0pLCBzdW0obSkpOwogICAgY2xlYXIoKTsKfQoKaW50IG1haW4oKQp7CiAgICBmcmVvcGVuKCJpbnB1dC50eHQiLCAiciIsIHN0ZGluKTsKCiAgICBTLnJlc2VydmUoMTw8TUFYX0UpOwogICAgZm9yIChpbnQgeCA9IDA7IHggPD0gTUFYX0U7ICsreCkKICAgICAgICBmcmVxTW9kW3hdLnJlc2l6ZShqdW1wKHgpKTsKCiAgICB3aGlsZShzY2FuZigiJWQgJWQiLCAmbiwgJm0pICE9IEVPRikKICAgICAgICBteU1haW4oKTsKCn0=