Problem: Mary Thomas has a number of sheets of squared paper. Some of squares are painted either in black or some colorful color (such as red and blue) on the front side. Cutting off the unpainted part, she will have eight opened-up unit cubes. A unit cube here refers to a cube of which each face consists of one square.

She is going to build those eight unit cubes with the front side exposed and then a bicube with them. A bicube is a cube of the size 2 × 2 × 2, consisting of eight unit cubes, that satisfies the following conditions:

* faces of the unit cubes that comes to the inside of the bicube are all black;
* each face of the bicube has a uniform colorful color; and
* the faces of the bicube have colors all different.



Your task is to write a program that reads the specification of a sheet of squared paper and decides whether a bicube can be built with the eight unit cubes resulting from it.



Input

The input contains the specification of a sheet. The first line contains two integers H and W, which denote the height and width of the sheet (3 ≤ H, W ≤ 50). Then H lines follow, each consisting of W characters. These lines show the squares on the front side of the sheet. A character represents the color of a grid: alphabets and digits ('A' to 'Z', 'a' to 'z', '0' to '9') for colorful squares, a hash ('#') for a black square, and a dot ('.') for an unpainted square. Each alphabet or digit denotes a unique color: squares have the same color if and only if they are represented by the same character.

Each component of connected squares forms one opened-up cube. Squares are regarded as connected when they have a common edge; those just with a common vertex are not.

Output

Print "Yes" if a bicube can be built with the given sheet; "No" otherwise.

Examples

Input

3 40
.a....a....a....a....f....f....f....f...
#bc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.#be#.
.#....#....#....#....#....#....#....#...


Output

Yes


Input

3 40
.a....a....a....a....f....f....f....f...
bc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.#be#.
.#....#....#....#....#....#....#....#...


Output

Yes


Input

5 35
.a....a....a....a....f....f....f...
bc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.
.#..f.#....#....#....#....#....#...
..e##..............................
.b#................................


Output

Yes


Input

3 40
.a....a....a....a....f....f....f....f...
bc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.#eb#.
.#....#....#....#....#....#....#....#...


Output

No

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

// 0: top, 1: front, 2:right, 3:back, 4:left, 5:bottom
const vector<vector<string>> dice_map = {
    {"0...",
     "1234",
     "5..."},
    {"0...",
     "1234",
     ".5.."},
    {"0...",
     "1234",
     "..5."},
    {"0...",
     "1234",
     "...5"},
    {".0..",
     "4123",
     ".5.."},
    {".0..",
     "4123",
     "..5."},
    {"...0",
     "2341",
     "..5."},
    {"...0",
     "2341",
     ".5.."},
    {"...0",
     "2341",
     "5..."},
    {"..0.",
     "3412",
     ".5.."},
    {"..0.",
     "3412",
     "5..."},
    {".0..",
     "4123",
     "5..."},
    {"..025",
     "341.."},
    {"025..",
     "..143"},
    {"..02",
     "341.",
     "5..."},
    {"40..",
     ".123",
     "...5"},
    {"..02",
     "341.",
     ".5.."},
    {"40..",
     ".123",
     "..5."},
    {"..02",
     "341.",
     "..5."},
    {"40..",
     ".123",
     ".5.."},
    {"..02",
     ".41.",
     "35.."},
    {"40..",
     ".12.",
     "..53"},
};

vector<string> rot_map(vector<string> const& v) {
    const int n = v.size(), m = v[0].size();
    vector<string> res(m);
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            res[j] += v[n - i - 1][j];
        }
    }
    return res;
};

using dice = string;

constexpr int rot_d[2][6] = {
    {3, 0, 2, 5, 4, 1}, // Front
    {0, 4, 1, 2, 3, 5}, // Side
};

dice rot_dice(dice const& v, int dir) {
    dice res(6, ' ');
    for(int j = 0; j < 6; ++j) {
        res[j] = v[rot_d[dir][j]];
    }
    return res;
}

bool is_valid_dice(dice const& d) {
    bool res = true;
    for(int i = 0; i < 3; ++i) {
        res &= isalpha(d[i]) || isdigit(d[i]);
        res &= d[i + 3] == '#';
    }
    return res;
}

bool check(vector<dice>& ds, int i) {
    bool res = false;
    if(i == 8) {
        res = true;
        for(int j = 0; j < 4; ++j) {
            res &= ds[j][0] == ds[0][0]; // top
            res &= ds[j + 4][0] == ds[4][0]; // bottom
            // side
            res &= ds[j][2] == ds[(j + 1) % 4][1];
            //res &= ds[j + 4][1] == ds[(j + 1) % 4 + 4][2];
            res &= ds[j][1] == ds[j + 4][2] && ds[j][2] == ds[j + 4][1];
        }
        return res;
    } else {
        for(int j = 0; j < 3; ++j) {
            res |= check(ds, i + 1);
            rotate(begin(ds[i]), begin(ds[i]) + 1, end(ds[i]));
        }
    }
    return res;
}

int main() {
    int h, w; cin >> h >> w;
    vector<string> v(h);
    for(auto& s : v) cin >> s;

    { // check1
        map<char, int> cols;
        for(auto const& s : v) {
            for(auto const c : s) {
                if(c == '.' || c == '#') continue;
                cols[c] += 1;
            }
        }
        bool chk = cols.size() == 6u;
        for(auto const& p : cols) {
            chk &= p.second == 4;
        }
        if(!chk) {
            cout << "No" << endl;
            return 0;
        }
    }

    vector<dice> dices;
    auto in_range = [&] (int y, int x) {
        return 0 <= y && y < h && 0 <= x && x < w;
    };
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            for(auto dm : dice_map) {
                string td;
                for(int k = 0; k < 4; ++k, dm = rot_map(dm)) {
                    const int n = dm.size(), m = dm[0].size();
                    if(!in_range(i + n - 1, j + m - 1)) continue;
                    string d(6, '.');
                    for(int y = i; y < i + n; ++y) {
                        for(int x = j; x < j + m; ++x) {
                            if(dm[y - i][x - j] == '.') continue;
                            d[dm[y - i][x - j] - '0'] = v[y][x];
                        }
                    }
                    if(d[0] == '.' || d[0] == '#') {
                        d = rot_dice(rot_dice(d, 0), 0);
                    }
                    for(int l = 0; l < 4; ++l, d = rot_dice(d, 1)) {
                        if(!is_valid_dice(d)) continue;
                        td = d.substr(0, 3);
                    }
                }
                if(!td.empty()) {
                    dices.push_back(td);
                }
            }
        }
    }

    // check
    sort(begin(dices), end(dices));
    bool ans = false;
    do {
        ans |= check(dices, 1);
    } while(!ans && next_permutation(begin(dices) + 1, end(dices)));

    cout << (ans ? "Yes" : "No") << endl;
}