#P7304. Variable Replacement for Array Equality

    ID: 20503 Type: Default 1000ms 256MiB

Variable Replacement for Array Equality

Variable Replacement for Array Equality

Vlatko likes working with integer arrays. He writes down two arrays, each containing (N) elements. Each element is either an integer or a variable represented by a string consisting only of lowercase letters. A variable may be replaced by any integer, but all occurrences of the same variable (even across both arrays) must be replaced by the same integer. Vlatko wonders if it is possible to choose an integer to replace each variable so that the two arrays become equal element‐wise. In other words, if we denote the elements of the first array as (a_1, a_2, \ldots, a_N) and of the second array as (b_1, b_2, \ldots, b_N), is there an assignment to the variables such that for every index (i) ((1 \le i \le N)) we have (a_i = b_i)?

inputFormat

The first line contains an integer \(N\) (the number of elements in each array). The second line contains \(N\) tokens (each token is either an integer or a variable name) describing the first array. The third line contains \(N\) tokens describing the second array. An integer token will consist of an optional minus sign followed by digits, and a variable token will consist only of lowercase letters.

outputFormat

Output a single line: YES if there exists an assignment of integers to the variables so that the two arrays become identical, or NO otherwise.

sample

3
1 2 3
1 2 3
YES

</p>