// https://en.wikipedia.org/wiki/Dinic%27s_algorithm in O(V^2 * E)
class MaxFlowDinic(nodes: Int) {

    data class Edge(val t: Int, val rev: Int, val cap: Int, var f: Int = 0)

    val graph = (1..nodes).map { arrayListOf<Edge>() }.toTypedArray()
    val dist = IntArray(nodes)

    fun addBidiEdge(s: Int, t: Int, cap: Int) {
        graph[s].add(Edge(t, graph[t].size, cap))
        graph[t].add(Edge(s, graph[s].size - 1, 0))
    }

    fun dinicBfs(src: Int, dest: Int, dist: IntArray): Boolean {
        dist.fill(-1)
        dist[src] = 0
        val q = IntArray(graph.size)
        var sizeQ = 0
        q[sizeQ++] = src
        var i = 0
        while (i < sizeQ) {
            val u = q[i++]
            for (e in graph[u]) {
                if (dist[e.t] < 0 && e.f < e.cap) {
                    dist[e.t] = dist[u] + 1
                    q[sizeQ++] = e.t
                }
            }
        }
        return dist[dest] >= 0
    }

    fun dinicDfs(ptr: IntArray, dest: Int, u: Int, f: Int): Int {
        if (u == dest)
            return f
        while (ptr[u] < graph[u].size) {
            val e = graph[u][ptr[u]]
            if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {
                val df = dinicDfs(ptr, dest, e.t, Math.min(f, e.cap - e.f))
                if (df > 0) {
                    e.f += df
                    graph[e.t][e.rev].f -= df
                    return df
                }
            }
            ++ptr[u]
        }
        return 0
    }

    fun maxFlow(src: Int, dest: Int): Int {
        var flow = 0
        while (dinicBfs(src, dest, dist)) {
            val ptr = IntArray(graph.size)
            while (true) {
                val df = dinicDfs(ptr, dest, src, Int.MAX_VALUE)
                if (df == 0)
                    break
                flow += df
            }
        }
        return flow
    }

    // invoke after maxFlow()
    fun minCut() = dist.map { it != -1 }.toBooleanArray()

    fun clearFlow() {
        for (edges in graph)
            for (edge in edges)
                edge.f = 0
    }
}

// Usage example
fun main(args: Array<String>) {
    val flow = MaxFlowDinic(3)
    flow.addBidiEdge(0, 1, 3)
    flow.addBidiEdge(0, 2, 2)
    flow.addBidiEdge(1, 2, 2)
    println(4 == flow.maxFlow(0, 2))
}

Compiled from "MaxFlowDinic.kt"
public final class MaxFlowDinicKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #17                 // class MaxFlowDinic
       9: dup
      10: iconst_3
      11: invokespecial #21                 // Method MaxFlowDinic."<init>":(I)V
      14: astore_1
      15: aload_1
      16: iconst_0
      17: iconst_1
      18: iconst_3
      19: invokevirtual #25                 // Method MaxFlowDinic.addBidiEdge:(III)V
      22: aload_1
      23: iconst_0
      24: iconst_2
      25: iconst_2
      26: invokevirtual #25                 // Method MaxFlowDinic.addBidiEdge:(III)V
      29: aload_1
      30: iconst_1
      31: iconst_2
      32: iconst_2
      33: invokevirtual #25                 // Method MaxFlowDinic.addBidiEdge:(III)V
      36: iconst_4
      37: aload_1
      38: iconst_0
      39: iconst_2
      40: invokevirtual #29                 // Method MaxFlowDinic.maxFlow:(II)I
      43: if_icmpne     50
      46: iconst_1
      47: goto          51
      50: iconst_0
      51: istore_2
      52: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      55: iload_2
      56: invokevirtual #41                 // Method java/io/PrintStream.println:(Z)V
      59: return
}

Compiled from "MaxFlowDinic.kt"
public final class MaxFlowDinic$Edge {
  private final int t;

  private final int rev;

  private final int cap;

  private int f;

  public MaxFlowDinic$Edge(int, int, int, int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field t:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field rev:I
      14: aload_0
      15: iload_3
      16: putfield      #19                 // Field cap:I
      19: aload_0
      20: iload         4
      22: putfield      #22                 // Field f:I
      25: return

  public MaxFlowDinic$Edge(int, int, int, int, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload         5
       2: bipush        8
       4: iand
       5: ifeq          11
       8: iconst_0
       9: istore        4
      11: aload_0
      12: iload_1
      13: iload_2
      14: iload_3
      15: iload         4
      17: invokespecial #27                 // Method "<init>":(IIII)V
      20: return

  public final int getT();
    Code:
       0: aload_0
       1: getfield      #13                 // Field t:I
       4: ireturn

  public final int getRev();
    Code:
       0: aload_0
       1: getfield      #16                 // Field rev:I
       4: ireturn

  public final int getCap();
    Code:
       0: aload_0
       1: getfield      #19                 // Field cap:I
       4: ireturn

  public final int getF();
    Code:
       0: aload_0
       1: getfield      #22                 // Field f:I
       4: ireturn

  public final void setF(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #22                 // Field f:I
       5: return

  public final int component1();
    Code:
       0: aload_0
       1: getfield      #13                 // Field t:I
       4: ireturn

  public final int component2();
    Code:
       0: aload_0
       1: getfield      #16                 // Field rev:I
       4: ireturn

  public final int component3();
    Code:
       0: aload_0
       1: getfield      #19                 // Field cap:I
       4: ireturn

  public final int component4();
    Code:
       0: aload_0
       1: getfield      #22                 // Field f:I
       4: ireturn

  public final MaxFlowDinic$Edge copy(int, int, int, int);
    Code:
       0: new           #2                  // class MaxFlowDinic$Edge
       3: dup
       4: iload_1
       5: iload_2
       6: iload_3
       7: iload         4
       9: invokespecial #27                 // Method "<init>":(IIII)V
      12: areturn

  public static MaxFlowDinic$Edge copy$default(MaxFlowDinic$Edge, int, int, int, int, int, java.lang.Object);
    Code:
       0: iload         5
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #13                 // Field t:I
      11: istore_1
      12: iload         5
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #16                 // Field rev:I
      23: istore_2
      24: iload         5
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #19                 // Field cap:I
      35: istore_3
      36: iload         5
      38: bipush        8
      40: iand
      41: ifeq          50
      44: aload_0
      45: getfield      #22                 // Field f:I
      48: istore        4
      50: aload_0
      51: iload_1
      52: iload_2
      53: iload_3
      54: iload         4
      56: invokevirtual #46                 // Method copy:(IIII)LMaxFlowDinic$Edge;
      59: areturn

  public java.lang.String toString();
    Code:
       0: new           #50                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #51                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #53                 // String Edge(t=
       9: invokevirtual #57                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field t:I
      16: invokevirtual #60                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #62                 // String , rev=
      21: invokevirtual #57                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field rev:I
      28: invokevirtual #60                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: ldc           #64                 // String , cap=
      33: invokevirtual #57                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #19                 // Field cap:I
      40: invokevirtual #60                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      43: ldc           #66                 // String , f=
      45: invokevirtual #57                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      48: aload_0
      49: getfield      #22                 // Field f:I
      52: invokevirtual #60                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      55: bipush        41
      57: invokevirtual #69                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      60: invokevirtual #71                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      63: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field t:I
       4: invokestatic  #77                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #16                 // Field rev:I
      16: invokestatic  #77                 // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #19                 // Field cap:I
      29: invokestatic  #77                 // Method java/lang/Integer.hashCode:(I)I
      32: iadd
      33: istore_1
      34: iload_1
      35: bipush        31
      37: imul
      38: aload_0
      39: getfield      #22                 // Field f:I
      42: invokestatic  #77                 // Method java/lang/Integer.hashCode:(I)I
      45: iadd
      46: istore_1
      47: iload_1
      48: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class MaxFlowDinic$Edge
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class MaxFlowDinic$Edge
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field t:I
      25: aload_2
      26: getfield      #13                 // Field t:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field rev:I
      38: aload_2
      39: getfield      #16                 // Field rev:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: aload_0
      48: getfield      #19                 // Field cap:I
      51: aload_2
      52: getfield      #19                 // Field cap:I
      55: if_icmpeq     60
      58: iconst_0
      59: ireturn
      60: aload_0
      61: getfield      #22                 // Field f:I
      64: aload_2
      65: getfield      #22                 // Field f:I
      68: if_icmpeq     73
      71: iconst_0
      72: ireturn
      73: iconst_1
      74: ireturn
}

Compiled from "MaxFlowDinic.kt"
public final class MaxFlowDinic {
  private final java.util.ArrayList<MaxFlowDinic$Edge>[] graph;

  private final int[] dist;

  public MaxFlowDinic(int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: new           #11                 // class kotlin/ranges/IntRange
       8: dup
       9: iconst_1
      10: iload_1
      11: invokespecial #14                 // Method kotlin/ranges/IntRange."<init>":(II)V
      14: checkcast     #16                 // class java/lang/Iterable
      17: astore_2
      18: astore        11
      20: iconst_0
      21: istore_3
      22: aload_2
      23: astore        4
      25: new           #18                 // class java/util/ArrayList
      28: dup
      29: aload_2
      30: bipush        10
      32: invokestatic  #24                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      35: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
      38: checkcast     #28                 // class java/util/Collection
      41: astore        5
      43: iconst_0
      44: istore        6
      46: aload         4
      48: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      53: astore        7
      55: aload         7
      57: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          106
      65: aload         7
      67: checkcast     #40                 // class kotlin/collections/IntIterator
      70: invokevirtual #44                 // Method kotlin/collections/IntIterator.nextInt:()I
      73: istore        8
      75: aload         5
      77: iload         8
      79: istore        9
      81: astore        12
      83: iconst_0
      84: istore        10
      86: new           #18                 // class java/util/ArrayList
      89: dup
      90: invokespecial #45                 // Method java/util/ArrayList."<init>":()V
      93: nop
      94: aload         12
      96: swap
      97: invokeinterface #49,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     102: pop
     103: goto          55
     106: aload         5
     108: checkcast     #51                 // class java/util/List
     111: nop
     112: aload         11
     114: swap
     115: checkcast     #28                 // class java/util/Collection
     118: astore_2
     119: nop
     120: iconst_0
     121: istore_3
     122: aload_2
     123: astore        4
     125: aload         4
     127: iconst_0
     128: anewarray     #18                 // class java/util/ArrayList
     131: invokeinterface #55,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     136: checkcast     #57                 // class "[Ljava/util/ArrayList;"
     139: putfield      #60                 // Field graph:[Ljava/util/ArrayList;
     142: aload_0
     143: iload_1
     144: newarray       int
     146: putfield      #64                 // Field dist:[I
     149: return

  public final java.util.ArrayList<MaxFlowDinic$Edge>[] getGraph();
    Code:
       0: aload_0
       1: getfield      #60                 // Field graph:[Ljava/util/ArrayList;
       4: areturn

  public final int[] getDist();
    Code:
       0: aload_0
       1: getfield      #64                 // Field dist:[I
       4: areturn

  public final void addBidiEdge(int, int, int);
    Code:
       0: aload_0
       1: getfield      #60                 // Field graph:[Ljava/util/ArrayList;
       4: iload_1
       5: aaload
       6: new           #91                 // class MaxFlowDinic$Edge
       9: dup
      10: iload_2
      11: aload_0
      12: getfield      #60                 // Field graph:[Ljava/util/ArrayList;
      15: iload_2
      16: aaload
      17: invokevirtual #94                 // Method java/util/ArrayList.size:()I
      20: iload_3
      21: iconst_0
      22: bipush        8
      24: aconst_null
      25: invokespecial #97                 // Method MaxFlowDinic$Edge."<init>":(IIIIILkotlin/jvm/internal/DefaultConstructorMarker;)V
      28: invokevirtual #98                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      31: pop
      32: aload_0
      33: getfield      #60                 // Field graph:[Ljava/util/ArrayList;
      36: iload_2
      37: aaload
      38: new           #91                 // class MaxFlowDinic$Edge
      41: dup
      42: iload_1
      43: aload_0
      44: getfield      #60                 // Field graph:[Ljava/util/ArrayList;
      47: iload_1
      48: aaload
      49: invokevirtual #94                 // Method java/util/ArrayList.size:()I
      52: iconst_1
      53: isub
      54: iconst_0
      55: iconst_0
      56: bipush        8
      58: aconst_null
      59: invokespecial #97                 // Method MaxFlowDinic$Edge."<init>":(IIIIILkotlin/jvm/internal/DefaultConstructorMarker;)V
      62: invokevirtual #98                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      65: pop
      66: return

  public final boolean dinicBfs(int, int, int[]);
    Code:
       0: aload_3
       1: ldc           #104                // String dist
       3: invokestatic  #110                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_3
       7: iconst_m1
       8: iconst_0
       9: iconst_0
      10: bipush        6
      12: aconst_null
      13: invokestatic  #116                // Method kotlin/collections/ArraysKt.fill$default:([IIIIILjava/lang/Object;)V
      16: aload_3
      17: iload_1
      18: iconst_0
      19: iastore
      20: aload_0
      21: getfield      #60                 // Field graph:[Ljava/util/ArrayList;
      24: arraylength
      25: newarray       int
      27: astore        4
      29: iconst_0
      30: istore        5
      32: aload         4
      34: iload         5
      36: iinc          5, 1
      39: iload_1
      40: iastore
      41: iconst_0
      42: istore        6
      44: iload         6
      46: iload         5
      48: if_icmpge     159
      51: aload         4
      53: iload         6
      55: iinc          6, 1
      58: iaload
      59: istore        7
      61: aload_0
      62: getfield      #60                 // Field graph:[Ljava/util/ArrayList;
      65: iload         7
      67: aaload
      68: invokevirtual #117                // Method java/util/ArrayList.iterator:()Ljava/util/Iterator;
      71: dup
      72: ldc           #119                // String iterator(...)
      74: invokestatic  #122                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      77: astore        8
      79: aload         8
      81: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      86: ifeq          44
      89: aload         8
      91: invokeinterface #126,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      96: dup
      97: ldc           #128                // String next(...)
      99: invokestatic  #122                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     102: checkcast     #91                 // class MaxFlowDinic$Edge
     105: astore        9
     107: aload_3
     108: aload         9
     110: invokevirtual #131                // Method MaxFlowDinic$Edge.getT:()I
     113: iaload
     114: ifge          79
     117: aload         9
     119: invokevirtual #134                // Method MaxFlowDinic$Edge.getF:()I
     122: aload         9
     124: invokevirtual #137                // Method MaxFlowDinic$Edge.getCap:()I
     127: if_icmpge     79
     130: aload_3
     131: aload         9
     133: invokevirtual #131                // Method MaxFlowDinic$Edge.getT:()I
     136: aload_3
     137: iload         7
     139: iaload
     140: iconst_1
     141: iadd
     142: iastore
     143: aload         4
     145: iload         5
     147: iinc          5, 1
     150: aload         9
     152: invokevirtual #131                // Method MaxFlowDinic$Edge.getT:()I
     155: iastore
     156: goto          79
     159: aload_3
     160: iload_2
     161: iaload
     162: iflt          169
     165: iconst_1
     166: goto          170
     169: iconst_0
     170: ireturn

  public final int dinicDfs(int[], int, int, int);
    Code:
       0: aload_1
       1: ldc           #150                // String ptr
       3: invokestatic  #110                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_3
       7: iload_2
       8: if_icmpne     14
      11: iload         4
      13: ireturn
      14: aload_1
      15: iload_3
      16: iaload
      17: aload_0
      18: getfield      #60                 // Field graph:[Ljava/util/ArrayList;
      21: iload_3
      22: aaload
      23: invokevirtual #94                 // Method java/util/ArrayList.size:()I
      26: if_icmpge     187
      29: aload_0
      30: getfield      #60                 // Field graph:[Ljava/util/ArrayList;
      33: iload_3
      34: aaload
      35: aload_1
      36: iload_3
      37: iaload
      38: invokevirtual #154                // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
      41: dup
      42: ldc           #156                // String get(...)
      44: invokestatic  #122                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      47: checkcast     #91                 // class MaxFlowDinic$Edge
      50: astore        5
      52: aload_0
      53: getfield      #64                 // Field dist:[I
      56: aload         5
      58: invokevirtual #131                // Method MaxFlowDinic$Edge.getT:()I
      61: iaload
      62: aload_0
      63: getfield      #64                 // Field dist:[I
      66: iload_3
      67: iaload
      68: iconst_1
      69: iadd
      70: if_icmpne     172
      73: aload         5
      75: invokevirtual #134                // Method MaxFlowDinic$Edge.getF:()I
      78: aload         5
      80: invokevirtual #137                // Method MaxFlowDinic$Edge.getCap:()I
      83: if_icmpge     172
      86: aload_0
      87: aload_1
      88: iload_2
      89: aload         5
      91: invokevirtual #131                // Method MaxFlowDinic$Edge.getT:()I
      94: iload         4
      96: aload         5
      98: invokevirtual #137                // Method MaxFlowDinic$Edge.getCap:()I
     101: aload         5
     103: invokevirtual #134                // Method MaxFlowDinic$Edge.getF:()I
     106: isub
     107: invokestatic  #162                // Method java/lang/Math.min:(II)I
     110: invokevirtual #164                // Method dinicDfs:([IIII)I
     113: istore        6
     115: iload         6
     117: ifle          172
     120: aload         5
     122: aload         5
     124: invokevirtual #134                // Method MaxFlowDinic$Edge.getF:()I
     127: iload         6
     129: iadd
     130: invokevirtual #167                // Method MaxFlowDinic$Edge.setF:(I)V
     133: aload_0
     134: getfield      #60                 // Field graph:[Ljava/util/ArrayList;
     137: aload         5
     139: invokevirtual #131                // Method MaxFlowDinic$Edge.getT:()I
     142: aaload
     143: aload         5
     145: invokevirtual #170                // Method MaxFlowDinic$Edge.getRev:()I
     148: invokevirtual #154                // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     151: checkcast     #91                 // class MaxFlowDinic$Edge
     154: astore        7
     156: aload         7
     158: aload         7
     160: invokevirtual #134                // Method MaxFlowDinic$Edge.getF:()I
     163: iload         6
     165: isub
     166: invokevirtual #167                // Method MaxFlowDinic$Edge.setF:(I)V
     169: iload         6
     171: ireturn
     172: aload_1
     173: iload_3
     174: aload_1
     175: iload_3
     176: iaload
     177: iconst_1
     178: iadd
     179: iastore
     180: aload_1
     181: iload_3
     182: iaload
     183: pop
     184: goto          14
     187: iconst_0
     188: ireturn

  public final int maxFlow(int, int);
    Code:
       0: iconst_0
       1: istore_3
       2: aload_0
       3: iload_1
       4: iload_2
       5: aload_0
       6: getfield      #64                 // Field dist:[I
       9: invokevirtual #175                // Method dinicBfs:(II[I)Z
      12: ifeq          53
      15: aload_0
      16: getfield      #60                 // Field graph:[Ljava/util/ArrayList;
      19: arraylength
      20: newarray       int
      22: astore        4
      24: nop
      25: aload_0
      26: aload         4
      28: iload_2
      29: iload_1
      30: ldc           #176                // int 2147483647
      32: invokevirtual #164                // Method dinicDfs:([IIII)I
      35: istore        5
      37: iload         5
      39: ifne          45
      42: goto          2
      45: iload_3
      46: iload         5
      48: iadd
      49: istore_3
      50: goto          24
      53: iload_3
      54: ireturn

  public final boolean[] minCut();
    Code:
       0: aload_0
       1: getfield      #64                 // Field dist:[I
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #18                 // class java/util/ArrayList
      12: dup
      13: aload_1
      14: arraylength
      15: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
      18: checkcast     #28                 // class java/util/Collection
      21: astore        4
      23: iconst_0
      24: istore        5
      26: iconst_0
      27: istore        6
      29: aload_3
      30: arraylength
      31: istore        7
      33: iload         6
      35: iload         7
      37: if_icmpge     86
      40: aload_3
      41: iload         6
      43: iaload
      44: istore        8
      46: aload         4
      48: iload         8
      50: istore        9
      52: astore        11
      54: iconst_0
      55: istore        10
      57: iload         9
      59: iconst_m1
      60: if_icmpeq     67
      63: iconst_1
      64: goto          68
      67: iconst_0
      68: invokestatic  #185                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      71: aload         11
      73: swap
      74: invokeinterface #49,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      79: pop
      80: iinc          6, 1
      83: goto          33
      86: aload         4
      88: checkcast     #51                 // class java/util/List
      91: nop
      92: checkcast     #28                 // class java/util/Collection
      95: invokestatic  #189                // Method kotlin/collections/CollectionsKt.toBooleanArray:(Ljava/util/Collection;)[Z
      98: areturn

  public final void clearFlow();
    Code:
       0: aload_0
       1: getfield      #60                 // Field graph:[Ljava/util/ArrayList;
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: arraylength
       9: istore_3
      10: iload_2
      11: iload_3
      12: if_icmpge     76
      15: aload_1
      16: iload_2
      17: aaload
      18: astore        4
      20: aload         4
      22: invokevirtual #117                // Method java/util/ArrayList.iterator:()Ljava/util/Iterator;
      25: dup
      26: ldc           #119                // String iterator(...)
      28: invokestatic  #122                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      31: astore        5
      33: aload         5
      35: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      40: ifeq          70
      43: aload         5
      45: invokeinterface #126,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      50: dup
      51: ldc           #128                // String next(...)
      53: invokestatic  #122                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      56: checkcast     #91                 // class MaxFlowDinic$Edge
      59: astore        6
      61: aload         6
      63: iconst_0
      64: invokevirtual #167                // Method MaxFlowDinic$Edge.setF:(I)V
      67: goto          33
      70: iinc          2, 1
      73: goto          10
      76: return
}


import kotlin.math.abs

// https://en.wikipedia.org/wiki/Determinant
fun det(matrix: Array<DoubleArray>): Double {
    val EPS = 1e-10
    val a = matrix.map { it.copyOf() }.toTypedArray()
    val n = a.size
    var res = 1.0
    for (i in 0 until n) {
        val p = (i until n).maxByOrNull { abs(a[it][i]) }!!
        if (abs(a[p][i]) < EPS)
            return 0.0
        if (i != p) {
            res = -res
            a[i] = a[p].also { a[p] = a[i] }
        }
        res *= a[i][i]
        for (j in i + 1 until n)
            a[i][j] /= a[i][i]
        for (j in 0 until n)
            if (j != i && abs(a[j][i]) > EPS /*optimizes overall complexity to O(n^2) for sparse matrices*/)
                for (k in i + 1 until n)
                    a[j][k] -= a[i][k] * a[j][i]
    }
    return res
}

// Usage example
fun main() {
    val d = det(arrayOf(doubleArrayOf(0.0, 1.0), doubleArrayOf(-1.0, 0.0)))
    println(abs(d - 1) < 1e-10)
}

Compiled from "Determinant.kt"
public final class DeterminantKt {
  public static final double det(double[][]);
    Code:
       0: aload_0
       1: ldc           #9                  // String matrix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc2_w        #16                 // double 1.0E-10d
       9: dstore_1
      10: aload_0
      11: checkcast     #19                 // class "[Ljava/lang/Object;"
      14: astore        4
      16: iconst_0
      17: istore        5
      19: aload         4
      21: astore        6
      23: new           #21                 // class java/util/ArrayList
      26: dup
      27: aload         4
      29: arraylength
      30: invokespecial #25                 // Method java/util/ArrayList."<init>":(I)V
      33: checkcast     #27                 // class java/util/Collection
      36: astore        7
      38: iconst_0
      39: istore        8
      41: iconst_0
      42: istore        9
      44: aload         6
      46: arraylength
      47: istore        10
      49: iload         9
      51: iload         10
      53: if_icmpge     106
      56: aload         6
      58: iload         9
      60: aaload
      61: astore        11
      63: aload         7
      65: aload         11
      67: checkcast     #29                 // class "[D"
      70: astore        12
      72: astore        19
      74: iconst_0
      75: istore        13
      77: aload         12
      79: dup
      80: arraylength
      81: invokestatic  #35                 // Method java/util/Arrays.copyOf:([DI)[D
      84: dup
      85: ldc           #37                 // String copyOf(...)
      87: invokestatic  #40                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      90: nop
      91: aload         19
      93: swap
      94: invokeinterface #44,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      99: pop
     100: iinc          9, 1
     103: goto          49
     106: aload         7
     108: checkcast     #46                 // class java/util/List
     111: nop
     112: checkcast     #27                 // class java/util/Collection
     115: astore        4
     117: nop
     118: iconst_0
     119: istore        5
     121: aload         4
     123: astore        6
     125: aload         6
     127: iconst_0
     128: anewarray     #29                 // class "[D"
     131: invokeinterface #50,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     136: checkcast     #52                 // class "[[D"
     139: astore_3
     140: aload_3
     141: checkcast     #19                 // class "[Ljava/lang/Object;"
     144: arraylength
     145: istore        4
     147: dconst_1
     148: dstore        5
     150: iconst_0
     151: istore        7
     153: iload         7
     155: iload         4
     157: if_icmpge     552
     160: iload         7
     162: iload         4
     164: invokestatic  #58                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     167: checkcast     #60                 // class java/lang/Iterable
     170: astore        9
     172: iconst_0
     173: istore        10
     175: aload         9
     177: invokeinterface #64,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     182: astore        11
     184: aload         11
     186: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     191: ifne          198
     194: aconst_null
     195: goto          313
     198: aload         11
     200: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     205: astore        12
     207: aload         11
     209: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     214: ifne          222
     217: aload         12
     219: goto          313
     222: aload         12
     224: checkcast     #76                 // class java/lang/Number
     227: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     230: istore        13
     232: iconst_0
     233: istore        15
     235: aload_3
     236: iload         13
     238: aaload
     239: iload         7
     241: daload
     242: invokestatic  #86                 // Method java/lang/Math.abs:(D)D
     245: nop
     246: dstore        13
     248: aload         11
     250: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     255: astore        15
     257: aload         15
     259: checkcast     #76                 // class java/lang/Number
     262: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     265: istore        16
     267: iconst_0
     268: istore        18
     270: aload_3
     271: iload         16
     273: aaload
     274: iload         7
     276: daload
     277: invokestatic  #86                 // Method java/lang/Math.abs:(D)D
     280: nop
     281: dstore        16
     283: dload         13
     285: dload         16
     287: invokestatic  #92                 // Method java/lang/Double.compare:(DD)I
     290: ifge          301
     293: aload         15
     295: astore        12
     297: dload         16
     299: dstore        13
     301: aload         11
     303: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     308: ifne          248
     311: aload         12
     313: dup
     314: invokestatic  #96                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     317: checkcast     #76                 // class java/lang/Number
     320: invokevirtual #80                 // Method java/lang/Number.intValue:()I
     323: istore        8
     325: aload_3
     326: iload         8
     328: aaload
     329: iload         7
     331: daload
     332: invokestatic  #86                 // Method java/lang/Math.abs:(D)D
     335: dload_1
     336: dcmpg
     337: ifge          342
     340: dconst_0
     341: dreturn
     342: iload         7
     344: iload         8
     346: if_icmpeq     394
     349: dload         5
     351: dneg
     352: dstore        5
     354: aload_3
     355: iload         7
     357: aload_3
     358: iload         8
     360: aaload
     361: astore        9
     363: aload         9
     365: astore        10
     367: istore        20
     369: astore        19
     371: iconst_0
     372: istore        11
     374: aload_3
     375: iload         8
     377: aload_3
     378: iload         7
     380: aaload
     381: aastore
     382: getstatic     #102                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     385: astore        21
     387: aload         19
     389: iload         20
     391: aload         9
     393: aastore
     394: dload         5
     396: aload_3
     397: iload         7
     399: aaload
     400: iload         7
     402: daload
     403: dmul
     404: dstore        5
     406: iload         7
     408: iconst_1
     409: iadd
     410: istore        9
     412: iload         9
     414: iload         4
     416: if_icmpge     453
     419: aload_3
     420: iload         7
     422: aaload
     423: astore        10
     425: iload         9
     427: istore        11
     429: aload         10
     431: iload         11
     433: aload         10
     435: iload         11
     437: daload
     438: aload_3
     439: iload         7
     441: aaload
     442: iload         7
     444: daload
     445: ddiv
     446: dastore
     447: iinc          9, 1
     450: goto          412
     453: iconst_0
     454: istore        9
     456: iload         9
     458: iload         4
     460: if_icmpge     546
     463: iload         9
     465: iload         7
     467: if_icmpeq     540
     470: aload_3
     471: iload         9
     473: aaload
     474: iload         7
     476: daload
     477: invokestatic  #86                 // Method java/lang/Math.abs:(D)D
     480: dload_1
     481: dcmpl
     482: ifle          540
     485: iload         7
     487: iconst_1
     488: iadd
     489: istore        10
     491: iload         10
     493: iload         4
     495: if_icmpge     540
     498: aload_3
     499: iload         9
     501: aaload
     502: astore        11
     504: iload         10
     506: istore        12
     508: aload         11
     510: iload         12
     512: aload         11
     514: iload         12
     516: daload
     517: aload_3
     518: iload         7
     520: aaload
     521: iload         10
     523: daload
     524: aload_3
     525: iload         9
     527: aaload
     528: iload         7
     530: daload
     531: dmul
     532: dsub
     533: dastore
     534: iinc          10, 1
     537: goto          491
     540: iinc          9, 1
     543: goto          456
     546: iinc          7, 1
     549: goto          153
     552: dload         5
     554: dreturn

  public static final void main();
    Code:
       0: iconst_2
       1: anewarray     #29                 // class "[D"
       4: astore_2
       5: aload_2
       6: iconst_0
       7: iconst_2
       8: newarray       double
      10: astore_3
      11: aload_3
      12: iconst_0
      13: dconst_0
      14: dastore
      15: aload_3
      16: iconst_1
      17: dconst_1
      18: dastore
      19: aload_3
      20: aastore
      21: aload_2
      22: iconst_1
      23: iconst_2
      24: newarray       double
      26: astore_3
      27: aload_3
      28: iconst_0
      29: ldc2_w        #139                // double -1.0d
      32: dastore
      33: aload_3
      34: iconst_1
      35: dconst_0
      36: dastore
      37: aload_3
      38: aastore
      39: aload_2
      40: invokestatic  #142                // Method det:([[D)D
      43: dstore_0
      44: dload_0
      45: iconst_1
      46: i2d
      47: dsub
      48: invokestatic  #86                 // Method java/lang/Math.abs:(D)D
      51: ldc2_w        #16                 // double 1.0E-10d
      54: dcmpg
      55: ifge          62
      58: iconst_1
      59: goto          63
      62: iconst_0
      63: istore_2
      64: getstatic     #148                // Field java/lang/System.out:Ljava/io/PrintStream;
      67: iload_2
      68: invokevirtual #154                // Method java/io/PrintStream.println:(Z)V
      71: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #158                // Method main:()V
       3: return
}


import java.math.BigInteger

class Rational(n: BigInteger, d: BigInteger = BigInteger.ONE) : Comparable<Rational> {
    val num: BigInteger
    val den: BigInteger

    init {
        val gcd = n.gcd(d)
        val g = if (d.signum() > 0) gcd else if (d.signum() < 0) gcd.negate() else BigInteger.ONE
        num = n.divide(g)
        den = d.divide(g)
    }

    constructor(num: Long, den: Long = 1) : this(BigInteger.valueOf(num), BigInteger.valueOf(den))

    operator fun plus(r: Rational): Rational = Rational(num.multiply(r.den).add(r.num.multiply(den)), den.multiply(r.den))

    operator fun minus(r: Rational): Rational = Rational(num.multiply(r.den).subtract(r.num.multiply(den)), den.multiply(r.den))

    operator fun times(r: Rational): Rational = Rational(num.multiply(r.num), den.multiply(r.den))

    operator fun div(r: Rational): Rational = Rational(num.multiply(r.den), den.multiply(r.num))

    operator fun unaryMinus(): Rational = Rational(num.negate(), den)

    fun inverse(): Rational = Rational(den, num)

    fun abs(): Rational = Rational(num.abs(), den)

    fun signum(): Int = num.signum()

    fun doubleValue(): Double = num.toDouble() / den.toDouble()

    fun longValue(): Long = num.toLong() / den.toLong()

    override fun compareTo(other: Rational): Int = num.multiply(other.den).compareTo(other.num.multiply(den))

    override fun equals(other: Any?): Boolean = num == (other as Rational).num && den == other.den

    override fun hashCode(): Int = num.hashCode() * 31 + den.hashCode()

    override fun toString(): String = "$num/$den"

    companion object {
        val ZERO = Rational(0)
        val ONE = Rational(1)
        val POSITIVE_INFINITY = Rational(1, 0)
        val NEGATIVE_INFINITY = Rational(-1, 0)
    }
}

// Usage example
fun main() {
    val a = Rational(1, 3)
    val b = Rational(1, 6)
    val s1 = Rational(1, 2)
    val s2 = a + b
    println(true == (s1 == s2))
    println(a * b / b - a)
    println(a * Rational.ZERO)
}

Compiled from "Rational.kt"
public final class RationalKt {
  public static final void main();
    Code:
       0: new           #8                  // class Rational
       3: dup
       4: lconst_1
       5: ldc2_w        #9                  // long 3l
       8: invokespecial #14                 // Method Rational."<init>":(JJ)V
      11: astore_0
      12: new           #8                  // class Rational
      15: dup
      16: lconst_1
      17: ldc2_w        #15                 // long 6l
      20: invokespecial #14                 // Method Rational."<init>":(JJ)V
      23: astore_1
      24: new           #8                  // class Rational
      27: dup
      28: lconst_1
      29: ldc2_w        #17                 // long 2l
      32: invokespecial #14                 // Method Rational."<init>":(JJ)V
      35: astore_2
      36: aload_0
      37: aload_1
      38: invokevirtual #22                 // Method Rational.plus:(LRational;)LRational;
      41: astore_3
      42: iconst_1
      43: aload_2
      44: aload_3
      45: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      48: if_icmpne     55
      51: iconst_1
      52: goto          56
      55: iconst_0
      56: istore        4
      58: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      61: iload         4
      63: invokevirtual #40                 // Method java/io/PrintStream.println:(Z)V
      66: aload_0
      67: aload_1
      68: invokevirtual #43                 // Method Rational.times:(LRational;)LRational;
      71: aload_1
      72: invokevirtual #46                 // Method Rational.div:(LRational;)LRational;
      75: aload_0
      76: invokevirtual #49                 // Method Rational.minus:(LRational;)LRational;
      79: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      82: swap
      83: invokevirtual #52                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      86: aload_0
      87: getstatic     #56                 // Field Rational.Companion:LRational$Companion;
      90: invokevirtual #62                 // Method Rational$Companion.getZERO:()LRational;
      93: invokevirtual #43                 // Method Rational.times:(LRational;)LRational;
      96: getstatic     #34                 // Field java/lang/System.out:Ljava/io/PrintStream;
      99: swap
     100: invokevirtual #52                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     103: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #70                 // Method main:()V
       3: return
}

Compiled from "Rational.kt"
public final class Rational$Companion {
  private Rational$Companion();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final Rational getZERO();
    Code:
       0: invokestatic  #18                 // Method Rational.access$getZERO$cp:()LRational;
       3: areturn

  public final Rational getONE();
    Code:
       0: invokestatic  #22                 // Method Rational.access$getONE$cp:()LRational;
       3: areturn

  public final Rational getPOSITIVE_INFINITY();
    Code:
       0: invokestatic  #26                 // Method Rational.access$getPOSITIVE_INFINITY$cp:()LRational;
       3: areturn

  public final Rational getNEGATIVE_INFINITY();
    Code:
       0: invokestatic  #30                 // Method Rational.access$getNEGATIVE_INFINITY$cp:()LRational;
       3: areturn

  public Rational$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #32                 // Method "<init>":()V
       4: return
}

Compiled from "Rational.kt"
public final class Rational implements java.lang.Comparable<Rational> {
  public static final Rational$Companion Companion;

  private final java.math.BigInteger num;

  private final java.math.BigInteger den;

  private static final Rational ZERO;

  private static final Rational ONE;

  private static final Rational POSITIVE_INFINITY;

  private static final Rational NEGATIVE_INFINITY;

  public Rational(java.math.BigInteger, java.math.BigInteger);
    Code:
       0: aload_1
       1: ldc           #12                 // String n
       3: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #20                 // String d
       9: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #23                 // Method java/lang/Object."<init>":()V
      16: nop
      17: aload_1
      18: aload_2
      19: invokevirtual #29                 // Method java/math/BigInteger.gcd:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      22: astore_3
      23: aload_2
      24: invokevirtual #33                 // Method java/math/BigInteger.signum:()I
      27: ifle          34
      30: aload_3
      31: goto          51
      34: aload_2
      35: invokevirtual #33                 // Method java/math/BigInteger.signum:()I
      38: ifge          48
      41: aload_3
      42: invokevirtual #37                 // Method java/math/BigInteger.negate:()Ljava/math/BigInteger;
      45: goto          51
      48: getstatic     #41                 // Field java/math/BigInteger.ONE:Ljava/math/BigInteger;
      51: astore        4
      53: aload_0
      54: aload_1
      55: aload         4
      57: invokevirtual #44                 // Method java/math/BigInteger.divide:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      60: dup
      61: ldc           #46                 // String divide(...)
      63: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      66: putfield      #52                 // Field num:Ljava/math/BigInteger;
      69: aload_0
      70: aload_2
      71: aload         4
      73: invokevirtual #44                 // Method java/math/BigInteger.divide:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      76: dup
      77: ldc           #46                 // String divide(...)
      79: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      82: putfield      #55                 // Field den:Ljava/math/BigInteger;
      85: nop
      86: return

  public Rational(java.math.BigInteger, java.math.BigInteger, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          10
       6: getstatic     #41                 // Field java/math/BigInteger.ONE:Ljava/math/BigInteger;
       9: astore_2
      10: aload_0
      11: aload_1
      12: aload_2
      13: invokespecial #61                 // Method "<init>":(Ljava/math/BigInteger;Ljava/math/BigInteger;)V
      16: return

  public final java.math.BigInteger getNum();
    Code:
       0: aload_0
       1: getfield      #52                 // Field num:Ljava/math/BigInteger;
       4: areturn

  public final java.math.BigInteger getDen();
    Code:
       0: aload_0
       1: getfield      #55                 // Field den:Ljava/math/BigInteger;
       4: areturn

  public Rational(long, long);
    Code:
       0: aload_0
       1: lload_1
       2: invokestatic  #68                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
       5: dup
       6: ldc           #70                 // String valueOf(...)
       8: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      11: lload_3
      12: invokestatic  #68                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
      15: dup
      16: ldc           #70                 // String valueOf(...)
      18: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      21: invokespecial #61                 // Method "<init>":(Ljava/math/BigInteger;Ljava/math/BigInteger;)V
      24: return

  public Rational(long, long, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload         5
       2: iconst_2
       3: iand
       4: ifeq          9
       7: lconst_1
       8: lstore_3
       9: aload_0
      10: lload_1
      11: lload_3
      12: invokespecial #74                 // Method "<init>":(JJ)V
      15: return

  public final Rational plus(Rational);
    Code:
       0: aload_1
       1: ldc           #78                 // String r
       3: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #2                  // class Rational
       9: dup
      10: aload_0
      11: getfield      #52                 // Field num:Ljava/math/BigInteger;
      14: aload_1
      15: getfield      #55                 // Field den:Ljava/math/BigInteger;
      18: invokevirtual #81                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      21: aload_1
      22: getfield      #52                 // Field num:Ljava/math/BigInteger;
      25: aload_0
      26: getfield      #55                 // Field den:Ljava/math/BigInteger;
      29: invokevirtual #81                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      32: invokevirtual #84                 // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      35: dup
      36: ldc           #86                 // String add(...)
      38: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      41: aload_0
      42: getfield      #55                 // Field den:Ljava/math/BigInteger;
      45: aload_1
      46: getfield      #55                 // Field den:Ljava/math/BigInteger;
      49: invokevirtual #81                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      52: dup
      53: ldc           #88                 // String multiply(...)
      55: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      58: invokespecial #61                 // Method "<init>":(Ljava/math/BigInteger;Ljava/math/BigInteger;)V
      61: areturn

  public final Rational minus(Rational);
    Code:
       0: aload_1
       1: ldc           #78                 // String r
       3: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #2                  // class Rational
       9: dup
      10: aload_0
      11: getfield      #52                 // Field num:Ljava/math/BigInteger;
      14: aload_1
      15: getfield      #55                 // Field den:Ljava/math/BigInteger;
      18: invokevirtual #81                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      21: aload_1
      22: getfield      #52                 // Field num:Ljava/math/BigInteger;
      25: aload_0
      26: getfield      #55                 // Field den:Ljava/math/BigInteger;
      29: invokevirtual #81                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      32: invokevirtual #92                 // Method java/math/BigInteger.subtract:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      35: dup
      36: ldc           #94                 // String subtract(...)
      38: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      41: aload_0
      42: getfield      #55                 // Field den:Ljava/math/BigInteger;
      45: aload_1
      46: getfield      #55                 // Field den:Ljava/math/BigInteger;
      49: invokevirtual #81                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      52: dup
      53: ldc           #88                 // String multiply(...)
      55: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      58: invokespecial #61                 // Method "<init>":(Ljava/math/BigInteger;Ljava/math/BigInteger;)V
      61: areturn

  public final Rational times(Rational);
    Code:
       0: aload_1
       1: ldc           #78                 // String r
       3: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #2                  // class Rational
       9: dup
      10: aload_0
      11: getfield      #52                 // Field num:Ljava/math/BigInteger;
      14: aload_1
      15: getfield      #52                 // Field num:Ljava/math/BigInteger;
      18: invokevirtual #81                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      21: dup
      22: ldc           #88                 // String multiply(...)
      24: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      27: aload_0
      28: getfield      #55                 // Field den:Ljava/math/BigInteger;
      31: aload_1
      32: getfield      #55                 // Field den:Ljava/math/BigInteger;
      35: invokevirtual #81                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      38: dup
      39: ldc           #88                 // String multiply(...)
      41: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      44: invokespecial #61                 // Method "<init>":(Ljava/math/BigInteger;Ljava/math/BigInteger;)V
      47: areturn

  public final Rational div(Rational);
    Code:
       0: aload_1
       1: ldc           #78                 // String r
       3: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #2                  // class Rational
       9: dup
      10: aload_0
      11: getfield      #52                 // Field num:Ljava/math/BigInteger;
      14: aload_1
      15: getfield      #55                 // Field den:Ljava/math/BigInteger;
      18: invokevirtual #81                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      21: dup
      22: ldc           #88                 // String multiply(...)
      24: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      27: aload_0
      28: getfield      #55                 // Field den:Ljava/math/BigInteger;
      31: aload_1
      32: getfield      #52                 // Field num:Ljava/math/BigInteger;
      35: invokevirtual #81                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      38: dup
      39: ldc           #88                 // String multiply(...)
      41: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      44: invokespecial #61                 // Method "<init>":(Ljava/math/BigInteger;Ljava/math/BigInteger;)V
      47: areturn

  public final Rational unaryMinus();
    Code:
       0: new           #2                  // class Rational
       3: dup
       4: aload_0
       5: getfield      #52                 // Field num:Ljava/math/BigInteger;
       8: invokevirtual #37                 // Method java/math/BigInteger.negate:()Ljava/math/BigInteger;
      11: dup
      12: ldc           #100                // String negate(...)
      14: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      17: aload_0
      18: getfield      #55                 // Field den:Ljava/math/BigInteger;
      21: invokespecial #61                 // Method "<init>":(Ljava/math/BigInteger;Ljava/math/BigInteger;)V
      24: areturn

  public final Rational inverse();
    Code:
       0: new           #2                  // class Rational
       3: dup
       4: aload_0
       5: getfield      #55                 // Field den:Ljava/math/BigInteger;
       8: aload_0
       9: getfield      #52                 // Field num:Ljava/math/BigInteger;
      12: invokespecial #61                 // Method "<init>":(Ljava/math/BigInteger;Ljava/math/BigInteger;)V
      15: areturn

  public final Rational abs();
    Code:
       0: new           #2                  // class Rational
       3: dup
       4: aload_0
       5: getfield      #52                 // Field num:Ljava/math/BigInteger;
       8: invokevirtual #104                // Method java/math/BigInteger.abs:()Ljava/math/BigInteger;
      11: dup
      12: ldc           #106                // String abs(...)
      14: invokestatic  #49                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      17: aload_0
      18: getfield      #55                 // Field den:Ljava/math/BigInteger;
      21: invokespecial #61                 // Method "<init>":(Ljava/math/BigInteger;Ljava/math/BigInteger;)V
      24: areturn

  public final int signum();
    Code:
       0: aload_0
       1: getfield      #52                 // Field num:Ljava/math/BigInteger;
       4: invokevirtual #33                 // Method java/math/BigInteger.signum:()I
       7: ireturn

  public final double doubleValue();
    Code:
       0: aload_0
       1: getfield      #52                 // Field num:Ljava/math/BigInteger;
       4: invokevirtual #110                // Method java/math/BigInteger.doubleValue:()D
       7: aload_0
       8: getfield      #55                 // Field den:Ljava/math/BigInteger;
      11: invokevirtual #110                // Method java/math/BigInteger.doubleValue:()D
      14: ddiv
      15: dreturn

  public final long longValue();
    Code:
       0: aload_0
       1: getfield      #52                 // Field num:Ljava/math/BigInteger;
       4: invokevirtual #114                // Method java/math/BigInteger.longValue:()J
       7: aload_0
       8: getfield      #55                 // Field den:Ljava/math/BigInteger;
      11: invokevirtual #114                // Method java/math/BigInteger.longValue:()J
      14: ldiv
      15: lreturn

  public int compareTo(Rational);
    Code:
       0: aload_1
       1: ldc           #118                // String other
       3: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #52                 // Field num:Ljava/math/BigInteger;
      10: aload_1
      11: getfield      #55                 // Field den:Ljava/math/BigInteger;
      14: invokevirtual #81                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      17: aload_1
      18: getfield      #52                 // Field num:Ljava/math/BigInteger;
      21: aload_0
      22: getfield      #55                 // Field den:Ljava/math/BigInteger;
      25: invokevirtual #81                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      28: invokevirtual #121                // Method java/math/BigInteger.compareTo:(Ljava/math/BigInteger;)I
      31: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: getfield      #52                 // Field num:Ljava/math/BigInteger;
       4: aload_1
       5: ldc           #126                // String null cannot be cast to non-null type <root>.Rational
       7: invokestatic  #129                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
      10: aload_1
      11: checkcast     #2                  // class Rational
      14: getfield      #52                 // Field num:Ljava/math/BigInteger;
      17: invokestatic  #133                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      20: ifeq          44
      23: aload_0
      24: getfield      #55                 // Field den:Ljava/math/BigInteger;
      27: aload_1
      28: checkcast     #2                  // class Rational
      31: getfield      #55                 // Field den:Ljava/math/BigInteger;
      34: invokestatic  #133                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      37: ifeq          44
      40: iconst_1
      41: goto          45
      44: iconst_0
      45: ireturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #52                 // Field num:Ljava/math/BigInteger;
       4: invokevirtual #137                // Method java/math/BigInteger.hashCode:()I
       7: bipush        31
       9: imul
      10: aload_0
      11: getfield      #55                 // Field den:Ljava/math/BigInteger;
      14: invokevirtual #137                // Method java/math/BigInteger.hashCode:()I
      17: iadd
      18: ireturn

  public java.lang.String toString();
    Code:
       0: new           #141                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #142                // Method java/lang/StringBuilder."<init>":()V
       7: aload_0
       8: getfield      #52                 // Field num:Ljava/math/BigInteger;
      11: invokevirtual #146                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      14: bipush        47
      16: invokevirtual #149                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      19: aload_0
      20: getfield      #55                 // Field den:Ljava/math/BigInteger;
      23: invokevirtual #146                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      26: invokevirtual #151                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      29: areturn

  public int compareTo(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #2                  // class Rational
       5: invokevirtual #154                // Method compareTo:(LRational;)I
       8: ireturn

  public static final Rational access$getZERO$cp();
    Code:
       0: getstatic     #158                // Field ZERO:LRational;
       3: areturn

  public static final Rational access$getONE$cp();
    Code:
       0: getstatic     #161                // Field ONE:LRational;
       3: areturn

  public static final Rational access$getPOSITIVE_INFINITY$cp();
    Code:
       0: getstatic     #165                // Field POSITIVE_INFINITY:LRational;
       3: areturn

  public static final Rational access$getNEGATIVE_INFINITY$cp();
    Code:
       0: getstatic     #169                // Field NEGATIVE_INFINITY:LRational;
       3: areturn

  static {};
    Code:
       0: new           #172                // class Rational$Companion
       3: dup
       4: aconst_null
       5: invokespecial #175                // Method Rational$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #179                // Field Companion:LRational$Companion;
      11: new           #2                  // class Rational
      14: dup
      15: lconst_0
      16: lconst_0
      17: iconst_2
      18: aconst_null
      19: invokespecial #181                // Method "<init>":(JJILkotlin/jvm/internal/DefaultConstructorMarker;)V
      22: putstatic     #158                // Field ZERO:LRational;
      25: new           #2                  // class Rational
      28: dup
      29: lconst_1
      30: lconst_0
      31: iconst_2
      32: aconst_null
      33: invokespecial #181                // Method "<init>":(JJILkotlin/jvm/internal/DefaultConstructorMarker;)V
      36: putstatic     #161                // Field ONE:LRational;
      39: new           #2                  // class Rational
      42: dup
      43: lconst_1
      44: lconst_0
      45: invokespecial #74                 // Method "<init>":(JJ)V
      48: putstatic     #165                // Field POSITIVE_INFINITY:LRational;
      51: new           #2                  // class Rational
      54: dup
      55: ldc2_w        #182                // long -1l
      58: lconst_0
      59: invokespecial #74                 // Method "<init>":(JJ)V
      62: putstatic     #169                // Field NEGATIVE_INFINITY:LRational;
      65: return
}


data class Point(val x: Int, val y: Int)

// Convex hull in O(n*log(n))
fun convexHull(points: Array<Point>): Array<Point> {

    fun isNotRightTurn(p3: List<Point>): Boolean {
        val (a, b, c) = p3
        val cross = (a.x - b.x).toLong() * (c.y - b.y) - (a.y - b.y).toLong() * (c.x - b.x)
        val dot = (a.x - b.x).toLong() * (c.x - b.x) + (a.y - b.y).toLong() * (c.y - b.y)
        return cross < 0 || cross == 0L && dot <= 0
    }

    val sortedPoints = points.sortedArrayWith(compareBy({ it.x }, { it.y }))
    val n = sortedPoints.size
    val hull = arrayListOf<Point>()
    for (i in 0 until 2 * n) {
        val j = if (i < n) i else 2 * n - 1 - i
        while (hull.size >= 2 && isNotRightTurn(hull.takeLast(2) + sortedPoints[j]))
            hull.removeAt(hull.size - 1)
        hull.add(sortedPoints[j])
    }
    return hull.subList(0, hull.size - 1).toTypedArray()
}

// Usage example
fun main() {
    val points = arrayOf(Point(0, 0), Point(2, 2), Point(1, 1), Point(0, 1), Point(1, 0), Point(0, 0))
    val hull = convexHull(points)
    println(hull.contentToString())
}

Compiled from "ConvexHull.kt"
public final class ConvexHullKt {
  public static final Point[] convexHull(Point[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String points
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iconst_2
       8: anewarray     #17                 // class kotlin/jvm/functions/Function1
      11: astore_2
      12: aload_2
      13: iconst_0
      14: invokedynamic #36,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      19: aastore
      20: aload_2
      21: iconst_1
      22: invokedynamic #41,  0             // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      27: aastore
      28: aload_2
      29: invokestatic  #47                 // Method kotlin/comparisons/ComparisonsKt.compareBy:([Lkotlin/jvm/functions/Function1;)Ljava/util/Comparator;
      32: invokestatic  #53                 // Method kotlin/collections/ArraysKt.sortedArrayWith:([Ljava/lang/Object;Ljava/util/Comparator;)[Ljava/lang/Object;
      35: checkcast     #55                 // class "[LPoint;"
      38: astore_1
      39: aload_1
      40: arraylength
      41: istore_2
      42: new           #57                 // class java/util/ArrayList
      45: dup
      46: invokespecial #61                 // Method java/util/ArrayList."<init>":()V
      49: astore_3
      50: iconst_0
      51: istore        4
      53: iconst_2
      54: iload_2
      55: imul
      56: istore        5
      58: iload         4
      60: iload         5
      62: if_icmpge     147
      65: iload         4
      67: iload_2
      68: if_icmpge     76
      71: iload         4
      73: goto          84
      76: iconst_2
      77: iload_2
      78: imul
      79: iconst_1
      80: isub
      81: iload         4
      83: isub
      84: istore        6
      86: aload_3
      87: invokevirtual #65                 // Method java/util/ArrayList.size:()I
      90: iconst_2
      91: if_icmplt     132
      94: aload_3
      95: checkcast     #67                 // class java/util/List
      98: iconst_2
      99: invokestatic  #73                 // Method kotlin/collections/CollectionsKt.takeLast:(Ljava/util/List;I)Ljava/util/List;
     102: checkcast     #75                 // class java/util/Collection
     105: aload_1
     106: iload         6
     108: aaload
     109: invokestatic  #79                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     112: invokestatic  #83                 // Method convexHull$isNotRightTurn:(Ljava/util/List;)Z
     115: ifeq          132
     118: aload_3
     119: aload_3
     120: invokevirtual #65                 // Method java/util/ArrayList.size:()I
     123: iconst_1
     124: isub
     125: invokevirtual #87                 // Method java/util/ArrayList.remove:(I)Ljava/lang/Object;
     128: pop
     129: goto          86
     132: aload_3
     133: aload_1
     134: iload         6
     136: aaload
     137: invokevirtual #91                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     140: pop
     141: iinc          4, 1
     144: goto          58
     147: aload_3
     148: iconst_0
     149: aload_3
     150: invokevirtual #65                 // Method java/util/ArrayList.size:()I
     153: iconst_1
     154: isub
     155: invokevirtual #95                 // Method java/util/ArrayList.subList:(II)Ljava/util/List;
     158: dup
     159: ldc           #97                 // String subList(...)
     161: invokestatic  #100                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     164: checkcast     #75                 // class java/util/Collection
     167: astore        4
     169: iconst_0
     170: istore        5
     172: aload         4
     174: astore        6
     176: aload         6
     178: iconst_0
     179: anewarray     #102                // class Point
     182: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     187: checkcast     #55                 // class "[LPoint;"
     190: areturn

  public static final void main();
    Code:
       0: bipush        6
       2: anewarray     #102                // class Point
       5: astore_1
       6: aload_1
       7: iconst_0
       8: new           #102                // class Point
      11: dup
      12: iconst_0
      13: iconst_0
      14: invokespecial #121                // Method Point."<init>":(II)V
      17: aastore
      18: aload_1
      19: iconst_1
      20: new           #102                // class Point
      23: dup
      24: iconst_2
      25: iconst_2
      26: invokespecial #121                // Method Point."<init>":(II)V
      29: aastore
      30: aload_1
      31: iconst_2
      32: new           #102                // class Point
      35: dup
      36: iconst_1
      37: iconst_1
      38: invokespecial #121                // Method Point."<init>":(II)V
      41: aastore
      42: aload_1
      43: iconst_3
      44: new           #102                // class Point
      47: dup
      48: iconst_0
      49: iconst_1
      50: invokespecial #121                // Method Point."<init>":(II)V
      53: aastore
      54: aload_1
      55: iconst_4
      56: new           #102                // class Point
      59: dup
      60: iconst_1
      61: iconst_0
      62: invokespecial #121                // Method Point."<init>":(II)V
      65: aastore
      66: aload_1
      67: iconst_5
      68: new           #102                // class Point
      71: dup
      72: iconst_0
      73: iconst_0
      74: invokespecial #121                // Method Point."<init>":(II)V
      77: aastore
      78: aload_1
      79: astore_0
      80: aload_0
      81: invokestatic  #123                // Method convexHull:([LPoint;)[LPoint;
      84: astore_1
      85: aload_1
      86: invokestatic  #129                // Method java/util/Arrays.toString:([Ljava/lang/Object;)Ljava/lang/String;
      89: dup
      90: ldc           #131                // String toString(...)
      92: invokestatic  #100                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      95: astore_2
      96: getstatic     #137                // Field java/lang/System.out:Ljava/io/PrintStream;
      99: aload_2
     100: invokevirtual #143                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     103: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #146                // Method main:()V
       3: return

  private static final boolean convexHull$isNotRightTurn(java.util.List<Point>);
    Code:
       0: aload_0
       1: iconst_0
       2: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       7: checkcast     #102                // class Point
      10: astore_1
      11: aload_0
      12: iconst_1
      13: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      18: checkcast     #102                // class Point
      21: astore_2
      22: aload_0
      23: iconst_2
      24: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      29: checkcast     #102                // class Point
      32: astore_3
      33: aload_1
      34: invokevirtual #155                // Method Point.getX:()I
      37: aload_2
      38: invokevirtual #155                // Method Point.getX:()I
      41: isub
      42: i2l
      43: aload_3
      44: invokevirtual #158                // Method Point.getY:()I
      47: aload_2
      48: invokevirtual #158                // Method Point.getY:()I
      51: isub
      52: i2l
      53: lmul
      54: aload_1
      55: invokevirtual #158                // Method Point.getY:()I
      58: aload_2
      59: invokevirtual #158                // Method Point.getY:()I
      62: isub
      63: i2l
      64: aload_3
      65: invokevirtual #155                // Method Point.getX:()I
      68: aload_2
      69: invokevirtual #155                // Method Point.getX:()I
      72: isub
      73: i2l
      74: lmul
      75: lsub
      76: lstore        4
      78: aload_1
      79: invokevirtual #155                // Method Point.getX:()I
      82: aload_2
      83: invokevirtual #155                // Method Point.getX:()I
      86: isub
      87: i2l
      88: aload_3
      89: invokevirtual #155                // Method Point.getX:()I
      92: aload_2
      93: invokevirtual #155                // Method Point.getX:()I
      96: isub
      97: i2l
      98: lmul
      99: aload_1
     100: invokevirtual #158                // Method Point.getY:()I
     103: aload_2
     104: invokevirtual #158                // Method Point.getY:()I
     107: isub
     108: i2l
     109: aload_3
     110: invokevirtual #158                // Method Point.getY:()I
     113: aload_2
     114: invokevirtual #158                // Method Point.getY:()I
     117: isub
     118: i2l
     119: lmul
     120: ladd
     121: lstore        6
     123: lload         4
     125: lconst_0
     126: lcmp
     127: iflt          144
     130: lload         4
     132: lconst_0
     133: lcmp
     134: ifne          148
     137: lload         6
     139: lconst_0
     140: lcmp
     141: ifgt          148
     144: iconst_1
     145: goto          149
     148: iconst_0
     149: ireturn

  private static final java.lang.Comparable convexHull$lambda$0(Point);
    Code:
       0: aload_0
       1: ldc           #169                // String it
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #155                // Method Point.getX:()I
      10: invokestatic  #175                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: checkcast     #177                // class java/lang/Comparable
      16: areturn

  private static final java.lang.Comparable convexHull$lambda$1(Point);
    Code:
       0: aload_0
       1: ldc           #169                // String it
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #158                // Method Point.getY:()I
      10: invokestatic  #175                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: checkcast     #177                // class java/lang/Comparable
      16: areturn
}


// https://en.wikipedia.org/wiki/Persistent_data_structure
object PersistentTree {

    data class Node(
            val left: Node? = null,
            val right: Node? = null,
            val sum: Int = (left?.sum ?: 0) + (right?.sum ?: 0)
    )

    fun build(left: Int, right: Int): Node {
        if (left == right)
            return Node(null, null)
        val mid = left + right shr 1
        return Node(build(left, mid), build(mid + 1, right))
    }

    fun sum(a: Int, b: Int, root: Node, left: Int, right: Int): Int {
        if (a == left && b == right)
            return root.sum
        val mid = left + right shr 1
        var s = 0
        if (a <= mid)
            s += sum(a, minOf(b, mid), root.left!!, left, mid)
        if (b > mid)
            s += sum(maxOf(a, mid + 1), b, root.right!!, mid + 1, right)
        return s
    }

    fun set(pos: Int, value: Int, root: Node, left: Int, right: Int): Node {
        if (left == right)
            return Node(null, null, value)
        val mid = left + right shr 1
        return if (pos <= mid)
            Node(set(pos, value, root.left!!, left, mid), root.right)
        else
            Node(root.left, set(pos, value, root.right!!, mid + 1, right))
    }

    // Usage example
    @JvmStatic
    fun main(args: Array<String>) {
        val n = 10
        val t1 = build(0, n - 1)
        val t2 = set(0, 1, t1, 0, n - 1)
        println(0 == sum(0, 9, t1, 0, n - 1))
        println(1 == sum(0, 9, t2, 0, n - 1))
    }
}

Compiled from "PersistentTree.kt"
public final class PersistentTree {
  public static final PersistentTree INSTANCE;

  private PersistentTree();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final PersistentTree$Node build(int, int);
    Code:
       0: iload_1
       1: iload_2
       2: if_icmpne     18
       5: new           #15                 // class PersistentTree$Node
       8: dup
       9: aconst_null
      10: aconst_null
      11: iconst_0
      12: iconst_4
      13: aconst_null
      14: invokespecial #18                 // Method PersistentTree$Node."<init>":(LPersistentTree$Node;LPersistentTree$Node;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
      17: areturn
      18: iload_1
      19: iload_2
      20: iadd
      21: iconst_1
      22: ishr
      23: istore_3
      24: new           #15                 // class PersistentTree$Node
      27: dup
      28: aload_0
      29: iload_1
      30: iload_3
      31: invokevirtual #20                 // Method build:(II)LPersistentTree$Node;
      34: aload_0
      35: iload_3
      36: iconst_1
      37: iadd
      38: iload_2
      39: invokevirtual #20                 // Method build:(II)LPersistentTree$Node;
      42: iconst_0
      43: iconst_4
      44: aconst_null
      45: invokespecial #18                 // Method PersistentTree$Node."<init>":(LPersistentTree$Node;LPersistentTree$Node;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
      48: areturn

  public final int sum(int, int, PersistentTree$Node, int, int);
    Code:
       0: aload_3
       1: ldc           #28                 // String root
       3: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_1
       7: iload         4
       9: if_icmpne     23
      12: iload_2
      13: iload         5
      15: if_icmpne     23
      18: aload_3
      19: invokevirtual #38                 // Method PersistentTree$Node.getSum:()I
      22: ireturn
      23: iload         4
      25: iload         5
      27: iadd
      28: iconst_1
      29: ishr
      30: istore        6
      32: iconst_0
      33: istore        7
      35: iload_1
      36: iload         6
      38: if_icmpgt     69
      41: iload         7
      43: aload_0
      44: iload_1
      45: iload_2
      46: iload         6
      48: invokestatic  #44                 // Method java/lang/Math.min:(II)I
      51: aload_3
      52: invokevirtual #48                 // Method PersistentTree$Node.getLeft:()LPersistentTree$Node;
      55: dup
      56: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      59: iload         4
      61: iload         6
      63: invokevirtual #54                 // Method sum:(IILPersistentTree$Node;II)I
      66: iadd
      67: istore        7
      69: iload_2
      70: iload         6
      72: if_icmple     107
      75: iload         7
      77: aload_0
      78: iload_1
      79: iload         6
      81: iconst_1
      82: iadd
      83: invokestatic  #57                 // Method java/lang/Math.max:(II)I
      86: iload_2
      87: aload_3
      88: invokevirtual #60                 // Method PersistentTree$Node.getRight:()LPersistentTree$Node;
      91: dup
      92: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      95: iload         6
      97: iconst_1
      98: iadd
      99: iload         5
     101: invokevirtual #54                 // Method sum:(IILPersistentTree$Node;II)I
     104: iadd
     105: istore        7
     107: iload         7
     109: ireturn

  public final PersistentTree$Node set(int, int, PersistentTree$Node, int, int);
    Code:
       0: aload_3
       1: ldc           #28                 // String root
       3: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload         4
       8: iload         5
      10: if_icmpne     24
      13: new           #15                 // class PersistentTree$Node
      16: dup
      17: aconst_null
      18: aconst_null
      19: iload_2
      20: invokespecial #69                 // Method PersistentTree$Node."<init>":(LPersistentTree$Node;LPersistentTree$Node;I)V
      23: areturn
      24: iload         4
      26: iload         5
      28: iadd
      29: iconst_1
      30: ishr
      31: istore        6
      33: iload_1
      34: iload         6
      36: if_icmpgt     74
      39: new           #15                 // class PersistentTree$Node
      42: dup
      43: aload_0
      44: iload_1
      45: iload_2
      46: aload_3
      47: invokevirtual #48                 // Method PersistentTree$Node.getLeft:()LPersistentTree$Node;
      50: dup
      51: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      54: iload         4
      56: iload         6
      58: invokevirtual #71                 // Method set:(IILPersistentTree$Node;II)LPersistentTree$Node;
      61: aload_3
      62: invokevirtual #60                 // Method PersistentTree$Node.getRight:()LPersistentTree$Node;
      65: iconst_0
      66: iconst_4
      67: aconst_null
      68: invokespecial #18                 // Method PersistentTree$Node."<init>":(LPersistentTree$Node;LPersistentTree$Node;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
      71: goto          108
      74: new           #15                 // class PersistentTree$Node
      77: dup
      78: aload_3
      79: invokevirtual #48                 // Method PersistentTree$Node.getLeft:()LPersistentTree$Node;
      82: aload_0
      83: iload_1
      84: iload_2
      85: aload_3
      86: invokevirtual #60                 // Method PersistentTree$Node.getRight:()LPersistentTree$Node;
      89: dup
      90: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      93: iload         6
      95: iconst_1
      96: iadd
      97: iload         5
      99: invokevirtual #71                 // Method set:(IILPersistentTree$Node;II)LPersistentTree$Node;
     102: iconst_0
     103: iconst_4
     104: aconst_null
     105: invokespecial #18                 // Method PersistentTree$Node."<init>":(LPersistentTree$Node;LPersistentTree$Node;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
     108: areturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #78                 // String args
       3: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: bipush        10
       8: istore_1
       9: getstatic     #81                 // Field INSTANCE:LPersistentTree;
      12: iconst_0
      13: iload_1
      14: iconst_1
      15: isub
      16: invokevirtual #20                 // Method build:(II)LPersistentTree$Node;
      19: astore_2
      20: getstatic     #81                 // Field INSTANCE:LPersistentTree;
      23: iconst_0
      24: iconst_1
      25: aload_2
      26: iconst_0
      27: iload_1
      28: iconst_1
      29: isub
      30: invokevirtual #71                 // Method set:(IILPersistentTree$Node;II)LPersistentTree$Node;
      33: astore_3
      34: getstatic     #81                 // Field INSTANCE:LPersistentTree;
      37: iconst_0
      38: bipush        9
      40: aload_2
      41: iconst_0
      42: iload_1
      43: iconst_1
      44: isub
      45: invokevirtual #54                 // Method sum:(IILPersistentTree$Node;II)I
      48: ifne          55
      51: iconst_1
      52: goto          56
      55: iconst_0
      56: istore        4
      58: getstatic     #87                 // Field java/lang/System.out:Ljava/io/PrintStream;
      61: iload         4
      63: invokevirtual #93                 // Method java/io/PrintStream.println:(Z)V
      66: iconst_1
      67: getstatic     #81                 // Field INSTANCE:LPersistentTree;
      70: iconst_0
      71: bipush        9
      73: aload_3
      74: iconst_0
      75: iload_1
      76: iconst_1
      77: isub
      78: invokevirtual #54                 // Method sum:(IILPersistentTree$Node;II)I
      81: if_icmpne     88
      84: iconst_1
      85: goto          89
      88: iconst_0
      89: istore        4
      91: getstatic     #87                 // Field java/lang/System.out:Ljava/io/PrintStream;
      94: iload         4
      96: invokevirtual #93                 // Method java/io/PrintStream.println:(Z)V
      99: return

  static {};
    Code:
       0: new           #2                  // class PersistentTree
       3: dup
       4: invokespecial #99                 // Method "<init>":()V
       7: putstatic     #81                 // Field INSTANCE:LPersistentTree;
      10: return
}

Compiled from "PersistentTree.kt"
public final class PersistentTree$Node {
  private final PersistentTree$Node left;

  private final PersistentTree$Node right;

  private final int sum;

  public PersistentTree$Node(PersistentTree$Node, PersistentTree$Node, int);
    Code:
       0: aload_0
       1: invokespecial #10                 // Method java/lang/Object."<init>":()V
       4: aload_0
       5: aload_1
       6: putfield      #14                 // Field left:LPersistentTree$Node;
       9: aload_0
      10: aload_2
      11: putfield      #17                 // Field right:LPersistentTree$Node;
      14: aload_0
      15: iload_3
      16: putfield      #21                 // Field sum:I
      19: return

  public PersistentTree$Node(PersistentTree$Node, PersistentTree$Node, int, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          9
       7: aconst_null
       8: astore_1
       9: iload         4
      11: iconst_2
      12: iand
      13: ifeq          18
      16: aconst_null
      17: astore_2
      18: iload         4
      20: iconst_4
      21: iand
      22: ifeq          53
      25: aload_1
      26: dup
      27: ifnull        36
      30: getfield      #21                 // Field sum:I
      33: goto          38
      36: pop
      37: iconst_0
      38: aload_2
      39: dup
      40: ifnull        49
      43: getfield      #21                 // Field sum:I
      46: goto          51
      49: pop
      50: iconst_0
      51: iadd
      52: istore_3
      53: aload_0
      54: aload_1
      55: aload_2
      56: iload_3
      57: invokespecial #25                 // Method "<init>":(LPersistentTree$Node;LPersistentTree$Node;I)V
      60: return

  public final PersistentTree$Node getLeft();
    Code:
       0: aload_0
       1: getfield      #14                 // Field left:LPersistentTree$Node;
       4: areturn

  public final PersistentTree$Node getRight();
    Code:
       0: aload_0
       1: getfield      #17                 // Field right:LPersistentTree$Node;
       4: areturn

  public final int getSum();
    Code:
       0: aload_0
       1: getfield      #21                 // Field sum:I
       4: ireturn

  public final PersistentTree$Node component1();
    Code:
       0: aload_0
       1: getfield      #14                 // Field left:LPersistentTree$Node;
       4: areturn

  public final PersistentTree$Node component2();
    Code:
       0: aload_0
       1: getfield      #17                 // Field right:LPersistentTree$Node;
       4: areturn

  public final int component3();
    Code:
       0: aload_0
       1: getfield      #21                 // Field sum:I
       4: ireturn

  public final PersistentTree$Node copy(PersistentTree$Node, PersistentTree$Node, int);
    Code:
       0: new           #2                  // class PersistentTree$Node
       3: dup
       4: aload_1
       5: aload_2
       6: iload_3
       7: invokespecial #25                 // Method "<init>":(LPersistentTree$Node;LPersistentTree$Node;I)V
      10: areturn

  public static PersistentTree$Node copy$default(PersistentTree$Node, PersistentTree$Node, PersistentTree$Node, int, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #14                 // Field left:LPersistentTree$Node;
      11: astore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #17                 // Field right:LPersistentTree$Node;
      23: astore_2
      24: iload         4
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #21                 // Field sum:I
      35: istore_3
      36: aload_0
      37: aload_1
      38: aload_2
      39: iload_3
      40: invokevirtual #42                 // Method copy:(LPersistentTree$Node;LPersistentTree$Node;I)LPersistentTree$Node;
      43: areturn

  public java.lang.String toString();
    Code:
       0: new           #46                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #47                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #49                 // String Node(left=
       9: invokevirtual #53                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #14                 // Field left:LPersistentTree$Node;
      16: invokevirtual #56                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      19: ldc           #58                 // String , right=
      21: invokevirtual #53                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #17                 // Field right:LPersistentTree$Node;
      28: invokevirtual #56                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      31: ldc           #60                 // String , sum=
      33: invokevirtual #53                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #21                 // Field sum:I
      40: invokevirtual #63                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      43: bipush        41
      45: invokevirtual #66                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #68                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #14                 // Field left:LPersistentTree$Node;
       4: ifnonnull     11
       7: iconst_0
       8: goto          18
      11: aload_0
      12: getfield      #14                 // Field left:LPersistentTree$Node;
      15: invokevirtual #71                 // Method hashCode:()I
      18: istore_1
      19: iload_1
      20: bipush        31
      22: imul
      23: aload_0
      24: getfield      #17                 // Field right:LPersistentTree$Node;
      27: ifnonnull     34
      30: iconst_0
      31: goto          41
      34: aload_0
      35: getfield      #17                 // Field right:LPersistentTree$Node;
      38: invokevirtual #71                 // Method hashCode:()I
      41: iadd
      42: istore_1
      43: iload_1
      44: bipush        31
      46: imul
      47: aload_0
      48: getfield      #21                 // Field sum:I
      51: invokestatic  #76                 // Method java/lang/Integer.hashCode:(I)I
      54: iadd
      55: istore_1
      56: iload_1
      57: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class PersistentTree$Node
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class PersistentTree$Node
      20: astore_2
      21: aload_0
      22: getfield      #14                 // Field left:LPersistentTree$Node;
      25: aload_2
      26: getfield      #14                 // Field left:LPersistentTree$Node;
      29: invokestatic  #85                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #17                 // Field right:LPersistentTree$Node;
      41: aload_2
      42: getfield      #17                 // Field right:LPersistentTree$Node;
      45: invokestatic  #85                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      48: ifne          53
      51: iconst_0
      52: ireturn
      53: aload_0
      54: getfield      #21                 // Field sum:I
      57: aload_2
      58: getfield      #21                 // Field sum:I
      61: if_icmpeq     66
      64: iconst_0
      65: ireturn
      66: iconst_1
      67: ireturn

  public PersistentTree$Node();
    Code:
       0: aload_0
       1: aconst_null
       2: aconst_null
       3: iconst_0
       4: bipush        7
       6: aconst_null
       7: invokespecial #89                 // Method "<init>":(LPersistentTree$Node;LPersistentTree$Node;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
      10: return
}