A+B

Time limit2sMemory limit64 MB

Summary
Given forbidden strings V, find the lexicographic index sum of A and B among all strings orthogonal to V, then output the string at that index modulo the count.
Level

Medium7 of 10

Topics
Math, Combinatorics, String
Solved
No attempts yet

Problem

Two strings P=P1P2⋯PnP = P_1 P_2 \cdots P_n and Q=Q1Q2⋯QnQ = Q_1 Q_2 \cdots Q_n of the same length nn are called orthogonal if Pi≠QiP_i \ne Q_i for every ii with 1≤i≤n1 \le i \le n. A string SS of length nn is orthogonal to a set of strings V={V1,V2,…,Vm}V = \{V_1, V_2, \ldots, V_m\} (each also of length nn) if SS is orthogonal to VjV_j for every jj with 1≤j≤m1 \le j \le m.

Fix the alphabet of lowercase English letters. Given a set VV, take all strings of length nn that are orthogonal to VV and sort them in ascending lexicographic order. This yields a sequence T=T0,T1,…,TM−1T = T_0, T_1, \ldots, T_{M-1}, where MM is the number of such strings.

The orthogonal sum of A=TaA = T_a and B=TbB = T_b is the string C=TcC = T_c where c=(a+b) mod Mc = (a + b) \bmod M.

Given the set VV and two strings AA and BB (both orthogonal to VV), compute the orthogonal sum CC of AA and BB with respect to VV.

Input

The first line contains two integers nn and kk: the length of each string nn (1≤n≤1000001 \le n \le 100000) and the number of strings in VV, with 1≤n⋅k≤1000001 \le n \cdot k \le 100000. Each of the next kk lines contains one string VjV_j. The following two lines contain the strings AA and BB, each of length nn.

All strings VjV_j, AA, and BB consist of lowercase English letters. It is guaranteed that AA and BB are orthogonal to VV.

Output

Print the orthogonal sum CC of AA and BB with respect to VV.

Examples6

  1. Example 1

    Input
    2 2
    ac
    ad
    bb
    bb
    
    Expected output
    be
    
  2. Example 2

    Input
    2 1
    yy
    zz
    zz
    
    Expected output
    zx
    
  3. Example 3

    Input
    1 1
    a
    b
    c
    
    Expected output
    c
    
  4. Example 4

    Input
    1 1
    a
    z
    z
    
    Expected output
    y
    
  5. Example 5

    Input
    3 2
    abc
    abd
    xyz
    mno
    
    Expected output
    kmn
    
  6. Example 6

    Input
    4 3
    bcda
    efgb
    hijc
    zzzz
    yyyy
    
    Expected output
    yyyx