#include<iostream>
using namespace std;
const double prices[] =
{ 55.39, 109.23, 48.29, 81.59, 81.58, 105.53, 94.45, 12.24 };
bool mark[8] ;
const int size = 8 ;
const char * act[] = {"\tbuy 1" , "\tsell all" , "\tpass"} ;
int main() {
for (int i = size - 1 , v = size - 1 ; ~i ; -- i)
if (prices[i] >= prices[v])
mark[v = i] = true ;
double cost = 0.0 , earned = 0.0;
int ntickets = 0 ;
for (int i = 0 ; i < size ; ++ i) {
if (mark[i]) {
if (ntickets) {
earned += ntickets * prices[i] - cost ;
ntickets = 0 ;
cost = 0 ;
cout << prices[i] << act[1] << endl ;
} else cout << prices[i] << act[2] << endl ;
} else {
cout << prices[i] << act[0] << endl ;
cost += prices[i] ;
ntickets ++ ;
}
}
cout << endl << "Totally earned: " << earned << endl ;
return 0;
}