def print_board(board):
    for row in board:
        print("|" + "|".join(row) + "|")
    print("+" + "+".join("-" * 7) + "+")
    print(" " + " ".join(str(i) for i in range(1, 8)))

def is_valid_move(board, col):
    return 0 <= col < 7 and board[0][col] == " "

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

def check_win(board, row, col, player):
    directions = [(0, 1), (1, 0), (1, 1), (1, -1)]
    for dr, dc in directions:
        count = 1
        for step in [1, -1]:
            r, c = row + step * dr, col + step * dc
            while 0 <= r < 6 and 0 <= c < 7 and board[r][c] == player:
                count += 1
                r += step * dr
                c += step * dc
        if count >= 4:
            return True
    return False

def is_draw(board):
    return all(cell != " " for row in board for cell in row)

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

    while True:
        print_board(board)
        col = int(input(f"Player {players[current_player]}, choose a column (1-7): ")) - 1

        if not is_valid_move(board, col):
            print("Invalid move. Try again.")
            continue

        row = apply_move(board, col, players[current_player])

        if check_win(board, row, col, players[current_player]):
            print_board(board)
            print(f"Player {players[current_player]} wins!")
            break

        if is_draw(board):
            print_board(board)
            print("It's a draw!")
            break

        current_player = 1 - current_player

if __name__ == "__main__":
    main()
