akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

// 深さ優先探索
vector<bool> seen;
vll score;
void dfs(const Graph &G, int v) {
  seen[v] = true; // v を訪問済にする

  // v から行ける各頂点 next_v について
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue; // next_v が探索済だったらスルー
    score[next_v] += score[v];
    dfs(G, next_v); // 再帰的に探索
  }
}

int main()
{
  int N,Q;
  cin >> N >> Q;
  
  Graph G(N);
  score.assign(N, 0);
  REP(i,N-1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  REP(i,Q){
    int p,x;
    cin >> p >> x;
    p--;
    score[p] += x;
  }
  seen.assign(N,false);
  REP(i,N){
    if(seen[i])continue;
    dfs(G,i);
  }
  for(auto s :score){
    cout << s << " ";
  }
  cout << endl;
}

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

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    
    vector<string> orig(H);
    for(int h=0; h<H; h++) {
        cin >> orig[h];
    }
    
    for(int h=0; h<H; h++) {
        cout << orig[h] << endl;
        cout << orig[h] << endl;
    }



    return 0;
    
}

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

typedef bool B;
typedef long double D;
typedef complex<D> P;
typedef vector<P> VP;
typedef struct {P s,t;} L;
typedef vector<L> VL;
typedef struct {P c;D r;} C;
typedef vector <C> VC;

const D eps=1.0e-10;
const D pi=acos(-1.0);
template<class T> bool operator==(T a, T b){return abs(a-b)< eps;}
template<class T> bool operator< (T a, T b){return a < b-eps;}
template<class T> bool operator<=(T a, T b){return a < b+eps;}
template<class T> int sig(T r) {return (r==0||r==-0) ? 0 : r > 0 ? 1 : -1;}
#define X real()
#define Y imag()

D ip(P a, P b) {return a.X * b.X + a.Y * b.Y;}
D ep(P a, P b) {return a.X * b.Y - a.Y * b.X;}
D sq(D a) {return sqrt(max(a, (D)0));}
P vec(L l){return l.t-l.s;}
inline void input(P &p){D x,y;cin >> x >> y;p={x,y};}
// ???????????¬????????¨???

// ccw
enum CCW{
	LEFT = 1,
	RIGHT = 2,
	BACK = 4,
	FRONT = 8,
	MID = 16,
	ON=FRONT|BACK|MID
};

inline int ccw(P base, P a, P b) {              //???a??¨???b???????????????????????????
	a -= base; b -= base;
	if (ep(a, b) > 0)
		return LEFT;    // counter clockwise
	if (ep(a, b) < 0)
		return RIGHT;   // clockwise
	if (ip(a, b) < 0)
		return BACK;    // b--base--a on line
	if (norm(a) < norm(b))
		return FRONT;   // base--a--b on line
	// otherwise
	return MID;      // base--b--a on line  a??¨b????????????????????????
}

B iver(L a, L b) {return ip(vec(a),vec(b) )== 0.0;}
B ipar(L a, L b) {return ep(vec(a),vec(b) )== 0.0;}


// ??????
P pLL(L a,L b){ return a.s+vec(a)*ep(vec(b),b.s-a.s)/ep(vec(b),vec(a));}


// ?????¨??´?????¨????????¢??£???????????????

B iLL(L a,L b){return !ipar(a,b);}
B eqL(L a,L b){return !iLL(a, b) && ep(vec(a), b.s - a.s)==0;}
B iLS(L a,L b){return sig(ep(vec(a),b.s-a.s))*sig(ep(vec(a),b.t-a.s)) <= 0;}
B iLSs(L a,L b){return sig(ep(vec(a),b.s-a.s))*sig(ep(vec(a),b.t-a.s)) < 0;}
B iSS(L a,L b){
	int cwa = ccw(a.s,a.t, b.s) | ccw(a.s,a.t, b.t);
	int cwb = ccw(b.s,b.t, a.s) | ccw(b.s,b.t, a.t);
	return ((cwa | cwb) & MID) || ((cwa & cwb) == (LEFT | RIGHT));
}
B iSSs(L a,L b) {
	int cwa = ccw(a.s,a.t, b.s) | ccw(a.s,a.t, b.t);
	int cwb = ccw(b.s,b.t, a.s) | ccw(b.s,b.t, a.t);
	return (cwa & cwb) == (LEFT | RIGHT);
}

// ?????¨??´?????¨????????¢??£????????¢

D dLP(L l,P p){return abs( ep(vec(l),p-l.s) )/abs(vec(l));}
D dSP(L s,P p){
	if (sig( ip( vec(s), p - s.s)) <= 0) return abs(p - s.s);
	if (sig( ip(-vec(s), p - s.t)) <= 0) return abs(p - s.t);
	return dLP(s,p);
}
D dLL(L a,L b){ return iLL(a,b)?0:dLP(a,b.s);}
D dLS(L a,L b){ return iLS(a,b)?0:min(dLP(a, b.s),dLP(a, b.t));}
D dSS(L a,L b){ return iSS(a,b)?0:
	min({ dSP(a,b.s),dSP(a,b.t),dSP(b,a.s),dSP(b,a.t)});}


int main(void){
	int q;
	cin >> q;
	cout.precision(10);
	rep(loop,q){
		L line[2];
		rep(i,2){
			input(line[i].s);
			input(line[i].t);
		}
		P ans=pLL(line[0],line[1]);
		cout << fixed << ans.X << " " << ans.Y << endl;
	}
	return 0;
}

Measured memory_bytes: 1296
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#include<numeric>
#include<functional>
#include<random>

using namespace std;
#define ll long long
#define ull unsigned long long
#define rrep(i,m,n) for(ll (i)=(ll)(m);(i)>=(ll)(n);(i)--)
#define rep(i,m,n) for(ll (i)=(ll)(m);i<(ll)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
constexpr long double m_pi = 3.1415926535897932L;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 61;
constexpr long double EPS = 1e-10;
template<typename T> using vector2 = vector<vector<T>>;
template<typename T> using vector3 = vector<vector2<T>>;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

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

	ll n;
	cin >> n;
	vector s(2, vector<string>(n));//元の文字列と反転した文字列
	Array cost(n);
	REP(i, n)cin >> s[0][i] >> cost[i];
	REP(i, n)s[1][i] = s[0][i], reverse(all(s[1][i]));

	//ダイクストラ
	using T = tuple<ll, string, bool>;//コスト、文字列、反転しているかどうか
	map<pair<string, ll>, ll> mp;
	priority_queue<T, vector<T>, greater<T>> que;
	auto push = [&](ll c, string v, ll f) {
		if (mp.count({ v,f }) == 0 || mp[{v, f}] > c)que.push({ c,v,f }), mp[{v, f}] = c;
	};
	ll ans = INF;
	auto pcheck = [&](string& s) {
		REP(i, s.size() / 2)if (s[i] != s[s.size() - 1 - i])return false;
		return true;
	};
	REP(i, n) if(pcheck(s[0][i]) == true)chmin(ans, cost[i]);
	REP(i, n) push(cost[i], s[0][i], 1);
	while (que.size()) {
		auto [c, v, flip] = que.top();
		que.pop();
		if (mp[{v, flip}] < c || ans <= c)continue;
		if (pcheck(v) == true) {
			chmin(ans, c);
			continue;
		}
		REP(i, n) {
			auto check = [&](string a, string b)->string {
				REP(i, min(a.size(), b.size()))if (a[i] != b[i])return "!";
				if (a.size() == b.size())return "";
				else if (a.size() > b.size())return a.substr(b.size());
				else return b.substr(a.size());
			};
			auto ret = check(v, s[flip][i]);
			if (ret == "!")continue;
			else if (ret.size() <= 1)chmin(ans, c + cost[i]);
			else if (v.size() > s[flip][i].size())push(c + cost[i], ret, flip);
			else push(c + cost[i], ret, flip ^ 1);
		}
	}
	if (ans == INF)cout << -1 << "\n";
	else cout << ans << "\n";

	return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int X,Y; cin >> X >> Y;
    cout << X+Y/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int d[100005][3];
int main(){
    memset(d, 0, sizeof(d));
    int n; cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> d[i][0] >> d[i][1] >> d[i][2];
        d[i][0] += max(d[i - 1][1], d[i - 1][2]);
        d[i][1] += max(d[i - 1][0], d[i - 1][2]);
        d[i][2] += max(d[i - 1][1], d[i - 1][0]);
    }
    
    int maxn = -1;
    for(int i = 0; i < 3; ++i){
        if(d[n][i] > maxn) maxn = max(maxn, d[n][i]);
    }
    cout << maxn << endl;
    return 0;
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  while(1){
    cin>>n;
    if(n == 0) break;
    vector<int> x(n);
    arep(i,x) cin>>i;
    sort(all(x));
    int jud = x[n-1];
    if(jud < 2){
      cout<<"NA\n";
      continue;
    }

    int cnt = 0;
    int owa = 0;
    rep(i,0,n){
      if(x[i] == 1){
        ++cnt;
      }
      else if(x[i] >= 2) break;
    }

    auto net = upper_bound(all(x),x[n-1]) - lower_bound(all(x),2);
    cout<<cnt+net+1<<'\n';
  }

  return 0;
}


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

int main(void){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	int cnt = 0;
	rep(i,n) if(a[i] == cnt+1) cnt++;
	int ans = n-cnt;
	if(cnt == 0) ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  int N,i;
  bool p=false,w=false,g=false,y=false;
  cin >> N;
  for(i=0;i<N;i++){
    S = "";
    cin >> S;
 	if(S == "P"){
        p = true;
    }else if(S == "W"){
        w = true;
    }else if(S == "G"){
        g = true;
    }else if(S == "Y"){
        y = true;
    }
  }
  if(p && w && g && y ){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
  
}
  

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
int main(){
  ll i,j,N,M,a,b,ans=0;
  cin>>N>>M>>a>>b;
  rep(i,N){
    if(i<b){
      rep(j,M){
        if(j<a){
          cout<<0;
        }else{
          cout<<1;
        }
        if(j<M-1){
          
        }else{
          cout<<endl;
        }
      }
    }else{
      rep(j,M){
        if(j<a){
          cout<<1;
        }else{
          cout<<0;
        }
        if(j<M-1){
          
        }else{
          cout<<endl;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  double W, H, x, y;
  cin>>W>>H>>x>>y;

  double ans = (H * W) / 2;
  if(W/2 == x && H/2 == y) cout<<ans<<" "<<1<<endl;
  else cout<<ans<<" "<<0<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#define rep(i,j,k) for(register int i = j; i <= k; i++) 
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define fi first
#define se second
//#define P pair<ull,ull>
//#define PP pair<int,pair<int,int> >
//#define mp(a,b) make_pair(a,b)
#define ll long long
#define ull unsigned long long
using namespace std;
 
inline int read() { 
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;
}

const int N = 2e5+5;
int n, m, v[N], g[N]; 

inline bool check(int x) { 
	rep(i,1,m) g[i] = v[i] >= x;
	rep(i,1,n-1) { 
		if( g[n-i] == g[n-i+1] ) return g[n-i];
		if( g[n+i] == g[n+i-1] ) return g[n+i]; 
	}
	return g[1];
}

int main() {
	n = read(), m = (n-1) << 1 | 1; 
	rep(i,1,m) v[i] = read();
	int l = 1, r = m, mid;
	while( l < r ) { 
		mid = (l + r + 1) >> 1;
		if( check(mid) ) l = mid;
		else r = mid - 1;
	} cout<<l<<endl;
	return 0; 
}

Measured memory_bytes: 1792
sub f{my$i=pop;$p[$i]=$p[$i]-$i?f($p[$i]//=$i):$i}@s=(1)x<>;map{unshift@a,@s*$#s/2-$%;$%+=$s[$A]*$s[$B],$s[$p[$A]=$B]+=$s[$A]if($A=f$`-/ /)-($B=f$'-1)}reverse<>;print"@a"

Measured memory_bytes: 37760
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define PI 3.14159265359

int main(){
    int w, h, n; cin >> w >> h >> n;
    vector<int>x(n), y(n), a(n);
    int under_x=0, under_y=0;
    int over_x=w, over_y=h;

    rep(i,n) cin >> x[i] >> y[i] >> a[i];

    rep(i, n){
        if(a[i] == 1 and under_x<x[i]){
            under_x = x[i];
        }else if(a[i] == 2 and over_x>x[i]){
            over_x = x[i];
        }else if(a[i] == 3 and under_y<y[i]){
            under_y = y[i];
        }else if(a[i] == 4 and over_y>y[i]){
            over_y = y[i];
        }
    }
    if(over_x - under_x <= 0 || over_y - under_y <= 0){
        cout << 0 << endl;
    }else{
        cout << (over_x - under_x) * (over_y - under_y) << endl;
    }
    return 0;
}


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

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin >> l.at(i);
    }
    sort(l.begin(),l.end());
    int total=0;
    for(int i=n-1;i>=n-k;i--){
        total += l.at(i);
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#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); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N;
vector<int> A;

int main(){
  cin >> N;
  A.resize(N+1);
  REP(i, N){
    cin >> A[i];
  }
  A[N] = -1;
  ll ans = 0;
  bool flag = true;
  REPR(i, N-1){
    if(A[i] > i){
      flag = false;
      break;
    }
    if(A[i+1] <= A[i]){
      ans += A[i];
    }
    else if(A[i] + 1 == A[i+1]){

    }
    else{
      flag = false;
      break;
    }
  }
  if(flag){
    cout << ans << endl;
  }
  else{
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextInt(), sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N-1; i++ {
		a, b := sc.nextInt()-1, sc.nextInt()-1
		G[a] = append(G[a], b)
		G[b] = append(G[b], a)
	}
	sib := make([]int, N)
	done := make([]bool, N)
	ans := K
	var dfs func(cur, p int)
	dfs = func(cur, p int) {
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if done[next] {
				continue
			}
			//fmt.Fprintln(wtr, cur+1, next+1, p, sib[cur])
			ans *= max(K-p-sib[cur], 0)
			ans %= MOD
			np := p
			if p == 0 || p == 1 {
				np++
			}
			done[next] = true
			sib[cur]++
			dfs(next, np)
		}
	}
	done[0] = true
	dfs(0, 1)

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 57088
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();
    int Y = sc.nextInt();

    sc.close(); 

    long sum = 0;

    if ((C * 2) <= (A + B)) {
      if (X < Y) {
        sum += C * 2 * X;
        if (C * 2 < B) {
          sum += C * (Y - X) * 2;
        } else {
          sum += B * (Y - X);
        }
      } else {
        sum += C * 2 * Y;
        if (C * 2 < A) {
          sum += C * (X - Y) * 2;
        } else {
          sum += A * (X - Y);
        }
      }
    } else {
      sum += X * A;
      sum += Y * B;
    }

    System.out.println(sum);
  
  }

}

Measured memory_bytes: 23124
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);


	int N, M; cin >> N >> M;
	vector<int>A(N), B(N); rep(i, 0, N) { cin >> A[i] >> B[i]; }

	vector<vector<int>>v(M);
	rep(i, 0, N) {
		if (M - A[i] >= 0) {
			v[M - A[i]].eb(B[i]);
		}
	}

	int ans = 0;
	priority_queue < int, vector<int>, less<int >> pq;

	rrep(i, 0, M) {
		while (v[i].size()) {
			pq.push(v[i].back());
			v[i].pop_back();
		}
		if (pq.size()) {
			ans += pq.top();
			pq.pop();
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 7168
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(void) {
	int x, a, b;
	scanf("%d %d %d", &x, &a, &b);
	printf(abs(x - a) < abs(x - b) ? "A\n" : "B\n");
	return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

int main() {
    int y,m,d;
    scanf("%d/%d/%d",&y,&m,&d);
    string ans = "Heisei";
    if (y>2019 || (y<=2019&&m>4) ) ans = "TBD";

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl


int main(){
  int a, b;
  cin >> a >> b;
  string ans;
  int cnt = b-a+1;
  if(a > 0) ans = "Positive";
  else if(b >= 0) ans = "Zero";
  else if(cnt%2 == 0) ans ="Positive";
  else ans = "Negative";
  cout << ans << endl;
}


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

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var ans = n / 1000;
        if (n % 1000 != 0)
        {
            ans++;
        }
        Console.WriteLine(ans * 1000 - n);
    }
}

Measured memory_bytes: 27536
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;

int main(){
      int n,h,w;
      cin>>n>>h>>w;
      cout<<(n-h+1)*(n-w+1)<<endl;
      return 0;
}

Measured memory_bytes: 256
import sys
import math
al=0
bl=0
cl=0
dl=0
ar=0
br=0
cr=0
dr=0
try:
    while True:
        l,r=map(float,input().split())
        if(l>=1.1):
            al=al+1
        elif(l>=0.6 and l<1.1):
            bl=bl+1
        elif(l>=0.2 and l<0.6):
            cl=cl+1
        else:
            dl=dl+1
        if(r>=1.1):
            ar=ar+1
        elif(r>=0.6 and r<1.1):
            br=br+1
        elif(r>=0.2 and r<0.6):
            cr=cr+1
        else:
            dr=dr+1
except EOFError:
    pass
print(str(al)+' '+str(ar))
print(str(bl)+' '+str(br))
print(str(cl)+' '+str(cr))
print(str(dl)+' '+str(dr))


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

#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007

ll power(ll a,ll b){ll ans=1;while(b>0){if(b&1){ans = (ans*a);}b>>=1;a=a*a;}return ans;}
ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);}

int main() {
   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   // cout << fixed << setprecision(10);
   ll x;
   cin>>x;
   if(x%1000 == 0){
       cout<<0<<endl;
   }else{
       ll y=x/1000;
       ll p=(y+1)*1000 - x;
       cout<<p<<endl;
   }
	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int dp[3001][3001];



int lenlcs(string &s,string &t,int i,int j)
{
    int n=s.size();
    int m=t.size();
    if(i>=n || j>=m)
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];

    else
    {
        if(s[i]==t[j])
        return dp[i][j]=1+lenlcs(s,t,i+1,j+1);

        else{
            int x=lenlcs(s,t,i,j+1);
            int y=lenlcs(s,t,i+1,j);
            return dp[i][j]=max(x,y);
        }
    }

}
string solve(string &s,string &t)
{
    memset(dp,-1,sizeof dp);
    int len=lenlcs(s,t,0,0);
    string ans;
    if(len==0)
        return ans;
        int i=0,j=0;
        while(len>0)
        {
           if(s[i]==t[j])
           {
               len--;
               ans.push_back(s[i]);
               i++;
               j++;


           }
           else
           {
               if(dp[i][j+1]>dp[i+1][j])
                j++;
               else
                i++;

           }

        }
        return ans;

}

int main()
{

    string s,t;
    cin>>s;
    cin>>t;
    cout<<solve(s,t);

    return 0;

}


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

#define MAX 100010

struct NODE {
	int num;
	struct NODE* next;
	struct NODE* prev;
};

struct NODE SNS[MAX];

int d[MAX] = { 0 };

void Add(int Lperson, int Rperson) {
	struct NODE* addition = (struct NODE*)malloc(sizeof(struct NODE));
	struct NODE* prim = SNS[Lperson].next;
	SNS[Lperson].next = addition;
	addition->prev = &SNS[Lperson];
	addition->next = prim;
	if (prim != NULL) prim->prev = addition;
	addition->num = Rperson;
}

void FandC(int L, int cnt) {
	struct NODE* run = &SNS[L];
	while (run != NULL) {
		if (d[run->num] != cnt) {
			d[run->num] = cnt;
			if (run->prev != NULL)FandC(run->num, cnt);
		}
		run = run->next;
	}
}

int main() {
	int n, m, q;
	int Lperson, Rperson;
	for (int i = 0; i < MAX; i++) {
		SNS[i].num = i;
		SNS[i].next = NULL;
		SNS[i].prev = NULL;
	}
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &Lperson, &Rperson);
		Add(Lperson, Rperson);
		Add(Rperson, Lperson);
	}
	for (int i = 0; i < n; i++) {
		if (d[i] == 0)FandC(i, i + 1);
	}
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		scanf("%d %d", &Lperson, &Rperson);
		if (d[Lperson] == d[Rperson])printf("yes\n");
		else printf("no\n");
	}

	return 0;
}


Measured memory_bytes: 13756
//おまじないc++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
 
int main() {
int n;
  cin>>n;
  vector<int> t(n);
  vector<string> s(n);
    rep(i,n){
      cin>>s.at(i)>>t.at(i);
    }
  string x;
  cin>>x;
  
  int num;
  for( num=0;num<n;num++){
    if(x==s.at(num)){
      break;
    }
  }
  int sum=0;
  for(int i=num+1;i<n;i++){
    sum+=t.at(i);
  }
  
  cout<<sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int c,b,a,re;
    cin>>a>>b>>c;
    re=(a+b+c);
    if(re>=22){
        cout<<"bust"<<endl;
    }

    else{
        cout<<"win"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define MAX 100
#define MIN 1

int selection_sort(int A[MAX], int N) {
  int count = 0;

  for (int i = 0; i < N; i++) {
    int minj = i;
    for (int j = i; j < N; j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    if (i != minj) {
      swap(A[i], A[minj]);
      count++;
    }
  }

  return count;
}

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

  int count = selection_sort(A, N);

  for (int i = 0; i < N; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << A[i];
  }
  cout << endl;

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3104
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()[:-1]
from heapq import *

def dfs(s, es):
    dist = [None] * len(es)
    dist[s] = 0
    def ret(v, d):
        for u, c in es[v]:
            if dist[u] == None:
                dist[u] = dist[v] + c
                ret(u, dist[u])
    ret(s, 0)
    return dist
  
N = int(input())
es = [[] for i in range(N+1)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    es[a].append((b, c))
    es[b].append((a, c))
Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(Q)]
dist = dfs(K, es)
for i in range(Q):
    print(dist[xy[i][0]] + dist[xy[i][1]])


Measured memory_bytes: 174864
#include<stdio.h>
int main(){
  int n,a[100001],i,k=0;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &a[i]);
  }
  for(i=0; i<n+1; i++){
    k=a[k]-1;
    if(k==1){
      printf("%d\n",i+1);
      return 0;
    }
  }

  printf("-1\n");
  return 0;
}

Measured memory_bytes: 512
N = int(input())
A = sorted([int(x) for x in input().split()])
ans, p = 0, 0
for i in range(N):
    p = i
    if A[i] >= 0:
        break
for i in range(N):
    if i < p:
        ans -= A[i]
    else:
        ans += A[i]
if p % 2 != 0:
    ans += max(2*A[p-1],-2*A[p])
print(ans)


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

int main(void){

    int N, C;

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

    int s[N], t[N], c[N];

    for(int i = 0; i < N; i++){
        scanf("%d%d%d", &s[i], &t[i], &c[i]);
    }

    int sm[200002], tt[200002];

    for(int i = 0; i < 200002; i++){
        sm[i] = 0;
    }

    for(int i = 1; i <= C; i++){
        for(int j = 0; j < 200002; j++){
            tt[j] = 0;
        }
        for(int j = 0; j < N; j++){
            if(c[j] == i){
                tt[s[j] * 2 - 1]++;
                tt[t[j] * 2]--;
            }
        }
        for(int j = 1; j < 200002; j++){
            tt[j] += tt[j-1];
        }
        for(int j = 0; j < 200002; j++){
            if(tt[j] > 0){
                sm[j]++;
            }
        }
    }

    int max = 0;
    for(int i = 0; i < 200002; i++){
        if(max < sm[i]){
            max = sm[i];
        }
    }

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

    return 0;
}

Measured memory_bytes: 4460
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;

int main(){
     
    int a,b;
    
    cin>>a>>b;
    cout<<(a+b)%24<<endl;
     
    return 0;
}
 

Measured memory_bytes: 256
import java.io.*;
 
class Main {
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
        
            int w = Integer.parseInt(br.readLine());
            int[] amida = new int[w+1];
            amida[0]=0;
            for(int i=0; i<=w; i++){
                amida[i] = i;
            }
            int a,b;
            int temp;
            int n = Integer.parseInt(br.readLine());
            for(int i=0; i<n; i++){
                String[] values = br.readLine().split(",");
                a = Integer.parseInt(values[0]);
                b = Integer.parseInt(values[1]);
                 
                temp = amida[a];
                amida[a] = amida[b];
                amida[b] = temp;
            }
             
            for(int i=1; i<=w; i++){
                System.out.println(amida[i]);
            }
             
         
         
    }
}

Measured memory_bytes: 16920
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
bool cmpl(pair<int,int>p1,pair<int,int>p2){
    return p1.first<p2.first;
}
bool cmpr(pair<int,int>p1,pair<int,int>p2){
    return p1.second>p2.second;
}
void solve()
{
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<pair<int,int>>left,right;
    for(int u=0;u<N;u++){
        string s;
        cin>>s;
        string t;
        int tl=0,tr=0;
        for(char c:s){
            if(t.size()==0){
                t.push_back(c);
                if(c=='(')tl++;
                else tr++;
            }
            else {
                if(t.back()=='('&&c==')'){
                    t.pop_back();
                    tl--;
                }
                else {
                    t.push_back(c);
                    if(c=='(')tl++;
                    else tr++;
                }
            }
        }
        if(tl>tr)
            left.push_back({tr,tl});
        else right.push_back({tr,tl});
    }
    sort(left.begin(),left.end(),cmpl);
    sort(right.begin(),right.end(),cmpr);
    int instk=0;
    for(auto p:left){
        instk-=p.first;
        if(instk<0){
            cout<<"No\n";
            return;
        }
        instk+=p.second;
    }
    for(auto p:right){
        instk-=p.first;
        if(instk<0){
            cout<<"No\n";
            return;
        }
        instk+=p.second;
    }
    if(instk==0)cout<<"Yes\n";
    else cout<<"No\n";
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 11172
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

void solve(){
    ll n, k;
    cin >> n >> k;
    ll a[n];
    rep(i, n)
    {
        cin >> a[i];
    }
    ll ans = 0, mx = 0, mn = INF;
    rep(i, n)
    {
        if(2*a[i] < (1+k)){
            ans += a[i]*2;
        }
        else ans += (k-a[i])*2;
    }
    cout << ans;
}
main(){
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>//accumulate(v.begin(), v.end(), 0);
#include <algorithm>//sort(v.begin(),v.end());
#include <string>//
#include <cmath>
#include <iomanip> //setprecision(2)
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
        int k,n;
        cin >> n >> k;
        if(n%2==0) {
                if(n/2>=k) cout << "YES"<<endl;
                else cout << "NO" <<endl;
        }else{
                if(n/2+1>=k) cout << "YES"<<endl;
                else cout << "NO" <<endl;
        }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int a[3];

  for(int i=0;i<3;i++) scanf("%d", a+i);

  sort(a, a+3);

  cout << a[2] - a[1] + a[1] - a[0] << endl;

  return 0;
}


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

class Program {
    static string ReadLine() { return Console.ReadLine(); }
    static int ReadInt() { return int.Parse(ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }

    static void Main() {
        var nl = ReadInts();
        int n = nl[0];
        var xs = new List<string>();
        for (int i = 0; i < n; i++) {
            xs.Add(ReadLine());
        }
        xs.Sort();
        foreach (var x in xs) {
            Console.Write(x);
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 3288
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val array = readLine()!!.split(" ").map(String::toInt).toMutableList()
    if (n != array.size) return

    var count = 0
    var i = 1
    while (array.size - i > 0) {
        (1..(array.size - i)).forEach { index ->
            val num = array.size - index
            if (array[num] < array[num - 1]) {
                val temp = array[num]
                array[num] = array[num - 1]
                array[num - 1] = temp
                count++
            }
        }
        i++
    }

    array.forEachIndexed { index, num ->
        if (index == array.size - 1) println(num.toString()) else print(num.toString() + " ")
    }
    println(count)
}


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

int main() {
  int K;
  cin >> K;
  if (K % 2) {
    cout << (K/2) * (K/2 + 1) << endl;
  } else {
    cout << (K/2) * (K/2) << endl;
  }
}

Measured memory_bytes: 256
(let* ((s (read-line))
    (readt (read-line))
    (l (length s))
    (ans 0))

    (loop for i from 1 to l do
        (if (not (equal (subseq s (- i 1) i) (subseq readt (- i 1) i)))
            (incf ans)
        )
    )
    (princ ans)
)

Measured memory_bytes: 42056
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var k = 38;
  var n = k*k-k+1;
  var ans = xArray("[]",n);
  for(var i = 0; i < k; i++){
    ans[i].push(1);
    for(var j = 2; j <= k; j++){
      ans[i].push(i*(k-1)+j);
    }
  }
  for(var i = 1; i < k; i++){
    for(var j = 1; j < k; j++){
      var y = j + i*(k-1);
      var p = k+1;
      var q = j-1;
      ans[y].push(i+1);
      for(var x = 1; x < k; x++){
        ans[y].push(p+q);
        p += k-1;
        q += i-1;
        q %= k-1;
      }
    }
  }
  console.log(n,k);
  return ans.map(a=>a.join(" ")).join("\n");
}

Measured memory_bytes: 34136
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i,0,n) cin >> x[i];

    ll c(0);
    rep(i,0,n-1)
    {
        ll t = a*(x[i+1]-x[i]);

        if (t>b) 
            c+=b;
        else 
            c+=t;

        //cout << t << ' ' << c << endl;
    }

    cout << c << endl;

    return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >    

using namespace std;   


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

	    ll n, k=0, arr[1000001];
	    cin>>n;
	    for(int i=0;i<n;i++) cin>>arr[i];
	    
  		for(int i=1;i<n;i++) {
          k += max(arr[i-1], arr[i]) - arr[i];
          arr[i] = max(arr[i-1], arr[i]);
        }
		cout<<k<<endl;
	return 0;
}

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

int main() {
  int N, tmp, sum = 0;
  cin >> N;
  tmp = N;
  while(tmp != 0) {
    sum += tmp % 10;
    tmp /= 10;
  }
  if(N % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3596
# -*- coding: utf-8 -*-

import numpy as np
import itertools as it

# Nの町

# 入力
# N
# x1 y1
# ...
# xn yn

N = int(input())
townpoints = np.empty((N, 2), dtype=np.int16)
distances = np.empty((N, N))

for i in range(N):
    line = input()
    townpoints[i] = list(map(int, line.split(' ')))

xx, xy = np.meshgrid(townpoints[:, 0], townpoints[:, 0])
yx, yy = np.meshgrid(townpoints[:, 1], townpoints[:, 1])

xdist = (xx - xy) ** 2
ydist = (yx - yy) ** 2

distances = (xdist+ydist)**0.5

# [(1,2,3), (2,1,3), ... ] all visit orders
orders = list(it.permutations(list(range(N))))

distance_list = np.empty((len(orders)))

for n, i in enumerate(orders):
    dist_tmp = 0
    for j in range(N-1):
        dist_tmp += distances[i[j], i[j+1]]
    distance_list[n] = dist_tmp

avg = distance_list.sum()/len(distance_list)

print(avg)

Measured memory_bytes: 17256