akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int k, a, b;
	cin >> k >> a >> b;
	if(a % k == 0 || b % k == 0 || a / k != b / k)
		cout << "OK" << endl;
	else cout << "NG" << endl;			
}

Measured memory_bytes: 3572
import collections

N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


c = collections.Counter(prime_factorize(N))
values = c.values()

ans = 0
for i in values:
    value = i
    l = 1
    while((value - l) >= 0):
        ans += 1
        value -= l
        l += 1

print(ans)

Measured memory_bytes: 9468
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int N, K; cin >> N >> K;

	if (K > (N - 1)*(N - 2) / 2) cout << -1 << endl;
	else {
		int M = N - 1 + ((N - 1) * (N - 2) / 2 - K);
		cout << M << endl;
		
		for (int j = 2; j <= N; j++) cout << 1 << " " << j << endl;
		M -= (N - 1);
		for (int i = 2; i <= N && M > 0; i++) {
			for (int j = i + 1; j <= N && M > 0; j++) {
				cout << i << " " << j << endl;
				M--;
			}
		}
	}

	return 0;
}

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

signed main(void){ 
  
  int N; cin >> N;
  vector<int> A(N); 
  
  int sum = 0;
  
  for(int i = 0; i < N; i++){ 
    cin >> A[i]; sum += A[i];
  }
  
  int res = ( N*(N+1) )/2;
  
  if( sum % res != 0 ){ cout << "NO" << endl; return 0;}
  
  int m = sum/res; //全体の操作回数
  
  vector<int> delta(N);
  
  for(int i = 0; i < N; i++){ 
    if( i == N-1 ){ delta[N-1] = A[0]-A[N-1];} // N-1の次は0だから
    else{ delta[i] = A[i+1]-A[i];}
  }
  
  int test = 0;
  
  for(int i = 0; i < N; i++){ 
    if( (m-delta[i]) % N == 0 && m-delta[i] >= 0 ){ 
      test +=  (m-delta[i])/N; //これだけの回数iから足す操作を行う
    }
    else{ 
      cout << "NO" << endl; return 0;
    }
  }
  
  if( test != m ){ cout<< "NO" << endl; return 0;}
  
  cout << "YES" << endl;
  
  return 0;
} 

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
    int a[100],b[100],c,s,s1;
    scanf("%d%d",&a[100],&b[100]);
    c=(a[100]+b[100])/2;
    s=abs(a[100]-c);
    s1=abs(b[100]-c);
    if(s==s1&&a[100]!=b[100])
        printf("%d",c);
    else
        printf("IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n,k;

int main(){
	cin>>n>>k;
	ll res=0;
	for(ll i=k;i<=n+1;i++) (res+=(n-i+1)*i+1)%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,a[100003],ans;
int main(){
    cin>>n; 
	for(int i=1;i<=n;i++){
    	cin>>a[i];
	}
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    for(int i=1;i<=n;i++){
    	if(i+1>a[i+1]){
            for(int j=i+1;a[j]==i;j++){
                ans^=1;
            }
            ans=(ans|(a[i]-i)&1);
            cout<<(ans?"First":"Second")<<endl;
            return 0;
        }
	}
    return 0;
}

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

c = [0]*40
for i in range(40):
	for a in A:
		c[i] += (a >> i) & 1

X = 0
ans = 0

for i in range(39, -1, -1):
	if c[i] < N-c[i] and X+(1<<i) <= K:
		X += (1<<i)
		ans += (N-c[i]) * (1<<i)
	else:
		ans += (c[i]) * (1<<i)

print(ans)


Measured memory_bytes: 69008
#include<iostream>
#define ll long long
using namespace std;

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

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

	ll ans1 = max(a-k, 0LL);
	ll ans2 = b;
	if(ans1==0) ans2 = max(b-k+a, 0LL);
	cout << ans1 << " " << ans2;
	return 0;
}

Measured memory_bytes: 3612
use proconio::input;
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::HashSet;
#[allow(unused)]
const ALPHA_SMALL: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];
#[allow(unused)]
const ALPHA: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];

const MAX: usize = 100_000 + 100;
fn main() {
    input!(H: usize, W: usize, M: usize);
    let mut xy = HashSet::new();
    for _ in 0..M {
        input!(t: (usize, usize));
        xy.insert(t);
    }
    let mut ans = 0;
    let mut vx = vec![0; 3 * MAX];
    let mut vy = vec![0; 3 * MAX];
    for &(x, y) in &xy {
        vx[x] += 1;
        vy[y] += 1;
    }
    let x = calc(&vx, &vy, &xy, true);
    let y = calc(&vy, &vx, &xy, false);
    let ans = max(x, y);
    println!("{}", ans);
}

fn calc(v: &Vec<usize>, w: &Vec<usize>, set: &HashSet<(usize, usize)>, check: bool) -> usize {
    let n = v.len();
    let mut ret = 0;
    let mut a = 0;
    let mut mx = 0;
    for i in 0..n {
        let now = v[i];
        if mx < now {
            a = i;
            mx = now;
        }
    }
    ret += mx;

    let mut my = 0;
    let mut b = 0;
    for i in 0..n {
        let mut now = w[i];
        if check {
            if set.contains(&(a, i)) && now > 0 {
                now -= 1;
            }
        } else if set.contains(&(i, a)) && now > 0 {
            now -= 1;
        }
        if my < now {
            my = now;
            b = i;
        }
    }
    // println!("{} {}", a, b);
    //println!("{} {}", mx, my);
    mx + my
}


Measured memory_bytes: 19372
R,G,B,N = gets.chomp!.split(" ").map!(&:to_i)

box = {
    "R" => R,
    "G" => G,
    "B" => B,
}.sort {|(_, v1), (_, v2)| v2 <=> v1 }.to_h

max_r = N / R
max_g = N / G
max_b = N / B

# Rをr個選んだとき
memo = []
0.upto(max_r) do |i|
    memo[i] = [i, N - i * R]
end

memo2 = []
count = 0

0.upto(max_g) do |i|
    memo.each do |m|
        x = m[1] - i * G
        if x >= 0 && x % B == 0
            #memo2.push([memo[0][0], i, x])
            count += 1
            #puts "#{memo[0][0]},#{i}"
        end
    end
end

puts count

#require 'pp'
#pp memo2.count



Measured memory_bytes: 1788
//abc104_b.cpp
//Fri Nov  2 22:08:09 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	string s;
	cin >> s;

	int flag = 0;
	if (s[0] == 'A'){
		flag++;
	}
	int count = 0;
	int small = 0;
	for (int i=2;i<s.size()-1;i++){
		if (s[i] == 'C'){
			count++;
		}else {
			if (s[i] >= 'a' && s[i] <= 'z'){
			}else{
				small = -1;
			}
		}
	}
	if (s[s.size()-1] >= 'a' && s[s.size()-1] <= 'z'){
	}else{
		small = -1;
	}
	if (s[1] >= 'a' && s[1] <= 'z'){
	}else{
		small = -1;
	}

	if (count == 1){
		flag++;
	}

	if (small == 0){
		flag++;
	}

	if (flag == 3){
		cout << "AC" << endl;
	}else {
		cout << "WA" << endl;
	}
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# https://abs.contest.atcoder.jp/tasks/abc085_c


def currency(target_num, target_price, combi, cur=[10000, 5000, 1000], cur_num=0, subttl=0):
    if cur_num >= len(cur):
        return False

    unit = cur[cur_num]  # 通貨単位
    max_num = target_num-sum(combi)  # 最大可能枚数

    if cur_num == len(cur) - 1:  # 最小単位通貨
        total = subttl + (max_num * unit)
        if total == target_price:
            combi[cur_num] = max_num
            return True
        else:
            return False

    if subttl + (max_num * unit) < target_price:  # 最大でも足りないので評価しない
        return False
    for cx in range(max_num + 1):
        total = subttl + (unit*cx)  # 合計
        if total > target_price:  # 目標値を超えたら以下評価しない
            combi[cur_num] = 0
            return False

        combi[cur_num] = cx

        if total == target_price:  # ヒット
            if sum(combi) == target_num:  # 枚数もOK
                return True
        # 下位通貨で調整を試みる
        if currency(target_num, target_price, combi, cur, cur_num + 1, total):
            return True


# スペース区切りの整数の入力
n, y = map(int, input().split())
combi = [0, 0, 0]
resolve = currency(n, y, combi)
if not resolve:
    combi = [-1, -1, -1]
print(combi[0], combi[1], combi[2])


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

ans = 1
cnt = 0

for i in range(1, N):
    if A[i-1] < A[i]:
        if cnt == 0:
            f = True
            cnt = 1
        if f == False:
            f = True
            cnt = 0
            ans += 1
    elif A[i-1] > A[i]:
        if cnt == 0:
            f = False
            cnt = 1
        if f == True:
            f = False
            cnt = 0
            ans += 1

print(ans)


Measured memory_bytes: 14252
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int n;
	long a, min=1000000,max=-1000000, sum=0;
	scanf("%d\n", &n);
	for(int i=0; i<n; i++){
		scanf(" %ld", &a);
		if(a>max) max=a;
		if(a<min) min=a;
		sum+=a;
	}
	printf("%ld %ld %ld\n", min, max, sum);
	return 0;
}


Measured memory_bytes: 3236
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

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

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

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

	ll min = LLMAX;
	for (ll i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ll a = i + (N / i);
			if (min > a) {
				min = a;
			}
		}
	}

	cout << min - 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll qpow(ll a,ll b){ll res=1;while(b){if(b&1) res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll inv(ll a,ll p){return qpow(a,p-2);}
int main()
{
    std::ios::sync_with_stdio(false);
    ll n,m;
    while(cin>>n>>m)
    {
        if(n>m/2)
        {
            cout<<m/2<<endl;
        }
        else
        {
            cout<<n+(m-2*n)/4<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>

using namespace std;

int main()
{
	int H, W;
	while(true) {
		cin >> H >> W;
		if(H == 0 && W == 0)
			break;

		for(int i = 0; i < H;++i) {
			for(int j = 0; j < W;++j) {
				if(i == 0 || i == H - 1)
					cout << '#';

				else if(j == 0 || j == W - 1)
					cout << '#';
				else
					cout << '.';
			}
			cout << endl;
		}
		cout << endl;
	}
		return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b,ans;
    cin>>a>>b;
    
    if(abs(a)<=abs(b)){
        ans=abs(b)-abs(a);
        if(a<0) ans++;
        if(b<0) ans++;
    }else{
        ans=abs(a)-abs(b);
        if(a>0) ans++;
        if(b>0) ans++;
    }
    
    cout1(ans)
}

Measured memory_bytes: 256
// Problem : D - Replacing
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t,q;
	ll sum=0;
	cin>>n;
	ll f[100001]={0};
	ll ar[n];
	for(i=0;i<n;i++)
	{
		cin>>ar[i];
		sum+=ar[i];
		f[ar[i]]++;
	}
	cin>>q;
	while(q--)
	{
		ll a,b;
		cin>>a>>b;
		sum+=(b-a)*f[a];
		f[b]+=f[a];
		f[a]=0;
		cout<<sum<<'\n';
	}
}

Measured memory_bytes: 5180
import sys  
input = sys.stdin.readline
 
N, M = list(map(int, input().split()))
 
A = list(map(int, input().split()))



BC = []
for i in range(M):
    b, c = list(map(int, input().split()))
    BC.append([b, c])

BC=sorted(BC, reverse=True, key=lambda x:x[1])

cnt = 0
com = []
for b, c in BC:
    cnt += b
    if cnt > N:
        add = N-cnt+b
        com.extend([c]*add)
        break
    else:
        x = [c]*b 
        com.extend(x)
A.sort()   
num = -1
for k in range(N):
    if k == len(com):
        num = k
        break
    if A[k] > com[k]:
        num = k
        break

if num == -1:
    print(sum(com))
else:
    print(sum(com[:num])+sum(A[num:]))

Measured memory_bytes: 26780
a,b,k = map(int, input().split())

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  return set(table)

ad=divisor(a)
bd=divisor(b)

abd = list(set(ad & bd))
abd.sort()

print(abd[-k])

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
  int W,H,x,y,r,a,b;
  cin >>W>>H>>x>>y>>r;
  a=y+r;
  b=x+r;
  if (y<r||x<r||a>H||b>W) {
    cout << "No" << '\n';
  }
  else{
    cout << "Yes" << '\n';
  }
  return 0;
}

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

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, m;
    cin >> n >> m;

    vector<int> a(n);
    map<int, int> M;

    for(int i = 0; i < n; i++) {
        cin >> a[i];
        M[a[i]]++;
    }

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

    vector<pair<int, int> > P;
    for(auto it : M) {
        P.push_back(it);
    }

    reverse(P.begin(), P.end());

    ll ans = 0LL;
    for(int i = 0; i < P.size(); i++) {
        if(P[i].second >= n) {
            ans += 1LL * n * P[i].first;
            break;
        }
        else {
            ans += 1LL * P[i].second * P[i].first;
            n -= P[i].second;
        }
    }

    cout << ans << endl;
}

/**

3 2
1 3 3 4 5 5
2 3
1 5

*/


Measured memory_bytes: 12276
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.rbegin(), a.rend());

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (!(i % 2))
            ans += a[i];
        else
            ans -= a[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
/*
      H   H
       \ / 	
        C
       / \ 
      H   H
*/

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll, ll>
#define vi          vector<ll>
#define vvi			vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        998244353
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)		for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)	((c).find(x) != (c).end()) 
#define cpresent(c,x)	(find(all(c),x) != (c).end()) 
#define int ll
using namespace std;

#define N  100005

int n, m, x;
int cost[12];
int a[12][12];
int learnt[12];
int inf = 1e18;

int dfs(int i, int c, int mask)
{
	if(i==n)
	{
		memset(learnt, 0, sizeof(learnt));
		for(int k = 0; k<n; k++)
		{
			if(mask&1)
			{
				rep(j, 0, m)
				learnt[j]+=a[k][j];
			}
			mask/=2;
		}

		rep(j, 0, m)
		if(learnt[j]<x)
			return inf;
		return c;
	}

	int minv = inf;

	minv = min(minv, dfs(i+1, c, mask));
	minv = min(minv, dfs(i+1, c+cost[i], mask|(1<<i)));

	return minv;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		cin >> n >> m >> x;

		rep(i, 0, n)
		{
			cin >> cost[i];

			rep(j, 0, m)
			cin >> a[i][j];
		}

		int ans = dfs(0, 0, 0);

		if(ans==inf)
			cout << -1;
		else
			cout << ans;
	}
	return 0;
}

Measured memory_bytes: 3656
N=int(input())
ai=list(map(int,input().split()))

sum=0
for i in range(N-1):
    sum += abs(ai[i]-ai[i+1])
sum += abs(0-ai[0])
sum += abs(ai[N-1]-0)

print(sum - abs(0-ai[0]) - abs(ai[0]-ai[1]) + abs(0-ai[1]))

for i in range(N-2):
    m = sum - abs(ai[i]-ai[i+1]) - abs(ai[i+1]-ai[i+2]) + abs(ai[i]-ai[i+2])
    print(m)

print(sum - abs(ai[N-2]-ai[N-1]) - abs(ai[N-1]-0) + abs(ai[N-2]-0))

Measured memory_bytes: 14172
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int result = N/2 * (N-N/2);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    string a, b;
    cin >> a >> b;
    int isA;
    int lenA = a.length(), lenB = b.length();
    if(lenA > lenB) isA = true;
    else if (lenA < lenB) isA = false;
    else{
        bool isEqual = true;
        rep(i,lenA){
            if(a[i] != b[i]){
                isEqual = false;
                if(a[i] < b[i]) isA = false;
                else isA = true;
                break;
            }
        }
        if(isEqual) isA = -1;
    }
    if(isA == 1) cout << "GREATER" << ln;
    else if (isA == 0) cout << "LESS" << ln;
    else cout << "EQUAL" << ln;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc;
	public void run(){
		sc = new Scanner(System.in);
		ArrayList<Integer> n = new ArrayList<Integer>();

		while(sc.hasNextInt()){
			int value = sc.nextInt();
			if(value != 0){
				calc(value);
			}
			else{
				break;
			}
		}
	}
	public void calc(int N){
		int[][] map = new int[21][21];
		for(int i = 0; i < 21; i++){
			for(int j = 0; j < 21; j++){
				map[i][j] = 0;
			}
		}
		for(int i = 0; i < N; i++){
			int x = sc.nextInt();
			int y = sc.nextInt();
			map[x][y] = 1;
		}
		int M = sc.nextInt();
		int x = 10;
		int y = 10;
		map[10][10] = 0;
		for(int i = 0; i < M; i ++){
			String d = sc.next();
			int l = sc.nextInt();
			if(d.equals("N")){
				for(int j = 0; j < l; j++){
					y = y + 1;
					map[x][y] = 0;
				}
			}
			else if(d.equals("E")){
				for(int j = 0; j < l; j++){
					x = x + 1;
					map[x][y] = 0;
				}
			}
			else if(d.equals("S")){
				for(int j = 0; j < l; j++){
					y = y - 1;
					map[x][y] = 0;
				}
			}
			else if(d.equals("W")){
				for(int j = 0; j < l; j++){
					x = x - 1;
					map[x][y] = 0;
				}
			}
		}
		check(map);
	}
	public void check(int[][] map){
		boolean ans = true;
		for(int i = 0; i < 21; i++){
			for(int j = 0; j < 21; j++){
				if(map[i][j] == 1){
					ans = false;
					break;
				}
			}
		}
		if(ans){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 34504
import sys
input=sys.stdin.readline

k=int(input())
if k%7==0:
    k=k//7
if k==1:
    now=0
else:
    now=1
s=now
for i in range(k+100):
    if s==0:
        print(i+1)
        sys.exit()
    now=(now*10)%k
    s+=now
    s=s%k
print(-1)

Measured memory_bytes: 63220
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    String[] str = new String[3];
    for(int i=0;i<3;i++) str[i]=scan.next();
    boolean flag = str[0].charAt(str[0].length()-1) == str[1].charAt(0);
    boolean flag1 = str[1].charAt(str[1].length()-1) ==str[2].charAt(0);
    if(flag & flag1) System.out.println("YES"); else System.out.println("NO");

  }
}


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

string S, T;
void input() {
cin >> S >> T;
}

void solve() {
T.pop_back();
if(S == T) cout << "Yes" << endl;
else cout << "No" << endl;
}

int main() {
input();
solve();
return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <array>
#include <vector>

using namespace std;

template<int mod>
struct Ring_mod {
    int val;
    Ring_mod(): val(0) {}
    Ring_mod(int x)
    {
        x += (x < 0 ? mod : 0);
        x -= (x >= mod ? mod : 0);
        val = x;
    }
    explicit operator int() { return val; }
    Ring_mod operator+(const Ring_mod& b) { return Ring_mod(val + b.val); }
    Ring_mod operator-(const Ring_mod& b) { return Ring_mod(val - b.val); }
    void operator+=(const Ring_mod& b) { val = Ring_mod(val + b.val).val; }
    void operator-=(const Ring_mod& b) { val = Ring_mod(val - b.val).val; }
    Ring_mod operator*(const Ring_mod& b) { return Ring_mod((long long) val * b.val % mod); }
};
typedef Ring_mod<(int) 1e9 + 7> int_mod;

int main()
{
    int n;
    cin >> n;
    vector<vector<int> > adj(n);
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    array<vector<int_mod>, 2> f;
    f.fill(vector<int_mod>(n, 0));
    auto dfs = [&f, &adj](auto& self, int u, int p) -> void {
        f[0][u] = f[1][u] = 1;
        for (int v : adj[u])
            if (v != p) {
                self(self, v, u);
                f[0][u] = f[0][u] * (f[0][v] + f[1][v]);
                f[1][u] = f[1][u] * f[0][v];
            }
    };
    dfs(dfs, 0, 0);
    cout << (int) (f[0][0] + f[1][0]);
    return 0;
}


Measured memory_bytes: 9720
#include<bits/stdc++.h>
using namespace std;
int n;
char a[1200],b[1200];
int main() {
	cin>>a>>b;
	int n=strlen(a);
	for(int i=1;i<=n;i++) {
		int w=a[n-1];
		for(int j=n-1;j>=1;j--)
			a[j]=a[j-1];	
		a[0]=w;
//		cout<<a<<endl;
		bool flag=true;
		for(int i=0;i<n;i++) {
			if(a[i]!=b[i]){	
				flag=false;
				break;
			}
		}
		if(flag==true) {cout<<"Yes\n";return 0;}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
typedef long long int Int;

int main() {
  Int N;
  while(cin >>N && N){
    set<Int> S;
    FOR(i, 1, N) S.insert((i * i) % N);
    vector<Int> v(S.begin(), S.end()), cnt((N - 1) / 2 + 1, 0);
    REP(i, v.size()){
      REP(j, v.size()){
        if(i == j) continue;
        int n = v[i] - v[j];
        if(n < 0) n += N;
        if(n > (N - 1) / 2) n = N - n;
        cnt[n]++;
      }
    }
    FOR(i, 1, cnt.size()) cout <<cnt[i] <<endl;
  }
  return 0;
}

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

const int mod = 1e9 + 7, N = 1e5 + 7;

int x[N], y[N];

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		cin >> x[i];
	}
	for(int i = 1; i <= m; i++) {
		cin >> y[i];
	}
	int ans = 0, p = 0, q = 0;
	for(int i = 1; i < n; i++) {
		p += (i * (n - i) % mod) * (x[i + 1] - x[i]) % mod;
		p %= mod;
	}
	for(int i = 1; i < m; i++) {
		q += (y[i + 1] - y[i]) * (i * (m - i) % mod) % mod;
		q %= mod;
	}
	cout << p * q % mod << endl;
}

Measured memory_bytes: 5184
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
ll _(ll&a , ll b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
    return a;
}
ll dp2[100010],dp3[100010];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);dp2[0]=dp3[0]=1;ll tot=0;
    for(ll i=1;i<100010;i++)
    {
    	dp2[i]=(dp2[i-1]*2)%mod;
    	dp3[i]=(dp3[i-1]*3)%mod;
    }
    string l;cin >> l;
    for (int i = 0; i < l.size(); ++i)
    {
    	if(l[i]=='1')tot++;
    }
    ll ans=0;
    ll d=0;
    for (int i = 0; i < l.size(); ++i)
    {
    	if(l[i]=='1')
    	{
    		_(ans,((dp2[d]%mod)*(dp3[l.size()-i-1]%mod))%mod);
    		d++;
    	}
    }
    cout << (ans+dp2[tot])%mod;
    }

Measured memory_bytes: 2048
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

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

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	for(int N; cin >> N, N;) {
		vector<ll> shine(4001, 0LL);
		queue<int> idx;
		rep(i,N) {
			int num;
			ll a, b;
			cin >> num >> a >> b;
			if(shine[num] == 0) {
				shine[num] = a * b;
				idx.push(num);
			} else {
				shine[num] += a * b;
			}
		}
		bool f = false;
		while(!idx.empty()) {
			int t = idx.front(); idx.pop();
			if(shine[t] >= 1000000LL) {
				cout << t << endl;
				f = true;
			}
		}
		if(!f) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
// atcoder/abc056/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

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

  int w, a, b;
  while (cin >> w >> a >> b) {
    unless (a < b) swap(a, b);
    cout << max(0, b-(a+w)) << endl;
  }

  return 0;
}


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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    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;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    int N=in();
    int M=in();
    int a,b;
    vector<int> from1;
    vector<int> toN;
    REP(i,M){
        cin>>a>>b;
        if(a==1){
            from1.push_back(b);
        }else if(b==N){
            toN.push_back(a);
        }
    }
    sort(from1.begin(),from1.end());
    sort(toN.begin(),toN.end());
    int k;k=0;
    REP(i,from1.size()){
        for(int j=k;j<toN.size();j++){
            if(from1[i]==toN[j]){
                print("POSSIBLE");
                return 0;
            }
            if(from1[i]<toN[j]){
                k=j;
                break;
            }
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;

}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t; int n, m;
    cin >> s >> t;
    n = s.length(); m = t.length();
    string dps[n][m];
    int dp[n][m];
    char dpc[n][m];
    dp[n-1][m-1] = s[n-1] == t[m-1] ? 1 : 0;
    dpc[n-1][m-1] = s[n-1] == t[m-1] ? s[n-1] : '\0';
    for (int j = m-2; j >= 0; j--) {
        if(s[n-1] == t[j]) {
            dp[n-1][j] = 1;
            dpc[n-1][j] = s[n-1];
        }
        else {
            dp[n-1][j] = dp[n-1][j+1];
            dpc[n-1][j] = dpc[n-1][j+1];
        }
    }
    for(int i = n-2; i >= 0; i--) {
        if(s[i] == t[m-1]) {
            dp[i][m-1] = 1;
            dpc[i][m-1] = t[m-1];
        }
        else {
            dp[i][m-1] = dp[i+1][m-1];
            dpc[i][m-1] = dpc[i+1][m-1];
        }
        for (int j = m-2; j >= 0; j--) {
            if(s[i] == t[j]) {
                dp[i][j] = 1 + dp[i+1][j+1];
                dpc[i][j] = s[i];
            }
            else if(dp[i][j+1] > dp[i+1][j]){
                dp[i][j] = dp[i][j+1];
                dpc[i][j] = dpc[i][j+1];
            }
            else {
                dp[i][j] = dp[i+1][j];
                dpc[i][j] = dpc[i+1][j];
            }
        }
    }
    int i = 0, j = 0;
    for(int l = 0; l < dp[0][0]; l++) {
        char ch = dpc[i][j];
        while(s[i] != ch)
            i++;
        while(t[j] != ch)
            j++;
        cout << ch;
        i++, j++;
    }
    return 0;
}


Measured memory_bytes: 114560
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int i =	sc.nextInt();
	if(i == 1) {
            System.out.println("Hello World");
        }else {
            System.out.println(sc.nextInt()+sc.nextInt());
	}
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mp(p1,p2) make_pair(p1,p2)
#define mod 1000000007
#define PI 3.14159265358979323846
#define pii pair<ll ,ll>
using namespace std;
#define fast                                                                   \
 ios_base::sync_with_stdio(false);                                            \
 cin.tie(NULL);                                                               \
 cout.tie(NULL);
 
 
int main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
   fast
   ll n;
   cin >> n;
   cout << (n-2)*180;
   
   return 0;
}

Measured memory_bytes: 256
#                         author:  kagemeka 
#                         created: 2019-11-07 13:09:56(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    *n, k = (int(x) for x in sys.stdin.read().split())
    n.sort()
    total = n[0] + n[1] + n[2] * 2 ** k
    print(total)


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000
#define nil -1
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);

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

    int n;
    cin>>n;
    ll ans=0;
    vector<int> a(n,0);
    rep(i,n) {
        cin>>a[i];
    }
    SORT(a);
    if(n%2==0){
        for(int i=0;i<n/2-1;i++){
            ans-=2*a[i];
        }
        ans+=a[n/2]-a[n/2-1];
        for(int i=n/2+1;i<n;i++){
            ans+=2*a[i];
        }
    }else{
        ll temp1=0,temp2=0;
        for(int i=0;i<n/2;i++){
            temp1-=2*a[i];
        }
        temp1+=a[n/2]+a[n/2+1];
        for(int i=n/2+2;i<n;i++){
            temp1+=2*a[i];
        }
        for(int i=0;i<n/2-1;i++){
            temp2-=2*a[i];
        }
        temp2-=a[n/2-1]+a[n/2];
        for(int i=n/2+1;i<n;i++){
            temp2+=2*a[i];
        }
        ans=max(temp1,temp2);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 640
import random


class Dice(object):
    def __init__(self):
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6

    def __init__(self, faces):
        self.t = faces[0]
        self.s = faces[1]
        self.e = faces[2]
        self.w = faces[3]
        self.n = faces[4]
        self.b = faces[5]

    def roll(self, direct):
        if direct == 0:
            self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
        elif direct == 1:
            self.t, self.w, self.b, self.e = self.e, self.t, self.w, self.b
        elif direct == 2:
            self.n, self.w, self.s, self.e = self.w, self.s, self.e, self.n

    def is_equal(self, dice):
        if self.t == dice.t and self.s == dice.s and self.e == dice.e and self.w == dice.w and self.n == dice.n and self.b == dice.b:
            return True
        else:
            return False

faces1 = list(map(int, input().split()))
dice1 = Dice(faces1)
faces2 = list(map(int, input().split()))
dice2 = Dice(faces2)

flag = False

for i in range(10000):
    dice2.roll(random.randint(0, 3))
    if dice1.is_equal(dice2):
        flag = True
        break

if flag:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 8184
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
     ll x,r,d;
     cin>>r>>d>>x;
     for(int i=0;i<10;i++){
        ll cur=x*r - d;
        cout<<cur<<endl;
        x=cur;
     }

    return 0;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	string X;
	cin >> X;

	stack<char> s;

	for (int ii = 0; ii < X.size(); ++ii){
		if (s.empty()){
			s.push(X[ii]);
		} else if ( (s.top() == 'S') && (X[ii] == 'T') ){
			s.pop();
		} else {
			s.push(X[ii]);
		}
	}

	int ans = (s.empty()) ? 0 : s.size();

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 644
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] l = new Integer[n];
		for(int i=0;i<n;i++) {
			l[i] = sc.nextInt();
		}
		sc.close();
		
		Arrays.sort(l,Comparator.reverseOrder());
		int ans = 0;
		int k=0;
		
		for(int i=0;i<n-2;i++) {
			for(int j=i+1; j<n-1;j++) {
				for(k=j+1; k<n; k++) {
					if(l[i] < l[j]+l[k]) {
						ans++;
					}else {
						break;
					}
				}
				if(k==j+1) {
					break;
				}
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 25880
#include<iostream>
#include<string>
using namespace std;
string S;
int sum[2][100000],res[100000]={0};
bool s[100000];//R:true,L:false

int route(int g,int n,int p){
	int dir;
	
	if(s[n])dir=1;
	else dir=-1;
	
	if(n+dir==p){
		if(g==0)sum[g][n]=n;
		else sum[g][n]=p;
		return sum[g][n];
	}else{
		if(sum[1-g][n+dir]<0)sum[1-g][n+dir]=route(1-g,n+dir,n);
		return sum[1-g][n+dir];
	}
}
int main(){
	cin>>S;
	for(int i=0;i<S.length();i++){
		s[i]=(S[i]=='R');
		sum[0][i]=sum[1][i]=-1;
	}
	for(int i=0;i<S.length();i++){
		sum[0][i]=route(0,i,-1);
		res[sum[0][i]]++;
	}
	for(int i=0;i<S.length();i++){
		cout<<res[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 3072
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

class person{
public:
  person(int d, int t, int i){difficulty = d; time = t; index = i;};
  int difficulty;
  int time;
  int index;

  const bool operator <(person arg) const{
    if(time == arg.time){
      return difficulty < arg.difficulty;
    }else{
      return time < arg.time;
    }
  }
};

int main(void){
  int n,m;

  while(cin >> n >> m){
    if((n|m) == 0) break;
    vector<person> v;
    int tmp;
    int mintime;
    int minindex;
    for(int i=0;i<n;i++){
      cin >> tmp;
      v.PB(person(tmp,m/tmp*tmp,i));
    }
    /*
    v[0].time = (m / v[0].difficulty) * v[0].difficulty;
    mintime = v[0].time;
    minindex = 0;
    //dump(v[0].time);
    for(int i=1;i<n;i++){
      //±êÜÅÌÅ¬Æ¯êÉÅ«é
      if(mintime % v[i].difficulty == 0){
	//±êÜÅÌÅ¬Æ¯¶É·é
	if(v[minindex].difficulty <= v[i].difficulty){
	  v[i].time = mintime;
	}else{
	  //â¹éÈçâ·
	  if(mintime + v[i].difficulty <= m){
	    v[i].time = mintime + v[i].difficulty;
	  }else{
	    v[i].time = mintime;
	  }
	}
      }else{
	//z¦çêéê
	if(((mintime / v[i].difficulty) + 1) * v[i].difficulty <= m){
	  v[i].time = ((mintime / v[i].difficulty) + 1) * v[i].difficulty;
	}else{
	  v[i].time = (mintime / v[i].difficulty) * v[i].difficulty;
	}
      }
      if(mintime >= v[i].time){
	mintime = v[i].time;
	if(mintime > v[i].time){
	  minindex = i;
	}else if(v[minindex].difficulty > v[i].difficulty){
	  minindex = i;
	}
      }
      //dump(i)dump(v[i].time);
    }
    */
    sort(v.begin(),v.end());

    if(v[0].time != v[1].time){
      cout << v[0].index + 1 << endl;
    }else if(v[0].difficulty != v[1].difficulty){
      cout << v[0].index + 1 << endl;
    }else{
      cout << n << endl;
    }
  }
}

Measured memory_bytes: 0
#include<stdio.h>
main(){
    
    int a,b,c,x,n=0;
    scanf("%d %d %d %d", &a,&b,&c,&x);{
    for(int x = a; x < b+1; x++)
        if(c%x==0) n++;
        printf("%d\n",n);}
    return 0;
}
    


Measured memory_bytes: 2088
#include<iostream>

int main(){
    int n;
    
    std::cin>>n;
    
    for(int i=1;i<=n;i++){
        
        int test1=i%3;
        int test2=i%10;
        int test3=(i/10)%10;
        int test4=(i/100)%10;
        int test5=(i/1000)%10;
        
        if(test1==0 || test2==3 ||test3==3 ||test4==3 ||test5==3){
            std::cout << " " << i;
        }
    }
    std::cout<<std::endl;
    return 0;
}


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

int main(){
    double dp[3][3][16];//[x][y][n]
    char s,t,b;
    int n;
    int dx[]={-1,0,1,0};
    int dy[]={0,1,0,-1};
    cout.precision(8);
    cout << fixed;
    while(cin>>n,n){
        fill(dp[0][0],dp[3][0],0);
        cin>>s>>t>>b;
        s-='A';
        t-='A';
        b-='A';
        dp[s%3][s/3][n]=1;
        for(;n>0;n--){
            for(int x=0;x<3;x++){
                for(int y=0;y<3;y++){
                    for(int i=0;i<4;i++){
                        if((0<=x+dx[i]&&x+dx[i]<3)&&(0<=y+dy[i]&&y+dy[i]<3)&&!((x+dx[i])==(b%3)&&(y+dy[i])==(b/3))){
                            dp[x+dx[i]][y+dy[i]][n-1]+=dp[x][y][n]/4;
                        }else{
                            dp[x][y][n-1]+=dp[x][y][n]/4;
                        }
                    }
                }
            }
        }
        cout << dp[t%3][t/3][0] << endl;
    }
    return 0;
}

Measured memory_bytes: 3188
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstring>
#include <iomanip>
#include <utility>
#include <iostream>
#include <algorithm>

using namespace std;
const int N = 3e5 + 5;

int n, a[N];
long long ans;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n;
	n *= 3;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a, a + n);

	for (int i = n / 3; i < n; i += 2) {
		ans += a[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408