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.

Examples

Input

5
2 4 2 3 3


Output

12


Input

3
5 5 5


Output

15


Input

6
10 10 10 1 10 10


Output

11

Note

In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5.

In the second sample Vika can start to paint using any color.

In the third sample Vika should start painting using color number 5.
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            String filename = "";
            if (filename.isEmpty()) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                in = new BufferedReader(new FileReader(filename + ".in"));
                out = new PrintWriter(filename + ".out");
            }
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }


    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    int n;
    int prime1, prime2;
    int mod1, mod2;
    int[] pow1, pow2;

    class Hash {
        int[] h1, h2;
        int n;

        Hash(char[] s) {
            this.n = s.length;
            h1 = new int[n];
            h2 = new int[n];
            h1[0] = h2[0] = s[0];
            for (int i = 1; i < n; i++) {
                h1[i] = (int) ((h1[i - 1] + (long) pow1[i] * s[i]) % mod1);
                h2[i] = (int) ((h2[i - 1] + (long) pow2[i] * s[i]) % mod2);
            }
        }

        long getHash(int L, int R) {
            int hash1 = getHash(L, R, h1, pow1, mod1);
            int hash2 = getHash(L, R, h2, pow2, mod2);
            return ((long) hash1 << 32) | hash2;
        }

        int getHash(int L, int R, int[] h, int[] pow, int mod) {
            int hash = h[R];
            if (L > 0)
                hash -= h[L - 1];
            if (hash < 0)
                hash += mod;
            return (int) ((long) hash * pow[n - R - 1] % mod);
        }


    }

    void init(int n) {
        Random rnd = new Random();
        prime1 = BigInteger.valueOf(3000 + rnd.nextInt(500))
                .nextProbablePrime().intValue();
        prime2 = BigInteger.valueOf(4000 + rnd.nextInt(500))
                .nextProbablePrime().intValue();
        mod1 = BigInteger.valueOf((int) 1e9 + rnd.nextInt(500))
                .nextProbablePrime().intValue();
        mod2 = BigInteger.valueOf((int) 1e9 + (int) 1e6 + rnd.nextInt(500))
                .nextProbablePrime().intValue();
        this.n = n;
        pow1 = new int[n];
        pow2 = new int[n];
        pow1[0] = pow2[0] = 1;
        for (int i = 1; i < n; i++) {
            pow1[i] = (int) ((long) pow1[i - 1] * prime1 % mod1);
            pow2[i] = (int) ((long) pow2[i - 1] * prime2 % mod2);
        }
    }

    Hash ha;
    Hash hb;

    boolean ok(int l, int r, int l2, int r2) {
        long x = ha.getHash(l, r);
        long y = hb.getHash(l2, r2);
        if (x == y) return true;

        if ((r - l + 1) % 2 == 1) return false;
        int m1 = (l + r) >> 1;
        int m2 = (l2 + r2) >> 1;

        return ok(l, m1, l2, m2) && ok(m1 + 1, r, m2 + 1, r2)
                || ok(m1 + 1, r, l2, m2) && ok(l, m1, m2 + 1, r2);
    }

    void solve() throws IOException {
        int n = readInt();
        int[] a = readIntArray(n);
        long answer = 0;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            min = Math.min(min, a[i]);
        }
        int addCount = 0;
        for (int i = 0; i < 2 * n; i++) {
            if (a[i % n] > min) {
                addCount++;
            } else {
                addCount = 0;
            }
            answer = Math.max(answer, addCount);
        }
        answer += (long)n * min;
        out.println(answer);

    }


}