#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; typedef vector VI; typedef pair PI; const double EPS=1e-9; const int N = 10010; int a[N]; int acc[N]; const int mod = 1e9 + 7; int n; ll k; /* k is small */ void small() { a[n] = 0; ll sum = 0; REP(i, 0, n) { a[n] += a[i]; } sum = a[n] * 2 % mod; REP(i, n + 1, k) { int c = i % (n + 1); ll s = 2 * a[(i + n) % (n + 1)]; s += mod - a[c]; a[c] = s % mod; sum += a[c]; sum %= mod; } cout << a[(k - 1) % (n + 1)] << " " << sum << endl; } /* Requirement: vector T mod */ template class Matrix { public: int n; vector > mat; Matrix(int n) : n(n), mat(n) { for (int i = 0; i < n; ++i) { mat[i] = vector(n); } } vector &operator[] (int i) { return mat[i]; } const vector &operator[] (int i) const { return mat[i]; } Matrix operator *(Matrix const& ano) const { Matrix ret(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { for (int k = 0; k < n; ++k) { ret[i][j] += (*this)[i][k] * ano[k][j]; ret[i][j] %= mod; } } } return ret; } static Matrix unit(int n) { Matrix ret(n); for (int i = 0; i < n; ++i) { ret[i][i] = 1; } return ret; } Matrix pow(ll exp) const { Matrix sum = unit(n); Matrix cur = *this; while (exp > 0) { if (exp % 2 != 0) { sum = sum * cur; } cur = cur * cur; exp /= 2; } return sum; } }; void large() { Matrix cp(n); REP(i, 0, n - 1) { cp[i][i + 1] = 1; } REP(i, 0, n) { cp[n - 1][i] = 1; } cp = cp.pow(k - 1); ll val = 0; REP(i, 0, n) { val += cp[0][i] * a[i]; val %= mod; } Matrix sm(n + 1); REP(i, 0, n) { sm[i][i + 1] = 1; } sm[n][0] = mod - 1; sm[n][n] = 2; sm = sm.pow(k - 1); ll sum = 0; acc[0] = a[0]; REP(i, 1, n) { acc[i] = acc[i - 1] + a[i]; acc[i] %= mod; } acc[n] = 2 * acc[n - 1] % mod; REP(i, 0, n + 1) { sum += sm[0][i] * acc[i]; sum %= mod; } cout << val << " " << sum << endl; } int main(void){ cin >> n >> k; REP(i, 0, n) { cin >> a[i]; } if (n >= 31) { small(); return 0; } large(); }