akhauriyash/Code-Regression huggingface dataset:
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = myconv(next(),4);
  var N = one[0];
  var R = one[1];
  myout(N.toString(R).length);
}

Measured memory_bytes: 21064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int MAXN=20000,base=20009;
int a[MAXN+5],b[MAXN+5];
int n,x;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		a[i]=base*i;
	for(int i=1;i<=n;i++)
		b[i]=base*(n-i+1);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		a[x]-=(n-i+1);
	}
	for(int i=1;i<=n;i++)
		printf("%d ",a[i]);
	printf("\n");
	for(int i=1;i<=n;i++)
		printf("%d ",b[i]);
	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
int main(void){
    int dice[7],side[5]={2,3,5,4,2};
    int a,b,i,j,k,l,n;
    char move[8]={"00NWESn"};
     
    for(i=1;i<=6;i++) scanf("%d",&dice[i]);
    scanf("%d",&n);
     
    for(i=0;i<n;i++){
        scanf("%d %d",&a,&b);
        for(j=1;dice[j]!=a;j++);
         
        dice[0]=dice[1];
         
        switch(move[j]){
            case 'E':
            dice[1]=dice[4];
            dice[4]=dice[6];
            dice[6]=dice[3];
            dice[3]=dice[0];
            break;
             
            case 'N':
            dice[1]=dice[2];
            dice[2]=dice[6];
            dice[6]=dice[5];
            dice[5]=dice[0];
            break;
             
            case 'S':
            dice[1]=dice[5];
            dice[5]=dice[6];
            dice[6]=dice[2];
            dice[2]=dice[0];
            break;
             
            case 'W':
            dice[1]=dice[3];
            dice[3]=dice[6];
            dice[6]=dice[4];
            dice[4]=dice[0];
            break;
             
            case 'n':
            dice[1]=dice[6];
            dice[6]=dice[0];
            dice[0]=dice[2];
            dice[2]=dice[5];
            dice[5]=dice[0];
            break;
        }
         
        for(l=0;dice[side[l]]!=b;l++);
        printf("%d\n",dice[side[l+1]]);
    }
    
    return 0;
}


Measured memory_bytes: 2076
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var a = ReadSplitInt();
            Println(a[0] % a[1]);
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>

using namespace std;

int main() {

	string s;
	cin >> s;
	for (long i = 0; i < s.size() - 1; i++) {
		for (long j = i+1; j < s.size(); j++) {
			if (s[i] == s[j]) {
				cout << "no" << endl;
				return 0;
			}
		}
	}
	cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d.at(i);
    int m;
    cin >> m;
    vector<int> t(m);
    rep(i, m) cin >> t.at(i);

    map<int, int> problems;
    rep(i, n) problems[d.at(i)]++;

    string answer = "YES";
    rep(i, m)
    {
        if (problems[t.at(i)] <= 0)
        {
            answer = "NO";
            break;
        }
        else
        {
            problems[t.at(i)]--;
        }
    }

    cout << answer << endl;
}

Measured memory_bytes: 13184
N=int(input())
A=[int(i) for i in input().split()]
I,J,K=0,0,0
for a in A:
    if a==1:
        I+=1
    if a==2:
        J+=1
    if a==3:
        K+=1
L=I+J+K
M=J+K



dp=[[[0.0]*(K+1) for i in range(M+1)] for i in range(L+1)]
for n in range(1,L+1):
    for m in range(min(n,M)+1):#m=j+k
        for k in range(min(m,K)+1):
            j=m-k
            i=n-m
            #print(i,j,k)
            ret=N/(i+j+k)
            if i>0:
                ret+=dp[i-1][j][k]*(i/(i+j+k))
            if j>0:
                ret+=dp[i+1][j-1][k]*(j/(i+j+k))
            if k>0:
                ret+=dp[i][j+1][k-1]*(k/(i+j+k))
            dp[i][j][k]=ret
print(dp[I][J][K])


Measured memory_bytes: 254344
unittest
{
	assert( [ "4 3", "1 2", "2 3", "3 4" ].solve == 6 );
	assert( [ "5 4", "1 2", "1 3", "1 4", "4 5" ].solve == 48 );
	assert( [ "16 22", "12 1", "3 1", "4 16", "7 12", "6 2", "2 15", "5 16", "14 16", "10 11", "3 10", "3 13", "8 6", "16 8", "9 12", "4 3" ].solve == 271414432 );
	
	assert( [ "4 3", "1 2", "1 3", "1 4" ].solve == 0 );		// 追加ケース
}



import std.container;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	auto abs = new long[ 2 ][ n - 1 ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
		ab[] -= 1;
	}
	
	// dfsで塗り方を探索（行きがけに塗り方パターン数を計算、帰りがけに塗り済隣接頂点を+1する）
	const M = 10L ^^ 9 + 7;
	auto ans = ModWorld!M( k );
	auto nss = toAdjacencyList!true( n, abs );
	auto cs = new long[ n ];
	auto stack = make!SList( 0L );
	while( !stack.empty )
	{
		auto f = stack.front;
		stack.removeFront;
		
		foreach( t; nss[ f ] )
		{
			if( 0 < cs[ t ] ) continue;
			
			auto p = k - cs[ f ] - 1;
			if( p <= 0 ) return ModWorld!M( 0 );
			
			ans *= p;
			cs[ t ] = 1;
			cs[ f ]++;
			stack.insertFront( t );
		}
	}
	return ans;
}

// 辺配列から隣接リストを作成
auto toAdjacencyList( bool undirected = false )( long n, long[ 2 ][] es )
{
	auto nss = new long[][ n ];
	foreach( e; es )
	{
		nss[ e[ 0 ] ] ~= e[ 1 ];
		static if( undirected ) nss[ e[ 1 ] ] ~= e[ 0 ];
	}
	return nss;
}

// モジュラ整数型（n mod M）
struct ModWorld( long M )
{
	long n;
	
	void opUnary( string OP )() if( OP == "++" ){ this.n = ( this.n + 1 ) % M; }
	void opUnary( string OP )() if( OP == "--" ){ this.n = ( this.n + M - 1 ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "+"  ){ this.n = ( this.n + r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "-"  ){ this.n = ( this.n + M - r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "*"  ){ this.n = ( this.n * r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "/"  ){ this *= r ^^ ModWorld( M - 2 ); }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "^^" )
	{
		auto a = this.n;
		this.n = 1L;
		for( auto i = r.n; 0 < i; i >>= 1 )
		{
			if( i & 1 ) this.n = ( this.n * a ) % M;
			a = ( a * a ) % M;
		}
	}
	auto opBinary( string OP )( ModWorld r ){ auto l = this; l.opOpAssign!OP( r ); return l; }
	
	void opAssign( long r ){ this.n = r; }
	void opOpAssign( string OP )( long r ){ this.opOpAssign!OP( ModWorld( r ) ); }
	auto opBinary( string OP )( long r ){ return this.opBinary!OP( ModWorld( r ) ); }
	auto opBinaryRight( string OP )( long l ){ return ModWorld( l ).opBinary!OP( this ); }
	auto opEquals( long r ){ return this.n == r; }
	
	auto toString(){ return this.n.to!string; }
}


Measured memory_bytes: 13100
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
         
        int n = sc.nextInt();
        Res[] l = new Res[n];
        
        for(int i=1;i<=n;i++){
        	l[i-1] = new Res(sc.next(),sc.nextInt(),i);
        }
        
        Arrays.sort(l);
        
        for(Res r:l){
            System.out.println(r.idx);
        }

    }

}

class Res implements Comparable<Res>{
	String city;
	int point;
	int idx;
	
	public Res(String city, int point,int idx){
		this.city = city;
		this.point = point;
		this.idx = idx;
	}
	
	@Override
	public int compareTo(Res o){
		if(!city.equals(o.city)){
			return city.compareTo(o.city);
		}
		return Integer.compare(o.point, point);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 21460
/**２つの整数 a と b を読み込んで、以下の値を計算するプログラムを作成して下さい：
?a ÷ b ： d (整数)
?a ÷ b の余り ： r (整数)
?a ÷ b ： f (浮動小数点数)
**/

/*sucannerクラス使うためにインポート*/
import java.util.Scanner;

class Main{
	//プログラムのエントリポイント
	public static void main(String[] args){
		//入力ストリームの生成
		Scanner sc = new Scanner(System.in);
		//数字を二つうけとる
		int inta = sc.nextInt();
		int intb = sc.nextInt();
		sc.close();
		//割算の整数の結果を出す計算式
		int intd = inta / intb;
		//割算のあまりを出す計算式
		int intr = inta % intb;

		//浮動小数点数を出す計算式
		double dbf = (double)inta/intb;
		//結果の表示
		//表示の際浮動小数計算は.以降7桁まで表示するように変更

		System.out.printf("%d %d %.7f%n",intd,intr,dbf);

	}
}

Measured memory_bytes: 17348
#include<iostream>
#define K 510001
using namespace std;
int h[K],w[K],n,m,i,j,p[1500],k;
int main(){
  while(1){
    for(i=1;i<K;i++)h[i]=0,w[i]=0;
    cin>>n>>m;if(n==0)break;
    for(i=0;i<n;i++){
      cin>>p[i];
      for(j=i,k=0;j>=0;j--,k+=p[j])h[p[i]+k]++;
    }
    for(i=0;i<m;i++){
      cin>>p[i];
      for(j=i,k=0;j>=0;j--,k+=p[j])w[p[i]+k]++;
    }
    n=0;
    for(i=1;i<K;i++)n+=h[i]*w[i];
    cout<<n<<endl;
  }
  return 0;
}

Measured memory_bytes: 5148
#include <stdio.h>
#include <ctype.h>

int S[100];
int top;

void push(int n) {
  S[top] = n;
  top++;
}

int pop() {
  top--;
  return S[top];
}

int main() {
  int a;
  while ((a = getchar()) != EOF) {
    int tmp;
    static int buf = 0;
    if (isdigit(a)) {
      if (buf > 0) {
	buf *= 10;
	buf += (a-'0');
      }
      else {
	buf = (a-'0');
      }
    }
    else if (a == '+') {
      tmp = pop();
      S[top-1] += tmp;
    }
    else if (a == '-') {
      tmp = pop();
      S[top-1] -= tmp;
    }
    else if (a == '*') {
      tmp = pop();
      S[top-1] *= tmp;
    }
    else if (a == ' ' && buf > 0) {
      push(buf);
      buf = 0;
    }
  }
  printf("%d\n", S[top-1]);
  return 0;
}



Measured memory_bytes: 2052
from collections import Counter
from math import factorial

def comb(n,r):
    return factorial(n)//factorial(r)//factorial(n-r)

N,A,B = map(int,input().split())
V=list(map(int,input().split()))

V_C=Counter(V)

max_val=max(V)
CC=V_C[max_val]
if A<=CC:
    ans=0
    for v in range(A,min(B,CC)+1):
        ans+=comb(CC,v)
    print(max_val)
    print(ans)
    exit()

tmp_sum=0
tmp_num=0

for key in sorted(V_C.keys(),reverse=True):
    val = V_C[key]
    #追加しても大丈夫なら加える(加えないとAに行かないから加えないといけない)
    #ぎりAに届くように追加するのが良い
    if A<=tmp_num+val:
        rest=A-tmp_num

        tmp_num+=rest
        tmp_sum+=key*rest
        print(tmp_sum/tmp_num)
        print(comb(val,rest))
        exit()
    else:
        tmp_num+=val
        tmp_sum+=key*val


Measured memory_bytes: 66524
import java.io.*;
import java.util.StringTokenizer;

public class Main {
  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> out.close()));
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));
    int D = sc.nextInt();
    switch (D) {
      case 25:
        out.println("Christmas");
        break;
      case 24:
        out.println("Christmas Eve");
        break;
      case 23:
        out.println("Christmas Eve Eve");
        break;
      case 22:
        out.println("Christmas Eve Eve Eve");
    }
  }

  /*
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


Measured memory_bytes: 27604
#include<bits/stdc++.h>
using namespace std;

int main(){
 int N;
 char S[N];
  cin>>N;
  cin>>S;

  int x=0, max=0;
  for(int i=0; i<N; i++){
   if(S[i]=='I'){x++;}
    else{x--;}
   if(max<x){max=x;}  //xの最大値がmaxに格納される
  }
   
cout<<max<<endl;
}

Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

W, H, x, y = map(int, input().split())

if x == W/2.0 and y == H/2.0:
    print(W*H/2.0,1)
else:
    print(W*H/2.0,0)




Measured memory_bytes: 77508
#include <bits/stdc++.h>

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define WHITE 0  // 未訪問
#define BLACK 1  // 訪問ずみ

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
const int N=100000;
//const ll M = 1000000000+7;


struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n, -1){}
  int root(int x) {
    if(d[x]<0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y){
    x = root(x); y=root(y);
    if(x==y) return false;
    if (d[x]>d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) {return root(x)==root(y);}
  int size(int x) {return -d[root(x)];}
  int factor_size() {
    int ans=0;
    rep(i,d.size()){
      if (d[i]<0) {ans++;}
    }
    return ans;
  }
  
};

bool inc(char c){
  string AGCT = "AGCT";
  bool ans = false;
  rep(i, 4) if(c==AGCT[i]) ans = true;
  return ans;
}

int main(){
  int n,m;

  cin >> n;

  ll a[n],b[n],c[n],aa[n],cc[n];

  rep(i, n){
    cin>>a[i];
  }
  rep(i, n){
    cin>>b[i];
  }
  rep(i, n){
    cin>>c[i];
  }
  sort(a, a+n);
  sort(b, b+n);
  sort(c, c+n);

  //reverse(a, a+n);
  //reverse(b, b+n);
  //reverse(c, c+n);

  ll ans=0;


  rep(i,n){
    aa[i] = lower_bound(a,a+n, b[i]) - a;  
    cc[i] = upper_bound(c,c+n, b[i]) - c;  
    // cout <<aa[i]<<" "<<cc[i]<<c[i]<<b[i]<<endl;
    ans+=aa[i]*(n-cc[i]);
  }
  
  cout << ans <<endl;
}




Measured memory_bytes: 4096
#include <iostream>

int main(void)
{
	int a, b;

	std::cin >> a >> b;
	if (a < b){
		std::cout << "a < b\n";
	}else if(a > b){
		std::cout << "a > b\n";
	}else{
		std::cout << "a == b\n";
	}
	return 0;
}

Measured memory_bytes: 1124
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    i64 n,k;
    cin>>n>>k;
    vector<i64> h(n);
    REP(i,n) cin>>h[i];

    sort(h.begin(),h.end());
    reverse(h.begin(),h.end());
    
    REP(i,min(k,n)) h[i] = 0;
    
    i64 sum = 0;
    REP(i,n) sum += h[i];

    cout<<sum<<endl;

    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;



int main(){
    int N; cin >> N;
    vector<int> d(N);
    rep(i,N) cin >> d[i];
    sort(d.begin(),d.end());
    int ans = 0;
    rep(i,100010){
        int index = (int)(lower_bound(d.begin(),d.end(),i) - d.begin());
        int cnt1 = index;
        int cnt2 = N - index;
        if(cnt1 == cnt2) ans++;
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int N;//人数
	int K;//菓子の種類
	int sum=0;//合計
	int t = 0;
	int c = 1;//カウンター
	cin >> N >> K;
	vector<int> d(K);//お菓子iを持ってる人数
	vector<vector<int>> A(K, vector<int>(N));//各お菓子の所有者の人数
	for (int i = 0; i < K; i++) {//iはお菓子の番号
		cin >> d[i];//
		sum = d[i] + sum;
		for (int j = 0; j < d[i]; j++) {//jは人間の番号
			cin >> A[i][j];
		}
	}
	vector<int> data(sum);
	for (int a = 0; a < K; a++) {//iはお菓子の番号
		for (int b = 0; b < d[a]; b++) {//jは人間の番号
			data[t]=A[a][b];

			t = t + 1;
		}
	}
	sort(data.begin(), data.end());
	for (int e = 1; e< sum; e++) {
		if (data[e] != data[e - 1]) {
			c = c+1;
		}
	}
	int ans=N-c;
	cout <<ans ; 

	return 0;
}

Measured memory_bytes: 3660
H,W = gets.split.map &:to_i
nums = Hash[("a".."z").map{ |c| [c,0] }]
(0...H).map{ gets.chomp }.join.split("").each{ |c|
  nums[c] += 1
}

if H % 2 == 1 && W % 2 == 1
  if nums.count{ |c,n| n % 2 == 1 } != 1
    puts "No"; exit
  end
  nums.each{ |c,n| nums[c] = n - (n%2) }
end
if nums.count{ |c,n| n % 2 == 1 } > 0
  puts "No"; exit
end
s = (H - H%2) * (W - W%2)
nums.each{ |c,n|
  v = (n/4)*4
  nums[c] -= v
  s -= v
}
puts s <= 0 ? "Yes" : "No"


Measured memory_bytes: 2172
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    int x,h,m1,m,s;
    cin >> x;
    h = x / 3600;
    m1 = x % 3600;
    m = m1 / 60;
    s = m1 % 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>

#define ms(a,b) memset(a, b, sizeof(a))
#define rep(a,b,c) for(int a = (int)(b); a < (int)(c); a++)
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define m_p(a,b) make_pair(a, b)
#define lson l,mid,o << 1
#define rson mid + 1,r,o << 1 | 1
#define ls o << 1
#define rs o << 1 | 1
#define inf 0x3f3f3f3f

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

inline bool isdigit(char& ch) {
	return ch >= '0' && ch <= '9';
}
template<class T>
void read(T &x) {
	x = 0;
	ll f = 1;char ch = getchar();
	for (;!isdigit(ch);ch = getchar()) 
		if (ch == '-') f = -1;
	for (; isdigit(ch);ch = getchar())
		x = (x << 1) + (x << 3) + ch - '0';
	x *= f;
}
template<class T>
inline void write(T x) {
	if (x == 0) {putchar('0');return ;}
	if (x < 0) {putchar('-');x = -x;}
	int _stk[65],_top = 0;
	for (;x;x /= 10) _stk[++_top] = x % 10 + 48;
	for (;_top;_top--)putchar(_stk[_top]);
}
const int MAXN = 300000 + 100;
const ll mod = 998244353;

int n, k;
ll sum[MAXN << 2], pw[MAXN];
ll ch[MAXN << 2];
ll inv[50];

ll qpow(ll x, ll y) {
	ll r = 1;
	while(y) {
		if (y & 1)
			r = r * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return r;
}
void pushup(int o, int l, int r) {
	int mid = l + r >> 1;
	ll len = (r - mid);
	sum[o] = (sum[ls]  * pw[len] % mod + sum[rs]) % mod;
}

void pushdown(int o, int l, int r) {
	int mid = l + r >> 1;
	int len2 = (r - mid);
	int len1 = (mid - l + 1);
	if (ch[o]) {
		ch[ls] = ch[o];
		sum[ls] = pw[len1] % mod;
		sum[ls] -= 1;
		if (sum[ls] < 0)
			sum[ls] += mod;
		sum[ls] = sum[ls] * inv[9] % mod * ch[ls] % mod;
	}
	if (ch[o]) {
		ch[rs] = ch[o];
		sum[rs] = pw[len2] % mod;
		sum[rs] -= 1;
		if (sum[rs] < 0)
			sum[rs] += mod;
		sum[rs] = sum[rs] * inv[9] % mod * ch[rs] % mod;
	}
	ch[o] = 0;
}

void build(int l, int r, int o) {
	if (l == r) {
		sum[o] = 1;
		return;
	}
	int mid = l + r >> 1;
	build(lson);
	build(rson);
	pushup(o, l, r);
}

void update(int L, int R, ll d, int l, int r, int o) {
	pushdown(o, l, r);
	if (L <= l && r <= R) {
		ch[o] = d;
		int len = r - l + 1;
		ll s = pw[len] % mod;
		s -= 1;
		if (s < 0)
			s += mod;
		sum[o] = s * inv[9] % mod * d % mod;
	//	cout << sum[o] << endl;
		return ;
	}
	int mid = l + r >> 1;
	if (L <= mid)
		update(L, R, d, lson);
	if (mid < R)
		update(L, R, d, rson);
	pushup(o, l, r);
}


int main () {
	read(n);
	read(k);
	pw[0] = 1;
	rep(i, 1, n + 10)
		pw[i] = pw[i - 1] * 10 % mod;
	rep(i, 1, 12)
		inv[i] = qpow(i, mod - 2);
	build(1, n, 1);
//	cout << sum[1] << endl;
	while(k--) {
		int l, r;
		ll d;
		read(l);
		read(r);
		read(d);
		update(l, r, d, 1, n, 1);
//		cout << ch[5] << "A" << endl;
	//	cout << sum[5] << "a" << endl;
		write(sum[1]);
		putchar('\n');
	}	
	return 0;
}

Measured memory_bytes: 21516
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n;
	cin>>n;
	if(n%2!=0)
	{
		cout<<0<<endl;
		return 0;
	}
	n=n/2;
	int sum=0;
	for(int i=5;n/i>=1;i*=5){
		sum+=n/i;
	}
	cout<<sum;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}

Measured memory_bytes: 3600
import java.io.*;
import java.util.*;

public class Main{
    
    public static void main(String[] arg){

        Scanner scan =new Scanner(System.in);

        int n=Integer.parseInt(scan.next());
        int m=Integer.parseInt(scan.next());

        long[] A=new long[n];

        for(int i=0;i<n;i++){
            A[i]=scan.nextLong();
         
        }

        int i,j,k;
        
        BandC[] BC=new BandC[m];
        SortBandC srt=new SortBandC();

        for(i=0;i<m;i++){

            BC[i]=new BandC(Integer.parseInt(scan.next()), 
                Integer.parseInt(scan.next()));
        }

        Arrays.sort(BC, srt);

        int[] D=new int[n];
        int count=0;
        for(k=0;k<m;k++){
            for(i=0;i<BC[k].b;i++){
                if(count>=n) break;
                D[count]=BC[k].c;
                count++;
                

            }
        }

        Arrays.sort(A);


        for(i=0;i<n;i++){
            if(A[i]<=D[i]) A[i]=D[i];
        }
        

        long sum = 0;
        for(long d : A){
        sum += d;
        }
        System.out.print(sum);
        
        
     
    }

    static class BandC{
        int b,c;

        BandC(int b,int c){
            this.b=b;
            this.c=c;
        }
    }

    static class SortBandC implements Comparator<BandC>{
        public int compare(BandC bc1,BandC bc2){
            return bc2.c-bc1.c;
        }
    }

}



Measured memory_bytes: 65488
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <climits>
#include <queue>

using namespace std;

#define int long long int

// int MOD = 1e9 + 7;

vector<int> a, f;
// set<pair<int, pair<int, int> > > st;
vector<pair<int, int> > st;

bool solve(int value, int k){
	// set<pair<int, pair<int, int> > > temp = st;
	int ans = 0;
	for(auto x : st){
		int t = x.second - value/(x.first);
		ans += max(t, 0ll);
	}
	if(ans > k) return false;
	return true;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k;
	cin>>n>>k;
	for(int i = 0; i<n; i++){
		int x;
		cin>>x;
		a.emplace_back(x);
	}
	for(int j = 0; j<n; j++){
		int x;
		cin>>x;
		f.emplace_back(x);
	}
	sort(a.begin(), a.end());
	sort(f.begin(), f.end());

	for(int i = 0; i<n; i++){
		// st.insert({-1ll * a[i] * f[n-i-1], {a[i], f[n-i-1]}});
		st.emplace_back(f[i], a[n-i-1]);
	}
	int low = 0;
	int high = 1e18;
	int mid = 1e9;
	int count = 0;
	while(count<100){
		// cout<<low<<", "<<high<<endl;
		mid = (low + high)/2;
		if(solve(mid, k)) high = mid;
		else low = mid;
		count++;
	}
	if(solve(low, k)) cout<<low<<endl;
	else if(solve(high, k)) cout<<high<<endl;
	else cout<<high + 1<<endl;
	return 0;
}

Measured memory_bytes: 9584
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    vector<char> S(N, false);
    loop(i, N){
        char c = getchar();
        if (c == '1'){
            S[i] = true;
        }
    }
    set<int, greater<int>> lseed; // l
    set<int> rseed; // r
    loop(i, N - 2){
        if (S[i] && !S[i + 1] && S[i + 2]){
            rseed.emplace(i + 2);
            lseed.emplace(i);
        }
    }
    map<int, set<int>> t1011; // l -> r
    map<int, set<int>> t1101; // r -> l
    loop(i, N){
        if (!S[i]) continue;
        if (lseed.count(i - 2)){
            t1011[i - 2].emplace(i);
            t1101[i].emplace(i - 2);
        }
        auto it = lseed.lower_bound(i - 2);
        if (it == lseed.end()) continue;
        if (*(t1011[*it].rbegin()) + 1 == i){
            t1011[*it].emplace(i);
        }
    }
    for (int i = N - 1; 0 <= i; --i){
        if (!S[i]) continue;
        auto it = rseed.lower_bound(i + 2);
        if (it == rseed.end()) continue;
        if (*(t1101[*it].begin()) - 1 == i){
            t1101[*it].emplace(i);
        }
    }
    // for (auto& e : t1011){
    //     printf("%d : ", e.first);
    //     for (auto& g : e.second){
    //         printf("%d ", g);
    //     }
    //     puts("");
    // }
    // for (auto& e : t1101){
    //     printf("%d : ", e.first);
    //     for (auto& g : e.second){
    //         printf("%d ", g);
    //     }
    //     puts("");
    // }
    map<int, set<int>, greater<int>> lr;
    for (auto& e : t1011){
        for (auto& g : e.second){
            lr[e.first].emplace(g);
        }
    }
    for (auto& e : t1101){
        for (auto& g : e.second){
            lr[g].emplace(e.first);
        }
    }
    // for (auto& e : lr){
    //     printf("%d : ", e.first);
    //     for (auto& g : e.second){
    //         printf("%d ", g);
    //     }
    //     puts("");
    // }
    vector<int> dp(N, 0);
    int result = 0;
    loop(i, N){
        dp[i] = max(dp[i], dp[max(i - 1, 0)]);
        if (lr.count(i) == 0) continue;
        for (auto& r : lr[i]){
            dp[r] = max(dp[r], dp[max(0, i - 1)] + r - i - 1);
            result = max(result, dp[r]);
        }
    }
    printf("%d\n", result);
}


Measured memory_bytes: 142720
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using vi  = vector<int>;
using ii  = pair<int,int>;
using vii = vector<ii>;
using ll  = long long;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) int((x).size())
#define REP(i, a, b) for (auto (i) = (a); (i) <= (b); (i)++)
#define PER(i, a, b) for (auto (i) = (a); (i) >= (b); (i)--)
#define ITR(i, x) for (auto (i) = (x).begin(); (i) != (x).end(); (i)++)

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int k;
	cin >> k;
	if (k % 2 == 0 or k % 5 == 0) {
		cout << "-1\n";
	} else {
		int idx = 1;
		ll num = 7 % k;
		ll add = 70 % k;
		while (num != 0) {
			num = (num + add) % k;
			add = (add * 10) % k;
			idx++;
		}
		cout << idx << '\n';
	}
	return 0;
}

Measured memory_bytes: 3648
import numpy as np

N,S = map(int, input().split())
A = list(map(int, input().split()))

MOD = 998244353

dp = np.zeros(S + 1, dtype=int)
dp[0] = 1

for i in A:
    ep = dp.copy()
    ep += dp
    ep[i:] += dp[:-i]
    dp = ep % MOD

print(dp[S])


Measured memory_bytes: 27472
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

// 全部プラスorマイナスのときのみ注意

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	vector<int> Vp;
	vector<int> Vm;

	for (int i = 0; i < N; i++) {
		int tmp; cin >> tmp;
		if (tmp >= 0) Vp.push_back(tmp);
		else Vm.push_back(tmp);
	}

	if (Vp.size()>0 && Vm.size()>0) { // 両符号存在するとき
		ll M = 0LL;
		for (int i = 0; i < Vp.size(); i++) M += Vp[i];
		for (int i = 0; i < Vm.size(); i++) M -= Vm[i];
		cout << M << endl;

		ll num = ll(Vm[0]);
		for (int i = 0; i < Vp.size() - 1; i++) {
			cout << num << " " << Vp[i] << endl;
			num -= Vp[i];
		}
		cout << Vp[Vp.size() - 1] << " " << num << endl;
		num = Vp[Vp.size() - 1] - num;
		for (int i = 1; i < Vm.size(); i++) {
			cout << num << " " << Vm[i] << endl;
			num -= Vm[i];
		}
	}
	else if (Vm.size() > 0) {
		sort(Vm.begin(), Vm.end(), greater<int>());
		ll M = ll(Vm[0]);
		for (int i = 1; i < N; i++) M -= Vm[i];
		cout << M << endl;

		ll num = (Vm[0]);
		for (int i = 1; i < N; i++) {
			cout << num << " " << Vm[i] << endl;
			num -= Vm[i];
		}
	}
	else { // 全て0以上
		sort(Vp.begin(), Vp.end());
		ll M = ll(-Vp[0]);
		for (int i = 1; i < N; i++) M += Vp[i];
		cout << M << endl;

		ll num = ll(Vp[0]);
		for (int i = 1; i < N - 1; i++) {
			cout << num << " " << Vp[i] << endl;
			num -= Vp[i];
		}
		cout << Vp[N - 1] << " " << num << endl;
	}


	return 0;
}

Measured memory_bytes: 2424
#include <iostream>
#include <string>

using namespace std;

int main(){
	string card, card1;
	int m, h;
	
	while(1){
		int i = 0;
		cin >> card >> m;
		if(card == "-") break;
		
		while(i < m){
			cin >> h;
			i++;
			card1 = card.substr(0, h);
			card.erase(0, h);
			card += card1;
		}
		cout << card << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3176
import java.util.*;
public class Main{
public static void main(String[]args){
  Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int k=sc.nextInt();
  int[]po=new int[n];
  for(int i=0;i<n;i++)po[i]=sc.nextInt();
  Arrays.sort(po);
  int ans=0;
  for(int i=0;i<k;i++)ans+=po[n-1-i];
  System.out.println(ans);
}

}


Measured memory_bytes: 23252
s = input()
if s[1] == s[2] and s[3] == s[0] and s[1] != s[3]:
    print("Yes")
elif s[1] == s[3] and s[2] == s[0] and s[1] != s[2]:
    print("Yes")
elif s[1] == s[0] and s[3] == s[2] and s[1] != s[2]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var aa = ToIntArray(input.ReadLine(), n);

        return aa.Max() - aa.Min();
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 13268
#include <iostream>
int main() {
	long long int n, l[86];
	l[0] = 2;
	l[1] = 1;
	std::cin >> n;
	for (int i = 2; i <= n; i++) {
		l[i] = l[i - 1] + l[i - 2];
	}
	std::cout << l[n];
		return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int N=205;
int n,m,cnt,a[N][N],b[N][N],c[N][N],d[N][N];
pair<int,int> bel[N];
vector<int> e[N][N];
namespace flow{
	int cnt,s,t,head[N],dep[N],to[N*N],nxt[N*N],dd[N*N];
	queue<int> q;
	void adde(int u,int v,int d){
		to[++cnt]=v;
		nxt[cnt]=head[u];
		dd[cnt]=d;
		head[u]=cnt;
		to[++cnt]=u;
		nxt[cnt]=head[v];
		dd[cnt]=0;
		head[v]=cnt;
	}
	void init(){
		cnt=1;
		s=0;
		t=2*n+1;
		memset(head,0,sizeof(head));
		for(int i=1;i<=n;i++){
			adde(s,i,1);
			adde(i+n,t,1);
			for(int j=1;j<=n;j++){
				if(e[i][j].size()){
					adde(i,j+n,1);
				}
			}
		}
	}
	bool bfs(){
		memset(dep,0,sizeof(dep));
		dep[s]=1;
		q.push(s);
		while(!q.empty()){
			int u=q.front(),v;
			q.pop();
			for(int i=head[u];i;i=nxt[i]){
				v=to[i];
				if(!dep[v]&&dd[i]){
					dep[v]=dep[u]+1;
					q.push(v);
				}
			}
		}
		return dep[t];
	}
	int dfs(int u,int f){
		if(u==t||!f){
			return f;
		}
		int v,tmp,res=0;
		for(int i=head[u];i&&f;i=nxt[i]){
			v=to[i];
			if(dep[v]==dep[u]+1&&(tmp=dfs(v,min(f,dd[i])))){
				dd[i]-=tmp;
				dd[i^1]+=tmp;
				f-=tmp;
				res+=tmp;
			}
		}
		if(!res){
			dep[u]=-1;
		}
		return res;
	}
	void maxflow(){
		while(bfs()){
			dfs(s,0x7fffffff);
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
			bel[a[i][j]].first=i;
			b[i][j]=++cnt;
			bel[b[i][j]].second=i;
		}
	}
	for(int i=1;i<=n*m;i++){
		e[bel[i].first][bel[i].second].push_back(i);
	}
	for(int i=1;i<=m;i++){
		flow::init();
		flow::maxflow();
		for(int j=1;j<=n;j++){
			for(int k=flow::head[j];k;k=flow::nxt[k]){
				int l=flow::to[k];
				if(l&&!flow::dd[k]){
					l-=n;
					c[j][i]=d[l][i]=e[j][l].back();
					e[j][l].pop_back();
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			printf("%d ",c[i][j]);
		}
		puts("");
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			printf("%d ",d[i][j]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    map<string,ll> mp;
    rep(i,n){
        string tmp;
        cin>>tmp;
        mp[tmp]++;
    }
    ll m;
    cin>>m;
    rep(i,m){
        string tmp;
        cin>>tmp;
        mp[tmp]--;
    }

    ll ans= 0;
    Each(elm,mp){
        chmax(ans,elm.se);
    }
    dbgmap(mp);
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

int main() {
  string N;
  cin >> N;
  if (N[0] == '7' or N[1] == '7' or N[2] == '7') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define ms(s, n) memset(s, n, sizeof(s))
#define rp(i,l,m) for(int i=l; i<m; ++i)
#define Rp(i,l,m) for(int i=l; i<=m; i++)
#define rpD(i,l,m) for(int i=m; i>l; i--)
#define RpD(i,m,l) for(int i=m; i>=l; i--)
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define sz(a) int((a).size())
#define is insert
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
inline ll gcd(ll a, ll b) {ll r; while (b) {r=a%b;a=b;b=r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p=MOD){ll r=1; for(;k;k>>=1){if(k&1)r=r*n%p;n=n*n%p;}return r;}
inline ll Pow(int n, int k){int r=1; for(;k;k>>=1){if(k&1)r=r*n;n=n*n;}return r;}
#define N 5005

int ans, a, b, n, g;

inline void input(){
    cin >> n;
}
/*
5
AB
RABYBBE
BMHQUVA
BPA
MCMABAOBHZ
*/
inline void solve(){
    for(int i=1; i<=n; i++){
        string s;
        cin >> s;
        for(int i=0; i<sz(s)-1; i++){
            if(s[i]=='A' && s[i+1]=='B') ans++;
        }
        if(s[0]=='B' && s[sz(s)-1]=='A') {g++; continue;}
        if(s[0]=='B') b++;
        if(s[sz(s)-1]=='A') a++;
    }
    //cout << a << " " << b << " " << ans << endl;
    if(g) ans+=g-1;
    if(a && g) a--, ans++;
    if(b && g) b--, ans++;
    cout << ans + min(a,b);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    input();
    solve();
  return 0;
}












Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
   int a, b, c;
   cin >> a >> b >> c;
   cout << a*b/2 << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#define PI 3.1415926535897932384626433832795028841971
using namespace std;

int main(){
    int w,h;
    
    while(true){
        cin >> h >> w;
        if(w == 0 && h == 0){
            break;
        }
        
        for(int hh = 0;hh<h;hh++){
            for(int ww = 0;ww<w;ww++){
                if( hh == 0 || hh == h - 1 ||ww == 0 || ww == w - 1){
                    cout << '#';
                }
                else{
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;

#define all(v) v.begin(), v.end()
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPE(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void chmax(T& a, T b) { if(a > b) a = b; }
template<class T> void chmin(T& a, T b) { if(a < b) b = a; }
typedef long long ll;

int main() {
    int n; cin >> n;
    string ans = "Three";
    rep(i, n){
        char c; cin >> c;
        if(c == 'Y'){
            ans = "Four";
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256