uses testlib, SysUtils;

type 
pair = record                                                                               
	p, a : int64;
end;
	tarr = array[1..10000] of pair;

function isPrime(x : integer) : boolean;
var j : integer;
begin
	if x <= 1 then begin
		result := false;
		exit;
	end;
	j := 2;
	while j * j <= x do begin
		if x mod j = 0 then begin
			isPrime := false;
			exit;
		end;
		inc(j);
	end;
	isPrime := true;
end;

procedure process(var a : tarr; size : integer; x : integer; code: TResult);
var i : integer;
begin
	if x = 0 then begin
		for i := 1 to size do begin
			a[i].a := a[i].a * 2;
		end;
	end
	else begin
		if not isPrime(x) then begin
			quit(code, 'C' + intToStr(x) + 'H' + intToStr(2 * x + 1) + 'OH doesn''t exist');
		end;
		for i := 1 to size do begin
			if a[i].p = x then begin
				if a[i].a = 0 then begin
					break;
				end;
				dec(a[i].a);
				exit;
			end;
		end;
		quit(code, 'Can''t add C' + intToStr(x) + 'H' + intToStr(2 * x + 1) + 'OH');
	end;
end;

function eq(arr : tarr; size : integer; expected : int64) : boolean;
var  
	i, j : integer;
	k : int64;
begin
	k := 1;
	for i := 1 to size do begin
		for j := 1 to arr[i].a do begin
			k := k * arr[i].p;
			if (k > expected) then begin
				result := false;
				exit;
			end;
		end;
	end;
	if (k = expected) then begin
		result := true;
	end
	else result := false;
end;

function tostr(arr : tarr; size : integer; expected : int64) : string;
var  
	i, j : integer;
	k : int64;
begin
	k := 1;
	for i := 1 to size do begin
		for j := 1 to arr[i].a do begin
			k := k * arr[i].p;
			if (k > 1e15) then begin
				result := intToStr(k) + '+';
				exit;
			end;
		end;
	end;
	result := intToStr(k);
end;


procedure decomp(a : int64; var arr : tarr; var size : integer);
var
	i, cnt : integer;
begin
	i := 2;
	size := 0;
	while i * i <= a do begin
		if (a mod i = 0) then begin
			cnt := 0;
			while a mod i = 0 do begin
				inc(cnt);
				a := a div i;
			end;
			inc(size);
			arr[size].p := i;
			arr[size].a := cnt;
		end;
		inc(i);
	end;
	if a <> 1 then begin
		inc(size);
		arr[size].p := a;
		arr[size].a := 1;
	end;
end;

var
	ps, js : string;
	pi, pj, code : longint;
	pcnt, jcnt : longint;
	//np, nj : int64;
	n, m : int64;
	juryFound : boolean;
	aj, ap : tarr;
	sizep, sizej : integer;

begin
	n := inf.readlongint;	
	m := inf.readlongint;
	if ouf.seekeof then begin
		if ans.seekeof then begin
			quit(_ok, 'File is empty');
		end;
		quit(_wa, 'Empty file found');
	end;
	if not ouf.seekeof and ans.seekeof then begin
		quit(_wa, 'Non-empty file found');
	end;
	ps := ouf.readword(blanks, blanks);
	js := ans.readword(blanks, blanks);
	if upperCase(ps) = upperCase('Impossible') then begin
		if upperCase(js) = upperCase('Impossible') then begin
			quit(_ok, 'Impossible');
		end;
		quit(_wa, 'Solution not found');
	end;
	val(ps, pi, code);
	if code <> 0 then begin
		quit(_pe, 'Impossible or number expected, "' + ps + '" found');
	end;
	if upperCase(js) <> upperCase('Impossible') then begin
		val(js, pj, code);
		decomp(n, aj, sizej);
		process(aj, sizej, pj, _fail);
		jcnt := 1;
		while not ans.seekeof do begin
			pj := ans.readLongint;
			process(aj, sizej, pj, _fail);
			inc(jcnt);
		end;
		juryFound := true;
	end
	else begin
		jcnt := 1000;
		juryFound := false;
	end;
	
	decomp(n, ap, sizep);
	process(ap, sizep, pi, _wa);
	pcnt := 1;
	while not ouf.seekeof do begin
		pi := ouf.readLongint;
		process(ap, sizep, pi, _wa);
		inc(pcnt);
		if pcnt > jcnt then begin
			quit(_wa, 'Contestant solution too large');
		end;                                                                                    			
	end;
	if not eq(ap ,sizep, m) then begin
		quit(_wa, 'Made ' + tostr(ap ,sizep, m) + ' bacteria, but ' + inttostr(m) + ' needed');
	end;
	if not juryFound then begin
		quit(_fail, 'Contestant found solution');
	end;
	if not eq(aj ,sizej, m) then begin
		quit(_fail, 'Made ' + tostr(aj ,sizej, m) + ' bacteria, but ' + inttostr(m) + ' needed');
	end;
	if pcnt < jcnt then begin
		quit(_fail, 'Contestant found better solution');
	end;
	if pcnt > jcnt then begin
		quit(_wa, 'Jury has better solution');
	end;
	quit(_ok, inttostr(pcnt) + ' operations');	
end.
