Language: C++

#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <chrono>
#include <complex>
#include <condition_variable>
#include <deque>
#include <exception>
#include <forward_list>
#include <fstream>
#include <functional>
#include <future>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
//constexpr int INF = 1<<30;
//constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

// Matrix (m * n)
struct Matrix {
    vector<vd> val; // column vectors
    int M;
    int N;

    Matrix(int m, int n, ll x = 0) :
      val(m, vd(n, x)), M(m), N(n) {}

    void init(int m, int n, ll x = 0) {
      val.clear();
      val.assign(m, vd(n, x));
      M = m;
      N = n;
    }

    // Return the number of rows
    size_t size() const {
      return val.size();
    }

    vd&       operator[](size_t i)       {return val[i];}
    const vd& operator[](size_t i) const {return val[i];}
};

ostream& operator << (ostream& s, const Matrix& A) {
  s << endl;
  for (int i=0; i<A.M; i++) {
    for (int j = 0; j < A.N; j++) {
      s << A[i][j] << ", ";
    }
    s << endl;
  }
  return s;
}

Matrix operator * (const Matrix& A, const Matrix& B) {
  assert(A.N == B.M);
  Matrix R(A.M, B.N);

  for (int i = 0; i < A.M; i++)
    for (int j = 0; j < B.N; j++)
      for (int k = 0; k < B.M; k++)
        R[i][j] += A[i][k] * B[k][j];

  return R;
}

Matrix pow(Matrix A, ull n) {
  assert(A.M == A.N);
  Matrix R(A.M, A.M);

  for (int i = 0; i < int(A.size()); i++) R[i][i] = 1;

  while (n > 0) {
    if (n & 1ull) R = R * A;
    A = A * A;
    n >>= 1;
  }
  return R;
}

// Return rank of A.
//   rank: Aの値域の次元 <=> Aの列ベクトルが張る線型部分空間の次元
int GaussJordan(Matrix& A, bool is_extended = false) {
  int rank = 0;
  for (int col=0; col<A.N; col++) {
    if (is_extended && col == A.N-1) break;

    int pivot = -1;
    for (int row=rank; row<A.M; ++row) {
      if (A[row][col] != 0) {
        pivot = row;
        break;
      }
    }
    if (pivot == -1) continue;

    swap(A[pivot], A[rank]);
    const auto inv = 1.0/A[rank][col];

    // Make A[rank][col] be 1
    for (int col2=0; col2<A.N; col2++)
      A[rank][col2] = A[rank][col2] * inv;

    // 掃き出し
    for (int row=0; row<A.M; row++) {
      if (row != rank && A[row][col]) {
        const auto fac = A[row][col];
        for (int col2=0; col2<A.N; col2++) {
          A[row][col2] -= A[rank][col2] * fac;
        }
      }
    }
    rank++;
  }

  return rank;
}

// Ax = b
int linear_equation(const Matrix& A, vd b, vd &res) {
  Matrix M(A.M, A.N+1);
  for (int i=0; i<A.M; i++) {
    for (int j=0; j<A.N; j++) {
      M[i][j] = A[i][j];
    }

    M[i][A.N] = b[i];
  }
  int rank = GaussJordan(M, true);

  // check if it has no solution
  for (int row=rank; row<A.M; row++) {
    if (M[row][A.N]) return -1;
  }

  // answer
  res.assign(A.N, 0);
  for (int i=0; i<rank; i++) res[i] = M[i][A.N];
  return rank;
}

int N;

int main(int argc, char** argv) {
  cin >> N;

  Matrix M(N, N);
  for (int i=0; i<N; i++) {
    M.val[i][i] = 1;
    M.val[i][(i+1)%N] = 1;
  }

  cerr << M << endl;

  vd A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }

  vd ret;
  linear_equation(M, A, ret);

  for (int i=0; i<N; i++) {
    cout << ll(ret[i])*2;
    if (i<N-1) cout << " ";
  }
  cout << endl;

  return 0;
}


Compiler output:
a.cc: In function 'Matrix operator*(const Matrix&, const Matrix&)':
a.cc:167:3: error: 'assert' was not declared in this scope
  167 |   assert(A.N == B.M);
      |   ^~~~~~
a.cc:51:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
   50 | #include <valarray>
  +++ |+#include <cassert>
   51 | #include <vector>
a.cc: In function 'Matrix pow(Matrix, ull)':
a.cc:179:3: error: 'assert' was not declared in this scope
  179 |   assert(A.M == A.N);
      |   ^~~~~~
a.cc:179:3: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'