#include <iostream>#include <cstdio>usingnamespacestd;
constintN=8192;
doublem[N];
intmonth, number;
doublepayment, loan;
boolinput();
voidsolve();
intmain()
{
#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endifwhile (input()) {
solve();
}
return0;
}
boolinput()
{
cin>>month>>payment>>loan>>number;
if (month<0) returnfalse;
intj=0;
for (inti=0; i<number; i++) {
intk;
doublex;
cin>>k>>x;
for (; j<k; j++) {
m[j] =m[j-1];
}
m[j++] =x;
}
for (; j<=month; j++) {
m[j] =m[j-1];
}
returntrue;
}
voidsolve()
{
doubletotal=loan+payment;
doublep=loan/ (double)month;
total*= (1-m[0]);
inti;
for (i=0; i<month; i++) {
if (loan<total) break;
total*= (1-m[i+1]);
loan-=p;
}
cout<<i<<" month"<< (i!=1?"s" : "") <<endl;
}