import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author kontris */ public class Raining { /** * @param args the command line arguments */ private static boolean found = false; private static int poc; public static void main(String[] args) throws IOException { // TODO code application logic here BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); String line; String[] poleS; while ((line = input.readLine()) != null) { found = false; int[][] arr = new int[13][4]; poleS = line.split(" "); String card; poc = 0; for (int i = 1; i < poleS.length; i++) { card = poleS[i]; //System.out.println(card); int znak = 0; //System.out.println(card.charAt(1)); switch (card.charAt(1)) { case 'C': znak = 0; break; case 'D': znak = 1; break; case 'H': znak = 2; break; case 'S': znak = 3; break; } int typ = 0; switch (card.charAt(0)) { case 'A': typ = 0; break; case '2': typ = 1; break; case '3': typ = 2; break; case '4': typ = 3; break; case '5': typ = 4; break; case '6': typ = 5; break; case '7': typ = 6; break; case '8': typ = 7; break; case '9': typ = 8; break; case 'X': typ = 9; break; case 'J': typ = 10; break; case 'Q': typ = 11; break; case 'K': typ = 12; break; } poc++; arr[typ][znak]++; } for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[0].length; j++) { // System.out.print(arr[i][j]+" "); if (arr[i][j] > 0) { arr[i][j]--; rek(i, j, arr,1); arr[i][j]++; } } // System.out.println(""); } if(found){ System.out.println("YES"); }else{ System.out.println("NO"); } } } private static void rek(int row, int col, int[][] arr, int layer) { if(layer == poc)found = true; if(found)return; for (int i = 0; i < arr.length; i++) { if (arr[i][col] > 0) { arr[i][col]--; rek(i, col, arr,layer+1); arr[i][col]++; } if(found)return; } for (int j = 0; j < arr[0].length; j++) { if (arr[row][j] > 0) { arr[row][j]--; rek(row, j, arr, layer+1); arr[row][j]++; } if(found)return; } } }