#include #include #include #include using namespace std; typedef long long LL; #define M 300010 int n, m, a[M], b[M]; LL ans; pair p[M]; int TT, vis[M], root[M]; int find_root(int h) { if (h == root[h]) return h; return root[h] = find_root(root[h]); } LL s[M]; LL solve() { for (int i = 1; i <= m; i++) p[i] = make_pair(b[i], i); sort(p + 1, p + m + 1); reverse(p + 1, p + m + 1); ++TT; for (int i = 1; i <= m; i++) root[i] = i, s[i] = 0; LL res = 0; for (int i = 1; i <= m; i++) { int x = p[i].second; if (x > 1 && vis[x - 1] == TT) { root[x] = root[x - 1]; } if (x < m && vis[x+1] == TT) { root[x + 1] = root[x]; int y = find_root(x + 1); s[y] += s[x + 1]; } int y = find_root(x); s[y] += p[i].first; LL tmp = s[y] * p[i].first; if (tmp > res) res = tmp; vis[x] = TT; } return res; } void read(int &x) { x = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c <= '9' && c >= '0') x = 10 * x + c - '0', c = getchar(); } int main() { //freopen("in.txt", "r", stdin); int T; for (scanf("%d", &T); T--; ) { read(n); for (int i = 1; i <= n; i++) read(a[i]); ans = 0; for (int step = 1; step <= n; step++) { m = 0; for (int i = step; i <= n; i += step) b[++m] = a[i]; LL res = solve(); LL tmp = res * (int)(sqrt(step) + (1e-8)); if (tmp > ans) ans = tmp; } cout << ans << endl; } }