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
}

Python: INF = 10**10
while(True):
    N, M = [int(n) for n in input().split()]
    if N + M == 0:
        break
    chair = ["#" for _ in range(N)]
    for i in range(M):
        a = str(input())
        if a == "A":
            for i in range(N):
                if chair[i] == "#":
                    chair[i] = "A"
                    break
        elif a == "B":
            OK = False
            for i in range(N-1, -1, -1):
                if chair[i] == "#":
                    if i != 0 and chair[i-1] == "A":
                        continue
                    if i != N-1 and chair[i+1] == "A":
                        continue
                    chair[i] = "B"
                    OK = True
                    break
            if OK:
                continue
            for i in range(N):
                if chair[i] == "#":
                    chair[i] = "B"
                    break
        elif a == "C":
            if chair.count("#") == N:
                chair[(N)//2] = "C"
                continue
            OK = False
            for i in range(N):
                if chair[i] != "#":
                    if i != N-1 and chair[i+1] == "#":
                        chair[i+1] = "C"
                        OK = True
                        break
                    if i != 0 and chair[i-1] == "#":
                        chair[i-1] = "C"
                        OK = True
                        break
        elif a == "D":
            if chair.count("#") == N:
                chair[0] = "D"
                continue
            start = False
            distmap = [0 for _ in range(N)]
            dist = 0
            for i in range(N):
                if chair[i] != "#":
                    dist = 0
                    distmap[i] = dist
                    start = True
                elif start:
                    dist += 1
                    distmap[i] = dist
                else:
                    distmap[i] = INF
            start = False
            for i in range(N-1, -1, -1):
                if chair[i] != "#":
                    dist = 0
                    distmap[i] = min(dist, distmap[i])
                    start = True
                elif start:
                    dist += 1
                    distmap[i] = min(dist, distmap[i])
            target = max(distmap)
            for i in range(N):
                if distmap[i] == target and chair[i] == "#":
                    chair[i] = "D"
                    break
    print("".join(chair))

Python: INF = 10 ** 20

while True:
  n, m = map(int, input().split())
  if not n:
    break

  chairs = list("#" * n)

  def sit(s):
    if s == "A":
      chairs[chairs.index("#")] = "A"
    
    elif s == "B":
      for i in range(n - 1, -1, -1):
        if chairs[i] == "#" and (i == 0 or chairs[i - 1] != "A") and (i == n - 1 or chairs[i + 1] != "A"):
          chairs[i] = "B"
          break
      else:
        chairs[chairs.index("#")] = "B"

    elif s == "C":
      for i in range(0, n):
        if chairs[i] != "#":
          if i - 1  >= 0 and chairs[i - 1] == "#":
            chairs[i - 1] = "C"
            break
          elif i + 1 <= n - 1 and chairs[i + 1] == "#":
            chairs[i + 1] = "C"
            break

    else:
      score = [INF for _ in range(n)]
      dist = INF
      for i in range(n):
        if chairs[i] == "#":
          dist += 1
        else:
          dist = 0
        score[i] = dist

      dist = INF
      for i in range(n - 1, -1, -1):
        if chairs[i] == "#":
          dist += 1
        else:
          dist = 0
        score[i] = min(score[i], dist)
      high_score = max(score)
      chairs[score.index(high_score)] = "D"
  
  first = input()
  if first in ["A", "D"]:
    chairs[0] = first
  elif first == "B":
    chairs[-1] = "B"
  else:
    chairs[n // 2] = "C"
  for _ in range(m - 1):
    sit(input())

  print("".join(chairs))

Python: INF = 10 ** 20

while True:
  n, m = map(int, input().split())
  if not n:
    break

  chairs = list("#" * n)

  def sit(s):
    if s == "A":
      chairs[chairs.index("#")] = "A"
    
    elif s == "B":
      for i in range(n - 1, -1, -1):
        if chairs[i] == "#" and (i == 0 or chairs[i - 1] != "A") and (i == n - 1 or chairs[i + 1] != "A"):
          chairs[i] = "B"
          break
      else:
        chairs[chairs.index("#")] = "B"

    elif s == "C":
      for i in range(n):
        if chairs[i] != "#":
          if i + 1 <= n - 1 and chairs[i + 1] == "#":
            chairs[i + 1] = "C"
            break
 
          elif i - 1  >= 0 and chairs[i - 1] == "#":
            chairs[i - 1] = "C"
            break

    else:
      score = [INF for _ in range(n)]
      dist = INF
      for i in range(n):
        if chairs[i] == "#":
          dist += 1
        else:
          dist = 0
        score[i] = dist

      dist = INF
      for i in range(n - 1, -1, -1):
        if chairs[i] == "#":
          dist += 1
        else:
          dist = 0
        score[i] = min(score[i], dist)
      high_score = max(score)

      chairs[score.index(high_score)] = "D"
  
  first = input()
  if first in ["A", "D"]:
    chairs[0] = first
  elif first == "B":
    chairs[-1] = "B"
  else:
    chairs[n // 2] = "C"
  
  for _ in range(m - 1):
    sit(input())
  print("".join(chairs))