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.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Properties;
import java.util.Stack;

/**
 * Works good for CF
 * @author cykeltillsalu
 */
public class D130 {

	//some local config
	static boolean test = false;
	static String testDataFile = "testdata.txt";
	static String feedFile = "feed.txt";
	CompetitionType type = CompetitionType.CF;
	private static String ENDL = "\n";

	class S {
		int[] cards;

		public S(int[] cards) {
			this.cards = cards;
		}

		@Override
		public String toString() {
			return "S [cards=" + Arrays.toString(cards) + "]";
		}
	}
	
	// solution
	private void solve() throws Throwable {
		works = false;
		int n = iread();
		int[] card = new int[n];
		cache = new boolean[53][53][53][53];
		
		for (int i = 0; i < n; i++) {
			String wread = wread();
			int val = toSuite(wread.charAt(1) + "") + toValue(wread.charAt(0));
			card[i] = val;
		}
		
		rec(card, n - 1);
		if(works){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		out.flush();
	}
	
	private int toValue(char c) {
		switch (c) {
		case 'T':
			return 10;
		case 'J':
			return 11;
		case 'Q':
			return 12;
		case 'K':
			return 0;
		case 'A':
			return 1;
			
		}
		return c - '0';
	}

	boolean[][][][] cache;
	boolean works = false;
	
	
	private void rec(int[] card, int i) {
		int cnt = 0;
		for (int j = card.length-1; j >= 0; j--) {
			if(card[j] >= 0){
				cnt ++;
			}
			if(cnt > 1){
				break;
			}
		}
		if(cnt == 1){
			works = true;
			return;
		}
		if(i <= 0){
			return;
		}
		if(card[i] == -1 && i > 0){
			rec(card, i-1);
		}
		if(i >= 2){
			if(cache[i][card[i]+1][card[i-1]+1][card[i-2]+1]){
				return;
			}
			cache[i][card[i]+1][card[i-1]+1][card[i-2]+1] = true;
		}
		
		int suiteA = suite(card[i]);
		int valueA = value(card[i]);
		if(i >= 3){
			int suiteB = suite(card[i-3]);
			int valueB = value(card[i-3]);
			if(suiteA == suiteB || valueA == valueB){
				int tmp = card[i];
				int tmp2 = card[i-3];
				card[i-3] = card[i];
				card[i] = -1;
				rec(card, i-1);
				card[i-3] = tmp2;
				card[i] = tmp;
			}
		}
		
		if(suiteA == suite(card[i-1]) || valueA == value(card[i-1])){
			int tmp = card[i];
			int tmp2 = card[i-1];
			card[i-1] = card[i];
			card[i] = -1;
			rec(card, i-1);
			card[i-1] = tmp2;
			card[i] = tmp;
		}
	}

	private int value(int i) {
		return i - suite(i)*13;
	}

	private int suite(int i) {
		return (i/13);
	}

	private int toSuite(String string) {
		if(string.equals("S")){
			return 0;
		}
		if(string.equals("D")){
			return 13*1;
		}
		if(string.equals("H")){
			return 13*2;
		}
		if(string.equals("C")){
			return 13*3;
		}
		return 0;
	}

	public int iread() throws Exception {
		return Integer.parseInt(wread());
	}

	public double dread() throws Exception {
		return Double.parseDouble(wread());
	}

	public long lread() throws Exception {
		return Long.parseLong(wread());
	}

	public String wread() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) throws Throwable {
		
		if(test){ //run all cases from testfile:
			BufferedReader testdataReader = new BufferedReader(new FileReader(testDataFile));
			String readLine = testdataReader.readLine();
			int casenr = 0;
			out: while (true) {
				BufferedWriter w = new BufferedWriter(new FileWriter(feedFile));
				if(!readLine.equalsIgnoreCase("input")){
					break;
				}
				while (true) {
					readLine = testdataReader.readLine();
					if(readLine.equalsIgnoreCase("output")){
						break;
					}
					w.write(readLine + "\n");
				}
				w.close();
				System.out.println("Answer on case "+(++casenr)+": ");
				
				new D130().solve();
				System.out.println("Expected answer: ");
				
				
				while (true) {
					readLine = testdataReader.readLine();
					
					if(readLine == null){
						break out;
					}
					if(readLine.equalsIgnoreCase("input")){
						break;
					}
					System.out.println(readLine);
				}
				System.out.println("----------------");
			}
			testdataReader.close();
		} else { // run on server
			new D130().solve();
		}
		out.close();
	}

	public D130() throws Throwable {
		if (test) {
			in = new BufferedReader(new FileReader(new File(feedFile)));
		}
	}

	InputStreamReader inp = new InputStreamReader(System.in);
	BufferedReader in = new BufferedReader(inp);
	static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
	
	enum CompetitionType {CF, OTHER};
}