#include #include #include #include #include #include #include int main(){ int n; scanf("%d",&n); int *calories = malloc(sizeof(int) * n); for(int calories_i = 0; calories_i < n; calories_i++){ scanf("%d",&calories[calories_i]); } // where magic happens long int miles = 0; //sorting the calories array in ascending order for(int i =0; i < n - 1; i++) for(int j = 0; j < n - i - 1; j++) { if(calories[j] < calories[j+1]) { int temp = calories[j]; calories[j] = calories[j+1]; calories[j+1] = temp; } } //applying the mathematical formula for the problem for(int i = 0; i < n; i++) { miles = miles + (calories[i] * pow(2,i)); } printf("%ld",miles); return 0; }