package atcoder.arc159

fun main() {
	readInt()
	val a = readInts().toIntArray()
	val ans = mutableListOf<IntArray>()

	fun apply(p: IntArray) {
		for (i in a.indices) a[i] += p[i]
		ans.add(p)
	}

	var sumOk = false
	for (j in a.indices) {
		if (a.sum() % a.size == 0) {
			sumOk = true
			break
		}
		val b = a.indices.sortedBy { a[it] }
		val p = IntArray(a.size)
		for (i in a.indices) p[b[i]] = a.size - 1 - i
		apply(p)
	}
	if (!sumOk) return println("No")
	println("Yes")

	while (true) {
		val delta = a.sum() / a.size
		for (i in a.indices) a[i] -= delta
		val x = a.indexOf(a.max()!!)
		if (a[x] == 0) break
		val y = a.indexOf(a.min()!!)
		val k = minOf(a[x], -a[y], a.size - 1)
		val p = IntArray(a.size) { -1 }
		p[y] = 0
		p[x] = k
		var t = 1
		for (i in p.indices) {
			if (p[i] >= 0) continue
			if (t == k) t++
			p[i] = t++
		}
		val q = IntArray(a.size) { a.size - 1 - p[it] }
		p[y] = k
		p[x] = 0
		apply(q)
		apply(p)
	}

	println(ans.size)
	println(ans.joinToString("\n") { p -> p.joinToString(" ") { (it + 1).toString() } })
}

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

Compiled from "c.kt"
public final class atcoder.arc159.CKt {
  public static final void main();
    Code:
       0: invokestatic  #10                 // Method readInt:()I
       3: pop
       4: invokestatic  #14                 // Method readInts:()Ljava/util/List;
       7: checkcast     #16                 // class java/util/Collection
      10: invokestatic  #22                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
      13: astore_0
      14: new           #24                 // class java/util/ArrayList
      17: dup
      18: invokespecial #27                 // Method java/util/ArrayList."<init>":()V
      21: checkcast     #29                 // class java/util/List
      24: astore_1
      25: iconst_0
      26: istore_2
      27: iconst_0
      28: istore_3
      29: aload_0
      30: arraylength
      31: istore        4
      33: iload_3
      34: iload         4
      36: if_icmpge     148
      39: aload_0
      40: invokestatic  #35                 // Method kotlin/collections/ArraysKt.sum:([I)I
      43: aload_0
      44: arraylength
      45: irem
      46: ifne          54
      49: iconst_1
      50: istore_2
      51: goto          148
      54: aload_0
      55: invokestatic  #39                 // Method kotlin/collections/ArraysKt.getIndices:([I)Lkotlin/ranges/IntRange;
      58: checkcast     #41                 // class java/lang/Iterable
      61: astore        6
      63: iconst_0
      64: istore        7
      66: aload         6
      68: new           #43                 // class atcoder/arc159/CKt$main$$inlined$sortedBy$1
      71: dup
      72: aload_0
      73: invokespecial #46                 // Method atcoder/arc159/CKt$main$$inlined$sortedBy$1."<init>":([I)V
      76: checkcast     #48                 // class java/util/Comparator
      79: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
      82: astore        5
      84: aload_0
      85: arraylength
      86: newarray       int
      88: astore        6
      90: iconst_0
      91: istore        7
      93: aload_0
      94: arraylength
      95: istore        8
      97: iload         7
      99: iload         8
     101: if_icmpge     135
     104: aload         6
     106: aload         5
     108: iload         7
     110: invokeinterface #56,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     115: checkcast     #58                 // class java/lang/Number
     118: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     121: aload_0
     122: arraylength
     123: iconst_1
     124: isub
     125: iload         7
     127: isub
     128: iastore
     129: iinc          7, 1
     132: goto          97
     135: aload_0
     136: aload_1
     137: aload         6
     139: invokestatic  #65                 // Method main$apply:([ILjava/util/List;[I)V
     142: iinc          3, 1
     145: goto          33
     148: iload_2
     149: ifne          162
     152: ldc           #67                 // String No
     154: getstatic     #73                 // Field java/lang/System.out:Ljava/io/PrintStream;
     157: swap
     158: invokevirtual #79                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     161: return
     162: ldc           #81                 // String Yes
     164: getstatic     #73                 // Field java/lang/System.out:Ljava/io/PrintStream;
     167: swap
     168: invokevirtual #79                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     171: nop
     172: aload_0
     173: invokestatic  #35                 // Method kotlin/collections/ArraysKt.sum:([I)I
     176: aload_0
     177: arraylength
     178: idiv
     179: istore_3
     180: iconst_0
     181: istore        4
     183: aload_0
     184: arraylength
     185: istore        5
     187: iload         4
     189: iload         5
     191: if_icmpge     214
     194: iload         4
     196: istore        6
     198: aload_0
     199: iload         6
     201: aload_0
     202: iload         6
     204: iaload
     205: iload_3
     206: isub
     207: iastore
     208: iinc          4, 1
     211: goto          187
     214: aload_0
     215: aload_0
     216: invokestatic  #84                 // Method kotlin/collections/ArraysKt.maxOrThrow:([I)I
     219: invokestatic  #88                 // Method kotlin/collections/ArraysKt.indexOf:([II)I
     222: istore        4
     224: aload_0
     225: iload         4
     227: iaload
     228: ifeq          446
     231: aload_0
     232: aload_0
     233: invokestatic  #91                 // Method kotlin/collections/ArraysKt.minOrThrow:([I)I
     236: invokestatic  #88                 // Method kotlin/collections/ArraysKt.indexOf:([II)I
     239: istore        5
     241: aload_0
     242: iload         4
     244: iaload
     245: aload_0
     246: iload         5
     248: iaload
     249: ineg
     250: aload_0
     251: arraylength
     252: iconst_1
     253: isub
     254: invokestatic  #97                 // Method java/lang/Math.min:(II)I
     257: invokestatic  #97                 // Method java/lang/Math.min:(II)I
     260: istore        6
     262: iconst_0
     263: istore        8
     265: aload_0
     266: arraylength
     267: istore        9
     269: iload         9
     271: newarray       int
     273: astore        10
     275: iload         8
     277: iload         9
     279: if_icmpge     298
     282: iload         8
     284: istore        11
     286: aload         10
     288: iload         11
     290: iconst_m1
     291: iastore
     292: iinc          8, 1
     295: goto          275
     298: aload         10
     300: astore        7
     302: aload         7
     304: iload         5
     306: iconst_0
     307: iastore
     308: aload         7
     310: iload         4
     312: iload         6
     314: iastore
     315: iconst_1
     316: istore        8
     318: iconst_0
     319: istore        9
     321: aload         7
     323: arraylength
     324: istore        10
     326: iload         9
     328: iload         10
     330: if_icmpge     367
     333: aload         7
     335: iload         9
     337: iaload
     338: ifge          361
     341: iload         8
     343: iload         6
     345: if_icmpne     351
     348: iinc          8, 1
     351: aload         7
     353: iload         9
     355: iload         8
     357: iinc          8, 1
     360: iastore
     361: iinc          9, 1
     364: goto          326
     367: iconst_0
     368: istore        10
     370: aload_0
     371: arraylength
     372: istore        11
     374: iload         11
     376: newarray       int
     378: astore        12
     380: iload         10
     382: iload         11
     384: if_icmpge     412
     387: iload         10
     389: istore        13
     391: aload         12
     393: iload         13
     395: aload_0
     396: arraylength
     397: iconst_1
     398: isub
     399: aload         7
     401: iload         13
     403: iaload
     404: isub
     405: iastore
     406: iinc          10, 1
     409: goto          380
     412: aload         12
     414: astore        9
     416: aload         7
     418: iload         5
     420: iload         6
     422: iastore
     423: aload         7
     425: iload         4
     427: iconst_0
     428: iastore
     429: aload_0
     430: aload_1
     431: aload         9
     433: invokestatic  #65                 // Method main$apply:([ILjava/util/List;[I)V
     436: aload_0
     437: aload_1
     438: aload         7
     440: invokestatic  #65                 // Method main$apply:([ILjava/util/List;[I)V
     443: goto          171
     446: aload_1
     447: invokeinterface #100,  1          // InterfaceMethod java/util/List.size:()I
     452: istore_3
     453: getstatic     #73                 // Field java/lang/System.out:Ljava/io/PrintStream;
     456: iload_3
     457: invokevirtual #103                // Method java/io/PrintStream.println:(I)V
     460: aload_1
     461: checkcast     #41                 // class java/lang/Iterable
     464: ldc           #105                // String \n
     466: checkcast     #107                // class java/lang/CharSequence
     469: aconst_null
     470: aconst_null
     471: iconst_0
     472: aconst_null
     473: invokedynamic #126,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     478: bipush        30
     480: aconst_null
     481: invokestatic  #130                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     484: getstatic     #73                 // Field java/lang/System.out:Ljava/io/PrintStream;
     487: swap
     488: invokevirtual #79                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     491: return

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #158                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #163                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final int readInt();
    Code:
       0: invokestatic  #165                // Method readLn:()Ljava/lang/String;
       3: invokestatic  #171                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #165                // Method readLn:()Ljava/lang/String;
       3: checkcast     #107                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #175                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #177                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #183                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      25: areturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #186                // Method readStrings:()Ljava/util/List;
       3: checkcast     #41                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #24                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #190                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #192                // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #16                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #196,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #202,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #206,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #175                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #171                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #210                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #214,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #29                 // class java/util/List
      96: nop
      97: areturn

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

  private static final void main$apply(int[], java.util.List<int[]>, int[]);
    Code:
       0: iconst_0
       1: istore_3
       2: aload_0
       3: arraylength
       4: istore        4
       6: iload_3
       7: iload         4
       9: if_icmpge     33
      12: iload_3
      13: istore        5
      15: aload_0
      16: iload         5
      18: aload_0
      19: iload         5
      21: iaload
      22: aload_2
      23: iload_3
      24: iaload
      25: iadd
      26: iastore
      27: iinc          3, 1
      30: goto          6
      33: aload_1
      34: aload_2
      35: invokeinterface #232,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      40: pop
      41: return

  private static final java.lang.CharSequence main$lambda$2$lambda$1(int);
    Code:
       0: iload_0
       1: iconst_1
       2: iadd
       3: invokestatic  #237                // Method java/lang/String.valueOf:(I)Ljava/lang/String;
       6: checkcast     #107                // class java/lang/CharSequence
       9: areturn

  private static final java.lang.CharSequence main$lambda$2(int[]);
    Code:
       0: aload_0
       1: ldc           #238                // String p
       3: invokestatic  #242                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: ldc           #177                // String
       9: checkcast     #107                // class java/lang/CharSequence
      12: aconst_null
      13: aconst_null
      14: iconst_0
      15: aconst_null
      16: invokedynamic #248,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      21: bipush        30
      23: aconst_null
      24: invokestatic  #251                // Method kotlin/collections/ArraysKt.joinToString$default:([ILjava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      27: checkcast     #107                // class java/lang/CharSequence
      30: areturn
}

Compiled from "Comparisons.kt"
public final class atcoder.arc159.CKt$main$$inlined$sortedBy$1<T> implements java.util.Comparator {
  final int[] $a$inlined;

  public atcoder.arc159.CKt$main$$inlined$sortedBy$1(int[]);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $a$inlined:[I
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #28                 // class java/lang/Number
       4: invokevirtual #32                 // Method java/lang/Number.intValue:()I
       7: istore_3
       8: iconst_0
       9: istore        4
      11: aload_0
      12: getfield      #18                 // Field $a$inlined:[I
      15: iload_3
      16: iaload
      17: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      20: checkcast     #40                 // class java/lang/Comparable
      23: aload_2
      24: checkcast     #28                 // class java/lang/Number
      27: invokevirtual #32                 // Method java/lang/Number.intValue:()I
      30: istore_3
      31: astore        5
      33: iconst_0
      34: istore        4
      36: aload_0
      37: getfield      #18                 // Field $a$inlined:[I
      40: iload_3
      41: iaload
      42: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      45: aload         5
      47: swap
      48: checkcast     #40                 // class java/lang/Comparable
      51: invokestatic  #46                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      54: ireturn
}


package atcoder.arc128

fun main() {
	readLn()
	val a = readInts()
	val cumSum = mutableListOf(0.toModular())
	fun sum(from: Int, to: Int) = cumSum[maxOf(to, from)] - cumSum[from]
	var same = 0
	var diff = 0
	var ans = 1.toModular()
	for (i in a.indices) {
		if (i < 2 || a[i] != a[i - 2]) diff = i
		if (i < 1 || a[i] == a[i - 1]) {
			same = i
		} else {
			ans = sum(same, i) - sum(maxOf(diff - 1, same), i - 2)
		}
		cumSum.add(cumSum.last() + ans)
	}
	println(ans)
}

private fun Int.toModular() = Modular(this)
private class Modular {
	companion object {
		const val M = 998244353
	}
	val x: Int
	@Suppress("ConvertSecondaryConstructorToPrimary")
	constructor(value: Int) { x = (value % M).let { if (it < 0) it + M else it } }
	operator fun plus(that: Modular) = Modular((x + that.x) % M)
	operator fun minus(that: Modular) = Modular((x + M - that.x) % M)
	operator fun times(that: Modular) = (x.toLong() * that.x % M).toInt().toModular()
	private fun modInverse() = Modular(x.toBigInteger().modInverse(M.toBigInteger()).toInt())
	operator fun div(that: Modular) = times(that.modInverse())
	override fun toString() = x.toString()
}
private operator fun Int.plus(that: Modular) = Modular(this) + that
private operator fun Int.minus(that: Modular) = Modular(this) - that
private operator fun Int.times(that: Modular) = Modular(this) * that
private operator fun Int.div(that: Modular) = Modular(this) / that

private fun readLn() = readLine()!!
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

Compiled from "d.kt"
public final class atcoder.arc128.DKt {
  public static final void main();
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: pop
       4: invokestatic  #14                 // Method readInts:()Ljava/util/List;
       7: astore_0
       8: iconst_1
       9: anewarray     #16                 // class atcoder/arc128/Modular
      12: astore_2
      13: aload_2
      14: iconst_0
      15: iconst_0
      16: invokestatic  #20                 // Method toModular:(I)Latcoder/arc128/Modular;
      19: aastore
      20: aload_2
      21: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      24: astore_1
      25: iconst_0
      26: istore_2
      27: iconst_0
      28: istore_3
      29: iconst_1
      30: invokestatic  #20                 // Method toModular:(I)Latcoder/arc128/Modular;
      33: astore        4
      35: iconst_0
      36: istore        5
      38: aload_0
      39: checkcast     #28                 // class java/util/Collection
      42: invokeinterface #32,  1           // InterfaceMethod java/util/Collection.size:()I
      47: istore        6
      49: iload         5
      51: iload         6
      53: if_icmpge     195
      56: iload         5
      58: iconst_2
      59: if_icmplt     95
      62: aload_0
      63: iload         5
      65: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      70: checkcast     #40                 // class java/lang/Number
      73: invokevirtual #43                 // Method java/lang/Number.intValue:()I
      76: aload_0
      77: iload         5
      79: iconst_2
      80: isub
      81: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      86: checkcast     #40                 // class java/lang/Number
      89: invokevirtual #43                 // Method java/lang/Number.intValue:()I
      92: if_icmpeq     98
      95: iload         5
      97: istore_3
      98: iload         5
     100: iconst_1
     101: if_icmplt     137
     104: aload_0
     105: iload         5
     107: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     112: checkcast     #40                 // class java/lang/Number
     115: invokevirtual #43                 // Method java/lang/Number.intValue:()I
     118: aload_0
     119: iload         5
     121: iconst_1
     122: isub
     123: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     128: checkcast     #40                 // class java/lang/Number
     131: invokevirtual #43                 // Method java/lang/Number.intValue:()I
     134: if_icmpne     143
     137: iload         5
     139: istore_2
     140: goto          170
     143: aload_1
     144: iload_2
     145: iload         5
     147: invokestatic  #47                 // Method main$sum:(Ljava/util/List;II)Latcoder/arc128/Modular;
     150: aload_1
     151: iload_3
     152: iconst_1
     153: isub
     154: iload_2
     155: invokestatic  #53                 // Method java/lang/Math.max:(II)I
     158: iload         5
     160: iconst_2
     161: isub
     162: invokestatic  #47                 // Method main$sum:(Ljava/util/List;II)Latcoder/arc128/Modular;
     165: invokevirtual #57                 // Method atcoder/arc128/Modular.minus:(Latcoder/arc128/Modular;)Latcoder/arc128/Modular;
     168: astore        4
     170: aload_1
     171: aload_1
     172: invokestatic  #61                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     175: checkcast     #16                 // class atcoder/arc128/Modular
     178: aload         4
     180: invokevirtual #64                 // Method atcoder/arc128/Modular.plus:(Latcoder/arc128/Modular;)Latcoder/arc128/Modular;
     183: invokeinterface #68,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     188: pop
     189: iinc          5, 1
     192: goto          49
     195: getstatic     #74                 // Field java/lang/System.out:Ljava/io/PrintStream;
     198: aload         4
     200: invokevirtual #80                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     203: return

  private static final atcoder.arc128.Modular toModular(int);
    Code:
       0: new           #16                 // class atcoder/arc128/Modular
       3: dup
       4: iload_0
       5: invokespecial #93                 // Method atcoder/arc128/Modular."<init>":(I)V
       8: areturn

  private static final atcoder.arc128.Modular plus(int, atcoder.arc128.Modular);
    Code:
       0: new           #16                 // class atcoder/arc128/Modular
       3: dup
       4: iload_0
       5: invokespecial #93                 // Method atcoder/arc128/Modular."<init>":(I)V
       8: aload_1
       9: invokevirtual #64                 // Method atcoder/arc128/Modular.plus:(Latcoder/arc128/Modular;)Latcoder/arc128/Modular;
      12: areturn

  private static final atcoder.arc128.Modular minus(int, atcoder.arc128.Modular);
    Code:
       0: new           #16                 // class atcoder/arc128/Modular
       3: dup
       4: iload_0
       5: invokespecial #93                 // Method atcoder/arc128/Modular."<init>":(I)V
       8: aload_1
       9: invokevirtual #57                 // Method atcoder/arc128/Modular.minus:(Latcoder/arc128/Modular;)Latcoder/arc128/Modular;
      12: areturn

  private static final atcoder.arc128.Modular times(int, atcoder.arc128.Modular);
    Code:
       0: new           #16                 // class atcoder/arc128/Modular
       3: dup
       4: iload_0
       5: invokespecial #93                 // Method atcoder/arc128/Modular."<init>":(I)V
       8: aload_1
       9: invokevirtual #101                // Method atcoder/arc128/Modular.times:(Latcoder/arc128/Modular;)Latcoder/arc128/Modular;
      12: areturn

  private static final atcoder.arc128.Modular div(int, atcoder.arc128.Modular);
    Code:
       0: new           #16                 // class atcoder/arc128/Modular
       3: dup
       4: iload_0
       5: invokespecial #93                 // Method atcoder/arc128/Modular."<init>":(I)V
       8: aload_1
       9: invokevirtual #105                // Method atcoder/arc128/Modular.div:(Latcoder/arc128/Modular;)Latcoder/arc128/Modular;
      12: areturn

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #111                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #116                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: checkcast     #120                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #122                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #124                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #130                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      25: areturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #133                // Method readStrings:()Ljava/util/List;
       3: checkcast     #135                // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #137                // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #141                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #142                // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #28                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #146,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #152,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #122                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #162                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #166                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #167,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #34                 // class java/util/List
      96: nop
      97: areturn

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

  private static final atcoder.arc128.Modular main$sum(java.util.List<atcoder.arc128.Modular>, int, int);
    Code:
       0: aload_0
       1: iload_2
       2: iload_1
       3: invokestatic  #53                 // Method java/lang/Math.max:(II)I
       6: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      11: checkcast     #16                 // class atcoder/arc128/Modular
      14: aload_0
      15: iload_1
      16: invokeinterface #38,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      21: checkcast     #16                 // class atcoder/arc128/Modular
      24: invokevirtual #57                 // Method atcoder/arc128/Modular.minus:(Latcoder/arc128/Modular;)Latcoder/arc128/Modular;
      27: areturn

  public static final atcoder.arc128.Modular access$toModular(int);
    Code:
       0: iload_0
       1: invokestatic  #20                 // Method toModular:(I)Latcoder/arc128/Modular;
       4: areturn
}


package yandex.y2022.qual

import kotlin.random.Random

fun main() {
	val (n, _) = readInts()
	val s = List(n) { readLn().map { "ACGT".indexOf(it) }.toIntArray() }
		.let { it.plus(IntArray(it[0].size)) }
	data class Edge(val u: Int, val v: Int, val len: Int)
	val edges = mutableListOf<Edge>()
	for (i in s.indices) for (j in 0 until i) {
		val len = s[i].indices.sumOf { k -> dist(s[i][k], s[j][k]) }
		edges.add(Edge(i, j, len))
	}
	val dsu = DisjointSetUnion(s.size)
	var ans = 0
	for (edge in edges.sortedBy { it.len }) {
		if (dsu.unite(edge.u, edge.v)) ans += edge.len
	}
	println(ans)
}

private fun dist(x: Int, y: Int): Int {
	if (x == y) return 0
	if (x xor y == 2) return 2
	return 1
}

private class DisjointSetUnion(n: Int) {
	var p: IntArray
	var r: Random = Random(566)

	init {
		p = IntArray(n)
		clear()
	}

	fun clear() {
		for (i in p.indices) {
			p[i] = i
		}
	}

	operator fun get(v: Int): Int {
		if (p[v] == v) {
			return v
		}
		p[v] = get(p[v])
		return p[v]
	}

	fun unite(v: Int, u: Int): Boolean {
		val vv = get(v)
		val uu = get(u)
		if (vv == uu) return false
		if (r.nextBoolean()) {
			p[vv] = uu
		} else {
			p[uu] = vv
		}
		return true
	}
}

private fun readLn() = readLine()!!
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

Compiled from "d.kt"
public final class yandex.y2022.qual.DKt$main$Edge {
  private final int u;

  private final int v;

  private final int len;

  public yandex.y2022.qual.DKt$main$Edge(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 u:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field v:I
      14: aload_0
      15: iload_3
      16: putfield      #19                 // Field len:I
      19: return

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

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

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

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

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

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

  public final yandex.y2022.qual.DKt$main$Edge copy(int, int, int);
    Code:
       0: new           #2                  // class yandex/y2022/qual/DKt$main$Edge
       3: dup
       4: iload_1
       5: iload_2
       6: iload_3
       7: invokespecial #32                 // Method "<init>":(III)V
      10: areturn

  public static yandex.y2022.qual.DKt$main$Edge copy$default(yandex.y2022.qual.DKt$main$Edge, int, int, int, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #13                 // Field u:I
      11: istore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #16                 // Field v:I
      23: istore_2
      24: iload         4
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #19                 // Field len:I
      35: istore_3
      36: aload_0
      37: iload_1
      38: iload_2
      39: iload_3
      40: invokevirtual #36                 // Method copy:(III)Lyandex/y2022/qual/DKt$main$Edge;
      43: areturn

  public java.lang.String toString();
    Code:
       0: new           #40                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #41                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #43                 // String Edge(u=
       9: invokevirtual #47                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field u:I
      16: invokevirtual #50                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #52                 // String , v=
      21: invokevirtual #47                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field v:I
      28: invokevirtual #50                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: ldc           #54                 // String , len=
      33: invokevirtual #47                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #19                 // Field len:I
      40: invokevirtual #50                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      43: bipush        41
      45: invokevirtual #57                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #59                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field u:I
       4: invokestatic  #65                 // 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 v:I
      16: invokestatic  #65                 // 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 len:I
      29: invokestatic  #65                 // Method java/lang/Integer.hashCode:(I)I
      32: iadd
      33: istore_1
      34: iload_1
      35: 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 yandex/y2022/qual/DKt$main$Edge
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class yandex/y2022/qual/DKt$main$Edge
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field u:I
      25: aload_2
      26: getfield      #13                 // Field u:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field v:I
      38: aload_2
      39: getfield      #16                 // Field v:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: aload_0
      48: getfield      #19                 // Field len:I
      51: aload_2
      52: getfield      #19                 // Field len:I
      55: if_icmpeq     60
      58: iconst_0
      59: ireturn
      60: iconst_1
      61: ireturn
}

Compiled from "d.kt"
public final class yandex.y2022.qual.DKt {
  public static final void main();
    Code:
       0: invokestatic  #10                 // Method readInts:()Ljava/util/List;
       3: iconst_0
       4: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       9: checkcast     #18                 // class java/lang/Number
      12: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      15: istore_0
      16: new           #24                 // class java/util/ArrayList
      19: dup
      20: iload_0
      21: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      24: astore_2
      25: iconst_0
      26: istore_3
      27: iload_3
      28: iload_0
      29: if_icmpge     177
      32: iload_3
      33: istore        4
      35: aload_2
      36: iload         4
      38: istore        5
      40: astore        17
      42: iconst_0
      43: istore        6
      45: invokestatic  #32                 // Method readLn:()Ljava/lang/String;
      48: checkcast     #34                 // class java/lang/CharSequence
      51: astore        7
      53: iconst_0
      54: istore        8
      56: aload         7
      58: astore        9
      60: new           #24                 // class java/util/ArrayList
      63: dup
      64: aload         7
      66: invokeinterface #37,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      71: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      74: checkcast     #39                 // class java/util/Collection
      77: astore        10
      79: iconst_0
      80: istore        11
      82: iconst_0
      83: istore        12
      85: iload         12
      87: aload         9
      89: invokeinterface #37,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      94: if_icmpge     152
      97: aload         9
      99: iload         12
     101: invokeinterface #43,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     106: istore        13
     108: aload         10
     110: iload         13
     112: istore        14
     114: astore        15
     116: iconst_0
     117: istore        16
     119: ldc           #45                 // String ACGT
     121: checkcast     #34                 // class java/lang/CharSequence
     124: iload         14
     126: iconst_0
     127: iconst_0
     128: bipush        6
     130: aconst_null
     131: invokestatic  #51                 // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
     134: invokestatic  #57                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     137: aload         15
     139: swap
     140: invokeinterface #61,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     145: pop
     146: iinc          12, 1
     149: goto          85
     152: aload         10
     154: checkcast     #12                 // class java/util/List
     157: nop
     158: checkcast     #39                 // class java/util/Collection
     161: invokestatic  #67                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     164: aload         17
     166: swap
     167: invokevirtual #68                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     170: pop
     171: iinc          3, 1
     174: goto          27
     177: aload_2
     178: checkcast     #12                 // class java/util/List
     181: astore_3
     182: iconst_0
     183: istore        4
     185: aload_3
     186: checkcast     #39                 // class java/util/Collection
     189: aload_3
     190: iconst_0
     191: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     196: checkcast     #70                 // class "[I"
     199: arraylength
     200: newarray       int
     202: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     205: nop
     206: astore_1
     207: new           #24                 // class java/util/ArrayList
     210: dup
     211: invokespecial #76                 // Method java/util/ArrayList."<init>":()V
     214: checkcast     #12                 // class java/util/List
     217: astore_2
     218: iconst_0
     219: istore_3
     220: aload_1
     221: checkcast     #39                 // class java/util/Collection
     224: invokeinterface #79,  1           // InterfaceMethod java/util/Collection.size:()I
     229: istore        4
     231: iload_3
     232: iload         4
     234: if_icmpge     384
     237: iconst_0
     238: istore        5
     240: iload         5
     242: iload_3
     243: if_icmpge     378
     246: aload_1
     247: iload_3
     248: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     253: checkcast     #70                 // class "[I"
     256: invokestatic  #85                 // Method kotlin/collections/ArraysKt.getIndices:([I)Lkotlin/ranges/IntRange;
     259: checkcast     #87                 // class java/lang/Iterable
     262: astore        7
     264: iconst_0
     265: istore        8
     267: aload         7
     269: invokeinterface #91,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     274: astore        9
     276: aload         9
     278: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     283: ifeq          349
     286: aload         9
     288: checkcast     #99                 // class kotlin/collections/IntIterator
     291: invokevirtual #102                // Method kotlin/collections/IntIterator.nextInt:()I
     294: istore        10
     296: iload         8
     298: iload         10
     300: istore        11
     302: istore        17
     304: iconst_0
     305: istore        12
     307: aload_1
     308: iload_3
     309: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     314: checkcast     #70                 // class "[I"
     317: iload         11
     319: iaload
     320: aload_1
     321: iload         5
     323: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     328: checkcast     #70                 // class "[I"
     331: iload         11
     333: iaload
     334: invokestatic  #106                // Method dist:(II)I
     337: istore        18
     339: iload         17
     341: iload         18
     343: iadd
     344: istore        8
     346: goto          276
     349: iload         8
     351: istore        6
     353: aload_2
     354: new           #108                // class yandex/y2022/qual/DKt$main$Edge
     357: dup
     358: iload_3
     359: iload         5
     361: iload         6
     363: invokespecial #111                // Method yandex/y2022/qual/DKt$main$Edge."<init>":(III)V
     366: invokeinterface #112,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     371: pop
     372: iinc          5, 1
     375: goto          240
     378: iinc          3, 1
     381: goto          231
     384: new           #114                // class yandex/y2022/qual/DisjointSetUnion
     387: dup
     388: aload_1
     389: invokeinterface #115,  1          // InterfaceMethod java/util/List.size:()I
     394: invokespecial #116                // Method yandex/y2022/qual/DisjointSetUnion."<init>":(I)V
     397: astore_3
     398: iconst_0
     399: istore        4
     401: aload_2
     402: checkcast     #87                 // class java/lang/Iterable
     405: astore        6
     407: iconst_0
     408: istore        7
     410: aload         6
     412: new           #118                // class yandex/y2022/qual/DKt$main$$inlined$sortedBy$1
     415: dup
     416: invokespecial #119                // Method yandex/y2022/qual/DKt$main$$inlined$sortedBy$1."<init>":()V
     419: checkcast     #121                // class java/util/Comparator
     422: invokestatic  #125                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     425: invokeinterface #126,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     430: astore        5
     432: aload         5
     434: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     439: ifeq          484
     442: aload         5
     444: invokeinterface #130,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     449: checkcast     #108                // class yandex/y2022/qual/DKt$main$Edge
     452: astore        6
     454: aload_3
     455: aload         6
     457: invokevirtual #133                // Method yandex/y2022/qual/DKt$main$Edge.getU:()I
     460: aload         6
     462: invokevirtual #136                // Method yandex/y2022/qual/DKt$main$Edge.getV:()I
     465: invokevirtual #140                // Method yandex/y2022/qual/DisjointSetUnion.unite:(II)Z
     468: ifeq          432
     471: iload         4
     473: aload         6
     475: invokevirtual #143                // Method yandex/y2022/qual/DKt$main$Edge.getLen:()I
     478: iadd
     479: istore        4
     481: goto          432
     484: getstatic     #149                // Field java/lang/System.out:Ljava/io/PrintStream;
     487: iload         4
     489: invokevirtual #154                // Method java/io/PrintStream.println:(I)V
     492: return

  private static final int dist(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: if_icmpne     7
       5: iconst_0
       6: ireturn
       7: iload_0
       8: iload_1
       9: ixor
      10: iconst_2
      11: if_icmpne     16
      14: iconst_2
      15: ireturn
      16: iconst_1
      17: ireturn

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #192                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #198                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #32                 // Method readLn:()Ljava/lang/String;
       3: checkcast     #34                 // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #202                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #204                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #208                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      25: areturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #211                // Method readStrings:()Ljava/util/List;
       3: checkcast     #87                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #24                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #215                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #39                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #91,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #130,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #202                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #219                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #57                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #61,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #12                 // class java/util/List
      96: nop
      97: areturn

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

Compiled from "Comparisons.kt"
public final class yandex.y2022.qual.DKt$main$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public yandex.y2022.qual.DKt$main$$inlined$sortedBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class yandex/y2022/qual/DKt$main$Edge
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method yandex/y2022/qual/DKt$main$Edge.getLen:()I
      12: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: checkcast     #35                 // class java/lang/Comparable
      18: aload_2
      19: checkcast     #23                 // class yandex/y2022/qual/DKt$main$Edge
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method yandex/y2022/qual/DKt$main$Edge.getLen:()I
      32: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: aload         5
      37: swap
      38: checkcast     #35                 // class java/lang/Comparable
      41: invokestatic  #41                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}


package yandex.y2022.qual

import kotlin.random.Random

fun main() {
	val (n, q) = readInts()
	val dsu = DisjointSetUnionRPS(n)
	val three = IntArray(n + 1)
	three[0] = 1
	for (i in 1 until three.size) three[i] = (3 * three[i - 1].toModular()).x
	repeat(q) {
		val (uIn, vIn, resultIn) = readStrings()
		val u = uIn.toInt() - 1
		val v = vIn.toInt() - 1
		val result = "LDW".indexOf(resultIn) - 1
		dsu.unite(u, v, result)
		println(if (dsu.broken) 0 else three[dsu.degrees])
	}
}

private class DisjointSetUnionRPS(n: Int) {
	val p: IntArray
	val diffP: IntArray
	val r: Random = Random(566)
	var broken: Boolean
	var degrees: Int

	init {
		p = IntArray(n)
		for (i in p.indices) {
			p[i] = i
		}
		diffP = IntArray(n)
		broken = false
		degrees = n
	}

	operator fun get(v: Int): Pair<Int, Int> {
		if (p[v] == v) return v to 0
		val (r, diffR) = get(p[v])
		p[v] = r
		diffP[v] += diffR
		return p[v] to diffP[v]
	}

	fun unite(u: Int, v: Int, d: Int) {
		val (uu, diffU) = get(u)
		val (vv, diffV) = get(v)
		if (vv == uu) {
			if ((diffU - diffV - d) % 3 != 0) broken = true
			return
		}
		degrees--
		if (r.nextBoolean()) {
			p[vv] = uu
			diffP[vv] = diffU - diffV - d
		} else {
			p[uu] = vv
			diffP[uu] = diffV - diffU + d
		}
	}
}

private fun Int.toModular() = Modular(this)//toDouble()
private class Modular {
	companion object {
		const val M = 1_000_000_007
	}
	val x: Int
	@Suppress("ConvertSecondaryConstructorToPrimary")
	constructor(value: Int) { x = (value % M).let { if (it < 0) it + M else it } }
	operator fun plus(that: Modular) = Modular((x + that.x) % M)
	operator fun minus(that: Modular) = Modular((x + M - that.x) % M)
	operator fun times(that: Modular) = (x.toLong() * that.x % M).toInt().toModular()
	private fun modInverse() = Modular(x.toBigInteger().modInverse(M.toBigInteger()).toInt())
	operator fun div(that: Modular) = times(that.modInverse())
	override fun toString() = x.toString()
}
private operator fun Int.plus(that: Modular) = Modular(this) + that
private operator fun Int.minus(that: Modular) = Modular(this) - that
private operator fun Int.times(that: Modular) = Modular(this) * that
private operator fun Int.div(that: Modular) = Modular(this) / that

private fun readLn() = readLine()!!
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

Compiled from "e.kt"
public final class yandex.y2022.qual.EKt {
  public static final void main();
    Code:
       0: invokestatic  #10                 // Method readInts:()Ljava/util/List;
       3: astore_0
       4: aload_0
       5: iconst_0
       6: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      11: checkcast     #18                 // class java/lang/Number
      14: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      17: istore_1
      18: aload_0
      19: iconst_1
      20: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      25: checkcast     #18                 // class java/lang/Number
      28: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      31: istore_2
      32: new           #24                 // class yandex/y2022/qual/DisjointSetUnionRPS
      35: dup
      36: iload_1
      37: invokespecial #28                 // Method yandex/y2022/qual/DisjointSetUnionRPS."<init>":(I)V
      40: astore_3
      41: iload_1
      42: iconst_1
      43: iadd
      44: newarray       int
      46: astore        4
      48: aload         4
      50: iconst_0
      51: iconst_1
      52: iastore
      53: iconst_1
      54: istore        5
      56: aload         4
      58: arraylength
      59: istore        6
      61: iload         5
      63: iload         6
      65: if_icmpge     96
      68: aload         4
      70: iload         5
      72: iconst_3
      73: aload         4
      75: iload         5
      77: iconst_1
      78: isub
      79: iaload
      80: invokestatic  #32                 // Method toModular:(I)Lyandex/y2022/qual/Modular;
      83: invokestatic  #36                 // Method times:(ILyandex/y2022/qual/Modular;)Lyandex/y2022/qual/Modular;
      86: invokevirtual #41                 // Method yandex/y2022/qual/Modular.getX:()I
      89: iastore
      90: iinc          5, 1
      93: goto          61
      96: iconst_0
      97: istore        5
      99: iload         5
     101: iload_2
     102: if_icmpge     238
     105: iload         5
     107: istore        6
     109: iconst_0
     110: istore        7
     112: invokestatic  #44                 // Method readStrings:()Ljava/util/List;
     115: astore        8
     117: aload         8
     119: iconst_0
     120: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     125: checkcast     #46                 // class java/lang/String
     128: astore        9
     130: aload         8
     132: iconst_1
     133: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     138: checkcast     #46                 // class java/lang/String
     141: astore        10
     143: aload         8
     145: iconst_2
     146: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     151: checkcast     #46                 // class java/lang/String
     154: astore        11
     156: aload         9
     158: invokestatic  #52                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     161: iconst_1
     162: isub
     163: istore        12
     165: aload         10
     167: invokestatic  #52                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     170: iconst_1
     171: isub
     172: istore        13
     174: ldc           #54                 // String LDW
     176: checkcast     #56                 // class java/lang/CharSequence
     179: aload         11
     181: iconst_0
     182: iconst_0
     183: bipush        6
     185: aconst_null
     186: invokestatic  #62                 // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
     189: iconst_1
     190: isub
     191: istore        14
     193: aload_3
     194: iload         12
     196: iload         13
     198: iload         14
     200: invokevirtual #66                 // Method yandex/y2022/qual/DisjointSetUnionRPS.unite:(III)V
     203: aload_3
     204: invokevirtual #70                 // Method yandex/y2022/qual/DisjointSetUnionRPS.getBroken:()Z
     207: ifeq          214
     210: iconst_0
     211: goto          221
     214: aload         4
     216: aload_3
     217: invokevirtual #73                 // Method yandex/y2022/qual/DisjointSetUnionRPS.getDegrees:()I
     220: iaload
     221: istore        15
     223: getstatic     #79                 // Field java/lang/System.out:Ljava/io/PrintStream;
     226: iload         15
     228: invokevirtual #84                 // Method java/io/PrintStream.println:(I)V
     231: nop
     232: iinc          5, 1
     235: goto          99
     238: return

  private static final yandex.y2022.qual.Modular toModular(int);
    Code:
       0: new           #38                 // class yandex/y2022/qual/Modular
       3: dup
       4: iload_0
       5: invokespecial #103                // Method yandex/y2022/qual/Modular."<init>":(I)V
       8: areturn

  private static final yandex.y2022.qual.Modular plus(int, yandex.y2022.qual.Modular);
    Code:
       0: new           #38                 // class yandex/y2022/qual/Modular
       3: dup
       4: iload_0
       5: invokespecial #103                // Method yandex/y2022/qual/Modular."<init>":(I)V
       8: aload_1
       9: invokevirtual #108                // Method yandex/y2022/qual/Modular.plus:(Lyandex/y2022/qual/Modular;)Lyandex/y2022/qual/Modular;
      12: areturn

  private static final yandex.y2022.qual.Modular minus(int, yandex.y2022.qual.Modular);
    Code:
       0: new           #38                 // class yandex/y2022/qual/Modular
       3: dup
       4: iload_0
       5: invokespecial #103                // Method yandex/y2022/qual/Modular."<init>":(I)V
       8: aload_1
       9: invokevirtual #114                // Method yandex/y2022/qual/Modular.minus:(Lyandex/y2022/qual/Modular;)Lyandex/y2022/qual/Modular;
      12: areturn

  private static final yandex.y2022.qual.Modular times(int, yandex.y2022.qual.Modular);
    Code:
       0: new           #38                 // class yandex/y2022/qual/Modular
       3: dup
       4: iload_0
       5: invokespecial #103                // Method yandex/y2022/qual/Modular."<init>":(I)V
       8: aload_1
       9: invokevirtual #117                // Method yandex/y2022/qual/Modular.times:(Lyandex/y2022/qual/Modular;)Lyandex/y2022/qual/Modular;
      12: areturn

  private static final yandex.y2022.qual.Modular div(int, yandex.y2022.qual.Modular);
    Code:
       0: new           #38                 // class yandex/y2022/qual/Modular
       3: dup
       4: iload_0
       5: invokespecial #103                // Method yandex/y2022/qual/Modular."<init>":(I)V
       8: aload_1
       9: invokevirtual #121                // Method yandex/y2022/qual/Modular.div:(Lyandex/y2022/qual/Modular;)Lyandex/y2022/qual/Modular;
      12: areturn

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #129                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #135                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #138                // Method readLn:()Ljava/lang/String;
       3: checkcast     #56                 // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #46                 // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #140                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #144                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      25: areturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #44                 // Method readStrings:()Ljava/util/List;
       3: checkcast     #147                // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #149                // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #155                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #156                // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #158                // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #162,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #167,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #171,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #46                 // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #52                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #175                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #179,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #12                 // class java/util/List
      96: nop
      97: areturn

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

  public static final yandex.y2022.qual.Modular access$toModular(int);
    Code:
       0: iload_0
       1: invokestatic  #32                 // Method toModular:(I)Lyandex/y2022/qual/Modular;
       4: areturn
}


package yandex.y2022.finals

fun main() {
	val (a, m) = readLongs()
	val ps = mutableListOf<Long>()
	var b = a
	for (p in 2..b) {
		if (b == 1L) break
		if (p * p > b) {
			ps.add(b)
			break
		}
		if (b % p != 0L) continue
		ps.add(p)
		while (b % p == 0L) b /= p
	}
	var ans = Long.MAX_VALUE
	for (r in 0..2) {
		if ((r != 0) and (3 in ps)) continue
		var cur = 1L
		for (p in ps) {
			b = a
			var k = 0L
			while (b % p == 0L) {
				b /= p
				k++
			}
			k *= m
			if (p == 3L) {
				cur = maxOf(cur, searchUsual(k, 3))
				continue
			}
			if (r == 0) {
				cur = maxOf(cur, 3 * searchUsual(k, p))
				continue
			}
			cur = maxOf(cur, searchUnusual(k, p, r))
		}
		ans = minOf(ans, cur)
	}
	println(ans)
}

fun searchUsual(m: Long, p: Long): Long {
	var low = 0L
	var high = p * m
	while (low + 1 < high) {
		val mid = low + (high - low) / 2
		var x = mid / p
		var count = 0L
		while (x > 0) {
			count += x
			x /= p
		}
		if (count >= m) high = mid else low = mid
	}
	return high
}

fun searchUnusual(m: Long, p: Long, r: Int): Long {
	var low = 0L
	var high = m * p
	while (low + 1 < high) {
		val mid = low + (high - low) / 2
		var t = p
		var count = 0L
		while (t <= 3 * mid + r) {
			val f = (if ((t % 3).toInt() == r) t else 2 * t) / 3
			if (mid >= f) {
				count += (mid - f) / t + 1
			}
//			if (t * 3 > 3 * mid + r) break
			if (t >= mid + 1) break
			t *= p
		}
		if (count >= m) high = mid else low = mid
	}
	return 3 * high + r
}

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }
private fun readLongs() = readStrings().map { it.toLong() }

Compiled from "c.kt"
public final class yandex.y2022.finals.CKt {
  public static final void main();
    Code:
       0: invokestatic  #10                 // Method readLongs:()Ljava/util/List;
       3: astore_0
       4: aload_0
       5: iconst_0
       6: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      11: checkcast     #18                 // class java/lang/Number
      14: invokevirtual #22                 // Method java/lang/Number.longValue:()J
      17: lstore_1
      18: aload_0
      19: iconst_1
      20: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      25: checkcast     #18                 // class java/lang/Number
      28: invokevirtual #22                 // Method java/lang/Number.longValue:()J
      31: lstore_3
      32: new           #24                 // class java/util/ArrayList
      35: dup
      36: invokespecial #27                 // Method java/util/ArrayList."<init>":()V
      39: checkcast     #12                 // class java/util/List
      42: astore        5
      44: lload_1
      45: lstore        6
      47: ldc2_w        #28                 // long 2l
      50: lstore        8
      52: lload         6
      54: lstore        10
      56: lload         8
      58: lload         10
      60: lcmp
      61: ifgt          158
      64: lload         6
      66: lconst_1
      67: lcmp
      68: ifeq          158
      71: lload         8
      73: lload         8
      75: lmul
      76: lload         6
      78: lcmp
      79: ifle          98
      82: aload         5
      84: lload         6
      86: invokestatic  #35                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      89: invokeinterface #39,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      94: pop
      95: goto          158
      98: lload         6
     100: lload         8
     102: lrem
     103: lconst_0
     104: lcmp
     105: ifne          141
     108: aload         5
     110: lload         8
     112: invokestatic  #35                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     115: invokeinterface #39,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     120: pop
     121: lload         6
     123: lload         8
     125: lrem
     126: lconst_0
     127: lcmp
     128: ifne          141
     131: lload         6
     133: lload         8
     135: ldiv
     136: lstore        6
     138: goto          121
     141: lload         8
     143: lload         10
     145: lcmp
     146: ifeq          158
     149: lload         8
     151: lconst_1
     152: ladd
     153: lstore        8
     155: goto          64
     158: ldc2_w        #40                 // long 9223372036854775807l
     161: lstore        8
     163: iconst_0
     164: istore        10
     166: iload         10
     168: iconst_3
     169: if_icmpge     364
     172: iload         10
     174: ifeq          181
     177: iconst_1
     178: goto          182
     181: iconst_0
     182: aload         5
     184: ldc2_w        #42                 // long 3l
     187: invokestatic  #35                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     190: invokeinterface #46,  2           // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     195: iand
     196: ifne          358
     199: lconst_1
     200: lstore        11
     202: aload         5
     204: invokeinterface #50,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     209: astore        13
     211: aload         13
     213: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     218: ifeq          349
     221: aload         13
     223: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     228: checkcast     #18                 // class java/lang/Number
     231: invokevirtual #22                 // Method java/lang/Number.longValue:()J
     234: lstore        14
     236: lload_1
     237: lstore        6
     239: lconst_0
     240: lstore        16
     242: lload         6
     244: lload         14
     246: lrem
     247: lconst_0
     248: lcmp
     249: ifne          272
     252: lload         6
     254: lload         14
     256: ldiv
     257: lstore        6
     259: lload         16
     261: lstore        18
     263: lload         18
     265: lconst_1
     266: ladd
     267: lstore        16
     269: goto          242
     272: lload         16
     274: lload_3
     275: lmul
     276: lstore        16
     278: lload         14
     280: ldc2_w        #42                 // long 3l
     283: lcmp
     284: ifne          305
     287: lload         11
     289: lload         16
     291: ldc2_w        #42                 // long 3l
     294: invokestatic  #64                 // Method searchUsual:(JJ)J
     297: invokestatic  #69                 // Method java/lang/Math.max:(JJ)J
     300: lstore        11
     302: goto          211
     305: iload         10
     307: ifne          330
     310: lload         11
     312: iconst_3
     313: i2l
     314: lload         16
     316: lload         14
     318: invokestatic  #64                 // Method searchUsual:(JJ)J
     321: lmul
     322: invokestatic  #69                 // Method java/lang/Math.max:(JJ)J
     325: lstore        11
     327: goto          211
     330: lload         11
     332: lload         16
     334: lload         14
     336: iload         10
     338: invokestatic  #73                 // Method searchUnusual:(JJI)J
     341: invokestatic  #69                 // Method java/lang/Math.max:(JJ)J
     344: lstore        11
     346: goto          211
     349: lload         8
     351: lload         11
     353: invokestatic  #76                 // Method java/lang/Math.min:(JJ)J
     356: lstore        8
     358: iinc          10, 1
     361: goto          166
     364: getstatic     #82                 // Field java/lang/System.out:Ljava/io/PrintStream;
     367: lload         8
     369: invokevirtual #88                 // Method java/io/PrintStream.println:(J)V
     372: return

  public static final long searchUsual(long, long);
    Code:
       0: lconst_0
       1: lstore        4
       3: lload_2
       4: lload_0
       5: lmul
       6: lstore        6
       8: lload         4
      10: lconst_1
      11: ladd
      12: lload         6
      14: lcmp
      15: ifge          84
      18: lload         4
      20: lload         6
      22: lload         4
      24: lsub
      25: iconst_2
      26: i2l
      27: ldiv
      28: ladd
      29: lstore        8
      31: lload         8
      33: lload_2
      34: ldiv
      35: lstore        10
      37: lconst_0
      38: lstore        12
      40: lload         10
      42: lconst_0
      43: lcmp
      44: ifle          63
      47: lload         12
      49: lload         10
      51: ladd
      52: lstore        12
      54: lload         10
      56: lload_2
      57: ldiv
      58: lstore        10
      60: goto          40
      63: lload         12
      65: lload_0
      66: lcmp
      67: iflt          77
      70: lload         8
      72: lstore        6
      74: goto          8
      77: lload         8
      79: lstore        4
      81: goto          8
      84: lload         6
      86: lreturn

  public static final long searchUnusual(long, long, int);
    Code:
       0: lconst_0
       1: lstore        5
       3: lload_0
       4: lload_2
       5: lmul
       6: lstore        7
       8: lload         5
      10: lconst_1
      11: ladd
      12: lload         7
      14: lcmp
      15: ifge          141
      18: lload         5
      20: lload         7
      22: lload         5
      24: lsub
      25: iconst_2
      26: i2l
      27: ldiv
      28: ladd
      29: lstore        9
      31: lload_2
      32: lstore        11
      34: lconst_0
      35: lstore        13
      37: lload         11
      39: iconst_3
      40: i2l
      41: lload         9
      43: lmul
      44: iload         4
      46: i2l
      47: ladd
      48: lcmp
      49: ifgt          120
      52: lload         11
      54: iconst_3
      55: i2l
      56: lrem
      57: l2i
      58: iload         4
      60: if_icmpne     68
      63: lload         11
      65: goto          73
      68: iconst_2
      69: i2l
      70: lload         11
      72: lmul
      73: iconst_3
      74: i2l
      75: ldiv
      76: lstore        15
      78: lload         9
      80: lload         15
      82: lcmp
      83: iflt          101
      86: lload         13
      88: lload         9
      90: lload         15
      92: lsub
      93: lload         11
      95: ldiv
      96: lconst_1
      97: ladd
      98: ladd
      99: lstore        13
     101: lload         11
     103: lload         9
     105: lconst_1
     106: ladd
     107: lcmp
     108: ifge          120
     111: lload         11
     113: lload_2
     114: lmul
     115: lstore        11
     117: goto          37
     120: lload         13
     122: lload_0
     123: lcmp
     124: iflt          134
     127: lload         9
     129: lstore        7
     131: goto          8
     134: lload         9
     136: lstore        5
     138: goto          8
     141: iconst_3
     142: i2l
     143: lload         7
     145: lmul
     146: iload         4
     148: i2l
     149: ladd
     150: lreturn

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #114                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #120                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final int readInt();
    Code:
       0: invokestatic  #124                // Method readLn:()Ljava/lang/String;
       3: invokestatic  #130                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #124                // Method readLn:()Ljava/lang/String;
       3: checkcast     #134                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #136                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #138                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #144                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      25: areturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #148                // Method readStrings:()Ljava/util/List;
       3: checkcast     #150                // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #24                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #156                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #159                // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #161                // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #162,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #136                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #130                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #166,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #12                 // class java/util/List
      96: nop
      97: areturn

  private static final java.util.List<java.lang.Long> readLongs();
    Code:
       0: invokestatic  #148                // Method readStrings:()Ljava/util/List;
       3: checkcast     #150                // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #24                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #156                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #159                // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #161                // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #162,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #136                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #183                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      76: nop
      77: invokestatic  #35                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      80: aload         9
      82: swap
      83: invokeinterface #166,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #12                 // class java/util/List
      96: nop
      97: areturn

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


package yandex.y2022.finals

import java.util.*
import kotlin.math.sign

fun main() {
	readLn()
	val our = readInts()
	val their = readInts()
	val e = List(our.size) { i -> IntArray(their.size) { j -> -(our[i] - their[j]).sign } }
	val h = hungarian(e)
	println(-h)
}

fun hungarian(e: List<IntArray>): Int {
	val ans = IntArray(e.size)
	Arrays.fill(ans, -1)
	val infty = Int.MAX_VALUE / 3
	var swap = false
	val n1 = e.size
	val n2 = e[0].size
	val u = IntArray(n1 + 1)
	val v = IntArray(n2 + 1)
	val p = IntArray(n2 + 1)
	val way = IntArray(n2 + 1)
	for (i in 1..n1) {
		p[0] = i
		var j0 = 0
		val minv = IntArray(n2 + 1)
		Arrays.fill(minv, infty)
		val used = BooleanArray(n2 + 1)
		do {
			used[j0] = true
			val i0 = p[j0]
			var j1 = 0
			var delta = infty
			for (j in 1..n2) {
				if (!used[j]) {
					val cur = e[i0 - 1][j - 1] - u[i0] - v[j]
					if (cur < minv[j]) {
						minv[j] = cur
						way[j] = j0
					}
					if (minv[j] < delta) {
						delta = minv[j]
						j1 = j
					}
				}
			}
			for (j in 0..n2) {
				if (used[j]) {
					u[p[j]] += delta
					v[j] -= delta
				} else {
					minv[j] -= delta
				}
			}
			j0 = j1
		} while (p[j0] != 0)
		do {
			val j1 = way[j0]
			p[j0] = p[j1]
			j0 = j1
		} while (j0 > 0)
	}
	var sum = 0
	for (j in 1..n2) {
		if (p[j] > 0) {
			// if (e[p[j] - 1][j - 1] >= infty) no matching of size n1;
			sum += e[p[j] - 1][j - 1];
			if (swap) {
				ans[j - 1] = p[j] - 1
			} else {
				ans[p[j] - 1] = j - 1
			}
		}
	}
	return sum
}

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

Compiled from "a_small.kt"
public final class yandex.y2022.finals.A_smallKt {
  public static final void main();
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: pop
       4: invokestatic  #14                 // Method readInts:()Ljava/util/List;
       7: astore_0
       8: invokestatic  #14                 // Method readInts:()Ljava/util/List;
      11: astore_1
      12: aload_0
      13: invokeinterface #20,  1           // InterfaceMethod java/util/List.size:()I
      18: istore_3
      19: new           #22                 // class java/util/ArrayList
      22: dup
      23: iload_3
      24: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
      27: astore        4
      29: iconst_0
      30: istore        5
      32: iload         5
      34: iload_3
      35: if_icmpge     140
      38: iload         5
      40: istore        6
      42: aload         4
      44: iload         6
      46: istore        7
      48: astore        13
      50: iconst_0
      51: istore        8
      53: iconst_0
      54: istore        9
      56: aload_1
      57: invokeinterface #20,  1           // InterfaceMethod java/util/List.size:()I
      62: istore        10
      64: iload         10
      66: newarray       int
      68: astore        11
      70: iload         9
      72: iload         10
      74: if_icmpge     125
      77: iload         9
      79: istore        12
      81: aload         11
      83: iload         12
      85: aload_0
      86: iload         7
      88: invokeinterface #30,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      93: checkcast     #32                 // class java/lang/Number
      96: invokevirtual #35                 // Method java/lang/Number.intValue:()I
      99: aload_1
     100: iload         12
     102: invokeinterface #30,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     107: checkcast     #32                 // class java/lang/Number
     110: invokevirtual #35                 // Method java/lang/Number.intValue:()I
     113: isub
     114: invokestatic  #41                 // Method kotlin/math/MathKt.getSign:(I)I
     117: ineg
     118: iastore
     119: iinc          9, 1
     122: goto          70
     125: aload         11
     127: aload         13
     129: swap
     130: invokevirtual #45                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     133: pop
     134: iinc          5, 1
     137: goto          32
     140: aload         4
     142: checkcast     #16                 // class java/util/List
     145: astore_2
     146: aload_2
     147: invokestatic  #49                 // Method hungarian:(Ljava/util/List;)I
     150: istore_3
     151: iload_3
     152: ineg
     153: istore        4
     155: getstatic     #55                 // Field java/lang/System.out:Ljava/io/PrintStream;
     158: iload         4
     160: invokevirtual #60                 // Method java/io/PrintStream.println:(I)V
     163: return

  public static final int hungarian(java.util.List<int[]>);
    Code:
       0: aload_0
       1: ldc           #73                 // String e
       3: invokestatic  #79                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #20,  1           // InterfaceMethod java/util/List.size:()I
      12: newarray       int
      14: astore_1
      15: aload_1
      16: iconst_m1
      17: invokestatic  #85                 // Method java/util/Arrays.fill:([II)V
      20: ldc           #86                 // int 715827882
      22: istore_2
      23: iconst_0
      24: istore_3
      25: aload_0
      26: invokeinterface #20,  1           // InterfaceMethod java/util/List.size:()I
      31: istore        4
      33: aload_0
      34: iconst_0
      35: invokeinterface #30,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      40: checkcast     #70                 // class "[I"
      43: arraylength
      44: istore        5
      46: iload         4
      48: iconst_1
      49: iadd
      50: newarray       int
      52: astore        6
      54: iload         5
      56: iconst_1
      57: iadd
      58: newarray       int
      60: astore        7
      62: iload         5
      64: iconst_1
      65: iadd
      66: newarray       int
      68: astore        8
      70: iload         5
      72: iconst_1
      73: iadd
      74: newarray       int
      76: astore        9
      78: iconst_1
      79: istore        10
      81: iload         10
      83: iload         4
      85: if_icmpgt     385
      88: aload         8
      90: iconst_0
      91: iload         10
      93: iastore
      94: iconst_0
      95: istore        11
      97: iload         5
      99: iconst_1
     100: iadd
     101: newarray       int
     103: astore        12
     105: aload         12
     107: iload_2
     108: invokestatic  #85                 // Method java/util/Arrays.fill:([II)V
     111: iload         5
     113: iconst_1
     114: iadd
     115: newarray       boolean
     117: astore        13
     119: aload         13
     121: iload         11
     123: iconst_1
     124: bastore
     125: aload         8
     127: iload         11
     129: iaload
     130: istore        14
     132: iconst_0
     133: istore        15
     135: iload_2
     136: istore        16
     138: iconst_1
     139: istore        17
     141: iload         17
     143: iload         5
     145: if_icmpgt     246
     148: aload         13
     150: iload         17
     152: baload
     153: ifne          233
     156: aload_0
     157: iload         14
     159: iconst_1
     160: isub
     161: invokeinterface #30,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     166: checkcast     #70                 // class "[I"
     169: iload         17
     171: iconst_1
     172: isub
     173: iaload
     174: aload         6
     176: iload         14
     178: iaload
     179: isub
     180: aload         7
     182: iload         17
     184: iaload
     185: isub
     186: istore        18
     188: iload         18
     190: aload         12
     192: iload         17
     194: iaload
     195: if_icmpge     212
     198: aload         12
     200: iload         17
     202: iload         18
     204: iastore
     205: aload         9
     207: iload         17
     209: iload         11
     211: iastore
     212: aload         12
     214: iload         17
     216: iaload
     217: iload         16
     219: if_icmpge     233
     222: aload         12
     224: iload         17
     226: iaload
     227: istore        16
     229: iload         17
     231: istore        15
     233: iload         17
     235: iload         5
     237: if_icmpeq     246
     240: iinc          17, 1
     243: goto          148
     246: iconst_0
     247: istore        17
     249: iload         17
     251: iload         5
     253: if_icmpgt     334
     256: aload         13
     258: iload         17
     260: baload
     261: ifeq          304
     264: aload         8
     266: iload         17
     268: iaload
     269: istore        18
     271: aload         6
     273: iload         18
     275: aload         6
     277: iload         18
     279: iaload
     280: iload         16
     282: iadd
     283: iastore
     284: iload         17
     286: istore        18
     288: aload         7
     290: iload         18
     292: aload         7
     294: iload         18
     296: iaload
     297: iload         16
     299: isub
     300: iastore
     301: goto          321
     304: iload         17
     306: istore        18
     308: aload         12
     310: iload         18
     312: aload         12
     314: iload         18
     316: iaload
     317: iload         16
     319: isub
     320: iastore
     321: iload         17
     323: iload         5
     325: if_icmpeq     334
     328: iinc          17, 1
     331: goto          256
     334: iload         15
     336: istore        11
     338: aload         8
     340: iload         11
     342: iaload
     343: ifne          119
     346: aload         9
     348: iload         11
     350: iaload
     351: istore        14
     353: aload         8
     355: iload         11
     357: aload         8
     359: iload         14
     361: iaload
     362: iastore
     363: iload         14
     365: istore        11
     367: iload         11
     369: ifgt          346
     372: iload         10
     374: iload         4
     376: if_icmpeq     385
     379: iinc          10, 1
     382: goto          88
     385: iconst_0
     386: istore        10
     388: iconst_1
     389: istore        11
     391: iload         11
     393: iload         5
     395: if_icmpgt     459
     398: aload         8
     400: iload         11
     402: iaload
     403: ifle          446
     406: iload         10
     408: aload_0
     409: aload         8
     411: iload         11
     413: iaload
     414: iconst_1
     415: isub
     416: invokeinterface #30,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     421: checkcast     #70                 // class "[I"
     424: iload         11
     426: iconst_1
     427: isub
     428: iaload
     429: iadd
     430: istore        10
     432: nop
     433: aload_1
     434: aload         8
     436: iload         11
     438: iaload
     439: iconst_1
     440: isub
     441: iload         11
     443: iconst_1
     444: isub
     445: iastore
     446: iload         11
     448: iload         5
     450: if_icmpeq     459
     453: iinc          11, 1
     456: goto          398
     459: iload         10
     461: ireturn

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #112                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #116                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final int readInt();
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: invokestatic  #123                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: checkcast     #127                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #129                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #131                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #137                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      25: areturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #140                // Method readStrings:()Ljava/util/List;
       3: checkcast     #142                // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #22                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #148                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #150                // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #154,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #160,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #129                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #123                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #168                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #169,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #16                 // class java/util/List
      96: nop
      97: areturn

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