def print_board(board):
    for row in board:
        print(' '.join(row))
    print('1 2 3 4 5 6 7')  # column numbers for reference
    print()


def get_move(player, board):
    while True:
        try:
            col = int(input(f"Player {player} (R/Y), choose column (1-7): ")) - 1
            if not 0 <= col < 7:
                print("Column must be between 1 and 7.")
                continue
            if board[0][col] != '.':
                print("Column is full. Choose another.")
                continue
            return col
        except ValueError:
            print("Invalid input. Enter a number 1-7.")


def apply_move(board, col, piece):
    for row in range(5, -1, -1):
        if board[row][col] == '.':
            board[row][col] = piece
            return row, col


def is_winner(board, piece):
    directions = [(1, 0), (0, 1), (1, 1), (1, -1)]
    for r in range(6):
        for c in range(7):
            if board[r][c] != piece:
                continue
            for dr, dc in directions:
                cnt = 0
                rr, cc = r, c
                while 0 <= rr < 6 and 0 <= cc < 7 and board[rr][cc] == piece:
                    cnt += 1
                    if cnt == 4:
                        return True
                    rr += dr
                    cc += dc
    return False


def is_draw(board):
    return all(cell != '.' for cell in board[0])


def main():
    board = [['.' for _ in range(7)] for _ in range(6)]
    players = [('R', 'R'), ('Y', 'Y')]
    turn = 0

    while True:
        print_board(board)
        piece, name = players[turn % 2]
        col = get_move(name, board)
        apply_move(board, col, piece)

        if is_winner(board, piece):
            print_board(board)
            print(f"Player {name} wins!")
            break
        if is_draw(board):
            print_board(board)
            print("It's a draw!")
            break
        turn += 1


if __name__ == "__main__":
    main()
