#include #define show(x) std::cerr << #x << " = " << x << std::endl using ll = long long; constexpr ll MOD = 1000000007LL; struct Matrix { Matrix(const std::size_t n) : Matrix{n, n} {} Matrix(const std::size_t r, const std::size_t c) : R{r}, C{c}, table(r, std::vector(c, (ll)0)) {} std::vector& operator[](const std::size_t n) { return table[n]; } const std::vector& operator[](const std::size_t n) const { return table[n]; } Matrix operator*(const Matrix& mat) const { assert(C == mat.R); Matrix result(R, mat.C); for (std::size_t i = 0; i < R; i++) { for (std::size_t j = 0; j < mat.C; j++) { for (std::size_t k = 0; k < C; k++) { (result[i][j] += table[i][k] * mat[k][j]) %= MOD; } } } return result; } static Matrix Unit(const std::size_t n) { Matrix ans(n, n); for (std::size_t i = 0; i < n; i++) { ans[i][i] = 1; } return ans; } std::size_t R, C; std::vector> table; }; Matrix power(const Matrix& mat, const ll n) { return n == 0 ? Matrix::Unit(mat.R) : n % 2 == 1 ? power(mat, n - 1) * mat : power(mat * mat, n / 2); } int main() { int N; ll K; std::cin >> N >> K; if (N <= 30) { std::vector A(N); for (int i = 0; i < N; i++) { std::cin >> A[i]; } const ll B = std::accumulate(A.begin(), A.end(), 0LL); Matrix mat(N + 1); for (int j = 0; j <= N; j++) { mat[0][j] = 1; } for (int j = 1; j <= N; j++) { mat[1][j] = 1; } for (int i = 2; i <= N; i++) { mat[i][i - 1] = 1; } const auto M = power(mat, K - N); ll F = 0, S = M[0][0] * B % MOD; for (int i = 1; i <= N; i++) { (F += M[1][i] * A[N - i]) %= MOD, (S += M[0][i] * A[N - i]) %= MOD; } std::cout << F << " " << S << std::endl; } else { std::queue q; ll F = 0; for (int i = 0; i < N; i++) { ll A; std::cin >> A, (F += A) %= MOD, q.push(A); } ll S = F; for (ll i = N + 1; i < K; i++) { const ll p = q.front(); q.pop(), q.push(F), (S += F) %= MOD, (F += (MOD - p) + F) %= MOD; } std::cout << F << " " << (F + S) % MOD << std::endl; } return 0; }