ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

1721. Two Sides of the Same Coin

Time limit: 1.0 second
Memory limit: 64 MB
Side one
Poll flew above the City. Bright street lights flashed by below. He was winding his way around needle-sharp spires of communication towers and wicker grid radiators of thermonuclear power plants. Express mail helicopters rushed past him. Suddenly, the neat layout of the streets below was broken. The streets, which used to be straight and parallel, had started to twist and twirl like a bunch of glowing tentacles. Poll soared upwards. Looking down from above, Poll no longer saw streets. Instead, he saw a neural network — live and pulsating with energy. One of the neurons flashed and faded to black. Its neighbours were saturated with energy and burst too. With each impulse, a neuron would reach its neighbour and turn it into light. The wave of flashes was propagating through the neural tissue, consuming and annihilating it. Soon, Poll found himself alone in the dark. The darkness surrounded him, filled his eye sockets and mouth, squeezed his chest. Poll couldn't breath, couldn't think and the only thing he felt was absolute, total terror…
Poll woke up screaming. His dreams had turned for the worse that week. Vivid, detailed, indistinguishable from reality, but at the same time incoherent and perplexed. Actually, it was a well-known symptom, one of those that were featured prominently in the sermons of street preachers from doomsday cults. Poll was in a state of denial for a month, but his condition had become too obvious to ignore. He typed “neurointerface autoinduction syndrome” in his favourite search engine and in a short time found a specialized clinic nearby. He registered on its site and booked an appointment that evening.
Poll went to work on foot. Private vehicles were forbidden in the City, and he didn't want to suffocate in overcrowded carriages. But the streets were far from deserted either. The buzzing of the crowd was complemented by the screaming ads running on huge screens which were profusely hanged above the pavement. Poll noticed painfully familiar logo on one of the screens, and a pleasant female voice informed him that “Subregional Programming Contest will be held in the City in less than a week. Make sure you're registered!”
Poll had entered a high-rise building and went up to floor 70. The floor housed the jury of the contest mentioned in the advertisement, and Poll was the chairman of the jury. Several people were sitting behind their desktops in a big room. Most of them were using neurointerfaces, so no clacking of keyboards could be heard. Those people were Poll's hand-picked team, they were preparing the problems for the contest. All of them were professionally licensed problemsetters with a rank of 3 or higher. Nevertheless, Poll always verified and approved every problem by himself before a contest. He trusted his team, but the stakes were high — and a second pair of eyes couldn't hurt.
Poll went to his office, got connected to the internal network via his neurointerface and plunged into the work. The day passed by. Poll noticed that it got dark outside only when headlights of a fire helicopter flying by his window illuminated the room. He looked at his watch, and realized that he was late for the doctor's appointment. He logged off and hurried to the clinic.
A nice nurse greeted Poll at the reception and directed him to the doctor Wasat's office. Dr. Wasat turned out to be a friendly, sympathetic aged physician, who could easily gain the confidence of his patients. He listened carefully and immediately went to the heart of the problem. After some consideration, he suggested for Poll to undergo brain scanning immediately, to confirm or deny any issues with the neurointerface. Poll felt relieved that his case had been in the hands of a specialist, and he agreed to the procedure. They went to the neighbouring room, where there was a sophisticated device resembling an electric chair. Poll sat down on it. The doctor fixed his head between two hemispheres and stepped away to the control panel. Poll saw nothing but a plain white wall in front of him. He sensed that something was connected to his neurointerface.
“Don't resist it,” the doctor said gently.
Poll relaxed. The device hummed to life, sending warm waves through Poll's body. Nothing happened for a while, but then suddenly Poll noticed thin sharp spikes extending from the white wall. They were slowly growing, coming closer and closer to him. All of them were aimed at his heart. He tried to break free, to dodge, but to no avail. Thousands of white spikes penetrated his chest, pierced his heart, and started to pump bright white light into him. The light displaced blood in his arteries, reached all corners of his body, flooded his mouth, poured out of his eyes. Poll shut his eyes tight and violently writhed.
“Poll! Poll! Calm down! It's OK, it's over now!” the doctor's voice sounded concerned.
Poll opened his eyes. Doctor Wasat was holding his shoulders and watching him closely. There were neither spikes nor light around.
A nurse took Poll back to the office and brought him hot tea. He was sitting there alone for a long time, until doctor Wasat finally returned. The doctor was gloomy. He sat behind his desk and categorically stated:
“I don't want to scare you, but your condition is very serious indeed. I'm sure you understand it too. It'll get worse. You'll experience visions not only when you're sleeping, but when you're awake too. To be precise, you won't be able to distinguish dreams and reality.”
They talked for a couple of hours. The doctor promised to help in any way possible, but he couldn't guarantee anything. Modern medical science still wasn't able to treat such conditions.
Poll left the clinic very depressed. The doctor suggested to lift him home in a medical helicopter, but Poll declined. He didn't want to go home. He went straight to the local council building, which was the tallest in the neighbourhood. Although its roof was off-limits to the public, Poll happened to know the access code. He climbed the roof, walked up to the edge, and breathed the cool night air. He could see the City up to the horizon. Not the twisted city from his dreams, but the usual bustling city of real people. The Reality. With all its flaws, Poll didn't want to get detached from it. Better to be dead than to end up in a straitjacket inside an asylum.
“Gonna jump?” A female voice from behind caught Poll by surprise.
Poll turned back. A girl, mid-20's, was sitting on an air duct. She grinned and looked down at him.
“Don't know,” said Poll with a smile.
The girl jumped off the duct and walked up to Poll. She stepped on the edge near him and looked down in awe.
“So high… I'm Alhena. You?”
They were standing shoulder to shoulder for a few minutes. Poll started to feel a little self-conscious. Alhena broke the silence first:
“So, Poll. Gonna invite me for a date? But not tonight,” she added hastily.
“All right, how about tomorrow?” Poll replied captivatedly.
“That'd be great.”
They exchanged their numbers and went down to the street together. Poll tried to follow her, but soon lost her in the crowd.
Next morning Poll was late for work. When he finally arrived, he found his old friend Castor waiting for him in the office. They had been arranging contests together for a long time. But Castor wasn't a problemsetter. From a young age he was passionate about protection of everything. He was responsible for physical and information security of the contests. People called him “Castor-hound” behind his back, but Poll liked him. Maybe because Castor helped Poll deal with several delicate situations and difficult people, earning his deep trust and respect.
From time to time, Castor came to each employee to personally update the access codes through the neurointerface. The employees called this “Castor eating our brains.” And when the codes weren't updated for some time, someone always asked “When will Castor eat our brains again?”
Today was the day. Castor got connected to Poll's neurointerface and while the codes were being uploaded, they chatted randomly. When Castor left, Poll was feeling much better. A chat with a friend calmed him down and he was ready to get into gear.
He worked hard all day. In the evening he called Alhena and invited her for dinner. They went to the best restaurant in the neighbourhood. Alhena turned out to be very sociable, able to find common ground even with such an extreme introvert as Poll. They talked about a range of things, and Poll felt he really got to know her. The only thing that troubled him was that he couldn't figure out what she was doing on the roof, and he didn't know how to ask.
After the restaurant they went to her place. She lived alone in a small, tidy apartment. Poll settled on a couch while Alhena poured out two glasses of wine. They toasted the evening and sipped a little. She leaned forward to kiss him…
Side two
She leaned forward to kiss him, when suddenly her head jerked up and she gave a shrill scream. Her whole body was shaking with convulsions and she tumbled down to the floor.
In a moment, mayhem broke out in the apartment. The main door was pulled out, windows were broken, and a dozen of armed men wearing masks and body armor poured inside. Four of them grabbed Alhena and dragged her away. Two were holding Poll down tight. But Poll didn't even try to struggle, he was dumbfounded by the unexpected twist of the story.
A man in the same body armor but without a mask entered the room. Poll, to his utter surprise, recognized his buddy Castor. Castor sat down opposite Poll and grinned. By then, the initial shock was wearing off, and Poll burst out on him:
“Castor, what the hell? What's going on here?”
“Me saving your ass again is going on here,” said Castor favorably and in a commanding voice ordered, “Release him.”
The two let Poll off and stepped out. Poll rubbed his left shoulder and asked, frowning:
“What's up with Alhena?”
“She was smashed by the virus I planted into your head today.”
“I don't understand.”
“It's really easy,” said Castor, making himself comfortable. “As a matter of fact, you're not ill. They somehow managed to hack your brain and infect it with a virus which made you believe you've got a syndrome. Besides, the virus allowed them to make a copy of your memory via the neurointerface without you even noticing it. She just tried to do this very thing. She tried to download your today's memories, memories of all the problems you worked on. But she didn't know that I erased their virus from your system and planted mine. I call it Castor-hound,” and he winked at Poll. “Whenever someone tries to connect to the backdoor in your head, Castor-hound starts to eat his brain. You saw the result.”
Poll started to connect the dots.
“And doctor Wasat…”
“… is not a doctor at all. You were his first and last patient. He downloaded a good chunk of information from your head, all the work you did this month. We eventually captured him, but it was too late, he already sold the data. There is no way we can stop the leak now. I'm afraid the contest should be canceled.”
Poll was fuming. He was tricked like a big silly. He stared at Castor and said categorically:
“No, we won't cancel the contest. We'll prepare new problems.”
“Do you have enough time? How many problems can you prepare simultaneously?”
That was a good question. The contest rules state that every problem should be prepared by two persons exactly: one should write a statement, the other one should prepare a set of tests. Generally, professional problemsetters have license for only one of the tasks, but some of them can do both. Besides, to eliminate a possibility of conflicts between the problemsetters working on the same problem, the difference of their ranks should be equal to 2.
They had not much time left, so each of them could prepare only one problem. Poll urgently needed to answer the question: how many problems would the jury be able to prepare for the contest?


The first line contains the number n of problemsetters in the program committee (2 ≤ n ≤ 1000). Each of the following n lines contains a problemsetter's name, his specialization and his rank separated with spaces. The name consists of up to 20 Latin letters. There are no two problemsetters with the same name. Specialization is denoted by one of the three words: “statements”, “testdata”, or “anything”, corresponding to the people able to write statements, people able to prepare the tests and to the people able to do both. The rank is an integer in range from 3 to 1000.


In the first line output the maximal number of problems that can be prepared for the contest. For each of these problems output a line containing the name of a person writing the statement, a space, and the name of a person preparing the tests. If there are several ways to prepare such an amount of problems output any one.


Poll anything 8
Tejat statements 6
Mebsuta testdata 6
Propus testdata 4
Alzir anything 7
Mekbuda anything 3
Dirah testdata 9
Poll Mebsuta
Tejat Propus
Alzir Dirah
Problem Author: Pavel Atnashev
Problem Source: NEERC 2009, Eastern subregional contest