codeforces 610B

Description

Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i.

Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × 1. Squares are numbered 1, 2,3 and so on. Vika decided that she will start painting squares one by one from left to right, starting from the square number 1 and some arbitrary color. If the square was painted in color x, then the next square will be painted in color x + 1. In case of x = n, next square is painted in color 1. If there is no more paint of the color Vika wants to use now, then she stops.

Square is always painted in only one color, and it takes exactly 1 liter of paint. Your task is to calculate the maximum number of squares that might be painted, if Vika chooses right color to paint the first square.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of jars with colors Vika has.

The second line of the input contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is equal to the number of liters of paint in the i-th jar, i.e. the number of liters of color i that Vika has.

Output

The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above.

Sample Input

Input
52 4 2 3 3
Output
12
Input
35 5 5
Output
15
Input
610 10 10 1 10 10
Output
11

要涂油漆,有T(需要输入)种油漆,每种编号1,2,3,4....,没涂完一次,下一种油漆序号要比第一种大,如果到最大,那下一种就是1,输入各种油漆的数量,问你最多能涂多少油漆

 #include <stdio.h>
 #include <iostream>
 using namespace std;
 #define Maxn 210000
 #define INF 1500000000

 struct Node
 {
     long long int num;
 }N[Maxn];

 int main()
 {
     long long int T;
     scanf("%lld",&T);
     long long int min = INF;
     long long int flag_big;
     long long int flag_small;
     long long int flag;
     long long int bigger;
     bool Q = false;
     ; i <= T; i++)
     {
         scanf("%lld",&N[i].num);
         if (min > N[i].num)
         {
             min = N[i].num;
             flag = i;
         }
     }
     )
     {
         printf(].num);//我在这里错了十发- -
         ;
     }
     flag_small = flag;
     ; i <= T; i++)
     {
         if (min == N[i].num && flag < i)
         {
             flag = i;
             Q = true;
         }
     }
     flag_big = flag;
     long long int biggest;
     bigger = T - flag_big + flag_small -;
     ;
     ;
     if (Q)
     {
         for(int i = flag_small; i <= T; i++)
         {
             if (N[i].num == min)
             {
                 count = i - flag_small-;
                 flag_small = i;
             }
             if (count > cnt)
             {
                 cnt = count;
             }
         }
         biggest = max(cnt,bigger);
         //long long Fuck;
         //Fuck = T*min;
         printf("%lld\n",T*min + biggest);
     }
     else
     {
         printf();
     }
 }
上一篇:问题:Maven: missing net.sf.json-lib


下一篇:android--------自定义弹幕控件(视频弹幕操作)