#include <iostream>
using namespace std;
int main(){
while(1)
{
int x, S=0, nrCif=0;
cin >> x;
if (x==0) break;
int t=x;
while(t)
{
S += t%10;
nrCif++;
t /= 10;
}
if (float(S)/nrCif<5)
{
t = x;
int inv=0;
while (t)
{
inv = inv*10 + t%10;
t /= 10;
}
cout << inv << " ";
}
else cout << x << " ";
}
return 0;
}