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

/*-------------------------- HRIDOY ROY -------------------------*/

#define     fRead           freopen("input.txt","r",stdin)
#define     fWrite          freopen("output.txt","w",stdout)

#define     I(X)            scanf("%d",&(X))
#define     II(X, Y)        scanf("%d%d",&(X),&(Y))
#define     III(X,Y,Z)      scanf("%d%d%d",&(X),&(Y),&(Z))
#define     IL(X)           scanf("%lld",&(X))
#define     IIL(X, Y)       scanf("%lld%lld",&(X),&(Y))
#define     pb              push_back
#define     popb            pop_back
#define     lld             long long int
#define     ull             unsigned long long int
#define     max3(a,b,c)     max(a,max(b,c))
#define     max4(a,b,c,d)   max(max3(a,b,c),d)
#define     min3(a,b,c)     min(a,min(b,c))
#define     min4(a,b,c,d)   min(a,min3(b,c,d))
#define     MOD             1000000007
#define     f               first
#define     s               second
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     mp              make_pair

#define     show            printf("---***---")
#define     all(v)          v.begin(),v.end()
#define     fast            ios_base::sync_with_stdio(0);cin.tie(0)
#define     pii             pair<int,int>
#define     PLL             pair<lld,lld>
#define     MAX             100000000000014
#define     MIN             -100000000000014
#define     gti             greater<int>
#define     gtL             greater<lld>
#define     PI1             acos(-1.0)
#define     pi2             2.0*acos(0.0)
#define     endl            '\n'

//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

//int Set(int N,int pos){return N=N | (1<<pos);}
//int reset(int N,int pos){return N= N & ~(1<<pos);}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
//__builtin_popcount // back_inserter()
// priority_queue<pii,vector<pii>,greater<pii> >q;
//priority_queue<int, vector<int>, greater<int> >pq; // DSCS;
//priority_queue<int, vector<int>, less<int> >pq; // INCS;

int Day12[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int prime100[]={2, 3, 5, 7, 11, 13, 17, 19, 23,29,31, 37, 41, 43, 47, 53, 59,61, 67,71, 73, 79, 83, 89, 97, 101, 103 };

template <typename T> inline bool isLeap(T y) {return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false);}
template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b); if(a < b) swap(a, b); while ( b ) { a = a % b; swap ( a, b ); } return a;}
template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
template <typename T> inline T BIGMOD(T A,T B,T M = MOD){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T BigMod(T A,T B,T M){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
lld MySqrt(lld n){lld p=sqrt(n);if((p+1)*(p+1)<=n) return p+1;else if(p*p<=n) return p;else return p-1;}
lld MyPow(lld x, lld n){if(n==0) return 1; else if(n%2==0) return MyPow(x*x,n/2); else return x*MyPow(x*x,((n-1)/2));}

//----------------------------- O.D.Y.W.F.M ----------------------------------//

lld dp_ncr[1005][1005];
lld DP[1005];
lld arr[1005];
int main(int argc, char const *argv[])
{
    int K;
    I(K);

        for(int i = 1 ; i <= K; i++){
            IL(arr[i]);
        }

        for(int i = 0 ; i < 11; i++){
            for(int j = 0; j <= i ; j++){
                if(i == 0 || j == 0)
                    dp_ncr[i][j]=1;
                else
                    dp_ncr[i][j] = dp_ncr[i-1][j-1] + dp_ncr[i-1][j];

                dp_ncr[i][j] = dp_ncr[i][j]%MOD;
            }
        }

        lld now=arr[1];
        DP[1] = 1;

        for(int i = 2; i <= K; i++){
            now = now + arr[i];

            DP[i] = DP[i-1] * (dp_ncr[now-1][arr[i]-1]);
            DP[i] = DP[i]%MOD;
        }

        printf("%lld\n",DP[K]);

    return 0;
}


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

/*-------------------------- HRIDOY ROY -------------------------*/

#define     fRead           freopen("input.txt","r",stdin)
#define     fWrite          freopen("output.txt","w",stdout)

#define     I(X)            scanf("%d",&(X))
#define     II(X, Y)        scanf("%d%d",&(X),&(Y))
#define     III(X,Y,Z)      scanf("%d%d%d",&(X),&(Y),&(Z))
#define     IL(X)           scanf("%lld",&(X))
#define     IIL(X, Y)       scanf("%lld%lld",&(X),&(Y))
#define     pb              push_back
#define     popb            pop_back
#define     lld             long long int
#define     ull             unsigned long long int
#define     max3(a,b,c)     max(a,max(b,c))
#define     max4(a,b,c,d)   max(max3(a,b,c),d)
#define     min3(a,b,c)     min(a,min(b,c))
#define     min4(a,b,c,d)   min(a,min3(b,c,d))
#define     MOD             1000000007
#define     f               first
#define     s               second
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     mp              make_pair

#define     show            printf("---***---")
#define     all(v)          v.begin(),v.end()
#define     fast            ios_base::sync_with_stdio(0);cin.tie(0)
#define     pii             pair<int,int>
#define     PLL             pair<lld,lld>
#define     MAX             100000000000014
#define     MIN             -100000000000014
#define     gti             greater<int>
#define     gtL             greater<lld>
#define     PI1             acos(-1.0)
#define     pi2             2.0*acos(0.0)
#define     endl            '\n'

//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

//int Set(int N,int pos){return N=N | (1<<pos);}
//int reset(int N,int pos){return N= N & ~(1<<pos);}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
//__builtin_popcount // back_inserter()
// priority_queue<pii,vector<pii>,greater<pii> >q;
//priority_queue<int, vector<int>, greater<int> >pq; // DSCS;
//priority_queue<int, vector<int>, less<int> >pq; // INCS;

int Day12[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int prime100[]={2, 3, 5, 7, 11, 13, 17, 19, 23,29,31, 37, 41, 43, 47, 53, 59,61, 67,71, 73, 79, 83, 89, 97, 101, 103 };

template <typename T> inline bool isLeap(T y) {return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false);}
template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b); if(a < b) swap(a, b); while ( b ) { a = a % b; swap ( a, b ); } return a;}
template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
template <typename T> inline T BIGMOD(T A,T B,T M = MOD){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T BigMod(T A,T B,T M){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
lld MySqrt(lld n){lld p=sqrt(n);if((p+1)*(p+1)<=n) return p+1;else if(p*p<=n) return p;else return p-1;}
lld MyPow(lld x, lld n){if(n==0) return 1; else if(n%2==0) return MyPow(x*x,n/2); else return x*MyPow(x*x,((n-1)/2));}

//----------------------------- O.D.Y.W.F.M ----------------------------------//

lld dp_ncr[1005][1005];
lld DP[1005];
lld arr[1005];
int main(int argc, char const *argv[])
{
    int K;
    I(K);

        for(int i = 1 ; i <= K; i++){
            IL(arr[i]);
        }

        for(int i = 0 ; i < 1001; i++){
            for(int j = 0; j <= i ; j++){
                if(i == 0 || j == 0)
                    dp_ncr[i][j]=1;
                else
                    dp_ncr[i][j] = dp_ncr[i-1][j-1] + dp_ncr[i-1][j];

                dp_ncr[i][j] = dp_ncr[i][j]%MOD;
            }
        }

        lld now=arr[1];
        DP[1] = 1;

        for(int i = 2; i <= K; i++){
            now = now + arr[i];

            DP[i] = DP[i-1] * (dp_ncr[now-1][arr[i]-1]);
            DP[i] = DP[i]%MOD;
        }

        printf("%lld\n",DP[K]);

    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<cmath>
#define ll long long
using namespace std;
ll dp[1005];
ll a[1005];
ll sum[1005];
const int maxn =1000005;
const ll mod = 1000000007;
ll Jc[maxn];

void calJc()	//求maxn以内的数的阶乘
{
    Jc[0] = Jc[1] = 1;
    for(ll i = 2; i < maxn; i++)
        Jc[i] = Jc[i - 1] * i % mod;
}

//费马小定理求逆元
ll pow(ll a, ll n, ll p)	//快速幂 a^n % p
{
    ll ans = 1;
    while(n)
    {
        if(n & 1) ans = ans * a % p;
        a = a * a % p;
        n >>= 1;
    }
    return ans;
}

ll niYuan(ll a, ll b)	//费马小定理求逆元
{
    return pow(a, b - 2, b);
}

ll C(ll a, ll b)	//计算C(a, b)
{
    if(a < b) return 0;
    return Jc[a] * niYuan(Jc[b], mod) % mod
        * niYuan(Jc[a - b], mod) % mod;
}
ll cal(int i){
	ll n = sum[i-1]+1;
	ll m = a[i]-1;
//	cout<<n<<" "<<m<<"\n";
	if(m<=0){
		return 1;
	}
	ll ans=0;
	for(ll i=1;i<=m;i++){
	//	cout<<n<<" "<<i<<" "<<C(3, 1)<<"\n";
		ans=(ans+((C(n, i)*C(m-1, i-1))%mod))%mod;
	}
	//cout<<ans<<"\n";
	return ans;
}
int main(){
//	freopen("in.txt","r",stdin);
	calJc();
//	cout<<C(3, 1);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	dp[1]=1;sum[1]=a[1];
	for(int i=2;i<=n;i++){
		dp[i]=(dp[i-1]*cal(i))%mod;
		sum[i]=sum[i-1]+a[i];
	}
//	for(int i=1;i<=n;i++)cout<<dp[i]<<" ";
//	cout<<"\n";
	printf("%lld",dp[n]);
}


#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define int                 long long int
#define ld                  long double
#define pb                  push_back
#define F                   first
#define S                   second
#define si                  set <int>
#define vi                  vector <int>
#define vvi                 vector <vector <int>>
#define vs                  vector <string>
#define pii                 pair <int, int>
#define vpi                 vector <pii>
#define vpp                 vector <pair<int, pii>>
#define mii                 map <int, int>
#define mci                 map<char, int>
#define mpi                 map <pii, int>
#define spi                 set <pii>
#define speed               ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl                "\n"
#define all(p)              p.begin(), p.end()
#define T                   int tcf;cin>>tcf;while(tcf--)
#define que_max             priority_queue <int>
#define que_min             priority_queue <int, vector<int>, greater<int>>
#define debuga(a, l, r)     for(auto x:a)cout<<x<<" ";cout<<endl;
#define debug1(x)           cout << #x " = " << x << endl;
#define debug2(x,y)         cout << #x " = " << x << " " << #y " = " << y << endl;
#define debug3(x,y,z)       cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define debug4(x,y,z,w)     cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << " " << #w " = " << w << endl;
#define debug5(x,y,z,w,v)   cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << " " << #w " = " << w << " " << #v " = " << v << endl;
#define debug6(x,y,z,w,v,a) debug3(a, y, x)debug3(w, v, a)
#define p2d(v)             for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)              for(auto a:v)cout<<a<<" ";cout<<endl;

void aps554(int n=10){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<setprecision(n)<<fixed;
    #ifndef ONLINE_JUDGE
         freopen("input.txt",  "r",  stdin);
         freopen("output.txt", "w", stdout);
    #endif
}

int M = 1e9 + 7;
int M1 = 998244353;
#define qqq 4000005

vvi NCR(1001,vi(1001));
void NCRbuild(){
    NCR[0][0]=1;
    for(int i=1;i<1001;i++)NCR[i][0]=1;
    for(int i=1;i<1001;i++){
        for(int j=1;j<1001;j++){
            NCR[i][j]=(NCR[i-1][j]+NCR[i-1][j-1])%M;
        }
    }
}

int32_t main(){
    aps554();
    NCRbuild();
    int n,s=0;
    cin>>n;
    std::vector<int> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
        s+=arr[i];
    }
    int res=1,l=arr[0];
    for(int i=1;i<n;i++){
        arr[i]--;
        res=(res*(NCR[l+arr[i]][arr[i]]))%M;
        l+=arr[i]+1;
    }
    cout<<res<<endl;
}


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

//Hello World

typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define piiti pair< pair<int,int>,int>
#define ipii pair<int,pair<int,int> >
#define mod 1000000007
#define lasB(b) (b&(-b))
#define N 1003

lli n , sol=1 , acc , t;

lli C(int n ,int k)
{
    lli num =1, dem=1;
    for(int i=1;i<=n;i++)
    {
        num*=i;
        if(i<=k)dem*=i;
        if(i<=n-k)dem*=i;
        lli gcd = __gcd(num , dem);
        num/=gcd ;
        dem/=gcd;
    }
    return num /dem;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie();
    cin>>n;
    while(n-- && cin >>t)
    {
        acc+=t;
        sol=1LL * sol * C( acc -1 , t-1 ) %mod;;
    }
    cout<<sol;
    return 0;
}


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

//Hello World

typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define piiti pair< pair<int,int>,int>
#define ipii pair<int,pair<int,int> >
#define mod 1000000007
#define lasB(b) (b&(-b))
#define N 1003

lli n , sol=1 , acc , t;

lli C(int n ,int k)
{
    lli num =1, dem=1;
    for(int i=1;i<=n;i++)
    {
        num*=i;
        if(i<=k)dem*=i;
        if(i<=n-k)dem*=i;
        lli gcd = __gcd(num , dem);
        num/=gcd ;
        dem/=gcd;
    }
    return num /max(dem,1LL);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie();
    cin>>n;
    while(n-- && cin >>t)
    {
        acc+=t;
        sol=1LL * sol * C( acc -1 , t-1 ) %mod;;
    }
    cout<<sol;
    return 0;
}


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

//Hello World

typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define piiti pair< pair<int,int>,int>
#define ipii pair<int,pair<int,int> >
#define mod 1000000007
#define lasB(b) (b&(-b))
#define N 1003

lli n , sol =1 , acc , t;

int C[N][N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie();
    C[0][0]=1;
    for(int i=1;i<=1000;i++)
        for(int j=0;j<=i;j++)
            C[i][j]= (j==0 ? 1LL  :1LL *C[i-1][j-1]+C[i-1][j] )%mod ;
    cin>>n;
    while(n-- && cin >>t)
    {
        acc+=t;
        sol=1LL * sol * C[acc-1][t-1] %mod;
    }
    cout<<sol%mod;
    return 0;
}


#include <bits/stdc++.h>
#define N int(2e5+5)
#define mod 1000000007
using namespace std;
typedef long long ll;
ll ans = 1;
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
	if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
	fact.resize(n+5);
	inv_fact.resize(n+5);
	fact[0] = inv_fact[0] = 1;
	for(int i = 1; i <= n; i++){
		fact[i] = (fact[i-1] * i) % mod;
		inv_fact[i] = exp(fact[i], mod-2, mod);
	}
}
ll komb(ll a, ll b){
	if(a < b) return 0;
	return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

int main(){
    fact_init(1005);
    int n;
    cin >> n;
    int arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];
    int sum = arr[0];
    for(int i=1; i<n; i++){
        sum+=arr[i];
        ans*=komb((sum-1),arr[i]-1);
        ans = ans % mod;
    }
    cout << ans;
    /*
    2,1 2
    5,2 10
    9,3 84
    */
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define N 1000001
#define mod 1000000007
using namespace std;
ll gt[N+1];
ll power(ll a,ll n,ll m){
	ll cur=a,ans=1;
	while (n){
		if (n%2) ans=ans*cur%m;
		cur=cur*cur%m;
		n/=2;
	}
	return ans;
}
ll inv(ll a,ll m){
	return power(a,m-2,m);
}
ll C(ll k,ll n){
	return gt[n] * inv (gt[k],mod) % mod *inv(gt[n-k],mod) %mod;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	ll a[n+1];
	for (int i=1;i<=n;i++) cin>>a[i];
	ll ans=1,cur=a[1];
	gt[1]=1;
	for (int i=2;i<=N;i++) gt[i]=gt[i-1]*i%mod;
	for (int i=2;i<=n;i++) {
		ans*=C(cur,a[i]-1+cur);
		ans%=mod;
		cur+=a[i];
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define ll long long
#define N 1000001
#define mod 1000000007
using namespace std;
ll gt[N+1];
ll power(ll a,ll n,ll m){
	ll cur=a,ans=1;
	while (n){
		if (n%2) ans=ans*cur%m;
		cur=cur*cur%m;
		n/=2;
	}
	return ans;
}
ll inv(ll a,ll m){
	return power(a,m-2,m);
}
ll C(ll k,ll n){
	return gt[n] * inv (gt[k],mod) % mod *inv(gt[n-k],mod) %mod;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	ll a[n+1];
	for (int i=1;i<=n;i++) cin>>a[i];
	ll ans=1,cur=a[1];
	gt[0]=1;
	for (int i=1;i<=N;i++) gt[i]=gt[i-1]*i%mod;
	for (int i=2;i<=n;i++) {
		ans*=C(cur,a[i]-1+cur);
		ans%=mod;
		cur+=a[i];
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define ll long long
#define N 1000001
#define mod 1000000007
using namespace std;
ll gt[N+1];
ll power(ll a,ll n,ll m){
	ll cur=a,ans=1;
	while (n){
		if (n%2) ans=ans*cur%m;
		cur=cur*cur%m;
		n/=2;
	}
	return ans;
}
ll inv(ll a,ll m){
	return power(a,m-2,m);
}
ll C(ll k,ll n){
	return gt[n] * inv (gt[k],mod) % mod *inv(gt[n-k],mod) %mod;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	ll a[n+1];
	for (int i=1;i<=n;i++) cin>>a[i];
	ll ans=1,cur=a[1];
	gt[1]=1;
	for (int i=2;i<=N;i++) gt[i]=gt[i-1]*i%mod;
	for (int i=2;i<=n;i++) if (a[i]>1){
		ans*=C(cur,a[i]-1+cur);
		ans%=mod;
		cur+=a[i];
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define ll long long
#define N 1000001
#define mod 1000000007
using namespace std;
ll gt[N+1];
ll power(ll a,ll n,ll m){
	ll cur=a,ans=1;
	while (n){
		if (n%2) ans=ans*cur%m;
		cur=cur*cur%m;
		n/=2;
	}
	return ans;
}
ll inv(ll a,ll m){
	return power(a,m-2,m);
}
ll C(ll k,ll n){
	return gt[n] * inv (gt[k],mod) % mod *inv(gt[n-k],mod) %mod;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	ll a[n+1];
	for (int i=1;i<=n;i++) cin>>a[i];
	ll ans=1,cur=a[1];
	gt[1]=1;
	for (int i=2;i<=N;i++) gt[i]=gt[i-1]*i%mod;
	for (int i=2;i<=n;i++) if (a[i]>1){
		ans*=C(cur,a[i]-1+cur);
		cur+=a[i];
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 1e6 + 10;

int n, a[N];

#define ll int
ll power(ll a, ll b, ll m = mod){if(b < 0)b += m-1; ll r = 1; while(b){if(b&1)r=(r*a)%m; a = (a*a)%m; b>>=1;}return r;}

int fact[N+10], ifact[N+10];
void pre(int N){
   fact[0] = 1;
   for (int i = 1; i <= N; ++i)
   {
      fact[i] = (i*fact[i-1])%mod;
   }
   ifact[N] = power(fact[N], -1);
   for (int i = N-1; i >= 0; --i)
   {
      ifact[i] = ((i+1)*ifact[i+1])%mod;
   }
}

int nCr(int n, int r){
   if(n < r)return 0;
   return ((fact[n]*ifact[r])%mod * ifact[n-r])%mod;
}

int32_t main(){_

   cin>>n;

   pre(N);

   int sum = 0;
   int ans = 1;
   for (int i = 0; i < n; ++i)
   {
      int x;
      cin >> x;
      sum += x;
      ans *= nCr(sum-1, x-1);
      ans %= mod;
   }

   cout<<ans;

   return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define pb push_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;

const ll modo=1e9+7;
const ll inf=2e14;
const ll ms=(1e6) +5;

ll pp[ms];
ll ar[ms];

ll inverse(ll a,ll b,ll m)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        {
            res*=a;
            res%=modo;
        }
        a*=a;
        a%=m;
        b>>=1;
    }
    return res;
}

void func()
{
    int n=1e6;
    int i;
    pp[0]=1;
    for(i=1;i<=n;i++)
    {
        pp[i]=i*pp[i-1];
        pp[i]%=modo;
    }
}

ll ncr(ll n,ll r)
{
    ll den=(pp[r]*pp[n-r])%modo;
    den=inverse(den,modo-2,modo);
    ll aa=(pp[n]*den)%modo;
    return aa;
}

int main()
{
    idfc;
    func();

    ll n;
    cin>>n;
    int i;
    ll ss=0;
    ll ans=1;
    for(i=1;i<=n;i++)
    {
        cin>>ar[i];
    }
     ss=ar[1];
    ll aa;
    ll tmp;
    for(i=2;i<=n;i++)
    {
        if(ar[i]>1)
        {
            tmp=ans;
            ans+=((ncr(ss+ar[i]-1,ar[i]-1)-1)*tmp);
            ans%=modo;
        }

        ss+=ar[i];
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e3+10;
const int mod=1e9+7;
int a[N],pre[N],dp[N];
int com[N][N];
void combi(){
    com[0][0]=1;
    for(int i=1;i<N;i++){
        com[i][0]=1;
        for(int j=1;j<=i;j++){
            com[i][j]=(com[i-1][j-1]+com[i-1][j])%mod;

        }
    }
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pre[i]=pre[i-1]+a[i];
    }
    combi();
    dp[1]=1;
    for(int i=2;i<=n;i++){
        dp[i]=(dp[i-1]*com[pre[i]-1][a[i]-1])%mod;
    }
    cout<<dp[n]<<'\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e3+10;
const int mod=1e9+7;
int a[N],pre[N],dp[N];
int com[N][N];
void combi(){
    for(int i=1;i<N;i++){
        for(int j=0;j<=i;j++){
            if(j==0 or j==i) com[i][j]=1;
            else{
                com[i][j]=(com[i-1][j-1]+com[i-1][j])%mod;
            }
        }
    }
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pre[i]=pre[i-1]+a[i];
    }
    combi();
    dp[1]=1;
    for(int i=2;i<=n;i++){
        dp[i]=(dp[i-1]*com[pre[i]-1][a[i]-1])%mod;
    }
    cout<<dp[n]<<'\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e3+10;
const int mod=1e9+7;
int a[N],pre[N];
ll com[N][N],dp[N];
void combi(){
    com[0][0]=1;
    for(int i=1;i<N;i++){
        com[i][0]=1;
        for(int j=1;j<=i;j++){
            com[i][j]=(com[i-1][j-1]+com[i-1][j])%mod;

        }
    }
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pre[i]=pre[i-1]+a[i];
    }
    combi();
    dp[1]=1;
    for(int i=2;i<=n;i++){
        dp[i]=(dp[i-1]*com[pre[i]-1][a[i]-1])%mod;
    }
    cout<<dp[n]<<'\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e3+10;
const int mod=1e9+7;
int a[N],pre[N],dp[N];
int com[N][N];
void combi(){
    for(int i=1;i<N;i++){
        for(int j=0;j<=i;j++){
            if(j==0 or j==i) com[i][j]=1;
            else{
                com[i][j]=(com[i-1][j-1]+com[i-1][j])%mod;
            }
        }
    }
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pre[i]=pre[i-1]+a[i];
    }
    combi();
    dp[1]=1;
    for(int i=2;i<=n;i++){
        dp[i]=(dp[i-1]*com[pre[i]-1][a[i]-1])%mod;
    }
    cout<<dp[n]<<'\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	int c,d,f;
	double e;
	cin>>a>>b;
	cin>>c>>d>>e>>f;
	int g=0;
	g+=a*60;
	g+=b;
	int u=1200-g;
	double h;
	if(c%f==0){
		h=c/f;
	}
	if(c%f!=0){
		h=c/f+1;
	}
	h*=e;
	e=e*80/100;
	double p;
	if((c+(u*d))%f==0){
		p=(c+(u*d)/f);
	}
	if((c+(u*d))%f!=0){
		p=(c+(u*d))/f+1;
	}
	p*=e;
	cout<<setprecision(4)<<min(h,p);
}


#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
	double hh, mm, hunger, c, N, D;
	cin >> hh >> mm;
	cin >> hunger >> D >> c >> N;

	int wake = (hh*60)+mm;

	double openTime = (20*60) - wake;
	if(wake > 20*60)
	openTime = (24*60) - (wake - 20*60);

	double ex_hung = D*openTime;
//	cout<< "ex_hung "<<ex_hung<<endl;

	double ex_bun = ceil((ex_hung + hunger)/N);
//	cout<< "ex_bun "<<ex_bun <<endl;
	double ex_cost = (ex_bun*c)*(8.00/10);
//	cout<< "ex_cost "<<ex_cost<<endl;

	double real_cost = c*( ceil(hunger/N));

//	cout << real_cost << "  " << ex_cost<<endl;

	printf("%f\n", (min(real_cost, ex_cost)) );

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
	int t = 10;

	double hh, mm, hunger, c, N, D;
	cin >> hh >> mm;
	cin >> hunger >> D >> c >> N;

	int wake = (hh*60)+mm;

	double openTime = (20*60) - wake;
	if(wake > 20*60)
	openTime = (24*60) - (wake - 20*60);

//	cout<< "openTime = " <<openTime <<endl;

	double ex_hung = D*openTime;
//	cout<< "ex_hung "<<ex_hung<<endl;

	double ex_bun = ceil((ex_hung + hunger)/(N*1.00));
//	cout<< "ex_bun "<<ex_bun <<endl;
	double ex_cost = (ex_bun*c)*(8.00/10);
//	cout<< "ex_cost "<<ex_cost<<endl;

	double real_cost = c*( ceil(hunger/(N*1.00)));

//	cout << real_cost << "  " << ex_cost<<endl;

	printf("%0.3f\n", (min(real_cost, ex_cost)) );

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
	int t = 10;
	while(t--)
	{

	double hh, mm, hunger, c, N, D;
	cin >> hh >> mm;
	cin >> hunger >> D >> c >> N;

	int wake = (hh*60)+mm;

	double openTime = (20*60) - wake;
	if(wake > 20*60)
	openTime = (24*60) - (wake - 20*60);

//	cout<< "openTime = " <<openTime <<endl;

	double ex_hung = D*openTime;
//	cout<< "ex_hung "<<ex_hung<<endl;

	double ex_bun = ceil((ex_hung + hunger)/(N*1.00));
//	cout<< "ex_bun "<<ex_bun <<endl;
	double ex_cost = (ex_bun*c)*(8.00/10);
//	cout<< "ex_cost "<<ex_cost<<endl;

	double real_cost = c*( ceil(hunger/(N*1.00)));

//	cout << real_cost << "  " << ex_cost<<endl;

	printf("%0.3f\n", (min(real_cost, ex_cost)) );

}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
	int t = 10;

	double hh, mm, hunger, c, N, D;
	cin >> hh >> mm;
	cin >> hunger >> D >> c >> N;

	int wake = (hh*60)+mm;

	double openTime = (20*60) - wake;
	if(wake > 20*60)
	{
		double real_cost = c*( ceil(hunger/(N*1.00)));
		printf("%0.3f\n", real_cost*0.8);
		return 0;
	}

//	cout<< "openTime = " <<openTime <<endl;

	double ex_hung = D*openTime;
//	cout<< "ex_hung "<<ex_hung<<endl;

	double ex_bun = ceil((ex_hung + hunger)/(N*1.00));
//	cout<< "ex_bun "<<ex_bun <<endl;
	double ex_cost = (ex_bun*c)*(8.00/10);
//	cout<< "ex_cost "<<ex_cost<<endl;

	double real_cost = c*( ceil(hunger/(N*1.00)));

//	cout << real_cost << "  " << ex_cost<<endl;

	printf("%0.3f\n", (min(real_cost, ex_cost)) );

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
	double hh, mm, hunger, c, N, D;
	cin >> hh >> mm;
	cin >> hunger >> D >> c >> N;

	if(mm == 0) mm = 60;

	double openTime = 60*(22 - hh) + (60 - mm);
	double ex_hung = D*openTime;
//	cout<< "ex_hung "<<ex_hung<<endl;

	double ex_bun = ceil((ex_hung + hunger)/N);
//	cout<< "ex_bun "<<ex_bun <<endl;
	double ex_cost = (ex_bun*c)*(8.00/10);
//	cout<< "ex_cost "<<ex_cost<<endl;

	double real_cost = c*( ceil(hunger/N));

//	cout << real_cost << "  " << ex_cost<<endl;

	printf("%0.4f\n", (min(real_cost, ex_cost)) );

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
	double hh, mm, hunger, c, N, D;
	cin >> hh >> mm;
	cin >> hunger >> D >> c >> N;

	if(mm == 0) mm = 60;

	double openTime = 60*(22 - hh) + (60 - mm);
	double ex_hung = D*openTime;
//	cout<< "ex_hung "<<ex_hung<<endl;

	double ex_bun = ceil((ex_hung + hunger)/N);
//	cout<< "ex_bun "<<ex_bun <<endl;
	double ex_cost = (ex_bun*c)*(8.00/10);
//	cout<< "ex_cost "<<ex_cost<<endl;

	double real_cost = c*( ceil(hunger/N));

//	cout << real_cost << "  " << ex_cost<<endl;

	cout << min(real_cost, ex_cost) <<endl;

//	printf("%d\n", min(real_cost, ex_cost));

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
	int t = 10;
	double hh, mm, hunger, c, N, D;
	cin >> hh >> mm;
	cin >> hunger >> D >> c >> N;

	int wake = (hh*60)+mm;

	double openTime = (20*60) - wake;
	if(wake > 20*60)
	openTime = (24*60) - (wake - 20*60);

	cout<< "openTime = " <<openTime <<endl;

	double ex_hung = D*openTime;
//	cout<< "ex_hung "<<ex_hung<<endl;

	double ex_bun = ceil((ex_hung + hunger)/N);
//	cout<< "ex_bun "<<ex_bun <<endl;
	double ex_cost = (ex_bun*c)*(8.00/10);
//	cout<< "ex_cost "<<ex_cost<<endl;

	double real_cost = c*( ceil(hunger/N));

//	cout << real_cost << "  " << ex_cost<<endl;

	printf("%0.3f\n", (min(real_cost, ex_cost)) );

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
	int t = 10;
	double hh, mm, hunger, c, N, D;
	cin >> hh >> mm;
	cin >> hunger >> D >> c >> N;

	int wake = (hh*60)+mm;

	double openTime = (20*60) - wake;
	if(wake > 20*60)
	openTime = (24*60) - (wake - 20*60);

//	cout<< "openTime = " <<openTime <<endl;

	double ex_hung = D*openTime;
//	cout<< "ex_hung "<<ex_hung<<endl;

	double ex_bun = ceil((ex_hung + hunger)/N);
//	cout<< "ex_bun "<<ex_bun <<endl;
	double ex_cost = (ex_bun*c)*(8.00/10);
//	cout<< "ex_cost "<<ex_cost<<endl;

	double real_cost = c*( ceil(hunger/N));

//	cout << real_cost << "  " << ex_cost<<endl;

	printf("%0.3f\n", (min(real_cost, ex_cost)) );

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
	double hh, mm, hunger, c, N, D;
	cin >> hh >> mm;
	cin >> hunger >> D >> c >> N;

	int wake = (hh*60)+mm;

	double openTime = (20*60) - wake;
	if(wake > 20*60)
	openTime = (24*60) - (wake - 20*60);

	double ex_hung = D*openTime;
//	cout<< "ex_hung "<<ex_hung<<endl;

	double ex_bun = ceil((ex_hung + hunger)/N);
//	cout<< "ex_bun "<<ex_bun <<endl;
	double ex_cost = (ex_bun*c)*(8.00/10);
//	cout<< "ex_cost "<<ex_cost<<endl;

	double real_cost = c*( ceil(hunger/N));

//	cout << real_cost << "  " << ex_cost<<endl;

	printf("%0.4f\n", (min(real_cost, ex_cost)) );

	return 0;
}


    #include<bits/stdc++.h>
       using namespace std;
       typedef long long ll;
       typedef long double ld;
       int setbit(int n, int i, int v)
       {
               return ((v) ? (n | (1 << i)) : (n&~(1 << i)));
       }
       ll gcd(int i, int j)
       {
               if (j == 0)
                       return i;
               return gcd(j, i%j);
       }
       bool chk(int n, int i)
       {
               if ((n >> i) & 1 == 1)
                       return 1;
               return 0;
       }
       string tostring1(ll n)
       {
               string res = "";
               while (n)
               {
                       res += ((n % 10) + '0');
                       n /= 10;

               }
               reverse(res.begin(), res.end());
               return res;
       }
       bool T(pair<int, int>p1, pair<int, int>p2)
       {
               return (p2.second - p1.first >= p2.second - p2.first);
       }
       ll todec(string s)
       {
               ll res = 0; ll cnt = 0;
               for (int i = s.length() - 1; i >= 0; i--)
               {
                       res += (s[i] - '0')*pow(10, cnt);
                       cnt++;
               }
               return res;
       }

       int main()
       {

           double h,m,hh,d,c,n;
           cin>>h>>m>>hh>>d>>c>>n;
           double x;
           x=h*60+m;
           x=1200-x;
           if(x<0)
               x=0;
           double cc1=ceil(hh/n);
           cc1*=c;
           hh+=(d*x);
           double cc2=ceil(hh/n);
           c-=(0.2*c);
           cc2=(c*cc2);
           if(cc1<=cc2)
               cout<<setprecision(4)<<fixed<<cc1<<endl;
           else
                cout<<setprecision(4)<<fixed<<cc2<<endl;

               return 0;
       }


    #include<bits/stdc++.h>
       using namespace std;
       typedef long long ll;
       typedef long double ld;
       int setbit(int n, int i, int v)
       {
               return ((v) ? (n | (1 << i)) : (n&~(1 << i)));
       }
       ll gcd(int i, int j)
       {
               if (j == 0)
                       return i;
               return gcd(j, i%j);
       }
       bool chk(int n, int i)
       {
               if ((n >> i) & 1 == 1)
                       return 1;
               return 0;
       }
       string tostring1(ll n)
       {
               string res = "";
               while (n)
               {
                       res += ((n % 10) + '0');
                       n /= 10;

               }
               reverse(res.begin(), res.end());
               return res;
       }
       bool T(pair<int, int>p1, pair<int, int>p2)
       {
               return (p2.second - p1.first >= p2.second - p2.first);
       }
       ll todec(string s)
       {
               ll res = 0; ll cnt = 0;
               for (int i = s.length() - 1; i >= 0; i--)
               {
                       res += (s[i] - '0')*pow(10, cnt);
                       cnt++;
               }
               return res;
       }

       int main()
       {

           double h,m,hh,d,c,n;
           cin>>h>>m>>hh>>d>>c>>n;
           double x,y;
           if(h<=20)
               x=20-h;
           x*=60;
           x-=m;
             if(n>hh)
               hh=n;

           double cc1=ceil(hh/n);
           cc1*=c;
           hh+=(d*x);

           double cc2=ceil(hh/n);
           c-=((20*c)/100);
           cc2=(c*cc2);
           if(cc1<cc2)
               cout<<setprecision(10)<<fixed<<cc1<<endl;
           else
                cout<<setprecision(10)<<fixed<<cc2<<endl;

               return 0;
       }


    #include<bits/stdc++.h>
       using namespace std;
       typedef long long ll;
       typedef long double ld;
       int setbit(int n, int i, int v)
       {
               return ((v) ? (n | (1 << i)) : (n&~(1 << i)));
       }
       ll gcd(int i, int j)
       {
               if (j == 0)
                       return i;
               return gcd(j, i%j);
       }
       bool chk(int n, int i)
       {
               if ((n >> i) & 1 == 1)
                       return 1;
               return 0;
       }
       string tostring1(ll n)
       {
               string res = "";
               while (n)
               {
                       res += ((n % 10) + '0');
                       n /= 10;

               }
               reverse(res.begin(), res.end());
               return res;
       }
       bool T(pair<int, int>p1, pair<int, int>p2)
       {
               return (p2.second - p1.first >= p2.second - p2.first);
       }
       ll todec(string s)
       {
               ll res = 0; ll cnt = 0;
               for (int i = s.length() - 1; i >= 0; i--)
               {
                       res += (s[i] - '0')*pow(10, cnt);
                       cnt++;
               }
               return res;
       }

       int main()
       {

           double h,m,hh,d,c,n;
           cin>>h>>m>>hh>>d>>c>>n;
           double x,y;
           x=h*60+m;
           x=1200-x;
           double cc1=ceil(hh/n);
           cc1*=c;
           hh+=(d*x);

           double cc2=ceil(hh/n);
           c-=(0.2*c);
           cc2=(c*cc2);
           if(cc1<cc2)
               cout<<setprecision(4)<<fixed<<cc1<<endl;
           else
                cout<<setprecision(4)<<fixed<<cc2<<endl;

               return 0;
       }


    #include<bits/stdc++.h>
       using namespace std;
       typedef long long ll;
       typedef long double ld;
       int setbit(int n, int i, int v)
       {
               return ((v) ? (n | (1 << i)) : (n&~(1 << i)));
       }
       ll gcd(int i, int j)
       {
               if (j == 0)
                       return i;
               return gcd(j, i%j);
       }
       bool chk(int n, int i)
       {
               if ((n >> i) & 1 == 1)
                       return 1;
               return 0;
       }
       string tostring1(ll n)
       {
               string res = "";
               while (n)
               {
                       res += ((n % 10) + '0');
                       n /= 10;

               }
               reverse(res.begin(), res.end());
               return res;
       }
       bool T(pair<int, int>p1, pair<int, int>p2)
       {
               return (p2.second - p1.first >= p2.second - p2.first);
       }
       ll todec(string s)
       {
               ll res = 0; ll cnt = 0;
               for (int i = s.length() - 1; i >= 0; i--)
               {
                       res += (s[i] - '0')*pow(10, cnt);
                       cnt++;
               }
               return res;
       }

       int main()
       {

           double h,m,hh,d,c,n;
           cin>>h>>m>>hh>>d>>c>>n;
           double x,y;
           if(h<=20)
               x=20-h;
           x*=60;
           x-=m;
             if(n>hh)
               hh=n;
           double cc1=ceil(hh/n);
           cc1*=c;
           hh+=(d*x);
           double cc2=ceil(hh/n);
           c-=((20*c)/100);
           cc2=(c*cc2);
           if(cc1<cc2)
               cout<<setprecision(4)<<fixed<<cc1<<endl;
           else
                cout<<setprecision(4)<<fixed<<cc2<<endl;

               return 0;
       }


    #include<bits/stdc++.h>
       using namespace std;
       typedef long long ll;
       typedef long double ld;
       int setbit(int n, int i, int v)
       {
               return ((v) ? (n | (1 << i)) : (n&~(1 << i)));
       }
       ll gcd(int i, int j)
       {
               if (j == 0)
                       return i;
               return gcd(j, i%j);
       }
       bool chk(int n, int i)
       {
               if ((n >> i) & 1 == 1)
                       return 1;
               return 0;
       }
       string tostring1(ll n)
       {
               string res = "";
               while (n)
               {
                       res += ((n % 10) + '0');
                       n /= 10;

               }
               reverse(res.begin(), res.end());
               return res;
       }
       bool T(pair<int, int>p1, pair<int, int>p2)
       {
               return (p2.second - p1.first >= p2.second - p2.first);
       }
       ll todec(string s)
       {
               ll res = 0; ll cnt = 0;
               for (int i = s.length() - 1; i >= 0; i--)
               {
                       res += (s[i] - '0')*pow(10, cnt);
                       cnt++;
               }
               return res;
       }

       int main()
       {

           double h,m,hh,d,c,n;
           cin>>h>>m>>hh>>d>>c>>n;
           double x,y;
           x=0;
           if(h<=20)
               x=20-h;

           x*=60;
           x-=m;

           double cc1=ceil(hh/n);
           cc1*=c;
           hh+=(d*x);

           double cc2=ceil(hh/n);
           c-=(0.2*c);
           cc2=(c*cc2);
           if(cc1<cc2)
               cout<<setprecision(4)<<fixed<<cc1<<endl;
           else
                cout<<setprecision(4)<<fixed<<cc2<<endl;

               return 0;
       }


    #include<bits/stdc++.h>
       using namespace std;
       typedef long long ll;
       typedef long double ld;
       int setbit(int n, int i, int v)
       {
               return ((v) ? (n | (1 << i)) : (n&~(1 << i)));
       }
       ll gcd(int i, int j)
       {
               if (j == 0)
                       return i;
               return gcd(j, i%j);
       }
       bool chk(int n, int i)
       {
               if ((n >> i) & 1 == 1)
                       return 1;
               return 0;
       }
       string tostring1(ll n)
       {
               string res = "";
               while (n)
               {
                       res += ((n % 10) + '0');
                       n /= 10;

               }
               reverse(res.begin(), res.end());
               return res;
       }
       bool T(pair<int, int>p1, pair<int, int>p2)
       {
               return (p2.second - p1.first >= p2.second - p2.first);
       }
       ll todec(string s)
       {
               ll res = 0; ll cnt = 0;
               for (int i = s.length() - 1; i >= 0; i--)
               {
                       res += (s[i] - '0')*pow(10, cnt);
                       cnt++;
               }
               return res;
       }

       int main()
       {

           double h,m,hh,d,c,n;
           cin>>h>>m>>hh>>d>>c>>n;
           double x,y;
           if(h<=20)
               x=20-h;
           x*=60;
           x-=m;
             if(n>hh)
               hh=n;
           double cc1=ceil(hh/n);

           cc1*=c;
           hh+=(d*x);
           double cc2=ceil(hh/n);
           c-=(0.2*c);
           cc2=(c*cc2);
           if(cc1<cc2)
               cout<<setprecision(4)<<fixed<<cc1<<endl;
           else
                cout<<setprecision(4)<<fixed<<cc2<<endl;

               return 0;
       }


    #include<bits/stdc++.h>
       using namespace std;
       typedef long long ll;
       typedef long double ld;
       int setbit(int n, int i, int v)
       {
               return ((v) ? (n | (1 << i)) : (n&~(1 << i)));
       }
       ll gcd(int i, int j)
       {
               if (j == 0)
                       return i;
               return gcd(j, i%j);
       }
       bool chk(int n, int i)
       {
               if ((n >> i) & 1 == 1)
                       return 1;
               return 0;
       }
       string tostring1(ll n)
       {
               string res = "";
               while (n)
               {
                       res += ((n % 10) + '0');
                       n /= 10;

               }
               reverse(res.begin(), res.end());
               return res;
       }
       bool T(pair<int, int>p1, pair<int, int>p2)
       {
               return (p2.second - p1.first >= p2.second - p2.first);
       }
       ll todec(string s)
       {
               ll res = 0; ll cnt = 0;
               for (int i = s.length() - 1; i >= 0; i--)
               {
                       res += (s[i] - '0')*pow(10, cnt);
                       cnt++;
               }
               return res;
       }

       int main()
       {

           double h,m,hh,d,c,n;
           cin>>h>>m>>hh>>d>>c>>n;
           double res1,res2;
           double x,y;
           if(h<20)
               x=20-h;
           x*=60;
           x-=m;
           double cc1=ceil(hh/n);
           cc1*=c;
           hh+=(d*x);
           double cc2=ceil(hh/n);
           c-=(0.2*c);
           cc2=(c*cc2);
           if(cc1<cc2)
               cout<<setprecision(4)<<fixed<<cc1<<endl;
           else
                cout<<setprecision(4)<<fixed<<cc2<<endl;

               return 0;
       }


    #include<bits/stdc++.h>
       using namespace std;
       typedef long long ll;
       typedef long double ld;
       int setbit(int n, int i, int v)
       {
               return ((v) ? (n | (1 << i)) : (n&~(1 << i)));
       }
       ll gcd(int i, int j)
       {
               if (j == 0)
                       return i;
               return gcd(j, i%j);
       }
       bool chk(int n, int i)
       {
               if ((n >> i) & 1 == 1)
                       return 1;
               return 0;
       }
       string tostring1(ll n)
       {
               string res = "";
               while (n)
               {
                       res += ((n % 10) + '0');
                       n /= 10;

               }
               reverse(res.begin(), res.end());
               return res;
       }
       bool T(pair<int, int>p1, pair<int, int>p2)
       {
               return (p2.second - p1.first >= p2.second - p2.first);
       }
       ll todec(string s)
       {
               ll res = 0; ll cnt = 0;
               for (int i = s.length() - 1; i >= 0; i--)
               {
                       res += (s[i] - '0')*pow(10, cnt);
                       cnt++;
               }
               return res;
       }

       int main()
       {

           double h,m,hh,d,c,n;
           cin>>h>>m>>hh>>d>>c>>n;
           double x,y;
           x=0;
           if(h<=20)
               x=20-h;

           x*=60;
           x-=m;
             if(n>hh)
               hh=n;

           double cc1=ceil(hh/n);
           cc1*=c;
           hh+=(d*x);

           double cc2=ceil(hh/n);
           c-=((20*c)/100);
           cc2=(c*cc2);
           if(cc1<cc2)
               cout<<setprecision(4)<<fixed<<cc1<<endl;
           else
                cout<<setprecision(4)<<fixed<<cc2<<endl;

               return 0;
       }


    #include<bits/stdc++.h>
       using namespace std;
       typedef long long ll;
       typedef long double ld;
       int setbit(int n, int i, int v)
       {
               return ((v) ? (n | (1 << i)) : (n&~(1 << i)));
       }
       ll gcd(int i, int j)
       {
               if (j == 0)
                       return i;
               return gcd(j, i%j);
       }
       bool chk(int n, int i)
       {
               if ((n >> i) & 1 == 1)
                       return 1;
               return 0;
       }
       string tostring1(ll n)
       {
               string res = "";
               while (n)
               {
                       res += ((n % 10) + '0');
                       n /= 10;

               }
               reverse(res.begin(), res.end());
               return res;
       }
       bool T(pair<int, int>p1, pair<int, int>p2)
       {
               return (p2.second - p1.first >= p2.second - p2.first);
       }
       ll todec(string s)
       {
               ll res = 0; ll cnt = 0;
               for (int i = s.length() - 1; i >= 0; i--)
               {
                       res += (s[i] - '0')*pow(10, cnt);
                       cnt++;
               }
               return res;
       }

       int main()
       {

           double h,m,hh,d,c,n;
           cin>>h>>m>>hh>>d>>c>>n;
           double x,y;
           x=0;
           if(h<=20)
               x=20-h;

           x*=60;
           x-=m;
           if(x<0)
               x=0;
           double cc1=ceil(hh/n);
           cc1*=c;
           hh+=(d*x);

           double cc2=ceil(hh/n);
           c-=((20*c)/100);
           cc2=(c*cc2);
           if(cc1<cc2)
               cout<<setprecision(4)<<fixed<<cc1<<endl;
           else
                cout<<setprecision(4)<<fixed<<cc2<<endl;

               return 0;
       }


    #include<bits/stdc++.h>
       using namespace std;
       typedef long long ll;
       typedef long double ld;
       int setbit(int n, int i, int v)
       {
               return ((v) ? (n | (1 << i)) : (n&~(1 << i)));
       }
       ll gcd(int i, int j)
       {
               if (j == 0)
                       return i;
               return gcd(j, i%j);
       }
       bool chk(int n, int i)
       {
               if ((n >> i) & 1 == 1)
                       return 1;
               return 0;
       }
       string tostring1(ll n)
       {
               string res = "";
               while (n)
               {
                       res += ((n % 10) + '0');
                       n /= 10;

               }
               reverse(res.begin(), res.end());
               return res;
       }
       bool T(pair<int, int>p1, pair<int, int>p2)
       {
               return (p2.second - p1.first >= p2.second - p2.first);
       }
       ll todec(string s)
       {
               ll res = 0; ll cnt = 0;
               for (int i = s.length() - 1; i >= 0; i--)
               {
                       res += (s[i] - '0')*pow(10, cnt);
                       cnt++;
               }
               return res;
       }

       int main()
       {

           double h,m,hh,d,c,n;
           cin>>h>>m>>hh>>d>>c>>n;
           double x,y;
           if(h<=20)
               x=20-h;
           x*=60;
           x-=m;
           double cc1=ceil(hh/n);
           cc1*=c;
           hh+=(d*x);
           double cc2=ceil(hh/n);
           c-=(0.2*c);
           cc2=(c*cc2);
           if(cc1<cc2)
               cout<<setprecision(4)<<fixed<<cc1<<endl;
           else
                cout<<setprecision(4)<<fixed<<cc2<<endl;

               return 0;
       }


#include<cstdio>
#include<cmath>
#include<algorithm>
using std::min;

int main()
{
	double hh, mm;
	double H, D, C, N;

	scanf("%lf%lf", &hh, &mm);
	scanf("%lf%lf%lf%lf", &H, &D, &C, &N);

	double T = 20*60 - (hh*60+mm);
	if(hh >= 20) printf("%.4lf", 0.8*C*ceil(H/N) + 0.00001);
	else printf("%.4lf", min(C*ceil(H/N) + 0.00001, 0.8*C*ceil((H+T*D)/N) + 0.00001));
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
using std::min;

int main()
{
	double hh, mm;
	double H, D, C, N;

	scanf("%lf%lf", &hh, &mm);
	scanf("%lf%lf%lf%lf", &H, &D, &C, &N);

	double T = 20*60 - hh*60+mm;
	if(hh >= 20) printf("%.4lf", 0.8*C*ceil(H/N) + 0.00001);
	else printf("%.4lf", min(C*ceil(H/N) + 0.00001, 0.8*C*ceil((H+T*D)/N) + 0.00001));
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
using std::min;

int main()
{
	long long hh, mm;
	double H, D, C, N;

	scanf("%lld%lld", &hh, &mm);
	scanf("%lf%lf%lf%lf", &H, &D, &C, &N);

	long long T = 20*60 - hh*60+mm;
	if(hh >= 20) T = 0;
	printf("%.4lf\n", min(C*ceil(H/N), 0.8*C*ceil((H+T*D)/N)) + 0.00001);
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
using std::min;

int main()
{
	long long hh, mm;
	double H, D, C, N;

	scanf("%lld%lld", &hh, &mm);
	scanf("%lf%lf%lf%lf", &H, &D, &C, &N);

	long long T = 20*60 - hh*60+mm;
	if(hh >= 20) T = 0;
	printf("%.4lf\n", min(C*ceil(H/N), 0.8*C*ceil((H+T*D)/N)));
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
using std::min;

int main()
{
	int hh, mm;
	double H, D, C, N;

	scanf("%d%d", &hh, &mm);
	scanf("%lf%lf%lf%lf", &H, &D, &C, &N);

	int T = 20*60 - hh*60+mm;
	if(hh >= 20) T = 0;
	printf("%.4lf\n", min(C*ceil(H/N), C*(0.8)*ceil((H+(T*D))/N)));
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
using std::min;

int main()
{
	double hh, mm;
	double H, D, C, N;

	scanf("%lf%lf", &hh, &mm);
	scanf("%lf%lf%lf%lf", &H, &D, &C, &N);

	double T = 20*60 - hh*60+mm;
	if(hh >= 20) printf("%.4lf", 0.8*C*ceil(H/N) + 0.00001);
	else printf("%.4lf", min(C*ceil(H/N), 0.8*C*ceil((H+T*D)/N)) + 0.00001);
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
using std::min;

int main()
{
	long long hh, mm;
	double H, D, C, N;

	scanf("%lld%lld", &hh, &mm);
	scanf("%lf%lf%lf%lf", &H, &D, &C, &N);

	double T = 20*60 - hh*60+mm;
	if(hh >= 20) printf("%.4lf", 0.8*C*ceil(H/N) + 0.00001);
	else printf("%.4lf", min(C*ceil(H/N), 0.8*C*ceil((H+T*D)/N)) + 0.00001);
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
using std::min;

int main()
{
	long long hh, mm;
	double H, D, C, N;

	scanf("%lld%lld", &hh, &mm);
	scanf("%lf%lf%lf%lf", &H, &D, &C, &N);

	long long T = 20*60 - hh*60+mm;
	if(hh >= 20) printf("%.4lf", 0.8*C*ceil(H/N));
	else printf("%.4lf", min(C*ceil(H/N), 0.8*C*ceil((H+T*D)/N)) + 0.00001);
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
float hr,h,m,d,c,n,a,b;
int main ()
{
	cin>>hr>>m;
	cin>>h>>d>>c>>n;
	//if(hr<20){
		a=(h/n)*c;
		c=(c*8)/10;
		b=((((((20-hr-1)*60)+(60-m))*d)+(h))/n)*c;
		//cout<<a<<" "<<b<<"\n";
		cout<<fixed<<setprecision(4)<<min(a,b);
	//}
	//else{
	//	c=(c*8)/10;
	//	a=(h/n)*c;
	//	cout<<a;
	//}
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
float hr,h,m,d,c,n,a,b;
int main ()
{
	cin>>hr>>m;
	cin>>h>>d>>c>>n;
	if(hr<20){
		a=ceil(h/n)*c;
		c=(c*8)/10;
		b=ceil((((((20-hr-1)*60)+(60-m))*d)+(h))/n)*c;
		//cout<<a<<" "<<b<<"\n";
		cout<<fixed<<setprecision(4)<<min(a,b);
	}
	else{
		c=(c*8)/10;
		a=ceil(h/n)*c;
		cout<<a;
	}
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main ()
{
	float hr,h,m,d,c,n,a,b;
	cin>>hr>>m;
	cin>>h>>d>>c>>n;
	if(hr<20){
		a=(h/n)*c;
		c=(c*8)/10;
		b=((((((20-hr-1)*60)+(60-m))*d)+(h))/n)*c;
		//cout<<a<<" "<<b<<"\n";
		cout<<min(a,b);
	}
	else{
		c=(c*8)/10;
		a=(h/n)*c;
		cout<<a;
	}
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
float hr,h,m,d,c,n,a,b;
int main ()
{
	cin>>hr>>m;
	cin>>h>>d>>c>>n;
	//if(hr<20){
		a=ceil(h/n)*c;
		c=ceil(c*8)/10;
		b=ceil((((((20-hr-1)*60)+(60-m))*d)+(h))/n)*c;
		//cout<<a<<" "<<b<<"\n";
		cout<<fixed<<setprecision(4)<<min(a,b);
	//}
	//else{
	//	c=(c*8)/10;
	//	a=(h/n)*c;
	//	cout<<a;
	//}
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
float hr,h,m,d,c,n,a,b;
int main ()
{
	cin>>hr>>m;
	cin>>h>>d>>c>>n;
	//if(hr<20){
		a=ceil(h/n)*c;
		c=(c*8)/10;
		b=ceil((((((20-hr-1)*60)+(60-m))*d)+(h))/n)*c;
		//cout<<a<<" "<<b<<"\n";
		cout<<fixed<<setprecision(4)<<min(a,b);
	//}
	//else{
	//	c=(c*8)/10;
	//	a=(h/n)*c;
	//	cout<<a;
	//}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
   double H,D,C,N;
   int hh,mm;
   double cost1,cost2;
   cin>>hh>>mm>>H>>D>>C>>N;
   int x=(hh*60)+mm;
   double z=1200-x;
   double dd=D*z;
   double HH=H+dd;
   double reduced=ceil(HH/N);
   double money=reduced*C;
   cost1=money-(money*0.2);

   reduced=ceil(H/N);
   cost2=reduced*C;
   cout<<min(cost1,cost2);

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    double H,D,C,N;
    int hh,mm;
    double cost1,cost2;
    cin>>hh>>mm>>H>>D>>C>>N;
    int x=(hh*60)+mm;
    if(x>= 1200 && x<1439)
    {

    cout<<H*0.8;
    return 0;
    }
    else {
    double z=1200-x;
    double dd=D*z;
    double HH=H+dd;
    double reduced=ceil(HH/N);
    double money=reduced*C;
    cost1=money-(money*0.2);

    reduced=ceil(H/N);
    cost2=reduced*C;
    cout<<min(cost1,cost2);
    }

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    double H,D,C,N;
    int hh,mm;
    double cost1,cost2;
    cin>>hh>>mm>>H>>D>>C>>N;
    int x=(hh*60)+mm;
    if(x>= 1200 && x<=1439)
    {

    cout<<H*0.8;
    return 0;
    }
    else {
    double z=1200-x;
    double dd=D*z;
    double HH=H+dd;
    double reduced=ceil(HH/N);
    double money=reduced*C;
    cost1=money-(money*0.2);

    reduced=ceil(H/N);
    cost2=reduced*C;
    cout<<min(cost1,cost2);
    }

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    double H,D,C,N;
    int hh,mm;
    double cost1,cost2;
    cin>>hh>>mm>>H>>D>>C>>N;
    int x=(hh*60)+mm;
    if(x>= 1200 && x<=1439)
    {

    cout<<ceil(H/N)*C*0.8;
    return 0;
    }
    else {
    double z=1200-x;
    double dd=D*z;
    double HH=H+dd;
    double reduced=ceil(HH/N);
    double money=reduced*C;
    cost1=money-(money*0.2);

    reduced=ceil(H/N);
    cost2=reduced*C;
    cout<<min(cost1,cost2);
    }

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    double H,D,C,N;
    int hh,mm;
    double cost1,cost2;
    cin>>hh>>mm>>H>>D>>C>>N;
    int x=(hh*60)+mm;
    if(x>= 1200 && x<=1439)
    {

    cout<<(H/D)*C*0.8;
    return 0;
    }
    else {
    double z=1200-x;
    double dd=D*z;
    double HH=H+dd;
    double reduced=ceil(HH/N);
    double money=reduced*C;
    cost1=money-(money*0.2);

    reduced=ceil(H/N);
    cost2=reduced*C;
    cout<<min(cost1,cost2);
    }

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    double H,D,C,N;
    int hh,mm;
    double cost1,cost2;
    cin>>hh>>mm>>H>>D>>C>>N;
    int x=(hh*60)+mm;
    if(x>= 1200 && x<=1439)
    {

    cout<<(H/N)*C*0.8;
    return 0;
    }
    else {
    double z=1200-x;
    double dd=D*z;
    double HH=H+dd;
    double reduced=ceil(HH/N);
    double money=reduced*C;
    cost1=money-(money*0.2);

    reduced=ceil(H/N);
    cost2=reduced*C;
    cout<<min(cost1,cost2);
    }

}


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

int main() {
    int h , m , health , d , c , n ;
    cin >>h >> m >> health >> d >>c >> n;
    double  nc = c* .8 ;
    int cnt = 0;
    if (h<20)
    {
         cnt = 0 ;
        while (h!= 20)
        {
            if(m ==59)
            {
                m=0, h++;
            }
            m++;
            cnt+= d ;
        }
    } else{
        cout << ceil(health*1.0 /n)  * nc << endl;
        return 0;
    }
    cnt+= health;
    double a , b ;
    a = ceil(health*1.0/n) * c ;
    b = ceil(cnt*1.0/n)*nc ;
    printf("%.5f\n", min(a,b));
    return 0;
}


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

int main() {
    ll h , m , health , d , c , n ;

    cin >>h >> m >> health >> d >>c >> n;
   long double  nc = c* .8 ;
    ll cnt = 0;
    if (h<20)
    {
         cnt = 0 ;
        while (h!= 20)
        {
            if(m ==59)
            {
                m=0, h++;
            }
            m++;
            cnt+= d ;
        }
    } else{
        int out = 0;
        while (health>0)
            health-= n, out++;
        cout << std::setprecision(9) << out * nc* 1.0;
        return 0;
    }
    cnt+= health;
   long double a , b ;
    int x=0, y=0 ;
    while (health>0)
        health-= n, x++;
    while (cnt>0)
        cnt-=n , y++;
    a = x * c *1.0;
    b = y*nc *1.0;

    cout << std::setprecision(9) << min(a,b);
    return 0;
}


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

int main() {
    int h , m , health , d , c , n ;

    cin >>h >> m >> health >> d >>c >> n;
    double  nc = c* .8 ;
    int cnt = 0;
    if (h<20)
    {
         cnt = 0 ;
        while (h!= 20)
        {
            if(m ==59)
            {
                m=0, h++;
            }
            m++;
            cnt+= d ;
        }
    } else{
        int out = 0;
        while (health>0)
            health-= n, out++;
        printf("%.5f\n" , out * nc* 1.0);
        return 0;
    }
    cnt+= health;
    double a , b ;
    int x=0, y=0 ;
    while (health>0)
        health-= n, x++;
    while (cnt>0)
        cnt-=n , y++;
    a = x * c *1.0;
    b = y*nc *1.0;
    printf("%.5f\n", min(a,b));
    return 0;
}


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

int main() {
    int h , m , health , d , c , n ;
    cin >>h >> m >> health >> d >>c >> n;
    double  nc = c* .8 ;
    int cnt = 0;
    if (h<20)
    {
         cnt = 0 ;
        while (h!= 20)
        {
            if(m ==59)
            {
                m=0, h++;
            }
            m++;
            cnt+= d ;
        }
    } else{
        int out = 0;
        while (health>0)
            health-= n, out++;
        printf("%.5f" , out * nc);
        return 0;
    }
    cnt+= health;
    double a , b ;
    int x=0, y=0 ;
    while (health>0)
        health-= n, x++;
    while (cnt>0)
        cnt-=n , y++;
    a = x * c ;
    b = y*nc ;
    printf("%.5f\n", min(a,b));
    return 0;
}


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

int main() {
    int h , m , health , d , c , n ;
    cin >>h >> m >> health >> d >>c >> n;
    double  nc = c* .8 ;
    int cnt = 0;
    if (h<20)
    {
         cnt = 0 ;
        while (h!= 20)
        {
            if(m ==59)
            {
                m=0, h++;
            }
            m++;
            cnt+= d ;
        }
    } else{
        int out = 0;
        while (health>0)
            health-= n, out++;
        printf("%.5f" ,ceil(health*1.0 /n)  * nc );
        return 0;
    }
    cnt+= health;
    double a , b ;
    a = ceil(health*1.0/n) * c ;
    b = ceil(cnt*1.0/n)*nc ;
    printf("%.5f\n", min(a,b));
    return 0;
}


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

int main() {
    int h , m , health , d , c , n ;
    cin >>h >> m >> health >> d >>c >> n;
    double  nc = c* .8 ;
    int cnt = 0;
    if (h<20)
    {
         cnt = 0 ;
        while (h!= 20)
        {
            if(m ==59)
            {
                m=0, h++;
            }
            m++;
            cnt+= d ;
        }
    } else{
        int out = 0;

        printf("%.5f" ,ceil(health*1.0 /n)  * nc );
        return 0;
    }
    cnt+= health;
    double a , b ;
    a = ceil(health*1.0/n) * c ;
    b = ceil(cnt*1.0/n)*nc ;
    printf("%.5f\n", min(a,b));
    return 0;
}


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

int main() {
    int h , m , health , d , c , n ;

    cin >>h >> m >> health >> d >>c >> n;
    double  nc = c* .8 ;
    int cnt = 0;
    if (h<20)
    {
         cnt = 0 ;
        while (h!= 20)
        {
            if(m ==59)
            {
                m=0, h++;
            }
            m++;
            cnt+= d ;
        }
    } else{
        int out = 0;
        while (health>0)
            health-= n, out++;
        printf("%.5f\n" , out * nc);
        return 0;
    }
    cnt+= health;
    double a , b ;
    int x=0, y=0 ;
    while (health>0)
        health-= n, x++;
    while (cnt>0)
        cnt-=n , y++;
    a = x * c *1.0;
    b = y*nc *1.0;
    printf("%.5f\n", min(a,b));
    return 0;
}


#include <bits/stdc++.h>

using namespace std ;

int main()
{
    int hours,mm,h,d,c,n ;  double d1,d2,d3 ;
    cin >> hours >> mm >> h >> d >> c >> n ;
    if(hours >= 20)
    {
        if(h%n == 0) d3 = double (h/n)*c  ;
        else d3 = int((h/n)+1)*c ;
        d3 = d3 - ((d3*20)/100) ;
        printf("%0.6f", d3 ) ;
        return 0 ;
    }
    else
    {
        if(h%n == 0) d1 = double (h/n)*c  ;
        else d1 = int((h/n)+1)*c ;

        int t = (1200 - ((hours*60) + mm))*d ;
        int ss = (t+h) ;

        if(ss%n == 0) d2 = double (ss/n)*c  ;
        else d2 = int((ss/n)+1)*c ;
        d2 = d2 - ((d2*20)/100) ;
        if(d2 < d1) printf("%0.6f", d2 )  ; else printf("%0.6f", d1 ) ;

        return 0 ;
    }
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <iostream>

using namespace std;

int main()
{
    int hh, mm;

    double ct = 0, ct2 = 0, ct3 = 0, f = 0, h, d, c, n;

    cin >> hh >> mm;
    cin >> h >> d >> c >> n;

    if( hh >= 20.0 )
    {
        ct = h / n * (c * 0.8);
        cout << ct;
    }
    else
    {
        ct = (h + ((20.0 - hh + mm ) * 60.0 )) / n * (c * 0.8);
        ct2 = h / n * c;

        cout << min(ct, ct2);
    }

    return 0;
}


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

#define all(v) 	((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define sz(v) 	((int)((v).size()))
#define ll 	long long

typedef pair<int, string> p;

void File()
{
    // Reading from file
    freopen("output.txt","m",stdout);
    // Writeing in file
    freopen("input.txt","m",stdin);
}
void fast()
{
    ios::sync_with_stdio(NULL);
    cout.tie(NULL);
    cin.tie(NULL);
}

int main()
{
    fast();
    cout << fixed << setprecision(4);
	int h, m, a, b, c, d;
	cin >> h >> m >> a >> b >> c >> d;
	if (h >= 20)
	{
	    double x=ceil(double(a) / d);
	    x*=c;
	    x*=80;
	    x/=100;
		cout << fixed << x;
		return 0;
	}
	double first, second;
	first = ceil(double(a) / d);
	first *= c;
	second = (20 * 60) - (h * 60 + m);
	second *= b;
	second += a;
	second = ceil(second / d);
	second *= c;
	second = ceil(second*80.0) / 100;
	cout << fixed << min(first, second) << endl;
    return 0;
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <iostream>

using namespace std;

int main()
{
    int hh, mm;

    double ct = 0, ct2 = 0, f = 0, h, d, c, n;

    cin >> hh >> mm;
    cin >> h >> d >> c >> n;

    if( hh >= 20.0 )
    {
        ct = floor((h / n * (c * 0.8)));
        cout << ct;
    }
    else
    {
        ct = floor((h + ((20.0 - hh + mm ) * 60.0 )) / n * (c * 0.8));
        ct2 = floor((h / n * c));

        cout << min(ct, ct2);
    }

    return 0;
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <iostream>

using namespace std;

int main()
{
    int hh, mm;

    double ct = 0, ct2 = 0, f = 0, h, d, c, n;

    cin >> hh >> mm;
    cin >> h >> d >> c >> n;

    if( hh >= 20.0 )
    {
        ct = floor(h / n * (c * 0.8));
        cout << ct;
    }
    else
    {
        ct = floor((h + ((20.0 - hh + mm ) * 60.0 )) / n * (c * 0.8));
        ct2 = floor(h / n * c);

        cout << min(ct, ct2);
    }

    return 0;
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <iostream>

using namespace std;

int main()
{
    int hh, mm;

    double ct = 0, ct2 = 0, ct3 = 0, f = 0, h, d, c, n;

    cin >> hh >> mm;
    cin >> h >> d >> c >> n;

    if( hh >= 20.0 )
    {
        ct = (int)(h / n * (c * 0.8));
        cout << ct;
    }
    else
    {
        ct = (int)((h + ((20.0 - hh + mm ) * 60.0 )) / n * (c * 0.8));
        ct2 = (int)(h / n * c);

        cout << min(ct, ct2);
    }

    return 0;
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <iostream>

using namespace std;

int main()
{
    int hh, mm;

    double ct = 0, ct2 = 0, f = 0, h, d, c, n;

    cin >> hh >> mm;
    cin >> h >> d >> c >> n;

    if( hh >= 20.0 )
    {
        ct = ceil((h / n * (c * 0.8)));
        cout << ct;
    }
    else
    {
        ct = ceil((h + ((20.0 - hh + mm ) * 60.0 )) / n * (c * 0.8));
        ct2 = ceil((h / n * c));

        cout << min(ct, ct2);
    }

    return 0;
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int hh, mm;

    double ct = 0.0, ct2 = 0.0, f = 0.0, h, d, c, n;

    cin >> hh >> mm;
    cin >> h >> d >> c >> n;

    if( hh >= 20.0 )
    {
        ct = (h / n * (c * 0.8));
        cout << ct;
    }
    else
    {
        ct = (h + ((20.0 - hh + mm ) * 60.0 )) / n * (c * 0.8);
        ct2 = (h / n * c);

        cout << round(min(ct,ct2));
    }

    return 0;
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <iostream>

using namespace std;

int main()
{
    int hh, mm;

    double h, d, c, n;

    cin >> hh >> mm;
    cin >> h >> d >> c >> n;

    if( hh >= 20.0 )
    {
        int ct = h / n * (c * 0.8);
        cout << ct;
    }
    else
    {
        int ct = (h + ((20.0 - hh + mm ) * 60.0 )) / n * (c * 0.8);
        int ct2 = h / n * c;

        cout << min(ct, ct2);
    }

    return 0;
}


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

#define mod 1000000007
#define inf 1e9
typedef long long ll;
typedef long double ld;

typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<ll> vl;
typedef vector <ld> vd;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<pii> vii;
typedef vector<pll> vll;

#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>b;i--)
#define endl '\n'
#define nl cout<<endl;
#define vsort(v) sort(v.begin(),v.end())
#define w(a) while(a--)
#define all(v) v.begin(),v.end()
#define vuni(v) v.erase(unique(v.begin(),v.end()),v.end())
#define gl(a) getline(cin,a)
#define mp make_pair
#define pb push_back
#define pq priority_queue
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); }

int main(){
	int hh,mm;
	float tm=0,t,h,d,n,ans,c,ans1=LLONG_MAX;
	// string sh,sm;
	cin>>hh>>mm;
	// if(sh[0]=='0') sh.erase(sh.begin());
	// if(sm[0]=='0') sm.erase(sm.begin());
	// hh = atoi(sh);
	// mm = atoi(sm);
	tm = 1200-((60*hh)+mm);
	// cout<<tm;
	cin>>h>>d>>c>>n;
	if(tm <=0)
	{
		ans = (ceil(h/n))*c;
	}
	else{
		ans = (ceil(h/n))*c;
		ans1 = ((ceil((h+tm*d)/n))*c*0.8);
	}
	cout<<min(ans,ans1);

	return 0;
}


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

#define mod 1000000007
#define inf 1e9
typedef long long ll;
typedef long double ld;

typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<ll> vl;
typedef vector <ld> vd;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<pii> vii;
typedef vector<pll> vll;

#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>b;i--)
#define endl '\n'
#define nl cout<<endl;
#define vsort(v) sort(v.begin(),v.end())
#define w(a) while(a--)
#define all(v) v.begin(),v.end()
#define vuni(v) v.erase(unique(v.begin(),v.end()),v.end())
#define gl(a) getline(cin,a)
#define mp make_pair
#define pb push_back
#define pq priority_queue
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); }

int main(){
	int hh,mm;
	float tm=0,t,h,d,n,ans,c,ans1=LLONG_MAX;
	// string sh,sm;
	cin>>hh>>mm;
	// if(sh[0]=='0') sh.erase(sh.begin());
	// if(sm[0]=='0') sm.erase(sm.begin());
	// hh = atoi(sh);
	// mm = atoi(sm);
	tm = 1200-(60*hh)+mm;
	cin>>h>>d>>c>>n;
	if(tm <=0)
	{
		ans = (ceil(h/n))*c;
	}
	else{
		ans = (ceil(h/n))*c;
		ans1 = ((ceil((h+tm*d)/n))*c*0.8);
	}
	cout<<min(ans,ans1);

	return 0;
}


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

#define mod 1000000007
#define inf 1e9
typedef long long ll;
typedef long double ld;

typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<ll> vl;
typedef vector <ld> vd;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<pii> vii;
typedef vector<pll> vll;

#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>b;i--)
#define endl '\n'
#define nl cout<<endl;
#define vsort(v) sort(v.begin(),v.end())
#define w(a) while(a--)
#define all(v) v.begin(),v.end()
#define vuni(v) v.erase(unique(v.begin(),v.end()),v.end())
#define gl(a) getline(cin,a)
#define mp make_pair
#define pb push_back
#define pq priority_queue
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); }

int main(){
	int hh,mm;
	float tm=0,t,h,d,n,ans,c,ans1=LLONG_MAX;
	// string sh,sm;
	cin>>hh>>mm;
	// if(sh[0]=='0') sh.erase(sh.begin());
	// if(sm[0]=='0') sm.erase(sm.begin());
	// hh = atoi(sh);
	// mm = atoi(sm);
	tm = 1200-((60*hh)+mm);
	// cout<<tm;
	cin>>h>>d>>c>>n;
	if(tm <=0)
	{
		ans = (ceil(h/n))*c*0.8;
	}
	else{
		ans = (ceil(h/n))*c;
		ans1 = ((ceil((h+tm*d)/n))*c*0.8);
	}
	cout<<min(ans,ans1);
	return 0;
}


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

#define mod 1000000007
#define inf 1e9
typedef long long ll;
typedef long double ld;

typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<ll> vl;
typedef vector <ld> vd;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<pii> vii;
typedef vector<pll> vll;

#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>b;i--)
#define endl '\n'
#define nl cout<<endl;
#define vsort(v) sort(v.begin(),v.end())
#define w(a) while(a--)
#define all(v) v.begin(),v.end()
#define vuni(v) v.erase(unique(v.begin(),v.end()),v.end())
#define gl(a) getline(cin,a)
#define mp make_pair
#define pb push_back
#define pq priority_queue
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); }

int main(){
	float hh,mm;
	float tm=0,t,h,d,n,ans,c,ans1=LLONG_MAX;
	// string hh,mm;
	cin>>hh>>mm;
	// if(sh[0]=='0') sh.erase(sh.begin());
	// if(sm[0]=='0') sm.erase(sm.begin());
	// hh = atoi(sh);
	// mm = atoi(sm);
	tm = 1200-(60*hh)+mm;
	cin>>h>>d>>c>>n;
	if(tm <=0)
	{
		ans = (ceil(h/n))*c;
	}
	else{
		ans = (ceil(h/n))*c;
		ans1 = (((h+ceil((tm*d))/n))*c*0.8);
	}
	cout<<min(ans,ans1);

	return 0;
}


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

#define mod 1000000007
#define inf 1e9
typedef long long ll;
typedef long double ld;

typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<ll> vl;
typedef vector <ld> vd;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<pii> vii;
typedef vector<pll> vll;

#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>b;i--)
#define endl '\n'
#define nl cout<<endl;
#define vsort(v) sort(v.begin(),v.end())
#define w(a) while(a--)
#define all(v) v.begin(),v.end()
#define vuni(v) v.erase(unique(v.begin(),v.end()),v.end())
#define gl(a) getline(cin,a)
#define mp make_pair
#define pb push_back
#define pq priority_queue
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); }

int main(){
	int hh,mm;
	float tm=0,t,h,d,n,ans,c,ans1=LLONG_MAX;
	// string sh,sm;
	cin>>hh>>mm;
	// if(sh[0]=='0') sh.erase(sh.begin());
	// if(sm[0]=='0') sm.erase(sm.begin());
	// hh = atoi(sh);
	// mm = atoi(sm);
	tm = 1200-(60*hh)+mm;
	cin>>h>>d>>c>>n;
	if(tm <=0)
	{
		ans = (ceil(h/n))*c;
	}
	else{
		ans = (ceil(h/n))*c;
		ans1 = ((h+ceil((tm*d)/n))*c*0.8);
	}
	cout<<min(ans,ans1);

	return 0;
}


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

#define mod 1000000007
#define inf 1e9
typedef long long ll;
typedef long double ld;

typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<ll> vl;
typedef vector <ld> vd;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<pii> vii;
typedef vector<pll> vll;

#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>b;i--)
#define endl '\n'
#define nl cout<<endl;
#define vsort(v) sort(v.begin(),v.end())
#define w(a) while(a--)
#define all(v) v.begin(),v.end()
#define vuni(v) v.erase(unique(v.begin(),v.end()),v.end())
#define gl(a) getline(cin,a)
#define mp make_pair
#define pb push_back
#define pq priority_queue
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); }

int main(){
	int hh,mm;
	float tm=0,t,h,d,n,ans,c,ans1=LLONG_MAX;
	// string sh,sm;
	cin>>hh>>mm;
	// if(sh[0]=='0') sh.erase(sh.begin());
	// if(sm[0]=='0') sm.erase(sm.begin());
	// hh = atoi(sh);
	// mm = atoi(sm);
	tm = 1200-(60*hh)-mm;
	cout<<tm;
	cin>>h>>d>>c>>n;
	if(tm <=0)
	{
		ans = (ceil(h/n))*c;
	}
	else{
		ans = (ceil(h/n))*c;
		ans1 = ((ceil((h+tm*d)/n))*c*0.8);
	}
	cout<<min(ans,ans1);

	return 0;
}


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

#define mod 1000000007
#define inf 1e9
typedef long long ll;
typedef long double ld;

typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<ll> vl;
typedef vector <ld> vd;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<pii> vii;
typedef vector<pll> vll;

#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>b;i--)
#define endl '\n'
#define nl cout<<endl;
#define vsort(v) sort(v.begin(),v.end())
#define w(a) while(a--)
#define all(v) v.begin(),v.end()
#define vuni(v) v.erase(unique(v.begin(),v.end()),v.end())
#define gl(a) getline(cin,a)
#define mp make_pair
#define pb push_back
#define pq priority_queue
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); }

int main(){
	int hh,mm;
	float tm=0,t,h,d,n,ans,c,ans1=LLONG_MAX;
	// string hh,mm;
	cin>>hh>>mm;
	// if(sh[0]=='0') sh.erase(sh.begin());
	// if(sm[0]=='0') sm.erase(sm.begin());
	// hh = atoi(sh);
	// mm = atoi(sm);
	tm = 1200-(60*hh)+mm;
	cin>>h>>d>>c>>n;
	if(tm <=0)
	{
		ans = (h/n)*c;
	}
	else{
		ans = (ceil(h/n))*c;
		ans1 = (((h+ceil((tm*d))/n))*c*0.8);
	}
	cout<<min(ans,ans1);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int h,m,H,d,c,n;
double res,temp;
int main() {
    freopen("pA.inp","r",stdin);
    cin>>h>>m,m=h*60+m;
    cin>>H>>d>>c>>n,res=(double)ceil((double)H/n)*c;
    temp=(double)ceil((double)((1200-m)*d+H)/n)*c*0.8;
    if (temp<0) res=res*.8;
    res=min(res,temp);
    printf("%.4f",res);
}


#include<bits/stdc++.h>
using namespace std;
int h,m,H,d,c,n;
double res,temp;
int main() {
    //freopen("pA.inp","r",stdin);
    cin>>h>>m,m=h*60+m;
    cin>>H>>d>>c>>n,res=(double)ceil((double)H/n)*c;
    temp=(double)ceil((double)((1200-m)*d+H)/n)*c*0.8;
    if (1200-m<0) res=res*.8;
    res=min(res,temp);
    printf("%.4f",res);
}


#include<bits/stdc++.h>
using namespace std;
int h,m,H,d,c,n;
double res;
int main() {
    freopen("pA.inp","r",stdin);
    cin>>h>>m,m=h*60+m;
    cin>>H>>d>>c>>n,res=(double)(H*c/n);
    res=min(res,(double)(((1200-m)*d+H)*c/n)*0.8);
    printf("%.4f",res);
}


#include<bits/stdc++.h>
using namespace std;
int h,m,H,d,c,n;
double res;
int main() {
    //freopen("pA.inp","r",stdin);
    cin>>h>>m,m=h*60+m;
    cin>>H>>d>>c>>n,res=(double)(H*c/n);
    res=min(res,(double)(((1200-m)*d+H)*c/n)*0.8);
    printf("%.4f",res);
}


#include<bits/stdc++.h>
using namespace std;
int h,m,H,d,c,n;
double res,temp;
int main() {
    //freopen("pA.inp","r",stdin);
    cin>>h>>m,m=h*60+m;
    cin>>H>>d>>c>>n,res=(double)ceil((double)H/n)*c;
    temp=(double)ceil((double)((1200-m)*d+H)/n)*c*0.8,res=min(res,temp);
    printf("%.4f",res);
}


#include<bits/stdc++.h>
using namespace std;
int h,m,H,d,c,n;
double res,temp;
int main() {
    freopen("pA.inp","r",stdin);
    cin>>h>>m,m=h*60+m;
    cin>>H>>d>>c>>n,res=ceil((double)H/n)*c;
    temp=ceil((double)((1200-m)*d+H)/n)*c*0.8,res=min(res,temp);
    printf("%.4f",res);
}


#include<bits/stdc++.h>
using namespace std;
int h,m,H,d,c,n;
double res,temp;
int main() {
    //freopen("pA.inp","r",stdin);
    cin>>h>>m,m=h*60+m;
    cin>>H>>d>>c>>n,res=ceil((double)H/n)*c;
    temp=ceil(((1200-m)*d+H)/n)*c*0.8,res=min(res,temp);
    printf("%.4f",res);
}


#include<bits/stdc++.h>
using namespace std;
int h,m,H,d,c,n;
double res,temp;
int main() {
    //freopen("pA.inp","r",stdin);
    cin>>h>>m,m=h*60+m;
    cin>>H>>d>>c>>n,res=(double)ceil((double)H/n)*c;
    temp=(double)ceil((double)((1200-m)*d+H)/n)*c*0.8;
    if (temp<0) res=res*.8;
    res=min(res,temp);
    printf("%.4f",res);
}


#include<bits/stdc++.h>
using namespace std;
int h,m,H,d,c,n;
double res,temp;
int main() {
    //freopen("pA.inp","r",stdin);
    cin>>h>>m,m=h*60+m;
    cin>>H>>d>>c>>n,res=(double)ceil((double)H/n)*c;
    temp=(double)ceil((double)(abs(1200-m)*d+H)/n)*c*0.8;
    if (1200-m<=0) res=res*.8;
    res=min(res,temp);
    printf("%.4f",res);
}


#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
    int o, m, h, d, c, n, t;
    double s;
    cin >> o >> m;
    cin >> h >> d >> c >> n;
    cout << setprecision( 4 ) << fixed;
    t = 20 * 60 - o * 60 - m;
    if( t < 0 )
    {
        s = h * c * 4 / 5 / n;
        if( h % n != 0 )
            s = ( h / n + 1 ) * c * 4 / 5;
        cout << setprecision( 4 ) << fixed << s;
        return 0;
    }
    if( ( h + t * d ) * c * 4 / 5 / n < h * c / n )
    {
        s = ( h + t * d ) * c * 4 / 5 / n;
        if( ( h + t * d ) % n != 0 )
            s = ( ( h + t * d ) / n + 1 ) * c * 4 / 5;
        if( s < c )
            s = c;
        cout << setprecision( 4 ) << fixed << s;
    }
    else
    {
        s = h * c / n;
        if( h % n != 0 )
            s = ( h / n + 1 ) * c;
        if( s < c )
            s = c;
        cout << setprecision( 4 ) << fixed << s;
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
    int o, m, h, d, c, n, t;
    double s1, s2;
    cin >> o >> m;
    cin >> h >> d >> c >> n;
    cout << setprecision( 4 ) << fixed;
    t = 20 * 60 - o * 60 - m;
    if( t < 0 )
    {
        s1 = h * c * 4 / 5 / n;
        if( h % n != 0 )
            s1 = (double)( h / n + 1 ) * c * 4 / 5;
        //cout << " > 20 " << endl;
        cout << setprecision( 4 ) << fixed << s1;
        return 0;
    }
    s1 = ( h + t * d ) * c * 4 / 5 / n;
    if( ( h + t * d ) % n != 0 )
        s1 = (double)( ( h + t * d ) / n + 1 ) * c * 4 / 5;
    if( s1 < c )
        s1 = c;
    s2 = h * c / n;
    if( h % n != 0 )
        s2 = (double)( h / n + 1 ) * c;
    if( s2 < c )
        s2 = c;
    if( s1 < s2 )
    {
        //cout << " = 20 " << endl;
        cout << setprecision( 4 ) << fixed << s1;
    }
    else
    {
        //cout << " < 20 " << endl;
        cout << setprecision( 4 ) << fixed << s2;
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
    int o, m, h, d, c, n, t;
    double s;
    cin >> o >> m;
    cin >> h >> d >> c >> n;
    cout << setprecision( 4 ) << fixed;
    t = 20 * 60 - o * 60 - m;
    if( t < 0 )
    {
        s = h * c * 4 / 5 / n;
        if( h % n != 0 )
            s = (double)( h / n + 1 ) * c * 4 / 5;
        cout << setprecision( 4 ) << fixed << s;
        return 0;
    }
    if( ( h + t * d ) * c * 4 / 5 / n < h * c / n )
    {
        s = ( h + t * d ) * c * 4 / 5 / n;
        if( ( h + t * d ) % n != 0 )
            s = (double)( ( h + t * d ) / n + 1 ) * c * 4 / 5;
        if( s < c )
            s = c;
        cout << setprecision( 4 ) << fixed << s;
    }
    else
    {
        s = h * c / n;
        if( h % n != 0 )
            s = (double)( h / n + 1 ) * c;
        if( s < c )
            s = c;
        cout << setprecision( 4 ) << fixed << s;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int o, m, h, d, c, n, t;
    float s;
    cin >> o >> m;
    cin >> h >> d >> c >> n;
    t = 20 * 60 - o * 60 - m;
    if( ( h + t * d ) * c * 4 / 5 / n < h * c / n )
    {
        if( ( h + t * d ) * c * 4 % ( 5 * n ) != 0 )
            h = h + 1;
        s = ( h + t * d ) * c * 4 / 5 / n;
        cout << s;
    }
    else
    {
        if( h * c % n != 0 )
            h = h + 1;
        s = h * c / n;
        cout << s;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int o, m, h, d, c, n, t;
    cin >> o >> m;
    cin >> h >> d >> c >> n;
    t = 20 * 60 - o * 60 - m;
    if( ( h + t * d ) * c * 4 / 5 / n < h * c / n )
    {
        if( ( h + t * d ) * c * 4 % ( 5 * n ) != 0 )
            h = h + 1;
        cout << ( h + t * d ) * c * 4 / 5 / n;
    }
    else
    {
        if( h * c % n != 0 )
            h = h + 1;
        cout << h * c / n;
    }
    return 0;
}


#include <bits/stdc++.h>

#define int long long
#define ld long double
#define print(a) for(auto it = (a).begin(); it != (a).end(); it++) cout << *it << " "; cout << endl;
#define pii pair<int, int>

using namespace std;

signed main() {
    int hh, mm, h, d, s, n ;
    cin >> hh >> mm >> h >> d >> s >> n;
    int time = hh * 60 + mm;
    int twenty = 60 * 20;
    int delta = 0;
    if(time > twenty) {
        delta = 0;
    } else if(time <= twenty) {
        delta = twenty - time;
    }
    int new_h = delta * d;

    int needed_old = ceil((ld)h / (ld)n) * s;

    int needed_new = ceil(((ld)h + (ld)new_h) / (ld)n) * s;

    cout << fixed << setprecision(10) << min((ld)needed_new * 0.8l, (ld)needed_old);

}


#include <bits/stdc++.h>

#define int long long
#define ld long double
#define print(a) for(auto it = (a).begin(); it != (a).end(); it++) cout << *it << " "; cout << endl;
#define pii pair<int, int>

using namespace std;

signed main() {
    int hh, mm, h, d, s, n ;
    cin >> hh >> mm >> h >> d >> s >> n;
    int time = hh * 60 + mm;
    int twenty = 60 * 20;
    int delta;
    if(time > twenty) {
        delta = 1440 - time + twenty;
    } else {
        delta = twenty - time;
    }
    int new_h = delta * d;

    int needed_old = ceil((ld)h / (ld)n) * s;

    int needed_new = ceil(((ld)h + (ld)new_h) / (ld)n) * s;

    cout << fixed << setprecision(10) << min((ld)needed_new * 0.8l, (ld)needed_old);

}


#include <bits/stdc++.h>

#define int long long
#define ld long double
#define print(a) for(auto it = (a).begin(); it != (a).end(); it++) cout << *it << " "; cout << endl;
#define pii pair<int, int>

using namespace std;

signed main() {
    ld hh, mm, h, d, s, n ;
    cin >> hh >> mm >> h >> d >> s >> n;
    ld time = hh * 60 + mm;
    ld twenty = 60 * 20;
    ld delta;
    if(time >= twenty) {
        delta = 1440 - time + twenty;
    } else {
        delta = twenty - time;
    }
    ld neew_h = delta * d;

    ld needed_old = ceil(h / n);
    needed_old = needed_old * s;

    ld needed_new = ceil((h + neew_h) / n);
    needed_new = needed_new * s * 0.8;

    //cout << needed_new << " " << needed_old;

    cout << fixed << setprecision(10) << min(needed_new, needed_old);

}


#include <bits/stdc++.h>

#define int long long
#define ld long double
#define print(a) for(auto it = (a).begin(); it != (a).end(); it++) cout << *it << " "; cout << endl;
#define pii pair<int, int>

using namespace std;

signed main() {
    ld hh, mm, h, d, s, n ;
    cin >> hh >> mm >> h >> d >> s >> n;
    ld time = hh * 60 + mm;
    ld twenty = 60 * 20;
    ld delta;
    if(time > twenty) {
        delta = 1440 - time + twenty;
    } else {
        delta = twenty - time;
    }
    ld neew_h = delta * d;

    ld needed_old = ceil(h / n);
    needed_old = needed_old * s;

    ld needed_new = ceil((h + neew_h) / n);
    needed_new = needed_new * s * 0.8;

    //cout << needed_new << " " << needed_old;

    cout << fixed << setprecision(10) << min(needed_new, needed_old);

}


#include <bits/stdc++.h>

#define int long long
#define ld long double
#define print(a) for(auto it = (a).begin(); it != (a).end(); it++) cout << *it << " "; cout << endl;
#define pii pair<int, int>

using namespace std;

signed main() {
    ld hh, mm, h, d, s, n ;
    cin >> hh >> mm >> h >> d >> s >> n;
    ld time = hh * 60 + mm;
    ld twenty = 60 * 20;
    ld delta;
    if(time >= twenty) {
        delta = 1440 - time + twenty;
    } else {
        delta = twenty - time;
    }
    ld neew_h = delta * d;

    ld needed_old = ceil(h / n);
    needed_old = needed_old * s;

    ld needed_new = ceil((h + neew_h) / n);
    needed_new = needed_new * s * 0.8;

    //cout << needed_new << " " << needed_old;

    cout << min(needed_new, needed_old);

}


#include <bits/stdc++.h>

#define int __int64
#define ld long double
#define print(a) for(auto it = (a).begin(); it != (a).end(); it++) cout << *it << " "; cout << endl;
#define pii pair<int, int>

using namespace std;

signed main() {
    int hh, mm, h, d, s, n ;
    cin >> hh >> mm >> h >> d >> s >> n;
    int time = hh * 60 + mm;
    int twenty = 60 * 20;
    int delta = 0;
    if(time > twenty) {
        delta = 0;
    } else if(time <= twenty) {
        delta = twenty - time;
    }
    int new_h = delta * d;

    int needed_old = ceil((ld)h / (ld)n) * s;

    int needed_new = ceil(((ld)h + (ld)new_h) / (ld)n) * s;

    cout << fixed << setprecision(10) << min((ld)needed_new * 0.8l, (ld)needed_old);

}


//Don't despair and never lose hope ^_^
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<functional>
#include <bitset>
#include<algorithm>
#include<fstream>
#include<string>
#include<stdio.h>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265
#define ebs 1e-8
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL);

	ll  H, N;
	double C, m, h, D, ans1, ans2;
	cin >> h >> m >> H >> D >> C >> N;
	if (h >= 20){
		ans1 = ((H / N) + (H%N != 0))*(C - ((C * 20) / 100.0));
		return cout << fixed << setprecision(4) << ans1, 0;
	}
	m = (m == 0) ? (20 - h) * 60 : (20 - h - 1) * 60 + (60 - m);
	ans1 = ((H / N) + (H%N != 0))*C;
	H += D*m;
	cout << 'y' << H<< endl;
	ans2 = ((H / N) + (H%N != 0))*(C - ((C * 20) / 100.0));
	cout << fixed << setprecision(4) << min(ans1, ans2);

	return 0;
}


//Don't despair and never lose hope ^_^
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<functional>
#include <bitset>
#include<algorithm>
#include<fstream>
#include<string>
#include<stdio.h>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265
#define ebs 1e-8
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL);

	ll h, m, H, D, C, N;
	cin >> h >> m >> H >> D >> C >> N;
	double ans1, ans2;
	m = (m == 0) ? m = (20 - h) * 60 : (20 - (h - 1)) * 60 + (60 - m);
	ans1 = (((H / (N)) + (H%N != 0)))*C;
	//cout << (((H /N) + (H%N != 0))) <<endl;
	H += D*m;
	ans2 = ((H /N) + (H%N != 0))*(C-((C * 20) / 100.0));
	cout << fixed << setprecision(4) << min(ans1, ans2);

	return 0;
}


#include<iostream>
#include<fstream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<bitset>
#include<map>
#define mod1 100007
#define mod2 100021
#define fin cin
#define fout cout
using namespace std;
//ifstream fin("date.in");
//ofstream fout("date.out");
int n,i,a,b[111][2],k,M1,M2,rez,aux,nr,ok,sol,j;
map<pair<int,int>,int> m;
int main()
{
    fin>>n;
    for(i=1;i<=n;i++)
    {
        fin>>a;
        b[i][1]=a>>15;
        b[i][0]=(a&((1<<15)-1));
    }
    for(k=0;k<(1<<15);k++)
    {
        M1=0;M2=0;
        for(i=1;i<=n;i++)
        {
            aux=b[i][1]^k;nr=0;
            for(j=1;j<(1<<15);j<<=1) if(aux&j) nr++;
            M1=(M1*15+nr)%mod1;
            M2=(M2*15+nr)%mod2;
        }
        m[make_pair(M1,M2)]=k+1;
    }
    for(rez=0;rez<30;rez++)
    {
        for(k=0;k<(1<<15);k++)
        {
            M1=0;M2=0;ok=0;
            for(i=1;i<=n;i++)
            {
                aux=b[i][0]^k;nr=0;
                for(j=1;j<(1<<15);j<<=1) if(aux&j) nr++;
                if(rez<nr||rez-nr>15) {ok=1;break;}
                M1=(M1*15+rez-nr)%mod1;
                M2=(M2*15+rez-nr)%mod2;
            }
            if(ok==1) continue;
            sol=m[make_pair(M1,M2)];
            if(sol!=0){sol--;fout<<(sol<<15)+k;return 0;}
        }
    }
    fout<<-1;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <vector>
#include <unordered_set>
#include <unordered_map>

#define pb push_back
#define For(i, n) for (int i=0;i<n;++i)
using namespace std;
typedef unsigned long long ll;

struct Hash {
  size_t operator()(const vector<int> &s) const noexcept
  {
    ll x = 378940648;
    for (int i=0;i<s.size();i++) x ^= 18946412363+(s[i] << (i*2 % 63));
    return x;
  }
};

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int half = 12;
  int arr[n][1<<half];
  int on=(1<<30)-1;
  int off=(1<<30)-1;
  for (int i=0;i<n;i++) {
    cin >> arr[i][0];
    on &= arr[i][0];
    off &= !arr[i][0];
  }
  for (int i=1;i<(1<<half);i++) {
    for (int j=0;j<n;j++) {
      arr[j][i] = arr[j][0] ^ i;
    }
  }
  vector<pair<vector<int>, int>> v;
  v.push_back(make_pair(vector<int>(n, 0), 0));
  v.reserve(1<<(30-half));
  for (int i=half;i<31;i++) {
    if (on & (1 << i) || off & (1 << i)) continue;
    int x = v.size();
    for (int t=0;t<x;t++) {
      v.push_back(v[t]);
      for (int j=0;j<n;j++) {
        if (arr[j][0] & (1 << i)) --(v[x+t].first[j]);
        else ++(v[x+t].first[j]);
      }
      v[x+t].second |= (1 << i);
    }
  }
  unordered_map<vector<int>, int, Hash> us;
  for (int i=0;i<v.size();i++) {
    us[v[i].first] = v[i].second;
  }
  for (int i=0;i<(1<<half);i++) {
    vector<int> vec;
    vec.reserve(100);
    For (j, n) {
      vec.push_back(0);
      For (k, 30) {
        if (arr[j][i] & 1 << k) vec[j]--;
      }
    }
    For (k, 30) {
      For (j, n) vec[j]++;
      if (us.count(vec) == 1) {
        cout << (i | us[vec]) << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <vector>
#include <unordered_set>
#include <unordered_map>

#define pb push_back
#define For(i, n) for (int i=0;i<n;++i)
using namespace std;
typedef unsigned long long ll;

struct Hash {
  size_t operator()(const vector<int> &s) const noexcept
  {
    ll x = 0;
    for (int i=0;i<s.size();i++) x ^= (s[i] << (i*2 % 63));
    return x;
  }
};

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int half = 12;
  int arr[n][1<<half];
  int on=(1<<30)-1;
  int off=(1<<30)-1;
  for (int i=0;i<n;i++) {
    cin >> arr[i][0];
    on &= arr[i][0];
    off &= !arr[i][0];
  }
  for (int i=1;i<(1<<half);i++) {
    for (int j=0;j<n;j++) {
      arr[j][i] = arr[j][0] ^ i;
    }
  }
  vector<pair<vector<int>, int>> v;
  v.push_back(make_pair(vector<int>(n, 0), 0));
  v.reserve(1<<(30-half));
  for (int i=half;i<31;i++) {
    if (on & (1 << i) || off & (1 << i)) continue;
    int x = v.size();
    for (int t=0;t<x;t++) {
      v.push_back(v[t]);
      for (int j=0;j<n;j++) {
        if (arr[j][0] & (1 << i)) --(v[x+t].first[j]);
        else ++(v[x+t].first[j]);
      }
      v[x+t].second |= (1 << i);
    }
  }
  unordered_map<vector<int>, int, Hash> us;
  for (int i=0;i<v.size();i++) {
    us[v[i].first] = v[i].second;
  }
  for (int i=0;i<(1<<half);i++) {
    vector<int> vec;
    vec.reserve(100);
    For (j, n) {
      vec.push_back(0);
      For (k, 30) {
        if (arr[j][i] & 1 << k) vec[j]--;
      }
    }
    For (k, 31) {
      For (j, n) vec[j]++;
      if (us.count(vec) == 1) {
        cout << (i | us[vec]) << endl;
        return 0;
      }
    }
    For (j, n) vec[j]-=31;
    For (k, 30) {
      For (j, n) vec[j]--;
      if (us.count(vec) == 1) {
        cout << (i | us[vec]) << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}


#include <map>
#include <bitset>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 105
#define LL long long
#define Pa pair<LL, LL>
#define Mod 998244353
#define Int register int
#define INF 1000000000000000000ll
using namespace std;
inline LL Min(LL x,LL y)
{
	if (x < y)
		return x;
	return y;
}
inline LL Max(LL x,LL y)
{
	if (x > y)
		return x;
	return y;
}
inline void read(LL &x)
{
	x = 0;
	LL f = 1;
	char s = getchar();
	while (s < '0' || s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
inline void Swap(LL &x,LL &y)
{
	LL Temp = x;
	x = y;
	y = Temp;
}
LL a[MAXN], n, Ans;
vector<LL> Fren;
map<vector<LL>, LL> Map;
void Dfs(LL Num,LL Get,LL Type)
{
	if (Num == 16)
	{
		Fren.clear();
		for (Int i = 1; i <= n; ++ i)
			if (! Type)
				Fren.push_back(__builtin_popcount((Get ^ a[i]) % (1ll << 15)));
			else Fren.push_back(__builtin_popcount(Get ^ (a[i] >> 15)));
		for (Int i = 1; i < n; ++ i)
			Fren[i - 1] = Fren[i - 1] - Fren[i];
		Fren.pop_back();
		if (! Type)
		{
			if (! Map[Fren])
				Map[Fren] = Get;
		}
		else
		{
			if ( Map[Fren] )
				Ans = Map[Fren] | (Get << 15); // Map[Fren] ^ x = (Get << 15)
		}
		return ;
	}
	Dfs(Num + 1, Get, Type);
	Dfs(Num + 1, Get + (1ll << Num - 1), Type);
}
int main()
{
	read( n );
	for (Int i = 1; i <= n; ++ i)
		read( a[i] );
	Dfs(1, 0, 0);
	Dfs(1, 0, 1);
	printf("%lld", Ans);
	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

	int n;scanf("%d",&n);
	ll a[maxn],b[maxn];
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);

	map<vector<int>,int> mp;
	vector<int> v;
	for(int i=0;i<(1<<15);i++){
		v.clear();
		for(int j=0;j<n;j++){
			v.pb(__builtin_popcount(i^(a[j]&((1<<15)-1))));
		}
		for(int j=0;j<n-1;j++){
			v[j]=v[j+1]-v[j];
		}
		v.pop_back();
		if(mp[v]==0) mp[v]=i;
	}

	for(int i=0;i<(1<<15);i++){
		v.clear();
		for(int j=0;j<n;j++){
			v.pb(__builtin_popcount(i^(a[j]>>15)));
		}
		for(int j=0;j<n-1;j++){
			v[j]=-v[j+1]+v[j];
		}
		v.pop_back();
		if(mp[v]){
            printf("%d",mp[v]+(i<<15));
			return 0;
		}
	}
	 printf("-1\n");
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=110;
int n,k1=(1<<15)-1,k2=(1<<30)-1-k1,a[N];
map<vector<int>,int>mp;
int solve(int x){
	int cnt=0;
	while(x) x&=(x-1),cnt++;
	return cnt;
}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=0;i<(1<<15);i++){
		vector<int>v;
		int tmp=solve((a[1]&k1)^i);
		for(int j=2;j<=n;j++)
			v.push_back(tmp-solve((a[j]&k1)^i));
		mp[v]=i;
	}
	for(int i=0;i<(1<<15);i++){
		vector<int>v;
		int tmp=solve((a[1]&k2)^i);
		for(int j=2;j<=n;j++)
			v.push_back(tmp-solve((a[j]&k2)^i));
		if(mp.count(v)) printf("%lld\n",(i<<15)+mp[v]),exit(0);
	}
	puts("-1");
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=110;
int n,k1=(1<<15)-1,k2=(1<<30)-1-k1,a[N];
map<vector<int>,int>mp;
int solve(int x){
	int cnt=0;
	while(x) x&=(x-1),cnt++;
	return cnt;
}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=0;i<(1<<15);i++){
		vector<int>v;
		int tmp=solve((a[1]&k1)^i);
		for(int j=2;j<=n;j++)
			v.push_back(tmp-solve((a[j]&k1)^i));
		mp[v]=i;
	}
	for(int i=0;i<(1<<15);i++){
		vector<int>v;
		int tmp=solve((a[1]&k2)^i);
		for(int j=2;j<=n;j++)
			v.push_back(solve((a[j]&k2)^i)-tmp);
		if(mp.count(v)) printf("%lld\n",(i<<15)+mp[v]),exit(0);
	}
	puts("-1");
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=110;
int n,m=(1<<15)-1,a[N];
map<vector<int>,int>mp;
int solve(int x){
	int cnt=0;
	while(x) x&=(x-1),cnt++;
	return cnt;
}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=0;i<(1<<15);i++){
		vector<int>v;
		int tmp=solve((a[1]&m)^i);
		for(int j=2;j<=n;j++)
			v.push_back(tmp-solve((a[j]&m)^i));
		mp[v]=i;
	}
	for(int i=0;i<(1<<15);i++){
		vector<int>v;
		int tmp=solve((a[1]>>15)^i);
		for(int j=2;j<=n;j++)
			v.push_back(solve((a[j]>>15)^i)-tmp);
		if(mp.count(v)) printf("%lld\n",(i<<15)+mp[v]),exit(0);
	}
	puts("-1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0;char ch;
	while(!isdigit(ch=getchar()));x=ch-48;
	while(isdigit(ch=getchar()))x=x*10+ch-48;
	return x;
}
const int MAXN=105;
#define count(x) __builtin_popcount(x)
int n,ans=-1,a[MAXN];
vector<int>g;
map<vector<int>,int>mp;
inline void dfs1(int x,int y)
{
	if(x==15)
	{
		g.clear();
		for(int i=1;i<n;i++)
			g.push_back(count(a[i+1]^y)&(1<<15)-count((a[i]^y)&(1<<15)));
		mp[g]=y;
		return;
	}
	dfs1(x+1,y),dfs1(x+1,y|(1<<x));
}
inline void dfs2(int x,int y)
{
	if(x==15)
	{
		g.clear();
		for(int i=1;i<n;i++)
			g.push_back(count((a[i]>>15)^y)-count((a[i+1]>>15)^y));
		if(mp[g])ans=mp[g]|(y<<15);
		return;
	}
	dfs2(x+1,y),dfs2(x+1,y|(1<<x));
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	dfs1(0,0),dfs2(0,0);
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0;char ch;
	while(!isdigit(ch=getchar()));x=ch-48;
	while(isdigit(ch=getchar()))x=x*10+ch-48;
	return x;
}
const int MAXN=105;
#define count(x) __builtin_popcount(x)
int n,ans=-1,a[MAXN];
vector<int>g;
map<vector<int>,int>mp;
inline void dfs1(int x,int y)
{
	if(x==15)
	{
		g.clear();
		for(int i=1;i<n;i++)
			g.push_back(count(a[i+1]^y)%(1<<15)-count((a[i]^y)%(1<<15)));
		mp[g]=y;
		return;
	}
	dfs1(x+1,y),dfs1(x+1,y|(1<<x));
}
inline void dfs2(int x,int y)
{
	if(x==15)
	{
		g.clear();
		for(int i=1;i<n;i++)
			g.push_back(count((a[i]>>15)^y)-count((a[i+1]>>15)^y));
		if(mp[g])ans=mp[g]|(y<<15);
		return;
	}
	dfs2(x+1,y),dfs2(x+1,y|(1<<x));
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	dfs1(0,0),dfs2(0,0);
	printf("%d\n",ans);
	return 0;
}