# include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)

#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())

#define inf32 2147483647
#define inf64 9223372036854775807
#define mod 1000000007
#define pi 3.141592653589793238462643383279

ld rad(ld radian) {return (radian * pi/180.0);}//角度をラジアンに変換
ld angle(ld x){return (x * 180) / pi;}//ラジアンを角度に変換
int Euclid_algorithm(int x, int y) {for(;;){x %= y;swap(x,y);if(y==0) break; }return x;}//ユークリッドの互除法

signed main() {
    ll num,K,N1,N2;
    string N;
    cin >> N >> K;
    rep(i,K){
        sort(N.begin(),N.end(),greater<ll>());
        N1 = stol(N);
        sort(N.begin(),N.end());
        N2 = stol(N);
        N = to_string(N1 - N2);
    }
    
    cout << N << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める
using Graph = vector<vector<int>>;

int main()
{
    int a,b;
    cin >> a >> b;
    cout << (a+b)/2 << " " << (a-b)/2 << endl;
    return 0;
}