#include #include #include using namespace std; // m = number of equations, n = number of variables, // a[m][n+1] = coefficients matrix // Returns vector ans containing the solution, if there is no // solution returns vector() const double eps = 1e-7; bool zero(double a){return (a-eps);} vector solve(vector > a, int m, int n) { int cur=0; for (int i=0;i(); vector ans(n); for (int i=0,sat=0;i> tn; tn--;) { int n; cin >> n; vector f(n); for (int i = 0; i < n; i++) cin >> f[i]; double next = -1; bool found = false; for (int d = 1; d <= 3 && !found; d++) { vector > c(n - d, vector(d + 1)); for (int i = d; i < n; i++) for (int j = 0; j <= d; j++) c[i - d][d - j] = f[i - j]; vector a = solve(c, n - d, d); if (a.size() > 0) { next = 0; for (int i = 0; i < d; i++) next += a[i] * f[n - d + i]; found = true; } } cout << (int)round(next) << endl; } return 0; }