Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

const INF = 0x7FFFFFFF

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		n, _ := strconv.Atoi(buf[0])
		m, _ := strconv.Atoi(buf[1])
		if n == 0 && m == 0 {
			break
		}
		chair := make([]string, n+1)
		for i := range chair {
			chair[i] = "#"
		}
		chair[n] = "Sentinel"
		for i := 0; i < m; i++ {
			scanner.Scan()
			switch who := scanner.Text(); who {
			case "A": // 左から眺めて行って空いている席があったら即座に座る
				for j := 0; j < n; j++ {
					if chair[j] == "#" {
						chair[j] = "A"
						break
					}
				}
				// log.Println(chair)
				break // 次の人を読み込む
			case "B":
				flag := true
				// 右端からAの隣でない席を探していく
				for j := n-1; j > -1; j-- {
					if chair[j] == "#" && (j == 0 || chair[j-1] != "A") && chair[j+1] != "A" {
						flag = false
						chair[j] = "B"
						break
					}
				}
				// Aの隣しか空いていないので一番左端の空いている席に座る
				if flag {
					for j := 0; j < n; j++ {
						if chair[j] == "#" {
							chair[j] = "B"
							break
						}
					}
				}
				// log.Println(chair)
				break // 次の人を読み込む
			case "C":
				if i == 0 {
					chair[n/2] = "C" // 先客が誰もいないときは真ん中の椅子に座る
				} else {
					for j := 0; j < n; j++ { // 左から舐めて
						if chair[j] != "#" { // その席が空いていなくて
							if chair[j+1] == "#" { // 右隣が空いているなら座る
								chair[j+1] = "C"
								break
							} else if j != 0 && chair[j-1] == "#" { // 右隣が空いていないので左隣に座る
								chair[j-1] = "C"
								break
							}
						}
					}
				}
				// log.Println(chair)
				break // 次の人を読み込む
			case "D":
				distanceTable := make([]int ,n)
				for j := range distanceTable {
					distanceTable[j] = INF
				}
				for j:= 0; j < n; j++ {
					if chair[j] != "#" {
						for k := 0; k < n; k++ {
							distanceTable[k] = min(distanceTable[k], abs(j-k))
						}
					}
				}
				// log.Println("distanceTAble:", distanceTable)
				at := 0
				distance := 0
				for j := 0; j < n; j++ {
					if distance < distanceTable[j] {
						at = j
						distance = distanceTable[j]
					}
				}
				chair[at] = "D"
				// log.Println(chair)
				break // 次の人を読み込む
			}
		}
		fmt.Println(strings.Join(chair, ""))
	}
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int n, m;
int seet[100];

int main() {
	
	while (cin >> n >> m, n || m) {
		memset(seet, -1, sizeof(seet));
		REP(t, m) {
			char c; scanf(" %c", &c);
			
			bool ok = false;
			
			switch (c) {
				case 'A':
					REP(i, n) if (seet[i] == -1) {
						seet[i] = 0;
						break;
					}
				break;
					
				case 'B':
					for (int i = n - 1; i > 0; i--) if (seet[i] == -1) {
						if (seet[i - 1] == 0) i -= 2;
						else {
							seet[i] = 1;
							ok = true;
							break;
						}
					}
					if (ok) break;
					
					REP(i, n) if (seet[i] == -1) {
						seet[i] = 1;
						break;
					}
				break;
					
				case 'C':
					REP(i, n) if (seet[i] != -1) {
						if (i < n - 1 && seet[i + 1] == -1) {
							seet[i + 1] = 2;
							ok = true;
							break;
						}
						if (i > 0 && seet[i - 1] == -1) {
							seet[i - 1] = 2;
							ok = true;
							break;
						}
					}
					if (ok) break;
					seet[n / 2] = 2;
				break;
				
				case 'D':
					pii ma(-1, 0); // ?????¢, ??????
					
					int l = -1, r = 0;
					
					REP(i, n) {
						if (seet[i] == -1) {
							chmax(r, i + 1);
							while (r < n && seet[r] == -1) r++;
							
							int ls = l == -1 ? INF : i - l;
							int rs = r == n ? INF : r - i;
							
							chmax(ma, pii(min(ls, rs), -i));
						}
						else {
							l = i;
						}
					}
					
					if (ma.fi == INF) seet[0] = 3;
					else seet[-ma.se] = 3;
					
				break;
			}
			
		}
		REP(i, n) printf("%c", seet[i] == -1 ? '#' : seet[i] + 'A');
		puts("");
	}
	return 0;
}

C++: #include <iostream>
#include <set>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <stdio.h>
using namespace std;
typedef pair<int,int> P;
int chair[110];
int n,m;
void A(){
	int ans=0;
	while(chair[ans]!=0)ans++;
	chair[ans]=1;
	return;
}
void B(){
	for(int i=n-1;i>=0;i--){
		if(chair[i]==0){
			if(i==0&&chair[1]!=1){chair[0]=2;return;}
			else if(i==n-1&&chair[n-2]!=1){chair[n-1]=2;return;}
			else if(0<i&&i<n-1&&chair[i-1]!=1&&chair[i+1]!=1){chair[i]=2;return;}
		}
	}
	int ans=0;
	while(chair[ans]!=0)ans++;
	chair[ans]=2;
	return;
}
void C(){
	int ans=0;
	if(chair[0]!=0){
		while(chair[ans]!=0)ans++;
		chair[ans]=3;
		return;
	}
	for(int i=0;i<n;i++){
		if(chair[i]!=0){
			if(chair[i+1]==0)chair[i+1]=3;
			else chair[i-1]=3;
			return;
		}
	}
	if(n%2)chair[(n+1)/2-1]=3;
	else chair[n/2]=3;
	return;
}
void D(){
	int a=0,f=0;
	P bl[52];
	bool in=false;
	for(int i=0;i<=n;i++){
		if(in&&chair[i]!=0){
			in=false;bl[a++]=P(f,i);
		}else if(!in&&chair[i]==0){
			in=true;f=i;
		}
	}
	if(bl[0].first==0&&bl[0].second==n){
		chair[0]=4;return;
	}else{
		int mi,mlen=-1;
		for(int i=0;i<a;i++){
			int dis=(bl[i].second-bl[i].first-1)/2;
			if(bl[i].second==n)dis=bl[i].second-bl[i].first-1;
			if(dis>mlen){mlen=dis;mi=i;}
		}
		chair[bl[mi].first+mlen]=4;return;
	}
}
int main()
{
	while(cin>>n>>m&&(n||m)){
		fill(chair,chair+n,0);
		chair[n]=5;
		while(m--){
			char c;cin>>c;
			if(c=='A')A();
			if(c=='B')B();
			if(c=='C')C();
			if(c=='D')D();
		}
		for(int i=0;i<n;i++){
			if(chair[i]==0)cout<<'#';
			if(chair[i]==1)cout<<'A';
			if(chair[i]==2)cout<<'B';
			if(chair[i]==3)cout<<'C';
			if(chair[i]==4)cout<<'D';
		}
		cout<<endl;
	}
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n){
    string s;
    for(int i=0;i<n;i++)s+='#';
    while(m--){
      string p;
      cin>>p;
      if(p=="A"){
        for(int i=0;i<n;i++)
          if(s[i]=='#'){
            s[i]='A';
            break;
          }
      }
      if(p=="B"){
        int pp=0;
        for(int i=n-1;i>0;i--)
          if(s[i-1]!='A'&&s[i]=='#'){pp++,s[i]='B';break;}
        if(!pp)for(int i=0;i<n;i++)
             if(s[i]=='#'){
               s[i]='B';
               break;
            }
      }
      if(p=="C"){
        int pp=0;
        for(int i=0;i<n;i++)
          if(s[i]!='#'){
            if(i){if(s[i-1]=='#'){s[i-1]='C';pp++;break;}}
            if(i!=n-1){if(s[i+1]=='#'){s[i+1]='C';pp++;break;}}
          }
        if(!pp){
          if(n%2)s[(n+1)/2-1]='C';
          else s[n/2-1]='C';
        }
      }
      else if(p=="D"){
        int d[n]={},p=0,sp=0;
        for(int i=0;i<n;i++){
          int p1=0,p2=0;
          for(int j=i;j<n;j++)
            if(s[j]=='#')p1++;
            else break;
          for(int j=i;j>=0;j--)
            if(s[j]=='#')p2++;
            else break;
            sp=max(max(p1,p2),sp);
          p1=min(p1,p2);
          p=max(p,p1);
          d[i]=p1;
        }
        if(sp==n)s[0]='D';
        else for(int i=0;i<n;i++)
          if(d[i]==p){
            s[i]='D';
            break;
          }
      }

    }
    cout<<s<<endl;
  }
}