1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
 
public class backjun_2503_숫자야구 {
 
    static int totalGame ;
    static int ans = 0;
    static numberInfo[] gogo;
    static class numberInfo{
        String number;
        int striker;
        int ball;
        numberInfo(String number, int striker, int ball){
            this.number = number;
            this.striker = striker;
            this.ball = ball;
        }
    }
    static void DFS(int nn, int[] makeNumber, int[] visit) {
        if(nn==3) {
            String makeNumber2string = "";
            for(int i=0; i<makeNumber.length; i++)
                makeNumber2string+=makeNumber[i];
 
            int allSatis = 0;
            for(int i=0; i<gogo.length; i++) {
 
                int strikerCnt = 0;
                int ballNumberCnt = 0;
                //스트라이크, 볼 위치 찾기
 
                for(int j=0; j<gogo[i].number.length(); j++) {
                    if(makeNumber2string.charAt(j) == gogo[i].number.charAt(j)) strikerCnt += 1;
                }
 
                if(makeNumber2string.charAt(0== gogo[i].number.charAt(1||
                        makeNumber2string.charAt(0== gogo[i].number.charAt(2)
                 ) ballNumberCnt +=1;
 
                if(makeNumber2string.charAt(1== gogo[i].number.charAt(0||
                        makeNumber2string.charAt(1== gogo[i].number.charAt(2)
                 ) ballNumberCnt +=1;
 
                if(makeNumber2string.charAt(2== gogo[i].number.charAt(0||
                        makeNumber2string.charAt(2== gogo[i].number.charAt(1)
                 ) ballNumberCnt +=1;
 
                if(gogo[i].ball == ballNumberCnt && gogo[i].striker == strikerCnt)
                    allSatis+=1;
            }
            if(gogo.length == allSatis) ans+=1;
 
        }else {
            for(int i=1; i<=9; i++) {
                if(visit[i] == 0) {
                    visit[i] = 1;
                    makeNumber[nn] = i;
                    DFS(nn+1, makeNumber, visit);
                    visit[i] = 0;
                }
            }
        }
    }
    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        totalGame = Integer.parseInt(br.readLine());
 
        gogo = new numberInfo[totalGame];
        for(int i=0; i<totalGame; i++) { 
                StringTokenizer st = new StringTokenizer(br.readLine());
                gogo[i] = new numberInfo(st.nextToken(),
                                Integer.parseInt(st.nextToken()),
                                Integer.parseInt(st.nextToken())
                        );
        }//end of first loop
 
        int[] makeNumber = new int[3];
        int[] visit = new int[10];
        DFS(0,makeNumber,visit);
        System.out.println(ans);
    }
 
}
cs