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

int main(void) {
    long n;
    cin >> n;
    vector<long> b(n-1);
    for(auto &e: b) cin >> e;

    vector<long> a(n);
    a[0] = b[0];
    for(long i=1; i<n-1; i++)
        a[i] = min(b[i], b[i-1]);
    a[n-1] = b[n-2];

    long r = 0;
    for(auto &e: a) r += e;
    cout << r << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int A[1000];

void printArray (int N) {
	for (int i=0; i<N; i++) {
		// cout << A[i] << " ";
		printf("%d", A[i]);
		if (i==N-1) {
			printf("\n");
			// cout << endl;
		} else {
			printf(" ");
		}
	}
	return;
}

void insertionSort (int N) {
	printArray(N);
	for (int i=1; i<N; i++) {
		int v = A[i];
		int j = i -1;
		while (A[j] > v) {
			A[j+1] = A[j];
				j--;
		}
		A[j+1] = v;
		printArray(N);
	}
	return;
}

int main(int argc, char const* argv[])
{
	int N;
	cin >> N;
	for (int i=0; i<N; i++) {
		cin >> A[i];
	}
	insertionSort (N);
	
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define pb push_back
typedef long long ll;
typedef complex<int> P;

int n, m;
double ans = 0;
double x[21], y[21], z[21];

double f(int i, int j){
	return (x[i]-x[j]) * (x[i]-x[j])
	+ (y[i]-y[j]) * (y[i]-y[j])
	+ (z[i]-z[j]) * (z[i]-z[j]);
}

void dfs(int p, vector<int> &v){
	if(p == n){
		if(v.size() == m){
			double sum = 0.0;
			for(int i=0;i<v.size();i++){		//
				for(int j=0;j<i;j++){			//
					sum += f(v[i], v[j]);
				}
			}
			ans = max(ans, sum);
			return;
		}
	}else{
		dfs(p+1, v);
		v.push_back(p);
		dfs(p+1, v);
		v.pop_back();
	}
}

bool solve(){
	cin>> n>> m;
	for(int i=0;i<n;i++){
		cin>> x[i]>> y[i]>> z[i];
	}
	
	ans = 0.0;
	vector<int> v;
	dfs(0, v);
	cout<< ans<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	
	solve();

	return 0;
}

 

Measured memory_bytes: 1312
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    Queue<String> A = new ArrayDeque<String>();
    Queue<String> B = new ArrayDeque<String>();
    Queue<String> C = new ArrayDeque<String>();
    char next = 'a';
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = read();
        this.B = read();
        this.C = read();
    }
    
    //キューに値を格納するためのメソッド
    private Queue<String> read() {
    	Queue<String> tmp = new ArrayDeque<String>();
    	String S = sc.next();
    	for (int i=0; i<S.length(); i++) {
    		tmp.add(String.valueOf(S.charAt(i)));
    	}
    	return tmp;
    }
    
    //解答処理
    private String solve() {
        String answer = null;
        
        while (true) {
        	if (next == 'a') {
        		if (A.size() == 0) {
            		answer = "A";
            		break;
            	}
        		play(A);
        	} else if (next == 'b') {
        		if (B.size() == 0) {
            		answer = "B";
            		break;
            	}
        		play(B);
        	} else if (next == 'c') {
        		if (C.size() == 0) {
            		answer = "C";
            		break;
            	}
        		play(C);
        	}
        	  
        }
        
        return answer;
    }
    
    //操作
    private Queue<String> play(Queue<String> tmp) {
    	next = tmp.poll().charAt(0);
    	return tmp;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35640
use std::cmp::max;
use std::io::*;
use std::str::FromStr;
use std::vec::Vec;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn open_num(pat: i32, store: &Vec<i64>) -> usize {
    (0..10)
        .filter(|p| pat & (1 << p) != 0 && store[*p as usize] == 1)
        .collect::<Vec<_>>()
        .len()
}

fn main() {
    let n: usize = read();

    let mut fs: Vec<Vec<i64>> = Vec::new();
    for i in 0..n {
        fs.push(Vec::new());
        for _ in 0..10 {
            fs[i].push(read())
        }
    }

    let mut ps: Vec<Vec<i64>> = Vec::new();
    for i in 0..n {
        ps.push(Vec::new());
        for _ in 0..11 {
            ps[i].push(read())
        }
    }

    let ans = (1..1 << 10)
        .map(|pat| (0..n).map(|j| ps[j][open_num(pat, &fs[j])]).sum())
        .fold(-1 << 60, max);

    println!("{}", ans)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  V<> c(5);
  for (int i = 0; i < 6; ++i) {
    int a; cin >> a;
    ++c[a];
  }
  cout << (*max_element(begin(c), end(c)) == 2 ? "YES" : "NO") << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n,a[2020];
ll k;
const ll M=1e9+7;
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n>>k;
	fo(i,0,n)cin>>a[i];
	ll an=0,ans=0;
	fo(i,0,n) fo(j,i+1,n) if(a[i]>a[j])an++;
	fo(i,0,n) fo(j,0,n) if(a[i]>a[j])ans++;
	cout<<(an*k%M+k*(k-1)/2%M*ans)%M<<endl;
	return 0;
}


Measured memory_bytes: 256
use std::collections::*;
use std::io::*;
use std::*;
// template {{{
macro_rules! get {
    ($($t:tt),*; $n:expr) => {
        {
            let stdin = std::io::stdin();
            let ret = std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
                let line = line.unwrap();
                let mut it = line.split_whitespace();
                _get!(it; $($t),*)
            }).collect::<Vec<_>>();
            ret
        }
    };
    ($($t:tt),*) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut it = line.split_whitespace();
            _get!(it; $($t),*)
        }
    };
}
macro_rules! _get {
    ($it:ident; [char]) => {
        _get!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; [u8]) => {
        _get!($it; String).bytes().collect::<Vec<_>>()
    };
    ($it:ident; usize1) => {
        $it.next().unwrap().parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap().parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:tt),+) => {
        ($(_get!($it; $t)),*)
    };
}
// }}}

fn main() {
    let (n, d) = get!(usize, i64);
    let points = get!(i64, i64; n);
    let mut ans = 0;
    for (x, y) in points.iter() {
        if x * x + y * y <= d * d {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5264
N = int(input())
a = list(map(int, input().split()))

Alice = 0
Bob = 0

while len(a) > 0:
    m_a = max(a)
    Alice += m_a
    a.remove(m_a)

    if len(a) == 0:
        break
    else:
        m_a = max(a)
        Bob += m_a
        a.remove(m_a)

print(Alice-Bob)

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

const int MAXN = 2e5 + 5;
const int MOD = 998244353;

int N;
char s[MAXN];
int dp[MAXN][3][3];

void load() {
	scanf("%s", s);
}

inline int add(int x, int y) {
	x += y;
	if (x >= MOD)	
		x -= MOD;
	else if (x < 0)
		x += MOD;
	return x;
}

inline int mul(int x, int y) {
	return (long long)x * y % MOD;
}

int solve() {
	N = strlen(s);
	
	int cnt = 0;
	for (int i = 1; i < N; i++)
		cnt += s[i] == s[i - 1];
	
	if (cnt == N - 1)
		return 1;
	
	if (N == 3 && !cnt && s[0] != s[2])
		return 3;
		
	for (int i = 0; i < 3; i++)
		dp[0][i][i] = 1;
		
	for (int i = 1; i < N; i++) 
		for (int j = 0; j < 3; j++)
			for (int k = 0; k < 3; k++)
				for (int l = 0; l < 3; l++)
					if (l != k)
						dp[i][j][k] = add(dp[i][j][k], dp[i - 1][(j - k + 3) % 3][l]);
	
	int pot = 1;
	for (int i = 1; i < N; i++)
		pot = mul(pot, 3);
	
	int sum = 0;
	for (int i = 0; i < N; i++)
		sum += s[i] - 'a';
	
	int sol = !cnt + pot;
	for (int i = 0; i < 3; i++)
		sol = add(sol, -dp[N - 1][sum % 3][i]);
	
	return sol;
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 7424
#include<stdio.h>

int func(int,int,int);

int s;

int main(void){
  int n,i;

  while(scanf("%d %d",&n,&s),n){
    printf("%d\n",func(0,0,n));
  }

  return 0;
}

int func(int now,int sum,int num){

  int count=0;

  if(!num)return s==sum?1:0;

  if(now==10 || !num || sum>s) return 0;
  
    count+=func(now+1,sum+now,num-1);
    count+=func(now+1,sum,num);
    return count;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    int c[5]={0};
    REP(i,N){
        string s; cin>>s;
        if(s[0]=='M') c[0]++;
        if(s[0]=='A') c[1]++;
        if(s[0]=='R') c[2]++;
        if(s[0]=='C') c[3]++;
        if(s[0]=='H') c[4]++;
    }
    
    int ans=0;
    REP(i,5) for(int j=i+1;j<5;j++) for(int k=j+1;k<5;k++){
        ans+=c[i]*c[j]*c[k];
    }
    cout<<ans<<endl;
 
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static long MOD = 998244353;
  static HashMap<Long, Long> memo = new HashMap<>();

  public static void main(String[] args) {
    char[] s = sc.next().toCharArray();
    int N = s.length;
    boolean[] S = new boolean[N];
    for (int i = 0; i < N; i++) {
      S[i] = s[i] == '1';
    }
    System.out.println(solve(S));
  }

  static long solve(boolean[] s) {
    int N = s.length;
    long key = 0;
    if (N < 50) {
      key |= (long)N << 55;
      for (int i = 0; i < N; i++) {
        if (s[i]) key |= (1L << i);
      }
      if (memo.containsKey(key)) return memo.get(key);
    }
    long[][] count = new long[N][N];
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        boolean[] cs = new boolean[j - i + 1];
        for (int k = i; k <= j; k++) {
          cs[k - i] = s[k];
        }
        count[i][j] = count(cs);
      }
    }
//    for (int i = 0; i < N; i++) {
//      for (int j = i + 1; j < N; j++) {
//        System.err.println("i:" + i + " j:" + j + " " + count[i][j]);
//      }
//    }
//    System.err.println("");
    long[] dp = new long[N + 1];
    dp[0] = 1;
    for (int i = 0; i < N; i++) {
      dp[i] %= MOD;
      if (s[i]) {
        dp[i + 1] += dp[i] * 2;
      } else {
        dp[i + 1] += dp[i];
      }
      for (int j = i; j < N; j++) {
        dp[j + 1] += dp[i] * count[i][j] % MOD;
      }
//      System.err.println(Arrays.toString(dp));
    }
    dp[N] %= MOD;
    if (N < 50) {
      memo.put(key, dp[N]);
    }
    return dp[N];
  }

  static long count(boolean[] s) {
    long ret = 0;
    for (int i = 2; i <= s.length; i++) {
      if (s.length % i != 0) continue;
      boolean[] sub = new boolean[s.length / i];
      Arrays.fill(sub, true);
      for (int j = 0; j < s.length; j++) {
        sub[j % sub.length] &= s[j];
      }
      ret += solve(sub);
      if (ret >= MOD) ret -= MOD;
    }
    return ret;
  }
}


Measured memory_bytes: 93772
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

long long int solve(long long int n){
	if(n==2){return 3;}
	else if(n==4||n==6||n==9||n==11){return 2;}
	else{return 1;}
}

int main() {
	long long int n=0,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b>>c>>d;
	cout<<max(a*b,c*d);
	




	cout<<endl;
} 


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize
    }

    let mut graph: Vec<Vec<usize>> = vec![vec![]; n];
    let mut dp: Vec<usize> = vec![std::usize::MAX; n];

    for _ in 0..m {
        input! {
            x: usize,
            y: usize
        }
        graph[x - 1].push(y - 1);
    }

    let mut ans = 0;
    for i in 0..n {
        ans = std::cmp::max(ans, f(i, &graph, &mut dp));
    }

    println!("{}", ans);
}

fn f(node: usize, graph: &Vec<Vec<usize>>, dp: &mut Vec<usize>) -> usize {
    if dp[node] != std::usize::MAX {
        return dp[node];
    }

    let mut res = 0;

    for &next in graph[node].iter() {
        res = std::cmp::max(res, f(next, graph, dp) + 1);
    }
    dp[node] = res;

    res
}


Measured memory_bytes: 11904
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = lc()
x,y = li()


# F,Tコマンド圧縮
command = []
last = ""
com = ""
cnt = 0
for i, si in enumerate(s):
    if si != last:
        if i != 0:
            command.append((com, cnt))
        cnt = 1
        com = si
        last = si
    
    else:
        cnt += 1
        last = si
        
    if i == len(s)-1:
        command.append((com, cnt))
        
        
# コマンド処理
isx = 1
if command[0][0] == "F":
    x_cand = set([command[0][1]])
    y_cand = set([0])
    command = command[1:]
else:
    x_cand = set([0])
    y_cand = set([0]) 

for cmd, cnt in command:
    if cmd == 'F':
        if isx == 1:
            x_cand = set([xi+cnt for xi in x_cand]) | set([xi-cnt for xi in x_cand])
        elif isx == -1:
            y_cand = set([yi+cnt for yi in y_cand]) | set([yi-cnt for yi in y_cand])
        
    elif cmd == 'T':
        if cnt%2 == 1:
            isx *= -1
    
if x in x_cand and y in y_cand:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 5192
#pragma comment(linker, "/STACK: 2000000")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define double long double
#define x first
#define y second
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
#define PI 3.14159265358979
const ll mod=1000000007;
int n, ans;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin>>n;
    for(int i=1; i<=n; i++) ans+=i*(i+1)/2;
    //cout<<ans<<endl;
    for(int i=1; i<n; i++){
        int x, y;
        cin>>x>>y;
        ans-=min(x, y)*(n-max(x, y)+1);
    }
    cout<<ans;
}



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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

const int N = 2e3 + 10;

int ca[N], cb[N], t[N], f[N], c, ans;

int getans(int A, int B, int ty = 5){
	if(ty == 5) return A < B ? (B - 1) / (A + 1) + 1 : (A - 1) / (B + 1) + 1;
	else if(ty == 1) return (B - 1) / ans <= A - 1;
	else if(ty == 2) return (B - 1) / ans <= A;
}

int A, B, L, R;
char S[N];

int main(){

	int Case;
	scanf("%d", &Case);
	while(Case--){

		scanf("%d%d%d%d", &A, &B, &L, &R);

		ans = getans(A, B);
		c = 0;

		int l = 0, r = min(B, A / ans);
		while(l < r){
			int mid = (l + r + 1) >> 1;
			if(getans(A - mid * ans, B - mid, 1)) l = mid;
			else r = mid - 1;
		}

		if(l){
			A -= l * ans, B -= l;
			ca[++c] = ans, cb[c] = 1, t[c] = l, f[c] = 1; 
		}

		l = 0, r = min(A, ans);
		while(l < r){
			int mid = (l + r + 1) >> 1;
			if(getans(A - mid, B, 2)) l = mid;
			else r = mid - 1;
		}
		ca[++c] = l, cb[c] = 0, t[c] = 1, f[c] = 1;
		A -= l;


		l = B - A * ans;
		ca[++c] = 0, cb[c] = l, t[c] = 1, f[c] = 0;
		B -= l;

		assert(A * ans == B);
		ca[++c] = 1, cb[c] = ans, t[c] = A, f[c] = 1;

		For(i, L, R){
			int x = i;
			For(j, 1, c) 
				if((ca[j] + cb[j]) * t[j] < x) x -= (ca[j] + cb[j]) * t[j];
				else{
					x = (x - 1) % (ca[j] + cb[j]) + 1;
					putchar(x <= ca[j] ? 'A' : 'B');
					break;
				}
		}
		puts("");
		
	}
	
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
	int n, i, amount=100000;
	
	scanf("%d", &n);
	
	for (i=0; i<n; i++) {
		amount += amount*0.05;
		amount += 999;
		amount /= 1000;
		amount *= 1000;
	}
	
	printf("%d\n", amount);
	
	return 0;
}

Measured memory_bytes: 588
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
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;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];
    sort(all(a));
    sort(all(b));
    ll min_, max_;
    ll ans = 0;
    if(n & 1){
        min_ = a[n/2];
        max_ = b[n/2];
        ans = max_ - min_ + 1;
    }
    else{
        min_ = a[n/2-1] + a[n/2];
        max_ = b[n/2-1] + b[n/2];
        ans = max_ - min_ + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6344
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
int A[500001],h;

void maxHeapify(int i){
  int l=(i*2);
  int r=(i*2+1);
  int largest,temp;
  if(l<=h && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=h && A[r]>A[largest])largest=r;
  if(largest!=i){
    temp=A[i];
    A[i]=A[largest];
    A[largest]=temp;
    maxHeapify(largest);
  }
}

int main(){
  int i, j;

  scanf("%d", &h);
 for ( i = 1; i <= h; i++ ){
    scanf("%d", &A[i]);
  }
  for(i=h/2;i>=1;i--)maxHeapify(i);
   for ( j = 1; j <= h; j++ ){
     printf(" %d",A[j]);
   }
   printf("\n");
  return 0;
}




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

using namespace std;
int n;
//vector<int> a, b, c;

int res = 0;

class Data {
public:
	int a, i;
	Data() {
	}
	bool operator>(Data &rdt) {
		return this->a > rdt.a;
	}
	bool operator<(Data &rdt) {
		return this->a < rdt.a;
	}
};
vector<Data> dt;

int main() {
	cin >> n;
	dt.resize(n);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		dt[i].a = a;
		dt[i].i = i;
	}
	sort(dt.begin(), dt.end());
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (abs(i - dt[i].i) % 2 == 1)
			cnt++;
	}
	res = cnt / 2;
	cout << res << endl;
//	cin >> n;
	return 0;
}

Measured memory_bytes: 1024
N,M=map(int,input().split())
C=[0]*N
for i in range(N):
  C[i]=tuple(map(int,input().split()))
  
C.sort(key=lambda x:x[0])
cnt=0
cost=0

for i in range(N):
  #print(C[i][0],C[i][1])
  if cnt+C[i][1] < M:
    #print(cnt,cost)
    cnt += C[i][1]
    cost += C[i][0]*C[i][1]
  else:
    #print(cnt,cost)
    cost += (M-cnt)*C[i][0]
    break
    
print(cost)

Measured memory_bytes: 18092
import java.util.Scanner;

public class Main {
	static Scanner sc = new java.util.Scanner(System.in);

	public static void main(String[] args) {

		while (sc.hasNext()) {

			double v = sc.nextDouble();
			double y = (v * v) / (2 * 9.8);
			int n = 0;

			for (int i = 0;; i++) {
				if (y < (5 * i - 5)) {
					n = i;
					break;
				}
			}
			System.out.println(n);
		}
	}
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int r,c; cin>>r>>c;
	vector<vector<int>>s(r+1,vector<int>(c+1,0));
	for(int i=0;i<r;++i){
		for(int j=0;j<c;++j){
			cin>>s.at(i).at(j);
			s.at(i).back()+=s.at(i).at(j);
			s.back().at(j)+=s.at(i).at(j);
			s.back().back()+=s.at(i).at(j);
		}
	}
	for(int i=0;i<=r;++i){
		cout<<s.at(i).front();
		for(int j=1;j<=c;++j){
			cout<<" "s<<s.at(i).at(j);
		}
		cout<<"\n"s;
	}
}


Measured memory_bytes: 3212
#include<stdio.h>
#include<string.h>

int main(void){
  
  while(1){
  char su[1000];
  int i,nu = 0;
     scanf("%s",&su);
    if(su[0]=='0')
      break;
    else{
      for(i=0;i<strlen(su);i++)
            {
                nu+=su[i]-'0';
            }
            printf("%d\n",nu);
    }
  }
  return 0;
}


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

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

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

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

#define dump(x)  cout << #x << " = " << (x) << endl;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
//             0123456789 - digits. check the limits, int vs long
const int MX = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    int n;
    cin >> n;
    int cur;
    cin >> cur;
    int x;
    for (int i = 1; i < n; i++) {
        cin >> x;
        if (x > cur) {
            cur = x;
        } else if (cur > x + 1){
            cout << "No\n";
            return 0; 
        }
        // dump(cur);
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
func in() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func str() string {
	sc.Scan()
	return sc.Text()
}

var out = fmt.Println

func main() {
	n := float64(in())
	out(float64(int((n + 1) / 2)) / n)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX_N 10010000
#define pb push_back
vector<int> g[MAX_N];//tree
int c[MAX_N];
int N,root=0,parent[MAX_N],depth[MAX_N];

void dfs(int v,int p,int d){
  depth[v]=d;
  for(int i=0;i<g[v].size();i++){
    if(g[v][i]==p)continue; parent[g[v][i]]=v; dfs(g[v][i],v,d+1);
  }
}

void dfs2(int n, int x){
  for(int i=0;i<g[n].size();i++){
    if(parent[n]!=g[n][i]){c[g[n][i]]+=x; dfs2(g[n][i],c[g[n][i]]);}
  }
}

void add_edge(int u,int v){g[u].pb(v); g[v].pb(u);}

int main(){
  int N,Q;
  cin >> N >> Q;
  vector<int> a(N-1),b(N-1),p(Q),x(Q),m(N+10);
  for(int i=1;i<=N;i++){c[i]=0; m[i]=0;}
  for(int i=0;i<N-1;i++)cin >> a[i] >> b[i];
  for(int i=0;i<Q;i++)cin >> p[i] >> x[i];
  for(int i=0;i<N-1;i++){add_edge(a[i],b[i]);}
  dfs(1,-1,0);
  for(int i=0;i<Q;i++){c[p[i]]+=x[i];}
  dfs2(1,c[1]);
  for(int i=1;i<=N;i++)cout << c[i] << " ";
}

Measured memory_bytes: 265088
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(true){
int H=Integer.parseInt(sc.next());
int W=Integer.parseInt(sc.next());
if(H==0&&W==0){break;}
for(int i=0;i<H;i++){
for(int t=0;t<W;t++){System.out.print("#"); }System.out.println("");
 }System.out.println("");

}
}
}


Measured memory_bytes: 33476
// 8 Queens Problem
#include <stdio.h>
#include <stdlib.h>
#define N 8

void putQueen(int);
void printBoard();

int p[N][N] = {0};
int row[N] = {0};
int col[N] = {0};
int dneg[2*N] = {0};
int dpos[2*N] = {0};

int r[64] = {0}, c[64] = {0};
int k;

int main() {
  int i, j;

  // input
  scanf("%d", &k);
  for(i = 0; i < k; i++) {
    scanf("%d %d", &r[i], &c[i]);
    // cannot put another queen on this row and column
  }
  putQueen(0);
  
  return 0;
}

void putQueen(int i) {
  int j;
  int cnt = 0;
  
  if(i == N) {
    for(i = 0; i < k; i++) {
      if(p[r[i]][c[i]] == 1) cnt++;
    }
    if(cnt == k) printBoard();
    return;
  }

  for(j = 0; j < N; j++) {
    if((col[j] == 1)||(dpos[i+j] == 1)||(dneg[i-j+N-1]== 1))
      continue;
    // put a queen at (i, j)
    row[i] = j;
    col[j] = 1;
    dpos[i+j] = 1;
    dneg[i-j+N-1] = 1;
    p[i][j] = 1;
    // try the next row
    putQueen(i+1);
    // remove the queen at (i, j) for backtracking
    col[j] = 0;
    dpos[i+j] = 0;
    dneg[i-j+N-1] = 0;
    p[i][j] = 0;
  }
}

void printBoard() {
  int i, j;
  // output
  for(i = 0; i < N; i++) {
    for(j = 0; j < N; j++) {
      if(p[i][j] == 1) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2088
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;

int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n;
        cin >> n;
        int i,a[n+1];
        int m=inf;
        int ans=0;
        for(i=1; i<=n; i++){
            cin >> a[i];
            m=min(m,a[i]);
            if(m==a[i]){
                ans++;
            }
        }
        cout << ans << '\n';

        

}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
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 int long long

ll mod_pow(ll x, ll n, ll m) {
    if(n == 0) return 1;
    ll res = mod_pow(x * x % m, n / 2, m);
    if(n & 1) res = res * x % m;
    return res;
}

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(all(a));
    if(n % 2 == 0) {
        int j = 1;
        int cnt = 0;
        rep(i, n) {
            if(a[i] != j) {
                cout << 0 << endl; return;
            }
            cnt ++;
            if(cnt == 2) {
                j += 2;
                cnt = 0;
            }
        }
    }
    if(n % 2 == 1) {
        int j = 2;
        int cnt = 0;
        if(a[0] != 0) {
                cout << 0 << endl; return;
        }
        rep1(i, n - 1) {
            if(a[i] != j) {
                cout << 0 << endl; return;
            }
            cnt ++;
            if(cnt == 2) {
                j += 2;
                cnt = 0;
            }
        }
    }

    cout << mod_pow(2LL, (ll)n / 2, mod) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

int main()
{
	int Snuke[101];
	for(int i = 0; i <= 100; i++){
		Snuke[i] = 0;
	}
	int N, K;
	cin >> N >> K;
	for(int i = 0; i < K; i++){
		int d;
		cin >> d;
		for(int j = 0; j < d; j++){
			int A;
			cin >> A;
			Snuke[A]++; 
		}
	}
	
	int count = 0;
	for(int i = 1; i <=N; i++){
		if(Snuke[i] == 0){
			count++;
		}
	}
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 3652
import math
N,D= map(int,input().split())

A=[[int(a) for a in input().split()]for a in range(N)]

def int_test(a,n):
    if a.is_integer():
        n+=1

n=0


for i in range(0,N):

    if i != N:
        for j in range(i+1,N):
            sq=0.0
            for k in range(0,D):
                sq=sq+(A[i][k]-A[j][k])**2

            sq2=math.sqrt(sq)
            #print(i,j,k,sq2)
            if sq2.is_integer():
                n+=1

print(n)


Measured memory_bytes: 3064
from string import digits, ascii_uppercase

def parse(S, N, R):
    S = S + "$"
    cur = 0
    def expr():
        nonlocal cur
        *r0, = range(N)
        while 1:
            r = term()
            r0[:] = [r0[e] for e in r]
            if S[cur] != '+':
                break
            cur += 1 # '+'
        return r0
    def term():
        nonlocal cur
        if S[cur] in digits:
            # m(expr)
            k = number()
            if S[cur] == '(':
                cur += 1 # '('
                r = expr()
                cur += 1 # ')'
            else:
                r = identity()
            r = power(r, k)
        else:
            r = identity()
        return r
    def power(r, k):
        *r0, = range(N)
        r1 = r[:]
        while k:
            if k & 1:
                r0[:] = [r0[e] for e in r1]
            r1[:] = [r1[e] for e in r1]
            k >>= 1
        return r0
    def number():
        nonlocal cur
        v = 0
        while S[cur] in digits:
            v = 10*v + int(S[cur])
            cur += 1 # '0' ~ '9'
        return v
    def identity():
        nonlocal cur
        r = R[S[cur]]
        cur += 1 # 'A' ~ 'Z'
        return r
    return expr()

def main():
    N, K = map(int, input().split())
    R = {}
    for i in range(K):
        p, h = input().split(); h = int(h)
        *r, = range(N)
        for i in range(h-1):
            *g, = map(int, input().split())
            for j in range(N-1):
                if g[j]:
                    r[j], r[j+1] = r[j+1], r[j]
        R[p] = r
    E = int(input())
    for i in range(E):
        S = input()
        res = parse(S, N, R)
        print(*map(lambda x: x+1, res))
main()



Measured memory_bytes: 6920
use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {

    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);

}

fn solve(input: String) -> String {

    input!(input => (n:usize)(list: [i32]));    

    let mut a = Vec::new();

    for x in list {
        a.push(x);
    }
    
    a.sort_by(|a, b| b.cmp(a));
    
    let mut alice: i32;
    let mut bob: i32;

    alice = 0;
    bob = 0;
    
    let mut cnt: i32;
    cnt = 0;
    for i in a {
        if cnt % 2 == 0 {
            alice = alice + i;
        } else {
            bob = bob + i;
        }

        cnt = cnt + 1;
    }
    
    //println!("alice = {}  bob = {}", alice, bob);

    (alice - bob).to_string()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 1000000007;
auto mod = [](ll modx) {modx%=mo;modx+=mo;modx%=mo;return modx; };

int main()
{
ll n , k ;
cin >> n >> k ;
ll mx=0,mi=0;
rep(i,k){
  mi+=i;
  mx+=n-i;
}
ans=mod(ans+mx-mi+1);
for (ll i = k; i < n+1; i++)
{
  mi+=i;
  mx+=n-i;
  ans=mod(ans+mx-mi+1);
}

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

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


const int N = 1e4 + 10;
int par[N];

int find(int x) {
   if (par[x] != x) {
       par[x] = find(par[x]);
   }
   return par[x];
}

void unite(int x, int y) {
    int fx = find(x);
    int fy = find(y);
    // cout << x << " " << y << " " << fx << " " << fy << endl;
    if (fx != fy) {
        par[fx] = fy;
    }
}

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

int main() {
    int n, q;
    scanf("%d %d", &n, &q);

    for (int i = 0; i < n; ++i) {
        par[i] = i;
    }

    for (int i = 0; i < q; ++i) {
        int t, x, y;
        scanf("%d%d%d", &t, &x, &y);
        if (t) {
            printf("%d\n", same(x, y) ? 1 : 0);
        } else {
            unite(x, y);
        }
    }
    return 0;
}


Measured memory_bytes: 3268
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

template <class T>
void read(T &x)
{
	char ch;
	for (ch=getchar();(ch<'0'||ch>'9')&&ch!='-';) ch=getchar();
	x=0;int t=1;if (ch=='-') {ch=getchar();t=-1;}
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	x*=t;
}

char a[55];

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	scanf("%s",a+1);int n=strlen(a+1);
	if (n>9) {puts("NO");return 0;}
	for (int i=0;i<(1<<(n+1));i++)
	{
		int k=0;string s="";
		for (int j=0;j<n+1;j++)
		{
			if (i&(1<<j)) s+='A';
			if (j<n) s+=a[j+1];
		}
		if (s=="AKIHABARA") {puts("YES");return 0;}
	}
	puts("NO");
	return 0;
}



Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int m1,m2,d1,d2;
    cin >> m1 >> m2 >> d1 >> d2;
    cout << ((d2==1) ? 1 : 0) << endl;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
// using Graph = vector<vector<Edge>>;
const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

// 配るdp
int main()
{
    int N;
    cin >> N;
    vector<int> h(N + 5);
    vector<int> dp(N + 5, INF_32);

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

    dp[0] = 0;
    for (int i = 0; i < N - 1; i++) {
        dp[N - 1, i + 1] = min(dp[N - 1, i + 1], dp[i] + abs(h[i + 1] - h[i]));
        dp[N - 1, i + 2] = min(dp[N - 1, i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }

    cout << dp[N - 1] << endl;

    return 0;
}

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

ll mpower(ll a,ll b,ll c){
  int z;
  if(b==0){
    z=1;
    z%=c;
    return z;
  }
  if(b==1){
    z=a;
    z%=c;
    return z;
  }
  else{
    return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
  }
}

int main(){
  ll mod=1e9+7;
  int a;
  cin>>a;
  if(a%2==0){
    int vec[a];
    for(int i=0;i<a;i++){
      cin>>vec[i];
      if(vec[i]%2!=1){
        cout<<0<<endl;
        return 0;
      }
    }
    sort(vec,vec+a);
    for(int i=0;i<a;i++){
      if((i/2)*2+1!=vec[i]){
        cout<<0<<endl;
        return 0;
      }
    }
    cout<<mpower(2,a/2,mod)<<endl;
    return 0;
  }
  int vec[a];
  for(int i=0;i<a;i++){
    cin>>vec[i];
    if(vec[i]%2!=0){
      cout<<0<<endl;
      return 0;
    }
  }
  sort(vec,vec+a);
  for(int i=0;i<a;i++){
    if((i+1)/2*2!=vec[i]){
      cout<<0<<endl;
      return 0;
    }
  }
  cout<<mpower(2,a/2,mod)<<endl;
}

Measured memory_bytes: 640
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, const char * argv[]) {
    
    string s, ans;
    
    cin >> s;
    
    if(s[2] == s[3] && s[4] == s[5]) ans = "Yes";
    else ans = "No";
    
    cout << ans;


    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[][][] house = new int[3][10][4];
		String count = br.readLine();
		for(int i = 0 ; i < Integer.parseInt(count) ; i++){
			String info = br.readLine();
			String[] ia = info.split(" ");
			house[Integer.parseInt(ia[1])-1][Integer.parseInt(ia[2])-1][Integer.parseInt(ia[0])-1] += Integer.parseInt(ia[3]);
			                                                         
		}
		for(int i = 0 ; i < house[2][0].length ; i++){
			for(int j = 0 ; j < house.length ; j++){
				for(int k = 0 ; k < house[j].length ; k++){
					System.out.print(" " + house[j][k][i]);
				}
				System.out.println();
			}
			if(i != house[0][0].length-1) System.out.println("####################");
		}
	}

}

Measured memory_bytes: 19328
//おまじない
//#include <bits/stdc++.h>
#include <iostream>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 200000;

int main(){
    
    int n;
    ll a[maxn];
    map<ll,ll> m;
    set<ll> s;
    ll ans = 0;
    ll sum=0;
    
    cin >> n;
    rep(i,n)cin >> a[i];
    
    m[0]+=1;
    rep(i,n){
        sum += a[i];
        m[sum]+=1;
        s.insert(sum);
    }
    auto ite = s.begin();
    while(ite != s.end()){
        ll cnt = m[*ite];
        //cout <<*ite<<endl;
        ll add = cnt*(cnt-1)/2;
        ans += add;
        ite++;
    }
    
    cout << ans<<endl;
    
    return 0;
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ub upper_bound
#define int long long
#define vbe(sdk) sdk.begin(),sdk.end()
#define pb push_back
#define loop(i,a,b) for(int i=a;i<b;++i)
#define rloop(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define mod 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
#define pi 3.14159265358979323846
using namespace std;

bool isPalindrome(string str) 
{ 
    // Start from leftmost and rightmost corners of str 
    int l = 0; 
    int h = str.length() - 1; 
  
    // Keep comparing characters while they are same 
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        { 
            return false;
        } 
    } 
    return true;
} 

signed main()
{
    string s;
    cin>>s;
    int n=s.length();
    if(isPalindrome(s))
    {
       // cout<<"hello\n";
        string p=s.substr(0,((n-1)/2));
        string q=s.substr((n+3)/2-1,n-1);
       // cout<<p<<" "<<q<<"\n";
        if(isPalindrome(p) && isPalindrome(q))
        {
            cout<<"Yes\n";
        }
        else
        {
            cout<<"No\n";
        }
        
    }
    else
    {
        cout<<"No\n";
    }
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int x,n,k,q;
const int maxn=1e5+5;
int b[maxn];
int main()
{
    scanf("%d%d%d",&n,&k,&q);
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&x);
        b[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(k-q+b[i]>0)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


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

int main(){
  int A;
  int B;
  int S=0;
  int T=0;

  for(int i=0;i<4;++i){
    cin >> A;
    S+=A;
  }

  for(int i=0;i<4;++i){
    cin >> B;
    T+=B;
  }

  if(T>S) cout<<T<<endl;
  else cout<<S<<endl;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef long long ll;

int main(){
	int a, b;
	cin >> a >> b;
	if (a + b == 15) {
		cout << "+" << endl;
	}
	else if (a * b == 15) {
		cout << "*" << endl;
	}
	else {
		cout << "x" << endl;
	}
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    long long a[100001];
    for(int i = 0; i < n; i++) cin >> a[i];
    long long sum1 = 0;
    long long p1 = 0;
    long long sum2 = 0;
    long long p2 = 0;
    for(int i = 0; i < n; i++){
        sum1 += a[i];
        if(i%2 == 0 && sum1 <= 0){
            p1 += (1 - sum1);
            sum1 += (1 - sum1);
        }

        else if(i%2 == 1 && sum1 >= 0){
            p1 += (1 + sum1);
            sum1 -= (1 + sum1);
        }
    }
    for(int i = 0; i < n; i++){
        sum2 += a[i];
        if(i%2 == 1 && sum2 <= 0){
            p2 += (1 - sum2);
            sum2 += (1 - sum2);
        }

        else if(i%2 == 0 && sum2 >= 0){
            p2 += (1 + sum2);
            sum2 -= (1 + sum2);
        }
    }
    
    long long p = (p1 < p2) ? p1 : p2;
    cout << p << endl; 
    return 0;
}


Measured memory_bytes: 4276