Language: Java

#include <iostream>
#include <queue>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

typedef int Capacity;
typedef int Cost;
struct MCF {
    struct Edge {
        int dst;
        Capacity cap, cap_orig;
        Cost cost;
        int revEdge; bool isRev;
        Edge(int dst, Capacity cap, Cost cost, int revEdge, bool isRev)
            :dst(dst), cap(cap), cap_orig(cap), cost(cost), revEdge(revEdge), isRev(isRev) {}
    };
    int n;
    vector<vector<Edge> > g;
    enum : Cost { inf = 1<<29 };
    enum : int { MAX_V = 200 };

    MCF(int n_) : n(n_), g(vector<vector<Edge> >(n_)){}

    pair<int,int> add_edge(int src, int dst, Capacity cap, Cost cost) {
        g[src].emplace_back(dst, cap, cost, g[dst].size(), false);
        g[dst].emplace_back(src, 0, -cost, g[src].size() - 1, true);
        return make_pair(g[src].size()-1, g[dst].size()-1);
    }
    int mcf(int s, int t, int f) {
        int res = 0;
        // vector<Cost> h(g.size()), dist(g.size());
        // vector<int> prevv(g.size()), preve(g.size());
        static Cost h[MAX_V], dist[MAX_V];
        static int prevv[MAX_V], preve[MAX_V];
        rep(i,n)h[i] = 0;
        while (f > 0) {
            typedef pair<Cost,int> pcv;
            priority_queue<pcv, vector<pcv>, greater<pcv> > q;
            rep(i,n) dist[i] = inf;
            dist[s] = 0;
            q.emplace(pcv(0, s));
            while (q.size()) {
                pcv p = q.top(); q.pop();
                int v = p.second;
                if (dist[v] < p.first) continue;
                rep(i,g[v].size()){
                    Edge &e = g[v][i];
                    if (e.cap > 0 && dist[e.dst] > dist[v] + e.cost + h[v] - h[e.dst]) {
                        dist[e.dst] = dist[v] + e.cost + h[v] - h[e.dst];
                        prevv[e.dst] = v;
                        preve[e.dst] = i;
                        q.emplace(pcv(dist[e.dst], e.dst));
                    }
                }
            }
            if (dist[t] == inf) {
                return -1;
            }
            rep(v,n) h[v] += dist[v];
            // s-t 間最短路に沿って目一杯流す
            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]) {
                Edge &e = g[prevv[v]][preve[v]];
                e.cap -= d;
                g[v][e.revEdge].cap += d;
            }
        }
        return res;
    }

    // 流れたフロー=元々の容量-現在の容量を表示
    void view(){
        rep(i,g.size()){
            rep(j,g[i].size())if(!g[i][j].isRev){
                Edge& e = g[i][j];
                printf("%3d->%3d (flow:%d)\n", i, e.dst, e.cap_orig - e.cap);
            }
        }
    }
};

int main(){
    int n;
    while(cin>>n){
        MCF mcf(n*2+2);
        int p[111];
        rep(i,n) cin >> p[i];
        rep(i,n){
            mcf.add_edge(n*2,i,1,0);
            mcf.add_edge(n+i,n*2+1,1,0);
        }
        rep(i,n)rep(j,n)if(i!=j){
            int x = find(p,p+n,i+1)-p;
            mcf.add_edge(i,n+j,1,(i+1)*abs(x-j));
        }
        cout << mcf.mcf(n*2,n*2+1,n) << endl;
    }
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include <iostream>
^
Main.java:2: error: illegal character: '#'
#include <queue>
^
Main.java:3: error: illegal character: '#'
#include <vector>
^
Main.java:4: error: illegal character: '#'
#include <cstdio>
^
Main.java:5: error: illegal character: '#'
#include <algorithm>
^
Main.java:8: error: illegal character: '#'
#define all(c) (c).begin(), (c).end()
^
Main.java:8: error: class, interface, enum, or record expected
#define all(c) (c).begin(), (c).end()
        ^
Main.java:9: error: illegal character: '#'
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
^
Main.java:9: error: class, interface, enum, or record expected
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
                                  ^
Main.java:9: error: class, interface, enum, or record expected
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
                                           ^
Main.java:10: error: illegal character: '#'
#define rep(i,b) loop(i,0,b)
^
Main.java:13: error: class, interface, enum, or record expected
typedef int Cost;
^
Main.java:14: error: class, interface, enum, or record expected
struct MCF {
^
Main.java:17: error: class, interface, enum, or record expected
        Capacity cap, cap_orig;
        ^
Main.java:18: error: unnamed classes are a preview feature and are disabled by default.
        Cost cost;
        ^
  (use --enable-preview to enable unnamed classes)
Main.java:20: error: class, interface, enum, or record expected
        Edge(int dst, Capacity cap, Cost cost, int revEdge, bool isRev)
        ^
Main.java:25: error: <identifier> expected
    enum : Cost { inf = 1<<29 };
        ^
Main.java:25: error: enum constant expected here
    enum : Cost { inf = 1<<29 };
         ^
Main.java:25: error: <identifier> expected
    enum : Cost { inf = 1<<29 };
                     ^
Main.java:25: error: ';' expected
    enum : Cost { inf = 1<<29 };
                             ^
Main.java:26: error: <identifier> expected
    enum : int { MAX_V = 200 };
        ^
Main.java:26: error: enum constant expected here
    enum : int { MAX_V = 200 };
         ^
Main.java:26: error: <identifier> expected
    enum : int { MAX_V = 200 };
              ^
Main.java:26: error: ';' expected
    enum : int { MAX_V = 200 };
                            ^
Main.java:28: error: '.class' expected
    MCF(int n_) : n(n_), g(vector<vector<Edge> >(n_)){}
            ^
Main.java:28: error: <identifier> expected
    MCF(int n_) : n(n_), g(vector<vector<Edge> >(n_)){}
              ^
Main.java:28: error: illegal start of expression
    MCF(int n_) : n(n_), g(vector<vector<Edge> >(n_)){}
                                               ^
Main.java:28: error: ',', '}', or ';' expected
    MCF(int n_) : n(n_), g(vector<vector<Edge> >(n_)){}
                                                       ^
Main.java:39: error: illegal start of expression
        static Cost h[MAX_V], dist[MAX_V];
        ^
Main.java:39: error: ']' expected
        static Cost h[MAX_V], dist[MAX_V];
                      ^
Main.java:39: error: <identifier> expected
        static Cost h[MAX_V], dist[MAX_V];
                           ^
Main.java:39: error: ']' expected
        static Cost h[MAX_V], dist[MAX_V];
                                   ^
Main.java:39: error: ';' expected
        static Cost h[MAX_V], dist[MAX_V];
                                        ^
Main.java:40: error: ']' expected
        static int prevv[MAX_V], preve[MAX_V];
                         ^
Main.java:40: error: <identifier> expected
        static int prevv[MAX_V], preve[MAX_V];
                              ^
Main.java:40: error: ']' expected
        static int prevv[MAX_V], preve[MAX_V];
                                       ^
Main.java:40: error: ';' expected
        static int prevv[MAX_V], preve[MAX_V];
                                            ^
Main.java:41: error: ',', '}', or ';' expected
        rep(i,n)h[i] = 0;
                ^
Main.java:41: error: ']' expected
        rep(i,n)h[i] = 0;
                  ^
Main.java:41: error: ';' expected
        rep(i,n)h[i] = 0;
                   ^
Main.java:42: error: illegal start of type
        while (f > 0) {
        ^
Main.java:42: error: <identifier> expected
        while (f > 0) {
                ^
Main.java:43: error: ';' expected
            typedef pair<Cost,int> pcv;
                        ^
Main.java:43: error: illegal start of expression
            typedef pair<Cost,int> pcv;
                                   ^
Main.java:45: error: ';' expected
            rep(i,n) dist[i] = inf;
                    ^
Main.java:52: error: ';' expected
                rep(i,g[v].size()){
                                  ^
Main.java:65: error: ';' expected
            rep(v,n) h[v] += dist[v];
                    ^
Main.java:79: error: illegal start of type
        return res;
        ^
Main.java:84: error: ';' expected
        rep(i,g.size()){
                       ^
Main.java:85: error: ';' expected
            rep(j,g[i].size())if(!g[i][j].isRev){
                              ^
Main.java:96: error: not a statement
        MCF mcf(n*2+2);
                   ^
Main.java:98: error: not a statement
        rep(i,n) cin >> p[i];
                     ^
Main.java:107: error: not a statement
        cout << mcf.mcf(n*2,n*2+1,n) << endl;
                                     ^
Main.java:96: error: ';' expected
        MCF mcf(n*2+2);
               ^
Main.java:96: error: ';' expected
        MCF mcf(n*2+2);
                     ^
Main.java:97: error: ']' expected
        int p[111];
              ^
Main.java:98: error: ';' expected
        rep(i,n) cin >> p[i];
                ^
Main.java:99: error: ';' expected
        rep(i,n){
                ^
Main.java:103: error: ';' expected
        rep(i,n)rep(j,n)if(i!=j){
                ^
Main.java:103: error: ';' expected
        rep(i,n)rep(j,n)if(i!=j){
                        ^
60 errors