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

using namespace std;

#define rep(i,x,n) for(int i=x;i<n;i++)
#define repe(i,x,n) for(int i=x;i<=n;i++)
#define repn(i,x,n) for(int i=x;i>=n;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define F first
#define S second
#define mod 1000000007

typedef long long ll;

const double PI=3.14159265;

struct node
{
	pair<char,node*>nxt;
	node(char c)
	{
		nxt.first=c;
	}
};

node*root;
void insrt(string s)
{
	node*cur=root;
	for(int i=s.length()-2;i>=0;i--)
	{
		if(cur->nxt.second==NULL)
			cur->nxt.second=new node(s[i]);
		cur=cur->nxt.second;
	}
}

bool srch(string t)
{
	node *cur=root;
	for(int i=0;i<t.length();i++)
	{
		if(cur->nxt.first!=t[i])
			return 0;
		cur=cur->nxt.second;
	}
	return 1;
}

int main()
{
	ios::sync_with_stdio(false);
	int n;
	string s,t;
	cin>>n>>s>>t;
	root=new node(s[s.length()-1]);
	insrt(s);
	string newt="";
	for(int i=t.length()-1;i>=0;i--)newt+=t[i];
	string sub="";
	t="";
	for(int i=0;i<newt.length();i++)
	{
		sub=newt.substr(i,newt.length()-i);
		if(srch(sub))break;
		t=newt[i]+t;
	}
	int res=s.size()+t.size();
	cout<<res<<endl;
	//cout<<s+t<<endl;
	return 0;
}






Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>
#include <array>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mn(x) *min_element((x).begin(),(x).end())
#define mx(x) *max_element((x).begin(),(x).end())
#define acc(x) accumulate((x).begin(),(x).end(),0ll)
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ld pi=acos(-1);
const ll inf=(ll)1e12+1;
//const int mod=1000000007;
const int mod=998244353;

int n,m,k;
const int N=3e5+10;







int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n >> m;
    int mx=1;
    for(int i=1; i*i<=m; i++){
        if(m%i==0){
            if(i>=n)
                mx=max(mx,m/i);
            if(m/i>=n)
                mx=max(mx,i);
        }
    }
    cout << mx << el;
    
    return 0;
}






Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

    	//ココから下にソースを書く
    	Scanner scanner = new Scanner(System.in);

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();


        int ptn1 = a + b;
        int ptn2 = a + c;
        int ptn3 = b + c;

        if(ptn1 <ptn2) {
        	if (ptn1 <ptn3) {
        		System.out.println(ptn1);
        	}else {
        		System.out.println(ptn3);
        	}
        }else if(ptn2<ptn3) {
        		System.out.println(ptn2);
        }else {
        		System.out.println(ptn3);
        }

     }

}


Measured memory_bytes: 21844
def main():
    n = int(input())
    machi_list = list(map(int, input().split()))
    yusha_list = list(map(int, input().split()))

    init_sum = sum(machi_list)

    for i in range(n):
        machi_list[i] -= yusha_list[i]
        if machi_list[i] < 0:
            machi_list[i+1] += machi_list[i]
            if machi_list[i+1] < 0:
                machi_list[i+1] = 0
            machi_list[i] = 0

    print(init_sum-sum(machi_list))

if __name__ == '__main__':
    main()

Measured memory_bytes: 81892
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

int n,maxv;
vector<vector<int>>g;
map<pair<int,int>,int>mp;
vector<int>color;
vector<bool>visited;

void dfs(int v){
    visited[v]=1;
    int c=1;
    for(auto x:g[v]){
        if(!visited[x]){
            if(c==color[v])++c;
            mp[make_pair(v,x)]=c;
            color[x]=c;
            ++c;
            dfs(x);
        }
    }
}

void solve(){
    cin>>n;
    g.resize(n);
    color.resize(n);
    visited.resize(n);
    vector<int>a(n-1),b(n-1);
    rep(i,n-1){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        g[a[i]].pb(b[i]);
        g[b[i]].pb(a[i]);
    }
    maxv=0;
    rep(i,n)chmax(maxv,(int)g[i].size());
    color[0]=0;
    dfs(0);
    cout<<maxv<<"\n";
    rep(i,n-1)cout<<mp[make_pair(a[i],b[i])]<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 15232
#include <bits/stdc++.h>
using namespace std;
int main(){
    int c1=0,c2=0,c3=0,c4=0,x;
    string s;
    cin>>x;
    for(int i=0;i<x;i++){
        cin>>s;
        if(s=="AC"){
            c1++;
        }
        else if(s=="WA")
            c2++;
        else if (s=="TLE")
            c3++;
        else if(s=="RE")
            c4++;
        
    }

    cout<<"AC x "<<c1<<endl;
    cout<<"WA x "<<c2<<endl;
    cout<<"TLE x "<<c3<<endl;
    cout<<"RE x "<<c4<<endl;



    return 0;

}

Measured memory_bytes: 3592
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <boost/range/algorithm.hpp>
#include <boost/integer/common_factor_rt.hpp>

using namespace std;

int N, M, ret;
bool b[100001];
int dp[100001];

int step(int s) {
    if (b[s]) {
        return 0;
    }
    if (s == N) {
        return 1;
    }
    int ret = dp[s + 1];
    if (s + 2 != N + 1) {
        ret += dp[s + 2];
    }
    return ret % 1000000007;
}

int main() {

    while (cin >> N >> M) {
        for (int i = 0; i <= N; i++) {
            b[i] = false;
        }
        for (int i = 0; i < M; i++) {
            int a;
            cin >> a;
            b[a] = true;
        }
        for (int i = 0; i <= N; i++) {
            dp[N - i] = step(N - i);
        }

        cout << dp[0] << endl;
    }

    return 0;
}



Measured memory_bytes: 768
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			1e9
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};    // King's move
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hx[]={-2,-2,-1,+1,+2,+2,-1,+1};    // Knight's move
int hy[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)2e5+9;


int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n>>k; int a[n+9];
    for(i=1; i<=n; i++) cin>>a[i];
    sort(a+1, a+n+1);

    int ans = 0;
    for(i=1; i<=k; i++) ans+=a[i];

    cout<<ans<<endl;

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 3640
let n = stdin.ReadLine() |> int
let caps = stdin.ReadLine().Split() |> Array.map int

// 正しいかぶせ方は{a;b;c;a;b;c;a;...}なる集合であり、かつa^^^b=cが成立している必要がある
caps |> Seq.countBy (fun x -> x) |>Seq.toArray 
|> function
| [|(ax,ai);(bx,bi);(cx,ci)|] when
    ([ai;bi;ci]|>List.max) - ([ai;bi;ci]|>List.min) = 0
    && ax ^^^ bx = cx -> 
        "Yes"
| [|(ax,ai);(bx,bi)|] ->
    match [|(ax,ai);(bx,bi)|] |> Array.sort with
    | [|(0,ai);(bx,bi)|] when bi = 2 * ai ->
        "Yes"
    | _  ->
        "No"
| [|(0,ai)|] ->
    "Yes"
| _ ->
    "No"
|> stdout.WriteLine


Measured memory_bytes: 32988
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  int result = 0;
  cin >> N;
  cin >> S;
  int A[N];
  int c = N;
  for(int b = 0;b < c;b++){
    
  for(int a = 0;a < c;a++)A[a] = 0;
A[0] = N;
  
 int i = 1, j = 0;
    
 while (i < N) {
   while (i+j < N && S[j] == S[i+j]) ++j; // 右向きにjを伸ばしていく
   A[i] = j;
   if(result < j&&i >= j)result = j;
   if (j == 0) { ++i; continue;}
   int k = 1;
   while (i+k < N && k+A[k] < j) A[i+k] = A[k], ++k; // i~j間にkを走らせる
   i += k; j -= k;
 }
    S.erase(0,1);
    N -= 1;
  }
  
  cout << result << endl;
  
}

Measured memory_bytes: 256
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000
#define MAXM 200000

#define M 1000000007

vector<vector<pair<int,long>>> g;
int n, m;
int s, t;

int input() {
	if (scanf("%d %d", &n, &m) < 0) return 0;
	g.resize(n);
	scanf("%d %d", &s, &t);
	s--, t--;
	for (int i=0; i<m; i++) {
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		x--, y--;
		g[x].push_back({y,z});
		g[y].push_back({x,z});
	}
	return 1;
}

void init() {
}

void dijkstra(int s, long *d, long *c) {
	typedef pair<long,int> node;
	priority_queue<node,vector<node>,greater<node>> q;
	for (int i=0; i<n; i++) {
		d[i] = LONG_MAX;
		c[i] = 0;
	}
	d[s] = 0;
	c[s] = 1;
	q.push({0, s});
	while (!q.empty()) {
		node x = q.top();
		q.pop();
		int v = x.second;
		if (x.first > d[v]) continue;
		for (auto e: g[v]) {
			int u = e.first;
			long w = d[v] + e.second;
			if (w < d[u]) {
				d[u] = w;
				c[u] = c[v];
				q.push({w, u});
			}
			else if(w == d[u]) {
				c[u] += c[v];
				c[u] %= M;
			}
		}
	}
}

long ds[MAXN], dt[MAXN];
long ns[MAXN], nt[MAXN];

void dec(long &a, long b) {
	a = (a-b) % M;
}

long solve() {
	dijkstra(s, ds, ns);
	dijkstra(t, dt, nt);
	//printa(ds, n); printa(ns, n); printa(dt, n); printa(nt, n);
	long len = ds[t];
	long r = ns[t] * nt[s] % M;
	for (int i=0; i<n; i++)	{
		if (ds[i]==dt[i]) {
			long x = ns[i]*nt[i] % M;
			dec(r, x * x);
		}
	}
	for (int i=0; i<n; i++) {
		for (auto e: g[i]) {
			int j = e.first;
			if (ds[i] + dt[j] + e.second != len)
				continue;
			if (ds[i]*2 < len && dt[j]*2 < len) {
				long x = ns[i]*nt[j] % M;
				dec(r, x * x);
			}
		}
	}
	if (r<0) r += M;
	return r;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
	g.clear();
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





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

int check(int x, string s){
  if(s.at(x)=='0') return 0;
  if(s.at(x)=='1') return 0;
  if(s.at(x)=='2') return 0;
  if(s.at(x)=='3') return 0;
  if(s.at(x)=='4') return 0;
  if(s.at(x)=='5') return 0;
  if(s.at(x)=='6') return 0;
  if(s.at(x)=='7') return 0;
  if(s.at(x)=='8') return 0;
  if(s.at(x)=='9') return 0;
  return 1;
}

int main(){
  int A, B; cin >> A >> B;
  string S; cin >> S;
  for(int i=0;i<A+B+1;i++){
    if(i==A && S.at(i)!='-'){
      cout << "No" << endl;
      return 0;
    }
    if(i!=A){
      if(check(i,S)==1){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const int INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};

int main(){
  string s;
  cin >> s;
  if(s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR"){
    cout << 1 << endl;
  }
  else if(s == "RRS" || s == "SRR"){
    cout << 2 << endl;
  }
  else if(s == "RRR"){
    cout << 3 << endl;
  }
  else cout << 0 << endl;
}

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

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

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

  string s, t;
  cin >> s >> t;
  int ans = 0;

  rep(i, 0, s.size()) {
    if (s[i] != t[i]) ++ans;
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    Cins(int, n, b);
    Cins(int, n-1, c);

    ll ans = 0;
    For(i, n) ans += b[i];
    For(i, n-1){
        if(a[i]+1 == a[i+1]) ans += c[a[i]-1];
    }
    Cout(ans);
}


Measured memory_bytes: 256
#pragma optimization_level 3
#include <bits/stdc++.h>
#define  f               first
#define  s               second
#define  sym(s)          s = "#" + s + "#";
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  newl            cout<<"\n";
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}

using namespace std;
using ll              =  long long;
using ld              =  long double;
const ll   MOD        =  1e+9 + 7;
const ll   INF        =  LLONG_MAX;
const int  N          =  (int)2e+5 + 8;

ll n, x[N], y[N];

void MAIN(int tc) {
    cin >> n;
    vector<pair<ll, ll>> v;
    for (int i = 1; i <= n; i++) {
        ll x, y;
        cin >> x >> y;
        v.push_back({x, y});
    }
    v.push_back({0, 0});
    sort(all(v), [&](pair<ll, ll> p1, pair<ll, ll> p2) {
        return p1.f == p2.f ? p1.s < p2.s : p1.f < p2.f;
    });

    ll res1 = 0;
    {
        vector<ll> mx(n + 2, -INF), mn(n + 2, INF);
        for (int i = n; i >= 1; i--) {
            mx[i] = max(mx[i + 1], v[i].f + v[i].s);
        }

        for (int i = 1; i <= n; i++) {
            mn[i] = min(mn[i - 1], v[i].f + v[i].s);
        }

        for (int i = 1; i <= n; i++) {
            res1 = max(res1, mx[i] - mn[i]);
        }
    }

    sort(all(v), [&](pair<ll, ll> p1, pair<ll, ll> p2) {
        return p1.f == p2.f ? p1.s > p2.s : p1.f < p2.f;
    });

    ll res2 = 0;
    {
        vector<ll> mx(n + 2, -INF), mn(n + 2, INF);
        for (int i = n; i >= 1; i--) {
            mx[i] = max(mx[i + 1], v[i].f - v[i].s);
        }

        for (int i = 1; i <= n; i++) {
            mn[i] = min(mn[i - 1], v[i].f - v[i].s);
        }

        for (int i = 1; i <= n; i++) {
            res2 = max(res2, mx[i] - mn[i]);
        }
    }

    deb1(max(res1, res2));

}

int main() {
    ios:: sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout << fixed; cout << setprecision(10);

    int test_cases = 1;
    //cin>>test_cases;
    for (int i = 1; i <= test_cases; i++) {
        MAIN(i);
    }
}

Measured memory_bytes: 9504
input()
A = list(map(int, input().split()))

a_score = 0
b_score = 0

A.sort(reverse=True)

for i in range(len(A)):
  if i % 2 == 0:
    a_score += A[i]
  else:
    b_score += A[i]

print(a_score - b_score)

Measured memory_bytes: 3060
#行数ｒ、列数ｃを入力
r,c = map(int,input().split())

#r x c の行列Aの入力
A = [[int(i) for i in input().split()]for j in range(r)]

#各行と各列をそれぞれたして行列に追加
for i in range(r):
    addr = 0 #行の合計
    for j in range(c):
        addr += A[i][j]
    A[i].append(addr) #各行の最後に追加

B = list(map(list,(zip(*A)))) #リストAの行列を転置したBを作成
for i in range(c+1): #行を追加してサイズが1増えたから
    addc = 0 #もとの列の合計(転置後の行の合計)
    for j in range(r):
        addc += B[i][j]
    B[i].append(addc) #リストに追加

A = list(map(list,(zip(*B)))) #Bを転置してもとに戻す

for i in range(r+1):
    for j in range(c+1):
        if j < c:
            print(A[i][j],end=" ")
        elif j == c:
            print(A[i][j])
    



Measured memory_bytes: 6456
#include<bits/stdc++.h>
//#include<inttypes.h>//__int64,__int128..
#define MAX_N 100005
//vector&pair
#define pb push_back
#define mp make_pair
//math
#define sq(x) ((x)*(x))
#define abs(x) ((x)>0?(x):(-(x)))//Regardless of type
//for pair
#define fi first
#define se second
//infinit
#define LL_inf (1LL<<60)
#define full_inf 0x7fffffff
#define half_inf 0x3fffffff
//MOD
#define MOD 1000000007LL
using namespace std;
//type
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pil;
typedef long double LD;
struct node{
	LL l,r,idx;
};
struct cmp1{
	bool operator()(const node x,const node y){
		if(x.r==y.r)	return x.idx<y.idx;
		return x.r<y.r;
	}
};
struct cmp2{
	bool operator()(const node x,const node y){
		if(x.l==y.l)	return x.idx<y.idx;
		return x.l>y.l;
	}
};
set<node,cmp1> Sl;
set<node,cmp2> Sr;
LL n,ans;
int main(){
	LL i,j,x,y=0,z=0;
	node p,q;
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		scanf("%lld %lld",&p.l,&p.r);
		p.idx=i;
		Sl.insert(p);
		Sr.insert(p);
		if(p.r<0)	y++;
		if(p.l>0)	z++;
	}
	p=*Sl.begin();
	q=*Sr.begin();
	x=0;
	if(y>z){
		Sl.erase(p);
		Sr.erase(p);
		ans+=max(x-p.r,0LL);
		if(max(x-p.r,0LL))	x=p.r;
	}else if(z>y){
		Sl.erase(q);
		Sr.erase(q);
		ans+=max(q.l-x,0LL);
		if(max(q.l-x,0LL))	x=q.l;
	}else{
		x=0;
	}
	while(!Sl.empty()){
		p=*Sl.begin();
		q=*Sr.begin();
		if(x-p.r>=q.l-x){
			Sl.erase(p);
			Sr.erase(p);
			ans+=max(x-p.r,0LL);
			if(max(x-p.r,0LL))	x=p.r;
		}else{
			Sl.erase(q);
			Sr.erase(q);
			ans+=max(q.l-x,0LL);
			if(max(q.l-x,0LL))	x=q.l;
		}
	}
	ans+=abs(x);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 12800
package main

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

func main() {
	r := readInt()
	fmt.Println(3 * r * r)
}

func toInt(s string) int {
	i, e := strconv.Atoi(s)
	if e != nil {
		fmt.Println(e)
	}
	return i
}

func nextLine(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return toInt(nextLine(scanner))
}

func readStr() string {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return nextLine(scanner)
}

func readLineAsStr() string {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanLines)
	return nextLine(scanner)
}

func readLineAsInts() []int {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanLines)
	s := strings.Split(nextLine(scanner), " ")
	ints := make([]int, len(s))
	for i, str := range s {
		ints[i] = toInt(str)
	}
	return ints
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(i) sort((i).begin(),(i).end())
#define INF 2000000000
constexpr ll mod = 1000000007;

int main() {
	char a, b;
	cin >> a >> b;
	if (a > b) cout << '>' << "\n";
	else if (a < b)cout << '<' << "\n";
	else cout << '=' << "\n";

	return 0;
}

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

int main(){
    int n;
    cin>>n;
    map<long long,int> m;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        m[t]++;
    }
    long long check=-1;
    long long ans=0;
    for(auto it=m.rbegin();it!=m.rend();it++){
        if(it->second>1){
            if(check==-1&&it->second>3){
                ans=it->first*it->first;
                break;
            }
            else if(check==-1&&it->second>1){
                check=it->first;
                continue;
            }
            else if(check!=-1){
                if(it->second>1){
                    ans=it->first*check;
                    break;
                }
            }
        }
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 6528
import sys
readline = sys.stdin.readline
 
INF = 10**30
def calc(k):
    if k in D:
        return D[k]
    if not k:
        return 0
    res = k*d
    if k != k//2 + 1:
        res = min(res, calc(k//2 + 1) + a + d*(2-k%2))
    if k != k//3 + 1:
        res = min(res, calc(k//3 + 1) + b + d*(3-k%3))
    if k != k//5 + 1:
        res = min(res, calc(k//5 + 1) + c + d*(5-k%5))
    
    if k >= 2:
        res = min(res, calc(k//2) + a + d*(k%2))
    if k >= 3:
        res = min(res, calc(k//3) + b + d*(k%3))
    if k >= 5:
        res = min(res, calc(k//5) + c + d*(k%5))
    D[k] = res
    return res
T = int(readline())
Ans = [None]*T
for qu in range(T):
    n, a, b, c, d = map(int, readline().split())
    D = dict()
    Ans[qu] = calc(n)
print('\n'.join(map(str, Ans)))

Measured memory_bytes: 100740
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

int val1[100010], maxval1[100010];
int val2[100010], maxval2[100010];

signed main() {
	int N, C;
	cin >> N >> C;

	vector<int> x(N), v(N);
	rep(i, N) cin >> x[i] >> v[i];

	val1[0] = v[0] - x[0];
	REP(i, 1, N - 1) {
		val1[i] = v[i] - (x[i] - x[i - 1]) + val1[i - 1];
	}

	val2[N - 1] = v[N - 1] - (C - x[N - 1]);
	for (int i = N - 2; i >= 0; i--) {
		val2[i] = v[i] - (x[i + 1] - x[i]) + val2[i + 1];
	}

	maxval1[0] = max(0LL, val1[0]);
	REP(i, 1, N - 1) {
		maxval1[i] = max(val1[i], maxval1[i - 1]);
	}

	maxval2[N - 1] = max(0LL, val2[N - 1]);
	for (int i = N - 2; i >= 0; i--) {
		maxval2[i] = max(val2[i], maxval2[i + 1]);
	}

	int ret = 0;
	ret = max(maxval1[N - 1], ret);
	ret = max(maxval2[0], ret);

	rep(i, N - 1) {
		int tmp = val1[i] + maxval2[i + 1] - x[i];
		ret = max(tmp, ret);
	}

	REP(i, 1, N - 1) {
		int tmp = val2[i] + maxval1[i - 1] - (C - x[i]);
		ret = max(tmp, ret);
	}

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main(){
  ll a,b,c;
  cin>>a>>b>>c;
  if(a + b >= c){
    cout<<b+c<<"\n";
  }else{
    cout<<a + 2*b + 1<<"\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int b,is_red=0,count=0;
    char a[200000]={};
  scanf("&d",&b);
  scanf("%*s%s",&a);
  for(int i=0;i<200000;i++){
      if(a[i]=='R')is_red++;
  }
  count=is_red;
  for(int i=0;i<is_red;i++){
      if(a[i]=='R')count--;
  }
  printf("%d",count);
  return 0;
}


Measured memory_bytes: 1920
n = int(input())
c = input()

res = 0
left, right = c.find('W'), c.rfind('R')
while left != -1 and right != -1 and left < right:
    res += 1
    left += 1
    right -= 1
    while left < n and c[left] != 'W':
        left += 1
    while right >= 0 and c[right] != 'R':
        right -= 1
print(res)


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

using namespace std;

int main(void)
{
    int cc;
    int dd;
    int ee;
    int A[3];

    cin >> A[0] >> A[1] >> A[2];

    sort(A,A+3);

    cout << A[0] <<" "<< A[1] << " "<<A[2] << endl;




   return 0;
}



Measured memory_bytes: 3128
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int kosu=sc.nextInt();
		int mjs=sc.nextInt();
		String[] aa=new String[kosu];

		for(int i=0; i<kosu; i++) {
			aa[i]=sc.next();
		}
		Arrays.sort(aa);
		String src="";
		for(int i=0; i<kosu; i++) {
			src=src+aa[i];
		}
		System.out.println(src);
	}
}

Measured memory_bytes: 28500
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define GIO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{ GIO;
string str;
string str1="";
ll x;
cin>>str>>x;
for(ll i=0;i<str.length();i=i+(x))  str1 = str1+str[i];

cout<<str1<<endl;

return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a,b,k,i,m;
    scanf("%d%d%d",&a,&b,&k);
    m=a+k-1;
    for(i=a;i<a+k;i++)if(b>=i)printf("%d\n",i);
    for(i=b-k+1;i<=b;i++)if(i>m&&i>=a)printf("%d\n",i);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){

	int a=0,b=0;
	int i;

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


	for( i=0;i<30;i++){

		if(b<=(a-1)*i+1)
			break;

	}

	printf("%d",i);
	return 0;
}


	




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

int main() {
  int N;
  cin >> N;
  
  int D = N % 10;
  N = N / 10;
  int C = N % 10;
  N = N / 10;
  int B = N % 10;
  N = N / 10;
  int A = N % 10;
  
  int E = ( A + B + C + D - 7 ) / 2;
  
  if(E == B) {
    cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
  }
  else if(E == C) {
    cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
  }
  else if(E == D) {
    cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
  }
  else if(E == B + C) {
    cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
  }
  else if(E == B + D) {
    cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
  }
  else if(E == C + D) {
    cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
  }
  else if(E == B + C + D) {
    cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
  }
  else {
    cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
  }
}


Measured memory_bytes: 256
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
ans=[0,0,0]
for i in l:
    ans[0],ans[1],ans[2]=max(ans[1],ans[2])+i[0],max(ans[0],ans[2])+i[1],max(ans[0],ans[1])+i[2]
print(max(ans))

Measured memory_bytes: 63064
// Author: Jashan Bansal
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second   
#define mp make_pair
#define int long long
#define ll long long
#define pii pair<int,int>
#define all(arr) arr.begin(), arr.end()
#define sz(arr) ((long long)arr.size())
// const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
#define log1(x) cout << x << '\n'
#define log2(x,y) cout << x << " " << y <<'\n'
#define log3(x,y,z) cout << x <<" " << y <<" " << z << '\n'
#define logarr(arr,n) for(int __=0; __ < n; __++)   cout << arr[__] << " "; cout << '\n'

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

string arr[1001];

void solve(){
    int h,w; cin >> h >> w;

    for(int i=0; i<h; i++){
        cin >> arr[i];
    }
    vector<vi> dp(h, vi(w, 0));

    for(int i=1; i<w; i++){
        if(arr[0][i] == '#'){
            break;
        }
        dp[0][i] = 1;
    }

    for(int i=1; i<h; i++){
        if(arr[i][0] == '#'){
            break;
        }
        dp[i][0] = 1;
    }

    for(int i=1; i<h; i++){
        for(int j=1; j<w; j++){
            if(arr[i][j] == '#'){
                dp[i][j] = 0;
            }
            else{
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
            }
        }
    }

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

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}   


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

int dig_sum(int n) {
	int sum = 0;
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}
	return sum;
}




int main() {

	int X;
	cin >> X;

	if (X % dig_sum(X) == 0)
		cout << "Yes";

	else
		cout << "No";

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if(A == B and A != C) puts("Yes");
    else if(A == C and A != B) puts("Yes");
    else if(B == C and B != A) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 3640
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.endl(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
vec2int b(2, vecint(3, 0));
vec2int c(3, vecint(2, 0));
vec2int G(3, vecint(3, -1));
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vecll a(x), b(y), c(z);
  REPe(e, a) cin >> e;
  REPe(e, b) cin >> e;
  REPe(e, c) cin >> e;
  vecll ab(x * y, 0);
  int cnt = 0;
  REP(i, x) {
    REP(j, y) {
      ab[cnt] = a[i] + b[j];
      cnt++;
    }
  }
  sort(ab.rbegin(), ab.rend());
  int size = min(k, x * y);
  vecll abred(size, 0);
  REP(i, size) { abred[i] = ab[i]; }
  vecll abc(size * z);
  cnt = 0;
  REP(i, size) {
    REP(j, z) {
      abc[cnt] = abred[i] + c[j];
      cnt++;
    }
  }
  sort(abc.rbegin(), abc.rend());
  REP(i, k) { cout << abc[i] << endl; }
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,i,j,cnt,xlh,ans,op,a[302][302],b[302],v[302];
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)v[i]=1;
	ans=n;
	for(i=1;i<=n;i++)
	 for(j=1;j<=m;j++)scanf("%d",&a[i][j]);
	for(cnt=1;cnt<m;cnt++){
		for(i=1;i<=m;i++)b[i]=0;
		for(i=1;i<=n;i++)
		 for(j=1;j<=m;j++)if(v[a[i][j]]){
		 	b[a[i][j]]++;break;
		 }
		xlh=0;
		for(i=1;i<=m;i++){
			if(b[i]>xlh)op=i;
		 xlh=max(xlh,b[i]);
	 }
		ans=min(ans,xlh);
		v[op]=0;
	}
	printf("%d",ans);
}

Measured memory_bytes: 640
// https://atcoder.jp/contests/abc073/tasks/abc073_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
const int INF = 1e9;
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> v;
    REP(i, r) {
        int t;
        cin >> t;
        v.push_back(t - 1);
    }
    sort(ALL(v));
    vector<vector<int>> g(n, vector<int>(n, INF));
    REP(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        g[a][b] = g[b][a] = c;
    }
    // ダイクストラ法
    REP(k, n) REP(i, n) REP(j, n) { g[i][j] = min(g[i][j], g[i][k] + g[k][j]); }

    int M = INT32_MAX;
    do {
        int tmp = 0;
        REP(i, r - 1) tmp += g[v[i]][v[i + 1]];
        M = min(M, tmp);
    } while (next_permutation(ALL(v))); // 次の順列を生成

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


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] as = new int[m];
		int[] bs = new int[m];
		for (int i = 0; i < m; i++) {
			as[i] = sc.nextInt() - 1;
			bs[i] = sc.nextInt() - 1;
		}

		int count = 0;
		for (int i = 0; i < m; i++) {
			UnionFindTree uf = new UnionFindTree(n);
			for (int j = 0; j < m; j++) {
				if (i == j) {
					continue;
				}
				uf.union(as[j], bs[j]);
			}
			for (int j = 1; j < n; j++) {
				if (!uf.same(0, j)) {
					count++;
					break;
				}
			}
		}
		System.out.println(count);
	}
}

class UnionFindTree {

	int[] parent; //インデックスにとノードを対応させ、そのルートノードのインデックスを格納
	int[] rank; //parentと同様に、木の高さを格納

	public UnionFindTree(int size) {
		this.parent = new int[size];
		this.rank = new int[size];

		for (int i = 0; i < size; i++) {
			makeSet(i);
		}
	}

	public void makeSet(int i) {
		parent[i] = i;
		rank[i] = 0; //集合の高さ
	}

	public void union(int x, int y) {
		int xRoot = find(x);
		int yRoot = find(y);

		//xが属する木の方が大きい場合
		if (rank[xRoot] > rank[yRoot]) {
			parent[yRoot] = xRoot; //yの親をxに更新
		} else if (rank[xRoot] < rank[yRoot]) {
			parent[xRoot] = yRoot;
		} else if (xRoot != yRoot) {
			parent[yRoot] = xRoot;
			rank[xRoot]++; //同じ高さの木がルートの子として着くから大きさ++;
		}
	}

	//引数の属する木のルートのidを返す
	public int find(int i) {
		if (i != parent[i]) {
			parent[i] = find(parent[i]);
		}
		return parent[i];
	}

	//同じ木に属しているか
	public boolean same(int x, int y) {
		return find(x) == find(y);
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-6;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

int N;
int a[100005];

ll doit(int f)
{
	ll sum = 0, res = 0;
	for(int i=0,j=f; i<N; ++i,j*=-1){
		sum += a[i];
		if(sum >= 0 && j < 0) { res += sum+1, sum = -1; }
		else if(sum <= 0 && j > 0) { res += 1-sum, sum = 1; }
	}
	return res;
}

void solve()
{
	cout << min(doit(1), doit(-1)) << endl;
}

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

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

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
# define M_PI           3.14159265358979323846



int main()
{    
    ll n,i,h1,h2,m1,m2,k,h,m;
    char t[200001];
    cin>>t;
    n=strlen(t);
    for(i=0;i<n;i++)
    {
        if(t[i]=='?')
            t[i]='D';
    }
    cout<<t;
}




Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll>a(n), ans(n,0);
    ll sum;
    rep(i,0,n){
        cin >> a[i];
    }
    rep(i,0,n-1){
        ans[i+1] = a[i+1] - ans[i];
    }
    ans[0] = (a[0]-ans[n-1])/2;
    rep(i,0,n-1)ans[i+1] = a[i+1] - ans[i];
    cout << 2*ans[n-1] << " " ;
    rep(i,0,n-1)cout << 2*ans[i] << " " ;
    cout << endl;

}

Measured memory_bytes: 2944
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        var sb = new StringBuilder();

        for(int i=1; i<=n; i++) {
            var c = calc(i);
            sb.AppendLine(c.ToString());
        }
        return sb;
    }

    static int calc(int n) {
        int co = 0;

        for(int x=1; x<=n; x++) {
            var xx = x*x;
            if(xx > n) break;

            for(int y=1; y<=n; y++) {
                var yy = y*y;
                var xy = x*y;
                if(xx + yy + xy > n) break;

                for(int z=1; z<=n; z++) {
                    var zz = z*z;
                    var xz = x*z;
                    var yz = y*z;

                    var r = xx + yy + zz + xy + yz + xz;
                    if (r == n){
                        co++;
                    }
                    if(r > n) break;
                }
            }
        }

        return co;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        if (n == 0) return ret;
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 27496
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <cstdio>
#include <cstdint>
#include <unistd.h>
#include <queue>

using i64 = std::uint_fast32_t;

namespace io {
  constexpr int is = 1 << 17;
  char ib[is], *ip = ib + is, it;
  inline char getc() {
    if (ip == ib + is) { read(STDIN_FILENO, ib, is); ip = ib; }
    return *ip++;
  }
  inline i64 scan() {
    i64 r = 0;
    if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
    else while ((it = *ip++) & 16) r = r * 10 + it - '0';
    return r;
  }
  constexpr int os = 1 << 17;
  char ob[os], *op = ob, ot;
  inline void putc(const char c) {
    *op++ = c;
    if (op == ob + os) { write(STDOUT_FILENO, ob, os); op = ob; }
  }
  /* x shoud be greater than or equal to zero */
  inline void print(i64 x) {
    char d[20];
    int i = 0;
    while (true) {
      d[i] = x % 10 + 48;
      x /= 10;
      ++i;
      if (x <= 0) break;
    }
    while (i--) {
      putc(d[i]);
    }
  }
  inline void flush() {
    write(STDOUT_FILENO, ob, op - ob);
  }
}

signed main() {
  i64 n = io::scan();
  i64 k = io::scan();
  if (k >= n) {
    puts("0");
    return 0;
  }
  i64 s = 0;
  std::priority_queue<i64> que;
  for (int i = 0; i < n - k; i++) {
    i64 h = io::scan();
    s += h;
    que.push(h);
  }
  for (int i = 0; i < k; i++) {
    i64 h = io::scan();
    if (que.top() > h) {
      s += h - que.top();
      que.pop();
      que.push(h);
    }
  }
  io::print(s);
  io::flush();
  return 0;
}

Measured memory_bytes: 2548
#include<stdio.h>
#define N 100000
#define Q 50000

int search(int);
int S[N];
int n;

int main() {
  int q,T[Q],i,j,x,count=0;
  scanf("%d",&n);
  for(i = 0; i < n; i++) {
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0; i < q; i++) {
    scanf("%d",&T[i]);
  }
  for(i = 0; i < q; i++) {
   x = search(T[i]);
    if(x == 1 ) {
      count++;
          }
  }
  printf("%d\n",count);
  return 0;
}

int search(int key) {
  int left = 0,right,mid;
  right = n;
  while(1) {
    mid =(left + right) / 2;
    if(key == S[mid]) {
      return 1;
    }
    if(key < S[mid]) right = mid;
    else if(key > S[mid]) left = mid + 1;
    if(left == right)
      {
        break;
      }
  }
  return 0;
}

Measured memory_bytes: 1180
#include <stdio.h>
#include <string.h>

int main() {
	int i, count;
	char N[200001];
	count = 0;
	scanf("%s", &N);
	for (i = 0; i < strlen(N); i++) {
		count = count + N[i] - 48;
	}
	if (count % 9 == 0) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

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

struct dice {
	int back, bottom, front, left, right, top;
};

class Dice {
	dice a;

public:
	Dice(dice& newA) : a(newA) {}

	dice get() {
		return a;
	}

	bool isSame(Dice& b) {
		return a.back == b.get().back && a.bottom == b.get().bottom && a.front == b.get().front && a.left == b.get().left && a.right == b.get().right && a.top == b.get().top;
	}

	void move(string b) {
		for (char& i : b) {
			dice tmp;
			if (i == 'E') {
				tmp.back = a.back;
				tmp.bottom = a.right;
				tmp.front = a.front;
				tmp.left = a.bottom;
				tmp.right = a.top;
				tmp.top = a.left;
			}
			else if (i == 'N') {
				tmp.back = a.top;
				tmp.bottom = a.back;
				tmp.front = a.bottom;
				tmp.left = a.left;
				tmp.right = a.right;
				tmp.top = a.front;
			}
			else if (i == 'S') {
				tmp.back = a.bottom;
				tmp.bottom = a.front;
				tmp.front = a.top;
				tmp.left = a.left;
				tmp.right = a.right;
				tmp.top = a.back;
			}
			else {
				tmp.back = a.back;
				tmp.bottom = a.left;
				tmp.front = a.front;
				tmp.left = a.top;
				tmp.right = a.bottom;
				tmp.top = a.right;
			}
			a = tmp;
		}
	}

	void rotate() {
		dice tmp;
		tmp.back = a.right;
		tmp.bottom = a.bottom;
		tmp.front = a.left;
		tmp.left = a.back;
		tmp.right = a.front;
		tmp.top = a.top;
		a = tmp;
	}
};

int main() {
	dice a, b;
	cin >> a.top >> a.front >> a.right >> a.left >> a.back >> a.bottom >> b.top >> b.front >> b.right >> b.left >> b.back >> b.bottom;
	Dice c(a), d(b);
	vector<Dice> tmp;
	for (int i = 0; i < 4; ++i) {
		tmp.push_back(c);
		c.rotate();
	}
	c.move("E");
	for (int i = 0; i < 4; ++i) {
		tmp.push_back(c);
		c.move("N");
	}
	c.move("WN");
	for (int i = 0; i < 4; ++i) {
		tmp.push_back(c);
		c.move("E");
	}
	c.move("SS");
	for (int i = 0; i < 4; ++i) {
		tmp.push_back(c);
		c.move("E");
	}
	c.move("NW");
	for (int i = 0; i < 4; ++i) {
		tmp.push_back(c);
		c.move("N");
	}
	c.move("W");
	for (int i = 0; i < 4; ++i) {
		tmp.push_back(c);
		c.rotate();
	}
	int i;
	for (i = 0; i < 24; ++i) {
		if (tmp[i].isSame(d)) break;
	}
	if (i == 24) cout << "No";
	else cout << "Yes";
	cout << endl;
}


Measured memory_bytes: 3220
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
const int C=3001, M=1000000007;

ll dp[C][C], csc[C][C], wynn;
char k[C], q;

int sget(char tab[]){
	for (int z=0;;z++){
		tab[z]=getchar();
		if (tab[z]<=32)	return z;
	}
}

int main(){
	int i, j, n;
	scanf ("%d", &n);
	q=getchar();
	sget(k);
	
	dp[0][0]=1;
	for (j=0;j<n;j++) csc[0][j]=1;
	
	for (i=1;i<n;i++){
		for (j=0;j<n;j++){
			if (j>i)	dp[i][j]=0;
			else if (k[i-1]=='<'&&j>0)	dp[i][j]=csc[i-1][n-1]-csc[i-1][j-1];
			else if (k[i-1]=='<')		dp[i][j]=csc[i-1][n-1];
			else if (k[i-1]=='>'&&j>0)	dp[i][j]=csc[i-1][j-1];
			
			if (j>0)	csc[i][j]=csc[i][j-1]+dp[i][j];
			else 		csc[i][j]=dp[i][j];
			dp[i][j]%=M, csc[i][j]%=M;
		}
	}
	
	for (i=0;i<n;i++)	wynn+=dp[n-1][i];
	wynn%=M;
	if (wynn<0)	wynn+=M;
	printf ("%lld\n", wynn%M);
	
return 0;}

Measured memory_bytes: 140800