akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define MOD 1000000007LL
//#define MOD 998244353LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[&](auto f,auto... args){return f(f,args...);};


int main(){
    string s;
    cin>>s;
    sort(all(s));
    rep(i,s.size()-1)if(s[i]==s[i+1]){
        cout<<"no"<<endl;
        return 0;
    }
    cout<<"yes"<<endl;
}

Measured memory_bytes: 256
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int input;
int output;

struct process{
	string name;
	int time;
};

void enque(process *a, process inProcess){
	if (input == 100000){
		input = 0;
	}
		a[input++] = inProcess;
}

process deque(process *a){
	if (output == 100000){
		output = 0;
	}
	return a[output++];
}

int main(){
	process a[100000];
	int n, q;
	cin >> n >> q;
	input = n;
	output = 0;
	long long totalTime = 0;

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

	process num;
	while(n){
		num = deque(a);
		if (num.time <= q){
			totalTime += num.time;
			cout << num.name << " " << totalTime << endl;
			n--;
		}
		else{
			totalTime += q;
			num.time -= q;
			enque(a, num);
		}
	}



	return 0;
}



Measured memory_bytes: 7076
# def make_divisors(n):
#     divisors = []
#     for i in range(1, int(n**0.5)+1):
#         if n % i == 0:
#             # divisors.append(i)
#             if i != n // i:
#                 x = (n//i)
#                 y = x + (n / x)
#                 divisors.append(y)
#
#     divisors.sort()
#     return divisors

def make_divisors2(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())

t = make_divisors2(n)
li = []
for i in t:
    li.append(i + n / i)

print(int(min(li)-2))






Measured memory_bytes: 3424
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
    int n;
    cin >> n;
    vector<int>h(n);
    rep(i,n) {
        cin >> h[i];
    }
    rep(i,n) {
        if(i==0 || h[i-1] < h[i]) h[i]--;
    }
    rep(i,n-1) {
        if(h[i] > h[i+1]) {
            cout << "No" << endl;
            return 0;
        }    
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 640
n = int(input())
a = sorted([int(i) for i in input().split()])
b = sorted([int(i) for i in input().split()])
c = sorted([int(i) for i in input().split()], reverse=True)

a.append(10**9)

check_a = 0
check_c = n - 1
ans = 0
for i in b:
    while a[check_a] < i and check_a < n :
        check_a += 1
    while c[check_c] <= i and check_c >= 0:
        check_c -= 1
    ans += check_a * (check_c + 1)
print(ans)

Measured memory_bytes: 22720
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

struct unionfind{
	vector<int> data;
	vector<int> size;
	unionfind(int n){
		for(int i=0;i<n;i++){
			data.push_back(i);
			size.push_back(1);
		}
	}
	
	int find(int x){
		if(data[x]==x)return x;
		return data[x]=find(data[x]);
	}
	
	bool unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return false;
		if(size[x]>size[y])swap(x,y);
		data[x]=y;
		size[y]+=size[x];
		return true;
	}
	
	bool check(int x,int y){
		return (find(x)==find(y));
	}
	
	int get_size(int x){
		int X = find(x);
		return size[X];
	}
};

int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<pair<long long,int>> a(N);
	for(int i=0;i<N;i++){
		cin>>a[i].first;
		a[i].second = i;
	}
	
	sort(a.begin(),a.end());
	
	unionfind uf(N);
	for(int i=0;i<M;i++){
		int x,y;
		cin>>x>>y;
		uf.unite(x,y);
	}
	
	map<int,int> mp;
	set<int> S;
	long long ans = 0;
	long long cnt = 2*(N-1-M);
	
	if(cnt==0){
		cout<<0<<endl;
		return 0;
	}
	
	for(int i=0;i<N;i++){
		int x = uf.find(a[i].second);
		if(mp.count(x))continue;
		cnt--;
		ans+=a[i].first;
		mp[x]++;
		S.insert(i);
	}
	
	for(int i=0;i<N;i++){
		if(S.count(i))continue;
		int x = uf.find(a[i].second);
		if(mp[x]==N-1-M)continue;
		cnt--;
		ans += a[i].first;
		mp[x]++;
		if(cnt==0)break;
	}
	
	if(cnt==0)cout<<ans<<endl;
	else cout<<"Impossible"<<endl;
	
	return 0;
}

Measured memory_bytes: 12020
#include <stdio.h>

#define MAX 1000000
#define NIL -1

typedef struct Node {
	int p, l, r;
} Node;

Node T[MAX];

int n;

void preParse(int t){
	if(t == NIL) return;
	printf(" %d",t);
	preParse(T[t].l);
	preParse(T[t].r);
}

void inParse(int t){
	if(t == NIL) return;
	inParse(T[t].l);
	printf(" %d",t);
	inParse(T[t].r);
}

void postParse(int t){
	if(t == NIL) return;
	postParse(T[t].l);
	postParse(T[t].r);
	printf(" %d",t);
}


int main(void){

	int i,v,l,r,root;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		T[i].p = NIL;
	}

	for(i=0;i<n;i++){

		scanf("%d %d %d",&v,&l,&r);
		
		T[v].l = l;
		T[v].r = r;
		if(l != NIL){
			T[l].p = v;
		}
		if(r != NIL){
			T[r].p = v;	
		}
	}

	for(i=0;i<n;i++){
		if(T[i].p == NIL){
			root = i;
		}
	}

	printf("Preorder\n");
	preParse(root);
	printf("\n");
	printf("Inorder\n");
	inParse(root);
	printf("\n");
	printf("Postorder\n");
	postParse(root);
	printf("\n");

	return 0;
}











Measured memory_bytes: 2092
fun main(args: Array<String>) {
    val (X, Y) = readLine()!!.split(" ").map(String::toInt)
    var ans = 0
    ans += Math.max(0, 400000 - X * 100000)
    ans += Math.max(0, 400000 - Y * 100000)
    if (X == 1 && Y == 1) ans += 400000
    println(ans)
}

Measured memory_bytes: 38112
fn main() {
    let n: u64 = read();
    println!("{}", n / 2 + n % 2);
}

use std::io::stdin;
use std::io::Read;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let token: String = cin
        .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")
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

typedef struct {
  int h;
  int w;
  int magic;
} pos;

int h, w;
int sh, sw, gh, gw;
vector<string> mp;
vector<vector<int>> dis;
vector<pos> vec;
queue<pos> que;

void dfs(pos p){
  int y = p.h, x = p.w;
  int magic = p.magic;
  if(mp[y][x] != '.' || dis[y][x] != -1) return;
  dis[y][x] = magic;
  vec.push_back({y, x, magic});
  if(y+1 < h && mp[y+1][x] == '.' && dis[y+1][x] == -1){
    dfs({y+1, x, magic});
  }
  if(y-1 >= 0 && mp[y-1][x] == '.' && dis[y-1][x] == -1){
    dfs({y-1, x, magic});
  }
  if(x+1 < w && mp[y][x+1] == '.' && dis[y][x+1] == -1){
    dfs({y, x+1, magic});
  }
  if(x-1 >= 0 && mp[y][x-1] == '.' && dis[y][x-1] == -1){
    dfs({y, x-1, magic});
  }
}

int main(){
  cin >> h >> w;
  cin >> sh >> sw >> gh >> gw;
  sh--; sw--; gh--; gw--;
  rep(i, h) dis.push_back(vector<int>(w, -1));
  rep(i, h){
    string str;
    cin >> str;
    mp.push_back(str);
  }
  pos p;
  p.h = sh;
  p.w = sw;
  p.magic = 0;
  que.push(p);
  while(!que.empty()){
    vec.clear();
    pos p = que.front();
    que.pop();
    dfs(p);
    rep(i, vec.size()){
      pos tp = vec[i];
      int y = tp.h, x = tp.w;
      for(int i=-2; i<=2; i++){
        for(int j=-2; j<=2; j++){
          if(i==0 && j==0) continue;
          if(!(y+i>=0 && y+i<h && x+j>=0 && x+j<w)) continue;
          if(mp[y+i][x+j] == '.' && dis[y+i][x+j] == -1) que.push({y+i, x+j, tp.magic+1});
        }
      }
    }
  }
  cout << dis[gh][gw] << endl;
  return 0;
}
  

Measured memory_bytes: 8852
let isLower c = (c >= 'a') && (c <='z')

let S = stdin.ReadLine().ToCharArray()
let N = Array.length S

let check1 =
  S.[0] = 'A'
let check2 = 
  S.[2..(N - 2)]
  |> Array.filter ((=) 'C')
  |> Array.length
  |> (=) 1
let check3 = 
  S
  |> Array.filter isLower
  |> Array.length
  |> (=) (N - 2)

if (check1 && check2 && check3) then "AC" else "WA" 
|> printfn "%s"


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

ll judge(int n) {
  ll ans = 0;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ans++;
      if(n / i != i)
        ans++;
    }
  }
  return ans;
}

int main() {
  int n;
  cin >> n;

  ll ans = 0;
  rep(i, n - 1) {
    ans += judge(n - i - 1);
  }

  cout << ans;
}


Measured memory_bytes: 3644
from collections import deque
S = deque(list(input()))
Q = int(input())
parity = 0

for i in range(Q):
    query = input().split()
    if len(query) == 1:
        parity += 1
    else:
        if int(query[1]) == 1 + (parity % 2):
            S.appendleft(query[2])
        else:
            S.append(query[2])
S = ''.join([c for c in S])
if parity % 2 == 1:
    S = S[::-1]
print(S)

Measured memory_bytes: 90856
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll A, B, C;
    cin >> A >> B >> C;
    if ((A <= C && C <= B) || (B <= C && C <= A)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int H, W;
    while (1) {
        cin >> H >> W;
        if (W == 0 && H == 0) break;
        for(int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (0 < i && i < H - 1 && 0 < j && j < W - 1) {
                    cout << ".";
                } else {
                    cout << "#";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3008
#include<iostream>
#define MOD 1000000007
using namespace std;
int n,k,i,j,ind,X[305],Y[305],Nr[605],Fact[605],g,Dp[605][605],rez,val;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(i=1; i<=k; i++)
    {
        cin>>X[i]>>Y[i];
        if(X[i]>Y[i])
            swap(X[i],Y[i]);
        Nr[X[i]]=-1;
        Nr[Y[i]]=-1;
    }
    for(i=1; i<=2*n; i++)
        Nr[i]=Nr[i]+Nr[i-1]+1;
    Fact[0]=1;
    Fact[2]=1;
    for(i=4; i<=2*n; i+=2)
        Fact[i]=(1LL*Fact[i-2]*(i-1))%MOD;
    for(i=1; i<=2*n; i++)
    {
        for(j=i+1; j<=2*n; j+=2)
        {
            g=1;
            for(ind=1; ind<=k; ind++)
                if((X[ind]<i && Y[ind]>=i && Y[ind]<=j) || (X[ind]>=i && X[ind]<=j && Y[ind]>j))
                {
                    g=0;
                    break;
                }
            if(g==0)
                continue;
            Dp[i][j]=Fact[Nr[j]-Nr[i-1]];
            for(ind=i+1; ind<j; ind+=2)
            {
                val=(1LL*Dp[i][ind]*Fact[Nr[j]-Nr[ind]])%MOD;
                Dp[i][j]=(Dp[i][j]-val+MOD)%MOD;
            }
            val=(1LL*Dp[i][j]*Fact[Nr[2*n]-Nr[j]+Nr[i-1]])%MOD;
            rez=(rez+val)%MOD;
        }
    }
    cout<<rez<<"\n";
    return 0;
}


Measured memory_bytes: 1664
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private int ans = Integer.MAX_VALUE;

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[][] A = new int[N][M];
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < M; ++j) {
                A[i][j] = sc.nextInt() - 1;
            }
        }
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < M; ++i) {
            set.add(i);
        }

        calc(A, N, M, set);

        _out.println(ans);
    }
    private void calc(int[][] A, int N, int M, Set<Integer> set) {
        int[] cnt = new int[M];
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < M; ++j) {
                if (set.contains(A[i][j])) {
                    ++cnt[A[i][j]];
                    break;
                }
            }
        }
        int P = -1;
        int max = 0;
        for (int i = 0; i < M; ++i) {
            if (cnt[i] > max) {
                max = cnt[i];
                P = i;
            }
        }
        if (max < ans) {
            ans = max;
        }

        set.remove(P);
        if (set.size() > 0) {
            calc(A, N, M, set);
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 86972
#include <iostream>
#include <string>
#include <algorithm>

int main()
{
  std::string word;
  std::cin >> word;
  uint count = 0;
  while (std::cin.peek() != EOF) {
    std::string s;
    std::cin >> s;
    std::transform(std::begin(s), std::end(s), std::begin(s), tolower);
    if (s == word) count++;
  }
  std::cout << count << std::endl;
}



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

int main() {
    int n, sum = 0;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n; ++i) {
        if(s[i] == '(') {
            sum++;
        } else {
            if(sum > 0) sum--;
        }
    }
    for(int i = 0; i < sum; ++i) {
        s += ')';
    }
    sum = 0;
    for(int i = 0; i < s.size(); ++i) {
        if(s[s.size()-i-1] == ')') {
            sum++;
        } else {
            if(sum > 0) sum--;
        }
    }
    for(int i = 0; i < sum; ++i) {
        s = '(' + s;
    }
    cout << s << '\n';
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> matrix(H, vector<char>(W));
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      cin >> matrix.at(i).at(j);
    }
  }
  
  for (int j=0; j<W; j++) {
    for (int i=0; i<H; i++) {
      if (matrix.at(i).at(j) == '#') {
        break;
      }
      if (i==H-1) {
        if (j==W-1) {
          for (int k=0; k<H; k++) {
            matrix.at(k).at(j)='o';
          }
        }
        else {
          for (int k=0; k<H; k++) {
            matrix.at(k).at(j)='x';
          }
        }
      }
    }
  }
  
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (matrix.at(i).at(j) == '#') {
        break;
      }
      if (j==W-1) {
        for (int k=0; k<W; k++) {
          matrix.at(i).at(k)='x';
        }
      }
    }
  }

  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (matrix.at(i).at(j) != 'x' && matrix.at(i).at(j) != 'o') {
        cout << matrix.at(i).at(j);
        if (j==W-1) {
          cout << endl;
        }
      }
      if (matrix.at(i).at(j) == 'o') {
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 256
N=int(input())
A=sorted([int(i) for i in input().split()])
Plus=[]
Noplus=[]
for i in A:
    if i>0:
        Plus.append(i)
    else:
        Noplus.append(i)
X=len(Plus)
Y=len(Noplus)
if Y==0:
    #全部正
    #-b1+b2+...bn
    M=sum(A)-2*min(A)
    print(M)
    tmp=A[0]
    for i in range(1,N):
        if i!=N-1:
            print(tmp,A[i])
            tmp-=A[i]
        else:
            print(A[i],tmp)
            tmp=A[i]-tmp
elif X==0:
    #全部負
    #-b1-b2-...-b(n-1)+bn
    M=-sum(A)+2*max(A)
    print(M)
    tmp=A[N-1]
    for i in range(N-1):
        print(tmp,A[i])
        tmp-=A[i]
elif X<Y:
    print(sum([abs(i) for i in A]))
    D=Y-X
    #X:+,X+D:-
    #負の方が多い
    tmp=Plus.pop()
    for i in range(D):
        tmp2=Noplus.pop()
        print(tmp,tmp2)
        tmp-=tmp2
    #Plus:X-1個,tmp
    #Noplus:Y-D-1=X個
    tmp2=Noplus.pop()
    print(tmp,tmp2)
    tmp-=tmp2
    for i in range(X-1):
        tmp2=Noplus.pop()
        print(tmp2,tmp)
        tmp=tmp2-tmp
        tmp2=Plus.pop()
        print(tmp2,tmp)
        tmp=tmp2-tmp
else:
    print(sum([abs(i) for i in A]))
    #Y<X
    D=X-Y
    #Y+D:+,Y:-
    #正の方が多い
    tmp=Noplus.pop()
    for i in range(D):
        tmp2=Plus.pop()
        print(tmp,tmp2)
        tmp-=tmp2
    #Plus:X-D=Y個
    #Noplus:Y-1個,tmp
    tmp2=Plus.pop()
    print(tmp2,tmp)
    tmp=tmp2-tmp
    for i in range(Y-1):
        tmp2=Noplus.pop()
        print(tmp2,tmp)
        tmp=tmp2-tmp
        tmp2=Plus.pop()
        print(tmp2,tmp)
        tmp=tmp2-tmp

Measured memory_bytes: 14332
n, m = gets.split.map(&:to_i)
ps = m.times.map {gets.split}
memo = Array.new(n + 1)
penalty_memo = Hash.new(0)
score = penalty = 0

ps.each do |p, s|
  p0 = p.to_i
  next if memo[p0]
  case s
  when "AC"
    score += 1
    penalty += penalty_memo[p0]
    memo[p0] = true
  else
    penalty_memo[p0] += 1
  end
end

puts "#{score} #{penalty}"
    


Measured memory_bytes: 20988
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<LL> a(n);
  REP(i, 0, n) cin >> a[i];
  a.erase(unique(ALL(a)), a.end());
  DUMP(a);
  n=a.size();
  int cnt = 0;
  REP(i, 1, n - 1) {
    LL pre = a[i - 1];
    LL now = a[i];
    LL next = a[i + 1];
    if ((pre < now && now > next) || (pre > now && now < next)) {
      ++cnt;
      // cerr<<i<<endl;
      ++i;
    }
  }
  ++cnt;
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 1024
import bisect
n,k,c = map(int,input().split())
s = input()

lst = []
for i in range(n):
    if s[i]=='o':
        lst.append(i+1)

x,y = [],[]
for i in range(len(lst)):
    if i==0:
        x.append(lst[i])
    else:
        if lst[i]-x[-1]>c:
            x.append(lst[i])
    if len(x)==k:
        break

for i in range(len(lst))[::-1]:
    if i==len(lst)-1:
        y.append(lst[i])
    else:
        if y[-1]-lst[i]>c:
            y.append(lst[i])
    if len(y)==k:
        break

x.sort()
y.sort()

ans = []
for i in range(k):
    if x[i]==y[i]:
        ans.append(x[i])
for a in ans:
    print(a)

Measured memory_bytes: 17516
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()

import math

print(2**int(math.log2(N)))

Measured memory_bytes: 3060
// A - Harmony

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

int main() {
	int A, B;
	cin >> A >> B;

	int ans;
	if ((A + B) % 2 == 0) {
		cout << (A + B) / 2 << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}

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

void solve()
{
	int x;
	cin >> x;
	int ans = 1;
	for(int i = 2; i * i <= x; i++)
	{
		int score = i * i;
		do
		{
			ans = max(ans, score);
			score *= i;
		} while (score <= x);
	}
	cout << ans << "\n";
}

int main()
{
	solve();
}


Measured memory_bytes: 256
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <thread>
#include <unordered_set>
#include <vector>
#include <memory.h>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <stdio.h>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <random>
#include <string>
#include <cassert>


#define getcx _getchar_nolock

using namespace std;
 
namespace std
{
	string to_string(string const& s) { return '"' + s + '"'; }
	string to_string(char c) { return string(1, c); }
	string to_string(const char* s) { return to_string((string)s); }
	string to_string(bool b) { return (b ? "true" : "false"); }
 
	template <class T1, class T2>
	string to_string(pair<T1, T2> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
 
	template <class T>
	string to_string(T c)
	{
		string s = "[";
		for (auto vvv : c) { s += to_string(vvv) + ","; }
		s += "]";
		return s;
	}
 
	void debug_impl() { cerr << endl; };
 
	template <typename T1, typename... T2>
	void debug_impl(T1 a, T2 ... b)
	{
		cerr << " " << to_string(a);
		debug_impl(b...);
	}
}
 
template <typename T>
struct reversion_wrapper
{
	T& iterable;
};
 
template <typename T>
auto begin(reversion_wrapper<T> w) { return std::rbegin(w.iterable); }
 
template <typename T>
auto end(reversion_wrapper<T> w) { return std::rend(w.iterable); }
 
template <typename T>
reversion_wrapper<T> reverse(T&& iterable) { return { iterable }; }
 
template<class T>T gcd(T a, T b) { while (a && b)if (a > b)a %= b; else b %= a; return a + b; }
template<class T>T powmod(T a, T b, T mod) { if (b == 0)return 1 % mod; T res = powmod(a, b / 2, mod); res *= res; res %= mod; if (b & 1) { res *= a; res %= mod; } return res; }
template<class T>T inv(T a, T mod) { return powmod(a, mod - 2, mod); }
 
#ifdef __ASD__
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_impl(__VA_ARGS__)
#define endl "\n"
#else
#define dbg(...) ;
#define endl "\n"
#endif
 
#define lng long long

lng const MOD = 998244353;


int main()
{
#ifdef __ASD__
	auto start_t = chrono::steady_clock::now();
	freopen("input.txt", "r", stdin);
	//freopen("1nul", "w", stderr);
	//freopen("output.txt", "w", stdout);
#else
	ios_base::sync_with_stdio(false);
#endif

	int n, x, y;
	cin >> n >> x >> y;

	vector<int> res(n);

	for(int i=1;i<=n;i++) {
		for(int j=i+1;j<=n;j++) {

			int d = abs(i-j);
			d=min(d, abs(i-x)+abs(j-y)+1);
			d=min(d, abs(j-x)+abs(i-y)+1);
			dbg(i,j,d);
			res[d]++;
		}
	}

	for(int i=1;i<n;i++)cout<<res[i]<<endl;

#ifdef __ASD__
	auto finish_t = chrono::steady_clock::now();
	cerr << "Elapsed " << chrono::duration_cast<chrono::milliseconds>(finish_t - start_t).count() << " ms" << endl;
#endif
	return 0;
}

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

using namespace std;
#define REP(i,n) for(int i = 0; i <(n);i++)

int main()
{
  int N;
  string vote[103];
  while(cin >> N,N){
    REP(i,N){
     cin >> vote[i];
    }
    pair<int,char> count[26];
    REP(i,26){
      count[i] = make_pair(0,'A' + i);
    }
    int endtime = -1;
    char ans;
    REP(i,N){
      count[vote[i][0] - 'A'].first++;
      pair<int,char> tmpcount[26];
      copy_n(count, 26, tmpcount);
      sort(tmpcount, tmpcount + 26, greater<pair<int,char> >());
      REP(i,26){
        //                cout << tmpcount[i].first << ' ' << tmpcount[i].second << endl;
      }
      if(tmpcount[0].first > tmpcount[1].first + N - i - 1){
        endtime = i;
        ans = tmpcount[0].second;
        break;
      }
    }
    if(endtime == -1){
      sort(count, count + 26, greater<pair<int,char> >());
      if(count[0].first == count[1].first) cout << "TIE" << endl;
      else cout << count[0].second << ' ' << N << endl;
    }else{
      cout << ans << ' ' << endtime + 1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3156
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

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

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

struct Scanner {
    FILE* fp = nullptr;
    char line[1 << 15];
    size_t st = 0, ed = 0;
    void reread() {
        memmove(line, line + st, ed - st);
        ed -= st;
        st = 0;
        ed += fread(line + ed, 1, (1 << 15) - ed, fp);
    }
    bool succ() {
        while (true) {
            if (st == ed) {
                reread();
                if (st == ed) return false;
            }
            while (st != ed && isspace(line[st])) st++;
            if (st != ed) break;
        }
        if (ed - st <= 50) reread();
        return true;
    }
    template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
    bool read_single(T& ref) {
        if (!succ()) return false;
        while (true) {
            succ();
            size_t sz = 1;
            while (st + sz < ed && !isspace(line[st + sz])) sz++;
            ref.append(line + st, sz);
            st += sz;
            if (st != ed) break;
        }
        return true;
    }
    template <class T, enable_if_t<is_integral<T>::value, int> = 0>
    bool read_single(T& ref) {
        if (!succ()) return false;
        bool neg = false;
        if (line[st] == '-') {
            neg = true;
            st++;
        }
        ref = T(0);
        while (isdigit(line[st])) {
            ref = 10 * ref + (line[st++] - '0');
        }
        if (neg) ref = -ref;
        return true;
    }
    void read() {}
    template <class H, class... T> void read(H& h, T&... t) {
        bool f = read_single(h);
        assert(f);
        read(t...);
    }
    Scanner(FILE* _fp) : fp(_fp) {}
};

int main() {
    Scanner sc(stdin);
    int n;
    string s;
    sc.read(n, s);
    string t;
    for (char c: s) {
        if (t.empty() || t.back() != c) t.push_back(c);
    }
    cout << t.size() << endl;
    return 0;
}


Measured memory_bytes: 640
#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);
  int n; cin >> n;
  for (int _ = 0; _ < n; ++_) {
    V<> a(3); for (int i = 0; i < 3; ++i) cin >> a[i];
    sort(begin(a), end(a));
    cout << (a[0] * a[0] + a[1] * a[1] == a[2] * a[2] ? "YES" : "NO") << '\n';
  }
}


Measured memory_bytes: 2980
N=gets.to_i
ary = gets.split.map(&:to_i)
h = {}
ary.each do |elm|
  if h[elm].nil?
    h[elm] = 1
  else
    h[elm] += 1
  end
end
total = 0
h.each do |key,val|
  if 1 < val
    total += val * (val -1) / 2
  end
end

N.times do |k|
  k_key = ary[k]
  val = h[k_key]
  k_val = h[k_key] - 1
  tmp = 0
  org = 0
  if 1 < val
    org = (val * (val - 1) ) / 2
    tmp = (k_val * (k_val - 1) ) / 2
  end
  puts total - (org - tmp)
end


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

#define ff first
#define ss second
#define endl '\n'

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

	int x;
	cin >> x;

	int max = 200001;
	bool isPrime[200001];
	for (int i = 0; i < max; ++i) {
		isPrime[i] = 1;
	}

	for (int p = 2; p * p <= max; ++p) {
		if (!isPrime[p]) {
			continue;
		}

		for (int i = p * p; i <= max; i += p) {
			isPrime[i] = 0;
		}
	}

	for (int i = 2; i < max; ++i) {
		if (isPrime[i] && i >= x) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  int n; cin >> n;
  vector<int> h(n);
  int ans = 0, res = 0;
  rep(i, n) cin >> h[i];
  rep(i, n-1) {
    if(h[i] >= h[i+1]) res++;
    else ans = max(ans, res), res = 0;
  }
  ans = max(ans, res);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
N=int(input())
P=list(map(int,input().split()))
q=N
cnt=0
A=[]
for i in range(N):
  q=min(q,P[i])
  A.append(q)
for i in range(N):
  if A[i]>=P[i]:
    cnt=cnt+1
print(cnt)

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

int main(){
  int w,h,x,y;
  scanf("%d%d%d%d", &w, &h, &x, &y);
  printf("%lf %d\n", double(w)*double(h)/2, x*2==w && y*2==h);
 }


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

#define dbg(x) cerr<<#x": "<<x<<"\n"
#define dbg_p(x) cerr<<#x": "<<x.first<<","<<x.second<<"\n"
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define st first
#define nd second

#define DMAX 
#define NMAX 
#define MMAX 

using namespace std;

int n, k, a, b;

template<class T>
ostream& operator<<(ostream& out, vector<T> v) {
	out << v.size() << '\n';
	for(auto e : v) out << e << ' ';
	return out;
}


long long cb(int low, int high) {
	while(low != high) {
		int mid = (low + high + 1) / 2;
		long long j = (a * b / mid);
		if(mid * j == a * b) j--;
		if(mid > j) // nu e ok mid-ul
			high = mid - 1;
		else low = mid;
	}
	return 1;
}

long long solve(long long a, long long b)
{
	if(b > a) swap(a, b);
	long long ans = 2 * b - 1;
	if(a == b || a == b + 1)
		ans--;
	//ans++; // b* (a - 1)
	// dbg(ans);
	// int maxb = cb(b + 1, a - 2);

	if(a - b > 1000000) {
		int i;
		long long maxj = a - 2;
		for(i = b + 1; i < a; i+=10000) {
			long long j = (a * b / i);
			if(i * j == a * b) j--;
			// if(j > maxj) j = maxj;
			// maxj = j - 1;
			// dbg(i);
			// dbg(j);
			if(i >= j) break;
			else ans += 20000;
		}
		i -= 10000;
		ans -= 20000;
		for(; i < a; i++) {
			long long j = (a * b / i);
			if(i * j == a * b) j--;
			// if(j > maxj) j = maxj;
			// maxj = j - 1;
			// dbg(i);
			// dbg(j);
			if(i > j) break;
			if(i == j)
				ans++;
			else ans += 2;
		}
		
		return ans;
	}


	long long maxj = a - 2;
	for(int i = b + 1; i < a; i++) {
		long long j = (a * b / i);
		if(i * j == a * b) j--;
		// if(j > maxj) j = maxj;
		// maxj = j - 1;
		// dbg(i);
		// dbg(j);
		if(i > j) break;
		if(i == j)
			ans++;
		else ans += 2;
	}


	return ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++)	{
		cin >> a >> b;
		cout << solve(a, b) << '\n';
	}
}

Measured memory_bytes: 256
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> Dbg &dump(C b, C e) {
    *this << "\n[";
    int cur = 0;
    for (C i = b; i!=e and cur<26; i++, cur++) *this << ", "+2*(i==b) << *i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<sizeof(C)!=1, Dbg&>::type operator <<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << '{' << x.first << ", " << x.second << '}';
}
template<class C, size_t Y> struct TP {
    void operator()(Dbg& os, const C &t) { TP<C, Y-1>()(os, t); os << ", " << get<Y-1>(t); }
};
template<class C> struct TP<C, 1> { void operator()(Dbg& os, const C &t) { os << get<0>(t); } };
template<class... C> Dbg& operator<<(const tuple<C...> &t) {
    os << '{', TP<decltype(t), sizeof...(C)>()(*this, t); return *this << '}';
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args ...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(string(#args)), args), dbg << endl
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 200005;

int n, dp[mxn], nxt[mxn], occ[30];
char a[mxn], ans[mxn];

signed main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.precision(11);
    cin >> a;
    n = sl(a);
    for (int i = 0; i < 26; i++) {
        occ[i] = n;
    }
    dp[n] = 1, ans[n] = 'a', nxt[n] = n+1;
    for (int i = n-1; i >= 0; i--) {
        occ[a[i]-'a'] = i;
        dp[i] = inf;
        for (int j = 0; j < 26; j++) {
            if(occ[j]==n){dp[i] = 1, ans[i] = char(j+'a'), nxt[i] = n+1; break;}
            if (1+dp[occ[j]+1]<dp[i]) dp[i] = 1+dp[occ[j]+1], ans[i] = char(j+'a'), nxt[i] = occ[j]+1;
        }
    }
    int tmp = 0;
    while (tmp<n+1) {
        cout << ans[tmp];
        tmp = nxt[tmp];
    }
    cout << '\n';
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int n, d[101010];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> d[i];
	}
	
	sort(d, d+n);
	cout << d[n/2] - d[n/2-1] << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n,t,a[200001];
signed main()
{
	int ans;
	scanf("%d%d",&t,&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	ans=a[n]-a[1];
	for(int i=1;i<n;i++)
	ans=min(ans,t-a[i+1]+a[i]);
	printf("%d",ans);
    return 0;
}

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

using namespace std;

const int N = 3e5 + 5;

int n, a[15], ans;

void rec(int cur, int pr) {
    if (cur == n + 1) {
        if (pr % 2 == 0) {
            ans++;
        }
        return;
    }
    rec(cur + 1, pr * (a[cur] - 1));
    rec(cur + 1, pr * a[cur]);
    rec(cur + 1, pr * (a[cur] + 1));
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    rec(1, 1);
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char ch[100009],temp;
    scanf("%s",&ch);
    int len=strlen(ch),cnt=0;
    if(len==1)
    {
        printf("0\n");
        return 0;
    }
    for(int i=0; i<len-1; i++)
    {
        if(ch[i]==ch[i+1])
        {
            if(ch[i]=='0')
            {
                temp=ch[i+1];
                ch[i+1]='1';
                ++cnt;
            }
            else if(ch[i]=='1')
            {
                temp=ch[i+1];
                ch[i+1]='0';
                ++cnt;
            }
        }
    }
    printf("%d\n",cnt);
}


Measured memory_bytes: 384
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("IMPOSSIBLE");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=5e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}

	const int N=5e3+10;
	//------------------FIXED------------------
	vc<int> son[N];int wt[N],dp[N];
	int f[N],g[N];
	void solve(int x)
	{
		for(auto y:son[x]) solve(y);
		mem(f,0x3f);f[0]=0;
		for(auto y:son[x])
		{
			mem(g,0x3f);
			fo(i,0,N-1-wt[y]) chmin(g[i+wt[y]],f[i]+dp[y]);
			fo(i,0,N-1-dp[y]) chmin(g[i+dp[y]],f[i]+wt[y]);
			Swap(f,g,N-1);
		}
		dp[x]=INF;fo(i,0,wt[x]) chmin(dp[x],f[i]);if(dp[x]==INF) GG();
		if(x==1)
			deb;
	}
	void main()
	{
		int n=qread();fo(i,2,n) son[qread()].PB(i);fo(i,1,n) wt[i]=qread(); solve(1);
		puts("POSSIBLE");
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 512
# include<iostream>
# include<algorithm>
# include<map>
# include<cstring>
using namespace std;

long long  cal(long long  i)
{
	 long long sum = (i)*(i-1)/2;
	 return sum;
}
int main ()
{
	 map <string,long long > mp;
	 int N; 
	 cin>>N;
	 string k[N];
	 int t=0;
	 for(int i=0;i<N;i++)
	 {
	 	 char s[10];
	 	 cin>>s;
	 	 int l = strlen(s);
	 	 sort(s,s+l);
	 	 string str;
	 	 for(int j=0;j<l;j++)
	 	 {
	 	 	str+=s[j];
		  }
		  if(mp[str]==0)
		  {
		  	 k[t++] = str;  
		  	 mp[str]=1;
		  }
		  else
		  {
		  	mp[str]++;
		  }
		  
	 }
	 long long  sum=0;
	 for(int i=0;i<t;i++)
	 {
	 	 sum+=cal(mp[k[i]]);
	 }
	 cout<<sum<<endl;
	 
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  string s; cin >> s;
  if(s[2] == s[3] && s[4] == s[5])cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<long long> a(n), b(n+1, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++) b[i+1] = b[i] + a[i]; 
    
    auto judge = [&](int x) {
        long long curr = a[x]; int ci = x;
        while (true) {
            auto i = upper_bound(a.begin(), a.end(), curr * 2) - a.begin();
            if (i == n) return true;
            if (i == ci) break;
            ci = i;
            curr = b[ci];
        }
        return false;
    };

    int l = -1, r = n;
    while (r - l > 1) {
        int m = (l + r) / 2;
        if (judge(m)) r = m;
        else l = m;
    }
    cout << n - r << "\n";
    return 0;
}

Measured memory_bytes: 1792