mosquito.cpp
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int a[3];
int b[3];
int N;
while(scanf("%i %i %i %i %i %i %i",&a[0],&a[1],&a[2],&b[0],&b[1],&b[2], &N)==7)
{
int z = N % 3;
int x = a[z];
int y2 = b[1] * b[2];
int y1 = b[0];
for (int i = z; i>=1; i--)
{
x = x / b[i];
}
int d;
if ((y1 != 0) && (N >= 3))
{
if (y1 > y2)
{
d = y1 / y2;
if (d != 1)
x = x * (d * (N / 3));
}
if (y1 < y2)
{
d = y2 / y1;
if (d != 1)
x = x / (d * (N / 3));
}
}
else
{
if ( N >= 3)
x = 0;
}
printf("%i\n",x);
}
return 0;
}