Problem:
虫食い算
足し算は筆算で簡単に計算できますが、もし、いくつかの数字が欠けていたら、欠けている数字を埋めるのは簡単でしょうか？ 例えば、以下のような筆算において、１から９の数字が一度しか現れないという条件があるとき、ＣとＥのマスに入る数字はいくつになるでしょう？ この場合、Ｃに入るのは８，Ｅに入るのは５が正解となります。このように、数字がいくつか欠けている演算を虫食い算と呼びます。
１から９の数字が一度しか現れないという条件はそのままで、以下のようにもっとたくさんの数字が欠けていたら、正解となる数字の埋め方は一通りしかないのでしょうか？ 実は、必ず一通りに決まるとは限りません。
上の図のような形をした虫食い算の、ＡからＩの各マスの情報が与えられたとき、正しい埋め方が何通りあるかを出力するプログラムを作成せよ。
Input
入力は以下の形式で与えられる。
A
B
C
D
E
F
G
H
I
１行に、虫食い算の
Ａ
から
Ｉ
のマスに入っている数字の情報が与えられる。ただし、与えられた値が -1 のときは、そのマスの数字が欠けていることを表す。-1 以外の値は、1 から 9 の整数のいずれかで、それらの間に重複はない。
Output
正しい埋め方が何通りあるかを１行に出力する。
Sample Input 1
7 6 -1 1 -1 9 2 3 4
Sample Output 1
1
Sample Input 2
7 6 5 1 8 9 2 3 4
Sample Output 2
0
Sample Input 3
-1 -1 -1 -1 -1 -1 8 4 6
Sample Output 3
12
Sample Input 4
-1 -1 -1 -1 -1 -1 -1 -1 -1
Sample Output 4
168

Submitted solutions:

code_snippet: #include<bits/stdc++.h>

using namespace std;

#define rep(i, l, n) for(int i = int(l); i < int(n); i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template<class T> bool chmin(T &a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T &a, T b) {if(a < b) {a = b; return true;} return false;}
template<class T> using spq = priority_queue<T, vector<T>, greater<T>>;

// bool -> Yes/No
string answer(bool b) {return b ? "Yes" : "No";}

void fix(int k) {cout << fixed << setprecision(k);}

const int inf = 2e9;
const long long INF = 2e18;
const long double eps = 1e-12;
const long double pi = acos(-1);
int dx[] = {0, -1, 0, 1, -1, -1, 1, 1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int num[4][3];

int judge(int i, int j, int k) {
    int sum = i + j + k;
    if(sum >= 1000) return 0;
    string s[4];
    s[0] = to_string(i); s[1] = to_string(j);
    s[2] = to_string(k); s[3] = to_string(sum);
    int cnt[10];
    rep(i, 0, 10) cnt[i] = 0;
    rep(t, 0, 4) {
        int len = min(3, t + 1);
        rep(m, 0, len) {
            int c = s[t][m] - '0';
            if(c == 0) return 0;
            if(num[t][m] != -1 && num[t][m] != c) return 0;
            cnt[c]++;
            if(cnt[c] > 1) return 0;
        }
    }
    return 1;
}

void main_program() {
    cin >> num[0][0] >> num[1][0] >> num[1][1];
    cin >> num[2][0] >> num[2][1] >> num[2][2];
    cin >> num[3][0] >> num[3][1] >> num[3][2];
    int ans = 0;
    rep(i, 1, 10) rep(j, 10, 100) rep(k, 100, 1000) {
        ans += judge(i, j, k);
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    //cin >> T;
    while(T--) {
        main_program();
    }
}
accuracy: 1
time_ms: 130
memory_kb: 3528
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
int answer=0;
void judge(int a[],set<int> b,int d){
    while(d<9&&a[d]!=-1){
        d+=1;
    }
    if(d!=9){
    for(auto p:b){
        set<int> b2=b;
        a[d]=p;
        b2.erase(p);
        judge(a,b2,d+1);
        a[d]=-1;
    }
    }else{
        if(a[0]+a[1]*10+a[2]+a[3]*100+a[4]*10+a[5]==a[6]*100+a[7]*10+a[8]){
            answer+=1;
        }
    }
    return;
}
int main(void){
    int a[9];
    set<int> b;
    for(int i=0;i<9;i+=1){
        b.insert(i+1);
    }
    for(int i=0;i<9;i+=1){
        cin>>a[i];
        if(a[i]!=-1){
            b.erase(a[i]);
        }
    }
    judge(a,b,0);
    cout<<answer<<endl;
}
accuracy: 1
time_ms: 60
memory_kb: 3436
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(a) a.begin(),a.end()


void yn(bool n)
{
	if(n)
	{
		cout<<"yes"<<endl;
	}
	else
	{
		cout<<"no"<<endl;
	}
	return;
}


int main()
{
	auto all_in=vector<int>();
	for(int i=0; i<9; i++)
	{
		int a;
		cin>>a;
		all_in.push_back(a);
	}

	auto unused=vector<int>();
	for(int i=1; i<=9; i++)
	{
		bool cnt=true;
		for(int t=0; t<10; t++)
		{
			if(all_in[t]==i)
			cnt=false;
		}
		if(cnt)
		{
			unused.push_back(i);
		}
	}
	int ans=0;
	do
	{
		auto ijiru=all_in;
		for(int i=0; i<unused.size(); i++)
		{
			for(int t=0; t<9; t++)
			{
				if(ijiru[t]==-1)
				{
					ijiru[t]=unused[i];
					break;
				}
			}
		}
		int sum=ijiru[0]+ijiru[1]*10+ijiru[2]+ijiru[3]*100+ijiru[4]*10+ijiru[5];
		if(sum==ijiru[6]*100+ijiru[7]*10+ijiru[8])
		{
			ans++;
		}
	}while(next_permutation(all(unused)));
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3440
final_rank: 14

code_snippet: #include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807

int n[9];

int solve(int now, vector<int> m, vector<bool> b){
    if(now == 9){
        if(m[0] + 10*m[1]+m[2] +100*m[3]+10*m[4]+m[5] == 100*m[6]+10*m[7]+m[8]) return 1;
        return 0;
    }
    if(n[now] != -1) return solve(now+1, m, b);

    int re = 0;
    for(int i=0; i<9; i++){
        if(b[i] == true) continue;
        b[i] = true;
        m[now] = i+1;
        re += solve(now+1, m, b);
        b[i] = false;
        m[now] = -1;
    }
    return re;
}

int main(){
    
    vector<int> m;
    vector<bool> b;
    for(int i=0; i<9; i++) b.push_back(false);

    for(int i=0; i<9; i++){
        cin >> n[i];
        m.push_back(n[i]);
        if(n[i] != -1) b[n[i]-1] = true;
    }

    cout << solve(0, m, b) << endl;
    
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3172
final_rank: 12

code_snippet: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int z[9], cnt = 0;
    int a, b, c, d, e, f, g, h, i;

    for(int k = 0; k < 9; k++) cin >> z[k];

    for(a = 1; a <= 9; a++){
        if(z[0] == -1 || z[0] == a){
            for(b = 1; b <= 9; b++){
                if((z[1] == -1 || z[1] == b) && a != b){
                    for(c = 1; c <= 9; c++){
                        if((z[2] == -1 || z[2] == c) && c != a && c != b){
                            for(d = 1; d <= 9; d++){
                                if((z[3] == -1 || z[3] == d) && d != a && d != b && d != c){
                                    for(e = 1; e <= 9; e++){
                                        if((z[4] == -1 || z[4] == e) && e != a && e != b && e != c && e != d){
                                            for(f = 1; f <= 9; f++){
                                                if((z[5] == -1 || z[5] == f) && f != a && f != b && f != c && f != d && f != e){
                                                    for(g = 1; g <= 9; g++){
                                                        if((z[6] == -1 || z[6] == g) && g != a && g != b && g != c && g != d && g != e && g != f){
                                                            for(h = 1; h <= 9; h++){
                                                                if((z[7] == -1 || z[7] == h) && h != a && h != b && h != c && h != d && h != e && h != f && h != g){
                                                                    for(i = 1; i <= 9; i++){
                                                                        if((z[8] == -1 || z[8] == i) && i != a && i != b && i != c && i != d && i != e && i != f && i != g && i != h){
                                                                            int p[9];
                                                                            p[0] = a;
                                                                            p[1] = b;
                                                                            p[2] = c;
                                                                            p[3] = d;
                                                                            p[4] = e;
                                                                            p[5] = f;
                                                                            p[6] = g;
                                                                            p[7] = h;
                                                                            p[8] = i;
                                                                            sort(p, p + 8);
                                                                            if(p[0] != p[1] && p[1] != p[2] && p[2] != p[3] && p[3] != p[4] && p[4] != p[5] && p[5] != p[6] && p[6] != p[7] && p[7] != p[8]){
                                                                                if((a + c + f + b * 10 + e * 10 + d * 100) == (i + h * 10 + g * 100)) cnt++;
                                                                            }

                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout << cnt << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3168
final_rank: 10

code_snippet: #include <iostream>
using namespace std;

int num[10];
int a = 0;

int dfs(int i) {
	if (i == 9) {
		int s[10] = {};
		for (int j = 0; j < 9; j++) {
			s[num[j]]++;
			if (s[num[j]] > 1) return 0;
		}
	
		int a = num[0];
		int b = num[1] * 10 + num[2];
		int c = num[3] * 100 + num[4] * 10 + num[5];
		int d = num[6] * 100 + num[7] * 10 + num[8];
		
		if (a + b + c == d) return 1;
		else return 0;
	}
	
	int d = 0;
	
	if (num[i] != -1) {
		d += dfs(i + 1);
	}
	else {
		for (int j = 1; j < 10; j++) {
			num[i] = j;
			d += dfs(i + 1);
		}
		num[i] = -1;
	}
	
	return d;
}

int main() {
	
	for (int i = 0; i < 9; i++) {
		cin >> num[i];
		if (num[i] == -1) a++;
	}
	
	if (a == 9) {
		cout << 168 << endl;
	}
	else {
		cout << dfs(0) << endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 3096
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;

int A[9];
int B[9];

bool check(int* arr){
	return arr[0] + arr[2] + arr[5] + (arr[1] + arr[4])*10 + arr[3]*100 == arr[6]*100 + arr[7]*10 + arr[8];
}

int perm(vector<int> v,vector<int> idx,int* arr,int ans=0){
	if(v.empty()){
		if(check(arr)){
			return ans + 1;
		}
		else{
			return ans;
		}
	}
	for(int i = 0; i < v.size(); i++){
		arr[idx[idx.size()-1]] = v[i];
		vector<int> idx2 = idx;
		vector<int> v2 = v;
		idx2.pop_back();
		v2.erase(v2.begin()+i);
		ans = perm(v2,idx2,arr,ans);
	}
	return ans;
}

int main(){
	vector<int> v = vector<int>(9);
	vector<int> idx = vector<int>();
	for(int i = 0; i < 9; i++){
		v[i] = i+1;
	}
	for(int i = 0; i < 9; i++){
		cin >> A[i];
		B[i] = A[i];
		if(A[i] != -1){
			for(int j = 0; j < v.size(); j++){
				if(v[j] == A[i]){
					v.erase(v.begin()+j);
					break;
				}
			}
		}
		else{
			idx.push_back(i);
		}
	}
	cout << perm(v,idx,B) << endl;

	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3156
final_rank: 13

code_snippet: #include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
int a[9], used[9], ans = 0;

void calc() {
  int _p = a[0]+a[2]+a[5], p =_p%10; // 1
  int _q = _p/10+a[1]+a[4], q = _q%10; // 10
  int _r = _q/10+a[3], r = _r%10; // 100
  if (p==a[8] && q==a[7] && r==a[6]) ans++;
}

void dfs(int x) {
  if (x == 9) {
    calc();
  } else if (a[x] != -1) {
    dfs(x+1);
  } else {
    for(int i=0;i<9;i++){
      if(used[i]==1) continue;
      used[i]=1, a[x]=i+1;
      dfs(x+1);
      used[i]=0, a[x]=-1;
    } 
  }
}

signed main() {
  for (int i = 0; i < 9; i++) {
    cin >> a[i];
    if (a[i] != -1) used[a[i]-1]=1;
  }
  dfs(0);
  cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3120
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
int a[10];
int num[10];
int cnt;
bool flag(){
  for(int i=0;i<9;i++){
    if(a[i]==-1) return false;
  }
  return true;
}
void dfs(int k){
  for(int i=k;i<9;i++){
    if(a[i]==-1){
      for(int j=1;j<10;j++){
	if(num[j]==0){
	  a[i]=j;
	  num[j]=1;
	  dfs(i);
	  num[j]=0;
	  a[i]=-1;
	}
      }
    }
    if(i==8 && flag()){
      if(a[0]+a[1]*10+a[2]+a[3]*100+a[4]*10+a[5]==a[6]*100+a[7]*10+a[8]){
	//cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<" "<<a[5]<<" "<<a[6]<<" "<<a[7]<<" "<<a[8]<<endl;
	cnt++;
      }
    }
  }
}
      
int main(){
  for(int i=0;i<9;i++){
    cin>>a[i];
    num[a[i]]=1;
  }
  dfs(0);
  cout<<cnt<<endl;
  return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 3120
final_rank: 18

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> V;
typedef pair<ll,ll> P;
typedef map<ll,ll> M;

#define REP(i,n) for(ll (i) = 0; (i) < (n); ++(i))


int main(){
    V v(9);
    for(auto& x : v)
        cin >> x;

    int flag = 0;
    for(auto& x : v)
        if(x != -1)
            flag |= (1<<x);
    V nouse;
    REP(i,10)
        if(i != 0 && (flag & (1<<i)) == 0)
            nouse.push_back(i);


    V nouse2;
    REP(i,9)if(v[i] == -1)nouse2.push_back(i);

    ll ans = 0;

    V iot(nouse.size());
    iota(iot.begin(), iot.end(), 0);
    do{
        V values(9);
        REP(i,9)
            if(v[i] != -1)
                values[i] = v[i];

        REP(i, nouse.size()){
            values[nouse2[i]] = nouse[iot[i]];
        }

        int val = values[0] + values[2] + values[5] - values[8];
        val += 10 * (values[1] + values[4] - values[7]);
        val += 100 * (values[3] - values[6]);

        if(!val)
            ++ans;

    }while(next_permutation(iot.begin(), iot.end()));

    cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3148
final_rank: 8

code_snippet: #include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807

int n[9];

int solve(int now, vector<int> m, vector<bool> b){
    if(now == 9){
        if(m[0] + 10*m[1]+m[2] +100*m[3]+10*m[4]+m[5] == 100*m[6]+10*m[7]+m[8]) return 1;
        return 0;
    }
    if(n[now] != -1) return solve(now+1, m, b);

    int re = 0;
    for(int i=0; i<9; i++){
        if(b[i] == true) continue;
        b[i] = true;
        m[now] = i+1;
        re += solve(now+1, m, b);
        b[i] = false;
        m[now] = -1;
    }
    return re;
}

int main(){
    
    vector<int> m;
    vector<bool> b;
    for(int i=0; i<9; i++) b.push_back(false);

    for(int i=0; i<9; i++){
        cin >> n[i];
        m.push_back(n[i]);
        if(n[i] != -1) b[n[i]-1] = true;
    }

    cout << solve(0, m, b) << endl;
    
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3168
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    vector<int> v(9);
    for(int i = 0; i < 9; ++i) {
        cin >> v[i];
    }

    function<int(int)> solve = [&] (int i) {
        int res = 0;
        if(i == 6) {
            int r = v[0] + 10 * v[1] + v[2] + 100 * v[3] + 10 * v[4] + v[5];
            bool b = true;
            vector<int> cnt(10);
            for(int j = 0; j < 6; ++j) {
                cnt[v[j]] += 1;
            }
            for(int j = 0; j < 3; ++j) {
                int d = r % 10;
                r /= 10;
                b &= (d == v[8 - j] || v[8 - j] == -1) && d != 0;
                cnt[d] += 1;
            }
            res = b & (r == 0) & (*max_element(begin(cnt), end(cnt)) <= 1);
        } else {
            if(v[i] == -1) {
                for(int d = 1; d <= 9; ++d) {
                    v[i] = d;
                    res += solve(i + 1);
                    v[i] = -1;
                }
            } else {
                res = solve(i + 1);
            }
        }
        return res;
    };

    cout << solve(0) << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3104
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<string,string> Pss;
const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int f[MAX_N]={};
int b[MAX_N]={};
bool dp[MAX_N]={};
vector<Pss> Vs,Vs2;

int main() {
	int a,b,c,d,e,f,g,h,i;
	int total=0;
	cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
	rep(j,1000000){
		int j1=j;
		int f1=j1%10;
		j1/=10;
		int e1=j1%10;
		j1/=10;
		int d1=j1%10;
		j1/=10;
		int c1=j1%10;
		j1/=10;
		int b1=j1%10;
		int a1=j1/10;
		int r=a1+c1+b1*10+d1*100+e1*10+f1;
		int g1=r/100;
		int i1=r%10;
		int h1=(r/10)%10;
		if(a!=a1&&a>0)continue;
		if(b!=b1&&b>0)continue;
		if(c!=c1&&c>0)continue;
		if(d!=d1&&d>0)continue;
		if(e!=e1&&e>0)continue;
		if(f!=f1&&f>0)continue;
		if(g!=g1&&g>0)continue;
		if(h!=h1&&h>0)continue;
		if(i!=i1&&i>0)continue;

		int s[9]={a1,b1,c1,d1,e1,f1,g1,h1,i1};
		sort(s,s+9);
		bool flg=true;
		rep(k,9){
			if(s[k]!=k+1)flg=false;
		}
		if(flg)total++;
	}
	cout<<total<<endl;
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3120
final_rank: 9

code_snippet: #include <stdio.h>
#define rep(i, n) for(int i = 0; i < n; ++i)

int count, flag[10], a[9];

int saiki(int n) {
  int i;
  if(n == 10) {
    if((a[0] + a[2] + a[5]) + (a[1] + a[4]) * 10 + a[3] * 100 == a[8] + a[7] * 10 + a[6] * 100) ++count;
    return 0;
  }
  if(a[n] != -1) saiki(n + 1);
  else {
    for(i = 1; i <= 9; ++i) {
      if(flag[i]) {
        flag[i] = 0, a[n] = i;
        saiki(n + 1);
        flag[i] = 1, a[n] = -1;
      }
    }
  }
  return 0;
}

int main(void) {
  int i, j, k;
  count = 0;
  rep(i, 9) scanf("%d", &a[i]);
  rep(i, 10) flag[i] = 1;
  rep(i, 9) if(a[i] != -1) flag[a[i]] = 0;
  saiki(0);
  printf("%d\n", count);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2748
final_rank: 1

code_snippet: #include<iostream>
#include<vector>
using namespace std;
int crossnum[]{1,10,1,100,10,1,100,10,1};
int u,d;
void addnum(int place,int add){
	if(place<6){
		u+=add;
	}else{
		d+=add;
	}
}
void input(vector<int> &line,vector<int> &used){
	line.resize(9);
	used.resize(10,false);
	u=d=0;
	for(int i=0;i<9;++i){
		cin>>line[i];
		if(line[i]>0){
			used[line[i]]=true;
			addnum(i,line[i]*crossnum[i]);
		}
	}
}

int func(int place,vector<int> &line,vector<int> &used){
	if(place==9){
		return u==d?1:0;
	}
	int res=0;
	if(line[place]>0){
		return func(place+1,line,used);
	}
	for(int i=1;i<used.size();++i){
		if(used[i]){
			continue;
		}
		addnum(place,i*crossnum[place]);
		used[i]=true;
		res+=func(place+1,line,used);
		used[i]=false;
		addnum(place,-i*crossnum[place]);
	}
	return res;
}
int main(){
	vector<int> line;
	vector<int> used;
	input(line,used);
	cout<<func(0,line,used)<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3060
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int tt[10];
int cou = 0;

void solve(int i, string num, string str) {
  if(i == 9) {
    int a = (char)(str[0] - 48);
    int b = (char)(str[1] - 48);
    int c = (char)(str[2] - 48);
    int d = (char)(str[3] - 48);
    int e = (char)(str[4] - 48);
    int f = (char)(str[5] - 48);
    int g = (char)(str[6] - 48);
    int h = (char)(str[7] - 48);
    int ii = (char)(str[8] - 48);

    if((a + c + f) % 10 != ii) return;
    int t = (a + c + f) / 10;
    if((b + e + t) % 10 != h) return;
    t = (b + e + t) / 10;
    if((d + t) == g) {
      cou++;
      return;
    }
  }
  if(tt[i] != -1) {
    if(num[tt[i] - 1] == '0') {
      num[tt[i] - 1] = '1';
      solve(i + 1, num, str + (char)(48 + tt[i]));
    }
  }else {
    for(int j = 0; j < 9; j++) {
      if(num[j] == '0') {
        num[j] = '1';
        solve(i + 1, num, str + (char)(48 + j + 1));
        num[j] = '0';
      }
    }
  }
}

int main() {
  rep(i, 0, 9) cin >> tt[i];
  solve(0, "000000000", "");
  cout << cou << endl;
}
accuracy: 1
time_ms: 80
memory_kb: 3220
final_rank: 15

code_snippet: #include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int num[9],per[9],ans = 0;
	for(int i = 0;i < 9;i++) {
		cin >> num[i];
		per[i] = i + 1;
	}
	do{
		bool flag = true;
		for(int i = 0;i < 9;i++){
			if(num[i] != -1 && per[i] != num[i]) flag = false;
		}
		if((per[0] + per[2] + per[5]) % 10 != per[8]) flag = false;
		if(((per[0] + per[2] + per[5]) / 10 + per[1] + per[4]) % 10 != per[7]) flag = false;
		if(((per[0] + per[2] + per[5]) / 10 + per[1] + per[4]) / 10 + per[3] != per[6]) flag = false;
		if(flag) ans++;
	}while(next_permutation(per,per + 9));
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3092
final_rank: 4

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	vector<int>v(9);
	{
		for (int i = 0; i < 9; ++i)cin >> v[i];
	}
	vector<int>perms(9);
	iota(perms.begin(), perms.end(), 0);
	int ans = 0;
	do {
		vector<int>nums(9);
		for (int i = 0; i < 9; ++i) {
			nums[perms[i]] = i+1;
		}
		bool flag = true;
		for (int i = 0; i < 9; ++i) {
			if (v[i] != -1 && v[i] != nums[i])flag = false;
		}
		if (!flag)continue;
		int aa = (nums[0] + nums[2] + nums[5]) * 1+ (nums[1] + nums[4]) * 10 + nums[3] * 100;
		int bb = (nums[8]) * 1 + (nums[7]) * 10 + (nums[6]) * 100;
		if (aa == bb)ans++;
	} while (next_permutation(perms.begin(), perms.end()));
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3088
final_rank: 3

code_snippet: #include<iostream>
#include<cstdio>
using namespace std;
int a[10]={},b[10]={},c=1,cnt=0,j;

void d( ){
  if(c==10&&b[7]*100+b[8]*10+b[9]==b[4]*100+(b[5]+b[2])*10+b[1]+b[3]+b[6]){
    cnt++;
    return;
  }
  if(b[c]!=0){
    c++;
    d();
    c--;
    return;
  }
  for(int i=1;i<=9;i++){
    if(a[i]==0){
      a[i]++;
      b[c]=i;
      c++;
      d();
      a[i]--;
      c--;
      b[c]=0;
    }
  }
  
}

int main(){
  int n;
  for(int i=1;i<10;i++){
    cin>>n;
    if(n>0){
      a[n]++;
      b[i]=n;
    }
  }
  d();
  cout<<cnt<<endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3112
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=1;i<=n;i++)
int main(){
int z[9],sum=0;
for(int i=0;i<9;i++)cin>>z[i];
r(a,9)if(z[0]==-1||z[0]==a)
r(b,9)if((z[1]==-1||z[1]==b)&&a!=b)
r(c,9)if((z[2]==-1||z[2]==c)&&c!=b&&c!=a)
r(d,9)if((z[3]==-1||z[3]==d)&&d!=a&&d!=b&&d!=c)
r(e,9)if((z[4]==-1||z[4]==e)&&e!=a&&e!=b&&e!=c&&e!=d)
r(f,9)if((z[5]==-1||z[5]==f)&&f!=a&&f!=b&&f!=c&&f!=d&&f!=e)
r(g,9)if((z[6]==-1||z[6]==g)&&g!=a&&g!=b&&g!=c&&g!=d&&g!=e&&g!=f)
r(h,9)if((z[7]==-1||z[7]==h)&&h!=a&&h!=b&&h!=c&&h!=d&&h!=e&&h!=f&&h!=g)
r(i,9)if(z[8]==-1||z[8]==i){
  int p[9];
  p[0]=a;p[1]=b;p[2]=c;
  p[3]=d;p[4]=e;p[5]=f;
  p[6]=g;p[7]=h;p[8]=i;
  sort(p,p+9);
  if(p[0]!=p[1]&&p[1]!=p[2]&&p[2]!=p[3]&&p[3]!=p[4]&&p[4]!=p[5]&&p[5]!=p[6]&&p[6]!=p[7]&&p[7]!=p[8]){
    if((a+c+f+b*10+e*10+d*100)==(g*100+h*10+i))sum++;
  }
}
cout<<sum<<endl;
}
accuracy: 1
time_ms: 130
memory_kb: 3160
final_rank: 16