In 1916, Tsar Nicholas II hosts a ball at the Catherine Palace to celebrate the Romanov tricentennial. His mother, the Dowager Empress Marie Feodorovna, is visiting from Paris and gives a music box and a necklace inscribed with the words  Together in Paris  as parting gifts to her youngest granddaughter, eight-year-old Grand Duchess Anastasia. The ball is suddenly interrupted by the sorcerer Grigori Rasputin, the former royal advisor of the Romanovs until he was banished by Nicholas II for treason. Feeling betrayed and seeking revenge, Rasputin sold his soul in exchange for an unholy reliquary, which he uses to place a curse on the Romanov family, sparking the Russian Revolution. Only Marie and Anastasia are able to escape the ensuing siege of the palace, thanks to a young servant boy named Dimitri who shows them a secret passageway in Anastasia's room. Rasputin confronts the two royals outside on a frozen river, only to fall through the ice and freeze to death. The pair manage to reach a moving train, but only Marie climbs aboard while Anastasia falls, hitting her head on the platform and giving her amnesia.
Ten years later in 1926, Russia is under communist rule and Marie has publicly offered 10 million rubles for the safe return of her granddaughter. Dimitri and his friend/partner-in-crime Vladimir search for a look-alike to bring to Paris and pass off as Anastasia so as to collect the reward from Marie. Elsewhere, Anastasia, now using the name "Anya", leaves the rural orphanage where she grew up, having lost her memory prior to arriving there. Accompanied by a stray puppy she names "Pooka", she decides to head to Saint Petersburg, inspired by the passage on the necklace she still has. She is unable to leave Russia due to not having an exit visa, but a strange woman advises her to see Dimitri at the abandoned palace where he has made residence there. In the deserted palace she encounters Dimitri and Vladimir, who are impressed by her resemblance to the "real" Anastasia and decide to take her with them to Paris.
Bartok, Rasputin's albino bat minion, is nearby and notices his master's dormant reliquary suddenly revived by Anastasia's presence; it drags him to limbo, where the soul of Rasputin survives. Enraged to hear that Anastasia escaped the curse, Rasputin sends his demonic minions from the reliquary to kill her; despite two assassination attempts, the trio manage to (unwittingly) foil him, forcing Rasputin and Bartok to travel back to the surface.
Anastasia, Dimitri and Vladimir eventually reach Paris and go to meet Marie, who refuses to see her, having been nearly fooled numerous times before by impostors. Despite this, Sophie (Marie's cousin) quizzes Anastasia to confirm her identity. Though Anastasia offers the expected answers as taught to her by Dimitri, he realizes she is indeed the real Anastasia when she vaguely recollects how a boy had saved her ten years prior. Sophie, also convinced of Anastasia's identity, arranges a meeting with Marie at the Palais Garnier Opera house, but Marie initially refuses, having heard of Dimitri's scheme to present a stand-in in order to collect the reward money. Anastasia overhears the argument and angrily leaves. Dimitri kidnaps Marie and takes her to see Anastasia. When she refuses, Dimitri shows her the music box that he had found at the palace, and when its music plays, Anastasia is awash with her memories, convincing Marie of her identity. The two are joyfully reunited.
Marie offers Dimitri the reward money, but to her surprise, he refuses it and leaves for Russia, thanking Anastasia for her return to her grandmother. That night at Anastasia's return celebration, Marie informs her of Dimitri's gesture. Anastasia, deep in thought about Dimitri, wanders onto the Pont Alexandre III where she is trapped and attacked by Rasputin. Dimitri returns to save her, but is injured and knocked unconscious while Bartok abandons Rasputin. In the struggle, Anastasia manages to get hold of Rasputin's reliquary and crushes it under her foot, destroying it. With Rasputin's soul having been tied to the reliquary, he promptly dies and disintegrates.
Afterwards, Dimitri and Anastasia reconcile after Anastasia finally discovers the truth about herself; they elope and Anastasia sends a farewell letter to Marie and Sophie, promising to return one day. The couple kisses on a riverboat and Bartok shares a kiss with a female bat before bidding the audience farewell.
Output: What does Dimitri do that restores Anastasia's memories?