akhauriyash/Code-Regression huggingface dataset:
/*
Miles Morales : When will I know I'm ready?
Peter B. Parker : You won't. It's a leap of faith. That's all it is, Miles. A leap of faith.
*/
//KEEP IT SIMPLE STUPID
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define print(o) for(auto it=(o).begin();it!=(o).end();it++) cout<<*it<<" ";
#define vll vector<ll>
#define pb push_back
#define FOR(n) for(ll i=0;i<=n;i++)
#define FORd(n) for(ll i=n;i>=0;i--)
#define FORrd(a,b) for(ll i=a;i>=b;i--)
#define FORr(a,b) for(ll i=a;i<=b;i++)
#define all(x) (x).begin(),(x).end()
#define FIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define ff first
#define ss second
//#define w(t) ll t;cin>>t;while(t--)

int main()
{
    //FIO;
    ll n,m,wa=0,ac=0;
    cin>>n>>m;
    bool solved[n]={false};
    vll w(n);
    while(m--)
    {
        ll p;
        string s;
        cin>>p>>s;
        p--;
        if(s=="WA"&&!solved[p])
            w[p]++;
        else if(s=="AC"&&!solved[p]){
            solved[p]=true;
            ac++;
        }
    }
    FOR(n-1)
    {
        if(solved[i])
            wa+=w[i];
    }
    cout<<ac<<" "<<wa<<'\n';
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


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

int main() {
  string S;
  cin >> S;
  int len = S.length();

  while (S.length() > 0) {
    for (int i{}; i < S.length() - 1; ++i) {
      if (S[i] != S[i+1]) {
        S.erase(i, 2);
        goto NEXT;
      }
    }
    break;
    NEXT:
    ;
  }

  cout << len - S.length() << endl;
  return 0;
}


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

const int MAXW = 1e5 + 10;

long long knapsack[MAXW];
int N, W;

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

    for (int item = 1; item <= N; item++) {
        int w, v;
        cin >> w >> v;
        for (int i = W; i >= w; i--) knapsack[i] = max(knapsack[i - w] + v, knapsack[i]);
    }

    long long best = 0;
    for (int i = 0; i <= W; i++) best = max(best, knapsack[i]);
    cout << best << endl;

    return 0;
}

Measured memory_bytes: 4396
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 200000;
int n;
ll a[MAX_N + 1];

int main() {
    fastio();

    cin >> n;
    forn1(i, n) cin >> a[i];

    map<ll, ll> cnt;
    cnt[a[1] + 1] = 1;

    ll ans = 0;
    for (ll i = 2; i <= n; i++) {
        ans += cnt[i - a[i]];
        cnt[i + a[i]]++;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<string> svec;

#define IN_LL(in) ll in; cin >> in
#define IN_STR(in) string in; cin >> in
#define IN_VEC(in, size) vec in; for(int i = 0; i < (size); ++i){int ____cur; cin >> ____cur; in.push_back(____cur); } 0
#define IN_SVEC(in, size) svec in; for(int i = 0; i < (size); ++i){int ____cur; cin >> ____cur; in.push_back(____cur); } 0

#define OUT(out) cout << (out)
#define OUT_VEC(out) for(ll i = 0; i < (out).size(); ++i) cout << (out)[i]

ll func(ll n, ll k){
	ll res = 0;
	ll min = 0, max = 0;
	for(ll j = 0; j < k - 1; ++j){
		min += j;
		max += n - j;
	}
	for(ll i = k; i <= n + 1; ++i){
		min += i - 1;
		max += n - i + 1;
		// ll min = 0, max = 0;
		// for(ll j = 0; j < i; ++j){
		// 	min += j;
		// 	max += n - j;
		// }
		res += max - min + 1;
		res %= 1000000007;
	}
	return res;
}

int main(void){
	IN_LL(n);
	IN_LL(k);
	
	ll res = func(n, k);
	
	OUT(res);
	return 0;
}


Measured memory_bytes: 3572
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
bool arr[10000001];
int Nmax=10000001;
void Eratosthenes(){
	for(int i = 0; i < Nmax; i++){
		arr[i] = true;
	}
	arr[0]=false; arr[1]=false;
	for(int i = 2; i < sqrt(Nmax); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < Nmax; j++){
				arr[i *(j + 2)] = false;
			}
		}
	}
}
ll kosu[10000001];
int main(){
	Eratosthenes();
	ll N;
	scan(N);
	rep1(i,N) kosu[i]=1;
	rep1(i,N){
		if(arr[i]){
			for(int j=1;i*j<=N;j++){
				int m=i*j;
				int num=0;
				while(m%i==0){
					m/=i;
					num++;
				}
				kosu[i*j]*=num+1;
			}
		}
	}
	ll ans=0;
	//rep1(i,N) debug(i,kosu[i]);
	rep1(i,N){
		if(i!=1) ans+=(kosu[i])*i;
		else ans+=1;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 91532
n,m,q=map(int,input().split())
counts=[[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l,r=map(int,input().split())
    counts[l-1][r-1]+=1
cumsum=[[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(n):
        cumsum[i+1][j+1]=cumsum[i+1][j]+counts[i][j]
for j in range(n+1):
    for i in range(n):
        cumsum[i+1][j]+=cumsum[i][j]
        
for _ in range(q):
    l,r=map(int,input().split())
    print(cumsum[r][r]-cumsum[r][l-1]-cumsum[l-1][r]+cumsum[l-1][l-1])

Measured memory_bytes: 61656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int MAX = 310;
vector<vector<char> > cake(MAX,vector<char> (MAX));
vector<vector<int> > ans(MAX,vector<int> (MAX,0));
int num = 1;

void dfs(int x_l, int x_h, int y_l, int y_h){
  int count = 0;
  vector<int> W_count(MAX,0);
  vector<int> H_count(MAX,0);
  repp(y,y_l,y_h) repp(x,x_l,x_h) if(cake[x][y] == '#'){
    ++W_count[x];
    ++H_count[y];
    ++count;
  }
  if(count == 1){
    repp(y,y_l,y_h) repp(x,x_l,x_h) ans[x][y] = num;
    ++num;
    return;
  }

  repp(x,x_l,x_h) if(W_count[x] >= 1 && W_count[x] != count){
    dfs(x_l,x+1,y_l,y_h);
    dfs(x+1,x_h,y_l,y_h);
    return;
  }
  repp(y,y_l,y_h) if(H_count[y] >= 1 && H_count[y] != count){
    dfs(x_l,x_h,y_l,y+1);
    dfs(x_l,x_h,y+1,y_h);
    return;
  }
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int H,W,K;cin >> H >> W >> K;
  rep(y,H)rep(x,W)cin >> cake[x][y];
  dfs(0,W,0,H);
  rep(y,H){
    rep(x,W) cout << ans[x][y] SPF;
    cout << endl;
  }
  return 0;

}


Measured memory_bytes: 2320
let n = read_int ();;

let call n =
  let rec checknum i =
    if i <> 1 && i > n then print_newline ()
    else
      if i mod 3 = 0 then begin
          Printf.printf " %d" i; checknum (i+1)
        end
      else
        let rec include3 j =
          if j mod 10 = 3 then begin
              Printf.printf " %d" i; checknum (i+1)
            end
          else
            let k = j/10 in
            if k > 0 then include3 k else checknum (i+1)
      in include3 i
  in checknum 1;;

 let () = call n;;

Measured memory_bytes: 3496
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    ll n;
    cin >> n;
    ll a[n], k = 0;
    rep(i, n) {
        cin >> a[i];
        k += a[i];
    }
    if(k % (n * (n + 1) / 2)) {
        cout << "NO" << endl;
        return 0;
    }
    k /= n * (n + 1) / 2;
    rep(i, n) {
        ll x = a[(i + 1) % n] - a[i] - k;
        if(x > 0 || (-x) % n) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        int min = n / k;
        int max = n - min*k + min;
        System.out.println(max-min);
    }
}


Measured memory_bytes: 23124
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;

ll po[POW_MAX + 2];

ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

ll mod_inv (ll x) {
  return mod_pow(x, MOD - 2) % MOD;
}

ll comb(int n, int r) {
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}

bool comp_second_desc(const P a, const P b) {
  return a.second > b.second;
}
struct PairSecondGreater {
  bool operator() (P a, P b) {
    return a.second > b.second;
  }
};
struct PairSecondLess {
  bool operator() (P a, P b) {
    return a.second < b.second;
  }
};

ll g(ll deli, ll var) {
  return deli + var * var;
}

int N, K;
map<int, int> mp;
priority_queue<P, vector<P>, PairSecondLess> in_q;
priority_queue<P, vector<P>, PairSecondGreater> q;

int main() {
  scanf("%d %d", &N, &K);
  rep(i, N) {
    int t, d;
    scanf("%d %d", &t, &d);
    in_q.push(P(t, d));
  }

  int variety = 0;
  ll sum_deli = 0;
  rep(i, K) {
    P p = in_q.top();
    in_q.pop();
    if (mp[p.first]) {
      q.push(p);
    } else {
      variety++;
    }
    mp[p.first]++;
    sum_deli += p.second;
  }

  ll max_satisfy = g(sum_deli, variety);
  while (!q.empty()) {
    P p = q.top();
    q.pop();
    sum_deli -= p.second;

    bool found = false;
    while (!in_q.empty()) {
      P d = in_q.top();
      in_q.pop();
      if (mp[d.first]) continue;

      found = true;
      variety++;
      mp[d.first]++;
      sum_deli += d.second;
      break;
    }
    if (!found) break;

    max_satisfy = max(max_satisfy, g(sum_deli, variety));
  }
  printf("%lld\n", max_satisfy);
}


Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


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

    sort(all(A));
    reverse(all(A));

    if(A[M-1]*4*M>=sum){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    



    return 0;
    

}

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

int main(){
  string s;
  cin >> s;
  
  int counter = 0;
  
  if (s[0] == '1') ++counter;
  if (s[1] == '1') ++counter;
  if (s[2] == '1') ++counter;
  
  cout << counter << endl;
  

}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<ll> a, b;
  for(int i = 0; i < n; i++){
    ll x, y;
    cin >> x >> y;
    a.pb(x);
    b.pb(y);
  }
  ll res = 0;
  for(int i = n - 1; i >= 0; i--){
    a[i] += res;
    ll tmp = ((a[i] + b[i] - 1) / b[i]) * b[i] - a[i];
    res += tmp;
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 2036
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
ve = v[0::2]
vo = v[1::2]
edict = sorted(Counter(ve).items(), key=lambda x: x[1], reverse=True)[:2]
odict = sorted(Counter(vo).items(), key=lambda x: x[1], reverse=True)[:2]
ans = 10 ** 6
if len(edict) == 1 and len(odict) == 1 and edict[0][0] == odict[0][0]:
    ans = n // 2
else:
    for e in edict:
        for o in odict:
            if e[0] == o[0]:
                continue
            ans = min(ans, len(ve) - e[1] + len(vo) - o[1])
print(ans)


Measured memory_bytes: 17500
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int n;
	cin>>n;
	string s[n];
	map<string,int>m;
	for(int i = 0; i < n ; i++){
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
		m[s[i]]++;
	}
	ll ans = 0;
	for(auto it :m){
		if(it.second <= 0)continue;
        for(int i = 1;i < it.second;i++)
        	ans += i;
	}
	cout<<ans<<endl;
	
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

ll f(ll d, ll c, ll& ans) {
	if(c == 1) return d;
	ans += (1 + (d >= 5)) * (c / 2);
	ll d2 = (11 * d) % 9;
	if(d == 9) d2 = 9;
	ll ret = f(d2, c / 2, ans);
	if(c % 2) {
		ret += d;
		ans += 1 + (ret >= 10);
		if(ret >= 10) ret -= 9;
	}
	return ret;
}

int main() {
//	cout << fixed << setprecision(15);
	ll m;
	cin >> m;
	vll d(m), c(m);
	rep(i, m) cin >> d[i] >> c[i];

	ll ans = 0;
	rep(i, m) d[i] = f(d[i], c[i], ans);
	ll d2 = d[0];
	for(int i = 1; i < m; i++) {
		d2 += d[i];
		ans += 1 + (d2 >= 10);
		if(d2 >= 10) d2 -= 9;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3328
//2018年  3月 23日 金曜日 02:59:22 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////


int N;
ll A[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	ll res = 0;

	int odd = 0;
	rep(i, 0, N) {
		if((A[i] + odd) % 2 == 0) {
			res += (A[i] + odd) / 2;
			odd = 0;
		}
		else {
			res += (A[i] + odd) / 2;
			if(A[i] >= 1) odd = 1;
			else odd = 0;
		}
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 1024
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 20
#define MAXM (1<<20)
#define MAXK 405
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,m,k,a[MAXK],b[MAXK],c[MAXK];
int go[MAXM][MAXN][2];
bool ban[MAXM][MAXN][2];
int dp[MAXN][MAXM];
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    n--;
    memset(ban,false,sizeof(ban));
    for(int i=0;i<k;i++) 
    {
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        ban[a[i]][b[i]][1-c[i]]=true;
    }
    for(int mask=0;mask<(1<<n);mask++)
    {
        for(int i=0;i<n;i++)
        {
            if(mask&(1<<i))
            {
                go[mask][i][0]=-1;
                go[mask][i][1]=mask;
            }
            else
            {
                go[mask][i][0]=mask;
                int newmask=mask^(1<<i);
                for(int j=i+1;j<n;j++) 
                {
                    if(newmask&(1<<j))
                    {
                        newmask^=(1<<j);
                        break;
                    }
                }
                go[mask][i][1]=newmask;
            }
        }
    }
    memset(dp,0,sizeof(dp));
    dp[n][0]=1;
    for(int i=1;i<=m;i++)
    {
        for(int mask=0;mask<(1<<n);mask++) dp[0][mask]=dp[n][mask];
        for(int pos=1;pos<=n;pos++)
            for(int mask=0;mask<(1<<n);mask++)
                dp[pos][mask]=0;
        for(int pos=0;pos<n;pos++)
        {
            for(int mask=0;mask<(1<<n);mask++)
            {
                if(!dp[pos][mask]) continue;
                if(!ban[i][pos+1][0]&&go[mask][pos][0]!=-1)
                {
                    int newmask=go[mask][pos][0];
                    add(dp[pos+1][newmask],dp[pos][mask]);
                }
                if(!ban[i][pos+1][1]&&go[mask][pos][1]!=-1)
                {
                    int newmask=go[mask][pos][1];
                    add(dp[pos+1][newmask],dp[pos][mask]);
                }
            }
        }
    }
    int ans=0;
    for(int mask=0;mask<(1<<n);mask++) add(ans,dp[n][mask]);
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 207232
s = input()
n = int(input())
 
for _ in range(n):
    line = input().split()
    order = line[0]
    a = int(line[1])
    b = int(line[2])
    p = line[3] if len(line) == 4 else ''
 
    if order == 'print':
        print(s[a:b+1])
    elif order == 'reverse':
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif order == 'replace':
        s = s[:a] + p + s[b+1:]

Measured memory_bytes: 7720
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if((a+b)%2==0)cout<<(a+b)/2<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

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

class Program {
    static Scanner cin = new Scanner();

    static void Main(string[] args) {
        int N = cin.Int();
        var A = cin.ArrayLong(N);
        var B = cin.ArrayLong(N);

        long a_sum = 0, b_sum = 0;
        for (int i = 0; i < N; i++) {
            a_sum += A[i];
            b_sum += B[i];
        }

        if (a_sum < b_sum) Console.WriteLine(-1);
        else {
            long ans = 0;
            long shortage = 0;
            for (int i = 0; i < N; i++) {
                if (A[i] < B[i]) {
                    shortage += B[i] - A[i];
                    ans++;
                }
            }
            var rest = new long[N];
            for (int i = 0; i < N; i++) {
                if (A[i] > B[i]) rest[i] = A[i] - B[i];
            }
            rest = rest.OrderByDescending(x => x).ToArray();
            int index = 0;
            while(shortage > 0) {
                shortage -= rest[index];
                ans++;
                index++;
            }
            Console.WriteLine(ans);
        }
        Console.ReadLine();
    }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

// template starts
typedef long long int ll;

// template ends here

void solve(){
	// code starts from here
	ll a=0, b=0, c=0, d=0;
	ll N;
	cin >> N;
	
	while(N--){
		string str;
		cin >> str;
		
		if(str == "AC") a++;
		else if(str == "WA") b++;
		else if(str == "TLE") c++;
		else d++;
	}
	
	cout << "AC x " << a << endl;
	cout << "WA x " << b << endl;
	cout << "TLE x " << c << endl;
	cout << "RE x " << d << endl;
}

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

	int T;
	T = 1;
	while(T--){
		solve();
	}

	return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n,mini;
  cin >> n;
  vector <string> data1(n),data2(n);
  for(int i=0;i<n;i++){
    cin >> data1[i];
    data2[i] = data1[i];
  }
  for(int i=0;i<n-1;i++){
    for(int j=n-1;j>i;j--){
      if(data1[j][1]<data1[j-1][1]) swap(data1[j],data1[j-1]);
    }
  }
  for(int i=0;i<n;i++){
    mini = i;
    for(int j=i;j<n;j++){
      if(data2[j][1]<data2[mini][1]) mini = j;
    }
    if(mini != i) swap(data2[i],data2[mini]);
  }
  for(int i=0;i<n;i++) cout << (i!=0?" ":"") << data1[i];
  cout << endl << "Stable" << endl;
  for(int i=0;i<n;i++) cout << (i!=0?" ":"") << data2[i];
  if(data1==data2) cout << endl << "Stable" << endl;
  else cout << endl << "Not stable" << endl;
}



Measured memory_bytes: 3204
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
    n: usize,
    a: [usize; n - 1]
    );
    let mut c = vec![0; n];
    for i in a.clone(){
        c[ i - 1 ] += 1;
    }
    for i in c{
        println!("{}", i);
    }
}


Measured memory_bytes: 6012
#include <iostream>

using namespace std;

int main(void) {
	int H, W;
	cin >> H >> W;
	while (H || W)
	{
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (i%2 == 0 && j%2 == 0 || i%2 == 1 && j%2 == 1)
				{
					cout << "#";
				}
				else
				{
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;
	}
}


Measured memory_bytes: 3084
import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        String s = br.readLine();
        s = s.replace("eraser", "");
        s = s.replace("erase", "");
        s = s.replace("dreamer", "");
        s = s.replace("dream", "");
        System.out.println(s.length() > 0 ? "NO" : "YES");
        bw.flush();
    }
}


Measured memory_bytes: 27860
x, k, d = map(int, input().split())
x = abs(x)
if k * d < x:
  print(x - k * d)
else:
  y = x // d
  if (k - y) % 2 == 0:
    print(x - d * y)
  else:
    print(-(x - d * y - d));

Measured memory_bytes: 9172
parseInt(x) = parse(Int,x)
parseMap(x::Array{SubString{String}, 1}) = map(parseInt, x)
function main()
  n,m = map(parseInt, split(readline()))
  temp = 1:m
  for i in 1:n
    a = readline() |> split |> parseMap
    for i2 = temp
      if !in(i2,a[2:end])
    	temp = filter(x->!(x in i2),temp)
      end
    end
  end
  println(Int64(length(temp)))
end
main()

Measured memory_bytes: 121224
/*
   Username : moondancer
   Name : Moon Dancer
*/


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

#define int long long

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,ans=0;
    cin>>n;
    int x;
    cin>>x;
    int m=x;
    for (int i = 1; i < n; ++i)
    {
        int x;
        cin>>x;
        ans+=max(0ll,m-x);
        m=max(m,x);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const P<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}

signed main()
{
   int R, C, N; cin >> R >> C >> N;
   V<P<int,int>> outer[4];
   REP(i, N) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      if ((x1 == 0 || x1 == R || y1 == 0 || y1 == C) &&
          (x2 == 0 || x2 == R || y2 == 0 || y2 == C)) {
         if (x1 == 0)      outer[0].PB(MP(y1,i));
         else if (y1 == C) outer[1].PB(MP(x1,i));
         else if (x1 == R) outer[2].PB(MP(y1,i));
         else              outer[3].PB(MP(x1,i));

         if (x2 == 0)      outer[0].PB(MP(y2,i));
         else if (y2 == C) outer[1].PB(MP(x2,i));
         else if (x2 == R) outer[2].PB(MP(y2,i));
         else              outer[3].PB(MP(x2,i));
      }
   }
   SORT(outer[0]); SORT(outer[1]); RSORT(outer[2]); RSORT(outer[3]);

   stack<int> stk;
   REP(i, 4) {
      REP(j, outer[i].size()) {
         if (stk.empty() || stk.top() != outer[i][j].second) {
            stk.push(outer[i][j].second);
         } else {
            stk.pop();
         }
      }
   }

   cout << (stk.empty() ? "YES" : "NO") << endl;

   return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}


//#########################################

int a[5]={1,4,7,9,10};
int x;
bool can(int i){

    return (a[i]<=x);

}

int main() {

int a=D(),b=D();
int cnt=0;

for(int i=a;i<=b;i++){

    int x=i;
    int a5=x%10;
    x/=10;

    int a4=x%10;
    x/=10;

    int a3=x%10;
    x/=10;
    int a2=x%10;
    x/=10;
    int a1=x%10;
    if((a5==a1)&&(a4==a2)){

        cnt++;
    }




}
cout<<cnt;

}


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	int n ;
	cin >> n ;
	int t[n],x[n],y[n];
	rep(i,n) cin >> t[i] >> x[i] >> y[i] ;
	//x[i+1] - x[i] + y[i+1] -y[i]が移動距離
	int start_x = 0,start_y = 0, time = 0 ;
	rep(i,n){
		int dist = abs(x[i] - start_x )+  abs(y[i] - start_y);
		int move_time = t[i] - time ;

		//移動する秒数がdistよりも多くて、さらにその差が２の倍数ならおけ
		if(move_time >= dist && (move_time-dist)%2==0){
			//ok
			start_y = y[i] , start_x = x[i] ;
			time = t[i];
		} else { 
			puts("No");
			return 0 ;
		} 
	}
	puts("Yes"); 
}


Measured memory_bytes: 1408
import numpy as np
n = int(input())
argList = np.array(list(map(int, input().split())) )

g = sum(argList % 2 == 0)
k = sum(argList % 2 == 1)

flag = False
if( k % 2 == 0):
    #if( (int(k/2) + g) % 2 == 0):
    flag = True
if flag:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 37860
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

type pair struct {
	first int
	last  int
}

func getpair(num int) pair {
	first := 0
	last := num % 10
	for num > 0 {
		if num < 10 {
			first = num
			break
		}
		num /= 10
	}
	return pair{first, last}
}

func main() {
	var n, count int

	sc.Split(bufio.ScanWords)
	n = next()

	var freq map[pair]int

	freq = make(map[pair]int, 0)
	for A := 1; A <= n; A++ {
		p := getpair(A)
		freq[p]++
	}
	for B := 1; B <= n; B++ {
		p := getpair(B)
		q := pair{p.last, p.first}
		count += freq[q]
	}

	fmt.Println(count)
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int A, B, C, D;

//----------最大公約数----------
int gcd(int x, int y)
{
	int r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}


//----------最小公倍数----------
int lcm(int x, int y)
{
	return (x / gcd(x, y) * y);
}


signed main()
{
	cin >> A >> B >> C >> D;

	if (C > D)
	{
		int temp = C;
		C = D;
		D = temp;
	}
	//A<B C<D

	if (D % C == 0)
	{
		int a = (B / C);
		int b = ((A - 1) / C);
		int n = a - b;
		cout << (B - A + 1) - n << endl;
	}
	else
	{
		int l = lcm(D, C);

		int a1 = B / C;
		int b1 = B / D;
		int c1 = B / l;
		int n1 = a1 + b1 - c1;

		int a2 = (A - 1) / C;
		int b2 = (A - 1) / D;
		int c2 = (A - 1) / l;
		int n2 = (a2 + b2 - c2);
		
		int n = n1 - n2;
		cout << (B - A + 1) - n << endl;
	}
}











Measured memory_bytes: 384
#include<iostream>
#include<algorithm>

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);

int input[100];

int main(){
	IOS;
	int N,sum1=0,sum2=0;
	while(cin>>N){
		for(int i=0;i<N;i++){
			cin>>input[i];
		}
		sort(input,input+N);
		reverse(input,input+N);
		for(int i=0;i<N;i++){
			if(i%2==0){
				sum1+=input[i];
			}
			else{
				sum2+=input[i];
			}
		}
		cout<<sum1-sum2<<endl;
		sum1=0;
		sum2=0;
	}
	return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
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; }
template<class T> inline T int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
// sort(ALL(v), [](auto const& lhs, auto const& rhs) { return lhs > rhs; /* 左の方が大きい...というイメージ。*/ });
// --------------------------------------------------------------------------------------------- //

static const int MAX = 100001;
static const ll MOD = 1000000007;


int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int n, m; cin >> n >> m;
	dsu d(n);
	rep(i, m){
		int x,y; cin >> x >> y;
		x--; y--;
		d.merge(x, y);
	}
	cout << d.groups().size() - 1 << endl;

	return 0;
}


Measured memory_bytes: 8884
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC opatimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }


int main() {
//    freopen("in.txt","r", stdin);
//    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n,k;
    cin >> n >> k;
    int ans = 0;
    while (n > 0) {
        ++ans;
        n /= k;
    }
    cout << ans << endl;
}


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

int main(){
  string o, e;
  cin >> o >> e;

  for(int i=0; i<o.length()+e.length(); i++){
    cout << ((i%2)?e[i/2]: o[i/2]);
  }
  cout << endl;
  return 0;
}


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

typedef long long ull;

set<ull> su;
ull ans =  1e18+1;

void solve(ull n , ull k){
	if(su.count(n) > 0)
		return;
	else{
		su.insert(n);
		ans = min(ans, n);
		solve(abs(n-k), k);
	}
}

int main(){
	ull n, k;
	cin >> n >> k;
	if(n > k){
		solve(n % k, k);
	}else if(n == k){
		ans = 0;
	}else
		solve(n, k);
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n+1];
		int[] b = new int[n+1];
		int[] c = new int[n];

		for ( int i = 1; i <= n; i++ )
			a[i] = in.nextInt();
		for ( int i = 1; i <= n; i++ )
			b[i] = in.nextInt();
		for ( int i = 1; i <= n - 1; i++ )
			c[i] = in.nextInt();

		int sum = 0;
		int prev = 0;
		for ( int i = 1; i <= n; i++ ) {
			sum += b[a[i]];
			// System.out.println("a:" + a[i] + " b:" + b[i] + " sum:" + sum);
			
			if(prev == a[i] - 1 ) {
				sum += c[prev];
			}
			
			prev = a[i];
		}

		System.out.println(sum);
		in.close();

	}
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    final int M = 1_000_000_007;
    int H = scanner.nextInt();
    int W = scanner.nextInt();
    char[][] grid = new char[H][W];
    for (int i = 0; i < H; i++) grid[i] = scanner.next().toCharArray();

    long[][] dp = new long[H][W];
    dp[0][0] = 1;
    for (int i = 1; i < W; i++) if(grid[0][i] == '.') dp[0][i] = dp[0][i - 1];
    for (int i = 1; i < H; i++) if(grid[i][0] == '.') dp[i][0] = dp[i - 1][0];
    for (int i = 1; i < H; i++)
      for (int j = 1; j < W; j++) 
        if (grid[i][j] == '.') dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % M;
    System.out.println(dp[H - 1][W - 1]);
  }
}


Measured memory_bytes: 51820
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
int n;
const int N=2e5+10;
struct path{int y,nxt;}g[N<<1];int h[N];
int dep[N];
void dfs(int x,int f,int &k){
	dep[x]=dep[f]+1;if(dep[x]>dep[k])k=x;
	for(int i=h[x];i;i=g[i].nxt)if(g[i].y!=f)dfs(g[i].y,x,k);
}
int dp[N];
int tr[N];
void add(int pos){for(;pos,pos<=n;pos+=pos&-pos)tr[pos]++;}
int qry(int pos){int re=0;if(pos<=0)return 0;for(;pos;pos-=pos&-pos)re+=tr[pos];return re;}
int main(){
	//freopen("a.in","r",stdin);
	scanf("%d",&n);int x,y;
	for(int i=1;i<n;i++){
		scanf("%d%d",&x,&y);g[i*2-1]=path{y,h[x]};h[x]=i*2-1;
		g[i*2]=path{x,h[y]};h[y]=i*2;
	}
	int a=0,b=0,d;
	dfs(1,0,a);
	memset(dep,0,sizeof(dep));
	dfs(a,0,b);d=dep[b];
	//first_win:0
	for(int i=2;i<=n;i++){
		if(qry(i-1)-qry(i-3)==0) dp[i]=1,add(i);else dp[i]=0;
	}
	if(!dp[d])puts("First");else puts("Second");
}

Measured memory_bytes: 15872
#include "bits/stdc++.h"
#include <random>
#include <algorithm>
#include <unordered_set>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define Sort(a) sort(a.begin(),a.end())
#define cSort(a,cmp) sort(a.begin(),a.end(),cmp)
#define reSort(a) sort(a.rbegin(), a.rend())
static const ll llMAX = numeric_limits<long long>::max();
static const int intMAX = numeric_limits<int>::max();
static const ll  llMIN = numeric_limits<long long>::min();
static const int intMIN = numeric_limits<int>::min();
static const ll d_5 = 100000;
static const ll d9_7 = 1000000007;
static const ll d_9 = 1000000000;
static const double PI=3.14159265358979323846;

template<class T>
void Printvector(std::vector<T> &a){
  int size = a.size();
  rep(i,size){
    cout<<a[i]<<" ";
  }
  cout<<endl;
}
template<class T>
void Printvector(std::vector<std::vector<T>> &a){
  int size = a.size();
  rep(i,size){
    int size2=a[i].size();
    rep(j,size2){
      cout<<a[i][j]<<" ";
    }
    cout<<endl;
  }
  cout<<endl;
}
int main(void){
  ll x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<ll> p(a),q(b),r(c);
  rep(i,a)cin>>p[i];
  rep(i,b)cin>>q[i];
  rep(i,c)cin>>r[i];
  reSort(p);
  reSort(q);
  reSort(r);
  priority_queue<ll,vector<ll>,greater<ll>> sg;
  priority_queue<ll,vector<ll>,greater<ll>>  sr;
   ll sum1=0,sum2=0;
  rep(i,x){
    sr.push(p[i]);
    sum1+=p[i];
  }
  rep(i,y){
    sg.push(q[i]);
  sum2+=q[i];
  }
  rep(i,c){
    //c番目を入れるかどうか
    ll num1=sr.top();
    ll num2=sg.top();
    if(num1>=r[i] && num2 >= r[i]){
      continue;
    }
    if(num1>=r[i]){
      sg.pop();
      sg.push(r[i]);
      continue;
    }
    if(num2>=r[i]){
      sr.pop();
      sr.push(r[i]);
      continue;
    }
    if(num1>num2){
      //num2の方が小さい数を追い出せる
      sg.pop();
      sg.push(r[i]);

    }else{
      sr.pop();
      sr.push(r[i]);
    }
  }
  ll ans=0;
  while (!sg.empty()) {
      ans+=sg.top();
      sg.pop();
    }
  
  while (!sr.empty()) {
      ans+=sr.top();
      sr.pop();
    }
  cout<<ans<<endl;
  return 0;
}

//<<std::setprecision(30)

//重複削除
 /* std::sort(vec.begin(), vec.end());
 
  vec.erase(std::unique(vec.begin(), vec.end()), vec.end());*/

  //ペアの全探索
  /*do{
		int s=0;
		for(int i=0;i<n/2;i++)s+=v[i]^v[i+n/2];
		r=max(s,r);
		reverse(v.begin()+n/2,v.end());
	}while(next_permutation(v.begin(),v.end()));*/


Measured memory_bytes: 4852