akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string s;

int main() {
	cin >> s;
	
	cout << "ABC" << s << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void){
long int b,r,n;
  scanf("%ld %ld %ld",&n,&b,&r);
  
  if(b==0)printf("%ld",b);
  else if(b>n)printf("%ld",n);
  else if((b+r)>n)printf("%ld",b);
  else {long amari=n%(b+r);
    long ans=n/(b+r)*b;
    if(amari>=b)printf("%ld",ans+b);
        else printf("%ld",ans+amari);
       }
  return 0;
}

Measured memory_bytes: 128
/*input
4
10 80 90 30
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
int a[3001];
int dp[3001][3001][2];
int solve(int i,int j,int turn){
	if(i == j){
		if(turn == 0){
			return a[i];
		}
		return -a[i];
	}
	if(dp[i][j][turn]){
		return dp[i][j][turn];
	}
	if(turn == 0 ){
		return dp[i][j][turn]=max(a[i]+solve(i+1,j,!turn),a[j]+solve(i,j-1,!turn));
	}
	else{
		return dp[i][j][turn]=min(-a[i]+solve(i+1,j,!turn),-a[j]+solve(i,j-1,!turn));
	}
}
signed main() {
	IOS;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	cout << solve(0,n-1,0) << endl;
return 0;
}


Measured memory_bytes: 139776
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            String s = sc.next();
            System.out.print(s.charAt(i));
        }
        System.out.println();
    }
}


Measured memory_bytes: 25172
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];
        HashMap<Integer,Integer> hm=new HashMap<>();
        long sum=0;
        for(int i=0;i<n;++i) {
            a[i]=sc.nextInt();
            sum+=a[i];
            hm.put(a[i],hm.getOrDefault(a[i],0)+1);
        }
        int q=sc.nextInt();
        while(q-->0) {
            int b=sc.nextInt();
            int c=sc.nextInt();
          	if(hm.containsKey(b)) {
              int val=hm.get(b);
              sum+=val*(c-b);
              hm.remove(b);
              hm.put(c,hm.getOrDefault(c,0)+val);
              System.out.println(sum);
            } else 
              System.out.println(sum);
        }
    }
}

Measured memory_bytes: 64624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> L(M), R(M);
    rep(i, 0, M)
    {
        cin >> L.at(i) >> R.at(i);
    }
    sort(all(L));
    sort(all(R));
    if (R.at(0) - L.at(M - 1) + 1 > 0)
    {
        cout << R.at(0) - L.at(M - 1) + 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}

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

int main() {
  int A, B, C, D;
    cin >> A >> B >> C  >> D;
  if ( (A + B) > (C + D)){
    cout << "Left" << endl;
  }
  else if ( (A + B) < (C + D)){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#define REP(i, n) for(int i = 0; i < n; i++)
//using ll = long long;
using namespace std;


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

  int n, m, ans=0;
  cin >> n >> m;
  int sum=0, tmp;

  REP(i,m){
    cin >> tmp;
    sum += tmp;
  }

  
  if (sum <= n) {
    ans = n - sum;
  } else {
    ans = -1;
  }
  
  cout << ans << endl;
      
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    int n;cin>>n;
    ll B=(1<<n);
    vector<ll> a(B);
    rep(i,B){
        cin>>a[i];
    }
    pair<ll,ll> dp[B][n+1];
    rep(i,B){
        dp[i][0]=make_pair(a[i],0);
    }

    //dp[i][j]
    rep(i,B){
        rep(j,n){  
            if((i>>j)&1){
                vector<ll> t;
                t.push_back(dp[i][j].first);
                t.push_back(dp[i][j].second);
                t.push_back(dp[i& ~(1<<j)][j].first);
                t.push_back(dp[i& ~(1<<j)][j].second);
                sort(ALL(t));reverse(ALL(t));
                dp[i][j+1].first =t[0];
                dp[i][j+1].second=t[1];
            }else{
                dp[i][j+1]=dp[i][j];
            }
        }
    }
    ll ans=0;
    for(int i=1;i<B;i++){
        chmax(ans,dp[i][n].first+dp[i][n].second);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 82944
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 100000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int A,B,C;
    cin >> A >> B >> C;
    if(A%2 == 0 || B%2 == 0 || C%2 == 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << min({A*B,A*C,B*C}) << endl;
}


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = 1;
    fact[1] = 1;
    for(int i=2; i<=num; i++){
        fact[i] = fact[i-1] * i % MOD;
    }
}

void create_seq_inv_mod(int num){
    seq_inv[0] = 1;
    seq_inv[1] = 1;
    for(int i=2; i<=num; i++){
        seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
    }
}

void create_fact_inv_mod(int num){
    fact_inv[0] = 1;
    fact_inv[1] = 1;
    for(int i=2; i<=num; i++){
        fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
    }
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

vector<int> edges[2000];

int64_t dp[2001][2001][4], sub[2001][4];
int sz[2001];

void dfs(int i1){
    sz[i1] = 1;
    dp[i1][0][0] = 1;
    for(int i2 : edges[i1]){
        dfs(i2);
        memset(sub, 0, sizeof(sub));
        for(int j1=0; j1<sz[i1]; j1++){
            for(int j2=0; j2<sz[i2]; j2++){
                for(int k1=0; k1<4; k1++){
                    for(int k2=0; k2<4; k2++){
                        int64_t res = dp[i1][j1][k1] * dp[i2][j2][k2] % MOD;
                        add(sub[j1+j2][k1], res);
                        if(nth_bit(k1, 0) == 0 && nth_bit(k2, 1) == 0){
                            add(sub[j1+j2+1][k1+1], res);
                        }
                        if(nth_bit(k1, 1) == 0 && nth_bit(k2, 0) == 0){
                            add(sub[j1+j2+1][k1+2], res);
                        }
                    }
                }
            }
        }
        sz[i1] += sz[i2];
        for(int j=0; j<sz[i1]; j++) for(int k=0; k<4; k++) dp[i1][j][k] = sub[j][k];
    }
}

int main(){
    int N;
    cin >> N;
    for(int i=1; i<N; i++){
        int p;
        cin >> p;
        edges[p-1].push_back(i);
    }

    dfs(0);

    create_mod_tables(2000);
    int64_t ans = 0;
    for(int j=0; j<N; j++){
        int64_t res = 0;
        for(int k=0; k<4; k++) add(res, dp[0][j][k]);
        mul(res, fact[N-j]);
        add(ans, j%2 ? (MOD - res) : res);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 125696
// ConsoleApplication1001.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//



#include <iostream>
#include "string.h"
#include <stdio.h>
#include <math.h>
#include "cstring"
#define N 10001
#include "stack"
using namespace std;


//判断是否为素数
bool isPrime(int m)
{
    int i = 0;//循环次数
    int k = 0;//m的平方根
    k = (int)sqrt(double(m));
    for (i = 2; i <= k; i++)
    {
        if ((m%i) == 0)
        {
            break;
        }

    }
    if (i > k)
    {
        return true;
    }
    else
    {
        return false;
    }
}


int main()
{
    stack<string>  mysatck;
    string s,t;
    cin>>s;
    cin>>t;
    mysatck.push(s);
    mysatck.push(t);

    while(mysatck.size()!=0)
    {
        cout<<mysatck.top();
        mysatck.pop();
    }
    return 0;

}




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

using namespace std;

int main(){
  int N; cin >> N;
  vector<long long> A(N+1);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  A[N] = 0;
  long long a = 0;
  long long b = 0;
  long long sum = 0;
  
  for(int i=0;i<N;i++){
    sum += A[i];
  }
  int num=0;
  for(int i=0;i<N;i++){
    a += A[i];
    if(a>sum/2){
      num = i;
      a -= A[i];
      break;
    }
  }
  for(int i=num+1;i<N;i++){
    b += A[i];
  }
  
  cerr << a << " " << b << " " << num << "\n\n";
  if(a>b){
    b += A[num];
  }else{
    a += A[num];
  }
  cerr << sum << endl;
  cerr << "a=" << a << " b=" << b;
  cout << abs(a-b) << endl;

  return 0;
}


Measured memory_bytes: 1792
N,K = map(int,input().split())
S_list = ['0'] + list(input()) + ['-1']

s_count_list =[]

cnt = 1
for i in range(1,N+2) :
    if S_list[i] == S_list[i-1] :
        cnt +=1
    else:
        s_count_list.append(cnt)
        cnt = 1
if S_list[1] == '0':
    s_count_list[0] = s_count_list[0] -1
    s_count_list.insert(0,0)
else:
    s_count_list.pop(0)

ruisekiwa = [0]
for i,s in enumerate(s_count_list):
    ruisekiwa.append(ruisekiwa[i] + s)

if len(ruisekiwa) %2 ==0:
    ruisekiwa.append(0)

answer =  1
#print(s_count_list)
#Jjkprint(ruisekiwa)
for i in range(0,len(s_count_list),2):
    left = i
    right = min((i + (2 * K) + 1),len(s_count_list))
    #print(left,right)
    #print(ruisekiwa[right])
    tmp = ruisekiwa[right] - ruisekiwa[left]
    answer = max(tmp,answer)

print(answer)





Measured memory_bytes: 10408
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1LL); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};



class Kruskal {
private:
	UnionFind *uf;
	vector<edge> e;
public:
	vector<edge> mst;
	Kruskal(int N) { uf = new UnionFind(N); }
	void add(int x, int y, ll z);
	void run();
};



//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}

ll UnionFind::size(int x) {
	return -par[find(x)];
}

void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);

	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}



//----Kruskal-------------------------------
void Kruskal::add(int x, int y, ll z) {
	//x < y
	if (x > y) swap(x, y);
	e.push_back({ z,{x,y} });
}

void Kruskal::run() {
	sort(e.begin(), e.end());
	e.erase(unique(e.begin(), e.end()), e.end());
	for (auto x : e) {
		if (uf->same(x.second.first, x.second.second)) {
			continue;
		}
		else {
			mst.push_back(x);
			uf->unite(x.second.first, x.second.second);
		}
	}
}

signed main() {
	int a,b;
	cin >> a >> b;
	if (b % a==0) {
		cout << a + b << endl;
	} else {
		cout << b - a << endl;
	}
}

Measured memory_bytes: 256
import heapq
def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

h,w = map(int,input().split())
white = 0
n = h*w
edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
s = []
for i in range(h):
    p = list(input())
    s.append(p)

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            white += 1
            if i != h-1 and s[i+1][j] == ".":
                edge[w*i+j].append([1,w*i+j+w])
                edge[w*i+j+w].append([1,w*i+j])
            if j != w-1 and s[i][j+1] == ".":
                edge[w*i+j].append([1,w*i+j+1])
                edge[w*i+j+1].append([1,w*i+j])
#for i in range(len(edge)):
#    print(i,edge[i])
d = dijkstra_heap(0)
#print(d)
if d[-1] == float("inf"):
    print(-1)
else:
    print(white-d[-1]-1)






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

const int maxn = 4e5 + 3;
typedef long long ll;
int n;
ll t;
struct vec {
    ll a, b;
    void read() {
        scanf("%lld%lld", &a, &b);
    }
    bool operator<(const vec &other) const {
        return a * (other.b + 1ll) > other.a * (b + 1ll);
    }
} v[maxn];

ll dp[32];

int main() {
    scanf("%d%lld", &n, &t);
    for(int i = 0; i < n; ++i)
        v[i].read();
    int m = std::partition(v, v + n, [] (const auto &u) {
        return u.a != 0;
    }) - v;
    std::sort(v, v + m);
    memset(dp, 0x7f, sizeof(dp));
    dp[0] = 0;
    for(int i = 0; i < m; ++i) {
        for(int j = 31; j >= 1; --j) {
            if(dp[j - 1] + 1ll <= t)
                dp[j] = std::min(dp[j], dp[j - 1] + 1ll + v[i].a * (dp[j - 1] + 1ll) + v[i].b);
        }
    }
    int ans = 0;
    std::sort(v + m, v + n, [] (const auto &u, const auto &v) {
        return u.b < v.b;
    });
    ll ct = 0;
    for(int i = m; i <= n; ++i) {
        for(int j = 0; j < 32; ++j) {
            if(dp[j] <= t && dp[j] + ct <= t)
                ans = std::max(ans, j + i - m);
        }
        ct += 1ll + v[i].b;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MOD=998244353;
map<pii,int> mp;
int n,m,a[200005],b[200005],c[200005];
ll f[200005][3],ans;bool vis[200005];
int g[200005],h[200005];
ll qpow(ll x,ll y){
    ll ret=1;
    while(y){
        if(y&1LL) ret=ret*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return ret;
}
void mo(ll &x){
    if(x>=MOD) x-=MOD;
}
int main(){
    cin>>n>>m;
    memset(g,-1,sizeof(g));
    memset(h,-1,sizeof(h));
    for(int i=1;i<=m;i++){
        cin>>a[i]>>b[i]>>c[i];
        mp[pii(a[i],b[i])]=i;
    }
    int cou=0;
    for(int i=1;i<=m;i++){
        if(!vis[i])
        {
            if(a[i]==b[i]) c[i]=c[i];
            else if(mp[pii(b[i],a[i])]){
                int num=mp[pii(b[i],a[i])];
                vis[num]=1;
                c[i]=(c[i]+c[num])%2;
            }
            else vis[i]=1;
            
            if(a[i]!=b[i]) cou++;
            if(abs(a[i]-b[i])>=3&&!vis[i]&&c[i]!=0){
                puts("0");
                return 0;
            }
        }
    }

    ans=qpow(2,1LL*n*(n-1)/2-cou);
    for(int i=1;i<=m;i++){
        if(!vis[i]){
            if(a[i]<b[i]) swap(a[i],b[i]);
            if(a[i]==b[i]){
                if(g[a[i]]!=-1&&g[a[i]]!=c[i]){
                    puts("0");
                    return 0;
                }
                g[a[i]]=c[i];
            }
            else if(a[i]-b[i]==2){
                if(g[a[i]-1]!=-1&&g[a[i]-1]!=c[i]){
                    puts("0");
                    return 0;
                }
                g[a[i]-1]=c[i];

            }
            else if(a[i]-b[i]==1){
                if(h[a[i]]!=-1&&h[a[i]]!=c[i]){
                    puts("0");
                    return 0;
                }
                h[a[i]]=c[i];
            }
        }
    }
    f[0][0]=1;
    for(int i=1;i<=n;i++){
        if(g[i]!=1){
            if(h[i]!=1) mo(f[i][0]+=f[i-1][0]);
            if(h[i]!=0) mo(f[i][0]+=f[i-1][1]);
        }
        if(g[i]!=0){
            if(h[i]!=1) mo(f[i][1]+=f[i-1][1]);
            if(h[i]!=0) mo(f[i][1]+=f[i-1][0]);
        }
    }
    cout<<1LL*ans*(f[n][0]+f[n][1])%MOD<<endl;
    return 0;
}

Measured memory_bytes: 14592
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;





signed main() {
    ll n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    
    string t;
    cin >> t;
    
    vb prwin(k, false);
    
    
    ll sum = 0;
    rep(i, n) {
        
        if (t[i] == t[i-k] && prwin[i%k] == true) {
            prwin[i%k] = false;
        } else {
            if (t[i] == 'r') {
                sum += p;
                prwin[i%k] = true;
            }
            if (t[i] == 's') {
                sum += r;
                prwin[i%k] = true;
            }
            if (t[i] == 'p') {
                sum += s;
                prwin[i%k] = true;
            }
            
        }
        
        
        
    }
    
    mes(sum);
    
    
    
    
    
    
}

Measured memory_bytes: 3764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
 
#define int long long
#define MOD7 1000000007
#define MOD9 1000000009
 
#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))
 
using namespace std;
 
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };
 
template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
 
int cnt[100];
signed main() {
	int N;
	cin >> N;
 
	vector<int> x(N), y(N);
	rep(i, N) cin >> x[i] >> y[i];
 
	const int hoge = 3000000;
	const double R = 1e11;
	const double eps = 6.28318530718 / 2 / hoge;
 
	double rad = eps;
	rep(i, hoge) {
		double X = R * cos(rad);
		double Y = R * sin(rad);
 
		double minDist = 1e35;
		int minArg = -1;
		rep(i, N) {
			double dx = x[i] - X;
			double dy = y[i] - Y;
			double dist2 = dx*dx + dy*dy;
			if (dist2 < minDist) {
				minArg = i;
				minDist = dist2;
			}
		}
		cnt[minArg]++;
 
		X = -X;
		Y = -Y;
 
		minDist = 1e35;
		minArg = -1;
		rep(i, N) {
			int dx = x[i] - X;
			int dy = y[i] - Y;
			double dist2 = dx*dx + dy*dy;
			if (dist2 < minDist) {
				minArg = i;
				minDist = dist2;
			}
		}
		cnt[minArg]++;
		rad += eps;
	}

	rep(i, N) {
		printf("%.10f\n", (double)cnt[i] / hoge / 2);
	}
 
    return 0;
}


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

int main(){
    double n;
    cin >> n;
    if(fmod(n, 2) == 0) cout << n/2/n << endl;
    else cout << (n+1)/2/n << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<bitset>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int N=310,mod=998244353;
char s[N];
int K,ct,n,m;
int w[N];
ll sum,f[N][N][N];
void pls(ll &x,ll y){x+=y;x>=mod?x-=mod:0;}
int main(){
//	freopen("a.in","r",stdin);
	scanf("%s%d",s+1,&K);n=strlen(s+1);
	for(int i=1;i<=n;i++)if(s[i]=='0')m++,w[m]=ct,ct=0;else ct++;
	m++;w[m]=ct;
	f[m+1][0][0]=1;
	for(int i=m;i;i--){sum=min(sum,(ll)K);
		for(int j=0;j<=sum;j++)for(int k=j;k<=sum;k++)for(int c=0;c<=j+w[i];c++){
			if(c<w[i])pls(f[i][j+w[i]-c][k+w[i]-c],f[i+1][j][k]);
			else pls(f[i][j+w[i]-c][k],f[i+1][j][k]);
		}
		sum+=w[i];
	}
	K=min(K,n);
	sum=0;for(int i=0;i<=K;i++)pls(sum,f[1][0][i]);
	cout<<sum;
}

Measured memory_bytes: 31476
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,AC=0,WA=0,TLE=0,RE=0;
    cin>>n;
    string s;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s=="AC")
            AC++;
        else if(s=="WA")
            WA++;
        else if(s=="TLE")
            TLE++;
        else if(s=="RE")
            RE++;
    }
    cout<<"AC x "<<AC<<"\nWA x "<<WA<<"\nTLE x "<<TLE<<"\nRE x "<<RE;
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
using namespace std;
using ull=unsigned long;
int main(){
    unsigned x,y,z,K;
    scanf("%u %u %u %u",&x,&y,&z,&K);
    ull a[x],b[y],c[z];
    for(unsigned i=0;i<x;i++)scanf("%lu",&a[i]);
    for(unsigned i=0;i<y;i++)scanf("%lu",&b[i]);
    for(unsigned i=0;i<z;i++)scanf("%lu",&c[i]);
    priority_queue<ull,vector<ull>,greater<ull>>q;
    for(unsigned i=0;i<x;i++)for(unsigned j=0;j<y;j++)for(unsigned k=0;k<z;k++){
        if(q.size()<K)q.push(a[i]+b[j]+c[k]);
        else if(q.top()<a[i]+b[j]+c[k]){
            q.pop();
            q.push(a[i]+b[j]+c[k]);
        }
    }
    ull ans[K];
    for(unsigned i=K;i--;){
        ans[i]=q.top();
        q.pop();
    }
    for(unsigned i=0;i<K;i++)printf("%lu\n",ans[i]);
}


Measured memory_bytes: 512
N = gets.to_i

ans = [0]*N

1.upto(N) do |x|
    x2 = x*x
    break if x2>=N
    x.upto(N) do |y|
        y2 = y*y
        break if y2>=N

        xy_same = x==y

        y.upto(N) do |z|
            a = x2+y2+z*z + x*y + y*z + z*x
            break if a > N
            m = 6
            if xy_same then x != z
                m = x==z ? 1 : 3
            elsif x==z || y==z then 
                m = 3
            end
            ans[a-1] += m
        end
    end
end

ans.each do |a|
    p a
end

Measured memory_bytes: 14436
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/


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

	string s;
	cin >> s;

	// 2通り考える
	int ans = inf;

	int tmp = 0;
	// 最初が黒 0
	rep(i, s.size()) {
		if (i % 2 == 0) {
			if (s[i] == '1') {
				tmp++;
			}
		}
		else {
			if (s[i] == '0') {
				tmp++;
			}
		}
	}
	ans = min(ans, tmp);

	// 最初が1
	tmp = 0;
	rep(i, s.size()) {
		if (i % 2 == 0) {
			if (s[i] == '0') {
				tmp++;
			}
		}
		else {
			if (s[i] == '1') {
				tmp++;
			}
		}
	}

	ans = min(ans, tmp);

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 512
//
//  main.cpp
//  ajo
//
//  Created by Hashimoto Ryo on 2015/06/20.
//  Copyright (c) 2015??´ Hashimoto Ryo. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 100;

void out(int a[],int n){
    for(int i; i < n - 1;i++){
        cout << a[i]<< " ";
    }
    cout << a[n-1] << endl;
}


int main(){
    
    int a[MAX];
    int n;
    
    
    cin >> n;//?????????????????????
    for (int i = 0;i < n;i++){
        cin >> a[i];
    }
    
    out(a,n);
    
    for(int i = 1;i < n;i++){
        int j = i - 1;
        int v = a[i];
        
        while(v < a[j] && j >= 0){
            a[j+1] = a[j];
            j--;
        }
        
        a[j+1] = v;
        out(a, n);
    }
    
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int count[n];
  int a[n];
  for(int i = 0; i < n; i++) count[i] = 0;
  for(int i = 0; i < n - 1; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n - 1; i++){
    count[a[i] - 1]++;
  }
  for(int i = 0; i < n; i++){
    cout << count[i] << endl;
  }
}

Measured memory_bytes: 5180
import itertools
seq = ('M', 'A', 'R', 'C', 'H')
combs = list(itertools.combinations(seq, 3))
chr_dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}

n = int(input())
s = []
for _ in range(n):
  l = input()
  if l[0] in chr_dic:
    chr_dic[l[0]] += 1
  s.append(l)

ans = 0
for cmb in combs:
  if chr_dic[cmb[0]] > 0 and chr_dic[cmb[1]] > 0 and chr_dic[cmb[2]] > 0:
    ans += chr_dic[cmb[0]] * chr_dic[cmb[1]] * chr_dic[cmb[2]]
print(ans)

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

int main() {
  uint64_t N, K;
  cin >> N >> K;
  
  uint64_t first = N % K;
  uint64_t second = K - first;
  
  cout << (first < second ? first : second) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
#define REP(i,n) for(int i=0;i<signed(n);i++)
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
const ll MOD = 1000000007;
const ll INF = 9e9;
ll N,M,ans=INF;
ll A[300010],S[301000];
int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){
        cin>>A[i];
        S[i]+=A[i];
        S[i+1]=S[i];
    }
    //a:右半分の区切り i:真ん中 b:左半分
    //s:右の和 t:左の和
    ll a=0,b=2,s,t;
    REP(i,N-2){
        if(i==b)b++;
        s=(S[i]-S[a])-S[a];
        t=(S[N-1]-S[b])-(S[b]-S[i]);
        bool f=true;
        if(i==0)continue;
        while(f){
            f=false;
            if(a+1==i)continue;
            if(abs(s)>abs(s-A[a+1]*2)){
                s-=A[a+1]*2;
                a++;f=true;
            }
        }
        f=true;
        while(f){
            f=false;
            if(b+1==N-1||b==N-1)continue;
            if(abs(t)>abs(t-A[b+1]*2)){
                t-=A[b+1]*2;
                b++;f=true;
            }
        }
        ans=min( ans,( max({S[a],S[i]-S[a],S[b]-S[i],S[N-1]-S[b]})
        -min({S[a],S[i]-S[a],S[b]-S[i],S[N-1]-S[b]}) ) );
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<string> data(n);
    for (int i = 0; i < n; i++)
    {
        cin >> data[i];
    }
    vector<int> count_up(4, 0);
    for (int i = 0; i < n; i++)
    {
        if (data[i] == "AC")
        {
            count_up[0]++;
        }
        else if (data[i] == "WA")
        {
            count_up[1]++;
        }
        else if (data[i] == "TLE")
        {
            count_up[2]++;
        }
        else
        {
            count_up[3]++;
        }
    }
    cout << "AC x " << count_up[0] << endl;
    cout << "WA x " << count_up[1] << endl;
    cout << "TLE x " << count_up[2] << endl;
    cout << "RE x " << count_up[3] << endl;
}

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

using u64 = std::uint64_t;
constexpr u64 inf = std::numeric_limits<u64>::max();

#define REP(i, n) for (u64 i = 0; i < (n); ++i)

namespace io {
  constexpr int is = 1 << 17;
  char ib[is], *ip = ib + is, it;
  inline char getc() {
    if (ip == ib + is) { read(STDIN_FILENO, ib, is); ip = ib; }
    return *ip++;
  }
  inline u64 scan() {
    u64 r = 0;
    if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
    else while ((it = *ip++) & 16) r = r * 10 + it - '0';
    return r;
  }
  constexpr int os = 1 << 17;
  char ob[os], *op = ob, ot;
  inline void putc(const char c) {
    *op++ = c;
    if (op == ob + os) { write(STDOUT_FILENO, ob, os); op = ob; }
  }
  /* x shoud be greater than or equal to zero */
  inline void print(u64 x) {
    char d[20];
    int i = 0;
    while (true) {
      d[i] = x % 10 + 48;
      x /= 10;
      ++i;
      if (x <= 0) break;
    }
    while (i--) {
      putc(d[i]);
    }
  }
  inline void flush() {
    write(STDOUT_FILENO, ob, op - ob);
  }
}

signed main() {
  u64 n = io::scan();
  auto G = vector<vector<u64>>(n);
  auto H = vector<u64>(n * n);
  REP(i, n - 1) {
    u64 a = io::scan() - 1;
    u64 b = io::scan() - 1;
    G[a].push_back(b);
    G[b].push_back(a);
    H[a * n + b] = i;
    H[b * n + a] = i;
  }
  u64 m = io::scan();
  auto paths = vector<u64>(m);
  auto collect = [&n, &G, &H](auto &&collect, u64 u, u64 v, u64 p) -> u64 {
    if (u == v) return 0;
    for (auto t : G[u]) {
      if (t == p) continue;
      u64 s = collect(collect, t, v, u);
      if (s != inf) {
        return s | (1ULL << H[u * n + t]);
      }
    }
    return inf;
  };
  REP(j, m) {
    u64 u = io::scan() - 1;
    u64 v = io::scan() - 1;
    paths[j] = collect(collect, u, v, -1);
  }
  auto search = [&m, &paths](auto &&search, u64 ans, u64 j, u64 mask) -> u64 {
    if (j != m) {
      return (
        search(search, ans, j + 1, mask) - search(search, ans, j + 1, mask | paths[j])
      );
    } else {
      return ans >> __builtin_popcountll(mask);
    }
  };
  u64 ans = search(search, 1ULL << (n - 1), 0, 0);
  io::print(ans);
  io::flush();
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>

#define REP(i,N) for(i = 0; i < N; i++)

int right(int diff)
{
	int sum;
	if (diff % 2 == 0)
	{
		sum = (diff + 1) * diff / 2;
	}
	else
	{
		sum = (diff + 1) * (diff - 1) / 2 + (diff + 1) / 2;
	}
	return sum;
}

int main(void)
{
	int l, r;
	scanf("%d %d", &l, &r);
	printf("%d\n", right(r-l) - r);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  char a, b;
  cin >> a >> b;
  if (a<b) cout << '<' << endl;
  if (a>b) cout << '>' << endl;
  if (a==b) cout << '=' << endl;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef unsigned long long ULL;
#define int LL
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

const int MAX = 400*1000+5;
const int INF = 1000*1000*1000 + 7;
const LL LINF = 1LL*INF*INF;
const int MOD = INF;
const double PI = acos(-1.);
const int MAXN = 3*100007;

mt19937 rnd(time(0));

main()
{
    ios_base::sync_with_stdio(0);
    LL x,y;
    cin>>x>>y;
    if (abs(x-y) <= 1)
        cout<<"Brown";
    else
        cout<<"Alice";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  double r1,r2;
  cin>>r1>>r2;
  cout<<shosu(10)<<r1*r2/(r1+r2)<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int x[10000 + 5];
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> x[i];
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{

		if(x[i]%2==0)
			while (x[i] % 2 == 0)
			{
				x[i] = x[i] / 2;
				ans++;
			}

	}
	printf("%d", ans);
	return 0;
}

/*
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int d, n;
	cin >> d >> n;
	if (d == 0)
		printf("%d", n);
	else
		if (d == 1)
			printf("%d00",  n);
		else
			if (d == 2)
				printf("%d0000", n);
	return 0;
}
*/

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

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    akari<i64> as(n), bs(n);
    for (int i = 0; i < n; i++)
    {
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    if (n & 1)
    {
        i64 ans = 0, ans2 = 0;
        int plus = (n + 1) / 2, minus = n - plus;
        ans += accumulate(as.begin() + minus + 2, as.end(), (i64)0) * 2;
        ans -= accumulate(as.begin(), as.begin() + minus, (i64)0) * 2;
        ans += as[minus + 1] + as[minus];
        swap(plus, minus);
        ans2 += accumulate(as.begin() + minus, as.end(), (i64)0) * 2;
        ans2 -= accumulate(as.begin(), as.begin() + minus - 2, (i64)0) * 2;
        ans2 -= as[minus - 2] + as[minus - 1];
        ans = max(ans, ans2);
        cout << ans << endl;
    }
    else
    {
        i64 ans = 0;
        ans += accumulate(as.begin() + n / 2 + 1, as.end(), (i64)0) * 2;
        ans -= accumulate(as.begin(), as.begin() + n / 2 - 1, (i64)0) * 2;
        ans += as[n / 2] - as[n / 2 - 1];
        cout << ans << endl;
    }
}

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


Measured memory_bytes: 1920
#include<iostream>
using namespace std;
typedef long long int ll;

void solve(){
    ll n;cin>>n;
    ll a[n],ans=1000,stocks;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n-1;i++){
       stocks=0;
       if(a[i]<a[i+1]) 
          stocks=ans/a[i];
       ans+=(a[i+1]-a[i])*stocks;
    }
    cout<<ans<<"\n";
}

int main()
{
    int t;//cin>>t;
    t=1;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;
const ll INFll = 1E+18;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = a*c;
    chmax(ans, a*d);
    chmax(ans, b*c);
    chmax(ans, b*d);
    
    pr(ans);
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  int sum=0;
  for(int i=0; i<M; i++){
    int A;
    cin >> A;
    sum += A;
  }
  cout << (N-sum<0?-1:N-sum) << endl;
  return 0;
}

Measured memory_bytes: 3600
# frozen_string_literal: true

N = gets.to_i
A = gets.split.map(&:to_i)

list = Array.new(N) { 0 }
A.map(&:pred).each { |i| list[i] += 1 }

count = 0

list.each do |i|
  count += i * (i - 1) if i > 1
end

N.times do |i|
  puts (count - 2 * (list[A[i] - 1]) + 2) / 2
end

Measured memory_bytes: 23272
#include <list>
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    list<int> numbers;
    bool canDevine = false;
    
    for (int i = 1; i < 10; i ++){
        numbers.push_back(i);
    }
    
    for (int i : numbers){
        if (n%i == 0 && n/i < 10) canDevine = true;
    }
    
    if (canDevine){
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


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

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	string s;
	cin >> s;

	int count = 0;

	for (int i = 1; i < s.size(); i++)
	{
		if (s[i] != s[i-1])
		{
			count++;
		}
	}

	cout << count << endl;

	
	return 0;
}

Measured memory_bytes: 512
from _collections import deque
N, Q = map(int, input().split())
graph = [[] for _ in range(N+1)]
for i in range(N-1):
    u, v = map(int, input().split())
    graph[u].append(v)
    graph[v].append(u)

points = [0]*(N+1)
for i in range(Q):
    p, x = map(int, input().split())
    points[p] += x

stack = deque()
stack.append(1)
score = 0
score_array = [0]*(N+1)
is_checked = [0]*(N+1)
#print(graph)
while stack:
    node = stack.pop()
    is_checked[node] = 1

    #print("node=" + str(node))
    score_array[node] += points[node]
    #print("score=" + str(score_array[node]))
    for goto in graph[node]:
        if not is_checked[goto]:
            #print("goto=" + str(goto))
            stack.append(goto)
            score_array[goto] += score_array[node]

print(" ".join(map(str, score_array[1:])))



Measured memory_bytes: 74368
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 2000003;
const int MOD = 1000000007;

//




        signed main() {
    cout<<fixed<<setprecision(15);
     int a,b,c,x,ans=0;
     cin>>a>>b>>c>>x;
     for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)for(int k=0;k<=c;k++)if(500*i+100*j+50*k==x)ans++;
     cout<<ans;
      }

        


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main() {
  string S, T;
  cin >> S >> T;
  
  cout << T + S << endl;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n],g;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i==0){
            g=a[i];
        }
        else{
            g=__gcd(g,a[i]);
        }
    }
    cout << g<<endl;
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
   int n,m;
   cin >> n >> m;
   vector<int> a(n);
   int s = 0;
   for(int i = 0;i < n;i++){
         cin >> a[i];
         s += a[i];
   }
   
   sort(a.begin(),a.end(),greater<int>());
   int t = 0;
   for(int i = 0;i < m;i++){
         if(a[i] * 4 * m < s){
               cout << "No" << endl;
               return 0;
         }
   }
   cout << "Yes" << endl;
   return 0;
   
}


Measured memory_bytes: 3556
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        while (a !=0) {
            double[] b = new double[a];
            for (int x = 0; x < a; x++) {
                b[x] = scan.nextInt();
            }
            double average = 0;
            for (int x = 0; x < a; x++) {
                average = average +b[x];
            }
            average = average / a;
            double var = 0;
            for (int x = 0; x < a; x++) {
                var = var +  ((b[x] - average) *(b[x] - average));
            }
            var = var /a;
            System.out.printf("%.8f\n",Math.sqrt(var));
            a = scan.nextInt();
        }

    }
}


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

using namespace std;

long long n, m;

void readInput() {
    cin >> n >> m;
}

int main(int argc, char const *argv[]) {
    
    readInput();

    long long ans;

    if(m < 2 * n) {
        ans = m / 2;
    }
    else {
        ans = n + (m - 2 * n) / 4;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repeat(i,a,n) for(int i=a;i<n;i++)
using namespace std;

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

  int ans = K;
  repeat(i,1,N){
    ans *= K-1;
  }
  
  cout <<ans<< endl;
}

Measured memory_bytes: 256
# a atcooderkunの真偽  b atcooderkunの言動
# # b=H at「TOP本当」　b=D at「TOP嘘だ！
#    対応関係　〇　×
# 　　　　　　　×　〇

a, b = input().split()

if a==b:
    print("H")
else:
    print("D")

Measured memory_bytes: 9020
n, m, x, y = map(int, input().split())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))
x_max = max(x_list)
y_min = min(y_list)
war = 'War'
for i in range(y+1):
    if x_max < i and i <= y_min and x < i and i <= y:
        war = 'No War'
print(war)

Measured memory_bytes: 3064