akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <stdio.h>


int main()
{
    int n, m;
    std::multiset<int> set;
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i) {
        int x;
        scanf("%d", &x);
        set.emplace(x);
    }
    scanf("%d", &m);
    for (int i = 0; i < m; ++ i) {
        int x;
        scanf("%d", &x);
        auto it = set.find(x);
        if (it == set.end())
            return puts("NO"), 0;
        set.erase(it);
    }
    puts("YES");
}


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

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

    int num_black = 0;
    int num_white = 0;

    //最初を黒にする場合
    for(int i = 0; i < S.size(); i++) {

        //偶数番目
        if(i % 2 == 1) {
            // blackだった場合
            if(S[i] == '0') {
                num_black++;
            }else{
                num_white++;
            }
            //奇数番目
        } else {
            if(S[i] == '1') {
                num_black++;
            }else{
                num_white++;
            }
        }
    }

    if (num_black < num_white){
        cout << num_black << endl;
    }else{
        cout << num_white << endl;
    }

}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int n,a,b,c,d,x,y;
	scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
	x=n/a;
	y=n/c;
	if(n%a!=0) {
		x++;
	}
	if(n%c!=0) {
		y++;
	}
	if(x*b<y*d) {
		printf("%d\n",x*b);
	}
	else {
		printf("%d\n",y*d);
	}
	return 0;
}
	
		


Measured memory_bytes: 2756
# return x where
#   (when trueside<falseside)
#     [trueside,falseside) and yield(x)==true and (yield(x+tol)==false or falseside <= x+tol)
#   (when falseside<trueside)
#     (falseside,trueside] and yield(x)==true and (yield(x-tol)==false or x-tol <= falseside) 
# if trueside and falseside and tol is integer then do integer binary search
# note: neither yield(trueside) nor yield(falseside) were not called
def bsearch(trueside,falseside,tol=10**(-9))
  ok,ng=trueside,falseside
  div=2
  while((ok-ng).abs>tol) do
      mid=(ng+ok)/div
      if(yield(mid))
          ok=mid
      else
          ng=mid
      end
  end
  return ok
end


def solve(a,b)
  target=a*b

  temp=bsearch(0,2*10**9+1,tol=1){|x|
    if x%2==0
      next (x/2)**2<=target
    else
      next (x/2)*(x/2+1)<target
    end
  }
  if (temp/2)**2==target
    if a==b
      return temp-2
    else
      return temp-3
    end
  end
  return temp-2
end

N=gets.to_i
ans=[]
N.times do
  ans << solve(*(gets.split.map(&:to_i)))
end
puts ans

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


def fac(n):
    att = []
    t = n
    for i in range(2, int(-(-n ** 0.5 // 1) + 1)):
        while (t % i == 0):
            t //= i
            att += [i]
    if t > 1:
        att += [t]
    return att


def lnum(m):
    return len(list(filter(lambda x: memo[x] >= m - 1, memo)))


memo = {}
for i in range(2, N + 1):
    fl = fac(i)
    for f in fl:
        if f in memo:
            memo[f] += 1
        else:
            memo[f] = 1
s = []
for m in memo:
    if memo[m] == 1:
        continue
    s += [memo[m] + 1]
ans = lnum(75) + lnum(25) * (lnum(3) - 1) + lnum(15) * (lnum(5) - 1) \
    + lnum(5) * (lnum(5) - 1) // 2 * (lnum(3) - 2)
print(ans)


Measured memory_bytes: 38384
using System;
using System.Linq;
using System.Collections.Generic;
 
public class Program{
    public static void Main(){
        int N=int.Parse(Console.ReadLine());
        string[] s=new string[N];
        long ans=0;
        var dict = new Dictionary<string, int>();
        for(int i=0;i<N;i++){
            char[] a=Console.ReadLine().ToCharArray();
            Array.Sort(a);
            s[i]=new String(a);
            if(dict.ContainsKey(s[i])){
                ans+=dict[s[i]];
                dict[s[i]]++;
            }else{
                dict.Add(s[i],1);
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 32088
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int formula();
void input();  // 終了処理有り
void chkRPar();
int expression();
int calcPlus(int, int);
int calcMul(int, int);

char ch;
int pos;
string str;
int P, Q, R;
int nFlg = 1;  // 1 or -1 をformulaに掛ける。VARIABLEが来て初期化 1

int main(void) {
  int cnt, res;

  while(1) {
    cnt = 0;
    getline(cin, str);
    //cout << str << endl;
    for(P = 0; P < 3; P++) {
      for(Q = 0; Q < 3; Q++) {
	for(R = 0; R < 3; R++) {
	  pos = 0;
	  res = expression();
	  if(res == -1) return 0;
	  if(res == 2) cnt++;
	}
      }
    }

    cout << cnt << endl;
  }

  return 0;
}

void chkRPar() {
  input();
}
void input() {
  ch = str[pos++];
  // cout << "---" << ch << endl;
}

int expression() {
  int res = 0;
  
  input();
  if (ch == '.') return -1;

  switch (ch) {
  case '(':
    res = expression();
    input();
    switch(ch) {
    case '+':
      res = calcPlus(res, expression());
      break;
    case '*':
      res = calcMul(res, expression());
      break;
    }
    chkRPar();
    break;

  default:
    switch(ch) {
    case '-':
      res = 2 - expression();
      break;
    default:
      res = formula();
    }
    break;
  }

  return res;
}

int formula() {

  if(isdigit(ch)) return ch - '0';

  switch(ch) {
  case 'P': return P;
  case 'Q': return Q;
  case 'R': return R;
  }
}

int calcPlus(int d1, int d2) {
  switch(d1) {
  case 0:
    switch(d2) {
    case 0: return 0;
    case 1: return 1;
    case 2: return 2;
    }

  case 1:
    switch(d2) {
    case 0: return 1;
    case 1: return 1;
    case 2: return 2;
    }

  case 2:
    switch(d2) {
    case 0: return 2;
    case 1: return 2;
    case 2: return 2;
    }
  }
}

int calcMul(int d1, int d2) {
  switch(d1) {
  case 0:
    switch(d2) {
    case 0: return 0;
    case 1: return 0;
    case 2: return 0;
    }

  case 1:
    switch(d2) {
    case 0: return 0;
    case 1: return 1;
    case 2: return 1;
    }

  case 2:
    switch(d2) {
    case 0: return 0;
    case 1: return 1;
    case 2: return 2;
    }
  }
}

Measured memory_bytes: 1176
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<pair<int,int>> vip;

#define ZOOM ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define loop for(auto i=0;i<n;++i)
#define LOOP_IT(s) for(auto it=(s).begin();it!=(s).end();++it)

pair<ll,ll> func(ll x)
{
    ll a = x%10;
    ll b=0;
    while(x)
    {
        b = x;
        x/=10;
    }
    return {b,a};
}
int main(int argc,char* argv[])
{
    ZOOM

    ll n;
    ll ans = 0;
    cin>>n;
    map<pair<ll,ll> , ll> m;

    for(ll i=1;i<=n;++i)
    {
        ++m[func(i)];
    }



    for(ll i=1;i<10;++i)
        for(ll j=1;j<10;++j)
        {
            ans+=(m[{i,j}]*m[{j,i}]);
        }





    cout<<ans;

    return 0;
}


Measured memory_bytes: 256
local n, m = io.read("*n", "*n")
local edge = {}
for i = 1, n do edge[i] = {} end
for i = 1, m do
  local a, b, c = io.read("*n", "*n", "*n")
  edge[a][b] = c
end

local taskstate = {}
for i = 1, n do taskstate[i] = false end
local tasks = {}
local tasknum = 0
local done = 0
local tasklim = n + 1
local updatecount = 0
local len = {}
for i = 1, n do len[i] = -1000000000000 end
len[1] = 0
local function addtask(idx)
  if(not taskstate[idx]) then
    taskstate[idx] = true
    tasknum = tasknum + 1
    local taskidx = tasknum % tasklim
    if taskidx == 0 then taskidx = tasklim end
    tasks[taskidx] = idx
    if idx == n then
      updatecount = updatecount + 1
      if n + 2 < updatecount then
        return false
      end
    end
  end
  return true
end
addtask(1)

local ret = true
while(done < tasknum) do
  done = done + 1
  local taskidx = done % tasklim
  if(taskidx == 0) then taskidx = tasklim end
  local src = tasks[taskidx]
  taskstate[src] = false

  for dst, cost in pairs(edge[src]) do
    if len[dst] < len[src] + cost then
      len[dst] = len[src] + cost
      ret = addtask(dst) and ret
    end
  end
  if not ret then break end
  if 5000000 < done then break end
end
if ret then
  print(len[n])
else
  print("inf")
end


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

int main() {
    long a,b,c,d;
    long AC,AD,BC,BD;
    cin >> a >> b >> c >> d;
    AC = a*c;
    AD = a*d;
    BC = b*c;
    BD = b*d;
    cout << max({AC,AD,BC,BD}) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    string s;
    cin >> s;
    ll n = s.size();

    if(s[n-1] == 's') {
        out(s + "es");
    }
    else {
        out(s + "s");
    }
    
    re0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <numeric>

using namespace std;

int main() {
    int n, k, s = 0;
    scanf("%d%d", &n, &k);
    vector<int> a(n);
    set<int> c;
    for (int i = 0; i < n; ++i) scanf("%d", &a.at(i)), s += a.at(i);
    for (int i = 1; i * i <= s; ++i) if (s % i == 0) c.insert(i), c.insert(s / i);
    for (auto d = c.rbegin(); d != c.rend(); ++d) {
        int q = 0;
        vector<int> b = a;
        for (int i = 0; i < n; ++i) q += b.at(i) / *d, b.at(i) %= *d, b.at(i) = *d - b.at(i);
        sort(b.begin(), b.end());
        if (accumulate(b.begin(), b.begin() + (s / *d - q), 0) <= k) {
            printf("%d\n", *d);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

//-------------------------------------------------------------------
int M=1;
std::vector<int> seg;
void init(int N){
  while(M<N) M*=2;
  M=M*2-1;
  for(int i=0;i<M;i++) {
    seg.push_back(0);
  }
}
void update(ll k){
  k += (M+1)/2-1;
  seg[k] ++;
  while(k>0){
    k = (k-1)/2;
    seg[k] = seg[k*2+1] + seg[k*2+2];
  }
}
ll query(ll a, ll b, ll l, ll r, ll k){
  if(r<=a || b <= l) return 0;
  if(a<=l && r<=b) return seg[k];
  else{
    ll le = query(a, b, l, (l+r)/2, k*2+1);
    ll ri = query(a, b, (l+r)/2, r, k*2+2);
    return le + ri;
  }
}
//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  ll N;
  std::cin >> N;
  init(N+200000);
  std::vector<ll> A(N), check(N, 0), A_sum(N, 0);
  for(int i=0;i<N;i++) std::cin >> A[i];
  ll r=100000000000000, l=0;
  ll las_size = N*(N+1)/2;
  while(r - l > 1){
    ll ans = 0;
    ll mid = (r+l)/2;
    for(int i=0;i<seg.size();i++) seg[i]=0;
    for(int i=0;i<N;i++) {
      check[i]=(A[i]<mid?-1:1);
      A_sum[i] = (i==0?check[i]:A_sum[i-1]+check[i]);
      //std::cout << A_sum[i] << '\n';
      ans += query(0, A_sum[i]+200001, 0, (M+1)/2, 0);
      update(A_sum[i]+200000);
      if(A_sum[i]>=0) ans++;
    }
    //std::cout << ans << '\n';
    if(ans >= las_size/2 + (las_size%2==1?1:0)) l = mid;
    else r = mid;
    //std::cout << l << " " << r << '\n';
  }
  std::cout << l << '\n';
  return 0;
}


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

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for (int i=1,x;i<=n;i++) scanf("%d",&x);
	int ans=1; n-=k;
	ans+=(n%(k-1)==0?n/(k-1):n/(k-1)+1);
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int w, a, b;
  cin >> w >> a >> b;
  if ((b <= a && a <= b + w) || (a <= b && b <= a + w)) {
    cout << 0 << endl;
  } else {
    cout << min(abs(b - a - w), abs(b + w - a)) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>                                                                                                    
#include <algorithm>
   #include <iostream>
   #include <string>
   #include <vector>
   #include <numeric>
   using namespace std;
  
   int main(){
    int n,cost,sum,max = 0;
    vector<int> cost_;
    cin >> n;
    for(int i = 0; i < n;i++){
      cin >> cost;
      if(max < cost) max = cost;
      cost_.push_back(cost);
    }
    sum = accumulate(cost_.begin(),cost_.end(),0);
    sum -= max/2;
    cout << sum << endl;
    return 0;
  }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>
#include <queue>

using namespace std;

#define INF (1 << 30)
typedef pair<int, int> P;

map<int, int> G[101];

int dijkstra(int from, int to) {
	priority_queue<P, vector<P>, greater<P>> que;
	bool used[101] = { false };
	que.push(P(0, from));
	while (!que.empty()) {
		P t = que.top();
		que.pop();

		if (t.second == to)
			return t.first;
		if (used[t.second])
			continue;
		used[t.second] = true;

		for (auto it = G[t.second].begin(); it != G[t.second].end(); ++it) {
			que.push(P(t.first + it->second, it->first));
		}
	}
	return -1;
}

int main() {
	int n, k, t, c, d, e;

	while (cin >> n >> k && n != 0) {
		for (int i = 1; i <= n; ++i)
			G[i].clear();

		while (k--) {
			cin >> t;
			if (t) {
				cin >> c >> d >> e;
				if (G[c][d] == 0) G[c][d] = INF;
				if (G[d][c] == 0) G[d][c] = INF;
				G[c][d] = min(G[c][d], e);
				G[d][c] = min(G[d][c], e);
			}
			else {
				cin >> c >> d;
				cout << dijkstra(c, d) << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> p(n);
	for(int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	
	int ans = 0;
	for(int i = 0; i < n - 2; ++i) {
		if( p[i] < p[i + 1] && p[i + 1] < p[i + 2] ) ans++;
		if( p[i] > p[i + 1] && p[i + 1] > p[i + 2] ) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
# ABC073D - joisino's travel
from heapq import heapify, heappop, heappush
from itertools import permutations


def dijkstra(G: "Array[Array[int]]", size: int, start: int) -> list:
    dist = [1 << 30] * size
    unchecked = size - 1  # vertex_0 won't appear in 1-idx graph
    queue = [(0, start)]
    heapify(queue)
    while queue:
        cost, v = heappop(queue)
        if cost > dist[v]:
            continue
        dist[v] = cost
        for next_cost, u in G[v]:
            if cost + next_cost < dist[u]:
                heappush(queue, (cost + next_cost, u))
        unchecked -= 1
        if not unchecked:
            return dist


def main():
    global G, N
    N, M, R, *RABC = map(int, open(0).read().split())
    visit, ABC = RABC[:R], RABC[R:]
    G = [[] for _ in range(N + 1)]
    for v, u, cost in zip(*[iter(ABC)] * 3):
        G[v].append((cost, u)), G[u].append((cost, v))
    dist = {v: dijkstra(G, N + 1, v) for v in visit}
    ans = 1 << 60
    for perm in permutations(visit):
        cur = sum(dist[v][u] for v, u in zip(perm, perm[1:]))
        ans = min(ans, cur)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9832
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n,l;
    cin >> n >>l;
    string arr[105];
    for(int i =0;i<n;++i)
        cin >> arr[i];
    sort(arr, arr+n);
    for(int i =0;i<n;++i)
        cout << arr[i];
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n){
    cin >> a[i];
    b[i]=a[i];
  }
  sort(all(b));
  int x=b[n/2-1];
  int y=b[n/2];
  rep(i,n){
    if(a[i]<=x) cout << y << endl;
    else cout << x << endl;
  }
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() { IO;
  int n, a, b;
  cin >> n >> a >> b;

  int diff = abs(a - b);
  if (diff % 2 == 0) {
    cout << "Alice" << endl;
  } else {
    cout << "Borys" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
def abc176c_step():
    n = int(input())
    a = list(map(int, input().split()))
    total = 0
    max_val = a[0]
    for v in a:
        if v <= max_val:
            total += max_val - v
        else:
            max_val = v
    print(total)

abc176c_step()

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

#import
#import math
#import numpy as np
N, M, K = map(int, input().split())

for i in range(N + 1):
    for j in range(M + 1):
        k = i * M + j * N - i * j * 2
        if k == K:
            print("Yes")
            exit()

print("No")


Measured memory_bytes: 8904
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		//変数
		int count=0;
		boolean sw=false;
		int answer=0;
		//long answer=0;
		//double answer=0;
		//String answer="NO";
		//List<Integer> h=new ArrayList<Integer>();
		//int af=Integer.MAX_VALUE;
		int L=0;
		//int sub=0;
		int a=0;
		int b=0;
		//int t[]=new int[(int)Math.pow(10,5)];
		
		//入力
		Scanner sc = new Scanner(System.in);
		a=sc.nextInt();
		b=sc.nextInt();
		//X=sc.nextDouble();
		//int A[]=new int[L];
		//for(int i=0;i<L;i++)
		//{
		//	A[i]=sc.nextInt();
		//}
		//String S=sc.next();
		
		//処理
		if(b%a==0)
		{
			answer=a+b;
		}else
		{
			answer=b-a;
		}
		// 出力
		//System.out.println(Arrays.toString(X))
		//System.out.println(Arrays.deepToString(td));
		System.out.println(answer);
	}
}

Measured memory_bytes: 23252
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    S1 = readline().rstrip()
    S2 = readline().rstrip()
    if S1[0] == S2[0]:
        cnt = 3
        i = 1
        pre = 'x'
    else:
        cnt = 6
        i = 2
        pre = 'y'
    while i < N:
        if S1[i] == S2[i]:
            next = 'x'
        else:
            next = 'y'
        if pre == next == 'x':
            cnt *= 2
            i += 1
        elif pre == next == 'y':
            cnt *= 3
            i += 2
        elif pre == 'x' and next == 'y':
            cnt *= 2
            i += 2
        else:
            i += 1
        pre = next

    print(cnt % MOD)


if __name__ == '__main__':
    main()

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

string repeat(int n, string s) {
    string res = "";
    for (int i=0; i<n; ++i)
        res += s;
    return res;
}

int main() {
    int N; cin >> N;
    for (int i=0; i<N; ++i) {
        string snake; cin >> snake;

        int len = snake.size();
        if (len <= 4) {
            cout << "NA" << endl;
            continue;
        }

        string A = ">'" + repeat((len - 4)/2, "=") 
                    + "#" + repeat((len - 4)/2, "=") + "~";
        string B = ">^" + repeat((len - 4)/2, "Q=") + "~~";

        if (snake == A) {
            cout << "A" << endl;
        } else if (snake == B) {
            cout << "B" << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1216
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res;
	long N; cin >> N;
	long A[100009]; for (int i = 0; i < N; i++) cin >> A[i];

	long absum = 0, pmin = INT_MAX, nmax = INT_MIN, countn = 0;

	for (int i = 0; i < N; i++) {
		absum += abs(A[i]);
		if (A[i] >= 0) pmin = min(pmin, A[i]); else { nmax = max(nmax, A[i]); countn++; }
	}

	res = (countn % 2 == 0) ? absum : absum - 2 * min(abs(pmin), abs(nmax));

	cout << res << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr))
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
bool find(int num){
   
   int curr = num%10;
   while(num){
       
       int d = num%10;
       if(abs(d - curr)>1){
           return false;
       }
       curr =d;
       num/=10;
       
   }
   return true;
   
   
}
int finds(int num){
   int ind = -1;
   int curr = num%10;
   while(num){
       
      
       int d = num%10;
       if(abs(d - curr)>1){
           return ind;
       }
        ind++;
       curr =d;
       num/=10;
       
   }
   return ind;
   
   
}
string to_String(int n){
    string s="";
    while(n){
        char r  = n%10+'0';
        s = r+s;
        n/=10;
    }
    return s;
}
int findnum(string s){
    int num = 0;
    for(int i =0  ; i < s.size() ; i++)
    {
        num = num*10  +s[i]-'0'; 
    }
    return num;
}
int32_t main(){
         vi v;
        int i =0 ;
        int itr = 0;
        while(v.size()<=1e5){
            
            itr++;
                int num = i;
                if(find(num))
                    {
                        v.pb(num);
                    }
                else{
                    int d = finds(num);
                    
                    string s = to_String(num);
                    
                    for(int j= s.size()-1 ; j>=0 ;j--){
                          d--;
                        if(d < 0)
                            break;
                        s[j] = '9';
                      
                    }
                    // cout<<s<<endl;
                    int num = findnum(s);
                    i = num ;
                }
                
            // cout<<i<<" ";    
            i++;
            // cout<<i<<endl;
        }
   
    
    int t;
    cin>>t;
    cout<<v[t]<<endl;
        
    
}

Measured memory_bytes: 1400
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  rrep(i, 1, n + 1) {
    cnt += i;
    ans += cnt;
  }
  rep(i, n - 1) {
    cin >> a >> b;
    if (b < a) swap(a, b);
    ll minus;
    minus = a * (n - b + 1);
    ans -= minus;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 3612
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 6010;
int n, mod;
int f[N], invf[N], p3[N], p2[N], p1[N];
int binpow(int x, int y, int mod){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        x = x * x % mod;
        y /= 2;
    }
    return res;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt", "r", stdin);
    cin >> n >> mod;
    f[0] = invf[0] = 1;
    for (int i = 1; i <= 3 * n; i++) f[i] = f[i - 1] * i % mod;
    for (int i = 1; i <= 3 * n; i++) invf[i] = binpow(f[i], mod - 2, mod);
    for (int i = 0; i <= 3 * n; i++){
        p3[i] = binpow(invf[3], i, mod);
        p2[i] = binpow(invf[2], i, mod);
        p1[i] = binpow(2, i, mod);
    }
    int ans = 0;
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= n - i && 2 * j + 3 * i <= 3 * n; j++){
            int x = invf[i] * invf[j] % mod;
            ans = (ans + x * f[3 * n] % mod * p3[i] % mod * p2[j] % mod * invf[3 * n - 2 * j - 3 * i] % mod * p1[i]) % mod;
        }
    }
    cout << ans;
}


Measured memory_bytes: 512
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M:
    print(0)
else:
    X.sort()
    X_div = [0] * (M-1)
    for i in range(1,M):
        X_div[i-1] = X[i] - X[i-1]
    X_div.sort(reverse=True)
    m = 0
    for i in range(N-1):
        m += X_div[i]
    print(X[-1]-X[0]-m)


Measured memory_bytes: 13968
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N, K, L = MI()
    # UnionFind
    class UnionFind():
        def __init__(self, n):
            self.nodes=[-1] * n  # nodes[x]: 負なら、絶対値が木の要素数

        def get_root(self, x):
            # nodes[x]が負ならxが根
            if self.nodes[x] < 0:
                return x
            # 根に直接つなぎ直しつつ、親を再帰的に探す
            else:
                self.nodes[x]=self.get_root(self.nodes[x])
                return self.nodes[x]

        def unite(self, x, y):
            root_x=self.get_root(x)
            root_y=self.get_root(y)
            # 根が同じなら変わらない
            # if root_x == root_y:
            # pass
            if root_x != root_y:
                # 大きい木の方につないだほうが計算量が減る
                if self.nodes[root_x] < self.nodes[root_y]:
                    big_root=root_x
                    small_root=root_y
                else:
                    small_root=root_x
                    big_root=root_y
                self.nodes[big_root] += self.nodes[small_root]
                self.nodes[small_root]=big_root
            
        def same(self,x,y):
            return self.get_root(x)==self.get_root(y)
    uf1=UnionFind(N)
    uf2 = UnionFind(N)
    uf_both = UnionFind(N)
    for _ in range(K):
        p, q = MI_()
        uf1.unite(p, q)
        
    for _ in range(L):
        r, s = MI_()
        uf2.unite(r, s)

    cnt = defaultdict(int)    
    A = [-1]*N
    B = [-1]*N
    for i in range(N):
        A[i] = uf1.get_root(i)
        B[i] = uf2.get_root(i)
        cnt[A[i],B[i]] += 1
    
    print(*[cnt[A[i],B[i]] for i in range(N)] )


if __name__ == '__main__':
    main()

Measured memory_bytes: 46164
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long mod = 1e9 + 7;

string s, t;
void solve(){
    int n = s.length(), m = t.length();
    int i = 0, j = 0;
    int ans = n + 5;
    for(i = 0; i <= n - m; i++){
        int c = 0;
        for(j = 0; j < m; j++){
            if(s[i + j] != t[j])
                c++;
        }
        ans = min(ans, c);
    }
    cout << ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s >> t;
    solve();
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <algorithm>
 
using namespace std;
 
#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
 
typedef long long ll;
 
const int MOD = 1000000007;
const int INF = 1000000007;
const ll INFLL = 1000000000000000007LL;
 
ll extgcd(int a, int b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll d = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
 
void cmbmod_init(int n, vector<ll> &finv) {
  ll x, y;
  for (int i = 2; i <= n; i++) {
    extgcd(i, MOD, x, y);
    finv[i] = finv[i - 1] * (MOD + x % MOD) % MOD;
  }
}
 
ll modpow(ll a, ll n) {
  a %= MOD;
  if (n == 0) return 1;
  if (n % 2 == 1) return a * modpow(a, n - 1) % MOD;
  ll ret = modpow(a, n / 2);
  ret = sqr(ret) % MOD;
  return ret;
}
 
void solve() {
  int n, a, b;
  cin >> n >> a >> b;
  ll suba = 1, subb = 1, tmpn = n;
  vector<ll> finv(max(a, b) + 1, 1);
  cmbmod_init(max(a, b), finv);
  for (int i = 0; i < a; i++) {
    suba = suba * (tmpn--) % MOD;
  }
  suba = suba * finv[a] % MOD;
  tmpn = n;
  for (int i = 0; i < b; i++) {
    subb = subb * (tmpn--) % MOD;
  }
  subb = subb * finv[b] % MOD;
  cout << (modpow(2, n) - suba - subb - 1 +  2 * MOD) % MOD << endl;
}
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << fixed << setprecision(12);
 
  solve();
 
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int a,b,c;
    cin >>a>>b>>c;
    int s=a+b;
    if(s>=c){cout <<"Yes"<<endl;}
    else{cout <<"No"<<endl;}
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string s;
	cin>>s;
	int a,b,c,d;
	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	d=s[3]-'0';
	if(a+b+c+d==7){
		cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<'='<<7<<endl;
	}
	else if(a+b+c-d==7){
		cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<'='<<7<<endl;
	}
	else if(a+b-c+d==7){
		cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<'='<<7<<endl;
	}
	else if(a-b+c+d==7){
		cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<'='<<7<<endl;
	}
	else if(a+b-c-d==7){
		cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<'='<<7<<endl;
	}
	else if(a-b+c-d==7){
		cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<'='<<7<<endl;
	}
	else if(a-b-c+d==7){
		cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<'='<<7<<endl;
	}
	else if(a-b-c-d==7){
		cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<'='<<7<<endl;
	}
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

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

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n, k ,ans;

int main(){
	cin >> n >> k;
	ans = 1;
	for(int i=0;i<n;i++){
		if(ans+k>ans*2){
			ans*=2;
		}else{
			ans+=k;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  cout << "100 100" << endl;
  rep(i,50){
    rep(i, 25){
      if(a > 1){
        cout << ".#";
        --a;
      }else{
        cout << "##";
      }
    }
    rep(i, 25){
      if(b > 1){
        cout << ".#";
        --b;
      }else{
        cout << "..";
      }
    }
    cout << endl;
    rep(i, 50) cout << "#";
    rep(i, 50) cout << ".";
    cout << endl;
  }
}


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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main()
{
  long long result;
  long long N;
  long long m = 1000000007;
  cin >> N;
  result = modpow(10,N,m) - modpow(9,N,m) - modpow(9,N,m) + modpow(8,N,m);
  result %= m;
  result = (result+m) % m;

  cout << result << endl;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)(1e7))
#define pi (2*acos(0))
#define mp make_pair
#define M ((int)(1e9 + 7))
#define xx first
#define yy second
#define NN ((int)(5e5+2))
#define N ((int)(2e5 + 2))
#define pq priority_queue
///#define Q queue
#define eps 0
#define log 20
#define pb push_back
#define MOD 998244353


using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int lu;

typedef tree < int ,  null_type ,  less < int > ,  rb_tree_tag ,  tree_order_statistics_node_update > o_set;

char s[20];

int main()
{
    int n;
    bool m, f;
    ///scanf("%d",&n);
    printf("0\n");
    fflush(stdout);
    scanf("%d %s",&n,s);
    if(s[0]=='V'){
        return 0;
    }
    if(s[0]=='M'){
        m = 0;
        f = 1;
    }
    else{
        m = 1;
        f = 0;
    }
    int l = 1, r = n-1;
    while(l<r){
        int mid = (l+r)/2;
        printf("%d\n",mid);
        fflush(stdout);
        scanf("%s",s);
        if(s[0]=='V'){
            return 0;
        }
        if(s[0]=='M'){
            if(mid%2==m) l = mid+1;
            else r = mid;
        }
        else{
            if(mid%2==f) l = mid+1;
            else r = mid;
        }
    }
    printf("%d\n",l);
    fflush(stdout);
    return 0;
}


Measured memory_bytes: 852
#include<stdio.h>
#include<math.h>
    int main(){
      int n,i;
      scanf("%d",&n);
      double a[n];
      double sum=0,y=0;
      double min,x;
      scanf("%lf",&x);
      for(i=1;i<n;i++){
        scanf("%lf",&a[i]);
        sum+=a[i];
      }
      min=fabs(x-sum);
      for(i=1;i<n-1;i++){
        x+=a[i];
        sum-=a[i];
        if(fabs(x-sum)<min)
          min=fabs(x-sum);
      }
      printf("%.0lf\n",min);
	}

Measured memory_bytes: 1664
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <vector>

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

    int n, k; std::cin >> n >> k;

    std::unordered_map<int, int> m;
    m.reserve(n);
    for (int i = 0; i < n; i++) {
        int a; std::cin >> a;
        m[a]++;
    }
    std::vector<int> v;
    v.reserve(m.size());
    for (auto &p : m) {
        v.push_back(p.second);
    }
    std::sort(std::begin(v), std::end(v));
    int r = 0;
    for (int i = 0; i < (int)v.size() - k; i++) {
        r += v[i];
    }
    std::cout << r << std::endl;
}


Measured memory_bytes: 8832
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
    
a=factorization(int(input()))

b=[1,3,6,10,15,21,28,36,43]

ans=0
if len(a)==1 and a[0][0]==1:
    print(0)
    exit()

for i in a:
    for j in range(len(b)):
        if i[1]<b[j]:
            ans+=j
            break
print(ans)


Measured memory_bytes: 9500
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t H, W, D;
    std::cin >> H >> W >> D;

    struct Pos {
        int64_t x;
        int64_t y;
    };

    std::map<int64_t, Pos> A;

    for (int64_t y = 1; y <= H; ++y) {
        for (int64_t x = 1; x <= W; ++x) {
            int64_t a;
            std::cin >> a;
            A[a] = Pos{x, y};
        }
    }

    std::vector<int64_t> csum(H*W+1, 0);
    for (int64_t i = D+1; i <= H*W; ++i) {
        csum[i] = csum[i - D] + abs(A[i].x - A[i-D].x) + abs(A[i].y - A[i-D].y);
    }

    int64_t Q;
    std::cin >> Q;

    for (decltype(Q) i = 0; i < Q; ++i) {
        int64_t l, r;
        std::cin >> l >> r;
        std::cout << csum[r] - csum[l] << std::endl;
    }

    return 0;
}


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

#define DEBUG if(0)
#define lli long long int

int main()
{
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  while (1)
  {
    c -= b;
    if (c <= 0)
    {
      printf("Yes\n");
      return 0;
    }
    a -= d;
    if (a <= 0)
    {
      printf("No\n");
      return 0;
    }
  }
  return 0;
}
//Complexity: O(sqrt(n) * lg(n));

Measured memory_bytes: 3760
A = [[int(a) for a in input().split(" ")] for i in range(3)]
N = int(input())
for _ in range(N):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        A[i][j] = 0
        
bingo = False
# row
for i in range(3):
  bingo |= (A[i][0] == 0 and A[i][1] == 0 and A[i][2] == 0)
# col
for j in range(3):
  bingo |= (A[0][j] == 0 and A[1][j] == 0 and A[2][j] == 0)
# cross
bingo |= (A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0)
bingo |= (A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0)

print("Yes" if bingo else "No")

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in); 
    int N = sc.nextInt();
    int[] a = new int[N];
    int count =0;
    for (int i =0; i<N; i++) {
      a[i] = sc.nextInt();
    }
    for (int i =0; i<N; i++) {
      if (a[i] % 2 == 1 && i % 2 == 0) count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 35852
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    v = list(map(int, input().split()))
    
    #asc
    v.sort()
    
    s = 0
    pre = 0
    for i, v in enumerate(v):
        if i == 0:
            pre = v
        else:
            s = (pre + v) / 2
            pre = s
    
    print(s)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const LL INF = (1 << 30);
const LL INF2 = INF * INF;


//変数
LL N, ans;
vector<LL> a;






//サブ関数
//入力
void input()
{
	cin >> N;
	LL tmp;
	REP(i, N * 3) {
		cin >> tmp;
		a.push_back(-tmp);
	}
}

vector<LL> make_ans(vector<LL> a, LL N) {
	LL sum = 0;
	priority_queue<LL> pq;
	vector<LL> res;

	REP(i, N) {
		pq.push(a[i]);
		sum += a[i];
	}
	res.push_back(sum);

	FOR(i, N, N * 2) {
		sum += a[i]; pq.push(a[i]);
		sum -= pq.top(); pq.pop();
		res.push_back(sum);
	}
	for_each(res.begin(), res.end(), [](LL& n) {n = -n; });
	return res;
}

//vectorの中身を全部表示
template<typename T>
void show(vector<T> v)
{
	for (auto col : v)cout << col << " ";
	cout << endl;
}
template<typename T>
void show(vector<vector<T>> v)
{
	for (auto row : v)show(row);
	cout << endl;
}
//計算
void calc()
{
	auto left = make_ans(a, N);
	reverse(a.begin(), a.end());

	for_each(a.begin(), a.end(), [](LL& n) {n = -n; });
	auto right = make_ans(a, N);
	reverse(right.begin(), right.end());
	for_each(right.begin(), right.end(), [](LL& n) {n = -n; });

	//show(left);
	//cout << endl;
	//show(right);

	ans = -INF2;
	REP(i,left.size()) {
		ans = max(ans, left[i] -right[i]);
	}
}


//出力
void output()
{
	cout << ans << endl;
}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 10052
#include <stdio.h>
#include <stdlib.h>

#define NONE  (0)
#define ALICE (1)
#define BOB   (2)
#define INF   (10000)

typedef struct tagCARD {
  int number;
  int owner;
}CARD;

int selectCard(CARD* cards, int n, int player)
{
  int i;
  int max_index = 0;
  int max = -INF;
  for (i = 0; i < n; i++) {
    if (max < cards[i].number && cards[i].owner == NONE) {
      max = cards[i].number;
      max_index = i;
    }
  }

  return max_index;
}

int main()
{
  int n;
  int i;
  CARD *cards;
  int alice_total = 0;
  int bob_total = 0;

  scanf("%d", &n);
  
  cards = (CARD *)malloc(sizeof(CARD) * n);
  if (cards == NULL) return -1;
  memset(cards, 0, sizeof(CARD) * n);
  
  for (i = 0; i < n; i++) {
    scanf("%d", &cards[i].number);
  }

  for (i = 0; i < n; i++) {
    if (i % 2 == 0) { // Alice's turn
      int idx = selectCard(cards, n, ALICE);
      alice_total += cards[idx].number;
      cards[idx].owner = ALICE;
    } else {           // Bob's turn
      int idx = selectCard(cards, n, BOB);
      bob_total += cards[idx].number;
      cards[idx].owner = BOB;
    }
  }
  printf("%d\n", alice_total - bob_total);

  free(cards);

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stdio.h>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int n, ans;

int main() {
	cin >> n;
	vector<int>d(n, 0);
	rep(i,n){ cin >> d[i]; }
	

	for (int i = 0; i < n-1; i++) {
		for (int j = i+1; j <n; j++) {
			ans += d[i] * d[j];
		}
	}


	cout << ans << endl;
	return 0;
}

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

using namespace std;

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

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



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

    ll A, B, C;

    cin >> A >> B >> C;
    ll best = max(A, max(B, C));

    ll K;
    cin >> K;
    while(K--){
        best *= 2;
    }
    cout << A + B + C + best - max(A, max(B, C));
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
		h = "";
		i = j + 1;
	}
	return vec;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int a[5000];
int solve(int k) {
	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += k % a[i];
	}
	return sum;
}
signed main() {
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += read() - 1;
	}
	cout << ans << endl;
}

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

int main(int argc, char *argv[])
{
  int a, b, ans;
  cin >> a >> b;
  if(a == b){
    cout << a+b << endl;
  } else {
    ans = max(a,b);
    ans += ans - 1;
    cout << ans << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long mini = 1e9;
    long long ans = 0;
    for (int i = 0; i < 5; i++) {
        long long c; cin >> c;
        long long d = (c - 1) / 10 * 10;
        ans += d + 10;
        mini = min(mini, c - d);
    }
    cout << ans + mini - 10 << endl;
    return 0;
}

Measured memory_bytes: 256