#FT0000061. Mức độ đảo trật tự lời nói của Yoda (Yodaness Level)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mức độ đảo trật tự lời nói của Yoda (Yodaness Level)
Yodaness Level
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Yoda often speaks sentences whose word order differs from the normal order. A sentence consists of distinct words, so their ordering can be compared unambiguously.
You receive two permutations of the same set of words: Yoda's order and the normal order. A pair contributes to the yodaness level if its relative order is reversed between the sentences. For example, word appears before word normally but after in Yoda's sentence.
Count all such pairs of distinct words, counting each pair once.
Input
The first line contains , the number of words.
The second line contains the words in Yoda's order.
The third line contains exactly those words in normal order. Each word uses only lowercase letters a–z and contains no whitespace.
Output
Print one integer: the number of word pairs whose relative order is reversed.
Subtasks
-
Subtask 1 (20 points): ; ; all words are distinct, contain only
a–zand both lines are permutations of the same words. -
Subtask 2 (30 points): ; ; all words are distinct, contain only
a–zand both lines are permutations of the same words. -
Subtask 3 (50 points): ; ; all words are distinct, contain only
a–zand both lines are permutations of the same words.
Examples
Input
6
in the force strong you are
you are strong in the force
Output
11
Explanation
In the normal sentence, you, are, strong, in, the, and force have positions respectively.
Replacing Yoda's words with their normal positions yields . The numbers of smaller later positions are .
Each of in, the, and force precedes the three words strong, you, and are in Yoda's sentence while following them normally. strong precedes you and are as well. The total is .