#include <iostream> #include <vector> #include <algorithm> #include <map> using namespace std; using i64 = long long; using u64 = unsigned long long; using i32 = int; using u32 = unsigned int; #define rep(i,n) for(int i=0; i<(n); i++) bool is_piriodic(const string& s, int k){ int n = s.size(); for(int i=0; i<n; i++) if(s[i] != s[(i+k)%n]) return false; return true; } int main() { int N,M; cin >> N >> M; string X; cin >> X; vector<string> A(N); rep(i,N) cin >> A[i]; map<int, string> mem; rep(i,N) mem[i+1] = A[i]; auto access_mem = [&](int i) -> string& { if(mem.find(i) == mem.end()) return mem[i] = string(M, '0'); return mem[i]; }; auto dump_mem = [&]() -> void { //cout << "dump mem" << "\n"; //for(auto& a : mem){ cout << " [" << a.first << "] = " << a.second << "\n"; } //cout << endl; }; vector<vector<int>> ans; auto query_shift = [&](int o, int i) -> void { string& s = access_mem(i); access_mem(o) = s.substr(1) + "0"; ans.push_back({ 1, o, i }); }; auto query_nand = [&](int o, int a, int b) -> void { string& s1 = access_mem(a); string& s2 = access_mem(b); string buf = string(M, '1'); rep(i,M) if(s1[i] == '1' && s2[i] == '1') buf[i] = '0'; access_mem(o) = buf; ans.push_back({ 1, o, a, b }); }; query_nand(0,0,0); dump_mem(); reverse(X.begin(), X.end()); int Z = 7001; query_nand(Z,Z,Z); query_shift(Z,Z); rep(i,M){ if(X[i] == '1'){ query_nand(0,0,Z); query_nand(0,0,0); } dump_mem(); query_nand(Z,Z,Z); query_shift(Z,Z); query_nand(Z,Z,Z); } query_nand(0,0,0); dump_mem(); cout << ans.size() << "\n"; for(auto& a : ans){ rep(i,a.size()){ if(i) cout << " "; cout << a[i]; } cout << "\n"; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;