#include #include int isnum(char c){ if(c >= '0' && c <= '9') return 1; else return 0; } long long int exchange(char* str, int r){ long long int res = 0, weight = 1; int i; for(i = strlen(str)-1; 0 <= i; i--){ res += isnum(str[i]) ? (str[i]-'0')*weight : (str[i]-'A'+10)*weight; weight*=r; } return res; } int main(void) { int n, i; long long int min = -1; scanf("%d", &n); for(i = 0; n > i; i++){ char str[13]; int c, max = -1; long long int buf; scanf("%s", str); for(c = 0; strlen(str) > c; c++){ if(max < str[c]) max = str[c]; } if(isnum(max)) max = max-'0'; else max = max-'A'+10; buf = exchange(str, max+1); if(min == -1 || buf < min) min = buf; } printf("%lld", min); return 0; }