Language: C++

#include <iostream>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>
using namespace std;

struct Edge{
  int cap; // capacity
  int to;
  int rev; // reverse edge id

  Edge(){}
  Edge(int c, int t, int r) :
    cap(c), to(t), rev(r){}
};

struct CostEdge : public Edge{
  int cost;
  CostEdge() : Edge() {}
  CostEdge(int c, int t, int cs, int r) :
    Edge(c, t, r), cost(cs){}
};

template<class E> // Edge type
class Graph{
public:
  typedef std::vector<std::vector<E> > G;

private:
     G g;

public:
  Graph(int n) : g(G(n)) {}

  void addEdge(int from, int to, int cap){
    g[from].push_back(E(cap, to, g[to].size()));
    g[to].push_back(E(0, from, g[from].size() - 1));
  }

  void addEdge(int from, int to, int cap, int cost){
    g[from].push_back(E(cap, to, cost, g[to].size()));
    g[to].push_back(E(0, from, -cost, g[from].size() - 1));
  }

  G &getRowGraph(){
    return g;
  }
};

template<class E>
int minCostFlow(Graph<E> &graph, int s, int t, int f, bool negative = fal
  typedef pair<int, int> P;
  typename Graph<E>::G &g = graph.getRowGraph();
  int n = g.size();
  int res = 0;
  vector<int> h(n, 0);
  vector<int> prevv(n);
  vector<int> preve(n);
  const int inf = 10000000;

  if(negative){
    vector<int> dist(n, inf);
    dist[s] = 0;

    bool update = true;

    while(update){
      update = false;
      for(int v = 0; v < n; v++){
        if(dist[v] == inf) continue;
        for(int i = 0; i < (int)g[v].size(); i++){
          E &e = g[v][i];
          if(e.cap > 0 && dist[e.to] > dist[v] + e.cost){
            dist[e.to]  = dist[v] + e.cost;
            prevv[e.to] = v;
            preve[e.to] = i;
            update      = true;
          }
        }
      }
    }

    for(int i = 0; i < n; i++)
      h[i] = dist[i];
  }

  while(f > 0){
    priority_queue<P, vector<P>, greater<P> > que;
    vector<int> dist(n, inf);
    dist[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
      P p   = que.top(); que.pop();
      int v = p.second;
      if(dist[v] < p.first) continue;
      for(int i = 0; i < (int)g[v].size(); i++){
        E &e = g[v][i];

        if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]){
          dist[e.to]  = dist[v] + e.cost + h[v] - h[e.to];
          prevv[e.to] = v;
          preve[e.to] = i;
          que.push(P(dist[e.to], e.to));
        }
      }
    }
    if(dist[t] == inf){
      return -1;
    }

    for(int v = 0; v < n; v++) h[v] += dist[v];

    int d = f;
    for(int v = t; v != s; v = prevv[v]){
      d = min(d, g[prevv[v]][preve[v]].cap);
    }

    f   -= d;
    res += d * h[t];

    for(int v = t; v != s; v = prevv[v]){
      E &e = g[prevv[v]][preve[v]];
      e.cap -= d;
      g[v][e.rev].cap += d;
    }
  }
  return res;
}

int w[100][100];
int e[100][100];
int f[100][100];
int c[100][100];

int main(){
  const int n = getInt();

  REP(i,n) REP(j,n)
    w[i][j] = getInt();
  REP(i,n) REP(j,n)
    e[i][j] = getInt();

  REP(i,n){
    char b[128]; scanf("%s", b);
    REP(j,n) f[i][j] = (b[j] == 'o' ? 1 : 0);
  }

  REP(i,n){
    REP(j,n){
      int cc = 0;

      REP(k,n){
        if(f[i][k]  && k != j) cc += e[i][j];
        if(!f[i][k] && k == j) cc += w[i][j];
      }

      c[i][j] = cc;
    }
  }

  Graph<CostEdge> g(2 + 2 * n);
  const int start = 2 * n;
  const int goal  = 2 * n + 1;

  REP(i,n) REP(j,n){
    g.addEdge(i, n + j, 1, c[i][j]);
  }

  REP(i,n){
    g.addEdge(start, i, 1, 0);
    g.addEdge(n + i, goal, 1, 0);
  }

  int cost = minCostFlow(g, start, goal, n);

  printf("%d\n", cost);

  vector<string> ans;
  const Graph<CostEdge>::G &gg = g.getRowGraph();
  REP(i,n){
    int dst = -1;
    REP(j,n){
      if(gg[i][j].cap == 0){
        dst = gg[i][j].to - n;
      }
    }
    while(dst == -1) ;
    REP(j,n){
      char buff[256];
      if(f[i][j] && dst != j){
        sprintf(buff, "%d %d erase", i + 1, j + 1);
        ans.push_back(buff);
      }
      if(!f[i][j] && dst == j){
        sprintf(buff, "%d %d write", i + 1, j + 1);
        ans.push_back(buff);
      }
    }
  }

  printf("%d\n", ans.size());
  REP(i,ans.size())
    printf("%s\n", ans[i].c_str());

  return 0;
}

Compiler output:
a.cc:56:71: error: 'fal' was not declared in this scope
   56 | int minCostFlow(Graph<E> &graph, int s, int t, int f, bool negative = fal
      |                                                                       ^~~
a.cc:57:3: error: expected ',' or '...' before 'typedef'
   57 |   typedef pair<int, int> P;
      |   ^~~~~~~
a.cc:57:27: error: expected ')' before ';' token
   57 |   typedef pair<int, int> P;
      |                           ^
      |                           )
a.cc:56:16: note: to match this '('
   56 | int minCostFlow(Graph<E> &graph, int s, int t, int f, bool negative = fal
      |                ^
a.cc:58:18: error: 'E' was not declared in this scope
   58 |   typename Graph<E>::G &g = graph.getRowGraph();
      |                  ^
a.cc:58:19: error: template argument 1 is invalid
   58 |   typename Graph<E>::G &g = graph.getRowGraph();
      |                   ^
a.cc:58:29: error: 'graph' was not declared in this scope; did you mean 'Graph'?
   58 |   typename Graph<E>::G &g = graph.getRowGraph();
      |                             ^~~~~
      |                             Graph
a.cc:59:13: error: request for member 'size' in 'g', which is of non-class type 'int'
   59 |   int n = g.size();
      |             ^~~~
a.cc:66:3: error: expected unqualified-id before 'if'
   66 |   if(negative){
      |   ^~
a.cc:92:3: error: expected unqualified-id before 'while'
   92 |   while(f > 0){
      |   ^~~~~
a.cc:133:3: error: expected unqualified-id before 'return'
  133 |   return res;
      |   ^~~~~~
a.cc:134:1: error: expected declaration before '}' token
  134 | }
      | ^