Courier Rank
Difficulty: Hard

CourierRank is a very famous and well established company in the market and well known for transporting products with minimum cost for their customers. Your friend chandu works at CourierRank and is facing a problem these days. You being an excellent programmer and his friend. He asks you to help him with the problem.  

Problem requires to deliver N couriers(Assume each courier to be identical) to N locations in the city with two kinds of delivery options:  

- A Big Truck: It can carry any number of boxes to any location in the city for cost L dollars.  
- A Small Car: It costs R dollars for delivering 1 box to a location 1 unit away.  

For the sake of simplicity, Let us assume that:  
1) The whole city is located on a single straight road.  
2) The distance between consecutive cities is 1 unit.  
3) All the couriers are placed exactly 1 unit distance before the first location.  

Help your friend chandu, Finding the minimum cost for delivering the couriers.  

**Input**  
First line of input contains three integers N,L,R seperated by space, Where N is the number of Boxes, L and R are as described above.
Second line of input contains N integers seperated by space which are the locations where ith box needs to be couriered.

**Output**  
Output contains a single integer, which the minimum possible cost(in dollars) for delivering all the boxes to their respective locations.

**Constraints**  
1<=N<=100  
1<=L,R<=100000  
1<=location of box <= 10^6  

**Sample Input**  

    5 82456 74095
    761 685761 43 138742 8650
    
**Sample Output**

	412280

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <ctime>

// STL
#define pb push_back
#define LL long long
#define ULL unsigned long long
#define L long
#define VCTP vector<pair<LL,LL> >
#define PII pair<LL,LL>
#define PDD pair<double,double>
#define F first
#define S second


// Useful constants
#define INF                         (int)1e9
#define EPS                         1e-9

// Useful hardware instructions
#define bitcount                    __builtin_popcount
#define gcd                         __gcd

// Useful container manipulation / traversal macros
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair

// Some common useful functions
#define maX(a,b)                     ( (a) > (b) ? (a) : (b))
#define miN(a,b)                     ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)                ( (n >> b) & 1)
#define DREP(a)                      sort(all(a)); a.erase(unique(all(a)),a.end())
#define INDEX(arr,ind)               (lower_bound(all(arr),ind)-arr.begin())



#define st_clk double st=clock();
#define end_clk double en=clock();
#define show_time cout<<"\tTIME="<<(en-st)/CLOCKS_PER_SEC<<endl;

#define rd readInt()
#define sc(n) scanf("%d",&n)
#define scst(n) scanf("%s",n)
#define f_in(st) freopen(st,"r",stdin);
#define f_out(st) freopen(st,"w",stdout);

using namespace std;

inline int readInt(){
	long int n = 0, c = gc(), f = 1;
	while(c != '-' && (c < '0' || c > '9')) c = gc();
	if(c == '-') f = -1, c = gc();
	while(c >= '0' && c <= '9')
	n = (n<<3) + (n<<1) + c - '0', c = gc();
	return n * f;
}

/*
Problem can be solved using Dynamic programming. Solution is based on a tricky observation that optimal solution won't ever use truck to deliver
courier to a location where no courier is destined to be.
Reason: Let us say many couriers are taken by truck to position i and none of it was actually destined for there. let x be the couriers that should be moved
forward for their destined location and y be the couriers which should be moved backward for their destined location. 
Case I: x > y, then we can use truck to deliver at location i+1 for more optimal result.
Case II: y > x, then we can use truck to deliver at location i-1 for more optimal result.
case III: x == y,  then we can use truck to deliver at any of the two locations for more optimal result.
*/

long long dp[102][102];

int findcost(vector<int> bb,int tc,int _lc){
     int n = bb.size();
     long long ans = 0;
     long long lc = _lc;
     for(int i=0;i<n;i++) ans+=bb[i]*lc;
     sort(bb.begin(),bb.end());
     memset(dp,63,sizeof(dp));
     for(int i=0;i<n;i++){
	     dp[i][1] = tc;
	     for(int j=0;j<i;j++)
	     	dp[i][1] += min(bb[j],bb[i]-bb[j])*lc;
	 long long t = dp[i][1];
	 for(int j=i+1;j<n;j++) t+=(bb[j]-bb[i])*lc;
	 ans = min(ans,t);
	 for(int j=2;j<=i+1;j++) {
	    for(int k=0;k<i;k++){
		   t = dp[k][j-1] + tc;
		   for(int l=k+1;l<i;l++) t+=min(bb[l]-bb[k],bb[i]-bb[l])*lc;
		   dp[i][j] = min(dp[i][j],t);
		}
		t = dp[i][j];
		for(int k=i+1;k<n;k++) t+=(bb[k]-bb[i])*lc;
		ans = min(ans,t);
	 }
  }
  return int(ans);
}

int main()
{
     #ifndef ONLINE_JUDGE
     f_in("10.in")
	 f_out("10.out");
     #endif
	 int N,LC,RC;
     scanf("%d%d%d",&N,&LC,&RC);
     vector<int> boxes;
     for(int i=0;i<N;i++) {int temp; scanf("%d",&temp); boxes.push_back(temp); }
     printf("%d\n",findcost(boxes,LC,RC));
	return 0;
}