import locale locale.setlocale(locale.LC_ALL,'') while 1: A=[*map(float,input().split())] if A[0]==-1:break s=int(A[3]) del A[3] k=3 print('Month ' + str(s) + ' cost: $', end="") while 1: if s-1<=2: print(locale.format('%.2f',A[s-1],1));break else: A.append(round(A[k-3]*A[k-2]/A[k-1],2)) if s-1==k: print(locale.format('%.2f',A[k],1));break else:k+=1
5.23 5.50 5.52 4 5.23 5.50 5.52 2 2177.58 2713.7 433.11 1 2177.58 2713.7 433.11 2 2177.58 2713.7 433.11 3 1.00 1.00 300.00 4 2730.09 857.91 1657.49 23 1848.88 834.74 883.96 8 2139.59 1673.18 789.1 92 842.52 754.73 546.37 12 1661.62 583.08 2523.7 21 2323.23 446.56 1063.87 13 1609.55 2688.56 2446.8 6 1412.92 1182.61 1684.15 8 1474.11 1717.61 1474.11 34 685.29 2890.05 1655.34 54 2337.99 2490.45 618.13 11 1828.85 2307.46 892.15 20 1827.48 1325.26 1379.61 6 1952.23 2778.66 1247.81 84 551.16 780.3 2581.95 8 1652.54 2998.47 595.65 58 2117.78 1434.75 2304.84 81 308.16 2750.43 827.52 51 1583.25 172.82 1244.89 24 -1
Month 4 cost: $5.21 Month 2 cost: $5.50 Month 1 cost: $2,177.58 Month 2 cost: $2,713.70 Month 3 cost: $433.11 Month 4 cost: $0.00 Month 23 cost: $11.28 Month 8 cost: $7,637.98 Month 92 cost: $357,991,898.40 Month 12 cost: $6,580.54 Month 21 cost: $108,439.07 Month 13 cost: $21.42 Month 6 cost: $1,163.40 Month 8 cost: $698.31 Month 34 cost: $1,717.61 Month 54 cost: $0.01 Month 11 cost: $3.02 Month 20 cost: $1,475,522.79 Month 6 cost: $2,325.39 Month 84 cost: $542,457,751.68 Month 8 cost: $7.59 Month 58 cost: $495,509,353.86 Month 81 cost: $62,535.51 Month 51 cost: $227,603,337.36 Month 24 cost: $2,433.23