A boy named Vasya wants to play an old Russian solitaire called "Accordion". In this solitaire, the player must observe the following rules:

  * A deck of n cards is carefully shuffled, then all n cards are put on the table in a line from left to right; 
  * Before each move the table has several piles of cards lying in a line (initially there are n piles, each pile has one card). Let's number the piles from left to right, from 1 to x. During one move, a player can take the whole pile with the maximum number x (that is the rightmost of remaining) and put it on the top of pile x - 1 (if it exists) or on the top of pile x - 3 (if it exists). The player can put one pile on top of another one only if the piles' top cards have the same suits or values. Please note that if pile x goes on top of pile y, then the top card of pile x becomes the top card of the resulting pile. Also note that each move decreases the total number of piles by 1; 
  * The solitaire is considered completed if all cards are in the same pile. 



Vasya has already shuffled the cards and put them on the table, help him understand whether completing this solitaire is possible or not. 

Input

The first input line contains a single integer n (1 ≤ n ≤ 52) — the number of cards in Vasya's deck. The next line contains n space-separated strings c1, c2, ..., cn, where string ci describes the i-th card on the table. Each string ci consists of exactly two characters, the first one represents the card's value, the second one represents its suit. Cards on the table are numbered from left to right. 

A card's value is specified by one of these characters: "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A". A card's suit is specified by one of these characters: "S", "D", "H", "C".

It is not guaranteed that the deck has all possible cards. Also, the cards in Vasya's deck can repeat.

Output

On a single line print the answer to the problem: string "YES" (without the quotes) if completing the solitaire is possible, string "NO" (without the quotes) otherwise.

Examples

Input

4
2S 2S 2C 2C


Output

YES


Input

2
3S 2C


Output

NO

Note

In the first sample you can act like that: 

  * put the 4-th pile on the 1-st one; 
  * put the 3-rd pile on the 2-nd one; 
  * put the 2-nd pile on the 1-st one. 



In the second sample there is no way to complete the solitaire.
/* Codeforces Template */

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

import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	
	static long initTime;
	static final Random rnd = new Random(7777L);
	
	public static void main(String[] args) throws IOException {
		initTime = System.currentTimeMillis();
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
//					long prevTime = System.currentTimeMillis();
					new Main().run();
//					System.err.println("Total time: " + (System.currentTimeMillis() - prevTime) + " ms");
//					System.err.println("Memory status: " + memoryStatus());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start(); 
	}

	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
		in.close();
	}
	
	/*************************************************************** 
	 * Solution
	 **************************************************************/

	int n;
	int[] cards;
	Set<Integer> was = new TreeSet<Integer>();
	
	void solve() throws IOException  {
		
		n = nextInt();
		cards = new int [n];
		
		for (int i = 0; i < n; i++) {
			cards[i] = code(nextToken());
		}
		
		boolean ok = false;
		
		if (n <= 3) {
			ok = solveSmall(cards, n);
		} else {
			ok = dfs(n - 4, cards[n - 3], cards[n - 2], cards[n - 1]);
		}
	
		out.println(ok ? "YES" : "NO");
	}
	
	int[] tmp = new int [3];
	
	boolean dfs(int pos, int c1, int c2, int c3) {
	
//		System.err.println(pos + " " + c1 +" " + c2 + " " +c3);
		
		if (pos < 0) {
			tmp[0] = c1;
			tmp[1] = c2;
			tmp[2] = c3;
			return solveSmall(tmp, 3);
		}
		
		int state = codeState(pos, c1, c2, c3);
		
		if (was.contains(state)) {
			return false;
		}
		
		was.add(state);
		
		if (can(c2, c3) && dfs(pos - 1, cards[pos], c1, c3)) {
			return true;
		}
		
		if (can(cards[pos], c3) && dfs(pos - 1, c3, c1, c2)) {
			return true;
		}
		
		return false;
	}

	boolean can(int c1, int c2) {
		return s(c1) == s(c2) || v(c1) == v(c2);
	}

	int codeState(int pos, int c1, int c2, int c3) {
		return ((pos * 52 + c1) * 52 + c2) * 52 + c3;
	}

	boolean solveSmall(int[] cards, int cnt) {
		if (cnt <= 1) return true;
		if (cnt == 2) return can(cards[0], cards[1]);
		return can(cards[2], cards[1]) && can(cards[2], cards[0]); 
	}
	
	int s(int c) {
		return c / 13;
	}
	
	int v(int c) {
		return c % 13;
	}
	
	int code(String s) {
		return vn(s.charAt(0)) + 13 * sn(s.charAt(1));
	}
	
	int sn(char c) {
		if (c == 'S') return 0;
		if (c == 'D') return 1;
		if (c == 'H') return 2;
		if (c == 'C') return 3;
		return -1;
	}
	
	int vn(char c) {
		if ('2' <= c && c <= '9') return (c - '2');
		if (c == 'A') return 8;
		if (c == 'J') return 9;
		if (c == 'Q') return 10;
		if (c == 'K') return 11;
		if (c == 'T') return 12;
		return -1;
	}
	
	/*************************************************************** 
	 * Input 
	 **************************************************************/
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");
	
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	
	int[] nextIntArray(int size) throws IOException {
		int[] ret = new int [size];
		for (int i = 0; i < size; i++)
			ret[i] = nextInt();
		return ret;
	}
	
	long[] nextLongArray(int size) throws IOException {
		long[] ret = new long [size];
		for (int i = 0; i < size; i++)
			ret[i] = nextLong();
		return ret;
	}
	
	double[] nextDoubleArray(int size) throws IOException {
		double[] ret = new double [size];
		for (int i = 0; i < size; i++)
			ret[i] = nextDouble();
		return ret;
	}
	
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
	
	/*************************************************************** 
	 * Output 
	 **************************************************************/
	void printRepeat(String s, int count) {
		for (int i = 0; i < count; i++)
			out.print(s);
	}
	
	void printArray(int[] array) {
		if (array == null || array.length == 0)
			return;
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}
	
	void printArray(long[] array) {
		if (array == null || array.length == 0)
			return;
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}
	
	void printArray(double[] array) {
		if (array == null || array.length == 0)
			return;
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}
	
	void printArray(double[] array, String spec) {
		if (array == null || array.length == 0)
			return;
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.printf(Locale.US, spec, array[i]);
		}
		out.println();
	}
	
	void printArray(Object[] array) {
		if (array == null || array.length == 0)
			return;
		boolean blank = false;
		for (Object x : array) {
			if (blank) out.print(' '); else blank = true;
			out.print(x);
		}
		out.println();
	}
	
	@SuppressWarnings("rawtypes")
	void printCollection(Collection collection) {
		if (collection == null || collection.isEmpty())
			return;
		boolean blank = false;
		for (Object x : collection) {
			if (blank) out.print(' '); else blank = true;
			out.print(x);
		}
		out.println();
	}
	
	/*************************************************************** 
	 * Utility
	 **************************************************************/
	static String memoryStatus() {
		return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB";
	}
	
	static void checkMemory() {
		System.err.println(memoryStatus());
	}
	
	static long prevTimeStamp = Long.MIN_VALUE;
	
	static void updateTimer() {
		prevTimeStamp = System.currentTimeMillis();
	}
	
	static long elapsedTime() {
		return (System.currentTimeMillis() - prevTimeStamp);
	}
	
	static void checkTimer() {
		System.err.println(elapsedTime() + " ms");
	}
}
