#include <bits/stdc++.h>

#define se second
#define sz(x) (int)(x.size())
#define ll long long
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define ull unsigned ll

#define pi 3.14159265358979

using namespace std;

const int N = (int)(1e6) + 322;
const ll INF = 2e18 + 17;
const int inf = 2e9;
const int mod = 1000000007;
const double eps = 1e-9;

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }

int nbr_bits(int a){
	return log2(a)+1;
}

int fastpow(int a, int n, int mod) {
    if(n==0)
    	return 1;
    if(n%2==0){
    	int res = fastpow(a,n/2,mod);
    	res*=res;
    	res%=mod;
    	return res;
	}
	int res = (fastpow(a,n-1,mod)*a)%mod;
	return res;

}

// ----------------------------------------------------

signed main()
{

	int n;
	cin >>  n ;

	set<int> dis;
	int fr[n+1];
	rep(i,1,n) {
		cin >> fr[i] ;
		dis.insert(fr[i]);
	}

	sort(fr+1,fr+n+1);

	int mn = dis.size();
	vector<int> ch;
	ch.pb(fr[1]);
	rep(i,2,n){
		if(fr[i]!=fr[i-1]) ch.pb(fr[i]);
	}
	rep(i,0,ch.size()-1) {
		if(ch[i]==ch[i+1]-1  && ch[i]==ch[i+2]-2 ){
			mn-=2;
			i+=2;
		}
		else if(ch[i]==ch[i+1]-1){
			mn--;
			i++;
		}
		else if(ch[i]==ch[i+1]-2){
			mn--;
			i++;
		}

	}

	cout << mn << " " ;

	int mx=dis.size(); set<int> all;
	fr[1]--;
	all.insert(fr[1]);
	rep(i,2,n){
		if(  all.count(fr[i]-1)==0 ){
			all.insert(fr[i]-1);
		}
		else if(  all.count(fr[i])==0 ){
			all.insert(fr[i]);
		}
		else all.insert(fr[i]+1);
	}

	cout << all.size() << endl;

	return 0;
}


#include <bits/stdc++.h>

#define se second
#define sz(x) (int)(x.size())
#define ll long long
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define ull unsigned ll

#define pi 3.14159265358979

using namespace std;

const int N = (int)(1e6) + 322;
const ll INF = 2e18 + 17;
const int inf = 2e9;
const int mod = 1000000007;
const double eps = 1e-9;

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }

int nbr_bits(int a){
	return log2(a)+1;
}

int fastpow(int a, int n, int mod) {
    if(n==0)
    	return 1;
    if(n%2==0){
    	int res = fastpow(a,n/2,mod);
    	res*=res;
    	res%=mod;
    	return res;
	}
	int res = (fastpow(a,n-1,mod)*a)%mod;
	return res;

}

// ----------------------------------------------------

signed main()
{

	int n;
	cin >>  n ;

	set<int> dis;
	int fr[n+1];
	rep(i,1,n) {
		cin >> fr[i] ;
		dis.insert(fr[i]);
	}

	sort(fr+1,fr+n+1);

	int mn = dis.size(),cp=0;
	vector<int> ch;
	ch.pb(fr[1]);
	rep(i,2,n){
		if(fr[i]!=fr[i-1]) ch.pb(fr[i]);
	}
	rep(i,0,ch.size()-1) {
		if(ch[i]==ch[i+1]-1  && ch[i]==ch[i+2]-2 ){
			mn-=2;
			i+=2;
		}
		else if(ch[i]==ch[i+1]-1){
			mn--;
			i++;
		}
		else{
			if(i==ch.size()-1) mn--;
		}
	}

	cout << mn << " " ;

	int mx=dis.size(); set<int> all;
	fr[1]--;
	all.insert(fr[1]);
	rep(i,2,n){
		if(  all.count(fr[i]-1)==0 ){
			all.insert(fr[i]-1);
		}
		else if(  all.count(fr[i]+1)==0 ){
			all.insert(fr[i]+1);
		}
		else all.insert(fr[i]);
	}

	cout << all.size() << endl;

	return 0;
}


#include <bits/stdc++.h>

#define se second
#define sz(x) (int)(x.size())
#define ll long long
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define ull unsigned ll

#define pi 3.14159265358979

using namespace std;

const int N = (int)(1e6) + 322;
const ll INF = 2e18 + 17;
const int inf = 2e9;
const int mod = 1000000007;
const double eps = 1e-9;

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }

int nbr_bits(int a){
	return log2(a)+1;
}

int fastpow(int a, int n, int mod) {
    if(n==0)
    	return 1;
    if(n%2==0){
    	int res = fastpow(a,n/2,mod);
    	res*=res;
    	res%=mod;
    	return res;
	}
	int res = (fastpow(a,n-1,mod)*a)%mod;
	return res;

}

// ----------------------------------------------------

signed main()
{

	int n;
	cin >>  n ;

	set<int> dis;
	int fr[n+1];
	rep(i,1,n) {
		cin >> fr[i] ;
		dis.insert(fr[i]);
	}

	sort(fr+1,fr+n+1);

	int mn = dis.size(),cp=0;
	vector<int> ch;
	ch.pb(fr[1]);
	rep(i,2,n){
		if(fr[i]!=fr[i-1]) ch.pb(fr[i]);
	}
	rep(i,0,ch.size()-1) {
		if(ch[i]==ch[i+1]-1  && ch[i]==ch[i+2]-2 ){
			mn-=2;
			i+=2;
		}
		else if(ch[i]==ch[i+1]-1){
			mn--;
			i++;
		}

	}

	cout << mn << " " ;

	int mx=dis.size(); set<int> all;
	fr[1]--;
	all.insert(fr[1]);
	rep(i,2,n){
		if(  all.count(fr[i]-1)==0 ){
			all.insert(fr[i]-1);
		}
		else if(  all.count(fr[i]+1)==0 ){
			all.insert(fr[i]+1);
		}
		else all.insert(fr[i]);
	}

	cout << all.size() << endl;

	return 0;
}


#include <bits/stdc++.h>

#define se second
#define sz(x) (int)(x.size())
#define ll long long
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define ull unsigned ll

#define pi 3.14159265358979

using namespace std;

const int N = (int)(1e6) + 322;
const ll INF = 2e18 + 17;
const int inf = 2e9;
const int mod = 1000000007;
const double eps = 1e-9;

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }

int nbr_bits(int a){
	return log2(a)+1;
}

int fastpow(int a, int n, int mod) {
    if(n==0)
    	return 1;
    if(n%2==0){
    	int res = fastpow(a,n/2,mod);
    	res*=res;
    	res%=mod;
    	return res;
	}
	int res = (fastpow(a,n-1,mod)*a)%mod;
	return res;

}

// ----------------------------------------------------

signed main()
{

	int n;
	cin >>  n ;

	set<int> dis;
	int fr[n+1];
	rep(i,1,n) {
		cin >> fr[i] ;
		dis.insert(fr[i]);
	}

	sort(fr+1,fr+n+1);

	int mn = dis.size();
	vector<int> ch;
	ch.pb(fr[1]);
	rep(i,2,n){
		if(fr[i]!=fr[i-1]) ch.pb(fr[i]);
	}
	rep(i,0,ch.size()-1) {
		if(ch[i]==ch[i+1]-1  && ch[i]==ch[i+2]-2 ){
			mn-=2;
			i+=2;
		}
		else if(ch[i]==ch[i+1]-1){
			mn--;
			i++;
		}
		else if(ch[i]==ch[i+1]-2){
			mn--;
			i++;
		}

	}

	cout << mn << " " ;

	int mx=dis.size(); set<int> all;
	fr[1]--;
	all.insert(fr[1]);
	rep(i,2,n){
		if(  all.count(fr[i]-1)==0 ){
			all.insert(fr[i]-1);
		}
		else if(  all.count(fr[i]+1)==0 ){
			all.insert(fr[i]+1);
		}
		else all.insert(fr[i]);
	}

	cout << all.size() << endl;

	return 0;
}


#include <bits/stdc++.h>

#define se second
#define sz(x) (int)(x.size())
#define ll long long
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define ull unsigned ll

#define pi 3.14159265358979

using namespace std;

const int N = (int)(1e6) + 322;
const ll INF = 2e18 + 17;
const int inf = 2e9;
const int mod = 1000000007;
const double eps = 1e-9;

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }

int nbr_bits(int a){
	return log2(a)+1;
}

int fastpow(int a, int n, int mod) {
    if(n==0)
    	return 1;
    if(n%2==0){
    	int res = fastpow(a,n/2,mod);
    	res*=res;
    	res%=mod;
    	return res;
	}
	int res = (fastpow(a,n-1,mod)*a)%mod;
	return res;

}

// ----------------------------------------------------

signed main()
{

	int n;
	cin >>  n ;

	set<int> dis;
	int fr[n+1];
	rep(i,1,n) {
		cin >> fr[i] ;
		dis.insert(fr[i]);
	}

	sort(fr+1,fr+n+1);

	int mn = dis.size();
	rep(i,1,n-1){
		if(fr[i]==fr[i+1]-1) mn--;
	}

	cout << mn << " " ;

	int mx=dis.size(); set<int> all;
	fr[1]--; fr[n]++;
	rep(i,1,n){
		if( all.count(fr[i])==1 && all.count(fr[i]-1)==0 ){
			all.insert(fr[i]-1);
		}
		else if( all.count(fr[i])==1 && all.count(fr[i]+1)==0 ){
			all.insert(fr[i]+1);
		}
		else all.insert(fr[i]);
	}

	cout << all.size() << endl;

	return 0;
}


#include <bits/stdc++.h>

#define se second
#define sz(x) (int)(x.size())
#define ll long long
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define ull unsigned ll

#define pi 3.14159265358979

using namespace std;

const int N = (int)(1e6) + 322;
const ll INF = 2e18 + 17;
const int inf = 2e9;
const int mod = 1000000007;
const double eps = 1e-9;

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }

int nbr_bits(int a){
	return log2(a)+1;
}

int fastpow(int a, int n, int mod) {
    if(n==0)
    	return 1;
    if(n%2==0){
    	int res = fastpow(a,n/2,mod);
    	res*=res;
    	res%=mod;
    	return res;
	}
	int res = (fastpow(a,n-1,mod)*a)%mod;
	return res;

}

// ----------------------------------------------------

signed main()
{

	int n;
	cin >>  n ;

	set<int> dis;
	int fr[n+1];
	rep(i,1,n) {
		cin >> fr[i] ;
		dis.insert(fr[i]);
	}

	sort(fr+1,fr+n+1);

	int mn = dis.size(),cp=0;
	vector<int> ch;
	ch.pb(fr[1]);
	rep(i,2,n){
		if(fr[i]!=fr[i-1]) ch.pb(fr[i]);
	}
	rep(i,0,ch.size()-1) {
		if(ch[i]==ch[i+1]-1  && ch[i]==ch[i+2]-2){
			mn-=2;
			i+=2;
		}
		else if(ch[i]==ch[i+1]-1){
			mn--;
			i++;
		}
	}

	cout << mn << " " ;

	int mx=dis.size(); set<int> all;
	fr[1]--; fr[n]++;
	all.insert(fr[1]); all.insert(fr[n]);
	rep(i,2,n-1){
		if( all.count(fr[i])==1 && all.count(fr[i]-1)==0 ){
			all.insert(fr[i]-1);
		}
		else if( all.count(fr[i])==1 && all.count(fr[i]+1)==0 ){
			all.insert(fr[i]+1);
		}
		else all.insert(fr[i]);
	}

	cout << all.size() << endl;

	return 0;
}


#include <bits/stdc++.h>

#define se second
#define sz(x) (int)(x.size())
#define ll long long
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define ull unsigned ll

#define pi 3.14159265358979

using namespace std;

const int N = (int)(1e6) + 322;
const ll INF = 2e18 + 17;
const int inf = 2e9;
const int mod = 1000000007;
const double eps = 1e-9;

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }

int nbr_bits(int a){
	return log2(a)+1;
}

int fastpow(int a, int n, int mod) {
    if(n==0)
    	return 1;
    if(n%2==0){
    	int res = fastpow(a,n/2,mod);
    	res*=res;
    	res%=mod;
    	return res;
	}
	int res = (fastpow(a,n-1,mod)*a)%mod;
	return res;

}

// ----------------------------------------------------

signed main()
{

	int n;
	cin >>  n ;

	set<int> dis;
	int fr[n+1];
	rep(i,1,n) {
		cin >> fr[i] ;
		dis.insert(fr[i]);
	}

	sort(fr+1,fr+n+1);

	int mn = dis.size(),cp=0;
	vector<int> ch;
	ch.pb(fr[1]);
	rep(i,2,n){
		if(fr[i]!=fr[i-1]) ch.pb(fr[i]);
	}
	rep(i,0,ch.size()-1) {
		if(ch[i]==ch[i+1]-1  && ch[i]==ch[i+2]-2 && i < ch.size()-1){
			mn-=2;
			i+=2;
		}
		else if(ch[i]==ch[i+1]-1 && i < ch.size()-1){
			mn--;
			i++;
		}
		else if ( i == ch.size()-1 ) mn--;
	}

	cout << mn << " " ;

	int mx=dis.size(); set<int> all;
	fr[1]--;
	all.insert(fr[1]);
	rep(i,2,n){
		if(  all.count(fr[i]-1)==0 ){
			all.insert(fr[i]-1);
		}
		else if(  all.count(fr[i]+1)==0 ){
			all.insert(fr[i]+1);
		}
		else all.insert(fr[i]);
	}

	cout << all.size() << endl;

	return 0;
}


#include <bits/stdc++.h>

#define se second
#define sz(x) (int)(x.size())
#define ll long long
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define ull unsigned ll

#define pi 3.14159265358979

using namespace std;

const int N = (int)(1e6) + 322;
const ll INF = 2e18 + 17;
const int inf = 2e9;
const int mod = 1000000007;
const double eps = 1e-9;

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }

int nbr_bits(int a){
	return log2(a)+1;
}

int fastpow(int a, int n, int mod) {
    if(n==0)
    	return 1;
    if(n%2==0){
    	int res = fastpow(a,n/2,mod);
    	res*=res;
    	res%=mod;
    	return res;
	}
	int res = (fastpow(a,n-1,mod)*a)%mod;
	return res;

}

// ----------------------------------------------------

signed main()
{

	int n;
	cin >>  n ;

	set<int> dis;
	int fr[n+1];
	rep(i,1,n) {
		cin >> fr[i] ;
		dis.insert(fr[i]);
	}

	sort(fr+1,fr+n+1);

	int mn = dis.size(),cp=0;
	vector<int> ch;
	ch.pb(fr[1]);
	rep(i,2,n){
		if(fr[i]!=fr[i-1]) ch.pb(fr[i]);
	}
	rep(i,0,ch.size()-1) {
		if(fr[i]==fr[i+1]-1  && fr[i]==fr[i+2]-2){
			mn-=2;
			i+=2;
		}
		else if(fr[i]==fr[i+1]-1){
			mn--;
			i++;
		}
	}

	cout << mn << " " ;

	int mx=dis.size(); set<int> all;
	fr[1]--; fr[n]++;
	all.insert(fr[1]); all.insert(fr[n]);
	rep(i,2,n-1){
		if( all.count(fr[i])==1 && all.count(fr[i]-1)==0 ){
			all.insert(fr[i]-1);
		}
		else if( all.count(fr[i])==1 && all.count(fr[i]+1)==0 ){
			all.insert(fr[i]+1);
		}
		else all.insert(fr[i]);
	}

	cout << all.size() << endl;

	return 0;
}


#include <bits/stdc++.h>

#define se second
#define sz(x) (int)(x.size())
#define ll long long
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define ull unsigned ll

#define pi 3.14159265358979

using namespace std;

const int N = (int)(1e6) + 322;
const ll INF = 2e18 + 17;
const int inf = 2e9;
const int mod = 1000000007;
const double eps = 1e-9;

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }

int nbr_bits(int a){
	return log2(a)+1;
}

int fastpow(int a, int n, int mod) {
    if(n==0)
    	return 1;
    if(n%2==0){
    	int res = fastpow(a,n/2,mod);
    	res*=res;
    	res%=mod;
    	return res;
	}
	int res = (fastpow(a,n-1,mod)*a)%mod;
	return res;

}

// ----------------------------------------------------

signed main()
{

	int n;
	cin >>  n ;

	set<int> dis;
	int fr[n+1];
	rep(i,1,n) {
		cin >> fr[i] ;
		dis.insert(fr[i]);
	}

	sort(fr+1,fr+n+1);

	int mn = dis.size();
	vector<int> ch;
	ch.pb(fr[1]);
	rep(i,2,n){
		if(fr[i]!=fr[i-1]) ch.pb(fr[i]);
	}
	rep(i,0,ch.size()-1) {
		if(ch[i]==ch[i+1]-1  && ch[i]==ch[i+2]-2 ){
			mn-=2;
			i+=2;
		}
		else if(ch[i]==ch[i+1]-1){
			mn--;
			i++;
		}
		else mn--;
	}

	cout << mn << " " ;

	int mx=dis.size(); set<int> all;
	fr[1]--;
	all.insert(fr[1]);
	rep(i,2,n){
		if(  all.count(fr[i]-1)==0 ){
			all.insert(fr[i]-1);
		}
		else if(  all.count(fr[i]+1)==0 ){
			all.insert(fr[i]+1);
		}
		else all.insert(fr[i]);
	}

	cout << all.size() << endl;

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
	for (ll i = 0; i < v.size(); ++i) \
		cout << v[i] << " ";            \
	cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define get(n) \
	ll n;        \
	cin >> n
#define getvec(v, n)         \
	vector<ll> v(n);           \
	for (ll i = 0; i < n; i++) \
		cin >> v[i];
#define getstr(s) \
	string s;       \
	cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void minVal(vl &v)
{
	ll n = v.size();
	map<ll, ll> m;
	for (int i = 0; i < n; i++)
		m[v[i]]++;
	for (int i = 2; i <= n - 1; i += 3)
	{
		if (m[i] > 0 && m[i - 1] > 0 && m[i + 1] > 0)
		{
			m[i] = m[i - 1] + m[i + 1];
			m[i - 1] = 0;
			m[i + 1] = 0;
		}
	}
	for (int i = 1; i <= n; i++)
	{
		if (m[i] > 0 && m[i - 1] > 0)
			m[i - 1] = m[i - 1] + m[i], m[i] = 0;
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++)
		if (m[i] > 0)
			++ans;
	p0(ans);
}

void maxVal(vl &v)
{
	ll n = v.size();
	map<ll, ll> m;
	for (int i = 0; i < n; i++)
		m[v[i]]++;
	for (int i = 1; i <= n;)
	{
		if (m[i] == 0)
		{
			++i;
			continue;
		}
		ll j = i;
		ll sum = 0;
		while (m[j] != 0)
			sum += m[j++];
		ll diff = sum - (j - i);
		if (diff == 1)
		{
			if (m[i - 1] == 0)
				m[i - 1] = 1, i = j;
			else if (m[j] == 0)
				m[j] = 1, i = j + 1;
		}
		else if (diff > 1)
		{
			if (m[i - 1] == 0)
				m[i - 1] = 1, i = j;
			if (m[j] == 0)
				m[j] = 1, i = j + 1;
		}
		else
			i = j;
	}
	ll ans = 0;
	for (int i = 0; i <= n + 1; i++)
		if (m[i] > 0)
			++ans;
	p1(ans);
}

void mainSolve()
{
	get(n);
	getvec(v, n);
	minVal(v);
	maxVal(v);
}

int main()
{
	fio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//	get(t);
	ll t = 1;
	while (t--)
	{
		mainSolve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
	for (ll i = 0; i < v.size(); ++i) \
		cout << v[i] << " ";            \
	cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define get(n) \
	ll n;        \
	cin >> n
#define getvec(v, n)         \
	vector<ll> v(n);           \
	for (ll i = 0; i < n; i++) \
		cin >> v[i];
#define getstr(s) \
	string s;       \
	cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void mainSolve()
{
	get(n);
	getvec(v, n);
	map<ll, ll> m;
	set<ll> s;
	sort(all(v));
	for (int i = 0; i < n; i++)
	{
		++m[v[i]];
		s.insert(v[i]);
	}
	ll mx = 0, mn = n;
	for (auto it = s.begin(); it != s.end(); it++)
	{
		ll x = *it;
		if (m[x] > 2)
			m[x - 1]++, m[x + 1]++;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[v[i]] == 2)
		{
			if (m[x - 1] == 0)
				m[x - 1]++, m[x]--;
		}
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[v[i]] == 2)
		{
			if (m[x - 1] == 0)
				m[x - 1]++, m[x]--;
			else
				m[x + 1]++, m[x]--;
		}
	}
	ll maxVal = 0;
	for (int i = 0; i <= n; i++)
		if (m[i] > 0)
			maxVal++;
	// for (int i = 1; i <= n; i++)
	// 	p2(i, m[i]);
	m.clear();
	for (int i = 0; i < n; i++)
	{
		++m[v[i]];
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x - 1] >= 3 && m[x] <= 2)
			m[x] = 0;
		else if (m[x + 1] >= 3 && m[x] <= 2)
			m[x] = 0;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x] == 1 && m[x - 1] == 2)
			m[x]--;
		else if (m[x] == 1 && m[x + 1] == 2)
			m[x]--;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x] == 1 && m[x + 1] == 1)
			m[x]--;
		else if (m[x] == 1 && m[x + 1] == 1)
			m[x]--;
	}
	ll minVal = 0;
	for (int i = 0; i <= n; i++)
		if (m[i] > 0)
			minVal++;
	p2(minVal, maxVal);
}

int main()
{
	fio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//get(t);
	ll t = 1;
	while (t--)
	{
		mainSolve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
	for (ll i = 0; i < v.size(); ++i) \
		cout << v[i] << " ";            \
	cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define get(n) \
	ll n;        \
	cin >> n
#define getvec(v, n)         \
	vector<ll> v(n);           \
	for (ll i = 0; i < n; i++) \
		cin >> v[i];
#define getstr(s) \
	string s;       \
	cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void mainSolve()
{
	get(n);
	getvec(v, n);
	map<ll, ll> m;
	set<ll> s;
	sort(all(v));
	for (int i = 0; i < n; i++)
	{
		++m[v[i]];
		s.insert(v[i]);
	}
	ll mx = 0, mn = n;
	for (auto it = s.begin(); it != s.end(); it++)
	{
		ll x = *it;
		if (m[x] > 2)
			m[x - 1]++, m[x + 1]++;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[v[i]] == 2)
		{
			if (m[x - 1] == 0)
				m[x - 1]++;
		}
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[v[i]] == 2)
		{
			if (m[x - 1] == 0)
				m[x - 1]++;
			else
				m[x + 1]++;
		}
	}
	ll maxVal = 0;
	for (int i = 1; i <= n; i++)
		if (m[i] > 0)
			maxVal++;
	m.clear();
	for (int i = 0; i < n; i++)
	{
		++m[v[i]];
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x - 1] >= 3 && m[x] <= 2)
			m[x] = 0;
		else if (m[x + 1] >= 3 && m[x] <= 2)
			m[x] = 0;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x] == 1 && m[x - 1] == 2)
			m[x]--;
		else if (m[x] == 1 && m[x + 1] == 2)
			m[x]--;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x] == 1 && m[x + 1] == 1)
			m[x]--;
		else if (m[x] == 1 && m[x + 1] == 1)
			m[x]--;
	}
	ll minVal = 0;
	for (int i = 1; i <= n; i++)
		if (m[i] == 0)
			minVal++;
	minVal = n - minVal;
	p2(minVal, maxVal);
}

int main()
{
	fio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//get(t);
	ll t = 1;
	while (t--)
	{
		mainSolve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
	for (ll i = 0; i < v.size(); ++i) \
		cout << v[i] << " ";            \
	cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define get(n) \
	ll n;        \
	cin >> n
#define getvec(v, n)         \
	vector<ll> v(n);           \
	for (ll i = 0; i < n; i++) \
		cin >> v[i];
#define getstr(s) \
	string s;       \
	cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void minVal(vl &v)
{
	ll n = v.size();
	map<ll, ll> m;
	for (int i = 0; i < n; i++)
		m[v[i]]++;
	for (int i = 1; i <= n - 1;)
	{
		if (m[i - 1] > 0 && m[i + 1] > 0)
		{
			m[i] = m[i - 1] + m[i + 1];
			m[i - 1] = 0;
			m[i + 1] = 0;
			i += 3;
			continue;
		}
		i++;
	}
	for (int i = 1; i <= n; i++)
	{
		if (m[i] > 0 && m[i - 1] > 0)
			m[i - 1] = m[i - 1] + m[i], m[i] = 0;
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++)
		if (m[i] > 0)
			++ans;
	p0(ans);
}

void maxVal(vl &v)
{
	ll n = v.size();
	map<ll, ll> m;
	for (int i = 0; i < n; i++)
		m[v[i]]++;
	for (int i = 1; i <= n;)
	{
		if (m[i] == 0)
		{
			++i;
			continue;
		}
		ll j = i;
		ll sum = 0;
		while (m[j] != 0)
			sum += m[j++];
		ll diff = sum - (j - i);
		if (diff == 1)
		{
			if (m[i - 1] == 0)
				m[i - 1] = 1, i = j;
			else if (m[j] == 0)
				m[j] = 1, i = j + 1;
		}
		else if (diff > 1)
		{
			if (m[i - 1] == 0)
				m[i - 1] = 1, i = j;
			if (m[j] == 0)
				m[j] = 1, i = j + 1;
		}
		else
			i = j;
	}
	ll ans = 0;
	for (int i = 0; i <= n + 1; i++)
		if (m[i] > 0)
			++ans;
	p1(ans);
}

void mainSolve()
{
	get(n);
	getvec(v, n);
	minVal(v);
	maxVal(v);
}

int main()
{
	fio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//	get(t);
	ll t = 1;
	while (t--)
	{
		mainSolve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
	for (ll i = 0; i < v.size(); ++i) \
		cout << v[i] << " ";            \
	cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define get(n) \
	ll n;        \
	cin >> n
#define getvec(v, n)         \
	vector<ll> v(n);           \
	for (ll i = 0; i < n; i++) \
		cin >> v[i];
#define getstr(s) \
	string s;       \
	cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void minVal(vl &v)
{
	ll n = v.size();
	ll ans = 0;
	map<ll, ll> m;
	for (int i = 0; i < n; i++)
		m[v[i]]++;
	for (int i = 1; i <= n;)
	{
		if (m[i] == 0)
		{
			++i;
			continue;
		}
		++ans;
		i += 3;
	}
	p0(ans);
}

void maxVal(vl &v)
{
	ll n = v.size();
	map<ll, ll> m;
	for (int i = 0; i < n; i++)
		m[v[i]]++;
	for (int i = 1; i <= n;)
	{
		if (m[i] == 0)
		{
			++i;
			continue;
		}
		ll j = i;
		ll sum = 0;
		while (m[j] != 0)
			sum += m[j++];
		ll diff = sum - (j - i);
		if (diff == 1)
		{
			if (m[i - 1] == 0)
				m[i - 1] = 1, i = j;
			else if (m[j] == 0)
				m[j] = 1, i = j + 1;
		}
		else if (diff > 1)
		{
			if (m[i - 1] == 0)
				m[i - 1] = 1, i = j;
			if (m[j] == 0)
				m[j] = 1, i = j + 1;
		}
		else
			i = j;
	}
	ll ans = 0;
	for (int i = 0; i <= n + 1; i++)
		if (m[i] > 0)
			++ans;
	p1(ans);
}

void mainSolve()
{
	get(n);
	getvec(v, n);
	minVal(v);
	maxVal(v);
}

int main()
{
	fio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//	get(t);
	ll t = 1;
	while (t--)
	{
		mainSolve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
	for (ll i = 0; i < v.size(); ++i) \
		cout << v[i] << " ";            \
	cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define get(n) \
	ll n;        \
	cin >> n
#define getvec(v, n)         \
	vector<ll> v(n);           \
	for (ll i = 0; i < n; i++) \
		cin >> v[i];
#define getstr(s) \
	string s;       \
	cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void mainSolve()
{
	get(n);
	getvec(v, n);
	map<ll, ll> m;
	set<ll> s;
	for (int i = 0; i < n; i++)
	{
		++m[v[i]];
		s.insert(v[i]);
	}
	ll mx = 0, mn = n;
	for (auto it = s.begin(); it != s.end(); it++)
	{
		ll x = *it;
		if (m[x] > 2)
			m[x - 1]++, m[x + 1]++;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[v[i]] == 2)
		{
			if (m[x - 1] == 0)
				m[x - 1]++;
			else
				m[x + 1]++;
		}
	}
	ll maxVal = 0;
	for (int i = 1; i <= n; i++)
		if (m[i] > 0)
			maxVal++;
	m.clear();
	for (int i = 0; i < n; i++)
	{
		++m[v[i]];
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x - 1] >= 3 && m[x] <= 2)
			m[x] = 0;
		else if (m[x + 1] >= 3 && m[x] <= 2)
			m[x] = 0;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x] == 1 && m[x - 1] == 2)
			m[x]--;
		else if (m[x] == 1 && m[x + 1] == 2)
			m[x]--;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x] == 1 && m[x + 1] == 1)
			m[x]--;
		else if (m[x] == 1 && m[x + 1] == 1)
			m[x]--;
	}
	ll minVal = 0;
	for (int i = 1; i <= n; i++)
		if (m[i] == 0)
			minVal++;
	minVal = n - minVal;
	p2(minVal, maxVal);
}

int main()
{
	fio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//get(t);
	ll t = 1;
	while (t--)
	{
		mainSolve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
	for (ll i = 0; i < v.size(); ++i) \
		cout << v[i] << " ";            \
	cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define get(n) \
	ll n;        \
	cin >> n
#define getvec(v, n)         \
	vector<ll> v(n);           \
	for (ll i = 0; i < n; i++) \
		cin >> v[i];
#define getstr(s) \
	string s;       \
	cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void mainSolve()
{
	get(n);
	getvec(v, n);
	map<ll, ll> m;
	set<ll> s;
	sort(all(v));
	for (int i = 0; i < n; i++)
	{
		++m[v[i]];
		s.insert(v[i]);
	}
	ll mx = 0, mn = n;
	for (auto it = s.begin(); it != s.end(); it++)
	{
		ll x = *it;
		if (m[x] > 2)
			m[x - 1]++, m[x + 1]++;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[v[i]] == 2)
		{
			if (m[x - 1] == 0)
				m[x - 1]++, m[x]--;
		}
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[v[i]] == 2)
		{
			if (m[x - 1] == 0)
				m[x - 1]++, m[x]--;
			else
				m[x + 1]++, m[x]--;
		}
	}
	ll maxVal = 0;
	for (int i = 1; i <= n; i++)
		if (m[i] > 0)
			maxVal++;
	m.clear();
	for (int i = 0; i < n; i++)
	{
		++m[v[i]];
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x - 1] >= 3 && m[x] <= 2)
			m[x] = 0;
		else if (m[x + 1] >= 3 && m[x] <= 2)
			m[x] = 0;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x] == 1 && m[x - 1] == 2)
			m[x]--;
		else if (m[x] == 1 && m[x + 1] == 2)
			m[x]--;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x] == 1 && m[x + 1] == 1)
			m[x]--;
		else if (m[x] == 1 && m[x + 1] == 1)
			m[x]--;
	}
	ll minVal = 0;
	for (int i = 1; i <= n; i++)
		if (m[i] == 0)
			minVal++;
	minVal = n - minVal;
	p2(minVal, maxVal);
}

int main()
{
	fio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//get(t);
	ll t = 1;
	while (t--)
	{
		mainSolve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
	for (ll i = 0; i < v.size(); ++i) \
		cout << v[i] << " ";            \
	cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define get(n) \
	ll n;        \
	cin >> n
#define getvec(v, n)         \
	vector<ll> v(n);           \
	for (ll i = 0; i < n; i++) \
		cin >> v[i];
#define getstr(s) \
	string s;       \
	cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void mainSolve()
{
	get(n);
	getvec(v, n);
	map<ll, ll> m;
	set<ll> s;
	sort(all(v));
	for (int i = 0; i < n; i++)
	{
		++m[v[i]];
		s.insert(v[i]);
	}
	ll mx = 0, mn = n;
	for (auto it = s.begin(); it != s.end(); it++)
	{
		ll x = *it;
		if (m[x] > 2)
			m[x - 1]++, m[x + 1]++;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[v[i]] == 2)
		{
			if (m[x - 1] == 0)
				m[x - 1]++, m[x]--;
		}
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[v[i]] == 2)
		{
			if (m[x - 1] == 0)
				m[x - 1]++, m[x]--;
			else
				m[x + 1]++, m[x]--;
		}
	}
	if (m[n] > 1)
		m[n + 1] = 1;
	ll maxVal = 0;
	for (int i = 0; i <= n + 1; i++)
		if (m[i] > 0)
			maxVal++;
	m.clear();
	for (int i = 0; i < n; i++)
	{
		++m[v[i]];
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x - 1] >= 3 && m[x] <= 2)
			m[x] = 0;
		else if (m[x + 1] >= 3 && m[x] <= 2)
			m[x] = 0;
	}
	//printv(v);
	for (int i = 2; i <= n - 1; i += 3)
	{
		if (s.count(i - 1) == 1 && s.count(i) == 1 && s.count(i + 1) == 1)
		{
			m[i] = m[i + 1] + m[i - 1] + m[i];
			m[i + 1] = 0;
			m[i - 1] = 0;
		}
	}
	for (int i = 0; i <= n; i++)
	{
		if (m[i] > 0 && m[i + 1] > 0)
			m[i] = 0;
	}
	ll minVal = 0;
	for (int i = 0; i <= n; i++)
		if (m[i] > 0)
			minVal++;
	p2(minVal, maxVal);
}

int main()
{
	fio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//get(t);
	ll t = 1;
	while (t--)
	{
		mainSolve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
	for (ll i = 0; i < v.size(); ++i) \
		cout << v[i] << " ";            \
	cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define get(n) \
	ll n;        \
	cin >> n
#define getvec(v, n)         \
	vector<ll> v(n);           \
	for (ll i = 0; i < n; i++) \
		cin >> v[i];
#define getstr(s) \
	string s;       \
	cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void minVal(vl &v)
{
	ll n = v.size();
	map<ll, ll> m;
	for (int i = 0; i < n; i++)
		m[v[i]]++;
	for (int i = 2; i <= n - 1; i += 3)
	{
		if (m[i - 1] > 0 && m[i + 1] > 0)
		{
			m[i] = m[i - 1] + m[i + 1];
			m[i - 1] = 0;
			m[i + 1] = 0;
		}
	}
	for (int i = 1; i <= n; i++)
	{
		if (m[i] > 0 && m[i - 1] > 0)
			m[i - 1] = m[i - 1] + m[i], m[i] = 0;
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++)
		if (m[i] > 0)
			++ans;
	p0(ans);
}

void maxVal(vl &v)
{
	ll n = v.size();
	map<ll, ll> m;
	for (int i = 0; i < n; i++)
		m[v[i]]++;
	for (int i = 1; i <= n;)
	{
		if (m[i] == 0)
		{
			++i;
			continue;
		}
		ll j = i;
		ll sum = 0;
		while (m[j] != 0)
			sum += m[j++];
		ll diff = sum - (j - i);
		if (diff == 1)
		{
			if (m[i - 1] == 0)
				m[i - 1] = 1, i = j;
			else if (m[j] == 0)
				m[j] = 1, i = j + 1;
		}
		else if (diff > 1)
		{
			if (m[i - 1] == 0)
				m[i - 1] = 1, i = j;
			if (m[j] == 0)
				m[j] = 1, i = j + 1;
		}
		else
			i = j;
	}
	ll ans = 0;
	for (int i = 0; i <= n + 1; i++)
		if (m[i] > 0)
			++ans;
	p1(ans);
}

void mainSolve()
{
	get(n);
	getvec(v, n);
	minVal(v);
	maxVal(v);
}

int main()
{
	fio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//	get(t);
	ll t = 1;
	while (t--)
	{
		mainSolve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
	for (ll i = 0; i < v.size(); ++i) \
		cout << v[i] << " ";            \
	cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL)
#define get(n) \
	ll n;        \
	cin >> n
#define getvec(v, n)         \
	vector<ll> v(n);           \
	for (ll i = 0; i < n; i++) \
		cin >> v[i];
#define getstr(s) \
	string s;       \
	cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void mainSolve()
{
	get(n);
	getvec(v, n);
	map<ll, ll> m;
	set<ll> s;
	sort(all(v));
	for (int i = 0; i < n; i++)
	{
		++m[v[i]];
		s.insert(v[i]);
	}
	ll mx = 0, mn = n;
	for (auto it = s.begin(); it != s.end(); it++)
	{
		ll x = *it;
		if (m[x] > 2)
			m[x - 1]++, m[x + 1]++;
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[v[i]] == 2)
		{
			if (m[x - 1] == 0)
				m[x - 1]++, m[x]--;
		}
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[v[i]] == 2)
		{
			if (m[x - 1] == 0)
				m[x - 1]++, m[x]--;
			else
				m[x + 1]++, m[x]--;
		}
	}
	if (m[n] > 1)
		m[n + 1] = 1;
	ll maxVal = 0;
	for (int i = 0; i <= n + 1; i++)
		if (m[i] > 0)
			maxVal++;
	m.clear();
	for (int i = 0; i < n; i++)
	{
		++m[v[i]];
	}
	for (int i = 0; i < n; i++)
	{
		ll x = v[i];
		if (m[x - 1] >= 3 && m[x] <= 2)
			m[x] = 0;
		else if (m[x + 1] >= 3 && m[x] <= 2)
			m[x] = 0;
	}
	//printv(v);
	for (int i = 2; i <= n - 1; i += 3)
	{
		if (s.count(i - 1) == 1 && s.count(i) == 1 && s.count(i + 1) == 1)
		{
			m[i] = m[i + 1] + m[i - 1] + m[i];
			m[i + 1] = 0;
			m[i - 1] = 0;
		}
	}
	ll minVal = 0;
	for (int i = 0; i <= n; i++)
		if (m[i] > 0)
			minVal++;
	p2(minVal, maxVal);
}

int main()
{
	fio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//get(t);
	ll t = 1;
	while (t--)
	{
		mainSolve();
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<map>
#include<cstring>
#include<set>
#include<queue>
#include<climits>
#include<iomanip>
using namespace std;
#define uii long long int
#define it(a)  ::iterator a
#define sd(a) double a;scanf("%lf",&a);
#define slld(a) uii a;scanf("%lld",&a)
#define ss(a) scanf("%s",a)
#define plld(a) printf("%lld",a)
#define INF LLONG_MAX
#define MOD 1000000007
#define powOf2(a) !(a&a-1)
#define mod(a) (a>0 ? a : (-1*a))
#define tc(a) uii a; for(scanf("%lld",&a);a--;)
#define swap(a,b) a = a^b; b = a^b;a = a^b;
#define rep(i,n) for(uii i = 0;i<n;i++)
#define set(n,x) x |= (1 << n)
#define unset(n,x) x &= ~(1<<n)
#define check(n,x) (x & 1 << n) != 0
#define ppi pair<uii, pair<uii, uii> >

string a = "0123456789";

string createRandom(string curr, uii flag){
	for(uii i = 0;i<4;i++){
		if(check(i, flag)){
			uii ran = rand()%10;
			curr[i] = a[ran];
		}
	}
	return curr;
}

int main(){

	uii c = 1,b;
	string ans = "";
	string curr = "0000";
	uii f = (1 << 4) - 1;
	//cout<<createRandom(curr, f)<<endl;
	//cout<<createRandom(curr, f);
	//cin>>b>>c;
	//cout<<curr;
	//fflush(stdout);
	//cin>>b>>c;
	if(b == 4 && c == 0) return 0;
	//cout<<"here"<<endl;
	//fflush(stdout);
	//if(b == 4 && c == 0) return 0;
	uii prevb = b;
	prevb = -1;
	for(uii i = 0;i<10;i++){
		curr[0] = i+'0';
		cout<<curr<<endl;
		fflush(stdout);
		cin>>b>>c;
			if(b == 4 && c == 0) return 0;

			if(prevb > b){
				curr[0]-= 1;
				break;

			}

		prevb = b;
	}

	prevb= -1;
	//cout<<"ere"<<endl;
	for(uii i = 0;i<10;i++){
		curr[1] = i +'0';
		//cout<<(char)(i+'0')<<endl;
		cout<<curr<<endl;
		fflush(stdout);
		cin>>b>>c;
			if(b == 4 && c == 0) return 0;

			if(prevb > b){
				curr[1]-= 1;
				break;
			}

		prevb = b;
	}

	prevb= -1;

	for(uii i = 0;i<10;i++){
		curr[2] = i+'0';
		cout<<curr<<endl;
		fflush(stdout);
		cin>>b>>c;
			if(b == 4 && c == 0) return 0;

			if(prevb > b){
				curr[2]-= 1;
				break;
			}

		prevb = b;
	}

	prevb= -1;

	for(uii i = 0;i<10;i++){
		curr[3] = i+'0';
		cout<<curr<<endl;
		fflush(stdout);
		cin>>b>>c;
			if(b == 4 && c == 0) return 0;

			if(prevb > b){
				curr[3]-= 1;
				break;
			}

		prevb = b;
	}

	//cout<<"here"<<endl;
	/*while(b != 4 || c!=0){
		//cout<<"here"<<endl;
		while(prevb <= b){
			curr[i] =  (curr[i] + 1);
			cout<<curr;
		//	cout<<prevb<<" "<<b<<endl;
			fflush(stdout);
			prevb = b;
			cin>>b>>c;
			if(b == 4 && c == 0) return 0;
	//		fflush(stdout);
		}

		curr[i] -= 1;
		curr[i+1] += 1;
		cout<<curr;
		fflush(stdout);
		cin>>b>>c;
		if(b == 4 && c == 0) return 0;
		prevb = b;
		i++;
	}*/
	//while(b != 4 &&  c != 0){

	//}

	return 0;
}


#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<map>
#include<cstring>
#include<set>
#include<queue>
#include<climits>
#include<iomanip>
using namespace std;
#define uii long long int
#define it(a)  ::iterator a
#define sd(a) double a;scanf("%lf",&a);
#define slld(a) uii a;scanf("%lld",&a)
#define ss(a) scanf("%s",a)
#define plld(a) printf("%lld",a)
#define INF LLONG_MAX
#define MOD 1000000007
#define powOf2(a) !(a&a-1)
#define mod(a) (a>0 ? a : (-1*a))
#define tc(a) uii a; for(scanf("%lld",&a);a--;)
#define swap(a,b) a = a^b; b = a^b;a = a^b;
#define rep(i,n) for(uii i = 0;i<n;i++)
#define set(n,x) x |= (1 << n)
#define unset(n,x) x &= ~(1<<n)
#define check(n,x) (x & 1 << n) != 0
#define ppi pair<uii, pair<uii, uii> >

string a = "0123456789";

string createRandom(string curr, uii flag){
	for(uii i = 0;i<4;i++){
		if(check(i, flag)){
			uii ran = rand()%10;
			curr[i] = a[ran];
		}
	}
	return curr;
}

int main(){

	uii c = 1,b;
	string ans = "";
	string curr = "0000";
	uii f = (1 << 4) - 1;
	//cout<<createRandom(curr, f)<<endl;
	//cout<<createRandom(curr, f);
	//cin>>b>>c;
	cout<<curr<<endl;
	fflush(stdout);
	cin>>b>>c;
	if(b == 4 && c == 0) return 0;
	//cout<<"here"<<endl;
	//fflush(stdout);
	//if(b == 4 && c == 0) return 0;
	uii prevb = b;
	uii i = 0;
	//cout<<"here"<<endl;
	while(b != 4 || c!=0){
		//cout<<"here"<<endl;
		while(prevb <= b){
			curr[i] =  (curr[i] + 1);
			cout<<curr<<endl;
		//	cout<<prevb<<" "<<b<<endl;
			fflush(stdout);
			prevb = b;
			cin>>b>>c;
			if(b == 4 && c == 0) return 0;
	//		fflush(stdout);
		}

		curr[i] -= 1;
		curr[i+1] += 1;
		cout<<curr<<endl;
		fflush(stdout);
		cin>>b>>c;
		if(b == 4 && c == 0) return 0;
		prevb = b;
		i++;
	}
	//while(b != 4 &&  c != 0){

	//}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define inf ((ll)1e18)
#define pb push_back
#define clear(vis,i) memset(vis,i,sizeof(vis))
#define ll long long int
#define N 500500
vector<int> adj;
int remem[10];
int res[5];
int main(){
  int key = 0;
  int w = 0;
  int cnt = 0;
  int t = 0;
  int atm = 0;
  int notx = -1;
  while(1){
    if(!key){
      for(int i=0;i<4;i++){
        printf("%d",w);
      }
      printf("\n");
      int foo[2];
      scanf("%d%d",foo,foo+1);
      if(foo[0]){
        adj.pb(w);
        remem[w]++;
      }
      w++;
      if(w == 10){
        key = 1;
        for(int i=0;i<10;i++){
          if(!remem[i]){
            notx = i;
            break;
          }
        }
        w = 0;
        continue;
      }
      atm++;
    }
    else{
      for(int i=0;i<4;i++){
        if(i == cnt)
        printf("%d",adj[w]);
        else printf("%d",notx);
      }
      printf("\n");
      int foo[2];
      scanf("%d%d",foo,foo+1);
      if(foo[0]){
        res[t++] = adj[w];
      }
      cnt++;
      if(cnt == 4){
        w++;
        cnt = 0;
        if(w == 4){
          for(int i=0;i<5;i++){
            printf("%d",res[i]);
          }
          return 0;
        }
      }
      atm++;
    }
    fflush(stdout);
  }
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define inf ((ll)1e18)
#define pb push_back
#define clear(vis,i) memset(vis,i,sizeof(vis))
#define ll long long int
#define N 500500
vector<int> adj;
int remem[10];
int res[5];
int main(){
  int key = 0;
  int w = 0;
  int cnt = 0;
  int t = 0;
  int atm = 0;
  int notx = -1;
  while(1){
    if(!key){
      for(int i=0;i<4;i++){
        printf("%d",w);
      }
      printf("\n");
      fflush(stdout);
      int foo[2];
      scanf("%d%d",foo,foo+1);
      if(foo[0]){
        adj.pb(w);
        remem[w]++;
      }
      w++;
      if(w == 10){
        key = 1;
        for(int i=0;i<10;i++){
          if(!remem[i]){
            notx = i;
            break;
          }
        }
        w = 0;
        continue;
      }
      atm++;
    }
    else{
      for(int i=0;i<4;i++){
        if(i == cnt)
        printf("%d",adj[w]);
        else printf("%d",notx);
      }
      printf("\n");
      fflush(stdout);
      int foo[2];
      scanf("%d%d",foo,foo+1);
      if(foo[0]){
        res[t++] = adj[w];
      }
      cnt++;
      if(cnt == 4){
        w++;
        cnt = 0;
        if(w == 4){
          for(int i=0;i<4;i++){
            printf("%d",res[i]);
          }
          fflush(stdout);
          return 0;
        }
      }
      atm++;
    }
    fflush(stdout);
  }
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define inf ((ll)1e18)
#define pb push_back
#define clear(vis,i) memset(vis,i,sizeof(vis))
#define ll long long int
#define N 500500
vector<int> adj;
int remem[10];
int res[5];
int main(){
  int key = 0;
  int w = 0;
  int cnt = 0;
  int t = 0;
  int atm = 0;
  int notx = -1;
  while(1){
    if(!key){
      for(int i=0;i<4;i++){
        printf("%d",w);
      }
      printf("\n");
      fflush(stdout);
      int foo[2];
      scanf("%d%d",foo,foo+1);
      if(foo[0]){
        adj.pb(w);
        remem[w]++;
      }
      w++;
      if(w == 10){
        key = 1;
        for(int i=0;i<10;i++){
          if(!remem[i]){
            notx = i;
            break;
          }
        }
        w = 0;
        continue;
      }
      atm++;
    }
    else{
      for(int i=0;i<4;i++){
        if(i == cnt)
        printf("%d",adj[w]);
        else printf("%d",notx);
      }
      printf("\n");
      fflush(stdout);
      int foo[2];
      scanf("%d%d",foo,foo+1);
      if(foo[0]){
        res[cnt] = adj[w];
      }
      cnt++;
      if(cnt == 4){
        w++;
        cnt = 0;
        if(w == 4){
          for(int i=0;i<4;i++){
            printf("%d",res[i]);
          }
          printf("\n");
          fflush(stdout);
          return 0;
        }
      }
      atm++;
    }
    fflush(stdout);
  }
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define inf ((ll)1e18)
#define pb push_back
#define clear(vis,i) memset(vis,i,sizeof(vis))
#define ll long long int
#define N 500500
vector<int> adj;
int remem[10];
int res[5];
int main(){
  int key = 0;
  int w = 0;
  int cnt = 0;
  int t = 0;
  int atm = 0;
  int notx = -1;
  while(1){
    if(!key){
      for(int i=0;i<4;i++){
        printf("%d",w);
        fflush(stdout);
      }
      fflush(stdout);
      int foo[2];
      scanf("%d%d",foo,foo+1);
      if(foo[0]){
        adj.pb(w);
        remem[w]++;
      }
      w++;
      if(w == 10){
        key = 1;
        for(int i=0;i<10;i++){
          if(!remem[i]){
            notx = i;
            break;
          }
        }
        w = 0;
        continue;
      }
      atm++;
    }
    else{
      for(int i=0;i<4;i++){
        if(i == cnt)
        printf("%d",adj[w]);
        else printf("%d",notx);
        fflush(stdout);
      }
      fflush(stdout);
      int foo[2];
      scanf("%d%d",foo,foo+1);
      if(foo[0]){
        res[t++] = adj[w];
      }
      cnt++;
      if(cnt == 4){
        w++;
        cnt = 0;
        if(w == 4){
          for(int i=0;i<4;i++){
            printf("%d",res[i]);
            fflush(stdout);
          }
          fflush(stdout);
          return 0;
        }
      }
      atm++;
    }
    fflush(stdout);
  }
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define inf ((ll)1e18)
#define pb push_back
#define clear(vis,i) memset(vis,i,sizeof(vis))
#define ll long long int
#define N 500500
vector<int> adj;
int remem[10];
int res[5];
int main(){
  int key = 0;
  int w = 0;
  int cnt = 0;
  int t = 0;
  int atm = 0;
  int notx = -1;
  while(1){
    if(!key){
      for(int i=0;i<4;i++){
        printf("%d",w);
      }
      fflush(stdout);
      int foo[2];
      scanf("%d%d",foo,foo+1);
      if(foo[0]){
        adj.pb(w);
        remem[w]++;
      }
      w++;
      if(w == 10){
        key = 1;
        for(int i=0;i<10;i++){
          if(!remem[i]){
            notx = i;
            break;
          }
        }
        w = 0;
        continue;
      }
      atm++;
    }
    else{
      for(int i=0;i<4;i++){
        if(i == cnt)
        printf("%d",adj[w]);
        else printf("%d",notx);
      }
      fflush(stdout);
      int foo[2];
      scanf("%d%d",foo,foo+1);
      if(foo[0]){
        res[t++] = adj[w];
      }
      cnt++;
      if(cnt == 4){
        w++;
        cnt = 0;
        if(w == 4){
          for(int i=0;i<4;i++){
            printf("%d",res[i]);
          }
          fflush(stdout);
          return 0;
        }
      }
      atm++;
    }
    fflush(stdout);
  }
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define inf ((ll)1e18)
#define pb push_back
#define clear(vis,i) memset(vis,i,sizeof(vis))
#define ll long long int
#define N 500500
vector<int> adj;
int remem[10];
int res[5];
int main(){
  int key = 0;
  int w = 0;
  int cnt = 0;
  int t = 0;
  int atm = 0;
  int notx = -1;
  while(1){
    if(!key){
      for(int i=0;i<4;i++){
        printf("%d",w);
      }
      printf("\n");
      int foo[2];
      scanf("%d%d",foo,foo+1);
      if(foo[0]){
        adj.pb(w);
        remem[w]++;
      }
      w++;
      if(w == 10){
        key = 1;
        for(int i=0;i<10;i++){
          if(!remem[i]){
            notx = i;
            break;
          }
        }
        w = 0;
        continue;
      }
      atm++;
    }
    else{
      for(int i=0;i<4;i++){
        if(i == cnt)
        printf("%d",adj[w]);
        else printf("%d",notx);
      }
      printf("\n");
      int foo[2];
      scanf("%d%d",foo,foo+1);
      if(foo[0]){
        res[t++] = adj[w];
      }
      cnt++;
      if(cnt == 4){
        w++;
        cnt = 0;
        if(w == 4){
          for(int i=0;i<4;i++){
            printf("%d",res[i]);
          }
          return 0;
        }
      }
      atm++;
    }
    fflush(stdout);
  }
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<string> ans;
vector<char> digits;
void get(string a) {
   string b = a;
if(a.length() == 4) {
    ans.push_back(b);

}
for(int i =0;i<4;i++){
       bool v = false;
   for(int j=0;j<a.length();j++) {
    if(a[j] == digits[i]) v = true;
   }
    if(!v) {
        get(b + digits[i]);
    }
}
}
int main()
{
    while(true) {
        for(int i =0;i<10;i++){
           string a;
           a+='0'+i;a+='0'+i;a+='0'+i;a+='0'+i;
           cout << a;
           cout << endl;
           int b,c;
           cin >> b >> c;
           for(int s =0;s<c;s++) digits.push_back('0'+i);
        }
        get("");
        for(int i =0;i<ans.size();i++){
            cout << ans[i];
            cout <<endl;
            int b,c;
            cin >> b >> c;
            if(b == 4 && c ==0) return 0;
        }
    }

    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<string> ans;
vector<char> digits;
void get(string a) {
   string b = a;
if(a.length() == 4) {
    ans.push_back(b);

}
for(int i =0;i<4;i++){
       bool v = false;
   for(int j=0;j<a.length();j++) {
    if(a[j] == digits[i]) v = true;
   }
    if(!v) {
        get(b + digits[i]);
    }
}
}
int main()
{
    while(true) {
        for(int i =0;i<10;i++){
           string a;
           a+='0'+i;a+='0'+i;a+='0'+i;a+='0'+i;
           cout << a;
           cout << endl;
           int b,c;
           cin >> b >> c;
           for(int s =0;s<c+b;s++) digits.push_back('0'+i);
        }
        get("");
        for(int i =0;i<ans.size();i++){
            cout << ans[i];
            cout <<endl;
            int b,c;
            cin >> b >> c;
            if(b == 4 && c ==0) return 0;
        }
    }

    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<string> ans;
vector<char> digits;
void get(string a) {
   string b = a;
if(a.length() == 4) {
    ans.push_back(b);

}
for(int i =0;i<4;i++){
       bool v = false;
   for(int j=0;j<a.length();j++) {
    if(a[j] == digits[i]) v = true;
   }
    if(!v) {
        get(b + digits[i]);
    }
}
}
int main()
{
    while(true) {
        for(int i =0;i<10;i++){
           string a;
           a+='0'+i;a+='0'+i;a+='0'+i;a+='0'+i;
           cout << a<<endl;
           int b,c;
           cin >> b >> c;
           for(int s =0;s<c;s++) digits.push_back('0'+i);
        }
        get("");
        for(int i =0;i<ans.size();i++){
            cout << ans[i] <<endl;
            int b,c;
            cin >> b >> c;
            if(b == 4 && c ==0) return 0;
        }
    }

    return 0;
}


//
//  main.cpp
//  B. Interactive Bulls and Cows (Easy)
//
//  Created by y.m on 24.08.20.
//

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, const char * argv[]) {

    vector<int> ans;
    int b, c;

    for(int i=0; i<= 9; i++)
    {
        for(int k = 1; k<= 4; k++)
        {
            cout<<i;
        }
        cout<<"\n";
        fflush(stdout);
        cin>>b>>c;
        if(b)
        {
            ans.push_back(i);
        }
        if(ans.size() == 4)
        {
            break;

        }
    }
    sort(ans.begin(), ans.end());
    do{
        for(int i =0; i< 4; i++)
        {
            cout<<ans[i];
        }
        cout<<"\n";
        fflush(stdout);
        cin>>b>>c;
        if(b == 4)
            return 0;

    }while(next_permutation(ans.begin(),ans.end()));

    return 0;
}


//
//  main.cpp
//  B. Interactive Bulls and Cows (Easy)
//
//  Created by y.m on 24.08.20.
//

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, const char * argv[]) {

    vector<int> ans;
    int b, c;

    for(int i=0; i<= 9; i++)
    {
        for(int k = 1; k<= 4; k++)
        {
            cout<<i;
        }
        fflush(stdout);
        cin>>b>>c;
        if(b)
        {
            ans.push_back(i);
        }
        if(ans.size() == 4)
        {
            break;

        }
    }
    sort(ans.begin(), ans.end());
    do{
        for(int i =0; i< 4; i++)
        {
            cout<<ans[i];
        }
        fflush(stdout);
        cin>>b>>c;
        if(b == 4)
            return 0;

    }while(next_permutation(ans.begin(),ans.end()));

    return 0;
}


// #include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <sstream>

using namespace std;

#define MAXINT numeric_limits<int>::max()
#define MININT numeric_limits<int>::min()
#define PI 3.1415926
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define per(i, a, n) for(int i = (n)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sn second
#define vi vector<int>
#define si set<int>
#define li list<int>
#define lit list<int>::iterator
#define sit set<int>::iterator
#define mit map<int, int>::iterator

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, double> pdd;

template <typename T>
void print_array(T arr[], int size_arr){
	rep(i, 0, size_arr){
		cout << arr[i];
		if(i == size_arr - 1) cout << endl;
		else cout << " ";
	}
}

template<typename T>
void print_vector(vector<T> v){
	rep(i, 0, v.size()){
		cout << v[i];
		if(i == v.size() - 1) cout << endl;
		else cout << " ";
	}
}

template <typename T>
void memset_array(T arr[], T value, int size_arr){
	rep(i, 0, size_arr){
		arr[i] = value;
	}
}

bool compare_lexical_string(string a, string b){
	rep(i, 0, min(a.length(), b.length())){
		if(a[i] != b[i]) return a[i] < b[i];
	}
	return a.length() < b.length();
}
struct lex_string
{
	bool operator()(string a, string b){
		return compare_lexical_string(a, b);
	}
};

/////////////////////////////////////////////////////////////////////////////
// NEVER USE NAME : DISTANCE FOR FUNCTION
// NEVER USE NAME : FIND FOR FUNCTION
// AVOID DOUBLE IF POSSIBLE
////////////////////////////////////////////////////////////////////////////
// compare_lexical_string("huy", "huy") will return false

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	srand (time(NULL));
	bool ok[10000];
	memset_array(ok, true, 10000);
	int num = 10000;
	rep(times, 0, 49){
		// printf("%d\n", num);
		int bu, co;
		int K = rand() % num + 1;
		int pos = 0;
		rep(j, 0, 10000){
			if(ok[j]) K--;
			if(K == 0){
				pos = j;
				break;
			}
		}

		int a1, b1, c1, d1;
		int tmp1 = pos;
		a1 = tmp1/1000;
		tmp1 = tmp1 % 1000;
		b1 = tmp1/100;
		tmp1 = tmp1 % 100;
		c1 = tmp1/10;
		tmp1 = tmp1 % 10;
		d1 = tmp1;

		if(times < 2){
			a1 = 4*times;
			b1 = 4*times + 1;
			c1 = 4*times + 2;
			d1 = 4*times + 3;
		}

		cout << a1<<b1<<c1<<d1<<endl;
		cout << flush;
		cin>>bu>>co;
		if(bu == 4 && co == 0) return 0;

		rep(i, 0, 10000){
			if(ok[i]){
				int a, b, c, d;
				int tmp = i;
				a = tmp/1000;
				tmp = tmp % 1000;
				b = tmp/100;
				tmp = tmp % 100;
				c = tmp/10;
				tmp = tmp % 10;
				d = tmp;

				// cout << a << b<<c<<d<<endl;

				int bull, cow;
				bull = cow = 0;
				if(a == a1) bull++;
				if(b == b1) bull++;
				if(c == c1) bull++;
				if(d == d1) bull++;

				rep(k, 0, 10){
					if((a == k || b == k || c == k || d == k) && (a1 == k || b1 == k || c1 == k || d1 == k) &&
						!((a==k && a1 == k) || (b==k&&b1 == k) || (c==k&&c1==k)||(d==k && d1==k))){

							cow++;
							// cout << k << endl;
						}
				}
				// cout << bull << " " << cow << endl;
				if(bull != bu || cow != co){
					ok[i] = false;
					num--;
				}
				// else cout << i << endl;
			}
		}
	}

	rep(i, 0, 10000){
		if(ok[i]){
			int a, b, c, d;
			int tmp = i;
			a = tmp/1000;
			tmp = tmp % 1000;
			b = tmp/100;
			tmp = tmp % 100;
			c = tmp/10;
			tmp = tmp % 10;
			d = tmp;

			cout <<a<<b<<c<<d<<endl;
			cout << flush;
		}
	}

	return 0;
}


// #include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <sstream>

using namespace std;

#define MAXINT numeric_limits<int>::max()
#define MININT numeric_limits<int>::min()
#define PI 3.1415926
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define per(i, a, n) for(int i = (n)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sn second
#define vi vector<int>
#define si set<int>
#define li list<int>
#define lit list<int>::iterator
#define sit set<int>::iterator
#define mit map<int, int>::iterator

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, double> pdd;

template <typename T>
void print_array(T arr[], int size_arr){
	rep(i, 0, size_arr){
		cout << arr[i];
		if(i == size_arr - 1) cout << endl;
		else cout << " ";
	}
}

template<typename T>
void print_vector(vector<T> v){
	rep(i, 0, v.size()){
		cout << v[i];
		if(i == v.size() - 1) cout << endl;
		else cout << " ";
	}
}

template <typename T>
void memset_array(T arr[], T value, int size_arr){
	rep(i, 0, size_arr){
		arr[i] = value;
	}
}

bool compare_lexical_string(string a, string b){
	rep(i, 0, min(a.length(), b.length())){
		if(a[i] != b[i]) return a[i] < b[i];
	}
	return a.length() < b.length();
}
struct lex_string
{
	bool operator()(string a, string b){
		return compare_lexical_string(a, b);
	}
};

/////////////////////////////////////////////////////////////////////////////
// NEVER USE NAME : DISTANCE FOR FUNCTION
// NEVER USE NAME : FIND FOR FUNCTION
// AVOID DOUBLE IF POSSIBLE
////////////////////////////////////////////////////////////////////////////
// compare_lexical_string("huy", "huy") will return false
int main(){
	// ios_base::sync_with_stdio(0); cin.tie(0);
	int bu[6], co[6];
	int q[6][4];
	srand (time(NULL));

	// rep(i, 0, 3){
	// 	q[i][0] = 3*i;
	// 	q[i][1] = 3*i+1;
	// 	q[i][2] = 3*i+2;
	// 	q[i][3] = 3*i+3;
	// 	printf("%d%d%d%d\n", q[i][0], q[i][1], q[i][2], q[i][3]);
	// 	fflush(stdout);
	// 	scanf("%d %d", &bu[i], &co[i]);
	// 	if(bu[i] == 4 && co[i] == 0) return 0;
	// }

	rep(i, 0, 49){
		rep(j, 0, 4) q[i][j] = rand()%10;
		printf("%d%d%d%d\n", q[i][0], q[i][1], q[i][2], q[i][3]);
		fflush(stdout);
		scanf("%d %d", &bu[i], &co[i]);
		if(bu[i] == 4 && co[i] == 0) return 0;
	}

	rep(i, 0, 10000){
		bool ok = true;
		int a, b, c, d;
		int tmp = i;
		a = tmp/1000;
		tmp = tmp % 1000;
		b = tmp/100;
		tmp = tmp % 100;
		c = tmp/10;
		tmp = tmp % 10;
		d = tmp;

		// cout << a << b<<c<<d<<endl;

		rep(j, 0, 6){
			int bull, cow;
			bull = cow = 0;
			if(a == q[j][0]) bull++;
			if(b == q[j][1]) bull++;
			if(c == q[j][2]) bull++;
			if(d == q[j][3]) bull++;

			rep(k, 0, 10){
				if((a == k || b == k || c == k || d == k) && (q[j][0] == k || q[j][1] == k || q[j][2] == k || q[j][3] == k) &&
					!((a==k && q[j][0] == k) || (b==k&&q[j][1] == k) || (c==k&&q[j][2]==k)||(d==k && q[j][3]==k))){

						cow++;
						// cout << k << endl;
					}
			}
			// cout << bull << " " << cow << endl;
			if(bull != bu[j] || cow != co[j]) ok = false;
		}

		if(ok){
			printf("%d%d%d%d\n", a, b, c, d);
			fflush(stdout);
			break;
		}

	}

	return 0;
}


// #include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <sstream>

using namespace std;

#define MAXINT numeric_limits<int>::max()
#define MININT numeric_limits<int>::min()
#define PI 3.1415926
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define per(i, a, n) for(int i = (n)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sn second
#define vi vector<int>
#define si set<int>
#define li list<int>
#define lit list<int>::iterator
#define sit set<int>::iterator
#define mit map<int, int>::iterator

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, double> pdd;

template <typename T>
void print_array(T arr[], int size_arr){
	rep(i, 0, size_arr){
		cout << arr[i];
		if(i == size_arr - 1) cout << endl;
		else cout << " ";
	}
}

template<typename T>
void print_vector(vector<T> v){
	rep(i, 0, v.size()){
		cout << v[i];
		if(i == v.size() - 1) cout << endl;
		else cout << " ";
	}
}

template <typename T>
void memset_array(T arr[], T value, int size_arr){
	rep(i, 0, size_arr){
		arr[i] = value;
	}
}

bool compare_lexical_string(string a, string b){
	rep(i, 0, min(a.length(), b.length())){
		if(a[i] != b[i]) return a[i] < b[i];
	}
	return a.length() < b.length();
}
struct lex_string
{
	bool operator()(string a, string b){
		return compare_lexical_string(a, b);
	}
};

/////////////////////////////////////////////////////////////////////////////
// NEVER USE NAME : DISTANCE FOR FUNCTION
// NEVER USE NAME : FIND FOR FUNCTION
// AVOID DOUBLE IF POSSIBLE
////////////////////////////////////////////////////////////////////////////
// compare_lexical_string("huy", "huy") will return false
int main(){
	// ios_base::sync_with_stdio(0); cin.tie(0);
	int bu[49], co[49];
	int q[49][4];
	srand (time(NULL));

	// rep(i, 0, 3){
	// 	q[i][0] = 3*i;
	// 	q[i][1] = 3*i+1;
	// 	q[i][2] = 3*i+2;
	// 	q[i][3] = 3*i+3;
	// 	printf("%d%d%d%d\n", q[i][0], q[i][1], q[i][2], q[i][3]);
	// 	fflush(stdout);
	// 	scanf("%d %d", &bu[i], &co[i]);
	// 	if(bu[i] == 4 && co[i] == 0) return 0;
	// }

	rep(i, 0, 49){
		rep(j, 0, 4) q[i][j] = rand()%10;
		printf("%d%d%d%d\n", q[i][0], q[i][1], q[i][2], q[i][3]);
		fflush(stdout);
		scanf("%d %d", &bu[i], &co[i]);
		if(bu[i] == 4 && co[i] == 0) return 0;
	}

	rep(i, 0, 10000){
		bool ok = true;
		int a, b, c, d;
		int tmp = i;
		a = tmp/1000;
		tmp = tmp % 1000;
		b = tmp/100;
		tmp = tmp % 100;
		c = tmp/10;
		tmp = tmp % 10;
		d = tmp;

		// cout << a << b<<c<<d<<endl;

		rep(j, 0, 49){
			int bull, cow;
			bull = cow = 0;
			if(a == q[j][0]) bull++;
			if(b == q[j][1]) bull++;
			if(c == q[j][2]) bull++;
			if(d == q[j][3]) bull++;

			rep(k, 0, 10){
				if((a == k || b == k || c == k || d == k) && (q[j][0] == k || q[j][1] == k || q[j][2] == k || q[j][3] == k) &&
					!((a==k && q[j][0] == k) || (b==k&&q[j][1] == k) || (c==k&&q[j][2]==k)||(d==k && q[j][3]==k))){

						cow++;
						// cout << k << endl;
					}
			}
			// cout << bull << " " << cow << endl;
			if(bull != bu[j] || cow != co[j]) ok = false;
		}

		if(ok){
			printf("%d%d%d%d\n", a, b, c, d);
			fflush(stdout);
			break;
		}

	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool a[10];

vector <int> v;

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int dorost, ghalat;
    for (int i = 1; i < 10; i++)
    {
        cout << i << i << i << i << endl;
        cin >> dorost >> ghalat;
        if (dorost > 0 || ghalat > 0){a[i] = 1; v.push_back(i);}
    }
    for (int i = 0; i <= 30; i++)
    {
        for (int j = 0; j < 4; j++){cout << v[i];}
        cout << endl;
        next_permutation(v.begin(), v.end());
        cin >> dorost >> ghalat;
        if (dorost == 4){return 0;}
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool a[10];

vector <int> v;

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int dorost, ghalat;
    for (int i = 1; i < 10; i++)
    {
        cout << i << i << i << i << endl;
        cin >> dorost >> ghalat;
        if (dorost > 0 || ghalat > 0){a[i] = 1; v.push_back(i);}
    }
    for (int i = 0; i <= 30; i++)
    {
        for (int j = 0; j < 4; j++){cout << v[j];}
        cout << endl;
        next_permutation(v.begin(), v.end());
        cin >> dorost >> ghalat;
        if (dorost == 4){return 0;}
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool a[10];

vector <int> v;

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int dorost, ghalat;
    for (int i = 0; i < 10; i++)
    {
        cout << i << i << i << i << endl;
        cin >> dorost >> ghalat;
        if (dorost > 0 || ghalat > 0){a[i] = 1; v.push_back(i);}
    }
    for (int i = 0; i <= 30; i++)
    {
        for (int j = 0; j < 4; j++){cout << v[j];}
        cout << endl;
        next_permutation(v.begin(), v.end());
        cin >> dorost >> ghalat;
        if (dorost == 4){return 0;}
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <math.h>
#include <stack>
#include <sstream>
#include <bitset>
#include <ctime>

using namespace std;

#define lol long long
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define endl "\n"
#define mp make_pair
#define y1 asdskdjgsasdasd123
#define x1 sdkjfksdasdjfk
#define y2 sdkjfks123
#define x2 skaaaasd

/*
#include <fstream>
ifstream in("liz10c.in");
ofstream out("liz10c.out");
/**/

int used[10000];
int cnt = 10000;

string toStr(int x)
{
  string s = to_string(x);

  while (s.size() != 4)
    s.insert(s.begin(), '0');

  return s;
}

pii dist(string s, string t)
{
  set<int> r;
  pii ans = mp(0,0);
  for (int i = 0; i < 4; ++i)
    if (s[i] == t[i])
    {
      ++ans.first;
      r.insert(s[i]);
    }
  for (int i = 0; i < 4; ++i)
    if (r.find(s[i]) == r.end() && t.find(s[i]) != string::npos)
      ++ans.second;

  return ans;
}

bool distinct(string s)
{
  for (int i = 0; i < 4; ++i)
    for (int j = i + 1; j < 4; ++j)
      if (s[i] == s[j])
        return false;
  return true;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cout.precision(12);
  cout << fixed;

  for (int i = 0; i < 10000; ++i)
    if (!distinct(toStr(i)))
      used[i] = true;

  srand(time(0));
  while (cnt >= 2)
  {
    vector<int> cur;
    for (int i = 0; i < 10000; ++i)
      if (!used[i])
        cur.push_back(i);

    int c = rand() % cur.size();
    string d = toStr(cur[c]);
    cout << toStr(cur[c]) << endl;
    cout.flush();

    pii ret;
    cin >> ret.first >> ret.second;

    for (int i = 0; i < cur.size(); ++i)
      if (dist(d, toStr(cur[i])) != ret)
        used[cur[i]] = true;
  }

  for (int i = 0; i < 10000; ++i)
    if (!used[i])
    {
      cout << toStr(i) << endl;
      cout.flush();
      break;
    }

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <math.h>
#include <stack>
#include <sstream>
#include <bitset>
#include <ctime>

using namespace std;

#define lol long long
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define endl "\n"
#define mp make_pair
#define y1 asdskdjgsasdasd123
#define x1 sdkjfksdasdjfk
#define y2 sdkjfks123
#define x2 skaaaasd

/*
#include <fstream>
ifstream in("liz10c.in");
ofstream out("liz10c.out");
/**/

int used[10000];
int cnt = 10000;

string toStr(int x)
{
  string s = to_string(x);

  while (s.size() != 4)
    s.insert(s.begin(), '0');

  return s;
}

pii dist(string s, string t)
{
  set<int> r;
  pii ans = mp(0,0);
  for (int i = 0; i < 4; ++i)
    if (s[i] == t[i])
    {
      ++ans.first;
      r.insert(s[i]);
    }
  for (int i = 0; i < 4; ++i)
    if (r.find(s[i]) == r.end() && t.find(s[i]) != string::npos)
      ++ans.second;

  return ans;
}

bool distinct(string s)
{
  for (int i = 0; i < 4; ++i)
    for (int j = i + 1; j < 4; ++j)
      if (s[i] == s[j])
        return false;
  return true;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cout.precision(12);
  cout << fixed;

  for (int i = 0; i < 10000; ++i)
    if (!distinct(toStr(i)))
      used[i] = true;

  srand(time(0));
  while (cnt >= 2)
  {
    vector<int> cur;
    for (int i = 0; i < 10000; ++i)
      if (!used[i])
        cur.push_back(i);

    int c = rand() % cur.size();
    string d = toStr(cur[c]);
    cout << toStr(cur[c]) << endl;
    cout.flush();

    pii ret;
    cin >> ret.first >> ret.second;

    for (int i = 0; i < cur.size(); ++i)
      if (dist(d, toStr(cur[i])) != ret)
        used[cur[i]] = true;

    if (ret.first == 4 && ret.second == 0)
    {
      return 0;
    }
  }

  for (int i = 0; i < 10000; ++i)
    if (!used[i])
    {
      cout << toStr(i) << endl;
      cout.flush();
      break;
    }

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <math.h>
#include <stack>
#include <sstream>
#include <bitset>

using namespace std;

#define lol long long
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define endl "\n"
#define mp make_pair
#define y1 asdskdjgsasdasd123
#define x1 sdkjfksdasdjfk
#define y2 sdkjfks123
#define x2 skaaaasd

/*
#include <fstream>
ifstream in("liz10c.in");
ofstream out("liz10c.out");
/**/

int used[10000];
int cnt = 10000;

string toStr(int x)
{
  string s = to_string(x);

  while (s.size() != 4)
    s.insert(s.begin(), '0');

  return s;
}

pii dist(string s, string t)
{
  set<int> r;
  pii ans = mp(0,0);
  for (int i = 0; i < 4; ++i)
    if (s[i] == t[i])
    {
      ++ans.first;
      r.insert(s[i]);
    }
  for (int i = 0; i < 4; ++i)
    if (r.find(s[i]) == r.end() && t.find(s[i]) != string::npos)
      ++ans.second;

  return ans;
}

bool distinct(string s)
{
  for (int i = 0; i < 4; ++i)
    for (int j = i + 1; j < 4; ++j)
      if (s[i] == s[j])
        return false;
  return true;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cout.precision(12);
  cout << fixed;

  for (int i = 0; i < 10000; ++i)
    if (!distinct(toStr(i)))
      used[i] = true;

  srand(time(0));
  while (cnt >= 2)
  {
    vector<int> cur;
    for (int i = 0; i < 10000; ++i)
      if (!used[i])
        cur.push_back(i);

    int c = rand() % cur.size();
    string d = toStr(cur[c]);
    cout << toStr(cur[c]) << endl;
    cout.flush();

    pii ret;
    cin >> ret.first >> ret.second;

    for (int i = 0; i < cur.size(); ++i)
      if (dist(d, toStr(cur[i])) != ret)
        used[cur[i]] = true;
  }

  for (int i = 0; i < 10000; ++i)
    if (!used[i])
    {
      cout << toStr(i) << endl;
      cout.flush();
      break;
    }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif
void optimise()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main()
{
	int a,x,y,ct=0;
	for(int i=0;i<10;i++)
	{
		string s(4);
		for(int j=0;j<4;j++)
			s[j]='0'+i;
		cout << s << endl;
		cin >> x >>  y;
		if(x==0 && y==0)
		{
			a=i;
			break;
		}
	}
	char foo[5]={};
	char ans[5]={};
	for(int i=0;(i<10)&&(ct<4);i++)
	{
		for(int pos=0;pos<4;pos++)
		{
			for(int j=0;j<4;j++)
				foo[j]=a+'0';
			foo[pos]=i+'0';
			cout << foo << endl;
			cin  >> x >> y;
			if(x==1)
			{
				ct++;
				ans[pos]=i+'0';
				break;
			}

		}
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif
void optimise()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main()
{
	int a,x,y,ct=0;
	char s[4]={};
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<4;j++)
			s[j]='0'+i;
		cout << s << endl;
		cin >> x >>  y;
		if(x==0 && y==0)
		{
			a=i;
			break;
		}
	}
	char foo[4]={};
	char ans[4]={};
	for(int i=0;(i<10)&&(ct<4);i++)
	{
		for(int pos=0;pos<4;pos++)
		{
			for(int j=0;j<4;j++)
				foo[j]=a+'0';
			foo[pos]=i+'0';
			cout << foo << endl;
			cin  >> x >> y;
			if(x==1)
			{
				ct++;
				ans[pos]=i+'0';
				break;
			}

		}
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif
void optimise()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main()
{
	int a,x,y,ct=0;
	char s[5]={};
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<4;j++)
			s[j]='0'+i;
		cout << s << endl;
		cin >> x >>  y;
		if(x==0 && y==0)
		{
			a=i;
			break;
		}
	}
	char foo[5]={};
	char ans[5]={};
	for(int i=0;(i<10)&&(ct<4);i++)
	{
		for(int pos=0;pos<4;pos++)
		{
			for(int j=0;j<4;j++)
				foo[j]=a+'0';
			foo[pos]=i+'0';
			cout << foo << endl;
			cin  >> x >> y;
			if(x==1)
			{
				ct++;
				ans[pos]=i+'0';
				break;
			}

		}
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif
void optimise()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main()
{
	int a,x,y,ct=0;
	for(int i=0;i<10;i++)
	{
		char s[5]={};
		for(int j=0;j<4;j++)
			s[j]='0'+i;
		cout << s << endl;
		if(x==0 && y==0)
		{
			a=i;
			break;
		}
	}
	char foo[5]={};
	char ans[5]={};
	for(int i=0;(i<10)&&(ct<4);i++)
	{
		for(int pos=0;pos<4;pos++)
		{
			for(int j=0;j<4;j++)
				foo[j]=a+'0';
			foo[pos]=i+'0';
			cout << foo << endl;
			cin  >> x >> y;
			if(x==1)
			{
				ct++;
				ans[pos]=i+'0';
				break;
			}

		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

#define f1 first
#define s2 second
using namespace std;

bool used[100];
int p[100];

int f[100];

void out(string s){
    cout << s << endl;
    fflush(stdout);
}

pair <int, int> get_input(){
    int a, b;
    cin >> a >> b;
    return {a, b};
}

void get1_num(int f[100]){
    int sz = 0;
    string s;
    for (char i = '0'; i <= '9'; i++){
        if (sz == 4)
            break;
        s = i;
        s += i;
        s += i;
        s += i;
        out(s);
        pair <int, int> p = get_input();
        if (p.s2 >= 3 || p.f1 >= 1){
            f[sz] = (int(i - '0'));
            sz++;
        }
    }
}

string get_str(){
    string s;
    for (int i = 0; i < 4; i++){
        s += char(f[p[i]] + int('0'));
    }
    return s;
}

void gen(int n, int x){
    if (n == x){
        out(get_str());
        pair <int, int> f = get_input();
        if (f.f1 == 4 && f.s2 == 0){
            out(get_str());
            exit(0);
        }
    }
    else{
        for (int i = 0; i < n; i++){
            if (!used[i]){
                p[x] = i;
                used[i] = 1;
                gen(n, x + 1);
                used[i] = 0;
            }
        }
    }
}

int main()
{
    string s;
    get1_num(f);
    gen(4, 0);
    return 0;
}


#include <bits/stdc++.h>

#define f1 first
#define s2 second
using namespace std;

bool used[100];
int p[100];

int f[100];

void out(string s){
    cout << s << "\n";
    fflush(stdout);
}

pair <int, int> get_input(){
    int a, b;
    cin >> a >> b;
    return {a, b};
}

void get1_num(int f[100]){
    int sz = 0;
    string s;
    for (char i = '0'; i <= '9'; i++){
        if (sz == 4)
            break;
        s = i;
        s += i;
        s += i;
        s += i;
        out(s);
        pair <int, int> p = get_input();
        if (p.s2 > 0){
            f[sz] = (int(i - '0'));
            sz++;
        }
    }
}

string get_str(){
    string s;
    for (int i = 0; i < 4; i++){
        s += char(f[p[i]] + int('0'));
    }
    return s;
}

void gen(int n, int x){
    if (n == x){
        out(get_str());
        pair <int, int> f = get_input();
        if (f.f1 == 4 && f.s2 == 0){
            exit(0);
        }
    }
    else{
        for (int i = 0; i < n; i++){
            if (!used[i]){
                p[x] = i;
                used[i] = 1;
                gen(n, x + 1);
                used[i] = 0;
            }
        }
    }
}

int main()
{
    string s;
    get1_num(f);
    gen(4, 0);
    return 0;
}


#include <bits/stdc++.h>

#define f1 first
#define s2 second
using namespace std;

bool used[100];
int p[100];

int f[100];

void out(string s){
    cout << s << endl;
    fflush(stdout);
}

pair <int, int> get_input(){
    int a, b;
    cin >> a >> b;
    return {a, b};
}

void get1_num(int f[100]){
    int sz = 0;
    string s;
    for (char i = '0'; i <= '9'; i++){
        if (sz == 4)
            break;
        s = i;
        s += i;
        s += i;
        s += i;
        out(s);
        pair <int, int> p = get_input();
        if (p.s2 > 0){
            f[sz] = (int(i - '0'));
            sz++;
        }
    }
}

string get_str(){
    string s;
    for (int i = 0; i < 4; i++){
        s += char(f[p[i]] + int('0'));
    }
    return s;
}

void gen(int n, int x){
    if (n == x){
        out(get_str());
        pair <int, int> f = get_input();
        if (f.f1 == 4 && f.s2 == 0){
            out(get_str());
            exit(0);
        }
    }
    else{
        for (int i = 0; i < n; i++){
            if (!used[i]){
                p[x] = i;
                used[i] = 1;
                gen(n, x + 1);
                used[i] = 0;
            }
        }
    }
}

int main()
{
    string s;
    get1_num(f);
    gen(4, 0);
    return 0;
}


#include <bits/stdc++.h>

#define f1 first
#define s2 second
using namespace std;

bool used[100];
int p[100];

vector <int> f;

void out(string s){
    cout << s << "\n";
    fflush(stdout);
}

pair <int, int> get_input(){
    int a, b;
    cin >> a >> b;
    return {a, b};
}

vector <int> get_num(){
    vector <int> v;
    string s;
    for (char i = '0'; i <= '9'; i++){
        if (v.size() == 4)
            break;
        s = i;
        s += i;
        s += i;
        s += i;
        out(s);
        pair <int, int> p = get_input();
        if (p.s2 > 0){
            v.push_back(int(i - '0'));
        }
    }
    return v;
}

string get_str(int p[100]){
    string s;
    for (int i = 0; i < 4; i++){
        s += char(f[p[i]] + int('0'));
    }
    return s;
}

void gen(int n, int x){
    if (n == x){
        out(get_str(p));
        pair <int, int> f = get_input();
        if (f.f1 == 4 & f.s2 == 0){
            exit(0);
        }
    }
    else{
        for (int i = 0; i < n; i++){
            if (!used[i]){
                p[x] = i;
                used[x] = 1;
                gen(n, x + 1);
                used[x] = 0;
            }
        }
    }
}

int main()
{
    string s;
    f = get_num();
    gen(4, 0);
    return 0;
}


#include <bits/stdc++.h>

#define f1 first
#define s2 second
using namespace std;

bool used[100];
int p[100];

vector <int> f;

void out(string s){
    cout << s << "\n";
    fflush(stdout);
}

pair <int, int> get_input(){
    int a, b;
    cin >> a >> b;
    return {a, b};
}

vector <int> get_num(){
    vector <int> v;
    string s;
    for (char i = '0'; i <= '9'; i++){
        if (v.size() == 4)
            break;
        s = i;
        s += i;
        s += i;
        s += i;
        out(s);
        pair <int, int> p = get_input();
        if (p.s2 > 0){
            v.push_back(int(i - '0'));
        }
    }
    return v;
}

string get_str(int p[100]){
    string s;
    for (int i = 0; i < 4; i++){
        s += char(f[p[i]] + int('0'));
    }
    return s;
}

void gen(int n, int x){
    if (n == x){
        out(get_str(p));
        pair <int, int> f = get_input();
        if (f.f1 == 4 & f.s2 == 0){
            exit(0);
        }
    }
    else{
        for (int i = 0; i < n; i++){
            if (!used[i]){
                p[x] = i;
                used[i] = 1;
                gen(n, x + 1);
                used[i] = 0;
            }
        }
    }
}

int main()
{
    string s;
    f = get_num();
    gen(4, 0);
    return 0;
}


#include <bits/stdc++.h>

#define f1 first
#define s2 second
using namespace std;

bool used[100];
int p[100];

vector <int> f;

void out(string s){
    cout << s << "\n";
    fflush(stdout);
}

pair <int, int> get_input(){
    int a, b;
    cin >> a >> b;
    return {a, b};
}

vector <int> get_num(){
    vector <int> v;
    string s;
    for (char i = '0'; i <= '9'; i++){
        if (v.size() == 4)
            break;
        s = i;
        s += i;
        s += i;
        s += i;
        out(s);
        pair <int, int> p = get_input();
        if (p.s2 > 0){
            v.push_back(int(i - '0'));
        }
    }
    return v;
}

string get_str(int p[100]){
    string s;
    for (int i = 0; i < 4; i++){
        s += char(f[p[i]] + int('0'));
    }
    return s;
}

void gen(int n, int x){
    if (n == x){
        out(get_str(p));
        pair <int, int> f = get_input();
        if (f.f1 == 4 && f.s2 == 0){
            exit(0);
        }
    }
    else{
        for (int i = 0; i < n; i++){
            if (!used[i]){
                p[x] = i;
                used[i] = 1;
                gen(n, x + 1);
                used[i] = 0;
            }
        }
    }
}

int main()
{
    string s;
    f = get_num();
    gen(4, 0);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef int ll;
#define mx 100004
#define ff fflush(stdout);

void swap(int *a,int* b){
	int tmp=*a;
	*a=*b;
	*b=tmp;
}

void permute(vector<int> v,int l,int r){
	int i;
	for(i=l+1;i<=r;i++){
		swap(&v[l],&v[i]);
		permute(v,i,r);
		swap(&v[l],&v[i]);
	}
	for(i=0;i<=3;i++)printf("%d",v[i]);
	printf("\n");ff;
	int b,c;
	scanf("%d %d",&b,&c);
	ff;
	if(b==4 && c==0)return;
}

int main(){
	ll b[20],c[20];
	ff;
	ll i;
	vector<int>v;
	for(i=0;i<10;i++){
		printf("%d%d%d%d\n",i,i,i,i);
		ff;
		scanf("%d%d",&b[i],&c[i]);
		ff;
		if(b[i])v.push_back(i);
		if(b[i]==4 && c[i]==0)return 0;
	}
	permute(v,0,v.size()-1);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef int ll;
#define mx 100004
#define ff fflush(stdout);

void swap(int *a,int* b){
	int tmp=*a;
	*a=*b;
	*b=tmp;
}

void permute(vector<int>a, int l, int r)
{
   int i;
   if (l == r){
   		for(i=0;i<=3;i++)printf("%d",a[i]);
   		printf("\n");
   }
   else
   {
       for (i = l; i <= r; i++)
       {
          swap(&a[l],&a[i]);
          permute(a, l+1, r);
         swap(&a[l],&a[i]);
       }
   }
}

int main(){
	ll b[20],c[20];
	ff;
	ll i;
	vector<int>v;
	for(i=0;i<10;i++){
		printf("%d%d%d%d\n",i,i,i,i);
		ff;
		scanf("%d%d",&b[i],&c[i]);
		ff;
		if(b[i])v.push_back(i);
		if(b[i]==4 && c[i]==0)return 0;
	}
	permute(v,0,v.size()-1);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef int ll;
#define mx 100004
#define ff fflush(stdout);

void swap(int *a,int* b){
	int tmp=*a;
	*a=*b;
	*b=tmp;
}

void permute(vector<int> v,int l,int r){
	int i;
	for(i=l+1;i<=r;i++){
		swap(&v[l],&v[i]);
		permute(v,i,r);
		swap(&v[l],&v[i]);
	}
	for(i=0;i<=3;i++)printf("%d",v[i]);
	printf("\n");ff;
	int b,c;
	scanf("%d %d",&b,&c);
	ff;
	if(b==4 && c==0)return;
}

int main(){
	ll b[20],c[20];
	ff;
	ll i;
	vector<int>v;
	for(i=0;i<10;i++){
		printf("%d%d%d%d",i,i,i,i);
		ff;
		scanf("%d%d",&b[i],&c[i]);
		ff;
		if(b[i])v.push_back(i);
		if(b[i]==4 && c[i]==0)return 0;
	}
	permute(v,0,v.size()-1);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef int ll;
#define mx 100004
#define ff fflush(stdout);

void swap(int *a,int* b){
	int tmp=*a;
	*a=*b;
	*b=tmp;
}

void permute(vector<int> v,int l,int r){
	int i;
	for(i=l+1;i<=r;i++){
		swap(&v[l],&v[i]);
		permute(v,i,r);
		swap(&v[l],&v[i]);
	}
	for(i=0;i<=3;i++)printf("%d",v[i]);
	printf("\n");ff;
	int b,c;
	scanf("%d %d",&b,&c);
	if(b==4 && c==0)return;
}

int main(){
	ll b[20],c[20];
	ff;
	ll i;
	vector<int>v;
	for(i=0;i<10;i++){
		printf("%d%d%d%d",i,i,i,i);
		ff;
		scanf("%d%d",&b[i],&c[i]);
		if(b[i])v.push_back(i);
		if(b[i]==4 && c[i]==0)return 0;
	}
	permute(v,0,v.size()-1);
	return 0;
}


#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

Vi V;
int x,y;

int main(){
	For(i,0,10){
		printf("%d%d%d%d\n",i,i,i,i);
		fflush(stdout);
		x=IN(),y=IN();
		if (x) V.pb(i);
	}
	do{
		For(i,0,V.size()) printf("%d",V[i]);
		puts("");
		fflush(stdout);
		x=IN(),y=IN();
		if (x==4) return 0;
	} while (next_permutation(V.begin(),V.end()));
}


#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

Vi V;
int x,y;

int main(){
	For(i,0,10){
		printf("%d%d%d%d\n",i,i,i,i);
		fflush(stdout);
		x=IN(),y=IN();
		if (y) V.pb(i);
	}
	do{
		For(i,0,V.size()) printf("%d\n",V[i]);
		fflush(stdout);
		x=IN(),y=IN();
		if (x==4) return 0;
	} while (next_permutation(V.begin(),V.end()));
}


#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

Vi V;
int x,y;

int main(){
	For(i,0,10){
		printf("%d%d%d%d\n",i,i,i,i);
		fflush(stdout);
		x=IN(),y=IN();
		if (y) V.pb(i);
	}
	do{
		For(i,0,V.size()) printf("%d",V[i]);
		puts("");
		fflush(stdout);
		x=IN(),y=IN();
		if (x==4) return 0;
	} while (next_permutation(V.begin(),V.end()));
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    string ans = "";
    for (int i = 0; i <= 9; i++) {
        string s = "";
        for (int j = 0; j < 4; j++) s += to_string(i);
        cout << s << endl;
        int b, c;
        cin >> b >> c;
        if (b == 1 && c == 3) ans += to_string(i);
    }
    sort(ans.begin(), ans.end());
    do{
        cout << ans << endl;
        int b, c;
        cin >> b >> c;
        if (b == 4 && c == 0) break;
    }while(next_permutation(ans.begin(), ans.end()));
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    string ans = "";
    for (int i = 0; i <= 9; i++) {
        string s = "";
        for (int j = 0; j < 4; j++) s += to_string(i);
        cout << s << endl;
        int b, c;
        cin >> b >> c;
        if (b == 1 && c == 0) ans += to_string(i);
    }
    sort(ans.begin(), ans.end());
    do{
        cout << ans << endl;
        int b, c;
        cin >> b >> c;
        if (b == 4 && c == 0) break;
    }while(next_permutation(ans.begin(), ans.end()));
}


#include <bits/stdc++.h>
using namespace std;
array<int, 1005> us;
int main() {
    string ans = "";
    for (int i = 0; i <= 9; i++) {
        string s = "";
        for (int j = 0; j < 4; j++) s += to_string(i);
        cout << s << endl;
        int b, c;
        cin >> b >> c;
        if (b == 1 && c == 3) ans += to_string(i);
    }
    sort(ans.begin(), ans.end());
    do{
        cout << ans << endl;
        int b, c;
        cin >> b >> c;
        if (b == 4 && c == 0) break;
    }while(next_permutation(ans.begin(), ans.end()));
}


/*
ID: y1197771
PROG: test
LANG: C++
*/
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + 10;
int a[15];
void solve() {
    int x, y;
    string res = "";
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 4; j++) {
            cout << i;
        }
        cout << '\n';
        fflush(stdout);
        cin >> x >> y;
        a[i] = x + y;
        if(a[i] == 0) {
            res.append(1, '0' + i);
        }
    }
    sort(res.begin(), res.end());
    do {
        cout << res << "\n";
        fflush(stdout);
        cin >> x >> y;
        if(x == 4 && y == 0) break;
    } while(next_permutation(res.begin(), res.end()));
}
int main() {
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    //ios::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


/*
ID: y1197771
PROG: test
LANG: C++
*/
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + 10;
int a[15];
void solve() {
    int x, y;
    string res = "";
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 4; j++) {
            cout << i;
        }
        cout << '\n';
        fflush(stdout);
        cin >> x >> y;
        a[i] = x + y;
        if(x + y > 0) {
            res.append(1, '0' + i);
        }
    }
    sort(res.begin(), res.end());
    do {
        cout << res << "\n";
        fflush(stdout);
        cin >> x >> y;
        if(x == 4 && y == 0) break;
    } while(next_permutation(res.begin(), res.end()));
}
int main() {
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    //ios::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


/*
ID: y1197771
PROG: test
LANG: C++
*/
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + 10;
int a[15];
void solve() {
    int x, y;
    string res = "";
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 4; j++) {
            cout << i;
        }
        cout << '\n';
        fflush(stdout);
        cin >> x >> y;
        a[i] = x + y;
        if(a[i] == 0) {
            res.append(1, '0' + i);
        }
    }
    sort(res.begin(), res.end());
    do {
        cout << res << "\n";
        fflush(stdout);
        cin >> x >> y;
        if(x == 4 && y == 0) break;
    } while(next_permutation(res.begin(), res.end()));
}
int main() {
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


#include<cstdio>
using namespace std;
int main()
{
	char st[5]="0000";
	char ans[5]="0000";
	int mx,u,v;
	for (int i=0;i<4;i++)
	{
		mx=0;
		for (int j=0;j<9;j++)
		{
			printf("%s\n",st);
			fflush(stdout);
			scanf("%d%d",&u,&v);
			if (u>mx)
				ans[i]=st[i],mx=u;
			st[i]++;
		}
	}
	printf("%s\n",ans);
	fflush(stdout);
	return 0;
}


#include<cstdio>
using namespace std;
int main()
{
	char st[5]="0000";
	char ans[5]="0000";
	int mx,u,v;
	for (int i=0;i<4;i++)
	{
		mx=0;
		for (int j=0;j<=9;j++)
		{
			st[i]=j+'0';
			printf("%s\n",st);
			fflush(stdout);
			scanf("%d%d",&u,&v);
			if (u>mx)
				ans[i]=st[i],mx=u;
		}
	}
	printf("%s\n",ans);
	fflush(stdout);
	return 0;
}


#include<cstdio>
using namespace std;
int main()
{
	char st[5]="0000";
	char ans[5]="0000";
	int mx,u,v;
	for (int i=0;i<4;i++)
	{
		mx=0;
		for (int j=0;j<9;j++)
		{
			printf("%s",st);
			fflush(stdout);
			scanf("%d%d",&u,&v);
			if (u>mx)
				ans[i]=st[i],mx=u;
			st[i]++;
		}
	}
	printf("%s",ans);
	fflush(stdout);
	return 0;
}