#include <iostream>
#include <string>
using namespace std;
bool isMatch(string s, string p);
int main(void)
{
bool check;
string re, in;
//cout<<"Enter Regular Expression and Input: ";
cin>>re>>in;
check=isMatch(in,re);
if(check==true)
cout<<"ACCEPT";
else if(check==false)
cout<<"REJECT";
return 0;
}
bool isMatch(string input, string regex)
{
if (regex.empty()) return input.empty();
if (regex[1] != '*')
{
if(input[0] == regex[0] || (regex[0] == '.' && input[0] != '\\0'))
return isMatch(input.substr(1), regex.substr(1));
else
return false;
}
else
{
if (isMatch(input, regex.substr(2)))
return true;
int index = 0;
while (index < input.size() && (input[index] == regex[0] || regex[0] == '.'))
{
if (isMatch(input.substr(++index), regex.substr(2)))
return true;
}
return false;
}
}