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

struct Node {
    int key;
    Node *r,*l,*p;
};

Node *rootw, *NIL;

Node* treeMinimum(Node *x){
    while(x->l != NIL)x= x->l;
    return x;
}

Node * find(Node *u, int k){
    while (u != NIL && k != u->key ){
        if(k < u->key)u = u->l;
        else u = u->r;
    }
    return u;
}

Node* treeSuccessor(Node* x){
    if(x->r != NIL)return treeMinimum(x->r);
    Node *y=x->p;
    while(y != NIL && x == y->r){
        x=y;
        y=y->p;
    }
    return y;
}

void treeDelete(Node *z){
    Node *y;
    Node *x;


    if(z->l==NIL||z->r==NIL)y=z;
    else y = treeSuccessor(z);



    if(y->l != NIL){
        x=y->l;
    }else{
        x=y->r;
    }

    if(x != NIL){
        x->p=y->p;
    }

    if(y->p==NIL){
        rootw=x;
    }else{
        if(y==y->p->l){
            y->p->l=x;
        }else{
            y->p->r=x;
        }
    }

    if(y != z){
        z->key=y->key;
    }

    free(y);
}

void insert(int k){
    Node *y = NIL;
    Node *x = rootw;
    Node *z;

    z = (Node*)malloc(sizeof(Node));
    z->key = k;
    z->l = NIL;
    z->r = NIL;

    while(x != NIL){
        y=x;
        if(z->key < x->key){
            x=x->l;
        }
        else{
            x = x->r;
        }
    }
    z->p = y;
    if (y==NIL){
    rootw = z;
    }
    else{
        if(z->key < y->key){
            y->l = z;
        }
        else{
            y->r = z;
        }
    }
}

void inorder(Node *u){
    if(u == NIL)return;
    inorder(u->l);
    printf(" %d",u->key);
    inorder(u->r);
}
void preorder(Node *u){
    if(u == NIL)return;
    printf(" %d", u->key);
    preorder(u->l);
    preorder(u->r);
}

int main(){
    int ntw, i, x;
    string com;

    scanf("%d", &ntw);

    for(i = 0; i < ntw; i++){
        cin >> com;
        if(com[0]=='f'){
            scanf("%d",&x);
            Node *t=find(rootw,x);
            if(t != NIL)printf("yes\n");
            else printf("no\n");
        }
        else if(com == "insert"){
            scanf("%d", &x);
            insert(x);
        }
        else if (com == "print"){
            inorder(rootw);
            printf("\n");
            preorder(rootw);
            printf("\n");
        }
        else if(com == "delete"){
            scanf("%d",&x);
            treeDelete(find(rootw,x));
        }
    }

    return 0;
}


Measured memory_bytes: 21932
import java.util.*;

public class Main {
    public static boolean processLine(String line) {
        ArrayList<Character> stack = new ArrayList<Character>();
        for (int i = 0; i < line.length(); i++) {
            char c = line.charAt(i);
            switch (c) {
            case '[':
                stack.add(c);
                break;
            case ']':
                if (stack.size() > 0 && stack.get(stack.size() - 1) == '[') {
                    stack.remove(stack.size() - 1);
                } else {
                    return false;
                }
                break;
            case '(':
                stack.add(c);
                break;
            case ')':
                if (stack.size() > 0 && stack.get(stack.size() - 1) == '(') {
                    stack.remove(stack.size() - 1);
                } else {
                    return false;
                }
                break;
            }
        }
        return stack.size() == 0;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextLine()) {
            String line = sc.nextLine();
            if (line.equals(".")) {
                return;
            }
            boolean yes = processLine(line);
            if (yes) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }
        }
        sc.close();
    }
}



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

int main(){
    int s, w;
    cin >> s >> w;
    if(w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define pi acos(-1)
#define int long long int
#define ld long double
#define ar array
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<int> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const int ths = 1LL << 40;
const int NN = 5e3 + 6;

const int maxN = 1003;

void solve()
{

    int n, k;
    cin>>n>>k;
    int a[n];
    for(int i = 0; i < n; i ++) {
        cin>>a[i];
    }
    sort(a, a + n);
    int ans = 0;
    for(int i = 0; i < k; i ++) {
        ans += a[i];
    }
    cout<<ans;
    cout<<"\n";
    return ;
}

/*
*/

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

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


Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp14 {
    class Program {
        static void Main(string[] args) {
            var X = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int A = X[0];
            int B = X[1];

            int gcd = GCD(A, B);

            //Console.WriteLine(gcd);

            //Console.WriteLine((long)A * B);

            Console.WriteLine((long)A * B / gcd);
        }

        public static int GCD(int a, int b) {
            //a >= bとなるように入れ替え
            if (a < b) {
                return GCD(b, a);
            }

            while (b != 0) {
                int remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
string S,s,s1;
int ans,ans_;
int main()
{
	cin>>S;
	s="";
	s1="";
	for (int i=0;i<S.size();i++)
	  if (i%2) s=s+'0',s1=s1+'1';
		else s=s+'1',s1=s1+'0';
	for (int i=0;i<S.size();i++)
	{
		if (s[i]!=S[i]) ans++;
		if (s1[i]!=S[i]) ans_++;
    }
    cout<<min(ans,ans_);
    return 0;
}

Measured memory_bytes: 1148
#include <iostream>
#include <algorithm>

using namespace std;

int solve(int a, int b)
{
    float wa = 0.08;
    float wb = 0.1;
    int m = max(a, b);
    int i = 1;
    int ta = 0;
    int tb = 0;
    while(ta <= a && tb <= b) {
        ta = wa * i;
        tb = wb * i;
        if(ta == a && tb == b) {
            return i;
        }
        i++;
    }
    return -1;
}

int main()
{
    int a, b;
    cin >> a >> b;
    
    cout << solve(a, b) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
	}
	vector<int> b(N); rep(i, 0, N) {
		cin >> b[i];
	}
	int suma = accumulate(all(a), 0LL);
	int sumb = accumulate(all(b), 0LL);
	dump(suma, sumb);
	if (sumb < suma) {
		cout << "No" << endl;
	}
	else {
		int cnt1 = 0;
		int cnt2 = 0;
		rep(i, 0, N) {
			if (a[i] > b[i])
				cnt2 += a[i] - b[i];
			else {
				cnt1 += (b[i] - a[i]) / 2;
				if ((b[i] - a[i]) % 2) {
					cnt1++;
					cnt2++;
				}
			}
			dump(cnt1, cnt2);
		}
		dump(cnt1, cnt2);
		if (cnt1 >= cnt2) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

typedef long long ll;

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

// const int C ;
// const int M = 1000000007;

int main () {
  ll a[10];
  for (auto i = 0; i < 7; i++) {
    cin >> a[i];
  }
  ll ans_a = 0;
  ans_a += 4 * (a[0]/2 + a[3]/2 + a[4]/2);
  ans_a += 2 * a[1];
  if (a[0]%2 == 1 && a[3]%2 == 1 && a[4]%2 == 1) {
    ans_a += 6;
  }
  ll ans_b = 0;
  if (a[0] > 0 && a[3] > 0 && a[4] > 0) {
    ans_b += 6;
    a[0]--;
    a[3]--;
    a[4]--;
  }
  ans_b += 4 * (a[0]/2 + a[3]/2 + a[4]/2);
  ans_b += 2 * a[1];  
  cout << max(ans_a, ans_b)/2 << endl;
}


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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define pb push_back
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 507;
const int MX = 1e9 + 7;
const LL INF = 1e18 + 9LL;

int n;
LL tab[N][N];
vector <int> primes;

LL nwd(LL a, LL b){
	if(b == 0)
		return a;
	return nwd(b, a%b);
}

LL get(LL a, LL b, LL c, LL d){
	LL ret = a / nwd(a, b) * b;
	ret = ret / nwd(ret, c) * c;
	ret = ret / nwd(ret, d) * d;
	return ret;
}

bool ok(int a){
	for(int i = 2; i * i <= a; ++i)
		if(a%i == 0)
			return false;
	return true;
}

int main(){
	scanf("%d", &n);
	if(n == 2){
		puts("2 3\n5 4");
		return 0;
	}

	for(int i = 2; primes.size() < n + n; ++i)
		if(ok(i))
			primes.push_back(i);
	
	for(int i = 0; i <= n + 1; ++i)
		for(int j = 0; j <= n + 1; ++j)
			tab[i][j] = 1;
	
	int sx = n - 1 + (n & 1), sy = 1;
	for(int i = 1; i <= n - 1 + (n & 1); ++i){
		int cx = sx, cy = sy;
		while(cx <= n && cy <= n){
			tab[cx][cy] *= primes.back();
			++cx, ++cy;
		}
		
		if(sx > 2)
			sx -= 2;
		else{
			if(sy == 1 && sx == 2)
				sx = 1, sy++;
			else
				sy += 2;
		}
		
		primes.pop_back();
	}
	
	sx = 1, sy = 1;
	for(int i = 1; i <= n; ++i){
		int cx = sx, cy = sy;
		while(cx <= n && cy >= 1){
			tab[cx][cy] *= primes.back();
			++cx, --cy;
		}
		
		if(sy + 1 < n)
			sy += 2;
		else{
			if(sx == 1 && sy + 1 == n)
				sy = n, ++sx;
			else
				sx += 2;
		}
		
		primes.pop_back();
	}
	
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j){
			if((i + j) & 1)
				tab[i][j] = get(tab[i - 1][j], tab[i][j - 1], tab[i + 1][j], tab[i][j + 1]) + 1;
			printf("%lld ", tab[i][j]);
		}

		puts("");
	}
	
	return 0;
}

Measured memory_bytes: 5120
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

int main() {
  ll n, ans, h, w, q, x, y;
  cin >> n >> q;
  vector<ll> a(n + 1), b(n + 1);
  ans = (n - 2) * (n - 2);
  for (int i = 0; i <= n; i++) {
    a[i] = b[i] = n;
  }
  h = w = n;
  while (q--) {
    cin >> x >> y;
    if (x == 1) {
      if (y < w) {
        ans -= h - 2;
        for (int j = y + 1; j < w; j++) {
          b[j] = h;
        }
        w = y;
      } else {
        ans -= b[y] - 2;
      }
    } else {
      if (y < h) {
        ans -= w - 2;
        for (int j = y + 1; j < h; j++) {
          a[j] = w;
        }
        h = y;
      } else {
        ans -= a[y] - 2;
      }
    }
  }
  cout << ans << endl;
}

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

int main(){
  	long long int a,b;
  	cin>>a>>b;
  	long long int g=__gcd(a,b),ans=1;
  	bool is=1;
  	for(long long int i=2;i<=g;i++){
    	if(is){
          	bool chc=0;
        	for(long long int j=2;j<=sqrt(g);j++)
              	if(!(g%j))
                  	chc=1;
        	if(!chc){
            	cout<<ans+1<<'\n';
              	return 0;
            }
            is=0;
        }
      	if(!(g%i) && (is=1,ans++))
          while(!(g%i)) g/=i;
    }
  	cout<<ans<<'\n';
}

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

using namespace std;
int a[300], b[300], c[300], d[300];
int ok[300][300], to[300], prv[300], n, mar[300];
bool kun(int u) {
    if (mar[u]) return false;
    mar[u] = 1;
    for (int j = 1; j <= n; j++) {
        if (ok[u][j] && (prv[j] == 0 || kun(prv[j]))) {
            prv[j] = u;
            to[u] = j;
            return true;
        }
    }
    return false;;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
    for (int i = 1; i <= n; i++) cin >> c[i] >> d[i];
    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
        if (a[i] < c[j] && b[i] < d[j]) ok[i][j] = 1;
    int ans = 0;
    for (int i = 1; i <= n; i++)
        if (to[i] == 0) {
            for (int j = 1; j <= n; j++) mar[j] =0;
            if (kun(i)) ans++;
        }
    cout << ans << "\n";
    return 0;
}


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


int main() {
    string s;
    cin>>s;
    int n=s.size();
    int num1=(n-1)/2;
    int num2=(n+3)/2;
    bool d=true;

    rep(i,n){
        if(s.at(i)!=s.at(n-1-i)){
            d=false;
            break;
        }
    }

    rep(i,num1){
        if(s.at(i)!=s.at(num1-1-i)){
            d=false;
            break;
        }
    }
    if(d==false){
        cout<<"No"<<endl;
        return 0;
    }

    if(n-num2==0){
        cout<<"Yes"<<endl;
        return 0;
    }
    rep(i,n-num2){
        if(s.at(num2-1+i)!=s.at(n-1-i)){
            d=false;
        }
    }
    if(d==false){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    string s, t;
    cin >> n >> s >> t;
    string ans = "";
    rep(i, n){
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
}

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

int n;
float f_n;

int main() {
  cin >> n;
  f_n = (float) n;
  if (n == 1) cout << 1.0 << endl;
  else if (n % 2 == 0) cout << 0.5 << endl;
  else cout << (f_n + 1) / (2 * f_n) << endl;
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    Main.execute()
}

class Main {

    companion object {
        private val graphMatrix = arrayListOf<ArrayList<Boolean>>()


        fun execute() {

            val num = readLine()!!.toInt()

            initgraph(num)

            for (index in 1..num) {
                val inputs = readLine()!!.split(" ")
                val nodeIndex = inputs[0].toInt()
                for (inputIndex in 2 until inputs.size) {
                    val touchedNode = inputs[inputIndex].toInt()
                    graphMatrix[nodeIndex - 1][touchedNode - 1] = true
                }
            }

            graphMatrix.forEach { it2 ->
                println(it2.joinToString(" ") {
                    if (it) "1" else "0"
                })
            }
        }


        fun initgraph(num: Int) {
            for (i in 0 until num) {
                graphMatrix.add(arrayListOf())
                for (j in 0 until num) {
                    graphMatrix[i].add(false)
                }
            }
        }
    }
}


Measured memory_bytes: 34056
// Created by CAD on 2020/4/19.
#include <bits/stdc++.h>

#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x7fffffffffffffff
#define mst(name, value) memset(name,value,sizeof(name))
#define FOPEN freopen("C:\\Users\\14016\\Desktop\\cad.txt","r",stdin)
#define tst1(a) cout<<#a<<":"<<a<<endl
#define tst2(a, b) cout<<#a<<":"<<a<<" "<<#b<<":"<<b<<endl
#define tst3(a, b, c) cout<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<endl
#define tst4(a, b, c, d,e) cout<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<" "<<#d<<":"<<d<<" "<<#e<<":"<<e<<"\n"
#define lson (p<<1)
#define rson (p<<1|1)
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define ll long long
#define lowbit(i) (i&-i)
using namespace std;

const int mod=1e9+7;
const int maxn=1e5+5;
ll qpow(ll x,ll n){
    ll ans=1;
    while(n>0){
        if(n&1) ans=ans*x%mod;
        n>>=1,x=x*x%mod;
    }
    return ans;
}
ll sum[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;cin>>n>>k;
    ll ans=0;
    for(int i=k;i>=1;--i){
        sum[i]=qpow(k/i,n);
        for(int j=2*i;j<=k;j+=i) sum[i]-=sum[j];
        ans=(ans+1ll*i*sum[i]%mod)%mod;
    }
    cout<<(ans+mod)%mod<<"\n";

    return 0;
}


Measured memory_bytes: 4376
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int main(){
	int dp[250][150];
	int temp[250];
	int x[250][3];
	int D,N;
	int MAX;

	memset(dp,-1000000,sizeof(dp));

	cin>>D>>N;
	for(int i=1;i<=D;i++){
		cin>>temp[i];
	}
	for(int i=1;i<=N;i++){
		cin>>x[i][0]>>x[i][1]>>x[i][2];
		if(temp[1]>=x[i][0] && temp[1]<=x[i][1]){
			dp[1][x[i][2]]=0;
		}
	}
	for(int i=2;i<=D;i++){
		for(int j=1;j<=N;j++){
			if(temp[i]>=x[j][0] && temp[i]<=x[j][1]){
				for(int k=0;k<=100;k++){
					dp[i][x[j][2]]=max(dp[i][x[j][2]],dp[i-1][k]+abs(x[j][2]-k));
				}
			}
		}
	}
	for(int i=0;i<=100;i++){
		MAX=max(MAX,dp[D][i]);
	}
	cout<<MAX<<endl;
	return 0;
}

Measured memory_bytes: 1316
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        Deque<Integer> b = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                b.addLast(a[i]);
            } else {
                b.addFirst(a[i]);
            }
        }
        Integer c[] = new Integer[n];
        if (n % 2 == 1) {
            Collections.reverse(Arrays.asList(b.toArray(c)));
        } else {
            b.toArray(c);
        }
        for (int v : c) {
            System.out.print(Integer.toString(v) + " ");
        }
        System.out.println("");
    }
}

Measured memory_bytes: 64924
const main = (input) => {
  input = input.split(' ');
  const icon = input[1];
  const A = parseInt(input[0], 10);
  const B = parseInt(input[2], 10);
 
  if (icon=="+") {
    console.log(A+B);
  }else{
    console.log(A-B);
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

vector<vector<pair<int, int>>> G;
vector<int> es;

bool dfs(int v, int tv, int par = -1){
    if(v == tv) return true;
    for(auto nv : G[v]){
        if(nv.first == par) continue;
        if(dfs(nv.first, tv, v)){
            es.push_back(nv.second);
            return true;
        }
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N;
    G.resize(N);
    REP(i,N-1){
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }
    cin >> M;
    vector<ll> st(M);
    REP(i,M){
        int a, b;
        cin >> a >> b;
        --a, --b;
        es = vector<int>();
        dfs(a, b);
        for(auto e : es) st[i] |= (1LL << e);
    }
    ll ans = 0;
    REP(i, 1<<M){
        ll bits = 0;
        REP(j, M) if((i >> j) & 1) bits |= st[j];
        ll white = __builtin_popcountll(bits);
        if(__builtin_popcountll(i) % 2 == 0) ans += 1LL << (N - 1 - white);
        else ans -= 1LL << (N - 1 - white);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}

inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

signed main() {
	IOS();
	ll n;
	cin >> n;
	vector<ll> b(n), ans;
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int j = 0; j < n; j++) {
		for (int i = b.size() - 1; i >= 0; i--) {
			if (b[i] == i + 1) {
				ans.push_back(b[i]);
				b.erase(b.begin() + i);
				break;
			}
		}
	}
	//dump(ans.size());
	reverse(ans.begin(), ans.end());
	if (ans.size() != n) {
		dump(-1);
		return 0;
	}
	for (int i = 0; i < n; i++) {
		dump(ans[i]);
	}
	return 0;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    long long a, b, n;
    cin >> a >> b >> n;

    cout << a * min(b - 1, n) / b - a * (min(b - 1, n) / b) << "\n";

    return 0;
}


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

int main(){
 
  vector<vector<int>>  c(3,vector<int>(3));
  for(int i=0;i<3;++i){
    for(int j=0;j<3;++j){
      cin>>c.at(i).at(j);
    }
  }

  if(c.at(0).at(0)+c.at(1).at(1)==c.at(1).at(0)+c.at(0).at(1) && c.at(0).at(0)+c.at(2).at(2)==c.at(0).at(2)+c.at(2).at(0) && c.at(1).at(0)+c.at(2).at(1)==c.at(2).at(0)+c.at(1).at(1) && c.at(0).at(1)+c.at(1).at(2)==c.at(0).at(2)+c.at(1).at(1)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val n = readLine()!!.toInt()

    val v = readLine()!!.split(" ").map { it.toDouble() }.sorted().toTypedArray()

    for (i in 0 until n - 1) {
        v[i + 1] = (v[i] + v[i + 1]) / 2.0
    }

    println(v[n - 1])
}


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

using namespace std;
using ll = long long;
using ld = long double;

int main() {
  ld L;
  std::cin >> L;

  ld l = L / 3.0;

  std::cout << fixed << setprecision(12) << l*l*l << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

@SuppressWarnings("unchecked")
class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int w =  sc.nextInt(), h = sc.nextInt();
            if(w==0 && h==0) break;

            int sx = 0, sy = 0, gx = 0, gy = 0;
            ArrayList[] list = new ArrayList[5];
            for(int i=0; i<5; i++) list[i] = new ArrayList<int[]>();

            for(int i=0; i<h; i++){
                char[] line = sc.next().toCharArray();
                for(int j=0; j<w; j++){
                    if(line[j]=='S') {sx = j; sy = i;}
                    if(line[j]=='G') {gx = j; gy = i;}
                    if(Character.isDigit(line[j])) list[line[j]-'1'].add(new int[]{j, i});
                }
            }

            int INF = Integer.MAX_VALUE/2;
            int idx = 0; int min = INF;
            for(int start=0; start<5; start++){
                int[][] dp = new int[5][];
                for(int i=1; i<=4; i++){
                    int now = (start + i) % 5;
                    int before = (now + 4) % 5;
                    dp[now] = new int[list[now].size()];
                    Arrays.fill(dp[now], INF);
                    for(int j=0; j<list[now].size(); j++){
                        int[] pos = (int[])list[now].get(j);
                        if(i==1){
                            dp[now][j] = Math.abs(sx - pos[0]) + Math.abs(sy - pos[1]);
                            continue;
                        }
                        for(int k=0; k<list[before].size(); k++){
                            int[] pos2 = (int[])list[before].get(k);
                            int dist = dp[before][k] + Math.abs(pos[0] - pos2[0]) 
                                + Math.abs(pos[1] - pos2[1]);
                            if(i==4){
                                dist += Math.abs(gx - pos[0]) + Math.abs(gy - pos[1]);
                                if(dist<min){
                                    min = dist;
                                    idx = start + 1;
                                }
                            }
                            dp[now][j] = Math.min(dp[now][j], dist);
                        }
                    }
                }
            }
            if(min==INF) System.out.println("NA");
            else System.out.println(idx+" "+min);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 72460
#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(){
	string s;
	cin >> s;
	int sum = 0;
	sum += ((int)s.size() - 1)*9;
    sum += (s[0] - '0') -1;

    int sum1 = 0;
    rep(i,(int)s.size()){
    	sum1 += s[i] - '0';
    }
	cout << max(sum,sum1) << endl;
}

// cout << fixed << setprecision(15) <<  << endl;

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

using namespace std;

#define int long long

int n,m;
int a[5001], f[5001];
int b[5001][201];
int log_2[5001];
int rmq[201][5001][16];

void prepare()
{
	int cur = 1, val = -1;
	for (int i=1;i<=5000;i++)
	{
		if (i == cur)	
		{
			cur *= 2;
			val++;
		}	
		log_2[i] = val;
	}
}

int val(int l,int r)
{
	int d = (r-l+1);
	int z = log_2[d];
	int ans = (a[l] - a[r]);
	for (int k=1;k<=m;k++)
		ans += max(rmq[k][l][z],rmq[k][r-(1<<z)+1][z]);			
	return ans;		
}

void cal(int l,int r,int opt_l,int opt_r)
{
	if (l > r)
		return;
	int mi = (l+r)/2;
	int opt_val = -1e18, pos = -1;
	for (int i=opt_l;i<=min(mi,opt_r);i++)
	{
		int cost = val(i,mi);
		if (cost > opt_val)
		{
			opt_val = cost;
			pos = i;
		}
	}
	f[mi] = opt_val;
	cal(l,mi-1,opt_l,pos);
	cal(mi+1,r,pos,opt_r);
}

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

	prepare();
	cin >> n >> m;
	for (int i=2;i<=n;i++)
	{
		int d; cin >> d;
		a[i] = a[i-1] + d;
	}	
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		{
			cin >> b[i][j];
			rmq[j][i][0] = b[i][j];
		}
	for (int k=1;k<=m;k++)
		for (int j=1;j<=15;j++)
			for (int i=1;i+(1<<j)-1<=n;i++)
				rmq[k][i][j] = max(rmq[k][i][j-1],rmq[k][i+(1<<(j-1))][j-1]);
	cal(1,n,1,n);
	int ans = -1e18;
	for (int i=1;i<=n;i++)
		ans = max(ans,f[i]);
	cout << ans;	
}

Measured memory_bytes: 133248
def main():
    H, W, A, B = map(int, input().split())
    S = [[0] * W for _ in range(H)]
    for i in range(B):
        for j in range(W):
            if j >= A:
                S[i][j] = 1

    for i in range(A):
        for j in range(H):
            if j >= B:
                S[j][i] = 1

    for i in range(H):
        print(*S[i], sep='')




if __name__ == "__main__":
    main()

Measured memory_bytes: 88700
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	lli n, ans=0;
	cin >> n;
	vector<string> s(n);
	map<string, lli> im;
	rep(i,n){
		cin >> s[i];
		sort(all(s[i]));
		if(im[s[i]] > 0){
			ans += im[s[i]];
			im[s[i]] += 1;
		}else{
			im[s[i]] = 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
int n;
string s[110];
int main()
{
    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    int t;cin>>n>>t;
    for(int i=0;i<n;i++) cin>>s[i];
    sort(s,s+n);
    for(string i:s) cout<<i;
}



Measured memory_bytes: 256
#include <iostream>
#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 <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp

int N;
int A[10005];

int bubble() {
    bool flag = true;
    int cnt = 0;
    for (int i = 0; flag; i++) {
        flag = false;
        for (int j = N-1; j >= i+1; j--) {
            if (A[j] < A[j-1]) {
                flag = true;
                swap(A[j], A[j-1]);
                cnt++;
            }
        }
    }
    return cnt;
}

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];
    int c = bubble();
    arrdump(N, A);
    cout << c << "\n";
    return 0;
}



Measured memory_bytes: 3060
main(N){
	int i,S;
	for(;scanf("%d",&N)*N;){
		S=-N;
		for(i=1;i*i<N;i++){
			if(N%i==0)
				S+=i+N/i;
		}
		printf("%st number\n",S<N?"deficien":S>N?"abundan":"perfec");
	}
}

Measured memory_bytes: 0
let move_cur cur side =
    match side with
    | (a, b) when cur = a -> b
    | (a, b) when cur = b -> a
    | _                   -> cur

let () =
    let n_lines = read_int () in
    let n_sides = read_int () in

    let sides = Array.make n_sides (0, 0) in
    for i = 0 to n_sides-1 do
        let side = Scanf.scanf "%d,%d\n" (fun a b -> (a, b)) in
        sides.(i) <- side
    done ;

    let starts = Array.make n_lines 0 in
    for start = 1 to n_lines do
        let last = Array.fold_left move_cur start sides in
        starts.(last-1) <- start
    done ;

    Array.iter (Printf.printf "%d\n") starts

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

int main() {
  int K, S;
  cin >> K >>  S;
  
  int z, cnt=0;
  rep(x, K+1) {
    rep(y, K+1) {
      z = S - (x + y);
      if (0 <= z and z <= K) cnt++;
    }
  } 
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

	if (1 <= N && N <= 9) {
		cout << "Yes" << endl;
	}
	else {
		if (N % 2 == 0 && N / 2 < 10
			|| N % 3 == 0 && N / 3 < 10
			|| N % 4 == 0 && N / 4 < 10
			|| N % 5 == 0 && N / 5 < 10
			|| N % 6 == 0 && N / 6 < 10
			|| N % 7 == 0 && N / 7 < 10
			|| N % 8 == 0 && N / 8 < 10
			|| N % 9 == 0 && N / 9 < 10) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}

	}

	return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	while(true){
		int H=in(),W=in();
		if(!H && !W) break;
		REP(i,H){
			REP(j,W){
				if(i==0 || i==H-1 || j==0 || j==W-1) cout << '#';
				else cout << '.';
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}



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

int main(){
    int n;
    cin >> n;
    while(n--){
        int v[3];
        for(int i = 0 ; i < 3 ; ++i){
            cin >> v[i];
        }

        sort(v, v + 3);

        if(v[0] * v[0] + v[1] * v[1] == v[2] * v[2]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3116
size = gets.to_i
arr = gets.split(' ').map(&:to_i)
hash = arr.group_by(&:itself)
ans = {}
conb_count = 0
hash.each{|key, val|
  conb = val.size * (val.size - 1) / 2
  ans.store(key, conb)
  conb_count += conb
}

arr.each do |val|
  tmp = hash[val].size
  puts (conb_count - ans[val] + (tmp -1) * (tmp -2) /2)
end

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	while(1){
		int n, m, a;
		int ami[200][1000];
		cin >> n >> m >> a;
		if(n == 0 && m == 0 && a == 0) break;

		for(int i=0; i<=100; i++){
			for(int j=0; j<=1000; j++){
				ami[i][j] = -1;
			}
		}

		int height = -1;
		for(int i=0; i<m; i++){
			int h, p, q;
			cin >> h >> p >> q;
			height = max(height, h);
			ami[p][h] = q;
			ami[q][h] = p;
		}

		int pos = a;
		for(int i=height; i>0; i--){
			if(ami[pos][i] == -1){

			}else{
				pos = ami[pos][i];
			}
		}
		cout << pos << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3460
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

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

#define endl "\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(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<int>x(m);
	rep(i,m)cin>>x[i];
	if(m<=n){
		cout<<0<<endl;
		return 0;
	}
	sort(all(x));
	vector<lint>diff(m-1);
	rep(i,m-1)diff[i]=x[i+1]-x[i];
	sort(all(diff));
	reverse(all(diff));
	lint result=x.back()-x.front();
	rep(i,n-1)result-=diff[i];
	cout<<result<<endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 100000000;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 998244353;
const ll maxn = 2000005;
string s;
map<string,int> m;
int main(){
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		cin>>s;
		m[s]++;
	}
	
	printf("AC x %d\n",m["AC"]);
	printf("WA x %d\n",m["WA"]);
	printf("TLE x %d\n",m["TLE"]);
	printf("RE x %d",m["RE"]);


	return 0; 
}





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

int main() {
  int H,W;
  cin >> H >> W;
  
  vector<vector<char>> output(H+2, vector<char>(W+2,'#'));
  
  for(int i=1; i<H+1; i++){
    for(int j=1; j<W+1; j++){
      cin >> output.at(i).at(j);
    }
  }
  
  for(int i=0; i<H+2; i++){
    for(int j=0; j<W+2; j++){
      cout<< output.at(i).at(j);
      if(j==W+1)
        cout << endl;
    }
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int a[200010];
int main(){
    int n, ans, MIN;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    ans = -INF;
    MIN = a[0];
    for(int i = 1; i < n; i++){
        ans = max(ans, a[i] - MIN);
        MIN = min(MIN, a[i]);
    }
    printf("%d\n", ans);
}



Measured memory_bytes: 4000
use strict;
use warnings;
use utf8;
use feature qw/say/;

my $num = <STDIN>;
chomp($num);

if ( ($num / 100) >= 1)   { print "ABC$num"; } 
elsif ( ($num / 10) >= 1) { print "ABC0$num"; }
else { print "ABC00$num"; } 



Measured memory_bytes: 768
n = int(input())
s = input()
x = []
if s[0]=="E": x.append(1)
else: x.append(0)
for i in range(1,n):
	if s[i]=="E": x.append(x[-1]+1)
	else: x.append(x[-1])
ans = x[-1]-x[0]
for i in range(1,n): ans = min(ans,x[-1]-x[i]+i-x[i-1])
print(ans)

Measured memory_bytes: 15520
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

int main() {
  int N;
  cin>>N;
  int A[N+2];
  memset(A,0,sizeof(A));
  for (int i=1; i<=N; i++) {
    cin>>A[i];
  }
  int D=0;
  for (int i=0; i<=N; i++) {
    D+=abs(A[i+1]-A[i]);
  }
  for (int i=1; i<=N; i++) {
    int ans=(D-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]));
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 1664
ary = input().split(" ")
a = ary[0]
b = ary[1]
c = ary[2]

if a == b and ( a != c or b != c )  :
  print("Yes") 
elif a == c and ( a != b or c != b ) :
  print("Yes") 
elif b == c and ( b != a or c != a ) :
  print("Yes") 
else :
  print("No")
 

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n; std::cin >> n;
    vl a(n); rep(i, n) std::cin >> a[i];
    vl ans(n);
    ll l = -1, r = 2*1'000'000'000;
    while (r-l > 1) {
        ll mid = (l+r)/2;
        ans[0] = 2*mid;
        srep(i, 1, n) ans[i] = 2*(a[i-1] - ans[i-1]/2);
        if (ans[0]/2+ans[n-1]/2 == a[n-1])
            break;
        else if (ans[0]/2+ans[n-1]/2 > a[n-1])
            r = mid;
        else
            l = mid;
    }
    rep(i, n) std::cout << ans[i] << (i+1 < n ? " " : "\n");
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e15;
template<typename T> void cmax(T &a, T b) {a = max(a, b);}
template<typename T> void cmin(T &a, T b) {a = min(a, b);}

signed main(){
  string t;
  set<char> s={'y','u','i','o','p','h','j','k','l','n','m'};

  while(cin>>t){
    if(t=="#")break;
    vector<int> a;
    rep(i,t.size()){
      if(s.count(t[i]))a.push_back(1);
      else a.push_back(0);
    }
    int ans=0;
    rep(i,a.size()-1){
      ans+=(a[i+1]^a[i]);
    }
    cout<<ans<<endl;


  }

 return 0;
}



Measured memory_bytes: 3044
import sys

stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)


def li(): return map(int, stdin.readline().split())


def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())


def lf(): return map(float, stdin.readline().split())


def ls(): return stdin.readline().split()


def ns(): return stdin.readline().rstrip()


def lc(): return list(ns())


def ni(): return int(stdin.readline())


def nf(): return float(stdin.readline())

N = int(input())
P_str = input().split()
P = [int(p) for p in P_str]

Q = sorted(P)
check = 0
for i in range(len(P)):
    if P[i] != Q[i]:
        check += 1

    if check > 2:
        print("NO")
        exit()

if check == 1:
    print("NO")
    exit()

print("YES")



Measured memory_bytes: 3064
unittest
{
	assert( [ "5" ].parse.expand.solve == 3 );
	assert( [ "2" ].parse.expand.solve == 1 );
	assert( [ "100" ].parse.expand.solve == 50 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	return ( n + 1 ) / 2;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;
vector<int> P, Q;
bool judge(int n)
{
	rep(i, 0, n) if (P[i] != Q[i])return false;
	return true;
}
int facto(int n) {
	int p = 1;
	rep(i, 2, n + 1)p *= i;
	return p;
}

int main(void)
{
	int N; cin >> N;
	P.resize(N); Q.resize(N);
	rep(i, 0, N)cin >> P[i]; rep(i, 0, N)cin >> Q[i];
	bool flag = false;
	int ans = 0;
	while (!judge(N)) {
		ans++;
		if (!next_permutation(Q.begin(), Q.end()))flag = true;
		
	}
	if (flag)cout << (facto(N) -ans) << endl;
	else cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
S = input()
s = list(S)

m = len(S) // 2
answer = 0

string1 = s[0:m]
string2 = []
for i in range(m):
  string2.append(s[-(i+1)])

for i in range(m):
  if string1[i] == string2[i]:
    pass
  else:
    answer += 1
else:
  print(answer)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

bool isOK(int N, ll K, const vector<ll>& A, ll d) {
    ll cnt = 0;
    for (auto& a : A) {
        cnt += (a + d - 1) / d - 1;
    }
    return cnt <= K;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    ll l = 0, r = 1000000000;
    while (r - l > 1) {
        ll mid = (l + r) / 2;
        if (isOK(N, K, A, mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 4764