#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;
}



Measured memory_bytes: 3168