728x90
#include <iostream>
#include <algorithm>
using namespace std;
int oper[4];
int arr[11];
int n;
int t=0;
int maxcalc,mincalc;
void findminmax(int totaloper, int res, int plus, int minus, int mult, int divide)
{
if(plus==0 && minus==0 && divide==0 && mult==0 && totaloper!=n-1){return;}
if(totaloper==n-1){
if(t==0){maxcalc =res; mincalc=res;}
if(res>maxcalc){maxcalc=res;}
else if(res<mincalc){mincalc=res;}
t++;
return;
}
if(plus>0){
findminmax(totaloper+1,res+arr[totaloper+1],plus-1,minus,mult,divide);
}
if(minus>0){
findminmax(totaloper+1,res-arr[totaloper+1],plus,minus-1,mult,divide);
}
if(mult>0){
findminmax(totaloper+1,res*arr[totaloper+1],plus,minus,mult-1,divide);
}
if(divide>0){
findminmax(totaloper+1,res/arr[totaloper+1],plus,minus,mult,divide-1);
}
return;
}
int main()
{
cin>>n;
for(int i=0; i<n; i++){cin>>arr[i];}
for(int i=0; i<4; i++){
cin>>oper[i];
}
findminmax(0,arr[0],oper[0],oper[1],oper[2],oper[3]);
cout<<maxcalc<<"\n";
cout<<mincalc<<"\n";
}