#include <iostream>
using namespace std;
int cifra(int x) {
int max=-1;
do {
if (x%10>max) max=x%10;
x/10;
} while (x==0);
return max;
}
int cmmdc(int m, int n) {
if (m==0) return n;
if (n==0) return m;
while(m!=0) {
int r=n%m;
n=m;
m=r;
}
return n;
}
int main() {
int n, v[51], x;
cin>>n;
cin>>v[1]:
for (int i=2; i<=n; i++) {
cin>>v[i]; x=cmmdc(v[1], v[i]); v[1]=v[i];
}
for (int i=1; i<=n; i++) cout<<cifra(v[i])<<' ';
cout<<endl<<x;
return 0;
}