#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define double long double
#define mod 1000000007
#define iP pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define inf 1e15
#define mod1 998244353
#define pi 3.141592653589793238
#define lcm(a,b) a*b/__gcd(a,b)
#define sz(x) (int)x.size()
#define cmp complex<double>
int power(int x,int y){
    int res=1;
    while(y>0){
        if(y&1)res=(res*x);
        x=(x*x);
        y/=2;
    }
    return res;
}
void precompute(){
}
void multiply(vector<int> &v,int x){
    int rem=0;
    for(int i=0;i<v.size();i++){
        int z=v[i]*x+rem;
        rem=z/10;
        v[i]=z%10;
    }
    while(rem>0){
        v.push_back(rem%10);
        rem=rem/10;
    }
}
void solve(int tc){
    string str;
    cin>>str;
    vector<int> res({1});
    vector<bool> cnt(26);
    for(int i=0;i<str.size();i++){
        if(str[i]>='0' && str[i]<='9')continue;
        if(str[i]=='?'){
            if(i==0)multiply(res,9);
            else multiply(res,10);
        }
        if(str[i]>='A' && str[i]<='J'){
            if(cnt[str[i]-'A'])continue;
            else if(i==0)multiply(res,9);
            else multiply(res,10-count(cnt.begin(),cnt.end(),1));
            cnt[str[i]-'A']=1;
        }
    }
    reverse(res.begin(),res.end());
    for(auto it: res)cout<<it;
}
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(12);
    int t=1,ctr=0;
    // precompute();
    // cin>>t;
    while(t--){
        solve(ctr+1);
        ctr++;
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define double long double
#define mod 1000000007
#define iP pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define inf 1e15
#define mod1 998244353
#define pi 3.141592653589793238
#define lcm(a,b) a*b/__gcd(a,b)
#define sz(x) (int)x.size()
#define cmp complex<double>
int power(int x,int y){
    int res=1;
    while(y>0){
        if(y&1)res=(res*x);
        x=(x*x);
        y/=2;
    }
    return res;
}
void precompute(){
}
void solve(int tc){
    string str;
    cin>>str;
    int res=1;
    vector<bool> cnt(26);
    for(int i=0;i<str.size();i++){
        if(str[i]>='0' && str[i]<='9')continue;
        if(str[i]=='?'){
            if(i==0)res*=9;
            else res*=10;
        }
        if(str[i]>='A' && str[i]<='J'){
            if(cnt[str[i]-'A'])continue;
            else if(i==0)res*=9;
            else res*=10-count(cnt.begin(),cnt.end(),1);
            cnt[str[i]-'A']=1;
        }
    }
    cout<<res;
}
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(12);
    int t=1,ctr=0;
    // precompute();
    // cin>>t;
    while(t--){
        solve(ctr+1);
        ctr++;
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define double long double
#define mod 1000000007
#define iP pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define inf 1e15
#define mod1 998244353
#define pi 3.141592653589793238
#define lcm(a,b) a*b/__gcd(a,b)
#define sz(x) (int)x.size()
#define cmp complex<double>
int power(int x,int y){
    int res=1;
    while(y>0){
        if(y&1)res=(res*x);
        x=(x*x);
        y/=2;
    }
    return res;
}
void precompute(){
}
void multiply(vector<int> &v,int x){
    int rem=0;
    for(int i=0;i<v.size();i++){
        int z=v[i]*x+rem;
        rem=z/10;
        v[i]=z%10;
    }
    while(rem>0){
        v.push_back(rem%10);
        rem=rem/10;
    }
}
void solve(int tc){
    string str;
    cin>>str;
    int res=1;
    vector<bool> cnt(26);
    vector<int> arr(11);
    for(int i=0;i<str.size();i++){
        if(str[i]>='0' && str[i]<='9')continue;
        if(str[i]=='?'){
            if(i==0)arr[9]++;
            else arr[10]++;
        }
        if(str[i]>='A' && str[i]<='J'){
            if(cnt[str[i]-'A'])continue;
            else if(i==0)arr[9]++;
            else arr[10-count(cnt.begin(),cnt.end(),1)]++;
            cnt[str[i]-'A']=1;
        }
    }
    for(int i=1;i<10;i++){
        if(arr[i]==0)continue;
        res*=power(i,arr[i]);
    }
    cout<<res;
    for(int i=0;i<arr[10];i++)cout<<0;
}
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(12);
    int t=1,ctr=0;
    // precompute();
    // cin>>t;
    while(t--){
        solve(ctr+1);
        ctr++;
    }
}


#pragma comment(linker, "/STACK:167177216")

#include<stdio.h>
#include<stack>
#include<math.h>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string.h>
#include<string>
#include<set>
#include<memory.h>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<cassert>
#include<time.h>
#include<bitset>

using namespace std;

const int INF = 1e9;

typedef long long li;
typedef long double ld;

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define pb push_baack
#define mp make_pair

string s;
li c[100][100];

bool ok(int a)
{
    vector<int> nt(10, -1);
    vector<int> ns(10, -1);
    int r = s.size() - 1;
    while(a)
    {
        int cur = a % 10;
        if(s[r] >= '0' && s[r] <= '9' && (s[r] - '0') != cur)
            return false;
        if(s[r] >= 'A' && s[r] <= 'Z')
        {
            int sig = s[r] - 'A';
            if(nt[sig] == -1)
            {
                nt[sig] = cur;
                if(ns[cur] != -1)
                    return false;
                ns[cur] = sig;
            }
            else
                if(nt[sig] != cur)
                    return false;
        }
        r--;
        a /= 10;
    }
    return true;
}

inline void read()
{
    cin >> s;
}

map<char, bool> used;

inline void solve()
{
    forn (i, 100)
    {
        c[i][0] = c[i][i] = 1;
        for (int j = 1; j < i; ++j)
            c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
    }
    li ans = 1;
    int cnt = 10;
    int cnt0 = 0;
    int kol = 0;
    if(s[0] >= 'A' && s[0] <= 'Z')
    {
        ans *= 9;
        used[s[0]] = true;
        cnt--;
    }
    else
        if(s[0] == '?')
            ans *= 9;
    for (int i = 1; i < s.size(); ++i)
    {
        if(s[i] == '?')
        {
            cnt0++;
        }
        if(s[i] >= 'A' && s[i] <= 'Z' && !used[s[i]])
        {
            kol++;
            used[s[i]] = true;
        }
    }
    ans *= c[cnt][kol];
    for (int i = 2; i <= kol; ++i)
        ans *= i;
    cout << ans;
    forn (i, cnt0)
        cout << 0;

    /*int low = 1;
    for (int i = 0; i < s.size() - 1; ++i)
        low *= 10;
    int gans = 0;
    for (int i = low; i < low * 10; ++i)
    {
        if(ok(i))
            gans++;
    }
    cout << gans << endl;*/
}

int main()
{
#ifdef Baster
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    read();
    solve();
    return 0;
}


#pragma comment(linker, "/STACK:167177216")

#include<stdio.h>
#include<stack>
#include<math.h>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string.h>
#include<string>
#include<set>
#include<memory.h>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<cassert>
#include<time.h>
#include<bitset>

using namespace std;

const int INF = 1e9;

typedef long long li;
typedef long double ld;

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define pb push_baack
#define mp make_pair

string s;
li c[100][100];

bool ok(int a)
{
    vector<int> nt(10, -1);
    vector<int> ns(10, -1);
    int r = s.size() - 1;
    while(a)
    {
        int cur = a % 10;
        if(s[r] >= '0' && s[r] <= '9' && (s[r] - '0') != cur)
            return false;
        if(s[r] >= 'A' && s[r] <= 'Z')
        {
            int sig = s[r] - 'A';
            if(nt[sig] == -1)
            {
                nt[sig] = cur;
                if(ns[cur] != -1)
                    return false;
                ns[cur] = sig;
            }
            else
                if(nt[sig] != cur)
                    return false;
        }
        r--;
        a /= 10;
    }
    return true;
}

inline void read()
{
    cin >> s;
}

map<char, bool> used;

inline void solve()
{
    forn (i, 100)
    {
        c[i][0] = c[i][i] = 1;
        for (int j = 1; j < i; ++j)
            c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
    }
    li ans = 1;
    int cnt = 10;
    int cnt0 = 0;
    int kol = 0;
    if(s[0] >= 'A' && s[0] <= 'Z')
    {
        ans *= 9;
        used[s[0]] = true;
        cnt--;
    }
    else
        if(s[0] == '?')
            ans *= 9;
    for (int i = 1; i < s.size(); ++i)
    {
        if(s[i] == '?')
        {
            cnt0++;
        }
        if(s[i] >= 'A' && s[i] <= 'Z' && !used[s[i]])
        {
            kol++;
            used[s[i]] = true;
        }
    }
    ans *= c[cnt][kol];
    for (int i = 2; i <= kol; ++i)
        ans *= i;
    cout << ans << endl;
    forn (i, cnt0)
        cout << 0;

    /*int low = 1;
    for (int i = 0; i < s.size() - 1; ++i)
        low *= 10;
    int gans = 0;
    for (int i = low; i < low * 10; ++i)
    {
        if(ok(i))
            gans++;
    }
    cout << gans << endl;*/
}

int main()
{
#ifdef Baster
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    read();
    solve();
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define rep(_m,s,e) for(int _m=s;_m<e;_m++)
#define ll long long
string zarb(string first,int second)
{
	if (second == 10)
	{
		first += '0';
		return first;
	}
	string ans="",ans3="";
	ll ans2 = 0;
	char c;
	rep(i,0,first.length())
	{
		ans2 = ((first[i]-48) * second);
		while (ans2 / 10 > 0)
		{
			ans3 += (ans2 % 10) + 48;
			ans2 /= 10;
		}
		ans3 += (ans2 % 10) + 48;
		ans2 /= 10;
		rep(j,0,ans3.length())
		{
			c = (char)(ans3[ans3.length()-j-1]);
			ans += c;
		}
	}
	return ans;
}
int main()
{
	bool chars[26];
	rep(i,0,26)
		chars[i] = false;
	string s;
	cin >> s;
	string ans = "1";
	ll count = 1,charcount=0;
	rep(i,0,s.length())
		if (s[i] == '?')
		{
			if (i == 0)
				ans = zarb(ans,9);
			else ans = zarb(ans,10);
		}
		else if (s[i] <= 'Z' && s[i] >= 'A')
			if (!chars[s[i]-65])
			{
				chars[s[i]-65] = true;
				ans = zarb(ans,i == 0 ? 9-charcount : 10-charcount);
				charcount++;
			}
	string nahaii = "";
	bool flag = false,flag2 = false;
	rep(i,0,ans.length())
	{
		if (ans[i] == '0')
		{
			if (flag)
				nahaii += ans[i];
		}
		else if (ans[i] != '0')
		{
			flag = true;
			nahaii += ans[i];
		}
	}
	cout << nahaii << endl;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define rep(_m,s,e) for(int _m=s;_m<e;_m++)
#define ll long long
string zarb(string first,int second)
{
	if (second == 10)
	{
		first += '0';
		return first;
	}
	string ans="",ans3="";
	ll ans2 = 0;
	char c;
	rep(i,0,first.length())
	{
		ans2 = ((first[i]-48) * second);
		while (ans2 / 10 > 0)
		{
			ans3 += (ans2 % 10) + 48;
			ans2 /= 10;
		}
		ans3 += (ans2 % 10) + 48;
		ans2 /= 10;
		rep(j,0,ans3.length())
		{
			c = (char)(ans3[ans3.length()-j-1]);
			ans += c;
		}
		ans3 = "";
		ans2 = 0;
	}
	return ans;
}
int main()
{
	bool chars[26];
	rep(i,0,26)
		chars[i] = false;
	string s;
	cin >> s;
	string ans = "1";
	ll count = 1,charcount=0;
	rep(i,0,s.length())
		if (s[i] == '?')
		{
			if (i == 0)
				ans = zarb(ans,9);
			else ans = zarb(ans,10);
		}
		else if (s[i] <= 'Z' && s[i] >= 'A')
			if (!chars[s[i]-65])
			{
				chars[s[i]-65] = true;
				ans = zarb(ans,i == 0 ? 9-charcount : 10-charcount);
				charcount++;
			}
	string nahaii = "";
	bool flag = false,flag2 = false;
	rep(i,0,ans.length())
	{
		if (ans[i] == '0')
		{
			if (flag)
				nahaii += ans[i];
		}
		else if (ans[i] != '0')
		{
			flag = true;
			nahaii += ans[i];
		}
	}
	cout << nahaii << endl;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define rep(_m,s,e) for(int _m=s;_m<e;_m++)
#define ll long long
string zarb(string first,int second)
{
	if (second == 10)
	{
		first += '0';
		return first;
	}
	char c;
	int hasel=0,kool=0;
	string ans = "";
	for (int i=first.length()-1;i>=0;i--)
	{
		hasel = (first[i]-48) * second;
		hasel += kool;
		kool = hasel / 10;
		hasel %= 10;
		c = hasel + 48;
		ans += c;
	}
	while (kool/ 10 > 0)
	{
		ans += (kool % 10) + 48;
		kool /= 10;
	}
	ans += (kool % 10) + 48;
	kool /= 10;
	string ans3 = ans;
	ans = "";
	rep(j,0,ans3.length())
	{
		c = (char)(ans3[ans3.length()-j-1]);
		ans += c;
	}
	return ans;
	/*string ans="",ans3="";
	ll ans2 = 0;
	char c;
	rep(i,0,first.length())
	{
		ans2 = ((first[i]-48) * second);
		while (ans2 / 10 > 0)
		{
			ans3 += (ans2 % 10) + 48;
			ans2 /= 10;
		}
		ans3 += (ans2 % 10) + 48;
		ans2 /= 10;
		rep(j,0,ans3.length())
		{
			c = (char)(ans3[ans3.length()-j-1]);
			ans += c;
		}
		ans3 = "";
		ans2 = 0;
	}
	return ans;*/
}
int main()
{
	bool chars[26];
	rep(i,0,26)
		chars[i] = false;
	string s;
	cin >> s;
	string ans = "1";
	ll count = 1,charcount=0;
	rep(i,0,s.length())
		if (s[i] == '?')
		{
			if (i == 0)
				ans = zarb(ans,9);
			else ans = zarb(ans,10);
		}
		else if (s[i] <= 'Z' && s[i] >= 'A')
			if (!chars[s[i]-65])
			{
				chars[s[i]-65] = true;
				ans = zarb(ans,i == 0 ? 9-charcount : 10-charcount);
				charcount++;
			}
	string nahaii = "";
	bool flag = false,flag2 = false;
	rep(i,0,ans.length())
	{
		if (ans[i] == '0')
		{
			if (flag)
				nahaii += ans[i];
		}
		else if (ans[i] != '0')
		{
			flag = true;
			nahaii += ans[i];
		}
	}
	cout << nahaii << endl;
}


#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <stdint.h>

using namespace std;

int main( void )
{
	string s;
	getline( cin, s );

	vector< uint8_t > c( 'J' - 'A' + 1 );

	uint64_t r1 = 0;
	for( size_t i = 0; i < s.size(); i++ )
	{
		if( s[ i ] == '?' )
		{
			r1++;
		}
		else if( s[ i ] >= 'A' && s[ i ] <= 'J' )
		{
			c[ s[ i ] - 'A' ] = 1;
		}
	}

	uint64_t cq = 0;
	for( size_t i = 0; i < c.size(); i++ )
	{
		if( c[ i ] )
		{
			cq++;
		}
	}

	uint64_t r2 = 1;
	if( cq )
	{
		if( s[ 0 ] >= 'A' && s[ 0 ] <= 'J' )
		{
			if( cq == 1 )
			{
				r2 = 9;
			}
			else
			{
				cq--;
				r2 = 9;
				uint64_t k = 9;
				while( cq-- )
				{
					r2 *= k;
					k--;
				}
			}
		}
		else
		{
			uint64_t k = 10;
			while( cq-- )
			{
				r2 *= k;
				k--;
			}
		}
	}

	if( !r1 && r2 == 1 )
	{
		cout << 1;
	}
	else if( r1 && r2 == 1 )
	{
		if( s[ 0 ] == '?' )
		{
			cout << 9;
			r1--;
		}
		while( r1-- )
		{
			cout << 0;
		}
	}
	else if( !r1 & r2 != 1 )
	{
		cout << r2;
	}
	else
	{
		if( s[ 0 ] == '?' )
		{
			r2 *= 9;
			r1--;
		}
		cout << r2;
		while( r1-- )
		{
			cout << 0;
		}
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <stdint.h>

using namespace std;

int main( void )
{
	string s;
	getline( cin, s );

	vector< uint8_t > c( 'J' - 'A' + 1 );

	uint64_t r1 = 0;
	for( size_t i = 0; i < s.size(); i++ )
	{
		if( s[ i ] == '?' )
		{
			r1++;
		}
		else if( s[ i ] >= 'A' && s[ i ] <= 'J' )
		{
			c[ s[ i ] - 'A' ] = 1;
		}
	}

	uint64_t cq = 0;
	for( size_t i = 0; i < c.size(); i++ )
	{
		if( c[ i ] )
		{
			cq++;
		}
	}

	uint64_t r2 = 1;
	if( cq )
	{
		if( s[ 0 ] >= 'A' && s[ 0 ] <= 'J' )
		{
			if( cq == 1 )
			{
				r2 = 9;
			}
			else
			{
				cq--;
				r2 = 9;
				uint64_t k = 9;
				while( cq-- )
				{
					r2 *= k;
					k--;
				}
			}
		}
		else
		{
			uint64_t k = 10;
			while( cq-- )
			{
				r2 *= k;
				k--;
			}
		}
	}

	if( !r1 && r2 == 1 )
	{
		cout << 1;
	}
	else if( r1 && r2 == 1 )
	{
		if( s[ 0 ] == '?' )
		{
			cout << 9;
			r1--;
		}
		else
		{
			cout << 1;
		}
		while( r1-- )
		{
			cout << 0;
		}
	}
	else if( !r1 & r2 != 1 )
	{
		cout << r2;
	}
	else
	{
		if( s[ 0 ] == '?' )
		{
			r2 *= 9;
			r1--;
		}
		cout << r2;
		while( r1-- )
		{
			cout << 0;
		}
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <stdint.h>

using namespace std;

int main( void )
{
	string s;
	getline( cin, s );

	vector< uint8_t > c( 'J' - 'A' + 1 );

	uint64_t r1 = 1;
	for( size_t i = 0; i < s.size(); i++ )
	{
		if( s[ i ] == '?' )
		{
			r1 *= 10;
		}
		else if( s[ i ] >= 'A' && s[ i ] <= 'J' )
		{
			c[ s[ i ] - 'A' ] = 1;
		}
	}
	if( r1 )
	{
		if( s[ 0 ] == '?' )
		{
			if( r1 == 1 )
			{
				r1 = 9;
			}
			else
			{
				r1 = r1 / 10 * 9;
			}
		}
	}

	uint64_t cq = 0;
	for( size_t i = 0; i < c.size(); i++ )
	{
		if( c[ i ] )
		{
			cq++;
		}
	}

	uint64_t r2 = 1;
	if( cq )
	{
		if( s[ 0 ] >= 'A' && s[ 0 ] <= 'J' )
		{
			if( cq == 1 )
			{
				r2 = 9;
			}
			else
			{
				cq--;
				r2 = 9;
				uint64_t k = 9;
				while( cq-- )
				{
					r2 *= k;
					k--;
				}
			}
		}
		else
		{
			uint64_t k = 10;
			while( cq-- )
			{
				r2 *= k;
				k--;
			}
		}
	}

	if( r1 == 1 && r2 == 1 )
	{
		cout << 1;
	}
	else if( r1 != 1 && r2 == 1 )
	{
		cout << r1;
	}
	else if( r1 == 1 & r2 != 1 )
	{
		cout << r2;
	}
	else
	{
		cout << ( r1 * r2 );
	}

	return 0;
}


#pragma comment(linker, "/STACK:500000000")
#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <ctype.h>
#include <stdio.h>
#include <bitset>
#include <vector>
#include <string>
#include <math.h>
#include <time.h>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#define Int long long
#define INF 0x3F3F3F3F
#define eps 1e-9
using namespace std;

char A[1000001];

#define N 100

Int C[N][N];

Int AA(int n, int k)
{
	Int res = C[n][k];
	for(int i = 2; i <= k; i++)
		res *= i;
	return res;
}

int main()
{
	C[0][0] = 1;
	for(int i = 1; i < N; i++)
	{
		C[i][0] = 1;
		for(int j = 0; j <= i; j++)
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
	}

	scanf("%s", A);
	int n = strlen(A);
	int c1 = 0;
	set<char> S;
	for(int i = 0; i < n; i++)
		if (A[i] == '?')
			c1++;
		else if (isalpha(A[i]))
			S.insert(A[i]);
	int sz = S.size();
	Int res = 1;
	if (sz)
	{
		res = AA(10, sz);
		if (isalpha(A[0]))
			res -= AA(9, sz - 1);
	}
	if (c1)
	{
		if (A[0] == '?')
			res *= 9;
		else
			res *= 10;
		c1--;
	}
	cout << res;
	for(int i = 0; i < c1; i++)
		printf("0");
	puts("");
	return 0;
}


#pragma comment(linker, "/STACK:500000000")
#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <ctype.h>
#include <stdio.h>
#include <bitset>
#include <vector>
#include <string>
#include <math.h>
#include <time.h>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#define Int long long
#define INF 0x3F3F3F3F
#define eps 1e-9
using namespace std;

char A[1000001];

#define N 100

Int C[N][N];

Int AA(int n, int k)
{
	Int res = C[n][k];
	for(int i = 2; i <= k; i++)
		res *= i;
	return res;
}

int main()
{
	C[0][0] = 1;
	for(int i = 1; i < N; i++)
	{
		C[i][0] = 1;
		for(int j = 0; j <= i; j++)
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
	}

	scanf("%s", A);
	int n = strlen(A);
	int c1 = 0;
	set<char> S;
	for(int i = 0; i < n; i++)
		if (A[i] == '?')
			c1++;
		else if (isalpha(A[i]))
			S.insert(A[i]);
	int sz = S.size();
	Int res = 1;
	if (sz)
	{
		res = AA(10, sz);
		if (isalpha(A[0]))
			res -= AA(9, sz - 1);
	}
	if (c1)
	{
		if (A[0] == '?')
			res *= 9;
		else
			res *= 10;
		c1--;
	}
	cout << res;
	for(int i = 1; i < c1; i++)
		printf("0");
	puts("");
	return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
  //ReadData
  char str[100005];
  scanf("%s", &str);
  //Solve
  int len = strlen(str);
  bool used[15];
  memset(used, 0, sizeof(used));
  int answer = 1;
  int cnt = 10;
  for(int i = 0; i < len; i++)
  {
    if(str[i] == '?')
    {
      answer *= i == 0 ? 9 : 10;
    }
    else if(str[i] >= 'A' && str[i] <= 'Z')
    {
      if(!used[(int)(str[i] - 'A')])
      {
        used[(int)(str[i] - 'A')] = true;
        answer *= i == 0 ? cnt - 1 : cnt;
        cnt--;
        if(cnt == -1) throw;
      }
    }
  }
  //WriteData
  printf("%d\n", answer);
  return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  #endif
  if(!true)
  {
    freopen("input.txt", "w", stdout);
    /*printf("A");
    for(int i = 0; i < 100000 - 2; i++)
    {
      printf("J");
    }
    printf("B");*/
    for(int i = 0; i < 100000; i++)
    {
      printf("?");
    }
    return 0;
  }
  //ReadData
  char str[100005];
  scanf("%s", &str);
  //Solve
  int len = strlen(str);
  bool used[15];
  memset(used, 0, sizeof(used));
  __int64 answer = 1LL;
  __int64 cnt = 10;
  int zero = 0;
  for(int i = 0; i < len; i++)
  {
    if(str[i] == '?')
    {
      if(i == 0)
      {
        answer *= 9;
      }
      else
      {
        zero++;
      }
    }
    else if(str[i] >= 'A' && str[i] <= 'Z')
    {
      if(!used[(int)(str[i] - 'A')])
      {
        used[(int)(str[i] - 'A')] = true;
        answer *= i == 0 ? cnt - 1LL : cnt;
        cnt--;
        //if(cnt == -1LL) throw;
      }
    }
  }
  //WriteData
  printf("%I64d", answer);
  for(int i = 0; i < zero; i++)
  {
    printf("0");
  }
  printf("\n");
  return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
  //ReadData
  char str[100005];
  scanf("%s", &str);
  //Solve
  int len = strlen(str);
  bool used[15];
  memset(used, 0, sizeof(used));
  __int64 answer = 1LL;
  __int64 cnt = 10;
  for(int i = 0; i < len; i++)
  {
    if(str[i] == '?')
    {
      answer *= i == 0 ? 9LL : 10LL;
    }
    else if(str[i] >= 'A' && str[i] <= 'Z')
    {
      if(!used[(int)(str[i] - 'A')])
      {
        used[(int)(str[i] - 'A')] = true;
        answer *= i == 0 ? cnt - 1LL : cnt;
        cnt--;
        //if(cnt == -1LL) throw;
      }
    }
  }
  //WriteData
  printf("%I64d\n", answer);
  return 0;
}


#include <string>
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
vector <bool> c (256);
typedef vector<int> lnum;
const int base = 1000*1000*1000;
void print(lnum &a){
	printf("%d", a.empty() ? 0 : a.back());
	for(int i = (int)a.size() - 2; i >= 0; --i){
		printf("%09d", a[i]);
	}
}
void multiplicate(lnum &a, int b){
	int carry = 0;
	for (size_t i=0; i<a.size() || carry; ++i) {
		if (i == a.size())
			a.push_back (0);
		long long cur = carry + a[i] * 1ll * b;
		a[i] = int (cur % base);
		carry = int (cur / base);
	}
	while (a.size() > 1 && a.back() == 0)
		a.pop_back();
}
int main(){
	string mask;
	cin >> mask;
	lnum s;
	s.push_back(1);
	int remaining = 10;
	for(int i = 0; i < mask.size(); ++i){
		if(mask[i] >= '0' && mask[i] <= '9'){
			if(i == 0 && mask[i] == '0'){
				printf("0\n"); return (0);
			}
		}
		if(mask[i] >= 'A' && mask[i] <= 'J'){
			if(c[mask[i]]){
				continue;
			}
			if(i == 0){
				multiplicate(s, remaining - 1);
				// s *= remaining - 1;
			}
			else{
				multiplicate(s, remaining);
				// s *= remaining;
			}
			--remaining;
			c[mask[i]] = true;
		}
		if(mask[i] == '?'){
			if(i == 0){
				multiplicate(s, 9);
				// s *= 9;
			}
			else{
				multiplicate(s, 10);
				// s *= 10;
			}
		}
	}
	print(s); printf("\n");
	return (0);
}


#include <string>
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
vector <bool> c (256);
typedef vector<int> lnum;
const int base = 1000*1000*1000;
inline void print(lnum &a){
	printf("%d", a.empty() ? 0 : a.back());
	for(int i = (int)a.size() - 2; i >= 0; --i){
		printf("%09d", a[i]);
	}
}
int buffer = 1;
inline void multiplicate(lnum &a, int b, bool flush = false){
    if(buffer < 10000000 && !flush){
        buffer *= b;
        return;
    }
    else{
        b *= buffer;
        buffer = 1;
    }
	int carry = 0;
	for (size_t i=0; i<a.size() || carry; ++i) {
		if (i == a.size())
			a.push_back (0);
		long long cur = carry + a[i] * 1ll * b;
		a[i] = int (cur % base);
		carry = int (cur / base);
	}
	while (a.size() > 1 && a.back() == 0)
		a.pop_back();
}
int main(){
	string mask;
	cin >> mask;
	lnum s;
	s.push_back(1);
	int remaining = 10;
	for(int i = 0; i < mask.size(); ++i){
		if(mask[i] >= '0' && mask[i] <= '9'){
			if(i == 0 && mask[i] == '0'){
				printf("0\n"); return (0);
			}
		}
		if(mask[i] >= 'A' && mask[i] <= 'J'){
			if(c[mask[i]]){
				continue;
			}
			if(i == 0){
				multiplicate(s, remaining - 1);
				// s *= remaining - 1;
			}
			else{
				multiplicate(s, remaining);
				// s *= remaining;
			}
			--remaining;
			c[mask[i]] = true;
		}
		if(mask[i] == '?'){
			if(i == 0){
				multiplicate(s, 9);
				// s *= 9;
			}
			else{
				multiplicate(s, 10);
				// s *= 10;
			}
		}
	}
	multiplicate(s, 1, true);
	print(s); printf("\n");
	return (0);
}


#include <string>
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
vector <bool> c (256);
int main(){
	string mask;
	cin >> mask;
	long long s = 1;
	int remaining = 10;
	for(int i = 0; i < mask.size(); ++i){
		if(mask[i] >= '0' && mask[i] <= '9'){
			if(i == 0 && mask[i] == '0'){
				s = 0;
			}
		}
		if(mask[i] >= 'A' && mask[i] <= 'J'){
			if(c[mask[i]]){
				continue;
			}
			if(i == 0){
				s *= remaining - 1;
			}
			else{
				s *= remaining;
			}
			--remaining;
			c[mask[i]] = true;
		}
		if(mask[i] == '?'){
			if(i == 0){
				s *= 9;
			}
			else{
				s *= 10;
			}
		}
	}
	printf("%lld\n", s);
	return (0);
}


#include <string>
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
vector <bool> c (256);
int main(){
	string mask;
	cin >> mask;
	long long s = 1;
	int remaining = 10;
	for(int i = 0; i < mask.size(); ++i){
		if(mask[i] >= '0' && mask[i] <= '9'){
			if(i == 0 && mask[i] == '0'){
				s = 0;
			}
		}
		if(mask[i] >= 'A' && mask[i] <= 'J'){
			if(c[mask[i]]){
				continue;
			}
			if(i == 0){
				s *= remaining - 1;
			}
			else{
				s *= remaining;
			}
			--remaining;
			c[mask[i]] = true;
		}
		if(mask[i] == '?'){
			s *= 10;
		}
	}
	printf("%lld\n", s);
	return (0);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define INF 1000000007
#define TASK "champion"
#define nmax 1002

string s;
ll res=1;
bool used[100];
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
   // freopen(TASK".in", "r", stdin);
   // freopen(TASK".out", "w", stdout);
#endif
    cin>>s;

    int cnt = 10,kol=0;
    for (int i=0; i<s.length(); i++)
        if (s[i]=='?' && i!=0) kol++;
        else
        if (s[i]=='?' && i==0) res*=9;
        else
        if (s[i]>='A' && s[i]<='J' && i!=0 && !used[s[i]-'A']) res*=cnt,cnt--,used[s[i]-'A']=true;
        else
        if (s[i]>='A' && s[i]<='J' && i==0 && !used[s[i]-'A']) res*=(cnt-1),cnt--,used[s[i]-'A']=true;
    cout<<res;
    for (int i=0; i<kol; i++)
        cout<<0;

}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define INF 1000000007
#define TASK "champion"
#define nmax 1002

string s;
ll res=1;
bool used[100];
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
   // freopen(TASK".in", "r", stdin);
   // freopen(TASK".out", "w", stdout);
#endif
    cin>>s;

    int cnt = 10;
    for (int i=0; i<s.length(); i++)
        if (s[i]=='?' && i!=0) res*=10;
        else
        if (s[i]=='?' && i==0) res*=9;
        else
        if (s[i]>='A' && s[i]<='J' && i!=0 && !used[s[i]-'A']) res*=cnt,cnt--,used[s[i]-'A']=true;
        else
        if (s[i]>='A' && s[i]<='J' && i==0 && !used[s[i]-'A']) res*=(cnt-1),cnt--,used[s[i]-'A']=true;
    cout<<res;

}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define INF 1000000007
#define TASK "champion"
#define nmax 1002

string s;
int res=1;
bool used[100];
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
   // freopen(TASK".in", "r", stdin);
   // freopen(TASK".out", "w", stdout);
#endif
    cin>>s;

    int cnt = 10;
    for (int i=0; i<s.length(); i++)
        if (s[i]=='?' && i!=0) res*=10;
        else
        if (s[i]=='?' && i==0) res*=9;
        else
        if (s[i]>='A' && s[i]<='J' && i!=0 && !used[s[i]-'A']) res*=cnt,cnt--,used[s[i]-'A']=true;
        else
        if (s[i]>='A' && s[i]<='J' && i==0 && !used[s[i]-'A']) res*=(cnt-1),cnt--,used[s[i]-'A']=true;
    cout<<res;

}


//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
//#pragma comment(linker,"/STACK:33554432") /*32Mb*/
#define _CRT_SECURE_NO_DEPRECATE
#include<sstream>
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<memory>
#include<string>
#include<vector>
#include<cctype>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<complex>
#include<set>
#include<algorithm>

using namespace std;

typedef unsigned long long      ui64;
typedef long long               i64;
typedef vector<int>             VI;
typedef vector<bool>            VB;
typedef vector<VI>              VVI;
typedef vector<string>          VS;
typedef pair<int,int>           PII;
typedef map<string,int>         MSI;
typedef set<int>                SI;
typedef set<string>             SS;
typedef complex<double>         CD;
typedef vector< CD >            VCD;
typedef map<int,int>            MII;
typedef pair<double,double>     PDD;

#define PB                      push_back
#define MP                      make_pair
#define X                       first
#define Y                       second
#define FOR(i, a, b)            for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)           for(int i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b)             memset(a, b, sizeof(a))
#define SZ(a)                   int((a).size())
#define ALL(a)                  (a).begin(), (a).end()
#define RALL(a)                 (a).rbegin(), (a).rend()
#define INF                     (2000000000)

#ifdef _DEBUG
#define eprintf(...) fprintf (stderr, __VA_ARGS__)
#else
#define eprintf(...) assert (true)
#endif

const double PI = acos(-1.0);

int main() {
    string s;
    cin >> s;
    int res = 1;
    set<char> S;
    bool f =false;
    int small = 1;
    int zeros = 0;
    FOR(i,0,SZ(s)){
        if(s[i]>='0' && s[i]<='9')
            continue;
        if(s[i]=='?') {
            if(i)
                zeros ++;
            else
                small *= 9;
        }
        else {
            if(i==0)
                f = true;
            S.insert(s[i]);
        }
    }

    FOR(i,0,SZ(S)) {
        if(f && !i)
            small *= 9;
        else
            small *= 10-i;
    }
    cout << small;
    FOR(i,0,zeros)
        cout << "0";
    cout << endl;
    return 0;
}


//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
//#pragma comment(linker,"/STACK:33554432") /*32Mb*/
#define _CRT_SECURE_NO_DEPRECATE
#include<sstream>
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<memory>
#include<string>
#include<vector>
#include<cctype>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<complex>
#include<set>
#include<algorithm>

using namespace std;

typedef unsigned long long      ui64;
typedef long long               i64;
typedef vector<int>             VI;
typedef vector<bool>            VB;
typedef vector<VI>              VVI;
typedef vector<string>          VS;
typedef pair<int,int>           PII;
typedef map<string,int>         MSI;
typedef set<int>                SI;
typedef set<string>             SS;
typedef complex<double>         CD;
typedef vector< CD >            VCD;
typedef map<int,int>            MII;
typedef pair<double,double>     PDD;

#define PB                      push_back
#define MP                      make_pair
#define X                       first
#define Y                       second
#define FOR(i, a, b)            for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)           for(int i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b)             memset(a, b, sizeof(a))
#define SZ(a)                   int((a).size())
#define ALL(a)                  (a).begin(), (a).end()
#define RALL(a)                 (a).rbegin(), (a).rend()
#define INF                     (2000000000)

#ifdef _DEBUG
#define eprintf(...) fprintf (stderr, __VA_ARGS__)
#else
#define eprintf(...) assert (true)
#endif

const double PI = acos(-1.0);

int main() {
    string s;
    cin >> s;
    int res = 1;
    set<char> S;
    bool f =false;
    int small = 1;
    int zeros = 0;
    FOR(i,0,SZ(s)){
        if(s[i]>='0' && s[i]<='9')
            continue;
        if(s[i]=='?') {
            if(i)
                zeros ++;
            else
                small *= 9;
        }
        else {
            if(i==0)
                f = true;
            S.insert(s[i]);
        }
    }

    FOR(i,0,SZ(S)) {
        if(f && !i)
            small *= 9;
        else
            small *= 10-i;
    }
    cout << small;
    FOR(i,0,zeros)
        printf("0");
    cout << endl;
    return 0;
}


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

int main()
{
    string code;
    unsigned long long ans=1;
    char letters[10];
    short k=0 ;
    cin>>code ;
    int length=code.length() ;
    bool exist=false ;

    if (code[0]=='?')
    {
    ans=9;
    }

    else if(code[0]=='A' || code[0]=='B' ||code[0]=='C' ||code[0]=='D' ||code[0]=='E' ||code[0]=='F' ||code[0]=='G' ||code[0]=='H' ||code[0]=='I' ||code[0]=='J' )
    {
        ans=9 ;
        letters[0]=code[0];
        k++;
    }

    for(int i=1;i<length;i++)
    {
        if (code[i]=='?')
            ans*=10;
        else if (k<10)
        { if (code[i]=='A' || code[i]=='B' ||code[i]=='C' ||code[i]=='D' ||code[i]=='E' ||code[i]=='F' ||code[i]=='G' ||code[i]=='H' ||code[i]=='I' ||code[i]=='J' )

        {
            exist=false;
            for(int j=0;j<k;j++)
            {
                if(code[i]==letters[j])
                {
                    exist=true;
                    break;
                }
            }
            if(!exist && k<10)
            {
                ans=ans*(10-k);
                letters[k]=code[i];
                k++;
            }}
        }
    }
    cout<<ans ;
       return 0;
}


#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <locale>
#include <sstream>

using namespace std;

int main()
{
    string code;
    unsigned long long ans=1;
    char letters[10];
    short k=0 ;
    cin>>code ;
    int length=code.length() ;
    bool exist=false ;
    unsigned long long quesmarks=0;

    if (code[0]=='?')
    {
    ans=9;
    }

    else if(code[0]=='A' || code[0]=='B' ||code[0]=='C' ||code[0]=='D' ||code[0]=='E' ||code[0]=='F' ||code[0]=='G' ||code[0]=='H' ||code[0]=='I' ||code[0]=='J' )
    {
        ans=9 ;
        letters[0]=code[0];
        k++;
    }

    for(int i=1;i<length;i++)
    {
        if (code[i]=='?')
            quesmarks+=1;
        else if (k<10)
        { if (code[i]=='A' || code[i]=='B' ||code[i]=='C' ||code[i]=='D' ||code[i]=='E' ||code[i]=='F' ||code[i]=='G' ||code[i]=='H' ||code[i]=='I' ||code[i]=='J' )

        {
            exist=false;
            for(int j=0;j<k;j++)
            {
                if(code[i]==letters[j])
                {
                    exist=true;
                    break;
                }
            }
            if(!exist && k<10)
            {
                ans=ans*(10-k);
                letters[k]=code[i];
                k++;
            }}
        }
    }
    code="";
    ostringstream convert;
    convert << ans;
    code = convert.str();

    for (unsigned long long i=0;i<quesmarks;i++)
        code=code+"0";

    cout<<code ;
       return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>

using namespace std;

#pragma comment (linker, "/STACK:256000000")

typedef long long int64;

bool b_ar[10] = {false};

int64 binpow(int64 a, int n)
{
    int64 res = 1;

    while (n)
    {
        if (n & 1)
            res *= a;

        a *= a;
        n >>= 1;
    }

    return res;
}

int64 fact(int n)
{
    if (n < 2)
        return 1;

    int64 res = 1;

    for (int i = 2; i <= n; ++i)
        res *= i;

    return res;
}

int64 C(int n, int k)
{
    if (n <= k || k < 1)
        return 1;

    return fact(n) / fact(k) / fact(n - k);
}

int main()
{
    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

    string s;
    int qs = 0;
    int ls = 0;

    cin >> s;

    for (int i = 0; i < s.length(); ++i)
        if (s[i] == '?')
            ++qs;
        else if (s[i] >= 'A' && s[i] <= 'J')
            b_ar[s[i] - 'A'] = true;

    for (int i = 0; i < 10; ++i)
        ls += b_ar[i];

    /*int64 ans = binpow(10, qs) * C(10, ls) * fact(ls);

    if (s[0] == '?')
        ans = ans / 10 * 9;
    else if (s[0] >= 'A' && s[0] <= 'J')
        ans = binpow(10, qs) * (C(10, ls) * fact(ls) - C(9, ls - 1) * fact(ls - 1));
        */

    int64 ans = C(10, ls) * fact(ls);

    if (s[0] == '?')
    {
        //ans = ans / 10 * 9;
        ans *= 9;
        --qs;
    }
    else if (s[0] >= 'A' && s[0] <= 'J')
        ans = (C(10, ls) * fact(ls) - C(9, ls - 1) * fact(ls - 1));

    printf("%I64d", ans);
    for (int i = 0; i < qs; ++i)
        printf("0");
    printf("\n");

    return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>

using namespace std;

#pragma comment (linker, "/STACK:256000000")

typedef long long int64;

bool b_ar[10] = {false};

int64 binpow(int64 a, int n)
{
    int64 res = 1;

    while (n)
    {
        if (n & 1)
            res *= a;

        a *= a;
        n >>= 1;
    }

    return res;
}

int64 fact(int n)
{
    if (n < 2)
        return 1;

    int64 res = 1;

    for (int i = 2; i <= n; ++i)
        res *= i;

    return res;
}

int64 C(int n, int k)
{
    if (n <= k || k < 1)
        return 1;

    return fact(n) / fact(k) / fact(n - k);
}

int main()
{
//    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

    string s;
    int qs = 0;
    int ls = 0;

    cin >> s;

    for (int i = 0; i < s.length(); ++i)
        if (s[i] == '?')
            ++qs;
        else if (s[i] >= 'A' && s[i] <= 'J')
            b_ar[s[i] - 'A'] = true;

    for (int i = 0; i < 10; ++i)
        ls += b_ar[i];

    /*int64 ans = binpow(10, qs) * C(10, ls) * fact(ls);

    if (s[0] == '?')
        ans = ans / 10 * 9;
    else if (s[0] >= 'A' && s[0] <= 'J')
        ans = binpow(10, qs) * (C(10, ls) * fact(ls) - C(9, ls - 1) * fact(ls - 1));
        */

    int64 ans = C(10, ls) * fact(ls);

    if (s[0] == '?')
    {
        //ans = ans / 10 * 9;
        ans *= 9;
        --qs;
    }
    else if (s[0] >= 'A' && s[0] <= 'J')
        ans = (C(10, ls) * fact(ls) - C(9, ls - 1) * fact(ls - 1));

    printf("%I64d", ans);
    for (int i = 0; i < qs; ++i)
        printf("0");
    printf("\n");

    return 0;
}


#include <iostream>
#include <string>
#include <set>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int pro = 1;
	set<char > c;
//	set<char > ss;
	int count = 0;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] >= 'A' && s[i] <= 'J' && (!c.count(s[i])))
		{
			if (i == 0)
				pro *= 9-c.size();
			else
			{
				if (c.size() > 0)
					pro *= 10-c.size();
				else
					count++;
			}
			c.insert(s[i]);
		}
		else if (s[i] == '?')
		{
			if (i == 0)
				pro *= 9;
			else
				count++;
		}

	}
	cout << pro;
	for (int i = 0; i < count; i++)
		cout << 0;
	cout << endl;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md;
   int id;
}a[maxn];
ll e[maxn];
int n,m,id;
ll ans[maxn];
pq <pair<ll,int> >q;
int main(){
    scanf("%d%d", &n, &m);

    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v % m;
        a[i].md = tmp;
        e[tmp]++;
        a[i].id = i;
    }

    for(int i=0; i<m; i++) {
        q.push(make_pair(1ll*e[i],i));
    }

    ll cnt = 0;
    int st = n / m;
    while(!q.empty())
    {
        ll c = 1ll*q.top().fi;
        //debug(c);
        int d = q.top().se;
        q.pop();
        if(e[d] != c)continue;
        if(c > st)
        {
            cnt += c - st;
            e[d] = st;
            if(d+1==m) {
                e[0] += c - st;
                q.push(make_pair(1ll*e[0],0));
            } else {
                e[d+1] += c - st;
                q.push(make_pair(1ll*e[d+1],d+1));
            }
        }else break;

    }

    printf("%I64d\n",cnt);

    sort(a+1,a+1+n,[](node x,node y){if(x.md==y.md)return x.v<y.v;return x.md < y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st == 0)tp--;
        int x = (tp - a[i].md);
        if(x<0)x += m;
        x %= m;

        ans[a[i].id] = a[i].v + x;
    }

    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
ll a[maxn];
int ct[maxn];
int f[maxn];
int n,m;
int main(){
    int mx = 0,id ;
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++) {
        scanf("%I64d", a+i);
        int tmp = a[i]%m;
        ct[tmp]++;
        if(ct[tmp]>mx)
        {
            mx = ct[tmp];
            id = tmp;
        }
    }
    int cnt = 0;
    int st = n/m;
    for(int i=0; i<m; i++,id++) {
            if(id==m)id = 0;
            if(id+1!=m)ct[id+1] += ct[id] - st;
            else ct[0] += ct[id] - st;
            cnt += ct[id] - st>0?ct[id] - st:st-ct[id];
            f[id] = ct[id] - st;

    }
    printf("%d\n",cnt);
    for(int i=1; i<=n; i++)
    {
        int tmp = a[i] % m;
            if(f[tmp]>0)
            {
                printf("%I64d ",a[i]+1);
                f[tmp]--;
            }
            else if(f[tmp]<0)
            {
                printf("%I64d ",a[i]-1);
                f[tmp]++;
            }
            else  printf("%I64d ",a[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md,id;
} a[maxn];
int ct[maxn*2];
int n,m;
ll ans[maxn];

int main(){
    scanf("%d%d", &n, &m);
    int mx = -1,id;
    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v%m;
        a[i].md = tmp;
        ct[tmp]++;
        a[i].id = i;
        if(ct[tmp]>mx){
            mx = ct[tmp];
            id = tmp;
        }
    }
    for(int i=n+1;i<=2*n;i++)
        ct[i] = ct[i-n];

    ll cnt = 0;
    int st = n / m;
    for(int i=0; i<m; i++,id++) {
            ct[id+1] += ct[id] - st;
            cnt += ct[id] - st >= 0?ct[id] - st: st - ct[id];
    }
    printf("%I64d\n",cnt);
    sort(a+1,a+1+n,[](node x,node y){return x.md<y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st==0)tp--;
        int x = (tp-a[i].md);
        if(x<0)x+=m;
        ans[a[i].id]=a[i].v+x;
    }
    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md;
   int id;
}a[maxn];
ll e[maxn];
ll ndd[maxn];
int n,m,id;
ll ans[maxn];
pq <pair<ll,int> >q;
int main(){
    scanf("%d%d", &n, &m);

    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v % m;
        a[i].md = tmp;
        e[tmp]++;
        a[i].id = i;
    }

    for(int i=0; i<m; i++) {
        q.push(make_pair(1ll*e[i],i));
    }

    ll cnt = 0;
    int st = n / m;
    while(!q.empty())
    {
        ll c = 1ll*q.top().fi;
        //debug(c);
        int d = q.top().se;
        q.pop();
        if(e[d] != c)continue;
        if(c > st)
        {
            cnt += c - st;
            e[d] = st;
            if(d+1==m) {
                e[0] += c - st;
                q.push(make_pair(1ll*e[0],0));
                ndd[d] += c-st;
            } else {
                e[d+1] += c - st;
                q.push(make_pair(1ll*e[d+1],d+1));
                ndd[d] += c-st;
            }
        }else break;

    }

    printf("%I64d\n",cnt);

    sort(a+1,a+1+n,[](node x,node y){if(x.md==y.md)return x.v<y.v;return x.md < y.md;});
    for(int i=1; i<=n; i++)
    {
        int tmp = a[i].md;
        while(ndd[tmp]!=0&&tmp<m)
        {
            ndd[tmp]--;
            a[i].v++;
            tmp++;
        }
        ans[a[i].id] = a[i].v;
    }

    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
ll a[maxn];
int ct[maxn],c2[maxn];
int f[3][maxn];
int n,m;
int main(){
    int mx = 0,id ;
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++) {
        scanf("%I64d", a+i);
        int tmp = a[i]%m;
        ct[tmp]++;
        c2[tmp] = ct[tmp];
        if(ct[tmp]>mx)
        {
            mx = ct[tmp];
            id = tmp;
        }
    }
    int id2 = id;
    int cnt1 = 0,cnt2=0;
    int st = n/m;
    for(int i=0; i<m; i++,id++) {
            if(id==m)id = 0;
            if(id+1!=m)ct[id+1] += ct[id] - st;
            else ct[0] += ct[id] - st;
            cnt1 += ct[id] - st>0?ct[id] - st:st-ct[id];
            f[0][id] = ct[id] - st;

    }
    id = id2;
    for(int i=0; i<m; i++,id--) {
            if(id==-1)id = m-1;
            if(id!=0)c2[id-1] += c2[id] - st;
            else c2[m-1] += c2[id] - st;
            cnt2 += c2[id] - st>0?c2[id] - st:st-c2[id];
            f[1][id] = c2[id] - st;
    }
    int ans,flag;
    // debug(cnt2);
    if(cnt1<cnt2)
    {
        ans = cnt1;
        flag = 0;
    }
    else {
        ans = cnt2;
        flag = 1;
    }

    printf("%d\n",ans);
    if(flag==0)
    {
        for(int i=1; i<=n; i++)
        {
            int tmp = a[i] % m;
                if(f[flag][tmp]>0)
                {
                    printf("%I64d ",a[i]+1);
                    f[flag][tmp]--;
                }
                else if(f[flag][tmp]<0)
                {
                    printf("%I64d ",a[i]-1+m);
                    f[flag][tmp]++;
                }
                else  printf("%I64d ",a[i]);
        }
    }
    else{
         for(int i=1; i<=n; i++)
        {
            int tmp = a[i] % m;
                if(f[flag][tmp]>0)
                {
                    printf("%I64d ",a[i]-1+m);
                    f[flag][tmp]--;
                }
                else if(f[flag][tmp]<0)
                {
                    printf("%I64d ",a[i]+1);
                    f[flag][tmp]++;
                }
                else  printf("%I64d ",a[i]);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md,id;
} a[maxn];
int ct[maxn*2],e[maxn*2];
int n,m,id;
ll ans[maxn];
pq <pair<ll,int> >q;
int main(){
    scanf("%d%d", &n, &m);
    ll mx=-1,id;
    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v%m;
        a[i].md = tmp;
        e[tmp]++;
        a[i].id = i;

    }
    for(int i=0;i<m;i++) {
        q.push(make_pair(e[i],i));
    }

    ll cnt = 0;
    ll st = n / m;
    while(!q.empty())
    {
        ll c = q.top().fi;
        int d = q.top().se;
        q.pop();
        if(c>st)
        {
            cnt+=c-st;
            if(d+1==m) {
                e[0] += c-st;
                q.push(make_pair(e[0],0));
            }else {
                e[d+1] += c-st;
                q.push(make_pair(e[d+1],d+1));
            }
        }
    }

    printf("%I64d\n",cnt);
    sort(a+1,a+1+n,[](node x,node y){return x.md < y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st == 0)tp--;
        int x = (tp - a[i].md);
        if(x<0)x += m;
        ans[a[i].id] = a[i].v + x;
        cnt += x;
    }

    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md,id;
} a[maxn];
int ct[maxn];
int f[maxn];
int n,m;
ll ans[maxn];

int main(){
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v%m;
        a[i].md = tmp;
        ct[tmp]++;
        a[i].id = i;
    }
    ll cnt = 0;
    int st = n / m;
    for(int i=0; i<m; i++) {
            ct[i+1] += ct[i] - st;
            cnt += ct[i] - st >= 0?ct[i] - st: st - ct[i];
            f[i] = ct[i] - st;
    }
    printf("%I64d\n",cnt);
    sort(a+1,a+1+n,[](node x,node y){return x.md<y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st==0)tp--;
        int x = (tp-a[i].md);
        if(x<0)x+=m;
        ans[a[i].id]=a[i].v+x;
    }
    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
ll a[maxn];
int ct[maxn];
int f[maxn];
int n,m;
int gt(int a,int b)
{
    return (a/b+1)*b-a;
}
int main(){
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++) {
        scanf("%I64d", a+i);
        int tmp = a[i]%m;
        ct[tmp]++;
    }
    ll cnt = 0;
    int st = n/m;
    for(int i=0; i<m; i++) {
            ct[i+1] += ct[i] - st;
            cnt+= ct[i] - st>=0?ct[i] - st:st-ct[i];
            f[i] = ct[i] - st;

    }
    printf("%I64d\n",cnt);
    for(int i=1; i<=n; i++)
    {
        int tmp = a[i] % m;
            if(f[tmp]>0)
            {
                printf("%I64d ",a[i]+1);
                f[tmp]--;
            }
            else if(f[tmp]<0)
            {
                printf("%I64d ",a[i]-1+m);
                f[tmp]++;
            }
            else  printf("%I64d ",a[i]);

    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md;
} a[maxn];
int ct[maxn];
int f[maxn];
int n,m;
ll ans[maxn];

int main(){
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v%m;
        a[i].md = tmp;
        ct[tmp]++;
    }
    ll cnt = 0;
    int st = n / m;
    for(int i=0; i<m; i++) {
            ct[i+1] += ct[i] - st;
            cnt += ct[i] - st >= 0?ct[i] - st: st - ct[i];
            f[i] = ct[i] - st;
    }
    printf("%I64d\n",cnt);
    sort(a+1,a+1+n,[](node x,node y){return x.md<y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st==0)tp--;
        int x = (tp-a[i].md);
        if(x<0)x+=m;
        printf("%I64d ",a[i].v+x);
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md,id;
} a[maxn];
int ct[maxn*2];
int n,m;
ll ans[maxn];

int main(){
    scanf("%d%d", &n, &m);
    int mx = -1,id;
    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v%m;
        a[i].md = tmp;
        ct[tmp]++;
        a[i].id = i;
        if(ct[tmp]>mx){
            mx = ct[tmp];
            id = tmp;
        }
    }
    // for(int i=n+1;i<=2*n;i++)
    //     ct[i] = ct[i-n];

    ll cnt = 0;
    int st = n / m;
    // for(int i=0; i<m; i++,id++) {
    //         ct[id+1] += ct[id] - st;
    //         cnt += ct[id] - st >= 0?ct[id] - st: st - ct[id];
    // }
    // printf("%lld\n",cnt);
    sort(a+1,a+1+n,[](node x,node y){return x.md<y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st==0)tp--;
        int x = (tp-a[i].md);
        if(x<0)x+=m;
        ans[a[i].id]=a[i].v+x;
        cnt+=x;
    }
    printf("%I64d\n",cnt);
    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
int n,m;
vector<int >mp[maxn];
vector<pair<int, int> >v;
ll a[maxn];
int main(){
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d", a + i);
        int tmp = a[i] % m;
        mp[tmp].pb(i);
    }
    ll ans = 0;
    int k = n/m;
    for(int i=0; i<2*m; i++)
    {
        int cur = i % m;
        while(int(mp[cur].size())>k)
        {
            int tmp = mp[cur].back();
            mp[cur].pop_back();
            v.pb(make_pair(tmp,i));
        }

        while(int(mp[cur].size())<k&&!v.empty())
        {
            int id = v.back().fi;
            int dis = v.back().se;
            v.pop_back();
            mp[cur].pb(id);
            a[id] += i - dis;
            ans += i- dis;
        }
    }
    printf("%I64d\n",ans);
    for(int i=1; i<=n; i++)
    {
        printf("%I64d ", a[i]);
    }
    puts("");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md;
   int id;
} a[maxn];
ll e[maxn];
int n,m,id;
ll ans[maxn];
pq <pair<ll,int> >q;
int main(){
    scanf("%d%d", &n, &m);

    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v % m;
        a[i].md = tmp;
        e[tmp]++;
        a[i].id = i;
    }

    for(int i=0; i<m; i++) {
        q.push(make_pair(1ll*e[i],i));
    }

    ll cnt = 0;
    int st = n / m;
    while(!q.empty())
    {
        ll c = 1ll*q.top().fi;
        //debug(c);
        int d = q.top().se;
        q.pop();
        if(e[d] != c)continue;
        if(c > st)
        {
            cnt += c - st;
            e[d] = st;
            if(d+1==m) {
                e[0] += c - st;
                q.push(make_pair(1ll*e[0],0));
            } else {
                e[d+1] += c - st;
                q.push(make_pair(1ll*e[d+1],d+1));
            }
        }else break;

    }

    printf("%I64d\n",cnt);

    sort(a+1,a+1+n,[](node x,node y){return x.md < y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st == 0)tp--;
        int x = (tp - a[i].md);
        if(x<0)x += m;
        ans[a[i].id] = a[i].v + x;
        cnt += x;
    }

    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md;
   int id;
} a[maxn];
ll e[maxn];
int n,m,id;
ll ans[maxn];
pq <pair<ll,int> >q;
int main(){
    scanf("%d%d", &n, &m);

    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v % m;
        a[i].md = tmp;
        e[tmp]++;
        a[i].id = i;
    }

    for(int i=0; i<m; i++) {
        q.push(make_pair(e[i],i));
    }

    ll cnt = 0;
    int st = n / m;
    while(!q.empty())
    {
        ll c = q.top().fi;
        //debug(c);
        int d = q.top().se;
        q.pop();

        if(c > st)
        {
            cnt += c - st;
            e[d] = st;
            if(d+1==m) {
                e[0] += c - st;
                q.push(make_pair(e[0],0));
            } else {
                e[d+1] += c - st;
                q.push(make_pair(e[d+1],d+1));
            }
        }

    }

    printf("%I64d\n",cnt);

    sort(a+1,a+1+n,[](node x,node y){return x.md < y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st == 0)tp--;
        int x = (tp - a[i].md);
        if(x<0)x += m;
        ans[a[i].id] = a[i].v + x;
        cnt += x;
    }

    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;
#define lld I64d
/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md;
   int id;
} a[maxn];
ll e[maxn];
int n,m,id;
ll ans[maxn];
pq <pair<ll,int> >q;
int main(){
    scanf("%d%d", &n, &m);

    for(int i=1; i<=n; i++) {
        scanf("%lld", &a[i].v);
        int tmp = a[i].v % m;
        a[i].md = tmp;
        e[tmp]++;
        a[i].id = i;
    }

    for(int i=0; i<m; i++) {
        q.push(make_pair(1ll*e[i],i));
    }

    ll cnt = 0;
    int st = n / m;
    while(!q.empty())
    {
        ll c = 1ll*q.top().fi;
        //debug(c);
        int d = q.top().se;
        q.pop();

        if(c > st)
        {
            cnt += c - st;
            e[d] = st;
            if(d+1==m) {
                e[0] += c - st;
                q.push(make_pair(1ll*e[0],0));
            } else {
                e[d+1] += c - st;
                q.push(make_pair(1ll*e[d+1],d+1));
            }
        }else break;

    }

    printf("%lld\n",cnt);

    sort(a+1,a+1+n,[](node x,node y){return x.md < y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st == 0)tp--;
        int x = (tp - a[i].md);
        if(x<0)x += m;
        ans[a[i].id] = a[i].v + x;
        cnt += x;
    }

    for(int i=1; i<=n; i++)
    {
        printf("%lld ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md;
   int id;
}a[maxn];
ll e[maxn];
int n,m,id;
ll ans[maxn];
pq <pair<ll,int> >q;
int main(){
    scanf("%d%d", &n, &m);

    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v % m;
        a[i].md = tmp;
        e[tmp]++;
        a[i].id = i;
    }

    for(int i=0; i<m; i++) {
        q.push(make_pair(1ll*e[i],i));
    }

    ll cnt = 0;
    int st = n / m;
    while(!q.empty())
    {
        ll c = 1ll*q.top().fi;
        //debug(c);
        int d = q.top().se;
        q.pop();
        if(e[d] != c)continue;
        if(c > st)
        {
            cnt += c - st;
            e[d] = st;
            if(d+1==m) {
                e[0] += c - st;
                q.push(make_pair(1ll*e[0],0));
            } else {
                e[d+1] += c - st;
                q.push(make_pair(1ll*e[d+1],d+1));
            }
        }else break;

    }

    printf("%I64d\n",cnt);

    sort(a+1,a+1+n,[](node x,node y){return x.md < y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st == 0)tp--;
        int x = (tp - a[i].md);
        if(x<0)x += m;
        x %= m;

        ans[a[i].id] = a[i].v + x;
    }

    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md,id;
} a[maxn];
int ct[maxn*2],e[maxn*2];
int n,m,id;
ll ans[maxn];
pq <pair<ll,int> >q;
int main(){
    scanf("%d%d", &n, &m);
    ll mx=-1,id;
    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v%m;
        a[i].md = tmp;
        e[tmp]++;
        a[i].id = i;
        if(e[tmp]>mx)
        {
            mx = e[tmp];
            id = tmp;
        }
    }
    q.push(make_pair(mx,id));
    for(int i=m; i<=2*m-1; i++)
        e[i] = e[i-m];

    ll cnt = 0;
    int st = n / m;
    while(!q.empty())
    {
        ll c = q.top().fi;
        int d = q.top().se;
        q.pop();
        if(c>st)
        {
            cnt+=c-st;
            if(d+1==m) {
                e[0] += c-st;
                q.push(make_pair(e[0],0));
            }else {
                e[d+1] += c-st;
                q.push(make_pair(e[d+1],d+1));
            }
        }
    }

    printf("%I64d\n",cnt);
    // printf("%lld\n",cnt);
    sort(a+1,a+1+n,[](node x,node y){return x.md < y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st == 0)tp--;
        int x = (tp - a[i].md);
        if(x<0)x += m;
        ans[a[i].id] = a[i].v + x;
        cnt += x;
    }

    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
ll a[maxn];
int ct[maxn];
int f[maxn];
int n,m;
int gt(int a,int b)
{
    return (a/b+1)*b-a;
}
int main(){
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++) {
        scanf("%I64d", a+i);
        int tmp = a[i]%m;
        ct[tmp]++;
    }
    int cnt = 0;
    int st = n/m;
    for(int i=0; i<m; i++) {
            ct[i+1] += ct[i] - st;
            cnt+= ct[i] - st>=0?ct[i] - st:(st - ct[i])*(m-1);
            f[i] = ct[i] - st;

    }
    printf("%d\n",cnt);
    for(int i=1; i<=n; i++)
    {
        int tmp = a[i] % m;
            if(f[tmp]>0)
            {
                printf("%I64d ",a[i]+1);
                f[tmp]--;
            }
            else if(f[tmp]<0)
            {
                printf("%I64d ",a[i]-1+m);
                f[tmp]++;
            }
            else  printf("%I64d ",a[i]);

    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md;
   int id;
}a[maxn];
ll e[maxn];
ll ndd[maxn];
int n,m,id;
ll ans[maxn];
pq <pair<ll,int> >q, qa;
int main(){
    scanf("%d%d", &n, &m);

    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v % m;
        a[i].md = tmp;
        e[tmp]++;
        a[i].id = i;
    }

    for(int i=0; i<m; i++) {
        q.push(make_pair(1ll*e[i],i));
    }

    ll cnt = 0;
    int st = n / m;
    while(!q.empty())
    {
        ll c = 1ll*q.top().fi;
        int d = q.top().se;
        q.pop();
        if(e[d] != c)continue;
        if(c > st)
        {
            cnt += c - st;
            e[d] = st;

            if(d+1==m) {
                e[0] += c - st;
                q.push(make_pair(1ll*e[0],0));
                ndd[d] += c - st;
            } else {
                e[d+1] += c - st;
                q.push(make_pair(1ll*e[d+1],d+1));
                ndd[d] += c - st;
            }
        }else break;
    }

    printf("%I64d\n",cnt);
    ll cnt1 = 0;
    sort(a+1,a+1+n,[](node x,node y){if(x.md==y.md)return x.v<y.v;return x.md < y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st != 0)tp++;
        if(tp == m) tp = 0;
        int x = (tp - a[i].md);
        if(x<0)x += m;
        x %= m;
        ans[a[i].id]=a[i].v + x;
    }
    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]-1);
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   ll md,id;
} a[maxn];
ll ct[maxn*2],e[maxn*2];
int n,m,id;
ll ans[maxn];
pq <pair<ll,int> >q;
int main(){
    scanf("%d%d", &n, &m);
    ll mx = -1,id;
    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v % m;
        a[i].md = tmp;
        e[tmp]++;
        a[i].id = i;
    }

    for(int i=0; i<m; i++) {
        q.push(make_pair(e[i],i));
    }

    ll cnt = 0;
    ll st = n / m;
    while(!q.empty())
    {
        ll c = q.top().fi;
        //debug(c);
        int d = q.top().se;
        q.pop();
        if(c > st)
        {
            cnt += c - st;
            if(d+1==m) {
                e[0] += c - st;
                q.push(make_pair(e[0],0));
            } else {
                e[d+1] += c - st;
                q.push(make_pair(e[d+1],d+1));
            }
        }
    }

    printf("%I64d\n",cnt);
    sort(a+1,a+1+n,[](node x,node y){return x.md < y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st == 0)tp--;
        int x = (tp - a[i].md);
        if(x<0)x += m;
        ans[a[i].id] = a[i].v + x;
        cnt += x;
    }

    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md;
   int id;
} a[maxn];
ll e[maxn];
int n,m,id;
ll ans[maxn];
pq <pair<ll,int> >q;
int main(){
    scanf("%d%d", &n, &m);

    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v % m;
        a[i].md = tmp;
        e[tmp]++;
        a[i].id = i;
    }

    for(int i=0; i<m; i++) {
        q.push(make_pair(e[i],i));
    }

    ll cnt = 0;
    int st = n / m;
    while(!q.empty())
    {
        int c = q.top().fi;
        //debug(c);
        int d = q.top().se;
        q.pop();
        if(c > st)
        {
            cnt += c - st;
            e[d] = st;
            if(d+1==m) {
                e[0] += c - st;
                q.push(make_pair(e[0],0));
            } else {
                e[d+1] += c - st;
                q.push(make_pair(e[d+1],d+1));
            }
        }
    }

    printf("%I64d\n",cnt);

    sort(a+1,a+1+n,[](node x,node y){return x.md < y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st == 0)tp--;
        int x = (tp - a[i].md);
        if(x<0)x += m;
        ans[a[i].id] = a[i].v + x;
        cnt += x;
    }

    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
ll a[maxn];
int ct[maxn];
int f[maxn];
int n,m;
int main(){
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++) {
        scanf("%I64d", a+i);
        int tmp = a[i]%m;
        ct[tmp]++;
    }
    int cnt = 0;
    int st = n/m;
    for(int i=0; i<m; i++) {
            ct[i+1] += ct[i] - st;
            cnt+= ct[i] - st>0?ct[i] - st:st-ct[i];
            if(ct[i]-st>0) f[i] = ct[i] - st;
            else f[i] = st - ct[i];
    }
    printf("%d\n",cnt);
    for(int i=1; i<=n; i++)
    {
        int tmp = a[i] % m;
            if(f[tmp]>0)
            {
                printf("%I64d ",a[i]+1);
                f[tmp]--;
            }
            else if(f[tmp]<0)
            {
                printf("%I64d ",a[i]-1);
                f[tmp]++;
            }
            else  printf("%I64d ",a[i]);

    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

#define Pll pair<ll,ll>
#define Pii pair<int,int>

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行

typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5+9;
struct node{
   ll v;
   int md,id;
} a[maxn];
int ct[maxn*2],e[maxn*2];
int n,m,id;
ll ans[maxn];

int main(){
    scanf("%d%d", &n, &m);

    for(int i=1; i<=n; i++) {
        scanf("%I64d", &a[i].v);
        int tmp = a[i].v%m;
        a[i].md = tmp;
        e[tmp]++;
        a[i].id = i;
    }
    for(int i=m; i<=2*m-1; i++)
        e[i] = e[i-m];

    ll cnt = 2e18;
    int st = n / m;
    for(int j=0; j<m; j++)
    {
        ll to = 0;
        id = j;
        memcpy(ct,e,sizeof(e));
        for(int i=0; i<m; i++,id++) {
                ct[id+1] += ct[id] - st;
                if(ct[id]-st >= 0)
                {
                     to += ct[id] - st;
                } else {
                    to  += (st - ct[id])*(m-1) ;
                }

        }
        cnt = min(cnt,to);
    }

    printf("%I64d\n",cnt);
    // printf("%lld\n",cnt);
    sort(a+1,a+1+n,[](node x,node y){return x.md < y.md;});
    for(int i=1; i<=n; i++)
    {
        int tp = i / st;
        if(i%st == 0)tp--;
        int x = (tp - a[i].md);
        if(x<0)x += m;
        ans[a[i].id] = a[i].v + x;
        cnt += x;
    }

    for(int i=1; i<=n; i++)
    {
        printf("%I64d ",ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int M=2e5+1;
vector<pair<LL,int> > V[M];
int n,m,A[M];
set<int> S;
set<int> ::iterator it;
LL sol,ans[M];
int main()
{
    S.insert(1);
    S.insert(2);
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        S.insert(A[i]%m);
        V[A[i]%m].push_back({A[i],i});
    }
    int bo=n/m;
    for(int i=0;i<m;i++){
        if((int)V[i].size()<bo){
            it=S.lower_bound(i);
            while(V[i].size()!=bo && it!=S.begin()){
                it--;
                while((int)V[*it].size()>bo && V[i].size()<bo){
                    sol+=(i-*it);
                    V[*it].back().first+=(i-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
            }
            it=S.lower_bound(M);
            while(V[i].size()!=bo){
                while((int)V[*it].size()>bo && V[i].size()<bo){
                    sol+=(i+m-*it);
                    V[*it].back().first+=(i+m-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
            }
        }
    }
    printf("%I64d\n",sol);
    for(int i=0;i<m;i++){
        for(int j=0;j<V[i].size();j++){
            ans[V[i][j].second]=V[i][j].first;
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d ",ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int M=2e5+1;
vector<pair<LL,int> > V[M];
int n,m,A[M];
set<int> S;
set<int> ::iterator it,tot;
LL sol,ans[M];
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        V[A[i]%m].push_back({A[i],i});
    }
    int bo=n/m;
    for(int i=0;i<m;i++){
        if((int)V[i].size()>bo)         //samo ovi sto se menjaju
            S.insert(i);
    }
    for(int i=0;i<m;i++){
        vector<int> need;
        if((int)V[i].size()<bo){
            it=S.lower_bound(i);
            while((int)V[i].size()!=bo && it!=S.begin()){
                it--;
                while((int)V[*it].size()>bo && (int)V[i].size()<bo){
                    sol+=(i-*it);
                    V[*it].back().first+=(i-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo)  need.push_back(*it);
            }
            it=S.lower_bound(M);
            while(V[i].size()!=bo){
                it--;
                while((int)V[*it].size()>bo && (int)V[i].size()<bo){
                    sol+=(i+m-*it);
                    V[*it].back().first+=(i+m-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo){
                    need.push_back(*it);
                }
            }
        }
        for(int j=0;j<need.size();j++)  S.erase(need[j]);
    }
    printf("%I64d\n",sol);
    for(int i=0;i<m;i++){
        for(int j=0;j<V[i].size();j++){
            ans[V[i][j].second]=V[i][j].first;
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d ",ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int M=2e5+1;
vector<pair<LL,int> > V[M];
int n,m,A[M];
set<int> S;
set<int> ::iterator it,tot;
LL sol,ans[M];
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        V[A[i]%m].push_back({A[i],i});
    }
    int bo=n/m;
    for(int i=0;i<m;i++){
        if((int)V[i].size()>bo)         //samo ovi sto se menjaju
            S.insert(i);
    }
    for(int i=0;i<m;i++){
        vector<int> need;
        if((int)V[i].size()<bo){
            it=S.lower_bound(i);
            while((int)V[i].size()!=bo && it!=S.begin()){
                it--;
                while((int)V[*it].size()>bo && (int)V[i].size()<bo){
                    sol+=(i-*it);
                    V[*it].back().first+=(i-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo)  need.push_back(*it);
            }
            it=S.lower_bound(M);
            while((int)V[i].size()!=bo){
                while((int)V[*it].size()>bo && (int)V[i].size()<bo){
                    sol+=(i+m-*it);
                    V[*it].back().first+=(i+m-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo){
                    need.push_back(*it);
                }
                it--;
            }
        }
        for(int i=0;i<need.size();i++)  S.erase(need[i]);
    }
    printf("%I64d\n",sol);
    for(int i=0;i<m;i++){
        for(int j=0;j<V[i].size();j++){
            ans[V[i][j].second]=V[i][j].first;
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d ",ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int M=2e5+1;
vector<pair<LL,int> > V[M];
int n,m,A[M];
set<int> S;
set<int> ::iterator it,tot;
LL sol,ans[M];
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        V[A[i]%m].push_back({A[i],i});
    }
    int bo=n/m;
    for(int i=0;i<m;i++){
        if((int)V[i].size()>bo)         //samo ovi sto se menjaju
            S.insert(i);
    }
    for(int i=0;i<m;i++){
        vector<int> need;
        if((int)V[i].size()<bo){
            it=S.lower_bound(i);
            while((int)V[i].size()!=bo && it!=S.begin()){
                it--;
                while((int)V[*it].size()>bo && (int)V[i].size()<bo){
                    sol+=(i-*it);
                    V[*it].back().first+=(i-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo)  need.push_back(*it);
            }
            it=S.lower_bound(M);
            while(V[i].size()!=bo){
                if(*it>m){
                    printf("Sranje %d",*it);
                    return 0;
                }
                while((int)V[*it].size()>bo && (int)V[i].size()<bo){
                    sol+=(i+m-*it);
                    V[*it].back().first+=(i+m-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo){
                    need.push_back(*it);
                }
                if(it!=S.begin())   it--;
            }
        }
        for(int i=0;i<need.size();i++)  S.erase(need[i]);
    }
    printf("%I64d\n",sol);
    for(int i=0;i<m;i++){
        for(int j=0;j<V[i].size();j++){
            ans[V[i][j].second]=V[i][j].first;
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d ",ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int M=2e5+1;
vector<pair<LL,int> > V[M];
int n,m,A[M];
set<int> S;
set<int> ::iterator it,tot;
LL sol,ans[M];
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        V[A[i]%m].push_back({A[i],i});
    }
    int bo=n/m;
    for(int i=0;i<m;i++){
        if((int)V[i].size()>bo)         //samo ovi sto se menjaju
            S.insert(i);
    }
    for(int i=0;i<m;i++){
        vector<int> need;
        if((int)V[i].size()<bo){
            it=S.lower_bound(i);
            while((int)V[i].size()!=bo && it!=S.begin()){
                it--;
                while((int)V[*it].size()>bo && (int)V[i].size()<bo){
                    sol+=(i-*it);
                    V[*it].back().first+=(i-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo)  need.push_back(*it);
            }
            it=S.lower_bound(M);
            while(V[i].size()!=bo){
                while((int)V[*it].size()>bo && (int)V[i].size()<bo){
                    sol+=(i+m-*it);
                    V[*it].back().first+=(i+m-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo){
                    need.push_back(*it);
                }
                if(it!=S.begin())   it--;
            }
        }
        for(int i=0;i<need.size();i++)  S.erase(need[i]);
    }
    printf("%I64d\n",sol);
    for(int i=0;i<m;i++){
        for(int j=0;j<V[i].size();j++){
            ans[V[i][j].second]=V[i][j].first;
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d ",ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int M=2e5+1;
vector<pair<LL,int> > V[M];
int n,m,A[M];
set<int> S;
set<int> ::iterator it,tot;
LL sol,ans[M];
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        V[A[i]%m].push_back({A[i],i});
    }
    int bo=n/m;
    for(int i=0;i<m;i++){
        if((int)V[i].size()>bo)         //samo ovi sto se menjaju
            S.insert(i);
    }
    for(int i=0;i<m;i++){
        vector<int> need;
        if((int)V[i].size()<bo){
            it=S.lower_bound(i);
            while(V[i].size()!=bo && it!=S.begin()){
                it--;
                while((int)V[*it].size()>bo && V[i].size()<bo){
                    sol+=(i-*it);
                    V[*it].back().first+=(i-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo)  need.push_back(*it);
            }
            it=S.lower_bound(M);
            while(V[i].size()!=bo){
                while((int)V[*it].size()>bo && V[i].size()<bo){
                    sol+=(i+m-*it);
                    V[*it].back().first+=(i+m-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                it--;
                if((int)V[*it].size()==bo)  need.push_back(*it);
            }
        }
        for(int i=0;i<need.size();i++)  S.erase(need[i]);
    }
    printf("%I64d\n",sol);
    for(int i=0;i<m;i++){
        for(int j=0;j<V[i].size();j++){
            ans[V[i][j].second]=V[i][j].first;
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d ",ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int M=2e5+1;
vector<pair<LL,int> > V[M];
int n,m,A[M];
set<int> S;
set<int> ::iterator it,tot;
LL sol,ans[M];
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        V[A[i]%m].push_back({A[i],i});
    }
    int bo=n/m;
    for(int i=0;i<m;i++){
        if((int)V[i].size()>bo)         //samo ovi sto se menjaju
            S.insert(i);
    }
    for(int i=0;i<m;i++){
        vector<int> need;
        if((int)V[i].size()<bo){
            it=S.lower_bound(i);
            while((int)V[i].size()!=bo && it!=S.begin()){
                it--;
                while((int)V[*it].size()>bo && (int)V[i].size()<bo){
                    sol+=(i-*it);
                    V[*it].back().first+=(i-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo)  need.push_back(*it);
            }
            it=S.lower_bound(M);
            while(V[i].size()!=bo){
                if(*it>m || *it<0){
                    tot=it++;
                    printf("Sranje %d %d",*it,*tot);
                    return 0;
                }
                while((int)V[*it].size()>bo && (int)V[i].size()<bo){
                    sol+=(i+m-*it);
                    V[*it].back().first+=(i+m-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo){
                    need.push_back(*it);
                }
                it--;
            }
        }
        for(int i=0;i<need.size();i++)  S.erase(need[i]);
    }
    printf("%I64d\n",sol);
    for(int i=0;i<m;i++){
        for(int j=0;j<V[i].size();j++){
            ans[V[i][j].second]=V[i][j].first;
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d ",ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int M=2e5+1;
vector<pair<LL,int> > V[M];
int n,m,A[M];
set<int> S;
set<int> ::iterator it,tot;
LL sol,ans[M];
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        V[A[i]%m].push_back({A[i],i});
    }
    int bo=n/m;
    for(int i=0;i<m;i++){
        if((int)V[i].size()>bo)         //samo ovi sto se menjaju
            S.insert(i);
    }
    for(int i=0;i<m;i++){
        vector<int> need;
        if((int)V[i].size()<bo){
            it=S.lower_bound(i);
            while((int)V[i].size()!=bo && it!=S.begin()){
                it--;
                while((int)V[*it].size()>bo && (int)V[i].size()<bo){
                    sol+=(i-*it);
                    V[*it].back().first+=(i-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo)  need.push_back(*it);
            }
            it=S.lower_bound(M);
            while(V[i].size()!=bo){
         /*       if(*it>m || *it<0){
                    tot=it++;
                    printf("Sranje %d %d",*it,*tot);
                    return 0;
                }*/
                while((int)V[*it].size()>bo && (int)V[i].size()<bo){
                    sol+=(i+m-*it);
                    V[*it].back().first+=(i+m-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo){
                    need.push_back(*it);
                }
                it--;
            }
        }
        for(int j=0;j<need.size();j++)  S.erase(need[j]);
    }
    printf("%I64d\n",sol);
    for(int i=0;i<m;i++){
        for(int j=0;j<V[i].size();j++){
            ans[V[i][j].second]=V[i][j].first;
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d ",ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int M=2e5+1;
vector<pair<LL,int> > V[M];
int n,m,A[M];
set<int> S;
set<int> ::iterator it,tot;
LL sol,ans[M];
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        V[A[i]%m].push_back({A[i],i});
    }
    int bo=n/m;
    for(int i=0;i<m;i++){
        if((int)V[i].size()>bo)         //samo ovi sto se menjaju
            S.insert(i);
    }
    for(int i=0;i<m;i++){
        vector<int> need;
        if((int)V[i].size()<bo){
            it=S.lower_bound(i);
            while(V[i].size()!=bo && it!=S.begin()){
                it--;
                while((int)V[*it].size()>bo && V[i].size()<bo){
                    sol+=(i-*it);
                    V[*it].back().first+=(i-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo)  need.push_back(*it);
            }
            it=S.lower_bound(M);
            while(V[i].size()!=bo){
                while((int)V[*it].size()>bo && V[i].size()<bo){
                    sol+=(i+m-*it);
                    V[*it].back().first+=(i+m-*it);
                    V[i].push_back(V[*it].back());
                    V[*it].pop_back();              //ne postoji taj vise
                }
                if((int)V[*it].size()==bo){
                    need.push_back(*it);
                    if((int)V[i].size()!=bo)    it--;
                }
            }
        }
        for(int i=0;i<need.size();i++)  S.erase(need[i]);
    }
    printf("%I64d\n",sol);
    for(int i=0;i<m;i++){
        for(int j=0;j<V[i].size();j++){
            ans[V[i][j].second]=V[i][j].first;
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d ",ans[i]);
    }
    return 0;
}