Problem:
Score : 200 points

Problem Statement

Kurohashi has never participated in AtCoder Beginner Contest (ABC).

The next ABC to be held is ABC N (the N-th ABC ever held).
Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same.

What is the earliest ABC where Kurohashi can make his debut?

Constraints

100 \leq N \leq 999

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If the earliest ABC where Kurohashi can make his debut is ABC n, print n.

Sample Input 1

111

Sample Output 1

111

The next ABC to be held is ABC 111, where Kurohashi can make his debut.

Sample Input 2

112

Sample Output 2

222

The next ABC to be held is ABC 112, which means Kurohashi can no longer participate in ABC 111.
Among the ABCs where Kurohashi can make his debut, the earliest one is ABC 222.

Sample Input 3

750

Sample Output 3

777

Solution in C (GCC 5.4.1) (judge verdict: Accepted)

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef long long int ll;
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define m0(x) memset(x,0,sizeof(x))

//qsort用(昇順，降順)
int cmp_asc( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}
int cmp_desc( const void *p, const void *q ) {
    return *(int*)q - *(int*)p;
}

//二分累乗法
int powa(ll a, ll n){
	ll res = 1;
	while(n>0) {
		if(n&1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1; 
	}
	return res;
}

//逆元
int inverse(ll a){
	ll n = mod-2;
	return powa(a, n);
}

//組み合わせ（nとrが500以下のとき）
int combination_low(ll n,ll r){
	const ll N = 500;
	ll C[N][N];
	memset(C, 0, sizeof(C));
	C[0][0]=1;
	for(ll n=1; n<N; n++){
		C[n][0]=C[n-1][0];
		for(ll r=1; r<N; r++){
			C[n][r] = C[n-1][r-1] + C[n-1][r];
		}
	}
	return C[n][r];
}

/*組み合わせ*/
int combination(ll n,ll r){
	ll x=1,y=1;
	for(int i=1;i<=r;i++){
		x = x * (n-i+1) % mod;
		y = y * i % mod;
	}
	return x * inverse(y) % mod;
}


int main(void){
	int n,i,c;
	scanf("%d",&n);
	for(i=1;i<10;i++){
		c=i*111;
		if(n<111) break;
		else if(n==c) break;
		else if(n>c && n<c+111){
			c+=111;
			break;
		} 
	}
	printf("%d\n",c);
	return 0;
}