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

int main()
{
    // int N;
    // char S[110], T[110];
    // char ans[220];
    // cin >> N;
    // cin >> S >> T;

    // for(int i=0; i<2*N; i=i+2){
    //     ans[i]=S[i];
    //     ans[i+1]=T[i];
    //     printf("%s\n", ans);
    // };

    // // puts(ans);

    int N;
    char S[100], T[100];
    scanf("%d", &N);
    scanf("%s%s", S, T);
    for(int i=0; i<N; i++) {
        printf("%c%c", S[i],T[i]);
    };
    printf("\n");

    return 0;
}

Measured memory_bytes: 256
import sys

# import bisect
# import numpy as np
from collections import deque
# map(int, sys.stdin.read().split())



def input():
    return sys.stdin.readline().rstrip()


def main():
    N =int(input())
    H = list(map(int,input().split()))

    con = 0
    ans =0
    for i in range(N-1):
        if H[i] >=H[i+1]:
            con +=1
            ans =max(ans,con)
        else:
            con =0

    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 86768
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

long long n,q,p,ip,a[55],ans=1;

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n >> q;
    for(int i=1;i<=n;i++) {cin >> a[i]; if(a[i]%2) ip++; else p++;}
    if(q && !ip){
        cout << 0;
        return 0;
    }
    for(int i=1;i<=p;i++) ans*=2;
    for(int i=1;i<ip;i++) ans*=2;
    cout << ans;
}


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

int main() {
  int N, total;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    total += r - l + 1;
  }
  
  
  cout << total << endl;
}

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

int main(){
	int N, T;
	cin >> N >> T;
// mmax[i] は、A[i+1] ~ A[N-1] の最大
	int A[N], mmax[N-1];
	for(int i=0; i<N; i++) cin >> A[i];
	int m = A[N-1];
	mmax[N-2] = m;
	for(int i=N-3; i>=0; i--){
		if(m < A[i]) m = A[i];
		mmax[i] = m;
	}
	int MAX = mmax[0] - A[0], cnt = 0;
	for(int i=1; i<N-1; i++){
		if(MAX < mmax[i] - A[i]) MAX = mmax[i] - A[i];
	}
	for(int i=0; i<N-1; i++){
		if(mmax[i] - A[i] == MAX) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);

 string a;
 int b,ans1=0,ans2=0,ans3=0,ans4=0,c=0,d=0;
 cin>>a;
 b=a.size();
 for(int i=0;i<b;i++){
   if(a[i]=="N"[0]){
     ans1+=1;
   }
   else if(a[i]=="S"[0]){
     ans2+=1;
   }
   else if(a[i]=="E"[0]){
     ans3+=1;
   }
   else if(a[i]=="W"[0]){
     ans4+=1;
   }
 }
 
 if(ans1>0 && ans2>0){
   c=1;
 }
 else if(ans1==0 && ans2==0){
   c=1;
 }
 else{
   c=0;
 }
 if(ans3>0 && ans4>0){
   d=1;
 }
 else if(ans3==0 && ans4==0){
   d=1;
 }
 else{
   d=0;
 }

 if(d==1 && c==1){
   cout<<"Yes"<<"\n";
 }
 else{
   cout<<"No"<<"\n";
 }

 return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll ans = 1;
    bool flag = false;
    bool zero = false;
    cin >> N;
    rep(i, N) {
        ll prev;
        ll temp;
        cin >> temp;
        prev = ans;
        ans *= temp;
        if(prev > ans || ans > 1000000000000000000) {
            flag = true;
        }
        if(temp == 0) zero = true;
    }
    if(zero) cout << 0 << endl;
    else if(flag) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


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

int main()
{
    int INF = 1e5 + 5;
    int N, M;
    string S;
    cin >> N >> M >> S;

    reverse(S.begin(), S.end());
    vector<int> dp(S.size(), INF);
    int current = 0;
    dp.front() = current;
    queue<int> q;
    q.push(0);
    for (int i = 1; i < S.size(); i++)
    {
        while (q.size() > M)
        {
            q.pop();
        }
        while (q.front() == INF)
        {
            q.pop();
        }
        if (q.empty())
        {
            cout << -1 << endl;
            return 0;
        }
        if (S[i] == '0')
        {
            dp[i] = q.front() + 1;
        }
        q.push(dp[i]);
    }
    reverse(dp.begin(), dp.end());

    current = 0;
    vector<int> ans;
    for (int i = 0; i < dp.size(); i++)
    {
        if (dp[i] == dp[current] - 1)
        {
            ans.push_back(i - current);
            current = i;
        }
    }

    for (int a : ans)
    {
        cout << a << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1528
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
using namespace std;
int main(){
    int a,b;
    while(cin >> a >> b){
        cout << GCD(a,b) << endl;
    }
    return 0;
}


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

using namespace std;

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

#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(a) (int)a.size()

const int MAXN = 200005;
const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, a[MAXN];

struct BigString {
    vector<pii> s;
    int len;
    int alpha;

    BigString(int alpha): alpha(alpha) {
        len = 0;
    }

    void insertBlock(int ch, int siz) {
        if (!s.empty() && ch == s.back().ff)
            s.back().ss += siz;
        else
            s.pb({ch, siz});
        len += siz;
    }

    void cut(int newLen) {
        while (len - s.back().ss >= newLen) {
            len -= s.back().ss;
            s.pop_back();
        }
        s.back().ss -= len - newLen;
        len = newLen;
        //printf("len: %d\n", len);
    }

    bool inc() {
        int removedLen = 0;
        while (!s.empty() && s.back().ff == alpha - 1) {
//            int x = s[i].ss;
//            insertBlock(0, x);
            removedLen += s.back().ss;
            s.pop_back();
        }
        if (s.empty())
            return false;

        if (s.back().ss == 1) {
            ++s.back().ff;
            if (sz(s) > 1 && s[sz(s) - 2].ff == s.back().ff) {
                s.pop_back();
                s.back().ss += 1;
            }
        } else {
            s.back().ss -= 1;
            s.push_back({s.back().ff + 1, 1});
        }
        if (removedLen > 0)
            s.push_back({0, removedLen});

        return true;
    }

    void print() {
        printf("alpha, len: %d %d\n", alpha, len);
        for(pii p: s)
            printf("%d %d\n", p.ff, p.ss);
    }
};

bool check(int alpha) {
//    debug(alpha);
    BigString str(alpha);

    fto(i, 0, n-1) {
        if (a[i] > str.len)
            str.insertBlock(0, a[i] - str.len);
        else {
            str.cut(a[i]);
            if (!str.inc())
                return false;
        }
//        str.print();
//        debug(i);
    }

    return true;
}

int main () {
    scanf("%d", &n);
    fto(i, 0, n-1) scanf("%d", &a[i]);

    int lo = 1, hi = n, res = -1;
    while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (check(mid)) {
            res = mid;
            hi = mid - 1;
        } else lo = mid + 1;
    }

    printf("%d", res);

    return 0;
}


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

int n;
vector<int> v, w, x, y;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<(n+1)/2; ++i){
		v.push_back(i+(n+1)%2);
		w.push_back(n-i);
	}
/*	for(int i=0; i<v.size(); ++i)
		cout << i << " " << v[i] << "\n";
	for(int i=0; i<w.size(); ++i)
		cout << i << " " << w[i] << "\n";
*/	for(int i=0; i<v.size(); ++i)
		for(int j=0; j<v.size(); ++j){
			if(i == j) continue;
			if(v[i] > 0 && v[i] < v[j]){
				x.push_back(v[i]);
				y.push_back(v[j]);
			}
			if(v[i] > 0 && v[i] < w[j]){
				x.push_back(v[i]);
				y.push_back(w[j]);
			}
			if(w[i] > 0 && w[i] < v[i]){
				x.push_back(w[i]);
				y.push_back(v[i]);
			}
			if(w[i] > 0 && w[i] < w[j]){
				x.push_back(w[i]);
				y.push_back(w[j]);
			}
		}
	cout << x.size() << "\n";
	for(int i=0; i<x.size(); ++i)
		cout << x[i] << " " << y[i] << "\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){

  string S;
  cin >> S;
  int d[26] = {0};
  bool a = false;
  
  for(int i = 0;i < S.size();i++){
  d[S.at(i) - '0' - 49]++;  
  }

  for(int i = 0;i < 26;i++){
  if(d[i] == 0){
    cout << char('a' + i) << endl;
    a = true;
    break;
  }
  }

    if(a == false) cout << "None" << endl;
return 0;
  
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
	int n,k;
	cin >> n;
	char s[12];
	cin >> s >> k;
	for (int i = 0; i < n; ++i) {
		if (s[k-1] != s[i]) s[i] = '*';
	}
	
	cout << s << endl;

	return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

const int max_fac = 2 * 1e5;
long long fac[max_fac], finv[max_fac], inv[max_fac];
void ComInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < max_fac; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long Comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ComInit();

  int s;
  cin >> s;

  int max_leng = s / 3 + 1;
  if(s % 3 == 0) max_leng --;

  long long ans = 0;
  for(int i = 1; i <= max_leng; i++){
    int tmp = s;
    int num = i - 1;
    tmp -= 3 * i;

    ans += Comb(tmp + num, num);
    ans %= MOD;
  }

  cout << ans << endl;


  return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < n; ++i) {
    cout << s[i] << t[i];
  }
  cout << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
#define INF (1<<24)
#define MAX_N 3000
struct edge{
  int from,to,cost;
};
struct state{
  int pos,cost;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};

vector<int> v;
vector<edge> G[MAX_N],g;
int N,M,K,d[MAX_N];

void dijkstra(){
  priority_queue< state > Q;
  for(int i=0;i<MAX_N;i++)d[i]=INF;
  for(int i=0;i<K;i++){
    int w=v[i];
    d[w]=0;
    Q.push( (state){w,0} );
  }
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(s.cost>d[s.pos])continue;
    for(int i=0;i<(int)G[s.pos].size();i++){
      edge e=G[s.pos][i];
      if(s.cost+e.cost>=d[e.to])continue;
      d[e.to]=s.cost+e.cost;
      Q.push( (state){e.to,d[e.to]} );
    }
  }
}

void solve(){
  dijkstra();
  double ans=0;
  for(int i=0;i<(int)g.size();i++){
    edge e=g[i];
    double a=d[e.from],b=d[e.to],c=e.cost;
    // a+x==b+c-x>>2x==b+c-a
    double x=(b+c-a)*0.5;
    ans=max(ans,a+x);
  }
  int z=ans+0.5;
  cout<<z<<endl;
}

int main(){
  cin>>N>>M>>K;
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--,b--;
    g.push_back((edge){a,b,c});
    G[a].push_back((edge){a,b,c});
    G[b].push_back((edge){b,a,c});
  }
  for(int i=0;i<K;i++){
    int a;
    cin>>a;
    a--;
    v.push_back(a);
  }
  solve();
  return 0;
}

Measured memory_bytes: 6788
#include<bits/stdc++.h>
using namespace std;
int main()
{	
	string s, t, u;
	int a, b;
	cin>>s>>t>>a>>b>>u;
	if(u==s)
		cout<<a-1<<" "<<b;
	else 
		cout<<a<<" "<<b-1;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main() {
  int N;
  cin >> N;
  priority_queue<P, vector<P>, greater<P>> que;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    que.push(P(a, i));
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    P p = que.top(); que.pop();
    if (i % 2 == 0 && p.second % 2 == 1) {ans++;}
  }
  cout << ans << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005
vi factor[200005];
void seive()
{
    for(ll i=1;i<=200000;i++)
    {
        for(ll j=i;j<=200000;j+=i)
            factor[j].pb(i);
    }
}
int main()
{
    
    ios;
    ll tt=1;
    // cin>>tt;
    seive();
    while(tt--)
    {
        ll i,j,k,l,m,n;
        cin>>n;
        vi v(n+1),aa(n+1,0);
        for(i=1;i<=n;i++)
            cin>>v[i];
        set<ll> s;
        for(i=n;i>=1;i--)
        {
            // cout<<aa[i]<<endl;
            if(aa[i]%2!=v[i])
            {
                s.insert(i);
                for(auto j:factor[i])
                {
                    aa[j]++;
                }
            }
        }
        cout<<s.size()<<endl;
        for(auto i:s)
            cout<<i<<" ";
    }
    return 0;
}

Measured memory_bytes: 42240
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint A, B, C, D; cin >> A >> B >> C >> D;
    cout << max(A * B, C * D) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mp make_pair
#define mm(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define in_edges(m) repp(i, 1, m){ ll a, b; cin >> a >> b; adj[a].pb(b), adj[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define MOD 1000000007
//atoi() = char to int
// stoi() = int to char
//string g(1,"1"); char to string
//f[stoi(g)] = '0';
//cout.precision(14);
//
ll power(ll x,ll y);

int main()
{
	    // freopen("in.txt","r",stdin);
	    // freopen("out","w",stdout);
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	    ll t;t=1;
	    // cin >> t;
	    while(t--)
	    {
			ll x; cin >> x;
			ll j = x/500;
			ll k = x%500;
			 k = k/5;
			cout << k*5+j*1000 <<endl;		
		}
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

	char tmp = S[0];
	for(int i = 1; i < S.length(); ++i){
		if(tmp == S[i]) { cout << "Bad" << endl; return 0; }
		tmp = S[i];
	}

	cout << "Good" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>a>>b>>c;
	cout<<min(a,b)+min(max(a,b),c);
	return 0;
}


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


int main() {

  int n;
  cin>>n;


    vector<vector<int>> data(n, vector<int>(3));
    for(int i=0;i<n;i++){
      cin>>data.at(i).at(0)>>data.at(i).at(1)>>data.at(i).at(2);
    }

    int out_cx,out_cy,out_h;
    for(int cx=0;cx<=100;cx++){
      for(int cy=0;cy<=100;cy++){
        bool flg=false;
        int h,x,y,Hwk;
        bool first=true;
        bool second=false;
        for(int i=0;i<n;i++){
          h=data.at(i).at(2);
          x=data.at(i).at(0);
          y=data.at(i).at(1);
          if(first&&h!=0){
            Hwk=h+abs(x-cx)+abs(y-cy);
            first=false;
            second=true;
          }
          if(second){
            if(max(Hwk-abs(x-cx)-abs(y-cy),0)==h&&Hwk>=1){
              if(i==n-1){
                flg=true;
              }
            }else{
              flg=false;
              break;
            }
          }
          }
        if(flg){
          out_cx=cx;
          out_cy=cy;
          out_h=Hwk;
        }
      }
    }

  cout<<out_cx<<" "<<out_cy<<" "<<out_h<<endl;

  return 0;
}




Measured memory_bytes: 3628
from sys import stdin

class Node(object):
    def __init__(self, parent=None, left=None, right=None):
        self.parent = parent
        self.left = left
        self.right = right

class BinarySearchTree(object):
    def __init__(self):
        self.tree = {}
        self.root = None

    def insert(self, z):
        if not self.tree:
            self.tree[z] = Node(parent=-1)
            self.root = z
        else:
            x = self.root
            while x != None:
                y = x
                if z < x:
                    x = self.tree[x].left
                else:
                    x = self.tree[x].right

            self.tree[z] = Node(parent=y)
            if z < y:
                self.tree[y].left = z
            else:
                self.tree[y].right = z

    def print_nodes(self):
        A = [] # Preorder
        B = [] # Inorder
        def walk_tree(u):
            if u == None:
                return
            r = self.tree[u].right
            l = self.tree[u].left
            A.append(u)
            walk_tree(l)
            B.append(u)
            walk_tree(r)

        walk_tree(self.root)
        print(" ", end="")
        print(*B, sep=" ")
        print(" ", end="")
        print(*A, sep=" ")

def read_and_print_BSTree(bst, n):
    for _ in range(n):
        cmd = stdin.readline().strip().split()
        if cmd[0] == 'insert':
            bst.insert(int(cmd[1]))
        elif cmd[0] == 'print':
            bst.print_nodes()

n = int(input())
bst = BinarySearchTree()
read_and_print_BSTree(bst, n)


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int main() {
   int n;
   cin >> n;
   set<char> s;
   rep (i, n) {
      char c;
      cin >> c;
      s.insert(c);
   }
   if (s.size()==3) {
      puts("Three");
   } else {
      puts("Four");
   }

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(int& a){printf("%d",a);}
void print(long long& a){printf("%lld",a);}
void print(double& a){printf("%.15lf",a);}
template<class T> void print(T& a){cout<<a;}
template<class T> void print(vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(Head& head, Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(T& a){cerr<<a;}
template<class T> void dprint(vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(Head& head, Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int ans=0,a,b,n;
    in(a,b,n);
    for(int i=a;i<=b;i++){
        if(n%i==0)ans++;
    }
    out(ans);
}



Measured memory_bytes: 3216
n = int(input())
w = []
for i in range(n):
    wtemp = input()
    w.append(wtemp)

used = [w[0]]
check = True
for i in range(1,n):
    if w[i] in used:
        check = False
        break
    if w[i-1][-1] != w[i][0]:
        check = False
        break
    else:
        used.append(w[i])
if check:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int m; cin >> m;
    cout << 48 - m << endl;
}

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


int main() {

    int Ca, Cb, Cc, X, Y;
    cin >> Ca >> Cb >> Cc >> X >> Y;
    long long ans = -1;
    for(int c=0; c <= max(X, Y); c++) {
        long long parans = 2 * c * Cc + max(0, X - c) * Ca + max(0, Y - c) * Cb;
        if(ans == -1) {
            ans = parans;
        } else {
            ans = min(ans, parans);
        }
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=20,inf=0x3F3F3F3F;
int n,m,X,A[maxn][maxn],C[maxn],ans=inf,tep[maxn];
int main()
{
	scanf("%d%d%d",&n,&m,&X);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&C[i]);
		for(int j=1;j<=m;j++)
			scanf("%d",&A[i][j]);
	}
	for(int s=1;s<(1<<n);s++)
	{
		int sum=0;memset(tep,0,sizeof(tep));
		for(int i=1;i<=n;i++)
		{
			if(s&(1<<(i-1)))
			{
				sum+=C[i];
				for(int j=1;j<=m;j++) tep[j]+=A[i][j];
			}
		}
		bool suc=true;
		for(int i=1;i<=m;i++) if(tep[i]<X) suc=false;
		if(suc&&sum<ans) ans=sum;
	}
	if(ans==inf) ans=-1;
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    ll n, h, w, ans = 0; cin >> n >> h >> w;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        if (a >= h && b >= w) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod1 = 1e9 + 7;
const int mod2 = 998244353;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)

int N, S, dp[3030][3030], a[3030];

int main()
{
	fast();

	cin >> N >> S;

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

	dp[0][0] = 1;

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j <= S; j++)
		{
			if (j + a[i] <= S)
				dp[i + 1][j + a[i]] = (dp[i][j] + dp[i + 1][j + a[i]]) % mod2;
			dp[i + 1][j] = ((2 * dp[i][j]) % mod2 + dp[i + 1][j]) % mod2;
		}
	}
	cout << dp[N][S] << "\n";
}


Measured memory_bytes: 39100
import java.util.*;
public class Main {
	private static Scanner sc;
    public static void main(String[] args){
    	TreeSet<String> all = new TreeSet<String>();
    	sc = new Scanner(System.in);
    	int a=sc.nextInt();
    	for (int j=0; j<a; j++){
    		String word=sc.next();
    		String [] S = word.split("");

    		for (int i=1; i<S.length; i++){
    			String front =  word.substring(0, i);
    			String revfront = new StringBuffer(front).reverse().toString();
    			String back = word.substring(i,S.length);
    			String revback = new StringBuffer(back).reverse().toString();
    			all.add(front+back);
    			all.add(back+front);
    			all.add(front+revback);
    			all.add(revback+front);
    			all.add(revfront+back);
    			all.add(back+revfront);
    			all.add(revfront+revback);
    			all.add(revback+revfront);
    		}
    		System.out.println(all.size());
    		all.clear();
    	}
    	
    }
}

Measured memory_bytes: 65232
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s_a = [0]
s_b = [0]
for i in range(n):
    s_a.append(s_a[i] + a[i])
for i in range(m):
    s_b.append(s_b[i] + b[i])

ans = 0
tmp = m
for i in range(n+1):
    for j in range(tmp+1)[::-1]:
        if s_a[i] + s_b[j] <= k:
            ans = max(ans, i+j)
            tmp = j
            break
print(ans)

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

set<int> ada;
int n;

int main(){
	scanf("%d",&n);
	while(n--){
		int x;
		scanf("%d",&x);
		if(ada.find(x) == ada.end()) ada.insert(x);
		else ada.erase(x);
	}
	printf("%d\n",ada.size());
	return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,ans;
  cin >> n;
  ans = 1;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin >> s.at(i);
  }
  sort(s.begin(),s.end());
  for(int i=0;i<n-1;i++){
    if(s.at(i) != s.at(i+1)){
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
    
  while(true){
    int H,W;
    cin >> H >>W;
    
    if(H==0 && W==0) break;
    
    for(int i= 0; i < H; i++){
      for(int j=0; j < W; j++){
        if(i==0 || i==H-1||j==0||j==W-1) cout << "#";
        else cout << ".";
        
        if(j==W-1) cout << endl;
      }
    }
    cout << endl;
  }
  
}


Measured memory_bytes: 3008
#include <stdio.h>
#include <string.h>
int main(){
  int a, b;
  char c[2];

  scanf("%d %c %d", &a, c, &b);

  if(c[0] == '+' ){
    printf("%d\n", a + b);
  }else if(c[0] == '-'){
    printf("%d\n", a - b);
  }

}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll x[100001] = {};
int main() {
	ll n, a, b; cin >> n >> a >> b;
	rep(i, 0, n)cin >> x[i];

	ll cost = 0;
	rep(i, 0, n - 1) {
		cost += min((x[i + 1] - x[i])*a, b);
	}
	cout << cost << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    ll n;
    cin >> n;
    ll a, ans = 1, res = 1;
    REP(i, n){
        cin >> a;
        if(a % 2 == 0) res *= 2;
        ans *= 3;
    }
    ans -= res;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
n, t = map(int,input().split())
tl = list(map(int,input().split()))

water = 0
for i in range(1,n):
    diff = tl[i]-tl[i-1]
    if diff <= t:
        water += diff
    else:
        water += t
water += t
print(water)

Measured memory_bytes: 31672
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MOD = 1000000007;
int f[4005][2005];
int n, m, K, i, j, k, ans;
inline void change(int &x)
{
	if (x >= MOD) x -= MOD;
}
int main()
{
	cin >> n >> m >> K;
	int haha = m % (K - 1);
	f[0][0] = 1;
	for(i = 0; i < (m + n - 1) / (K - 1); i ++)
	{
		for(j = 0; j <= m; j ++)
			if (f[i][j])
			{
				for(k = 1; k < K && j + k <= m; k ++)
					f[i + 1][j + k] += f[i][j], change(f[i + 1][j + k]);
			}
			int tt = m % (K - 1);
			while (tt <= m)
			{
				if ((i + 1) * (K - 1) - tt <= n - 1 && ((i + 1) * (K - 1) - tt) % (K - 1) == (n - 1) % (K - 1))
					ans += f[i + 1][tt], change(ans);
				tt += K - 1;
			}
		for(j = 0; j <= m; j ++)
			f[i + 1][j] += f[i][j], change(f[i + 1][j]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 31616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int a, b, c, x;
    cin >> a >> b >> c >> x;
    long long int result = 0;
    REP(i,a+1){
        REP(j,b+1){
            if((x-500*i-100*j)%50==0&&0<=(x-500*i-100*j)/50&&(x-500*i-100*j)/50<=c){
                result++;
            }
        }
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 888
#include <iostream>
using namespace std;
const long long mod = 1e9+7;
int main(void){
    long long N,M;
    cin >> N >> M;
    long long ans = 0;
    long long x;
    if(N*2 <= M){
        ans = N + (M - N * 2) / 4;
    }
    else{
        ans = M / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3192
#include "bits/stdc++.h"
using namespace std;

int main(int argc, char* argv[]){
    int N;
    char S[100];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> S[i];
        if(S[i] == 'Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}

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

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)

int main() {
    int n, m;
    cin >> n >> m;
    int a[n][m] = {};
    int b[m] = {};
    int c[n] = {};

    REP(i, n) {
        REP(j, m) cin >> a[i][j];
    }

    REP(i, m) cin >> b[i];

    REP(i, n) {
        REP(k, m) c[i] += a[i][k] * b[k];
        cout << c[i] << endl;
    }

}

Measured memory_bytes: 3108
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String [] s;
		int sum;
		
		while(true){
			String s1 = sc.next();
			s = new String[s1.length()];
	        sum = 0;
	        
	        for (int i = 0; i < s1.length(); i++) {
	        s[i] = String.valueOf(s1.charAt(i));
	        sum += Integer.valueOf(s[i]);
	        }
	        if(sum == 0){
	        	break;
	        }
	        System.out.println(sum);
	        s1 = new String();
		}
        sc.close();

	}

}


Measured memory_bytes: 26628
#include <bits/stdc++.h>
using namespace std;
template < typename T > std::string to_string( const T& n ){
	std::ostringstream stm ;
	stm << n ;
	return stm.str() ;
}


int main(void){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		if(i%3 == 0||(int)to_string(i).find("3") !=-1) cout << " " << i;
	}
		cout << "\n";
	return 0;
}


Measured memory_bytes: 3164
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string s = Console.ReadLine();
		long ans = 1;
		long mod = 998244353;
		for(var i=1;i<=N;i++){
			ans = ans * i % mod;
		}
		int[]a = new int[3];
		int[]C = new int[N];
		int b = 0;
		int r = 0;
		int g = 0;
		for(var i=0;i<N*3;i++){
			string s1 = s.Substring(i,1);
			if(s1=="R"){
				r++;
				C[r-1]++;
				a[C[r-1]-1]++;
				if(C[r-1]-1==1){
                	for(var j=a[0];j>=a[1];j--){
                      ans = ans * (j-a[1]+1) % mod;
                      break;
                    }
                } else if(C[r-1]-1==2){
                    for(var j=a[1];j>=a[2];j--){
                      ans = ans * (j-a[2]+1) % mod;
                      break;
                    }
                }
			} else if(s1=="G"){
				g++;
				C[g-1]++;
				a[C[g-1]-1]++;
              	if(C[g-1]-1==1){
                	for(var j=a[0];j>=a[1];j--){
                      ans = ans * (j-a[1]+1) % mod;
                      break;
                    }
                } else if(C[g-1]-1==2){
                    for(var j=a[1];j>=a[2];j--){
                      ans = ans * (j-a[2]+1) % mod;
                      break;
                    }
                }
			} else if(s1=="B"){
				b++;
				C[b-1]++;
				a[C[b-1]-1]++;
                 if(C[b-1]-1==1){
                	for(var j=a[0];j>=a[1];j--){
                      ans = ans * (j-a[1]+1) % mod;
                      break;
                    }
                } else if(C[b-1]-1==2){
                    for(var j=a[1];j>=a[2];j--){
                      ans = ans * (j-a[2]+1) % mod;
                      break;
                    }
                }
			}
			//Console.WriteLine(r+" "+g+" "+b);
			//for(int j=0;j<N;j++){
            //  Console.Write(C[j]+" ");
            //}
          	//Console.WriteLine();
          	//for(int j=0;j<3;j++){
           //   Console.Write(a[j]+" ");
           // }
          	//Console.WriteLine(ans);
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 17252
use std::io;
use std::i64;


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}


fn main()
{
    // input
    let s: String = read::<String>();
    let t: String = read::<String>();

    let mut count = 0;
    for v in 0..s.len()
    {
        if (s.as_bytes()[v] != t.as_bytes()[v])
        {
            count = count + 1;
        }

    }

    // output
    println!("{0}", count);
}

Measured memory_bytes: 2568
# -*- coding:utf-8 -*-
import sys


def liner_search(data, targets):
    cnt = 0
    for num in targets:
        if num in data:
            cnt += 1
    return cnt


if __name__ == "__main__":
    data = [val.split() for val in sys.stdin.read().splitlines()]
    print(liner_search(data[1], data[3]))

Measured memory_bytes: 7992
#include <iostream>
#include <unordered_map>
#include <string>

using namespace std;

int main() {
  /* code */
  unordered_map<string, string> func;
  string a = "Sunny";
  string b = "Cloudy";
  string c = "Rainy";
  func[a] = b;
  func[b] = c;
  func[c] = a;

  string input;
  cin >> input;
  cout << func[input] << "\n";

  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int n,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++) {   
    if(i%3==0)printf(" %d",i);    
    else if(i%10==3)printf(" %d",i);
    else if(i/10%10==3)printf(" %d",i);
    else if(i/100%10==3)printf(" %d",i);
    else if(i/1000%10==3)printf(" %d",i);
 }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

#define SENTINEL 1000000000000000000

void merge(long long A[], long long left, long long mid, long long right){
  long long n1, n2, i, j, k;
  long long *L,*R;
  
  n1 = mid-left;
  n2 = right-mid;
  
  L = (long long*)malloc(sizeof(long long) *(n1 + 1));
  R = (long long*)malloc(sizeof(long long) *(n2 + 1));
  
  for(i = 0; i <= n1 - 1; i++){
    L[i] = A[left + i];
  }
  for(j = 0; j <= n2 - 1; j++){
    R[j] = A[mid + j];
  }
  
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  
  i = 0;
  j = 0;
  
  for(k = left; k <= right - 1; k++){
   if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }
    else{
      A[k] = R[j];
      j++;
    }
  }
  free(L);
  free(R);
}

void mergeSort(long long A[], long long left, long long right){
  long long mid;
  
  if(left + 1 < right){
    mid=(left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main(void){

    int N, K;

    scanf("%d%d", &N, &K);

    long long l[N];

    for(int i = 0; i < N; i++){
        scanf("%lld", &l[i]);
    }

    mergeSort(l, 0, N);

    int ans = 0;

    for(int i = N-1; i >= N-K; i--){
        ans += l[i];
    }

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

    return 0;
}

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

#define int int_fast32_t

bool solve()
{
        string S;
        int n;
        int bitsize;
        int cnt = 0;
        int pattern = 0;
        string ans[100050];
        cin >> S;
        if ( S == "#" ) return ( false );
        
        n = S.size();
        bitsize = 1 << n;
        
        for ( int i = 0; i < S.size(); i++ ) {
                if ( S[i] == 'z' ) pattern |= (1 << i);
        }
        
        for ( int i = 0; i < bitsize; i++ ) {
                if ( pattern & i ) continue;
                string T = S;
                int pos[25];
                bool flag = true;
                memset(pos, -1, sizeof(pos));
                for ( int j = n - 1; j >= 0; j-- ) {
                        T[j] += (i >> j) & 1;
                        pos[T[j] - 'b'] = j;
                }
                string save = T;
                for ( int j = 0; j < 25; j++ ) {
                        if ( pos[j] != -1 ) T[pos[j]]--;
                }
                if ( T == S ) ans[cnt++] = save;
        }
        
        sort(ans, ans + cnt);
        cout << cnt << endl;
        
        if ( cnt < 10 ) {
                for ( int i = 0; i < cnt; i++ ) cout << ans[i] << endl;
        } else {
                for ( int i = 0; i < 5; i++ ) cout << ans[i] << endl;
                for ( int i = cnt - 5; i < cnt; i++ ) cout << ans[i] << endl;
        }
        return ( true );
}
signed main()
{
        while ( solve() );
        return ( 0 );
}



Measured memory_bytes: 5060
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int maxn=2000+10,mo=1000000007;
int f[maxn][maxn][3],two[maxn];
int i,j,k,l,t,n,m,ans;
int main(){
	scanf("%d%d",&n,&k);
	two[0]=1;
	fo(i,1,n) two[i]=(ll)two[i-1]*2%mo;
	f[n+1][0][2]=1;
	fd(i,n+1,2){
		fd(j,n,0) (f[i][j][1]+=f[i][j+1][1])%=mo;
		fo(j,0,n)
			fo(t,1,2){
				(f[i-1][j+1][2]+=f[i][j][t])%=mo;
				(f[i-1][j][1]+=f[i][j][t])%=mo;
			}
	}
	ans=f[1][n-k][1];
	ans=(ll)ans*two[max(n-k-1,0)]%mo;
	(ans+=mo)%=mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 47360
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;
const int dx[] = {0, 1};
const int dy[] = {1, 0};

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<int>> dp(h, vector<int>(w, INF));
  if(s[0][0] == '#') dp[0][0] = 1;
  else dp[0][0] = 0;
  rep(i, h)rep(j, w) {
    rep(k, 2) {
      int nx = dx[k] + i;
      int ny = dy[k] + j;
      if (nx < h && ny < w) {
        int nextv = dp[i][j];
        if (s[i][j] == '.' && s[nx][ny] =='#') nextv++;
        chmin(dp[nx][ny], nextv);
      }
    }
  }

  int ans = dp[h - 1][w - 1];
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func add(a, b int) int { return a + b }

func sub(a, b int) int { return a - b }

func main() {
	var s string
	fmt.Scan(&s)
	ops := []func(a, b int) int{add, sub}
	name := []string{"+", "-"}
	a := int(s[0] - '0')
	b := int(s[1] - '0')
	c := int(s[2] - '0')
	d := int(s[3] - '0')
	for i, op1 := range ops {
		for j, op2 := range ops {
			for k, op3 := range ops {
				if op3(op2(op1(a, b), c), d) == 7 {
					fmt.Printf("%d%s%d%s%d%s%d=7\n", a, name[i], b, name[j], c, name[k], d)
					return
				}
			}
		}
	}

}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}



int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n >>k;

	VI x(n);
	rep(i, n) cin >>x[i];
	ll ans = 1LL<<60;
	rep(i, n){
		if(i+k-1 >=n) break;
		ll w = x[i] , w2 = x[i+k-1];
		if(w * w2 >=0) {
			ll cnd = max<ll>(abs(w), abs(w2));
			ans = min(ans, cnd);
		}else{
			ll mn=min<ll>(abs(w), abs(w2));
			ll mx=max<ll>(abs(w), abs(w2));
			ll cnd = mn * 2 + mx;
			ans = min(ans, cnd);
		}
	}
	
	cout <<ans <<"\n";
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807/2;
const int MOD = 1000000007;
const int N_MAX = 100 + 10;
const int K_MAX = pow(10,5)+10;

int N, K;
vector<int> dp(K_MAX, -1);
vector<int> a(N_MAX, -1);

bool dfs(int k) {
  if (k==0) return dp[0] = 0;
  if (dp[k]!=-1) return dp[k];
  int result = 0;
  rep(i, N) if (k>=a[i] && dfs(k-a[i]) == 0 ) result = 1;
  return dp[k] = result;
}

int main() {
  cin >> N >> K;
  rep(i, N) cin >> a[i];

  dfs(K);
  // rep(i, K+1) cout << dp[i] << endl;
  string result;
  if (dp[K]==1) result = "First";
  else result = "Second";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 6912