RIO DE JANEIRO -- In this exotic and storied city, a kind of class warfare is being waged through muggings, burglaries and kidnappings -- a stubbornly high level of crime that has left officials befuddled, tourists embattled and well-to-do residents all but resigned to the threat of assault as the price they pay for being here.

"Of course I've been mugged," said political scientist Amaury de Souza when the conversation turned to crime. "Haven't you?"

Crime was perhaps the major issue in the local campaign leading up to yesterday's elections, which were to select a new Congress and governors of the 26 states.

Stickups along Rio's beaches are so commonplace that one diplomat has called them a "directly paid tourist tax." Gangs have pioneered a chilling form of burglary, taking over entire apartment buildings and then systematically looting them, floor by floor.

And even more worrisome for wealthy cariocas, as residents of Rio are called, is a wave of kidnappings in which more than 30 people -- mostly businessmen or members of their families -- have been snatched for nearly $16 million in ransom this year.

The most recent high-profile kidnapping ended last Thursday when two university students, one of them the daughter of the owner of a string of jewelry stores, were freed after 17 days in captivity when their families paid about $500,000, in cash and nearly four pounds of pure gold.

Things have reached such a point that police chief Heraldo Gomes called that outcome a victory. After all, he said, the kidnappers had been forced to reduce their original multimillion-dollar demands.

In this metropolitan area of 10 million people, the crime situation is exacerbated by Brazil's sharp social divisions and by geography. Densely populated slums, called favelas, nestle in the hills overlooking the posh beachside neighborhoods of Copacabana, Ipanema and Leblon. Even amid some of the world's most glamorous surroundings, desperate poverty is never far away, never out of sight.

Statistics on muggings are hard to come by, but street assaults happen often enough to put a dent in Rio's vital tourist trade -- some hotels even had vacancies during this year's carnival, normally booked up well in advance -- and to prompt saturation efforts by police to handle the problem. The beaches are patrolled by young officers in sunglasses, muscle shirts and shorts, revolvers on their hips. Copacabana is floodlit at night like a soccer field.

But the police acknowledge they cannot hope to solve the problem.

"It is a fallacy to say that we are going to resolve the problem of violence with a bigger police force," former police chief Helio Saboya, now a candidate for Congress, said recently. "Other factors generate criminality, like the lack of education, {weak law enforcement in general}, the deterioration of moral standards, the bad example of our leaders, the enormous distortions in the distribution of income and the problem of abandoned children."

Most muggings seem to be of the kind common in New York or Washington. Several young men -- sometimes armed, more often not -- first pick a victim, then suddenly crowd in and demand money. The robbers flee to the favelas, where police have little chance of finding them.

Police rarely even venture into the toughest favelas. When they do, usually to conduct massive sweeps for the more notorious drug traffickers or kidnappers, their heavyhandedness and reputation for cor-ruption win them few friends. "The absence of public power in the favelas opens space for the criminals" to assume the leadership, said Saboya.

If most of the muggers are amateurs, the gangs that specialize in apartment-building heists are much more professional -- although recently their activity has declined in the face of tighter security.

The robbers generally arrive at a luxury high-rise in the morning, when the bustle of residents leaving for their offices and maids arriving for work means that heavily locked doors are swinging open and security guards are distracted. While some gang members hold the doormen and guards at gunpoint, others cut phone lines and other means of sounding an alarm. Then they go from floor to floor, forcing residents or employees to open apartment doors and safes.

While Rio has a soaring murder rate -- on one weekend this year, a record 57 homicides were recorded -- most killings occur in a vast lowland sprawl of slums called the Baixada Fluminense, far from pricey downtown.

The assaults, and now the kidnappings, hit closer to home for the Rio elite. Alexandre Wenkert, 24, and Vania Benzaquem, 20, were arriving for their business administration classes at the Gama Filho University on Sept. 11 when a car cut them off and six men hustled them away. Police say the gang was led by a desperado known as "Betinho."

The kidnappers, who fed the two students a diet of steak and french fries, were demanding $10 million from Vania Benzaquem's father, Leon Benzaquem, owner of the Roditi jewelry stores.

After the students' eventual release, the police tied Rio traffic in knots with roadblocks in a massive hunt for Betinho and his confederates. Callers complained on radio talk shows that the police would move heaven and earth when the interests of the rich were at stake, but did not care about crime when the victims were poor.

Police arrested a former girlfriend of Betinho who reportedly said he had been stalking Vania Benzaquem since the beginning of the year, tracking her movements and looking for the right opportunity.

The girlfriend also said that she saw Betinho bribe police officers several times, at least once paying for his release after being arrested.

The view that the police are ineffective and corrupt is seen by some as contributing to the crime and violence here. Jurandir Freire Costa, a psychoanalyst who has studied the violence, has written that Brazilians are losing "the idea of the perfectibility of social institutions" and falling into a kind of me-first "cynical reasoning" -- an attitude visible not only in assaults and robberies but also in widespread disregard for traffic regulations and an increase in hit-and-run accidents.

"We are living in an era in which each call for social responsibility is made fun of, as a moralizing fable or the kind of prayer an orphan might make on Christmas Eve," Freire Costa wrote.

Through it all, however, Rio remains Rio. There is a traditional easiness and informality that dies hard, a sunniness that takes the some of the chill off the most brutal realities.

A European journalist stationed here described how he was robbed for the second time in eight months along Copacabana beach. He had handed over his money and was beginning to back away, when one of the robbers recognized him and greeted him like a long-lost friend. "Maybe he lives in the favela up the hill from our apartment," the journalist said. "Maybe he was the guy who robbed me the first time. I don't know."

In any event, the robber gave the money back.