akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define mod 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

using namespace std;

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

int main(){
    int N;
    int W[100];
    cin>>N;
    rep(i,0,N)cin>>W[i];
    int a=0,b=0;
    int ans=100000000;
    int S[101]={};
    S[0]=W[0];
    rep(i,1,N){
        S[i]=S[i-1]+W[i];
    }
    rep(i,0,N-1){
        ans=min(ans,abs(S[N-1]-2*S[i]));
    }
    cout<<ans;
    return 0;
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  int n, k;
  cin >> n >> k;
  vector <LL> h (n + 1);
  for (int i = 1; i <= n; i++) cin >> h[i];
  vector <LL> dp (n + 1, INF);
  dp[1] = 0;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i - j >= 1) dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  cout << dp[n] << endl;
  return 0;
}


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

int main()
{
	int N, L;
	cin >> N >> L;
	vector<string> ss;
	string tmp;
	ss.reserve(N);
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		ss.push_back(tmp);
	}
	sort(ss.begin(),ss.end());
	string res;
	for (int i = 0; i < N; i++) {
		res += ss[i];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<tuple>
#include<set>
#include<map>
#include<cctype>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
ll N,M;
ll ans;
int main(void) {
	cin >> N >> M;
	if (N == 1 && M == 1)ct(1);
	else if (N == 1)ct(M - 2);
	else if (M == 1)ct(N - 2);
	else ct((N - 2)*(M - 2));
	
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

bool H[10000 + 3] = { false };

int main()
{
    int h, w;
    cin >> h >> w;

    Vs G(h);
    rep(i, h)  cin >> G[i];
    
    int sx = 0, sy = 0;
    // BFS のためのデータ構造
    Vii dist(h, Vi(w, -1)); // 全頂点を「未訪問」に初期化
    queue<the> que;
   
    // 初期条件 (頂点 0 を初期ノードとする)
    dist[sx][sy] = 0;
    que.push({ sx,sy });

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        the v = que.front(); // キューから先頭頂点を取り出す
        que.pop();
        // v から辿れる頂点をすべて調べる
        rep(i, 4) {
            the nv = { v.first + dx[i],v.second + dy[i] };
            if (nv.first < 0 || nv.first >= h || nv.second < 0 || nv.second >= w)  continue;
            if (dist[nv.first][nv.second] != -1)  continue;
            if (G[nv.first][nv.second] == '#')  continue;
            dist[nv.first][nv.second] = dist[v.first][v.second] + 1;
            que.push(nv);
        }
    }

    int cntw = 0;
    rep(i, h) {
        rep(j, w) {
            if (G[i][j] == '.')  cntw++;
        }
    }

    if (dist[h - 1][w - 1] != -1) {
        cout << cntw - dist[h - 1][w - 1] - 1 << endl;
    }
    else {
        cout << -1 << endl;
    }
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long long LL;
#define REP(i,N) for (int i=0; i<N; i++)

int main() {
  int N, ans = 0, left, right;
  int p[100000]={0};

  cin >> N;
  REP(i, N) {
    cin >> p[i];
  }
  if (p[N-1] == N) {
    ans++;
    left = p[N-2];
    right = p[N-1];
    p[N-2] = right;
    p[N-1] = left;
  }
  for (int i = 0; i < N - 1; i++) {
    if (p[i] == i+1) {
      ans++;
      left = p[i];
      right = p[i+1];
      p[i] = right;
      p[i+1] = left;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// import java.text.DecimalFormat; 
// import java.text.DecimalFormatSymbols; 
 
 
// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
 
public class Main {
    
    public static void main(String args[] ) throws Exception {
        /* Sample code to perform I/O:
         * Use either of these methods for input
 
        //BufferedReader
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String name = br.readLine();                // Reading input from STDIN
        System.out.println("Hi, " + name + ".");    // Writing output to STDOUT
 
        //Scanner
        Scanner s = new Scanner(System.in);
        String name = s.nextLine();                 // Reading input from STDIN
        System.out.println("Hi, " + name + ".");    // Writing output to STDOUT
        
        for Round off
         DecimalFormat deciFormat = new DecimalFormat(); 
        deciFormat.setMaximumFractionDigits(9); 
        */
 
        // Write your code here
        StringBuffer str = new StringBuffer();
        PrintWriter pw=new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int T =Integer.parseInt(br.readLine());
        int ans=0;
        if(T%1000!=0)
            ans = 1000- T%1000;
        str.append(ans);
        pw.print(str.toString());
        pw.close();
    }
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    
}

Measured memory_bytes: 32680
#include <iostream>
#include <string>

using std::string;
using std::cout;
using std::cin;
using ull = unsigned long long;
int main(){
    ull a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k<=a){
        cout << k << "\n";
    }else if(k<=a+b){
        cout << a << "\n";
    }else{
        cout << (long long)(2*a+b-k) << "\n";
    }
    return 0;
}

Measured memory_bytes: 3636
from operator import itemgetter

if __name__ == '__main__':
    n = int(input())
    input_list = [input() for i in range(n)]
    restaurant_list = []
    for index, _input in enumerate(input_list):
        _restaurant_data = {'id': index + 1, 'region': _input.split()[0], 'point': int(_input.split()[1])}
        restaurant_list.append(_restaurant_data)

    restaurant_list.sort(key=itemgetter('point'), reverse=True)
    restaurant_list.sort(key=itemgetter('region'))
    for restaurant in restaurant_list:
        print(restaurant['id'])


Measured memory_bytes: 3060
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0

X = 0
for i in range(40, -1, -1):
    if X | (1 << i) > K:
        continue
    cnt = 0
    for j in range(N):
        if A[j] & (1 << i) == 0:
            cnt += 1
    if cnt > N - cnt:
        X |= (1 << i)

ans = 0
for i in range(N):
    ans += X ^ A[i]

print(ans)


Measured memory_bytes: 14588
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)


//template functions
/////////////////////////
long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}
long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}
/////////////////////////



//Answer


int main() {
long N;
int X;
cin>>N;
X=(2200-(N+1))/200;

cout<<X<<endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;
    int n = int(s.size());
    for (int i = 0; i < n; i++) {
        if (s[i] != t[n - i - 1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


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

int main() {
  int N;
  cin >> N;

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  vector<long long> S(N);
  S.at(0) = A.at(0);
  for (int i = 1; i < N; i++) {
    S.at(i) = S.at(i-1) + A.at(i);
  }
  sort(S.begin(), S.end());

  long long ans = 0, count;
  if (S.at(0) == 0) {
    count = 0;
  } else {
    count = 1;
  }
  long long prev = 0, now;
  for (int i = 0; i < N; i++) {
    now = S.at(i);
    if (now == 0) ans++;
    if (prev == now) {
      count++;
    } else {
      ans += count * (count - 1) / 2;
      count = 1;
    }
    prev = now;
  }
  ans += count * (count - 1) / 2;
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define maxn 530100
#define mod 924844033
using namespace std;
struct edge{int r,nxt;}e[maxn<<1];
int n,esz,head[maxn],siz[maxn],h[maxn],fac[maxn],inv[maxn];
int anses[maxn],A[maxn],B[maxn],bh[maxn],C[maxn],D[maxn];
int qpow(int a,int b){
	int ans=1,tmp=a;
	for(;b;b>>=1,tmp=1ll*tmp*tmp%mod)
		if(b&1)ans=1ll*ans*tmp%mod;
	return ans;
}
void addedge(int u,int v){
	e[++esz].r=v;e[esz].nxt=head[u];head[u]=esz;
	e[++esz].r=u;e[esz].nxt=head[v];head[v]=esz;
}
void dfs(int u,int f){
	siz[u]=1;
	for(int t=head[u];t;t=e[t].nxt)if(e[t].r!=f)
		dfs(e[t].r,u),siz[u]+=siz[e[t].r];
}
int getC(int x,int y){
	if(x>y||x<0)return 0;
	return 1ll*fac[y]*inv[x]%mod*inv[y-x]%mod;
}
void fft(int h[],int len,int flag){
	for(int i=0;i<len;++i)if(bh[i]>i)swap(h[i],h[bh[i]]);
	for(int i=1;i<len;i<<=1){
		int wn=qpow(5,(flag==-1?(mod-1)-(mod-1)/(i<<1):(mod-1)/(i<<1)));
		for(int j=0;j<len;j+=(i<<1)){
			int w=1;
			for(int k=0;k<i;++k){
				int x=h[j+k],y=1ll*h[j+k+i]*w%mod;
				h[j+k]=(x+y)%mod;
				h[j+k+i]=(x-y+mod)%mod;
				w=1ll*w*wn%mod;
			}
		}
	}
	if(flag==-1){
		int inv=qpow(len,mod-2);
		for(int i=0;i<len;++i)
			h[i]=1ll*h[i]*inv%mod;
	}
}
int main(){
	scanf("%d",&n),fac[0]=inv[0]=1;
	for(int i=1;i<=n;++i)
		fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=qpow(fac[n],mod-2);
//	if(1ll*inv[n]*fac[n]%mod!=1)exit(-1);
	for(int i=n-1;i>=1;--i)
		inv[i]=1ll*inv[i+1]*(i+1)%mod;
	for(int i=2,u,v;i<=n;++i)
		scanf("%d%d",&u,&v),addedge(u,v);
	dfs(1,0);
	for(int i=1;i<=n;++i)anses[i]=1ll*(n+1)*getC(i,n)%mod;
	for(int i=1;i<=n;++i)A[siz[i]]++;
	int len=1,k=0;
	while(len<=n*2)len<<=1,k++;
	for(int i=0;i<len;i++)bh[i]=(bh[i>>1]>>1)|((i&1)<<(k-1));
	for(int i=0;i<=n;++i)B[i]=1ll*A[i]*fac[i]%mod;
	for(int i=0;i<=n;++i)C[i]=inv[n-i];
	fft(B,len,1),fft(C,len,1);
	for(int i=0;i<len;++i)B[i]=1ll*B[i]*C[i]%mod;
	fft(B,len,-1);
	for(int i=1;i<=n;++i)anses[i]=(anses[i]-1ll*B[i+n]*inv[i])%mod;
	memset(B,0,sizeof(B)),memset(C,0,sizeof(C));
	for(int i=0;i<=n;++i)B[i]=1ll*A[i]*fac[n-i]%mod;
	for(int i=0;i<=n;++i)C[i]=inv[i];
	fft(B,len,1),fft(C,len,1);
	for(int i=0;i<len;++i)B[i]=1ll*B[i]*C[i]%mod;
	fft(B,len,-1);
	for(int i=1;i<=n;++i)anses[i]=(anses[i]-1ll*B[n-i]*inv[i])%mod;
	for(int i=1;i<=n;++i)printf("%d\n",(anses[i]%mod+mod)%mod);
}

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

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second

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

    ll n,k,ans,tmp;
    cin >> k >> n;
    ans = k;
    ll a[n+2];
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
    }
    tmp=0;
    for(int i=1; i<n; i++)
    {
        tmp = max(tmp , a[i+1]-a[i]);
    }

    tmp = max(tmp , k-a[n]+a[1]);
    cout << ans-tmp << '\n';

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll N, K; cin >> N >> K;
    ll ans = K * pow(K - 1, N - 1);
    cout << ans << endl; 
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x"=" << x <<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3

#define MAX_N 1000000001

int main(){
	cin.sync_with_stdio(false);
	ll h, w, n;
	cin >> h >> w >> n;

	PL black[n];
	PL sq[9 * n];
	int j = 0;
	ll vx[] = {-2, -1, 0, -2, -1, 0, -2, -1, 0};
	ll vy[] = {-2, -2, -2, -1, -1, -1, 0, 0, 0};
	rep(i, n) {
		cin >> black[i].se >> black[i].fi;
		rep(k, 9) {
			ll x = black[i].fi + vx[k] - 1, y = black[i].se + vy[k] - 1;
			if (0 <= x && x + 2 < w && 0 <= y && y + 2 < h) {
				sq[j].fi = x;
				sq[j].se = y;
				j++;
			}
		}
	}

	sort(sq, sq + j);

	ll k = 0;
	ll ans[10] = {(h - 2) * (w - 2)};
	rep(i, j) {
		int cnt = 0;
		while(i < j) {
			if (sq[k] == sq[i]) {
				cnt++;
				i++;
			} else {
				k = i;
				i--;
				break;
			}
		}
		ans[cnt]++;
		ans[0]--;
	}

	rep(i, 10) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 15872
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int a = scan.nextInt();
      	int b = scan.nextInt();
      	int c = scan.nextInt();
      	int rest = a - b;
      	if(c -rest > 0){
        	System.out.print(c - rest);
        }
      	else{
        	System.out.print("0");
        }
    }
}

Measured memory_bytes: 21716
import std.stdio, std.string, std.conv, std.algorithm, std.range, std.array, std.typecons, std.math, std.numeric;

void main() {
    long n;
    readf("%d\n", &n);
    alias T = Tuple!(long, long);
    auto ts = new T[](n);
    foreach (i; 0..n) {
        long a, b;
        readf("%d %d\n", &a, &b);
        ts[i] = T(b, a);
    }
    ts = sort(ts).array;

    long cur = 0;
    foreach (t; ts) {
        cur += t[1];
        if (t[0] < cur) {
            writeln("No");
            return;
        }
    }
    writeln("Yes");


}


Measured memory_bytes: 8700
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

int main(){
    ll n;
    cin >> n;
    vector<ll> A(n);
    RAP(i, n){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    ll M = A[n-1], M2, idx;
    A.pop_back();
    auto itr = lower_bound(A.begin(), A.end(), M/2);
    idx = distance(A.begin(), itr);
    if(idx==0){
        M2 = A[0]; 
    }else if(idx==(n-1)){
        M2 = A[n-2];
    }else if((A[idx]-M/2)>(M/2-A[idx-1])){
        M2 = A[idx-1];
    }else{
        M2 = A[idx];
    }
    cout << M << " " << M2 << endl;
    return 0;
}


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

int main()
{
	int H, W;
	cin >> H >> W;
	int r[H] = {0}, c[W] = {0};
	vector<vector<char>> T(H, vector<char>(W));
	for (int i = 0; i < H; ++i)
		for (int j = 0; j < W; ++j)
		{
			cin >> T[i][j];
			if (T[i][j] == '#')
				r[i]++, c[j]++;

		}

	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			if (r[i] && c[j])
				cout << T[i][j];
		}
		if (r[i])
			cout << endl;
	}
}


Measured memory_bytes: 3600
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

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

    int a,b,c;
    cin >> a >> b >> c;

    if(b-a==c-b){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 3600
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

int n, k, m = 1e9 + 7;

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

    cin >> n >> m;

    priority_queue<ll> a;
    ll aa;
    rep(i, n) {
        cin >> aa;
        a.push(aa);
    }

    ll num = 0;
    while(num < m) {
        a.push(a.top() / 2);
        a.pop();
        num++;
    }

    ll pay = 0;
    rep(i, n) {
        pay += a.top();
        a.pop();
    }

    cout << pay << endl;
}

Measured memory_bytes: 4252
#include <bits/stdc++.h>
//一括include
using namespace std;
int main(){
    int n,num;
    int od = 0;
    int cnt = 0;
    int sm = 0;
    cin >> n;
    for (int i = 1; i <= n;i++){
        od = i;
        while (od){
            od = od / 2;
            cnt++;
            
        }
        if(sm<cnt){
            sm = cnt;
            num = i;
        }
        cnt = 0;
    }
    cout << num << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;

struct St{
  int ax, ay, bx, by, cst;
  St() {}
  St(int _ay, int _ax, int _by, int _bx, int _cst): ay(_ay), ax(_ax), by(_by), bx(_bx), cst(_cst) {}

  bool check(){
    return (ax == bx && ay == by);
  }

  void print(){
    cout << cst << " " << by << " " << bx << endl;
    return ;
  }
};

int p_n, w, h, pat[10];
char a[21][21];
bool vis[20][20][20][20][10];
int xdir[5] = {0, 1, 0, -1, 0}, ydir[5] = {-1, 0, 1, 0, 0};

bool bfs(St stt)
{
  queue<St> que;
  que.push(stt);

  while(!que.empty()){
    St st = que.front();
    que.pop();

    if(st.check()){
      st.print();
      return false;
    }
    int p = st.cst%p_n;
    int nby = st.by+ydir[pat[p]], nbx = st.bx+xdir[pat[p]];

    if(0 > nby || nby >= h || 0 > nbx || nbx >= w){
      nby = st.by; nbx = st.bx;
    }

    for(int i = 0; i < 5; ++i){
      int dy = st.ay+ydir[i], dx = st.ax+xdir[i];
      if(!(0 <= dy && dy < h && 0 <= dx && dx < w && a[dy][dx] == '.')){
	dy = st.ay; dx = st.ax;
      }

      if(vis[dy][dx][nby][nbx][p]){
	vis[dy][dx][nby][nbx][p] = false;
	que.push(St(dy, dx, nby, nbx, st.cst+1));
      }
    }
  }

  return true;
}

int main()
{
  int s, t, u, v;
  string str;

  while(cin>>h>>w && h+w){
    fill(&vis[0][0][0][0][0], &vis[20][0][0][0][0], true);

    for(int i = 0; i < h; ++i)
      for(int j = 0; j < w; ++j){
	cin >> a[i][j];
	if(a[i][j] == 'A'){
	  s = i; t = j;
	  a[i][j] = '.';
	} else if(a[i][j] == 'B'){
	  u = i; v = j;
	  a[i][j] = '.';
	}
      }
    cin >> str;
    p_n = str.size();

    for(int i = 0; i < p_n; ++i){
      if(str[i] == '8') pat[i] = 0;
      else if(str[i] == '2') pat[i] = 2;
      else if(str[i] == '6') pat[i] = 1;
      else if(str[i] == '4') pat[i] = 3;
      else if(str[i] == '5') pat[i] = 4;
    }

    if(bfs(St(s, t, u, v, 0))) cout << "impossible" << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    ll n, t, q, k;
    vector<ll> v;
    cin >> n;
    for(auto i = 0; i<n; i++){
        cin >> t;
        v.push_back(t);
    }
    cin >> q;
    for(auto i = 0; i<q; i++){
        cin >> k;
        cout << (int)binary_search(v.begin(), v.end(), k) << endl;
    }
    return 0;
}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  LL x;
  cin >> x;
  LL now = 100.0;

  LL ans = 0;
  while (now < x) {
    ans ++;
    now *= 1.01;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define N 1000
#define INF 100000000
#define ff(i,x,y) for(int i=x;i<=y;i++)
using namespace std;
typedef long long ll;
ll n,mes[200020],ans,sum;
map<ll,ll>mp;
int main()
{
    scanf("%lld",&n);
    ff(i,1,n)
    scanf("%lld",&mes[i]);
    ff(i,1,n)
    {
        sum+=mes[i];
        if(!mp.count(sum))
            mp[sum]=1;
        else
            mp[sum]++;
        if(sum==0)
            ans+=mp[sum];
        else
            ans+=(mp[sum]-1);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    for(ll i=0;i<n;i++){
        cin >> a[i];
        b[a[i]-1] = i+1;
    }
    for(ll i=0;i<b.size();i++){
        cout << b[i] << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n;
  scanf("%d",&n);
  set<int> s;
  rep(i,n) {
    int a;
    scanf("%d",&a);
    if (s.count(a)) s.erase(a);
    else s.insert(a);
  }
  cout<<sz(s)<<endl;
  return 0;
}






















Measured memory_bytes: 4864
a, b, c, d = map(int, input().split())
count_x = 0
count_y = 0
while a > 0:
    a -= d
    count_y += 1
while c > 0:
    c -= b
    count_x += 1

if count_x <= count_y:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61876
import numpy as np

N, K, Q = map(int, input().split())
A = []

for a in range(Q):
    A.append(int(input()))

P = [K] * N
X = [-1] * N
B = [0] * N

P_n = np.array(P)
X_n = np.array(X)
X_n_Q = X_n * Q

R_n = P_n + X_n_Q

B_n = np.array(B)

for a in A:
    B_n[a-1] = B_n[a-1] + 1

dif_n = R_n + B_n
dif = dif_n.tolist()

for d in dif:
    if d >= 1:
        print('Yes')
    else:
        print('No')

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/22  Problem: ABC 054 C / Link: http://abc054.contest.atcoder.jp/tasks/abc054_c  ----- */


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

	LL N, M; cin >> N >> M;
	VVI edge(N, VI(N, 0));
	FOR(i, 0, M) {
		int a, b; cin >> a >> b;
		a--, b--;
		edge[b][a] = edge[a][b] = 1;
	}

	VVL dp(1 << N, VL(N, 0));
	dp[1][0] = 1;
	FOR(state, 0, 1 << N) {
		FOR(f, 0, N) {
			if (state & 1 << f) {
				FOR(to, 0, N) {
					if (state & 1 << to)continue;
					if (edge[f][to]) {
						dp[state | (1 << to)][to] += dp[state][f];
					}
				}
			}
		}
	}
	LL ans = 0;
	FOR(i, 0, N) {
		ans += dp[(1<<N)-1][i];
	}
	
	
	cout << (ans) << "\n";

	return 0;
}


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

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pqb             priority_queue<ll>
#define pqs             priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            ll x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll n,m,a[2002],b[2002];

struct item{
ll wt,val;};
ll solve(vector<item>v,ll n,ll W){
    ll maxVal=n*1000;
   ll dp[n+1][maxVal+1];
   for(int val=0;val<=maxVal;val++){
    dp[1][val]=INT_MAX;
   }
   dp[1][0]=0;
   dp[1][v[1].val]=v[1].wt;
   for(int i=2;i<=n;i++){
    for(int val=0;val<=maxVal;val++){
        dp[i][val]=dp[i-1][val];
        if(v[i].val>val)continue;
        dp[i][val]=min(dp[i][val],v[i].wt+dp[i-1][val-v[i].val]);
    }
   }
ll ans=0;
for(int x=0;x<=maxVal;x++){
    if(dp[n][x]<=W){
        ans=x;
    }
}
return ans;
}

int main()
{
    FIO;
    ll c,d,e,f=0,sum=0,ans,ck,k,p,q,r,t,add=0,w,x,y,z;
    cin>>n>>w;
    vector<item>v(n+1);

    for(int i=1;i<=n;i++){cin>>v[i].wt;cin>>v[i].val;}
    ck=solve(v,n,w);
    cout<<ck<<endl;





    return 0;
}

Measured memory_bytes: 81764
#include <stdio.h>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, x, ans = 0;
  scanf("%lld%lld", &n, &x);
  for(i = n + 2; i >= 3; --i) {
    if((1ll << i) <= x + 3) {
     ans += (1ll << (i - 1)) - 1;
     x -= (1ll << i) - 3;
     if(x) x--, ans++;
    }
    if(x) x--;
  }
  if(x > 0) {
    if(x < 4) ans += x;
    else ans += 3;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.

*/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;
typedef long long ll;

int mod = 1000000007;
ll dp[100005];;

ll gcd(long long a,long long b){

  if(b == 0)
    return a;
  else return gcd(b,a%b);
}

bool compare(pair<int,int>p1, pair<int,int>p2){

  return p1.second > p2.second;
 }


 int main(){

  string a,b;
  cin>>a>>b;

  if(a.length() != b.length())
 {
 cout<<"No"<<endl;
  return 0; }

   long long pos=0;

  for(int i=0;i<a.length();i++){

    if(a[i] == b[0]){
        pos = i;
        break; }
  }

  //cout<<"the pos"<<pos<<endl;

  string emptys = "";
    long long ani=0,rot=pos;

  for(int i=rot;i<a.length();i++)
  {
     emptys += a[i];
  }

  for(int i = 0;i<rot;i++){
    emptys += a[i];
  }

  // cout<<"?? "<<emptys<<endl;

  if(emptys == b)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;


 return 0;
 }


Measured memory_bytes: 3580
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<long long,long long>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a);}
                a=(a*a);
                b>>=1;
        }
    return ans;
        
}
set<pii>s;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    srand(time(0));
    int k;
    cin>>k;
    int count=9;
    vector<int>v;
    for(int i=1;i<10;i++)v.push_back(i);
    
    while(count<k){
        vector<int>v1;
        for(auto i:v){
            if(i%10+1<10)v1.push_back(i*10+i%10+1);
            if(i%10-1>=0)v1.push_back(i*10+i%10-1);
            v1.push_back(i*10+i%10);
        }
        count+=v1.size();
        v=v1;
    }
    sort(v.begin(),v.end());
    cout<<v[v.size()-(count-k)-1];
    return 0;
}


Measured memory_bytes: 2848
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	as := make([]int, n)
	for i := range as {
		as[i] = nextInt()
	}

	var cnt int
	for _, a := range as {
		if a%2 == 1 {
			cnt++
		}
	}

	if cnt%2 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

int N,K;
int A[555];

bool check(int g){
	vint lis;
	rep(i,N){
		if(A[i]%g==0)continue;
		lis.pb(A[i]%g);
	}

	sort(all(lis));
	for(int i=0;i<=lis.size();i++){
		int p=0,s=0;
		rep(j,i)p+=lis[j];
		for(int j=i;j<lis.size();j++)s+=g-lis[j];
		if(p!=s)continue;
		if(p<=K)return true;
	}
	return false;
}

signed main(){
	cin>>N>>K;
	rep(i,N)cin>>A[i];

	int sum=accumulate(A,A+N,0ll);
	int ans=0;
	for(int g=1;g*g<=sum;g++){
		if(sum%g)continue;
		if(check(g))chmax(ans,g);
		if(check(sum/g))chmax(ans,sum/g);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
N=int(input())
A=[int(input()) for i in range(N)]
if A[0]!=0:
    print(-1)
else:
    flag=0
    for i in range(1,N):
        if A[i]-A[i-1]>1:
            flag=1
            break
    if flag==1:
        print(-1)
    else:
        ans=0
        for i in range(1,N):
            if A[i-1]+1==A[i]:
                ans+=1
            else:
                ans+=A[i]
        print(ans)


Measured memory_bytes: 11048
#include<stdio.h>
struct V{double x,y;}v[50],a,b;
V operator-(V a,V b){V c={a.x-b.x,a.y-b.y};return c;}
int main()
{
	int n,i,c=0;
	double s;
	while(scanf("%d",&n),n)
	{
		for(s=i=0;i<n;++i)scanf("%lf%lf",&v[i].x,&v[i].y);
		for(i=2;i<n;++i)
		{
			a=v[i]-v[0],b=v[i-1]-v[0];
			s+=(a.x*b.y-a.y*b.x)/2;
		}
		printf("%d %.1f\n",++c,s);
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)

vector<long long> fact(200000 + 5, 1);
int h, w, a, b;

long long powmod(long long n, long long k){
    if (k == 0) return 1;
    else if (k % 2 == 0){
        long long tmp = powmod(n, k / 2);
        return tmp * tmp % mod;
    }
    else return powmod(n, k - 1) * n % mod;
}

long long inverse(long long n) {
    return powmod(n, mod - 2);
}

vector<long long> init_fact(long long n) {
    for (int i = 1; i <= n; i++) {
        fact[i] = fact[i - 1] * i % mod;
    }
    return fact;
}

long long nCk(long long n, long long k) {
    if (n - k < k) k = n - k;
    return fact[n] * (inverse(fact[n - k]) * inverse(fact[k]) % mod) % mod;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w >> a >> b;
    fact = init_fact(h + w + 2);
    int lh = h - a, lw = b;
    ll ans = 0;
    rep(i, lh) {
        addm(ans, nCk(i + lw - 1, lw - 1) * nCk(h - 1 - i + w - 1 - lw, h - 1 - i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, m, l, r=IINF;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(i, 0, m){
    int _l, _r;
    cin >> _l >> _r;
    maxs(l, _l);
    mins(r, _r);
  }
  cout << max(0, r-l+1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 9e18;

signed main() {
    int N;
    cin >> N;
    int ans = 0;
    vector<pair<int, int>> food(N);
    for (int i = 0; i < N; i++) {
        int A, B;
        cin >> A >> B;
        ans -= B;
        food.emplace_back(A, B);
    }
    auto sorting = [](pair<int, int> a, pair<int, int> b) {
        return a.first + a.second > b.first + b.second;
    };
    sort(food.begin(), food.end(), sorting);
    for (int i = 0; i < N; i += 2) {
        auto temp = food[i];
        ans += temp.first + temp.second;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int dfs(vector<vector<int>> &t, int v, int parent, int K){
	int ans = 1, i, j;
	for(i = 0, j = 2; i < t[v].size(); i++){
		if(t[v][i] != parent){
			ans = MOD(ans * dfs(t, t[v][i], v, K));
			ans = MOD(ans * (K - j));
			j++;
		}
	}
	return ans;
}

signed main(){
	int N, K, i;
	scanf("%lld%lld", &N, &K);
	if(N == 1){
		printf("%lld\n", K);
		return 0;
	}
	vector<vector<int>> t(N, vector<int>(0));
	for(i = 1; i < N; i++){
		int a, b;
		scanf("%lld%lld", &a, &b);
		a--;
		b--;
		t[a].push_back(b);
		t[b].push_back(a);
	}
	for(i = 0; t[i].size() > 1; i++);
	int ans = MOD(MOD(K * (K - 1)) * dfs(t, t[i][0], i, K));
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=100000+10;
int a[maxn];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	int first=0;
	int second=0;
	for(int i=1;i<=n;i+=2){
		if(a[i]==a[i+1]){
			second=first;
			first=a[i];
		}
		else i--;
	}
	cout<<(long long)first*second<<endl;
	return 0;
}

Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class DWaterBottle {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    double a, b, x;

    double check(double t) {
        t = t * M_PI / 180.0;
        if (a * tan(t) <= b) {
            return a * a * b - a * a * a * tan(t) / 2.0;
        } else {
            return b * b / tan(t) * a / 2.0;
        }
    }

    void solve(std::istream& cin, std::ostream& cout) {
        cin >> a >> b >> x;

        double l = 0;
        double r = 90;
        REP(i, 1000000) {
            double m = (r + l) / 2.0;
            double tmp = check(m);
            if (tmp >= x) {
                l = m;
            } else {
                r = m;
            }
        }
        fcout << l << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DWaterBottle solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
    int H,W;
    for(int i = 0;;i++){
        scanf("%d%d",&H,&W);
        if(H != 0 && W != 0){
            for(int j = 0;j < H;j++){
                for(int k = 0;k < W;k++){
                    printf("#");
                    k++;
                    if(k == W){
                        break;
                    }
                    printf(".");
                }
                printf("\n");
                j++;
                if(j == H){
                    break;
                }
                for(int k = 0;k < W;k++){
                    printf(".");
                    k++;
                    if(k == W){
                        break;
                    }
                    printf("#");
                }
                printf("\n");
            }
            printf("\n");
            continue;
        }
        break;
    }
    return 0;
}


Measured memory_bytes: 2672
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 1e9 + 7;
const int N = 3 * 1e3 + 111;
const int MOD = 998244353;
int dp[N][N];
signed main () {
    ios_base::sync_with_stdio(NULL);
    cin.tie(0); cout.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for (int i = a; i <= c; i++)
        for (int j = b; j <= d; j++) {
            dp[i + 1][j] += j * dp[i][j];
            dp[i][j + 1] += i * dp[i][j];
            dp[i + 1][j] %= MOD;
            dp[i][j + 1] %= MOD;
            dp[i + 1][j + 1] -= (dp[i][j] * (i) * (j) % MOD);
            dp[i + 1][j + 1] += MOD;
            dp[i + 1][j + 1] %= MOD;
        }
    cout << dp[c][d] << '\n';
    return 0;
}


Measured memory_bytes: 76444
n, m = map(int, input().split())
al = list(list(map(int, input().split())) for _ in range(n))
cl = list(list(map(int, input().split())) for _ in range(m))

for a in al:
    ans = 1001001001
    no = 0
    for i in range(m):
        dis = abs(a[0]-cl[i][0])+abs(a[1]-cl[i][1])
        if dis < ans:
            ans = dis
            no = i
    print(no+1)


Measured memory_bytes: 9196
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int n; cin >> n;
	if (n % 2 == 0) cout << n;
	else cout << n * 2;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (int argc, char const *argv[])
{
    int64_t n, v;
    int64_t oddnum[(int)1e5] = {0}, evennum[(int)1e5] = {0};
    uint64_t ans = 0, oddmax = 0, evenmax = 0, oddmax2 = 0, evenmax2 = 0, oddi = 0, eveni = 0;

    scanf("%"PRId64, &n);
    for (int i = 0; i < n; i++) {
        scanf("%"PRId64, &v);
        if (i % 2) {
            oddnum[v]++;
        } else {
            evennum[v]++;
        }
    }

    for (int i = 0; i < (int)1e5; i++) {
        if (oddmax < oddnum[i]) {
            oddmax2 = oddmax;
            oddmax = oddnum[i];
            oddi = i;
        } else if (oddmax2 < oddnum[i]) {
            oddmax2 = oddnum[i];
        }
        if (evenmax < evennum[i]) {
            evenmax2 = evenmax;
            evenmax = evennum[i];
            eveni = i;
        } else if (evenmax2 < evennum[i]) {
            evenmax2 = evennum[i];
        }
    }

    if (oddi != eveni) {
        ans = ((n / 2) - oddmax) + ((n / 2) - evenmax);
    } else {
        if ((oddmax + evenmax2) > (oddmax2 + evenmax)) {
            ans = ((n / 2) - oddmax) + ((n / 2) - evenmax2);
        } else {
            ans = ((n / 2) - oddmax2) + ((n / 2) - evenmax);
        }
    }

    printf("%"PRId64"\n", ans);
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

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

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static String s = "";

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();

		if(4*a*b < (c-a-b)* (c-a-b) && c-a-b > 0)
			System.out.println("Yes");
		else
			System.out.println("No");

	}

}


Measured memory_bytes: 22996