#include #include #include #include #include #include #include #include #include #include // #define DEBUG using namespace std; // typedef pairP; // typedef complexP; typedef long long int ll; typedef unsigned long long int ull; const int INF = 1e9; const double EPS=1e-9; const ll MOD = 1000000007; ll N,K; vectorF; void solve1(){ int sum = 0; for(int i = 0 ; i < N ; i++)sum += F[i]; for(int i = N ; i < K ; i++){ F.push_back(sum); sum = sum - F[i-N] + F[F.size()-1]; } int S = 0; for(int i = 0 ; i < K ; i++){ S = (S + F[i])%MOD; } cout << F[K-1] << ' ' << S << endl; } class Matrix :public vector >{ public: Matrix(int _n){ for(int i = 0 ; i < _n ; i++){ this->push_back(vector(_n,0)); } } Matrix operator * (Matrix& m1){ int size = m1.size(); Matrix ret = Matrix(size); for(int i = 0 ; i < size ; i++){ for(int j = 0 ; j < size ; j++){ for(int k = 0 ; k < size ; k++){ ret[i][j] = (ret[i][j] + (*this)[i][k] * m1[k][j])%MOD; } } } return ret; } static Matrix getIdentity(int _n){ Matrix ret(_n); for(int i = 0 ; i < _n ; i++)ret[i][i] = 1; return ret; }; void display(){ int size = this->size(); for(int i = 0 ; i < size ; i++){ for(int j = 0 ; j < size ; j++){ cout << (*this)[i][j] << ' ' ; } cout << endl; } } }; Matrix pow(Matrix m,ll t){ Matrix ret(m.size()); if(t == 0)return m.getIdentity(m.size()); if(t == 1)return m; ret = pow(m,t/2); if(t % 2)return ret*ret*m; else return ret*ret; } void solve2(){ /* Matrix s_mat(N),e_mat(N),mat(N); for(int i = 0 ; i < N ; i++)mat[N-1][i] = 1; for(int i = 0 ; i < N-1 ; i++)mat[i][i+1] = 1; for(int i = 0 ; i < N ; i++)s_mat[i][0] = F[i]; e_mat = pow(mat,K-1)*s_mat; cout << e_mat[0][0] << ' ' << endl; */ Matrix s_mat(N+1),e_mat(N+1),mat(N+1); for(int i = 1 ; i < N+1 ; i++)mat[N][i] = 1; for(int i = 1 ; i < N ; i++)mat[i][i+1] = 1; mat[0][0] = 1; mat[0][2] = 1; s_mat[0][0] = F[0]; for(int i = 0 ; i < N ; i++)s_mat[i+1][0] = F[i]; e_mat = pow(mat,K-1)*s_mat; cout << e_mat[1][0] << ' ' << e_mat[0][0] << endl; } int main(int argc, char *argv[]) { cin >> N >> K; for(int i = 0 ; i < N ; i++){ int num; cin >> num; F.push_back(num); } if(2 <= N <= 10000 && N < K && K <= 1000000){ solve1(); } else { solve2(); } return 0; }