<?php
    error_reporting(-1);
    
    $amountCredit = 40000;
	$percent = 0.03;
	$commission = 1000;
	$payment = 5000;
	
	$amountPayment = 0;
	$finalPayment = 0;
	
	for($month = 0; $amountCredit != 0; $month++){
		$amountCredit += $percent*$amountCredit + $commission;
		if ($amountCredit < $payment){
			$amountPayment += $amountCredit;
			$amountCredit -= $amountCredit;
		}else{
			$amountPayment += $payment;
			$amountCredit -= $payment;
		}
	}
	echo "Школьнику айфон обошелся в {$amountPayment} \n";
	echo "Избавился от долга за {$month}";
	
?>