"""
A script for couple seatings
"""
import random
import sys

def usage():
    print("%s cols rows" % __file__)


def has_adjacent_seat(row):
    return any(
        a == 0 and b == 0
        for a, b in zip(row, row[1:])
    )


def get_adjacent_seat(seats, cols, free_rows):
    while free_rows:
        y = random.choice(free_rows)
        x = random.randrange(cols - 1)
        if seats[y][x] == 0 and seats[y][x + 1] == 0:
            return (y, x)
    else:
        return (None, None)


def main(cols, rows):
    seats = [[0]* cols for _ in range(rows)]
    free_rows = list(range(rows))
    while True:
        (y, x) = get_adjacent_seat(seats, cols, free_rows)

        if y is None or x is None:
            break
        seats[y][x] = 1
        seats[y][x + 1] = 1

        if not has_adjacent_seat(seats[y]):
            # remove the row from free_rows
            free_rows.remove(y)

    # count the number of empty seats
    occupied = sum(sum(row) for row in seats)
    print("vacancy rate = %.5f" % (1 - occupied /(cols * rows)))

if __name__ == "__main__":
    if len(sys.argv) != 3:
        usage()
        sys.exit(-1)

    sys.exit(main(int(sys.argv[1]), int(sys.argv[2])))
