Nadal beats Medvedev in epic US Open final