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

def get_move(player, board):
    while True:
        try:
            col = input(f"Player {player}'s turn. Choose column (1-7): ")
            col = int(col)
            if not 1 <= col <= 7:
                print("Invalid column. Choose a number from 1 to 7.")
                continue
            if board[0][col-1] != '.':
                print("Column is full. Choose another one.")
                continue
            return col - 1
        except ValueError:
            print("Invalid input. Enter a number from 1 to 7.")

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

def check_win(board, row, col, player):
    directions = [
        (0, 1),  # horizontal
        (1, 0),  # vertical
        (1, 1),  # diagonal down-right
        (1, -1), # diagonal down-left
    ]
    for dr, dc in directions:
        count = 1
        # Check forward direction
        r, c = row + dr, col + dc
        while 0 <= r < 6 and 0 <= c < 7 and board[r][c] == player:
            count += 1
            r += dr
            c += dc
        # Check backward direction
        r, c = row - dr, col - dc
        while 0 <= r < 6 and 0 <= c < 7 and board[r][c] == player:
            count += 1
            r -= dr
            c -= dc
        if count >= 4:
            return True
    return False

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

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

    while True:
        print_board(board)
        player = players[turn % 2]
        col = get_move(player, board)
        row, col = apply_move(board, col, player)
        if check_win(board, row, col, player):
            print_board(board)
            print(f"Player {player} wins!")
            break
        if board_full(board):
            print_board(board)
            print("It's a draw!")
            break
        turn += 1

if __name__ == "__main__":
    main()
