akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
const int N = 1e6 + 7, M = 1000000007, inf = INT_MAX;

int freq[N], f2[N];

#define pii pair<int,int>
#define ff first
#define ss second
#define all(v) v.begin(),v.end()

void solve()
{
	int n;
	cin >> n;

	int arr[n], brr[n], res[n];
	memset(res, -1, sizeof res);
	lop(i, 0, n) cin >> arr[i], f2[ arr[i] ]++;
	lop(i, 0, n) cin >> brr[i], freq[ brr[i] ]++;

	auto cmp = [](int a, int b) {

		if ( freq[a] != freq[b] ) return freq[a] > freq[b];
		else return a > b;
	};

	lop(i, 0, n + 1) if ( f2[i] + freq[i] > n )
	{
		cout << "No" << endl;
		return;
	}

	set<int, decltype(cmp)> st(cmp);
	lop(i, 0, N) if ( freq[i] ) st.insert(i);
	int i = 0;
	while ( i < n )
	{
		int x = arr[i], id = i;
		if ( res[id] != -1 )
		{
			i++;
			continue;
		}

		auto it = st.begin();
		int rem = -1;
		if ( *it == x  ) rem = x, st.erase(rem);

		if ( rem != -1 ) it = st.begin();
		if ( it == st.end() ) {
			res[id] = x;
			int found = -1;
			vector<int> v1;
#define pb push_back
			lop(j, 0, n)
			{
				if ( j == id ) continue;
				if ( res[j] != x and res[j] != -1 and arr[j] != x ) found = j, v1.pb(j);
			}
			int sz = v1.size();
			int j = i;
			while ( j < n and arr[j] == x )
			{
				int p = v1.back();
				res[j] = res[ p ]; v1.pop_back();
				res[p] = x;
				j++;
				sz--;
				freq[x]--;
			}
		}
		else
		{
			res[id] = *it;
			int val = *it;
			st.erase(val);
			freq[val]--;
			if (freq[val]) st.insert(val);
		}
		if ( rem != -1 ) st.insert(rem);
		i++;
	}
	cout << "Yes" << endl;
	lop(i, 0, n) cout << res[i] << " "; cout << endl;
}

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

	int test = 1;
	// cin >> test;
	while (test--)solve();


}






















Measured memory_bytes: 16768
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;

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


/////////////////////////////////////////////////////////////////////////////////////////
int par[100000],rank_[100000];


void init(int N){
    for (int i = 0;i < N;i++){
        par[i] = i;
        rank_[i] = 0;
    }
}

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

    return par[x] = find(par[x]);
}


void unite(int x,int y){ 
    x = find(x);
    y = find(y);

    if (x == y) return;

    if (rank_[x] < rank_[y]){
        par[x] = y;
    }
    else {
        par[y] = x;
        if (rank_[x] == rank_[y]){
            rank_[x]++;
        }
    }
}


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

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

    vector<int> com(q),x(q),y(q);
    for (int i = 0;i < q;i++){
        cin >> com[i] >> x[i] >> y[i];
    }

    init(n);
    
    for (int i = 0;i < q;i++){
        if (com[i] == 0) {
            if (same(x[i],y[i])) continue;
            unite(x[i],y[i]);
        }
        else{
            if (same(x[i],y[i])) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 4136
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

vector<int> divisor(int m) {
  vector<int> a;
  int mm = m;
  for (int i = 2; i * i <= mm; i++) {
    if (m == 1) break;
    int res = 0;
    while (m % i == 0) {
      res++;
      m /= i;
    }
    a.push_back(res);
  }
  if (m != 1) a.push_back(1);
  return a;
}

ll modpow(ll a,ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll nCr(ll n, ll r) {
  r = min(n-r, r);
  if (r == 0) return 1;
  ll ans = 1;
  FOR(i, n-r+1, n+1) ans = ans * i % mod;
  ll a = 1;
  FOR(i, 1, r+1) a = a * i % mod;
  ans = ans * modpow(a, mod-2) % mod;
  return ans;
}

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

  vector<int> a = divisor(m);
  int k = a.size();
  ll ans = 1;
  rep(i, k) {
    ans = (ans * nCr(a[i] + n - 1, n - 1)) % mod;
  }
  cout << ans << endl;




  
  return 0;
}

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

int n, a[500010];
int cnt = 0;

int L[250010], R[250010];
const int inf = 2000000000;

void merge( int  l, int m, int r ){
    int n1 = m - l;
    int n2 = r - m;
    for( int i = 0; i < n1; i++ ) L[i] = a[l + i];
    for( int i = 0; i < n2; i++ ) R[i] = a[m + i];

    L[n1] = R[n2] = inf;
    int i = 0, j = 0;
    for( int k = l; k < r; k++ ){
        cnt++;
        if( L[i] <= R[j] ){
            a[k] = L[i++];
        }
        else {
            a[k] = R[j++];
        }
    }
}

void msort( int l, int r ){
    if( l + 1 < r ){
        int m = ( l + r )/ 2;
        msort( l, m );
        msort( m, r );
        merge( l, m, r );
    }
}

int main()
{
    cin >> n;
    for( int i = 0; i < n; i++ ) cin >> a[i];

    msort( 0, n );

    for( int i = 0; i < n; i++ ) cout << ( i ? " " : "" ) << a[i];
    cout << endl << cnt << endl;

    return 0;
}



Measured memory_bytes: 6976
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

const int MOD = 1e9 + 7;

int main() {
	std::string s; cin >> s;
	
	std::vector<i64> latte(s.size() + 1, 1), malta(s.size() + 1, 1);
	for(int i = 0; i < (int)latte.size() - 1; i++) latte[i + 1] = (latte[i] << 1) % MOD;
	for(int i = 0; i < (int)malta.size() - 1; i++) malta[i + 1] = (malta[i] * 3LL) % MOD;
	
	i64 ans = 0, tmp = 0;
	for(int i = 0; i < (int)s.size(); i++) {
		if(s[i] == '1') tmp++;
		if(s[i] == '0') continue;
		(ans += latte[tmp - 1] * malta[(int)s.size() - i - 1] % MOD) %= MOD;
	}
	(ans += latte[tmp]) %= MOD;
	
	printf("%lld\n", ans);
	return 0;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> a(h,vector<char>(w));
  rep(i,h){
    rep(j,w){
      cin >> a.at(i).at(j);
    }
  }
  VI hcheck(h);
  rep(i,h){
    rep(j,w){
      if(a.at(i).at(j)=='.'){
        hcheck.at(i)++;
      }
    }
  }
  VI wcheck(w);
  rep(i,w){
    rep(j,h){
      if(a.at(j).at(i)=='.'){
        wcheck.at(i)++;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      bool b=true;
      bool c=true;
    if(hcheck.at(i)==w){
      b=false;
    }
      if(wcheck.at(j)==h){
        c=false;
    }
     if(b && c) cout << a.at(i).at(j) ;
     if(b){
       if(j==w-1) cout << endl;
     }
    }
  }
      
      
}

Measured memory_bytes: 256
//AOJ DSL_2_H RMQ and RAQ

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

struct lazysegtree {
    int size;
    //初期値0
    vector<ll> node, lazy;
    
    lazysegtree(int n) {
        size = 1;
        while (size<n) size *= 2;
        node.resize(2*size-1);
        lazy.resize(2*size-1);
    }
    
    void eval(int k) {
        node[k] += lazy[k];
        
        if (k<size-1) {
            lazy[2*k+1] += lazy[k];
            lazy[2*k+2] += lazy[k];
        }
        
        lazy[k] = 0;
    }
    
    void update(int a, int b, ll x, int k, int l, int r) {
        eval(k);
        
        if (b<=l || r<=a) return;
        
        if (a<=l && r<=b) {
            lazy[k] += x;
            eval(k);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            //ここ変える
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }
    
    ll query(int a, int b, int k, int l, int r) {
        eval(k);
        
        //ここ単位元にする
        if (b<=l || r<=a) return INF;
        if (a<=l && r<=b) return node[k];
        ll vl = query(a, b, 2*k+1, l, (l+r)/2);
        ll vr = query(a, b, 2*k+2, (l+r)/2, r);
        //ここ変える
        return min(vl, vr);
    }
    
    //[a, b)にxを足す
    void add(int a, int b, ll x) {
        update(a, b, x, 0, 0, size);
    }
    
    //[a, b)に対するクエリ
    ll get(int a, int b) {
        return query(a, b, 0, 0, size);
    }
};

int main() {
    int n, q; cin >> n >> q;
    lazysegtree lst(n);
    
    rep(i, q) {
        int f; cin >> f;
        
        if (f==0) {
            int s, t, x; cin >> s >> t >> x;
            lst.add(s, t+1, x);
        }
        else {
            int s, t; cin >> s >> t;
            cout << lst.get(s, t+1) << endl;
        }
    }
}


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

vector<long> div(long n) {
  vector<long> v;
  for (long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
      if (i * i != n) v.push_back(n / i);
    }
  }
  sort(begin(v), end(v));
  return v;
}

int main() {
  long N;
  cin >> N;
  set<long> ans;
  for (auto a : div(N)) {
    if (a == 1) continue;
    auto n = N;
    while (n % a == 0) n /= a;
    if (n % a == 1) ans.insert(a);
  }
  for (auto a : div(N - 1)) {
    if (a == 1) continue;
    ans.insert(a);
  }
  cout << ans.size() << "\n";
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


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

    //5文字以下は要らない
    set<string> sset;
    rep(i, s.size()){
        rep(j,5){
            string t = s.substr(i, j+1);
            sset.insert(t);
        }
    }

    int p = 0;
    for (auto i = sset.begin(); i != sset.end(); i++)
    {
        p++;
        if (p == k) {cout << *i  << endl; return 0;}
    }
}



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

int main(){
    int x;cin>>x;
    bool judge = false;
    int val;
    for (int i=0;i<=1000000;i++){
        val = 105 * i;
        if (x == val){
            cout << 1 << endl;
            return 0;
        } else if (x < val){
            break;
        }
        for (int j=0;j<=1000000;j++){
            val = 105 * i + 104 * i;
            if (x == val){
                cout << 1 << endl;
                return 0;
            } else if (x < val){
                break;
            }
            for (int k=0;k<=1000000;k++){
                val = 105 * i + 104 * j + 103 * k;
                if (x == val){
                    cout << 1 << endl;
                    return 0;
                } else if (x < val){
                    break;
                }
                for (int l=0;l<=1000000;l++){
                    val = 105 * i + 104 * j + 103 * k + 102 * l;
                    if (x == val){
                        cout << 1 << endl;
                        return 0;
                    } else if (x < val){
                        break;
                    }
                    for (int m=0;m<=1000000;m++){
                        val = 105 * i + 104 * j + 103 * k + 102 * l + 101 * m;
                        if (x == val){
                            cout << 1 << endl;
                            return 0;
                        } else if (x < val){
                            break;
                        }
                        for (int o=0;o<=1000000;o++){
                            val = 105 * i + 104 * j + 103 * k + 102 * l + 101 * m + 100 * o;
                            if (x == val){
                                cout << 1 << endl;
                                return 0;
                            } else if (x < val){
                                break;
                            }

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

Measured memory_bytes: 256
using System;
namespace _0627
{
  class Program
  {
  	static void Main(string[] args)
    {
      int a ;
    bool success = int.TryParse(Console.ReadLine(), out a);
    
    if(success){
    	//数値を計算する
      a = a +(a*a) + (a*a*a);
      
      //計算結果を出力する
      Console.WriteLine(a.ToString());
    
    }
    }
    
  }  
  
  
  }


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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

int calc(vector<long long> a){
	int N = a.size();
	int K = 0;
	while(1){
		/*
		cout<<"calc"<<endl;
		REP(i,N)cout<<a[i]<<" ";
		cout<<endl;
		*/
		int max_id = -1;
		int max_val = -INF;
		REP(i,a.size()){
			if(max_val < a[i]){
				max_val = a[i];
				max_id = i;
			}
		}
		if(max_val <= N-1)return K;
		K++;
		REP(i,a.size()){
			if(i == max_id)a[i] -= N;
			else a[i]++;
		}
	}
}

void solve(long long N, vector<long long> a){
	long long s = accumulate(ALL(a),0ll);
	vector<long long> r(a);
	REP(i,N)r[i]%=(N+1);
	int rsum_max = -INF;
	vector<long long> rsum_vec;
	REP(d,N+1){
		bool valid = false;
		vector<long long> r2(r);
		REP(i,N){
			r2[i] = (r[i] + d)%(N+1);
			if(r2[i] == N)valid = true;
		}
		if(!valid)continue;
		long long rsum = accumulate(ALL(r2),0ll);
		if(rsum>rsum_max){
			rsum_max = rsum;
			rsum_vec = r2;
		}
	}
	/*
	cout<<s<<" "<<rsum_min<<endl;
	REP(i,rsum_vec.size()){
		cout<<rsum_vec[i]<<" ";
	}
	cout<<endl;
	*/
	long long K = 0;
	if(s>=rsum_max){
		REP(i,N)K+=(a[i]-rsum_vec[i]);
		a = rsum_vec;
	}
	/*
	dump(K);
	REP(i,a.size()){
		cout<<a[i]<<" ";
	}
	cout<<endl;
	*/
	K+=calc(a);
	cout<<K<<endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> a(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
	}
	solve(N, a);
	return 0;
}


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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	priority_queue<int,vector<int>,greater<int> >pq_a;
	priority_queue<int,vector<int>,greater<int> >pq_b;
	priority_queue<int,vector<int>,less<int> >pq_c;
	while(a--){
		int a;
		cin>>a;
		pq_a.push(a);
	}
	while(b--){
		int a;
		cin>>a;
		pq_b.push(a);
	}
	while(c--){
		int a;
		cin>>a;
		pq_c.push(a);
	}
	while(pq_a.size()>x) pq_a.pop();
	while(pq_b.size()>y) pq_b.pop();
	while(!pq_c.empty()){
		int curr = pq_c.top();
		pq_c.pop();
		if(pq_a.top()>=curr && pq_b.top()>=curr) break;
		if(pq_a.top()>=pq_b.top()){
			pq_b.pop();
			pq_b.push(curr);
		}
		else{
			pq_a.pop();
			pq_a.push(curr);
		}
	}
	long long ret = 0;
	while(!pq_a.empty()){
		ret+=pq_a.top();
		pq_a.pop();
	}
	while(!pq_b.empty()){
		ret+=pq_b.top();
		pq_b.pop();
	}
	cout<<ret;
}

Measured memory_bytes: 4644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    for(int i=K;i<N;i++){
        if(A[i-K]<A[i]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int k;
  cin>>k;
  vector<int>a(n+1);
  a[0]=0;
  for(int i=0;i<n;i++){
    cin>>a[i+1];
    a[i+1]+=a[i];
  }
  int maxval=INT_MIN;
  for(int i=k;i<=n;i++){
       maxval=max(maxval,a[i]-a[i-k]);
  }
 // cout<<maxval<<endl;
  double ans = 1.0*(maxval+k)/2;
  cout<<fixed<<setprecision(10)<<ans<<endl;
  }


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    string s, t;
    cin >> s >> t;
    ll n = s.size();

    vvl v(26);
    rep(i, n) {
        v[s[i] - 'a'].pb(i+1);
    }
    rep(i, n) {
        v[s[i] - 'a'].pb(n+i+1);
    }

    ll ans = 0;
    ll now = 0;
    rep(i, t.size()) {
        ll x = t[i] - 'a';
        if(v[x].size() == 0) {
            out(-1);
            re0;
        }
        now = *upper_bound(all(v[x]), now);
        if(now > n) {
            now -= n;
            ans += n;
        }
    }
    ans += now;

    out(ans);
    re0;
}

Measured memory_bytes: 2800
#include <iostream>
#include <vector>

void swapval(int& a, int& b) {
    const int tmp = a;
    a = b;
    b = tmp;
    return;
}

void output(std::vector<int> & A) {
    const int n = A.size();
    for (int i = 0; i < n - 1; ++i) {
        std::cout << A[i] << " ";
     }
    std::cout << A[n - 1] << std::endl;
}

int main() {
    int N; std::cin >> N;
    std::vector<int> A(N);
    for (int i = 0; i < N; ++i) std::cin >> A[i];
    output(A);

    for (int i = 1; i < N; ++i) {
        int j = i - 1;
        for (int j = i - 1; j >= 0; --j) {
            if (A[j+1] > A[j]) break;
            swapval(A[j + 1], A[j]);
        }
        output(A);
    }

    return 0;

}


Measured memory_bytes: 3100
a, b = gets.split(" ").map{|d|d.to_i}
if a == 1 and b == 1
	puts "Draw"
elsif a == 1
	puts "Alice"
elsif b == 1
	puts "Bob"
elsif a == b
	puts "Draw"
elsif a > b
	puts "Alice"
else
	puts "Bob"
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1000000007;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

const int INF = 1e9;
const ll LLINF = 1e16;
 
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
 
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll h,n;
    cin >> h >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n){
      h -= a[i];
    }
    if(h <= 0) {
      print("Yes");
    } else{
      print("No");
    }
}


Measured memory_bytes: 1024
#include<stdio.h>

int selectionSort(int *a, int n) 
{
	int i, j, minj, temp;
	int count = 0;
	
	for(i=0;i<n-1;i++) {
		minj = i;
		for(j=i+1;j<n;j++) {
			if(a[j] < a[minj]) {
			    minj = j;
			}
		}
		if(i != minj) {
			temp = a[i];
			a[i] = a[minj];
			a[minj] = temp;
			count++;
		}
	}
	
	return count;
}

void print_array(int *a, int n) 
{
	int i;
	for(i=0;i<n;i++) {
		if(i > 0) printf(" ");
		printf("%d", a[i]);
	}
	printf("\n");
}

int main(void) 
{
	int n, a[100], i, count;
	
	scanf("%d", &n);
	for(i=0;i<n;i++) {
		scanf("%d", &a[i]);
	}
	
	count = selectionSort(a, n);
	print_array(a, n);
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
int main (){
    int n,Y,flag=0;
    cin >> n >> Y;

    for(int x=0;x<=2000;x++){
        for(int y=0;y<=2000;y++){
            if(9*x+4*y+n == Y/1000 && 0<=n-x-y && n-x-y<=2000){
                cout << x << " " << y << " " << n-x-y << endl;
                flag++;
                break;
            }
        }
        if(flag == 1){
            break;
        }
    }
    
    if(flag == 0){
        cout << -1 <<" " << -1 << " "<< -1 << endl;
    }
}

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

using namespace std;

int OriginalData[10][10], Ans[10][10], Tmp[10][10];
int Used[10];

bool judge() {
	int dx[] = { 0,-1,0,1,0 };
	int dy[] = { -1,0,0,0,1 };
	int currentX, currentY;

	memset(Ans, 0, sizeof(Ans));
	memcpy(Tmp, OriginalData, sizeof(Tmp));

	for (int j = 0; j < 10; j++) {
		Ans[0][j] = Used[j];
		if (Used[j]) {
			for (int k = 0; k < 5; k++) {
				currentX = dx[k];
				currentY = j + dy[k];

				if (currentX<0 || currentX>9 || currentY<0 || currentY>9) {
					continue;
				}
				Tmp[currentX][currentY] = !Tmp[currentX][currentY];
			}
		}
	}

	for (int i = 1; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (Tmp[i - 1][j]) {
				Ans[i][j] = 1;
				for (int k = 0; k < 5; k++) {
					currentX = i + dx[k];
					currentY = j + dy[k];

					if (currentX<0 || currentX>9 || currentY<0 || currentY>9) {
						continue;
					}
					Tmp[currentX][currentY] = !Tmp[currentX][currentY];
				}
			}
		}
	}

	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (Tmp[i][j]) {
				return false;
			}
		}
	}
	return true;
}

bool solve(int col) {
	if (col == 10) {
		if (judge()) {
			return true;
		}
		return false;
	}

	if (solve(col + 1)) {
		return true;
	}
	Used[col] = 1;
	if (solve(col + 1)) {
		return true;
	}
	Used[col] = 0;
	
	return false;
}

int main() {
	int n;

	cin >> n;
	while (n--) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				cin >> OriginalData[i][j];
			}
		}
		memset(Used, 0, sizeof(Used));
		solve(0);

		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				cout << Ans[i][j] << (j == 9 ? "\n" : " ");
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3056
def main():
    N=int(input())
    A=list(map(int,input().split()))
    t={}
    flag=True
    for i in range(N):
        if str(A[i]) not in t:
            t[str(A[i])]=1
        elif t[str(A[i])]==1:
            t[str(A[i])]=2
        elif t[str(A[i])]==2:
            flag=False
            break
    if flag==False:
        print(0)
    if flag and N%2==1:
        if t["0"]!=1:
            print(0)
            flag=False
        if flag:
            count_zero=0
            for v in t.values():
                if v==1:
                    count_zero+=1
                    if count_zero>=2:
                        print(0)
                        flag=False
                        break
        if flag:
            print((2**(N//2))%1000000007)

    elif flag and N%2==0:
        for v in t.values():
            if v==1:
                print(0)
                flag=False
                break
        if flag:
            print((2**(N//2))%1000000007)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 15660
from sys import stdin
import math

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

def xxx(x,c,d):
    return x - x//c - x//d + x//lcm(c,d)

a, b, c, d = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0

aa = xxx(a-1,c,d)
bb = xxx(b,c,d)
ans = bb - aa
print(ans)


Measured memory_bytes: 38484
#include<iostream>

int maxInt(int x,int y){
	if(x<y){
		return y;
	} else{
		return x;
	}
}

int main(){
	//入力機構
	int a,b;
	std::cin>>a>>b;
	//解答
	int ans=maxInt(a+b,maxInt(a-b,a*b));//3つのうちの最大値は3つのmaxを取れば良い
	//結果出力
	std::cout<<ans<<std::endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void fun(vector<int> &arr, int n, int k){
	int dp[k+1];
	//memset(dp,1,sizeof(dp));
	dp[0]=0;
	for(int i=1;i<=k;i++){
		dp[i]=0;
		for(int j=0;j<n;j++){
			if(i>=arr[j]){
				if(dp[i-arr[j]]==0) dp[i]=1;
			}
		}
	}
//	for(int i=0;i<=k;i++){
//		cout<<dp[i]<<" ";
//	}cout<<endl;
if(dp[k]==1) cout<<"First"<<endl;
else cout<<"Second"<<endl;
}

int main(){
	int n,k;
	cin>>n>>k;
	vector<int> arr(n);
	for(int i=0;i<n;i++) cin>>arr[i];
	fun(arr,n,k);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int a,b;
    std::cin >> a >> b ;
    if (a>b) 
    {
        cout<< "a > b" << std::endl ;
    }
    else if (a == b)
    {
        cout << "a == b" << std::endl;
    }
    else if (a<b)
    {
        cout << "a < b" << std::endl;
        
    } 
    return 0;
}



Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <set>
#include <cmath>
#include <map>


int main(int,char**){
	int n;
	char from,to;
	char in;
	while(std::cin >> n){
		if(!n) break;
		std::map<char,char> map;
		while(n--){
			std::cin >> from >> to;
			map[from] = to;
		}
		std::cin >> n;
		while(n--){
			std::cin >> in;
			if(map[in]) std::cout << map[in];
			else std::cout << in;
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 904
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
	int f;char c;
	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>inline void write(T x){
	static char q[64];int cnt=0;
	if(!x)pc('0');if(x<0)pc('-'),x=-x;
	while(x)q[cnt++]=x%10+'0',x/=10;
	while(cnt--)pc(q[cnt]);
}
const int maxn=50005,mod=998244353;
int mo(const int x){
	return x>=mod?x-mod:x;
}
int power(int a,int x){
	int re=1;
	while(x){
		if(x&1)re=1ll*re*a%mod;
		a=1ll*a*a%mod,x>>=1;
	}
	return re;
}
int rev[maxn*4],N;
void NTT(int*F,int rv){
	for(int i=0;i<N;++i)if(rev[i]<i)
		F[rev[i]]^=F[i]^=F[rev[i]]^=F[i];
	for(int mid=1;mid<N;mid<<=1){
		int len=mid<<1,gn=power(3,(mod-1)/len);
		for(int i=0;i<N;i+=len){
			for(int j=0,g=1;j<mid;++j,g=1ll*g*gn%mod){
				int l=i+j,r=l+mid;
				int L=F[l],R=1ll*F[r]*g%mod;
				F[l]=mo(L+R),F[r]=mo(mod-R+L);
			}
		}
	}
	if(!rv)return;reverse(F+1,F+N);int tmp=power(N,mod-2);
	for(int i=0;i<N;++i)F[i]=1ll*tmp*F[i]%mod;
}
int F[maxn*4],G[maxn*4],S[maxn*2],L[maxn*2],R[maxn*2];
void solve(int l,int r){
	if(l==r)return;int mid=(l+r)>>1,o=mid+1;
	solve(l,mid);solve(o,r);
	int mx=R[l]-L[l]+R[o]-L[o]-1,cn=-1;N=1;
	while(N<mx)N<<=1,++cn;
	for(int i=1;i<N;++i)
		rev[i]=(rev[i>>1]>>1)|((i&1)<<cn);
	int cf=0,cg=0;
	for(int i=L[l];i!=R[l];++i)F[cf++]=S[i];
	for(int i=L[o];i!=R[o];++i)G[cg++]=S[i];
	while(cf!=N)F[cf++]=0;while(cg!=N)G[cg++]=0;
	NTT(F,0);NTT(G,0);
	for(int i=0;i<N;++i)F[i]=1ll*F[i]*G[i]%mod;
	NTT(F,1);
	for(int i=0;i<mx;++i)S[L[l]+i]=F[i];
	R[l]=L[l]+mx;
}
int GO[maxn],iac[maxn*2],fac[maxn*2];
int binom(int n,int m){
	return 1ll*iac[m]*iac[n-m]%mod*fac[n]%mod;
}
int a[maxn*2];
int main(){
	int n;read(n);
	GO[0]=1;
	for(int i=1;i<=n;++i)
		GO[i]=1ll*GO[i-1]*(i*2-1)%mod;
	iac[0]=iac[1]=fac[0]=fac[1]=1;
	for(int i=2;i<=n*2;++i)
		iac[i]=1ll*(mod-mod/i)*iac[mod%i]%mod;
	for(int i=2;i<=n*2;++i)
		iac[i]=1ll*iac[i-1]*iac[i]%mod,fac[i]=1ll*fac[i-1]*i%mod;
	for(int i=1;i<=n*2;++i)read(a[i]);
	sort(a+1,a+n*2+1);int cnt=0,num=0;
	for(int l=1,r=l;l<=n*2;l=r=r+1){
		while(r+1<=n*2&&a[r+1]==a[l])++r;
		int len=r-l+1;++num;L[num]=cnt;
		for(int x=0;x*2<=len;++x)
			S[cnt++]=1ll*GO[x]*binom(len,x*2)%mod;
		R[num]=cnt;
	}
	solve(1,num);
	int mx=R[1]-L[1],delta=L[1],ans=0;
	for(int i=0;i<mx;++i){
		int tmp=1ll*GO[n-i]*(S+delta)[i]%mod;
		if(i&1)tmp=mo(mod-tmp);
		ans=mo(ans+tmp);
	}
	write(ans),pc('\n');
	return 0;
}

Measured memory_bytes: 6204
import java.util.Scanner;
public class Main {
		public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++) {
			double x1 = sc.nextDouble();
			double y1 = sc.nextDouble();
			double x2 = sc.nextDouble();
			double y2 = sc.nextDouble();
			double x3 = sc.nextDouble();
			double y3 = sc.nextDouble();
			double a = Math.pow(x2 - x1, 2.0) + Math.pow(y2 - y1, 2.0);
			double b = Math.pow(x3 - x2, 2.0) + Math.pow(y3 - y2, 2.0);
			double c = Math.pow(x1 - x3, 2.0) + Math.pow(y1 - y3, 2.0);
			double s = Math.pow(0.5 * ((x2-x1)*(y3-y1) - (x3-x1)*(y2-y1)), 2.0);
			double px = (a * (b + c - a) * x3 + b * (c + a - b) * x1 + c * (a + b - c) * x2) / (16 * s);
			double py = (a * (b + c - a) * y3 + b * (c + a - b) * y1 + c * (a + b - c) * y2) / (16 * s);
			double r = Math.pow(px - x1, 2.0) + Math.pow(py - y1, 2.0);
			System.out.printf("%.3f ", px);
			System.out.printf("%.3f ", py);
			System.out.printf("%.3f\n", Math.sqrt(r));
		}
	}
}

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

const int TOP = 0,FRONT = 1,LEFT = 3, RIGHT = 2,BACK = 4,BOTTOM = 5;
class Dice{
public:
  vector<int> val;
  Dice():val(6){for(int i=0;i<6;i++) val[i] = i;}
  Dice(int val[6]){for(int i=0;i<6;i++) this->val[i] = val[i];}
  Dice(vector<int> val):val(val){assert(val.size() == 6);}
  int& operator [](int a){return val[a];}
  bool operator == (Dice a){
    for(int i=0;i<6;(i%2? a.rotN():a.rotE()),i++)
      for(int j=0;j<4;j++){
        if(val == a.val) return 1;
        a.rotCW();
      }
    return 0;
  }

  void rot(string s){
    if(s == "N" || s == "B") rotN();
    else if(s == "S" || s == "F") rotS();
    else if(s == "E" || s == "R") rotE();
    else if(s == "W" || s == "L") rotW();
    else if(s == "CW") rotCW();
    else if(s == "CCW") rotCCW();
    else assert(!"rot error"); /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
  }

  
  void rot(char ch){rot(string(1,ch));}
  
  //奥に転がす
  void rotN(){
    swap(val[TOP],val[FRONT]);
    swap(val[FRONT],val[BOTTOM]);
    swap(val[BOTTOM],val[BACK]);
  }

  //手前に転がす
  void rotS(){
    //rotN(),rotN(),rotN();
    swap(val[TOP],val[BACK]);
    swap(val[BACK],val[BOTTOM]);
    swap(val[BOTTOM],val[FRONT]);
  }
  
  //右に転がす
  void rotE(){
    swap(val[TOP],val[LEFT]);
    swap(val[LEFT],val[BOTTOM]);
    swap(val[BOTTOM],val[RIGHT]);
  }

  //左に転がす
  void rotW(){
    //rotE(),rotE(),rotE();
    swap(val[TOP],val[RIGHT]);
    swap(val[RIGHT],val[BOTTOM]);
    swap(val[BOTTOM],val[LEFT]);
  }

  //上から見て時計回りに回す
  void rotCW(){
    swap(val[FRONT],val[RIGHT]);
    swap(val[RIGHT],val[BACK]);
    swap(val[BACK],val[LEFT]);
  }

  //上からみて反時計回りに回す。
  void rotCCW(){
    //rotCW(),rotCW(),rotCW();
    swap(val[FRONT],val[LEFT]);
    swap(val[LEFT],val[BACK]);
    swap(val[BACK],val[RIGHT]);
  }

  void init(int top,int front){
    for(int i=0;i<6;(i%2? rotN():rotE()),i++)
      for(int j=0;j<4;j++){
        if(val[TOP] == top && val[FRONT] == front) return;
        rotCW();
      }
    assert(!"can not find");
  }
};

int main(){
  Dice D1,D2;
  for(int i=0;i<6;i++) cin>>D1[i];
  for(int i=0;i<6;i++) cin>>D2[i];
  int ans = D1 == D2;
  cout<<(ans? "Yes":"No")<<endl;
  return 0;
}



Measured memory_bytes: 3168
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
long long x,y,ans=0,sum=0;
int main()
{
    cin>>x>>y;
    sum=y/x;
    while (sum>=1)
    {
        sum/=2;
        ans++;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    vector<char> S(4);
    rep(i, 0, 4) cin >> S.at(i);
    int x = 0;
    rep(i, 0, 4){
        if (S.at(i) == '+') x++;
        else x--;
    }
    cout << x << endl;
}


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

int main() {
	// your code goes here
	int x,n;
	cin>>x>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	int ans,j=0,value =100;
	for(int i=0;i<=101;i++)
	{
		if(a[j]==i and j<n)
		{
			j++;
			continue;
		}
		if(abs(i-x)<value)
		{
			value=abs(i-x);
			ans=i;
		}
 
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a * c, max(a * d, max(b * c, b * d))) << endl;
    return 0;
}

Measured memory_bytes: 3632
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

vector<int> g[100111];

bool incyc[100111];
int len,cyc[100111],n,m;

int sum[100111];
void dfs(int x,int f,int c,LL&ans)
{
	if(c)sum[x]=1;else sum[x]=-1;
	for(auto v:g[x])if(v!=f&&!incyc[v])
	{
		dfs(v,x,c^1,ans);
		sum[x]+=sum[v];
		ans+=abs(sum[v]);
	}
}


namespace cycle
{
	int stk[100111],dep[100111];
	void dfs(int x,int f=0,int d=1)
	{
		dep[x]=d;stk[d]=x;
		for(auto v:g[x])if(v!=f)
		{
			if(!dep[v])dfs(v,x,d+1);
			else if(dep[v]<dep[x])
			{
				for(int i=dep[v];i<=dep[x];i++)
				{
					cyc[++len]=stk[i];
					incyc[stk[i]]=1;
				}
			}
		}
	}
};

int main()
{
	get2(n,m);
	for(int i=1,u,v;i<=m;i++)
	{
		get2(u,v);
		g[u].pb(v);
		g[v].pb(u);
	}
	LL ans=0;
	if(m==n-1)
	{
		dfs(1,0,0,ans);
		if(sum[1])ans=-1;
	}
	else
	{
		cycle::dfs(1);
		int s=0;
		for(int i=1;i<=len;i++)
		{
			dfs(cyc[i],0,i&1,ans);
			s+=sum[cyc[i]];
		}
		if(len%2==1)
		{
			if(s%2!=0)ans=-1;
			else
			{
				sum[cyc[1]]-=s/2;
				sum[cyc[len]]-=s/2;
				ans+=abs(s/2);
				for(int i=1;i<len;i++)
				{
					ans+=abs(sum[cyc[i]]);
					sum[cyc[i+1]]+=sum[cyc[i]];
				}
			}
		}
		else
		{
			if(s!=0)ans=-1;
			else
			{
				int cur=0;
				vector<int>vs;
				for(int i=1;i<=len;i++)
				{
					cur+=sum[cyc[i]];
					vs.pb(cur);
				}
				sort(vs.begin(),vs.end());
				for(int i=0;i<(int)vs.size();i++)
					ans+=abs(vs[i]-vs[len>>1]);
			}
		}
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 14332
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#define ll long long
using namespace std;

vector<int> operate(deque<int> V, int left, int right){
    vector<int> ret;
    for(int i=0; i<left; i++){
        ret.push_back(V.front());
        V.pop_front();
    }
    for(int i=0; i<right; i++){
        ret.push_back(V.back());
        V.pop_back();
    }

    sort(ret.begin(), ret.end());
    return ret;
}

int main(){
    int N, K;
    cin >> N >> K;
    deque<int> V;
    for(int i=0; i<N; i++){
        int v;  cin >> v;
        V.push_back(v);
    }

    int ans = -(1e9+1);
    for(int k=0; k<=min(N,K); k++){
        for(int left=0; left<=k; left++){
            int right = k-left;
            vector<int> take = operate(V, left, right);
            
            int score = accumulate(take.begin(), take.end(), 0);
            for(int i=0; i<min(K-k,k); i++){
                if(take[i]<0){
                    score -= take[i];
                }else{
                    break;
                }
            }
            
            ans = max(ans, score);
        }
    }
    cout << ans << endl;
}


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

const size_t MAX_N = (size_t)1e5 + 5;

int n, pow2, a[MAX_N], tree[2][MAX_N << 2], t;

inline void init() { for (pow2 = 1; pow2 < n; pow2 <<= 1) {} }
template<class UnaryOperation>
inline void push(int* tree, int p, int val, UnaryOperation op) {
    for (tree[p += pow2] = val; p > 1; p >>= 1)
        tree[p >> 1] = op(tree[p], tree[p ^ 1]);
}
template<class UnaryOperation>
inline int rmq(int* tree, int l, int r, int initial, UnaryOperation op) {
    int res = initial;
    for (l += pow2, r += pow2; l < r; l >>= 1, r >>= 1) {
        if (l & 1) res = op(res, tree[l++]);
        if (r & 1) res = op(res, tree[--r]);
    }
    return res;
}

int main() {
    unordered_map<int, int> pos;
    pos.reserve(512);
    pos.max_load_factor(0.25f);
    scanf("%d%d", &n, &t);
    init();
    auto Min = [](int x, int y) -> int { return x < y ? x : y; };
    auto Max = [](int x, int y) -> int { return x > y ? x : y; };
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
        pos[a[i]] = i;
        push(tree[0], i, a[i], Min);
        push(tree[1], i, a[i], Max);
    }
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int en = rmq(tree[1], i, n,           INT_MIN, Max);
        int st = rmq(tree[0], i, pos[en] + 1, INT_MAX, Min);
        mp[en - st]++;
        i = pos[en];
    }
    printf("%d", mp.rbegin()->second);
}

Measured memory_bytes: 13100
object Main extends App {
	val Array(n, t) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	var ans = List[Int]()

	for(i<-0 until n){
		val Array(c, t1) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
		if(t1 <= t) ans =  c :: ans
	}

	if(ans.size == 0) println("TLE")
	else println(ans.min)
}


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

int N,M;
int G[20][20],U[110],V[110],W[110];
int Sum[(1<<15)+5],F[(1<<15)+5][20];

int main()
{
	int i,j,k,s;
	scanf("%d%d",&N,&M);
	for(i=1; i<=M; i++)
	{
		scanf("%d%d%d",&U[i],&V[i],&W[i]);
		U[i]--,V[i]--;
		G[U[i]][V[i]]=G[V[i]][U[i]]=W[i];
	}
	for(i=0; i<1<<N; i++)
		for(j=1; j<=M; j++)
			if(i>>U[j]&1&&i>>V[j]&1)
				Sum[i]+=W[j];
	memset(F,-0x3f,sizeof(F));
	F[1][0]=0;
	for(i=1; i<1<<N; i++)
		for(j=0; j<N; j++)
			if(F[i][j]>=0)
			{
				s=(1<<N)-1-i;
				for(k=s; k; k=(k-1)&s)
					F[i|k][j]=max(F[i|k][j],F[i][j]+Sum[k|1<<j]);
				if(~i>>N-1&1)
					for(k=0; k<N; k++)
						if(~i>>k&1&&G[j][k])
							F[i|1<<k][k]=max(F[i|1<<k][k],F[i][j]+G[j][k]);
			}
	printf("%d\n",Sum[(1<<N)-1]-F[(1<<N)-1][N-1]);
	return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,m; cin >> n >> m;
    VI p(m),y(m);
    VVI ans(n);
    rep(i, m){
        cin >> p[i] >> y[i];
        p[i]--;
        ans[p[i]].push_back(y[i]);
    }
    rep(i,n) SORT(ans[i]);
    rep(i,m){
        cout<< setfill('0') << setw(6) << p[i] + 1;
      	int num = lower_bound(all(ans[p[i]]),y[i]) - ans[p[i]].begin();
        cout<< setfill('0') << setw(6) << num + 1 <<endl;
    }

    return 0;
}




Measured memory_bytes: 9344
import java.util.*

class Vector(p1: Pair<Double, Double>, p2: Pair<Double, Double>) {
    private val x = p2.first - p1.first
    private val y = p2.second - p1.second

    fun cross(other: Vector): Double = this.x * other.y - this.y * other.x
}

fun calc(p1: Pair<Double, Double>, p2: Pair<Double, Double>, p3: Pair<Double, Double>): Boolean {
    val v1 = Vector(p1, p2)
    val v2 = Vector(p2, p3)
    return v1.cross(v2) >= 0
}

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    while (sc.hasNext()) {
        val a = sc.nextLine().split(",").map { it.toDouble() }
        val p = Array(4) { i -> Pair(a[i*2], a[i*2+1]) }
        var flag = true
        for (i in 0..3) {
            for (j in 0..3) {
                for (k in 0..3) {
                    for (l in 0..3) {
                        if (hashSetOf<Int>(i, j, k, l).size != 4) continue
                        if (hashSetOf(calc(p[j], p[i], p[l]), calc(p[k], p[j], p[l]), calc(p[i], p[k], p[l])).size == 1) {
                            //println("$i, $j, $k, ${calc(p[j], p[i], p[l])}, ${calc(p[k], p[j], p[l])}, ${calc(p[i], p[k], p[l])}")
                            flag = false
                        }

                    }
                }
            }
        }
        if (flag) println("YES")
        else println("NO")
    }
}


Measured memory_bytes: 34208
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
int read () {
	int s=0,w=1;
	char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') w=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int A,B,C,i;
int main () {
	A=read();
	B=read();
	C=read();
	for (i=1;i<=100;i++) 
		if (i*A%B==C) {
			puts ("YES");
			return 0;
		}
	puts ("NO");
	return 0;
}

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

int main() {
    int n,k,i,j;
    cin>>n>>k;
    int a[n],dp[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++){
        int x = INT_MAX;
        for(j=i>=k?i-k:0;j<i;j++){
            x = min(x,dp[j]+abs(a[i]-a[j]));
        }
        dp[i] = x;
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

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

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))

using namespace std;

using ll = long long;
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<int> IntList;

typedef struct S{
  int y;
  int x;
  int distance;
} Object;

int main(){
  ll H, W;
  cin >> H >> W;
  char S[H+2][W+2];
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      S[i][j] = '#';
    }
  }
  for(int i=1;i<H+1;i++){
    for(int j=1;j<W+1;j++){
      cin >> S[i][j];
    }
  }
  
  ll ans = 0;
  char S2[H+2][W+2];
  vector<int> x_vec = {-1, 1, 0, 0};
  vector<int> y_vec = {0, 0, -1, 1};
  queue<Object> q;
  for(int i=1;i<H+1;i++){
    for(int j=1;j<W+1;j++){
      if(S[i][j] == '#'){
        continue;
      }
      for(int k=1;k<H+1;k++){
        for(int l=1;l<W+1;l++){
          S2[k][l] = S[k][l];
        }
      }
      Object start = {i, j, 0};
      q.push(start);
      S2[i][j] = '#';
      vector<int> x_vec = {-1, 1, 0, 0};
      vector<int> y_vec = {0, 0, -1, 1};
      while(!q.empty()){
        Object current = q.front();
        q.pop();
        //4方向に
        for(int k=0;k<4;k++){
          if(S2[current.y+y_vec[k]][current.x+x_vec[k]] == '.'){
            Object next = {current.y+y_vec[k], current.x+x_vec[k], current.distance+1};
            q.push(next);
            ans = max(ans, (ll)(next.distance));
            S2[next.y][next.x] = '#';
          }
        }
      }
    }
  }
      
  cout << ans << endl;
}

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

#define FOR( i, m, n )   for( int i = m; i < n; i++ )
#define REP( i, n )      FOR( i, 0, n )
#define ALL( a )         (a).begin(), (a).end()

int main(){
  int n; cin >> n;
  vector<int> a( n ), o ( n );

  int res = 0, mino = 1001, odd = 0;
  REP( i, n ){
    cin >> a[i];
    res += a[i];
    if( a[i] % 2 == 1 ){
      odd++;
      mino = min( mino, a[i] );
    }
    
  }

  
  if( odd % 2 == 1 ) res -= mino;
    

  cout << res / 2 << endl;
}



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

typedef pair<int, int> P;

int n, q;
int fish[1000001];

int main() {
  cin >> n >> q;
  
  priority_queue<P> pq;
  
  for(int i = 0; i < q; i++) {
    int a, v;
    cin >> a >> v;
    fish[a] += v;
    pq.push(P(fish[a], a * (-1)));
    
    while(!pq.empty()) {
      P p = pq.top();
      p.second *= -1;
      if(p.first == fish[p.second]) {
        cout << p.second << ' ' << p.first << endl;
        break;
      }
      pq.pop();
    }
  }

  return 0;
}

Measured memory_bytes: 7660
#include<stdio.h>
int main(void){
  int flg=0,n,c,d,i,fd=0,fdd=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&c,&d);
    if(fdd&&fd&&c==d){
      flg=1;
    }
    fdd=fd;
    fd=c==d;
  }
  if(flg) puts("Yes"); else puts("No");
}

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

int main(){
  int n,m;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    int a;
    cin >> a;
    n-=a;
  }
  if(n>=0)
    cout << n << endl;
  else
    cout << -1 << endl;
}

Measured memory_bytes: 3624