package codeforces.round614

fun main() {
	readLn()
	val a = readInts()
	val aCount = a.groupBy { it }.mapValues { it.value.size }
	var b = aCount.keys.toList()
	val (primes, factPrimes) = List(2) { MutableList(2) { listOf<Int>() } }
	for (i in 2..b.maxOrNull()!!) {
		val j = (2..i).first { i % it == 0 }
		primes.add(primes[i / j].plus(j))
		factPrimes.add(factPrimes[i - 1].plus(primes[i]).sortedDescending())
	}
	var ans = aCount.map { factPrimes[it.key].size * 1L * it.value }.sum()
	for (x in factPrimes.last().indices) {
		val groups = b.groupBy { factPrimes[it].getOrNull(x) }
		val win = groups.mapValues { entry -> 2 * entry.value.sumOf { aCount.getValue(it) } - a.size }
		val p = win.entries.firstOrNull { it.value > 0 }?.key ?: break
		ans -= win.getValue(p)
		b = groups.getValue(p)
	}
	println(ans)
}

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

Compiled from "d.kt"
public final class codeforces.round614.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: aload_0
       9: checkcast     #16                 // class java/lang/Iterable
      12: astore_2
      13: iconst_0
      14: istore_3
      15: aload_2
      16: astore        4
      18: new           #18                 // class java/util/LinkedHashMap
      21: dup
      22: invokespecial #21                 // Method java/util/LinkedHashMap."<init>":()V
      25: checkcast     #23                 // class java/util/Map
      28: astore        5
      30: iconst_0
      31: istore        6
      33: aload         4
      35: invokeinterface #27,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        7
      42: aload         7
      44: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          157
      52: aload         7
      54: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        8
      61: aload         8
      63: checkcast     #39                 // class java/lang/Number
      66: invokevirtual #43                 // Method java/lang/Number.intValue:()I
      69: istore        9
      71: iconst_0
      72: istore        10
      74: iload         9
      76: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      79: astore        11
      81: aload         5
      83: astore        12
      85: iconst_0
      86: istore        13
      88: aload         12
      90: aload         11
      92: invokeinterface #53,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      97: astore        14
      99: aload         14
     101: ifnonnull     136
     104: iconst_0
     105: istore        15
     107: new           #55                 // class java/util/ArrayList
     110: dup
     111: invokespecial #56                 // Method java/util/ArrayList."<init>":()V
     114: checkcast     #58                 // class java/util/List
     117: astore        15
     119: aload         12
     121: aload         11
     123: aload         15
     125: invokeinterface #62,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     130: pop
     131: aload         15
     133: goto          138
     136: aload         14
     138: nop
     139: checkcast     #58                 // class java/util/List
     142: astore        9
     144: aload         9
     146: aload         8
     148: invokeinterface #66,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     153: pop
     154: goto          42
     157: aload         5
     159: nop
     160: astore_2
     161: nop
     162: iconst_0
     163: istore_3
     164: aload_2
     165: astore        4
     167: new           #18                 // class java/util/LinkedHashMap
     170: dup
     171: aload_2
     172: invokeinterface #69,  1           // InterfaceMethod java/util/Map.size:()I
     177: invokestatic  #75                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     180: invokespecial #78                 // Method java/util/LinkedHashMap."<init>":(I)V
     183: checkcast     #23                 // class java/util/Map
     186: astore        5
     188: iconst_0
     189: istore        6
     191: aload         4
     193: invokeinterface #82,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     198: checkcast     #16                 // class java/lang/Iterable
     201: astore        7
     203: iconst_0
     204: istore        8
     206: aload         7
     208: invokeinterface #27,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     213: astore        9
     215: aload         9
     217: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     222: ifeq          307
     225: aload         9
     227: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     232: astore        10
     234: aload         5
     236: aload         10
     238: checkcast     #84                 // class java/util/Map$Entry
     241: astore        11
     243: astore        12
     245: iconst_0
     246: istore        13
     248: aload         11
     250: invokeinterface #87,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     255: aload         12
     257: swap
     258: aload         10
     260: checkcast     #84                 // class java/util/Map$Entry
     263: astore        14
     265: astore        36
     267: astore        35
     269: iconst_0
     270: istore        15
     272: aload         14
     274: invokeinterface #90,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     279: checkcast     #58                 // class java/util/List
     282: invokeinterface #91,  1           // InterfaceMethod java/util/List.size:()I
     287: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     290: astore        37
     292: aload         35
     294: aload         36
     296: aload         37
     298: invokeinterface #62,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     303: pop
     304: goto          215
     307: aload         5
     309: nop
     310: nop
     311: astore_1
     312: aload_1
     313: invokeinterface #94,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     318: checkcast     #16                 // class java/lang/Iterable
     321: invokestatic  #100                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     324: astore_2
     325: iconst_2
     326: istore        4
     328: new           #55                 // class java/util/ArrayList
     331: dup
     332: iload         4
     334: invokespecial #101                // Method java/util/ArrayList."<init>":(I)V
     337: astore        5
     339: iconst_0
     340: istore        6
     342: iload         6
     344: iload         4
     346: if_icmpge     439
     349: iload         6
     351: istore        7
     353: aload         5
     355: iload         7
     357: istore        8
     359: astore        35
     361: iconst_0
     362: istore        9
     364: iconst_2
     365: istore        10
     367: new           #55                 // class java/util/ArrayList
     370: dup
     371: iload         10
     373: invokespecial #101                // Method java/util/ArrayList."<init>":(I)V
     376: astore        11
     378: iconst_0
     379: istore        12
     381: iload         12
     383: iload         10
     385: if_icmpge     420
     388: iload         12
     390: istore        13
     392: aload         11
     394: iload         13
     396: istore        14
     398: astore        15
     400: iconst_0
     401: istore        16
     403: invokestatic  #104                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     406: nop
     407: aload         15
     409: swap
     410: invokevirtual #105                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     413: pop
     414: iinc          12, 1
     417: goto          381
     420: aload         11
     422: checkcast     #58                 // class java/util/List
     425: nop
     426: aload         35
     428: swap
     429: invokevirtual #105                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     432: pop
     433: iinc          6, 1
     436: goto          342
     439: aload         5
     441: checkcast     #58                 // class java/util/List
     444: astore_3
     445: aload_3
     446: iconst_0
     447: invokeinterface #108,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     452: checkcast     #58                 // class java/util/List
     455: astore        4
     457: aload_3
     458: iconst_1
     459: invokeinterface #108,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     464: checkcast     #58                 // class java/util/List
     467: astore        5
     469: iconst_2
     470: istore        6
     472: aload_2
     473: checkcast     #16                 // class java/lang/Iterable
     476: invokestatic  #112                // Method kotlin/collections/CollectionsKt.maxOrNull:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     479: dup
     480: invokestatic  #118                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     483: checkcast     #39                 // class java/lang/Number
     486: invokevirtual #43                 // Method java/lang/Number.intValue:()I
     489: istore        7
     491: iload         6
     493: iload         7
     495: if_icmpgt     672
     498: new           #120                // class kotlin/ranges/IntRange
     501: dup
     502: iconst_2
     503: iload         6
     505: invokespecial #123                // Method kotlin/ranges/IntRange."<init>":(II)V
     508: checkcast     #16                 // class java/lang/Iterable
     511: astore        9
     513: iconst_0
     514: istore        10
     516: aload         9
     518: invokeinterface #27,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     523: astore        11
     525: aload         11
     527: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     532: ifeq          573
     535: aload         11
     537: checkcast     #125                // class kotlin/collections/IntIterator
     540: invokevirtual #128                // Method kotlin/collections/IntIterator.nextInt:()I
     543: istore        12
     545: iload         12
     547: istore        13
     549: iconst_0
     550: istore        14
     552: iload         6
     554: iload         13
     556: irem
     557: ifne          564
     560: iconst_1
     561: goto          565
     564: iconst_0
     565: ifeq          525
     568: iload         12
     570: goto          583
     573: new           #130                // class java/util/NoSuchElementException
     576: dup
     577: ldc           #132                // String Collection contains no element matching the predicate.
     579: invokespecial #135                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
     582: athrow
     583: istore        8
     585: aload         4
     587: aload         4
     589: iload         6
     591: iload         8
     593: idiv
     594: invokeinterface #108,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     599: checkcast     #137                // class java/util/Collection
     602: iload         8
     604: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     607: invokestatic  #141                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     610: invokeinterface #66,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     615: pop
     616: aload         5
     618: aload         5
     620: iload         6
     622: iconst_1
     623: isub
     624: invokeinterface #108,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     629: checkcast     #137                // class java/util/Collection
     632: aload         4
     634: iload         6
     636: invokeinterface #108,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     641: checkcast     #16                 // class java/lang/Iterable
     644: invokestatic  #144                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     647: checkcast     #16                 // class java/lang/Iterable
     650: invokestatic  #147                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     653: invokeinterface #66,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     658: pop
     659: iload         6
     661: iload         7
     663: if_icmpeq     672
     666: iinc          6, 1
     669: goto          498
     672: aload_1
     673: astore        8
     675: iconst_0
     676: istore        9
     678: aload         8
     680: astore        10
     682: new           #55                 // class java/util/ArrayList
     685: dup
     686: aload         8
     688: invokeinterface #69,  1           // InterfaceMethod java/util/Map.size:()I
     693: invokespecial #101                // Method java/util/ArrayList."<init>":(I)V
     696: checkcast     #137                // class java/util/Collection
     699: astore        11
     701: iconst_0
     702: istore        12
     704: aload         10
     706: invokeinterface #82,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     711: invokeinterface #150,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     716: astore        13
     718: aload         13
     720: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     725: ifeq          811
     728: aload         13
     730: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     735: checkcast     #84                 // class java/util/Map$Entry
     738: astore        14
     740: aload         11
     742: aload         14
     744: astore        15
     746: astore        35
     748: iconst_0
     749: istore        16
     751: aload         5
     753: aload         15
     755: invokeinterface #87,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     760: checkcast     #39                 // class java/lang/Number
     763: invokevirtual #43                 // Method java/lang/Number.intValue:()I
     766: invokeinterface #108,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     771: checkcast     #58                 // class java/util/List
     774: invokeinterface #91,  1           // InterfaceMethod java/util/List.size:()I
     779: i2l
     780: lconst_1
     781: lmul
     782: aload         15
     784: invokeinterface #90,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     789: checkcast     #39                 // class java/lang/Number
     792: invokevirtual #154                // Method java/lang/Number.longValue:()J
     795: lmul
     796: invokestatic  #159                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     799: aload         35
     801: swap
     802: invokeinterface #160,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     807: pop
     808: goto          718
     811: aload         11
     813: checkcast     #58                 // class java/util/List
     816: nop
     817: checkcast     #16                 // class java/lang/Iterable
     820: invokestatic  #164                // Method kotlin/collections/CollectionsKt.sumOfLong:(Ljava/lang/Iterable;)J
     823: lstore        6
     825: iconst_0
     826: istore        8
     828: aload         5
     830: invokestatic  #168                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     833: checkcast     #137                // class java/util/Collection
     836: invokeinterface #169,  1          // InterfaceMethod java/util/Collection.size:()I
     841: istore        9
     843: iload         8
     845: iload         9
     847: if_icmpge     1426
     850: aload_2
     851: checkcast     #16                 // class java/lang/Iterable
     854: astore        11
     856: iconst_0
     857: istore        12
     859: aload         11
     861: astore        13
     863: new           #18                 // class java/util/LinkedHashMap
     866: dup
     867: invokespecial #21                 // Method java/util/LinkedHashMap."<init>":()V
     870: checkcast     #23                 // class java/util/Map
     873: astore        14
     875: iconst_0
     876: istore        15
     878: aload         13
     880: invokeinterface #27,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     885: astore        16
     887: aload         16
     889: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     894: ifeq          1017
     897: aload         16
     899: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     904: astore        17
     906: aload         17
     908: checkcast     #39                 // class java/lang/Number
     911: invokevirtual #43                 // Method java/lang/Number.intValue:()I
     914: istore        18
     916: iconst_0
     917: istore        19
     919: aload         5
     921: iload         18
     923: invokeinterface #108,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     928: checkcast     #58                 // class java/util/List
     931: iload         8
     933: invokestatic  #173                // Method kotlin/collections/CollectionsKt.getOrNull:(Ljava/util/List;I)Ljava/lang/Object;
     936: checkcast     #45                 // class java/lang/Integer
     939: astore        20
     941: aload         14
     943: astore        21
     945: iconst_0
     946: istore        22
     948: aload         21
     950: aload         20
     952: invokeinterface #53,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     957: astore        23
     959: aload         23
     961: ifnonnull     996
     964: iconst_0
     965: istore        24
     967: new           #55                 // class java/util/ArrayList
     970: dup
     971: invokespecial #56                 // Method java/util/ArrayList."<init>":()V
     974: checkcast     #58                 // class java/util/List
     977: astore        24
     979: aload         21
     981: aload         20
     983: aload         24
     985: invokeinterface #62,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     990: pop
     991: aload         24
     993: goto          998
     996: aload         23
     998: nop
     999: checkcast     #58                 // class java/util/List
    1002: astore        25
    1004: aload         25
    1006: aload         17
    1008: invokeinterface #66,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
    1013: pop
    1014: goto          887
    1017: aload         14
    1019: nop
    1020: astore        10
    1022: aload         10
    1024: astore        12
    1026: iconst_0
    1027: istore        13
    1029: aload         12
    1031: astore        14
    1033: new           #18                 // class java/util/LinkedHashMap
    1036: dup
    1037: aload         12
    1039: invokeinterface #69,  1           // InterfaceMethod java/util/Map.size:()I
    1044: invokestatic  #75                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
    1047: invokespecial #78                 // Method java/util/LinkedHashMap."<init>":(I)V
    1050: checkcast     #23                 // class java/util/Map
    1053: astore        15
    1055: iconst_0
    1056: istore        16
    1058: aload         14
    1060: invokeinterface #82,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
    1065: checkcast     #16                 // class java/lang/Iterable
    1068: astore        17
    1070: iconst_0
    1071: istore        18
    1073: aload         17
    1075: invokeinterface #27,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
    1080: astore        19
    1082: aload         19
    1084: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
    1089: ifeq          1265
    1092: aload         19
    1094: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    1099: astore        20
    1101: aload         15
    1103: aload         20
    1105: checkcast     #84                 // class java/util/Map$Entry
    1108: astore        21
    1110: astore        22
    1112: iconst_0
    1113: istore        23
    1115: aload         21
    1117: invokeinterface #87,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
    1122: aload         22
    1124: swap
    1125: aload         20
    1127: checkcast     #84                 // class java/util/Map$Entry
    1130: astore        24
    1132: astore        36
    1134: astore        35
    1136: iconst_0
    1137: istore        25
    1139: iconst_2
    1140: aload         24
    1142: invokeinterface #90,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
    1147: checkcast     #16                 // class java/lang/Iterable
    1150: astore        26
    1152: istore        27
    1154: iconst_0
    1155: istore        28
    1157: aload         26
    1159: invokeinterface #27,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
    1164: astore        29
    1166: aload         29
    1168: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
    1173: ifeq          1229
    1176: aload         29
    1178: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    1183: astore        30
    1185: iload         28
    1187: aload         30
    1189: checkcast     #39                 // class java/lang/Number
    1192: invokevirtual #43                 // Method java/lang/Number.intValue:()I
    1195: istore        31
    1197: istore        32
    1199: iconst_0
    1200: istore        33
    1202: aload_1
    1203: iload         31
    1205: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
    1208: invokestatic  #176                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
    1211: checkcast     #39                 // class java/lang/Number
    1214: invokevirtual #43                 // Method java/lang/Number.intValue:()I
    1217: istore        34
    1219: iload         32
    1221: iload         34
    1223: iadd
    1224: istore        28
    1226: goto          1166
    1229: iload         28
    1231: istore        32
    1233: iload         27
    1235: iload         32
    1237: imul
    1238: aload_0
    1239: invokeinterface #91,  1           // InterfaceMethod java/util/List.size:()I
    1244: isub
    1245: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
    1248: astore        37
    1250: aload         35
    1252: aload         36
    1254: aload         37
    1256: invokeinterface #62,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    1261: pop
    1262: goto          1082
    1265: aload         15
    1267: nop
    1268: nop
    1269: astore        11
    1271: aload         11
    1273: invokeinterface #82,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
    1278: checkcast     #16                 // class java/lang/Iterable
    1281: astore        14
    1283: iconst_0
    1284: istore        15
    1286: aload         14
    1288: invokeinterface #27,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
    1293: astore        16
    1295: aload         16
    1297: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
    1302: ifeq          1353
    1305: aload         16
    1307: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    1312: astore        17
    1314: aload         17
    1316: checkcast     #84                 // class java/util/Map$Entry
    1319: astore        18
    1321: iconst_0
    1322: istore        19
    1324: aload         18
    1326: invokeinterface #90,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
    1331: checkcast     #39                 // class java/lang/Number
    1334: invokevirtual #43                 // Method java/lang/Number.intValue:()I
    1337: ifle          1344
    1340: iconst_1
    1341: goto          1345
    1344: iconst_0
    1345: ifeq          1295
    1348: aload         17
    1350: goto          1354
    1353: aconst_null
    1354: checkcast     #84                 // class java/util/Map$Entry
    1357: dup
    1358: ifnull        1379
    1361: invokeinterface #87,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
    1366: checkcast     #45                 // class java/lang/Integer
    1369: dup
    1370: ifnull        1379
    1373: invokevirtual #177                // Method java/lang/Integer.intValue:()I
    1376: goto          1383
    1379: pop
    1380: goto          1426
    1383: istore        12
    1385: lload         6
    1387: aload         11
    1389: iload         12
    1391: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
    1394: invokestatic  #176                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
    1397: checkcast     #39                 // class java/lang/Number
    1400: invokevirtual #154                // Method java/lang/Number.longValue:()J
    1403: lsub
    1404: lstore        6
    1406: aload         10
    1408: iload         12
    1410: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
    1413: invokestatic  #176                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
    1416: checkcast     #58                 // class java/util/List
    1419: astore_2
    1420: iinc          8, 1
    1423: goto          843
    1426: getstatic     #183                // Field java/lang/System.out:Ljava/io/PrintStream;
    1429: lload         6
    1431: invokevirtual #189                // Method java/io/PrintStream.println:(J)V
    1434: return

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #258                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #118                // 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     #262                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #264                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc_w         #266                // String
      16: aastore
      17: aload_0
      18: iconst_0
      19: iconst_0
      20: bipush        6
      22: aconst_null
      23: invokestatic  #272                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      26: areturn

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

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


package codeforces.educationalround95

fun main() {
	val M = 998244353
	val (n, m) = readInts()
	val d = readInts().sorted()
	val sum = d.sumOf { it.toLong() }
	val ab = List(m) { readInts() }.withIndex().sortedBy { -it.value[1] }
	var i = n - 1
	var large = 0
	var sumLarge = 0L
	val ans = IntArray(m)
	for (p in ab) {
		val (a, b) = p.value
		while (i >= 0 && d[i] >= b) {
			large++
			sumLarge += d[i]
			i--
		}
//		val large = d.count { it >= b }
//		val sumLarge = d.filter { it >= b }.sumOf { it.toLong() }
		val sumSmall = sum - sumLarge
		val pLarge = if (large == 0) 0 else (1 - minOf(a, large).toLong() * modInverse(large, M)) % M
		val pSmall = (1 - minOf(a, large + 1).toLong() * modInverse(large + 1, M)) % M
		ans[p.index] = (((sumLarge % M * pLarge + sumSmall % M * pSmall) % M + M) % M).toInt()
	}
	println(ans.joinToString("\n"))
}

fun gcdExtended(a: Int, b: Int, xy: IntArray): Int {
	if (a == 0) {
		xy[0] = 0
		xy[1] = 1
		return b
	}
	val d = gcdExtended(b % a, a, xy)
	val t = xy[0]
	xy[0] = xy[1] - b / a * xy[0]
	xy[1] = t
	return d
}

fun modInverse(x: Int, p: Int): Int {
	val xy = IntArray(2)
	val gcd = gcdExtended(x, p, xy)
	require(gcd == 1) { "$x, $p" }
	var result = xy[0] % p
	if (result < 0) {
		result += p
	}
	return result
}

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

Compiled from "Comparisons.kt"
public final class codeforces.educationalround95.EKt$main$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public codeforces.educationalround95.EKt$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 kotlin/collections/IndexedValue
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method kotlin/collections/IndexedValue.getValue:()Ljava/lang/Object;
      12: checkcast     #29                 // class java/util/List
      15: iconst_1
      16: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      21: checkcast     #35                 // class java/lang/Number
      24: invokevirtual #39                 // Method java/lang/Number.intValue:()I
      27: ineg
      28: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      31: checkcast     #47                 // class java/lang/Comparable
      34: aload_2
      35: checkcast     #23                 // class kotlin/collections/IndexedValue
      38: astore_3
      39: astore        5
      41: iconst_0
      42: istore        4
      44: aload_3
      45: invokevirtual #27                 // Method kotlin/collections/IndexedValue.getValue:()Ljava/lang/Object;
      48: checkcast     #29                 // class java/util/List
      51: iconst_1
      52: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      57: checkcast     #35                 // class java/lang/Number
      60: invokevirtual #39                 // Method java/lang/Number.intValue:()I
      63: ineg
      64: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      67: aload         5
      69: swap
      70: checkcast     #47                 // class java/lang/Comparable
      73: invokestatic  #53                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      76: ireturn
}

Compiled from "e.kt"
public final class codeforces.educationalround95.EKt {
  public static final void main();
    Code:
       0: ldc           #7                  // int 998244353
       2: istore_0
       3: invokestatic  #11                 // Method readInts:()Ljava/util/List;
       6: astore_1
       7: aload_1
       8: iconst_0
       9: invokeinterface #17,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      14: checkcast     #19                 // class java/lang/Number
      17: invokevirtual #23                 // Method java/lang/Number.intValue:()I
      20: istore_2
      21: aload_1
      22: iconst_1
      23: invokeinterface #17,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      28: checkcast     #19                 // class java/lang/Number
      31: invokevirtual #23                 // Method java/lang/Number.intValue:()I
      34: istore_3
      35: invokestatic  #11                 // Method readInts:()Ljava/util/List;
      38: checkcast     #25                 // class java/lang/Iterable
      41: invokestatic  #31                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
      44: astore        4
      46: aload         4
      48: checkcast     #25                 // class java/lang/Iterable
      51: astore        7
      53: lconst_0
      54: lstore        8
      56: aload         7
      58: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      63: astore        10
      65: aload         10
      67: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          116
      75: aload         10
      77: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      82: astore        11
      84: lload         8
      86: aload         11
      88: checkcast     #19                 // class java/lang/Number
      91: invokevirtual #23                 // Method java/lang/Number.intValue:()I
      94: istore        12
      96: lstore        24
      98: iconst_0
      99: istore        13
     101: iload         12
     103: i2l
     104: lstore        26
     106: lload         24
     108: lload         26
     110: ladd
     111: lstore        8
     113: goto          65
     116: lload         8
     118: lstore        5
     120: new           #47                 // class java/util/ArrayList
     123: dup
     124: iload_3
     125: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
     128: astore        8
     130: iconst_0
     131: istore        9
     133: iload         9
     135: iload_3
     136: if_icmpge     170
     139: iload         9
     141: istore        10
     143: aload         8
     145: iload         10
     147: istore        11
     149: astore        24
     151: iconst_0
     152: istore        12
     154: invokestatic  #11                 // Method readInts:()Ljava/util/List;
     157: aload         24
     159: swap
     160: invokevirtual #55                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     163: pop
     164: iinc          9, 1
     167: goto          133
     170: aload         8
     172: checkcast     #13                 // class java/util/List
     175: checkcast     #25                 // class java/lang/Iterable
     178: invokestatic  #59                 // Method kotlin/collections/CollectionsKt.withIndex:(Ljava/lang/Iterable;)Ljava/lang/Iterable;
     181: astore        8
     183: iconst_0
     184: istore        9
     186: aload         8
     188: new           #61                 // class codeforces/educationalround95/EKt$main$$inlined$sortedBy$1
     191: dup
     192: invokespecial #63                 // Method codeforces/educationalround95/EKt$main$$inlined$sortedBy$1."<init>":()V
     195: checkcast     #65                 // class java/util/Comparator
     198: invokestatic  #69                 // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     201: astore        7
     203: iload_2
     204: iconst_1
     205: isub
     206: istore        8
     208: iconst_0
     209: istore        9
     211: lconst_0
     212: lstore        10
     214: iload_3
     215: newarray       int
     217: astore        12
     219: aload         7
     221: invokeinterface #70,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     226: astore        13
     228: aload         13
     230: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     235: ifeq          450
     238: aload         13
     240: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     245: checkcast     #72                 // class kotlin/collections/IndexedValue
     248: astore        14
     250: aload         14
     252: invokevirtual #75                 // Method kotlin/collections/IndexedValue.getValue:()Ljava/lang/Object;
     255: checkcast     #13                 // class java/util/List
     258: astore        15
     260: aload         15
     262: iconst_0
     263: invokeinterface #17,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     268: checkcast     #19                 // class java/lang/Number
     271: invokevirtual #23                 // Method java/lang/Number.intValue:()I
     274: istore        16
     276: aload         15
     278: iconst_1
     279: invokeinterface #17,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     284: checkcast     #19                 // class java/lang/Number
     287: invokevirtual #23                 // Method java/lang/Number.intValue:()I
     290: istore        17
     292: iload         8
     294: iflt          346
     297: aload         4
     299: iload         8
     301: invokeinterface #17,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     306: checkcast     #19                 // class java/lang/Number
     309: invokevirtual #23                 // Method java/lang/Number.intValue:()I
     312: iload         17
     314: if_icmplt     346
     317: iinc          9, 1
     320: lload         10
     322: aload         4
     324: iload         8
     326: invokeinterface #17,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     331: checkcast     #19                 // class java/lang/Number
     334: invokevirtual #79                 // Method java/lang/Number.longValue:()J
     337: ladd
     338: lstore        10
     340: iinc          8, -1
     343: goto          292
     346: lload         5
     348: lload         10
     350: lsub
     351: lstore        18
     353: iload         9
     355: ifne          362
     358: lconst_0
     359: goto          383
     362: lconst_1
     363: iload         16
     365: iload         9
     367: invokestatic  #85                 // Method java/lang/Math.min:(II)I
     370: i2l
     371: iload         9
     373: iload_0
     374: invokestatic  #88                 // Method modInverse:(II)I
     377: i2l
     378: lmul
     379: lsub
     380: iload_0
     381: i2l
     382: lrem
     383: lstore        20
     385: lconst_1
     386: iload         16
     388: iload         9
     390: iconst_1
     391: iadd
     392: invokestatic  #85                 // Method java/lang/Math.min:(II)I
     395: i2l
     396: iload         9
     398: iconst_1
     399: iadd
     400: iload_0
     401: invokestatic  #88                 // Method modInverse:(II)I
     404: i2l
     405: lmul
     406: lsub
     407: iload_0
     408: i2l
     409: lrem
     410: lstore        22
     412: aload         12
     414: aload         14
     416: invokevirtual #91                 // Method kotlin/collections/IndexedValue.getIndex:()I
     419: lload         10
     421: iload_0
     422: i2l
     423: lrem
     424: lload         20
     426: lmul
     427: lload         18
     429: iload_0
     430: i2l
     431: lrem
     432: lload         22
     434: lmul
     435: ladd
     436: iload_0
     437: i2l
     438: lrem
     439: iload_0
     440: i2l
     441: ladd
     442: iload_0
     443: i2l
     444: lrem
     445: l2i
     446: iastore
     447: goto          228
     450: aload         12
     452: ldc           #93                 // String \n
     454: checkcast     #95                 // class java/lang/CharSequence
     457: aconst_null
     458: aconst_null
     459: iconst_0
     460: aconst_null
     461: aconst_null
     462: bipush        62
     464: aconst_null
     465: invokestatic  #101                // 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;
     468: getstatic     #107                // Field java/lang/System.out:Ljava/io/PrintStream;
     471: swap
     472: invokevirtual #113                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     475: return

  public static final int gcdExtended(int, int, int[]);
    Code:
       0: aload_2
       1: ldc           #146                // String xy
       3: invokestatic  #152                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_0
       7: ifne          20
      10: aload_2
      11: iconst_0
      12: iconst_0
      13: iastore
      14: aload_2
      15: iconst_1
      16: iconst_1
      17: iastore
      18: iload_1
      19: ireturn
      20: iload_1
      21: iload_0
      22: irem
      23: iload_0
      24: aload_2
      25: invokestatic  #154                // Method gcdExtended:(II[I)I
      28: istore_3
      29: aload_2
      30: iconst_0
      31: iaload
      32: istore        4
      34: aload_2
      35: iconst_0
      36: aload_2
      37: iconst_1
      38: iaload
      39: iload_1
      40: iload_0
      41: idiv
      42: aload_2
      43: iconst_0
      44: iaload
      45: imul
      46: isub
      47: iastore
      48: aload_2
      49: iconst_1
      50: iload         4
      52: iastore
      53: iload_3
      54: ireturn

  public static final int modInverse(int, int);
    Code:
       0: iconst_2
       1: newarray       int
       3: astore_2
       4: iload_0
       5: iload_1
       6: aload_2
       7: invokestatic  #154                // Method gcdExtended:(II[I)I
      10: istore_3
      11: iload_3
      12: iconst_1
      13: if_icmpne     20
      16: iconst_1
      17: goto          21
      20: iconst_0
      21: ifne          65
      24: iconst_0
      25: istore        5
      27: new           #157                // class java/lang/StringBuilder
      30: dup
      31: invokespecial #158                // Method java/lang/StringBuilder."<init>":()V
      34: iload_0
      35: invokevirtual #162                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      38: ldc           #164                // String ,
      40: invokevirtual #167                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      43: iload_1
      44: invokevirtual #162                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      47: invokevirtual #171                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      50: astore        5
      52: new           #173                // class java/lang/IllegalArgumentException
      55: dup
      56: aload         5
      58: invokevirtual #174                // Method java/lang/Object.toString:()Ljava/lang/String;
      61: invokespecial #177                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      64: athrow
      65: aload_2
      66: iconst_0
      67: iaload
      68: iload_1
      69: irem
      70: istore        4
      72: iload         4
      74: ifge          83
      77: iload         4
      79: iload_1
      80: iadd
      81: istore        4
      83: iload         4
      85: ireturn

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

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

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #193                // Method readLn:()Ljava/lang/String;
       3: checkcast     #95                 // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #203                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #205                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #211                // 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  #214                // Method readStrings:()Ljava/util/List;
       3: checkcast     #25                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #47                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #218                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #220                // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #35,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #203                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #199                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #224                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #225,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #13                 // class java/util/List
      96: nop
      97: areturn

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


package codeforces.polynomial2022

fun main() {
	val (n, d) = readInts()
	val nei = List(n) { mutableListOf<Int>() }
	repeat(n - 1) {
		val (u, v) = readInts().map { it - 1 }
		nei[u].add(v)
		nei[v].add(u)
	}
	val arrays = List(2) { readInts().drop(1).map { it - 1 } }
	val needed = List(2) { BooleanArray(n).also { it[0] = true } }
	for (t in 0..1) {
		for (x in arrays[t]) needed[t][x] = true
		val stack = IntArray(n)
		var stackSize = 0
		fun dfs(v: Int, p: Int) {
			stack[stackSize++] = v
			if (needed[t][v] && stackSize > d) {
				needed[t xor 1][stack[stackSize - 1 - d]] = true
			}
			for (u in nei[v]) if (u != p) {
				dfs(u, v)
			}
			stackSize--
		}
		dfs(0, -1)
	}
	var ans = 0
	for (t in 0..1) {
		var travel = 0
		fun dfs(v: Int, p: Int): Boolean {
			var result = needed[t][v]
			for (u in nei[v]) if (u != p) {
				if (dfs(u, v)) result = true
			}
			if (result) travel++
			return result
		}
		dfs(0, -1)
		ans += (travel - 1) * 2
	}
	println(ans)
}

private fun readStrings() = readln().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

Compiled from "e_slow.kt"
public final class codeforces.polynomial2022.E_slowKt {
  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 java/util/ArrayList
      35: dup
      36: iload_1
      37: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      40: astore        4
      42: iconst_0
      43: istore        5
      45: iload         5
      47: iload_1
      48: if_icmpge     90
      51: iload         5
      53: istore        6
      55: aload         4
      57: iload         6
      59: istore        7
      61: astore        21
      63: iconst_0
      64: istore        8
      66: new           #24                 // class java/util/ArrayList
      69: dup
      70: invokespecial #30                 // Method java/util/ArrayList."<init>":()V
      73: checkcast     #12                 // class java/util/List
      76: nop
      77: aload         21
      79: swap
      80: invokevirtual #34                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      83: pop
      84: iinc          5, 1
      87: goto          45
      90: aload         4
      92: checkcast     #12                 // class java/util/List
      95: astore_3
      96: iload_1
      97: iconst_1
      98: isub
      99: istore        4
     101: iconst_0
     102: istore        5
     104: iload         5
     106: iload         4
     108: if_icmpge     310
     111: iload         5
     113: istore        6
     115: iconst_0
     116: istore        7
     118: invokestatic  #10                 // Method readInts:()Ljava/util/List;
     121: checkcast     #36                 // class java/lang/Iterable
     124: astore        8
     126: iconst_0
     127: istore        9
     129: aload         8
     131: astore        10
     133: new           #24                 // class java/util/ArrayList
     136: dup
     137: aload         8
     139: bipush        10
     141: invokestatic  #42                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     144: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
     147: checkcast     #44                 // class java/util/Collection
     150: astore        11
     152: iconst_0
     153: istore        12
     155: aload         10
     157: invokeinterface #48,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     162: astore        13
     164: aload         13
     166: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     171: ifeq          219
     174: aload         13
     176: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     181: astore        14
     183: aload         11
     185: aload         14
     187: checkcast     #18                 // class java/lang/Number
     190: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     193: istore        15
     195: astore        16
     197: iconst_0
     198: istore        17
     200: iload         15
     202: iconst_1
     203: isub
     204: invokestatic  #64                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     207: aload         16
     209: swap
     210: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     215: pop
     216: goto          164
     219: aload         11
     221: checkcast     #12                 // class java/util/List
     224: nop
     225: astore        18
     227: aload         18
     229: iconst_0
     230: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     235: checkcast     #18                 // class java/lang/Number
     238: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     241: istore        8
     243: aload         18
     245: iconst_1
     246: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     251: checkcast     #18                 // class java/lang/Number
     254: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     257: istore        9
     259: aload_3
     260: iload         8
     262: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     267: checkcast     #12                 // class java/util/List
     270: iload         9
     272: invokestatic  #64                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     275: invokeinterface #66,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     280: pop
     281: aload_3
     282: iload         9
     284: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     289: checkcast     #12                 // class java/util/List
     292: iload         8
     294: invokestatic  #64                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     297: invokeinterface #66,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     302: pop
     303: nop
     304: iinc          5, 1
     307: goto          104
     310: iconst_2
     311: istore        5
     313: new           #24                 // class java/util/ArrayList
     316: dup
     317: iload         5
     319: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
     322: astore        6
     324: iconst_0
     325: istore        7
     327: iload         7
     329: iload         5
     331: if_icmpge     477
     334: iload         7
     336: istore        8
     338: aload         6
     340: iload         8
     342: istore        9
     344: astore        21
     346: iconst_0
     347: istore        10
     349: invokestatic  #10                 // Method readInts:()Ljava/util/List;
     352: checkcast     #36                 // class java/lang/Iterable
     355: iconst_1
     356: invokestatic  #70                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     359: checkcast     #36                 // class java/lang/Iterable
     362: astore        11
     364: iconst_0
     365: istore        12
     367: aload         11
     369: astore        13
     371: new           #24                 // class java/util/ArrayList
     374: dup
     375: aload         11
     377: bipush        10
     379: invokestatic  #42                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     382: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
     385: checkcast     #44                 // class java/util/Collection
     388: astore        14
     390: iconst_0
     391: istore        15
     393: aload         13
     395: invokeinterface #48,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     400: astore        16
     402: aload         16
     404: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     409: ifeq          457
     412: aload         16
     414: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     419: astore        17
     421: aload         14
     423: aload         17
     425: checkcast     #18                 // class java/lang/Number
     428: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     431: istore        18
     433: astore        19
     435: iconst_0
     436: istore        20
     438: iload         18
     440: iconst_1
     441: isub
     442: invokestatic  #64                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     445: aload         19
     447: swap
     448: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     453: pop
     454: goto          402
     457: aload         14
     459: checkcast     #12                 // class java/util/List
     462: nop
     463: nop
     464: aload         21
     466: swap
     467: invokevirtual #34                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     470: pop
     471: iinc          7, 1
     474: goto          327
     477: aload         6
     479: checkcast     #12                 // class java/util/List
     482: astore        4
     484: iconst_2
     485: istore        6
     487: new           #24                 // class java/util/ArrayList
     490: dup
     491: iload         6
     493: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
     496: astore        7
     498: iconst_0
     499: istore        8
     501: iload         8
     503: iload         6
     505: if_icmpge     556
     508: iload         8
     510: istore        9
     512: aload         7
     514: iload         9
     516: istore        10
     518: astore        21
     520: iconst_0
     521: istore        11
     523: iload_1
     524: newarray       boolean
     526: astore        12
     528: aload         12
     530: astore        13
     532: iconst_0
     533: istore        14
     535: aload         13
     537: iconst_0
     538: iconst_1
     539: bastore
     540: aload         12
     542: nop
     543: aload         21
     545: swap
     546: invokevirtual #34                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     549: pop
     550: iinc          8, 1
     553: goto          501
     556: aload         7
     558: checkcast     #12                 // class java/util/List
     561: astore        5
     563: iconst_0
     564: istore        6
     566: iload         6
     568: iconst_2
     569: if_icmpge     670
     572: aload         4
     574: iload         6
     576: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     581: checkcast     #12                 // class java/util/List
     584: invokeinterface #71,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     589: astore        7
     591: aload         7
     593: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     598: ifeq          635
     601: aload         7
     603: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     608: checkcast     #18                 // class java/lang/Number
     611: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     614: istore        8
     616: aload         5
     618: iload         6
     620: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     625: checkcast     #73                 // class "[Z"
     628: iload         8
     630: iconst_1
     631: bastore
     632: goto          591
     635: iload_1
     636: newarray       int
     638: astore        7
     640: new           #75                 // class kotlin/jvm/internal/Ref$IntRef
     643: dup
     644: invokespecial #76                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
     647: astore        8
     649: aload         7
     651: aload         8
     653: aload         5
     655: iload         6
     657: iload_2
     658: aload_3
     659: iconst_0
     660: iconst_m1
     661: invokestatic  #80                 // Method main$dfs:([ILkotlin/jvm/internal/Ref$IntRef;Ljava/util/List;IILjava/util/List;II)V
     664: iinc          6, 1
     667: goto          566
     670: iconst_0
     671: istore        6
     673: iconst_0
     674: istore        7
     676: iload         7
     678: iconst_2
     679: if_icmpge     724
     682: new           #75                 // class kotlin/jvm/internal/Ref$IntRef
     685: dup
     686: invokespecial #76                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
     689: astore        8
     691: aload         5
     693: iload         7
     695: aload_3
     696: aload         8
     698: iconst_0
     699: iconst_m1
     700: invokestatic  #84                 // Method main$dfs$7:(Ljava/util/List;ILjava/util/List;Lkotlin/jvm/internal/Ref$IntRef;II)Z
     703: pop
     704: iload         6
     706: aload         8
     708: getfield      #88                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     711: iconst_1
     712: isub
     713: iconst_2
     714: imul
     715: iadd
     716: istore        6
     718: iinc          7, 1
     721: goto          676
     724: getstatic     #94                 // Field java/lang/System.out:Ljava/io/PrintStream;
     727: iload         6
     729: invokevirtual #99                 // Method java/io/PrintStream.println:(I)V
     732: return

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #140                // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: checkcast     #142                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #144                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #146                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #152                // 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  #155                // Method readStrings:()Ljava/util/List;
       3: checkcast     #36                 // 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  #42                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #44                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #48,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #144                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #159                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #64                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #65,  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  #164                // Method main:()V
       3: return

  private static final void main$dfs(int[], kotlin.jvm.internal.Ref$IntRef, java.util.List<boolean[]>, int, int, java.util.List<? extends java.util.List<java.lang.Integer>>, int, int);
    Code:
       0: aload_0
       1: aload_1
       2: getfield      #88                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
       5: istore        8
       7: aload_1
       8: iload         8
      10: iconst_1
      11: iadd
      12: putfield      #88                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      15: iload         8
      17: iload         6
      19: iastore
      20: aload_2
      21: iload_3
      22: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      27: checkcast     #73                 // class "[Z"
      30: iload         6
      32: baload
      33: ifeq          70
      36: aload_1
      37: getfield      #88                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      40: iload         4
      42: if_icmple     70
      45: aload_2
      46: iload_3
      47: iconst_1
      48: ixor
      49: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      54: checkcast     #73                 // class "[Z"
      57: aload_0
      58: aload_1
      59: getfield      #88                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      62: iconst_1
      63: isub
      64: iload         4
      66: isub
      67: iaload
      68: iconst_1
      69: bastore
      70: aload         5
      72: iload         6
      74: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      79: checkcast     #12                 // class java/util/List
      82: invokeinterface #71,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      87: astore        8
      89: aload         8
      91: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      96: ifeq          139
      99: aload         8
     101: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     106: checkcast     #18                 // class java/lang/Number
     109: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     112: istore        9
     114: iload         9
     116: iload         7
     118: if_icmpeq     89
     121: aload_0
     122: aload_1
     123: aload_2
     124: iload_3
     125: iload         4
     127: aload         5
     129: iload         9
     131: iload         6
     133: invokestatic  #80                 // Method main$dfs:([ILkotlin/jvm/internal/Ref$IntRef;Ljava/util/List;IILjava/util/List;II)V
     136: goto          89
     139: aload_1
     140: getfield      #88                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     143: istore        8
     145: aload_1
     146: iload         8
     148: iconst_m1
     149: iadd
     150: putfield      #88                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     153: return

  private static final boolean main$dfs$7(java.util.List<boolean[]>, int, java.util.List<? extends java.util.List<java.lang.Integer>>, kotlin.jvm.internal.Ref$IntRef, int, int);
    Code:
       0: aload_0
       1: iload_1
       2: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       7: checkcast     #73                 // class "[Z"
      10: iload         4
      12: baload
      13: istore        6
      15: aload_2
      16: iload         4
      18: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      23: checkcast     #12                 // class java/util/List
      26: invokeinterface #71,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      31: astore        7
      33: aload         7
      35: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      40: ifeq          85
      43: aload         7
      45: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      50: checkcast     #18                 // class java/lang/Number
      53: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      56: istore        8
      58: iload         8
      60: iload         5
      62: if_icmpeq     33
      65: aload_0
      66: iload_1
      67: aload_2
      68: aload_3
      69: iload         8
      71: iload         4
      73: invokestatic  #84                 // Method main$dfs$7:(Ljava/util/List;ILjava/util/List;Lkotlin/jvm/internal/Ref$IntRef;II)Z
      76: ifeq          33
      79: iconst_1
      80: istore        6
      82: goto          33
      85: iload         6
      87: ifeq          104
      90: aload_3
      91: getfield      #88                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      94: istore        7
      96: aload_3
      97: iload         7
      99: iconst_1
     100: iadd
     101: putfield      #88                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     104: iload         6
     106: ireturn
}


package codeforces.polynomial2022

import java.util.TreeSet

private fun solve(): String {
	val (n, _, k) = readInts()
	val a = readInts()
	val allow = LongArray(n) { -1 }
	val allowed = TreeSet<Long>()
	fun encode(count: Int, index: Int) = (count.toLong() shl 32) + index.toLong()
	for (i in a.indices) {
		allowed.add(encode(a[i], i))
	}
	for (i in 0 until n) {
		if (allow[i] >= 0) allowed.add(allow[i])
		val use = allowed.pollLast() ?: return "NO"
		val count = (use shr 32).toInt()
		val index = use.toInt()
		if (count > 1 && i + k < n) allow[i + k] = encode(count - 1, index)
	}
	return "YES"
}

fun main() = repeat(readInt()) { println(solve()) }

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

Compiled from "b_slow.kt"
public final class codeforces.polynomial2022.B_slowKt {
  private static final java.lang.String solve();
    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_2
      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: invokestatic  #10                 // Method readInts:()Ljava/util/List;
      35: astore_3
      36: iconst_0
      37: istore        5
      39: iload_1
      40: newarray       long
      42: astore        6
      44: iload         5
      46: iload_1
      47: if_icmpge     68
      50: iload         5
      52: istore        7
      54: aload         6
      56: iload         7
      58: ldc2_w        #23                 // long -1l
      61: lastore
      62: iinc          5, 1
      65: goto          44
      68: aload         6
      70: astore        4
      72: new           #26                 // class java/util/TreeSet
      75: dup
      76: invokespecial #30                 // Method java/util/TreeSet."<init>":()V
      79: astore        5
      81: iconst_0
      82: istore        6
      84: aload_3
      85: checkcast     #32                 // class java/util/Collection
      88: invokeinterface #35,  1           // InterfaceMethod java/util/Collection.size:()I
      93: istore        7
      95: iload         6
      97: iload         7
      99: if_icmpge     136
     102: aload         5
     104: aload_3
     105: iload         6
     107: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     112: checkcast     #18                 // class java/lang/Number
     115: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     118: iload         6
     120: invokestatic  #39                 // Method solve$encode:(II)J
     123: invokestatic  #45                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     126: invokevirtual #49                 // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
     129: pop
     130: iinc          6, 1
     133: goto          95
     136: iconst_0
     137: istore        6
     139: iload         6
     141: iload_1
     142: if_icmpge     242
     145: aload         4
     147: iload         6
     149: laload
     150: lconst_0
     151: lcmp
     152: iflt          169
     155: aload         5
     157: aload         4
     159: iload         6
     161: laload
     162: invokestatic  #45                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     165: invokevirtual #49                 // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
     168: pop
     169: aload         5
     171: invokevirtual #53                 // Method java/util/TreeSet.pollLast:()Ljava/lang/Object;
     174: checkcast     #41                 // class java/lang/Long
     177: dup
     178: ifnull        187
     181: invokevirtual #57                 // Method java/lang/Long.longValue:()J
     184: goto          191
     187: pop
     188: ldc           #59                 // String NO
     190: areturn
     191: lstore        7
     193: lload         7
     195: bipush        32
     197: lshr
     198: l2i
     199: istore        9
     201: lload         7
     203: l2i
     204: istore        10
     206: iload         9
     208: iconst_1
     209: if_icmple     236
     212: iload         6
     214: iload_2
     215: iadd
     216: iload_1
     217: if_icmpge     236
     220: aload         4
     222: iload         6
     224: iload_2
     225: iadd
     226: iload         9
     228: iconst_1
     229: isub
     230: iload         10
     232: invokestatic  #39                 // Method solve$encode:(II)J
     235: lastore
     236: iinc          6, 1
     239: goto          139
     242: ldc           #61                 // String YES
     244: areturn

  public static final void main();
    Code:
       0: invokestatic  #80                 // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: istore_1
       6: iload_1
       7: iload_0
       8: if_icmpge     32
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: invokestatic  #82                 // Method solve:()Ljava/lang/String;
      18: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
      21: swap
      22: invokevirtual #94                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      25: nop
      26: iinc          1, 1
      29: goto          6
      32: return

  private static final int readInt();
    Code:
       0: invokestatic  #101                // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: invokestatic  #107                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #101                // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: checkcast     #111                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #113                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #115                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #121                // 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  #124                // Method readStrings:()Ljava/util/List;
       3: checkcast     #126                // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #128                // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #134                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #137                // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #32                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #141,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #147,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #113                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #107                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #153                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #154,  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  #168                // Method main:()V
       3: return

  private static final long solve$encode(int, int);
    Code:
       0: iload_0
       1: i2l
       2: bipush        32
       4: lshl
       5: iload_1
       6: i2l
       7: ladd
       8: lreturn
}


package codeforces.polynomial2022

import java.lang.StringBuilder

private fun solve() {
	val (hei, wid) = readInts()
	val a = List(hei) { readInts() }
	val aSum = a.map { it.sum() }.toIntArray()
	val totalOnes = aSum.sum()
	if (totalOnes % hei != 0) return println(-1)
	val needOnes = totalOnes / hei
	val ans = StringBuilder()
	val donors = IntArray(hei)
	val acceptors = IntArray(hei)
	var ops = 0
	for (x in 0 until wid) {
		var donorsCount = 0
		var acceptorsCount = 0
		for (y in 0 until hei) {
			if (aSum[y] == needOnes) continue
			if (aSum[y] > needOnes && a[y][x] == 1) {
				donors[donorsCount++] = y
			}
			if (aSum[y] < needOnes && a[y][x] == 0) {
				acceptors[acceptorsCount++] = y
			}
		}
		for (i in 0 until minOf(donorsCount, acceptorsCount)) {
			aSum[donors[i]]--
			aSum[acceptors[i]]++
			ans.append("${donors[i] + 1} ${acceptors[i] + 1} ${x + 1}\n")
			ops++
		}
	}
	println(ops)
	print(ans)
}

fun main() = repeat(readInt()) { solve() }

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

Compiled from "d.kt"
public final class codeforces.polynomial2022.DKt {
  private static final void solve();
    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 java/util/ArrayList
      35: dup
      36: iload_1
      37: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      40: astore        4
      42: iconst_0
      43: istore        5
      45: iload         5
      47: iload_1
      48: if_icmpge     82
      51: iload         5
      53: istore        6
      55: aload         4
      57: iload         6
      59: istore        7
      61: astore        20
      63: iconst_0
      64: istore        8
      66: invokestatic  #10                 // Method readInts:()Ljava/util/List;
      69: aload         20
      71: swap
      72: invokevirtual #32                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      75: pop
      76: iinc          5, 1
      79: goto          45
      82: aload         4
      84: checkcast     #12                 // class java/util/List
      87: astore_3
      88: aload_3
      89: checkcast     #34                 // class java/lang/Iterable
      92: astore        5
      94: iconst_0
      95: istore        6
      97: aload         5
      99: astore        7
     101: new           #24                 // class java/util/ArrayList
     104: dup
     105: aload         5
     107: bipush        10
     109: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     112: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
     115: checkcast     #42                 // class java/util/Collection
     118: astore        8
     120: iconst_0
     121: istore        9
     123: aload         7
     125: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     130: astore        10
     132: aload         10
     134: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     139: ifeq          188
     142: aload         10
     144: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     149: astore        11
     151: aload         8
     153: aload         11
     155: checkcast     #12                 // class java/util/List
     158: astore        12
     160: astore        20
     162: iconst_0
     163: istore        13
     165: aload         12
     167: checkcast     #34                 // class java/lang/Iterable
     170: invokestatic  #60                 // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     173: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     176: aload         20
     178: swap
     179: invokeinterface #67,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     184: pop
     185: goto          132
     188: aload         8
     190: checkcast     #12                 // class java/util/List
     193: nop
     194: checkcast     #42                 // class java/util/Collection
     197: invokestatic  #71                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     200: astore        4
     202: aload         4
     204: invokestatic  #77                 // Method kotlin/collections/ArraysKt.sum:([I)I
     207: istore        5
     209: iload         5
     211: iload_1
     212: irem
     213: ifeq          228
     216: iconst_m1
     217: istore        6
     219: getstatic     #83                 // Field java/lang/System.out:Ljava/io/PrintStream;
     222: iload         6
     224: invokevirtual #88                 // Method java/io/PrintStream.println:(I)V
     227: return
     228: iload         5
     230: iload_1
     231: idiv
     232: istore        6
     234: new           #90                 // class java/lang/StringBuilder
     237: dup
     238: invokespecial #92                 // Method java/lang/StringBuilder."<init>":()V
     241: astore        7
     243: iload_1
     244: newarray       int
     246: astore        8
     248: iload_1
     249: newarray       int
     251: astore        9
     253: iconst_0
     254: istore        10
     256: iconst_0
     257: istore        11
     259: iload         11
     261: iload_2
     262: if_icmpge     529
     265: iconst_0
     266: istore        12
     268: iconst_0
     269: istore        13
     271: iconst_0
     272: istore        14
     274: iload         14
     276: iload_1
     277: if_icmpge     391
     280: aload         4
     282: iload         14
     284: iaload
     285: iload         6
     287: if_icmpeq     385
     290: aload         4
     292: iload         14
     294: iaload
     295: iload         6
     297: if_icmple     338
     300: aload_3
     301: iload         14
     303: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     308: checkcast     #12                 // class java/util/List
     311: iload         11
     313: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     318: checkcast     #18                 // class java/lang/Number
     321: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     324: iconst_1
     325: if_icmpne     338
     328: aload         8
     330: iload         12
     332: iinc          12, 1
     335: iload         14
     337: iastore
     338: aload         4
     340: iload         14
     342: iaload
     343: iload         6
     345: if_icmpge     385
     348: aload_3
     349: iload         14
     351: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     356: checkcast     #12                 // class java/util/List
     359: iload         11
     361: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     366: checkcast     #18                 // class java/lang/Number
     369: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     372: ifne          385
     375: aload         9
     377: iload         13
     379: iinc          13, 1
     382: iload         14
     384: iastore
     385: iinc          14, 1
     388: goto          274
     391: iconst_0
     392: istore        14
     394: iload         12
     396: iload         13
     398: invokestatic  #98                 // Method java/lang/Math.min:(II)I
     401: istore        15
     403: iload         14
     405: iload         15
     407: if_icmpge     523
     410: aload         8
     412: iload         14
     414: iaload
     415: istore        16
     417: aload         4
     419: iload         16
     421: iaload
     422: istore        17
     424: aload         4
     426: iload         16
     428: iload         17
     430: iconst_m1
     431: iadd
     432: iastore
     433: aload         9
     435: iload         14
     437: iaload
     438: istore        18
     440: aload         4
     442: iload         18
     444: iaload
     445: istore        19
     447: aload         4
     449: iload         18
     451: iload         19
     453: iconst_1
     454: iadd
     455: iastore
     456: aload         7
     458: new           #90                 // class java/lang/StringBuilder
     461: dup
     462: invokespecial #92                 // Method java/lang/StringBuilder."<init>":()V
     465: aload         8
     467: iload         14
     469: iaload
     470: iconst_1
     471: iadd
     472: invokevirtual #102                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     475: bipush        32
     477: invokevirtual #105                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     480: aload         9
     482: iload         14
     484: iaload
     485: iconst_1
     486: iadd
     487: invokevirtual #102                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     490: bipush        32
     492: invokevirtual #105                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     495: iload         11
     497: iconst_1
     498: iadd
     499: invokevirtual #102                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     502: bipush        10
     504: invokevirtual #105                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     507: invokevirtual #109                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     510: invokevirtual #112                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     513: pop
     514: iinc          10, 1
     517: iinc          14, 1
     520: goto          403
     523: iinc          11, 1
     526: goto          259
     529: getstatic     #83                 // Field java/lang/System.out:Ljava/io/PrintStream;
     532: iload         10
     534: invokevirtual #88                 // Method java/io/PrintStream.println:(I)V
     537: getstatic     #83                 // Field java/lang/System.out:Ljava/io/PrintStream;
     540: aload         7
     542: invokevirtual #116                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     545: return

  public static final void main();
    Code:
       0: invokestatic  #152                // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: istore_1
       6: iload_1
       7: iload_0
       8: if_icmpge     24
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: invokestatic  #154                // Method solve:()V
      18: iinc          1, 1
      21: goto          6
      24: return

  private static final int readInt();
    Code:
       0: invokestatic  #160                // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: invokestatic  #164                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #160                // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: checkcast     #168                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #170                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #172                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #178                // 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  #181                // Method readStrings:()Ljava/util/List;
       3: checkcast     #34                 // 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  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #42                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #170                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #164                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #67,  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  #186                // Method main:()V
       3: return
}