/* P43
#include <iostream>
#include <stdio.h>
using namespace std;
int N = 6;
char S[6] = {'A','C','D','B','C','B'};
void solve(){
int a = 0,b = N-1;
while(a<=b){
bool left = false;
for (int i = 0; i+a <= b; i++)
{
if (S[a+i] < S[b])
{
left = true;
break;
}
else if (S[a+i] > S[b])
{
left = false;
break;
}
}
if (left)
{
putchar(S[a++]);
}
else{
putchar(S[b--]);
}
}printf("\n");
}
int main()
{
solve();
cout << "Hello world!" << endl;
return 0;
}
/* P74
#include <queue>
#include <cstdio>
using namespace std;
int main(){
priority_queue <int> pque;
pque.push(3);
pque.push(6);
pque.push(5);
while(!pque.empty()){
printf("%d ",pque.top());
pque.pop();
}
return 0;
}
*/
/*
#include <stdio.h>
#include <queue>
using namespace std;
int main(){
int N,L,P;
scanf("%d",&N);
int A[N+1];
int B[N+1];
for(int i=0;i<N;i++)
{
scanf("%d%d",&A[i],&B[i]);
}
scanf("%d%d",&L,&P);
A[N] = L;
B[N] = 0;
priority_queue<int> que;
int ans = 0, pos = 0, tank = P;
for(int i = 0; i < N; i++)
{
int d = A[i] - pos;
while(tank < d){
if(que.empty()){
puts("-1");
return 0;
}
tank += que.top();
que.pop();
ans++;
}
tank -= d;
pos = A[i];
que.push(B[i]);
}
printf("%d\n",ans);
return 0;}
*/
//p51
/*
#include <stdio.h>
#include <algorithm>
using namespace std;
int n = 4,W = 5;
int w[] = {2,1,3,2};
int v[] = {3,2,4,2};
int rec(int i, int j)
{
int res;
if(i == n)
{
res = 0;
}
else if(j < w[i])
{
res = rec(i+1,j);
}
else
{
res = max( rec(i+1,j), rec(i+1,j-w[i])+v[i] );
}
return res;
}
int main(){
return printf("%d",rec(0,W));
}