static int f(int i,int j){
		if(i==j)return 0;
		if(mem[i][j]>0)return mem[i][j];
		int min=MAX_VALUE-1000000;
		for(int k=(i+1)%N;k!=(j+1)%N;k=(k+1)%N){
			int val1,val2;
			if(k-1>=i)val1=sums[k-1]-(i>0?sums[i-1]:0);
			else val1=sums[N-1]-sums[i-1]+(k>0?sums[k-1]:0);
			if(j>=k)val2=sums[j]-(k>0?sums[k-1]:0);
			else val2=sums[N-1]-sums[k-1]+sums[j];
			min=min(min,f(i,(k+N-1)%N)+f(k,j)+max(val1,val2));
		}
		return mem[i][j]=min;
	}