akhauriyash/Code-Regression huggingface dataset:
/**Bismillahir Rahmanir Rahim**/


#include<bits/stdc++.h>
using namespace std;
#define ll long long

#define pb push_back
#define io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define clr(v) v.clear()
vector<ll>v;
pair<ll,ll>p;
map<ll,ll>mp;
set<ll>st;
deque<ll>dq;
priority_queue<ll>pq;
#define f(i,b) for(i=0;i<b;i++)
#define f1(i,b) for(i=1;i<=b;i++)
#define fr(i,b)for(i=b-1;i>=0;i--)
ll mn=INT_MAX,mx=INT_MIN;
ll n,m,tc,i,j,tmp,sum,cn,ans,res,pos,flag,l,x,k,dif;

string s,str;


ll a[200007],b[200007];
int main()
{

   io;
ll d;

cin>>n>>m>>d;
if(n>d||(n+m)<d)puts("NO");
else puts("YES");
return 0;
}





Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back

void solve()
{
    int n,k;cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=k;i<n;i++)
    {
        if(a[i]>a[i-k])
            cout<<"Yes"<<nl;
        else
            cout<<"No"<<nl;
    }
}

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

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 5228
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N,L;
    vector<string> S;

    cin >> N >> L;

    for(int i = 0; i < N; i++){
        string s;
        cin >> s;
        S.push_back(s);
    }

    sort(S.begin(), S.end()); 
    for(auto i:S){
        cout << i;
    } 
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
string s;
cin >> s;
for(int i=0;i<s.size();i=i+2){
   if(s[i]=='L'){
      cout << "No" << endl;
      return 0;
   }
}
for(int i=1;i<s.size();i=i+2){
   if(s[i]=='R'){
      cout << "No" << endl;
      return 0;
   }
}
cout << "Yes" << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

typedef struct{
    int v,d;
}E;

int mostmin(int a[],int flg[],int n){
    int i,min=INT_MAX-1,num;
    for(i=0;i<n;i++){
        if(flg[i]==0&&a[i]<min){
            min = a[i]; num=i;
        }
    }
    return num;
}

int main(void){
    int n,i,j,k,v1,v2,d;
    E **a;
    int *dist,*flg,*pass;
    scanf("%d",&n);
    a = (E**)malloc(sizeof(E*)*n);
    dist = (int*)malloc(sizeof(int)*n);
    flg = (int*)malloc(sizeof(int)*n);
    pass = (int*)malloc(sizeof(int)*n);
    for(i=0;i<n;i++){
        dist[i]=INT_MAX;
        flg[i]=0;
        pass[i]=0;
    }
    for(i=0;i<n;i++){
        scanf("%d",&v1);scanf("%d",&k);
        a[v1]=(E*)malloc(sizeof(E)*k);
        pass[v1]=k;
        for(j=0;j<k;j++){
            scanf("%d %d",&v2,&d);
            a[v1][j].v=v2;a[v1][j].d=d;
        }
    }
    dist[0]=0;
    for(i=0;i<n;i++){
        v1 = mostmin(dist,flg,n);
        flg[v1]=1;
        for(j=0;j<pass[v1];j++){
            d = dist[v1]+a[v1][j].d;
            if(d<dist[a[v1][j].v]){
                dist[a[v1][j].v]=d;
            }
        }
    }
    for(i=0;i<n;i++){
        printf("%d %d\n",i,dist[i]);
    }
}


Measured memory_bytes: 5628
S = int(input())

if S == 10**18:
  x1 = 0
  x2 = 0
  x3 = 0
  x4 = 10 ** 9
  x5 = 10 ** 9
  x6 = 0
elif S >= 10**9: 
  num = (S // (10 ** 9) + 1) * 10 ** 9 - S
  x1 = 0
  x2 = 0
  x3 = num
  x4 = S // (10 ** 9) + 1
  x5 = 10 ** 9
  x6 = 1
else:
  x1 = 0
  x2 = 0
  x3 = 1
  x4 = S+1
  x5 = 1
  x6 = 1

print(x1, x2, x3, x4, x5, x6)

Measured memory_bytes: 3064
#include <stdio.h>

int book[101];
int sum[101];
int min;
int n;

void rack(int start, int m, int max)
{
	int i;
	int max_next;
//printf("<%d>", max);

	if (min < max){
		return;
	}


	if (start > n){
		if (min > max){
			min = max;
//			printf("<%d>", min);
		}
		return;
	}

	if (m == 1){
		if (start > n){
			return;
		}
		if (max < sum[n] - sum[start - 1]){
			max = sum[n] - sum[start - 1];
		}
		if (min > max){
			min = max;
		}
		return;
	}
	
	for (i = start; i <= n; i++){
		max_next = max;
		if (max_next < sum[i] - sum[start - 1]){
			max_next = sum[i] - sum[start - 1];
		}
		rack(i + 1, m - 1, max_next);
	}
}
		
int main(void)
{
	int m;
	int i, j;
	
	while (1){
		scanf("%d%d", &m, &n);
		if (m == 0 && n == 0){
			break;
		}
		
		for (i = 1; i <= n; i++){
			scanf("%d", &book[i]);
		}
		
		sum[0] = 0;
		for (i = 1; i <= n; i++){
			sum[i] = (sum[i - 1] + book[i]);
//printf("(%d=%d+%d)", sum[i], sum[i - 1], book[i]);
		}

		min =  100000000;
		rack(1, m, 0);
		
		printf("%d\n", min);
	}
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
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;
}
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;



int main(){
  ll a,b,k;
  cin >> a >> b >> k;
  if(a-k>=0){
    cout << a-k <<" "<<b <<endl;
  }
  else{
    cout << 0 <<" "<< max((ll)0,b-k+a)<<endl;
  }
}
    



Measured memory_bytes: 256
h, n = map(int, input().split())
dp = [[0] * (h+1) for i in range(n)]
a, b = map(int, input().split())
for c in range(1, h+1):
  dp[0][c] = b * ((c-1) // a + 1)
for i in range(1, n):
  a, b = map(int, input().split())
  for c in range(1, h+1):
    opt1 = dp[i-1][c]
    opt2 = dp[i-1][max(0, c-a)] + b
    opt3 = dp[i][max(0, c-a)] + b
    dp[i][c] = min(opt1, opt2, opt3)
print(dp[-1][-1])

Measured memory_bytes: 121068
#include <cstdio>
using namespace std;

char buf[100];

bool IsSuccessive(char *buf, char c) {
  for (int i=0; i<3; i++) {
    int a = i*3;
    if (buf[a] == c && buf[a+1] == c && buf[a+2] == c) return true;
    if (buf[i] == c && buf[i+3] == c && buf[i+6] == c) return true;
  }

  if (buf[0] == c && buf[4] == c && buf[8] == c) return true;
  if (buf[2] == c && buf[4] == c && buf[6] == c) return true;

  return false;
}

int main() {
  while (1) {
    if (scanf("%s", buf) != 1) return 0;

    if (IsSuccessive(buf, 'o')) puts("o");
    else if (IsSuccessive(buf, 'x')) puts("x");
    else puts("d");
  }
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll n;
    cin >> n;
    VL a(n);
    rep(i, 0, n) cin >> a[i];
    VL pos, neg;
    rep(i, 0, n) {
        if(a[i] >= 0) pos.push_back(a[i]);
        else neg.push_back(a[i]); 
    }
    sort(ALL(pos),greater<ll>());
    sort(ALL(neg));
    if(neg.empty()) {
        neg.push_back(pos.back());
        pos.pop_back();
    }
    if(pos.empty()) {
        pos.push_back(neg.back());
        neg.pop_back();
    }
    VP res;
    ll cur = neg[0];
    rep(i, 0, pos.size()-1) {
        res.push_back({cur, pos[i]});
        cur -= pos[i];
    }
    res.push_back({pos.back(), cur});
    cur = pos.back() - cur;
    rep(i, 1, neg.size()) {
        res.push_back({cur, neg[i]});
        cur -= neg[i];
    }
    cout << cur << endl;
    for(auto e : res) cout << e.first << " " << e.second << endl;
    return 0;
}

Measured memory_bytes: 8020
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        sc.close();
        if (S.length() != 3) {
			PrintNo();
			return;
        }
        int anum = 0;
        int bnum = 0;
        for (int i = 0; i < 3; i++) {
	        if (S.substring(i,i+1).equals("A") == false &&
	            S.substring(i,i+1).equals("B") == false ) {
                PrintNo();
                return;
            }
            if (S.substring(i,i+1).equals("A")) {
            	anum++;
                continue;
            }
			bnum++;
        }
        if (anum == 0 || bnum == 0) {
            PrintNo();
            return;
        }
        PrintYes();
        return;
    }
    private static void PrintYes() {
        System.out.println("Yes");
	}
    private static void PrintNo() {
        System.out.println("No");
	}
}

Measured memory_bytes: 21716
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD[10] = {
    998244353, 1000000007, 4764563, 9999889, 9999901, 
    9999907, 9999929, 9999931, 9999937, 9999943};
constexpr int N_MOD = 10;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

ll modpow(ll a, ll t, int j) {
    ll ret = 1LL;
    while(t){
        if(t & 1LL){
            ret *= a;
            ret %= MOD[j];
        }
        a *= a;
        a %= MOD[j];
        t >>= 1;
    }
    return ret;
}

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, ans = 0;
    cin >> n;
    string s;
    cin >> s;

    int ok = 0, ng = n+1, mid;
    while(ng-ok > 1) {
        mid = (ok+ng) / 2;
        vector<vector<Pll>> v(n-mid+1, vector<Pll>(N_MOD, {0, 0}));
        for(int i=0;i<mid;++i) {
            for(int j=0;j<N_MOD;++j) {
                v[0][j].first *= 26;
                v[0][j].first %= MOD[j];
                v[0][j].first += s[i] - 'a';
                v[0][j].first %= MOD[j];
            }
        }
        for(int j=0;j<N_MOD;++j) v[0][j].second = 0;
        for(int i=1;i<n-mid+1;++i) {
            for(int j=0;j<N_MOD;++j) {
                v[i][j].first = v[i-1][j].first + MOD[j] - ((s[i-1] - 'a') * modpow(26, mid-1, j)) % MOD[j];
                v[i][j].first %= MOD[j];
                v[i][j].first *= 26;
                v[i][j].first %= MOD[j];
                v[i][j].first += s[i+mid-1] - 'a';
                v[i][j].first %= MOD[j];
                v[i][j].second = i;
            }
        }
        sort(v.begin(), v.end());

        ll min_idx = v[0][0].second, max_idx = v[0][0].second;
        bool is_ok = false;
        for(int i=1;i<n-mid+1;++i) {
            // cerr << v[i][j].first << " " << v[i][j].second << endl;
            bool is_same = true;
            for(int j=0;j<N_MOD;++j) is_same &= (v[i][j].first == v[i-1][j].first);
            if(!is_same) {
                min_idx = v[i][0].second;
                max_idx = v[i][0].second;
            } else {
                min_idx = min(min_idx, v[i][0].second);
                max_idx = max(max_idx, v[i][0].second);
                if(max_idx - min_idx >= mid) {
                    is_ok = true;
                    break;
                }
            }
        }

        if(is_ok) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    cout << ok << endl;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;
    for(int i = 0; i <= n - 3; i++)
    {
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
        {
            ans++;
            i += 2;
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cfloat>
using namespace std;
using llong = long long;

llong l;

double pow3(double x) {
    return x * x * x;
}

int main() {
    cin >> l;

    printf("%.*lf\n", DBL_DIG, pow3((double)l / 3));

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

string s[1000];



int main(){
	int n;
	while(cin>>n&&n){
		rep(i,n){
			cin>>s[i];
		}
		rep(i,n){
			int idx=-1;
			rep(j,s[i].size()){
				if(s[i][j]=='.')idx=j;
			}
			if(idx!=-1)s[i][idx]='+';
			rep(j,s[i].size()){
				if(s[i][j]=='.')s[i][j]=' ';
			}
		}
		int tate[1050];
		memset(tate,-1,sizeof(tate));
		rep(i,n){
			int idx=-1;
			rep(j,s[i].size()){
				if(s[i][j]=='+')idx=j;
				else if(s[i][j]!=' ')tate[j]=-1;
			}
			if(idx==-1)continue;
			if(tate[idx]!=-1){
				for(int j=tate[idx]+1;j<i;j++)
					s[j][idx]='|';
			}

			tate[idx]=i;
		}

		rep(i,n)cout<<s[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1992
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define mod 1000000007
#define pb push_back
#define in(a) int a;cin>>a;
#define in2(a,b)in(a)in(b)
#define out(x) cout<<x<<endl
#define out2(x,y) cout<<x<<" "<<y<<" ";
#define pi 3.14159265359
#define modulo 998244353

int32_t main()
{
	in2(n,w);
	int wt[n],val[n];
	for(int i=0;i<n;i++){
		cin>>wt[i]>>val[i];
	}
	
	int dp[n+1][w+1];
	for(int i=0;i<(n+1);i++){
		for(int j=0;j<(w+1);j++){
			if(i==0 || j==0){
				dp[i][j]=0;
			}
		}
	}
	
	for(int i=1;i<(n+1);i++){
		for(int j=1;j<(w+1);j++){
			if(wt[i-1]<=j){
				dp[i][j]=max((val[i-1]+dp[i-1][j-wt[i-1]]),(dp[i-1][j]));
			}else{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	out(dp[n][w]);
	return 0;	
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

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

	rep(j, n)rep(i, j) {
		const int val = abs(a[i] - a[j]);
		if (val % (n - 1) == 0) {
			cout << a[i] << " " << a[j] << endl;
			return 0;
		}
	}


	return 0;
}


Measured memory_bytes: 3100
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)

int_fast32_t nn, n, sqrtN;
int_fast64_t ans, d;
char c;
char wr[15];
char *w = wr;
main() {
    char c;
    while(1) {
        c = getwchar_unlocked();
        if(c != '\n')
            nn = nn * 10 + c - '0';
        else
            break;
    }
    const int_least32_t n = nn;
    if(n == 1){
        putchar_unlocked('1');
        return 0;
    }
    const int_fast32_t sqrtN = sqrt(n);
    ans = -(int_fast64_t)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
    for(int i = 1; i <= sqrtN; ++i) {
        const int_fast32_t a = n / i;
        ans += ((int_fast64_t)i * (i + a) * (a + 1 - i));
    }
    while(ans) {
        *w = ans % 10 + '0';
        ans /= 10;
        w++;
    }
    while(1) {
        w--;
        putwchar_unlocked(*w);
        if(w == wr) break;
    }
}

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

int main(void){
    int n; cin >> n;
    ll cnt=0;
    for(int i=0;i<n;i++){
        int l,r; cin >> l >> r;
        cnt += r-l+1;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int W, H, x, y, r;
    scanf("%d %d %d %d %d",&W, &H, &x, &y, &r);
    if((x-r >= 0)&&(y-r >= 0)&&(x+r <= W)&&(y+r <= H)){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,m,n,ans=0;
	cin>>a>>b>>c>>n;
	m=max(max(a,b),c);
	ans=a+b+c-m;
	for(int i=0;i<n;i++)
	m*=2;
	ans+=m;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int[] l = new int[n];
      int sum = 0;
      for(int i = 0;i < n;i++) l[i] = sc.nextInt();
      Arrays.sort(l);
      for(int i = n-1;i>=n-k;i--) sum += l[i];
      System.out.println(sum);
    }
}


Measured memory_bytes: 23764
#include<stdio.h>

int main(){
    int N,A[21],B[21],C[21];
    int i,sum=0;
    scanf("%d",&N);
    for(i = 1 ; i <= N ; i++){
        scanf("%d",&A[i]);
    }
    for(i = 1 ; i <= N ; i++){
        scanf("%d",&B[i]);
    }
    for(i = 1 ; i <= N-1 ; i++){
        scanf("%d",&C[i]);
    }
    C[N] = 0;
    sum += B[A[1]];
    for(i = 2 ; i <= N ; i++){
        if(A[i-1] == A[i] - 1){
            sum += B[A[i]] + C[A[i-1]];
        }else{
            sum += B[A[i]];
        }
    }
    printf("%d",sum);
    return 0;
}

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

int main() {
   int N, M;
   cin >> N >> M;
   vector<int> A(M);
   int total_day = 0;
   for(int i=0; i<M; i++) {
      cin >> A[i];
      total_day += A[i];
   }

   if(N < total_day) {
      cout << -1 << endl;
      return 0;
   }

   cout << N - total_day << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    int n, r, ans = 0;
    cin >> n >> r;
    (n >= 10) ? ans = r : ans = 100 * (10 - n) + r;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  if(a < b){
    return gcd(b, a);
  }
  return gcd(b, a%b);
}
ll lcm(ll a, ll b){
  return a*b/gcd(a, b);
}
int main()
{
  ll a,b;
  cin >> a>>b;
  cout << lcm(a,b) << endl;

}


Measured memory_bytes: 384
// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#define pc(...)
#endif

#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 2e5 + 5, MOD = 1000000007;

class Solution
{
private:
    vector<string> S;
    int h, w, k;
    int solve(vector<vector<int>> &CCnt)
    {
        vector<int> Cnt(h);
        int prev = -1, ret = 0;
        for (size_t i = 0; i < w; i++)
        {
            bool okCut = false;
            for (size_t j = 0; j < h; j++)
            {
                if (CCnt[j][i] > k)
                    return INT_MAX;
                if (Cnt[j] + CCnt[j][i] > k)
                {
                    okCut = true;
                }
            }
            if (okCut)
            {
                ret++;
                for (size_t j = 0; j < h; j++)
                    Cnt[j] = CCnt[j][i];
                prev = i;
            }
            else
            {
                for (size_t j = 0; j < h; j++)
                    Cnt[j] += CCnt[j][i];
            }
            db(i);
            pc(Cnt);
        }
        return ret;
    }

public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        cin >> h >> w >> k;
        db(h, w, k);
        S.resize(h);
        for (auto &x : S)
            cin >> x;
        ll res = INT_MAX;
        for (int i = 0; i < (1 << (h - 1)); i++)
        {
            vector<vector<int>> CCnt(h, vector<int>(w));
            int ptr = 0;
            for (size_t j = 0; j < h; j++)
            {
                for (int z = 0; z < w; z++)
                    CCnt[ptr][z] += S[j][z] == '1';
                if (i & (1 << j))
                    ++ptr;
            }
#ifdef LOCAL
            db(i);
            for (size_t j = 0; j < h; j++)
            {
                for (int z = 0; z < w; z++)
                    cout << CCnt[j][z] << ' ';
                cout << '\n';
            }
#else

#endif
            res = min(res, (ll)ptr + solve(CCnt));
            db(i, res);
        }
        cout << res << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}

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

using namespace std;

#define int long long
#define MOD 1000000007

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

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int a,b,c;

signed main()
{
   cin>>a>>b>>c;

    int s = a+b+c;
    int m= max({a,b,c});
    int m3 = m*3;

    int M;

    if((s%2) == (m3%2)){
        M=m;
    }
    else{
        M=m+1;
    }

    int ans = 3*M-(a+b+c);
    ans/=2;

    cout <<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	string s;
	cin >> s;
	string a;
	for (int i = 0; i < s.size(); i++) {
		if (s.at(i) == 'A') a += 'T';
		if (s.at(i) == 'T') a += 'A';
		if (s.at(i) == 'C') a += 'G';
		if (s.at(i) == 'G') a += 'C';
	}
	cout << a << endl;
	
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int main() {
	char s[1010];
	cin >> s;
	int n;
	cin >> n;
	rep(i, strlen(s)) {
		if (i%n == 0) {
			cout << s[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char str;
  scanf("%c",&str);
  if(str=='a'||str=='i'){
    printf("vowel");
  }else if(str=='u'||str=='e'){
    printf("vowel");
  }else if(str=='o'){
    printf("vowel");
  }else{
    printf("consonant");
  }
  return 0;
}

Measured memory_bytes: 128
o = list(input())
e = list(input())
result = []
for a, b in zip(o, e):
    result.append(a)
    result.append(b)
if len(o) > len(e):
    result.append(o[-1])
elif len(e) > len(o):
    result.append(e[-1])
print("".join(result))

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

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

    ll i, j, N = 3e3 + 10;
    ll dp[N][N];
    for (i = 0; i < N; i++)
    {
        for (j = 0; j < N; j++)
        {
            dp[i][j] = -1;
        }
    }
    for (i = 0; i < N; i++)
    {
        dp[i][0] = dp[0][i] = 0;
    }

    string s, t, f;
    cin >> s >> t;

    for (i = 1; i <= s.size(); i++)
    {
        for (j = 1; j <= t.size(); j++)
        {
            if (dp[i][j] == -1)
            {
                if (s[i - 1] == t[j - 1])
                    dp[i][j] = max(1 + dp[i - 1][j - 1], max(dp[i - 1][j], dp[i][j - 1]));
                else
                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    if (dp[s.size()][t.size()] == 0)
    {
        cout << "\n";
        return 0;
    }

    for (i = s.size(), j = t.size(); i > 0 && j > 0 && dp[i][j] != 0;)
    {

        if (dp[i - 1][j] == dp[i][j])
            i--;
        else if (dp[i][j - 1] == dp[i][j])
            j--;
        else if (dp[i - 1][j] != dp[i][j] && dp[i][j - 1] != dp[i][j])
        {
            f.pb(t[j-1]);
            i--, j--;
        }
    }

    reverse(f.begin(), f.end());
    cout << f << "\n";

    /*for (i = 0; i <= s.size(); i++)
    {
        for (j = 0; j <= t.size(); j++)
            cout << dp[i][j] << " ";
        cout << "\n";
    }
    cout << dp[s.size()][t.size()] << "\n";*/
    return 0;
}

Measured memory_bytes: 71040
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<vector>
using namespace std;
int n;
char p[10][10][10] = {
	{},{},{},
{
	"..a",
	"..a",
	"bb."
},
{
	"aabc",
	"ddbc",
	"bcaa",
	"bcdd"
},
{
	"abc..",
	"abc..",
	"effaa",
	"e.gbb",
	"hhgcc"
},
{
	"aabcc.",
	"b.b..d",
	"baa..d",
	"c..baa",
	"c..b.b",
	".ddaab"
},
{
	"....abc",
	"....abc",
	"....def",
	"....def",
	"aadd..g",
	"bbee..g",
	"ccffhh."
}
};
char res[1010][1010];
void Print() {
	int i;
	for (i = 0; i < n; i++) {
		printf("%s\n", res[i]);
	}
}
int Path[1010], D[1010];
int main() {
	scanf("%d", &n);
	if (n == 2) {
		puts("-1");
		return 0;
	}
	int i, j, k;
	for (i = 0; i < n; i++)for (j = 0; j < n; j++)res[i][j] = '.';
	if (n % 4 == 0) {
		for (i = 0; i < n / 4; i++) {
			for (j = 0; j < 4; j++) {
				for (k = 0; k < 4; k++) {
					res[i * 4 + j][i * 4 + k] = p[4][j][k];
				}
			}
		}
		Print();
		return 0;
	}
	if (n % 3 == 0) {
		int i, j, k;
		for (i = 0; i < n / 3; i++) {
			for (j = 0; j < 3; j++) {
				for (k = 0; k < 3; k++) {
					res[i * 3 + j][i * 3 + k] = p[3][j][k];
				}
			}
		}
		Print();
		return 0;
	}
	D[0] = 1;
	for (i = 0; i <= n; i++) {
		if (!D[i])continue;
		for (j = 5; j <= 7; j++) {
			if (i + j <= n) {
				D[i + j] = 1;
				Path[i + j] = j;
			}
		}
	}
	int x = n;
	while (x) {
		int t = Path[x];
		for (i = 0; i < t; i++) {
			for (j = 0; j < t; j++) {
				res[x - t + i][x - t + j] = p[t][i][j];
			}
		}
		x -= t;
	}
	Print();
}

Measured memory_bytes: 2176
INF = 10 ** 9 + 7

n, k = gets.chomp.split.map(&:to_i)
h = gets.chomp.split.map(&:to_i)

dp = Array.new(n, INF)
dp[0] = 0

(1...n).each do |i|
  (([0, i - k].max)...i).each do |j|
    c = dp[j] + (h[i] - h[j]).abs
    dp[i] = c if c < dp[i]
  end
end

puts dp[n - 1]

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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        if(a == b){
            ans += 1;
        }else{
            ans = 0;
        }
        if(ans == 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3640
/*
 * Author : Sadi
 * Mon 06/07/2020
 * 18:26:23.40
 */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

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

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

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

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;
unordered_map<int, int> cnt;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n;
    cin >> n;
    vector<int> v(n);
    int amax = -1, bmax = -1;
    for(int i = 0; i < n; ++i) {
    	cin >> v[i];
    	if(v[i] >= amax) {
    		bmax = amax;
    		amax = v[i];
    	}
    	else if(v[i] > bmax) {
    		bmax = v[i];
    	}
    	cnt[v[i]]++;
    }
    for(int i = 0; i < n; ++i) {
 		if(v[i] == amax && cnt[v[i]] == 1) {
 			cout << bmax << endl;
 		}
 		else {
 			cout << amax << endl;
 		}
    }
    return 0;
}


Measured memory_bytes: 8468
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    set<string> S;
    int n;
    cin >> n;
    rep(i,0,n){
        string a;
        cin >>a;
        S.insert(a);
    }
    cout << S.size() << endl;

    return 0;
}

Measured memory_bytes: 19148
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N = int(input())
A = list(map(int, input().split()))

ans = []
a1 = 0
for i in range(N):
    a1 += (-1)**i*A[i]

ans.append(a1)

a = a1//2
for i in range(N-1):
    a = A[i] - a
    ans.append(2*a)

ans = map(str, ans)
print(" ".join(ans))




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

int main() {
  int H, N, A, B;
  cin >> H >> N;
  vector<int> DP(H + 1, 1e9);
  DP.at(0) = 0;
  while (cin >> A >> B)
    for (int h = 0; h < H; h++)
      DP.at(min(h + A, H)) = min(DP.at(min(h + A, H)), DP.at(h) + B);
  cout << DP.at(H) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using pint = pair<int, int>;

double dist(pint xyi, pint xyj) {
	double ans;
	ans = sqrt(pow(xyi.first - xyj.first, 2) + pow(xyi.second - xyj.second, 2));
	return ans;
}

int main(){
	int N;
	cin >> N;
	vector<pint> xy(N);
	for (int i = 0; i < N; i++) {
		cin >> xy[i].first;
		cin >> xy[i].second;
	}

	vector<int> order(N);
	for (int i = 0; i < N; i++) order[i] = i;

	double dist_sum = 0;
	int count = 0;

	do {
		for (int i = 1; i < N; i++) {
			dist_sum += dist(xy[order[i - 1]], xy[order[i]]);
		}
		count++;
	} while (next_permutation(order.begin(), order.end()));

	double dist_avg = dist_sum / count;

	cout << fixed << setprecision(6) << dist_avg << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main()
{

    string s;
    cin >> s;
    if (s.size() != 4)
    {
        cout << "No" << endl;
    }
    else
    {
        map<char, int> mp;
        rep(i, 4)
        {
            mp[s[i]]++;
        }
        for (auto x : mp)
        {
            if (x.second != 2)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


int main(){
   long long n, C;
   cin >> n >> C;
   vector<long long> s(n), t(n), c(n);
   for(int i = 0; i < n; ++i) cin >> s[i] >> t[i] >> c[i];
   vector<long long> cnt(1e5 * 2 + 2), sm(1e5 * 2 + 2);
   for(int i = 1; i <= C; ++i){
       cnt.assign(1e5 * 2 + 2, 0);
       for(int j = 0; j < n; ++j) if(c[j] == i) cnt[2 * s[j] - 2]++, cnt[2 * t[j]]--;
       for(int j = 1; j <= 1e5 * 2 + 1; ++j) cnt[j] += cnt[j - 1];
       for(int j = 0; j <= 1e5 * 2 + 1; ++j) if(cnt[j]) sm[j]++;
   }
   long long ans = 0;
   for(int i = 0; i <= 1e5 * 2 + 1; ++i) ans = max(ans, sm[i]);
   cout << ans;
}


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

int main(){
  int N;
  int A=0,B=0;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  	sort(vec.begin(),vec.end());
  	reverse(vec.begin(),vec.end());
  for(int i=0;i<N;i++){
  	if(i%2 == 0){
    	A+=vec.at(i);
  	}else{
    	B+=vec.at(i);
  	}
  }
  	cout << A-B << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld; 
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << ", ";
	err(++it, args...);
	cout<<"\n";
}

#define vmax(type)   std::numeric_limits<type>::max()
#define vmin(type)   std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'

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

const ll mod = 1e9 + 7;
const ll N = 1000005;
const ll inf = 1e9;

void solve()
{
	ll x, k, d;
	cin>>x>>k>>d;
	ll rem = (x < 0 ? -x : x) / d;
	// error(rem);
	if(rem >= k)
		cout<<((x < 0 ? -x : x) - k * d)<<endl;
	else{
		ll curr = (x < 0 ? -x : x) - rem * d;
		k -= rem;
		if(k % 2)
			curr -= d;
		cout<<abs(curr)<<endl;
	}

}

// #define _DEBUG 
// #define testCases
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);
	
	int tc = 1;
#ifdef testCases
	cin>>tc;
#endif
	while(tc--)
	{
#ifdef _DEBUG
	int tt = clock();
#endif
		solve();
		
#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
#endif
	}
	return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n>> m;
    if(n>=2&&m>=2){
        cout << n*(n-1)/2 + m*(m-1)/2;
    }
    else if(n==1 && m==1){
        cout << 0;
    }
    else{
        cout << max(n,m)*(max(n,m)-1)/2;
    }
}

Measured memory_bytes: 3628
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <random>
#pragma comment(linker, "/STACK:836777216")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define N 200005

int a[N];

int main(void) {
	int n, k;
	scanf("%d%d", &k, &n);
	REP(i, n) {
		scanf("%d", &a[i]);
	}

	int diff = k - a[n - 1] + a[0];
	FOR(i, 1, n) {
		diff = max(diff, a[i] - a[i - 1]);
	}

	printf("%d\n", k - diff);
	//scanf("%d", &k);
}

Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanLines)
	for sc.Scan() {
		n, _ := strconv.ParseFloat(sc.Text(), 64)
		ans := n
		sum := n
		for i := 2; i <= 10; i++ {
			if i%2 == 0 {
				ans *= 2
				sum += ans
			} else {
				ans /= 3
				sum += ans
			}
		}
		fmt.Println(sum)
	}
}


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

int main() {
  int A = 0, B = 0, C = 0;
  bool flag = false;

  cin >> A >> B >> C;

  if (A == B && B != C && C != A)
    flag = true;
  else if (A != B && B == C && C != A) flag = true;
  else if (A != B && B != C && C == A) flag = true;

  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
A = [int(x) for x in input().split()]

Bi = []
if n % 2 == 0:
    half_Bi = list(range(1, n, 2))
    Bi = half_Bi + half_Bi
else:
    half_Bi = list(range(2, n, 2))
    Bi = half_Bi + half_Bi
    Bi.append(0)

A.sort()
Bi.sort()
if A != Bi:
    print(0)
    exit()

print((2**(n//2)) % (10**9+7))


Measured memory_bytes: 13880
#include <cstdio>

using namespace std;

int main() {
    int a, b;
    char op = '+';

    while(op != '?') {
        scanf("%d %c %d", &a, &op, &b);
        if (op == '+') {
            printf("%d\n", a + b);
        } else if (op == '-') {
            printf("%d\n", a - b);
        } else if (op == '*') {
            printf("%d\n", a * b);
        } else if (op == '/' && b != 0) {
            printf("%d\n", a / b);
        }
    }

    return 0;
}



Measured memory_bytes: 2724
//
// Created by Hideaki Imamura on 2019-06-06.
//

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll gcd(ll m, ll n) {
    if (m < n) {
        ll tmp = m;
        m = n;
        n = tmp;
    }
    while (n > 0) {
        ll tmp = n;
        n = m % n;
        m = tmp;
    }
    return m;
}

int main() {
    ll n, a;
    vector <ll> as;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        as.push_back(a);
    }

    ll l[100010], r[100010];
    l[0] = 0;
    r[n] = 0;
    for (int i = 0; i <= n-1; ++i) {
        l[i+1] = gcd(l[i], as[i]);
    }
    for (int i = n - 1; i >= 0; --i) {
        r[i] = gcd(r[i+1], as[i]);
    }

    vector<ll> m;
    for (int i = 0; i <= n - 1; ++i) {
        m.push_back(gcd(l[i], r[i+1]));
    }

    ll res = *std::max_element(m.begin(), m.end());

    cout << res << endl;

    return 0;
}

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

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] a = new int[n];

        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }

        int cnt = 0;
        int sum = Arrays.stream(a).sum();
        double temp = 4.0 * m;
        double line = sum / temp;
        

        for(int i = 0; i < n; i++){
            if (a[i] >= line){
                cnt++;
            }
        }

        System.out.println(cnt>=m?"Yes":"No");
    }
}

Measured memory_bytes: 29140
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    int t[200005];
    int i;
    for(i=0;i<=200000;i++)t[i]=0;
    for(i=1;i<=n;i++){
        int q;
        scanf("%d",&q);
        t[q]++;
    }
    sort(t+1,t+200000);
    
    int ansm=0;
    for(i=1;i<=k;i++){
        ansm+=t[200000-i];
    }
    printf("%d",n-ansm);
    return 0;
    
}


Measured memory_bytes: 896