akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long a, bb, b;
  cin >> a;
  b = 1;
  int count = 0;
  for (int i = 0; i < a; i++) {
    cin >> bb;
    b *= bb;
    while (b % 2 == 0) {
      b /= 2;
      count ++;
    }
  }
  cout << count << endl;
}

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


	int main() {
		int N, A[100];
		cin >> N;
		int a = 0;
		for (int i = 0; i < N; i++) {
			cin >> A[i];
		}
		int flag = 1;
		while (flag == 1) {
			flag = 0;
			for (int j = N - 1; j >= 1; j--) {
				if (A[j - 1] > A[j]) {
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					flag = 1;
					a++;
				}
			}
		}
		for (int i = 0; i < N - 1; i++) {
			cout << A[i] << ' ';
		}
		cout << A[N-1] << endl;

		cout << a << endl;

		return 0;
	}



Measured memory_bytes: 3116
<?php

$n = (int)fgets(STDIN);
while (--$n >= 0) {
  $set = explode(' ', trim(fgets(STDIN)));
  $cards[$set[0]][(int)$set[1]] = 1;
}
foreach(array('S','H','C','D') as $val) {
  for ($i = 1; $i <= 13; $i++) {
    if (!isset($cards[$val][$i])) echo "$val $i",PHP_EOL;
  }
}

Measured memory_bytes: 15188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

int sum(int n)
{
    if(n == 0){
        return 0;
    }
    return sum(n - 1) + n;
}

int main() {
    //cout.precision(10);
    int a, b;
    cin >> a >> b;
    cout << sum(b - a) - b << endl;
    return 0;

    return 0;
}

Measured memory_bytes: 256
/**
 *
 * AtCoder Regular Contest 058 - Problem E: Iroha's Obsession
 *
 * Count sequences a1, a1, ..., aN with 1 <= ai <= 10 that we can find indexes r and s such as
 *
 * ar + ... + at-1 = X
 * at + ... + au-1 = Y
 * au + ... + as   = Z
 *
 * DP solution: its better count sequences that note contains such indexes. Represent all 
 * integers x as strings "10..0", with (x - 1) zeroes. A solution can be represented concatenating
 * these strings. Ex.:
 *
 * X = 7, 1 + 3 + 1 + 2 => s = 1100110
 *
 * Notice that s.size() = X.
 *
 * Using a bit mask to represent the concatenation of the previous numbers with sum < MAX (in 
 * this problem, MAX = 5 + 7 + 5 = 17), we have the state
 *
 * st(N, mask) = number of sequences that not contains such indexes with previous numbers in mask
 *
 * We have a solution if the bits corresponding to the beginning of X, Y a Z are on (1 mark the
 * start of a number). So the recurrence is:
 *
 * st(0, 0) = 1
 * st(N, mask) = 0,                              if mask contains a solution
 * st(N, mask) = st(N - 1, mask - {1}) 
 *       + st(N - 1, mask - {2}) + ... 
 *       + st(N - 1, mask - {10}),               otherwise
 */
#include <iostream>

using namespace std;
using ll = long long;

const ll MOD { 1000000007 };
const int MAXN { 41 };
const int MAXS { 17 };      // S = X + Y + Z

ll st[MAXN][1 << (MAXS - 1)];

ll fast_exp(ll a, ll n)
{
    ll res = 1, base = a;

    while (n)
    {
        if (n & 1)
        {
            res *= base;
            res %= MOD;
        }

        base *= base;
        base %= MOD;

        n >>= 1;
    }

    return res;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, X, Y, Z;
    cin >> N >> X >> Y >> Z;

    int S = X + Y + Z;
    int zbit = (1 << (Z - 1));
    int ybit = (1 << (Y - 1)) << Z;
    int xbit = (1 << (X - 1)) << (Y + Z);

    int all_bits = (1 << (S - 1)) - 1;
    int solution = xbit | ybit | zbit;

    // Bottom-up DP solution
    st[0][0] = 1;

    for (int n = 1; n <= N; n++)
    {
        // pmask is the mask of the previous state (its easier adding than remove a number from the mask
        for (int pmask = 0; pmask < (1 << (S - 1)); pmask++) {
            for (int d = 1; d <= 10; d++) {
                // concat d to the end of pmask
                int mask = (pmask << d) | (1 << (d - 1)); 

                // mask contains a solution
                if ((mask & solution) == solution)
                    continue;

                // Update the state: we can discard the overflowing left bits (mask & all_bits)
                // because they are not part of a solution
                st[n][mask & all_bits] += st[n - 1][pmask];
                st[n][mask & all_bits] %= MOD;
            }
        }
    }

    // All sequences
    ll sequences = fast_exp(10, N);

    // Now we remove the sequences that no contains a XYZ-Haiky
    for (int mask = 0; mask < (1 << (S - 1)); mask++)
    {
        sequences -= st[N][mask];
        sequences = (sequences + MOD) % MOD;
    }

    cout << sequences << endl;
}



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

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

    int n;
    cin>>n;
    for(int i = 1;i<= 9; i++){
        for(int j = 1; j <= 9; j++){
            if(i*j == n){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main(){
    int b,f,r,v,n;
    cin>>n;
    int lst[4][3][10];
    for(int b=0;b<4;b++){
        for(int c=0;c<3;c++){
            for(int d=0;d<10;d++){
                lst[b][c][d]=0;
            }
        }
    }
    for(int a=0;a<n;a++){
        cin>>b>>f>>r>>v;
        lst[b-1][f-1][r-1]=lst[b-1][f-1][r-1]+v;
    }
    for(int e=0;e<3;e++){
        for(int f=0;f<10;f++){
            cout<<" "<<lst[0][e][f];
        }cout<<endl;
    }cout<<"####################"<<endl;
    for(int e=0;e<3;e++){
        for(int f=0;f<10;f++){
            cout<<" "<<lst[1][e][f];
        }cout<<endl;
    }cout<<"####################"<<endl;
    for(int e=0;e<3;e++){
        for(int f=0;f<10;f++){
            cout<<" "<<lst[2][e][f];
        }cout<<endl;
    }cout<<"####################"<<endl;
    for(int e=0;e<3;e++){
        for(int f=0;f<10;f++){
            cout<<" "<<lst[3][e][f];
        }cout<<endl;
    }
}


Measured memory_bytes: 3080
from collections import defaultdict

def main():
    n, k, q = map(int, input().split(" "))
    a = (int(input()) for i in range(q))
    d = defaultdict(lambda:k-q)
    for i in range(n):
        d[i]

    for i in a:
        d[i-1] += 1

    for value in d.values():
        print("Yes" if value > 0 else "No")


main()

Measured memory_bytes: 22364
n, l = map(int, input().split())

lis = []

for i in range(1,n+1):
    lis.append(l+i-1)

lis = sorted(lis)


if 0 in lis:
    lis.remove(0)
elif lis[0] >= 0:
    lis.remove(min(lis))
else:
    lis.remove(max(lis))
    
print(sum(lis))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const long long  mod = 1e9+7;
long long n;
map<long long ,long long>dp;
long long Dp(long long x){return dp[x]?dp[x]:dp[x]=((Dp(x/2)+Dp((x-1)/2)+Dp((x-2)/2)) )%mod;}
int main()
{
    dp[0] = 1;
    dp[1] = 2;
    scanf("%lld",&n);
    printf("%lld",Dp(n));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define CIN(n) int n; cin>>(n);
int main()
{
	unsigned long long int n;
	unsigned long long int m;
	cin >> n;
	m = n;
	int k = 0;
	for (int i = 9; i > 0; i--) {
		int t = 1;
			for(int p = 0; p < i; p++) {
				t = t * 10;
			}
			int f;
				f= n / t;
		k += f;
		n = n - f * t;
	}
	k += n; 
	unsigned long long int r;

	r = m% k;
	if (r == 0)cout << "Yes"; else cout << "No";
		 
}

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

int main(){
 int N,L;
  cin>>N>>L;
 vector<string>S(N);
  for(int i=0; i<N; i++){
   cin>>S[i]; }
  
  sort(S.begin(), S.end()); //Sの全配列を対象にsort

  for(int i=0; i<N; i++){
   cout<<S[i]; }
  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n, 0);

	rep(i, k) {
		int d;
		cin >> d;
		for(int i = 0; i < d; i++) {
			int b;
			cin >> b;
			b--;
			a[b]++;
		}
	}
	int ans = 0;
	rep(i, n) {
		if (a[i] == 0) ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int H, W, K; cin >> H >> W >> K;
  vector<string> S(H); rep(i,H) cin >> S[i];
  int allb = 0;
  rep(y,H) rep(x,W){
    if(S[y][x] == '#') allb++;
  }
  int ans = 0;
  rep(i,1<<H){
    rep(j,1<<W){
      int g = i;
      int r = j;
      vector<bool> gg;
      vector<bool> rr;
      rep(k,H){
        gg.pb(g&1);
        g >>= 1;
      }
      rep(k,W){
        rr.pb(r&1);
        r >>= 1;
      }
      int cnt = 0;
      rep(y,H){
        rep(x,W){
          if(gg[y] && rr[x] && S[y][x] == '#') cnt++;
        }
      }
      if(cnt==K) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cmath>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	double n,t,a,mi=100001,ans=1001;
	cin>>n>>t>>a;
	vector<pair<double,int>>v(n);
	for(int i=0;i<n;i++){
		cin>>v.at(i).first;
		v.at(i).second=i+1;
		if(mi>abs((t-v.at(i).first*0.006)-a)){
			mi=abs((t-v.at(i).first*0.006)-a);
			ans=v.at(i).second;
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:String,
    }
    let mut a=a.chars().collect_vec();
    if a[a.len()-1]=='s' {
        a.push('e');
        a.push('s')
    }
    else {a.push('s')}
    let a:String=a.iter().collect();
    println!("{}",a)
}

Measured memory_bytes: 2168
X,K,D = map(int,input().split())
ans = 0
if X == 0:
    if K % 2 == 0:
        ans = 0
    else:
        ans = D
if X > 0:
    if K*D <= X:
        ans = X - K*D
    else:
        n = X // D
        if X % D != 0:
            n += 1
        if (K - n) % 2 == 0:
            ans = abs(X-D*n)
        else:
            ans = abs(X-D*(n-1))
if X < 0:
    if K*D + X <= 0:
        ans = abs(K*D+X)
    else:
        n = -X // D
        if -X % D != 0:
            n += 1
        if (K-n) % 2 == 0:
            ans = abs(X+n*D)
        else:
            ans = abs(X+(n-1)*D)

print(ans)

Measured memory_bytes: 9176
import sys
input = sys.stdin.readline
from collections import defaultdict

class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        p = x
        
        while not self.par[p]<0:
            p = self.par[p]
        
        while x!=p:
            tmp = x
            x = self.par[x]
            self.par[tmp] = p
        
        return p
    
    def unite(self, x, y):
        rx, ry = self.root(x), self.root(y)
        
        if rx==ry: return False
        
        if self.rank[rx]<self.rank[ry]:
            rx, ry = ry, rx
        
        self.par[rx] += self.par[ry]
        self.par[ry] = rx
    
        if self.rank[rx]==self.rank[ry]:
            self.rank[rx] += 1
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N, M = map(int, input().split())
a = list(map(int, input().split()))
uf = Unionfind(N)

for _ in range(M):
    x, y = map(int, input().split())
    uf.unite(x, y)

d = defaultdict(list)
rs = set()

for i in range(N):
    r = uf.root(i)
    rs.add(r)
    d[r].append(a[i])

if len(rs)==1:
    print(0)
    exit()

if 2*(len(rs)-1)>N:
    print('Impossible')
    exit()
    
ans = 0

for k in d.keys():
    d[k].sort()
    ans += d[k][0]

l = []

for v in d.values():
    l += v[1:]

l.sort()
ans += sum(l[:len(rs)-2])

print(ans)

Measured memory_bytes: 81592
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [10**10]*n
dp[0] = 0
for i in range(n):
    for j in range(k+1):
        if i - j >= 0:
            dp[i] = min(dp[i],dp[i-j] + abs(h[i] - h[i-j]))
print(dp[n-1])

Measured memory_bytes: 84792
#include<stdio.h>
#include<string.h>
#define LEN 100005
 
typedef struct pp{
  char name[100];
  int t;
}P;
 
P Q[LEN+1];
int h, t, n;
 
void enqueue(P x){
  Q[t] = x;
  if (t + 1 == LEN){
    t = 0;
  }
  else{
    t = t + 1;
  } 
}
 
P dequeue(){
  P tmp = Q[h];
  if (h + 1 == LEN){
    h = 0;
  }
  else{
    h = h + 1;
  }
  return tmp;
}
 
 
int main(){
  int elaps = 0, c;
  int i, q, total = 0;
  P u;
  scanf("%d %d", &n, &q); 
  for ( i = 1; i <= n; i++){   
    scanf("%s", u.name);
    scanf("%d", &u.t);
    enqueue(u);
  }
   
  while(n>0){
    u = dequeue();
    if (u.t <= q){
      elaps += u.t;
      printf("%s %d\n", u.name, elaps);
      n--;
    }   
    else if(u.t>q){
      u.t -= q;
      elaps += q;
      enqueue(u);
    }  
  }
  return 0;
}

Measured memory_bytes: 10756
#pragma warning(disable: 4996)
#define _USE_MATH_DEFINES
#include <iostream>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
using namespace std;

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

	string S;
	cin >> S;
	if (S == "SUN") cout << 7 << endl;
	if (S == "MON") cout << 6 << endl;
	if (S == "TUE") cout << 5 << endl;
	if (S == "WED") cout << 4 << endl;
	if (S == "THU") cout << 3 << endl;
	if (S == "FRI") cout << 2 << endl;
	if (S == "SAT") cout << 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    vector<int> x(5);
    rep(i, 5) cin >> x[i];
    rep(i, 5) {
        if (x[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3588
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int l = max(a,c);
  int r = min(b,d);
  cout<<max(r-l, 0);

	return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);
//ll dx[4] = {1,0,-1,0};
//ll dy[4] = {0,1,0,-1};

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;

int main() {
	ll a = 0, b = 0, c = 0, d = 0, ans = 0, ret = M, n, m;
	string s, t;
	t = "keyence";
	bool x = true;
	cin >> s;
	rep(j, s.size()) {
		//cout << s[j] << " " << t[i] << endl;
		if (s[j] == t[j]) a++;
		else break;
	}
	c = 6;
	repr(i, s.size()) {
		if (0 > c) break;
		if (s[i] == t[c]) b++,c--;
		else break;
	}
	// cout << t.size() << " " << i << endl;
	if(a+b >= 7 || a==7 || b==7)
		cout << "YES\n";
	else cout << "NO\n";
	exit:
	return 0;
}


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

int main() {

    int N ;

    cin >> N ;

    int count = 0;

    while(true){

        bool odd = false;

        for(int i=1 ; i < N+1 ; i++){
            if(i%2 ==0) odd=true ;
        }

        if(odd) {
            count++;
            N /= 2 ;
        }

        else break ;
 
    }

    int ans = 1;

    for(int i =0 ; i < count ; i++){

        ans *=2;
    }

    cout << ans << endl ;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int [] a=new int [n+1];
		int [] b=new int [n];
		for(int i=0;i<=n;i++)
		{
			a[i]=in.nextInt();

		}
		for(int i=0;i<n;i++)
		{			
			b[i]=in.nextInt();
		}
		long ans=0;
		if(a[n]>b[n-1])
		{
			ans=b[n-1];
			b[n-1]=0;
		}
		else
		{
			ans=a[n];
			b[n-1]=b[n-1]-a[n];
		}
		for(int i=n-1;i>0;i--)
		{
			if(a[i]-b[i]>0)
			{
				if(a[i]-b[i-1]-b[i]>0)
				{
					ans=ans+b[i]+b[i-1];
					b[i-1]=0;
				}
				else
				{
					ans=ans+a[i];
					b[i-1]=b[i-1]+b[i]-a[i];
				}
			}
			else
			{
				ans=ans+a[i];
			}
		}
		if(a[0]>b[0])
		{
			ans=ans+b[0];
		}
		else
		{
			ans+=a[0];
		}
		System.out.println(ans);
			
	}
}
	

Measured memory_bytes: 85424
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> vec;
    for(int i = 0; i < m; i++){
        int s;
        cin >> s;
        vec.push_back(s);
    }

    sort(vec.begin(),vec.end());

    int max, min, ct=0;
    while(true){
        min = n - ct;
        max = n + ct;
        if(auto itr = find(vec.begin(), vec.end(), min) == vec.end()){
            cout << min << endl;
            break;
        }
        if(auto itr = find(vec.begin(), vec.end(), max) == vec.end()){
            cout << max << endl;
            break;
        }
        ct++;
    }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a;
  cin >> n >> a;
  int k[n]={};
  for(int i=0;i<n;i++){
    cin >> k[i];
  }
  int sum=0;
  sort(k,k+n,greater<int>());
  for(int i=0;i<a;i++){
    sum+=k[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
// vector<int> vec(3); = vector<int> vec={0,0,0}
// vec.at()
// sort(num.begin(),num.end(), greater<int>());
// reverse(num.begin(),num.end());
 
// 切り上げ　a/b+1
//  1からNの総和　N*(N+1)/2
 
int main() {
  string S;
  cin >> S;
  
  S.at(5) = ' ';
  S.at(13) = ' ';
  
  cout << S << endl;

}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int a, b, x, r, cand1, cand2;

  std::cin >> a >> b >> x;

  if (a <= b) {
    // Aが爆安
    std::cout << x / 1000 * a + (x % 1000 == 0 ? 0 : a) << std::endl;
  } else if (b < a && a < 2 * b && 500 < x % 1000) {
    // 常識的かつAが安め
    r = x % 1000;
    std::cout << x / 1000 * a + (x % 1000 == 0 ? 0 : a) << std::endl;
  } else if (b < a && a < 2 * b) {
    // 常識的
    r = x % 1000;
    std::cout << x / 1000 * a + r / 500 * b + (x % 500 == 0 ? 0 : b) << std::endl;
  } else if (2 * b <= a) {
    // Bが爆安
    std::cout << x / 500 * b + (x % 500 == 0 ? 0 : b) << std::endl;
  }

  return 0;
}



Measured memory_bytes: 3104
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF = 1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

const ll M = 1000000007;

int main(){
	static ll n,l;
	static ll x[5002],a[5002];
	scanf("%lld%lld",&n,&l);
	rep(i,n){
		scanf("%lld",&x[i]);
	}
	rep(i,n){
		scanf("%lld",&a[i]);
	}
	
	static ll dp[2][5002] = {};
	int t = 0,t_ = 1;
	dp[t][l] = 1;
	rrep(i,n){
		rep(j,5002){
			dp[t_][j] = 0;
		}
		rrep(j,l){
			dp[t_][j] = dp[t_][j+1] + dp[t][j+1];
			dp[t_][j] %= M;
		}
		rep(j,5002){
			if(j < x[i] || j > l-1)dp[t_][j] = 0;
			else if(a[i] == 0){
				if(j != x[i])dp[t_][j] = 0;
			}
			else {
				if((j-x[i])%a[i] != 0)dp[t_][j] =0;
			}
		}
		swap(t,t_);
	}
	
	/*rep(i,n){
		rep(j,l){
			printf("%lld ",dp[i][j]);
		}puts("");
	}*/
	
	ll ret = 0;
	rep(i,5002){
		ret += dp[t][i];
	}
	cout << ret%M << endl;
}

Measured memory_bytes: 1352
#include<iostream>
int main()
{
	int v1, a, b, c;
	std::cin >> v1;
	a=v1/3600;
	b=v1%3600/60;
	c=v1%3600%60;
	std::cout << a << ":" << b << ":" << c << std::endl;
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>

using namespace std;

const int MOD = 1000000007;
const int MAX = 2100000;

long long fac[MAX], finv[MAX], inv[MAX], pow25[MAX], pow26[MAX];

void init() {
	fac[0] = fac[1] = inv[1] = finv[0] = finv[1] = pow25[0] = pow26[0] = 1;
	pow25[1] = 25; pow26[1] = 26;
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
		pow25[i] = pow25[i - 1] * 25 % MOD;
		pow26[i] = pow26[i - 1] * 26 % MOD;
	}
}

long long nCr(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

int main() {
	init();
	int k; cin >> k;
	string s; cin >> s;
	int n = s.size();
	long long ans = 0;
	for (int i = n - 1; i < n + k; ++i)
		(ans += nCr(i, n - 1) * (pow25[i - (n - 1)] * pow26[n + k - i - 1] % MOD) % MOD) %= MOD;
	cout << ans << endl;

	return 0;
}

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

int main(){
  string O, S;
  int a;
  cin>>O>>S;

  a = min(O.size(),S.size());
  for(int i = 0; i < a; i++){
    cout<<O[i]<<S[i];
  }//cout<<a<< O.size()<< S.size()<<endl;
  if(a < O.size())cout<<O[a];
  if(a < S.size())cout<<S[a];
cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
int T[100000];
int main() {
	int N, C, K;
	cin >> N >> C >> K;
	rep(i, N) {
		cin >> T[i];
	}
	sort(T, T + N);
	int pos = 0;
	int ans = 0;
	while (pos < N) {
		int cnt = 0;
		while (pos < N&&cnt < C&&T[pos] <= T[pos - cnt] + K) pos++, cnt++;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>	// 入出力
#include<stdio.h>	// printf()が使える小数は%fで
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか

using namespace std;

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

	int two[7] = { 64,32,16,8,4,2,1 };

	for (int i = 0; i < 7; ++i)
	{
		if (N / two[i] > 0)
		{
			cout << (N / two[i])*two[i] << endl;
			return 0;
		}
	}

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  bool answer = false;
  for(int i = 0; i <= 25; i++){
    if(answer){
      break;
    }
    for(int j = 0; j <= 15; j++){
      if(i * 4 + j * 7 == n){
        answer = true;
        break;
      }
    }
  }

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++){
			a[i] = scanner.nextInt();
		}
		int count = 0;
		for(int i=0;i<n;i++){
			if(a[i] == i+1){
				count++;
				i++;
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 51684
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n);

	for(int i = 0; i < n; i++){
		ll x;
		cin >> x;
		x -= i+1;
		a[i] = x;
	}
	sort(all(a));
	ll ans = 0;
	if(n%2 == 0){
		ll b = a[n/2], bb = a[n/2-1];
		ll res = 0;
		for(int i = 0; i < a.size(); i++){
			res += abs(a[i] - b);
		}
		ans = res;
		res = 0;
		for(int i = 0; i < a.size(); i++){
			res += abs(a[i] - bb);
		}
		ans = min(res,ans);
	}else{
		ll b = a[(n-1)/2];
		ll res = 0;
		for(int i = 0; i < a.size(); i++){
			res += abs(a[i] - b);
		}
		ans = res;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
'use strict'
function Main(input) {
    let Nums = input.trim().split('\n');
	let Info = Nums[0]*1;
  	let Row = Nums[1].split(' ').map(x=> x*1);
	// 配列をオブジェクトにするアルゴリズムを拝借
  	const obj = {};
    for(let i = 0, l = Row.length; i < l; i += 1) {
      obj[Row[i] - 1] = i;
    }
  	let ans = [];
  	// 並べ替えたものを配列にする
	for(let i = 0, l = Row.length; i < l; i += 1) {
      ans.push(obj[i]+1);
    }
  	console.log(ans.join(' '));
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 37220
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+999;

struct edge{
	int to,dis,nxt;
}e[maxn<<1];
int head[maxn],tot;
void add(int x,int y,int z){
	e[++tot].to=y;
	e[tot].dis=z;
	e[tot].nxt=head[x];
	head[x]=tot;
}
int n,w[maxn],rt,vis[maxn],mn,N,dist[maxn],siz[maxn];
void getrt(int x,int fa){
	siz[x]=1;int maxpart=0;
	for(int i=head[x];i;i=e[i].nxt){
		int y=e[i].to;
		if(y==fa||vis[y])continue;
		getrt(y,x);
		siz[x]+=siz[y];maxpart=max(maxpart,siz[y]);
	}
	maxpart=max(maxpart,N-siz[x]);
	if(maxpart<mn)mn=maxpart,rt=x;
}
int pos,mx;
struct EDGE{
	int x,y,dis;
	friend bool operator<(EDGE a,EDGE b){
		return a.dis<b.dis;
	}
}edg[maxn*20];
int cnt;
void dfs(int x,int fa,int dep){
	if(dep+w[x]<mx)mx=dep+w[x],pos=x;
	for(int i=head[x];i;i=e[i].nxt)
		if(!vis[e[i].to]&&e[i].to!=fa)
			dfs(e[i].to,x,dep+e[i].dis);
}
void Link(int x,int fa,int dep){
	edg[++cnt]=(EDGE){x,pos,mx+dep+w[x]};
	for(int i=head[x];i;i=e[i].nxt)
		if(!vis[e[i].to]&&e[i].to!=fa)
			Link(e[i].to,x,dep+e[i].dis);
}
void solve(int x){
	vis[x]=1;
	mx=1e18;pos=0;
	dfs(x,0,0);Link(x,0,0);
	for(int i=head[x];i;i=e[i].nxt){
		int y=e[i].to;
		if(vis[y])continue;
		mn=n+1,N=siz[y];
		getrt(y,x);
		solve(rt);
	}
}
int f[maxn];
int find(int x){
	return f[x]==x?f[x]:f[x]=find(f[x]);
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;++i)cin>>w[i],f[i]=i;
	for(int i=1;i<n;++i){
		int x,y,z;cin>>x>>y>>z;
		add(x,y,z);add(y,x,z);
	}
	mn=n+1,N=n;
	getrt(1,0);
	solve(rt);
	sort(edg+1,edg+1+cnt);
	int ans=0;
	for(int i=1;i<=cnt;++i){
		int x=find(edg[i].x),y=find(edg[i].y);
		if(x!=y)f[x]=y,ans+=edg[i].dis;
	}
	cout<<ans;
} 

Measured memory_bytes: 110336
#include<bits/stdc++.h>
using namespace std;
const int M=102;
const int MX=1e5+4;
const int MD=1e9+7;
int a[M],dp[M][MX],dp1[M][MX];
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	dp1[0][0]=1;
	for(int i=1;i<=n;i++) dp[i][0]=1;
	for(int j=1;j<=k;j++) dp1[0][j]=dp1[0][j-1]+dp[0][j];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(j-a[i]>0)
			dp[i][j]=(dp[i][j]+dp1[i-1][j]-dp1[i-1][j-a[i]-1]+MD)%MD;
			else
			dp[i][j]=(dp[i][j]+dp1[i-1][j])%MD;
		}
		dp1[i][0]=dp[i][0];
		for(int j=1;j<=k;j++)
		dp1[i][j]=(dp1[i][j-1]+dp[i][j])%MD;
	}
	cout<<dp[n][k];
	return 0;	
}

Measured memory_bytes: 79488
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████   
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬╬╬██╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<60
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef pair<int,int> P;
typedef vector<vector<P>> Graph;

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

  int n,l,t;
  cin >> n >> l >> t;

  vector<int> x(n),w(n);
  REP(i,n) cin >> x[i] >> w[i];
  
  vector<int> tmp(n);
  int in = 0;
  REP(i,n){
    tmp[i] = x[i];
    if(w[i] == 1) tmp[i] += t;
    else tmp[i] -= t;
    in += tmp[i]/l;
    if(tmp[i] < 0 && tmp[i] % l != 0) in--;
    tmp[i] = (tmp[i]%l+l)%l;
  }

  sort(tmp.begin(),tmp.end());

  in = (in%n+n)%n;

  //debug(in);

  REP(i,n) cout << tmp[(i+in)%n] << endl;

  return 0;
}

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

using namespace std;

int main(){
	//~ freopen("input.txt", "r", stdin);
	//~ freopen("output.txt", "w", stdout);
	int a, b;
	scanf("%d %d", &a, &b);
	for (int i = 0; i <= a; i++){
		int j = a - i;
		if (2 * i + 4 * j == b){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 3768
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

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

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()

	goods := map[string]int{}
	for i := 0; i < n; i++ {
		goods[next()]++
	}

	puts(len(goods))
}


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

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    Int t[2];
    Int a[2];
    Int b[2];
    cin >> t[0] >> t[1];
    cin >> a[0] >> a[1];
    cin >> b[0] >> b[1];
    Int s1 = (b[0] - a[0]) * t[0];
    Int s2 = (b[1] - a[1]) * t[1];
    if ((s1 > 0 and s2 > 0) or (s1 < 0 and s2 < 0)) {
        dump(0);
        return 0;
    }
    if (abs(s1) > abs(s2)) {
        dump(0);
        return 0;
    }
    if (abs(s1) == abs(s2)) {
        dump("infinity");
        return 0;
    }
    if (s1 < 0) {
        s1 = -s1;
        s2 = -s2;
    }
    Int res = 1 + s1 / abs(s1 + s2) * 2;
    if (s1 % abs(s1 + s2) == 0) {
        res--;
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define mp make_pair
int n,m,f[32],res;
vector<int>zero;
vector<pii>nz;
bool cmp(const pii &x,const pii &y){
	return y.first*x.second<x.first*y.second;
}
signed main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1,x,y;i<=n;i++){
		scanf("%lld%lld",&x,&y);
		y+=x+1;
		if(!x)zero.push_back(y);
		else nz.push_back(make_pair(x,y));
	}
	sort(nz.begin(),nz.end(),cmp);
	sort(zero.begin(),zero.end());
	memset(f,0x3f3f3f3f,sizeof(f)),f[0]=0;
	for(auto p:nz)for(int i=30;i>=0;i--)if(f[i]<=m)f[i+1]=min(f[i+1],f[i]*(p.first+1)+p.second);
	for(int i=0,r;i<32;i++){
		if(f[i]>m)continue;
		int k=i;
		for(auto j:zero)if(f[i]+j<=m)f[i]+=j,k++;else break;
		res=max(res,k);
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 6384
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int[] param = new int[n];
    
    for(int i=0 ; i<n ; i++){
      param[i] = sc.nextInt();
    }
    
    Arrays.sort(param);
    
    int alice = 0;
    int bob = 0;
    
    if(n%2==0){
      for(int i=0 ; i<n ; i++){
        if(i%2==0){
          bob += param[i];
        }else{
          alice += param[i];
        }
      }
    }else{
      for(int i=0 ; i<n ; i++){
        if(i%2==0){
          alice += param[i];
        }else{
          bob += param[i];
        }
      }
    }
    
    int total = alice - bob;
    System.out.println(total);
  }
}

Measured memory_bytes: 21716
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    H,W = inputMap()
    a = []
    for i in range(H):
        tmp = input()
        tmp = "#" + tmp + "#"
        a.append(tmp)
        
    tmp = ""
    for i in range(W+2):
        tmp += "#"
    
    print(tmp)
    for i in a:
        print(i)
    print(tmp)
    
    
class UnionFind(object):
	def __init__(self, n=1):
		self.par = [i for i in range(n)]
		self.rank = [0 for _ in range(n)]
		self.size = [1 for _ in range(n)]
		
	# x が属するグループを探索
	def find(self, x):
		if self.par[x] == x:
			return x
		else:
			self.par[x] = self.find(self.par[x])
			return self.par[x]
		
	# x と y のグループを結合
	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x != y:
			# メンバ数の更新
			sum = self.size[x] + self.size[y]
			self.size[x] = sum
			self.size[y] = sum
			# 短いリストを長いリストのルートに繋ぎ直す
			if self.rank[x] < self.rank[y]:
				x, y = y, x
			if self.rank[x] == self.rank[y]:
				self.rank[x] += 1
			self.par[y] = x
	
	# x と y が同じグループがどうか
	def is_same(self, x, y):
		return self.find(x) == self.find(y)
		
	# x が属するグループのメンバ数を返却
	def getSize(self, x):
		par_x = self.find(x)
		return self.size[par_x]
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38512
// Your day breaks, your mind aches
// You find that all the words of kindness linger on
// When she no longer needs you
//#pragma GCC optimize ("Ofast,unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
#define debug(x) cout << #x << " = " << x << endl
#define For(i,a,b) for (int i = a; i < b; i++)
#define roF(i,a,b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int N = 1e6;
const ll INF = 1e18;
const ld EPS = 10e-9;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll random(ll a, ll b) { return uniform_int_distribution<ll> (a, b) (rng); }

int main() {
	fastio;
	int n;
	cin >> n;
	int a[n];
	For(i,0,n) cin >> a[i];
	int ans = 0;
	int x = 1;
	For(i,0,n) {
		if (a[i] == x) x++;
		else ans++;
	}
	if (x == 1) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  int h, w, m;
  cin >> h >> w >> m;
  set<pair<int,int>> s;
  vi ycnt(h);
  vi xcnt(w);
  int ymx = 0, xmx = 0;
  rep(i,m) {
    int y, x;
    cin >> y >> x;
    y--; x--;
    s.insert({y,x});
    ycnt[y]++;
    xcnt[x]++;
    ymx = max(ymx, ycnt[y]);
    xmx = max(xmx, xcnt[x]);
  }
  vi ym, xm;
  rep(i,h){
    if(ycnt[i] == ymx) ym.push_back(i);
  }
  rep(i,w){
    if(xcnt[i] == xmx) xm.push_back(i);
  }
  int ans = ymx + xmx -1;
  for(auto i : ym){
    for(auto j : xm){
      if(!s.count({i,j})){
        ans++;
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 23796
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a);
    rep(i, a){
        cin >> p[i];
    }
    sort(all(p));
    reverse(all(p));

    vector<ll> q(b);
    rep(i, b){
        cin >> q[i];
    }
    sort(all(q));
    reverse(all(q));

    priority_queue<ll> r;
    rep(i, c){
        ll d;
        cin >> d;
        r.push(d);
    }
    rep(i, x){
        r.push(p[i]);
    }
    rep(i, y){
        r.push(q[i]);
    }

    ll ans = 0;
    rep(i, x+y){
        ll tmp = r.top();
        r.pop();
        ans += tmp;
    }
    cout << ans << endl;

    return 0;
}

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

#define int long long

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

int N, L;
int a[100001];

signed main() {
    cin >> N >> L;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
    }
    int tie = 0;
    for (int i = 1; i < N; i++) {
        if (a[i] + a[i + 1] >= L) {
            tie = i;
        }
    }
    if (tie != 0) {
        cout << "Possible" << endl;
        for (int i = 1; i < tie; i++) {
            cout << i << endl;
        }
        for (int i = N - 1; i > tie; i--) {
            cout << i << endl;
        }
        cout << tie << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}


Measured memory_bytes: 1536
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();

    int[] x = new int[N];
    int[] y = new int[N];
    int[] h = new int[N];

    for (int i = 0; i < N; i++) {
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
      h[i] = sc.nextInt();
    }

    sc.close();

    // 最大は100
    int max = 100;

    for (int i = 0; i <= max; i++) {
      for (int j = 0; j <= max; j++) {
        
        // あるべき高さ -2:調査中止 -1:継続調査 0以上:高さ確定
        int height = -1;
        
        for (int k = 0; k < N; k++) {
          
          if (h[k] > 0) {

            int tmp = h[k] + Math.abs(i - x[k]) + Math.abs(j - y[k]);

            if (height == -1) {
              height = tmp;
            } else {
              if (height != tmp) {
                height = -2;
                break;
              }
            }

          }

        }

        if (height == -2) {
          continue;
        }

        for (int k = 0; k < N; k++) {
          
          if (h[k] == 0) {
            int tmp = Math.abs(i - x[k]) + Math.abs(j - y[k]);
            if (height > tmp) {
              height = -2;
              break;
            }
          }

        }

        if (height == -2) {
          continue;
        }

        System.out.println(i + " " + j + " " + height);

      }
    }

  }

}

Measured memory_bytes: 24020
/* 
* code by: imasnegi
**/

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

#define ll long long
#define nl "\n"
#define spc " "
#define fr(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define deb(a) cout << #a << " " << a << nl;

template<typename T>
void printArray(vector<T>& v) {
	for(auto& i : v)
		cout << i << spc;
	cout << nl;
}
const int MaxN = 2e5 + 5;
const int MOD = 1e9 + 7;

void solve_cases() {
	int n, x, t;
	cin >> n >> x >> t;
	cout << (int)ceil(n / (double)x) * t << nl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cout << setprecision(10) << fixed;
	int t = 1;
	//cin >> t;
	FOR(tt, 1, t) {
		//cout << "Case #" << tt << ": ";
		solve_cases();
	}
}

Measured memory_bytes: 3648
N,T = map(int,input().split())

P = list(map(int,input().split()))

OYUSUM = 0
now = P[0]
for t in P[1:]:
    if t-now<T:
        OYUSUM+=t-now
        now = t
    else:
        OYUSUM+=T
        now = t
    
OYUSUM+=T
    
print(OYUSUM)

Measured memory_bytes: 26832
x=int(input())
if x==1:
    print(1)
    exit()
if x==2:
    print(2)
    exit()
ans=0
for i in range(2,int(x**0.5)+1):
    a=i
    while a*i<=x:
        a*=i
    ans=max(ans,a)
print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

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

	while (1) {
		int M, T, P, R; cin >> M >> T >> P >> R;
		if (M == 0) { break; }

		vector<vector<ll>> penalty(T);
		vector<ll> solved(T, 0);
		vector<ll> elapsed(T, 0);

		for (int i = 0; i < T; i++) {
			penalty[i].resize(P, 0);
		}
		for (int i = 0; i < R; i++) {
			int m, t, p, _j; cin >> m >> t >> p >> _j;
			bool judge = (_j == 0);
			t--;
			p--;
			if (judge == true) {
				solved[t]++;
				elapsed[t] += m + 20 * penalty[t][p];
			}
			else {
				penalty[t][p]++;
			}
		}
		vector<pair<ll, int>> ans;
		for (int i = 0; i < T; i++) {
			ll score = -10000000LL * solved[i] + elapsed[i];
			ans.push_back({ score, -i - 1 });
		}
		sort(ans.begin(), ans.end());
		for (int i = 0; i < T; i++) {
			if (i != 0) {
				if (ans[i].first == ans[i - 1].first) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
			cout << -ans[i].second;
		}
		cout << endl;
	}

	return 0;
}


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

int main() {
  int N, A, B, C, D;
  cin >> N;
  A = N/1000;
  B = (N-A*1000)/100;
  C = (N-A*1000-B*100)/10;
  D = N-A*1000-B*100-C*10;

  if (A == B && A == C) {
    cout << "Yes" << endl;
  }
  else if (B == C && B == D) {
      cout << "Yes" << endl;
    }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())
lis = list(map(int,input().split()))
s=sum(lis)
for i in range(n//2):
    s-=2*lis[1+2*i]
print(s,end="")
ans=s
for i in range(n-1):
    ans=2*lis[i]-ans
    print(" ",end="")
    print(ans,end="")
           

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

int main() {
    string s;  cin >> s;
    for (int i = 0; i < (int)s.size(); ++i) {
        if (i == 0 && s[i] == '?') s[i] = 'D';
        if (s[i] == '?' && s[i - 1] == 'P') s[i] = 'D';
        else if (s[i] == '?' && s[i - 1] == 'D') s[i] = 'D';
    }
    cout << s << endl;
}


Measured memory_bytes: 3728
ans = 0
S = list(input())
po = 1

for i in range(2**(len(S)-1)):
    buf = ""
    oper = bin(po)[2:].zfill(len(S))
    for j in range(len(S)-1):
        buf += S[j]
        if oper[j] == "0":
            continue
        elif oper[j] == "1":
            buf += "+"
    buf += S[-1]
    ans += eval(buf)
    if oper[-1] == "0" and i :
        po += 2
    else:
        po += 1
    
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
	int i, N, M;
	scanf("%d %d", &N, &M);
	if (N % 2 == 1) {
		for (i = 1; i <= M; i++) printf("%d %d\n", i, N - i + 1);
	} else {
		for (i = 1; i <= M && i <= N / 4; i++) printf("%d %d\n", i, N - i + 1);
		for (; i <= M; i++) printf("%d %d\n", i, N - i);
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1704