akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b) PrintLn(c);
	if(a == c) PrintLn(b);
	if(c == b) PrintLn(a);

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  long n;
  scanf("%ld", &n);
  long a[n+1];
  for (long i = 2; i <= n; i++) {
    scanf("%ld", &a[i]);
  }

  long list[n+1];
  for (int i = 1; i <= n; i++) {
    list[i] = 0;
  }
  for (int i = n; i >= 2; i--) {
    list[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    printf("%ld\n", list[i]);
  }

  return 0;
}

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

int main() {
    int n, h;
    cin >> n >> h;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i) >> b.at(i);
    }
    
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    vector<int> b_greater_a;
    for (int i = 0; i < n; i++)
    {
        if (b.at(i) > a.at(0)) b_greater_a.push_back(b.at(i));
    }
    sort(b_greater_a.begin(), b_greater_a.end());
    reverse(b_greater_a.begin(), b_greater_a.end());

    int cnt = 0;
    for (int i = 0; i < (int)b_greater_a.size(); i++)
    {
        cnt++;
        h -= b_greater_a.at(i);
        if (h <= 0) {
            cout << cnt << endl;
            return 0;
        }
    }
    
    cnt += ceil((double)h / a.at(0));
    cout << cnt << endl;
}


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

int main() {
    int c[3][3];
    REP (i, 0, 3) REP (j, 0, 3) cin >> c[i][j];
    int a2 = c[1][0] - c[0][0], a3 = c[2][0] - c[0][0];
    if (a2 + c[0][1] == c[1][1] && a2 + c[0][2] == c[1][2] && a3 + c[0][1] == c[2][1] && a3 + c[0][2] == c[2][2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin>>S;
    int N = S.size();
    auto check = [&](){
        if (S[0]=='0'||S[N-1]=='1') return false;
        rep(i,N/2)if(S[i]!=S[N-i-2]){
            return false;
        }
        return true;
    };
    if (!check()){
        cout<<"-1\n";
        return 0;
    }
    int cur=1;
    rep(i,N/2){
        cout<<cur<<" "<<i+2<<"\n";
        if (S[i]=='1') cur=i+2;
    }
    rep(i,N-N/2-1){
        cout<<cur<<" "<<N-i<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;

int main(){
	int sum=0,min,scr;
	cin >> scr;
	sum += scr;
	min = scr;
	cin >> scr;
	sum += scr;
	if(min>scr) min = scr;
	cin >> scr;
	sum += scr;
	if(min>scr) min = scr;
	cin >> scr;
	sum += scr;
	if(min>scr) min = scr;
	sum -= min;
	cin >> scr;
	sum += scr;
	min = scr;
	cin >> scr;
	sum += scr;
	if(min>scr) min = scr;
	sum -= min;
	printf("%d\n",sum);
	return 0;
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    string s,t;
    cin>>s>>t;
    cout<<t<<s<<endl;
    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll T1,T2;
    ll A1,A2;
    ll B1,B2;
    cin>>T1>>T2>>A1>>A2>>B1>>B2;
    if(A1 < B1){
        swap(A1,B1);
        swap(A2,B2);
    }
    ll ans = 0;
    if(A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2){
        cout<<"infinity";
    }
    else if(A1 * T1 + A2 * T2 < B1 * T1 + B2 * T2){
        ll x =B1 * T1 + B2 * T2 -A1 * T1 - A2 * T2;
        if((A1 * T1 - B1 * T1)%x == 0){
            ans -= 1;
        }
        ans += ((A1 * T1 - B1 * T1)/x) * 2;
        ans += 1;
        cout<<ans;
    }
    else{
        cout<<0;
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define fin freopen("input", "r", stdin);
#define fout freopen("output", "w", stdout);
#define wt(x) cerr << #x << ": " << x << " ";
#define whatis(x) {cerr << #x << ": " << x << endl;}
#define whatis2(x, y) {wt(x); wt(y); cerr << endl;}
#define whatis3(x, y, z) {wt(x); wt(y); wt(z); cerr << endl;}
#define whatis4(x, y, z, a) {wt(x); wt(y); wt(z); wt(a); cerr << endl;}
using namespace std;

typedef long long ll; typedef unsigned long long ull; typedef long double ld;
const ll MOD = 1000000007; const ld PI = acos(-1.0);

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

    int a, b, k;
    cin >> k >> a >> b;

    for (int i = a; i <= b; ++i) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;


    return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node {
    int parent, left, right;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d){
    if ( u == NIL ) return;
    D[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}

int setHeight(int u){
    int h1 = 0, h2 = 0;
    if ( T[u].left != NIL )
        h1 = setHeight(T[u].left) + 1;
    if ( T[u].right != NIL )
        h2 = setHeight(T[u].right) + 1;
    return H[u] = ( h1 > h2 ? h1 : h2 );
}

// 節点uの兄弟を返す
int getSibling(int u){
    if ( T[u].parent == NIL ) return NIL;
    if ( T[T[u].parent].left != u && T[T[u].parent].left != NIL )
        return T[T[u].parent].left;
    if( T[T[u].parent].right != u && T[T[u].parent].right != NIL )
        return T[T[u].parent].right;
    return NIL;
}

void print(int u){
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if ( T[u].left != NIL ) deg++;
    if ( T[u].right != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if ( T[u].parent == NIL ){
        printf("root\n");
    } else if ( T[u].left == NIL && T[u].right == NIL){
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}

int main(){
    int v, l, r, root = 0;
    scanf("%d", &n);

    for ( int i = 0; i < n; i++ ) T[i].parent = NIL;

    for ( int i = 0; i < n; i++ ){
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if ( l != NIL ) T[l].parent = v;
        if ( r != NIL ) T[r].parent = v;
    }

    for( int i = 0; i < n; i++ ) if ( T[i].parent == NIL ) root = i;

    setDepth(root, 0);
    setHeight(root);

    for (int i = 0; i < n; i++) print(i);

    return 0;
}


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

int main(){
	int w,h,n;
	cin >> w >> h >> n;
	vector<int> a(n);
	vector<int> x(n);
	vector<int> y(n);
	rep(i,n) cin >> x[i] >> y[i] >> a[i];
	int xmin = 0;
	int ymin = 0;
	rep(i,n){
		if(a[i] == 1){
			xmin = max(xmin,x[i]);
		}
		else if(a[i] == 2){
			w = min(w,x[i]);
		}
		else if(a[i] == 3){
			ymin = max(ymin,y[i]);
		}
		else if(a[i] == 4){
			h = min(h,y[i]);
		}
	if((w-xmin)*(h-ymin) <= 0){
	 cout << 0 << endl;
	 return 0;
	}
	}
	cout << (w-xmin)*(h-ymin) << endl;
}

Measured memory_bytes: 3648
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
Alice = []
Bob = []
while len(A) != 0:
        Alice.append(A[0])
        A = A[1:]
        if len(A) != 0:
                Bob.append(A[0])
                A = A[1:]

print(sum(Alice)-sum(Bob))

Measured memory_bytes: 3064
use std::io::*;
use std::str::FromStr;

pub 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 main() {
  let H = read::<u32>();
  let W = read::<u32>();
  let h = read::<u32>();
  let w = read::<u32>();

  println!("{}", (H - h) * (W - w));
}



Measured memory_bytes: 4352
import java.io.*;
import java.util.*;


class Main {
    static long gcd(long x,long y){
        while(y!=0){
            long r=x%y;
            x=y;
            y=r;
        }
        return x;
    }
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        long k=sc.nextInt();
        long[]a=new long[n];
        long g=0;
        long max=0;
        for(int i=0;i<n;++i){
            a[i]=sc.nextInt();
            g=gcd(g,a[i]);
            max=Math.max(max,a[i]);
        }
        out.println(k%g==0&&k<=max?"POSSIBLE":"IMPOSSIBLE");
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 34716
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
int N, A, B;
int main() {
	cin >> N >> A >> B;
	int sum = 0;
	for (int i = 1; i <= N; ++i) {
		int digit_sum = 0;
		int j = i;
		while (j) {
			digit_sum += j % 10;
			j /= 10;
		}
		if (A <= digit_sum && digit_sum <= B) sum += i;
	}
	cout << sum << endl;
	return 0;
}

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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N;
int A[3010];
ll dp[3010][3010];

ll rec(int from, int to){
    if(dp[from][to] >= 0) return dp[from][to];
    ll res = 0;
    if(from > to){
        res = 0;
    }
    else{
        bool is_taro = (N - (to - from + 1)) % 2 == 0;
        if(is_taro){
            res = max(res, rec(from + 1, to) + A[from]);
            res = max(res, rec(from, to - 1) + A[to]);
        }
        else{
            res = rec(from + 1, to);
            res = min(res, rec(from, to - 1));
        }
    }
    return dp[from][to] = res;
}

int main(){

    cin >> N;
    
    ll tot = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        tot += A[i];
    }
    memset(dp, -1, sizeof(dp));
    ll s = rec(0, N - 1);
    cout << s - (tot - s) << endl;

    return 0;
}


Measured memory_bytes: 71168
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;cin>>n;
  string s[n];
  for(int i=0;i<n;i++)cin>>s[i];
  map<string,int>mp;
  for(int i=0;i<n;i++)mp[s[i]]++;
  int mx=0;
  for(auto p:mp)mx=max(mx,p.second);
  for(auto p:mp){
    if(p.second!=mx)continue;
    cout<<p.first<<endl;
  }
}

Measured memory_bytes: 26752
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt(),X = sc.nextInt(), Y = sc.nextInt();
	int[] cnt_list = new int[N-1];
	int l= 0;
	for(int i=1;i<N;i++) {
		for(int j=i+1;j<N+1;j++) {
//			System.out.println("i:"+i+"j:"+j);
			if(i>=Y||j<=X) {
				l = j-i;
				cnt_list[l-1]++;
			}else {
				int another = Math.abs(i-X)+Math.abs(j-Y)+1;
//				System.out.println(another);
				l = Integer.min(j-i, another);
				cnt_list[l-1]++;	
			}
//			System.out.println(Arrays.toString(cnt_list));
		}
	}
	for(int cnt:cnt_list) {
		System.out.println(cnt);
	}
}
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define INFTY 10000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};

int main(){
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll ans=a[0];n-=2;
    int i=1;
    while(n>0){
        //cout<<ans<<endl;
        if(n==1){ans+=a[i];break;}
        ans += 2 * a[i];
        i++;n-=2; 
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4776
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n;

int ask(int x) {
    static map<int, int> mp;
    
    if (mp.find(x) != mp.end()) return mp[x];
    printf("%d\n", x);
    fflush(stdout);
    
    static char in[10];
    scanf("%s", in);
    if (*in == 'V') exit(0);
    return mp[x] = (*in == 'F');
}

int main() {
    scanf("%d", &n);
    int s = 1, e = n - 1;
    int st = ask(0);
    while (s <= e) {
        int m = (s + e) / 2;
        int mt = ask(m);
        if ((s ^ m ^ st ^ mt) & 1) {
            s = m + 1;
            st = mt;
        }
        else {
            e = m - 1;
        }
    }
	return 0;
}


Measured memory_bytes: 852
var main = function(s) {
	var N =parseInt(s);
  	var array=s.split('').map(x=>parseInt(x));
  	var L = s.length;
  	var sum = 0;
  	for(var i=0;i<L;i++){
  	sum+=array[i];
    }
  	if(N%sum === 0){
      console.log('Yes');
    } else{
      console.log('No');
    }
    return 0; 
}

main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

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

long long N,M;
void input()
{
    cin >> N >> M;
}

void solve()
{
    if (N >= 2 && M >= 2){
        cout << (N-2) * (M-2) << endl;
    } else if (N == 1 && M == 1) {
        cout << 1 << endl;
    } else {
        cout << max(N,M) - 2 << endl;
    }
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
// vector<int> vec(3); = vector<int> vec={0,0,0}
// vec.at()
// sort(num.begin(),num.end(), greater<int>());
// reverse(num.begin(),num.end());
// transform(a.begin(), a.end(), a.begin(), ::toupper);
 
// 切り上げ　a/b+1
//  1からNの総和　N*(N+1)/2
 
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  
  
  if(c >= a && c <= b){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
  
  
}

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

string s[2];

int solve();

int main() {
  int ans;
  cin >> s[0] >> s[1];
  ans = solve();
  if(ans == 1)
    cout << "GREATER" << endl;
  else if(ans == 0)
    cout << "LESS" << endl;
  else
    cout << "EQUAL" << endl;
  return 0;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<utility>
#include<map>
#include<set>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<functional>
#include<sstream>
#include<cstring>
#include<bitset>
#include<stack>
using namespace std;

char s;
string a,b,c;
queue<char>qa,qb,qc;

int main()
{
	cin>>a>>b>>c;
	for(int i=0;i<a.size();i++)
	{
		qa.push(a[i]);
	}
	for(int i=0;i<b.size();i++)
	{
		qb.push(b[i]);
	}
	for(int i=0;i<c.size();i++)
	{
		qc.push(c[i]);
	}
	
	s='a';
	while(1)
	{
		if(s=='a')
		{
			if(qa.empty())
			{
				cout<<'A'<<endl;
				return 0;
			}
			s=qa.front();
			qa.pop();
		}
		else if(s=='b')
		{
			if(qb.empty())
			{
				cout<<'B'<<endl;
				return 0;
			}
			s=qb.front();
			qb.pop();
		}
		else if(s=='c')
		{
			if(qc.empty())
			{
				cout<<'C'<<endl;
				return 0;
			}
			s=qc.front();
			qc.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2*10**5)

n, u, v = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
u -= 1
v -= 1

connect = [set() for _ in range(n)]
for a, b in edge:
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

du = [0] * n
dv = [0] * n

def dfs(v, dis, ng, d):
    d[v] = dis
    ng.add(v)
    for w in connect[v]:
        if w not in ng:
            dfs(w, dis+1, ng, d)

dfs(u, 0, set(), du)
dfs(v, 0, set(), dv)

ans = 0
for i in range(n):
    if du[i] < dv[i]:
        ans = max(ans, dv[i]-1)
print(ans)

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1010;
const ll INF = 1LL << 50;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
	int a, b, q;
	cin>>a>>b>>q;
	vector<ll> s(a), t(b);
	rep(i, 0, a)
	{
		cin>>s[i];
	}
	rep(i, 0, b)
	{
		cin>>t[i];
	}
	while(q--)
	{
		ll x;
		cin>>x;
		auto temp = lower_bound(all(t), x);
		auto shr = lower_bound(all(s), x);
		ll lt, rt, ls, rs;
		if(temp == t.begin())
			lt = INF;
		else
			lt = x - *(temp-1);
		if(shr == s.begin())
			ls = INF;
		else
			ls = x - *(shr-1);
		if(temp == t.end())
			rt = INF;
		else 
			rt = *temp - x;
		if(shr == s.end())
			rs = INF;
		else
			rs = *shr - x;
		ll left = max(ls, lt);
		ll right = max(rt, rs);
		ll lsrt = ls*2 + rt;
		ll ltrs = lt*2 + rs;
		ll rslt = rs*2 + lt;
		ll rtls = rt*2  + ls;
		ll aa = min(left, right);
		ll bb= min(lsrt, ltrs);
		ll cc = min(rslt, rtls);
		cout<<min(aa, min(bb, cc))<<endl;
	}
}


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

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

    int x = 0, max = 0;
    for (int i = 0; i < n; i++) {
        if (s.at(i) == 'I') {
            x++;
        } else {
            x--;
        }
        if (max < x) max = x;
    }

    cout << max << endl;

    return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		@SuppressWarnings("resource")
		Scanner num = new Scanner(System.in);
		int n = num.nextInt();
		long l0 = 2;
		long l1 = 1;
		long ln = 0;

		if(n==1)System.out.println(l1);
		else{
			for(int i=2; i<=n; i++) {
				ln=l1+l0;
				l0=l1;
				l1=ln;
			}
			System.out.println(ln);
		}
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
#define coa cout << ans << endl;
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;

int main(){
    int n;
    cin >> n;
    
    long long ans = 0;
    for(int a = 1; a <= n; a++){
        int tp = (n - 1) / a;
        ans += tp;
    }

    coa;
    return 0;
}


Measured memory_bytes: 3584
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int slen = s.length();
    if(slen % 2 == 1){
      slen++;
    }
    for(int i = 0;i < slen;i +=2){
      System.out.print(s.substring(i,i+1));
    }
  }
}


Measured memory_bytes: 32840
import sys
    
def shortest_path(GRAPH, distance):
    
    nodes0 = range(len(distance))
    nodes1 = set()
    p1 = 0
    distance[p1] = 0
    while True:
        dp1 = distance[p1]
        gp1 = GRAPH[p1]
        status[p1]=2
        for p2 in gp1.keys():
            tmp = gp1[p2] + dp1
            if status[p2]<=1 and tmp < distance[p2]:
                distance[p2] = tmp
                status[p2] = 1
                nodes1.add(p2)

        p1 = -1
        mini = 1000000
            
        for p2 in nodes1:
            if distance[p2]<mini:
                p1 = p2
                mini = distance[p2]
        if mini == 1000000:
            break
        nodes1.remove(p1)
    return

def resultout(distance):
    for i in xrange(len(distance)):
        print "%d %d" %(i, distance[i])
    return

n = int(raw_input())
x = [{} for i in xrange(n)]
status = [0 for i in xrange(n)]
distance = [1000000 for i in xrange(n)]

for i in xrange(n):
    seq = map(int, raw_input().split())
    tmp={}
    for j in xrange(2, len(seq), 2):
        j2, weight = seq[j:j+2]
        tmp[j2] = weight
    x[seq[0]] = tmp
    status[i] = 0

shortest_path(x, distance)
resultout(distance)

Measured memory_bytes: 72288
#include <stdio.h>
#define error -1
int size=0,list[2000000];
 
int parent(int i){
   return i/2;
}
 
int Left(int i){
  return 2*i;
 }
 
int Right(int i){
  return 2*i+1;  
 }
 
void maxHeapify(int i){
  int left,right,largest,key;
  left=Left(i);
  right=Right(i);
   
  if(left<=size && list[left]>list[i])
    largest=left;
  else largest=i;
   
  if(right<=size && list[right]>list[largest])
    largest=right;
   
  if(largest!=i){
    key=list[i];
    list[i]=list[largest];
    list[largest]=key;
    maxHeapify(largest);
  }  
}
void heapIncrease(int i,int key){
  int ch;
  if(key<list[i]) return;
  list[i]=key;
  while(i>0 && list[parent(i)]<list[i]){
    ch=list[i];
    list[i]=list[parent(i)];
    list[parent(i)]=ch;
    i=parent(i);
  }
  return;
}
 
 
void insert(int key){
  size=size+1;
  list[size]=-1000000;
  heapIncrease(size,key);
}
 
 
int heapExtractMax(){
  int max;
  if(size<0) return error;
  max=list[0];
  list[0]=list[size];
  size=size-1;
  maxHeapify(0);
  return max;
}
  
int main(){
  char Inst[10];
  int count,del,key;
  
 while(1){
    
   scanf("%s %d",Inst,&key);
   if(Inst[0]=='i') insert(key);
   else if(Inst[1]=='x'){
     del=heapExtractMax();
     printf("%d\n",del);
   }
   else if(Inst[2]=='d') break;
    
 }
 return 0;
}

Measured memory_bytes: 4696
#include<stdio.h>

int main(void) {

	long long int N, n, i, u, d[101], sum = 0, answer;

	scanf("%lld", &N);

	n = N - 1;

	for(i = 0;i < N;i++) {
		scanf("%lld", &d[i] );
	}

	for(i = 0;i < n;i++) {
		u = i + 1;
		for(;u < N;u++) {
			answer = d[i] * d[u];
			sum = sum + answer; 
		}
	}

	printf("%lld", sum); 

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stack>
using namespace std;

//const int maxn = 2 * 1e5 + 10;

int judge(string s) {
	//int mark = 0;
	stack<char>res;
	int size=s.size();
	for(int i=0;i<s.size();i++)
	{
		if(res.empty()){
			res.push(s[i]);
			continue;
		}
	    if(res.top()=='S'&&s[i]=='T'){
			res.pop();
			size=size-2;
			
		}
		else{
			res.push(s[i]);
		}
	
	}
	for(int i=1;i<=size;i++){
		char c=res.top();
		res.pop();
	}
	return size;
}


int main() {
	string s;
	cin>>s;
    cout<<judge(s)<<endl;
	return 0;
}

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

vector<vector<int> > rotate(vector<vector<int> > a) {
  int n=a.size(),m=a[0].size();
  vector<vector<int> > b(m,vector<int>(n));
  rep(i,m)rrep(j,n) b[i][n-j-1]=a[j][i];
  return b;
}

int main() {
  int n,m;
  cin >> m >> n;
  vector<vector<int> > a(n,vector<int>(m));
  rep(i,n)rep(j,m)cin >> a[i][j];
  sort(a.begin(),a.end());
  a=rotate(a);
  sort(a.begin(),a.end());
  rep(k,2) {
    vector<vector<int> > b(n,vector<int>(m));
    rep(i,n)rep(j,m)b[i][j]=(i+j+k)%2;
    sort(b.begin(),b.end());
    b=rotate(b);
    sort(b.begin(),b.end());
    if(a==b) {
      cout << "yes" << endl;
      return 0;
    }
  }
  cout << "no" << endl;
  return 0;
}


Measured memory_bytes: 20812
n=int(input())
l=list(map(int,input().split()))
c=10**18
ans=1
miss=False
zero=False
for i in range(n):
  if not miss:
    ans*=l[i]
  if l[i]==0:
    zero=True
    break
  elif ans>c:
    miss=True
    
if zero:
  print(0)
elif miss:
  print(-1)
else:
  print(ans)
    


Measured memory_bytes: 84636
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions
fn gcd(a:i64, b:i64) -> i64{
    if b==0{
        return a;
    }else{
        return gcd(b, a%b);
    }
}
// Main
fn main(){
    input!{
        N: usize,
        A: [i64; N],
    }
    let mut ans = A[0];
    for i in 1..N{
        ans = gcd(ans,A[i]);
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <stdio.h>

int main(void)
{
 int x,y;

 while(1){

  scanf("%d %d",&x,&y);

  if(x==0&&y==0) break;

  if(x<=y){
    printf("%d %d\n",x,y);
  }else{
    printf("%d %d\n",y,x);
  }

 }

 return 0;

}

Measured memory_bytes: 1736
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)) {
            System.out.println(new Main().run(sc));
        }
    }

    public String run(Scanner sc) {
        int n = Integer.parseInt(sc.nextLine());
        int i = 1;
        while (true) {
            int payment = i * 1000;
            if (payment >= n) {
                return String.valueOf(payment - n);
            }
            i++;
        }
    }
}


Measured memory_bytes: 35704
<?php
$dummy = fgets(STDIN);
$a = explode(" ", fgets(STDIN));
$intRank = [];
foreach ($a as $val) {
    $val = intval($val);
    $box = [];
    $box[$val] = true;
    $valMax = $val + 1;
    if ($valMax > 99999) {
        $valMax = 99999;
    }
    $valMin = $val - 1;
    if ($valMin < 0) {
        $valMin = 0;
    }
    $box[$valMax] = true;
    $box[$valMin] = true;
    
    foreach (array_keys($box) as $value) {
        if (!isset($intRank[$value])) {
            $intRank[$value] = 0;
        }
        $intRank[$value] ++;
    }
}

arsort($intRank);
$intRank = array_keys($intRank);
$x = $intRank[0];
$cnt = 0;
foreach ($a as $val) {
    $val = intval($val);
    $valMax = $val + 1;
    if ($valMax > 99999) {
        $valMax = 99999;
    }
    $valMin = $val - 1;
    if ($valMin < 0) {
        $valMin = 0;
    }
    if ($val === $x || $valMin === $x || $valMax === $x) {
        $cnt ++;
    }
}

echo $cnt;
?>


Measured memory_bytes: 20980
n = int(input())
w = [str(input()) for i in range(n)]
used = []
count = 0
for i in range(n-1):
    if((w[i] not in used) and (w[i][-1] == w[i+1][0])):
        count += 1
        used.append(w[i])
if count == n-1 and w[-1] not in used:
    print("Yes")
else:
    print("No")

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

#define ff first
#define ss second
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
#define d(a,b,c) cout<<a<<" "<<b<<" "<<c<<'\n'
#define IO ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define mem(a, b) memset(a,b,sizeof(a))

int main()
{
    int n; cin >> n;
    string s; cin >> s;
    int k = s.size();
    if(k <= n)
        return !(cout << s << endl);
    for(int i = 0; i < n; i++)
        cout << s[i];
    cout << "..." << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i= (a); i<(b); i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(), (obj).end()
using namespace std;

const long long INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
typedef long long ll;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
signed main () {
    int n;scanf("%d",&n);
    vector<int> list(n);
    REP(i,n){
        int tmp;scanf("%d",&tmp);
        list[i]= tmp;
    }
    int q;scanf("%d",&q);
    vector<bool> sumTable(400001,false);
    for(int i=0;i<(1<<n);i++){
        int tmp_sum=0;
        for(int j=0;j<n;j++){
            if(i&(1<<j))tmp_sum+=list[j];
        }
        sumTable[tmp_sum]=true;
    }
    REP(i,q){
        int target;scanf("%d",&target);
        if(sumTable[target]){
            printf("yes\n");
        } else{
            printf("no\n");
        }
    }
    
}


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

int main(){
  int n;
  cin >> n;
  
  long long ans = 1;
  
  for(int i = 1; i <= n; i++) {
  	ans = (long long)ans*i % 1000000007;
  }
  
  cout << ans << endl;
}

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

int main() {
    string B;
    cin >> B;
    for (int i = 0; i < B.length(); i++) {
        if (B[i] == 'A') cout << 'T';
        else if (B[i] == 'C') cout << 'G';
        else if (B[i] == 'T') cout << 'A';
        else cout << 'C';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

Measured memory_bytes: 21716
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define PB push_back
#define MP make_pair

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

const int MOD = 1e9+7;
const int INF = 1e9;
const char cmp[5] = {'M', 'A', 'R', 'C', 'H'};

int main() {
  ll N, cnt[5];
  ll ans = 0;
  cin >> N;
  for (int i = 0; i < 5; i++) {
    cnt[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    string tmp;
    cin >> tmp;
    for (int j = 0; j < 5; j++) {
      if (tmp[0] == cmp[j]) {
        cnt[j]++;
      }
    }
  }
  for (int i = 0; i < 5; i++) {
    for (int j = i+1; j < 5; j++) {
      for (int k = j+1; k < 5; k++) {
        ans += cnt[i]*cnt[j]*cnt[k];
      }
    }
  }

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


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

using namespace std;
using ll = long long;

struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<int> sz;

	UnionFind(size_t Size) {
		par.resize(Size);
		rank.resize(Size, 0);
		sz.resize(Size, 1);
		for (int i = 0; i < Size; ++i) { par[i] = i; }
	}

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

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) { return; }

		if (rank[x] < rank[y]) { swap(x, y); }
		if (rank[x] == rank[y]) { ++rank[x]; }
		par[y] = x;
		sz[x] += sz[y];
	}

	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return sz[find(x)]; }
};

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

	UnionFind uf(N + 1);
	vector<ll> res(M, 0);
	res[M - 1] = (N - 1) * N / 2;
	for (int i = M - 1; i > 0; --i) {
		if (uf.same(a[i], b[i])) {
			res[i - 1] = res[i];
			continue;
		}
		ll s = uf.size(a[i]);
		ll t = uf.size(b[i]);
		res[i - 1] = res[i] - (s * t);
		uf.unite(a[i], b[i]);
	}

	for (int i = 0; i < M; ++i) {
		cout << res[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
const int N=500010;
int n,m,p[N],t[N],op,ed;set<pair<int,int> > S;
struct node{int l,r;}a[N];
int main(){
	scanf("%d%d",&n,&m);
	ref(i,1,n)scanf("%d",&p[i]);
	S.insert(make_pair(n+1,n+1));
	ref(i,1,n){
		S.insert(make_pair(p[i],i));
		if(i-m>0)S.erase(make_pair(p[i-m],i-m));
		t[i]=(*S.upper_bound(make_pair(p[i],i))).second;
	}
	ed=n+1;op=n+2;a[op].r=ed;a[ed].l=op;
	ref(i,1,n){
		a[i].r=t[i];a[i].l=a[t[i]].l;
		a[a[t[i]].l].r=i;a[t[i]].l=i;
	}
	for(int i=a[op].r,s=1;i!=ed;i=a[i].r,++s)p[i]=s;
	ref(i,1,n)printf("%d\n",p[i]);
}

Measured memory_bytes: 34816
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n, m, k;
vector<bool> dark;
vector<int> cnv;
vector<ll> dp;
vector<vector<int>> g;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%d %d %d", &n, &m, &k);
	dark = vector<bool>(n, false);
	cnv = vector<int>(n, -1);
	dp = vector<ll>((1 << m), -1);
	for (int i = 0; i < m; i++) {
		int d; scanf("%d", &d);
		dark[d - 1] = true;
		cnv[d - 1] = i;
	}
	g.resize(m);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < k; j++) {
			int v; scanf("%d", &v);
			v--;
			if (dark[i]) g[cnv[i]].push_back(cnv[v]);
		}
	}
	queue<int> q;
	dp[(1 << m) - 1] = 0;
	q.push((1 << m) - 1);
	while (!q.empty()) {
		int S = q.front();
		q.pop();
		for (int i = 0; i < k; i++) {
			int nS = 0;
			for (int j = 0; j < m; j++) {
				if (S >> j & 1) {
					if(g[j][i] != -1) nS |= (1 << g[j][i]);
				}
			}
			if (dp[nS] == -1) {
				dp[nS] = dp[S] + 1;
				q.push(nS);
			}
		}
	}
	cout << dp[0] << endl;
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意！！！！！！！！！！！！
	*/
}



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

int main(){
	long long a,b,c,numa,numb,numc,more,ans=0;
	cin>>a>>b>>c>>numa>>numb;
	if((a+b)>c*2){  //套装价格便宜
		numc=min(numa,numb)*2;
		if(numa>numb){
			int parta=numa-numb;
			ans=numc*c+parta*a;
		}else{
			int partb=numb-numa;
			ans=numc*c+partb*b;
		}
	}else{           //分开购买便宜
		ans=a*numa+b*numb;
	}
	long long num=max(numb,numa)*2;
	more=num*c;

	cout<<min(ans,more);
	//cout<<endl<<ans<<"  "<<more;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	double W,H,w,h,x,y;
	double left,right,top,under;

	scanf("%lf %lf %lf %lf %lf %lf",&W,&H,&w,&h,&x,&y);

	left = max(-W/2,x-w/2);
	right = min(W/2,x+w/2);
	top = min(H/2,y+h/2);
	under = max(-H/2,y-h/2);

	printf("%.10lf\n",((top+under)/2)/((left+right)/2));

	return 0;
}



Measured memory_bytes: 3220
n = int(input())
s = input()
ec = 0
wc = 0
el = []
wl = []
for f,r in zip(s,reversed(s)):
    el.append(ec)
    wl.append(wc)
    if f == 'W':
        wc += 1
    if r == 'E':
        ec += 1

ans = n
for e,w in zip(wl, reversed(el)):
    ans = min(ans, e+w)

print(ans)

Measured memory_bytes: 23444
using System;

class CF2016QCC
{
	static public void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[] T = new int[N];
		int[] A = new int[N];

		string[] vals = Console.ReadLine().Split(' ');
		for(int i=0; i < N; i++)
		{
			T[i] = int.Parse(vals[i]);
		}

		vals = Console.ReadLine().Split(' ');
		for(int i=0; i < N; i++)
		{
			A[i] = int.Parse(vals[i]);
		}
		
		bool[] TC = new bool[N];
		bool[] AC = new bool[N];

		TC[0] = true;
		for(int i=1; i<N; i++)
		{
			if(T[i-1] < T[i])
			{
				TC[i] = true;
			}
		}

		AC[N-1] = true;
		for(int i=N-2; i>=0; i--)
		{
			if(A[i] > A[i+1])
			{
				AC[i] = true;
			}
		}

		int[] TA = new int[N];
		bool[] TAC = new bool[N];

		for(int i=0; i<N; i++)
		{
			if(TC[i] == false && AC[i] == false)
			{
				TA[i] = Math.Min(T[i], A[i]);
				TAC[i] = false;
			}
			else if(TC[i] == true && AC[i] == false)
			{
				if(T[i] <= A[i])
				{
					TA[i] = T[i];
					TAC[i] = true;
				}
				else
				{
					Console.WriteLine(0);
					return;
				}
			}
			else if(TC[i] == false && AC[i] == true)
			{
				if(A[i] <= T[i])
				{
					TA[i] = A[i];
					TAC[i] = true;
				}
				else
				{
					Console.WriteLine(0);
					return;
				}
			}
			else
			{
				if(T[i] == A[i])
				{
					TA[i] = T[i];
					TAC[i] = true;
				}
				else
				{
					Console.WriteLine(0);
					return;
				}
			}
		}

		long ans = 1;
		long M = 1000000007;
		for(int i=0; i<N; i++)
		{
			if(TAC[i] == false)
			{
				ans = ans * TA[i] % M;
			}
		}
		Console.WriteLine(ans);
	}
}


Measured memory_bytes: 35852
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

s=input()
if len(s)%2==1:
    print("No")
    quit()

for i in range(len(s)//2):
    if s[i*2]=="h" and s[i*2+1]=="i":
        continue
    else:
        print("No")
        quit()

print("Yes")

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

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

    bool a(true);
    rep(i,k){
        if(s[i]!='1'){
            if(k==1 || s.size()==1)    cout << s[0] << endl;
            else if(i<=k)    cout << s[i] << endl;
            else    cout << 1 << endl;
            a = false;
            break;
        }
    }
    if(a)   cout << 1 << endl;

    return 0;
}

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

int main() {
    string s,ans="Good";
    cin>>s;
    if (s[0]==s[1]||s[1]==s[2]||s[2]==s[3]) ans="Bad";
    cout<<ans<<endl;
}   

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
bool used[26];
int main() {
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) used[S[i] - 'a'] = 1;
	for (int i = 0; i < 26; i++) {
		if (used[i]) continue;
		char c = 'a' + i;
		cout << c << endl;
		return 0;
	}
	cout << "None" << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int ans=0,pre=0,con=0;
    for(int i=0;i<n;i++){
        int h;
        cin>>h;
        if(pre<h){
            con=0;
        }
        else {
            con++;
        }
        pre=h;
        ans=max(ans,con);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    ll h[100010];
    rep(i, n) cin >> h[i];

    ll dp[100010];
    dp[0] = 0;

    for (int i = 1; i < n; i++) {
        ll mi = 10000000000;
        for (int j = 1; j <= k; j++) {
            mi = min(mi, dp[i - j] + abs(h[i] - h[i - j]));
            if (i == j) break;
        }
        dp[i] = mi;
    }

    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cctype>
#include <cassert>
using namespace std;

string input;
int idx;

int minimum_votes();
int parse_int();

int main()
{
    int N;
    cin >> N;
    while (N--) {
        cin >> input;
        idx = 0;
        cout << minimum_votes() << endl;
    }
}

bool open_bracket()
{
    return input[idx] == '[';
}

bool close_bracket()
{
    return input[idx] == ']';
}

int minimum_votes()
{
    assert(open_bracket());
    idx++;

    {
        int voters = parse_int();
        if (voters >= 0) {
            assert(close_bracket());
            idx++;

            return (voters + 1) / 2;
        }
    }

    vector<int> voters;

    while (open_bracket()) {
        voters.push_back(minimum_votes());
    }

    assert(close_bracket());
    idx++;

    sort(voters.begin(), voters.end());

    int sum = 0;
    for (int i = 0; i < (voters.size() + 1) / 2; i++) {
        sum += voters[i];
    }

    return sum;
}

int parse_int()
{
    if (isdigit(input[idx])) {
        int result = 0;
        while (isdigit(input[idx])) {
            result *= 10;
            result += input[idx] - '0';
            idx++;
        }
        return result;
    } else {
        return -1;
    }
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N;
  cin >> N;
  vi L(N);
  for (auto& x: L) {
    cin >> x;
  }
  Sort(L);

  ll ret = 0;
  REP(i, N-2) {
    for (int j=i+1; j<N-1; j++) {
      int x = L[j+1];
      int y = L[j]+L[i];

      // [from ,to)
      auto from = lower_bound(begin(L)+j+1, end(L), x);
      auto to   = lower_bound(begin(L)+j+1, end(L), y);
      int count = distance(from, to);
      ret += count;
    }
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256