import java.util.HashSet;
public class NumberBaseball {
public int solution(int[][] baseball) {
int answer = 0;
for (int ele = 123; ele <= 987; ele++) {
HashSet<String> set = new HashSet<>();
for(int f = 0; f < 3; f++) {
set.add(Integer.toString(ele).charAt(f) + "");
}
if(set.size() != 3 || set.contains("0")) {
continue;
}
for (int i = 0; i < baseball.length; i++) {
int strike = 0, ball = 0;
for (int j = 0; j < 3; j++) {
if ((ele + "").charAt(j) == (baseball[i][0] + "").charAt(j)) {
strike++;
}
}
for (int x = 0; x < 3; x++) {
char temp = (ele + "").charAt(x);
for (int y = 0; y < 3; y++) {
if (temp == (baseball[i][0] + "").charAt(y)) {
ball++;
}
}
}
ball -= strike;
if (strike != baseball[i][1] || ball != baseball[i][2]) {
break;
}
if (i == baseball.length - 1) {
answer++;
}
}
}
return answer;
}
public static void main(String[] args) {
NumberBaseball s = new NumberBaseball();
int[][] baseball = { { 123, 1, 1 }, { 356, 1, 0 }, { 327, 2, 0 }, { 489, 0, 1 } };
System.out.println(s.solution(baseball));
}
}