akhauriyash/Code-Regression huggingface dataset:
//
// Created by ?????°?????? on 2016/04/14.
//

#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdio>
using namespace std;

struct Node{
    int key;
    Node *right,*left,*parent;
};

Node *root ,*NIL;

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

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

    z = new 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);
    cout << " " << u -> key;
    inorder(u->right);
}

void preorder (Node *u){
    if(u == NIL) return;
    cout << " " <<u->key;
    preorder(u->left);
    preorder(u->right);
}

Node * find(Node *u,int k){
    while (u != NIL && k != u->key){
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

Node * treeSuccessor(Node *x){
    if( x -> right != NIL) return treeMinimum(x -> right);
    Node *y = x->parent;
    while (y != NIL and x == y->right){
        x = y;
        y = y->parent;
    }
    return y;
}

void treeDelete(Node *z){
    Node *y; //????????????????±?
    Node *x; //y??????
    // ?????????????????????????????????
    if(z->left == NIL or z->right == NIL) y = z;
    else y = treeSuccessor(z);
    // y??????x????????????
    if(y -> left != NIL){
        x = y->left;
    }else{
        x = y->right;
    }

    if(x != NIL){
        x->parent = y ->parent;
    }

    if(y -> parent == NIL){
        root = x;
    }else{
        if(y == y->parent->left){
            y ->parent->left =x;
        }else{
            y->parent->right = x;
        }
    }

    if(y != z){
        z->key = y->key;
    }
    
    free(y);

}

int main(){
    int n,x;
    string com;
    cin >> n;

    for (int i = 0; i < n ; ++i) {
        cin >> com;
        if(com == "insert"){
            cin >> x;
            insert(x);
        }else if(com == "print"){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }else if(com == "find"){
            cin >> x;
            Node *t = find(root,x);
            if (t != NIL) cout << "yes" << endl;
            else cout << "no" << endl;
        }else if (com == "delete"){
            cin >> x;
            treeDelete(find(root,x));
        }
    }
    return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

int N, K;
const int MAX_N = 200005;
int P[MAX_N];
bool sortFlag[MAX_N];

signed main()
{
  cin >> N >> K;
  REP(n,N) {
    cin >> P[n];
  }

  int cnt = 0;
  FOR(n,1,K) {
    if(P[n] > P[n-1]) {
      cnt++;
    } else {
      cnt--;
    }
  }

  bool SF = false;
  FOR(n,K,N) {
    if(cnt == K-1) {
      // cerr << "sort: " << n-K << "," << n << endl;
      sortFlag[n-K] = true;
      SF = true;
    }
    if(P[n] > P[n-1]) {
      cnt++;
    } else {
      cnt--;
    }
    if(P[n-K] > P[n-K+1]) {
      cnt++;
    } else {
      cnt--;
    }
  }
  if(cnt == K-1) {
    sortFlag[N-K] = true;
    SF = true;
    // cerr << "sort: " << N-K << "," << N << endl;
  }

  set<int> S;
  
  int ans = 0;
  bool sf = true;
  
  REP(n,K) {
    S.insert(P[n]);
    if(n>=1 && P[n] < P[n-1]) {
      sf = false;
    }
  }

  if(!sf) {
    ans++;
  } 

  FOR(n,K,N) {
    int pre = P[n-K];
    auto it = S.find(pre);

    bool flag = false;
    if(it != S.begin()) {
      flag = true;
    }
    S.erase(it);

    S.insert(P[n]);
    it = S.find(P[n]);
    it++;
    if(it != S.end()) {
      flag = true;
    }

    if(flag && !sortFlag[n-K+1]) {
      // cerr << n-K+1 << ", " << n+1 << endl;
      ans++;
    }
  }

  if(SF) {
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11136
"use strict";
function main(input) {
    const line = input.split("\n");
    let arr = line[0].split(" ");
    const K = parseInt(arr[0]);
    const X = parseInt(arr[1]);
    let sp = "";
    for (let i = X - K + 1; i < X + K; i++) {
        process.stdout.write(sp);
        process.stdout.write(String(i));
        sp = " ";
    }
    console.log();
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 30544
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string T,ans="";
  cin >> T;
  long long len = T.length();
  for(long long i = 0; i < len; i++){
    string s="";
    if(T.substr(i,1) == "P" || T.substr(i,1) == "D") s = T.substr(i,1);
  	else s = "D";
    cout << s;
  }
  cout << endl;
}

Measured memory_bytes: 3756
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
long long binpow(long long a, long long b, long long m=(ll)1e15) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
signed main()
{
    fasino
    ll n;
    cin>>n;
    vector<char> ch(26);
    for(int i=0;i<26;i++){
        ch[i]='a'+i;
    }
    string res = "";
    while(n){
        int m = n%26;
        if(n%26==0)m = 26;
        // cout<<m<<' ';
        res=ch[m-1]+res;
        n-=m;
        n/=26;
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<29;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,k; cin >> n >> k;
    map<int,int> A{};
    rep(i,n){
        int a; cin >> a;
        A[a]++;
    }
    
    vector<pair<int,int>> Ap{};
    
    int diverse = (int)A.size();
    
    for(auto it = A.begin(); it != A.end(); it++) Ap.push_back(make_pair(it->second,it->first));
    
    sort(Ap.begin(),Ap.end());
    
    int Ans = 0;
    for(int i = 0; i < max(0,diverse-k); i++) Ans += Ap[i].first;
    
    cout << Ans << endl;
}



Measured memory_bytes: 11764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,g[2],s[2],b[2];
    cin>>n;
    ifr(i,2) cin>>g[i]>>s[i]>>b[i];
    vector<vector<ll>> dp1(5,vector<ll>(n+1));
    for(ll j=0;j<=n;++j){
        if(j<g[1]) dp1[1][j]=dp1[0][j];
        else dp1[1][j]=max(dp1[0][j],dp1[1][j-g[1]]+g[0]);
    }
    for(ll j=0;j<=n;++j){
        if(j<s[1]) dp1[2][j]=dp1[1][j];
        else dp1[2][j]=max(dp1[1][j],dp1[2][j-s[1]]+s[0]);
    }
    for(ll j=0;j<=n;++j){
        if(j<b[1]) dp1[3][j]=dp1[2][j];
        else dp1[3][j]=max(dp1[2][j],dp1[3][j-b[1]]+b[0]);
    }
    for(ll j=0;j<=n;++j){
        if(j==0) dp1[4][j]=dp1[3][j];
        else dp1[4][j]=max(dp1[3][j],dp1[4][j-1]+1);
    }
    n=dp1[4][n];
    swap(g[0],g[1]);
    swap(s[0],s[1]);
    swap(b[0],b[1]);
    vector<ll> dp(n+1),ndp(n+1);
    if(g[0]<=g[1]);
    else {
        for (ll j = 0; j <= n; ++j) {
            if (j < g[1]) ndp[j] = dp[j];
            else ndp[j] = max(dp[j], ndp[j - g[1]] + g[0]);
        }
        dp.swap(ndp);
    }
    if(s[0]<=s[1]);
    else {
        for (ll j = 0; j <= n; ++j) {
            if (j < s[1]) ndp[j] = dp[j];
            else ndp[j] = max(dp[j], ndp[j - s[1]] + s[0]);
        }
        dp.swap(ndp);
    }
    if(b[0]<=b[1]);
    else {
        for (ll j = 0; j <= n; ++j) {
            if (j < b[1]) ndp[j] = dp[j];
            else ndp[j] = max(dp[j], ndp[j - b[1]] + b[0]);
        }
        dp.swap(ndp);
    }
    for(ll j=0;j<=n;++j){
        if(j==0) ndp[j]=dp[j];
        else ndp[j]=max(dp[j],ndp[j-1]+1);
    }
    dp.swap(ndp);
    cout<<max(n,dp[n])<<endl;
}

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

constexpr int MAX_N = 1e5;

int H[MAX_N];

int main() {
  int N; cin >> N;
  for (int i{}; i < N; ++i) {
    cin >> H[i];
  }

  bool ans{true};
  --H[0];
  for (int i{1};i < N; ++i) {
    if (H[i-1] > H[i]) {
      ans = false;
      break;
    }
    if (H[i-1] < H[i])
      --H[i];
  }

  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 640
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

const int mod = 1e9+7;
enum{N=5003};

struct Edge{ int nxt,to; } bow[N*2];
int head[N],tot_e;
il void add(int x,int y){
	tot_e++;
	bow[tot_e<<1]=(Edge){head[x],y};
	bow[tot_e<<1|1]=(Edge){head[y],x};
	head[y]=(head[x]=tot_e<<1)|1;
}

bool vis[N],flag;
int cnt;
il void dfs(int u,int ue){
	vis[u] = 1;
	cnt++;
	each(i,u) if( i^ue^1 ){
		int v = bow[i].to;
		if( vis[v] ){ flag = 1; continue; }
		dfs(v,i);
	}
}

int q[N];
ll f[N];
ll qpow[N];

int main(){
	int n = ci();
	qpow[0] = 1;
	int tot_q = 0;
	rep(i,1,n){
		if( (q[i]=ci())==-1 ) qpow[tot_q+1] = qpow[tot_q]*(n-1)%mod, tot_q++;
		else add(i,q[i]);
	}
	static int a[N]; int tot=0;
	ll ans = 0;
	rep(i,1,n) if( vis[i]==0 ){
		cnt = flag = 0;
		dfs(i,0);
		if( flag ) ans = (ans+qpow[tot_q])%mod;
		else a[++tot] = cnt;
	}
	rep(i,1,tot) ans = (ans+(a[i]-1)*(qpow[tot_q-1]))%mod;
	f[0] = 1;
	rep(i,1,tot){
		rev_rep(j,i,1){
			f[j] = (f[j]+a[i]*f[j-1])%mod;
		}
	}
	ll fac = 1;
	rep(i,2,tot) ans = (ans+f[i]*fac%mod*qpow[tot_q-i])%mod, fac = fac*i%mod;
	ans = (qpow[tot_q]*n-ans)%mod;
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}


Measured memory_bytes: 1752
#include <iostream>

using namespace std;

int main() {
    int H;
    int W;
    cin >> H;
    cin >> W;
    char field [55][55];
    int count=0;
    
    for (int i =0; i< H; i++){
        for (int j=0; j<W; j ++){
            cin >> field[i][j];
        }
    }
    
    for (int i =0; i< H; i++){
        for (int j=0; j<W; j ++){
            if(field[i][j] == '#' && field[i+1][j] != '#' && field[i-1][j] !='#' && field[i][j+1] !='#' && field[i][j-1] !='#'){
                count++;
            }
        }
    }
    
    if (count == 0) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
f [] = []
f [x] = [x]
f [x,y] = if x==y then [x] else [x,y]
f (x:y:xs) = if x==y then f (y:xs) else [x]++f (y:xs) 
main = do
 getLine
 s<-getLine
 print$length(f s)

Measured memory_bytes: 4988
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int h,w,k;
    cin>>h>>w>>k;
    string grid[h];
    for(int i=0;i<h;i++) cin>>grid[i];
    int res=0;
    for(int mask=0;mask<(1<<(h+w));mask++) {
        int cnt=0;
        for(int col=0;col<w;col++) {
            for(int row=0;row<h;row++) {
                if(grid[row][col]!='#') continue;
                if((mask&((1<<col)|(1<<(w+row))))!=0) continue;
                cnt++;
            }
        }
        if(cnt==k) res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3620
class BinarySearchTree:
    class __Node:
        def __init__(self, key=-1, parent=-1, left=-1, right=-1):
            self.key = key
            self.parent = parent
            self.left = left
            self.right = right

    def __init__(self):
        self.root = -1

    def insert(self, z):
        node = BinarySearchTree.__Node(key=z)
        x, y = self.root, -1
        while x != -1:
            y = x
            if z < x.key:
                x = x.left
            else:
                x = x.right

        node.parent = y

        if y == -1:
            self.root = node
        elif z < y.key:
            y.left = node
        else:
            y.right = node

    def find(self, k):
        x = self.root
        while x != -1 and k != x.key:
            if k < x.key:
                x = x.left
            else:
                x = x.right

        return x

    def print_tree(self):
        def in_order(z):
            if z == -1:
                return

            in_order(z.left)
            print(" {}".format(z.key), end="")
            in_order(z.right)

        def pre_order(z):
            if z == -1:
                return

            print(" {}".format(z.key), end="")
            pre_order(z.left)
            pre_order(z.right)

        in_order(self.root)
        print()
        pre_order(self.root)
        print()


def main():
    n = int(input())
    bst = BinarySearchTree()

    for i in range(n):
        order = input().split()
        if order[0][0] == "i":
            bst.insert(int(order[1]))
        elif order[0][0] == "f":
            if bst.find(int(order[1])) == -1:
                print("no")
            else:
                print("yes")
        else:
            bst.print_tree()


if __name__ == '__main__':
    main()



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

int main(){
    vector<int> vec(101);
    int i,j;
    int t;
   // int min;
    int N;
    cin >> N;
    for(i=0;i<N;i++){
        cin >> vec.at(i);
    }
 //   min=vec.at(0);
    for(i=0;i<N-1;i++){
        for(j=N-1;j>i;j--){
            if(vec.at(j-1)>vec.at(j)){
              t=vec.at(j-1);
              vec.at(j-1)=vec.at(j);
              vec.at(j)=t;  
              //min=vec.at(j+1);
            }
        }
    }
  /*  for(i=0;i<N;i++){
    cout << vec.at(i) <<" ";
    }
    cout << endl;*/
   int count=0;
   for(i=0;i<N;i++){
       if(vec.at(i)==vec.at(i+1)){
           count++;
       }
   }
   //cout << count <<endl;
   cout << N-count << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
hs = list(map(int, input().split()))
cs = [0]
for i in range(1, N):
  ccs = []
  for j in range(1, min(i, K)+1):
    c = cs[i-j]+abs(hs[i]-hs[i-j])
    ccs.append(c)
  c = min(ccs)
  cs.append(c)
r = cs[-1]
print(r)


Measured memory_bytes: 58336
N = int(input())
X = input()
MOD = 998244353

ans = 0
memo = dict()

# def get_divisor(n):
#     '''nの約数を返す
#     '''
#     d = set()
#     for i in range(1, int(n**0.5)+1):
#         if n % i == 0:
#             d.add(i)
#             d.add(n//i)
#     return d

def get_oddivisor(n):
    '''nの約数のうち商が奇数のものを返す
    '''
    d = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            if i%2 == 1:
                d.add(n//i)
            if (n//i)%2 == 1:
                d.add(i)
    return d

D = list(get_oddivisor(N))
D.sort()

def alternate(x, n):
    '''x: 00101, y: 11010, z: (00101)(11010)... n times
    '''
    y = ('0'*len(x) + bin(int(x,2) ^ (2**len(x)-1))[2:])[-len(x):]
    z = (x + y) * (n//2)
    if n%2 == 1:
        z += x
    return z

for d in D:
    cnt = int(X[:d], 2)
    if int(X, 2) >= int(alternate(X[:d], N//d), 2):
        cnt += 1
    dd = list(get_oddivisor(d))
    for ddd in dd:
        if ddd != d:
            cnt -= memo[ddd]
    memo[d] = cnt
    ans += cnt * 2 * d
    ans %= 998244353

print(ans)


Measured memory_bytes: 4288
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

bool check(int X, int N, int M, const vector<vector<int>>& v){
  vector<bool> kyogi(M, true);

  rep(i,M){
    map<int,int> m;
    rep(j,N){
      rep(k,M){
        if(kyogi[v[j][k]-1]){
          m[v[j][k]]++;
          break;
        }
      }
    }
    int mx = -1;
    int mx_i = -1;
    FOR(it,m){
      if(it->second > mx){
        mx = it->second;
        mx_i = it->first;
      }
    }

    if(mx <= X) return true;
    kyogi[mx_i-1] = false;
  }
  return false;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> v;
  rep(i,N){
    vector<int> t;
    rep(j,M){
      int a;
      cin >> a;
      t.push_back(a);
    }
    v.push_back(t);
  }

  int lb=0, ub=N+1;
  while(ub-lb>1){
    int mid = (ub+lb)/2;

    if(check(mid, N, M, v)) ub = mid;
    else lb = mid;
  }

  cout << ub << endl;
  
  return 0;
}



Measured memory_bytes: 640
import java.util.*;

class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		
		System.out.println(Math.min(a, b)+" "+Math.max(a+b-n, 0));
	}
}


Measured memory_bytes: 22228
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define MOD 1000000007LL
#define calc_fact(n) tgamma(n+1)


signed main()
{
    FIO;
    string s;
    cin>>s;
    map<char,ll> mp;
    for(ll i=0;i<s.length();i++)mp[s[i]]++;
    for(auto it:mp)
    {
        if(it.S%2!=0)
        {
            cout<<"No";
            goto h;
        }
    }
    cout<<"Yes";
    h:;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;

typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    string s, t; cin >> s >> t;
    int ans = 0;
    for(int i=0; i<s.size(); i++) ans += s[i] != t[i];
    cout << ans;
}

Measured memory_bytes: 3796
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

string S;
ll a[500001] = {}, box = 1, ans = 0;

int main() {
	cin >> S;
	a[0] = 0;
	rep(i, sz(S) - 1) {
		if (i > 0 && S[i - 1] == '<') {
			a[i] = box;
			box++;
		}
		if (S[i] == '>' && S[i + 1] == '<') {
			for (int j = i; j >= 0 && S[j] == '>'; j--)a[j] = max(a[j], (ll)i - j + 1);
			box = 1;
			a[i + 1] = 0;
		}
	}
	if (S[sz(S) - 1] == '>') {
		for (int i = sz(S); i == sz(S) || (i >= 0 && S[i] == '>'); i--)a[i] = max(a[i], (ll)sz(S) - i);
	}
	else if (S[sz(S) - 2] == '<') {
		a[sz(S) - 1] = box;
		if (S[sz(S) - 1] == '<') {
			a[sz(S)] = box + 1;
		}
		else {
			a[sz(S)] = 0;
		}
	} 
	else {
		a[sz(S)] = box;
	}
	rep(i, sz(S) + 1)ans += a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4740
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var abhm = lines[0].split(' ');
 var a = Number(abhm[0]);
 var b = Number(abhm[1]);
 var h = Number(abhm[2]);
 var m = Number(abhm[3]);

 var hkaku = h * 30 + m * 0.5;
 var mkaku = m * 6;
 var kaku = Math.abs(hkaku-mkaku);
 var kaku2 = 360 - Math.abs(hkaku-mkaku);
 kaku = Math.min(kaku2,kaku);
 kaku = Math.cos(kaku*(Math.PI/180));

 var ans = (a*a) + (b*b) - (2*a*b*kaku);
 console.log(Math.sqrt(ans));
});


Measured memory_bytes: 30480
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cassert>
  
using namespace std;
  
string str[2];
int s, n, t, m, lt, rt, t_w, t_t;
long double p;
  
int conv(string s){
  string data[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};  
  for(int i=0;i<7;i++) if(s == data[i]) return i;
  if(s == "All") return -1;
  assert(false);
}
  
bool check(int s_w, int s_t, int f_w, int f_t){
  if(!(t_w == -1 || (t_w == s_w && t_w == f_w))) return false;
    if(t_t == 0){
      if(0 <= s_t && s_t < 24 * 60 && 0 <= f_t && f_t < 24 * 60) return true;
    }else
    if(t_t == 1){
      if(6 * 60 <= s_t && s_t < 18 * 60 && 6 * 60 <= f_t && f_t < 18 * 60) return true;
    }else
    if(t_t == 2){
      if(((18 * 60 <= s_t && s_t < 24 * 60) || (0 <= s_t && s_t < 6 * 60))
         && ((18 * 60 <= f_t && f_t < 24 * 60) || (0 <= f_t && f_t < 6 * 60))) return true;
    }else assert(false);
    return false;
}
  
main(){
  while(cin >> s >> n >> t >> str[0] >> str[1] >> p >> m && (s|n|t|m) && str[0] != "None" && str[1] != "None"){
    t_w = conv(str[0]);
    if(str[1] == "All") t_t = 0;
    if(str[1] == "Day") t_t = 1;
    if(str[1] == "Night") t_t = 2;
    //int ans = 0;
    //for(int i=0;i<7;i++) for(int j=0;j<24*60;j++) ans = max(ans, calc(i, j, t_w, t_t));
    long double ans = 0.0;
    for(int i=0;i<7;i++){
      for(int j=0;j<24*60;j++){
        int s_w = i;
        int s_t = j;
        long double cnt = 0.0;
        for(int k=0;k<m;k++){
          int f_w = s_w;
          int f_t = s_t + s;
          if(f_t >= 24 * 60){
            f_t -= 24 * 60;
            f_w = (f_w + 1) % 7;
          }
          if(check(s_w, s_t, f_w, f_t)) cnt++;
          s_t += t;
          if(s_t >= 24 * 60){
            s_t -= 24 * 60;
            s_w = (s_w + 1) % 7;
          }
        }
        ans = max(ans, 1.0 - pow((p - 1.0) / p, n * cnt));
      }
    }
        //cout << setiosflags(ios::fixed) << setprecision(10) << (1.0 - my_pow(1.0 - 1.0 / (double)p, n * ans)) << endl;
    //printf("%.10f\n", (1.0 - pow(1.0 - 1.0 / p, n * ans)));
    cout << setiosflags(ios::fixed) << setprecision(10) << ans << endl;
  }
}

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

using namespace std;
#define ll long long
vector<vector<ll> > g(100001);
ll black[100001], white[100001], n, x, y;
const ll mod = (ll) (1e9 + 7);

void dfs(ll v) {
    black[v] = white[v] = 1;
    for (int i = 0; i < g[v].size(); i++) {
        if (black[g[v][i]] != 0)continue;
        dfs(g[v][i]);
        black[v] *= white[g[v][i]];
        black[v] %= mod;
        white[v] *= white[g[v][i]] + black[g[v][i]];
        white[v] %= mod;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    n--;
    while (n--) {
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1);
    cout << (black[1] + white[1]) % mod;
}

Measured memory_bytes: 11520
/********************************************//**
 ****** Author: Shivam Kejriwal *****************
 ****** Handle: techno_phyle    *****************
 ***********************************************/

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long ll;

#define mod 1000000007
#define N 100010
#define M 100010
#define db(a) cout << a << endl
#define db2(a,b) cout << a << " " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) for(auto it:a) cout << it << " "; cout << endl
#define adbp(a) for(auto it:a) cout << it.first << " " << it.second << endl
#define pb push_back
//greater<pair<int,int> , greater<int>>
const ll INF = 1e18L + 5;
//int dp[N][3];
int main(){
	fastIO;
    //#ifndef ONLINE_JUDGE
    //    freopen("../input.txt", "r", stdin);
    //    freopen("../output.txt","w",stdout);
    //#endif	
    string s1,s2;
    cin >> s1 >> s2;
    int n = s1.length();
    int m = s2.length();
    int dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    for(int i=n-1;i>=0;i--){
        for(int j=m-1;j>=0;j--){
            if(s1[i]==s2[j])
                dp[i][j] = 1 + dp[i+1][j+1];
            else
                dp[i][j] = max(dp[i+1][j],dp[i][j+1]);               
        }
    }
    for(int i=0,j=0;i<n&&j<m;){
            if(s1[i]==s2[j]){
                cout << s1[i];
                i++;
                j++;
            }
            else{
                if(dp[i+1][j]>=dp[i][j+1])
                    i++;
                else
                    j++;
            }
    }
    cout << endl;
	return 0;

}

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

int main(){
    int n,k;
    int r,s,p;
    string t;
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;
    int points=0;
    for(int i=0; i<k; i++){
        char status='b';
        for(int j=i; j<n; j+=k){
            if(t.at(j)==status){
                status='b';
                continue;
            }
            else{
                if(t.at(j)=='r'){
                    points += p;
                    status = 'r';
                }
                if(t.at(j)=='s'){
                    points += r;
                    status = 's';
                }
                if(t.at(j)=='p'){
                    points += s;
                    status = 'p';
                }
            }
        }
    }
    cout << points << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
using namespace std;

int main(){
  int n, key;
  char com[10];
  list<int> v;

  cin >> n;
  for (int i=0; i<n; i++){
    cin >> com;
    if (com[0] == 'i'){
      cin >> key;
      v.push_front(key);
    } else if (com[6] == 'L') {
      v.pop_back();
    } else if (com[6] == 'F') {
      v.pop_front();
    } else if (com[0] == 'd') {
      cin >> key;
      for (list<int>::iterator it=v.begin(); it != v.end(); it++){
        if (*it == key) {
          v.erase(it);
          break;
        }
      }
    }
  }
  int i = 0;
  for (list<int>::iterator it=v.begin(); it != v.end(); it++){
    if (i++ > 0) cout << " ";
    cout << *it;
  }
  cout << endl;

  return 0;
}



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

using namespace std;

int main (){
	int a, b, c;

	cin >> a >> b;

	string s;

	cin >> s;

	for(int i = 0 ; i < s.length(); i++){
		if(i == a){
			if(s[i] != '-'){
				cout << "No\n";
				return 0;
			}
		}else{
			if(s[i] < '0' || s[i] > '9'){
				cout << "No\n";
				return 0;	
			}
		}	
	}

	cout << "Yes\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    if(n<3) {cout<<"0";return 0;}
    int cnt=0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            if(a[i]!=a[j]){
                for(int k=j+1;k<n;k++){
                    if(a[k]!=a[j] && a[k]!=a[i]){
                        set<int>s;
                        s.insert(a[i]);
                        s.insert(a[j]);
                        s.insert(a[k]);
                        set<int> ::iterator k;
                        k=s.begin();
                        if(*k++ + *k++ > *k){
                            cnt++;
                        }
                    }
                }
            }
        }
    }
    cout<<cnt;
    return 0;
}

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

int main(void){
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    
    sort(h.begin(), h.end(), greater<ll>());
    
    ll ans = 0;
    for (int i = k; i < n; i++)
        ans += h[i];
        
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 5e5+7;
int n;
int a[N],h[N],pos[N];
bool cmp(int i,int j) {
    return a[i] < a[j];
}
void nhap()
{
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a + 1,a + 1 + n);
}
void solve()
{
    int X = (a[n] + 1) >> 1;
    int res = 2e9 + 100;
    int gt = -1;
    for (int i = 1; i < n; i++) {
        if (abs(X - a[i]) < res) {
            res = abs(X - a[i]);
            gt = a[i];
        }
    }
    cout << a[n] << " " << gt;
}
int main()
{
    nhap();
    solve();
}


Measured memory_bytes: 2560
v = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(v[k-1])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    ll m;
    cin >> m;
    ll d[m];
    ll c[m];
    ll ans = 0;
    rep(i, m) cin >> d[i] >> c[i];
    ll digitsum = 0;
    ll length = 0;
    rep(i, m)
    {
        digitsum += d[i] * c[i];
        length += c[i];
    }
    cout << (digitsum - 1) / 9 + length - 1 << endl;
    return 0;
}


Measured memory_bytes: 3328
import numpy as np 

def make_bit(A):
    arr = np.zeros(31)
    i = 30
    while A:
        arr[i] = A % 2
        A = A // 2
        i -= 1

    return arr

def return_first_second_third(a_lst):
    first = [a_lst[0], 0]
    second = [-1, -1]
    third = [-1, -1]
    i = 0
    while i < len(a_lst) - 1:
        if a_lst[i] != a_lst[i+1]:
            second[0] = a_lst[i+1]
            second[1] = i+1
            i += 1
            break
        else:
            i += 1
    while i < len(a_lst) - 1:
        if a_lst[i] != a_lst[i+1]:
            third[0] = a_lst[i+1]
            third[1] = i+1
            i += 1
            break
        else:
            i += 1
    
    return first, second, third


N = int(input())

a_lst = list(map(int, input().split()))
a_lst.sort()
first, second, third = return_first_second_third(a_lst)

done = False
if second[0] == -1: # 全ての数が同じとき
    done = True
    if first[0] == 0: # 全ての数がゼロの時
        print("Yes")
    else:
        print("No")
elif third[0] == -1:    # 数が2種類だけの時
    done = True
    if N % 2 == 0 and second[1] == N // 2 and first[0] == 0:
        print("Yes")
    elif N % 3 == 0 and N != 3 and second[1] == N // 3:
        done = False
        a_lst = [ a_lst[0], a_lst[second[1]], a_lst[second[1]] ]
    else:
        print("No")
elif N % 3 == 0 and N != 3 and second[1] == N // 3:
    if third[1] == N * 2 // 3:
        a_lst = [ a_lst[0], a_lst[second[1]], a_lst[third[1]] ]
    elif third[1] == - 1:
        a_lst = [ a_lst[0], a_lst[second[1]], a_lst[third[1]] ]

a_lst.reverse()

if not done:
    if len(a_lst) == 3:

        a1 = make_bit(a_lst[0])
        a2 = make_bit(a_lst[1])
        a3 = make_bit(a_lst[2])
        bits_arr = np.array([a1, a2, a3])

        judge = True
        for i in range(31):
            if bits_arr[0][i] == bits_arr[1][i] and bits_arr[2][i] == 1:
                judge = False
                break

            elif bits_arr[0][i] != bits_arr[1][i] and bits_arr[2][i] == 0:
                judge = False
                break
                
        if judge:
            print("Yes")
        else:
            print("No")


    else:
        print("No")



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

int main(void)
{   
    int n,k;
    cin >> n >> k;
    vector<bool> snuke(n+1, false);

    rep(i, k) {
        int d; cin >> d;
        rep(j, d) {
            int a; cin >> a;
            snuke[a] = true;
        }
    }
    int cnt = 0;
    for(int i = 1; i < n+1; i++) {
        if(!snuke[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Summer of KMC
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a==0&&b==0)break;
			int x = b-a;
			int t = x/1000;
			x %= 1000;
			int g = x/500;
			x %= 500;
			System.out.println(x/100+" "+g+" "+t);
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;

signed main(){
  vector<string> str={".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  int n;
  cin>>n;
  while(n--){
    string s;
    cin>>s;
    vector<pair<int,int>> p;
    REP(i,s.size()){
      int c=s[i]-'0';
      if(c==0)continue;
      int tmp=-1;
      while(s[i]!='0'){
        tmp++;
        i++;
      }
      p.PB(MP(c-1,tmp));
    }
    REP(i,p.size()){
      int f=p[i].FR;int sc=p[i].SC;
      if(f==0)cout<<str[0][sc%5];
      else if(f==6||f==8)cout<<str[f][sc%4];
      else cout<<str[f][sc%3];
    }
    cout<<endl;
   }
  return 0;
}



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

#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef  long long  ll;

int main()
{
  fastIO();
	//Editorial -_- -_- -_- 
	int  a , b , p , m , mu;
	cin>>a>>b;
	cout<<max({a+b,a-b,a*b})<<'\n';

 return 0;
 }


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

main()
{
        int n,m; cin>>n>>m;

        set<int> s,t;
        rep(i,m)
        {
                int a,b; cin>>a>>b;
                if(a==1)s.insert(b);
                if(b==n)t.insert(a);
        }
        each(it,s)
        {
                if(t.find(it)!=t.end())
                {
                        cout<<"POSSIBLE"<<endl;
                        return 0;
                }
        }
        cout<<"IMPOSSIBLE"<<endl;

}


Measured memory_bytes: 9600
import bisect
Input = map(int,raw_input().split(' '))
N = Input[0]
K = Input[1]
A = map(int,raw_input().split(' '))
A = sorted(A)
count = []
i = 0
while i < len(A):
	count.append(bisect.bisect_right(A,A[i]) - bisect.bisect_left(A,A[i]))
	i = bisect.bisect_right(A,A[i])
count = sorted(count)
dim = len(count)
rslt = 0
if dim <= K:
	print rslt
else:
	rslt += sum(count[:dim-K])
	print rslt

Measured memory_bytes: 20072
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define forr(i,k,n) for(ll i=k;i<n;i++)
int main(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    cout<<min(a,k)-max(0ll,k-a-b)<<"\n";
}

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

#define rep(i, first, to) for(ll i = first; i < to; ++i)

using namespace std;
typedef long long ll;

void replace(string s) {
	rep (i, 0, s.size()) {
		if (s[i] == ',') s[i] = ' ';
	}
	cout << s << endl;
}
void solve() {
	string s;
	cin >> s;
	replace(s);
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
long long i[3000000];
bool o;
bool ans[5];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h=0,j=0;
  cin >>a>>b>>c>>d;
  a+=b,c+=d;
  if(a>c) cout <<"Left\n";
  else{
    if(a<c) cout <<"Right\n";
    else cout <<"Balanced\n";
  }
  return (0);
}


Measured memory_bytes: 256
// copied
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int N=3e2+5;
const int M=3e2+5;
const ll mod=1e9+7;
ll dp[N][N][N];
int n,m;
vector<ii> v[N];//
bool check(int r,int g,int b)
{
	int k=max(r,max(g,b));
	for(int j=0;j<v[k].size();j++)
	{
		int l=v[k][j].first,x=v[k][j].second;
		int cnt=0;
		if(r>=l)	cnt++;
		if(g>=l)	cnt++;
		if(b>=l) 	cnt++;
		if(cnt!=x)
			return false;
	}
	return true;
}
int main()
{
	while(cin>>n>>m)
	{
		for(int i=1;i<=n;i++)
			v[i].clear();
		int l,r,x;
		for(int i=1;i<=m;i++)
		{
			cin>>l>>r>>x;
			v[r].push_back(ii(l,x));
		}
		memset(dp,0,sizeof(dp));
		dp[0][0][0]=1;
		ll ans=0;
		for(int r=0;r<=n;r++)
		{
			for(int g=0;g<=n;g++)
			{
				for(int b=0;b<=n;b++)
				{
					if(dp[r][g][b]==0)//非法
						continue;
					if(!check(r,g,b))
					{
						dp[r][g][b]=0;
						continue;
					}
					int k=max(r,max(g,b))+1;
					if(k==n+1)
						ans=(ans+dp[r][g][b])%mod;
					dp[k][g][b]+=dp[r][g][b]%mod;
					dp[r][k][b]+=dp[r][g][b]%mod;
					dp[r][g][k]+=dp[r][g][b]%mod;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

int main() {
	int n, p[22], ans=0; cin>>n;
	for(int i=0;i<n;i++) cin>>p[i];
	
	for(int i=0;i<n-2;i++){
		int tmp[3]={p[i],p[i+1],p[i+2]};
		sort(tmp,tmp+3);
		if(tmp[1]==p[i+1]) ans++;
	}
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;

int main() 
{
	int a, b, c;
	cin >> a >> b >> c ;
	if (a < b && b < c) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
}

Measured memory_bytes: 1120
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[3],i,s=0,t=0;
	for(i=0;i<3;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+3);
	if((a[2]-a[0])%2==0)
	{
		s+=(a[2]-a[0])/2;
		a[0]=a[2];
	}
	else
	{
		s+=(a[2]-a[0])/2;
		a[0]=a[2]-1;
		t++;
	}
	if((a[2]-a[1])%2==0)
	{
		s+=(a[2]-a[1])/2;
		a[1]=a[2];
	}
	else
	{
		s+=(a[2]-a[1])/2;
		a[1]=a[2];
		t++;
	}
	if(t==0)
	{
		printf("%d",s);
	}
	else if(t==1)
	{
		printf("%d",s+2);
	}
	else
	{
		printf("%d",s+1);
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt(), m = in.nextInt();
			int[] box = new int[n];
			boolean[] canRed = new boolean[n];
			Arrays.fill(box, 1);
			canRed[0] = true;

			for (int i = 0; i < m; i++) {
				int x = in.nextInt() - 1;
				int y = in.nextInt() - 1;

				if (canRed[x]) canRed[y] = true;

				box[y]++;
				box[x]--;
				if (box[x] == 0) canRed[x] = false;

			}

			int ans = 0;
			for (int i = 0; i < n; i++) {
				if (canRed[i]) ans++;
			}
			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 41524
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

const ll MOD = 1e9+7;
ll digit_num,ans,n;

void dfs(ll k,ll num){
    if(k > digit_num) return;

    if(k >= 3){
        if(num <= n){
            ll memo[3] = {},temp = num;
            while(num){
                if(num % 10 == 3) memo[0] = 1;
                else if(num % 10 == 5) memo[1] = 1;
                else memo[2] = 1;
                num /= 10;
            }
            if(memo[0] && memo[1] && memo[2]){
                ans++;
            }
            num = temp;
        }
        
    }

    dfs(k+1,num*10+7);
    dfs(k+1,num*10+5);
    dfs(k+1,num*10+3);

    return;
}

signed main(){
    cin >> n;
    digit_num = (ll)(log10(n)+1.0);

    dfs(0,0);
 
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3868
/* last edited at 31.8.2015 by charis
http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_3_B
*/

#include<iostream>
#include<string>
using namespace std;

class Queue{
private:
	int head, tail;	
public:
	int Q[100001];
	string name[100001];
	
	void initialize(){
		head = 0; tail = 0;
	}
	int isEmpty(){
		return head == tail;
	}
	int isFull(){
		return head == (tail + 1) % 100001;
	}
	void enqueue(int x, string c){
		if (isFull()) cout << "Error" << endl;
		Q[tail] = x ;
		name[tail] = c ;
		if (tail + 1 == 100001) tail = 0;
		else tail++;
	}
	int dequeue(){
		if (isEmpty()) cout << "Error" << endl;
		int x = Q[head];
		if(head + 1 == 100001) head = 0;
		else head++;
		return x;
	}	
	string outname(){
		if (head == 0) return name[100000];		
		else return name[head-1];
	}
};

int main(){
	int total=0;	
	int n, q;
	cin >> n >> q;

	Queue que;
	que.initialize();

	for ( int i = 0; i < n; i++){
		string c;
		int x;
		cin >> c >> x; 
		que.enqueue(x, c);
	} 
	if(n==1 && q==1){
		int x = que.dequeue();
		string c = que.outname();	
		cout << c << " " << x << endl;
	}
	else {
		int cnt=0;
		while(1){
			if (que.isEmpty()) break;
			int x = que.dequeue();
			string c = que.outname();
			if (x > q){
				x = x - q ;
				total += q;
				que.enqueue(x, c);
			}
			else if (x <= q){
				total += x;
				cout << c << " " << total << endl;
			}
			cnt++;			
		}		
	}	
	return 0; 	
}

Measured memory_bytes: 4720
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<int>X(N),Y(N);
    for(int i=0;i<N;i++){
        cin>>X[i];
        Y[i]=X[i];
    }
    sort(Y.begin(),Y.end());
    reverse(Y.begin(),Y.end());
    int ans=10000000;
    for(int i=1;i<=Y[0];i++){
        int sum=0;
        for(int j=0;j<N;j++){
            sum+=pow(X[j]-i,2);
        }
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256