akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
#pragma GCC optimize ("Ofast")

#define repk(i,a,b) for(int i=(a);i<=(b);++i)
#define FOR(i,n)  for(int i=0;i<=(n);++i)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define for1(i,n)  for(int i=1;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
#define ll long long
#define ld long double
#define point pair<double,double>
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
const int  inf = INT_MAX;
const int MOD = 1000000007;
const int N = 100100;

using namespace std;


void sol() {
	int x, y; cin >> x >> y;
	bool ok = 0;
	rep(i, 0, 200)rep(j, 0, 200) {
		if ((2 * i + 4 * j == y) && i + j == x)
		{
			ok = 1; break;
		}
	}


	if (ok)
		cout << "Yes";

	else
		cout << "No";


}



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

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int t = 1; // cin >> t;
	while (t--)
		sol();
	return 0;
}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int n;
	cin >> n;
	vector<int> arr(n);
	for(auto& el: arr) cin >> el;
	sort(arr.begin(), arr.end());
	int ans = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			if(arr[i] == arr[j]) continue;
			for(int k = j + 1; k < n; k++) {
				if(arr[k] == arr[j]) continue;
				if(arr[i] + arr[j] > arr[k]) ans++;
			}
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3656
void main() {
	auto N = ri;
	auto A = readAs!(real[]);
	A.sort();
	real tmp = A[0];
	foreach(i; 1..N) {
		tmp += A[i];
		tmp /= 2;
	}
	"%.6f".writefln(tmp);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	char S[1024];
	int i;
	int dir = 0;
	int count[4] = {0};
	int mikisinn = 0;
	if (scanf("%1023s", S) != 1) return 1;
	for (i = 0; S[i] != '\0'; i++) {
		if (S[i] == 'L') {
			dir = (dir + 3) % 4;
			if (dir == 0) {
				count[0] = count[1] = count[2] = count[3] = 0;
			}
		} else if (S[i] == 'R') {
			dir = (dir + 1) % 4;
			count[dir]++;
			if (dir == 0) {
				if (count[0] > 0 && count[1] > 0 && count[2] > 0 && count[3] > 0) {
					mikisinn++;
				}
				count[0] = count[1] = count[2] = count[3] = 0;
			}
		}
	}
	printf("%d\n", mikisinn);
	return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const int mod = 1000000007;

int main(void){
  int n;
  cin >> n;
  vector<P> task(n);
  REP(i, n){
    int a, b;
    cin >> a >> b;
    task[i] = P(b, a);
  }
  sort(ALL(task));

  int i = 0, time = 0;
  while(i < n){
    int b = task[i].first;
    int a = task[i].second;
    if(time + a <= b){
      time += a;
    }else{
      cout << "No" << endl;
      return 0;
    }
    i++;
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main() {
 int N ;
 string S ;
  cin >> N >> S ;
  if (N%2==1)
    cout << "No";
  else {
    for (int i=0;i<S.size()/2;i++){
      if (S.at(i) !=S.at(i+S.size()/2)){
         cout << "No";
          break;
          }
       if (i==S.size()/2-1)
          cout << "Yes";
          }
          }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1503;
int n;
char s[N][N];
int dp[N][N];
int leftmost[2][N][N], upmost[2][N][N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%s", s[i]);
	for (int i = 0; i <= n; i++)
		s[n][i] = s[i][n] = '#';
	ll ans = 0;
	for (int x = n - 1; x >= 0; x--) {
		for (int y = n - 1; y >= 0; y--) {
			for (int k = 0; k < n; k++)
				leftmost[0][y][k] = upmost[0][y][k] = N;
			if (s[x][y] == '#') continue;
			if (s[x + 1][y] != '#')
				for (int k = 0; k < n; k++) {
					leftmost[0][y][k] = min(leftmost[0][y][k], leftmost[1][y][k]);
					upmost[0][y][k] = min(upmost[0][y][k], upmost[1][y][k]);
				}
			if (s[x][y + 1] != '#')
				for (int k = 0; k < n; k++) {
					leftmost[0][y][k] = min(leftmost[0][y][k], leftmost[0][y + 1][k]);
					upmost[0][y][k] = min(upmost[0][y][k], upmost[0][y + 1][k]);
				}
			leftmost[0][y][x] = y;
			upmost[0][y][y] = x;
			
			//eprintf("cell = %d %d\n", x, y);
			/*
			for (int k = 0; k < n; k++)
				eprintf("%d ", leftmost[0][y][k]);
			eprintf("\n");
			for (int k = 0; k < n; k++)
				eprintf("%d ", upmost[0][y][k]);
			eprintf("\n");
			*/
			dp[x][y] = dp[x + 1][y] + dp[x][y + 1];
			if (x != n - 1 && y != n - 1) {
				for (int xx = x + 1; xx < n; xx++) {
					int yy = leftmost[0][y + 1][xx];
					//eprintf("!!! %d %d\n", xx, yy);
					if (upmost[1][y][yy] == xx)
						dp[x][y] -= dp[xx][yy];
				}
			}
			int c = (int)(s[x][y] - '0');
			ans += c * dp[x][y];
			dp[x][y] += c;
		}
		for (int y = 0; y < n; y++)
			for (int k = 0; k < n; k++) {
				leftmost[1][y][k] = leftmost[0][y][k];
				upmost[1][y][k] = upmost[0][y][k];
			}
	}
	/*
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)
			printf("%d ", dp[i][j]);
		printf("\n");
	}
	*/
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 26880
#!/usr/bin/env python3

a_size, b_size, m_size = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = []
for i in range(m_size):
    m.append(list(map(int, input().split())))

# それぞれの最安値で買う
min_sum = min(a) + min(b)

# 割引使って買う
for i in range(m_size):
    s = a[m[i][0]-1] + b[m[i][1]-1] - m[i][2]
    if min_sum > s:
        min_sum = s

print(min_sum)

Measured memory_bytes: 38492
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if(s==EOF)exit(0);
	if(s=='-')base=-1,s=getchar();
	while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
	return k*base;
}
int a[4],s;
int main()
{
	a[1]=read();a[2]=read();a[3]=read();
	sort(a+1,a+4);
	s+=a[3]-a[2];
	a[1]+=(a[3]-a[2]);
	if ((a[3]-a[1])%2==0)
	{
		s+=(a[3]-a[1])/2;
	} else
	{
		s+=(a[3]-a[1])/2+2;
	} 
	cout<<s<<" ";
	return 0;
}


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

int main() {
    ll s, ans = 0;
    cin >> s;
    s *= 4;  // s = (a+b)(b-a+1)(c+d)(d-c+1)/4
    // 約数列挙
    vector<int> divisor;
    for(int i=1;i*i<=s;i++){
        if(s%i==0){
            divisor.push_back(i);
            if(s/i != i) divisor.push_back(s/i);
        }
    }
    sort(divisor.begin(), divisor.end());
    for(auto x : divisor){
        for(auto y : divisor){
            if(s%(x*y)!=0 || (x+y)%2==0) continue;
            if(x<y) break;
            for(auto z : divisor){
                if(s%(x*y*z)!=0) continue;
                ll w = s/(x*y*z);
                if((z+w)%2==0)continue;
                if(z<w)continue;
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=1e18;
ll mod=1e9+7;
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
vector<int> graph[205];
int color[205];
int nCk[100][100];
bool bipartite_jugding(int v, int c){
    color[v] = c;
    for(int i = 0; i < graph[v].size(); ++i){
        if(color[graph[v][i]] == c) return false;
        if(color[graph[v][i]] == 0 && !bipartite_jugding(graph[v][i], -c)){
            return false;
        }
    }
    return true;
}

 void combi() {
	for (int i = 0; i <= 99; ++i) nCk[i][0] = 1;
	for (int i = 1; i <= 99; ++i) for (int j = 1; j <= i; ++j) {
		nCk[i][j] = (nCk[i-1][j] + nCk[i-1][j-1]) % mod;
	}
}

long long expo(ll x,ll n,ll M)
{

    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}
ll h,n;
void solve()
{
    cin>>h>>n;
    vector<ll> wt(n);
    vector<ll> val(n);
    for(int i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];
       // min1=min(min1,wt[i]);
    }
    ll dp[10001];
   // memset(dp, 1e4, sizeof dp);
for(int i=0;i<10001;i++)dp[i]=1e9;
dp[0]=0;
    //cout<<"kyyue"<<endl;
    // Fill dp[] using above recursive formula
    for (int i=0; i<10001; i++)
      for (int j=0; j<n; j++){
       // debug2(i,j);
         if (wt[j] <= i)
            dp[i] = min(dp[i], dp[i-wt[j]]+val[j]);
         else
            {
                dp[i]=min(dp[i],val[j]);
            }
         }
ll ans=1e9;
    for(int i=h;i<10001;i++)
    {
       // debug2(i,dp[i]);
        ans=min(ans,dp[i]);
    }
    cout<<ans<<endl;
}

int main()
{
    boost;
  solve();
}


Measured memory_bytes: 384
while True:
    a,op,b,=input().split()
    a=int(a)
    b=int(b)
    
    if op=='?':
        break
    if op=='+':
        print(a + b)
    if op=='-':
        print(a - b)
    if op=='*':
        print(a * b)
    if op=='/':
        print(a // b)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

int main(){
    int n;
    cin>>n;
    vector<int> b(n,0);
    rep(i,n-1)cin>>b[i];
    int cnt=0;
    cnt+=b[0];
    cnt+=b[n-2];
//    cout<<b[0]<<endl;
//    cout<<b[n-1]<<endl;
    for(int i = 1;i < n-1; i++){
//        cout<<cnt<<" ";
        cnt+=min(b[i-1],b[i]);
    }
//    cout<<endl;
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
def trans(n, dp, color):
    for i in range(n-color+1):
        dp[i+color] += dp[i]
    return dp

def main():
    r, g, b, n = [int(i) for i in input().split()]
    dp = [0 for i in range(n+1)]
    dp[0] = 1
    dp = trans(n, dp, r)
    dp = trans(n, dp, g)
    dp = trans(n, dp, b)
    print(dp[-1])

main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;

string subsum(int* A,int n,int m){
  bitset<2010> E(1);

  rep(i,0,n){
    E |= (E<<A[i]);
  }

  if(E.test(m)) return "yes";
  else return "no";
}



int main(int argc,char **argv){
  int n; cin>>n;
  vector<ll> s(n);
  rep(i,0,n) cin>>s.at(i);
  int q; cin>>q;
  vector<ll> t(n);
  rep(i,0,q) cin>>t.at(i);

  sort(all(s));
  int cnt=0;
  rep(i,0,q){
    if(binary_search(all(s),t[i])){
      cnt++;
    }
  }

  cout<<cnt<<endl;
  }


Measured memory_bytes: 4404
#include<bits/stdc++.h>
using namespace std;
int ara[101];
int main()
{
    int n,sum=0,m,p,x,res;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>ara[i];
        sum+=ara[i];
    }
    cin>>m;
    while(m--)
    {
        cin>>p>>x;
        res=sum-ara[p]+x;
        cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
from collections import deque

n,u,v=map(int,input().split())
u-=1
v-=1

a=[[] for i in range(n)]


for i in range(n-1):
  s,t=map(int,input().split())
  a[s-1].append(t-1)
  a[t-1].append(s-1)


def bfs(x):
  dist=[-1]*n
  dist[x]=0
  Q=deque()
  Q.append((x))

  while Q:
    q=Q.popleft()
    for i in a[q]:
      if dist[i]==-1:
        dist[i]=dist[q]+1
        Q.append((i))

  return dist

taka=bfs(u)
aoki=bfs(v)

ans=0
for i in range(n):
  if taka[i]<aoki[i]:
    ans=max(ans,aoki[i]-1)


print(ans)

Measured memory_bytes: 90624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define REP(i,a,b) \
for(int i=int(a);i<=int(b);i++)
#define DEP(i,a,b) \
for(int i=int(a);i>=int(b);i--)
#define TR(c, it) \
for (auto it = (c).begin(); it != (c).end(); it++)

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int T,i,k,n;
	cin>>n;
	int a[n];
	REP(i,0,n-2){
		cin>>a[i];
	}
	map<int,int> m;
	REP(i,1,n){
		m.insert({i,0});
	}
	REP(i,0,n-2){
		m.find(a[i])->second++;
	}
	TR(m,it){
		cout<<it->second<<"\n";
	}
	return 0;
}


Measured memory_bytes: 13824
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

const int MAX_N = 200005;

vector<vector<int>> g(MAX_N);
vector<int> ans(MAX_N, -1);
vector<int> a(MAX_N);
vector<int> dp(MAX_N, INT_MAX);

void dfs(int s, int p = -1) {
	int id = lower_bound(rng(dp), a[s]) - dp.begin();
	int old = dp[id];
	chmin(dp[id], a[s]);
	ans[s] = int(lower_bound(rng(dp), INT_MAX) - dp.begin()) - 1;
	for (int v: g[s]) {
		if (v == p) continue;
		dfs(v, s);
	}
	dp[id] = old;
}

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

	rep (i, n) cin >> a[i];
	rep (i, n - 1) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	dp[0] = -INT_MAX;
	
	dfs(0);

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

Measured memory_bytes: 27964
#include <stdio.h>

#define N 100


int main() {
  int data[N];
  int i, j, n, temp, count = 0;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d", &data[i]);
  }
  for(i = 0; i < n; i++) {
    for (j = n-1; j >= i+1; j--) {
      if (data[j] < data[j-1]) {
	temp = data[j];
	data[j] = data[j-1];
	data[j-1] = temp;
	count++;
      }
    }
  }
  
  for (i = 0; i < n; i++) {
    printf("%d", data[i]);
    if (i == n-1) printf("\n");
    else printf(" ");
  }

  printf("%d\n", count);

  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    int a;
    map<long, int> A;
    for(int i = 0; i < n; i++){
        cin >> a;
        A[a]++;
    }
    long w=0,h=0;
    for(map<long, int> :: reverse_iterator it = A.rbegin(), e = A.rend(); it != e; ++it){

        if(it->second >= 4){
            if(w != 0) {h = it->first;}
            else{w = h = it->first;}
            break;
        }else if(it->second >= 2){
            if(w == 0) w = it->first;
            else{h = it->first; break;}
        }
    }

    cout << w * h <<endl;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;

int n, c, k, o, per, bus;
int a[N];

int main() {
    scanf("%d%d%d", &n, &c, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a + 1, a + n + 1);
    o = 1, per = a[1], bus = 1;
    for(int i = 2; i <= n; i++) {
        if(o < c && a[i] <= per + k) o++;
        else {
            bus++;
            per = a[i];
            o = 1;
        }
    }
    printf("%d\n", bus);
}

Measured memory_bytes: 4092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e13;

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

    vector<pair<ll, ll>> spell(n);
    for (int i = 0; i < n; i++)
        cin >> spell[i].first >> spell[i].second;

    vector<ll> damage(h+50, 0);
    for (int i = 1; i <= h; i++) {
        ll cost = INF;
        for (auto p : spell)
            if (p.first >= i && p.second < cost)
                cost = p.second;

        for (int j = 1; j < i; j++)
            cost = min(cost, damage[j] + damage[i-j]);

        damage[i] = cost;
    }

    cout << damage[h] << endl;
}

Measured memory_bytes: 3724
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True


def main():
    A, B = MI()
    ans = 0

    for i in range(A, B+1):
        s = str(i)
        if s == s[::-1]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 66536
#include <stdio.h> 
int main(void) { 
int w,h,x,y,r,f;
scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
f=0;
if(x+r>w)f=1;
if(y+r>h)f=1;
if(r>x)f=1;
if(r>y)f=1;
if(f==0)printf("Yes\n");
else printf("No\n");
return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int length, no_of_moves;
    string S;
    cin >>  length >> no_of_moves >> S;

    int current_length = 0;
    vector <int> segment_lengths;
    for(int i = 0; i < length; i++)
    {
        if(i == 0 || S[i] == S[i - 1])
        {
            current_length++;
        }
        else
        {
            segment_lengths.push_back(current_length);

            current_length = 1;
        }
    }

    segment_lengths.push_back(current_length);

    vector <int> happiness_till(segment_lengths.size(), 0);
    happiness_till[0] = segment_lengths[0] - 1;
    for(int i = 1; i < segment_lengths.size(); i++)
        happiness_till[i] = happiness_till[i - 1] + segment_lengths[i] - 1;

    vector <int> happiness_from(segment_lengths.size(), 0);
    happiness_from[segment_lengths.size() - 1] = segment_lengths[segment_lengths.size() - 1] - 1;
    for(int i = segment_lengths.size() - 2; i > 0; i--)
        happiness_from[i] = happiness_from[i + 1] + segment_lengths[i] - 1;

    int segment_length = 2*no_of_moves + 1;
    int sum_here = 0, best_sum = 0, remaining_sum = 0;

    for(int i = 0; i < segment_lengths.size(); i++)
    {
        if(i < segment_length)
        {
            sum_here += segment_lengths[i];
        }
        else
        {
            sum_here += segment_lengths[i] - segment_lengths[i - segment_length];
        }

        remaining_sum = 0;

        if(i - segment_length - 1 >= 0)
            remaining_sum += happiness_till[i - segment_length - 1];

        if(i + 1 < segment_lengths.size())
                remaining_sum += happiness_from[i + 1];

        best_sum = max(best_sum, sum_here - 1 + remaining_sum);
    }

    cout << best_sum;
    return 0;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

struct UnionFind{
    vector<ll> par;
    UnionFind(ll n) : par(n, -1){}
    

    int root(int x){
        if(par[x]<0) return x;
        return par[x] = root(par[x]);
    }

    bool same(int a, int b){
        return root(a)==root(b);
    }
    void unite(int a, int b){
        int x=root(a), y=root(b);
        if(same(x, y)) return;
        if(y<x) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
    int size(int x){
        return -par[root(x)];
    }

};


int main(){
    int n;  cin >> n;
    typedef pair<ll, ll> P;
    typedef pair<ll, P> Edge;
    
    vector<P> x(n), y(n);
    REP(i, n){
        ll a, b;    cin >> a >> b;
        x[i] = {a, i};
        y[i] = {b, i};
    }
  
    vector<Edge> edge;
    vector<P> ids = x;
    sort(ALL(ids));
    REP(i, ids.size()-1){
        ll from=ids[i].second, to=ids[i+1].second;
        edge.push_back(Edge(x[to].first-x[from].first, make_pair(from, to)));
    }
    ids = y;
    sort(ALL(ids));
    REP(i, ids.size()-1){
        ll from=ids[i].second, to=ids[i+1].second;
        edge.push_back(Edge(y[to].first-y[from].first, make_pair(from, to)));
    }
    sort(ALL(edge));
    UnionFind tree = UnionFind(n);
    ll res=0;
    for(auto e: edge){
        ll from=e.second.first, to=e.second.second;
        if(!tree.same(from, to)){
            res += e.first;
            tree.unite(from, to);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 13168
#include <iostream>

using namespace std;

int main () {
    int n,m;
    cin >> n >> m;
    const int maxn = 100005;
    bool a[maxn];
    for(int i = 0;i < maxn;i++) a[i] = false;
    for(int i = 0,z;i < m;i++) cin >> z, a[z] = true;
    int dp[n + 1];
    for(int i = 0;i <= n;i++) dp[i] = 0;
    dp[0] = 1, dp[1] = 1;
    for(int i = 2;i <= n;i++){
        if(a[i - 1]){
            dp[i] += dp[i - 2];
        }
        if(a[i - 2]){
            dp[i] += dp[i - 1];
        }
        if(!a[i - 1] && !a[i - 2]){
            dp[i] += dp[i - 1] + dp[i - 2];
        }
        if(a[i - 1] && a[i - 2]){
            cout << 0;
            return 0;
        }
        dp[i] %= 1000000007;
    }
    cout << dp[n];
}

Measured memory_bytes: 768
import Control.Monad
import Data.List

cnt (_:ss) = length $ filter (== 'E') ss

sel ln [s] = [ln]
sel ln (s1:s2:ss) =
    let ln' = if s1 == 'W' then ln+1 else ln
        ln'' = if s2 == 'E' then ln'-1 else ln'
    in ln : (sel ln'' (s2:ss))

main = do
    n <- readLn :: IO Int
    s <- getLine
    let ln = cnt s
    print $ minimum $ sel ln s
 

Measured memory_bytes: 22908
#include <bits/stdc++.h>
#define Mod 1000000007
#define INF 9999999999
#define INFL 99999999999
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define N 100005
#define fs first
#define sc second 
using namespace std;
typedef  long long int ll;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
typedef vector <ll> vi;

int gcd(int a, int b)
{
    // Everything divides 0 
    if (a == 0 || b == 0)
       return 0;
 
    // base case
    if (a == b)
        return a;
 
    // a is greater
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}

int main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
ios::sync_with_stdio(false);
 cin.tie(0);
ll s,t;
cin>>s>>t;
if(t>s)
    cout<<0<<endl;
else
    cout<<s-t<<endl;



return 0;

}


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

int dp[100005];

int main() {
    int n; cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        dp[i]=0;
    }
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++) dp[i]=min(abs(a[i-1]-a[i]) + dp[i-1], abs(a[i-2]-a[i]) + dp[i-2]);
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 4328
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

bool check(const vector<int> &v, int hf)
{
    // 0 dp初期値
    // 要素数分(1 indexed)
    // 要素を -1 で初期化
    vector<int> dp(hf + 1, -1);

    dp[0] = 0;

    for (int i = 0; i < (signed)v.size(); i++)
    {
        for (int j = 0; j <= hf; j++)
        {
            // 最大で「1」 「0」→「1」 「1」→「1」
            if (0 <= dp[j]) dp[j] = 1;
            // 組合せで構築できない「-1」
            else if (j < v[i] || dp[j - v[i]] <= 0) dp[j] = -1;
            // 組合せで構築できる「0」
            else dp[j] = 0;
        }
    }

    return 0 <= dp[hf];
}

int main()
{
    const char *Yes = "Yes";
    const char *No = "No";

    char c;
    int cnt = 0, xy = 0;

    // 要素数 2 (x と y)
    vector<int> ar[2];

    while (c = getchar_unlocked(), c == 'T' || c == 'F')
    {
        if (c == 'F')
        {
            cnt++;
        }
        else
        {
            ar[xy].push_back(cnt);
            cnt = 0;
            xy ^= 1;    // ビット排他的論理和 反転(0 ⇔ 1)
        }
    }

    int x, y;
    if (scanf("%d%d", &x, &y) < 2) return 0;

    // 最後が T でない場合の考慮
    ar[xy].push_back(cnt);

    // x の先頭を参照
    // 最初だけ 右確定 目標地点を左にずらす
    x -= ar[0][0];

    // x の先頭を削除
    ar[0].erase(ar[0].begin());

    // 正負を意識する必要はない
    // 先に左にずらしている為
    x = abs(x);
    // y は 0 始点の為
    y = abs(y);

    // x 合計
    int xs = accumulate(ar[0].begin(), ar[0].end(), 0);
    // y 合計
    int ys = accumulate(ar[1].begin(), ar[1].end(), 0);

    // 不足
    if (xs < x || ys < y) return !printf("%s\n", No);

    // 全力 Just
    if (xs == x && ys == y) return !printf("%s\n", Yes);

    // 奇数 行って帰れず
    if ((xs - x) % 2 || (ys - y) % 2) return !printf("%s\n", No);

    // 行き過ぎ 確定
    // ソート 昇順
    sort(ar[0].begin(), ar[0].end());   // x
    sort(ar[1].begin(), ar[1].end());   // y

    if (check(ar[0], (xs - x) / 2) && check(ar[1], (ys - y) / 2))
    {
        // 行き過ぎた距離の半分を
        // 組合せで構築できる
        return !printf("%s\n", Yes);
    }
    else
    {
        // 行き過ぎた距離の半分を
        // 組合せで構築できない
        return !printf("%s\n", No);
    }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: i64 = read();
    let k: i64 = read();
    let a: Vec<i64> = (0..n).map(|_| read()).collect();
    let mut cnt: Vec<i64> = vec![0; 50];
    for i in 0..n as usize {
        let mut po: i64 = a[i];
        let mut j = 0;
        while po > 0 {
            cnt[j] += po % 2;
            po /= 2;
            j += 1;
        }
    }
    let mut nya: i64 = 0;
    for i in (0..50).rev() {
        if cnt[i] < n - cnt[i] && nya + (1 << i) <= k {
            nya += 1 << i;
        }
    }
    let mut ans: i64 = 0;
    for i in 0..n as usize {
        ans += nya ^ a[i];
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main(void) {
    int M1, D1, M2, D2;
    cin >> M1 >> D1 >> M2 >> D2;
    if(M1 != M2) {
        cout << 1 << endl;
    } else {
        cout <<0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
while True:
    p, n1, n5, n10, n50, n100, n500 = map(int, input().split())
    if p == 0:break
    values = (500, 100, 50, 10, 5, 1)
    values_cnt = (n500, n100, n50, n10, n5, n1)
    INF = 10 ** 20


    def return_cnt(x):
        ret = 0
        for value in values:
            ret += x // value
            x %= value
        return ret


    def make_price(x):
        ret = 0
        for value, cnt in zip(values, values_cnt):
            available_cnt = x // value
            ret += min(available_cnt, cnt)
            x -= value * min(available_cnt, cnt)
        if x == 0:return ret
        return INF


    print(min([make_price(i) + return_cnt(i - p) for i in range(p, p + 500)]))




Measured memory_bytes: 5608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CModuloSummation solver = new CModuloSummation();
        solver.solve(1, in, out);
        out.close();
    }

    static class CModuloSummation {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);

            long sum = 0;
            for (int i = 0; i < n; i++) {
                sum += a[i] - 1;
            }

            out.println(sum);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

    }
}



Measured memory_bytes: 21716
#include<iostream>
#include<vector>
#include<climits>
using namespace std;

int main(){
	int n;
	int max = 0;
	int min;
	int min_diff;
	cin >> n;
	vector<int> v(n);
	for(int i=0; i<n; i++){
		cin >> v[i];
		if(v[i] > max) max = v[i];
	}
	min_diff = INT_MAX;
	for(int i=0; i<n; i++){
		if(abs(v[i] * 2 - max) < min_diff && v[i] != max) {
			min_diff = abs(v[i] * 2 - max);
			min = v[i];
		}
	}
	cout << max << ' ' << min;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    ll N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    rep(i,0,N){
        ll x = C * (N - 1 - i) - D * i;
        ll y = -C * i + (N - 1 - i) * D;
        if(B - A >= x && B - A <= y){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function euc(a,m)
	b = m
	x = 1
	u = 0
	while b>0
		q = div(a,b)
		tmp = u
		u = x-q*u
		x = tmp
		tmp = b
		b = a-q*b
		a = tmp
	end
	x<0?x+abs(m):x
end

function main()
	p = 10^9+7
	n,a,b = readline() |> split |> parseMap
	bx = 1
	r = 0
	while 2^r<=n
		r += 1
	end
	bx = ones(Int,r)
	bx[1] = 2
	for i in 2:r
		bx[i] = (bx[i-1]*bx[i-1])%p
	end
	all = 1
	tn = n
	ct = Dict{Int,Int}()
	for i in 0:r
		ct[2^i] = i+1
	end
	while tn>0
		x = tn&(-tn)
		all = (all*bx[ct[x]])%p
		tn -= x
	end
	ax = n
	for i in 2:a
		ax = ((ax*euc(i,p))%p*(n-i+1))%p
	end
	bx = n
	for i in 2:b
		bx = ((bx*euc(i,p))%p*(n-i+1))%p
	end
	println(mod(all-ax-bx-1,p))
end

main()

Measured memory_bytes: 170652
a=int(input())
b=list(map(int,input().split()))
c=-1
for i in range(a-1):
  if b[i]>b[i+1]:
    if c==-1:
      c=i
    else:
      b[c],b[i+1]=b[i+1],b[c]
      break
      
for i in range(a-1):
  if b[i]>b[i+1]:
    print("NO")
    exit()
    
print("YES")
  

Measured memory_bytes: 3060
#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

constexpr int MAX_N = 20000;

int N;
int p[MAX_N];
int a[MAX_N], b[MAX_N];

int main()
{
  scanf( "%d", &N );
  rep( i, N )
    scanf( "%d", p+i );

  rep( i, N )
    a[i] = (i+1)*N, b[i] = (N-i)*N;

  repi( i, 1, N )
    a[p[i]-1] += i;

  rep( i, N )
    printf( "%d%c", a[i], i==N-1?'\n':' ' );
  rep( i, N )
    printf( "%d%c", b[i], i==N-1?'\n':' ' );

  return 0;
}

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

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N;
string temps;
vpi blocks;
ll ans;

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	cin >> temps; N = SZ(temps);
	FOR(i, 0, N)
	{
		int x = (temps[i] == '>' ? -1 : 1);
		if (blocks.empty() || blocks.back().fi != x)
		{
			blocks.PB({x, 1});
		}
		else
		{
			blocks.back().se++;
		}
	}
	if (blocks.back().fi == 1)
	{
		blocks.back().se++;
	}
	//every block of 1's obviously starts from 0
	int x = 0;
	for (pii p : blocks)
	{
		// cerr << p.fi << ',' << p.se << endl;
		if (p.fi == 1)
		{
			//it starts from 0 duh 0...p.se - 1
			ans += 1ll * (p.se - 1) * (p.se) / 2;
			x = p.se;
		}
		else
		{
			//it decreases from p.se, or maybe
			if (x > p.se)
			{
				ans += (x - p.se);
			}
			ans += 1ll * (p.se) * (p.se + 1) / 2;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3352
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int ans;
	if(c>b){
		ans=b*2;
		c-=b;
	}	
	else{
		ans=b+c;
		c=0;
	}
	while(a>0&&c>0){
		ans++;
		a--;c--;
	}
	if(c)
		ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int q; cin >> q;
  while (q--) {
    int h, w; cin >> h >> w;
    V<string> s(h);
    for (auto&& e : s) cin >> e;
    V<> idx;
    for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
      if (s[i][j] != '.') {
        idx.push_back(s[i][j] - 'A');
      }
    }
    sort(begin(idx), end(idx));
    idx.erase(unique(begin(idx), end(idx)), end(idx));
    int n = idx.size();
    V<> il(26, h), ir(26, -1), jl(26, w), jr(26, -1);
    for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) if (s[i][j] != '.') {
      int x = s[i][j] - 'A';
      il[x] = min(il[x], i);
      ir[x] = max(ir[x], i);
      jl[x] = min(jl[x], j);
      jr[x] = max(jr[x], j);
    }
    bool safe = [&] {
      do {
        V<string> t(h, string(w, '.'));
        for (int k = 0; k < n; ++k) {
          for (int i = il[idx[k]]; i <= ir[idx[k]]; ++i) for (int j = jl[idx[k]]; j <= jr[idx[k]]; ++j) {
            t[i][j] = 'A' + idx[k];
          }
        }
        if (s == t) return true;
      } while (next_permutation(begin(idx), end(idx)));
      return false;
    }();
    cout << (safe ? "SAFE\n" : "SUSPICIOUS\n");
  }
}


Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  ll p26 = 26;
  ll len = 1;
  while(n > p26) {
    n-=p26;
    p26*=26;
    len++;
  }
  n--;
  deque<char> ANS;
  for(ll i=0; i<len; i++) {
    char ch = static_cast<char>('a'+(n%26));
    ANS.push_front(ch);
    n/=26;
  }
  for(auto& c : ANS) {
    cout << c;
  }
  cout << endl;
}


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

using namespace std;

int n,a[105];

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

int main(int argc, char *argv[]) {
	while(cin>>n) {
		for(int i=1;i<=n;i++)
			cin>>a[i];
		sort(a+1,a+n+1,compare);
		
		int sumA=0,sumB=0; 
		for(int i=1;i<=n;i++) {
			//cout<<a[i]<<endl;
			if(i%2) 
				sumA+=a[i];
			else 
				sumB+=a[i];	
		}
		cout<<sumA-sumB<<endl; 
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  if(a<0){
    if(b>=0){
      puts("Zero");
    }
    else {
      if((b-a)%2){
        puts("Positive");
      }
      else {
        puts("Negative");
      }
    }
  }
  else{
    puts("Positive");
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define eps 0.0000001
using namespace std;
struct po{int x,y,z,r; long long l;};
struct popo{int x,y,z;};

double mk_dis(popo a,popo b){
  return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}

int main(){
  int n,q;
  cin >>n>>q;
  po ball[51];
  for(int i=0;i<n;i++)cin>>ball[i].x>>ball[i].y>>ball[i].z>>ball[i].r>>ball[i].l;
  
  for(int i=0;i<q;i++){
    int a1,a2,b1,b2,c1,c2;
    double dis[3];
    cin >>a1>>b1>>c1>>a2>>b2>>c2;
    dis[0] = mk_dis((popo){a1,b1,c1},(popo){a2,b2,c2});
    long long ans=0;
    for(int j=0;j<n;j++){
      dis[1] = mk_dis((popo){a1,b1,c1},(popo){ball[j].x,ball[j].y,ball[j].z});
      dis[2] = mk_dis((popo){a2,b2,c2},(popo){ball[j].x,ball[j].y,ball[j].z});
      double s = (dis[0]+dis[1]+dis[2])/2.0;
      double S = sqrt(s*(s-dis[0])*(s-dis[1])*(s-dis[2]));
      double h = 2*S/dis[0];
      if(fabs(sqrt(dis[1]*dis[1]-h*h)+sqrt(dis[2]*dis[2]-h*h)-dis[0])>eps)continue;
      if(h-ball[j].r<=eps) ans+=ball[j].l;
    }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1172
#include <iostream>
using namespace std;
int n,m,cnt,ans,head[1100000],h[1100000];
struct road
{
    int to;
    int next;
}road[1100000];
void add(int u,int v)
{
    ++cnt;
    road[cnt].to=v;
    road[cnt].next=head[u];
    head[u]=cnt;
}
int check(int t)
{
    for(int i=head[t];i;i=road[i].next)
    {
        if(h[t]<=h[road[i].to])return 0;
    }
    return 1;
}
int main(void)
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>h[i];
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        add(u,v);
        add(v,u);
    }
    for(int i=1;i<=n;i++)
    {
        if(check(i))
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5496
import sys
input = sys.stdin.readline
import numpy as np

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = tuple(tuple(MI()) for i in range(n-1))

def main(j):
    time = 0
    for i in range(j,n-1):
        c, s, f = mylist[i]
        if time < s:
            time = s
        if (time - s) % f != 0:
            time += (f - (time - s) % f) #待ち時間を足す
        time += c
    print(time)
    
    
for i in range(n-1):
    main(i)
print(0)

Measured memory_bytes: 12496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (ll i = (ll)(start); i < (ll)(n); ++i)
static const ll INFTY = 1L << 62L;
void solver(ll *a, ll n)
{
    bool ispair = true;
    set<ll> s;
    rep(i, 0, n)
    {
        rep(j, 1, sqrt(a[i]) + 1)
        {
            if (a[i] % j == 0)
            {
                if (j != 1 && s.count(j))
                {
                    ispair = false;
                    break;
                }
                if (a[i] / j != 1 && s.count(a[i] / j))
                {
                    ispair = false;
                    break;
                }
                if (j != 1)
                    s.insert(j);
                if (a[i] / j != 1)
                    s.insert(a[i] / j);
            }
        }
        if (!ispair)
            break;
    }
    if (ispair)
    {
        cout << "pairwise coprime\n";
        return;
    }
    ll ans = a[0];
    rep(i, 1, n)
    {
        ans = gcd(ans, a[i]);
    }
    if (ans == 1)
    {
        cout << "setwise coprime\n";
        return;
    }
    cout << "not coprime\n";
    return;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll a[n];
    rep(i, 0, n) cin >> a[i];
    solver(a, n);
}

Measured memory_bytes: 11420
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long int lld;
#define sq(x) (x*x)
#define fr(i,m,n) for(i=m;i<n;i++)
#define vec vector<int>
#define sint set<int>
#define qint queue<int>
#define mip map<int,int>
#define pint priority_queue<int>
#define pb push_back
#define pp pop_back()
#define ft first
#define sd second
#define all(v) v.begin(),v.end()
#define mom(ara,n) memset(ara,0,sizeof(int)*(n));
#define m1m(ara,n) memset(ara,-1,sizeof(int)*(n));
int main()
{
    lld i,j,k,a,b,c,x,y,z,n,m,t;
    cin>>n;z=1;int ans=1;
    while(n--){
        cin>>x;
        if(x==0) ans=0;
        if(ans && 1000000000000000000/x<z) ans=-1;
        if(ans==1) z*=x;
    }
    if(ans==1) cout<<z<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 3600
s = int(input())

xx__ = s//100
__xx = s%100

if xx__ > 0 and xx__ < 13:
    if __xx > 0 and __xx < 13:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if __xx > 0 and __xx < 13:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    ll A, B; cin >> A >> B;
    ll ans = A * B / __gcd(A, B);
    cout << ans << endl;
}

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

using namespace std;

int main(){
	int n,x,m,sum;
	m=0;
	sum=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		sum+=x;
		m=max(m,x);
	}
	if(2*m<sum) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<pair<ll,ll> > up;
  ll now = 1;
  while(now<=k){
    ll buf = 0;
    for(d:a) if((d^now)>d) buf++;
    up.push_back(make_pair((2*buf-n)*now,now));
    now *= 2; 
  }
  sort(all(up));
  reverse(all(up));
  ll X = 0;
  for(p:up){
    //cout<<p.first<<"  "<<p.second<<endl;
    if(p.first <= 0) continue;
    if(p.second + X > k) continue;
    X += p.second;
  }
  ll ans = 0;
  for(d:a) ans += d^X;
  //cout << X << endl;
  cout<<ans<<endl;
}



Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int n;
  int age=0;
  int num[110];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>num[i];
    age+=num[i];
  }
  int ans,x=1000000;
  for(int j=0;j<n;j++){
    int s;
    s=abs(age-num[j]*n);
    if(s<x){
      x=s;
      ans=j;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>;

using namespace std;

int path[60];

int main() {
	int N, M; cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int ipta, iptb; cin >> ipta >> iptb;
		path[ipta]++; path[iptb]++;
	}
	for (int i = 1; i <= N; i++) {
		cout << path[i] << endl;
	}



	return 0;
}

Measured memory_bytes: 256