#include <stdio.h>
#include <math.h>
int gcd(int a, int b)
{
int r;
while (a % b != 0)
{
r = a % b;
a = b;
b = r;
}
return b;
}
int leaked(int a)
{
if (a > 2147483647)
return 1;
else
return 0;
}
int value(int type, int width, int height, int length)
{
int checktype = 0;
int ref[] = {82, 79, 47, 29, 26, 22};
for (int i = 0; i < 6; i++)
if (type == ref[i])
checktype = 1;
if (!checktype)
return -1;
if (width < 0 || height < 0 || length < 0)
return -2;
int ab = gcd(width, height);
int gcd_3 = gcd(ab, length);
int val
= type
* width
* height
* length
* pow(gcd_3
, 3); return val;
}
int main()
{
int a, b, c, d;
scanf("%d %d %d %d", &a
, &b
, &c
, &d
);
printf("%d\n", value
(a
, b
, c
, d
));
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgppbnQgZ2NkKGludCBhLCBpbnQgYikKewogICAgaW50IHI7CiAgICB3aGlsZSAoYSAlIGIgIT0gMCkKICAgIHsKICAgICAgICByID0gYSAlIGI7CiAgICAgICAgYSA9IGI7CiAgICAgICAgYiA9IHI7CiAgICB9CiAgICByZXR1cm4gYjsKfQoKaW50IGxlYWtlZChpbnQgYSkKewogICAgaWYgKGEgPiAyMTQ3NDgzNjQ3KQogICAgICAgIHJldHVybiAxOwogICAgZWxzZQogICAgICAgIHJldHVybiAwOwp9CgppbnQgdmFsdWUoaW50IHR5cGUsIGludCB3aWR0aCwgaW50IGhlaWdodCwgaW50IGxlbmd0aCkKewogICAgaW50IGNoZWNrdHlwZSA9IDA7CiAgICBpbnQgcmVmW10gPSB7ODIsIDc5LCA0NywgMjksIDI2LCAyMn07CiAgICBmb3IgKGludCBpID0gMDsgaSA8IDY7IGkrKykKICAgICAgICBpZiAodHlwZSA9PSByZWZbaV0pCiAgICAgICAgICAgIGNoZWNrdHlwZSA9IDE7CiAgICBpZiAoIWNoZWNrdHlwZSkKICAgICAgICByZXR1cm4gLTE7CiAgICBpZiAod2lkdGggPCAwIHx8IGhlaWd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