akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>pii;
typedef pair<long long, long long>pll;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7; constexpr int MAX = 100050;
const double pi = acos(-1); constexpr double EPS = 1e-12;
constexpr ll INF = 1e16;
void yes(bool c) { if (c)print("Yes"); else print("No"); };


void solve() {
	string S, T;
	cin >> S >> T;
	yes(T.substr(0, S.size()) == S);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 3620
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;

class Main{
        public static void main(String args[]){
                Scanner sc = new Scanner(System.in);
                String s = sc.next();
                int a=0,b=0,c=0;
                for(int i=0;i<3;i++){
                        if(s.charAt(i)=='a'){
                                a ++;
                        }else if(s.charAt(i)=='b'){
                                b ++;
                        }else if(s.charAt(i)=='c'){
                                c ++;
                        }
                }
                if(a==1&&b==1&&c==1){
                        System.out.print("Yes");
                }else{
                        System.out.print("No");
                }
        }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a.at(i);

	vector<int> num(2E+05 + 1, 0);
	for (int i = 0; i < n; i++) {
		num.at(a.at(i))++;
	}

	sort(num.begin(), num.end(), greater<int>());

	int cnt = 0;
	for (int i = 0; i < 2E+05 + 1; i++) {
		if (num.at(i) == 0) {
			cnt = i;
			break;
		}
	}

	if (cnt > k) {
		int ans = 0;
		for (int i = k; i < cnt; i++) {
			ans += num.at(i);
		}
		cout << ans << endl;
	} else {
		cout << 0 << endl;
	}

 	return 0;
 }

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<long long,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
P pa1[100005];
P pa2[100005];
int h,w,n;
bool comp1(P a,P b){
	return a.first<b.first;
}
bool comp2(P a,P b){
	return a.second<b.second;
}
bool decide(P1 a,P1 b){
	if(a.first<b.first){
		return true;
	}else if(a.first>b.first){
		return false;
	}else{
		if(a.second.first<b.second.first){
			return true;
		}else if(a.second.first>b.second.first){
			return false;
		}else{
			return a.second.second<b.second.second;
		}
	}
}
int main(){
	scanf("%d %d",&h,&w);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		pa1[i]=mp(x,y);
		pa2[i]=pa1[i];
	}
	sort(pa1+1,pa1+(n+1),comp1);
	int ha=(n+1)/2;
	int ax=pa1[ha].first;
	vector<P1>vec;
	vector<int>dx,dy;
	if(pa1[ha+1].first!=ax){
		dx.pb(ax);
		dx.pb(pa1[ha+1].first);
	}
	else{
		dx.pb(ax);
		dx.pb(ax-1);	
		dx.pb(ax+1);		
	}
	sort(pa1+1,pa1+(n+1),comp2);
	int ay=pa1[ha].second;
	if(pa1[ha+1].second!=ay){
		dy.pb(ay);
		dy.pb(pa1[ha+1].second);
	}
	else{
		dy.pb(ay);
		dy.pb(ay-1);	
		dy.pb(ay+1);		
	}

	for(int i=0;i<dx.size();i++){
		for(int j=0;j<=dy.size();j++){
			long long sd=0;
			int maxi=0;
			for(int g=1;g<=n;g++){
				sd+=(abs(pa1[g].first-dx[i])+abs(pa1[g].second-dy[j]));
				maxi=max(maxi,(abs(pa1[g].first-dx[i])+abs(pa1[g].second-dy[j])));
			}
			vec.pb(mp(sd*2-maxi,mp(dx[i],dy[j])));
		}
	}
sort(vec.begin(),vec.end(),decide);
printf("%lld\n%d %d\n",vec[0].first,vec[0].second.first,vec[0].second.second);
return 0;
}

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

using namespace std;

typedef long long ll;
const int mod=1e9+7;
int c[200005];
int fastpow(int a,int n)
{
    int res=1;
    int temp=a;
    while(n)
    {
        if(n&1)
        {
            res=(1LL*res*temp)%mod;
        }
        temp=(1LL*temp*temp)%mod;
        n>>=1;
    }
    return res%mod;
}
int main()
{
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
    }
    sort(c,c+n,greater<int>());
    int ans=fastpow(4,n-1);
    int res=0;
    for(int i=0;i<n;i++)
    {
        res=res+(1LL*(i+2)*c[i])%mod;
        res=res%mod;
    }
    res=(1LL*res*ans)%mod;
    cout<<res;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, num = 1;
  cin >> N >> K;
  
  for ( int i = 0; i < N; i++ ) {
    if ( num * 2 < num + K ) {
      num *= 2;
    }
    else {
      num += K;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int x;
  scanf("%d", &x);
  
  int i = 1;
  while(i <= 8){
    if(x >= -200*i + 2000 && x < -200*i + 2200){
      printf("%d\n", i);
    }
    i++;
  }
  
  return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<numeric>

using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)
#define reps(i, a, b) for(ll i = a; i < b; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

///////////////////////////////////////////////////////////////////////////

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

	string N;
	cin >> N;

	if (N == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (N == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else {
		cout << "Sunny" << endl;
	}
}



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

const int dummy=10000000;
int N;
int x[8];
int y[8];
bool marked[8];
vector<int> perm;

double sum=0;

double dist(int i, int j) {
  if (i==dummy || j==dummy) return 0;
  return sqrt( (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) );
}

void dfs(int to){
  perm.push_back(to);
  if((int)perm.size()==N) {
    //cerr << "depthN ";
    //for(auto i : perm) cerr << i << " ";
    //cerr << endl;
    for(int i=0; i<N-1; i++) sum += dist(perm[i],perm[i+1]);
  }
  marked[to] = true;
  for (int i = 0; i < N; i++) if(!marked[i]) dfs(i);
  marked[to] = false;
  perm.pop_back();
}

int main()
{
  cin >> N;
  for (int i=0; i<N; i++) cin >> x[i] >> y[i];

  //cout << N << endl;
  //for (int i=0; i<N; i++) cout << x[i] << " " << y[i] << endl;

  for (int i=0; i<N; i++) marked[i] = false;
  for (int i=0; i<N; i++) dfs(i);

  int kaijou = 1;
  for (int i=2; i<=N; ++i) kaijou *= i;

  cout << fixed << setprecision(10) << sum / kaijou << endl;

  
  return 0;
}


Measured memory_bytes: 256
n = int(input())

x = [0] * n
y = [0] * n
h = [0] * n

for i in range(n):
    x[i], y[i], h[i] = map(int, input().split())

for cx in range(101):
    for cy in range(101):
        H = -1
        for i in range(n):
            if h[i] == 0:
                pass
            else:
                tmp = h[i] + abs(x[i]-cx) + abs(y[i]-cy)
                H = tmp
                break
        flag = True
        for i in range(n):
            if h[i] != max(H-abs(x[i]-cx)-abs(y[i]-cy),0):
                flag = False
                break
        if flag:
            print(cx,cy,H)

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

vector<vector<pair<int, int>>> G;
vector<int> ans;

void dfs(int v, int dist, int pre) {
  ans.at(v) = dist % 2;
  for (auto g : G.at(v)) {
    if (g.first == pre) continue;
    dfs(g.first, dist + g.second, v);
  }
}

int main() {
  int N;
  cin >> N;
  G.resize(N);
  ans.resize(N);
  for (int i = 0, a, b, c; cin >> a >> b >> c; i++) {
    G.at(--a).push_back({--b, c % 2});
    G.at(b).push_back({a, c % 2});
  }
  dfs(0, 0, -1);
  for (auto a : ans) cout << a << "\n";
}

Measured memory_bytes: 8192
import math
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
q = int(math.sqrt(n))+1
sum = 0
for i in range(1,q):
    ddprint("i {}".format(i))
    if n%i==0:
        m = n//i - 1
        ddprint("divides m {}".format(m))
        if m==0:
            continue
        if n%m == n//m:
            sum += m
print(sum)


Measured memory_bytes: 40428
#include<stdio.h>
int main(){
  int x,y,tmp,d;
  scanf("%d %d",&x,&y);
  if(x<y){
    tmp=x;
    x=y;
    y=tmp;
  }
  d=x%y;
  while(d!=0){
    x=y;
    y=d;
    d=x%y;
  }
  printf("%d\n",y);
}



Measured memory_bytes: 2084
N, P = [int(x) for x in input().strip().split(" ")]

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        c = 0
        while n % i == 0:
            n /= i
            c+=1
        if c!=0:
            table.append((i,c))
        i += 1
    if n > 1:
        table.append((int(n), 1))
    return table


xx = prime_decomposition(P)

result = 1
for b, r in xx:
    result *= pow(b, r//N)
print(result)


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

int main()
{
    int a, b;
    cin >> a >> b;
    if(a + b == 15)
        cout << "+" << endl;
    if(a * b == 15)
        cout << "*" << endl;
    if(a + b != 15 && a * b != 15)
        cout << "x" << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

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

  int n, m;
  cin >> n >> m;
  vector<vector<int>> d(m, vector<int>(m));
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> d[i][j];
    }
  }
  vector<vector<int>> cnt(3, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int x;
      cin >> x;
      --x;
      cnt[(i + j) % 3][x]++;
    }
  }
  int best = 1 << 30;
  for (int u = 0; u < m; ++u) {
    for (int v = 0; v < m; ++v) {
      if (u == v) continue;
      for (int w = 0; w < m; ++w) {
        if (w == u || w == v) continue;
        vector<int> C = {u, v, w};
        int cur = 0;
        for (int k = 0; k < 3; ++k) {
          for (int i = 0; i < m; ++i) {
            cur += d[i][C[k]] * cnt[k][i];
          }
        }
        best = min(best, cur);
      }
    }
  }
  cout << best << endl;
  return 0;
}


Measured memory_bytes: 256
def compare(sub, t):
    for i in range(len(t)):
        if sub[i] == t[i] or sub[i] == '?':
            continue
        else:
            return False
    return True

clear = False
s = input()
t = input()
if len(s) == len(t):
    clear = compare(s, t)
    s = t
for i in range(len(s)-len(t), 0, -1):
    if compare(s[i:i+len(t)], t):
        clear = True
        s = s[:i] + t + s[i+len(t):]
        break
if clear:
    print(s.replace('?', 'a'))
else:
    print('UNRESTORABLE')

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

using namespace std;

typedef long long int lli;

int main() {
    int n, m, a;
    priority_queue<int> pq;

    cin >> n >> m;
    for (int i=0; i<n; i++) {
        cin >> a;
        pq.push(-a);
        //cout << a << endl;
    }

    pair<int, int> pr[100000];
    for (int i=0; i<m; i++) {
        cin >> pr[i].second >> pr[i].first;
    }
    sort(pr, pr+m, greater<pair<int, int>>());

    for (int i=0; i<m; i++) {
        if (pr[i].first <= -pq.top()) break;

        for (int j=0; j<pr[i].second; j++) {
            if (-pq.top() >= pr[i].first) break;
            pq.pop();
            pq.push(-pr[i].first);
        }
    }

    lli ans = 0;
    for (int i=0; i<n; i++) {
        ans += -pq.top();
        pq.pop();
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1528
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=sum(B)
for i in range(N-1):
    if A[i]+1==A[i+1]:
        ans+=C[A[i]-1]
print(ans)

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

int main(){
    int a,b;
    char op;

    cin >> a >> op >> b;

    while(op!='?'){
        if(op=='+'){
            cout << a+b << endl;
        }

        else if(op=='-'){
            cout << a-b << endl;
        }

        else if(op=='*'){
            cout << a*b << endl;
        }

        else if(op=='/'){
            cout << a/b << endl;
        }

        cin >> a >> op >> b;
    }

    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;

int main() {
	int n; cin >> n;
	vi ans(n*n, 0);
	Loop1(i, n) {
		int x; cin >> x;
		ans[x - 1] = i;
	}
	queue<int> que;
	Loop(i, n*n) {
		if (ans[i] > 1) {
			que.push(ans[i]);
		}
	}
	vi a(n + 1);
	Loop1(i, n) a[i] = i - 1;
	bool judge = true;
	Loop(i, n*n) {
		if (ans[i] != 0) {
			if (a[ans[i]] > 0) {
				judge = false;
				break;
			}
			else {
				a[ans[i]] += n - ans[i];
				if (ans[i] != n) que.push(ans[i]);
			}
		}
		else {
			if (que.size() == 0) {
				judge = false;
				break;
			}
			else {
				a[que.front()]--;
				ans[i] = que.front();
				if (a[que.front()] == 0) que.pop();
			}
		}
	}
	if (judge) {
		cout << "Yes" << endl;
		Loop(i, n*n) cout << ans[i] << " ";
		cout << endl;
	}
	else cout << "No" << endl;
	return 0;
}

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

typedef long long int ll;
typedef vector<int> vi;            typedef vector<ll> vl;
typedef vector<vi> vvi;         typedef vector<vl> vvl;
typedef pair<int, int>     pii;    typedef pair<ll, ll> pll;
typedef vector<pii> vii;         typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 998244353
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
const ll INFL = 1e18;
const int INFI = 1e9;
#ifdef KARAN
    #include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}
ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
    while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
    int n; cin>>n;
    vl a(n); forn(i, n) cin>>a[i];
    sort(all(a));
    ll ans = 1;
    ll maxval = 1e18;
    forn(i, a.size()){
        if(ans == 0){ cout<<0<<endl; return; }
        ll bmax = maxval/ans;
        if(a[i]>bmax){ cout<<-1<<endl; return;}
        ans = ans * a[i];
    }
    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifdef KARAN
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        freopen("err.txt", "w", stderr);
    #endif
    // init();
    int t=1;
    while(t--)
        solve();
}

Measured memory_bytes: 3992
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;


template <typename T>using ordered_set = tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;

#define PI              acos(-1.0)
#define en '\n'
#define Infi 0x3f3f3f3f
#define LInfi 0x3f3f3f3f3f3f3f3f

#define setzero(a)    memset(a,0,sizeof(a))
#define setneg(a)     memset(a,-1,sizeof(a))
#define setinf(a)     memset(a,126,sizeof(a))


#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);


const int dx[] = {+1,-1,+0,+0};                         // 4 X directions
const int dy[] = {+0,+0,+1,-1};                         // 4 Y directions
const int dx8[] = {+0,+0,+1,-1,-1,+1,-1,+1};            // King X Moves
const int dy8[] = {-1,+1,+0,+0,+1,+1,-1,-1};            // King Y Moves
const int kx[] = {-2, -2, -1, -1,  1,  1,  2,  2};      // Knight X Moves
const int ky[] = {-1,  1, -2,  2, -2,  2, -1,  1};      // Knight Y Moves



int  Set    (int N,int pos) {return N=N | (1<<pos);}    /// turn a bit on
int  reset  (int N,int pos) {return N= N & ~(1<<pos);}  /// turn a bit off
bool check  (int N,int pos) {return (bool)(N & (1<<pos));} /// check, if a bit is on or not

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif

typedef long long int  ll;
typedef unsigned long long int llu;

vector<vector<int>> graph;

int dp[100005];

int make(int id){

    if(dp[id]!=-1)return dp[id];

    int ans = 0;
    for(int i=0;i<graph[id].size();i++){
        ans = max(ans,1+make(graph[id][i]));
    }
    return dp[id] = ans;
}

int main(void){

    int n,m;
    cin >> n >> m;

    graph.assign(n+2,vector<int>());

    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        graph[a].push_back(b);
    }
    int ans = 0;

    memset(dp,-1,sizeof(dp));

    for(int i=1;i<=n;i++){
        ans = max(ans,make(i));
    }

    cout << ans << endl;

    return 0;
}


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

#define REP(i,n) for (int i=0;i<(n);++i)
#define rall(a) (a).rbegin(),(a).rend()

using namespace std;

using ll = long long;

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

    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> p(A), q(B), r(C);
    REP(i, A) cin >> p[i];
    REP(i, B) cin >> q[i];
    REP(i, C) cin >> r[i];

    sort(rall(p));
    sort(rall(q));

    vector<int> v;
    REP(i, X) v.push_back(p[i]);
    REP(i, Y) v.push_back(q[i]);
    REP(i, C) v.push_back(r[i]);
    sort(rall(v));
    cout << accumulate(v.begin(), v.begin() + (X + Y), 0ll) << endl;

    return 0;
}


Measured memory_bytes: 3572
#include <stdio.h>
int main(void)
{
  int a,b,i;
  char op;
  while(1){
    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=='/'){
      printf("%d\n",a/b);
    }else{
      break;
    }
  }
    return 0;
}

Measured memory_bytes: 600
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        string o = ins(), e = ins();
        string ans;
        int io = 0, ie = 0;
        for (int i = 0; i < o.size() + e.size(); ++i) {
            if (i % 2 == 0) {
                ans += o[io];
                io++;
            } else {
                ans += e[ie];
                ie++;
            }
        }
        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100001

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

int main() {
    int N, L;
    cin >> N >> L;
    int first, last;
    first = L;
    last = L + N - 1;

    int ans;
    ans = (L-1)*N + N*(N+1)/2;
    if ( first >= 0 ) {
        ans -= first;
    } else if (  last <= 0 ) {
        ans -= last;
    } 
    cout << ans << endl;

}



Measured memory_bytes: 256
fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let mut a: Vec<usize> = (0..n).map(|_| sc.read()).collect();

    let mut ans = 0;
    loop {
        let s: usize = a.iter().map(|&ai| ai / n).sum();
        for i in 0..n {
            a[i] = a[i] - a[i] / n * n + s - a[i] / n;
        }
        ans += s;

        if *a.iter().max().unwrap() <= n - 1 {
            break;
        }
    }

    println!("{}", ans);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 4352
# 2019/07/26

n=int(input())

xyh=[]

for i in range(n):
    x,y,h=map(int,input().split())
    xyh.append((h,x,y))

xyh.sort(reverse=True)

for i in range(101):
    for j in range(101):
        
        H=xyh[0][0]+abs(xyh[0][1]-i)+abs(xyh[0][2]-j)
        for k in range(1,n):
            h,x,y=xyh[k]
            HH=h+abs(x-i)+abs(y-j)
            if H==HH or H-HH<0 and h==0:continue
            else:break
        else:
            print(*[i,j,H])
            exit()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define loopf(i,a,b) for(int i = a;i < b;i++)
#define loopb(i,a,b) for(int i = a;i >= b;i--)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;


int32_t main()
{
    fast

   int test=1;
   //cin>>test;

  while(test--)
  {
  string s;
  cin>>s;
  int n=s.size();

  if(s[2]==s[3] && s[4]==s[5])cout<<"Yes";
  else cout<<"No";


  //while loop ending 
  }

return 0;
}

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

using namespace std;

typedef long long lint;

int sum(lint nr)
{
    int rez = 0;
    while(nr != 0)
    {
        rez += nr % 10;
        nr /= 10;
    }

    return rez;
}

int s[1000001];

int k;

int care[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 199, 299, 399, 499, 599, 699, 799, 899, 999};

struct elem
{
    lint nr;
    int i;
};

struct cmp
{
    bool operator () (const elem &a, const elem &b) const
    {
        return (a.nr * sum(b.nr) < sum(a.nr) * b.nr);
    }
};

elem v[1000];

int main()
{
    cin >> k;

    int i;
    for(i = 1; i <= min(27, k); i ++)
        cout << care[i] << "\n";

    k = max(0, k - 27);

    lint pas = 10;
    lint add = 9;
    for(int h = 4; h <= 15; h ++)
    {
        for(int j = 100; j <= 999; j ++)
            v[j - 99] = {j * pas + add, j};

        sort(v + 1, v + 900 + 1, cmp());

        int mx = 0;
        for(i = 1; i <= 900; i ++)
        {
            mx = max(mx, v[i].i);

            if(mx <= v[i].i)
            {
                if(k > 0)
                {
                    k --;
                    cout << v[i].nr << "\n";
                }
            }
        }

        add = add * 10 + 9;
        pas *= 10;
    }

/*
    for(int x = 1; x <= 1000000; x ++)
        s[x] = sum(x);

    int i;
    lint mn = 1;
    lint mx = 9;
    for(i = 1; i <= 1000000; i ++)
    {
        if(i > mx)
        {
            mx = mx * 10 + 9;
        }

        int ok = 1;
        for(int j = i + 1; j <= mx; j ++)
        {
            if(i * s[j] > j * s[i])
                ok = 0;
        }
        if(ok)
            cout << i << ", ";
    }*/

    return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C = MAP()

if (A == B) and (B != C):
	print("Yes")
	exit()
if (A != B) and (B == C):
	print("Yes")
	exit()
if (A == C) and (B != C):
	print("Yes")
	exit()
print("No")

Measured memory_bytes: 61676
#include<stdio.h>
#define MAX 2000001

int H, A[MAX],tmp;

void maxHeapify(int i){
  int l,r,largest,tmp;
  l=2*i;
  r=2*i+1;
  if(l<=H&&A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(r<=H&&A[r]>A[largest])
    largest=r;
  if(largest!=i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(largest);
    }
}

int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++)
    scanf("%d",&A[i]);
  for(i=H/2;i>=1;i--){
    maxHeapify(i);
  }
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 2548
def main():
	R, G, B, N = map(int, input().split())
	r_max, g_max = N//R, N//G
	def search(ball, goal):
		if goal % ball == 0:
			return 1
		return 0
	ans = search(R, N)
	ans += search(G, N)
	ans += search(B, N)
	for r in range(1, r_max+1):
		if r*R >= N:
			break
		ans += search(G, N-r*R)
		ans += search(B, N-r*R)
		for g in range(1, g_max+1):
			if r*R+g*G >= N:
				break
			ans += search(B, N-r*R-g*G)

	for g in range(1, g_max+1):
		if g*G >= N:
			break
		ans += search(B, N-g*G)
	print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    int a[x],b[x];
    for (int i=0;i<x;i++){
        cin>>a[i]>>b[i];
    }
    sort(a,a+x);
    sort(b,b+x);
    if (x%2==1)
        cout<<b[x/2]-a[x/2]+1<<endl;
    else
        cout<<b[x/2]+b[x/2-1]-a[x/2]-a[x/2-1]+1<<endl;

    return 0;
}


Measured memory_bytes: 5168
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  long long N;

  std::cin >> N;

  if (N & 1) {
    std::cout << 0 << std::endl;

    return 0;
  }

  long long C = 0;

  for ( ; N; N /= 5)
    C += N / 2 / 5;

  std::cout << C << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char S[10]; scanf("%s",S);
  int count=0,max_count=0;
  for(int i=0;i<10;i++){
    switch (S[i]) {
      case 'A':
      case 'C':
      case 'G':
      case 'T': count++; break;
      default: if(count>max_count){
                    max_count=count;
                  }
                  count=0;
                  break;
    }
  }
  if(count>max_count){
    max_count=count;
    count=0;
  }

  printf("%d\n",max_count);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<array<int, 4>> perms;
vector<array<int, 4>> v;
struct P {
    int id, x;
    P(int id = 0, int x = 0) : id(id), x(x) {};

    bool operator<(const P &b) const {
        for (auto &&i : perms[x]) {
            if(v[id][i] != v[b.id][i]) return v[id][i] < v[b.id][i];
        }
        return false;
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < k; ++j) {
            scanf("%d", &v[i][j]);
        }
    }
    int d;
    cin >> d;
    vector<vector<int>> G(n);
    vector<int> deg(n);
    for (int i = 0; i < d; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        deg[b]++;
        G[a].emplace_back(b);
    }
    {
        array<int, 4> a{};
        iota(a.begin(),a.begin()+k, 0);
        do {
            perms.emplace_back(a);
        }while (next_permutation(a.begin(),a.begin()+k));
    }
    int m = perms.size();
    vector<priority_queue<P>> Q(m);
    vector<int> visited(n);
    for (int i = 0; i < n; ++i) {
        if(!deg[i]){
            for (int j = 0; j < m; ++j) {
                Q[j].emplace(i, j);
            }
        }
    }
    int p = 0;
    auto update = [&](array<int, 4> &v){
        for (int i = 0; i < perms.size(); ++i) {
            if(v == perms[i]) {
                p = i;
                return;
            }
        }
    };
    {
        array<int, 4> x{};
        for (int i = 0; i < k; ++i) {
            cin >> x[i];
            x[i]--;
        }
        update(x);
    }
    int q;
    cin >> q;
    vector<pair<int, array<int, 4>>> query(q);
    for (int i = 0; i < q; ++i) {
        scanf("%d", &query[i].first);
        for (int j = 0; j < k; ++j) {
            scanf("%d", &query[i].second[j]);
            query[i].second[j]--;
        }
    }
    int cur = 0;
    for (int i = 0; i < n; ++i) {
        while(cur < q && query[cur].first == i){
            update(query[cur++].second);
        }
        int a = Q[p].top().id; Q[p].pop();
        while(visited[a]){
            a = Q[p].top().id; Q[p].pop();
        }
        printf("%d\n", a+1);
        visited[a] = 1;
        for (auto &&j : G[a]) {
            if(!--deg[j]){
                for (int l = 0; l < m; ++l) {
                    Q[l].emplace(j, l);
                }
            }
        }
    }
    return 0;
}


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

template <typename T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template <class c
#define ris return *this
#define dor > debug& operator<<
#define eni(x)                                                                 \
    sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(   \
              c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c&) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mem(a, s) memset(a, s, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for (int i = a; i >= b; --i)

typedef vector<int> vi;
typedef stack<int> sti;
typedef queue<int> qi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

int _x[] = {0, 0, -1, 1, -1, 1, -1, 1};
int _y[] = {-1, 1, 0, 0, 1, -1, -1, 1};

const int mod = 1e6 + 7;

void solve();
void pre();

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    int t = 1;
    // cin >> t;
    rep(i, 1, t) {
        // cout << "Case # " << i << ": ";
        solve();
    }
    return 0;
}

void pre() {}

void solve() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i, 1, sz(s) - 1) {
        if (s[i] == s[i - 1]) {
            ans++;
            if (s[i - 1] == '0')
                s[i] = '1';
            else
                s[i] = '0';
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3748
N = int(input())

li = []
for i in range(N):
	li.append(input())

last_str = li[0][0]

if len(li) != len(list(set(li))):
	print("No")
else:
	for i in li:
		if i[0] != last_str:
			print("No")
			break
		else:
			last_str = i[-1]
	else:
		print("Yes")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int N, a[109];

int main(){
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  sort(a, a + N, greater<int>());
  int ret = 0;
  for (int i = 0; i < N; i++){
    ret += a[i] * (i & 1 ? -1 : 1);
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//何個あるかの数
		String s = br.readLine();



		int x = s.length();

		String f = s.substring(0, 1);
		String e = s.substring(x-1);

		System.out.println(f+(x-2)+e);


	}


}

Measured memory_bytes: 21204
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	struct max_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	constexpr max_t max;
	constexpr min_t min;

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min();

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
}

void Main()
{
	std::size_t N, M;
	std::int64_t K;
	std::cin >> N >> M >> K;
	std::vector<std::int64_t> a(N), b(M), a_sum(N + 1), b_sum(M + 1);
	for (auto i : boost::irange(N))
	{
		std::cin >> a[i];
		a_sum[i + 1] = a_sum[i] + a[i];
	}
	for (auto i : boost::irange(M))
	{
		std::cin >> b[i];
		b_sum[i + 1] = b_sum[i] + b[i];
	}
	std::size_t max = 0;
	for (auto i : boost::irange(N + 1))
	{
		if (K < a_sum[i])
		{
			break;
		}
		auto t = K - a_sum[i];
		auto ite = boost::upper_bound(b_sum, t);
		max = std::max(max, std::size_t(i + std::distance(b_sum.begin(), ite) - 1));
	}
	std::cout << max << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 9532
from sys import stdin
N = int(stdin.readline().rstrip())
P = [int(x) for x in stdin.readline().rstrip().split()]
mi = P[0]
ma = P[0]
ans = 0
for i in range(N):
    if P[i] <= mi:
        ans += 1
    ma = max(ma,P[i])
    mi = min(mi,P[i])
print(ans)

Measured memory_bytes: 25768
N = int(input())
A = [0] + sorted([int(i) for i in input().split()]) + [10**9+1]
B = sorted([int(i) for i in input().split()])
C = [10**9+1] + sorted([int(i) for i in input().split()], reverse=True) + [0]

def A_count(n, ls):
    left = 0
    right = N + 1

    while right - left > 1:
        mid = (left + right) // 2

        if n <= ls[mid]: right = mid
        if n > ls[mid]: left = mid

    return left

def C_count(n, ls):
    left = 0
    right = N + 1

    while right - left > 1:
        mid = (left + right) // 2

        if n >= ls[mid]: right = mid
        if n < ls[mid]: left = mid

    return left

ans = 0
for i in range(N):
    n = B[i]
    ans += A_count(n, A) * C_count(n, C)

print(ans)

Measured memory_bytes: 24820
#include<iostream>
using namespace std;
int main() {
	int a[10],x,y;
	for (int n = 0; n < 10; n++) {
		cin >> a[n];
	}
	for (int j = 0; j < 10; j++) {
		for (int i = 0; i < 9; i++) {
			if (a[i] < a[i + 1]) {
				x = a[i];
				y = a[i + 1];
				a[i] = y;
				a[i + 1] = x;
			}
		}
	}
	cout << a[0] << endl << a[1] << endl << a[2] << endl;
	return 0;
}

Measured memory_bytes: 3076
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

class union_find {
    private:
        vector<int> par;
        vector<int> ran;
        vector<ll> size;
    public:
        union_find(int n);
        int find(int x);
        void unite(int x, int y);
        bool same(int x, int y);
        ll show_size(int x);
};

union_find::union_find(int n){
    par.resize(n);
    ran.resize(n);
    size.resize(n);
    rep(i,n) par[i] = i;
    rep(i,n) ran[i] = 0;
    rep(i,n) size[i] = 1;
};

int union_find::find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    ll t = show_size(x)+show_size(y);
    size[x] = size[y] = t;
    if(ran[x] < ran[y]){
        par[x] = y;
        //size[y] += size[x];
    }
    else{
        par[y] = x;
        //size[x] += size[y];
        if(ran[x] == ran[y]) ran[x]++;
    }
};

ll union_find::show_size(int x) {
    if(par[x] == x) return size[x];
    return show_size(par[x] = find(par[x]));
}

bool union_find::same(int x, int y) {
    return (find(x) == find(y));
};

int main(int argc, char const *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	rep(i,m){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}
	ll disable = n*(n-1)/2;
	vector<ll> ans(m);
	union_find uf(n);
	for(int i = m-1; i >= 0; i--){
		ans[i] = disable;
		if(!uf.same(a[i], b[i])){
			disable -= (uf.show_size(a[i])) * (uf.show_size(b[i]));
			uf.unite(a[i], b[i]);
		}
	}
	rep(i,m) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 4480