#include <bits/stdc++.h>
using namespace std;
struct Card {
  int value;
  char suit;
} cards[60];
bool dp[60][60][60][60];
int gaps[2] = {1, 3};
bool check(int x, int y) {
  if (cards[x].value == cards[y].value) return true;
  if (cards[x].suit == cards[y].suit) return true;
  return false;
}
int get_value(char ch) {
  if (ch <= '9') return ch -= '0';
  if (ch == 'T') return 10;
  if (ch == 'J') return 11;
  if (ch == 'Q') return 12;
  if (ch == 'K') return 13;
  if (ch == 'A') return 1;
}
bool have_ans(int now) {
  bool finds;
  for (int i = 1; i < now; i++) {
    finds = false;
    for (int j = 1; j <= now; j++) {
      if (i == j) continue;
      if (check(i, j)) {
        finds = true;
        break;
      }
    }
    if (!finds) return false;
  }
  return true;
}
bool dfs(int now, int a, int b, int c) {
  if (dp[now][a][b][c]) return false;
  if (now == 1) return true;
  if (check(a, b))
    if (dfs(now - 1, a, c, now - 3)) return true;
  ;
  if (now - 3 > 0 && check(a, now - 3))
    if (dfs(now - 1, b, c, a)) return true;
  dp[now][a][b][c] = true;
  return false;
}
int main() {
  int n;
  scanf("%d", &n);
  memset(dp, false, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    char card_info[5];
    scanf("%s", card_info);
    cards[i].value = get_value(card_info[0]);
    cards[i].suit = card_info[1];
  }
  if (have_ans(n))
    printf(dfs(n, n, n - 1, n - 2) ? "YES\n" : "NO\n");
  else
    puts("NO\n");
  return 0;
}

### Prompt

Create a solution in cpp for the following problem:

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.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct Card {
  int value;
  char suit;
} cards[60];
bool dp[60][60][60][60];
int gaps[2] = {1, 3};
bool check(int x, int y) {
  if (cards[x].value == cards[y].value) return true;
  if (cards[x].suit == cards[y].suit) return true;
  return false;
}
int get_value(char ch) {
  if (ch <= '9') return ch -= '0';
  if (ch == 'T') return 10;
  if (ch == 'J') return 11;
  if (ch == 'Q') return 12;
  if (ch == 'K') return 13;
  if (ch == 'A') return 1;
}
bool have_ans(int now) {
  bool finds;
  for (int i = 1; i < now; i++) {
    finds = false;
    for (int j = 1; j <= now; j++) {
      if (i == j) continue;
      if (check(i, j)) {
        finds = true;
        break;
      }
    }
    if (!finds) return false;
  }
  return true;
}
bool dfs(int now, int a, int b, int c) {
  if (dp[now][a][b][c]) return false;
  if (now == 1) return true;
  if (check(a, b))
    if (dfs(now - 1, a, c, now - 3)) return true;
  ;
  if (now - 3 > 0 && check(a, now - 3))
    if (dfs(now - 1, b, c, a)) return true;
  dp[now][a][b][c] = true;
  return false;
}
int main() {
  int n;
  scanf("%d", &n);
  memset(dp, false, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    char card_info[5];
    scanf("%s", card_info);
    cards[i].value = get_value(card_info[0]);
    cards[i].suit = card_info[1];
  }
  if (have_ans(n))
    printf(dfs(n, n, n - 1, n - 2) ? "YES\n" : "NO\n");
  else
    puts("NO\n");
  return 0;
}

```