// Задача "Куб"
// XVII командный чемпионат школьников Санкт-Петербурга по программированию
// Автор задачи: Михаил Дворкин
// Автор решения: Сергей Поромов, poromov@rain.ifmo.ru

import java.io.*;
import java.util.*;

public class cube_sp_wrong implements Runnable {

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

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			br = new BufferedReader(new FileReader(FILENAME + ".in"));
			out = new PrintWriter(FILENAME + ".out");
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	BufferedReader br;

	PrintWriter out;

	StringTokenizer st;

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(br.readLine());
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	void myAssert(boolean e, String s) {
		if (!e) {
			throw new Error("Assertion failure " + s);
		}
	}

	void inBounds(int x, int l, int r, String s) {
		myAssert(l <= x && x <= r, "Wrong value of " + s);
	}

	private static final String FILENAME = "cube";

	class Point {
		int x, y, z;

		Point(String s) {
			if ("A".equals(s)) {
				x = 0;
				y = 0;
				z = 0;
			} else if ("A1".equals(s)) {
				x = 0;
				y = 0;
				z = 1;
			} else if ("B".equals(s)) {
				x = 1;
				y = 0;
				z = 0;
			} else if ("B1".equals(s)) {
				x = 1;
				y = 0;
				z = 1;
			} else if ("C".equals(s)) {
				x = 1;
				y = 1;
				z = 0;
			} else if ("C1".equals(s)) {
				x = 1;
				y = 1;
				z = 1;
			} else if ("D".equals(s)) {
				x = 0;
				y = 1;
				z = 0;
			} else if ("D1".equals(s)) {
				x = 0;
				y = 1;
				z = 1;
			} else {
				myAssert(true, "Wrong string");
			}
		}

		@Override
		public boolean equals(Object o) {
			if (o instanceof Point) {
				Point p = (Point) o;
				return (x == p.x && y == p.y && z == p.z);
			}
			return false;
		}
	}

	class Box {
		int x1, y1, z1, x2, y2, z2;

		Box(Point a, Point b) {
			x1 = Math.min(a.x, b.x);
			x2 = Math.max(a.x, b.x);
			y1 = Math.min(a.y, b.y);
			y2 = Math.max(a.y, b.y);
			z1 = Math.min(a.z, b.z);
			z2 = Math.max(a.z, b.z);
		}

		@Override
		public boolean equals(Object o) {
			if (o instanceof Box) {
				Box p = (Box) o;
				return (x1 == p.x1 && y1 == p.y1 && z1 == p.z1 && 
						x2 == p.x2 && y2 == p.y2 && z2 == p.z2);
			}
			return false;
		}
	}

	public void solve() throws IOException {
		String s1 = nextToken();
		String s2 = nextToken();
		Point a = new Point((s1.indexOf("1") == 1) ? s1.substring(0, 2) : s1
				.substring(0, 1));
		Point b = new Point(s1.substring(s1.indexOf("1") == 1 ? 2 : 1));
		Point c = new Point((s2.indexOf("1") == 1) ? s2.substring(0, 2) : s2
				.substring(0, 1));
		Point d = new Point(s2.substring(s2.indexOf("1") == 1 ? 2 : 1));
		myAssert(!(a.equals(c) && b.equals(d)), "Equal segments");
		myAssert(!(a.equals(d) && b.equals(c)), "Equal segments");
		if (a.equals(c) || b.equals(c) || a.equals(d) || b.equals(d)) {
			out.println("Yes");
			return;
		}
		Box b1 = new Box(a, b);
		Box b2 = new Box(c, d);
//		if (b1.equals(b2)) {
//			out.println("Yes");
//			return;
//		}
		out.println("No");
	}
}
