#include int main() { int pocet, konto; int pole[70000]; scanf("%d", &pocet); while(pocet != 0) { scanf("%d", &konto); for(int i = 0; i < pocet; i++) { scanf("%d", &pole[i]); } int max, min; int r_max = 40001; int profit = 0; int a_profit = 0; int a_i = 0; do { min = 40001; max = 0; a_profit = 0; for(int i = pocet - 1; i >= a_i; i--) { if(pole[i] > max && pole[i] < r_max) { max = pole[i]; a_i = i; } } for(int i = 0; i <= a_i; i++) { if(pole[i] < min) { min = pole[i]; } } printf("max %d min %d\n", max, min); if( max >= min ) { a_profit = (konto / min) * max - konto + (konto % min); } if(a_profit > profit) profit = a_profit; r_max = max; } while( max*konto >= profit && a_i != pocet - 1 ); printf("%d\n", profit); scanf("%d", &pocet); } return 0; }