import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class cube_sm_wrong5 {
	final int wrong = Integer.parseInt(""
			+ this.getClass().getName().charAt(
					this.getClass().getName().length() - 1)); // Line 85

	class Point {
		int[] a;

		public Point(int x, int y, int z) {
			a = new int[3];
			a[0] = x;
			a[1] = y;
			a[2] = z;
		}

		boolean on(Point[] p) {
			for (int i = 0; i < 3; i++) {
				if (p[0].a[i] - a[i] != a[i] - p[1].a[i])
					return false;
			}
			return true;
		}

		@Override
		public boolean equals(Object obj) {
			Point p = (Point) obj;
			for (int i = 0; i < 3; i++) {
				if (a[i] != p.a[i])
					return false;
			}
			return true;
		}
	}

	Map<String, Point> coord = new HashMap<String, Point>() {
		{
			put("A", new Point(0, 0, 0));
			put("B", new Point(0, 2, 0));
			put("C", new Point(2, 2, 0));
			put("D", new Point(2, 0, 0));
			put("A1", new Point(0, 0, 2));
			put("B1", new Point(0, 2, 2));
			put("C1", new Point(2, 2, 2));
			put("D1", new Point(2, 0, 2));
		}
	};

	Point[] intresting = { new Point(0, 1, 1), new Point(2, 1, 1),
			new Point(1, 0, 1), new Point(1, 2, 1), new Point(1, 1, 0),
			new Point(1, 1, 2), new Point(1, 1, 1) };

	Point[] toPoints(String s) {
		Point[] res = new Point[2];
		if (Character.isDigit(s.charAt(1))) {
			res[0] = coord.get(s.substring(0, 2));
			s = s.substring(2);
		} else {
			res[0] = coord.get(s.substring(0, 1));
			s = s.substring(1);
		}
		res[1] = coord.get(s);
		return res;
	}

	private void solve() throws IOException {
		System.err.println(wrong);
		Point[] s1 = toPoints(br.readLine());
		Point[] s2 = toPoints(br.readLine());
		for (int i = 0; i < s1.length; i++) {
			for (int j = 0; j < s2.length; j++) {
				if (s1[i].equals(s2[j])) {
					out.println("YES");
					return;
				}
			}
		}
		for (int i = 0; i < intresting.length; i++) {
			if (i == wrong)
				continue;
			Point p = intresting[i];
			if (p.on(s1) && p.on(s2)) {
				out.println("YES");
				return;
			}
		}
		out.println("NO");

	}

	boolean isEquals(int... a) {
		for (int i = 1; i < a.length; i++) {
			if (a[i] != a[0])
				return false;
		}
		return true;
	}

	void myAssert(boolean b) {
		if (!b)
			throw new AssertionError();
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	public void run() {
		try {
			br = new BufferedReader(new FileReader("cube.in"));
			out = new PrintWriter("cube.out");
			solve();
			out.close();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}

	}

	int nextInt(int a, int b) {
		int x = Integer.parseInt(nextToken());
		if (x < a || x > b)
			throw new AssertionError();
		return x;
	}

	String nextToken() {
		try {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		} catch (IOException e) {
			return "0";
		}
	}

	public static void main(String[] args) {
		new cube_sm_wrong5().run();
	}
}
