criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <iostream>
#include <vector>
#include <queue>
#include <utility>

using namespace std;

inline bool inRange(int a, int x, int b) {
    return a <= x && x < b;
}

void fill(vector<vector<int> > &v, int r, int c) {
    queue<pair<int,int> > q;
    q.push(make_pair(r, c));
    v[r][c] = 0;
    while(!q.empty()) {
        const pair<int,int> cur = q.front();
        q.pop();
        for(int dr = -1; dr <= 1; ++dr) {
            for(int dc = -1; dc <= 1; ++dc) {
                int nr = cur.first + dr;
                int nc = cur.second + dc;
                if(inRange(0, nr, v.size()) && 
                   inRange(0, nc, v[0].size()) &&
                   v[nr][nc])
                {
                    v[nr][nc] = 0;
                    q.push(make_pair(nr, nc))
                }
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    while(true) {
        int C, R;
        cin >> C >> R;
        if(!C && !R) break;

        vector<vector<int> > v(R, vector<int>(C));
        for(int i = 0; i < R; ++i) 
            for(int j = 0; j < C; ++j)
                cin >> v[i][j];

        int cnt = 0;
        for(int r = 0; r < R; ++r) {
            for(int c = 0; c < C; ++c) {
                if(v[r][c]) {
                    ++cnt;
                    fill(v, r, c);
                }
            }
        }

        cout << cnt << endl;
    }

    return 0;
}

Compiler output:
a.cc: In function 'void fill(std::vector<std::vector<int> >&, int, int)':
a.cc:28:46: error: expected ';' before '}' token
   28 |                     q.push(make_pair(nr, nc))
      |                                              ^
      |                                              ;
   29 |                 }
      |                 ~
Language: C++

#include<iostream>
#include<queue>

typedef std::pair<int, int> P;
int vx[] = { 0, 1, 0, -1, 1, 1, -1, -1 }, vy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int w, h;
int map[51][51];

void bfs(int x, int y){

	map[y][x] = 0;

	std::queue<P>que;
	que.push(P(x, y));

	while (!que.empty()){

		P p = que.front();
		que.pop();

		for (int i = 0; i < 8; i++){
			int nx = p.first + vx[i], ny = p.second + vy[i];

			if (0 <= nx&&nx < w && 0 <= ny&&ny < h&&map[ny][nx] != 0){
				map[ny][nx] = 0;
				que.push(P(nx, ny));
			}
		}
	}

	return;
}

int main(){

	while (std::cin >> w >> h, w || h){

		int cnt = 0;

		memset(map, 0, sizeof(map));

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				std::cin >> map[i][j];
			}
		}

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if (map[i][j] != 0){
					bfs(j, i);
					cnt++;
				}
			}
		}

		std::cout << cnt << std::endl;
	}

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:17: error: 'memset' was not declared in this scope
   40 |                 memset(map, 0, sizeof(map));
      |                 ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<queue>
  +++ |+#include <cstring>
    3 |
Language: C++

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>

#define REP(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

template <class T> T read() { T t; cin >> t; return t; }
template <class T> vector<T> read(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> vector<vector<T>> read(int n, int m)
{
	vector<vector<T>> v;
	REP(i,n) { v.push_back(read<T>(m)); }
	return v;
}

template <class T> void write(const T &t) { cout << t << endl; }
template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; }
template <class T> void write(const vector<T> &v)
{
	ostringstream ss; 
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	cout << s.substr(0, s.length() - 1) << endl;
}

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__

void solve();
int main() { solve(); return 0; }

/// template end ///



void solve()
{
	while (true)
	{
		READ(int, H, W);
		if (!(W|H)) { break; }
		auto field = read<char>(W, H);
		for (auto &f : field) { f.insert(f.begin(), '0'); f.push_back('0'); }
		field.insert(field.begin(), vector<char>(H+2, '0'));
		field.push_back(vector<char>(H+2, '0'));
		W += 2; H += 2;

		int count = 0;
		REP(sx,W) REP(sy,H) if (field[sx][sy] == '1')
		{
			typedef complex<int> P;
			queue<P> q;
			q.push(P(sx, sy));
			while (!q.empty())
			{
				P cur = q.front(); q.pop();
				if (field[cur.real()][cur.imag()] == '0') { continue; }
				field[cur.real()][cur.imag()] = '0';
				P d[] = { P(-1,-1), P(0,-1), P(1,-1), P(-1, 0), P(1, 0), P(-1,1), P(0,1), P(1,1) };
				REP(i, _countof(d))
				{
					P next = cur + d[i];
					if (field[next.real()][next.imag()] == '1') q.push(next);
				}
			}
			count++;
		}
		write(count);
	}
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:75:40: error: '_countof' was not declared in this scope; did you mean 'count'?
   75 |                                 REP(i, _countof(d))
      |                                        ^~~~~~~~
a.cc:14:39: note: in definition of macro 'REP'
   14 | #define REP(i,n) for (int i = 0; i < (n); i++)
      |                                       ^
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
const int inf = 1 << 28;

int N;
vector<string> in;
vector<pair<int, bool> > var;

int dfs(int used, int sum){
    int k = __builtin_popcount(used);
    if((int)var.size() <= k)return sum == 0;
    int res = 0;
    rep(i, 10){
        if(used >> i & 1 || (!i && var[k].second))continue;
        res += dfs(used | 1 << i, sum + i * var[k].first);
    }
    return res;
}

int solve(){
    var.assign(26, mp(inf, false));
    rep(i, N)for(int j=(int)in[i].size()-1, d=1; j>=0; --j, d*=10){
        if(var[in[i][j] - 'A'].first == inf)var[in[i][j] - 'A'].first = 0;
        var[in[i][j] - 'A'].first += i != N-1? d: -d;
        var[in[i][j] - 'A'].second |= j == 0 & (int)in[i].size() != 1;
    }
    var.erase(remove_if(all(var), [](pair<int, bool> p){return p.first == inf;}), var.end());
    if(10 < (int)var.size())return 0;
    return dfs(0, 0);
}

int main(){
    while(cin >> N, N){
        in.assign(N, "");
        rep(i, N)cin >> in[i];
        cout << solve() << '\n';
    }
    return 0;
}

Compiler output:
a.cc: In function 'int solve()':
a.cc:28:20: error: 'mp' was not declared in this scope
   28 |     var.assign(26, mp(inf, false));
      |                    ^~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n&&n){
    m=0,an=0;
    memset(D,0,sizeof(D));
    string s;
    map<char,int> c;
    vector<char> v;
    for(int i=0;i<n;i++){
      cin>>s;
      int l=1;
      if(i==n-1)l=-1;
      for(int j=s.size()-1,k=1;j>=0;j--,k*=10){
	if(j==0&&s.size()!=1)v.push_back(s[j]);
	if(c.find(s[j])==c.end())c[s[j]]=l*k;
	else c[s[j]]+=l*k;
      }
    }
    map<char,int>::iterator it;
    for(it=c.begin();it!=c.end();it++){
      for(int i=0;i<v.size();i++)
	if((*it).first==v[i])D[m]=1;
      kei[m++]=(*it).second;
    }
    dfs(0,0);
    cout<<an<<endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:5: error: 'm' was not declared in this scope
    6 |     m=0,an=0;
      |     ^
a.cc:6:9: error: 'an' was not declared in this scope; did you mean 'n'?
    6 |     m=0,an=0;
      |         ^~
      |         n
a.cc:7:12: error: 'D' was not declared in this scope
    7 |     memset(D,0,sizeof(D));
      |            ^
a.cc:25:7: error: 'kei' was not declared in this scope
   25 |       kei[m++]=(*it).second;
      |       ^~~
a.cc:27:5: error: 'dfs' was not declared in this scope; did you mean 'ffs'?
   27 |     dfs(0,0);
      |     ^~~
      |     ffs
Language: C++

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string P[20], Q[20]; int N;
int c[26], F[20], r[20]; char d[26]; int cnt1 = 0;
int fact(int n) {
	int sum1 = 1;
	for (int i = 1; i <= n; i++)sum1 *= i;
	return sum1;
}
int main() {
	while (true) {
		for (int i = 0; i <= 10; i++) { F[i] = fact(i); r[i] = 0; }
		for (int i = 0; i < 20; i++) { P[i] = ""; Q[i] = ""; }
		for (int i = 0; i < 26; i++) { c[i] = 0; d[i] = ' '; }
		cnt1 = 0;
		cin >> N; if (N == 0) { break; }
		for (int i = 0; i < N; i++) {
			cin >> P[i];
			for (int j = 0; j < P[i].size(); j++) {
				c[P[i][j] - 'A']++;
			}
		}
		for (int i = 0; i < 26; i++) {
			if (c[i] >= 1) {
				d[i] = cnt1 + 'A';
				cnt1++;
			}
			else {
				d[i] = 'Z';
			}
		}
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < P[i].size(); j++) {
				P[i][j] = d[P[i][j] - 'A'];
			}
			if (P[i].size() >= 2) { r[P[i][0] - 'A'] = 1; }
		}
		int a[10] = { 0,1,2,3,4,5,6,7,8,9 };
		int cnt2 = 0, cnt3 = 0;
		do {
			if (cnt2%F[10 - cnt1] >= 1) { cnt2++; continue; }
			for (int i = 0; i < 10; i++) {
				if (a[i] == 0 && r[i] == 1) { goto E; }
			}
			int sum = 0;
			for (int i = 0; i < N; i++) {
				Q[i] = "";
				for (int j = 0; j < P[i].size(); j++) {
					Q[i] += a[P[i][j] - 'A'] + '0';
				}
				if (i < N - 1)sum += stoi(Q[i]);
				else {
					int V = stoi(Q[i]);
					if (sum == V)cnt3++;
				}
			}
		E:;
			cnt2++;
		}
		while (next_permutation(a, a + 10));
		cout << cnt3 << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:59:17: error: jump to label 'E'
   59 |                 E:;
      |                 ^
a.cc:45:68: note:   from here
   45 |                                 if (a[i] == 0 && r[i] == 1) { goto E; }
      |                                                                    ^
a.cc:47:29: note:   crosses initialization of 'int sum'
   47 |                         int sum = 0;
      |                             ^~~
Language: C++

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string P[20], Q[20]; int N;
int c[26], F[20], r[20]; char d[26]; int cnt1 = 0;
int fact(int n) {
	int sum1 = 1;
	for (int i = 1; i <= n; i++)sum1 *= i;
	return sum1;
}
int main() {
	while (true) {
		for (int i = 0; i <= 10; i++) { F[i] = fact(i); r[i] = 0; }
		for (int i = 0; i < 20; i++) { P[i] = ""; Q[i] = ""; }
		for (int i = 0; i < 26; i++) { c[i] = 0; d[i] = ' '; }
		cnt1 = 0;
		cin >> N; if (N == 0) { break; }
		for (int i = 0; i < N; i++) {
			cin >> P[i];
			for (int j = 0; j < P[i].size(); j++) {
				c[P[i][j] - 'A']++;
			}
		}
		for (int i = 0; i < 26; i++) {
			if (c[i] >= 1) {
				d[i] = cnt1 + 'A';
				cnt1++;
			}
			else {
				d[i] = 'Z';
			}
		}
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < P[i].size(); j++) {
				P[i][j] = d[P[i][j] - 'A'];
			}
			if (P[i].size() >= 2) { r[P[i][0] - 'A'] = 1; }
		}
		int a[10] = { 0,1,2,3,4,5,6,7,8,9 };
		int cnt2 = 0, cnt3 = 0, V = 0;
		do {
			if (cnt2%F[10 - cnt1] >= 1) { cnt2++; continue; }
			for (int i = 0; i < 10; i++) {
				if (a[i] == 0 && r[i] == 1) { goto E; }
			}
			int sum = 0;
			for (int i = 0; i < N; i++) {
				Q[i] = "";
				for (int j = 0; j < P[i].size(); j++) {
					Q[i] += a[P[i][j] - 'A'] + '0';
				}
				if (i < N - 1)sum += stoi(Q[i]);
				else {
					V = stoi(Q[i]);
					if (sum == V)cnt3++;
				}
			}
		E:;
			cnt2++;
		}
		while (next_permutation(a, a + 10));
		cout << cnt3 << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:59:17: error: jump to label 'E'
   59 |                 E:;
      |                 ^
a.cc:45:68: note:   from here
   45 |                                 if (a[i] == 0 && r[i] == 1) { goto E; }
      |                                                                    ^
a.cc:47:29: note:   crosses initialization of 'int sum'
   47 |                         int sum = 0;
      |                             ^~~
Language: C++

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string P[20];
int N, c[26], F[20], r[20]; char d[26]; int cnt1 = 0;
int fact(int n) {
	int sum1 = 1;
	for (int i = 1; i <= n; i++)sum1 *= i;
	return sum1;
}
int main() {
	while (true) {
		for (int i = 0; i <= 10; i++) { F[i] = fact(i); r[i] = 0; }
		for (int i = 0; i < 20; i++) { P[i] = ""; Q[i] = ""; }
		for (int i = 0; i < 26; i++) { c[i] = 0; d[i] = ' '; }
		cnt1 = 0;
		cin >> N; if (N == 0) { break; }
		for (int i = 0; i < N; i++) {
			cin >> P[i];
			for (int j = 0; j < P[i].size(); j++) {
				c[P[i][j] - 'A']++;
			}
		}
		for (int i = 0; i < 26; i++) {
			if (c[i] >= 1) {
				d[i] = cnt1 + 'A';
				cnt1++;
			}
			else {
				d[i] = 'Z';
			}
		}
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < P[i].size(); j++) {
				P[i][j] = d[P[i][j] - 'A'];
			}
			if (P[i].size() >= 2) { r[P[i][0] - 'A'] = 1; }
		}
		int a[10] = { 0,1,2,3,4,5,6,7,8,9 };
		int cnt2 = 0, cnt3 = 0, V = 0, sum = 0;
		do {
			if (cnt2%F[10 - cnt1] >= 1) { cnt2++; continue; }
			for (int i = 0; i < 10; i++) {
				if (a[i] == 0 && r[i] == 1) { goto E; }
			}
			sum = 0;
			for (int i = 0; i < N; i++) {
				int Q = 0;
				for (int j = 0; j < P[i].size(); j++) Q = Q * 10 + a[P[i][j] - 'A'];
				if (i != N - 1) sum += Q;
				else if (sum == Q) cnt3++;
			}
		E:;
			cnt2++;
		}
		while (next_permutation(a, a + 10));
		cout << cnt3 << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:59: error: 'Q' was not declared in this scope
   15 |                 for (int i = 0; i < 20; i++) { P[i] = ""; Q[i] = ""; }
      |                                                           ^
Language: C++

#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n, cnt, a[13][9], l[13], p[11], used[11]; char c[11];
int solve(int depth) {
	if (depth == cnt) {
		int b[13][9], ret = 0;
		memset(b, 0, 468);
		for (int i = 0; i < n; i++) {
			int res = 0;
			for (int j = l[i] - 1; j >= 0; j--) res = res * 10 + p[a[i][j]];
			if (i + 1 == n) ret -= res;
			else ret += res;
		}
		return ret ? 0 : 1;
	}
	int ret = 0;
	for (int i = 0; i < 10; i++) {
		if (!used[i]) {
			used[i] = 1, p[i] = i;
			ret += solve(depth + 1);
			used[i] = 0;
		}
	}
	return ret;
}
int main() {
	string s;
	while (cin >> n, n) {
		cnt = 0; memset(c, 0, 11);
		for (int i = 0; i < n; i++) {
			cin >> s; l[i] = s.size();
			reverse(s.begin(), s.end());
			for (int j = 0; j < s.size(); j++) {
				int flag = 0;
				for (int k = 0; k < cnt; k++) {
					if (s[j] == c[k]) {
						a[i][j] = k, flag = 1;
						break;
					}
				}
				if (!flag) a[i][j] = cnt, c[cnt++] = s[j];
			}
			cout << solve(0) << endl;
		}
	}
}

Compiler output:
a.cc: In function 'int solve(int)':
a.cc:9:17: error: 'memset' was not declared in this scope
    9 |                 memset(b, 0, 468);
      |                 ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <algorithm>
  +++ |+#include <cstring>
    4 | using namespace std;
a.cc: In function 'int main()':
a.cc:31:26: error: 'memset' was not declared in this scope
   31 |                 cnt = 0; memset(c, 0, 11);
      |                          ^~~~~~
a.cc:31:26: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
Language: C++

#include<bits/stdc++.h>
using namespace std;
int h[100];
vector<char> s;
vector<string> vs;
bool used[10];

bool calc(){
  int n = vs.size();
  int left = 0, item;
  for (int i = 0; i < n; i++) {
    if(h[vs[i][0]] == 0 and vs[i].size() != 1)return false;
  }
  for (int i = 0; i < n; i++) {
    item = 0;
    for (int j = 0; j < vs[i].size(); j++) {
      item = 10*item + h[vs[i][j]];
    }
    if(i < n - 1)left += item;
  }
  return left == item;
}
 
int dfs(int size = 0){
  if(size == s.size()){
    return calc();
  }
  int res = 0;
  for (int i = 0; i < 10; i++) {
    if(used[i] == true)continue;
    h[s[size]] = i;
    used[i] = true;
    res += dfs(size + 1);
    used[i] = false;
  }
  return res;
}
 
int main(){
  int n;
  while(std::cin >> n, n){
    s.clear();
    h.clear();
    vs.resize(n);
    for (int i = 0; i < n; i++) {
      std::cin >> vs[i];
    }
    unordered_set<char> tmp;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < vs[i].size(); j++) {
        tmp.insert(vs[i][j]);
      }
    }
    for (char c: tmp) {
      s.push_back(c);
    }
    std::cout << dfs() << std::endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:7: error: request for member 'clear' in 'h', which is of non-class type 'int [100]'
   43 |     h.clear();
      |       ^~~~~
Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>

#define MAX_N 12

using namespace std;

char form[MAX_N][8];
int N;
char alpha[10];
int na;
int fac[10];
int ans[100000][10];
int counter;

bool calc_form(){
	int sum = 0, s1;
	for (int i = 0; i < N; i++)
	{
		s1 = 0;
		for (int j = 0; j < strlen(form[i]); j++)
		{
			int k;
			for (k = 0; k < na; k++)
			{
				if(form[i][j] == alpha[k]) break;
			}
			if(j == 0 && fac[k] == 0 && strlen(form[i]) != 1) return false;
			s1 += fac[k];
			s1 *= 10;
		}
		s1 /= 10;
		if(i < N-1) sum += s1;
	}
	return sum == s1;
}

bool check_exist(char c){
	for (int i = 0; i < na; i++)
	{
		if(alpha[i] == c) return true;
	}
	return false;
}

bool check_ans(){
	for (int i = 0; i < counter; i++)
	{
		int j;
		for (j = 0; j < na; j++)
		{
			if(ans[i][j] != fac[j]) break;
		}
		if(j == na) return false;
	}
	return true;
}

int main(int argc, char const *argv[])
{
	while(1){
		cin >> N;
		if(N == 0) break;
		counter = 0;
		na = 0;
		for (int i = 0; i < N; i++)
		{
			cin >> form[i];
		}
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < strlen(form[i]); j++)
			{
				if(!check_exist(form[i][j])){
					alpha[na] = form[i][j];
					na++;
				}
			}
		}
		
		for (int i = 0; i < 10; i++) fac[i] = i;

		do{
			if(!calc_form()) continue;
			if(!check_ans()) continue;
			for (int i = 0; i < na; i++)
			{
				ans[counter][i] = fac[i];
			}
			counter++;
		}while(next_permutation(fac, fac+10));
		
		cout << counter << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'bool calc_form()':
a.cc:24:37: error: 'strlen' was not declared in this scope
   24 |                 for (int j = 0; j < strlen(form[i]); j++)
      |                                     ^~~~~~
a.cc:6:1: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include <cmath>
  +++ |+#include <cstring>
    6 | 
a.cc: In function 'int main(int, const char**)':
a.cc:75:45: error: 'strlen' was not declared in this scope
   75 |                         for (int j = 0; j < strlen(form[i]); j++)
      |                                             ^~~~~~
a.cc:75:45: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <strlen.h>

#define MAX_N 12

using namespace std;

char form[MAX_N][8];
int N;
char alpha[10];
int na;
int fac[10];
int ans[100000][10];
int counter;

bool calc_form(){
	int sum = 0, s1;
	for (int i = 0; i < N; i++)
	{
		s1 = 0;
		for (int j = 0; j < strlen(form[i]); j++)
		{
			int k;
			for (k = 0; k < na; k++)
			{
				if(form[i][j] == alpha[k]) break;
			}
			if(j == 0 && fac[k] == 0 && strlen(form[i]) != 1) return false;
			s1 += fac[k];
			s1 *= 10;
		}
		s1 /= 10;
		if(i < N-1) sum += s1;
	}
	return sum == s1;
}

bool check_exist(char c){
	for (int i = 0; i < na; i++)
	{
		if(alpha[i] == c) return true;
	}
	return false;
}

bool check_ans(){
	for (int i = 0; i < counter; i++)
	{
		int j;
		for (j = 0; j < na; j++)
		{
			if(ans[i][j] != fac[j]) break;
		}
		if(j == na) return false;
	}
	return true;
}

int main(int argc, char const *argv[])
{
	while(1){
		cin >> N;
		if(N == 0) break;
		counter = 0;
		na = 0;
		for (int i = 0; i < N; i++)
		{
			cin >> form[i];
		}
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < strlen(form[i]); j++)
			{
				if(!check_exist(form[i][j])){
					alpha[na] = form[i][j];
					na++;
				}
			}
		}
		
		for (int i = 0; i < 10; i++) fac[i] = i;

		do{
			//?¨???????????????????????????????????????§???????????¨?????????????????????
			if(!calc_form()) continue;
			if(!check_ans()) continue;
			for (int i = 0; i < na; i++)
			{
				ans[counter][i] = fac[i];
			}
			counter++;
		}while(next_permutation(fac, fac+10));
		
		cout << counter << endl;
	}
	return 0;
}

Compiler output:
a.cc:6:10: fatal error: strlen.h: No such file or directory
    6 | #include <strlen.h>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int main(void) {
  int fact[11];
  fact[0] = 1;
  REP(i, 1, 11) fact[i] = fact[i - 1] * i;

  for(int N; cin >> N, N > 0;) {
    string S[12];
    int a[256];

    REP(i, 0, N) {
      cin >> S[i];
      REP(j, 0, S[i].length()) a[S[i][j]] = 1;
    }

    int p = 0;
    REP(i, 0, 256) {
      if(a[i] == 1) a[i] = p++;
      else a[i] = -1;
    }

    int v[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    long cnt = 0;
    int s, t, u;
    while(next_permutation(v, v + 10)) {
      s = 0;
      REP(i, 0, N - 1) {
        if(S[i].length() > 1 && v[a[S[i][0]]] == 0) goto CONTINUE;
        t = 0;
        REP(j, 0, S[i].length()) t = t * 10 + v[a[S[i][j]]];
        s += t;
      }
      if(S[N - 1].length() > 1 && v[a[S[N - 1][0]]] == 0) goto CONTINUE;
      u = 0;
      REP(i, 0, S[N - 1].length()) u = u * 10 + v[a[S[N - 1][i]]];
      if(s == u) cnt++;
CONTINUE: continue;
    }

    cout << (cnt / fact[10 - p]) << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:11: error: 'next_permutation' was not declared in this scope
   28 |     while(next_permutation(v, v + 10)) {
      |           ^~~~~~~~~~~~~~~~
Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;

int N, M;
vector< char > list;
vector< string > s;
map< char, int > conv;

int dp[12][1 << 11];

int check() {
    int left = 0, right = 0;
    for(int i = 0; i < N; i++) {
        string num;
        for(int j = 0; j < s[i].size(); j++) {
            num.push_back(conv[s[i][j]] + '0');
        }
        //cout << num << endl;
        if(num[0] == '0' && num.size() != 1) return 0;
        else if(i == N - 1) {
            right = atoi(num.c_str());
        }
        else {
            left += atoi(num.c_str());
        }
    }
    //cout << left << " " << right << endl;
    if(right == left) return 1;
    else return 0;
}

int rec(int idx, int used) {

    if(idx == M) {
        return check();
    }
    //if(~dp[idx][used]) return dp[idx][used];

    int ret = 0;
    for(int i = 0; i <= 9; i++) {
        if((used >> i) & 1) {
            conv[list[idx]] = i;
            ret += rec(idx + 1, used & ~(1 << i));
        }
    }
    return dp[idx][used] = ret;
}

int main() {

    while(cin >> N, N) {
        for(int i = 0; i < N; i++) {
            string str; cin >> str;
            for(int i = 0; i < str.size(); i++) {
                list.push_back(str[i]);
            }
            s.push_back(str);
        }

        sort(list.begin(), list.end());
        list.erase(unique(list.begin(), list.end()), list.end());
        M = list.size();

        memset(dp, -1, sizeof(dp));
        cout << rec(0, (1 << 10) - 1) << endl;
        list.clear();
        s.clear();
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:63:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   63 |         sort(list.begin(), list.end());
      |         ^~~~
      |         short
a.cc:64:20: error: 'unique' was not declared in this scope
   64 |         list.erase(unique(list.begin(), list.end()), list.end());
      |                    ^~~~~~
a.cc:67:9: error: 'memset' was not declared in this scope
   67 |         memset(dp, -1, sizeof(dp));
      |         ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    4 | #include <map>
  +++ |+#include <cstring>
    5 | using namespace std;
Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;

int N, M;
vector< char > list;
vector< string > s;
map< char, int > conv;

map< string, int > dp;
map< string, bool > dp1;

int check() {
    int left = 0, right = 0;
    for(int i = 0; i < N; i++) {
        string num;
        for(int j = 0; j < s[i].size(); j++) {
            num.push_back(conv[s[i][j]] + '0');
        }
        //cout << num << endl;
        if(num[0] == '0' && num.size() != 1) return 0;
        else if(i == N - 1) {
            right = atoi(num.c_str());
        }
        else {
            left += atoi(num.c_str());
        }
    }
    //cout << left << " " << right << endl;
    if(right == left) return 1;
    else return 0;
}

int rec(int idx, int used) {

    if(idx == M) {
        return check();
    }

    int ret = 0;
    for(int i = 0; i <= 9; i++) {
        if(used >> i & 1) {
            conv[list[idx]] = i;
            ret += rec(idx + 1, used & ~(1 << i));
        }
    }

    return ret;
}

int main() {

    while(cin >> N, N) {
        for(int i = 0; i < N; i++) {
            string str; cin >> str;
            for(int i = 0; i < str.size(); i++) {
                list.push_back(str[i]);
            }
            s.push_back(str);
        }

        sort(list.begin(), list.end());
        list.erase(unique(list.begin(), list.end()), list.end());
        M = list.size();

        cout << rec(0, (1 << 10) - 1) << endl;
        list.clear();
        s.clear();
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:64:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   64 |         sort(list.begin(), list.end());
      |         ^~~~
      |         short
a.cc:65:20: error: 'unique' was not declared in this scope
   65 |         list.erase(unique(list.begin(), list.end()), list.end());
      |                    ^~~~~~
Language: C++

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repr(i,n) for(ll i=(ll)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

bool number[10];
int alphabet[26];
vector<char> v;
vector<int> perm(10);
int n;
string s[12];

bool countPattern() {
  ll num[n] = {};
  ll sum = 0;
  rep(i, n) {
    if (alphabet[s[i][0] - 'A'] == 0 && s[i].length() > 1) return false;

    rep(j, s[i].length()) {
      num[i] *= 10;
      num[i] += alphabet[s[i][j] - 'A'];
    }

    if (i < n - 1) sum += num[i];
  }

  // if (sum == num[n - 1]) {
  //   rep(i, n) cout << num[i] << ", ";
  //   cout << endl;
    return true;
  }
  return false;
}

int main(){
  cin.sync_with_stdio(false);

  iota(all(perm), 0);
  while (cin >> n, n) {
    v.clear();
    rep(i, 26) alphabet[i] = -1;

    rep(i, n) {
      cin >> s[i];
      rep(j, s[i].length()) v.pb(s[i][j]);
    }

    sort(all(v));
    uni(v);

    ll ans = 0;
    bool same;
    do {
      same = true;
      rep(i, v.size()) {
        if (alphabet[v[i] - 'A'] != perm[i]) same = false;
        alphabet[v[i] - 'A'] = perm[i];
      }
      if (!same && countPattern()) ans++;
    } while(next_permutation(all(perm)));

    cout << ans << endl;
  }

  return 0;
}

Compiler output:
a.cc:58:3: error: expected unqualified-id before 'return'
   58 |   return false;
      |   ^~~~~~
a.cc:59:1: error: expected declaration before '}' token
   59 | }
      | ^
Language: C++

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;

int N;
char s[12][8];
int sl[12];
char t[8];
int tl;
int cnt, m;
int perm[] = {0,1,2,3,4,5,6,7,8,9};

bool check()
{
  int sum1 = 0;
  for (int i = 0; i < N-1; ++i) {
    int d = 1;
    if (sl[i] > 1 && perm[s[i][0] - 'A'] == 0)
      return false;
    for (int j = sl[i]-1; j >= 0; --j) {
      sum1 += perm[s[i][j] - 'A'] * d;
      d *= 10;
    }
  }
  int sum2 = 0, d = 1;
  if (tl > 1 && perm[t[0] - 'A'] == 0)
    return false;
  for (int j = tl-1; j >= 0; --j) {
    sum2 += perm[t[j] - 'A'] * d;
    d *= 10;
  }
  return sum1 == sum2;
}

void dfs(int k)
{
  if (k == m && check()) {
    /*
    for (int i = 0; i < m; ++i) {
      printf("%c = %d\n", i + 'A', perm[i]);
    }
    puts("");
    */
    ++cnt;
  } else {
    for (int i = k; i < 10; ++i) {
      /*
      for (int j = 0; j < N-1; ++j) {
        if (sl[j] > 1 && perm[s[j][0]-'A'] == 0)
          goto next;
      }
      if (tl > 1 && perm[t[0]-'A'] == 0)
        goto next;
        */

      swap(perm[i], perm[k]);
      dfs(k+1);
      swap(perm[i], perm[k]);
next:;
    }
  }
}

int main()
{
  while (scanf("%d ", &N), N) {
    for (int i = 0; i < N-1; ++i) {
      gets(s[i]);
      sl[i] = strlen(s[i]);
    }
    gets(t);
    tl = strlen(t);

    map<char, char> M;
    int id = 0;
    for (int i = 0; i < N-1; ++i) {
      for (int j = 0; j < sl[i]; ++j) {
        if (!M.count(s[i][j]))
          M.insert(make_pair(s[i][j], id++ + 'A'));
      }
    }
    for (int j = 0; j < tl; ++j) {
      if (!M.count(t[j]))
        M.insert(make_pair(t[j], id++ + 'A'));
    }
    for (int i = 0; i < N-1; ++i) {
      for (int j = 0; j < sl[i]; ++j) {
        s[i][j] = M[s[i][j]];
      }
    }
    for (int j = 0; j < tl; ++j) {
      t[j] = M[t[j]];
    }

    /*
    for (int i = 0; i < N-1; ++i) {
      puts(s[i]);
    }
    puts(t);
    */

    m = id;
    cnt = 0;
    dfs(0);

    printf("%d\n", cnt);
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:70:7: error: 'gets' was not declared in this scope; did you mean 'getw'?
   70 |       gets(s[i]);
      |       ^~~~
      |       getw
a.cc:73:5: error: 'gets' was not declared in this scope; did you mean 'getw'?
   73 |     gets(t);
      |     ^~~~
      |     getw
Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>

#define N 12
#define L 9
using namespace std;

int n;
int cnum;
char m[N][L];
char f[128];
char vc[11];
bool used[10];
int mlen[N];
bool non_zero[128];
//set<char> non_zero;

int dfs(int depth){
  int ret = 0;
  if(depth==cnum){
    char tm[N][L];
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < mlen[i]; ++j){
	tm[i][j] = f[ m[i][j] ];
      }
    }
    /*
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < mlen[i]; ++j){
	cout << tm[i][j];
      }
      cout << endl;
    }
    cout << " ------------- " << endl;
    */
    int sum=0;
    for(int i = 0; i < n; ++i){
      char v[mlen[i]+1];
      for(int j = 0; j < mlen[i]; ++j){
	v[j] = tm[i][j];
      }
      v[mlen[i]]=0;
      if(i==n-1){
	if(sum==atoi(v)){
	  //cout << " CORRECT " << endl;
	  return 1;
	}
	else return 0;
      }
      sum+=atoi(v);
    }
  }
  for(int i = 0; i < 10; ++i){
    if( !used[i] ){
      used[i]=true;
      f[vc[depth]]=i+'0';
      if(i==0&&non_zero[vc[depth]] )goto NEXT;
      ret += dfs(depth+1);
    NEXT:;
      used[i]=false;
    }
  }
  return ret;
}

int main()
{
  while(true){
    int ans = 0;

    cin >> n;
    if(n==0)break;

    cnum = 0;
    for(int i = 0; i <128;++i){
      f[i]=0;
      non_zero[i]=false;
    }
    for(int i = 0; i < 10; ++i){
      used[i] = false;
      vc[i]=0;
    }
    vc[10]=0;
    for(int i = 0; i < N; ++i){
      mlen[i]=0;
      for(int j = 0; j < L; ++j){
	m[i][j] = '0';
      }
    }

    for(int i = 0; i < n; ++i){
      string t;
      cin >> t;
      mlen[i]=t.length();
      for(int j = 0; j < t.length(); ++j){
	m[i][j] = t[j];
	f[m[i][j]]='0';
	if(find(vc,vc+cnum,m[i][j])==vc+cnum)vc[cnum++]=m[i][j];
	if(j==0&&t.length()>1)non_zero[t[j]]=true;
      }
    }

    ans = dfs(0);
    
    cout << ans << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:102:16: error: no matching function for call to 'find(char [11], char*, char&)'
  102 |         if(find(vc,vc+cnum,m[i][j])==vc+cnum)vc[cnum++]=m[i][j];
      |            ~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:102:16: note:   mismatched types 'std::istreambuf_iterator<_CharT>' and 'char*'
  102 |         if(find(vc,vc+cnum,m[i][j])==vc+cnum)vc[cnum++]=m[i][j];
      |            ~~~~^~~~~~~~~~~~~~~~~~~~
Language: C++

#include <iostream>
#include <vector>
#include <string>

using namespace std;

const int g_keta[8] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};

struct Alphabet
{
	int keisu;
	char mozi;
	bool sento;
};
typedef struct Alphabet alphabet;

void create(string str, vector<alphabet>& alp, int sign)
{
	int len = str.size();
	int idx = len-1;
	vector<alphabet>::iterator it;

	for(int i=0; i < len; i++) {
		bool hit = false;
		for(it = alp.begin(); it != alp.end(); it++) {
			if(str[i] == (*it).mozi) {
				hit = true;
				(*it).keisu += (g_keta[idx] * sign);
				break;
			}
		}
		if(!hit) {
			alphabet tmp;
			tmp.keisu = g_keta[idx] * sign;
			tmp.mozi = str[i];
			if(len > 1) tmp.sento = (i)? false : true;
			else tmp.sento = false;
			alp.push_back( tmp );
		}
		idx--;
	}
}

bool g_use[10] = { false };
int g_cnt;
void search(vector<alphabet>& alp, int cnt, int sum)
{
	if(alp.size() == cnt){
		if(!sum) g_cnt++;
		return;
	}
	for(int i=0; i < 10; i++) {
		if(g_use[i]) continue;
		if(!i && alp[cnt].sento) continue;
		g_use[i] = true;
		int tmp = alp[cnt].keisu * i;
		sum += tmp;
		search(alp, cnt+1, sum);
		sum -= tmp;
		g_use[i] = false;
	}
}

timer mytimer;

int main()
{
	int n;
	while(cin >> n, n)
	{
		g_cnt = 0;
		vector<alphabet> alp;
		for(int i=0; i < n; i++) {
			string str;
			cin >> str;
			int sign = (i == n-1)? -1 : 1;
			create(str, alp, sign);
		}
		search(alp, 0, 0);
		cout << g_cnt << endl;

	}
	return 0;
}

Compiler output:
a.cc:64:1: error: 'timer' does not name a type; did you mean 'timex'?
   64 | timer mytimer;
      | ^~~~~
      | timex
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>

using namespace std;

typedef long long ll;
int N;
string nums[101];
string sum;
//map<char,int> applyNum;
int varNum;
int applyNums[1001];
char charSets[101];
int cnt=0;

bool used[11];
bool noZero[1000];

void dfs(int pos){
    if(pos==varNum){
        // stringツづ可青板篠堋づーツ環づィツ督鳴づづつ「ツづづгumツづーツ計ツ算
        ll a=0;
        for(int i=0;i<N-1;i++){
            ll mul=1;
            for(int j=nums[i].size()-1;j>=0;j--){
                a+=applyNums[nums[i][j]]*mul;
                mul*=10;
            }
        }
        ll b=0;
        ll mul=1;
        for(int j=sum.size()-1;j>=0;j--){
            b+=applyNums[sum[j]]*mul;
            mul*=10;
        }
        if(a==b)cnt++;
    }
    // ツ使ツづュツづェツづつ「ツづ按つ「ツ青板篠堋づーツ環づィツ督鳴づづゥ
    else{
        for(int i=0;i<=9;i++){
            if(used[i]||(i==0&&noZero[charSets[pos]]))continue;
            used[i]=true;
            applyNums[charSets[pos]]=i;
            dfs(pos+1);
            used[i]=false;
        }
    }
}

int main(){
    while(cin>>N&&N){
        memset(noZero,0,sizeof(noZero));
        set<char> sc;
        for(int i=0;i<N-1;i++){
            cin>>nums[i];
            for(int j=0;j<nums[i].size();j++){
                if(nums[i].size()!=1&&j==0)noZero[nums[i][j]]=true;
                sc.insert(nums[i][j]);
            }
        }
        cin>>sum;
        for(int i=0;i<sum.size();i++){
            if(i==0&&sum.size()!=1)noZero[sum[i]]=true;
            sc.insert(sum[i]);
        }
        varNum=0;
        // charツづーツ渉氾板づ可環づィツ督鳴づづつ「ツつュ
        for(set<char>::iterator it=sc.begin();it!=sc.end();it++)charSets[varNum++]=*it;
        dfs(0);
        cout<<cnt<<endl;
        cnt=0;
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:9: error: 'memset' was not declared in this scope
   55 |         memset(noZero,0,sizeof(noZero));
      |         ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include <set>
  +++ |+#include <cstring>
    6 |
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cstring>
#include <map>

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
int N;
string strs[101];
char charSets[101];
int charKinds;
int charIds[1001];

int perm[101];
int nums[101];

int cnt;

void dfs(int pos,int idx){
    if(pos==charKinds){
        // SÔ·
        do{
            ll lSum=0;
            ll rSum=0;
            bool ok=true;
            for(int i=0;i<N;i++){
                ll mul=1;
                for(int j=strs[i].size()-1;j>=0;j--){
                    char ch=strs[i][j];
                    // æª¶É0ÌèÄÍsÂ\
                    if(j==0&&perm[charIds[ch]]==0&&strs[i].size()!=1){
                        ok=false;
                        break;
                    }
                    if(i!=N-1)lSum+=mul*perm[charIds[ch]];
                    else rSum+=mul*perm[charIds[ch]];
                    mul*=10;
                }
                if(!ok)break;
            }
            if(ok&&lSum==rSum)cnt++;
        }while(next_permutation(perm,perm+pos));
    }
    else{
        //idx©çiÌÔÅèÄ
        for(int i=idx;i<=9;i++){
            perm[pos]=i;
            dfs(pos+1,i+1);
        }
    }
}

int main(){
    bool used[1001];
    while(cin>>N&&N){
        charKinds=0;
        memset(used,0,sizeof(used));
        for(int i=0;i<N;i++){
            cin>>strs[i];
            for(int j=0;j<strs[i].size();j++){
                //charSets.insert(strs[i][j]);
                if(!used[strs[i][j]]){
                    used[strs[i][j]]=true;
                    charSets[charKinds++]=strs[i][j];
                    charIds[strs[i][j]]=charKinds-1;
                }
            }
        }
        cnt=0;
        dfs(0,0);
        cout<<cnt<<endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:41:54: error: 'ch' was not declared in this scope
   41 |                     if(i!=N-1)lSum+=mul*perm[charIds[ch]];
      |                                                      ^~
a.cc:42:49: error: 'ch' was not declared in this scope
   42 |                     else rSum+=mul*perm[charIds[ch]];
      |                                                 ^~
a.cc:47:15: error: expected 'while' before '(' token
   47 |             if(ok&&lSum==rSum)cnt++;
      |               ^
a.cc:47:16: error: 'ok' was not declared in this scope
   47 |             if(ok&&lSum==rSum)cnt++;
      |                ^~
a.cc:47:20: error: 'lSum' was not declared in this scope
   47 |             if(ok&&lSum==rSum)cnt++;
      |                    ^~~~
a.cc:47:26: error: 'rSum' was not declared in this scope
   47 |             if(ok&&lSum==rSum)cnt++;
      |                          ^~~~
a.cc:47:31: error: expected ';' before 'cnt'
   47 |             if(ok&&lSum==rSum)cnt++;
      |                               ^~~
      |                               ;
a.cc: At global scope:
a.cc:50:5: error: expected unqualified-id before 'else'
   50 |     else{
      |     ^~~~
a.cc:57:1: error: expected declaration before '}' token
   57 | }
      | ^
Language: C++

#include <cstdio>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int getmin(int bit)
{
	return __builtin_ctz(~bit);
}
int getmax(int bit)
{
	return 31-__builtin_clz(~bit&1023);
}

int solve(int* c,int* z,int M,int sum,int bit)
{
	int depth=__builtin_popcount(bit);
	if(depth==M)
		return sum==0;
	
	// } è
	if(sum>0){
		int s=sum,b=bit;
		for(int i=depth;i<M;i++){
			int j=c[i]>0?getmin(b):getmax(b);
			b|=1<<j;
			s+=c[i]*j;
		}
		if(s>0)
			return 0;
	}
	if(sum<0){
		int s=sum,b=bit;
		for(int i=depth;i<M;i++){
			int j=c[i]>0?getmax(b):getmin(b);
			b|=1<<j;
			s+=c[i]*j;
		}
		if(s<0)
			return 0;
	}
	
	int res=0;
	for(int i=z[depth];i<10;i++){
		if(bit&1<<i) continue;
		res+=solve(c,z,M,sum+c[depth]*i,bit|1<<i);
	}
	return res;
}

int main()
{
	int d[9]={1};
	for(int i=1;i<9;i++)
		d[i]=d[i-1]*10;
	
	for(int N;scanf("%d ",&N),N;){
		string n[12];
		for(int i=0;i<N;i++){
			char buf[9];
			n[i]=gets(buf);
		}
		
		map<char,int> m;
		for(int i=0;i<N;i++)
			for(int j=0;j<n[i].size();j++)
				if(m.find(n[i][j])==m.end())
					m.insert(make_pair(n[i][j],m.size()));
		int M=m.size();
		
		int c[10]={},z[10]={}; // c:W, z:0ðèÄÄæ¢©Ç¤©
		for(int i=0;i<N;i++){
			if(n[i].size()>1)
				z[m[n[i][0]]]=1;
			reverse(n[i].begin(),n[i].end());
			for(int j=0;j<n[i].size();j++)
				c[m[n[i][j]]]+=i==N-1?-d[j]:d[j];
		}
		
		// WÌâÎlÌ~Å\[g
		for(int i=0;i<M;i++)
			for(int j=M-1;j>i;j--)
				if(abs(c[j-1])<abs(c[j])){
					swap(c[j-1],c[j]);
					swap(z[j-1],z[j]);
				}
		
		printf("%d\n",solve(c,z,M,0,0));
	}
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:63:30: error: 'gets' was not declared in this scope; did you mean 'getw'?
   63 |                         n[i]=gets(buf);
      |                              ^~~~
      |                              getw
Language: C++

#include<iostream>
#include<vector>
#include<map>
#define pb push_back
#define uni(c) c.erase(unique(all(c)),c.end())
#define all(c) c.begin(),c.end()
using namespace std;
int ans,cs,n;
vector<string> v;
vector<char> c;
bool flag;
map<int,int> mp;
map<char,int> c_t_n;
map<char,bool> nz;
int coun,a;
void calc(vector<int> now){
	do{
		coun++;
		int sum=0;
		for(int i=0;i<cs;i++){
			if(nz[c[i]]&&!now[i]){
				goto con;
			}
		}
		for(int i=0;i<cs;i++){
			sum+=c_t_n[c[i]]*now[i];
		}
		if(!sum)
			ans++;
		con:;
	}while(next_permutation(all(now)));
}
void ret(vector<int> now,int pos,int prev){
	a++;
	if(cs==pos){
		calc(now);
		return;
	}
	for(int i=prev+1;i<=10-(cs-pos);i++){
		now.pb(i);
		ret(now,pos+1,i);
		now.pop_back();
	}
}
int main(){
	while(cin>>n,n){
		coun=0;
		a=0;
		c_t_n.clear();
		ans=0;
		v.clear();
		c.clear();
		nz.clear();
		for(int i=0;i<n;i++){
			//string s;
			char s[100];
			cin>>s;
			//v.pb(s);
			int dec=1;
			int m=strlen(s);
			if(m>1){
				nz[s[0]]=true;
			}
			for(int j=m-1;j>=0/*s.size()*/;j--){
				if(n/*s.size()*/-1==i)
				c_t_n[s[j]]-=dec;
				else
				c_t_n[s[j]]+=dec;
				c.pb(s[j]);
				dec*=10;
			}
		}
		sort(all(c));
		uni(c);
		cs=c.size();
		ret(vector<int>(),0,-1);
		cout<<"     "<<a<<"   "<<cs<<endl;
		cout<<ans<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'void calc(std::vector<int>)':
a.cc:31:16: error: 'next_permutation' was not declared in this scope
   31 |         }while(next_permutation(all(now)));
      |                ^~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:60:31: error: 'strlen' was not declared in this scope
   60 |                         int m=strlen(s);
      |                               ^~~~~~
a.cc:4:1: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include<map>
  +++ |+#include <cstring>
    4 | #define pb push_back
a.cc:73:17: error: 'sort' was not declared in this scope; did you mean 'short'?
   73 |                 sort(all(c));
      |                 ^~~~
      |                 short
a.cc:5:24: error: 'unique' was not declared in this scope
    5 | #define uni(c) c.erase(unique(all(c)),c.end())
      |                        ^~~~~~
a.cc:74:17: note: in expansion of macro 'uni'
   74 |                 uni(c);
      |                 ^~~
Language: C++

// Sample : 0m2.437s

import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);
    
    int n;
    char[][] x;
    boolean[] usedArphabet;
    boolean[] noZero;
    boolean flag;
    int[] number;
    long ans;
    
    void run(){
	while(sc.hasNext()){
	    n = sc.nextInt();
	    if(n==0) break;
	    
	    flag = false;
	    x = new char[n][];
	    for(int i=0; i<n; i++)
		x[i] = sc.next().toCharArray();
	   

	    // テ」ツつ「テ」ツδォテ」ツδ陛」ツつ。テ」ツδ凖」ツδε」ツδ暗ヲツ篠「テ」ツ??
	    search();
	    if(flag) continue;

	    ans = 0;
	    number = new int[26];
	    Arrays.fill(number, -1);
	    solve(0);
	    System.out.println(ans);
	}
    }

    void solve(int p){
	if(p==26){
	    // ティツィツ暗ァツョツ療・ツ青暗」ツ?」テ」ツ?ヲテ」ツ??」ツつ凝」ツ?? テ」ツ?禿」ツ?禿」ツ?凝」ツつ?
	    int y = 0;
	    int keta;
	    for(int i=0; i<n-1; i++){
		keta = 1;
		for(int k=x[i].length-1; k>=0; k--){
		    y += number[x[i][k]-65]*keta;
		    keta *= 10;
		}
	    }
	    int tmp = 0;
	    keta = 1;
	    for(int k=x[n-1].length-1; k>=0; k--){
		tmp += number[x[n-1][k]-65]*keta;
		keta *= 10;
	    }
	    //ティツィツ暗ァツョツ療・ツ青暗」ツ?」テ」ツ?ヲテ」ツ??」ツつ凝」ツ?? テ」ツ?禿」ツ?禿」ツ?セテ」ツ?ァ
	    if(y==tmp) {
		//show();
		ans++;
	    }
	    return;
	}

	if(usedArphabet[p]){
	    int i = 0;
	    if(noZero[p]) i = 1;
	    for(; i<=9; i++){
		// テヲツ閉ーテ・ツュツ療」ツ?凝」ツ?カテ」ツ?」テ」ツ?ヲテ」ツ??」ツ?ェテ」ツ??」ツ?? テ」ツ?禿」ツ?禿」ツ?凝」ツつ?
		boolean notBad = true;
		for(int k=0; k<p; k++){
		    if(number[k]==-1) continue;
		    if(number[k]==i) notBad = false;
		}
		// テヲツ閉ーテ・ツュツ療」ツ?凝」ツ?カテ」ツ?」テ」ツ?ヲテ」ツ??」ツ?ェテ」ツ??」ツ?? テ」ツ?禿」ツ?禿」ツ?セテ」ツ?ァ

		if(notBad){
		    number[p] = i;
		    solve(p+1);
		}
	    }
	}
	else solve(p+1);
    }

    void search(){
	usedArphabet = new boolean[26]; // 0=A, 25=Z
	noZero = new boolean[26];
	int maxlength = 0;
	for(int i=0; i<n; i++){
	    maxlength = Math.max(maxlength, x[i].length);
	    for(int k=0; k<x[i].length; k++){
		int c = x[i][k] - 65;
		//System.out.println(x[i][k]+" "+c);
		usedArphabet[c] = true;
		if(k==0 && x[i].length!=1) noZero[c] = true;
	    }
	}

	// テ・ツ環?ァツョツ療」ツ?ェテ」ツ?ョテ」ツ?ォテヲツ。ツ?」ツ?古」ツ?甘」ツ?凝」ツ?療」ツ??」ツ?ィテ」ツ??
	if(maxlength > x[n-1].length){
	    badCase();
	    return;
	}
    }

    void badCase(){
	System.out.println(0);
	flag = true;
    }

    void show(){
	for(int i=0; i<number.length; i++)
	    System.out.print(number[i]+" ");
	System.out.println();
    }
}

Compiler output:
a.cc:3:1: error: 'import' does not name a type
    3 | import java.util.*;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: expected unqualified-id before 'public'
    4 | public class Main{
      | ^~~~~~