#include<bits/stdc++.h>

#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back

/** Dateloper */

using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int b,p,f;
        int h,c;
        cin>>b>>p>>f>>h>>c;
        if(b>=p*2+f*2)
            cout<<p*h+f*c<<endl;
        else
        {
            if(c>=h)
            {
                cout<<min(b/2,f)*c+min((b-min(b/2,f)*2)/2,p)*h<<endl;
            }
            else
                cout<<min(b/2,p)*h+min((b-min(b/2,p)*2)/2,f)*c<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back

/** Dateloper */

using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int b,p,f;
        int h,c;
        cin>>b>>p>>f>>h>>c;
        if(b>=p*2+f*2)
            cout<<p*5+f*c<<endl;
        else
        {
            if(h>=c)
            {
                int tmp=min(b/2,p)*2;
                cout<<tmp*h+min((b-tmp)/2,f)*c;
            }
            else
            {
                int tmp=min(b/2,f)*2;
                cout<<tmp=tmp*c+min((b-tmp)/2,p)*h;

            }
        }
    }
    return 0;
}


	if (len>=10){
		b#include<iostream>
using namespace std;
int main (){
	int a,b,p,f,hp,hf,c=0,d,e=0;
	cin>>a;
	for (int i =1;i<=a;i++){
		cin>>b>>p>>f>>hp>>hf;
		if(hf>= hp){
			if(f>= b/2){
				d = b/2;
			}else d =f;
			c = hf*d;
			b -= 2*d;
			if(b>=2){
				e= min(b/2,p);
			}else e=0
			c = c + hp*e;
		}else if (hp>=hf){
      if( p>= b/2){
				d = b/2;
			}else d =p;
			c = hp*d;
			b -= 2*d;
			if(b>=2){
				e= min(b/2,f);
			}
			c = c + hf*e;
		}
    cout<<c<<"\n";
	}
}


#include<iostream>
using namespace std;
int main (){
	int a,b,p,f,hp,hf,c=0,d,e=0;
	cin>>a;
	for (int i =1;i<=a;i++){
		cin>>b>>p>>f>>hp>>hf;
		if(hf>= hp){
			if(f>= b/2){
				d = b/2;
			}else d =f;
			c = hf*d;
			b -= 2*d;
			if(b>=2){
				e= min(b/2,p);
			}else e=0;
			c = c + hp*e;
		}else if (hp>=hf){
      if( p>= b/2){
				d = b/2;
			}else d =p;
			c = hp*d;
			b -= 2*d;
			if(b>=2){
				e= min(b/2,f);
			}else e=0;
			c = c + hf*e;
		}
    cout<<c<<"\n";
	}
}
// https://codeforces.com/problemset/problem/1207/A


#include<iostream>
using namespace std;
int main (){
	int a,b,p,f,hp,hf,c=0,d,e=0;
	cin>>a;
	for (int i =1;i<=a;i++){
		cin>>b>>p>>f>>hp>>hf;
		if(hf>= hp){
			if(f>= b/2){
				d = b/2;
			}else d =f;
			c = hf*d;
			b -= 2*d;
			if(b>=2){
				e= min(b/2,p);
			}else e=0;
			c = c + hp*e;
		}else if (hp>=hf){
      if( p>= b/2){
				d = b/2;
			}else d =p;
			c = hp*d;
			b -= 2*d;
			if(b>=2){
				e= min(b/2,f);
			}
			c = c + hf*e;
		}
    cout<<c<<"\n";
	}
}
// https://codeforces.com/problemset/problem/1207/A


#include<iostream>
using namespace std;
int main (){
	int a,b,p,f,hp,hf,c=0,d,e;
	cin>>a;
	for (int i =1;i<=a;i++){
		cin>>b>>p>>f>>hp>>hf;
		while(b>=2){
		if(hf>= hp){
			if( f>= b/2){
				d = b/2;
			}else d =f;
			c = hf*d;
			b -= 2*d;
			if(b>=2){
				e= min(b/2,p);
			}
			c = c + hp*e;
		}else if (hp>=hf){
				if( p>= b/2){
				d = b/2;
			}else d =p;
			c = hp*d;
			b -= 2*d;
			if(b>=2){
				e= min(b/2,f);
			}
			c = c + hf*e;
		}cout<<c<<"\n";
	}
	}
}


#include<iostream>
using namespace std;
int main (){
	int a,b,p,f,hp,hf,c=0,d,e;
	cin>>a;
	for (int i =1;i<=a;i++){
		cin>>b>>p>>f>>hp>>hf;
		if(b<2){
			c=0;
		}else
		if(hf>= hp){
			if( f>= b/2){
				d = b/2;
			}else d =f;
			c = hf*d;
			b -= 2*d;
			if(b>=2){
				e= min(b/2,p);
			}
			c = c + hp*e;
		}else if (hp>=hf){
				if( p>= b/2){
				d = b/2;
			}else d =p;
			c = hp*d;
			b -= 2*d;
			if(b>=2){
				e= min(b/2,f);
			}
			c = c + hf*e;
		}cout<<c<<"\n";
	}
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int q; cin >> q;
    while (q--)
    {
        int n, p, f, h, c;
        cin >> n >> p >> f >> h >> c;
        if (c > h)
        {
            int fish = min(n/2, f);
            int beef = min((n-f)/2, p);
        }
        else
        {
            int beef = min(n/2, p)
            int fish = min((n-h)/2, f);
        }
        cout << fish*c + beef*h << endl;
    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int q; cin >> q;
    while (q--)
    {
        int n, p, f, h, c;
        cin >> n >> p >> f >> h >> c;
        int chick, beef;
        if (c > h)
        {
            chick = min(n/2, f);
            beef = min((n-2*chick)/2, p);
        }
        else
        {
            beef = min(n/2, p);
            chick = min((n-2*beef)/2, f);
        }
        cout << chick*c + beef*h << endl;
    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int q; cin >> q;
    while (q--)
    {
        int n, p, f, h, c;
        cin >> n >> p >> f >> h >> c;
        int fish, beef;
        if (c > h)
        {
            fish = min(n/2, f);
            beef = min((n-fish)/2, p);
        }
        else
        {
            beef = min(n/2, p);
            fish = min((n-beef)/2, f);
        }
        cout << fish*c + beef*h << endl;
    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int q; cin >> q;
    while (q--)
    {
        int n, p, f, h, c;
        cin >> n >> p >> f >> h >> c;
        int fish, beef;
        if (c > h)
        {
            fish = min(n/2, f);
            beef = min((n-f)/2, p);
        }
        else
        {
            beef = min(n/2, p);
            fish = min((n-h)/2, f);
        }
        cout << fish*c + beef*h << endl;
    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int q; cin >> q;
    while (q--)
    {
        int n, p, f, h, c;
        cin >> n >> p >> f >> h >> c;
        if (c > h)
        {
            int fish = min(n/2, f);
            int beef = min((n-f)/2, p);
        }
        else
        {
            int beef = min(n/2, p);
            int fish = min((n-h)/2, f);
        }
        cout << fish*c + beef*h << endl;
    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int q; cin >> q;
    while (q--)
    {
        int n, p, f, h, c;
        cin >> n >> p >> f >> h >> c;
        int fish, beef;
        if (c > h)
        {
            fish = min(n/2, f);
            beef = min((n-2*fish)/2, p);
        }
        else
        {
            beef = min(n/2, p);
            fish = min((n-2*beef)/2, f);
        }
        cout << fish*c + beef*h << endl;
    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int t,b,p,f,h,c,ans;
	cin>>t;
    for(int i=0;i<t;i++){
        ans=0;
        cin>>b>>p>>f>>h>>c;
        if(b==0)cout<<0<<endl;
        else{
            b/=2;
            if(c>h){
                swap(c,h);
                swap(f,p);
            }
            if(p>0&&b>0){
                if(b>=p){
                    ans+=p*h;
                    b-=h;
                }
                else{
                    ans+=b*h;
                    b=0;
                }
            }
            /*
            while(p>0&&b>0){
                ans+=h;
                h--;
                b--;
            }
            */
            if(b>0){
                if(p>0&&b>0){
                    if(b>=f)ans+=p*c;
                    else ans+=b*c;
                }
                /*
                while(f>0&&b>0){
                    ans+=c;
                    f--;
                    b--;
                }
                */
            }
            cout<<ans+10<<endl;
        }
    }
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int t,b,p,f,h,c,ans;
	cin>>t;
    for(int i=0;i<t;i++){
        ans=0;
        cin>>b>>p>>f>>h>>c;
        if(b==0)cout<<0<<endl;
        else{
            b/=2;
            if(c>h){
                swap(c,h);
                swap(f,p);
            }
            if(p>0&&b>0){
                if(b>=p){
                    ans+=p*h;
                    b-=p;
                }
                else{
                    ans+=b*h;
                    b=0;
                }
            }
            if(b>0)
                if(f>0&&b>0){
                    if(b>=f)ans+=f*c;
                    else ans+=b*c;
                }
            cout<<ans<<endl;
        }
    }
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int t,b,p,f,h,c,ans;
	cin>>t;
    for(int i=0;i<t;i++){
        ans=0;
        cin>>b>>p>>f>>h>>c;
        if(b==0)cout<<0<<endl;
        else{
            b/=2;
            if(c>h){
                swap(c,h);
                swap(f,p);
            }
            if(p>0&&b>0){
                if(b>=p){
                    ans+=p*h;
                    b-=p;
                }
                else{
                    ans+=p*h;
                    b=0;
                }
            }
            if(b>0)
                if(f>0&&b>0){
                    if(b>=f)ans+=f*c;
                    else ans+=b*c;
                }
            cout<<ans<<endl;
        }
    }
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int t,b,p,f,h,c,ans;
	cin>>t;
    for(int i=0;i<t;i++){
        ans=0;
        cin>>b>>p>>f>>h>>c;
        if(b==0)cout<<0<<endl;
        else{
            b/=2;
            if(c>h){
                swap(c,h);
                swap(f,p);
            }
            if(p>0&&b>0){
                if(b>=p){
                    ans+=p*h;
                    b-=h;
                }
                else{
                    ans+=b*h;
                    b=0;
                }
            }
            /*
            while(p>0&&b>0){
                ans+=h;
                h--;
                b--;
            }
            */
            if(b>0){
                if(f>0){
                    if(b>=f)ans+=p*c;
                    else ans+=b*c;
                }
                /*
                while(f>0&&b>0){
                    ans+=c;
                    f--;
                    b--;
                }
                */
            }
            cout<<ans<<endl;
        }
    }
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int t,b,p,f,h,c,ans;
	cin>>t;
    for(int i=0;i<t;i++){
        ans=0;
        cin>>b>>p>>f>>h>>c;
        if(b==0)cout<<0<<endl;
        else{
            b/=2;
            if(c>h){
                swap(c,h);
                swap(f,p);
            }
            if(p>0&&b>0){
                if(b>=p){
                    ans+=p*h;
                    b-=h;
                }
                else{
                    ans+=b*h;
                    b=0;
                }
            }
            /*
            while(p>0&&b>0){
                ans+=h;
                h--;
                b--;
            }
            */
            if(b>0){
                if(p>0&&b>0){
                    if(b>=f)ans+=p*c;
                    else ans+=b*c;
                }
                /*
                while(f>0&&b>0){
                    ans+=c;
                    f--;
                    b--;
                }
                */
            }
            cout<<ans<<endl;
        }
    }
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int t,b,p,f,h,c,ans;
	cin>>t;
    for(int i=0;i<t;i++){
        ans=0;
        cin>>b>>p>>f>>h>>c;
        if(b==0)cout<<0<<endl;
        else{
            b/=2;
            if(c>h){
                swap(c,h);
                swap(f,p);
            }
            if(p>0&&b>0){
                if(b>=p){
                    ans+=p*h;
                    b-=p;
                }
                else{
                    ans+=p*h;
                    b=0;
                }
            }
            if(b>0){
                if(f>0){
                    ans+=b*c;
                }
            }
            cout<<ans<<endl;
        }
    }
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int t,b,p,f,h,c,ans;
	cin>>t;
    for(int i=0;i<t;i++){
        ans=0;
        cin>>b>>p>>f>>h>>c;
        if(b==0)cout<<0<<endl;
        else{
            b/=2;
            if(c>h){
                swap(c,h);
                swap(f,p);
            }
            if(p>0&&b>0){
                if(b>=p){
                    ans+=b*h;
                    b-=p;
                }
                else{
                    ans+=b*h;
                    b=0;
                }
            }
            if(b>0)
                if(f>0&&b>0){
                    if(b>=f)ans+=f*c;
                    else ans+=b*c;
                }
            cout<<ans<<endl;
        }
    }
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int t,b,p,f,h,c,ans;
	cin>>t;
    for(int i=0;i<t;i++){
        ans=0;
        cin>>b>>p>>f>>h>>c;
        if(b==0)cout<<0<<endl;
        else{
            b/=2;
            if(c>h){
                swap(c,h);
                swap(f,p);
            }
            if(p>0&&b>0){
                if(b>=p){
                    ans+=p*h;
                    b-=h;
                }
                else{
                    ans+=b*h;
                    b=0;
                }
            }
            /*
            while(p>0&&b>0){
                ans+=h;
                h--;
                b--;
            }
            */
            if(b>0){
                if(f>0){
                    if(b>=f)ans+=b*c;
                    else ans+=b*c;
                }
                /*
                while(f>0&&b>0){
                    ans+=c;
                    f--;
                    b--;
                }
                */
            }
            cout<<ans<<endl;
        }
    }
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int t,b,p,f,h,c,ans;
	cin>>t;
    for(int i=0;i<t;i++){
        ans=0;
        cin>>b>>p>>f>>h>>c;
        if(b==0)cout<<0<<endl;
        else{
            b/=2;
            if(c>h){
                swap(c,h);
                swap(f,p);
            }
            if(p>0&&b>0){
                if(b>=p){
                    ans+=p*h;
                    b-=p;
                }
                else{
                    ans+=b*h;
                    b=0;
                }
            }
            if(b>0){
                if(f>0){
                    if(b>=f)ans+=b*c;
                    else ans+=b*c;
                }
            }
            cout<<ans<<endl;
        }
    }
	return 0;
}


#include <string>
#include <iostream>

using namespace std;

int main()
{
    int t,b,p,f,h,c,costly1=0,costly2=0,price1=0,price2=0,tot=0,a=0,e=0;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
     cin>>b>>p>>f;
     cin>>h>>c;
     if(h>c)
     {
        costly1=h;
        a=p;
     }
     else
     {
        costly1=c;
        a=f;
     }
     if(a==p)
     {
       e=f;
       costly2=c;
     }
         while(a>=0&&b>=2)
         {
             b=b-2;
             a--;
             price1=price1+costly1;
         }
         while(b>=2&&e>=0)
         {
             b=b-2;
             e--;
             price2=price2+costly2;
         }
         tot=price1+price2;
         cout<<tot;
    }
    return 0;
}


#include <string>
#include <iostream>

using namespace std;

int main()
{
    int t,b,p,f,h,c,a,e;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
      int costly1=0,costly2=0,price1=0,price2=0,tot=0;
     cin>>b>>p>>f;
     cin>>h>>c;
     if(h>c)
     {
        costly1=h;
        a=p;
     }
     else
     {
        costly1=c;
        a=f;
     }
     if(a==p)
     {
       e=f;
       costly2=c;
     }
     else
     {
         e=p;
         costly2=h;
     }
         while(a>0&&b>=2)
         {
             b=b-2;
             a--;
             price1=price1+costly1;
         }
         while(b>=2&&e>0)
         {
             b=b-2;
             e--;
             price2=price2+costly2;
         }
         tot=price1+price2;
         cout<<tot<<"\n";
    }
    return 0;
}


#include <string>
#include <iostream>

using namespace std;

int main()
{
    int t,b,p,f,h,c,costly1=0,costly2=0,price1=0,price2=0,tot=0,a=0,e=0;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
     cin>>b>>p>>f;
     cin>>h>>c;
     if(h>c)
     {
        costly1=h;
        a=p;
     }
     else
     {
        costly1=c;
        a=f;
     }
     if(a==p)
     {
       e=f;
       costly2=c;
     }
         while(a>=0&&b>=2)
         {
             b=b-2;
             a--;
             price1=price1+costly1;
         }
         while(b>=2&&e>=0)
         {
             b=b-2;
             e--;
             price2=price2+costly2;
         }
         tot=price1+price2;
    }
    return 0;
}


#include <string>
#include <iostream>

using namespace std;

int main()
{
    int t,b,p,f,h,c;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
      int costly1=0,costly2=0,price1=0,price2=0,tot=0,a=0,e=0;
     cin>>b>>p>>f;
     cin>>h>>c;
     if(h>c)
     {
        costly1=h;
        a=p;
     }
     else
     {
        costly1=c;
        a=f;
     }
     if(a==p)
     {
       e=f;
       costly2=c;
     }
         while(a>=0&&b>=2)
         {
             b=b-2;
             a--;
             price1=price1+costly1;
         }
         while(b>=2&&e>=0)
         {
             b=b-2;
             e--;
             price2=price2+costly2;
         }
         tot=price1+price2;
         cout<<tot;
    }
    return 0;
}


#include <string>
#include <iostream>

using namespace std;

int main()
{
    int t,b,p,f,h,c,costly1=0,costly2=0,price1=0,price2=0,tot=0,a=0,e=0;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
     cin>>b>>p>>f;
     cin>>h>>c;
     if(h>c)
     {
        costly1=h;
        a=p;
     }
     else
     {
        costly1=c;
        a=f;
     }
     if(a==p)
     {
       e=f;
       costly2=c;
     }
     else
     {
         e=p;
         costly2=h;
     }
         while(a>=0&&b>=2)
         {
             b=b-2;
             a--;
             price1=price1+costly1;
         }
         while(b>=2&&e>=0)
         {
             b=b-2;
             e--;
             price2=price2+costly2;
         }
         tot=price1+price2;
         cout<<tot<<"\n";
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;

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

        int b, p, f;
        int h, c;

        cin >> b >> p >> f;
        cin >> h >> c;

        b -= b % 2;
        b = b / 2;

        if (h >= c)
        {
            if (p <= b)
            {
                summa += p * h;
                b -= p;

                if (f <= b)
                {
                    summa += f * c;
                }
                else
                {
                    summa += b * c;
                }
            }
            else
            {
                summa += b * h;
            }
        }
        else
        {
            if (f <= b)
            {
                summa += f * c;
                b -= f;

                if (p <= b)
                {
                    summa += p * h;
                }
                else
                {
                    summa += b * h;
                }
            }
        }

        cout << summa << endl;
    }
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;

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

        int b, p, f;
        int h, c;

        cin >> b >> p >> f;
        cin >> h >> c;

        if (b != 1)
        {
            b = b / 2;
        }

        if (h > c)
        {
            if (p <= b)
            {
                summa += p * h;
                b -= p;

                if (f <= b)
                {
                    summa += f * c;
                }
                else
                {
                    summa += b * c;
                }
            }
            else
            {
                summa += b * h;
            }
        }
        if (h < c)
        {
            if (f <= b)
            {
                summa += f * c;
                b -= f;

                if (p <= b)
                {
                    summa += p * h;
                }
                else
                {
                    summa += b * h;
                }
            }
            else
            {
                summa += b * c;
            }
        }

        if (h == c)
        {
            if (b <= f + p)
            {
                summa = b * h;
            }
            else
            {
                summa = h * (f + p);
            }
        }

        cout << summa << endl;
    }
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;

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

        int b, p, f;
        int h, c;

        cin >> b >> p >> f;
        cin >> h >> c;

        if (b > 1)
        {
            b = b / 2;
        }

        if (h >= c)
        {
            if (p <= b)
            {
                summa += p * h;
                b -= p;

                if (f <= b)
                {
                    summa += f * c;
                }
                else
                {
                    summa += b * c;
                }
            }
            else
            {
                summa += b * h;
            }
        }
        if (h < c)
        {
            if (f <= b)
            {
                summa += f * c;
                b -= f;

                if (p <= b)
                {
                    summa += p * h;
                }
                else
                {
                    summa += b * h;
                }
            }
            else
            {
                summa += b * c;
            }
        }

        cout << summa << endl;
    }
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;

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

        int b, p, f;
        int h, c;

        cin >> b >> p >> f;
        cin >> h >> c;

        b = b / 2;

        if (h >= c)
        {
            if (p <= b)
            {
                summa += p * h;
                b -= p;

                if (f <= b)
                {
                    summa += f * c;
                }
                else
                {
                    summa += b * c;
                }
            }
            else
            {
                summa += b * h;
            }
        }
        if (h < c)
        {
            if (f <= b)
            {
                summa += f * c;
                b -= f;

                if (p <= b)
                {
                    summa += p * h;
                }
                else
                {
                    summa += b * h;
                }
            }
            else
            {
                summa += b * c;
            }
        }

        cout << summa << endl;
    }
}


#include<iostream>
using namespace std;
main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long int b,h,c,hp,cp,bun,mprice=0,maxh=0,maxc=0,temp=0,max;
		cin>>b;
		cin>>h;
		cin>>c;
		cin>>hp;
		cin>>cp;
		bun=b/2;
		if(hp>cp)
		{
			if(c+h<=bun)
			{
				max=(c*cp)+(h*hp);
			}
			else if(h>=bun)
			{
				max=bun*hp;
			}
			else
			{
				max=h*hp;
				max=max+((bun-h)*cp);

			}
			cout<<max<<endl;
		}
		else if(cp>hp)
		{
			if(c+h<=bun)
			{
				max=(c*cp)+(h*hp);
			}
			else if(c>=bun)
			{
				max=bun*cp;
			}
			else
			{
				max=c*cp;
				max=max+((bun-c)*hp);
			}
			cout<<max<<endl;
		}
		else(bun<2||h==0&&c==0)
		{
			cout<<"0"<<endl;
		}
	}
}


#include<iostream>
using namespace std;
main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long int b,h,c,hp,cp,bun,mprice=0,maxh=0,maxc=0,temp=0,max;
		cin>>b;
		cin>>h;
		cin>>c;
		cin>>hp;
		cin>>cp;
		bun=b/2;
		if(hp>cp)
		{
			if(c+h<=bun)
			{
				max=(c*cp)+(h*hp);
			}
			else if(h>=bun)
			{
				max=bun*hp;
			}
			else
			{
				max=h*hp;
				max=max+((bun-h)*cp);

			}
			cout<<max<<endl;
		}
		else if(cp>hp)
		{
			if(c+h<=bun)
			{
				max=(c*cp)+(h*hp);
			}
			else if(c>=bun)
			{
				max=bun*cp;
			}
			else
			{
				max=c*cp;
				max=max+((bun-c)*hp);
			}
			cout<<max<<endl;
		}
		else if(bun<2||h==0&&c==0)
		{
			cout<<"0"<<endl;
		}
	}
}


#include<iostream>
using namespace std;
main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long int b,h,c,hp,cp,bun,mprice=0,maxh=0,maxc=0,temp=0,max;
		cin>>b;
		cin>>h;
		cin>>c;
		cin>>hp;
		cin>>cp;
		bun=b/2;
		if(hp>=cp)
		{
			if(c+h<=bun)
			{
				max=(c*cp)+(h*hp);
			}
			else if(h>=bun)
			{
				max=bun*hp;
			}
			else
			{
				max=h*hp;
				if(bun-h>0)
				max=max+((bun-h)*cp);

			}
			cout<<max<<endl;
		}
		else if(cp>=hp)
		{
			if(c+h<=bun)
			{
				max=(c*cp)+(h*hp);
			}
			else if(c>=bun)
			{
				max=bun*cp;
			}
			else
			{
				max=c*cp;
				if(bun-c>0)
				max=max+((bun-c)*hp);
			}
			cout<<max<<endl;
		}
		else if(bun<2||h==0&&c==0)
		{
			cout<<"0"<<endl;
		}
	}
}


#include<iostream>
using namespace std;
main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long int b,h,c,hp,cp,bun,mprice=0,maxh=0,maxc=0,temp=0,max;
		cin>>b;
		cin>>h;
		cin>>c;
		cin>>hp;
		cin>>cp;
		bun=b/2;
		if(hp>cp)
		{
			if(c+h<=bun)
			{
				max=(c*cp)+(h*hp);
			}
			else if(h>=bun)
			{
				max=bun*hp;
			}
			else
			{
				max=h*hp;
				max=max+((bun-h)*cp);

			}
			cout<<max<<endl;
		}
		else if(cp>hp)
		{
			if(c+h<=bun)
			{
				max=(c*cp)+(h*hp);
			}
			else if(c>=bun)
			{
				max=bun*cp;
			}
			else
			{
				max=c*cp;
				max=max+((bun-c)*hp);
			}
			cout<<max<<endl;
		}
		if(bun<2||h==0&&c==0)
		{
			cout<<"0"<<endl;
		}
	}
}


#include<bits/stdc++.h>

/// Constants
#define maxi                10000007
#define MOD                 1000000009
#define base                1000000007
#define eps                 1e-9
#define INF                 1llu<<61    // 2,305,843,009,213,693,952
#define inf                 1<<29       // 536,870,912
#define PI                  acos(-1.0)  // 3.1415926535897932

#define Loser ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define GCD(a,b) __gcd(a,b)
#define LCM(a,b) ((a*b)/__gcd(a,b) )
#define mp make_pair
#define pb push_back

#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<ll>())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
/*max element in set``->(int)*set_name.rbegin();
min element in set``->*/
ll revNumber(ll n) { ll b=0; while(n!=0){ b = b*10 + n%10; n/=10; } return b; }

ll leapYearCheck(ll year) { if(year%4!=0) return 0; else if(year%100!=0) return 1; else if(year%400!=0) return 0; else return 1; }

ll countDivisor(ll n) { ll ck=0; for(ll i=1; i*i<=n; i++){ if(n%i==0){ ck++; if(i!=n/i) ck++; } } return ck; }

ll primeFactorsCount(ll n){ ll gf =0;  while (n%2 == 0) { gf++; n = n/2; } for (ll i = 3; i <= sqrt(n); i = i+2) { while (n%i == 0) { gf++;  n = n/i; } } if (n > 2){ gf++; } return gf; }

ll factorial(ll n) { if(n == 1) return 1; return n*factorial(n-1); }

ll binarySearch(ll high, ll sV, ll arr[]) { ll low = 0; while(low<=high){ ll mid = (high+low)/2; if(sV == arr[mid]) return mid+1; else if(sV > arr[mid]) low = mid+1; else high = mid-1; } return -1; }

bool checkPrime(int n) { int i; if(n<=1)return false; for(i=2;i*i<=n;i++){ if(n%i==0)return false; } return true; }

void simpleSieve(int limit){bool mark[limit];memset(mark,true,sizeof(mark));for(int p=2;p*p<limit;++p){if(mark[p]==true){for(int i=p*2;i<limit;i+=p)mark[i]=false;}}for(int p=2;p<limit;++p){if(mark[p]==true)cout<<p<<" ";}}

int divSum(int n){int result=0;for(int i=2;i<=sqrt(n);++i){if(n%i==0){if(i==(n/i))result+=i;else result+=(i+n/i);}}return (result+1);}

bool isPerfectSquare(int n){for(int sum=0,i=1;sum<n;i+=2){sum+=i;if(sum==n)return true;}return false;}

int Combination(int n,int r){if(n==r)return 1;if(r==1)return n;return Combination(n-1,r)+Combination(n-1,r-1);}

int Permutation(int n,int r){return factorial(n)/factorial(n-r);}

int countDerangements(int n){if(n==1)return 0;if(n==0)return 1;if(n==2)return 1;return (n-1)*(countDerangements(n-1)+countDerangements(n-2));}

ull Catalan(ull n){if(n<=1)return 1;ull res=0;for(int i=0;i<n;++i){res+=Catalan(i)*Catalan(n-i-1);}return res;}

void swap(int *x,int *y)
{
    int t=*x;
    *x=*y;
    *y=t;
}
/*	for(int i=1;i*i<=n;++i)
	{
		if(n%i==0) {
			v.push_back(i);
			if(i!=n/i) v.push_back(n/i);
		}
	}
*/
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/

int main()
{
	Loser
	int a,b,c,d,e,t,res,sum;cin>>t;
	while(t--)
	{
		cin>>a>>b>>c>>d>>e;
		res=a/2;
		if(res<=b&&d>=e) sum=res*d;
		if(res<=c&&d<e) sum=res*e;
		if(res>b+c) sum=c*e+b*d;
		else
		{
			if(d>e) sum=b*d+(res-b)*e;
			if(d<e) sum=c*e+(res-c)*d;
			else
			{
				if(b>c) sum=b*d+(res-b)*e;
				else sum=c*e+(res-c)*d;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>

/// Constants
#define maxi                10000007
#define MOD                 1000000009
#define base                1000000007
#define eps                 1e-9
#define INF                 1llu<<61    // 2,305,843,009,213,693,952
#define inf                 1<<29       // 536,870,912
#define PI                  acos(-1.0)  // 3.1415926535897932

#define Loser ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define GCD(a,b) __gcd(a,b)
#define LCM(a,b) ((a*b)/__gcd(a,b) )
#define mp make_pair
#define pb push_back

#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<ll>())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
/*max element in set``->(int)*set_name.rbegin();
min element in set``->*/
ll revNumber(ll n) { ll b=0; while(n!=0){ b = b*10 + n%10; n/=10; } return b; }

ll leapYearCheck(ll year) { if(year%4!=0) return 0; else if(year%100!=0) return 1; else if(year%400!=0) return 0; else return 1; }

ll countDivisor(ll n) { ll ck=0; for(ll i=1; i*i<=n; i++){ if(n%i==0){ ck++; if(i!=n/i) ck++; } } return ck; }

ll primeFactorsCount(ll n){ ll gf =0;  while (n%2 == 0) { gf++; n = n/2; } for (ll i = 3; i <= sqrt(n); i = i+2) { while (n%i == 0) { gf++;  n = n/i; } } if (n > 2){ gf++; } return gf; }

ll factorial(ll n) { if(n == 1) return 1; return n*factorial(n-1); }

ll binarySearch(ll high, ll sV, ll arr[]) { ll low = 0; while(low<=high){ ll mid = (high+low)/2; if(sV == arr[mid]) return mid+1; else if(sV > arr[mid]) low = mid+1; else high = mid-1; } return -1; }

bool checkPrime(int n) { int i; if(n<=1)return false; for(i=2;i*i<=n;i++){ if(n%i==0)return false; } return true; }

void simpleSieve(int limit){bool mark[limit];memset(mark,true,sizeof(mark));for(int p=2;p*p<limit;++p){if(mark[p]==true){for(int i=p*2;i<limit;i+=p)mark[i]=false;}}for(int p=2;p<limit;++p){if(mark[p]==true)cout<<p<<" ";}}

int divSum(int n){int result=0;for(int i=2;i<=sqrt(n);++i){if(n%i==0){if(i==(n/i))result+=i;else result+=(i+n/i);}}return (result+1);}

bool isPerfectSquare(int n){for(int sum=0,i=1;sum<n;i+=2){sum+=i;if(sum==n)return true;}return false;}

int Combination(int n,int r){if(n==r)return 1;if(r==1)return n;return Combination(n-1,r)+Combination(n-1,r-1);}

int Permutation(int n,int r){return factorial(n)/factorial(n-r);}

int countDerangements(int n){if(n==1)return 0;if(n==0)return 1;if(n==2)return 1;return (n-1)*(countDerangements(n-1)+countDerangements(n-2));}

ull Catalan(ull n){if(n<=1)return 1;ull res=0;for(int i=0;i<n;++i){res+=Catalan(i)*Catalan(n-i-1);}return res;}

void swap(int *x,int *y)
{
    int t=*x;
    *x=*y;
    *y=t;
}
/*	for(int i=1;i*i<=n;++i)
	{
		if(n%i==0) {
			v.push_back(i);
			if(i!=n/i) v.push_back(n/i);
		}
	}
*/
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/

int main()
{
	Loser
	int a,b,c,d,e,t,res,sum;cin>>t;
	while(t--)
	{
		cin>>a>>b>>c>>d>>e;
		res=a/2;
		if(res<=b&&d>=e) sum=res*d;
		else if(res<=c&&d<e) sum=res*e;
		else if(res>b+c) sum=c*e+b*d;
		else
		{
			if(d>e) sum=b*d+(res-b)*e;
			else if(d<e) sum=c*e+(res-c)*d;
			else
			{
				if(b>c) sum=b*d+(res-b)*e;
				else sum=c*e+(res-c)*d;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>

/// Constants
#define maxi                10000007
#define MOD                 1000000009
#define base                1000000007
#define eps                 1e-9
#define INF                 1llu<<61    // 2,305,843,009,213,693,952
#define inf                 1<<29       // 536,870,912
#define PI                  acos(-1.0)  // 3.1415926535897932

#define Loser ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define GCD(a,b) __gcd(a,b)
#define LCM(a,b) ((a*b)/__gcd(a,b) )
#define mp make_pair
#define pb push_back

#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<ll>())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
/*max element in set``->(int)*set_name.rbegin();
min element in set``->*/
ll revNumber(ll n) { ll b=0; while(n!=0){ b = b*10 + n%10; n/=10; } return b; }

ll leapYearCheck(ll year) { if(year%4!=0) return 0; else if(year%100!=0) return 1; else if(year%400!=0) return 0; else return 1; }

ll countDivisor(ll n) { ll ck=0; for(ll i=1; i*i<=n; i++){ if(n%i==0){ ck++; if(i!=n/i) ck++; } } return ck; }

ll primeFactorsCount(ll n){ ll gf =0;  while (n%2 == 0) { gf++; n = n/2; } for (ll i = 3; i <= sqrt(n); i = i+2) { while (n%i == 0) { gf++;  n = n/i; } } if (n > 2){ gf++; } return gf; }

ll factorial(ll n) { if(n == 1) return 1; return n*factorial(n-1); }

ll binarySearch(ll high, ll sV, ll arr[]) { ll low = 0; while(low<=high){ ll mid = (high+low)/2; if(sV == arr[mid]) return mid+1; else if(sV > arr[mid]) low = mid+1; else high = mid-1; } return -1; }

bool checkPrime(int n) { int i; if(n<=1)return false; for(i=2;i*i<=n;i++){ if(n%i==0)return false; } return true; }

void simpleSieve(int limit){bool mark[limit];memset(mark,true,sizeof(mark));for(int p=2;p*p<limit;++p){if(mark[p]==true){for(int i=p*2;i<limit;i+=p)mark[i]=false;}}for(int p=2;p<limit;++p){if(mark[p]==true)cout<<p<<" ";}}

int divSum(int n){int result=0;for(int i=2;i<=sqrt(n);++i){if(n%i==0){if(i==(n/i))result+=i;else result+=(i+n/i);}}return (result+1);}

bool isPerfectSquare(int n){for(int sum=0,i=1;sum<n;i+=2){sum+=i;if(sum==n)return true;}return false;}

int Combination(int n,int r){if(n==r)return 1;if(r==1)return n;return Combination(n-1,r)+Combination(n-1,r-1);}

int Permutation(int n,int r){return factorial(n)/factorial(n-r);}

int countDerangements(int n){if(n==1)return 0;if(n==0)return 1;if(n==2)return 1;return (n-1)*(countDerangements(n-1)+countDerangements(n-2));}

ull Catalan(ull n){if(n<=1)return 1;ull res=0;for(int i=0;i<n;++i){res+=Catalan(i)*Catalan(n-i-1);}return res;}

void swap(int *x,int *y)
{
    int t=*x;
    *x=*y;
    *y=t;
}
/*	for(int i=1;i*i<=n;++i)
	{
		if(n%i==0) {
			v.push_back(i);
			if(i!=n/i) v.push_back(n/i);
		}
	}
*/
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/

int main()
{
	Loser
	int a,b,c,d,e,t,res,sum;cin>>t;
	while(t--)
	{
		cin>>a>>b>>c>>d>>e;
		res=a/2;
		if(res<=b&&d>=e) sum=res*d;
		else if(res<=c&&d<e) sum=res*e;
		else if(res>b+c) sum=c*e+b*d;
		else
		{
			if(d>e) sum=b*d+(res-b)*e;
			if(d<e) sum=c*e+(res-c)*d;
			else
			{
				if(b>c) sum=b*d+(res-b)*e;
				else sum=c*e+(res-c)*d;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>

/// Constants
#define maxi                10000007
#define MOD                 1000000009
#define base                1000000007
#define eps                 1e-9
#define INF                 1llu<<61    // 2,305,843,009,213,693,952
#define inf                 1<<29       // 536,870,912
#define PI                  acos(-1.0)  // 3.1415926535897932

#define Loser ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define GCD(a,b) __gcd(a,b)
#define LCM(a,b) ((a*b)/__gcd(a,b) )
#define mp make_pair
#define pb push_back

#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<ll>())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
/*max element in set``->(int)*set_name.rbegin();
min element in set``->*/
ll revNumber(ll n) { ll b=0; while(n!=0){ b = b*10 + n%10; n/=10; } return b; }

ll leapYearCheck(ll year) { if(year%4!=0) return 0; else if(year%100!=0) return 1; else if(year%400!=0) return 0; else return 1; }

ll countDivisor(ll n) { ll ck=0; for(ll i=1; i*i<=n; i++){ if(n%i==0){ ck++; if(i!=n/i) ck++; } } return ck; }

ll primeFactorsCount(ll n){ ll gf =0;  while (n%2 == 0) { gf++; n = n/2; } for (ll i = 3; i <= sqrt(n); i = i+2) { while (n%i == 0) { gf++;  n = n/i; } } if (n > 2){ gf++; } return gf; }

ll factorial(ll n) { if(n == 1) return 1; return n*factorial(n-1); }

ll binarySearch(ll high, ll sV, ll arr[]) { ll low = 0; while(low<=high){ ll mid = (high+low)/2; if(sV == arr[mid]) return mid+1; else if(sV > arr[mid]) low = mid+1; else high = mid-1; } return -1; }

bool checkPrime(int n) { int i; if(n<=1)return false; for(i=2;i*i<=n;i++){ if(n%i==0)return false; } return true; }

void simpleSieve(int limit){bool mark[limit];memset(mark,true,sizeof(mark));for(int p=2;p*p<limit;++p){if(mark[p]==true){for(int i=p*2;i<limit;i+=p)mark[i]=false;}}for(int p=2;p<limit;++p){if(mark[p]==true)cout<<p<<" ";}}

int divSum(int n){int result=0;for(int i=2;i<=sqrt(n);++i){if(n%i==0){if(i==(n/i))result+=i;else result+=(i+n/i);}}return (result+1);}

bool isPerfectSquare(int n){for(int sum=0,i=1;sum<n;i+=2){sum+=i;if(sum==n)return true;}return false;}

int Combination(int n,int r){if(n==r)return 1;if(r==1)return n;return Combination(n-1,r)+Combination(n-1,r-1);}

int Permutation(int n,int r){return factorial(n)/factorial(n-r);}

int countDerangements(int n){if(n==1)return 0;if(n==0)return 1;if(n==2)return 1;return (n-1)*(countDerangements(n-1)+countDerangements(n-2));}

ull Catalan(ull n){if(n<=1)return 1;ull res=0;for(int i=0;i<n;++i){res+=Catalan(i)*Catalan(n-i-1);}return res;}

void swap(int *x,int *y)
{
    int t=*x;
    *x=*y;
    *y=t;
}
/*	for(int i=1;i*i<=n;++i)
	{
		if(n%i==0) {
			v.push_back(i);
			if(i!=n/i) v.push_back(n/i);
		}
	}
*/
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/

int main()
{
	Loser
	int t,b,c,f,p,h,res;cin>>t;
	for(int i=0;i<t;++i)
	{
		cin>>b>>f>>p>>h>>c;
		res=b/2;
		if(res>=f+p)
		{
			cout<<f*h+p*c<<endl;
		}
		else
		{
			if(h<c)
			{
				cout<<c*p+(res-p)*h<<endl;
			}
			else if(h>c)
			{
				cout<<h*p+(res-f)*c<<endl;
			}
			else
			{
				cout<<res*h<<endl;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int b,f,c,h,p,t,i;
vector<int>vc;
 cin>>t;
 while(t--)
 { cin>>b>>p>>f;
 cin>>h>>c;
  int s,n,x,y,r,u,v,sum=0,sum2=0,w,q;
   x=2*p;
   y=2*f;
   if(h>=c)
   {
   if(x<=b)
   { n=h*p;
     w=(b-x);
     if(y<=w) r=f*c;
     else r=(w/2)*c;
     sum=n+r;
     ///cout<<sum<<" ";
   }
 else { n=(b/2)*h; sum=n;  }
 }
  else
  {
        if(y<=b)
   {
        s=c*f;
     v=(b-y);
     if(x<=v) u=h*p;
     else u=(v/2)*h;
     sum2=s+u;
     ///cout<<u<<" "<<s;
   }
   else { s=(b/2)*c;  sum2=s;}
  }
     sum=max(sum,sum2);
     vc.push_back(sum);
        cout<<sum<<endl;

 }
 /*for(int i=0;i<vc.size();i++)
    cout<<vc[i]<<endl;
*/

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int b,f,c,h,p,t,i;
vector<int>vc;
 cin>>t;
 while(t--)
 { cin>>b>>p>>f;
 cin>>h>>c;
  int s,n,x,y,r,u,v,sum,sum2,w,q;
   x=2*p;
   y=2*f;
   if(x<=b)
   { n=h*p;
     w=(b-x);
     if(y<=w) r=f*c;
     else r=(w/2)*c;
     sum=n+r;
     ///cout<<sum<<" ";
   }
   if(y<=b)
   { s=c*f;
     v=(b-y);
     if(x<=v) u=h*p;
     else u=(v/2)*h;
     sum2=s+u;
     ///cout<<u<<" "<<s;
   }
     sum=max(sum,sum2);
     vc.push_back(sum);

     ///cout<<sum<<endl;
      sum=0,sum2=0;

 }
 for(int i=0;i<vc.size();i++)
    cout<<vc[i]<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int b,f,c,h,p,t,i;
 cin>>t;
 while(t--)
 { cin>>b>>p>>f;
 cin>>h>>c;
  int s,n,x,y,r,u,v,sum,sum2,w,q;
   x=2*p;
   y=2*f;
   if(x<=b)
   { n=h*p;
     w=(b-x);
     if(y<=w) r=f*c;
     else r=(w/2)*c;
     sum=n+r;
     ///cout<<sum<<" ";
   }
   if(y<=b)
   { s=c*f;
     v=(b-y);
     if(x<=v) u=h*p;
     else u=(v/2)*h;
     sum2=s+u;
     ///cout<<u<<" "<<s;
   }
     sum=max(sum,sum2);
     cout<<sum<<endl;
      sum=0,sum2=0;

 }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int b,f,c,h,p,t,i;
vector<int>vc;
 cin>>t;
 while(t--)
 { cin>>b>>p>>f;
 cin>>h>>c;
  int s,n,x,y,r,u,v,sum=0,sum2=0,w,q;
   x=2*p;
   y=2*f;
   if(x<=b)
   { n=h*p;
     w=(b-x);
     if(y<=w) r=f*c;
     else r=(w/2)*c;
     sum=n+r;
     ///cout<<sum<<" ";
   }
   if(y<=b)
   { s=c*f;
     v=(b-y);
     if(x<=v) u=h*p;
     else u=(v/2)*h;
     sum2=s+u;
     ///cout<<u<<" "<<s;
   }
     sum=max(sum,sum2);
     vc.push_back(sum);
        cout<<sum<<endl;
     sum=0,sum2=0;

 }
 /*for(int i=0;i<vc.size();i++)
    cout<<vc[i]<<endl;
*/

return 0;
}


#include<iostream>
using namespace std;
int main()
{
    struct burger{
        int price,quant; //price of burger, pr
    };
    burger ham,chick,e,max1,min1;
    int t;
    cin>>t;
    int sol[t];
    for(int i=0;i<t;i++)
    {
        int buns;
        cin>>buns>>ham.quant>>chick.quant>>ham.price>>chick.price;
        buns/=2;
        max1=(ham.price>chick.price)?ham:chick;
        min1=(ham.price<chick.price)?ham:chick;
        if(buns>=max1.quant&&buns<=min1.quant)
            sol[i]=max1.price*max1.quant+min1.price*(buns-max1.quant);
        else if(buns<=max1.quant&&buns>=min1.quant)
            sol[i]=max1.price*buns;
        else if(buns<max1.quant&&buns<min1.quant)
            sol[i]=max1.price*buns;
        else if((buns>max1.quant&&buns>min1.quant)&&buns<(max1.quant+min1.quant))
            sol[i]=max1.price*max1.quant+min1.price*(buns-max1.quant);
        else if ((buns>max1.quant&&buns>min1.quant)&&buns>=(max1.quant+min1.quant))
            sol[i]=max1.price*max1.quant+min1.price*min1.quant;
    }
    for(int i=0;i<t;i++)
    cout<<sol[i]<<endl;

}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    while(t--)
    {
        int b=0,p=0,f=0,h=0,c=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(b>=(f+p))
        {
            cout<<p*h+f*c;
        }
        else if(b>p&&b>f)
        {
            if(h>c)
                cout<<p*h+(b-f)*c;
            else
                cout<<(b-p)*h+(f)*c;
        }
        else if(b>p&&b<f)
        {
            if(h>c)
                cout<<p*h+(b-p)*c;
            else
                cout<<b*c;
        }
        else if(b<p&&b>f)
        {
            if(h>c)
                cout<<b*h;
            else
                cout<<(b-f)*h+f*c;
        }
        else
        {
            if(h>c)
                cout<<h*p;
            else
                cout<<c*f;
        }

    }
}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    while(t--)
    {
        int b=0,p=0,f=0,h=0,c=0,max_cost=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(h>c)
        {
            if(b>=(f+p))
            {
                cout<<p*h+f*c;
            }
            else
            {
                cout<<b*h;

            }

        }
        else
        {
            if(b>=(f+p))
            {
                cout<<p*h+f*c;
            }
                else
                {
                cout<<b*f;

                }
        }

    }

}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    for(int i=0;i<n;i++)
    {
        int b=0,p=0,f=0,h=0,c=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(b>=(f+p))
        {
            test[i]=p*h+f*c;
        }
        else if(b>=p&&b>=f)
        {
            if(h>c)
                test[i]=p*h+(b-f)*c;
            else
                test[i]=(b-p)*h+(f)*c;
        }
        else if(b>=p&&b<=f)
        {
            if(h>c)
                test[i]=p*h+(b-p)*c;
            else
                test[i]=b*c;
        }
        else if(b<=p&&b>=f)
        {
            if(h>c)
                test[i]=b*h;
            else
                test[i]=(b-f)*h+f*c;
        }
        else
        {
            if(h>c)
                test[i]=h*b;
            else
                test[i]=c*b;
        }

    }
for(int i=0;i<n;i++)
    cout<<test[i]<<endl;
}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    for(int i=0;i<n;i++)
    {
        int b=0,p=0,f=0,h=0,c=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(b>=(f+p))
        {
            test[i]=p*h+f*c;
        }
        else if(b>p&&b>f)
        {
            if(h>c)
                test[i]=p*h+(b-f)*c;
            else
                test[i]=(b-p)*h+(f)*c;
        }
        else if(b>p&&b<f)
        {
            if(h>c)
                test[i]=p*h+(b-p)*c;
            else
                test[i]=b*c;
        }
        else if(b<p&&b>f)
        {
            if(h>c)
                test[i]=b*h;
            else
                test[i]=(b-f)*h+f*c;
        }
        else
        {
            if(h>c)
                test[i]=h*b;
            else
                test[i]=c*b;
        }

    }
for(int i=0;i<n;i++)
    cout<<test[i]<<endl;
}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    for(int i=0;i<n;i++)
    {
        int b=0,p=0,f=0,h=0,c=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(b>=(f+p))
        {
            test[i]=p*h+f*c;
        }
        else if(b>p&&b>f)
        {
            if(h>c)
                test[i]=p*h+(b-f)*c;
            else
                test[i]=(b-p)*h+(f)*c;
        }
        else if(b>p&&b<f)
        {
            if(h>c)
                test[i]=p*h+(b-p)*c;
            else
                test[i]=b*c;
        }
        else if(b<p&&b>f)
        {
            if(h>c)
                test[i]=b*h;
            else
                test[i]=(b-f)*h+f*c;
        }
        else
        {
            if(h>c)
                test[i]=h*p;
            else
                test[i]=c*f;
        }

    }
for(int i=0;i<n;i++)
    cout<<test[i]<<" ";
}


#include<iostream>
using namespace std;
int main()
{
    struct burger{
        int price,quant; //price of burger, pr
    };
    burger ham,chick,e,max1,min1;
    int t;
    cin>>t;
    int sol[t];
    for(int i=0;i<t;i++)
    {
        int buns;
        cin>>buns>>ham.quant>>chick.quant>>ham.price>>chick.price;
        buns/=2;
        max1=(ham.price>chick.price)?ham:chick;
        min1=(ham.price<chick.price)?ham:chick;
        if(buns<max1.quant)
            sol[i]=max1.price*buns;
        else if((buns>max1.quant&&buns>min1.quant)&&buns<(max1.quant+min1.quant))
            sol[i]=max1.price*max1.quant+min1.price*(buns-max1.quant);
        else if ((buns>max1.quant&&buns>min1.quant)&&buns>=(max1.quant+min1.quant))
            sol[i]=max1.price*max1.quant+min1.price*min1.quant;
    }
    for(int i=0;i<t;i++)
    cout<<sol[i]<<endl;

}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    while(t--)
    {
        int b=0,p=0,f=0,h=0,c=0,max_cost=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(h>c)
        {
            if(b>=(f+p))
            {
                test[t]=p*h+f*c;
            }
            else
            {
                test[t]=b*h;

            }

        }
        else
        {
            if(b>=(f+p))
            {
                test[t]=p*h+f*c;
            }
                else
                {
                test[t]=b*f;

                }
        }

    }
    for(int i=0;i<n;i++)
        cout<<test[i]<<endl;

}


#include<iostream>
using namespace std;
int main()
{
    struct burger{
        int price,quant; //price of burger, pr
    };
    burger ham,chick,e,max1,min1;
    int t;
    cin>>t;
    int sol[t];
    for(int i=0;i<t;i++)
    {
        int buns;
        cin>>buns>>ham.quant>>chick.quant>>ham.price>>chick.price;
        buns/=2;
        max1=(ham.price>chick.price)?ham:chick;
        min1=(ham.price<chick.price)?ham:chick;
        if(buns>=max1.quant&&buns<min1.quant)
            sol[i]=max1.price*max1.quant+min1.price*(buns-max1.quant);
        else if(buns<=max1.quant&&buns>min1.quant)
            sol[i]=max1.price*buns;
        else if(buns<max1.quant&&buns<min1.quant)
            sol[i]=max1.price*buns;
        else if((buns>max1.quant&&buns>min1.quant)&&buns<(max1.quant+min1.quant))
            sol[i]=max1.price*max1.quant+min1.price*(buns-max1.quant);
        else if ((buns>max1.quant&&buns>min1.quant)&&buns>=(max1.quant+min1.quant))
            sol[i]=max1.price*max1.quant+min1.price*min1.quant;
    }
    for(int i=0;i<t;i++)
    cout<<sol[i]<<endl;

}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    for(int i=0;i<n;i++)
    {
        int b=0,p=0,f=0,h=0,c=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(b>=(f+p))
        {
            test[i]=p*h+f*c;
        }
        else if(b>p&&b>f)
        {
            if(h>c)
                test[i]=p*h+(b-f)*c;
            else
                test[i]=(b-p)*h+(f)*c;
        }
        else if(b>p&&b<f)
        {
            if(h>c)
                test[i]=p*h+(b-p)*c;
            else
                test[i]=b*c;
        }
        else if(b<p&&b>f)
        {
            if(h>c)
                test[i]=b*h;
            else
                test[i]=(b-f)*h+f*c;
        }
        else
        {
            if(h>c)
                test[i]=h*p;
            else
                test[i]=c*f;
        }

    }
for(int i=0;i<n;i++)
    cout<<test[i];
}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    while(t--)
    {
        int b=0,p=0,f=0,h=0,c=0,max_cost=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(h>c)
        {
            if(b>=(f+p))
            {
                cout<<p*h+f*c;
            }
            else
            {
                cout<<b*h;

            }

        }
        else
        {
            if(b>=(f+p))
            {
                cout<<p*h+f*c;
            }
                else
                {
                cout<<b*c;

                }
        }

    }

}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    for(int i=0;i<n;i++)
    {
        int b=0,p=0,f=0,h=0,c=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(b>=(f+p))
        {
            test[i]=p*h+f*c;
        }
        else if(b>p&&b>f)
        {
            if(h>c)
                test[i]=p*h+(b-f)*c;
            else
                test[i]=(b-p)*h+(f)*c;
        }
        else if(b>p&&b<f)
        {
            if(h>c)
                test[i]=p*h+(b-p)*c;
            else
                test[i]=b*c;
        }
        else if(b<p&&b>f)
        {
            if(h>c)
                test[i]=b*h;
            else
                test[i]=(b-f)*h+f*c;
        }
        else
        {
            if(h>c)
                test[i]=h*p;
            else
                test[i]=c*f;
        }

    }
for(int i=0;i<n;i++)
    cout<<test[i]<<endl;
}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    for(int i=0;i<n;i++)
    {
        int b=0,p=0,f=0,h=0,c=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(b>=(f+p))
        {
            test[i]=p*h+f*c;
        }
        else if(b>p&&b>f)
        {
            if(h>c)
                test[i]=p*h+(b-f)*c;
            else
                test[i]=(b-p)*h+(f)*c;
        }
        else if(b>p&&b<f)
        {
            if(h>c)
                test[i]=p*h+(b-p)*c;
            else
                test[i]=b*c;
        }
        else if(b<p&&b>f)
        {
            if(h>c)
                test[i]=b*h;
            else
                test[i]=(b-f)*h+f*c;
        }
        else
        {
            if(h>c)
                test[i]=h*b;
            else
                test[i]=c*b;
        }

    }
for(int i=0;i<n;i++)
    cout<<test[i];
}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    for(int i=0;i<n;i++)
    {
        int b=0,p=0,f=0,h=0,c=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(b>=(f+p))
        {
            test[i]=p*h+f*c;
        }
        else if(b>p&&b>f)
        {
            if(h>c)
                test[i]=p*h+(b-f)*c;
            else
                test[i]=(b-p)*h+(f)*c;
        }
        else if(b>p&&b<f)
        {
            if(h>c)
                test[i]=p*h+(b-p)*c;
            else
                test[i]=b*c;
        }
        else if(b<p&&b>f)
        {
            if(h>c)
                test[i]=b*h;
            else
                test[i]=(b-f)*h+f*c;
        }
        else
        {
            if(h>c)
                test[i]=h*b;
            else
                test[i]=c*b;
        }
        cout<<test[i];

    }
/*for(int i=0;i<n;i++)
    cout<<test[i];*/
}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    while(t--)
    {
        int b=0,p=0,f=0,h=0,c=0,max_cost=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(h>c)
        {
            if(b>=(f+p))
            {
                test[t]=p*h+f*c;
            }
            else
            {
                test[t]=b*h;

            }

        }
        else
        {
            if(b>=(f+p))
            {
                test[t]=p*h+f*c;
            }
                else
                {
                test[t]=b*f;

                }
        }

    }
    for(int i=0;i<n;i++)
        cout<<test[i];

}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n=t//t=testcase
    cin>>t;
    int test[t];
    while(t--)
    {
        int b=0,p=0,f=0,h=0,c=0,max_cost=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(h>c)
        {
            if(b>=(f+p))
            {
                test[t]=p*h+f*c;
            }
            else
            {
                test[t]=b*h;

            }

        }
        else
        {
            if(b>=(f+p))
            {
                test[t]=p*h+f*c;
            }
                else
                {
                test[t]=b*f;

                }
        }

    }
    for(int i=0;i<n;i++)
        cout<<test[i]<<endl;

}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    for(int i=0;i<n;i++)
    {
        int b=0,p=0,f=0,h=0,c=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(b>=(f+p))
        {
            test[i]=p*h+f*c;
        }
        else if(b>p&&b>f)
        {
            if(h>c)
                test[i]=p*h+(b-f)*c;
            else
                test[i]=(b-p)*h+(f)*c;
        }
        else if(b>p&&b<f)
        {
            if(h>c)
                test[i]=p*h+(b-p)*c;
            else
                test[i]=b*c;
        }
        else if(b<p&&b>f)
        {
            if(h>c)
                test[i]=b*h;
            else
                test[i]=(b-f)*h+f*c;
        }
        else
        {
            if(h>c)
                test[i]=h*p;
            else
                test[i]=c*f;
        }
        cout<<test[i];

    }
/*for(int i=0;i<n;i++)
    cout<<test[i];*/
}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n=t;//t=testcase
    cin>>t;
    int test[t];
    while(t--)
    {
        int b=0,p=0,f=0,h=0,c=0,max_cost=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(h>c)
        {
            if(b>=(f+p))
            {
                test[t]=p*h+f*c;
            }
            else
            {
                test[t]=b*h;

            }

        }
        else
        {
            if(b>=(f+p))
            {
                test[t]=p*h+f*c;
            }
                else
                {
                test[t]=b*f;

                }
        }

    }
    for(int i=0;i<n;i++)
        cout<<test[i]<<endl;

}


#include<iostream>
using namespace std;
int main()
{
    int t,i;
    int n;//t=testcase
    cin>>t;
    n=t;
    int test[t];
    for(int i=0;i<n;i++)
    {
        int b=0,p=0,f=0,h=0,c=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(b>=(f+p))
        {
            test[i]=p*h+f*c;
        }
        else if(b>=p&&b>=f)
        {
            if(h>c)
                test[i]=p*h+(b-f)*c;
            else
                test[i]=(b-p)*h+(f)*c;
        }
        else if(b>=p&&b=<f)
        {
            if(h>c)
                test[i]=p*h+(b-p)*c;
            else
                test[i]=b*c;
        }
        else if(b<=p&&b>=f)
        {
            if(h>c)
                test[i]=b*h;
            else
                test[i]=(b-f)*h+f*c;
        }
        else
        {
            if(h>c)
                test[i]=h*b;
            else
                test[i]=c*b;
        }

    }
for(int i=0;i<n;i++)
    cout<<test[i]<<endl;
}


#include<iostream>
using namespace std;
int main()
{
    int t,i;//t=testcase
    cin>>t;
    while(t--)
    {
        int b=0,p=0,f=0,h=0,c=0,max_cost=0;
        cin>>b>>p>>f;
        cin>>h>>c;
        b=b/2;
        if(h>c)
        {
            if(b>=(f+p))
            {
                max_cost=p*h+f*c;
                cout<<max_cost<<" "<<1;
            }
            else
            {
                max_cost=b*h;
                cout<<max_cost<<" "<<2;
            }

        }
        else
        {
            if(b>=(f+p))
            {
                max_cost=p*h+f*c;
                cout<<max_cost;}
                else
                {
                max_cost=b*f;
                cout<<max_cost;
                }
        }

    }
}


#include<vector>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<algorithm>
#include<utility>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<cstdio>
#include<ctime>
#include<climits>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IO ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define ll long long int
#define nn cout<<"\n"
using namespace std;
int main()
{
	IO;
	int tc;
	cin>>tc;
	while(tc--)
	{
		int b,p,f,h,c,ans=0;
		cin>>b>>p>>f;
		cin>>h>>c;
		b=b/2;
		if(c>=h)
		{
			if(b>=f)
			{
				b=b-f;
				ans+=c*f;
			}
			else
			{
				if(b!=0)
				{
					ans+=c*min(b,f);
					b=b-(min(b,f));
				}
			}
			ans+=min(b,p)*h;
		}
		if(h>c)
		{
			if(b>=p)
			{
				b=b-p;
				ans+=c*p;
			}
			else
			{
				if(b!=0)
				{
					ans+=c*min(b,p);
					b=b-(min(b,p));
				}
			}
			ans+=min(b,f)*h;
		}
		cout<<ans;
		nn;
	}
}


#include<vector>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<algorithm>
#include<utility>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<cstdio>
#include<ctime>
#include<climits>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IO ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define ll long long int
#define nn cout<<"\n"
using namespace std;
int main()
{
	IO;
	int tc;
	cin>>tc;
	while(tc--)
	{
		int b,p,f,h,c,ans=0;
		cin>>b>>p>>f;
		cin>>h>>c;
		b=b/2;
		if(h<c)
		{
			swap(h,c);
			swap(p,f);
		}
		ans+=h*min(b,p);
		b=b-min(b,p);
		ans+=c*min(b,f);
		cout<<ans;
		nn;
	}
}


#include<vector>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<algorithm>
#include<utility>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<cstdio>
#include<ctime>
#include<climits>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IO ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define ll long long int
#define nn cout<<"\n"
using namespace std;
int main()
{
	IO;
	int tc;
	cin>>tc;
	while(tc--)
	{
		int b,p,f,h,c,ans=0;
		cin>>b>>p>>f;
		cin>>h>>c;
		b=b/2;
		if(c>h)
		{
			if(b>f)
			{
				b=b-f;
				ans+=c*f;
			}
			else
			{
				if(b!=0)
				{
					ans+=c*min(b,f);
					b=b-(min(b,f));
				}
			}
			ans+=min(b,p)*h;
		}
		if(h>c)
		{
			if(b>p)
			{
				b=b-p;
				ans+=c*p;
			}
			else
			{
				if(b!=0)
				{
					ans+=c*min(b,p);
					b=b-(min(b,p));
				}
			}
			ans+=min(b,f)*h;
		}
		cout<<ans;
		nn;
	}
}


#include<vector>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<algorithm>
#include<utility>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<cstdio>
#include<ctime>
#include<climits>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IO ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define ll long long int
#define nn cout<<"\n"
using namespace std;
int main()
{
	IO;
	int tc;
	cin>>tc;
	while(tc--)
	{
		int b,p,f,h,c,ans=0;
		cin>>b>>p>>f;
		cin>>h>>c;
		b=b/2;
		if(c>=h)
		{
			if(b>=f)
			{
				b=b-f;
				ans+=c*f;
			}
			else
			{
				if(b!=0)
				{
					ans+=c*min(b,f);
					b=b-(min(b,f));
				}
			}
			ans+=min(b,p)*h;
		}
		if(h>c)
		{
			if(b>=p)
			{
				b=b-p;
				ans+=h*p;
			}
			else
			{
				if(b!=0)
				{
					ans+=h*min(b,p);
					b=b-(min(b,p));
				}
			}
			ans+=min(b,f)*c;
		}
		cout<<ans;
		nn;
	}
}


#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d,e,f,t,g;
    cin>>t;
    while(t--)
    {
        cin>>a>>b>>c;
        cin>>d>>e;

        if((b+c)*2<a)
        {
            cout<<b*d+c*e<<endl;
        }
        else if((b+c)*2>a && a>3)
        {
            f = a/2;
            if(f==1)
                cout<<12<<endl;
            else if(f>1)
                g=f-1;
            cout<<1*10+g*12<<endl;
        }
        else if(a==1)
            cout<<0<<endl;
        else if(a==2 || a==3)
            cout<<12<<endl;
    }

}


#include <iostream>
#include<stdlib.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,d,e,f,t,g,k,l,m,n,o,p;
    cin>>t;
    while(t--)
    {
        cin>>a>>b>>c;
        cin>>d>>e;

        if(d<e)
        {
            swap(d,e);
            swap(b,c);
        }

        if((b+c)*2<a && a>1)
        {
            cout<<b*d+c*e<<endl;
        }
        else if((b+c)*2>a && a>1)
        {
             if(a%2!=0)
                a=a-1;
             if(b*2>a){
                m=a/2;
                n=m*d;
                cout<<n<<endl;
             }

             else if(b*2<=a)
             {
                 o=b*2;
                 p=abs((a-o)/2);
                 cout<<b*d+p*e<<endl;
             }

        }
        else if(a==1)
            cout<<0<<endl;

    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,n;

int main() {
	cin>>n;
	ll a[n],b[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	if(n==1) {
		cout<<0<<endl;
		cout<<a[0];
	} else {
		sort(a,a+n);
		ll x = n/2;
		ll i=0,j=0;
		while(i+x<n){
			b[j]=a[x];j++;
			b[j]=a[i];j++;
			i++;x++;
		}
		if(n%2==1) b[j]=a[x];
		cout<<i<<endl;
		for(int i=0; i<n; i++){
			cout<<b[i]<<" ";
		}
	}
	return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    long long n, a[100500], i, j, tam;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            if (a[i] > a[j])
            {
                tam = a[i];
                a[i] = a[j];
                a[j] = tam;
            }
        }
    }

    cout << (n - 1) / 2 << endl;
    i = 0;
    j = n - 1;
    while (i < j)
    {
        cout << a[j] << " " << a[i] << " ";
        i++;
        j--;
    }
    if (n % 2 == 1)
    {
        cout << a[i];
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    long long n, a[100500],i;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    if (n <= 2) {
        cout << 0 << endl;
    }
    else {
        cout << n/2 << endl;
    }
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    long long n, a[100500],i;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    cout << (n-1)/2 << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    long long n, s, i;
    vector<long long> vct;

    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> s;
        vct.push_back(s);
    }
    sort(vct.begin(), vct.begin() + n);
    cout << (n - 1) / 2 << endl;
    for (i = 0; i < n / 2; i++)
    {
        cout << vct[n-i-1] << " " << vct[i] << " ";
    }

    if (n % 2 == 1)
    {
        cout << vct[i];
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    long long n, s, i, j, tam;
    vector<long long> vct;

    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> s;
        vct.insert(vct.begin()+i, sizeof(long long), s);
    }
    sort(vct.begin(), vct.begin() + n);
    cout << (n - 1) / 2 << endl;
    for (i = 0; i < n / 2; i++)
    {
        cout << vct[n-i-1] << " " << vct[i] << " ";
    }

    if (n % 2 == 1)
    {
        cout << vct[i];
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    long long n, a[100500], i,j,tam;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            if (a[i] > a[j])
            {
                tam = a[i];
                a[i] = a[j];
                a[j] = tam;
            }
        }
    }
    cout << (n - 1) / 2 << endl;
    i = 0;
    j = n - 1;
    while (i < j)
    {
        cout << a[j] << " " << a[i] << " ";
        i++;
        j--;
    }
    if (n % 2 == 1)
    {
        cout << a[i];
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(),(c).end()
#define inf ((ll)1e18+1)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t=1;
    //cin>>t;
        while(t--)
        {
             ll n;
             cin>>n;
             ll a[n];
             ll i;
             for(i=0;i<n;i++)
             {
                 cin>>a[i];
             }
             sort(a,a+n);
             cout<<n/2<<endl;
             if(n<=2)
             continue;
             vector<ll>v(n,-1);
             ll c=0;

             for(i=1;i<n;i+=2)
             {

                 v[i]=a[c];
                 c++;
             }
             for(i=0;i<n;i++)
             {
                 if(v[i]==-1)
                 {

                     v[i]=a[c];
                     c++;
                 }
             }
             for(auto i:v)
             cout<<i<<" ";
             cout<<endl;
        }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(),(c).end()
#define inf ((ll)1e18+1)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t=1;
    //cin>>t;
        while(t--)
        {
             ll n;
             cin>>n;
             ll a[n];
             ll i;
             for(i=0;i<n;i++)
             {
                 cin>>a[i];
             }
             sort(a,a+n);
             cout<<n/2<<endl;
             if(n<=2)
             continue;
             vector<ll>v(n,-1);
             ll c=0;
             if(n%2==1)
             {
                 for(i=1;i<n;i+=2)
                 {
                     v[i]=a[c];
                     c++;
                 }
                 for(i=0;i<n;i++)
                 {
                     if(v[i]==-1)
                     {
                         v[i]=a[c];
                         c++;
                     }
                 }
                 for(auto i:v)
                 cout<<i<<" ";
                 cout<<endl;
             }
             else
            {
                   for(i=0;i<n;i+=2)
                   {
                       v[i]=a[c];
                       c++;

                   }
                   for(i=0;i<n;i++)
                   {
                       if(v[i]==-1)
                       {
                           v[i]=a[c];
                           c++;
                       }
                   }
                 for(auto i:v)
                 cout<<i<<" ";
                 cout<<endl;
             }
        }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(),(c).end()
#define inf ((ll)1e18+1)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t=1;
    //cin>>t;
        while(t--)
        {
             ll n;
             cin>>n;
             ll a[n];
             ll i;
             for(i=0;i<n;i++)
             {
                 cin>>a[i];
             }
             sort(a,a+n);
            ll xx=0;

             vector<ll>v(n,-1);
             ll c=0;
             for(i=1;i<n;i+=2)
             {

                 v[i]=a[c];
                 c++;
             }
             for(i=0;i<n;i++)
             {
                 if(v[i]==-1)
                 {

                     v[i]=a[c];
                     c++;
                 }
             }
             for(i=1;i+1<n;i+=2)
             {
                 if(v[i]<v[i-1]&&v[i]<v[i+1])
                 xx++;
             }
             cout<<xx<<endl;
             for(auto i:v)
             cout<<i<<" ";
             cout<<endl;
        }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(),(c).end()
#define inf ((ll)1e18+1)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t=1;
    //cin>>t;
        while(t--)
        {
             ll n;
             cin>>n;
             ll a[n];
             ll i;
             for(i=0;i<n;i++)
             {
                 cin>>a[i];
             }
             sort(a,a+n);
             cout<<n/2<<endl;
             if(n<=2)
             continue;
             vector<ll>v(n,-1);
             ll c=0;
             if(n%2==1)
             {
                 for(i=1;i<n;i+=2)
                 {
                     v[i+1]=a[c];
                     c++;
                 }
                 for(i=0;i<n;i++)
                 {
                     if(v[i]==-1)
                     {
                         v[i]=a[c];
                         c++;
                     }
                 }
                 for(auto i:v)
                 cout<<i<<" ";
                 cout<<endl;
             }
             else
            {
                   for(i=0;i<n;i+=2)
                   {
                       v[i]=a[c];
                       c++;

                   }
                   for(i=0;i<n;i++)
                   {
                       if(v[i]==-1)
                       {
                           v[i]=a[c];
                           c++;
                       }
                   }
                 for(auto i:v)
                 cout<<i<<" ";
                 cout<<endl;
             }
        }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(),(c).end()
#define inf ((ll)1e18+1)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t=1;
    //cin>>t;
        while(t--)
        {
             ll n;
             cin>>n;
             ll a[n];
             ll i;
             for(i=0;i<n;i++)
             {
                 cin>>a[i];
             }
             sort(a,a+n);
            cout<<(n-1)/2<<endl;
             if(n<=2)
             continue;
             vector<ll>v(n,-1);
             ll c=0;
             if(n%2==1)
             {
                 for(i=1;i<n;i+=2)
                 {
                     v[i]=a[c];
                     c++;
                 }
                 for(i=0;i<n;i++)
                 {
                     if(v[i]==-1)
                     {
                         v[i]=a[c];
                         c++;
                     }
                 }
                 for(auto i:v)
                 cout<<i<<" ";
                 cout<<endl;
             }
             else
            {
                   for(i=0;i<n;i+=2)
                   {
                       v[i]=a[c];
                       c++;

                   }
                   for(i=0;i<n;i++)
                   {
                       if(v[i]==-1)
                       {
                           v[i]=a[c];
                           c++;
                       }
                   }
                 for(auto i:v)
                 cout<<i<<" ";
                 cout<<endl;
             }
        }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(),(c).end()
#define inf ((ll)1e18+1)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t=1;
    //cin>>t;
        while(t--)
        {
             ll n;
             cin>>n;
             ll a[n];
             ll i;
             for(i=0;i<n;i++)
             {
                 cin>>a[i];
             }
             sort(a,a+n);
             cout<<(n-1)/2<<endl;

             vector<ll>v(n,-1);
             ll c=0;
             for(i=1;i<n;i+=2)
             {

                 v[i]=a[c];
                 c++;
             }
             for(i=0;i<n;i++)
             {
                 if(v[i]==-1)
                 {

                     v[i]=a[c];
                     c++;
                 }
             }
             for(auto i:v)
             cout<<i<<" ";
             cout<<endl;
        }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void)
{
        ll n,i,j;
        vector<ll> p,q;
        cin>>n;
        p.push_back(0);
        for(i=0;i<n;i++)
        {
                cin>>j;
                p.push_back(j);
         }
         sort(p.begin(),p.end());
         ll i1=1,j1;
         j1=n/2+1;
         cout<<n/2<<endl;
         for(i=0;i<n;i++)
         {
                if(i%2==0)
                {
                        cout<<p[j1]<<" ";
                        j1++;
                }
                else
                {
                        cout<<p[i1]<<" ";
                        i1++;
                 }
        }
        cout<<endl;}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void)
{
        ll n,i,j;
        vector<ll> p,q;
        cin>>n;
        p.push_back(0);
        for(i=0;i<n;i++)
        {
                cin>>j;
                p.push_back(j);
         }
         sort(p.begin(),p.end());
         ll i1=1,j1;
         j1=n/2+1;
         cout<<(n-1)/2<<endl;
         for(i=0;<<endl;i<n;i++)
         {
                if(i%2==0)
                {
                        cout<<p[j1]<<" ";
                        j1++;
                }
                else
                {
                        cout<<p[i1]<<" ";
                        i1++;
                 }
        }
        cout<<endl;}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void)
{
        ll n,i,j;
        vector<ll> p,q;
        cin>>n;
        p.push_back(0);
        for(i=0;i<n;i++)
        {
                cin>>j;
                p.push_back(j);
         }
         sort(p.begin(),p.end());
         ll i1=1,j1;
         j1=n/2+1;
         for(i=0;i<n;i++)
         {
                if(i%2==0)
                {
                        cout<<p[j1]<<" ";
                        j1++;
                }
                else
                {
                        cout<<p[i1]<<" ";
                        i1++;
                 }
        }
        cout<<endl;}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void)
{
        ll n,i,j;
        vector<ll> p,q;
        cin>>n;
        p.push_back(0);
        for(i=0;i<n;i++)
        {
                cin>>j;
                p.push_back(j);
         }
         sort(p.begin(),p.end());
         ll i1=1,j1;
         j1=n/2+1;
         cout<<n/2<<endl;
         for(i=0;<<endl;i<n;i++)
         {
                if(i%2==0)
                {
                        cout<<p[j1]<<" ";
                        j1++;
                }
                else
                {
                        cout<<p[i1]<<" ";
                        i1++;
                 }
        }
        cout<<endl;}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void)
{
        ll n,i,j;
        vector<ll> p,q;
        cin>>n;
        p.push_back(0);
        for(i=0;i<n;i++)
        {
                cin>>j;
                p.push_back(j);
         }
         sort(p.begin(),p.end());
         ll i1=1,j1;
         j1=n/2+1;
         if(n!=2)
         cout<<n/2<<endl;
         else
         cout<<0<<endl;
         for(i=0;i<n;i++)
         {
                if(i%2==0)
                {
                        cout<<p[j1]<<" ";
                        j1++;
                }
                else
                {
                        cout<<p[i1]<<" ";
                        i1++;
                 }
        }
        cout<<endl;}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void)
{
        ll n,i,j;
        vector<ll> p,q;
        cin>>n;
        p.push_back(0);
        for(i=0;i<n;i++)
        {
                cin>>j;
                p.push_back(j);
         }
         sort(p.begin(),p.end());
         ll i1=1,j1;
         j1=n/2+1;
         cout<<(n-1)/2<<endl;
         for(i=0;i<n;i++)
         {
                if(i%2==0)
                {
                        cout<<p[j1]<<" ";
                        j1++;
                }
                else
                {
                        cout<<p[i1]<<" ";
                        i1++;
                 }
        }
        cout<<endl;}


/// !! Killian !! ///

#include <bits/stdc++.h>
#define Killian "1419D"
#define endl "\n"
#define pii pair <int,int>
#define bit(mask,x) (((mask)>>(x))&1)
using namespace std;
const int MOD=1000000007;

int n;
int a[100005],ans[100005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen(Killian".inp","r",stdin);
//    freopen(Killian".out","w",stdout);
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    if (n<=2)
    {
        cout<<0<<endl;
        for (int i=1; i<=n; i++)
            cout<<a[i]<<" ";
        return 0;
    }
    sort(a+1,a+1+n);
    int l=1,r=n/2,res=0;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (a[mid]<a[mid+1])
        {
            res=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    int pos=2;
    for (int i=1; i<=res; i++)
        ans[pos]=a[i],pos+=2;
    pos=1;
    for (int i=res+1; i<=n; i++)
        ans[pos]=a[i],pos+=2;
    cout<<res<<endl;
    for (int i=1; i<=n; i++)
        cout<<ans[i]<<" ";
}


/// !! Killian !! ///

#include <bits/stdc++.h>
#define Killian "1419D"
#define endl "\n"
#define pii pair <int,int>
#define bit(mask,x) (((mask)>>(x))&1)
using namespace std;
const int MOD=1000000007;

int n;
int a[100005],ans[100005];
int res;

bool check (int cnt)
{
    int remain=n-cnt;
    return (remain>=cnt+1);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 //   freopen(Killian".inp","r",stdin);
//    freopen(Killian".out","w",stdout);
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    int l=0,r=n/2;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (check(mid))
        {
            res=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    cout<<res<<endl;
    if (res==0)
    {
        for (int i=1; i<=n; i++)
            cout<<a[i]<<" ";
        return 0;
    }
    int pos=n;
    for (int i=1; i<=n; i+=2)
        ans[i]=a[pos--];
    for (int i=2; i<=n; i+=2)
        ans[i]=a[pos--];
    for (int i=1;i<=n;i++)
        cout<<ans[i]<<" ";
}


/// !! Killian !! ///

#include <bits/stdc++.h>
#define Killian "1419D"
#define endl "\n"
#define pii pair <int,int>
#define bit(mask,x) (((mask)>>(x))&1)
using namespace std;
const int MOD=1000000007;

int n;
int a[100005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen(Killian".inp","r",stdin);
//    freopen(Killian".out","w",stdout);
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    int l=0,r=n/2,res;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (a[mid]<a[mid+1])
        {
            res=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    cout<<res;
}


/// !! Killian !! ///

#include <bits/stdc++.h>
#define Killian "1419D"
#define endl "\n"
#define pii pair <int,int>
#define bit(mask,x) (((mask)>>(x))&1)
using namespace std;
const int MOD=1000000007;

int n;
int a[100005],ans[100005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 //   freopen(Killian".inp","r",stdin);
//    freopen(Killian".out","w",stdout);
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    if (n<=2)
    {
        cout<<0<<endl;
        for (int i=1; i<=n; i++)
            cout<<a[i]<<" ";
        return 0;
    }
    sort(a+1,a+1+n);
    int l=1,r=n/2,res=0;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (a[mid]<a[mid+1])
        {
            res=mid;
            l=mid+1;
        }
        else
            r=mid;
    }
    int pos=2;
    for (int i=1; i<=res; i++)
        ans[pos]=a[i],pos+=2;
    pos=1;
    for (int i=res+1; i<=n; i++)
        ans[pos]=a[i],pos+=2;
    cout<<res<<endl;
    for (int i=1; i<=n; i++)
        cout<<ans[i]<<" ";
}


/// !! Killian !! ///

#include <bits/stdc++.h>
#define Killian "1419D"
#define endl "\n"
#define pii pair <int,int>
#define bit(mask,x) (((mask)>>(x))&1)
using namespace std;
const int MOD=1000000007;

int n;
int a[100005],ans[100005];
int res;

bool check (int cnt)
{
    int remain=n-cnt;
    return (remain>=cnt+1);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  //  freopen(Killian".inp","r",stdin);
//    freopen(Killian".out","w",stdout);
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    int l=0,r=n/2;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (check(mid))
        {
            res=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    cout<<res<<endl;
    if (res==0)
    {
        for (int i=1; i<=n; i++)
            cout<<a[i]<<" ";
        return 0;
    }
    int pos=2;
    for (int i=1; i<=res; i++)
        ans[pos]=a[i],pos+=2;
    pos=1;
    for (int i=res+1; i<=n; i++)
        ans[pos]=a[i],pos+=2;
    for (int i=1; i<=n; i++)
        cout<<ans[i]<<" ";
}


/// !! Killian !! ///

#include <bits/stdc++.h>
#define Killian "1419D"
#define endl "\n"
#define pii pair <int,int>
#define bit(mask,x) (((mask)>>(x))&1)
using namespace std;
const int MOD=1000000007;

int n;
int a[100005],ans[100005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  //  freopen(Killian".inp","r",stdin);
//    freopen(Killian".out","w",stdout);
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    int l=0,r=n/2,res;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (a[mid]<a[mid+1])
        {
            res=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    int pos=2;
    for (int i=1; i<=res; i++)
        ans[pos]=a[i],pos+=2;
    pos=1;
    for (int i=res+1; i<=n; i++)
        ans[pos]=a[i],pos+=2;
    cout<<res<<endl;
    for (int i=1; i<=n; i++)
        cout<<ans[i]<<" ";
}


/// !! Killian !! ///

#include <bits/stdc++.h>
#define Killian "1419D"
#define endl "\n"
#define pii pair <int,int>
#define bit(mask,x) (((mask)>>(x))&1)
using namespace std;
const int MOD=1000000007;

int n;
int a[100005],ans[100005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen(Killian".inp","r",stdin);
//    freopen(Killian".out","w",stdout);
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    if (n<=2)
    {
        cout<<0<<endl;
        for (int i=1; i<=n; i++)
            cout<<a[i]<<" ";
        return 0;
    }
    sort(a+1,a+1+n);
    int l=1,r=n/2,res=0;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (a[mid]<a[mid+1] && mid>1)
        {
            res=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    int pos=2;
    for (int i=1; i<=res; i++)
        ans[pos]=a[i],pos+=2;
    pos=1;
    for (int i=res+1; i<=n; i++)
        ans[pos]=a[i],pos+=2;
    cout<<res<<endl;
    for (int i=1; i<=n; i++)
        cout<<ans[i]<<" ";
}


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

int main(){

int kiek;
cin>>kiek;

vector<int> ledai;
for(int i = 0 ; i<kiek;i++){
    int x;
    cin>>x;
    ledai.push_back(x);
}

sort(ledai.begin(),ledai.end());
    cout<< (kiek-1) /2  << "\n";
vector<int> ats(kiek);

int j=0;
for(int i=1; i < kiek ;j++,i+=2){
    ats[i]=ledai[j];
}
for(int i=0; i < kiek ;j++,i+=2){
    ats[i]=ledai[j];
}

for(int i=0; i < kiek-1 ;i++){
    cout<<ats[i]<<" ";
}cout<<ats[kiek-1];

return 0;}


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

int main(){

int kiek;
cin>>kiek;

vector<int> ledai;
for(int i = 0 ; i<kiek;i++){
    int x;
    cin>>x;
    ledai.push_back(x);
}
    stack<int> st;
    cout<< (kiek-1) /2  << "\n";

if(kiek % 2 == 0){

    while(ledai.size() == 0){
        st.push(ledai[ledai.size()-1]);
        st.push(ledai[0]);
        ledai.pop_back();
        ledai.erase(ledai.begin());
    }

}else{
    int arr[kiek];
    for(int j = 0; j < kiek ;j++){
        if(j%2 == 0){
            st.push(ledai[ledai.size()-1]);
                    ledai.pop_back();
        }else{
                st.push(ledai[0]);
        ledai.erase(ledai.begin());
        }
    }
}

while(st.size()!=0){
    if(st.size()==1){
        cout<<st.top();
    }else{
        cout<<st.top()<<" ";
    }
st.pop();
}

return 0;}


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

int main(){

int kiek;
cin>>kiek;

vector<int> ledai;
for(int i = 0 ; i<kiek;i++){
    int x;
    cin>>x;
    ledai.push_back(x);
}
    cout<< (kiek-1) /2  << "\n";
vector<int> ats(kiek);

int j=0;
for(int i=1; i < kiek ;j++,i+=2){
    ats[i]=ledai[j];
}
for(int i=0; i < kiek ;j++,i+=2){
    ats[i]=ledai[j];
}

for(int i=0; i < kiek-1 ;i++){
    cout<<ats[i]<<" ";
}cout<<ats[kiek-1];

return 0;}


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

int main(){

int kiek;
cin>>kiek;

vector<int> ledai;
for(int i = 0 ; i<kiek;i++){
    int x;
    cin>>x;
    ledai.push_back(x);
}
    stack<int> st;

if(kiek % 2 == 0){
    cout<< kiek /2 -1 << "\n";

    while(ledai.size() == 0){
        st.push(ledai[ledai.size()-1]);
        st.push(ledai[0]);
        ledai.pop_back();
        ledai.erase(ledai.begin());
    }

}else{
    cout<< kiek /2 << "\n";
    int arr[kiek];
    for(int j = 0; j < kiek ;j++){
        if(j%2 == 0){
            st.push(ledai[ledai.size()-1]);
                    ledai.pop_back();
        }else{
                st.push(ledai[0]);
        ledai.erase(ledai.begin());
        }
    }
}

cout<<st.size()<<endl;

while(st.size()!=0){
    if(st.size()==1){
        cout<<st.top();
    }else{
        cout<<st.top()<<" ";
    }
st.pop();
}

return 0;}


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

int main(){

int kiek;
cin>>kiek;

vector<int> ledai;
for(int i = 0 ; i<kiek;i++){
    int x;
    cin>>x;
    ledai.push_back(x);
}
    stack<int> st;

if(kiek % 2 == 0){
    cout<< kiek /2 -1 << "\n";

    while(ledai.size() == 0){
        st.push(ledai[ledai.size()-1]);
        st.push(ledai[0]);
        ledai.pop_back();
        ledai.erase(ledai.begin());
    }

}else{
    cout<< kiek /2 << "\n";
    int arr[kiek];
    for(int j = 0; j < kiek ;j++){
        if(j%2 == 0){
            st.push(ledai[ledai.size()-1]);
                    ledai.pop_back();
        }else{
                st.push(ledai[0]);
        ledai.erase(ledai.begin());
        }
    }
}

while(st.size()!=0){
    if(st.size()==1){
        cout<<st.top();
    }else{
        cout<<st.top()<<" ";
    }
st.pop();
}

return 0;}


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

int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    ll v=(n-1)/2;
    vector<ll> v1;
    vector<ll> v2;
    for(ll i=0;i<v;i++)
    {
        v1.push_back(arr[i]);
    }
    for(ll i=v;i<n;i++)
    {
        v2.push_back(arr[i]);
        //cout<<arr[i]<<endl;
    }
    ll cnt=0;

    ll g=0,v2g=0,v1g=0;
    vector<ll> v3;
    if(n%2==1)
    {
    for(ll i=0;i<n;i++)
    {
        if(g==0)
        {
            //cout<<v2[v2g]<<endl;
            v3.push_back(v2[v2g]);
            ++g;
            ++v2g;
        }
        else
        {

           // cout<<v1[v1g]<<" ";
            v3.push_back(v1[v1g]);
            --g;
            ++v1g;
        }

    }
}
else
{
    for(ll i=0;i<n-1;i++)
    {
        if(g==0)
        {
            //cout<<v2[v2g]<<endl;
            v3.push_back(v2[v2g]);
            ++g;
            ++v2g;
        }
        else
        {

           // cout<<v1[v1g]<<" ";
            v3.push_back(v1[v1g]);
            --g;
            ++v1g;
        }

    }
    v3.push_back(v2[v2.size()-1]);

}
    for(ll i=1;i<n-1;i=i+2)
    {
        if(v3[i-1]>v3[i] && v3[i+1]>v3[i])
            ++cnt;

    }
    cout<<cnt<<endl;
    for(ll i=0;i<n;i++)
    {
        cout<<v3[i]<<" ";
    }

    return 0;
}


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

int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    ll v=(n-2)/2;
    vector<ll> v1;
    vector<ll> v2;
    for(ll i=0;i<v;i++)
    {
        v1.push_back(arr[i]);
    }
    for(ll i=v;i<n;i++)
    {
        v2.push_back(arr[i]);
        //cout<<arr[i]<<endl;
    }
    ll cnt=0;

    ll g=0,v2g=0,v1g=0;
    vector<ll> v3;
    if(n%2==1)
    {
    for(ll i=0;i<n;i++)
    {
        if(g==0)
        {
            //cout<<v2[v2g]<<endl;
            v3.push_back(v2[v2g]);
            ++g;
            ++v2g;
        }
        else
        {

           // cout<<v1[v1g]<<" ";
            v3.push_back(v1[v1g]);
            --g;
            ++v1g;
        }

    }
}
else
{
    for(ll i=0;i<n-1;i++)
    {
        if(g==0)
        {
            //cout<<v2[v2g]<<endl;
            v3.push_back(v2[v2g]);
            ++g;
            ++v2g;
        }
        else
        {

           // cout<<v1[v1g]<<" ";
            v3.push_back(v1[v1g]);
            --g;
            ++v1g;
        }

    }
    v3.push_back(v2[v2.size()-1]);

}
    for(ll i=1;i<n-1;i=i+2)
    {
        if(v3[i-1]>v3[i] && v3[i+1]>v3[i])
            ++cnt;

    }
    cout<<cnt<<endl;
    for(ll i=0;i<n;i++)
    {
        cout<<v3[i]<<" ";
    }

    return 0;
}


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

int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    ll v=(n-1)/2;
    vector<ll> v1;
    vector<ll> v2;
    for(ll i=0;i<v;i++)
    {
        v1.push_back(arr[i]);
    }
    for(ll i=v;i<n;i++)
    {
        v2.push_back(arr[i]);
        //cout<<arr[i]<<endl;
    }
    ll cnt=0;

    ll g=0,v2g=0,v1g=0;
    vector<ll> v3;
    for(ll i=0;i<n;i++)
    {
        if(g==0)
        {
            v3.push_back(v2[v2g]);
            ++g;
            ++v2g;
        }
        else
        {
           // cout<<v1[v1g]<<" ";
            v3.push_back(v1[v1g]);
            --g;
            ++v1g;
        }

    }
    for(ll i=1;i<n;i=i+2)
    {
        if(v3[i-1]>v3[i] && v3[i+1]>v3[i])
            ++cnt;

    }
    cout<<cnt<<endl;
    for(ll i=0;i<n;i++)
    {
        cout<<v3[i]<<" ";
    }

    return 0;
}


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

int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    ll v=(n-1)/2;
    vector<ll> v1;
    vector<ll> v2;
    for(ll i=0;i<v;i++)
    {
        v1.push_back(arr[i]);
    }
    for(ll i=v;i<n;i++)
    {
        v2.push_back(arr[i]);
        //cout<<arr[i]<<endl;
    }
    ll cnt=0;

    ll g=0,v2g=0,v1g=0;
    vector<ll> v3;
    if(n%2==1)
    {
    for(ll i=0;i<n;i++)
    {
        if(g==0)
        {
            //cout<<v2[v2g]<<endl;
            v3.push_back(v2[v2g]);
            ++g;
            ++v2g;
        }
        else
        {

           // cout<<v1[v1g]<<" ";
            v3.push_back(v1[v1g]);
            --g;
            ++v1g;
        }

    }
}
else
{
    for(ll i=0;i<n-1;i++)
    {
        if(g==0)
        {
            //cout<<v2[v2g]<<endl;
            v3.push_back(v2[v2g]);
            ++g;
            ++v2g;
        }
        else
        {

           // cout<<v1[v1g]<<" ";
            v3.push_back(v1[v1g]);
            --g;
            ++v1g;
        }

    }
    v3.push_back(v2[v2.size()-1]);

}
    for(ll i=1;i<n-1;i=i+2)
    {
        if(v3[i-1]>v3[i] && v3[i+1]>v3[i])
            ++cnt;

    }
    cout<<cnt<<endl;
    for(ll i=0;i<n;i++)
    {
        cout<<v3[i]<<" ";
    }

    return 0;
}


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

int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    ll v=(n)/2;
    vector<ll> v1;
    vector<ll> v2;
    for(ll i=0;i<v;i++)
    {
        v1.push_back(arr[i]);
    }
    for(ll i=v;i<n;i++)
    {
        v2.push_back(arr[i]);
        //cout<<arr[i]<<endl;
    }
    ll cnt=0;

    ll g=0,v2g=0,v1g=0;
    vector<ll> v3;
    if(n%2==1)
    {
    for(ll i=0;i<n;i++)
    {
        if(g==0)
        {
            //cout<<v2[v2g]<<endl;
            v3.push_back(v2[v2g]);
            ++g;
            ++v2g;
        }
        else
        {

           // cout<<v1[v1g]<<" ";
            v3.push_back(v1[v1g]);
            --g;
            ++v1g;
        }

    }
}
else
{
    for(ll i=0;i<n-1;i++)
    {
        if(g==0)
        {
            //cout<<v2[v2g]<<endl;
            v3.push_back(v2[v2g]);
            ++g;
            ++v2g;
        }
        else
        {

           // cout<<v1[v1g]<<" ";
            v3.push_back(v1[v1g]);
            --g;
            ++v1g;
        }

    }
    v3.push_back(v2[v2.size()-1]);

}
    for(ll i=1;i<n-1;i=i+2)
    {
        if(v3[i-1]>v3[i] && v3[i+1]>v3[i])
            ++cnt;

    }
    cout<<cnt<<endl;
    for(ll i=0;i<n;i++)
    {
        cout<<v3[i]<<" ";
    }

    return 0;
}