This page is still under construction.

Parts of this page are still being built. What you see may change.

Black and White Graphics

Interview

Time limit2sMemory limit512 MB

Summary
Apply a logical operation, given by a four-entry truth table, to two same-size black and white images pixel by pixel and print the result.
Level

Easy2 of 10

Topics
Implementation, Array, Simulation, Bit manipulation
Solved
No attempts yet

Problem

One of the basic problems in computer graphics is processing black and white images. An image can be represented as a rectangle of width w and height h divided into w×h unit squares, each of which is either white or black. These unit squares are called pixels. In computer memory, images are stored as rectangular tables containing zeros and ones.

In many fields, the problem of combining images comes up often. One of the simplest methods of combination used when working with black and white images is applying a logical operation pixel by pixel. This means that the value of a pixel in the result is obtained by applying that logical operation to the corresponding pixels of the arguments. A logical operation on two arguments is usually given by a truth table, which contains the value of the operation for every possible combination of arguments. For example, for the operation "exclusive OR" this table looks as follows.

First argumentSecond argumentResult
000
011
101
110

You must write a program that computes the result of applying a given logical operation pixel by pixel to two black and white images of the same size.

Input

The first line of the input file contains two integers w and h (1 ≤ w, h ≤ 100). The following h lines describe the first image, and each of these lines contains w characters, each of which is a zero or a one. After that comes the description of the second image in the same format. The last line of the input file contains the description of the logical operation as four numbers, each of which is a zero or a one. The first of them is the result of applying the logical operation when both arguments are zeros, the second is the result when the first argument is zero and the second is one, the third is the result when the first argument is one and the second is zero, and the fourth is the result when both arguments are ones.

Output

The output file must contain the result of applying the given logical operation to the images, in the same format in which the images are given in the input file.

Examples1

  1. Example 1

    Input
    5 3
    01000
    11110
    01000
    10110
    00010
    10110
    0110
    
    Expected output
    11110
    11100
    11110