#P5410. Z-Function and LCP Arrays XOR Weight

    ID: 18642 Type: Default 1000ms 256MiB

Z-Function and LCP Arrays XOR Weight

Z-Function and LCP Arrays XOR Weight

You are given two strings a and b. Your task is to compute two arrays:

  • The z-function array for string b. For 1-indexed array z of length m = |b|, z[1] is defined as 0 and for 2 ≤ i ≤ m, z[i] is the length of the longest common prefix (LCP) of b and the suffix of b starting at position i.
  • The LCP array between string b and every suffix of string a. In other words, for each 1-indexed position i (where 1 ≤ i ≤ |a|), p[i] is the length of the longest common prefix between b and the suffix of a starting at i. Note that if the matching length exceeds |b|, you should only consider |b| as the maximum match length.

For an array x of length n (where x can be either z or p), define its weight as follows:

\( \operatorname{weight}(x) = \bigoplus_{i=1}^{n} \Bigl(i \times (x_i + 1)\Bigr) \)

Here, \(\oplus\) denotes the bitwise XOR operation. Your program must compute and output the weight of the z array and the weight of the p array.

Input

  • The input consists of two lines. The first line contains string a and the second line contains string b.

Output

  • Output two integers separated by a space: the weight of the z array for string b and the weight of the p array for string a (with respect to b).

inputFormat

The input consists of two lines:

  1. The first line contains the string a.
  2. The second line contains the string b.

outputFormat

Output a single line containing two integers separated by a space. The first integer is the weight of the z array for b and the second integer is the weight of the p array computed for string a against b.

sample

abab
aba
5 11