#include <stdio.h>
#include <string.h>

int n, root;
int f[2048];
int lev[2048];
int left[2048];
int right[2048];
int read[2048];
int jury, cont;
FILE *fn;

void rec(int v, int l) {
	lev[v]=l;
	if (left[v]) rec(left[v], l+1);
	if (right[v]) rec(right[v], l+1);
}

int main(void) {
	int i, x, fat;
	char sign;

	fn=fopen("input", "r");
	fscanf(fn, "%d %d", &n, &root);
	for (i=1; i<=n; i++) fscanf(fn, "%d", &f[i]);
	fclose(fn);

	fn=fopen("output", "r");
	fscanf(fn, "%d", &root);
	read[root]=1;
	lev[root]=1;
	for (i=1; i<n; i++) {
		fscanf(fn, "%d %d %c", &x, &fat, &sign);
		read[x]=1;
		if (sign=='<') {
			left[fat]=x;
			lev[x]=lev[fat]+1;
		} else if (sign=='>') {
			right[fat]=x;
			lev[x]=lev[fat]+1;
		}
	}
	fclose(fn);

	for (i=1; i<=n; i++) jury+=f[i]*lev[i];

	for (i=0; i<=n; i++) {
		lev[i]=0;
		left[i]=0;
		right[i]=0;
		read[i]=0;
	}

	scanf("%d", &root);
	if (root<1 || root>n) {
		printf("Invalid root number!\n");
		return 0;
	}
	read[root]=1;
	for (i=1; i<n; i++) {
		if (scanf("%d %d %c", &x, &fat, &sign)!=3) {
			printf("Output file too short!\n");
			return 0;
		}
		if (x<1 || x>n) {
			printf("Invalid node number!\n");
			return 0;
		}
		if (fat<1 || fat>n) {
			printf("Invalid father number!\n");
			return 0;
		}
		if (read[x]) {
			printf("Repeated node!\n");
			return 0;
		}
		read[x]=1;
		if (sign=='<') {
			if (x>=fat) {
				printf("Greater element is on a smaller branch!\n");
				return 0;
			}
			if (left[fat]) {
				printf("Two smaller children of the same node!\n");
				return 0;
			} else {
				left[fat]=x;
			}
		} else if (sign=='>') {
			if (x<=fat) {
				printf("Smaller element is on a greater branch!\n");
				return 0;
			}
			if (right[fat]) {
				printf("Two greater children of the same node!\n");
				return 0;
			} else {
				right[fat]=x;
			}
		} else {
			printf("Invalid sign!\n");
			return 0;
		}
	}
	if (scanf("%d", &i)>0) {
		printf("Output file too long!\n");
		return 0;
	}

	rec(root, 1);

	for (i=1; i<=n; i++) cont+=f[i]*lev[i];

	printf("Jury:  %d\n", jury);
	printf("Contestant:  %d\n", cont);
	if (jury==cont) {
		printf("OK!\n");
	} else if (jury<cont) {
		printf("Tree is NOT optimal!\n");
	} else {
		printf("Jury's pogram is buggy :-(((((((((((((((((((((\n");
	}
	
	return 0;
}
