The first to leave was King George.

It was April 2016 when Jonathan Groff, who played King George in the megahit musical "Hamilton," left the show. Three months later, Lin-Manuel Miranda, who created the show, composed the music and starred as Alexander Hamilton, took his final bow. By the end of 2016, virtually the entire cast had been replaced.

With that, I thought the day might finally have arrived when one could buy "Hamilton" tickets at face value. Because of the ease with which ticket brokers have been able to use automated software to scoop up "Hamilton" tickets the millisecond they go on sale, it's been nearly impossible to buy a ticket at the box office. Instead, one had to go to the secondary market, where the brokers have been reselling tickets, at huge markups, that they had mostly bought for less than $200.

"Hamilton" also is now playing in Chicago and San Francisco, with a London version slated in November. I figured maybe that too would ease the pricing pressure since people in those cities wouldn't need to come to New York to see "Hamilton."

So I checked. If I wanted to see the show the following evening six tickets were available from Ticketmaster. The cheapest two cost $900 each, two others cost $1,000 each, and the most expensive cost $1,714.50 each. StubHub's lowest price was $600 and its highest was $3,500. SeatGeek? From $691 to … $9,444. The cast turnover wasn't exactly hurting the secondary market.

But, hey, those were last-minute tickets. What if I wanted to go six months from now? I picked a date in mid-September. There was nothing available at the box office, but plenty of tickets on the secondary market. At Ticketmaster they ranged from $400 and $1,800. SeatGeek had tickets from $360 to $2,593. StubHub didn't have tickets, but it was selling "Hamilton" parking passes for $40. (I kid you not.) In other words, prices were better, but still … .

It doesn't take a degree in economics to understand what is going on here. The Richard Rodgers Theatre, where Hamilton resides, has 1,319 seats. But the demand for tickets vastly exceeds that. The market is saying "Hamilton" tickets are worth much more than the producers are charging.

If you actually do have a degree in economics, the answer probably seems simple: "Hamilton's" producers should raise ticket prices to capture the market price. Last October, the Harvard economist N. Gregory Mankiw wrote in the New York Times that he paid $2,500 for a "Hamilton" ticket and was "happy about it." The tickets, he added, were "vastly underpriced" and his only regret about paying a four-figure sum was that the money was going to scalpers instead of the show's producers, actors and investors. "I would much rather give that money to Lin-Manuel so he can put on more shows and make the theater healthier," he told me.

"That's the classic laissez-faire right-wing economic view," sighed Jeffrey Seller, the veteran theater producer whom the Times described last year as the CEO of Hamilton Inc. In his view — indeed, in the view of virtually everyone in the theater business — sucking every last penny out of every last ticket has as much downside as upside. Seller wants people who can't afford $1,000 tickets to be able to see the show. He doesn't want the zeitgeist to turn against "Hamilton" because it is so expensive. He would really like to be in control of how much people pay.

"My job is to balance getting a great return for our investors with what we believe is our responsibility to the community," he said. (Not to worry: Even without maximizing ticket prices, "Hamilton" is making an estimated $600,000 a week in profit.)

What seemed particularly unfair, in Seller's mind, was the use of software bots, which give ticket brokers an insurmountable edge over humans trying to buy tickets. Indeed, thanks to the Hamilton-generated publicity bots have received, both the federal government and New York state passed laws last year outlawing the software for ticket buying. Miranda even wrote an op-ed urging New York to act, saying, "You shouldn't have to fight robots just to see something you love."

There is another way to rebalance supply and demand, of course — expand the supply. I've often wondered why Seller didn't solve the problem by simply renting a second Broadway theater and hiring a second cast. Alas, every theater person I spoke to thought it was a crazy idea. "I don't see why anyone would be motivated to do that," said Tom Viertel, a well-known Broadway producer. "You'd have to spend $8 million to $10 million, and you'd be competing with yourself." Seller told me that if "Hamilton" had a second cast, "the show wouldn't be as special."

Well, maybe. But if you were truly interested in allowing the largest number of people to see "Hamilton" at a reasonable price, using a second theater to double the number of seats makes more sense than trying to drive a stake through the heart of the bot industry. But it's an experiment that will clearly have to wait for another day.

Although I'm generally a fan of the free market, I'm also sympathetic to the idea that theater producers — and concert promoters, and Major League Baseball owners — ought to be able to sell tickets at a price of their choosing, and that profit maximization shouldn't always be the sole goal. "It's not a simple application of supply and demand," says Larry Lucchino, the former chief executive of the Boston Red Sox, a team that sold out every home game between 2003 and 2013. "The availability and accessibility of tickets to various socioeconomic groups is important to your brand building and longevity."

And so it is with theater. "Hamilton's" producers have made some efforts to ensure that the show is seen by more than the rich and famous. They have instituted a lottery to sell up to 46 seats each night for $10 apiece. They have a program that will make it possible for some 20,000 high school students to see "Hamilton." In London, Ticketmaster and "Hamilton" are experimenting with a paperless ticket system, in which people will only get tickets when they arrive at the theater and show their credit cards. They are hoping this will defeat the bots.

On the other hand, it's obvious that the prices on the secondary market have had an effect on what "Hamilton" charges. "Hamilton" used to sell its so-called premium seats for $475. Last June, the premium seats rose to $849. The top price for a nonpremium seat used to be $177. Today it is $229. As for the bots, they haven't gone away, despite the laws against them.

Gregory Mosher, the producer of such shows as "Six Degrees of Separation" and "Swimming to Cambodia," told me that he had brought up the subject of "Hamilton" and tickets in the acting class he teaches at Columbia University. Most of the students hadn't seen "Hamilton" because of its cost, and they all wanted lower ticket prices. So Mosher threw out this idea: set aside 200 cut-rate seats each night for people in the profession.

Then he asked, "If you could resell your ticket for $1,000, how many of you would do it?" Every hand went up.

Turns out it's not easy to sidestep the law of supply and demand.