const rl = require("readline").createInterface({ input: process.stdin });

var lines = [];
rl.on("line", (line) => {
    lines.push(line);
});

rl.on("close", () => {
    var arrI = lines[0].split(" ");
    var numI = arrI[0];
    arrI.splice(0, 1);
    // console.log(arrI)
    var arrR = lines[1].split(" ");
    var numR = arrR[0];
    arrR.splice(0, 1);
    arrR = [...new Set(arrR)].sort((a, b) => {
        return a - b;
    });
    // console.log(arrR);
    var map = new Map();
    var total = 0;
    arrR.forEach((item1) => {
        map.set(item1, "");
        var size = 0;
        arrI.forEach((item2, index) => {
            if (item2.includes(item1)) {
                map.set(item1, map.get(item1) + " " + index + " " + item2);
                total += 2;
                size++;
            }
        });
        map.set(item1, size + map.get(item1));
    });
    for (const [key, value] of map) {
        if (value === "0") {
            map.delete(key);
        }
    }
    total = total + map.size * 2;
    var str = total + ' ';
    for (const [key, value] of map) {
        str = str + key +" "+value +' '
    }
    console.log(str)
});