- 가능한 모든 경우의 수에서 소거해나가기
/* 1. ball은 strike를 제외한 경우를 생각할 것 */
/* 2. 문제 잘 읽기 -> 서로 다른 수를 힌트로 제공 */
#include <iostream>
#include <string>
#include <queue>
#include <string.h>
using namespace std;
int N;
queue<string> q;
string hint, candidate;
int strikes, balls;
bool vst[10];
void bf() {
if (candidate.size() == 3) {
q.push(candidate);
return;
}
for (int i = 1; i <= 9; ++i) {
if (vst[i]) continue;
vst[i] = true; /* 2 */
candidate.push_back(i + '0');
bf();
candidate.pop_back();
vst[i] = false; /* 2 */
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N;
bf();
while (N--) { // 숫자를 듣기
cin >> hint >> strikes >> balls;
memset(vst, 0, sizeof(vst));
for (auto digit : hint) {
vst[digit - '0'] = true;
}
int qs = q.size();
while (qs--) { // 후보를 살피기
string candidate = q.front();
q.pop();
// strikes
int ctr = 0;
for (int i = 0; i < 3; ++i) {
if (hint[i] == candidate[i]) {
++ctr;
}
}
if (strikes != ctr) continue;
// balls
ctr = 0;
for (int i = 0; i < 3; ++i) {
if (vst[candidate[i] - '0'] && hint[i] != candidate[i]) { /* 1 */
++ctr;
}
}
if (balls != ctr) {
continue;
}
q.push(candidate);
}
}
cout << q.size();
return 0;
}