#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef pair PII; typedef vector VI; typedef vector VPII; typedef pair PLL; typedef pair PIL; typedef pair PLI; typedef double DB; #define pb push_back #define mset(a, b) memset(a, b, sizeof a) #define all(x) (x).begin(), (x).end() #define bit(x) (1 << (x)) #define bitl(x) (1LL << (x)) #define sqr(x) ((x) * (x)) #define sz(x) ((int)(x.size())) #define cnti(x) (__builtin_popcount(x)) #define cntl(x) (__builtin_popcountll(x)) #define clzi(x) (__builtin_clz(x)) #define clzl(x) (__builtin_clzll(x)) #define ctzi(x) (__builtin_ctz(x)) #define ctzl(x) (__builtin_ctzll(x)) #define X first #define Y second #define Error(x) cout << #x << " = " << x << endl template inline void chkmax(T& x, U y) { if (x < y) x = y; } template inline void chkmin(T& x, U y) { if (y < x) x = y; } const int MAXN = 300003; int n; int a[MAXN], b[MAXN], prv[MAXN], nxt[MAXN], bn; LL sum[MAXN]; LL ans = 0; LL Sum(int st, int en) { return sum[en] - sum[st - 1]; } void calc(int x) { for (int i = 1; i < bn; i++) { sum[i] = sum[i - 1] + b[i]; } for (int i = 1; i < bn; i++) { int k = i - 1; while (k && b[k] >= b[i]) k = prv[k]; prv[i] = k; } for (int i = bn - 1; i >= 1; i--) { int k = i + 1; while (k < bn && b[k] >= b[i]) k = nxt[k]; nxt[i] = k; } for (int i = 1; i < bn; i++) { chkmax(ans, 1LL * Sum(prv[i] + 1, nxt[i] - 1) * b[i] * x); } } int main() { int ncase; for (scanf("%d", &ncase); ncase--;) { scanf("%d", &n); for (int k = 1; k <= n; k++) { scanf("%d", a + k); } ans = 0; for (int k = 1; k <= n; k++) { bn = 1; for (int j = k; j <= n; j += k) { b[bn++] = a[j]; } calc(int(sqrt(k + 1e-8))); } printf("%lld\n", ans); } return 0; }