akhauriyash/Code-Regression huggingface dataset:
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


template<class T>
bool is_prime(T n) {
    for (T i = 2; i * i <= n; ++i) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(X);
    int ans = 0;
    for(int i=X;;i++){
        if(is_prime(i)){
            ans = i;
            break;
        }
    }
    cout << ans << nn;
    return 0;
}

Measured memory_bytes: 256
package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func main(){
	arr := scanIntSplit(2)
	if (arr[0] * arr[1])%2 == 0{
		fmt.Println("Even")
	} else {
		fmt.Println("Odd")
	}
}

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

int main(void){
int n;
int v[20];
int c[20];
int i;
int m = 0;
cin >> n;
for(i=1;i<=n;i++){
	cin >> v[i];
}
for(i=1;i<=n;i++){
	cin >> c[i];
}
for(i=1;i<=n;i++){
	if(v[i] > c[i]){
    	m += v[i] - c[i];
    }
}
printf("%d",m);
return 0;
  

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+7;
int main()
{
	ll n;cin>>n;ll i=0;
	for(i=1;i*i<=n;i++);
	while(n%i!=0) i--;
	cout<<i+(n/i)-2<<endl;
	return 0;
}

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

int main() {
  int X, Y, a;
  cin >> X >> Y;
  a = Y - 2*X;
  if( a%2 == 0 ){
    if(X >= a/2 && a >= 0)
      cout << "Yes" <<endl;
    else   
      cout << "No" <<endl;
  }
  else
    cout << "No" <<endl;

}

Measured memory_bytes: 3672
S = input()

a = int("".join(["0" if i%2 == 0 else "1" for i in range(len(S))]), 2)
b = int("".join(["0" if i%2 == 1 else "1" for i in range(len(S))]), 2)


a_ = int(S, 2) ^ a
b_ = int(S, 2) ^ b

cnt1 = 0
cnt2 = 0

for c1 in bin(a_)[2:]:
    if c1 == "1":
        cnt1 += 1

for c2 in bin(b_)[2:]:
    if c2 == "1":
        cnt2 += 1

if cnt1 > cnt2:
    print(cnt2)
else:
    print(cnt1)


Measured memory_bytes: 3956
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		ArrayList<Integer> array = new ArrayList<Integer>();
		ArrayList<Integer> array2 = new ArrayList<Integer>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String data = "";
		br.readLine();
		data = br.readLine();

		String [] hairetsu = data.split(" ", 0);
		
		for(int i = 0; i < hairetsu.length; i++) {
			array.add(Integer.parseInt(hairetsu[i]));
		}
		
		for(int i = 0; i < array.size(); i++) {
			array2.add(array.get(array.size() - 1 - i));
		}
		
		for(int i = 0; i < array2.size(); i++) {
			System.out.print(array2.get(i));
			if(i < array2.size() - 1) {
				System.out.print(" ");
			}
		}
		System.out.println();

	}
}

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

template<typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b%a, a);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  vector<int> x(n+1);
  rep(i, n+1) cin >> x[i];
  sort(x.begin(), x.end());

  int ans = x[1] - x[0];
  rep(i, n) {
    ans = gcd(ans, x[i+1] - x[i]);
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll numDigits(int n) {
    ll digits = 0;
    while (n) {
        n /= 10;
        digits++;
    }
    return digits;
}

int main(){
    ll N; cin >> N;
    ll minF = 1e9;
    for (ll A = 1; A <= sqrt(N); A++) {
        if (N % A == 0) {
            ll B = N / A;
            ll cand = max(numDigits(A), numDigits(B));
            if (cand < minF) minF = cand;
        }
    }
    cout << minF << endl;
}

Measured memory_bytes: 256
#define _USE_MA_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    vi l(n+2),r(n+2);
    rep(i,n)l[i+1]=__gcd(l[i],a[i]);
    rev(i,n)r[i+1]=__gcd(r[i+2],a[i]);
    int ans=0;
    REP(i,1,n)ans=max(ans,__gcd(l[i-1],r[i+1]));
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
import java.util.*;

class Main {

	static int N;
	static void dfs(int cnt, StringBuilder x) {
		if (x.length()==N) {
			System.out.println(x);
		} else {
			for (int i=(int)'a';i<=(int)'a'+cnt+1;i++) {
				StringBuilder sb = new StringBuilder(x);
				sb.append((char)i);
				if (i==(int)'a'+cnt+1) {
					dfs(cnt+1, sb);
				} else {
					dfs(cnt, sb);
				}
			}
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		sb.append('a');
		dfs(0, sb);
	}
}

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

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n) for(lli i=1;i<=n;i++)

int main(){

	string str;
	cin >> str;

	lli size=0;
	lli ans = 0;
	char d[4] = {'A','T','C','G'};
	REP(i,str.size()){
		lli flag=0;
		REP(j,4){
			if(str.at(i) == d[j]){
				size++;
				flag=1;
				break;
			}
		}
		if(flag==0)size=0;
		ans = max(ans,size);
	}
	cout<<ans<<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,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

inline LL f(LL x) {
	return x * x * x * x * x;
}

int main()
{
	LL x;
	cin >> x;
	for(LL a = 1, b = 0; ; ++a) {
		for(b = -1000; b < a; ++b) if(f(a) - f(b) == x) {
			cout << a << ' ' << b << endl;
			return 0;
		}
	}
	return 0;
}


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

// @author: pashka

vector<int> z;
vector<vector<pair<int, int>>> g;
vector<bool> mark;
vector<int> res;

int dfs(int x) {
    int s = z[x];
    mark[x] = true;
    for (auto p : g[x]) {
        int y = p.first;
        if (!mark[y]) {
//            cout << x << "->" << y << "\n";
            int r = dfs(y);
            if (r == 1) {
                res.push_back(p.second);
            }
            s ^= r;
        }
    }
    return s;
}

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

    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(), a.end());
    vector<int> x(n);
    for (int i = 0; i < n; i++) x[i] = a[i].first;

    g.resize(n + 1);
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        l = lower_bound(x.begin(), x.end(), l) - x.begin();
        r = lower_bound(x.begin(), x.end(), r + 1) - x.begin();
//        cout << l << " " << r << "\n";
        g[l].push_back({r, i});
        g[r].push_back({l, i});
    }
    z.resize(n + 1);
    for (int i = 0; i < n - 1; i++) {
        z[i + 1] = a[i].second ^ a[i + 1].second;
    }
    z[0] = a[0].second;
    z[n] = a[n - 1].second;
//    for (int x : z) cout << x;
//    cout << "\n";

    mark.resize(n + 1);
    for (int i = 0; i < n; i++) {
        if (!mark[i]) {
            int r = dfs(i);
            if (r == 1) {
                cout << -1;
                return 0;
            }
        }
    }
    cout << res.size() << "\n";
    sort(res.begin(), res.end());
    for (int x : res) {
        cout << x + 1 << " ";
    }

    return 0;
}

Measured memory_bytes: 16636
from collections import defaultdict
N = int(input())
S = input()
countp = defaultdict(int)
counts = defaultdict(int)
prefix = S[:N]
suffix = S[2*N-1:N-1:-1]
for i in range(1 << (N - 1)):
    p1 = ''
    s1 = ''
    p2 = ''
    s2 = ''
    for j in range(N):
        if (1 << j) & i:
            p1 += prefix[j]
            s1 += suffix[j]
        else:
            p2 += prefix[j]
            s2 += suffix[j]
    countp[(p1, p2)] += 1
    countp[(p2, p1)] += 1
    counts[(s1, s2)] += 1
    counts[(s2, s1)] += 1
    

# print(countp, counts)

ans = 0
for k, v in countp.items():
    ans += v * counts[k]

print(ans)

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



int main(){
    int n; cin>>n;
    vector<ll> a(n);
    ll max = pow(10,18);
    ll ans =0;

    rep(i,n){
        cin >>a[i];
        if(a[i]==0){
            cout<<ans<<endl;
            return 0;
        }

    }
    ans = 1;
    for(int i = 0;i<n;++i){
        if(a[i]<=max/ans){
            ans *= a[i];
        }
        else {
            ans = -1;
            break;
        }
    }
    cout<<ans<<endl;
}


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

int main(){
     int N,M;
     while(cin>>N>>M,N){
	  int tosen[N][8],syokin[N];
	  int kuji[M][8];
	  for(int i=0;i<N;i++){
	       for(int k=0;k<8;k++){//ツ督鳴選ツ氾板債禿偲ヲツづィ
		    char a;
		    cin>>a;
		    switch(a){
		    case '*':
			 tosen[i][k]=-1;
			 break;
		    default:
			 tosen[i][k]=a-'0';
			 break;
		    }
	       }
	       cin>>syokin[i];
	  }
	  for(int i=0;i<M;i++){
	       for(int k=0;k<8;k++){
		    char a;
		    cin>>a;
		    kuji[i][k]=a-'0';
	       }
	  }
	  int sum=0;
	  for(int i=0;i<N;i++){
	       for(int j=0;j<M;j++){
		    bool flag=true;
		    for(int k=0;k<8;k++){
			 if(-1==tosen[i][k])continue;
			 if(tosen[i][k]!=kuji[j][k]){
			      //cout<<tosen[i][k]<<":"<<kuji[j][k]<<" ";
			      flag=false;
			      break;
			 }
		    }
		    if(flag)sum+=syokin[i];
	       }
	  }
	  cout<<sum<<endl;
     }
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

typedef long long ll;
ll num[101];
ll memo[101][101];
ll limit;
ll math(ll p,ll sum){
  if(sum<0 || sum>20) return 0;
  else if(p == limit-1 )return sum == num[p];
  else if(memo[p][sum]>0)return memo[p][sum];
  else return memo[p][sum] = math(p+1,sum+num[p])+math(p+1,sum-num[p]);
}

int main(){
  cin>>limit;
  for(int i = 0 ; i < limit ; i++)cin>>num[i];
  cout<<math(1,num[0])<<endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;
 
int main(){
    ll n,k;
    cin>>n>>k;
 
    long double ans=0;
    for(int i=1;i<=n;i++){
        int x=i;
        long double cnt=0;
        while(x<k){
            x*=2;
            cnt++;
        }
        long double tmp=1/pow(2,cnt);
        tmp/=(long double)n;
        ans+=tmp;
    }
 
    cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 3852
#include<stdio.h>
 
int main(void)
{
    int x, y;
    while (1) {
        scanf("%d %d\n", &x, &y);
        if (x == 0 && y == 0) {
            break;
        } else if (x <= y) {
            printf("%d %d\n", x, y);
        } else {
            printf("%d %d\n", y, x);
        }
    }
    return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

int main(){
	
	int N;
	string S;
	cin >> N >> S;
	
	int ans=0;

	FOR(i,1,N){
		int cnt = 0;
		FOR(j,0,N-i){
			if(S[j]==S[i+j]){
				ans = max(ans,++cnt);
				if(cnt==i)break;
			}else{
				cnt = 0;
			}
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Thu Jan 10 20:08:18 2019
//
package main

import (
	"fmt"
	"sort"
)

type pair struct {
	w, v int
}

func max(slice ...int) int {
	sort.Ints(slice)
	return slice[len(slice)-1]
}

func main() {
	var N, W int
	fmt.Scan(&N, &W)

	arr := make([]pair, N)
	for i := range arr {
		fmt.Scan(&arr[i].w, &arr[i].v)
	}

	dp := make([][]int, N+1)
	for i := range dp {
		dp[i] = make([]int, W+1)
	}
	dp[0][0] = 0

	for i := range arr {
		iw, iv := arr[i].w, arr[i].v
		for w := range dp[i] {
			if w-iw >= 0 {
				dp[i+1][w] = max(dp[i][w], dp[i][w-iw]+iv)
			} else {
				dp[i+1][w] = dp[i][w]
			}
		}
	}

	ans := 0
	for i := range dp[N] {
		if dp[N][i] != 1<<60 {
			ans = max(ans, dp[N][i])
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 160372
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <math.h>
#include <numeric>
#include <algorithm>
#include <string>
#include <tuple>

typedef long long ll;

using namespace std;



int main() {
    string s;
    cin >> s;
    int ret1=0, ret2=0;
    int ct=0;
    for(auto c : s){
        int nm = c-'0';
        if(nm==ct%2){++ret1;}else{++ret2;}
        ct++;
    }
    cout << min(ret1, ret2) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>


int main() {
	long long n;

	std::cin >> n;

	std::vector<long long> v(n + 1), v2(n);

	for (long long i = 0; i < n + 1; i++)
	{
		std::cin >> v[i];
	}

	for (long long i = 0; i < n; i++)
	{
		std::cin >> v2[i];
	}

	long long ans = 0;
	for (long long i = 0; i < n; i++)
	{
		if (v[i] >= v2[i]) {
			ans += v2[i];
		}
		else {
			ans += v[i];
			v2[i] -= v[i];
			if (v[i + 1] >= v2[i]) {
				ans += v2[i];
				v[i + 1] -= v2[i];
			}
			else {
				ans += v[i + 1];
				v[i + 1] = 0;
			}
		}
	}

	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
int main(){
	long long int n,a,b;
	long long int ans=0;
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a==b)ans=1;
	if(a<b){
		ans=(b-a)*(n-2)+1;
		if(n==1)ans=0;
	}
	printf("%lld\n",ans);
	return 0;
}
		

Measured memory_bytes: 128
from heapq import heappop, heappush, heapify

n, m = map(int, input().split())
arr = list(map(int, input().split()))
arr = [-x for x in arr]

heapify(arr)

for _ in range(m):
    a = heappop(arr)
    heappush(arr, -(-a // 2))

print(-sum(arr))

Measured memory_bytes: 20148
import java.io.*;

class Main{
        static void sort(int[] A){
                if(A[0]<A[1]){
                        int t = A[0];
                        A[0] = A[1];
                        A[1] = t;
                }
        }
        public static void main(String[] args) throws IOException{
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String s[] = br.readLine().split(" ");
                int A[] = {0, 0};

                for(int i=0; i<2; i++)
                        A[i] = Integer.parseInt(s[i]);
                sort(A);
                while((A[0]>1)&&A[1]!=0&&(A[0]!=A[0]%A[1])){
                        int t = A[0];
                        A[0] = A[1];
                        A[1] = t%A[1];
                        sort(A);
                }
                System.out.println(A[0]);
        }
}

Measured memory_bytes: 24280
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int main(){
    int H,W;
    while(true){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0) break;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}


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

typedef long long ll;
using namespace std;

#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define all(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() );
#define MOD 1000000007

int main(){
	ll h, w, m;	cin >> h >> w >> m;
	set<pair<int, int>> target;
	int sumH[h] = {0};
	int sumW[w] = {0};
	vector<int> cH;
	vector<int> cW;
	int mh, mw;
	REP(i, m){
		ll x, y;	cin >> x >> y;
		x--; y--;
		sumH[x]++;
		sumW[y]++;
		target.insert(make_pair(x, y));
	}

	mh = *max_element(sumH, sumH + h);
	mw = *max_element(sumW, sumW + w);
	REP(i, h){
		if( sumH[i] == mh )	cH.push_back(i);
	}
	REP(i, w){
		if( sumW[i] == mw )	cW.push_back(i);
	}

	REP(i, cH.size()) REP(j, cW.size()){
		if( target.find( make_pair(cH[i], cW[j]) ) == target.end() ){
			cout << mh + mw << endl;
			return 0;
		}
	}

	cout << mh + mw - 1 << endl;

	return 0;
}


Measured memory_bytes: 23728
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  ll ans = k % 2 == 0 ? a - b : b - a;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cmath>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
int a[3][3];
int vis[3][3];
int main(){
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    int n;
    cin>>n;
    int x;
    while(n--){
         cin>>x;
         for(int i=0;i<3;i++){
             for(int j=0;j<3;j++){
                 if(x==a[i][j]){
                     vis[i][j]=1;
                 }
             }
         }
    }
    int flag=0;
    for(int i=0;i<3;i++){
        int cc=0;
        for(int j=0;j<3;j++){
            if(vis[i][j]==1){
                cc++;
            }
        }
        if(cc==3){
            flag=1;
        }
    }
    for(int i=0;i<3;i++){
        int cc=0;
        for(int j=0;j<3;j++){
            if(vis[j][i]==1){
                cc++;
            }
        }
        if(cc==3){
            flag=1;
        }
    }
    if(vis[0][0]==1&&vis[1][1]==1&&vis[2][2]==1){
        flag=1;
    }
    if(vis[0][2]&&vis[1][1]&&vis[2][0]){
        flag=1;
    }
    if(flag){
        puts("Yes");
    }
    else{
        puts("No");
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=200005;
//i_am_noob
int n,a[100],ans=0;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	rep(n-1) cin >> a[i];
	ans+=a[0],ans+=a[n-2];
	rep(n-2) ans+=min(a[i],a[i+1]);
	print1(ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  vector<ll> a ;
  rep(i,3){
    ll inp; cin >> inp;
    a.pb(inp);
  }
  rmsame(a);
  cout << a.size() << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;

int main()
{
	int n; cin >> n;
	int tmp = n;
	int s = 0;
	while (1) {
		s+=n % 10;
		n=n / 10;
		if (n == 0) {
			break;
		}
	}
	if (tmp%s == 0) {
		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 sc = new Scanner(System.in);
        String S = sc.next();
        if (S.charAt(2) == S.charAt(3) && S.charAt(4) == S.charAt(5)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22612
#include<iostream>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll read(){
	ll x=0,w=1;
	char ch=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-')
			w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return w*x;
}
int main(){
	ll N,A,B;
	cin>>N>>A>>B;
	if(N==(A+B)){
		cout<<A<<endl;
	}else if(N>(A+B)){
		ll num=A+B;/*总数*/
		ll t=N/num;/*可以分成t组，每组有A个蓝的*/
		ll e=N%num;/*这是余数*/
		ll y=0;
		if(e>=A){
			y=A;
		}else{
			y=e;
		} 
		cout<<A*t+y<<endl;
	}else if(N<(A+B)){
		if(N>=A){
			cout<<A<<endl;
		}else{
			cout<<N<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const long long INF = 1LL << 60;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(int argc, const char * argv[]) {
    
    
    
    int N,K; cin >> N >> K;
    vector<ll> h(101000);
    vector<ll> dp(101000);
    
    for (int i = 0; i < 101000; i++) {
        dp[i] = INF;
        h[i] = 0;
    }
    for (int i = 0; i < N; i++) cin >> h[i];
    
    dp[0] = 0;
    
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            chmin( dp[i + j], dp[i] + abs( h[i] - h[i + j]) );
        }
    }
    
    cout << dp[N - 1] << endl;
    
    
    
}


Measured memory_bytes: 1792
#include <iostream>


using namespace std;


int main(void){
    int n;
    cin>>n;
    
    int max=0;
    int ans;
    if(n==1){
        cout<<"1"<<endl;
    return 0;}
    for(int i=1;i<=n;i++){
            int a=i;
            int count=0;
        while(1){
            if((a%2)==0){
                a/=2;
                count++;
                //cout<<a<<endl;
                if(max<count){
                    max=count;
                    ans=i;
                }
            }else{
                //cout<<"1"<<endl;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
main (){
  int N,K;
  cin >>N>>K;

  int a=1,sum=0;
  for(int i=0;i<N;i++){ 
    a*=2;
  
    if(K<a/2){
      break;
    }
    sum++;
  }
  if(a/2<=K){
    cout<<a<<endl;
  }
  else{
    
  
   cout<<a/2+(N-sum)*K<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int count=0;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
		if(500*i+100*j+50*k==X)count++;
      }
    }
  }
   cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

#define maxs(x,y) (x=std::max(x,y))
#define mins(x,y) (x=std::min(x,y))

int main() {
  ull N, A, B;
  cin >> N >> A >> B;
  ull a = N / (A+B);
  ull b = N % (A+B);

  mins(b, A);
  cout << a*A + b << '\n';
}


Measured memory_bytes: 888
#include <stdio.h>

int main(void)
{

  int n, i, j;
  double s, x[9];
  s=0.0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
        scanf("%lf",&x[i]);
        char y[3]={};
        scanf("%s",&y);
        if(y[0]== 'B') x[i]=x[i]*380000.0;
        s=s+x[i];
  }
  printf("%lf\n",s);
  return 0;
}


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

int main() {
  string s,ans="TBD";
  cin >> s;
  if(s[5]=='0'&&s[6]=='1') ans="Heisei";
  if(s[5]=='0'&&s[6]=='2') ans="Heisei";
  if(s[5]=='0'&&s[6]=='3') ans="Heisei";
  if(s[5]=='0'&&s[6]=='4') ans="Heisei";
  cout << ans << endl;
}

Measured memory_bytes: 256
def LI():return list(map(int,input().split()))
def II():return int(input())
def yes():return print("Yes")
def no():return print("No")
INF=float("inf")
from collections import deque, defaultdict, Counter
from heapq import heappop, heappush
from itertools import product, combinations
from functools import reduce, lru_cache
from math import pi, gcd
from decimal import Decimal

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

class Unionfind:
    def __init__(self, N):
        self.p = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def root(self, x):
        if self.p[x] != x:
            self.p[x] = self.root(self.p[x])

        return self.p[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        u = self.root(x)
        v = self.root(y)

        if u == v: return

        if self.rank[u] < self.rank[v]:
            self.p[u] = v
            self.size[v] += self.size[u]
            self.size[u] = 0
        else:
            self.p[v] = u
            self.size[u] += self.size[v]
            self.size[v] = 0

            if self.rank[u] == self.rank[v]:
                self.rank[u] += 1

    def count(self, x):
        return self.size[self.root(x)]

n=II()
a=[]
b=[]
for _ in range(n):
    x,y=LI()
    a+=(x+y),
    b+=(x-y),
    
# a.sort()
# b.sort()

ans1=max(a)-min(a)
ans2=max(b)-min(b)

ans=max(abs(ans1),abs(ans2))

print(ans)

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

using namespace std;

int main()
{
    int N,a=0,w=0,t=0,r=0;
    cin>>N;
    string s[N+5];
    for(int i=0;i<N;i++)
    {
        cin>>s[i];
        if(s[i]=="AC") a++;
        else if(s[i]=="WA") w++;
        else if(s[i]=="TLE") t++;
        else if(s[i]=="RE") r++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<r<<endl;

    return 0;
}


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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


	int a, b, c;
	cin >> a >> b >> c;

	cout << max(0, c - (a - b)) << endl;
	return 0;
}


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

if N == 1:
    print('Yes')
    print(2)
    print(1,1)
    print(1,1)    
    exit()

m = s = 1
while s < N:
    m += 1
    s += m
if s != N:
    print('No')
    exit()

k = m+1
print('Yes')
print(k)
ans = [[] for i in range(k)]
n = 1
for i in range(k-1):
    for j in range(i+1,k):
        ans[i].append(n)
        ans[j].append(n)
        n += 1

for row in ans:
    print(len(row), *row)

Measured memory_bytes: 9416
K, N = map(int, input().split())
A = list(map(int, input().split()))

L = []
for i in range(N):
    if (i < N - 1):
        L.append(A[i + 1] - A[i])
    elif (i == N - 1):
        L.append(K - A[i] + A[0])


print(sum(L) - max(L))


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

ll MOD = 1e9 + 7;
ll factorial[200010];

int main() {
  factorial[0] = 0, factorial[1] = 1;
  for (int i = 2; i <= 20000; i++) {
    factorial[i] = factorial[i - 1] * i % MOD;
  }

  string S;
  cin >> S;
  ll ans = 0;
  ll a = 0, ab = 0, num = 1;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'A') {
      a = (a + num) % MOD;
    } else if (S[i] == 'B') {
      ab = (ab + a) % MOD;
    } else if (S[i] == 'C') {
      ans = (ans + ab) % MOD;
    } else {
      ans = (ans * 3 + ab) % MOD;
      ab = (ab * 3 + a) % MOD;
      a = (a * 3) % MOD + num;
      num = num * 3 % MOD;
    }
  }
  cout << ans % MOD << endl;
}


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

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int count = 0;
    for(; a <= b; ++a) {
        string buffer = to_string(a);
        if(buffer[0] == buffer[4] && buffer[1] == buffer[3]) count++;
    }
    cout << count << '\n';
}


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

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;


int main() {
	// your code goes here
	int N, res = 0;
	cin >> N;
	vector<int> L;
	L.resize(2 * N);
	
	for (int& i : L)
		cin>>i;
		
	sort(L.begin(), L.end());
	for (auto it = L.begin(); it != L.end(); )
	{
		int f = *it++, l = *it++;
		
		res += min(f, l);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <unordered_set>
//#include <unordered_map>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
// map<pii,int> ma;
vint v;
int n;
/*
3
2
1
1
2
3
2
2
2
1
1
3
*/
int foo(pii a){
	// if(ma.count(a)) return ma[a];
	// cout<<a.F<<" "<<a.S<<endl;
	int ret=a.S-a.F+1;
	pii b=a;
	b.F--;
	b.S++;
	while(1){
		while(b.F>0&&v[b.F-1]==v[b.F]){
			b.F--;
		}
		while(b.S<n+1&&v[b.S+1]==v[b.S]){
			b.S++;
		}
		if(v[b.F]==v[b.S]&&b.S-b.F+1-ret>=4){
			ret=b.S-b.F+1;
		}
		else{
			break;
		}
		b.F--;
		b.S++;
	}
	return ret;
}
void mainmain(){
	while(cin>>n,n){
		v=vint(n+2,0);
		// ma.clear();
		rep(i,n) cin>>v[i+1];
		if(n<=3){
			cout<<n<<endl;
			continue;
		}
		// map<pii,bool> ma;
		int ans=0;
		reep(i,1,n+1){
			pii t(i-1,i+1);
			while(t.F>0&&v[t.F-1]==v[t.F]){
				t.F--;
			}
			while(t.S<n+1&&v[t.S+1]==v[t.S]){
				t.S++;
			}
			// cout<<"aa "<<i<<" "<<t.F<<" "<<t.S<<endl;
			if(v[i-1]==v[i+1]){
				if(t.S+1-t.F>=4){
					// cout<<i<<" "<<0<<endl;
					ans=max(ans,foo(t));
				}
			}
			else{
				if(i-t.F+1>=4){
					// cout<<i<<" "<<1<<endl;
					ans=max(ans,foo(pii(t.F,i)));
				}
				if(t.S-i+1>=4){
					// cout<<i<<" "<<2<<endl;
					ans=max(ans,foo(pii(i,t.S)));
				}
			}
		}
		cout<<n-ans<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1260
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    ll a[n];
    rp(i,n) cin >> a[i];
    sort(a,a+n);
    ll suma = 0;
    ll sumb = 0;
    ll cnt = 0;
    rpd(i,n){
      if(cnt % 2 == 0) suma += a[i];
      else sumb +=a[i];
      ++cnt;
    }
    cout << suma - sumb << endl;


    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

int main(){
  string s;
  ll k;
  cin>>s>>k;
  char c;
  int n=s.size();
  for(ll i=0;i<n;i++){
    if(i==k-1){
      c=s[i];
      break;
    }
    if(s[i]!='1'){
      c=s[i];
      break;
    }
    if(i==n-1) c=s[i];
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
/**
 *Code Author: codeknight13
 *Institution: IIT(ISM)
**/
 
#include <bits/stdc++.h>
using namespace std;

//remember-> largest 2d memory that can be allocated is dp[5100][5100];
#define ll long long int
#define v vector
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define str string
#define pq priority_queue
#define vi vector< ll >
#define vii vector< vi >
#define viii vector< vii >
#define pii pair< ll, ll >
#define vpii vector< pii >
#define len length()
#define pb push_back
#define mp make_pair3
#define ff first
#define ss second
#define nl cout <<  endl
#define all(ar) ar.begin(), ar.end()
#define ini(X,Y) ll X; X=Y
#define inx(X) ll X; cin >> X
#define inxy(X, Y) ll X, Y; cin >> X >> Y
#define iter(arr) for (ll i=0; i<arr.size(); i++)
#define ret return
#define cont continue
ll inf=1000000007;

ll min1(ll a, ll b, ll c)
{
	ret (min(a,min(b,c)));
}

int solve(vi &arr, vi &dp, int n)
{
	if (n<=1)
	{
		dp[n]=0;
		ret 0;
	}
	if (dp[n]!=-1)
	{
		ret dp[n];
	}
	dp[n]=min(abs(arr[n]-arr[n-2])+solve(arr,dp,n-2),abs(arr[n]-arr[n-1])+solve(arr,dp,n-1));
	ret dp[n];
}

int main()
{
	fast;
	int n;
	cin >> n;
	vi arr(n+2);
	arr[0]=	INT_MAX;
	arr[1]=	INT_MAX;
	for (int i=2; i<n+2; i++)
	{
		cin >> arr[i];
	}
	vi dp(n+2,-1);
	dp[2]=0;
	cout << solve(arr,dp,n+1);
	ret 0;
}

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

int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
	cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
	cout << s[i] << endl << s[i] << 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)

int possible[100010], cnt[100010];

int main(void) {
    int N, M, x, y;
    cin >> N >> M;
    rep(i, N) {possible[i] = 0; cnt[i] = 1;}
    possible[0] = 1;
    rep(i, M) {
        cin >> x >> y;
        x--; y--;
        if(possible[x]) possible[y] = 1;
        cnt[x]--; cnt[y]++;
        if(cnt[x]==0) possible[x] = 0;
    }
    int ans = 0;
    rep(i, N) ans += possible[i];
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d;
    int e,f,g,h;
    cin >> a>>b>>c>>d;
    cin >>e>>f>>g>>h;
    int x=a+b+c+d;
    int y=e+f+g+h;
    
    if(x>y){
        cout<< x<< endl;
        
    }
    else{
        cout << y<< endl;
    }
}



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

int main(){ 
string s;
cin>>s;
size_t n = s.length();
if(s.substr(0,(n-1)/2)==s.substr((n+1)/2,n-1)){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;  
}
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

const int N = 1000005;

int a[N] , b[N] ,n , tot , m;

vector<int>it , p;

int main(void) {
	it.clear();
	scanf("%d%d",&n , &m);
	for(int i = 1;i <= m;i ++) scanf("%d",&a[i]);
	for(int i = 1;i <= m;i ++) {
		if(a[i] % 2) it.push_back(a[i]); else p.push_back(a[i]);
	}
	if(it.size() > 2) {
		puts("Impossible");
		return 0;
	}
	if(m == 1) {
		for(int i = 1;i <= m;i ++) cout<<a[i] <<" "; puts("");
		if(a[1] == 1) {
			puts("1");
			puts("1");
			return 0;
		}
		puts("2");
		cout<< a[1] - 1 << " " << 1 << endl;
		return 0;
	}
	else {
		while(it.size() < 2) {
			it.push_back(p[(int)p.size() - 1]); p.pop_back();
		}
		b[++ tot] = it[0] + 1;
		printf("%d " , it[0]);
		for(int i = 0;i <(int) p.size();i ++) b[++ tot] = p[i] , printf("%d " , p[i]);
		b[++ tot] = it[1] - 1;
		printf("%d " , it[1]);
		if(!b[tot]) tot --;
		printf("\n%d\n" , tot);
		for(int i = 1;i <= tot;i ++) printf("%d " , b[i]);
	}
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

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

  int same = 0;
  for (int i = 1; i <= N; i++)
  {
    int p;
    cin >> p;
    if (i == p) same++;
  }
  
  string ans = (same == N || same == N - 2)? "YES" : "NO";
  cout << ans << endl;
}

Measured memory_bytes: 256
N, M, R = [int(_) for _ in input().split()]
r = [int(_) - 1 for _ in input().split()]

from collections import defaultdict
from itertools import permutations

INF = 10**10

D = [[INF] * N for _ in range(N)]

for i in range(M):
    a, b, c = [int(_) for _ in input().split()]
    D[a-1][b-1] = c
    D[b-1][a-1] = c

result = INF

# warshall_floyd
for i in range(N):
    for j in range(N):
        for k in range(N):
            D[j][k] = min(D[j][k], D[j][i] + D[i][k])

for xs in permutations(r):
    r = 0
    for i in range(R - 1):
        st, ed = xs[i], xs[i + 1]
        r += D[st][ed]
    result = min(result, r)

print(result)


Measured memory_bytes: 46552