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

const int N = 200010, mod = 1e9 + 7;

ll dp[N][20], k, num[N];
char s[N];

ll dfs(int pos, bool limit, bool lead, int cnt, ll state){
	if(!pos)	return cnt == k;
	if(cnt > k)	return 0;
	if(!limit && !lead && ~dp[pos][cnt])	return dp[pos][cnt];
	ll ans = 0;
	int up = limit ? num[pos] : 15;
	for(int i = 0; i <= up; ++ i){
		if(lead && !i)	ans = (ans + dfs(pos - 1, limit && i == up, true, 0, 0)) % mod;
		else{
			if((state >> i) & 1)	ans = (ans + dfs(pos - 1, limit && i == up, false, cnt, state)) % mod;
			else	ans = (ans + dfs(pos - 1, limit && i == up, false, cnt + 1, state | (1 << i))) % mod;
		}
	}
	if(!limit && !lead)	dp[pos][cnt] = ans;
	return ans;
}

ll solve(){
	int len = strlen(s + 1);
	for(int i = 1, j = len; i < j; ++ i, -- j)	swap(s[i], s[j]);
	for(int i = 1; i <= len; ++ i){
		if(s[i] >= '0' && s[i] <= '9')	num[i] = s[i] - '0';
		else	num[i] = s[i] - 'A' + 10;
	}
	return dfs(len, true, true, 0, 0);
} 

int main(){
	scanf("%s", s + 1);
	cin >> k;
	memset(dp, -1, sizeof dp);
	cout << solve();
	return 0;
}
//CODE YOUR WAY ;) -->> 

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

#define ll long long int
#define Loopi for(ll i=0;i<n;i++)
#define Loopj for(ll j=0;j<m;j++)
#define LoopLR(l,r) for(ll i=l;i<=r;i++)
#define pb push_back
#define Umap unordered_map<ll,ll> M
#define Omap map<int,int> M;
#define read(a,n) Loopi{  cin>> a[i];  }
#define print(a,n) Loopi{  cout<<a[i]<<" ";  }
#define findsum(a,n) Loopi{  sum+=a[i];  }


void Doit()
{
ll n;
cin>>n;
ll a[n];
read(a,n);
ll max=0;
ll min=1000000000000000000;
for(int i=0;i<n;i++)
{
    //max=a[i];
    min=INT_MAX;
    if(min>a[i])
    min=a[i];
    for(int j=i;j<n;j++)
    {
      if(min>a[j])
      min=a[j];
      ll x=min*(j-i+1);
      if(max<x)
      max=x;
      
      
    }
}
cout<<max<<endl;
}

int main()
{

ios::sync_with_stdio(false);
cin.tie(NULL);

// ll t;
// cin>>t;

// while(t--)
// {
    Doit();
// }

}