Ice Sculptures

CodeForces - 158D

The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.

The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.

When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:

  • the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),
  • the sum of the ti values of the remaining sculptures is maximized.

Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.

Input

The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tnti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.

Output

Print the required maximum sum of the sculptures' attractiveness.

Examples

Input
8
1 2 -3 4 -5 5 2 3
Output
14
Input
6
1 -2 3 -4 5 -6
Output
9
Input
6
1 2 3 4 5 6
Output
21

Note

In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.

sol:想了半天都不会,然后看题解,然后惊呼这TM能过??

for(i=;i*<=n;i++)
{
if(n%i==)
{
for(j=;j<=i;j++)
{
int Sum=;
for(k=j;k<=n;k+=i)
{
Sum+=a[k];
}
ans=max(ans,Sum);
}
}
}

这也太暴力了吧,我怎么算复杂度都是n2及以上啊,为什么能过啊qaq

Ps:不管了,弃了弃了(跪求更好的做法或证明一下复杂度)

4.3updata:这是调和级数的复杂度,似乎是n1.5。实锤不会算复杂度qaq

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,a[N];
int main()
{
int i,j,k,ans=-0x3f3f3f3f;
R(n);
for(i=;i<=n;i++) R(a[i]);
for(i=;i*<=n;i++)
{
if(n%i==)
{
for(j=;j<=i;j++)
{
int Sum=;
for(k=j;k<=n;k+=i)
{
Sum+=a[k];
}
ans=max(ans,Sum);
}
}
}
Wl(ans);
return ;
}
/*
input
8
1 2 -3 4 -5 5 2 3
output
14 input
6
1 -2 3 -4 5 -6
output
9 input
6
1 2 3 4 5 6
output
21 input
4
1 -10 1 -10
output
-18
*/

codeforces158D的更多相关文章

随机推荐

  1. 用C# 模拟实现unity里的协程

    注:需要了解C#的迭代器,不然很难理解. 之前面试有被问到unity协程的原理,以及撇开unity用纯C#去实现协程的方法.后来了解一下,确实可以的.趁这会有空,稍微总结一下. 还是结合代码说事吧: ...

  2. DAG也许是真正的区块链3.0

    从15年开始,区块链概念被单拎出来,这之前区块链还只是比特币技术里的一个数据结构,中本村白皮书里把block和chain连一起的时候也只是a chain of blocks .随着以太坊去中心化计算机 ...

  3. IdentityServer4 实战文档

    一.前言 IdentityServer4实战这个系列主要介绍一些在IdentityServer4(后文称:ids4),在实际使用过程中容易出现的问题,以及使用技巧,不定期更新,谢谢大家关注.这些问题. ...

  4. babel-polyfill使用与性能优化

    文章首发于笔者的个人博客 文章概览 本文主要内容包括:什么是babel-polyfill,如何使用,如何通过按需加载进行性能优化. 本文所有例子可以在 笔者的github 找到. 什么是babel-p ...

  5. vue prop 传递数据

    prop 组件实例的作用域是孤立的.这意味着不能 (也不应该) 在子组件的模板内直接引用父组件的数据.要让子组件使用父组件的数据,需要通过子组件的 props 选项 一个组件默认可以拥有任意数量的 p ...

  6. Go源码编译安装

    参考文档1:https://www.cnblogs.com/majianguo/p/7258975.html 参考文档2:http://www.loongson.cn/news/company/456 ...

  7. Nginx 通过 Lua + Redis 实现动态封禁 IP

    一.背景 为了封禁某些爬虫或者恶意用户对服务器的请求,我们需要建立一个动态的 IP 黑名单.对于黑名单之内的 IP ,拒绝提供服务. 二.架构 实现 IP 黑名单的功能有很多途径: 1.在操作系统层面 ...

  8. Randomized Online PCA Algorithms with Regret Bounds that are Logarithmic in the Dimension

    目录 Setup of Batch PCA and Online PCA Hedge Algorithm 改进算法 用于矩阵 \(rounding()\) 前俩次,都用到了\(rounding()\) ...

  9. Python—re模块

    re模块 正则表达式就是字符串的匹配规则,在多数编程语言里都有相应的支持,python里对应的模块是re 常用的表达式规则 '.' 默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹 ...

  10. HDU 3478 Catch (连通性&&二分图判断)

    链接 [https://vjudge.net/contest/281085#problem/C] 题意 一个n个点,m条边的图,开始的点是s 每次必须移动到相邻的位置,问你是否存在某个时刻所有点都可能 ...