akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) throws IOException{
        Scanner br = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
 
        int[] alp = new int[26];
 
        while (br.hasNext()) {
            String line = br.nextLine();
            line = line.toLowerCase();
            char[] c = line.toCharArray();
            for (int i=0; i<c.length; i++) {
                if (c[i] >= 'a' && c[i] <= 'z')
                    alp[c[i]-'a']++;
            }
        }
 
        for (int i=0; i<26; i++) {
            System.out.println((char)('a'+i)+" : "+alp[i]);
        }
 
        br.close();
    }
}




Measured memory_bytes: 26148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,m;
    cin>>n>>m;
    string a[55],b[55];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
    for(int i=0;i<n-m+1;i++){
        for(int j=0;j<n-m+1;j++){
            bool flag=true;
            for(int k=i;k<i+m;k++){
                if(a[k].substr(j,m)!=b[k-i]){
                    flag=false;
                    break;
                }
            }
            if(flag){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define REP(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  i32 X, N = 0;
  vector<u32> p;
  u32 pin;

  cin >> X >> N;

  REP(i, N) {
    cin >> pin;
    p.push_back(pin);
  }

  if (N == 0) {
    cout << X;
    return 0;
  }

  auto m = max_element(p.begin(), p.end());

  u32 ans = 0;
  u32 ans_diff = INT_MAX;

  for (int i = 0; i < (*m) + 2; i++) {
    if (find(p.begin(), p.end(), i) != p.end()) {
      continue;
    } else {
      if (abs(i - X) < ans_diff) {
        ans = i;
        ans_diff = abs(i - X);
      } else {
        cout << ans;
        return 0;
      }
    }
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define xy pair<ll, ll>
#define x first
#define y second 

#define inf std::numeric_limits<ll>().max()

int main() {
	int n;
	cin >> n;
	vector<int> v(n); 
	for(int i=0; i<n; i++) {
		cin >> v[i]; 
	}
	ll ans = 0;
	int nmax = v[0];
	for(int i=1; i<n; i++) {
		nmax = max(nmax, v[i]);
		if (v[i] < nmax) {
			ans += nmax - v[i];
		} 
	}
	cout << ans << '\n';
}



Measured memory_bytes: 3552
s = list(input())

while len(s) > 0:
    if ''.join(s[-7:]) == 'dreamer':
        del s[-7:]
    elif ''.join(s[-6:]) == 'eraser':
        del s[-6:]
    elif ''.join(s[-5:]) == 'dream' or ''.join(s[-5:]) == 'erase':
        del s[-5:]
    else:
        break
print('YES' if len(s) == 0 else 'NO')

Measured memory_bytes: 3956
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
const val MOD = 1000000007L

fun isOK(last4: String): Boolean {
    val regex = "AGC|AG.C|A.GC|GAC|ACG".toRegex()
    return !regex.containsMatchIn(last4)
}

fun solve(N: Int) {
    // dp[i][s] i文字で最後の三文字がsなものの総数
    val dp = Array<MutableMap<String, Long>>(N + 1) { mutableMapOf<String, Long>() }
    for (i in "AGCT") {
        for (j in "AGCT") {
            for (k in "AGCT") {
                val s = listOf(i, j, k).joinToString(separator = "")
                if (isOK(s)) dp[3][s] = 1L
            }
        }
    }
    for (i in 4..N) {
        for (j in dp[i - 1].keys) {
            for (k in "AGCT") {
                val last4 = j + k.toString()
                if (isOK(last4)) {
                    val last3 = last4.drop(1)
                    dp[i][last3] = (dp[i].getOrElse(last3){ 0 } + dp[i - 1][j]!!) % MOD
                }
            }
        }
    }
    // println(dp[N])
    println(dp[N].map { it.value }.sum() % MOD)
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    solve(N)
}


Measured memory_bytes: 51992
#include <bits/stdc++.h>
using namespace std;
string s;
int k;
int main(){
    cin>>k;
    cin>>s;
    int l=s.length();
    if(l<=k) cout<<s<<endl;
    else
    {
        for(int i=0;i<k;i++) cout<<s[i];
        cout<<"..."<<endl;
    }
    return 0;
}


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

main()
{
    int n; cin>>n;
    int a[1<<18];
    int div[1<<20]={};
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        div[a[i]]++;
    }

    bool ip[1<<20];
    fill(begin(ip), end(ip), 1);
    for(int i=2; i<1<<20; i++)
    {
        if(ip[i])
        {
            for(int j=1; j*i<1<<20; j++)
            {
                ip[j*i]=false;
                div[j*i]+=div[j];
            }
        }
    }

    int ans=0;
    for(int i=0; i<n; ++i)
    {
        if(div[a[i]]>1)
        {
            continue;
        }
        ans++;
    }
    cout << ans << "\n";

}


Measured memory_bytes: 9548
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        
        if (a + b == c || a + c == b || b + c == a) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21716
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  ll h, n, w;

  for (ll i = 1; i <= 3500; ++i)
  {
    for (ll j = 1; j <= 3500; ++j)
    {
      if ((4 * i * j - N * j - N * i) <= 0)
        continue;
      if ((N * i * j) % (4 * i * j - N * i - N * j) == 0)
        h = i, n = j;
    }
  }
  cout << h << ' ' << n << ' ' << (N * h * n) / (4 * h * n - N * n - N * h) << endl;

  return 0;
}


Measured memory_bytes: 384
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,(n))
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	int a, b;
	cin >> a >> b;
	if (a == 0 || b == 0 || (a < 0 && 0 < b)) {
		cout << "Zero" << endl;
	}
	else if (0 < a && 0 < b) {
		cout << "Positive" << endl;
	}
	else {
		if ((b - a) % 2) {
			cout << "Positive" << endl;
		}
		else {
			cout << "Negative" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
n, m, l = map(int, raw_input().split())

A = [[0] for i in range(n)]
B = [[0] for i in range(m)]
temp = 0

for i in range(n):
    A[i] = map(int, raw_input().split())
for i in range(m):
    B[i] = map(int, raw_input().split())

C = [[0 for i in range(l)] for j in range(n)]

for i in range(n):
    for j in range(l):
        for k in range(m):
            temp += A[i][k] * B[k][j]
        C[i][j] = temp
        temp = 0
for i in range(n):
    print " ".join(map(str, C[i]))

Measured memory_bytes: 7044
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <set>
#include <map>

using namespace std;

const int N = 100100;


int main() {
 string last;
 set<string> st;
 int n ; cin >> n;
 for(int i = 0;i < n; i++) {
   string cur; cin >> cur;
   if(last != "" && cur[0] != last[last.length() - 1]) {
     cout << "No" << endl;
     return 0;
   }
   if(st.find(cur) != st.end()) {
     cout << "No" << endl;
     return 0;
   }
   st.insert(cur);
   last = cur;
 }
 cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll k, t;
  cin >> k >> t;
  ll m = 0;
  rep(i, t) {
    ll a;
    cin >> a;
    m = max(m, a);
  }
  ll r = k - m;
  cout << max(0LL, m - r - 1) << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 1000000000000000005
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
int main(){
	char in[10];
	while(~scanf("%s",in)){
		int ans=0;
		F(i,0,4) in[i]=='+'?ans++:ans--;
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 256
D=*0..gets.to_i
c=0,i=1,2
$<.map{|l|a,b=l.split.map &:to_i
D[a],D[b]=D[b],D[a]
i!=a&&i!=b||i=a+b-i
c|=D[i-1,3]}
p~-c.size

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    int h , a ;
    cin >> h >> a ;

    int ans = 1 + ( h - 1 ) / a ;
    cout << ans ;

    line ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i + 1);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int m,mi;
    int a[40],b[40],c[40],d[40];
    char ac[40],bc[40],t;
    while(scanf("%d",&m)!=EOF)
    {
        int i,j,x;
        int r=1,flag=1;
        getchar();
        for(i=0; i<m; i++)
        {
            c[i]=i;
            d[i]=i;
            scanf("%c%d",&ac[i],&a[i]);
            getchar();
            b[i]=a[i];
            bc[i]=ac[i];
        }
        for(i=0; i<m; i++)
        {
            for(j=m-1; j>=i+1; j--)
                if(a[j]<a[j-1])
                {
                    x=a[j-1];
                    a[j-1]=a[j];
                    a[j]=x;
                    x=c[j-1];
                    c[j-1]=c[j];
                    c[j]=x;
                    t=ac[j-1];
                    ac[j-1]=ac[j];
                    ac[j]=t;
                }
        }
        for(i=0; i<m-1; i++)
        {
            printf("%c%d ",ac[i],a[i]);
            if(a[i]==a[i+1]&&c[i]>c[i+1])
                r=0;
        }
        printf("%c%d\n",ac[i],a[i]);
        if(flag)
            printf("Stable\n");
        else
            printf("Not stable\n");
        for(i=0; i<m; i++)
        {
            mi=i;
            for(j=i; j<m; j++)
                if(b[j]<b[mi])
                {
                    mi=j;
                }
            if(b[i]>b[mi])
            {
                x=b[i];
                b[i]=b[mi];
                b[mi]=x;
                x=d[i];
                d[i]=d[mi];
                d[mi]=x;
                t=bc[i];
                bc[i]=bc[mi];
                bc[mi]=t;
            }
        }
        for(i=0; i<m-1; i++)
        {
            printf("%c%d ",bc[i],b[i]);
            if(b[i]==b[i+1]&&d[i]>d[i+1])
                flag=0;
        }
        printf("%c%d\n",bc[i],b[i]);
        if(flag)
            printf("Stable\n");
        else
            printf("Not stable\n");
    }
}


Measured memory_bytes: 2096
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int n;
std::string s;

void search(char first, char second) {
    std::string res;
    res.push_back(first);
    res.push_back(second);
    for (int i = 1; i < n - 1; i++) {
        if (s[i] == 'o') {
            if (res[i] == 'S') {
                res.push_back(res[i - 1]);
            } else {
                if (res[i - 1] == 'S') {
                    res.push_back('W');
                } else {
                    res.push_back('S');
                }
            }
        } else {
            if (res[i] == 'S') {
                if (res[i - 1] == 'S') {
                    res.push_back('W');
                } else {
                    res.push_back('S');
                }

            } else {
                res.push_back(res[i - 1]);
            }
        }
    }
    // cout << res << endl;

    if (s[n - 1] == 'o' && res[n - 1] == 'S') {
        if (res[n - 2] != res[0]) {
            return;
        }
    } else if (s[n - 1] == 'o' && res[n - 1] == 'W') {
        if (res[n - 2] == res[0]) {
            return;
        }
    } else if (s[n - 1] == 'x' && res[n - 1] == 'S') {
        if (res[n - 2] == res[0]) {
            return;
        }
    } else {
        if (res[n - 2] != res[0]) {
            return;
        }
    }

    if (s[0] == 'o' && res[0] == 'S') {
        if (res[1] != res[n - 1]) {
            return;
        }
    } else if (s[0] == 'o' && res[0] == 'W') {
        if (res[1] == res[n - 1]) {
            return;
        }
    } else if (s[0] == 'x' && res[0] == 'S') {
        if (res[1] == res[n - 1]) {
            return;
        }
    } else {
        if (res[1] != res[n - 1]) {
            return;
        }
    }

    cout << res << endl;
    exit(0);

    return;
}

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    cin >> n;
    cin >> s;
    search('S', 'S');
    // cout << "false" << endl;
    search('S', 'W');
    // cout << "false" << endl;
    search('W', 'W');
    // cout << "false" << endl;
    search('W', 'S');
    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	string s, t;
	cin >> s >> t;
	int s_len = (int)s.size();
	int t_len = (int)t.size();
	reverse(s.begin(), s.end());
	reverse(t.begin(), t.end());
	set<string> s_set;

	bool check = 0;
	for (int i = 0; i < ((int)s_len - (int)t_len + 1); i++){
		bool flag = 1;
		for (int j = 0; j < t_len; j++){
			if (s[i+j] == t[j] or s[i+j] == '?') continue;
			flag = 0;
		}
		if (flag){
			string tmp = s;
			for (int j = 0; j < t_len; j++){
				tmp[i+j] = t[j];
			}
			for (int i = 0; i < s_len; i++){
				if (tmp[i] == '?') tmp[i] = 'a';
			}
			s_set.insert(tmp);
		}
	}

	if (s_set.empty()){
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	auto itr = s_set.end();

	string ans = *(--itr);

	reverse(ans.begin(), ans.end());

	cout << ans << endl;
}


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

int main(){
  vector<int> A(3);
  for (int i = 0; i < 3; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  cout << A.at(2)*10+A.at(0)+A.at(1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;
    stack<char> s;
    for (int i = 0; i < S.size(); i++) {
        if (s.empty()) {
            s.push(S[i]);
        } else {
            if (s.top() == '(' && S[i] == ')') {
                s.pop();
            } else {
                s.push(S[i]);
            }
        }
    }

    string left, right;
    while (!s.empty()) {
        char c = s.top(); s.pop();
        if (c == '(') right += ')';
        else left += '(';
    }

    cout << left + S + right << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;

}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL||k==u->key){
    return u;
  }
  if(k<u->key){
    return treeSearch(u->left,k);
  }else{
    return treeSearch(u->right,k);
  }
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else if(z->key<y->key){
    y->left=z;
  }else{
    y->right=z;
  }
}

void inorder(Node u){
  if(u==NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL){
    return ;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25136
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

template<class T> inline int sgn(T n) { if (n > 0) return 1; else if (n < 0) return -1; else return 0; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main () {
  string s;
  cin >> s;

  // bfs
  queue<int> q;
  bool can = false;
  q.push(0);
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    if (t == s.size()) {
      can = true;
      break;
    }
    for (string d : divide) {
      if (s.substr(t,d.size()) == d) {
        q.push(t+d.size());
      }
    }
  }

  puts(can ? "YES" : "NO");
  return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int x;cin>>x;
	cout<<(!x)<<endl;
}

Measured memory_bytes: 3572
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {        
        var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var A = input[0];
        var B = input[1];
        
        var sum = 0;
        if (A >= B) {
            sum += A;
            A--;
            if (A < B) {
                sum += B;
            } else {
                sum += A;
            }
        } else {
            sum += B;
            B--;
            if (B < A) {
                sum += A;
            } else {
                sum += B;
            }
        }
        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 11348
X, N = map(int, input().split())
P = list(map(int, input().split()))

ans = 10 ** 5
for i in range(X - 100, X + 100 + 1):
    if i not in P:
        if ans > abs(X - i):
            ans = abs(X - i)
            tmp = i

print(tmp)

Measured memory_bytes: 9160
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
    int n,t,minimum;
    cin >> n;
    vector<int> w(n);
    for(int i=0;i<n;i++) cin >> w.at(i);
    int count=0,flag=0;
    for(int i=0;i<n;i++)flag+=w.at(i);
    minimum=flag;
    for (int i=1;i<n;i++){
        t=i;
        flag=0;
        count=0;
        for(int i=0;i<=t;i++)count+=w.at(i);
        for(int i=t+1;i<n;i++)flag+=w.at(i);
        /*cout << "count:"  << count;
        cout << "flag:" << flag << endl;*/
        if(abs(count-flag)<=minimum) minimum=abs(count-flag);
    }
    cout << minimum << endl;
 }


Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

w, a, b = rm()
if a < b:
    print(max(b-(a+w), 0))
else:
    print(max(a-(b+w), 0))













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

int main() {
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  int ans = min(a*x+b*y,2*c*max(x,y));
  if(x < y) ans = min(ans,2*c*x+b*(y-x));
  else ans = min(ans,2*c*y+a*(x-y));
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
xy = []
for i in range(n):
  arrat = [int(i) for i in input().split()]
  xy.append(arrat)

ans = 0
for i in range(n):
  for j in range(i+1,n):
    ans += ((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**0.5

ans /= n
print(ans*2)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200


int main(){
	vector<int>a;
	vector<int>b;
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &x);
		a.push_back(x);
	}
	for (int i = 0; i < n; i++){
		scanf("%d", &x);
		b.push_back(x);
	}
	ans = 0;
	for (int i = 0; i < n; i++){
		s = 0;
		for (int j = 0; j < n; j++){
			if (j <= i)s += a[j];
			if (j >= i)s += b[j];
		}
		ans = max(ans, s);
	}

	printf("%d\n", ans);


	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

char s[500010];
int x[500010];
int d[500010];
int e[500010];

void change(int z){
	if(d[z]>=0&&z!=d[z]){
		++e[d[z]];
		d[z+1] = d[z];
		d[z] = -1;
	}
	if(e[z]>=0&&z!=e[z]){
		--d[e[z]];
		e[z-1] = e[z];
		e[z] = -1;
	}
	if(x[z] == x[z+1]){
		d[z] = d[z+1];
		--e[d[z]];
		d[z+1] = -1;
	} else if(x[z] == x[z-1]){
		e[z] = e[z-1];
		++d[e[z]];
		e[z-1] = -1;
	} else {
		d[z] = e[z] = z;
	}
}

int main(){
	scanf("%s" , s);
	int n = 0;
	for(; s[n] != 0 ; ++n){
		x[n] = s[n] - '0';
	}
	x[n] = 99;
	fill(d,d+n,-1);
	fill(e,e+n,-1);
	repp(i,0,n){
		int h = i;
		while(i < n && x[h] == x[i]) ++i;
		--i;
		d[h] = i;
		e[i] = h;
	}
	int ans = 0;
	int p = 0;
	while(p < n){
		int q = 0;
		int r = p;
		while(p < n && x[p] >= q){
			if(q != x[p]) r = p;
			p = d[p];
			q = x[p];
			++p;
		}
		++ans;
		if(p == n) break;
		if(e[p-1] != p-1){
			d[e[p-1]] = -1;
			++e[p-1];
			d[e[p-1]] = p-1;
		}
		p = r + 1;
		++x[n-1];
		if(x[n-1] <= 9) change(n-1);
		for(int i = n-1 ; x[i] > 9 ; --i){
			x[i] -= 10;
			x[i-1] += 1;
			change(i);
			if(x[i] <= 9) change(i-1);
		}
	}
	printf("%d\n" , ans);
	return 0;
}


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

using namespace std;
using ll = long long;

int main()
{
	int c = 0;
	string s;
	cin >> s;
	if (s == "RSR")
	{
		cout << 1 << endl;
		return 0;
	}
	for (int i = 0; i < 3; ++i)
	{
		if (s[i] == 'R')
			c++;
	}
	cout << c << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
#define int long long

int n, k;

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	if (n == 1 && !k)
		return cout << "0 0 1 1" << endl, 0;
	if (n == 1 && k == 1)
		return cout << -1 << endl, 0;
	
	if (k >= (1LL << n))
		return cout << -1 << endl, 0;
		
	for (int i = (1LL << n) - 1; i >= 0; i--)
		if (i != k)
			cout << i << ' ';
	cout << k << ' ';
	for (int i = 0; i < (1LL << n); i++)
		if (i != k)
			cout << i << ' ';
	cout << k << endl;
}

Measured memory_bytes: 1792
// ctrl+shift+b
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

/**
 * Library
 * --------------------------------------------------------
 */
class UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> size;
    vector<vector<int>> group;
public:
    UnionFind(int n = 1) {
        par.resize(n + 1);
        rank.resize(n + 1);
        size.resize(n + 1);
        group.resize(n + 1);
        for (int i = 0; i <= n; ++i) {
            par[i] = i;
            rank[i] = 0;
            size[i] = 1;
            group[i].push_back(i);
        }
    }

    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            int r = find(par[x]);
            return par[x] = r;
        }
    }

    bool is_same(int x, int y) {
        return find(x) == find(y);
    }

    bool unit(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        } else {
            if (rank[x] < rank[y]) {
                swap(x, y);
            }
            if (rank[x] == rank[y]) {
                ++rank[x];
            }
            par[y] = x;
            size[x] += size[y];
            return true;
        }
    }

    int get_size(int x) {
        return size[find(x)];
    }

    void merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (group[x].size() > group[y].size()) {
            swap(x, y);
        }
        copy(group[y].begin(), group[y].end(), back_inserter(group[x]));
        group[y].clear();
        par[y] = x;
    }
};
/**
 * --------------------------------------------------------
 */


void Main() {
    ll N, M; cin >> N >> M;
    UnionFind uf(N);
    rep(i, M){
        ll a, b; cin >> a >> b; a--; b--;
        uf.unit(a, b);
    }
    ll ans = -INF;
    rep(i, N){
        ll tmp = uf.get_size(i);
        if (tmp > ans){ans = tmp;}
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 16392
#include<cstdio>
#include<algorithm>
using namespace std;
 
int n,t,s;
int a[3001],b[3001];
int dp[3001][3001];
int front[3001],back[3001];
 
int main(){
  scanf("%d%d%d",&n,&t,&s);
  for(int i=0;i<n;i++)scanf("%d%d",&a[i],&b[i]);
 
  for(int i=0;i<=n;i++)
    for(int j=0;j<=s;j++)dp[i][j] = -1;
  dp[0][0] = 0;
 
  for(int i=0;i<n;i++)
    for(int j=0;j<=s;j++){
      dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
      dp[i][j+1] = max(dp[i][j+1],dp[i][j]);
      if(0<=dp[i][j] && j + b[i] <= s)
    dp[i+1][j+b[i]] = max(dp[i+1][j+b[i]],dp[i][j] + a[i]);
    }
 
  for(int i=0;i<=n;i++)front[i] = dp[i][s];
   
  for(int i=0;i<=n;i++)
    for(int j=0;j<=t-s;j++)dp[i][j] = -1;
  dp[n][0] = 0;
   
  for(int i=n;i>0;i--)
    for(int j=0;j<=t-s;j++){
      dp[i-1][j] = max(dp[i-1][j],dp[i][j]);
      dp[i][j+1] = max(dp[i][j+1],dp[i][j]);
      if(0<=dp[i][j] && j + b[i] <= t-s)
    dp[i-1][j+b[i]] = max(dp[i-1][j+b[i]],dp[i][j] + a[i]);
    }
  
  for(int i=0;i<=n;i++)back[i] = dp[i][t-s];
  
  int ans = 0;
  for(int i=0;i<n;i++)ans = max(ans,front[i]+back[i]);
  printf("%d\n",ans);
}

Measured memory_bytes: 35000
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int m , n ,a,b,c,ans;
    cin>>m>>n;
    a=m+n;
    b=m-n;
    c=m*n;
    ans= max(a,b);
    ans = max(ans,c);
    cout<<ans<<endl;
    return 0;

}


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

using namespace std;

int main() {
	int x, y;
	cin >> x >> y;

	for (int i = 0; i <= x; i++) {
		int p = i * 2;
		int q = (x - i) * 4;

		if (p + q == y) { cout << "Yes"; return 0; }
	}
	
	cout << "No";
}


Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main(){
    string N;int K;
    cin>>N>>K;
    int dp[N.size()+1][2][K+1];
    for(int i=0;i<=N.size();i++)for(int j=0;j<=1;j++)for(int k=0;k<=K;k++)dp[i][j][k]=0;
    dp[0][0][0]=1;
    for(int i=1;i<=N.size();i++){
        for(int j=0;j<=1;j++){
            for(int k=0;k<=K;k++){
                for(int d=0;d<=(j?9:N[i-1]-'0');d++){
                    if(k==K&&d!=0)continue;
                    dp[i][j||d<N[i-1]-'0'][k+(!!d)]+=dp[i-1][j][k];
                }
            }
        }
    }
    cout<<dp[N.size()][0][K]+dp[N.size()][1][K]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////


int main() {
	ll N, X, Y, Z;
	cin >> N >> X >> Y >> Z;

	ll K = X + Y + Z;

	vector<vector<mint>> dp(N + 1, vector<mint>(1 << K,0));

	dp[0][0] = 1;

	repn(i, N) {
		rep(j, 1 << K) {
			repn(k, 10) {
				ll x = j << k;
				x += 1 << (k - 1);
				x &= (1 << K) - 1;

				dp[i][x] += dp[i - 1][j];
			}
		}

		rep(j, 1 << K) {
			if((j>>(X-1))&1&&(j>>(X+Y-1))&1&&(j>>(K-1))&1){dp[i][j]=0; }
		}
	}

	mint ans = 1;

	rep(j, N) ans *= 10;

	rep(j, 1 << K) ans -= dp[N][j];

	cout << ans << endl;

	system("PAUSE");

}

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

const ll mod = 998244353;

ll dp[3030][3030][3];
int a[3030];

int main(){
    int n, k;
    cin >> n >> k;
    rep(i,n) cin >> a[i];
    dp[0][0][0] = 1;
    rep(i,n){
        rep(j,k+1){
            (dp[i+1][j][0] += dp[i][j][0]) %= mod;
            (dp[i+1][j][1] += dp[i][j][0] + dp[i][j][1]) %= mod;
            (dp[i+1][j][2] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2]) %= mod;
            if(j + a[i] <= k){
                (dp[i+1][j+a[i]][1] += dp[i][j][0] + dp[i][j][1]) %= mod;
                (dp[i+1][j+a[i]][2] += dp[i][j][0] + dp[i][j][1]) %= mod;
            }
        }
    }
    cout << dp[n][k][2] << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef std::vector<int> vi;
typedef std::vector<long long> vll;

#define pub push_back
#define pob pop_back
#define mp make_pair
#define ff first
#define ss second
#define umap unordered_map
#define uset unordered_set

#define forn(i, n)     for(ll i = 0; i< (ll)n; i++)
#define forf(i, x, y)  for(ll i=(x); i<=(ll)y; i++)
#define forb(i, x, y)  for(ll i=(x); i>=(ll)y; i--)
#define lpt() 		   ll T; std::cin>>T; while(T--)

#define nl "\n"
#define newl std::cout<<"\n";
#define bug(x) std::cerr<<"debug "<<#x<<" : "<<x<<"\n";
#define all(x) x.begin(),x.end()
#define fastio() ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);

template<typename X> std::ostream& operator<< (std::ostream& out, std::vector<X> v)
{ for(auto &i : v) out<<i<<" "; return out; }
template<typename X, typename Y> std::ostream& operator<< (std::ostream& out, std::pair<X,Y> p)
{ out<<p.first<<" "<<p.second; return out; }

static const long long mod = 1000000007;

using namespace std;

ll n,weight;
ll w[100],v[100];
ll dp[101][100000];

ll knap(ll i,ll j)
{
	if(i==n)
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	if(w[i]>j)
		return dp[i][j] = knap(i+1,j);
	return dp[i][j]= max(v[i]+knap(i+1,j-w[i]),knap(i+1,j));
}

int main()
{fastio();
	
	cin>>n>>weight;
	forn(i,n)
		cin>>w[i]>>v[i];

	memset(dp,-1,sizeof dp);
	cout<<knap(0,weight)<<nl;

return 0;}


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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}
 
void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

const int maxn = 2e3+10;
const int maxm = maxn*maxn;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int add(int x,int y) {return x+y>mod?x+y-mod:x+y;}
int del(int x,int y) {return x-y<0?x-y+mod:x-y;}
int mul(int x,int y) {return 1ll*x*y-1ll*x*y/mod*mod;}

int n,k,f[maxn][maxn],fac[maxm],ifac[maxm],inv[maxm];

void prepare() {
    inv[0]=inv[1]=fac[0]=ifac[0]=f[0][0]=1;
    for(int i=2;i<maxm;i++) inv[i]=mul(mod-mod/i,inv[mod%i]);
    for(int i=1;i<maxm;i++) fac[i]=mul(fac[i-1],i);
    for(int i=1;i<maxm;i++) ifac[i]=mul(ifac[i-1],inv[i]);
}

int c(int nn,int mm) {return mul(fac[nn],mul(ifac[mm],ifac[nn-mm]));}

int main() {
    read(n),read(k);prepare();if(k==1) puts("1"),exit(0);
    for(int i=1;i<=n;i++)
        for(int j=0;j<=i;j++)
            f[i][j]=add(f[i-1][j],mul(f[i][j-1],mul(n-j+1,c(n*k-i-(k-1)*(j-1)-1,k-2))));
    write(f[n][n]);
    return 0;
}


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int mod = 1e9 + 7;

int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}

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

  int n, m; cin >> n >> m;
  if(n == m)
    cout << "Yes";
  else
    cout << "No";
}


Measured memory_bytes: 256
// Problem : A - ∴ (Therefore)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int k = n%10;
 	if(k == 1 || k == 0 || k == 6 || k == 8)
 	{
 		cout<<"pon";
 	}
 	else if(k == 3)
 	{
 		cout<<"bon";
 	}
 	else
 	{
 		cout<<"hon";
 	}
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
//MOD??
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
int main (){
  long long int i;
  long long int n,a;
  cin>>n;
  vector<long long int>x(n);
  for(i=0;i<n-1;i++){
    cin>>a;
    x[a-1]++;
  }
  for(i=0;i<n;i++){
    cout<<x[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 4780
#include<iostream>
#include<algorithm>
using namespace std;

int main() {
	int h, m, s;
	scanf("%d", &s);
	if (s == 0) {
		h = 0;
		m = 0;
		s = 0;
	}
	else {
		m = s / 60;
		h = m / 60;
		m = m % 60;
		s = s % 60;
		
	}

	printf("%d", h);
	printf(":");
	printf("%d", m);
	printf(":");
	printf("%d", s);
	cout << endl;

	return 0;
}

Measured memory_bytes: 3252
N, K = map(int,input().split())
li = []

for i in range(N):
        li.append(int(input()))

li.sort()

co = K - 1
hmin = li[co] - li[0]
for i in range(N-K+1):
        if hmin > li[i+co] - li[i]:
                hmin = li[i+co] - li[i]
                if hmin == 0:
                        break
print(hmin)

Measured memory_bytes: 7484
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

const int MAX_N = 200001;
vector<int> prime;
void setPrime(int n) {
    vector<bool> alive(n, true);
    alive[0] = alive[1] = false;
    rep2(i, 2, n + 1) {
        if (alive[i]) {
            prime.emplace_back(i);
            for (int j = 2 * i; j <= n; j += i) {
                alive[j] = false;
            }
        }
    }
}

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

    setPrime(MAX_N);

    int m, a, b;
    while (cin >> m >> a >> b, m) {
        int mx_pro = -1;
        int opt_p = -1;
        int opt_q = -1;
        rep(i, prime.size()) {
            int p = prime[i];
            rep2(j, i, prime.size()) {
                int q = prime[j];
                if (p * q > m) break;
                if (a * q <= p * b) {
                    if (mx_pro < p * q) {
                        mx_pro = p * q;
                        opt_p = p;
                        opt_q = q;
                    }
                }
            }
        }
        cout << opt_p << " " << opt_q << endl;
    }
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  double a,b,x;
  cin >> a >> b >> x;

  double areaA = x/a;
  cout << std::setprecision(11);
  // cout << areaA << endl;

  if(x==a*a*b){
    cout << 0 << endl;
  }
  else if(a*b/2>=areaA){
    double downbar = areaA*2/b;
    // cout << downbar << endl;
    double hypo = sqrt(b*b + downbar*downbar);
    // cout << hypo << endl;
    double sinsita = (areaA*2)/(hypo*downbar);
    // cout << sinsita << endl;
    double sita = asin(sinsita);
    // cout << sita << endl;
    cout << sita * 180.0 / M_PI << endl;
  }
  else{
    areaA = a*b-areaA;
    double downbar = areaA*2/a;
    // cout << downbar << endl;
    double hypo = sqrt(a*a + downbar*downbar);
    // cout << hypo << endl;
    double sinsita = (areaA*2)/(hypo*downbar);
    // cout << sinsita << endl;
    double sita = asin(sinsita);
    // cout << sita << endl;
    cout << 90 - (sita * 180.0 / M_PI) << endl;
  }

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int N;
    cin >> N;
    vector<string> s;
    vector<int> t;
    string X;
    int sum = 0;
    for(int i = 0; i < N; i++){
        string S;
        int T;
        cin >> S >> T;
        s.push_back(S);
        t.push_back(T);
        sum += T;
    }
    cin >> X;
    
    for(int i = 0; i < N; i++){
        sum -= t[i];
        if(s[i] == X){
            break;
        }
    }
    
    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N,M,X) = readLine()!!.split(" ").map { it.toInt() }
    val As = readLine()!!.split(" ").map { it.toInt() }

    val a0 = As.filter { it < X }.size
    val aN = As.filter { it > X }.size

    println(listOf(a0,aN).min())
}

Measured memory_bytes: 37804