#include using namespace std; const int nmax=1000010; int n, m; int d[4], a[nmax], st[nmax]; ifstream fin("tsuk.in"); ofstream fout("tsuk.out"); void read() { fin>>m; for(int i=0; i>d[i]; fin>>n; for(int i=0; i>a[i]; } void prec() { int p, s, cnt; for(int i=1; i<=1000000; ++i) { cnt=0; p=i; while(p) { s=p%10; for(int j=0; j