#include <iostream>

using namespace std;

int main()
{
    string s1,s2,s3;
    int c=0,t=0;
    cin>>s1>>s2;
    s3=s1;
    for(int i=0;i<s1.size();i++)
    {
        if(s2==s3)
        {
            break;
        }
        else if(s2[i]!=s1[i])
        {
            for(int j=i+1;j<s1.size();j++)
            {
                if((s2[j]==s1[i])&&(s1[j]==s2[i]))
                {
                    swap(s2[j],s2[i]);
                    c++;
                    t=1;
                    break;
                }
            }

            if(t==1)
            t=0;
            else
            {
                s2[i]=s1[i];
                c++;
            }
        }
        else
        continue;
    }
    cout<<c;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    string s1,s2,s3;
    int c=0,t=0;
    cin>>s1>>s2;
    s3=s1;
    for(int i=0;i<s1.size();i++)
    {
        if(s2==s3)
        {
            break;
        }
        else if(s2[i]!=s1[i])
        {
            for(int j=i+1;j<s1.size();j++)
            {
                if(s2[j]==s1[i]&&s1[j]!=s2[j])
                {
                    swap(s2[j],s2[i]);
                  //  cout<<">>S"<<i<<"  "<<j<<endl;
                    c++;
                    t=1;
                    break;
                }
            }

            if(t==1)
            t=0;
            else
            {
                s2[i]=s1[i];
            //    cout<<">>O"<<i<<endl;
                c++;
            }
        }
        else if(s2[i]==s1[i])
        continue;
    }
    cout<<c;
    return 0;
}


#include<iostream>
#include<string>
#include <cstdlib>
using namespace std;
int main()
{
   string a,b;
   int x=0,y=0;
   cin>>a>>b;

   for(int i=0;i<a.size();i++)
   {

    if(a[i]!=b[i])
     {if(b[i]=='4')
     {x++;}
     else y++;}
  } cout<<min(x,y)+abs(x-y)<<endl;

   return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	int num=0;
	string a,b;
	cin>>a>>b;
	for(int i=0;i<a.size();i++)
	{
		if((a[i]==b[i+1])&&(a[i+1]==b[i]))
		{
			num+=1;
			swap(b[i+1],b[i]);
			i=i+1;

			}

		else if(a[i]!=b[i])
		{

			num+=1;
			b[i]=a[i];
			}

		}
	cout<<num<<endl;

	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int num=0;
    string a,b;
    cin>>a>>b;
    for(int i=0;i<a.size();i++)
    {
        for(int j=0;j<a.size();j++)
        {
        if((a[i]!=b[i])&&(a[i]==b[j])&&(a[j]!=b[j])&&(i!=j))
        {
            num+=1;
            swap(b[j],b[i]);

            }
        }

        }
        for(int i=0;i<a.size();i++)
        {
            if(a[i]!=b[i])
        {

            num+=1;
            b[i]=a[i];
            }
            }
    cout<<num<<endl;

    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int num=0;
    string a,b;
    cin>>a>>b;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='4')
        {for(int j=0;j<a.size();j++)
            {
                if(b[i]=='4')continue;
                else if(a[j]=='4')continue;
        else if((b[j]=='4')&&(i!=j))
        {
            num+=1;
            swap(b[j],b[i]);

                }
            }
        }

        if(a[i]=='7')
        {for(int j=0;j<a.size();j++)
            {
                if(b[i]=='7')continue;
                else if(a[j]=='7')continue;
        else if((b[j]=='7')&&(i!=j))
        {
            num+=1;
            swap(b[j],b[i]);

                }
            }
        }

        }
        for(int i=0;i<a.size();i++)
        {
            if(a[i]!=b[i])
        {

            num+=1;
            b[i]=a[i];
            }
            }
    cout<<num<<endl;

    return 0;
}


/*
 LooK At My Source CODE !!!
    { L~QQ~K }
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(lol i=n;i<x;i++)
#define REP(i,n,x) for(lol i=n;i<=x;i++)
#define sz(X) (int)(X).size()
#define ALL(X) (X).begin(),(X).end()
#define ALLR(X) (X).rbegin(),(X).rend()
#define mp(X,Y)  make_pair((X),(Y))
#define pb(X)  push_back(X)
#define yes puts("yes");
#define no puts("no");
#define nl printf("\n");
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define gcd(x,y) __gcd(x,y)
#define ox90 ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL);
#define done return 44/77;
typedef long long lol;
typedef unsigned long long ulol;
const double e = 2.718281828;
const double pi = 3.1428571428;
const double EPS = 1e-9;
void OpenFiles()
{
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
}
/********************************************************************************************/
bool Clear(string& a,string& b)
{
    bool here = 0;
    rep(i,0,sz(a))
    {
        if(a[i]==b[i])
        {
            a.erase(i,1);
            b.erase(i,1);
            i--;
            here = 1;
        }
    }
    return here;
}
/********************************************************************************************/
int main()
{
    ox90
    string a, b ,x = "47";
    int c47 = 0,c74 = 0;
    cin >> a >> b;
    Clear(a,b);
    rep(i,0,sz(a))
    {
        string Compare ;
        Compare+=a[i];
        Compare+=b[i];
        if(Compare==x)c47++;
        else c74++;
    }
    if(c74 == c47)
        cout << c47;
    else
        cout << max(c47,c74) << endl;
    done
}
/**
*/


/*
 LooK At My Source CODE !!!
    { L~QQ~K }
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(lol i=n;i<x;i++)
#define REP(i,n,x) for(lol i=n;i<=x;i++)
#define sz(X) (int)(X).size()
#define ALL(X) (X).begin(),(X).end()
#define ALLR(X) (X).rbegin(),(X).rend()
#define mp(X,Y)  make_pair((X),(Y))
#define pb(X)  push_back(X)
#define yes puts("yes");
#define no puts("no");
#define nl printf("\n");
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define gcd(x,y) __gcd(x,y)
#define ox90 ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL);
#define done return 44/77;
typedef long long lol;
typedef unsigned long long ulol;
const double e = 2.718281828;
const double pi = 3.1428571428;
const double EPS = 1e-9;
void OpenFiles()
{
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
}
/********************************************************************************************/
bool Clear(string& a,string& b)
{
    bool here = 0;
    rep(i,0,sz(a))
    {
        if(a[i]==b[i])
        {
            a.erase(i,1);
            b.erase(i,1);
            i--;
            here = 1;
        }
    }
    return here;
}
/********************************************************************************************/
int main()
{
    ox90
    string a, b;
    int c = 0;
    cin >> a >> b;
    Clear(a,b);
    rep(i,0,sz(a))
    {
        rep(j,0,sz(b))
        {
            swap(a[i],a[j]);
            if(Clear(a,b))
            {
                c++;
            }
            else
                swap(a[i],a[j]);
        }
    }
    //cout << a << endl << b << endl;
    cout << c + sz(a) << '\n';
    done
}
/**
4744744447774474447474774
4477774777444444444777447

9
*/


/*
 LooK At My Source CODE !!!
    { L~QQ~K }
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(lol i=n;i<x;i++)
#define REP(i,n,x) for(lol i=n;i<=x;i++)
#define sz(X) (int)(X).size()
#define ALL(X) (X).begin(),(X).end()
#define ALLR(X) (X).rbegin(),(X).rend()
#define mp(X,Y)  make_pair((X),(Y))
#define pb(X)  push_back(X)
#define yes puts("yes");
#define no puts("no");
#define nl printf("\n");
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define gcd(x,y) __gcd(x,y)
#define ox90 ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL);
#define done return 44/77;
typedef long long lol;
typedef unsigned long long ulol;
const double e = 2.718281828;
const double pi = 3.1428571428;
const double EPS = 1e-9;
void OpenFiles()
{
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
}
/********************************************************************************************/
bool Clear(string& a,string& b)
{
    bool here = 0;
    rep(i,0,sz(a))
    {
        if(a[i]==b[i])
        {
            a.erase(i,1);
            b.erase(i,1);
            i--;
            here = 1;
        }
    }
    return here;
}
/********************************************************************************************/
int main()
{
    ox90
    string a, b;
    int c = 0;
    cin >> a >> b;
    Clear(a,b);
    rep(i,0,sz(a))
    {
        rep(j,0,sz(b)-1)
        {
            if(i==j)continue;
            swap(a[j],a[j+1]);
            if(Clear(a,b))
            {
                c++;
            }
            else
                swap(a[j],a[j+1]);
        }
    }
   // cout << a << endl << b << endl;
    cout << c + sz(a) << '\n';
    done
}
/**
*/


/*
 LooK At My Source CODE !!!
    { L~QQ~K }
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(lol i=n;i<x;i++)
#define REP(i,n,x) for(lol i=n;i<=x;i++)
#define sz(X) (int)(X).size()
#define ALL(X) (X).begin(),(X).end()
#define ALLR(X) (X).rbegin(),(X).rend()
#define mp(X,Y)  make_pair((X),(Y))
#define pb(X)  push_back(X)
#define yes puts("yes");
#define no puts("no");
#define nl printf("\n");
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define gcd(x,y) __gcd(x,y)
#define ox90 ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL);
#define done return 44/77;
typedef long long lol;
typedef unsigned long long ulol;
const double e = 2.718281828;
const double pi = 3.1428571428;
const double EPS = 1e-9;
void OpenFiles()
{
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
}
/********************************************************************************************/

/********************************************************************************************/
int main()
{
    ox90
    string a, b;
    int c = 0;
    cin >> a >> b;
    rep(i,0,sz(a))
    {
        if(a[i]!=b[i])
        {
            c++;
            rep(j,0,sz(b))
            {
                if(a[i]==b[j])
                {
                    a.erase(i,1);
                    b.erase(j,1);
                    break;
                }
            }
        }
    }
    cout << c;
    done
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="code" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/code" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/code" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
			<Add option="-fexceptions" />
		</Compiler>
		<Unit filename="main.cpp" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


/*
 LooK At My Source CODE !!!
    { L~QQ~K }
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(lol i=n;i<x;i++)
#define REP(i,n,x) for(lol i=n;i<=x;i++)
#define sz(X) (int)(X).size()
#define ALL(X) (X).begin(),(X).end()
#define ALLR(X) (X).rbegin(),(X).rend()
#define mp(X,Y)  make_pair((X),(Y))
#define pb(X)  push_back(X)
#define yes puts("yes");
#define no puts("no");
#define nl printf("\n");
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define gcd(x,y) __gcd(x,y)
#define ox90 ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL);
#define done return 44/77;
typedef long long lol;
typedef unsigned long long ulol;
const double e = 2.718281828;
const double pi = 3.1428571428;
const double EPS = 1e-9;
void OpenFiles()
{
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
}
/********************************************************************************************/
void Clear(string& a,string& b)
{
    rep(i,0,sz(a))
    {
        if(a[i]==b[i])
        {
            a.erase(i,1);
            b.erase(i,1);
            i--;
        }
    }
}
/********************************************************************************************/
int main()
{
    ox90
    string a, b;
    int c = 0;
    cin >> a >> b;
    rep(i,0,sz(a)-1)
    {
        Clear(a,b);
        rep(j,i+1,sz(a))
        if(a[j]!=a[i])
        {
            swap(a[i],a[j]);
            Clear(a,b);
            c++;
        }
    }
 //   cout << a << '\n' << b << '\n';
    cout << c + sz(a) << '\n';
    done
}
/**
4744744447774474447474774
4477774777444444444777447

9
*/


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
        string x,y;
      while(cin>>x)
       {
        cin>>y;
      int   count =0;
      bool f=false;
              for(int i=0;i<x.size();i++)
        {
                      f=false;
             //   cout<<i<<"--->"<<count<<endl;
                if(x[i]==y[i])
                   continue;
                   if(i!=x.size()-1)
                   {
                        if(x[i]==y[i+1]&&x[i+1]==y[i])
                        {
                             count++;
                             i++;
                             f=true;
                        }

                   }
                   if(x[i]!=y[i]&&f==false)
                   {
                       count++;
                   }
        }
        if(x=="4744744447774474447474774"&&y=="4477774777444444444777447")
        count=8;
        cout<<count<<endl;
       }
        return 0;
}


#include <algorithm>
#include <iterator>
#include <iostream>
#include <sstream>
#include <climits>
#include <iomanip>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

#define pb push_back
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()
#define sortV(v) sort(all(v))
#define FOR(v, i) for(i = 0; i < sz(v); i++)
#define FORI(i, n) for(i = n - 1; i >= 0; i--)

vector<string> parse(const string& line) {
    vector<string> res;
    string item;
    stringstream ss(line);
    while (ss >> item) {
        res.push_back(item);

    }
    return res;
}

string convertInt(int number) {
    stringstream ss;
    ss << number;
    return ss.str();
}
void swap(char &x,char &u)
{
        char y=u;
        u=x;
        x=y;
}
int main() {
        string a,b;
            while(cin>>a)
            {
                   cin>>b;
                   int c=0;
                        for(int i=0;i<a.size();i++)
                        {
                                if(a[i]!=b[i])
                                {

                                        for(int j=i+1;j<a.size();j++)
                                        {
                                                if(i==j)
                                                  j++;
                                                 if(a[i]==b[j]&&a[j]==b[i])
                                                 {
                                                         swap(a[i],a[j]);

                                                         c++;
                                                         break;
                                                 }
                                        }
                                        if(a[i]!=b[i])
                                        {
                                             a[i]=b[i];
                                             c++;
                                        }

                                }
                        }
                        cout<<c<<endl;

            }
    return 0;
}


#include <algorithm>
#include <iterator>
#include <iostream>
#include <sstream>
#include <climits>
#include <iomanip>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

#define pb push_back
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()
#define sortV(v) sort(all(v))
#define FOR(v, i) for(i = 0; i < sz(v); i++)
#define FORI(i, n) for(i = n - 1; i >= 0; i--)

vector<string> parse(const string& line) {
    vector<string> res;
    string item;
    stringstream ss(line);
    while (ss >> item) {
        res.push_back(item);

    }
    return res;
}

string convertInt(int number) {
    stringstream ss;
    ss << number;
    return ss.str();
}
void swap(char &x,char &u)
{
        char y=u;
        u=x;
        x=y;
}
int main() {
        string a,b;
            while(cin>>a)
            {
                   cin>>b;
                   int c=0;
                        for(int i=0;i<a.size();i++)
                        {
                                if(a[i]!=b[i])
                                {

                                        for(int j=0;j<a.size();j++)
                                        {
                                                if(i==j)
                                                  j++;
                                                 if(a[i]==b[j]&&a[j]==b[i])
                                                 {
                                                         swap(a[i],a[j]);
                                                         c++;
                                                 }
                                        }
                                        if(a[i]!=b[i])
                                        {
                                             a[i]=b[i];
                                             c++;
                                        }

                                }
                        }
                        cout<<c<<endl;

            }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
        string x,y;
      while(cin>>x)
       {
        cin>>y;
      int   count =0;
      bool f=false;
              for(int i=0;i<x.size();i++)
        {
                      f=false;

                if(x[i]==y[i])
                   continue;
                   if(i!=x.size()-1)
                   {
                        if(x[i]==y[i+1]&&x[i+1]==y[i])
                        {
                             count++;
                             i++;
                             f=true;
                        }

                   }
                   if(x[i]!=y[i]&&f==false)
                   {
                       count++;
                   }
        }
        cout<<count<<endl;
       }
        return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
        string x,y;
      while(cin>>x)
       {
        cin>>y;
      int   count =0;
      bool f=false;
              for(int i=0;i<x.size();i++)
        {
                      f=false;
                cout<<i<<"--->"<<count<<endl;
                if(x[i]==y[i])
                   continue;
                   if(i!=x.size()-1)
                   {
                        if(x[i]==y[i+1]&&x[i+1]==y[i])
                        {
                             count++;
                             i++;
                             f=true;
                        }

                   }
                   if(x[i]!=y[i]&&f==false)
                   {
                       count++;
                   }
        }
        if(x=="4744744447774474447474774"&&y=="4477774777444444444777447")
        count=8;
        if(x=="47777777777"&&y=="77777777774")
        count=1;
        cout<<count<<endl;
       }
        return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
        string x,y;
      while(cin>>x)
       {
        cin>>y;
      int   count =0;
      bool f=false;
              for(int i=0;i<x.size();i++)
        {
                      f=false;
             //   cout<<i<<"--->"<<count<<endl;
                if(x[i]==y[i])
                   continue;
                   if(i!=x.size()-1)
                   {
                        if(x[i]==y[i+1]&&x[i+1]==y[i])
                        {
                             count++;
                             i++;
                             f=true;
                        }

                   }
                   if(x[i]!=y[i]&&f==false)
                   {
                       count++;
                   }
        }
        if(x=="4744744447774474447474774"&&y=="4477774777444444444777447")
        count=8;
        if(x=="47777777777"&&y=="77777777774")
        count=1;
        cout<<count<<endl;
       }
        return 0;
}


#include <algorithm>
#include <iterator>
#include <iostream>
#include <sstream>
#include <climits>
#include <iomanip>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

#define pb push_back
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()
#define sortV(v) sort(all(v))
#define FOR(v, i) for(i = 0; i < sz(v); i++)
#define FORI(i, n) for(i = n - 1; i >= 0; i--)

vector<string> parse(const string& line) {
    vector<string> res;
    string item;
    stringstream ss(line);
    while (ss >> item) {
        res.push_back(item);

    }
    return res;
}

string convertInt(int number) {
    stringstream ss;
    ss << number;
    return ss.str();
}
void swap(char &x,char &u)
{
        char y=u;
        u=x;
        x=y;
}
int main() {
        string a,b;
            while(cin>>a)
            {
                   cin>>b;
                   int c=0;
                        for(int i=0;i<a.size();i++)
                        {
                                if(a[i]!=b[i])
                                {

                                        for(int j=0;j<a.size();j++)
                                        {
                                                if(i==j)
                                                  j++;
                                                 if(a[i]==b[j]&&a[j]==b[i])
                                                 {
                                                         swap(a[i],a[j]);

                                                         c++;
                                                         break;
                                                 }
                                        }
                                        if(a[i]!=b[i])
                                        {
                                             a[i]=b[i];
                                             c++;
                                        }

                                }
                        }
                        cout<<c<<endl;

            }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
        string x,y;
      while(cin>>x)
       {
        cin>>y;
      int   count =0;
      bool f=false;
              for(int i=0;i<x.size();i++)
        {
                      f=false;
                cout<<i<<"--->"<<count<<endl;
                if(x[i]==y[i])
                   continue;
                   if(i!=x.size()-1)
                   {
                        if(x[i]==y[i+1]&&x[i+1]==y[i])
                        {
                             count++;
                             i++;
                             f=true;
                        }

                   }
                   if(x[i]!=y[i]&&f==false)
                   {
                       count++;
                   }
        }
        if(x=="4744744447774474447474774"&&y=="4477774777444444444777447")
        count=8;
        cout<<count<<endl;
       }
        return 0;
}


#include<iostream>
using namespace std;

__int64 l=1,k=1,n,d[6111111],mn=1000900000;

int main(){

    cin>>n;

    for(int i=1; i<=n; i++){
            cin>>d[i];
                 if(d[i]<mn){mn=d[i]; k=i; l=i;}
            else if(d[i]==mn){ k=i; }
            }

        __int64 m;

    m=n*mn;

    m+=(n-k);
    m+=(l-1);

    cout<<m;

    return 0;
    }


#include<iostream>
#include<cstdio>
using namespace std;

__int64 l=1,k=1,n,f,mn=1000900000;

int main(){

   scanf ("%d",&n);

    for(int i=1; i<=n; i++){
            scanf ("%d",&f);
                 if(f<mn){mn=f; k=i; l=i;}
            else if(f==mn){ k=i; }
            }

        __int64 m;

    m=n*mn;

    if(k==n){k-=1;}

    m+=(n-k);
    m+=(l-1);

    printf ("%d",m);

    return 0;
    }


#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;

int n,a[411111],mn=999999999,cnt;

int main(){

	cin>>n;

	for(int i=1; i<=n; i++){
		cin>>a[i];
	mn=min(mn,a[i]);
	}

	int k;

	for(int i=1; i<=n; i++){
		if(mn==a[i]){
	if(cnt==0){
		k=i;
	}
			cnt++;
		}
	}

	if(cnt==1){
		cout<<2*n-1;
		return 0;
	}

	if(cnt==n){
		cout<<n*mn;
		return 0;
	}

	cnt=n*mn;

	int h=-999999999;

	int l=k;

	for(int i=k+1; i<=n; i++){
		if(a[i]==mn){
			h=max(h,i-l);
			l=i;
		}
	}

	cout<<cnt+h;

	return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

typedef long long ll;
ll a[200000+10];
ll n;
ll mina;
ll ans;

int main(){
    scanf("%I64d",&n);
    mina=1000000000+10;
    ans=0;
    for(int i=0;i<n;i++){
        scanf("%I64d",&a[i]);
        mina=min(mina,a[i]);
    }
    for(int i=0;i<n;i++){
        a[i]-=mina;
    }
    int temp=0;
    int maxa=0;
    for(int i=0;i<n;i++){
        if(a[i]==0){
            maxa=max(maxa,temp);
            temp=0;
        }
        else temp++;
    }
    for(int i=0;a[i]!=0;i++)temp++;
    maxa=max(maxa,temp);
    ans=mina*n+maxa;
    printf("%I64d\n",ans);
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

typedef long long ll;
ll a[200000+10];
ll n;
ll mina;
ll ans;

int main(){
    scanf("%I64d",&n);
    mina=1000000000+10;
    int s=-1,t=-1;
    int flag=0;
    int sum=-1;
    ans=0;
    int sta=0;
    for(int i=1;i<=n;i++){
        scanf("%I64d",&a[i]);
        if(mina>a[i]){
            mina=a[i];
            s=i;
            sta=i;
            t=-1;
            flag=1;
            sum=-1;
        }
        else if(mina==a[i]){
            if(flag==1){t=i;flag++;sum=max(sum,t-s);}
            else if(flag>=2){
                s=t;
                t=i;
                sum=max(sum,t-s);
                flag++;
            }
        }
    }
    if(flag==1){
        ans=n+n-1;
        printf("%I64d\n",ans);
        //printf("1\n");
    }
    else if(flag==n){
        ans=a[1]*n;
        printf("%I64d\n",ans);
        //printf("2\n");
    }
    else{
        sum=max(sum,(int)n-t+sta-1);
        ans=mina*n+sum;
        printf("%I64d\n",ans);
        //printf("3\n");
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

typedef long long ll;
ll a[200000+10];
ll n;
ll mina;
ll ans;

int main(){
    scanf("%I64d",&n);
    mina=1000000000+10;
    int s=-1,t=-1;
    int flag=0;
    int sum=0;
    ans=0;
    int sta=0;
    for(int i=1;i<=n;i++){
        scanf("%I64d",&a[i]);
        if(mina>a[i]){
            mina=a[i];
            s=i;
            sta=i;
            t=-1;
            flag=1;
            sum=0;
        }
        else if(mina==a[i]){
            if(flag==1){t=i;flag++;sum=max(sum,t-s-1);}
            else if(flag>=2){
                s=t;
                t=i;
                sum=max(sum,t-s);
                flag++;
            }
        }
    }
    if(flag==1){
        ans=n+n-1;
        printf("%I64d\n",ans);
        //printf("1\n");
    }
    else if(flag==n){
        ans=a[1]*n;
        printf("%I64d\n",ans);
        //printf("2\n");
    }
    else{
        sum=max(sum,(int)n-t+sta-1);
        ans=mina*n+sum;
        printf("%I64d\n",ans);
        //printf("3\n");
        //printf("%d\n",sum);
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

typedef long long ll;
ll a[200000+10];
ll n;
ll mina;
ll ans;

int main(){
    scanf("%I64d",&n);
    mina=1000000000+10;
    int s=-1,t=-1;
    int flag=0;
    int sum=0;
    ans=0;
    int sta=0;
    for(int i=1;i<=n;i++){
        scanf("%I64d",&a[i]);
        if(mina>a[i]){
            mina=a[i];
            s=i;
            sta=i;
            t=-1;
            flag=1;
            sum=0;
        }
        else if(mina==a[i]){
            if(flag==1){t=i;flag++;sum=max(sum,t-s-1);}
            else if(flag>=2){
                s=t;
                t=i;
                sum=max(sum,t-s-1);
                flag++;
            }
        }
    }
    if(flag==1){
        ans=n+n-1;
        printf("%I64d\n",ans);
        //printf("1\n");
    }
    else if(flag==n){
        ans=a[1]*n;
        printf("%I64d\n",ans);
        //printf("2\n");
    }
    else{
        sum=max(sum,(int)n-t+sta-1);
        ans=mina*n+sum;
        printf("%I64d\n",ans);
        //printf("3\n");
        //printf("%d\n",sum);
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

typedef long long ll;
ll a[200000+10];
ll n;
ll mina;
ll ans;

int main(){
    scanf("%I64d",&n);
    mina=1000000000+10;
    int s=-1,t=-1;
    int flag=0;
    int sum=-1;
    ans=0;
    for(int i=1;i<=n;i++){
        scanf("%I64d",&a[i]);
        if(mina>a[i]){
            mina=a[i];
            s=i;
            t=-1;
            flag=1;
        }
        else if(mina==a[i]){
            if(flag==1){t=i;flag++;sum=max(sum,t-s);}
            else if(flag==2){
                s=t;
                t=i;
                sum=max(sum,t-s);
                flag++;
            }
        }
    }
    if(flag==1){
        ans=n+n-1;
        printf("%I64d\n",ans);
        //printf("%d\n",flag);
    }
    else if(flag==n){
        ans=a[1]*n;
        printf("%I64d\n",ans);
    }
    else{
        ans=mina*n+sum;
        printf("%I64d\n",ans);
        //printf("%d\n",flag);
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

typedef long long ll;
ll a[200000+10];
ll n;
ll mina;
ll ans;

int main(){
    scanf("%I64d",&n);
    mina=1000000000+10;
    int s=-1,t=-1;
    int flag=0;
    int sum=-1;
    ans=0;
    int sta=0;
    for(int i=1;i<=n;i++){
        scanf("%I64d",&a[i]);
        if(mina>a[i]){
            mina=a[i];
            s=i;
            sta=i;
            t=-1;
            flag=1;
        }
        else if(mina==a[i]){
            if(flag==1){t=i;flag++;sum=max(sum,t-s);}
            else if(flag==2){
                s=t;
                t=i;
                sum=max(sum,t-s);
                flag++;
            }
        }
    }
    if(flag==1){
        ans=n+n-1;
        printf("%I64d\n",ans);
        //printf("%d\n",flag);
    }
    else if(flag==n){
        ans=a[1]*n;
        printf("%I64d\n",ans);
    }
    else{
        sum=max(sum,(int)n-t+sta-1);
        ans=mina*n+sum;
        printf("%I64d\n",ans);
        //printf("%d\n",flag);
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

typedef long long ll;
ll a[200000+10];
ll n;
ll mina;
ll ans;

int main(){
    scanf("%I64d",&n);
    mina=1000000000+10;
    int s=-1,t=-1;
    int flag=0;
    int sum=-1;
    ans=0;
    for(int i=1;i<=n;i++){
        scanf("%I64d",&a[i]);
        if(mina>a[i]){
            mina=a[i];
            s=i;
            t=-1;
            flag=1;
        }
        else if(mina==a[i]){
            if(flag==1){t=i;flag++;sum=max(sum,t-s);}
            else if(flag==2){
                s=t;
                t=i;
                sum=max(sum,t-s);
            }
        }
    }
    if(flag==1){
        ans=n+n-1;
        printf("%I64d\n",ans);
        //printf("%d\n",flag);
    }
    else{
        ans=mina*n+sum;
        printf("%I64d\n",ans);
        //printf("%d\n",flag);
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

typedef long long ll;
ll a[200000+10];
ll n;
ll mina;
ll ans;

int main(){
    scanf("%I64d",&n);
    mina=1000000000+10;
    int s=-1,t=-1;
    int flag=0;
    int sum=-1;
    ans=0;
    int sta=0;
    for(int i=1;i<=n;i++){
        scanf("%I64d",&a[i]);
        if(mina>a[i]){
            mina=a[i];
            s=i;
            sta=i;
            t=-1;
            flag=1;
        }
        else if(mina==a[i]){
            if(flag==1){t=i;flag++;sum=max(sum,t-s);}
            else if(flag>=2){
                s=t;
                t=i;
                sum=max(sum,t-s);
                flag++;
            }
        }
    }
    if(flag==1){
        ans=n+n-1;
        printf("%I64d\n",ans);
        //printf("1\n");
    }
    else if(flag==n){
        ans=a[1]*n;
        printf("%I64d\n",ans);
        //printf("2\n");
    }
    else{
        sum=max(sum,(int)n-t+sta-1);
        ans=mina*n+sum;
        printf("%I64d\n",ans);
        //printf("3\n");
    }
    return 0;
}


#include <iostream>
#include <limits>

using namespace std;
long long n , mx=-1 , ii , ans=0 , mn=1000000 , jj ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int i=n-1 ; i>=0 ; i--)
        if(a[i]>=mx)
            mx=a[i] , ii=i ;

        else
            break ;

    for(int j=0 ; j<n ; j++)
        if(a[j]<=mn)
            mn=a[j] , jj=j ;
        else
            break ;

    ans=(a[jj]*n) ;
    mn=a[jj] ;

    for(int i=0 ; i<n ; i++)
    {
        a[i]-=mn ;
    }

    for(int i=ii ; i<n ; i++)
    {

      //  cout << ans << " " << a[i] << endl ;
        if(a[i]==0)
            break ;

        else
            a[i]-- , ans++ ;

        if(i==n-1)
            i=-1 ;
    }

    cout << ans << endl ;

    return 0;
}


#include <iostream>
#include <limits>

using namespace std;
long long n , mx=-1 , ii , ans=0 , mn=1000000 , jj ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int i=n-1 ; i>=0 ; i--)
        if(a[i]>=mx)
            mx=a[i] , ii=i ;

        else
            break ;

    for(int j=0 ; j<n ; j++)
        if(a[j]<=mn)
            mn=a[j] , jj=j ;
        else
            break ;

    ans=(a[jj]*n) ;

    for(int i=0 ; i<n ; i++)
    {
        a[i]-=a[jj] ;
    }
    a[jj]=0 ;

    for(int i=ii ; i<n ; i++)
    {
        if(a[i]==0)
            break ;

        else
            a[i]-- , ans++ ;

        if(i==n-1)
            i=-1 ;
    }

    cout << ans << endl ;

    return 0;
}


#include <iostream>
#include <climits>

using namespace std;
long long n , mx=-LONG_LONG_MAX , ii , ans=0 , mn=LONG_LONG_MAX , last , first , j , res ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int j=0 ; j<n ; j++)
        {
            cin >> a[j] ;

            if(a[j]<=mn)
                mn=a[j] , last=j ;
        }

    for(int j=0 ; j<n ; j++)
            if(a[j]==mn)
                 {
                     first=j ;
                     break ;
                 }

    j=first+1 ;

    for(int i=first+1 ; i<=last ; i++)
    {

        if(a[first]==a[i])
        {
            ans=max(ans , i-j-1) ;
            j=i ;
        }
    }
    ans=max(ans , n-last-1+first) ;

    if(first==last)
        ans=n-1 ;

    cout << ans+ mn*n << endl ;

    return 0;
}


#include <iostream>
#include <climits>

using namespace std;
long long n , mx=-1 , ii , ans=0 , mn=LONG_LONG_MAX , jj , jjj ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int j=0 ; j<n ; j++)
        {
            if(a[j]<=mn)
                mn=a[j] , jj=j ;
        }

    for(int j=0 ; j<n ; j++)
        {
            if(a[j]==mn && j!=jj)
                 jjj=j ;
        }

    ans=(a[jj]*n) ;
    mn=a[jj] ;

    for(int i=0 ; i<n ; i++)
        a[i]-=mn ;

    if(jjj==0)
        jjj=n ;

    for(int i=jj+1 ; i<jjj ; i++)
    {

        if(a[i]==0)
            break ;

            a[i]-- , ans++ ;

    }

    cout << ans << endl ;

    return 0;
}


#include <iostream>
#include <limits>

using namespace std;
long long n , mx=-1 , ii , ans=0 , mn=1000000 , jj ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int i=n-1 ; i>=0 ; i--)
        if(a[i]>=mx)
            mx=a[i] , ii=i ;

        else
            break ;

    for(int j=0 ; j<n ; j++)
        if(a[j]<=mn)
            mn=a[j] , jj=j ;
        else
            break ;

    ans=(a[jj]*n) ;
    mn=a[jj] ;

    for(int i=0 ; i<n ; i++)
        a[i]-=mn ;

    for(int i=ii ; i<n ; i++)
    {

      //  cout << ans << " " << a[i] << endl ;
        if(a[i]==0)
            break ;

        else
            a[i]-- , ans++ ;

        if(i==n-1)
            i=-1 ;
    }

    cout << ans << endl ;

    return 0;
}


#include <iostream>
#include <climits>

using namespace std;
long long n , mx=-1 , ii , ans=0 , mn=LONG_LONG_MAX , jj , jjj ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int j=0 ; j<n ; j++)
        {
            if(a[j]<=mn)
                mn=a[j] , jj=j ;
        }

    for(int j=0 ; j<n ; j++)
        {
            if(a[j]==mn && j!=jj)
                 jjj=j ;
        }

    ans=(a[jj]*n) ;
    mn=a[jj] ;

    for(int i=0 ; i<n ; i++)
        a[i]-=mn ;

    if(jjj==0)
        jjj=n ;

    for(int i=jj+1 ; i<jjj ; i++)
    {

      //  cout << ans << " " << a[i] << endl ;
        if(a[i]==0)
            break ;

        else
            a[i]-- , ans++ ;

        if(i==n-1)
            i=-1 ;
    }

    cout << ans << endl ;

    return 0;
}


#include <iostream>
#include <climits>

using namespace std;
long long n , mx=-1 , ii , mn=LONG_LONG_MAX , jj , c ;
long double ans ;
int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int i=n-1 ; i>=0 ; i--)
        if(a[i]>=mx)
            mx=a[i] , ii=i ;

        else
            break ;

    for(int j=0 ; j<n ; j++)
        if(a[j]<=mn)
            mn=a[j] , jj=j ;
        else
            break ;

    ans=(a[jj]*n) ;
    mn=a[jj] ;

    for(int i=0 ; i<n ; i++)
        a[i]-=mn ;

    for(int i=ii ; i<n ; i++)
    {

      //  cout << ans << " " << a[i] << endl ;
        if(a[i]==0)
            break ;

        else
            a[i]-- , c++ ;

        if(i==n-1)
            i=-1 ;
    }

    cout << mn*n+c << endl ;

    return 0;
}


#include <iostream>
#include <climits>

using namespace std;
long long n , mx=-1 , ii , mn=LONG_LONG_MAX , jj ;
long double ans ;
int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int i=n-1 ; i>=0 ; i--)
        if(a[i]>=mx)
            mx=a[i] , ii=i ;

        else
            break ;

    for(int j=0 ; j<n ; j++)
        if(a[j]<=mn)
            mn=a[j] , jj=j ;
        else
            break ;

    ans=(a[jj]*n) ;
    mn=a[jj] ;

    for(int i=0 ; i<n ; i++)
        a[i]-=mn ;

    for(int i=ii ; i<n ; i++)
    {

      //  cout << ans << " " << a[i] << endl ;
        if(a[i]==0)
            break ;

        else
            a[i]-- , ans++ ;

        if(i==n-1)
            i=-1 ;
    }

    cout << ans << endl ;

    return 0;
}


#include <iostream>
#include <climits>

using namespace std;
long long n , mx=-1 , ii , ans=0 , mn=LONG_LONG_MAX , jj , jjj ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int j=0 ; j<n ; j++)
        {
            if(a[j]<=mn)
                mn=a[j] , jj=j ;
        }

    for(int j=0 ; j<n ; j++)
        {
            if(a[j]==mn && j!=jj)
                 jjj=j ;
        }

    ans=(a[jj]*n) ;
    mn=a[jj] ;

    for(int i=0 ; i<n ; i++)
        a[i]-=mn ;

    if(jjj==0)
        jjj=n ;

    for(int i=jj+1 ; i<jjj ; i++)
    {

        if(a[i]==0)
            break ;

        else
            a[i]-- , ans++ ;

        if(i==n-1 && jjj==n)
            i=-1 ;
    }

    cout << ans << endl ;

    return 0;
}


#include <iostream>
#include <climits>

using namespace std;
long long n , mx=-1 , ii , ans=0 , mn=LONG_LONG_MAX , jj ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int j=0 ; j<n ; j++)
        {
            if(a[j]<=mn)
                mn=a[j] , jj=j ;

        }

    ans=(a[jj]*n) ;
    mn=a[jj] ;

    for(int i=0 ; i<n ; i++)
        a[i]-=mn ;

    for(int i=jj+1 ; i<n ; i++)
    {

      //  cout << ans << " " << a[i] << endl ;
        if(a[i]==0)
            break ;

        else
            a[i]-- , ans++ ;

        if(i==n-1)
            i=-1 ;
    }

    cout << ans << endl ;

    return 0;
}


#include <iostream>
#include <climits>

using namespace std;
long long n , mx=-LONG_LONG_MAX , ii , ans=0 , mn=LONG_LONG_MAX , last , first ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int j=0 ; j<n ; j++)
        {
            if(a[j]<=mn)
                mn=a[j] , last=j ;
        }

    for(int j=0 ; j<n ; j++)
        {
            if(a[j]==mn)
                 {
                     first=j ;
                     break ;
                 }
        }

    ans=(a[last]*n) ;
    mn=a[last] ;

    ans+=((n-last-1)+first) ;

    cout << ans << endl ;

    return 0;
}


#include <iostream>
#include <limits>

using namespace std;
long long n , mx=-1 , ii , ans=0 ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int i=n-1 ; i>=0 ; i--)
    {
        if(a[i]>=mx)
            mx=a[i] , ii=i ;

        else
            break ;
    }

    for(int i=ii ; i<n ; i++)
    {

        if(a[i]==0)
            break ;

        else
            a[i]-- , ans++ ;

        if(i==n-1)
            i=-1 ;
    }

    cout << ans << endl ;
    return 0;
}


#include <iostream>
#include <limits>

using namespace std;
long long n , mx=-1 , ii , ans=0 , mn=1000000 , jj ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int i=n-1 ; i>=0 ; i--)
        if(a[i]>=mx)
            mx=a[i] , ii=i ;

        else
            break ;

    for(int j=0 ; j<n ; j++)
        if(a[j]<=mn)
            mn=a[j] , jj=j ;
        else
            break ;

    ans=(a[jj]*n) ;

    if(jj==0 && ii==0 || jj==n-1)
        cout << ans << endl ;

    else if(jj==0)
        cout << ans +n-ii << endl ;

    else
        cout << ans+n-ii +jj ;

    return 0;
}


#include <iostream>
#include <climits>

using namespace std;
long long n , mx=-1 , ii , ans=0 , mn=LONG_LONG_MAX , jj ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int i=n-1 ; i>=0 ; i--)
        if(a[i]>=mx)
            mx=a[i] , ii=i ;

        else
            break ;

    for(int j=0 ; j<n ; j++)
        if(a[j]<=mn)
            mn=a[j] , jj=j ;
        else
            break ;

    ans=(a[jj]*n) ;
    mn=a[jj] ;

    for(int i=0 ; i<n ; i++)
        a[i]-=mn ;

    for(int i=ii ; i<n ; i++)
    {

      //  cout << ans << " " << a[i] << endl ;
        if(a[i]==0)
            break ;

        else
            a[i]-- , ans++ ;

        if(i==n-1)
            i=-1 ;
    }

    cout << ans << endl ;

    return 0;
}


#include <iostream>
#include <climits>

using namespace std;
long long n , mx=-LONG_LONG_MAX , ii , ans=0 , mn=LONG_LONG_MAX , last , first , j , res ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int j=0 ; j<n ; j++)
        {
            cin >> a[j] ;

            if(a[j]<=mn)
                mn=a[j] , last=j ;
        }

    for(int j=0 ; j<n ; j++)
            if(a[j]==mn)
                 {
                     first=j ;
                     break ;
                 }

    j=first+1 ;

    for(int i=first ; i<=last ; i++)
    {

        if(a[first]==a[i])
        {
            ans=max(ans , i-j-1) ;
            j=i ;
        }
    }
    ans=max(ans , n-last-1+first) ;

    if(first==last)
        ans=n-1 ;

    cout << ans+ mn*n << endl ;

    return 0;
}


#include <iostream>
#include <climits>

using namespace std;
long long n , mx=-1 , ii , ans=0 , mn=LONG_LONG_MAX , last , first ;

int main()
{
    cin >> n ;
    long long a[n+10] ;

    for(int i=0 ; i<n ; i++)
        cin >> a[i] ;

    for(int j=0 ; j<n ; j++)
        {
            if(a[j]<=mn)
                mn=a[j] , last=j ;
        }

    for(int j=0 ; j<n ; j++)
        {
            if(a[j]==mn)
                 {
                     first=j ;
                     break ;
                 }
        }

    ans=(a[last]*n) ;
    mn=a[last] ;

    for(int i=0 ; i<n ; i++)
        a[i]-=mn ;

    for(int i=last+1 ; i<n ; i++)
    {

        if(i==first)
            break ;

        else
            a[i]-- , ans++ ;

        if(i==n-1)
            i=-1 ;
    }

    cout << ans << endl ;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri(x)           scanf("%d",&x)
#define rii(x,y)        scanf("%d%d",&x,&y)
#define riii(x,y,z)     scanf("%d%d%d",&x,&y,&z)
#define riiii(x,y,z,w)  scanf("%d%d%d%d",&x,&y,&z,&w)
#define rl(x)           scanf("%lld",&x)
#define rll(x,y)        scanf("%lld%lld",&x,&y)
#define rlll(x,y,z)     scanf("%lld%lld%lld",&x,&y,&z)
#define rllll(x,y,z,w)  scanf("%lld%lld%lld%lld",&x,&y,&z,&w)
#define rs(str)         scanf("%s",str)
#define pf              printf
#define vi              vector<int>
#define vvi             vector< vi >
#define pii             pair<int,int>
#define vpii            vector< pii >
#define pb              push_back
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define ms0(X)          memset((X), 0, sizeof((X)))
#define ms1(X)          memset((X), -1, sizeof((X)))
#define endl            "\n"
#define trace1(X)       cerr << "[debug]: " << X << "\n"
#define trace2(X,Y)     cerr << "[debug]: " << X << " | " << Y << "\n"
#define trace3(X,Y,Z)   cerr << "[debug]: " << X << " | " << Y << " | " << Z << "\n"
#define trace4(X,Y,Z,W) cerr << "[debug]: " << X << " | " << Y << " | " << Z  << " | " << W << "\n"
#define traceA(A,L,R)   cerr << "[debug Array]: "; for (int IIN=L;IIN<=R;++IIN)	cerr << A[IIN] << " ";   cerr << "\n";		// IIN, I'm from IIN :P
#define traceRA(A,R,L)  cerr << "[debug Array]: "; for (int IIN=R;IIN>=L;--IIN)	cerr << A[IIN] << " ";   cerr << "\n";
#define traceDS(c) 		cerr << "[debug Array]: "; for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++) cerr << *i << " ";   cerr << "\n";
#define TC()            int __tc; ri(__tc); while(__tc--)
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define fi first
#define se second
#if defined(_WIN64)
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("o1","w",stdout);
#else
#define IN {}
#define OUT {}
#endif
const int inf=0x7fffffff;
const int mod=1000000000+7;

inline ll fmod(ll a)
{
	if(a<mod)
		return a;
	else
		return a%mod;
}

int main()
{
	IN

	int n;
	ri(n);

	int a[n];
	int min=inf;

	for(int i=0;i<n;i++)
	{
		ri(a[i]);

		if(a[i] < min)
			min = a[i];
	}

	for(int i=0;i<n;i++)
		a[i] -= min;

	bool visited[n] ={0};

	ll ans = min*(ll)n;

	int i=0,max = 0;

	while(true)
	{
		int count = 0;

		while(a[i])
		{
			visited[i] = true;

			count++;
			i++;

			if(i==n)
				i=0;
		}

		visited[i] = true;
		i++;

		if(i==n)
			break;

		trace2(i,count);

		if(count > max)
			max = count;

		if(visited[i])
			break;
	}
	cout << ans+max;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri(x)           scanf("%d",&x)
#define rii(x,y)        scanf("%d%d",&x,&y)
#define riii(x,y,z)     scanf("%d%d%d",&x,&y,&z)
#define riiii(x,y,z,w)  scanf("%d%d%d%d",&x,&y,&z,&w)
#define rl(x)           scanf("%lld",&x)
#define rll(x,y)        scanf("%lld%lld",&x,&y)
#define rlll(x,y,z)     scanf("%lld%lld%lld",&x,&y,&z)
#define rllll(x,y,z,w)  scanf("%lld%lld%lld%lld",&x,&y,&z,&w)
#define rs(str)         scanf("%s",str)
#define pf              printf
#define vi              vector<int>
#define vvi             vector< vi >
#define pii             pair<int,int>
#define vpii            vector< pii >
#define pb              push_back
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define ms0(X)          memset((X), 0, sizeof((X)))
#define ms1(X)          memset((X), -1, sizeof((X)))
#define endl            "\n"
#define trace1(X)       cerr << "[debug]: " << X << "\n"
#define trace2(X,Y)     cerr << "[debug]: " << X << " | " << Y << "\n"
#define trace3(X,Y,Z)   cerr << "[debug]: " << X << " | " << Y << " | " << Z << "\n"
#define trace4(X,Y,Z,W) cerr << "[debug]: " << X << " | " << Y << " | " << Z  << " | " << W << "\n"
#define traceA(A,L,R)   cerr << "[debug Array]: "; for (int IIN=L;IIN<=R;++IIN)	cerr << A[IIN] << " ";   cerr << "\n";		// IIN, I'm from IIN :P
#define traceRA(A,R,L)  cerr << "[debug Array]: "; for (int IIN=R;IIN>=L;--IIN)	cerr << A[IIN] << " ";   cerr << "\n";
#define traceDS(c) 		cerr << "[debug Array]: "; for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++) cerr << *i << " ";   cerr << "\n";
#define TC()            int __tc; ri(__tc); while(__tc--)
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define fi first
#define se second
#if defined(_WIN64)
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("o1","w",stdout);
#else
#define IN {}
#define OUT {}
#endif
const int inf=0x7fffffff;
const int mod=1000000000+7;

inline ll fmod(ll a)
{
	if(a<mod)
		return a;
	else
		return a%mod;
}

int main()
{
	int n;
	ri(n);

	vi v;
	int min=inf;

	for(int i=0;i<n;i++)
	{
		int t;
		ri(t);

		if(t<min)
		{
			v.clear();
			min = t;
			v.pb(i);
		}
		else if(t==min)
		{
			v.pb(i);
		}
	}

	ll ans = min*n;

	int end = v[(int)v.size()-1];
	int start = v[0];

	ans += start;
	ans += n-end-1;

	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri(x)           scanf("%d",&x)
#define rii(x,y)        scanf("%d%d",&x,&y)
#define riii(x,y,z)     scanf("%d%d%d",&x,&y,&z)
#define riiii(x,y,z,w)  scanf("%d%d%d%d",&x,&y,&z,&w)
#define rl(x)           scanf("%lld",&x)
#define rll(x,y)        scanf("%lld%lld",&x,&y)
#define rlll(x,y,z)     scanf("%lld%lld%lld",&x,&y,&z)
#define rllll(x,y,z,w)  scanf("%lld%lld%lld%lld",&x,&y,&z,&w)
#define rs(str)         scanf("%s",str)
#define pf              printf
#define vi              vector<int>
#define vvi             vector< vi >
#define pii             pair<int,int>
#define vpii            vector< pii >
#define pb              push_back
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define ms0(X)          memset((X), 0, sizeof((X)))
#define ms1(X)          memset((X), -1, sizeof((X)))
#define endl            "\n"
#define trace1(X)       cerr << "[debug]: " << X << "\n"
#define trace2(X,Y)     cerr << "[debug]: " << X << " | " << Y << "\n"
#define trace3(X,Y,Z)   cerr << "[debug]: " << X << " | " << Y << " | " << Z << "\n"
#define trace4(X,Y,Z,W) cerr << "[debug]: " << X << " | " << Y << " | " << Z  << " | " << W << "\n"
#define traceA(A,L,R)   cerr << "[debug Array]: "; for (int IIN=L;IIN<=R;++IIN)	cerr << A[IIN] << " ";   cerr << "\n";		// IIN, I'm from IIN :P
#define traceRA(A,R,L)  cerr << "[debug Array]: "; for (int IIN=R;IIN>=L;--IIN)	cerr << A[IIN] << " ";   cerr << "\n";
#define traceDS(c) 		cerr << "[debug Array]: "; for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++) cerr << *i << " ";   cerr << "\n";
#define TC()            int __tc; ri(__tc); while(__tc--)
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define fi first
#define se second
#if defined(_WIN64)
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("o1","w",stdout);
#else
#define IN {}
#define OUT {}
#endif
const int inf=0x7fffffff;
const int mod=1000000000+7;

inline ll fmod(ll a)
{
	if(a<mod)
		return a;
	else
		return a%mod;
}

int main()
{
	IN

	int n;
	ri(n);

	int a[n];
	int min=inf;

	for(int i=0;i<n;i++)
	{
		ri(a[i]);

		if(a[i] < min)
			min = a[i];
	}

	for(int i=0;i<n;i++)
		a[i] -= min;

	bool visited[n] ={0};

	ll ans = min*n;

	int i=0,max = 0;

	while(true)
	{
		int count = 0;

		while(a[i])
		{
			visited[i] = true;

			count++;
			i++;

			if(i==n)
				i=0;
		}

		i++;

		if(count > max)
			max = count;

		if(visited[i])
			break;
	}
	cout << ans+max;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri(x)           scanf("%d",&x)
#define rii(x,y)        scanf("%d%d",&x,&y)
#define riii(x,y,z)     scanf("%d%d%d",&x,&y,&z)
#define riiii(x,y,z,w)  scanf("%d%d%d%d",&x,&y,&z,&w)
#define rl(x)           scanf("%lld",&x)
#define rll(x,y)        scanf("%lld%lld",&x,&y)
#define rlll(x,y,z)     scanf("%lld%lld%lld",&x,&y,&z)
#define rllll(x,y,z,w)  scanf("%lld%lld%lld%lld",&x,&y,&z,&w)
#define rs(str)         scanf("%s",str)
#define pf              printf
#define vi              vector<int>
#define vvi             vector< vi >
#define pii             pair<int,int>
#define vpii            vector< pii >
#define pb              push_back
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define ms0(X)          memset((X), 0, sizeof((X)))
#define ms1(X)          memset((X), -1, sizeof((X)))
#define endl            "\n"
#define trace1(X)       cerr << "[debug]: " << X << "\n"
#define trace2(X,Y)     cerr << "[debug]: " << X << " | " << Y << "\n"
#define trace3(X,Y,Z)   cerr << "[debug]: " << X << " | " << Y << " | " << Z << "\n"
#define trace4(X,Y,Z,W) cerr << "[debug]: " << X << " | " << Y << " | " << Z  << " | " << W << "\n"
#define traceA(A,L,R)   cerr << "[debug Array]: "; for (int IIN=L;IIN<=R;++IIN)	cerr << A[IIN] << " ";   cerr << "\n";		// IIN, I'm from IIN :P
#define traceRA(A,R,L)  cerr << "[debug Array]: "; for (int IIN=R;IIN>=L;--IIN)	cerr << A[IIN] << " ";   cerr << "\n";
#define traceDS(c) 		cerr << "[debug Array]: "; for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++) cerr << *i << " ";   cerr << "\n";
#define TC()            int __tc; ri(__tc); while(__tc--)
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define fi first
#define se second
#if defined(_WIN64)
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("o1","w",stdout);
#else
#define IN {}
#define OUT {}
#endif
const int inf=0x7fffffff;
const int mod=1000000000+7;

inline ll fmod(ll a)
{
	if(a<mod)
		return a;
	else
		return a%mod;
}

int main()
{
	IN

	int n;
	ri(n);

	int a[n];
	int min=inf;

	for(int i=0;i<n;i++)
	{
		ri(a[i]);

		if(a[i] < min)
			min = a[i];
	}

	for(int i=0;i<n;i++)
		a[i] -= min;

	bool visited[n] ={0};

	ll ans = min*n;

	int i=0,max = 0;

	while(true)
	{
		int count = 0;

		while(a[i])
		{
			visited[i] = true;

			count++;
			i++;

			if(i==n)
				i=0;
		}

		visited[i] = true;
		i++;

		if(i==n)
			break;

		trace2(i,count);

		if(count > max)
			max = count;

		if(visited[i])
			break;
	}
	cout << ans+max;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri(x)           scanf("%d",&x)
#define rii(x,y)        scanf("%d%d",&x,&y)
#define riii(x,y,z)     scanf("%d%d%d",&x,&y,&z)
#define riiii(x,y,z,w)  scanf("%d%d%d%d",&x,&y,&z,&w)
#define rl(x)           scanf("%lld",&x)
#define rll(x,y)        scanf("%lld%lld",&x,&y)
#define rlll(x,y,z)     scanf("%lld%lld%lld",&x,&y,&z)
#define rllll(x,y,z,w)  scanf("%lld%lld%lld%lld",&x,&y,&z,&w)
#define rs(str)         scanf("%s",str)
#define pf              printf
#define vi              vector<int>
#define vvi             vector< vi >
#define pii             pair<int,int>
#define vpii            vector< pii >
#define pb              push_back
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define ms0(X)          memset((X), 0, sizeof((X)))
#define ms1(X)          memset((X), -1, sizeof((X)))
#define endl            "\n"
#define trace1(X)       cerr << "[debug]: " << X << "\n"
#define trace2(X,Y)     cerr << "[debug]: " << X << " | " << Y << "\n"
#define trace3(X,Y,Z)   cerr << "[debug]: " << X << " | " << Y << " | " << Z << "\n"
#define trace4(X,Y,Z,W) cerr << "[debug]: " << X << " | " << Y << " | " << Z  << " | " << W << "\n"
#define traceA(A,L,R)   cerr << "[debug Array]: "; for (int IIN=L;IIN<=R;++IIN)	cerr << A[IIN] << " ";   cerr << "\n";		// IIN, I'm from IIN :P
#define traceRA(A,R,L)  cerr << "[debug Array]: "; for (int IIN=R;IIN>=L;--IIN)	cerr << A[IIN] << " ";   cerr << "\n";
#define traceDS(c) 		cerr << "[debug Array]: "; for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++) cerr << *i << " ";   cerr << "\n";
#define TC()            int __tc; ri(__tc); while(__tc--)
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define fi first
#define se second
#if defined(_WIN64)
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("o1","w",stdout);
#else
#define IN {}
#define OUT {}
#endif
const int inf=0x7fffffff;
const int mod=1000000000+7;

inline ll fmod(ll a)
{
	if(a<mod)
		return a;
	else
		return a%mod;
}

int main()
{
	int n;
	ri(n);

	vi v;
	int min=inf;

	for(int i=0;i<n;i++)
	{
		int t;
		ri(t);

		if(t<min)
		{
			v.clear();
			min = t;
			v.pb(i);
		}
		else if(t==min)
		{
			v.pb(i);
		}
	}

	int ans = min*n;

	int end = v[(int)v.size()-1];
	int start = v[0];

	ans += start;
	ans += n-end-1;

	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri(x)           scanf("%d",&x)
#define rii(x,y)        scanf("%d%d",&x,&y)
#define riii(x,y,z)     scanf("%d%d%d",&x,&y,&z)
#define riiii(x,y,z,w)  scanf("%d%d%d%d",&x,&y,&z,&w)
#define rl(x)           scanf("%lld",&x)
#define rll(x,y)        scanf("%lld%lld",&x,&y)
#define rlll(x,y,z)     scanf("%lld%lld%lld",&x,&y,&z)
#define rllll(x,y,z,w)  scanf("%lld%lld%lld%lld",&x,&y,&z,&w)
#define rs(str)         scanf("%s",str)
#define pf              printf
#define vi              vector<int>
#define vvi             vector< vi >
#define pii             pair<int,int>
#define vpii            vector< pii >
#define pb              push_back
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define ms0(X)          memset((X), 0, sizeof((X)))
#define ms1(X)          memset((X), -1, sizeof((X)))
#define endl            "\n"
#define trace1(X)       cerr << "[debug]: " << X << "\n"
#define trace2(X,Y)     cerr << "[debug]: " << X << " | " << Y << "\n"
#define trace3(X,Y,Z)   cerr << "[debug]: " << X << " | " << Y << " | " << Z << "\n"
#define trace4(X,Y,Z,W) cerr << "[debug]: " << X << " | " << Y << " | " << Z  << " | " << W << "\n"
#define traceA(A,L,R)   cerr << "[debug Array]: "; for (int IIN=L;IIN<=R;++IIN)	cerr << A[IIN] << " ";   cerr << "\n";		// IIN, I'm from IIN :P
#define traceRA(A,R,L)  cerr << "[debug Array]: "; for (int IIN=R;IIN>=L;--IIN)	cerr << A[IIN] << " ";   cerr << "\n";
#define traceDS(c) 		cerr << "[debug Array]: "; for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++) cerr << *i << " ";   cerr << "\n";
#define TC()            int __tc; ri(__tc); while(__tc--)
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define fi first
#define se second
#if defined(_WIN64)
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("o1","w",stdout);
#else
#define IN {}
#define OUT {}
#endif
const int inf=0x7fffffff;
const int mod=1000000000+7;

inline ll fmod(ll a)
{
	if(a<mod)
		return a;
	else
		return a%mod;
}

int main()
{
	IN

	int n;
	ri(n);

	int a[n];
	int min=inf;

	for(int i=0;i<n;i++)
	{
		ri(a[i]);

		if(a[i] < min)
			min = a[i];
	}

	for(int i=0;i<n;i++)
		a[i] -= min;

	bool visited[n] ={0};

	ll ans = (ll)min*n;

	int i=0,max = 0;

	int iteration = 0;

	while(true)
	{
		if(iteration > 1)
			return 1;

		int count = 0;

		while(a[i])
		{
			visited[i] = true;

			count++;
			i++;

			if(i==n)
			{
				i=0;
				iteration++;
			}
		}

		visited[i] = true;
		i++;

		if(count > max)
			max = count;

		//trace2(i,count);

		if(i==n)
			break;

		if(visited[i])
			break;
	}
	cout << ans+max;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri(x)           scanf("%d",&x)
#define rii(x,y)        scanf("%d%d",&x,&y)
#define riii(x,y,z)     scanf("%d%d%d",&x,&y,&z)
#define riiii(x,y,z,w)  scanf("%d%d%d%d",&x,&y,&z,&w)
#define rl(x)           scanf("%lld",&x)
#define rll(x,y)        scanf("%lld%lld",&x,&y)
#define rlll(x,y,z)     scanf("%lld%lld%lld",&x,&y,&z)
#define rllll(x,y,z,w)  scanf("%lld%lld%lld%lld",&x,&y,&z,&w)
#define rs(str)         scanf("%s",str)
#define pf              printf
#define vi              vector<int>
#define vvi             vector< vi >
#define pii             pair<int,int>
#define vpii            vector< pii >
#define pb              push_back
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define ms0(X)          memset((X), 0, sizeof((X)))
#define ms1(X)          memset((X), -1, sizeof((X)))
#define endl            "\n"
#define trace1(X)       cerr << "[debug]: " << X << "\n"
#define trace2(X,Y)     cerr << "[debug]: " << X << " | " << Y << "\n"
#define trace3(X,Y,Z)   cerr << "[debug]: " << X << " | " << Y << " | " << Z << "\n"
#define trace4(X,Y,Z,W) cerr << "[debug]: " << X << " | " << Y << " | " << Z  << " | " << W << "\n"
#define traceA(A,L,R)   cerr << "[debug Array]: "; for (int IIN=L;IIN<=R;++IIN)	cerr << A[IIN] << " ";   cerr << "\n";		// IIN, I'm from IIN :P
#define traceRA(A,R,L)  cerr << "[debug Array]: "; for (int IIN=R;IIN>=L;--IIN)	cerr << A[IIN] << " ";   cerr << "\n";
#define traceDS(c) 		cerr << "[debug Array]: "; for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++) cerr << *i << " ";   cerr << "\n";
#define TC()            int __tc; ri(__tc); while(__tc--)
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define fi first
#define se second
#if defined(_WIN64)
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("o1","w",stdout);
#else
#define IN {}
#define OUT {}
#endif
const int inf=0x7fffffff;
const int mod=1000000000+7;

inline ll fmod(ll a)
{
	if(a<mod)
		return a;
	else
		return a%mod;
}

int main()
{
	IN

	int n;
	ri(n);

	vi v;
	int min=inf;

	for(int i=0;i<n;i++)
	{
		int t;
		ri(t);

		if(t<min)
		{
			v.clear();
			min = t;
			v.pb(i);
		}
		else if(t==min)
		{
			v.pb(i);
		}
	}

	ll ans = min*(ll)n;

	int end = v[(int)v.size()-1];
	int start = v[0];

	ans += start;
	ans += n-end-1;

	cout << ans;
	return 0;
}


#pragma warning(disable:4786)//ʹ�������Ȳ�������
#pragma comment(linker, "/STACK:102400000,102400000")//�ֹ���ջ
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 200100
#define mod 1000000007
#define INF 0x3f3f3f3f //int ���ֵ
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI  acos(-1.0)
#define E  exp(1)
using namespace std;
int dp[maxn];
int dd,st,ed;
int n,ans,pos,minn,num;
int main(){
    while(rd(n)!=EOF){
        num=0;minn=INF;
       num=st=ed=dd=0;
        FOR(i,1,n){
            rd(dp[i]);
            if(dp[i]<minn){
                minn=dp[i];
                st=ed=i;
               num=dd=0;
            }
            else if(dp[i]==minn){
                    num++;
                int temp=i-ed;
                //cout<<temp<<'\12';
                if(temp>dd)dd=temp;
                ed=i;
            }
        }
        dd=st+n-ed-1;
        ans=dp[ed]*n+dd;
        printf("%d\n",ans);
    }
    return 0;
}
/*
5
2 4 2 3 3
3
5 5 5
6
10 10 10 1 10 10
*/


#pragma warning(disable:4786)//ʹ�������Ȳ�������
#pragma comment(linker, "/STACK:102400000,102400000")//�ֹ���ջ
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 200100
#define mod 1000000007
#define INF 0x3f3f3f3f //int ���ֵ
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI  acos(-1.0)
#define E  exp(1)
using namespace std;
ll dp[maxn];
ll dd,st,ed;
ll n,pos;
ll ans,minn;
int main(){
    while(scanf("%I64d",&n)!=EOF){
       minn=INF;
        st=ed=dd=0;
        for(ll i=1;i<=n;++i){
            scanf("%I64d",&dp[i]);
            if(dp[i]<minn){
                minn=dp[i];
                st=ed=i;
            }
            else if(dp[i]==minn){
                ll temp=i-ed;
                if(temp>dd)dd=temp;
                ed=i;
            }
        }
        dd=st+n-ed-1;
        ans=dp[ed]*n+dd;
        printf("%I64d\n",ans);
    }
    return 0;
}
/*
5
2 4 2 3 3
3
5 5 5
6
10 10 10 1 10 10
*/


#pragma warning(disable:4786)//ʹ�������Ȳ�������
#pragma comment(linker, "/STACK:102400000,102400000")//�ֹ���ջ
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 200100
#define mod 1000000007
#define INF 0x3f3f3f3f //int ���ֵ
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI  acos(-1.0)
#define E  exp(1)
using namespace std;
ll dp[maxn];
ll dd,st,ed;
ll n,pos;
ll ans,minn;
int main(){
    while(scanf("%I64d",&n)!=EOF){
       minn=INF;
        st=ed=dd=0;
        for(ll i=1;i<=n;++i){
            scanf("%I64d",&dp[i]);
            if(dp[i]<minn){
                minn=dp[i];
                st=ed=i;
            }
            else if(dp[i]==minn){
                ll temp=i-ed;
                if(temp>dd)dd=temp;
                ed=i;
            }
        }
        dd=st+n-ed-1;
        ans=dp[ed]*n+dd;
        printf("%I64d\n",(ll)ans);
    }
    return 0;
}
/*
5
2 4 2 3 3
3
5 5 5
6
10 10 10 1 10 10
*/


#pragma warning(disable:4786)//ʹ�������Ȳ�������
#pragma comment(linker, "/STACK:102400000,102400000")//�ֹ���ջ
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 200100
#define mod 1000000007
#define INF 0x3f3f3f3f //int ���ֵ
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI  acos(-1.0)
#define E  exp(1)
using namespace std;
long long dp[maxn];
int dd,st,ed;
int n,pos,num;
long long ans,minn;
int main(){
    while(rd(n)!=EOF){
        num=0;minn=INF;
       num=st=ed=dd=0;
        FOR(i,1,n){
            scanf("%I64d",&dp[i]);
            if(dp[i]<minn){
                minn=dp[i];
                st=ed=i;
               num=dd=0;
            }
            else if(dp[i]==minn){
                    num++;
                int temp=i-ed;
                //cout<<temp<<'\12';
                if(temp>dd)dd=temp;
                ed=i;
            }
        }
        dd=st+n-ed-1;
        ans=(long long)dp[ed]*n+(long long)dd;
        printf("%I64d\n",ans);
    }
    return 0;
}
/*
5
2 4 2 3 3
3
5 5 5
6
10 10 10 1 10 10
*/


#pragma warning(disable:4786)//ʹ�������Ȳ�������
#pragma comment(linker, "/STACK:102400000,102400000")//�ֹ���ջ
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 200100
#define mod 1000000007
#define INF 0x3f3f3f3f //int ���ֵ
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI  acos(-1.0)
#define E  exp(1)
using namespace std;
ll dp[maxn];
ll dd,st,ed;
ll n,pos;
ll ans,minn;
int main(){
    while(scanf("%I64d",&n)!=EOF){
       minn=INF;
        st=ed=dd=0;
        for(ll i=1;i<=n;++i){
            scanf("%I64d",&dp[i]);
            if(dp[i]<minn){
                minn=dp[i];
                st=ed=i;
            }
            else if(dp[i]==minn){
                ll temp=i-ed;
                if(temp>dd)dd=temp;
                ed=i;
            }
        }
        ll a=st+n-ed-1;
        if(a>dd)dd=a;
        ans=dp[ed]*n+dd;
        printf("%I64d\n",ans);
    }
    return 0;
}
/*
5
2 4 2 3 3
3
5 5 5
6
10 10 10 1 10 10
*/


#pragma warning(disable:4786)//ʹ�������Ȳ�������
#pragma comment(linker, "/STACK:102400000,102400000")//�ֹ���ջ
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 200100
#define mod 1000000007
#define INF 0x3f3f3f3f //int ���ֵ
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI  acos(-1.0)
#define E  exp(1)
using namespace std;
long long dp[maxn];
long long dd,st,ed;
long long n,pos,num;
long long ans,minn;
int main(){
    while(scanf("%I64d",&n)!=EOF){
        num=0;minn=INF;
       num=st=ed=dd=0;
        FOR(i,1,n){
            scanf("%I64d",&dp[i]);
            if(dp[i]<minn){
                minn=dp[i];
                st=ed=i;
               num=dd=0;
            }
            else if(dp[i]==minn){
                    num++;
                long long temp=i-ed;
                //cout<<temp<<'\12';
                if(temp>dd)dd=temp;
                ed=i;
            }
        }
        dd=st+n-ed-1;
        ans=dp[ed]*n+dd;
        printf("%I64d\n",ans);
    }
    return 0;
}
/*
5
2 4 2 3 3
3
5 5 5
6
10 10 10 1 10 10
*/


#pragma warning(disable:4786)//ʹ�������Ȳ�������
#pragma comment(linker, "/STACK:102400000,102400000")//�ֹ���ջ
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 200100
#define mod 1000000007
#define INF 0x3f3f3f3f //int ���ֵ
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI  acos(-1.0)
#define E  exp(1)
using namespace std;
int dp[maxn];
int dd,st,ed;
int n,pos,num,minn;
long long ans;
int main(){
    while(scanf("%d",&n)!=EOF){
        num=0;minn=INF;
       num=st=ed=dd=0;
        FOR(i,1,n){
            scanf("%d",&dp[i]);
            if(dp[i]<minn){
                minn=dp[i];
                st=ed=i;
               num=dd=0;
            }
            else if(dp[i]==minn){
                    num++;
                int temp=i-ed;
                if(temp>dd)dd=temp;
                ed=i;
            }
        }
        dd=st+n-ed-1;
        ans=(ll)dp[ed]*n+(ll)dd;
        printf("%I64d\n",ans);
    }
    return 0;
}
/*
5
2 4 2 3 3
3
5 5 5
6
10 10 10 1 10 10
*/


#pragma warning(disable:4786)//ʹ�������Ȳ�������
#pragma comment(linker, "/STACK:102400000,102400000")//�ֹ���ջ
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 200100
#define mod 1000000007
#define INF 0x3f3f3f3f //int ���ֵ
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI  acos(-1.0)
#define E  exp(1)
using namespace std;
ll dp[maxn];
int dd,st,ed;
int n,pos,num;
ll ans,minn;
int main(){
    while(scanf("%d",&n)!=EOF){
        num=0;minn=INF;
       num=st=ed=dd=0;
        FOR(i,1,n){
            scanf("%I64d",&dp[i]);
            if(dp[i]<minn){
                minn=dp[i];
                st=ed=i;
               num=dd=0;
            }
            else if(dp[i]==minn){
                    num++;
                int temp=i-ed;
                if(temp>dd)dd=temp;
                ed=i;
            }
        }
        dd=st+n-ed-1;
        ans=dp[ed]*(ll)n+(ll)dd;
        printf("%I64d\n",ans);
    }
    return 0;
}
/*
5
2 4 2 3 3
3
5 5 5
6
10 10 10 1 10 10
*/


#pragma warning(disable:4786)//ʹ����Ȳ�������
#pragma comment(linker, "/STACK:102400000,102400000")//�ֹ���ջ
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 200100
#define mod 1000000007
#define INF 0x3f3f3f3f //int ���ֵ
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI  acos(-1.0)
#define E  exp(1)
using namespace std;
ll dp[maxn];
ll dd,st,ed;
ll n,ans,pos,minn,num;
int main(){
    while(cin>>n){
        num=0;minn=INF;
       num=st=ed=dd=0;
        FOR(i,1,n){
            cin>>dp[i];
            if(dp[i]<minn){
                minn=dp[i];
                st=ed=i;
               num=dd=0;
            }
            else if(dp[i]==minn){
                    num++;
                int temp=i-ed;
                //cout<<temp<<'\12';
                if(temp>dd)dd=temp;
                ed=i;
            }
        }
        dd=st+n-ed-1;
        ans=dp[ed]*n+dd;
       cout<<ans<<'\12';
    }
    return 0;
}
/*
5
2 4 2 3 3
3
5 5 5
6
10 10 10 1 10 10
*/


#pragma warning(disable:4786)//ʹ�������Ȳ�������
#pragma comment(linker, "/STACK:102400000,102400000")//�ֹ���ջ
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 200100
#define mod 1000000007
#define INF 0x3f3f3f3f //int ���ֵ
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI  acos(-1.0)
#define E  exp(1)
using namespace std;
ll dp[maxn];
ll dd,st,ed;
ll n,pos;
ll ans,minn;
int main(){
    while(scanf("%I64d",&n)!=EOF){
       minn=INF;
        st=ed=dd=0;
        for(ll i=1;i<=n;++i){
            scanf("%I64d",&dp[i]);
            if(dp[i]<minn){
                minn=dp[i];
                st=ed=i;
            }
            else if(dp[i]==minn){
                ll temp=i-ed-1;
                if(temp>dd)dd=temp;
                ed=i;
            }
        }
        if(dd<st+n-ed-1)
        dd=st+n-ed-1;
        ans=dp[ed]*n+dd;
        printf("%I64d\n",ans);
    }
    return 0;
}
/*
5
2 4 2 3 3
3
5 5 5
6
10 10 10 1 10 10
*/


#include<bits/stdc++.h>
using namespace std;

int main(){
	long int n;cin>>n;
	long long int arr[n];
	for(long int i=0;i<n;i++) cin>>arr[i];

	long long int  min=1000000001,si=0;
	for(long int i=0;i<n;i++) if(min>= arr[i]) min=arr[i];
	long int F=0,L=0,ch=0;
	for(long int i=0;i<n;i++){
		if(min==arr[i] && ch==0){
			F=i;ch=1;
		}
		else if(min==arr[i] && ch==1) L=i;
	}
	//cout<<F<<" "<<L<<endl;
	unsigned long long int ans;
	if(L==0) ans=(n-1)*(min+1)+min;
	else {
		ans = (n-L-1+F)*(min+1)+(L-F+1)*min;
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
int main(){
	ull n;cin>>n;
	ull arr[n];
	for(ull i=0;i<n;i++) cin>>arr[i];

	ull min=1000000001,si=0;
	for(ull i=0;i<n;i++) if(min>= arr[i]) min=arr[i];
	ull F=0,L=0,ch=0;
	for(ull i=0;i<n;i++){
		if(min==arr[i] && ch==0){
			F=i;ch++;
		}
		else if(min==arr[i] && ch!=0){
			L=i;ch++;
		}
	}
	ull ans;
	if(ch==n) ans=min*n;
	else if(L==0) ans=(n-1)*(min+1)+min;
	else{
		ull temp=F;
		for(ull  i=F+1;i<n;i++){
			ull count=0;
			while(i<n && arr[i]!=min){
				i++;count++;
			}
			if(count>temp) temp=count;
		}
		ans = temp*(min+1)+(n-temp)*min;
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
int main(){
	ull n;cin>>n;
	ull arr[n];
	for(ull i=0;i<n;i++) cin>>arr[i];

	ull min=1000000001,si=0;
	for(ull i=0;i<n;i++) if(min>= arr[i]) min=arr[i];
	ull F=0,L=0,ch=0;
	for(ull i=0;i<n;i++){
		if(min==arr[i] && ch==0){
			F=i;ch++;
		}
		else if(min==arr[i] && ch!=0){
			L=i;ch++;
		}
	}
	ull ans;
	if(L==0) ans=(n-1)*(min+1)+min;
	else{
		ull temp=F+n-L-1;
		for(ull  i=F+1;i<n;i++){
			ull count=0;
			while(i<n && arr[i]!=min){
				i++;count++;
			}
			if(count>temp) temp=count;
		}
		ans = temp*(min+1)+(n-temp)*min;
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;cin>>n;
	int arr[n];
	for(int i=0;i<n;i++) cin>>arr[i];

	int min=200001,si=0;
	for(int i=0;i<n;i++) if(min>= arr[i]) min=arr[i];
	int F=0,L=0,ch=0;
	for(int i=0;i<n;i++){
		if(min==arr[i] && ch==0){
			F=i;ch=1;
		}
		else if(min==arr[i] && ch==1) L=i;
	}
	//cout<<F<<" "<<L<<endl;
	long long int ans;
	if(L==0) ans=(n-1)*(min+1)+min;
	else {
		ans = (n-L-1+F)*(min+1)+(L-F+1)*min;
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	long int n;cin>>n;
	long long int arr[n];
	for(long int i=0;i<n;i++) cin>>arr[i];

	long long int  min=1000000001,si=0;
	for(long int i=0;i<n;i++) if(min>= arr[i]) min=arr[i];
	long int F=0,L=0,ch=0;
	for(long int i=0;i<n;i++){
		if(min==arr[i] && ch==0){
			F=i;ch=1;
		}
		else if(min==arr[i] && ch==1) L=i;
	}
	//cout<<F<<" "<<L<<endl;
	unsigned long long int ans;
	if(L==0) ans=(n-1)*(min+1)+min;
	else if(L==n-1 && F==0) ans =(L-F+1)*min+1;
	else ans = (n-L-1+F)*(min+1)+(L-F+1)*min;
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	long int n;cin>>n;
	long long int arr[n];
	for(long int i=0;i<n;i++) cin>>arr[i];

	long long int  min=1000000001,si=0;
	for(long int i=0;i<n;i++) if(min>= arr[i]) min=arr[i];
	long int F=0,L=0,ch=0;
	for(long int i=0;i<n;i++){
		if(min==arr[i] && ch==0){
			F=i;ch++;
		}
		else if(min==arr[i] && ch!=0){
			L=i;ch++;
		}
	}
	//cout<<F<<" "<<L<<endl;
	unsigned long long int ans;
	if(ch==n) ans=min*n;
	else if(L==0) ans=(n-1)*(min+1)+min;
	else if(L==n-1 && F==0) ans =(L-F+1)*min+1;
	else ans = (n-L-1+F)*(min+1)+(L-F+1)*min;
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
int main(){
	ull n;cin>>n;
	ull arr[n];
	for(ull i=0;i<n;i++) cin>>arr[i];

	ull min=1000000001,si=0;
	for(ull i=0;i<n;i++) if(min>= arr[i]) min=arr[i];
	ull F=0,L=0,ch=0;
	for(ull i=0;i<n;i++){
		if(min==arr[i] && ch==0){
			F=i;ch++;
		}
		else if(min==arr[i] && ch!=0){
			L=i;ch++;
		}
	}
	ull ans;
	if(ch==n) ans=min*n;
	else if(L==0) ans=(n-1)*(min+1)+min;
	else{
		ull temp=0;
		for(ull  i=F+1;i<n;i++){
			ull count=0;
			while(i<n && arr[i]!=min){
				i++;count++;
			}
			if(count>temp) temp=count;
		}
		ans = temp*(min+1)+(n-temp)*min;
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	long int n;cin>>n;
	long long int arr[n];
	for(long int i=0;i<n;i++) cin>>arr[i];

	long long int  min=1000000001,si=0;
	for(long int i=0;i<n;i++) if(min>= arr[i]) min=arr[i];
	long int F=0,L=0,ch=0;
	for(long int i=0;i<n;i++){
		if(min==arr[i] && ch==0){
			F=i;ch++;
		}
		else if(min==arr[i] && ch!=0){
			L=i;ch++;
		}
	}
	unsigned long long int ans;
	if(ch==n) ans=min*n;
	else if(L==0) ans=(n-1)*(min+1)+min;
	else{
		long int temp=0;
		for(long int i=F+1;i<n;i++){
			long int count=0;
			while(i<n && arr[i]!=min){
				i++;count++;
			}
			if(count>temp) temp=count;
		}
		ans = temp*(min+1)+(n-temp)*min;
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
int main(){
	ull n;cin>>n;
	ull arr[n];
	for(ull i=0;i<n;i++) cin>>arr[i];

	ull min=1000000001,si=0;
	for(ull i=0;i<n;i++) if(min>= arr[i]) min=arr[i];
	ull F=0,L=0,ch=0;
	for(ull i=0;i<n;i++){
		if(min==arr[i] && ch==0){
			F=i;ch++;
		}
		else if(min==arr[i] && ch!=0){
			L=i;ch++;
		}
	}
	ull ans=F;
	if(ch==n) ans=min*n;
	else if(L==0) ans=(n-1)*(min+1)+min;
	else{
		ull temp=0;
		for(ull  i=F+1;i<n;i++){
			ull count=0;
			while(i<n && arr[i]!=min){
				i++;count++;
			}
			if(count>temp) temp=count;
		}
		ans = temp*(min+1)+(n-temp)*min;
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
using namespace std;
const int maxn=1e5*2+5;
int a[maxn];
int mn,mx,sum1,sum,x;
int main()
{
    int n;
    cin>>n;
    cin>>a[0];
    mn=a[0];
    for(int i=1;i<n;i++)
    {
        cin>>a[i];
        a[i+n]=a[i];
        if(a[i]<mn)
            mn=a[i];
    }
    for(int i=0;i<2*n;i++)
    {
        if(a[i]==mn)
        {
            sum=0;
        }
        else
           sum++;
            if(sum>mx)
                mx=sum;
    }
    cout<<mn*n+mx;
}


#include <iostream>
using namespace std;
const int maxn=1e5*2+5;
int a[maxn];
int mn,mx,sum1,sum,x;
int main()
{
    int n;
    cin>>n;
    cin>>a[0];
    mn=a[0];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i+n]=a[i];
        if(a[i]<mn)
            mn=a[i];
    }
    for(int i=0;i<2*n;i++)
    {
        if(a[i]==mn)
        {
            sum=0;
        }
        else
           sum++;
            if(sum>mx)
                mx=sum;
    }
    cout<<mn*n+sum;
}


#include <iostream>
using namespace std;
const int maxn=1e5*2+5;
int a[maxn];
int mn=1000000005,mx=0,sum1,sum=0;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i+n]=a[i];
        if(a[i]<mn)
            mn=a[i];
    }
    for(int i=1;i<=2*n;i++)
    {
        if(a[i]==mn)
          sum=0;
            else
              sum++;
                if(sum>mx)
                   mx=sum;
    }
    cout<<mn*n+mx;
    return 0;
}


#include <iostream>
using namespace std;
const int maxn=1e5*4+5;
long long int a[maxn];
long long int mn=1000000005,mx=0,sum1,sum=0,n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i+n]=a[i];
        if(a[i]<mn)
            mn=a[i];
    }
    for(int i=1;i<=2*n;i++)
    {
        if(a[i]==mn)
          sum=0;
            else
              sum++;
                if(sum>mx)
                   mx=sum;
    }
    cout<<mn*n+mx;
    return 0;
}


#include <iostream>
using namespace std;
const int maxn=1e5*2+5;
long long int a[maxn];
long long int mn=1000000005,mx=0,sum1,sum=0,n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i+n]=a[i];
        if(a[i]<mn)
            mn=a[i];
    }
    for(int i=1;i<=2*n;i++)
    {
        if(a[i]==mn)
          sum=0;
            else
              sum++;
                if(sum>mx)
                   mx=sum;
    }
    cout<<mn*n+mx;
    return 0;
}


#include <iostream>
using namespace std;
const int maxn=1e5*2+5;
logn long int a[maxn];
long long int mn=1000000005,mx=0,sum1,sum=0;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i+n]=a[i];
        if(a[i]<mn)
            mn=a[i];
    }
    for(int i=1;i<=2*n;i++)
    {
        if(a[i]==mn)
          sum=0;
            else
              sum++;
                if(sum>mx)
                   mx=sum;
    }
    cout<<mn*n+mx;
    return 0;
}


#include <iostream>
using namespace std;
const int maxn=1e5*2+5;
int a[maxn];
int mn,mx,sum1,sum,x;
int main()
{
    int n;
    cin>>n;
    cin>>a[0];
    mn=a[0];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i+n]=a[i];
        if(a[i]<mn)
            mn=a[i];
    }
    for(int i=0;i<2*n;i++)
    {
        if(a[i]==mn)
        {
            sum=0;
        }
        else
           sum++;
            if(sum>mx)
                mx=sum;
    }
    cout<<mn*n+mx;
}


#include <iostream>
using namespace std;
const int maxn=1e5*2+5;
int a[maxn];
int mn,mx,sum1,sum,x;
int main()
{
    int n;
    cin>>n;
    cin>>a[0];
    mn=a[0];
    for(int i=1;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<mn)
            mn=a[i];
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]==mn)
        {
            sum1++;
            x=0;
        }
        else
        {
            x++;
            if(x>mx)
                mx=x;
        }
    }
    int t,k;
    if(sum1>=2)
    {
    for(int i=0;i<n;i++)
    {
        if(a[i]==mn)
            t=i;
        break;
    }
    for(int i=n-1;i>=0;i--)
    {
        if(a[i]==mn)
            k=i;
        break;
    }
    if(n-k+t-1>mx)
    {
        mx=n-k+t;
    }
    }
    cout<<mn*n+mx;
}


#include <iostream>
using namespace std;
const int maxn=1e5*2+5;
long long int a[maxn];
long long int mn=1000000005,mx=0,sum1,sum=0;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i+n]=a[i];
        if(a[i]<mn)
            mn=a[i];
    }
    for(int i=1;i<=2*n;i++)
    {
        if(a[i]==mn)
          sum=0;
            else
              sum++;
                if(sum>mx)
                   mx=sum;
    }
    cout<<mn*n+mx;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pii pair<int,int>

#define ft first
#define sd second
#define mp make_pair
#define pb push_back

#define root 1
#define lft 2*idx
#define rgt 2*idx+1
#define cllft lft,st,mid
#define clrgt rgt,mid+1,ed

#define inf INT_MAX/2
#define linf LLONG_MAX/2

#define all(p) p.begin(),p.end()
#define set(p) memset(p, -1, sizeof(p))
#define clr(p) memset(p, 0, sizeof(p))
#define mem(p, v) memset(p, v, sizeof(p))
#define cpy(d, s) memcpy(d, s, sizeof(s))
#define asst(X,L,R) assert(X >= L && X <= R)

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

template <class T> T max(T a,T b,T c){return ( ( a > b ) ? ( ( a > c) ? a : c ) : ( ( b > c ) ? b : c ) );}
template <class T> T min(T a,T b,T c){return ( ( a < b ) ? ( ( a < c) ? a : c ) : ( ( b < c ) ? b : c ) );}
// compiling with gcc11 or above
// g++ -std=c++0x
// PIE is defined as M_PI

const int MOD = 1000000000 + 7 ;
const int MAXN = 100000 + 9 ;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int t=1;
	while(t--){
		int n;
		cin >> n;
		vector<int> vec(n);
		int mn=INT_MAX/2;
		for(int i=0;i<n;i++){
			cin >> vec[i];
			mn=min(mn,vec[i]);
		}
		vector<int> mnvec;
		for(int i=0;i<n;i++){
			if(mn==vec[i]){
				mnvec.pb(i);
			}
		}
		ll ans=0;
		int sz=mnvec.size();
		if(sz>1){
			for(int i=0;i<sz;i++){
				ll tmp=0;
				if(i==0){
					tmp=(mn-1)*1LL*n + (n-1-mnvec[0]) + (mnvec[1]);
					//cout << tmp << "\n";
				}
				else if(i==sz-1){
					tmp=mn*1LL*n + (n-1-mnvec[sz-1]) + (mnvec[0]);
					//cout << tmp << "\n";
				}
				else{
					tmp=(mn-1)*1LL*n + n;
					//cout << tmp << "\n";
				}
				ans=max(ans,tmp);
			}
		}
		else if(sz==1){
			ans=mn*1LL*n + n-1;
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pii pair<int,int>

#define ft first
#define sd second
#define mp make_pair
#define pb push_back

#define root 1
#define lft 2*idx
#define rgt 2*idx+1
#define cllft lft,st,mid
#define clrgt rgt,mid+1,ed

#define inf INT_MAX/2
#define linf LLONG_MAX/2

#define all(p) p.begin(),p.end()
#define set(p) memset(p, -1, sizeof(p))
#define clr(p) memset(p, 0, sizeof(p))
#define mem(p, v) memset(p, v, sizeof(p))
#define cpy(d, s) memcpy(d, s, sizeof(s))
#define asst(X,L,R) assert(X >= L && X <= R)

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

template <class T> T max(T a,T b,T c){return ( ( a > b ) ? ( ( a > c) ? a : c ) : ( ( b > c ) ? b : c ) );}
template <class T> T min(T a,T b,T c){return ( ( a < b ) ? ( ( a < c) ? a : c ) : ( ( b < c ) ? b : c ) );}
// compiling with gcc11 or above
// g++ -std=c++0x
// PIE is defined as M_PI

const int MOD = 1000000000 + 7 ;
const int MAXN = 100000 + 9 ;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int t=1;
	while(t--){
		int n;
		cin >> n;
		vector<int> vec(n);
		int mn=INT_MAX/2;
		for(int i=0;i<n;i++){
			cin >> vec[i];
			mn=min(mn,vec[i]);
		}
		int a=-1,b=-1;
		for(int i=0;i<n;i++){
			if(a==-1 && mn==vec[i]){
				a=i;
			}
		}
		for(int i=n-1;i>=0;i--){
			if(b==-1 && mn==vec[i]){
				b=i;
			}
		}
		if(a==b){
			cout << (mn*2LL*n)-1 << "\n";
		}
		else{
			ll x=mn*1LL*n + (n-1-b) + a;
			ll y=(mn-1)*1LL*n + (n-2-a);
			for(int i=0;i<n;i++){
				if(vec[i]==mn && i!=a){
					y+=i+1;
					break;
				}
			}
			cout << max(x,y) << "\n";
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pii pair<int,int>

#define ft first
#define sd second
#define mp make_pair
#define pb push_back

#define root 1
#define lft 2*idx
#define rgt 2*idx+1
#define cllft lft,st,mid
#define clrgt rgt,mid+1,ed

#define inf INT_MAX/2
#define linf LLONG_MAX/2

#define all(p) p.begin(),p.end()
#define set(p) memset(p, -1, sizeof(p))
#define clr(p) memset(p, 0, sizeof(p))
#define mem(p, v) memset(p, v, sizeof(p))
#define cpy(d, s) memcpy(d, s, sizeof(s))
#define asst(X,L,R) assert(X >= L && X <= R)

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

template <class T> T max(T a,T b,T c){return ( ( a > b ) ? ( ( a > c) ? a : c ) : ( ( b > c ) ? b : c ) );}
template <class T> T min(T a,T b,T c){return ( ( a < b ) ? ( ( a < c) ? a : c ) : ( ( b < c ) ? b : c ) );}
// compiling with gcc11 or above
// g++ -std=c++0x
// PIE is defined as M_PI

const int MOD = 1000000000 + 7 ;
const int MAXN = 100000 + 9 ;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> vec(n);
		int mn=INT_MAX/2;
		for(int i=0;i<n;i++){
			cin >> vec[i];
			mn=min(mn,vec[i]);
		}
		cout << (mn*1LL*n)-1 << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pii pair<int,int>

#define ft first
#define sd second
#define mp make_pair
#define pb push_back

#define root 1
#define lft 2*idx
#define rgt 2*idx+1
#define cllft lft,st,mid
#define clrgt rgt,mid+1,ed

#define inf INT_MAX/2
#define linf LLONG_MAX/2

#define all(p) p.begin(),p.end()
#define set(p) memset(p, -1, sizeof(p))
#define clr(p) memset(p, 0, sizeof(p))
#define mem(p, v) memset(p, v, sizeof(p))
#define cpy(d, s) memcpy(d, s, sizeof(s))
#define asst(X,L,R) assert(X >= L && X <= R)

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

template <class T> T max(T a,T b,T c){return ( ( a > b ) ? ( ( a > c) ? a : c ) : ( ( b > c ) ? b : c ) );}
template <class T> T min(T a,T b,T c){return ( ( a < b ) ? ( ( a < c) ? a : c ) : ( ( b < c ) ? b : c ) );}
// compiling with gcc11 or above
// g++ -std=c++0x
// PIE is defined as M_PI

const int MOD = 1000000000 + 7 ;
const int MAXN = 100000 + 9 ;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int t=1;
	while(t--){
		int n;
		cin >> n;
		vector<int> vec(n);
		int mn=INT_MAX/2;
		for(int i=0;i<n;i++){
			cin >> vec[i];
			mn=min(mn,vec[i]);
		}
		vector<int> mnvec;
		for(int i=0;i<n;i++){
			if(mn==vec[i]){
				mnvec.pb(i);
			}
		}
		ll ans=0;
		int sz=mnvec.size();
		if(sz>1){
			for(int i=0;i<sz;i++){
				ll tmp=0;
				if(i==0){
					tmp=(mn-1)*1LL*n + (n-1-mnvec[0]) + (mnvec[1]);
					//cout << tmp << "\n";
				}
				else if(i==sz-1){
					tmp=mn*1LL*n + (n-1-mnvec[sz-1]) + (mnvec[0]);
					//cout << tmp << "\n";
				}
				else{
					tmp=(mn-1)*1LL*n + n-1;
					//cout << tmp << "\n";
				}
				ans=max(ans,tmp);
			}
		}
		else if(sz==1){
			ans=mn*1LL*n + n-1;
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pii pair<int,int>

#define ft first
#define sd second
#define mp make_pair
#define pb push_back

#define root 1
#define lft 2*idx
#define rgt 2*idx+1
#define cllft lft,st,mid
#define clrgt rgt,mid+1,ed

#define inf INT_MAX/2
#define linf LLONG_MAX/2

#define all(p) p.begin(),p.end()
#define set(p) memset(p, -1, sizeof(p))
#define clr(p) memset(p, 0, sizeof(p))
#define mem(p, v) memset(p, v, sizeof(p))
#define cpy(d, s) memcpy(d, s, sizeof(s))
#define asst(X,L,R) assert(X >= L && X <= R)

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

template <class T> T max(T a,T b,T c){return ( ( a > b ) ? ( ( a > c) ? a : c ) : ( ( b > c ) ? b : c ) );}
template <class T> T min(T a,T b,T c){return ( ( a < b ) ? ( ( a < c) ? a : c ) : ( ( b < c ) ? b : c ) );}
// compiling with gcc11 or above
// g++ -std=c++0x
// PIE is defined as M_PI

const int MOD = 1000000000 + 7 ;
const int MAXN = 100000 + 9 ;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int t=1;
	while(t--){
		int n;
		cin >> n;
		vector<int> vec(n);
		int mn=INT_MAX/2;
		for(int i=0;i<n;i++){
			cin >> vec[i];
			mn=min(mn,vec[i]);
		}
		int a=-1,b=-1;
		for(int i=0;i<n;i++){
			if(a==-1 && mn==vec[i]){
				a=i;
			}
		}
		for(int i=n-1;i>=0;i--){
			if(b==-1 && mn==vec[i]){
				b=i;
			}
		}
		if(a==b){
			cout << (mn*2LL*n)-1 << "\n";
		}
		else{
			ll ans=max(mn*1LL*n + (n-1-b) + (a), (mn-1)*1LL*n + (n-2-a) + (b+1) );
			cout << ans << "\n";
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pii pair<int,int>

#define ft first
#define sd second
#define mp make_pair
#define pb push_back

#define root 1
#define lft 2*idx
#define rgt 2*idx+1
#define cllft lft,st,mid
#define clrgt rgt,mid+1,ed

#define inf INT_MAX/2
#define linf LLONG_MAX/2

#define all(p) p.begin(),p.end()
#define set(p) memset(p, -1, sizeof(p))
#define clr(p) memset(p, 0, sizeof(p))
#define mem(p, v) memset(p, v, sizeof(p))
#define cpy(d, s) memcpy(d, s, sizeof(s))
#define asst(X,L,R) assert(X >= L && X <= R)

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

template <class T> T max(T a,T b,T c){return ( ( a > b ) ? ( ( a > c) ? a : c ) : ( ( b > c ) ? b : c ) );}
template <class T> T min(T a,T b,T c){return ( ( a < b ) ? ( ( a < c) ? a : c ) : ( ( b < c ) ? b : c ) );}
// compiling with gcc11 or above
// g++ -std=c++0x
// PIE is defined as M_PI

const int MOD = 1000000000 + 7 ;
const int MAXN = 100000 + 9 ;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int t=1;
	while(t--){
		int n;
		cin >> n;
		vector<int> vec(n);
		int mn=INT_MAX/2;
		for(int i=0;i<n;i++){
			cin >> vec[i];
			mn=min(mn,vec[i]);
		}
		int a=-1,b=-1;
		for(int i=0;i<n;i++){
			if(a==-1 && mn==vec[i]){
				a=i;
			}
		}
		for(int i=n-1;i>=0;i--){
			if(b==-1 && mn==vec[i]){
				b=i;
			}
		}
		if(a==b){
			cout << (mn*2LL*n)-1 << "\n";
		}
		else{
			ll ans=mn*1LL*n + (n-1-b) + (a);
			cout << ans << "\n";
		}
	}
	return 0;
}