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
		}
		chairs := make([]string, n)
		for i := range chairs {
			chairs[i] = "#"
		}
		sit := func(who string) {
			if who == "A" {
				chairs[getStringIndex(chairs, "#")] = "A" // A国の人は左から見て行って空いている席を見つけ次第座る
				// log.Println(chairs)
			} else if who == "B" {
				f := true
				for i := n-1; i > -1; i-- {
					// B国の人はA国人の隣以外で、右端から空いている椅子に座る
					if chairs[i] == "#" && (i == 0 || chairs[i-1] != "A") && (i == n-1 || chairs[i+1] != "A") {
								chairs[i] = "B"
								f = false
								break
					}
				}
				// A国人の隣しか空いていない場合、我慢して左端から空いている椅子に座る
				if f {
					chairs[getStringIndex(chairs, "#")] = "B"
				}
				// log.Println(chairs)
			} else if who == "C" { // C国人は人の隣に座りたい
				for i := 0; i < n; i++ {
					if chairs[i] != "#" {
						if i + 1 <= n-1 && chairs[i+1] == "#" {
							chairs[i+1] = "C"
							break
						} else if i - 1 >= 0 && chairs[i-1] == "#" {
							chairs[i-1] = "C"
							break
						}
					}
				}
				// log.Println(chairs)
			} else { // who == "D"
				// D国の人は人から離れて座りたい
				// どうしても誰かの隣に座らなければならない場合、その中で一番左側にある椅子に座る
				scores := make([]int, n)
				for i := range scores {
					scores[i] = INF
				}
				for i, v := range chairs {
					if v == "#" {
						scores[i]++
					}
				}
				for i := n-1; i > -1; i-- {
					tmp := 0
					if chairs[i] == "#" {
						tmp++
					} else {
						tmp = 0
					}
					scores[i] = min(scores[i], tmp)
				}
				chairs[getIntIndex(scores, getMax(scores))] = "D"
				// log.Println(chairs)
			}
		}
		scanner.Scan()
		if first := scanner.Text(); first == "A" || first == "D" {
			chairs[0] = first
		} else if first == "B" {
			chairs[len(chairs)-1] = "B"
		} else {
			chairs[n/2] = "C"
		}
		// log.Println(chairs)
		for i := 0; i < m-1; i++ {
			scanner.Scan()
			sit(scanner.Text())
		}
		fmt.Println(strings.Join(chairs, ""))
	}
}

func getStringIndex(chairs []string, who string) int {
	for i, v := range chairs {
		if v == who {
			return i
		}
	}
	return -1
}

func getIntIndex(scores []int, target int) int {
	for i, v := range scores {
		if v == target {
			return i
		}
	}
	return -1
}

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

func getMax(scores []int) int {
	tmp := -1
	for _, v := range scores {
		if tmp < v {
			tmp = v
		}
	}
	return tmp
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

int main(){
	int n, m;
	while(cin>> n >> m && (n || m)){
		string chair(n, '#');
		char ch;
		rep(i, m){
			cin >> ch;
			if(ch == 'A'){
				rep(j, n){
					if(chair[j] == '#'){
						chair[j] = ch;
						break;
					}
				}
			}else if(ch == 'B'){
				bool ok = false;
				rep(j, n){
					if(chair[n-j-1] == '#' && 
						(j == 0 || chair[n-j] != 'A' 
						&& j == n - 1 || chair[n-j-2] != 'A')){
						chair[n-j-1] = ch;
						ok = true;
						break;
					}
				}
				if(!ok){
					rep(j, n){
						if(chair[j] == '#'){
							chair[j] = ch;
							break;
						}
					}
				}
			}else if(ch == 'C'){
				if(i == 0){
					chair[n/2+1] = ch;
				}else{
					rep(j, n){
						if(chair[j] != '#'){
							if(chair[j+1] == '#'){
								chair[j+1] = ch;
								break;
							}else if(j > 0 && chair[j-1] == '#'){
								chair[j-1] = ch;
								break;
							}
						}
					}
				}
			}else{
				if(i == 0){
					chair[0] = ch;
				}else{
					int best = 0;
					int dis = 0;
					rep(i, n){
						if(chair[i] != '#') continue;
						int d = INF;
						rep(j, n){
							if(chair[j] != '#'){
								d = min(abs(j - i), d);
							}
						}
						if(d > dis){
							dis = d;
							best = i;
						}
					}
					chair[best] = ch;
				}
			}
		}
		cout << chair << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;

typedef pair<int, int> P;

int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		vector<char> isu(n, '#');
		char c;
		for (int i = 0; i < m; i++) {
			cin >> c;
			if (c == 'A') {
				for (int j = 0; j < n; j++) {
					if (isu[j] == '#') {
						isu[j] = 'A';
						break;
					}
				}
			} else if (c == 'B') {
				bool hantei = true;
				for (int j = n-1; j >= 0; j--) {
					if (isu[j] == '#') {
						if (j != 0 && j != n-1) {
							if (isu[j-1] != 'A' && isu[j+1] != 'A') {
								isu[j] = 'B';
								hantei = false;
								break;
							}
						} else if (j == 0) {
							if (isu[j+1] != 'A') {
								isu[j] = 'B';
								hantei = false;
								break;
							}
						} else {
							if (isu[j-1] != 'A') {
								isu[j] = 'B';
								hantei = false;
								break;
							}
						}
					}
				}
				if (hantei) {
					for (int j = 0; j < n; j++) {
						if (isu[j] =='#') {
							isu[j] = 'B';
							break;
						}
					}
				}
			} else if (c == 'C') {
				bool hantei = true;
				for (int j = 0; j < n; j++) {
					if (isu[j] != '#') {
						if (j != n-1 && isu[j+1] == '#') {
							isu[j+1] = 'C';
							hantei = false;
							break;
						} else if (j != 0 && isu[j-1] == '#') {
							isu[j-1] = 'C';
							hantei = false;
							break;
						}
					}
				}
				if (hantei) {
					isu[n/2] = 'C';
				}
			} else {
				queue<P> q;
				for (int j = 0; j < n; j++) {
					if (isu[j] == '#') {
						int counter = 1000;
						int counter2 = 1000;
						int d;
						for (int k = j-1; k >= 0; k--) {
							if (isu[k] != '#') {
								counter = j-k;
								break;
							}
						}
						for (int k = j+1; k < n; k++) {
							if (isu[k] != '#') {
								counter2 = k-j;
								break;
							}
						}
						d = min(counter, counter2);
						if (d == 1000) {
							break;
						}
						if (q.empty()) {
							P p;
							p.first = d;
							p.second = j;
							q.push(p);
						} else if ((q.front()).first < d) {
							while (!q.empty()) {
								q.pop();
							}
							P p;
							p.first = d;
							p.second = j;
							q.push(p);
						} else if ((q.front()).first == d) {
							P p;
							p.first = d;
							p.second = j;
							q.push(p);
						}
					}
				}
				if (q.empty()) {
					for (int j = 0; j < n; j++) {
						if (isu[j] == '#') {
							isu[j] = 'D';
							break;
						}
					}
				} else {
					P p = q.front();
					q.pop();
					isu[p.second] = 'D';
				}
			}
		}
		for (int i = 0; i < n; i++) {
			cout << isu[i];
		}
		cout << endl;
	}
	return 0; 
}