#include <bits/stdc++.h>
#include "testlib.h"

using namespace std;

int const MAX_OPS = 1000;
double const MAX_ERROR = 1e-9;

pair<int, double> readAns(InStream& in, int a, int b) {
	double expected = (double) a / b;
	int ops = in.readInt(1, MAX_OPS, "ops");
	double cur = 0;
	// TODO: force computations in doubles
	// ^^^^^^^^^  ok, decided not to force
	for (int i = 1; i <= ops; i++) {
		string op = in.readToken("a?(sin|cos|tan)", format("op[%i]", i));
		if (op == "sin") {
			cur = sin(cur);
		} else if (op == "cos") {
			cur = cos(cur);
		} else if (op == "tan") {
			cur = tan(cur);
		} else if (op == "asin") {
			cur = asin(cur);
		} else if (op == "acos") {
			cur = acos(cur);
		} else if (op == "atan") {
			cur = atan(cur);
		} else {
			in.quitf(_wa, "Wrong function %s", op.c_str());
		}
		if (isnan(cur) || isinf(cur)) {
			in.quitf(_wa, "Result is NaN or +-INF after %d operations", i);
		}	
	}
	double error = fabs(cur - expected);
	if (error > MAX_ERROR) {
		in.quitf(_wa, "Final result is %.10f, expected %.10f, absolute error = %.10f", cur, expected, error);
	}
	return {ops, error};
}

int main(int argc, char* argv[]) {
    registerTestlibCmd(argc, argv);
    int a = inf.readInt();
	int b = inf.readInt();
	
	auto ansOps = readAns(ans, a, b);
	auto partOps = readAns(ouf, a, b);
	quitf(_ok, "OK, a/b = %d/%d, ops = %d, error = %e", a, b, partOps.first, partOps.second);
}