#include<iostream>
using namespace std;
int main()
{
int mp = 1, n;
for(;n != 1;)
cin >> n;
if((n%3 == 0) && (n > 2))
mp *= n;
}
cout << mp;
return 0;
#include<iostream>
using namespace std;
int main()
{
int mp = 1, n;
for(;n != 1;)
{
cin >> n;
if((n%3 == 0) && (n > 2))
{
mp *= n;
}
}
cout << mp;
return 0;
}