akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define N 10
using namespace std;
int n,m,ans;
map<char,int> c;
set<char> ish;
bool used[N];
bool q[N];
string s;
int p[N];

void func(int x,int sum){
  if(x==m){
    if(!sum)ans++;
    return;
  }
  for(int i=0;i<10;i++){
    if(used[i])continue;
    if(!i&&q[x])continue;
    used[i]=true;
    func(x+1,sum+i*p[x]);
    used[i]=false;
  }
}

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin>>s;
      for(int j=s.size()-1,k=1;j>=0;j--,k*=10){
	if(!j&&s.size()!=1)ish.insert(s[j]);
	if(c.find(s[j])==c.end())
	  if(i!=n-1)c[s[j]]=k;
	  else c[s[j]]=-k;
	else
	  if(i!=n-1)c[s[j]]+=k;
	  else c[s[j]]-=k;
      }
    }
    memset(q,0,sizeof(q));
    map<char,int>::iterator ite;
    int k=0;
    for(ite=c.begin();ite!=c.end();ite++,k++){
      p[k]=(*ite).second;
      if(ish.find((*ite).first)!=ish.end())
	q[k]=true;
    }
    m=c.size();
    ans=0;
    func(0,0);
    cout<<ans<<endl;
    ish.clear();
    c.clear();
  }
  return 0;
}

Measured memory_bytes: 1204