akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
const int maxn=1e5+10;
using namespace std;
typedef long long ll;
ll n,a[maxn],tree[maxn*2+5],pre[maxn*2+5],l,r;
void add(ll x,ll v)
{
	for(ll i=x;i<=2*maxn;i+=i&-i)
    	tree[i]+=v;
}
ll ask(int x)
{
    ll ans=0;
    for(ll i=x;i>0;i-=i&-i)
    	ans+=tree[i];
    return ans;
}
bool check(ll mid)
{	
	ll ans=0;
	memset(tree,0,sizeof(tree));
	pre[0]=0;
	for(ll i=1;i<=n;++i)
	pre[i]=pre[i-1]+(a[i]>=mid?1:-1);
	for(ll i=0;i<=n;++i)
	{
		ans+=ask(pre[i]+maxn);
		add(pre[i]+maxn,1ll);
	}
	return ans>=n*(n+1)/4;
}
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",&a[i]);
	    r=max(r,a[i]);
    }
    while(l<=r)
    {
    	ll mid=(l+r)>>1; 
    	if(check(mid))l=mid+1;
		else r=mid-1; 
    }
    printf("%lld",r);
	return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
    
    int n;
    char s[100001];
    int ans=1;
    
    scanf("%d", &n);
    scanf("%s", s);
    
    for(int i=1; i<=n-1; i++){
        
        if(s[i-1]!=s[i]){
            
            ans += 1;
            
        }
        
    }
    
    printf("%d", ans);
    
    return 0;
    
}

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

int main(void) {
  int N;
	cin >> N;
  int cost = 800; int gain = 200; int cond = 15;

  cout << N * cost - gain * (N / cond) << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;

string toString(int n){
  ostringstream oss;
  oss << n;
  return oss.str();
}

vector<int> mod;

int boundary;

bool findMod(int M){
  for(int i = 0 ; i < mod.size() ; i++){
    if(mod[i] == M){
      boundary = mod.size()-i;
      return true;  
    }
  }
  return false;
}

int main(){
  int a, b;
  
  while(cin >> a >> b){
    bool flag = false;
    mod.clear();
    string ans = "";
    //a = a % b;
    mod.push_back(a);
    // a *= 10;
    for(; ;){
      a *= 10;
      int c = a / b;
      string s = toString(c);
      ans += s;
      if(a % b == 0){
	flag = true;
	goto END;
      }
      if(findMod(a % b)) goto END;
      mod.push_back(a % b);
      a -= b * c;

    }
  END:;
    if(flag) cout << ans << endl;
    else{
      cout << ans << endl;
      for(int i = 0 ; i < ans.size() - boundary ; i++) cout << ' ';
      for(int i = ans.size() - boundary ; i < ans.size() ; i++) cout << '^';
      cout << endl;
    }
    
  }
  return 0;
}

Measured memory_bytes: 1248
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t A[3];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> A[0]>>A[1]>>A[2];
	std::sort(A, A + 3);
	out << (A[0] == A[1] ? A[2] : A[0]) << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	int[][] table;
	boolean[] use;

	void run() {
		table = new int[11][331];
		use = new boolean[10];
		make(0, 0);
		while (sc.hasNext()) {
			int n = sc.nextInt();
			int s = sc.nextInt();
			System.out.println((n > 10 || s > 330) ? 0 : table[n][s]);
		}
	}

	void make(int depth, int sum) {
		table[depth][sum]++;
		if (depth == 10) return;
		for (int i = 0; i < 10; i++) {
			if (use[i]) continue;
			use[i] = true;
			make(depth + 1, sum + i * (depth + 1));
			use[i] = false;
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 18312
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

typedef signed long long ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) x.begin(),x.end()

#define DEBUG

int main()
{
	double n,a = 0,b = 0;
	cin >> n;

	for(int i = 1; i <= n; i++)
	{
		if(i % 2 == 1) a++;
	}

	cout << a / n << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  char a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a==b){
    if(a!=c&&c==d){
      cout<<"Yes";
    }else{
      cout<<"No";
    }
  }else{
    if(a==c&&b==d){
      cout<<"Yes";
    }else if(a==d&&b==c){
      cout<<"Yes";
    }else{
      cout<<"No";
    }
  }
}

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

ll dp[55][55][2505];  // dp[i+1][j][k] : x[i]まででj枚使って合計をkにする方法の総数

int main() {
    ll n, a;
    cin >> n >> a;

    vl x(n);
    ll u = 0;  // xの中の最大の数
    rep(i, n) {
        cin >> x[i];
        chmax(u, x[i]);
    }

    dp[0][0][0] = 1;
    rep(i, n) {
        exrep(j, 0, n) {
            exrep(k, 0, u*n) {
                ll y = 0;
                if(j >= 1 && k >= x[i]) {
                    y = dp[i][j - 1][k - x[i]];
                }
                dp[i+1][j][k] = dp[i][j][k] + y;
            }
        }
    }

    ll ans = 0;
    exrep(j, 1, n) {
        ans += dp[n][j][a*j];
    }

    out(ans);
    re0;
}

Measured memory_bytes: 54400
'use strict'

const main = (INPUT) => {
  const N = INPUT.split('\n')[0]
  const s = INPUT.split('\n')[1]

  let R = 0
  let B = 0
  for (let i = 0; i < s.length; i++) {
    if (s[i] == 'R') {
      R++
    } else {
      B++
    }
  }
  if (R > B) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


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

    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if(s == u){
        cout << a-1 << " " << b << endl;
    }else{
        cout << a << " " << b-1 << endl;
    }



    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int digitSum(int n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);

    // int n;
    // cin >> n;
    // vector<int> a(n);
    // rep(i, n)
    // {
    //     cin >> a[i];
    // }

    int l;
    cin >> l;

    cout << pow(l / 3.0, 3.0) << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
bool hei(int x){
	rep(0,i,10000){
		if(i*i==x){
			return true;
		}
	}
	return false;
}			
int a[45][45];
signed main(){
	int n,d;
	cin>>n>>d;
	rep(0,i,n){
		rep(0,j,d){
			cin>>a[i][j];
		}
	}
	int sum=0;
	int ans=0;
	rep(0,i,n){
		rep(0,j,n){
			sum=0;
			if(i!=j){
				rep(0,k,d){
					sum+=abs(a[i][k]-a[j][k])*abs(a[i][k]-a[j][k]);
				}
				if(hei(sum)==1){
					ans++;
				}
			}
		}
	}
	c(ans/2)
}				

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

int N, p[30], min_times;

map<int,int> rot[4] = {
    { {1, 28}, {2, 29}, {3, 30}, {15, 16}, {19, 21}, },
    { {3, 22}, {6, 25}, {9, 28}, {12, 19}, {13, 15} },
    { {7, 22}, {8, 23}, {9, 24}, {13, 18}, {10, 12} },
    { {1, 24}, {4, 27}, {7, 30}, {10, 21}, {16, 18} }
};

vector<int> group_id = {
    0, 0, 0, 0, 0, 0, 0, 0, 0,
    9, 9, 9,
    12, 12, 12,
    15, 15, 15,
    18, 18, 18,
    21, 21, 21, 21, 21, 21, 21, 21, 21
};

void rotate(int i) {
    for (auto it=rot[i].begin(); it!=rot[i].end(); ++it) {
        swap(p[it->first - 1], p[it->second - 1]);
    }
}

bool isOK() {
    for (int i=0; i<(int)group_id.size(); ++i) {
        if (p[i] != p[group_id[i]]) return false;
    }
    return true;
}

int solve(int times, int &min_times) {
    if (min_times <= times || isOK()) {
        min_times = min(min_times, times);
        return times;
    } else if (times == 7) {
        return 8;
    }
    int ret = 8;
    for (int i=0; i<4; ++i) {
        rotate(i);
        ret = min(ret, solve(times + 1, min_times));
        rotate(i);
    }
    return ret;
}

int main() {
    cin >> N;
    for (int i=0; i<N; ++i) {
        for (int j=0; j<30; ++j) {
            cin >> p[j];
        }
        min_times = 8;
        cout << solve(0, min_times) << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
#!/usr/bin/env ruby

N = gets.chomp.to_i
X = gets.chomp.split(' ').map(&:to_i)

sorted = X.sort

lesser_median = sorted[N / 2 - 1]
greater_median = sorted[N / 2]


if lesser_median == greater_median
  N.times do
    puts lesser_median
  end
  exit 0
end

the_median = (lesser_median + greater_median).to_f / 2

X.each do |x|
  if x < the_median
    puts greater_median
  else
    puts lesser_median
  end
end


Measured memory_bytes: 25316
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int N, C, D[35][35], c[510][510], cnt[5][35] = {{0}};

int main(){
    cin >> N >> C;
    REP(i, 1, C+1){
        REP(j, 1, C+1){
            cin >> D[i][j];
        }
    }
    REP(i, 1, N+1){
        REP(j, 1, N+1){
            cin >> c[i][j];
            cnt[(i+j)%3][c[i][j]]++;
        }
    }
    int ans = IINF;
    REP(k, 1, C+1){
        REP(l, 1, C+1){
            REP(m, 1, C+1){
                if(k == l || l == m || m == k){
                    continue;
                }
                int tmp = 0;
                REP(j, 1, C+1){
                    tmp += D[j][k] * cnt[0][j];
                    tmp += D[j][l] * cnt[1][j];
                    tmp += D[j][m] * cnt[2][j];
                }
                ans = min(ans, tmp);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int A, B, C;

    cin >> A >> B >> C;

    if (A != B && A != C){
        cout << A << endl;
    } else if (B != C && B != A){
        cout << B << endl;
    } else{
        cout << C << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int i = -1;
	int num = 1;
	
	while (1)
	{
	    scanf("%d", &i);
		if (i == 0)
		{
			break;
		}
		printf("Case %d: %d\n", num, i);
		num++;
	}

	
	return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define size(x) int(x.size())
typedef long long ll;
using namespace std;
int main(){
    int A,B; cin >> A >> B;
    A--; B--;
    int ans = (A+B-1) / A;

    cout << ans <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;

int res;
vector<string> input(int n){
    vector<string> res;
    for(int i = 0 ; i < n ; i ++){
        string line;
        for(int j = 0 ; j < 5 ; j ++){
            char c;
            cin>>c;
            line += c;
        }
        res.push_back(line);
        line="";
    }
    return res;
}

pair<string,int> chek(string s){
    int res = 0;
    string nu ="00000";
    // a a a a a 
//    cout<<"che"<<endl<<s<<endl;   
    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3] && s[3] == s[4] && s[0] != '0'){
        return make_pair(nu,(s[0] - '0') * 5);
    }
    // a a a a b
    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3] && s[0] != '0'){
        return make_pair(nu.substr(0,4)+s.substr(4,1),(s[0] - '0') * 4);
    }
    // b a a a a
    if(s[1] == s[2] && s[2] == s[3] && s[3] == s[4] && s[1] != '0'){
        return make_pair(s.substr(0,1)+nu.substr(0,4),(s[1] - '0') * 4);
    }
    // a a a b c
    if(s[0] == s[1] && s[1] == s[2] && s[0] != '0'){
        return make_pair(nu.substr(0,3)+s.substr(3,2),(s[0] - '0') * 3);
    }
    // b a a a c 
    if(s[1] == s[2] && s[2] == s[3] && s[1] != '0'){
        return make_pair(s.substr(0,1)+nu.substr(0,3)+s.substr(4,1),(s[1] - '0') * 3);
    }
    // b c a a a
    if(s[2] == s[3] && s[3] == s[4] && s[2] != '0'){
        return make_pair(s.substr(0,2)+nu.substr(0,3),(s[2] - '0') * 3);
    }
    return make_pair(s,0);
}
vector<string> move(vector<string> line){
    for(int i = line.size() - 2 ; i >= 0 ; i --){
        for(int j = 0 ; j < 5 ; j ++){
            if(line[i+1][j] == '0'){
                line[i+1][j] = line[i][j];
                line[i][j] = '0';
            }
        }
    }
    return line;
}
int main(void){
    int n;
    while(cin>>n,n){
        res = 0;
        vector<string> in = input(n);
//        cout<<in.size()<<endl;
//        for(int i = 0 ; i < in.size(); i ++)cout<<in[i]<<endl;
        if(in.size() == 1){
            pair<string,int> line = chek(in[0]);
            cout<<line.second<<endl;
        }else{
            bool con = true;
            int ll=0;
            while(con){
//                cout<<endl;
                con = false;
                for(int i = 0 ; i < in.size() ; i ++){
                    pair<string,int> line = chek(in[i]);
                    in[i] = line.first;
                    res += line.second;
                    if(line.second)con=true;
                    in = move(in);
                }
//            for(int i = 0 ; i < in.size() ; i ++)cout<<in[i]<<endl;
            }
//            for(int i = 0 ; i < in.size() ; i ++)cout<<in[i]<<endl;
            cout<<res<<endl;
        }
    }
}

Measured memory_bytes: 1224
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
  int N,M;
  int x,y;
  int i,j;
  int l;
  int check=0;
  char d;
  
  while(1){
    cin >> N;
    if(N==0) break;
    
    int flag[21][21]={};

    for(i=0;i<N;++i){
      cin >> x >> y;

      
      flag[x][y]=1;
    }
    
    check =0;
    
    int rx=10,ry=10;
    
    cin >> M;
    
    for(i=0;i<M;++i){
      
      cin >> d >> l;
      
      for(j=1;j<=l;++j){
	
	if(d=='N'){
	  ry++;
	}else if(d=='E'){
	  rx++;
	}else if(d=='S'){
	  ry--;
	}else{
	  rx--;
	}
	if(flag[rx][ry]==1){
	  check++;
	  flag[rx][ry]=0;
	}
      }
    }
 
    
    if(check==N){
      cout << "Yes\n";
    }else{
      cout << "No\n";
    }
  }


  return 0;
}
  

Measured memory_bytes: 3068
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll tmp=a*c;
  chmax(tmp,a*d);
  chmax(tmp,b*c);
  chmax(tmp,b*d);
  cout<<tmp<<'\n';
  return(0);
}

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

int n,ans;
int d[105];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		if(x==y) d[i]=1;
		if(i>=3&&d[i]&&d[i-1]&&d[i-2]) ans=1;
	}
	if(ans) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3676
s = list(input())

a = len(s)
for i in range(0, (a-1)//2):
    if s[i] == s[a-1-i] == s[(a-3)//2 -i] == s[(a+1)//2+i]:
        continue
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 38508
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=1000000009;

int main()
{
    fastio;
    int n;cin>>n;
    ll a[n];
    ll maxx=-INF,maxx2=-INF,maxc=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        maxx=max(maxx,a[i]);
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]!=maxx)
            maxx2=max(maxx2,a[i]);
        else
            maxc++;
    }
    for(int i=0;i<n;i++)
        cout<<((a[i]==maxx && maxc==1) ? maxx2 : maxx)<<endl;

}
	

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N);
  ll alice = 0ll;
  ll bob = 0ll;
  vector< ll > a(N);
  REP(i, N) {
    cin >> a[i];
  }

  sort(ALL(a), greater< ll >());

  REP(i, N) {
    if (!(i & 1)) alice += a[i];
    else bob += a[i];
  }

  debug(alice);
  debug(bob);
  cout << alice - bob << endl;

  return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i].first >> v[i].second;

    sort(v.begin(), v.end());
    long long ans = 0;
    for(int i=0; i<n; ++i){
        int x = min(m, v[i].second);
        ans += v[i].first * (long long)x;
        m -= x;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

int main() {
	int n, l; cin >> n >> l;
	vector<string>s(n);

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

	sort(s.begin(), s.end());
	for (int i = 0; i < n; i++) {
		cout<< s[i];
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

ll dp[5][4001];

int main() {
  memset(dp,0,sizeof(dp));
  dp[0][0] = 1;
  REP(i,4) for (int j=4000; j>=0; --j)
    for (int k=0; k<=1000&&j+k<=4000; ++k)
      dp[i+1][j+k] += dp[i][j];
  int n;
  while(cin >> n) {
    cout << dp[4][n] << endl;
  }

}

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


string S;
ll dp[100001][13];

void input() {
	cin>>S;
}

void solve() {
	dp[0][0]=1;
	for(int i=0; i<S.len; i++) {
		if(S[i]=='?') {
			for(int j=0; j<13; j++) for(int k=0; k<10; k++) {
				int x=(j*10+k)%13;
				dp[i+1][x] = (dp[i+1][x]+dp[i][j])%MPRIME;
			}
			continue;
		}

		int k=int(S[i]-'0');
		for(int j=0; j<13; j++) {
			int x=(j*10+k)%13;
			dp[i+1][x] = (dp[i+1][x]+dp[i][j])%MPRIME;
		}
	}

	cout<<dp[S.len][5]<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 13908
#include<bits/stdc++.h>
using namespace std;
int n,q,ans,mod=1e9+7,ress,tmp,a[3333],p[3333],f[3333][3333];
long long quick_q(int x,int y){
	long long res=x,ans=1;
	for(;y;y>>=1,res*=res,res%=mod)if(y&1)ans*=res,ans%=mod;
	return (int)ans;
}
int main(){
	scanf("%d%d",&n,&q),ress=quick_q(2,q),tmp=quick_q(2,mod-2);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(a[i]>a[j])f[i][j]=1;
	for(int i=1,x,y;i<=q;f[x][y]=f[y][x]=1ll*(f[x][y]+f[y][x])%mod*tmp%mod,i++){
		scanf("%d%d",&x,&y);
		for(int j=1;j<=n;j++)if(j!=x&&j!=y)f[x][j]=f[y][j]=1ll*(f[x][j]+f[y][j])%mod*tmp%mod;
		for(int j=1;j<=n;j++)if(j!=x&&j!=y)f[j][x]=f[j][y]=1ll*(f[j][x]+f[j][y])%mod*tmp%mod;
	}
	for(int i=1;i<n;i++)for(int j=i+1;j<=n;j++)ans+=1ll*ress*f[i][j]%mod,ans%=mod;
	printf("%d",ans);
}

Measured memory_bytes: 41216
#include<stdio.h>
int main()
{
	char a[4];
	int i;
	scanf("%s",a);
	if(a[0]==a[1] || a[1]==a[2] || a[2]==a[3])
	{
		printf("Bad\n");
	}
	else
	{
		printf("Good\n");
	}
	return 0;
}


Measured memory_bytes: 128
import itertools
import bisect
N, M, K = map(int,input().split())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 

A_ = list(itertools.accumulate(A))
B_ = list(itertools.accumulate(B))

ans = 0
l = len(A_)
ans = max(ans, bisect.bisect_right(B_, K))
for idx, i in enumerate(A_):
  if i <= K:
          ans = max(idx+1 + bisect.bisect_right(B_, K-i), ans)
  
print(ans)

Measured memory_bytes: 47524
def f():
    n=int(input())
    s=list(input())
    a,b=s[n-1::-1],s[n:]
    from collections import defaultdict

    ad=defaultdict(int)
    bd=defaultdict(int)
    for i in range(2**n):
        sa,ta,sb,tb="","","",""
        for j in range(n):
            if i%2:
                sa+=a[j]
                sb+=b[j]
            else:
                ta+=a[j]
                tb+=b[j]
            i//=2
        ad[(sa,ta)]+=1
        bd[(sb,tb)]+=1
    ans=0
    for k in ad:
        if k in bd:
            ans+=bd[k]*ad[k]
    print(ans)
if __name__ == "__main__":
    f()

Measured memory_bytes: 126016
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main()
{	
	int n, m;
	
	cin >> n;
	
	while (n > 0) {
		map<string, string> tr;

		for (int i = 0; i < n; i++) {
			string a, b;
			cin >> a >> b;
			tr[a] = b;
		}

		cin >> m;

		string s;

		for (int i = 0; i < m; i++) {
			string t;
			cin >> t;
			if (tr.find(t) != tr.end())
				s += tr[t];
			else
				s += t;
		}

		cout << s << endl;

		cin >> n;
	}

	return 0;
}



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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;

ll fact[1001], rfact[1001];

ll perm(ll n, ll r){
    return (fact[n] * rfact[r]) % MOD;
}

ll comb(ll n, ll r){
    return (perm(n, r) * rfact[n-r]) % MOD;
}

void init(){
    fact[0] = fact[1] = 1;
    rfact[0] = rfact[1] = 1;
    for(int i=2;i<1001;i++){
        fact[i] = (fact[i-1] * (ll)i) % MOD;
        rfact[i] = 1;
        ll k = MOD-2;
        ll a = fact[i];
        while(k > 0){
            if(k & 1){
                rfact[i] *= a;
                rfact[i] %= MOD;
            }
            a *= a;
            a %= MOD;
            k  >>= 1;
        }
    }
}

int main(){

    init();

    ll R,C,ax,ay,bx,by;
    cin >> R >> C >> ay >> ax >> by >> bx;

    ll lengthx, lengthy, countx = 0LL, county = 0LL;
    if(ax == bx){
        lengthx = 0LL;
        countx = 1LL;
    }else if(bx == 0 || bx == C-1){
        lengthx = 1LL;
        if(abs(ax-bx) == 1LL){
            countx = 2LL;
        }else{
            countx = 1LL;
        }
    }else{
        lengthx = min({
            abs(bx-ax),
            1 + (C-1-bx),
            1 + bx
        });
        if(lengthx == abs(bx-ax)) countx++;
        if(lengthx == 1 + (C-1-bx)) countx++;
        if(lengthx == 1 + bx) countx++;
    }

    if(ay == by){
        lengthy = 0LL;
        county = 1LL;
    }else if(by == 0 || by == R-1){
        lengthy = 1LL;
        if(abs(ay-by) == 1LL){
            county = 2LL;
        }else{
            county = 1LL;
        }
    }else{
        lengthy = min({
            abs(by-ay),
            1 + (R-1-by),
            1 + by
        });
        if(lengthy == abs(by-ay)) county++;
        if(lengthy == 1 + (R-1-by)) county++;
        if(lengthy == 1 + by) county++;
    }

    ll ans = (countx * county) % MOD;
    ans = (ans * comb(lengthx+lengthy, lengthx)) % MOD;

    cout << lengthx+lengthy << " " << ans << endl;
}



Measured memory_bytes: 3120
import java.util.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A,B,C,X,Y;
    A = sc.nextInt();
    B = sc.nextInt();
    C = sc.nextInt();
    X = sc.nextInt();
    Y = sc.nextInt();
    int pizaC = 2 * Math.max(X,Y);
    int pizaA, pizaB;
    int ans = INF;
    int tmp;
    while(pizaC >= 0){
      pizaA = Math.max(0, X - pizaC/2);
      pizaB = Math.max(0, Y - pizaC/2);
      tmp = pizaA * A + pizaB * B + pizaC * C;
      ans = Math.min(tmp, ans);
      pizaC--;
    }
    System.out.println(ans);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

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

int main(){
    long int n, d;
    cin >> n >> d;

    long int x,y;
    int cnt=0;

    for(int i = 0; i < n; i++){
        cin >> x >> y;
        if(sqrt(x * x + y * y) <= d){
            cnt++;
        }
    }

    cout << cnt;
}


Measured memory_bytes: 3676
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x[] = new int[5];
		boolean bl = false;
		for(int i = 0; i < x.length; i++) {
			x[i] = sc.nextInt();
			if(x[i] == 0) {
				System.out.println(i + 1);
				bl = true;
			}
		}
		if(!bl)
			System.out.println("0");
	}
}


Measured memory_bytes: 35792
<?php

$lines = explode(" ", fgets(STDIN));

$a = array();

for ($i = 0; $i < count($lines); $i++) {
    $tmp = trim($lines[$i]);

    if (ctype_digit($tmp)) {
        $a[count($a)] = $tmp;
    } else {
        if ($tmp == "+") {
            $a[count($a) - 2] = $a[count($a) - 2] + $a[count($a) - 1];
        } elseif ($tmp == "*") {
            $a[count($a) - 2] = $a[count($a) - 2] * $a[count($a) - 1];
        } elseif ($tmp == "-") {
            $a[count($a) - 2] = $a[count($a) - 2] - $a[count($a) - 1];
        } elseif ($tmp == "/") {
            $a[count($a) - 2] = $a[count($a) - 2] / $a[count($a) - 1];
        }
        unset($a[count($a) - 1]);
    }
}

echo $a[0];
?>

Measured memory_bytes: 15436
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n, m;
    cin >> n>> m;
    int a1= 0;
    int a2 =0;
    int ans = 0;
    if(n<2){
        a1 = 0;
    }
    else
        a1 = n*(n-1)/2;
    
    if(m<2){
        a2 = 0;
    }
    else
        a2 = m*(m-1)/2;
        
    ans = a1+a2;
    
    std::cout << ans;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner s = new Scanner(System.in);
		String[] i = s.nextLine().split(" ");
		int i1 = Integer.parseInt(i[0]);
		int i2 =  Integer.parseInt(i[1]);
		int dec = i2-i1;
		int y = 0;
		for(int j =1;j<dec;j++){
			y = y+j;
		}
		System.out.println(y-i1);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define OUT(a) cout<<(a)<<endl;


//vector<LL> d(n+2,0),revd(n+2,0);
int r[200020]={},l[200020]={},n;
void dp(int a[],vector<LL> &d){
    REPN(i,1,n){
        for(int j=i-1;j>=0;--j){
            if(d[j]<d[i]){
                a[i]=j;
                break;
            }
            j=a[j]+1;
            continue;
        }
    }
    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL ans=0;
    //int n;
    cin >>n;
    vector<LL> d(n+2,0),revd(n+2,0);
    //int r[200020]={},l[200020]={};
    REP(i,n){
        cin >>d[i+1];
        revd[n-i]=d[i+1];
    }

    dp(l,d);
    dp(r,revd);

    REPN(i,1,n){
        ans+=d[i]*(i-l[i])*((n+1-r[n+1-i])-i);
    }
    cout << ans <<endl;


    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    FOR(b, k + 1, n) {
        ll x = (n - b + 1) / b;
        ll y = n - b * (x + 1);
        ans += (b - k) * (x + 1);
        if(y >= k) ans += y - k + 1;
        if(k == 0) ans -= 1;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Loop(i,a,b) for(int i=a;i<b;++i)
#define NLoop(i,a,b) for(int i=a;i>=b;--i)
#define print(arr,n,m) for(int i=0;i<n;++i) { for(int j=0;j<m;++j) cout<<arr[i][j]<<" "; cout<<endl; }
#define print2(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define mp(a,b) make_pair(a,b)
#define MOD 1000000007
#define pb(x) push_back(x)
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
using namespace std;
typedef long long int ll;
ll gcd(ll a,ll b) { if (b == 0) return a; return gcd(b, a % b);  }

ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
//class compare { public: bool operator() (ll a,ll b) { return a>b;};
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,x;
	cin>>n>>x;
	vector<ll> arr(n);
	for(ll i=0;i<n;++i) cin>>arr[i];
	ll d = 0;
	ll co = 1;
	for(ll i=0;i<n;++i)
	{
		d += arr[i];
		if(d>x) break;
		++co;
	}
	cout<<co<<endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=2e5;
const int inf=1e9;
int main(){
	int N;long C; cin>>N>>C;
	long X[N+2],V[N+1]; X[0] = V[0] = 0; X[N+1] = C;
	rep(i,1,N+1) cin>>X[i]>>V[i];
	long L[N+1],R[N+1]; R[0] = L[N] = 0;
    long mL[N+1],mR[N+1]; mR[0] = mL[N] = 0;
	for(int i = 1; i <= N; i++){ R[i] = R[i-1] + V[i]; }
	for(int i = 1; i <= N; i++){ R[i] -= X[i]; mR[i] = max(mR[i-1], R[i]); }
	for(int i = N-1; i >= 0; i--){ L[i] = L[i+1] + V[i+1]; }
	for(int i = N-1; i >= 0; i--){ L[i] += X[i+1] - C; mL[i] = max(mL[i+1], L[i]); }
	long ans = 0;
	for(int i = 0; i <= N; i++){ ans = max(ans, R[i] - X[i] + mL[i]); }
	for(int i = N; i >= 0; i--){ ans = max(ans, L[i] + X[i+1] - C + mR[i]); }
	cout<<ans<<endl;
    //print(R,,N+1);print(L,,N+1);
    //print(mR,,N+1);print(mL,,N+1);
}

Measured memory_bytes: 4992
using System;

class p0003
{

    static void Main(string[] args)
    {
        int[] a = new int[3];

        int n = int.Parse(Console.ReadLine());

        while (0 < n--)
        {
            var s = Console.ReadLine().Split(' ');
            for (int i = 0; i < 3; ++i)
            {
                a[i] = int.Parse(s[i]);
                a[i] = a[i] * a[i];
            }

            Array.Sort(a);
            Console.WriteLine((a[0] + a[1] == a[2]) ? "YES" : "NO");
        }

    }
    
}

Measured memory_bytes: 5564
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N=3e5+10;
typedef pair<int,int> pii;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,ans[N],rem[N];
pii a[N];
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i].fi=gi(),a[i].se=i;
    sort(a+1,a+n+1);
    int p=1;
    for(int i=1;i<=n;i++) {
        ans[a[i].fi]=a[i].se;
        for(int j=1;j<=a[i].se-1;j++) {
            while(ans[p]) p++;
            ans[p]=a[i].se; p++;
        }
        if(p-1>a[i].fi) return puts("No"),0;
    }
    for(int i=1;i<=n;i++) rem[i]=n-i;
    for(int i=p,j=1;i<=n*n;i++) {
        if(ans[i]) continue;
        while(!rem[a[j].se]) j++;
        if(a[j].fi>i) return puts("No"),0;
        ans[i]=a[j].se;rem[a[j].se]--;
    }
    puts("Yes");
    for(int i=1;i<=n*n;i++) printf("%d ",ans[i]);
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


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


const int INF = 1 << 29;

auto solve() {
    ll N, P;
    cin >> N >> P;

    if(N==1) {
        return P;
    }

    map<ll, int> sp;
    FOR(i, 2, 100100) {
        while (P % i == 0) {
            P /= i;
            sp[i]++;
        }
    }

    ll res = 1;
    for (auto &&e: sp) {
        ll t = e.second;
        while (t >= N) {
            res *= e.first;
            t -= N;
        }
    }

    return res;
}


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

    cout << solve() << endl;
//    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
#define repi(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define endl "\n"
#define ing long long
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

#define MAX 400

#define s first.first
#define l first.second
#define p second

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    vector<int> w;
    vector<pair<pair<int,int>,int>> in;
    vector<vector<int>> dp;
    
    cin>>n;

    in.resize(n);

    for(int i = 0; i  < n; i++){
        cin>>in[i].s>>in[i].l>>in[i].p;
    }

    cin>>m;
    
    w.resize(m);

    dp.resize(2,vector<int>(MAX*MAX,0));

    dp[0][0] = 0;
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < MAX; j++){
            for(int k = in[i].s; k <= in[i].l ; k++){
                int num = j + k;
                if(num < MAX) dp[0][num] = max(dp[0][num], dp[0][j] + in[i].p);

                //dp[0][num] = max(dp[0][num], dp[0][num]);
            }
        }
    }


    
    for(int i = 0; i < m; i++){
        cin>>w[i];

        if(dp[0][w[i]] == 0){

            cout<<-1<<endl;
            return 0;
        }
    }
    for(int i = 0; i < m; i++){
        cout<<(dp[0][w[i]]?dp[0][w[i]]:-1)<<endl;
    }

    return 0;
}




Measured memory_bytes: 4732
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(2 * n);
  for (int i = 0; i < 2 * n; ++i)
    cin >> a[i];
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < 2 * n; i += 2)
    ans += a[i];

  cout << ans << endl;

  return 0;
}


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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = 1e5;
int n, a[MAXN + 5], b[MAXN + 5];

int main() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
		b[a[i]] = i;
	}
	for (int i = 1; i <= n; ++i) {
		write(b[i]);
		putchar(' ');
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int K;
  string S;
  cin >> K >> S;
  if ((int)S.size() <= K) {
    cout << S << endl;
  } else {
    cout << S.substr(0, K) << "..." << endl;
  }
  return 0;
}


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

int main()
{
   int n,i,x,count=0;
   scanf("%d\n",&n);
   int a[n];
   for(i=1,x=1e9;i<=n;i++)
   {
       scanf("%d",&a[i]);
       if(a[i]<x)
        x=a[i],
       count++;
   }
   printf("%d\n",count);
   return 0;
}


Measured memory_bytes: 896