#include <iostream>
using namespace std;
int main()
{
int c,p,ga,po=0,cat,s=0,rest;
cout<<"Capete: ";cin>>c;
cout<<endl;
cout<<"Picioare: ";cin>>p;
for(int i=c;i<=p;i+=c)
{
cat=i; s++;
if(cat+c>p)
break;
}
rest=p-cat;
if(cat==4)
po+=c;
if(cat==2)
ga+=c;
if(cat>4)
{
for(int d=2;d<=cat/2;d++)
if(cat%d==0)
{
cat/=d;d=2;}
if(cat==4)
po+=c;
if(cat==2)
ga+=c;
}
if(rest==4)
po++;
if(rest==2)
ga++;
if(rest>4)
{
for(int d=2;d<=rest/2;d++)
if(rest%d==0)
{
rest/=d;d=2;}
if(rest==4)
po++;
if(rest==2)
ga++;
}
cout<<endl;
cout<<"Gaini si porci=";
cout<<ga<<' '<<po;
}