akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 7+1e18
#define lld long double
#define eps 0.000001
#define endl '\n'
using namespace std ;

int main()
{

    lli h,w;
    cin>>h>>w;
    char a[h][w],ans[h][w];

    loopl(i,0,h)
    loopl(j,0,w) 
    cin>>a[i][j];
    

    loopl(i,0,h)
    loopl(j,0,w) ans[i][j]='0';


    loopl(i,0,h)
    {
    	lli cnt=0;
    	loopl(j,0,w) if(a[i][j]=='.') cnt++;
        if(cnt!=w)
        {
           loopl(j,0,w) ans[i][j]=a[i][j];
        }

    }
   

    loopl(j,0,w)
    {
    	lli cnt=0;
    	loopl(i,0,h) if(ans[i][j]=='.'||ans[i][j]=='0') cnt++;
        if(cnt==h)
        {
           loopl(i,0,h) ans[i][j]='0';
        }

    }

    loopl(i,0,h) 
    {
    	lli cnt=0;
    	loopl(j,0,w)
    	if(ans[i][j]!='0') {cout<<ans[i][j]; cnt++;}
    	if(cnt!=0)cout<<endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(n%2==0){
            System.out.println(n);
        }
        else{
            System.out.println(n*2);
        }
    }    
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void read(i64 &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=100005;
const int mod=1e9+7;
int n;
i64 A,B,S[maxn];
struct szsz{
	int sum[maxn];
	inline void add(int x,int v){
		while(x<=n){
			sum[x]=(sum[x]+v)%mod;
			x+=lowbit(x);
		}
	}
	inline int query(int x){
		if(x<0)return 0;
		int res=0;
		while(x){
			res=(res+sum[x])%mod;
			x-=lowbit(x);
		}
		return res;
	}
	inline int query(int l,int r){
		if(l>r)return 0;
		return (query(r)-query(l-1)+mod)%mod;
	}
}F,G;
int f[maxn],g[maxn];
inline int find(int x,i64 v){
	int l=1,r=x,ans=0;
	while(l<=r){
		int md=(l+r)>>1;
		if(S[x]-S[md]>=v){
			ans=md;l=md+1;
		}else{
			r=md-1;
		}
	}return ans;
}
int main(){
	// judge();
	read(n);read(A);read(B);
	rep(i,1,n)read(S[i]);
	int lstf=0,lstg=0;
	f[1]=1;g[1]=1;
	S[0]=-1e18;
	F.add(1,f[1]);
	G.add(1,g[1]);
	rep(i,2,n){
		int posf=find(i,A),posg=find(i,B);
		//part F
		if(S[i]-S[i-2]>=A)
			f[i]=g[i-1];
		f[i]=(f[i]+G.query(lstf,min(i-2,posf+1)))%mod;

		//part G
		if(S[i]-S[i-2]>=B)
			g[i]=f[i-1];
		g[i]=(g[i]+F.query(lstg,min(i-2,posg+1)))%mod;

		if(S[i]-S[i-1]<B)lstf=i;
		if(S[i]-S[i-1]<A)lstg=i;
		
		F.add(i,f[i]);
		G.add(i,g[i]);
		// printf("%d %d\n",f[i],g[i]);
	}
	bool vf=1,vg=1;
	int ans=0;
	per(i,n,1){
		if(vf){
			ans=(ans+f[i])%mod;
		}
		//if(vf&&S[i+1]-S[i-1]>=A){
		//	ans=(ans+g[i])%mod;
		//}
		if(vg){
			ans=(ans+g[i])%mod;
		}
		//if(vg&&S[i+1]-S[i-1]>=B){
		//	ans=(ans+f[i])%mod;
		//}
		if(S[i]-S[i-1]<A)vf=0;
		if(S[i]-S[i-1]<B)vg=0;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
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;} }
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>



int main(){
    ll N,K; cin>>N>>K;
    int a[N]; CINA(a,N);
    ll ans = 0;
    for(int i=0;i<N;++i){
        ll x = 0;
        ll y = 0;
        for(int j=0;j<i;j++){
            if(a[i]>a[j]){++x;}
        }
        for(int j=i+1;j<N;++j){
            if(a[i]>a[j]){++y;}
        }
        
        ll temp = y*K%MOD;
        ll semp = K*(K-1)/2%MOD*(x+y)%MOD;
        ans += (temp+semp)%MOD;
        ans %= MOD;
    }
    cout << ans << "\n";
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll n, c;
	cin >> n >> c;

	ll x[n+2], v[n+2];
	x[0] = 0;
	v[0] = 0;
	x[n+1] = 0;
	v[n+1] = 0;
	rep(i,n) cin >> x[i+1] >> v[i+1];

	ll hx[n+2];
	hx[0] = 0;
	hx[n+1] = 0;
	rep(i,n) hx[i+1] = c - x[i+1];

	ll t = 0;
	ll tv[n+1];
	tv[0] = 0;

	rep(i,n){
		t += v[i+1] - x[i+1] + x[i];
		tv[i+1] = max(tv[i], t);
	}

	ll h = 0;
	ll hv[n+2];
	hv[n+1] = 0;


	rrep(i,n){
		h += v[i+1] - hx[i+1] + hx[i+2];
		hv[i+1] = max(hv[i+2], h);
	}

	ll ans = 0;
	rep(i,n){
		ans = max(ans, tv[i+1] + max(hv[i+2]- x[i+1],0LL));
		ans = max(ans, hv[i+1] + max(tv[i] - hx[i+1],0LL));
	}

	cout << ans << endl;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    ll k; cin >> k;
    for(ll i = 2; i <= 50; i++){
        vector<ll> v(i);
        rep(j,i){
            v[j] = (ll)j; 
        }
        rep(j,i){
            v[j] += k/i;
        }
        rep(j,k%i){
            for(int k = 0; k < i; k++){
                if(k == j){
                    v[k] += i;
                }else{
                    v[k] -= 1;
                }
            }
        }
        bool ok = true;
        rep(j,i){
            if(v[j] > 1e16 + 1000) ok = false;
        }
        if(ok){
            cout << i << endl;
            rep(j,i){
                cout << v[j] << ' ' ;
            }
            return 0;
        }
    }
}

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

int main(){
	int n, i;
	int a[100];
	
	cin >> n;
	
	for(i = 0; i < n; i++){
		cin >> a[i];
	}
	for(i = n-1; i >= 0; i--){
		if(i != n-1){
			cout << " ";
		}
		cout << a[i];
	}
	cout << endl;
	
    return 0;
}

Measured memory_bytes: 3092
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		
		while(stdIn.hasNext()){
			int[] length = new int[10];
			int[] v = new int[2];
			String str = stdIn.nextLine();
			int j = 0;
			int k = 0;
			
			for(int i=0;i<str.length();i++){
				if('0'<=str.charAt(i) && str.charAt(i)<='9'){
					length[j] = length[j] * 10;
					length[j] += (int)str.charAt(i)-(int)'0';
				}
				else{
					j++;
					if(j==10){
						k = i + 1;
						break;
					}
				}
			}
			j = 0;
			for(int i=k;i<str.length();i++){
				if('0'<=str.charAt(i) && str.charAt(i)<='9'){
					v[j] = v[j] * 10;
					v[j] += (int)str.charAt(i)-(int)'0';
				}
				else{
					j++;
				}
			}
			
			int l = 0;
			for(int i=0;i<10;i++){
				l += length[i];
			}
			double t = (double)l/(v[0]+v[1]);
			double len = v[0]*t;
			
			j=0;
			double le = 0;
			while(true){
				le += (double)length[j];
				if(le>=len){
					System.out.println(j+1);
					break;
				}
				j++;
			}
		}
	}
}

Measured memory_bytes: 17332
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

const int MOD = 1e9+7;
vector<vector<int>> to;
vector<vector<ll>> dp;
void dfs(int now, int prev) {
  dp[now][0] = 1;
  dp[now][1] = 1;
  for (auto next : to[now]) {
    if (next == prev)
      continue;
    dfs(next, now);
    (dp[now][0] *= (dp[next][0]+dp[next][1])%MOD) %= MOD;
    (dp[now][1] *= dp[next][0]) %= MOD;
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  to.resize(n);
  rep(i, n-1) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    to[x].push_back(y);
    to[y].push_back(x);
  }
  dp.resize(n, vector<ll>(2, 0));
  dfs(0, -1);
  int ans = (dp[0][0]+dp[0][1])%MOD;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

class Solution {
public:
	int f(string& s, int p) {
		int n = s.length();
		int k = 1 % p;
		int ret = 0;
		for (int i = n - 1; i >= 0; i--) {
			ret += k * (s[i] - '0');
			ret %= p;
			k <<= 1;
			k %= p;
		}
		return ret;
	}

	void solve() {
		int n;
		string s;
		cin >> n >> s;
		int c1 = 0;
		vector<int> dp(n + 1, 0);
		dp[1] = 1;
		for (int i = 2; i <= n; i++) {
			dp[i] = 1 + dp[i % __builtin_popcount(i)];
		}

		for (int i = 0; i < n; i++)
			if (s[i] == '1') c1++;
		if (c1 == 0) {
			for (int i = 0; i < n; i++) cout << 1 << "\n";
			return;
		}
		if (c1 == 1) {
			for (int i = 0; i < n; i++) {
				if (s[i] == '1')
					cout << "0\n";
				else if (s[n - 1] == '1' || i == n - 1)
					cout << "2\n";
				else
					cout << "1\n";
			}
			return;
		}
		int defp = f(s, c1 + 1);
		int defn = f(s, c1 - 1);
		vector<int> ans(n);
		int kp = 1 % (c1 + 1), kn = 1 % (c1 - 1);
		for (int i = n - 1; i >= 0; i--) {
			int p = c1 + ((s[i] == '0') ? 1 : -1);
			if (s[i] == '0') {
				ans[i] = 1 + dp[(defp + kp) % p];
			} else {
				ans[i] = 1 + dp[(defn + 100 * p - kn) % p];
			}
			kp <<= 1;
			kn <<= 1;
			kp %= c1 + 1;
			kn %= c1 - 1;
		}
		for (int i = 0; i < n; i++) cout << ans[i] << "\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m;
    cin >> n >> m;
    vector<ll> v(m);
    ll sum = 0;
    for(int i = 0; i < m; i++){
        cin >> v[i];
        sum += v[i];
    }
   // cout << sum << endl;
    if(sum <= n){
        cout << n - sum << endl;
    }
    else{
        cout << "-1" << endl;
    }
    return 0;
}


Measured memory_bytes: 3692
#include <stdio.h>
#include <stdlib.h>
#define MAX 199
#define true 1
#define false 0
void initialize(void);
int isEmpty(void);
int isFull(void);
void push(int);
int pop(void);
int top = 0;
int S[MAX];

int main()
{
  int x,a1,a2;
  char s[7];

  while(scanf("%s",s) != EOF){
    
    if(s[0] == '+'){
      a1 = pop();
      a2 = pop();
      x = a1 + a2;
      push(x); }
    else if(s[0] == '-'){
      a1 = pop();
      a2 = pop();
      x = a2 - a1; 
      push(x); }
    else if(s[0] == '*'){
      a1 = pop();
      a2 = pop();
      x = a1 * a2;
      push(x); }
    else{
      x = atoi(s);
      push(x); }
    
  }

  x = pop();
  
  printf("%d\n",x);

  return 0;
}

void initialize(void)
{
  top = 0;
}

int isEmpty(void)
{
  if(top == 0) return true;
  return false;
}

int isFull(void)
{
  if(top >= MAX - 1) return true;
  return false;
}

void push(int x)
{
  
  if(isFull() == true) printf("error overfllow\n");

  top++;
  
  S[top] = x;

}

int pop(void)
{

  if(isEmpty() == true) printf("error underfllow\n");

  top--;

  return S[top+1];
}


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

int main(void) {
  int n;cin >> n;
  vector<string> s(n);
  for (auto&& vec:s) {
    cin >> vec;
  }
  int c=0;
  for(int i=0;i<n-1;i++) {
    for(int j=i+1;j<n;j++) {
      if(s[i] == s[j]) {
        c = 1;
      }
    }
    if (s[i].back() != s[i+1].front()) {
      c = 1;
    }
  }
  if (c ==1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << 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);
    String str = sc.nextLine();
    sc.close();
    if(str.endsWith("3")) {
      System.out.println("bon");
    }else if(str.endsWith("0")||str.endsWith("1")||str.endsWith("6")||str.endsWith("8")) {
      System.out.println("pon");
    }else {
      System.out.println("hon");
    }

  }

}


Measured memory_bytes: 35660
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner scan = new Scanner(System.in);        
        String As = scan.next();
        String Bs = scan.next();
        String Cs = scan.next();

	    int A = Integer.parseInt(As);
	    int B = Integer.parseInt(Bs);
 	    int C = Integer.parseInt(Cs);

        if(A==B){
            if(A==C){
                System.out.println("No");
            }else{
                System.out.println("Yes");
            }
        }else if(B==C || A==C){
                System.out.println("Yes");
        }else{
                System.out.println("No");
        }
        
    }
}

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

int main() {
    long long n, m; cin >> n >> m;
    string s, t; cin >> s >> t;
    long long g = __gcd(n, m), l = n * m / g;
    for (int i = 0; i < g; i++) {
        if (s[i * n / g] != t[i * m / g]) {
            l = -1;
            break;
        } 
    }
    cout << l << endl;
}

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

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    ll n, W;
    cin >> n >> W;
    ll w[n], val[n];
    for (int i = 0; i < n; i++)
        cin >> w[i] >> val[i];
    ll dp[n + 1][W + 1];
    for (int i = 0; i <= n; i++)
    {
        for (int c = 0; c <= W; c++)
        {
            if (c== 0 || i == 0)
                dp[i][c] = 0;
            else if (w[i - 1] <= c)
                dp[i][c] = max(val[i-1] + dp[i-1][c-w[i-1]],  dp[i-1][c]); 
            else
                dp[i][c] = dp[i - 1][c];
        }
    }

    cout << dp[n][W];


    return 0;
}

Measured memory_bytes: 79232
#include <iostream>

using namespace std;


int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N; cin >> N;
    int cnt = 0;

    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        if (a == b) {
            cnt++;
        }
        else if(cnt < 3){
            cnt = 0;
        }
    }

    if (cnt >= 3) {
        std::cout << "Yes" << std::endl;
    }
    else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n;
int r[1111],w[1111];
int dp[1111];

int main(){
	cin.sync_with_stdio(false);
  while(1){
    cin>>n;
    if(n==0)break;
    int rs=0,ws=0;
    rep(i,n){
      cin>>r[i]>>w[i];
      rs+=r[i]; ws+=w[i];
    }
    int midx=max_element(r,r+n)-r;
    int mr=*max_element(r,r+n);
    if(mr<=rs/2){
      cout<<rs+ws<<endl;
    }else{
      int rest=mr*2-rs;
      memset(dp,0,sizeof(dp));
      dp[0]=1;
      rep(i,n)for(int j=1000;j>=0;j--){
        if(i==midx)continue;
        if(dp[j]&&w[i]+j<=1000)dp[w[i]+j]=1;
      }
      int used=0;
      rep(j,rest+1)if(dp[j])maxch(used,j);
      cout<<mr*2+(ws-used)<<endl;
    }
  }
	return 0;
}

Measured memory_bytes: 3112
n = int(input())
data = input().split()
 
ans = "APPROVED"
 
for i in range(n):
  num = int(data[i])
  if num % 2 == 0:
    if num % 3 != 0 and num % 5 != 0:
      ans = "DENIED"
      break  
 
print(ans)


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

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

    ll N;
    cin >> N;
    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    ll res = 0;
    REP(i, N){
        if(i%2==0 and a[i]%2==1) res++;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3588
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    A,B,C,K=map(int,input().split())
    if K<=A:
        print(K)
    else:
        if (K-A)<=B:
            print(A)
        else:
            print(2*A+B-K)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;
const int mod = 1000000007;

int main(){
    int S; cin >> S;
    vector<int> ans(2000 + 1, 0);
    ans[3] = 1;
    ans[4] = 1;
    ans[5] = 1;
    ans[6] = 2;
    ans[7] = 3;
    ans[8] = 4;
    for(int i = 9; i <= 2000; i++){
        ll tmp = 0;
        for(int j = 3; j <= i - 3; j++){
            tmp += ans[i - j];
            tmp %= mod;
        }
        // tmp += (i - 3) - 6 + 2;
        tmp++;
        tmp %= mod;
        ans[i] = tmp;
    }
    // rep(i, 20)cout << ans[i] << endl;
    cout << ans[S] << endl;
}

Measured memory_bytes: 3628
S=raw_input()
key="keyence"

num=0
if S[0]=="k":
    num=1
    for i in range(1,7):
        if S[i]==key[i]:
            num+=1
        else:
            break
    if num==7:
        print "YES"
    else:
        for i in range(1,8-num):
            if S[-i]==key[-i]:
                num+=1
            else:
                break
        if num==7:
            print "YES"
                    
if num<7:
    for i in range(1,8):
        if S[-i]==key[-i]:
            num+=1
        else:
            break
    if num==7:
        print "YES"
    else:
        print "NO"

Measured memory_bytes: 2692
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

//#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

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

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

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 64;
const int N = (int)2e5 + 7;
const int MAXN = (int)5e6 + 7;
const int MOD = (int)998244353;
const int INF = (int)2e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e18;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

int n, a[N], b[N];

void solve() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i];
	sort(a, a + n);
	sort(b, b + n);
	if (n % 2) {
		int l = a[n / 2], r = b[n / 2];
		cout << r - l + 1;
	}
	else {
		int l = a[n / 2 - 1] + a[n / 2];
		int r = b[n / 2 - 1] + b[n / 2];
		cout << r - l + 1;
	}
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 5196
package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for A - AtCoder Group Contest
	var N int
	fmt.Scanf("%d", &N)

	sc.Split(bufio.ScanWords)
	a := make([]int, 3*N)
	for i := 0; i < 3*N; i++ {
		a[i] = nextInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	var ans int
	for i := 0; i < 2*N; i++ {
		if i%2 != 0 {
			ans += a[i]
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 6780
n = int(input())
s = input()
num = 0
for i in range(len(s)):
    t1 = s[:i]
    t2 = s[i:]
    rec = 0
    rec1 = []
    for j in range(len(s)):
        if s[j] in t1 and s[j] in t2 and s[j] not in rec1:
            rec += 1
            rec1.append(s[j])

    num = max(num, rec)
print(num)

Measured memory_bytes: 3064
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Text.RegularExpressions;

namespace Yuzuki
{
    class Yukari
    {
        static int n, m;
        static string s, t;

        public static void Main(string[] args)
        {
            input();

            for (int i = 0; i <= n; i++)
            {
                if (2 * i + 4 * (n-i) == m)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");
        }

        public static void input()
        {
            string[] buf = Console.ReadLine().Split();

            n = int.Parse(buf[0]);
            m = int.Parse(buf[1]);
            //s = buf[0];
            //t = buf[1];
        }

    }
}

Measured memory_bytes: 27544
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair

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

    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    while(1)
    {
        c-=b;
        if(c<1)
        {
            cout<<"Yes"<<endl;
            break;
        }
        a-=d;
        if(a<1)
        {
            cout<<"No"<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>

using namespace std;

int main(){
  string ans;

  cin >> ans;

  string search;

  cin >> search;

  int count=0;
  int sa='a'-'A';

  while(search != "END_OF_TEXT"){
    for(int i=0;i<search.length();i++){
      if(search[i]<'a' && search[i]>='A') search[i]+=sa;
    }
    if(ans==search) count++;
    cin >> search;
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 3092
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int map[6][8][8];
int h, w, c;
int max_count;
int visited[8][8];

#define fors(i, n) for (int i = 0; i < n; i++)
#define clean_visited fors(i, h) fors(j, w) visited[i][j] = 0
#define when_visited fors(i, h) fors(j, w) if (visited[i][j] == 1)

int parse()
{
    scanf("%d %d %d", &h, &w, &c);
    if (h == 0)
        return 0;
    fors(i, h) fors(j, w) scanf("%d", &map[0][i][j]);
    max_count = 0;
    return 1;
}

int dfs_fillVisited(int depth, int x, int y)
{
    visited[y][x] = 1;
    if (x + 1 < w && map[depth][y][x + 1] == map[depth][y][x] && visited[y][x + 1] != 1)
        dfs_fillVisited(depth, x + 1, y);
    if (y + 1 < h && map[depth][y + 1][x] == map[depth][y][x] && visited[y + 1][x] != 1)
        dfs_fillVisited(depth, x, y + 1);
    if (x > 0 && map[depth][y][x - 1] == map[depth][y][x] && visited[y][x - 1] != 1)
        dfs_fillVisited(depth, x - 1, y);
    if (y > 0 && map[depth][y - 1][x] == map[depth][y][x] && visited[y - 1][x] != 1)
        dfs_fillVisited(depth, x, y - 1);
}

int dfs(int depth, int flip)
{
    if (depth < 5)
    {
        fors(i, h) fors(j, w) map[depth + 1][i][j] = map[depth][i][j];
        clean_visited;
        dfs_fillVisited(depth, 0, 0);
        when_visited
        {
            map[depth + 1][i][j] = flip;
        }
        fors(i, 6)
        {
            dfs(depth + 1, i + 1);
        }
    }
    else
    {
        if (map[depth][0][0] != c)
            return 0;
        clean_visited;
        dfs_fillVisited(depth, 0, 0);
        int count = 0;
        when_visited
        {
            count++;
        }
        if (count > max_count)
            max_count = count;
    }
}
int main()
{
    while (parse())
    {
        fors(i, 6)
        {
            dfs(0, i + 1);
        }
        printf("%d\n", max_count);
    }
}



Measured memory_bytes: 2040
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0353
#ifdef _GLIBCXX_DEBUG
#define NDEBUG
#endif
#include<cassert>
#include<iostream>
#include<vector>
#include<deque>
#include<set>
#include<algorithm>
std::set<int>merge(std::set<int>a,std::set<int>b){
	if(a.size()<b.size())std::swap(a,b);
	for(int x:b)a.insert(x);return a;
}
int main(){
	std::ios_base::sync_with_stdio(false);std::cin.tie(nullptr);
	int nnum;std::cin>>nnum;

	std::vector<int>avec(nnum);
	for(int&ai:avec)std::cin>>ai;
	std::vector<int>vals=avec;std::sort(vals.begin(),vals.end());
	for(int&ai:avec)ai=std::lower_bound(vals.begin(),vals.end(),ai)
		-vals.begin();

	std::deque<std::set<int>>a;
	for(int ai:avec){
		if(a.empty()||*a.back().begin()<ai)
			a.emplace_back();//new decreasing sequence
		bool success=a.back().insert(ai).second;
		assert(success);
	} avec.clear();

	long long ans=0;
	for(int p=0;p<nnum;++p){//try to remove (p) from the sequence
		std::vector<int>mins;//to be inserted to other sets
		while(p!=*a.front().begin()){
			std::set<int>seq=std::move(a.front());a.pop_front();
			ans+=seq.size();
			assert(!seq.empty());
			while(!mins.empty()&&mins.back()>*seq.begin()){
				bool success=seq.insert(mins.back()).second;assert(success);
				mins.pop_back();
			}
			mins.push_back(*seq.begin());seq.erase(seq.begin());

			#define push_seq_to_a \
			if(!seq.empty()){ \
				if(!a.empty()&&*seq.rbegin()<*a.back().begin()) \
					a.back()=merge(std::move(a.back()),std::move(seq)); \
				else \
					a.push_back(std::move(seq)); \
			}//seq is destroyed now

			push_seq_to_a
		}
		//now that p==*a.front().begin()
		std::set<int>seq=std::move(a.front());a.pop_front();
		ans+=seq.size()-1;
		for(int x:mins){
			bool success=seq.insert(x).second;assert(success);
		} assert(p==*seq.begin()); seq.erase(seq.begin());
		push_seq_to_a
		#undef push_seq_to_a
	}
	std::cout<<ans<<'\n';
}


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

ll a[200020];
int main(){
    int n;
    while (~scanf("%d", &n)){
        int l = 0 , r = 0 , d = 0;
        ll ans = 0;
        for (int i=1; i<=n; i++){
            scanf("%lld", &a[i]);
            a[i] -= (ll)i;
            if (a[i] < 0)  l ++;
            else if (a[i] > 0)  r ++;
            else d ++;
        }

        int k = 0;
        ll temp = 0;
        sort(a+1, a+n+1);

        if (l+d < r){
            int num = (r - l - d + 1) / 2;
            if (num != 0){
                for (int i=1; i<=n; i++){
                    if (a[i] > 0){
                        k ++;
                        if (k == num) {
                            temp = -a[i];
                            break;
                        }
                    }
                }
            }
        }
        else if (l > r+d){
            int num = (l - r - d + 1) / 2;
            reverse(a+1, a+n+1);
            if (num != 0){
                for (int i=1; i<=n; i++){
                    if (a[i] < 0){
                        k ++;
                        if (k == num) {
                            temp = -a[i];
                            break;
                        }
                    }
                }
            }
        }

        for (int i=1; i<=n; i++){
            a[i] += temp;
            ans += abs(a[i]);
        }
        printf("%lld\n", ans);
    }
    return 0;
}


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

typedef long long ll;
const ll INF = 1LL<<60, MOD = 1e9 + 7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const ll dx[] = {1,0,-1,0};
const ll dy[] = {0,1,0,-1};
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()
#define m_p make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b,ans=0;
    cin >> a >> b;
    if(a-2*b > 0) ans = a-2*b;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？


a,b,c,d=mii()
cnt=0
while a>0 and c>0:
    if cnt%2==0:
        c-=b
    else:
        a-=d
    cnt+=1

if a>c:
    print("Yes")
else:
    print("No")
    



Measured memory_bytes: 72512
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

typedef pair<int, int> P; 
typedef vector<P> vpair;

int main(void){
    int n, T;
    cin >> n >> T;
    vpair ct(n);
    rep(i, n) cin >> ct[i].se >> ct[i].fi;
    sort(all(ct));
    int mn = INF;
    rep(i, n) {
        if (ct[i].fi > T) break;
        mn = min(mn, ct[i].se);
    }
    if (mn == INF) puts("TLE");
    else cout << mn << endl;
}

Measured memory_bytes: 256
#include <stdint.h>
#include <stdio.h>
#include <algorithm>

int main()
{
	int L, R;
	scanf("%d%d", &L, &R);

	uint64_t L64 = L, R64 = R;
	int ans = 10000;
	for (uint64_t a = 0; a <= 2019; a++) {
		for (uint64_t b = 0; b <= 2019; b++) {
			if (L64 + a > R64 || L64 + b > R64) {
				continue;
			}
			if (a == b) {
				continue;
			}
			uint64_t x = (L64 + a) * (L64 + b) % 2019;
			ans = std::min(ans, (int)x);
		}
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 128
def solve(A,N):
    xor_sum = 0
    for i in range(N):
        xor_sum ^= A[i]

    B = [xor_sum ^ A[i] for i in range(N)]

    return B

def main():
    N = int(input())
    A = list(map(int,input().split()))

    ans = solve(A,N)

    print(" ".join(map(str,ans)))

if __name__ == "__main__":
    main()


Measured memory_bytes: 41764
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b[110000],cl[3],cnt=1,scnt=0;
signed main()
{
	cin>>a;
	rep(i,a){
		cin>>b[i];
		rep(j,3){
			if(cl[j]==b[i]){
				scnt++;
			}
		}
		if(cl[0]==b[i]){
			cl[0]++;
		}elif(cl[1]==b[i]){
			cl[1]++;
		}elif(cl[2]==b[i]){
			cl[2]++;
		}
		cnt=(cnt*scnt)%INF;
		scnt=0;
	}
	cout<<cnt;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<k;i++){
    ans+=p[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(){
	char S[3], T[3];
	scanf("%s", S);
	scanf("%s", T);

	int N = 0;
	for (int i=0; i<3; i++) {
		if(S[i] == T[i]) N++;
	}
	printf("%d\n", N);
}

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

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }//Nがaで割り切れるときaは必ず素数

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){
  ll n;
  cin >> n;
  vector<P> vec =  prime_factorize(n);

  /*for(auto p:vec){
    cout << p.first << " " << p.second << endl;
  }*/
   
  ll ans = 0; 
   
  for(auto p:vec){
    for(int i=1;i<=p.second;i++){
      if((i*(i+1)/2) <= p.second && p.second < (i+1)*(i+2)/2){
        ans += i;
        break;
      }
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define MAXN 500005
typedef long long ll;
priority_queue<int> q1;
priority_queue< int,vector<int>,greater<int> > q;
ll f[MAXN],g[MAXN],sum1=0,sum=0;
ll a[MAXN];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=3*n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
		q.push(a[i]),sum+=a[i],q1.push(a[3*n-i+1]),sum1+=a[3*n-i+1];
	f[n]=sum,g[2*n+1]=sum1;
	for(int i=n+1;i<=2*n;i++){
		q.push(a[i]);
		ll x=q.top();
		q.pop();
		f[i]=sum=sum-x+a[i];
		//cout<<sum<<" ";
	}//cout<<endl;
	for(int i=2*n;i>=n+1;i--){
		q1.push(a[i]);
		ll x=q1.top();
		q1.pop();
		g[i]=sum1=sum1-x+a[i];
		//cout<<sum1<<" ";
	}//cout<<endl;
	ll ans=f[n]-g[n+1];
	for(int i=n;i<=2*n;i++)
		ans=max(ans,f[i]-g[i+1]);
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 9460
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, sum = 0, num = 0, e = 0, w = 0, ans = 300001; string s; cin >> n >> s;
	for (int h = 0; h < n; h++) {
		if (s[h] == 'E') {
			num++;
		}
	}
	for (int h = 0; h < n; h++) {
		if (s[h] == 'E') {
			e++;
		}
		ans = min(ans, w + (num - e));
		if (s[h] == 'W') {
			w++;
		} 
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 900
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  int n, max_w;
  cin >> n >> max_w;
  long long w[n], v[n];
  for(int i=0; i < n; i++) {
    cin >> w[i] >> v[i];
  }

  long long dp[n+1][max_w+1];
  for(int i=0; i <= n; i++) {
    for(int j=0; j <= max_w; j++) {
      dp[i][j] = 0;
    }
  }

  for(int i=0; i < n; i++) {
    for(int j=0; j <= max_w; j++) {
      if (j - w[i] >= 0) { 
        dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]] + v[i]);
      }
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    }
  }

  cout << dp[n][max_w] << endl;
  return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int n,a,x,sum=1,l=0;
	cin>>n>>x;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		l+=a;
		if(l<=x)sum++;
	}
	cout<<sum<<endl;
	return 0;
}

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

int main(){
  int n, k;
  int num;
  cin >> n >> k;
  if ((n-k)%(k-1)==0){
    num = (n-k)/(k-1) + 1;
  } else {
    num = (n-k)/(k-1) + 2;
  }
  printf("%d", num);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("%s = %d\n", #x, x)
#define debug2(x, y) printf("%s = %d, %s = %d\n", #x, x, #y, y)
#define debug3(x, y, z) printf("%s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z)
#define debug4(x, y, z, t) printf("%s = %d, %s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z, #t, t)
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

const int MAXN = 100005;

ll n, k, best = LINF, A[MAXN];
vector<ll> l, r;

int main() {
    scanf("%lld%lld", &n, &k);

    for (int i = 0; i < n; i++) {
        scanf("%lld", &A[i]);
    }

    for (int i = 0; i < n; i++) {
        if (A[i] < 0) {
            l.push_back(A[i]);
        } else {
            r.push_back(A[i]);
        }
    }

    if (sz(r) >= k) {
        best = r[k - 1];
    }

    reverse(l.begin(), l.end());

    if (sz(l) >= k) {
        best = min(best, -l[k - 1]);
    }

    for (int i = 1; i <= sz(l); i++) {
        if (i + sz(r) >= k && sz(r) > 0) {
            best = min(best, min((-2) * l[i - 1] + r[k - i - 1], -l[i - 1] + 2 * r[k - i - 1]));
        }
    }

    printf("%lld\n", best);

    return 0;
}

Measured memory_bytes: 2424
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        management solver = new management();
        solver.solve(1, in, out);
        out.close();
    }

    static class management {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int n = sc.nextInt();
            int[] freq = new int[n + 1];
            for (int i = 0; i < n - 1; i++)
                freq[sc.nextInt()]++;
            for (int i = 1; i <= n; i++)
                pw.println(freq[i]);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 54136
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int dp[20010][256];
const int INF=1e12;

signed main(){
   int n,m;
   	while(1){
	   	cin>>n>>m;
	   	if(n+m==0) break;
	   	vi c(m),x(n);
	   	rep(i,0,m) cin>>c[i];
	   	rep(i,0,n) cin>>x[i];
	   	rep(i,0,n+10){
	   		rep(j,0,256){
	   			dp[i][j]=INF;
	   		}
	    }
	    dp[0][128]=0;
	    rep(i,0,n){
	    	rep(j,0,256){
	    		if(dp[i][j]==INF) continue;
	    		rep(k,0,m){
	    			int tmp=j+c[k];
	    			tmp=max((int)0,tmp);
	    			tmp=min((int)255,tmp);
	    			int diff=pow(abs(tmp-x[i]),(int)2);
	    			dp[i+1][tmp]=min(dp[i+1][tmp],dp[i][j]+diff);
	    		}
	    	}
	    }
	    int MIN=INF;
	    rep(i,0,256){
	    	MIN=min(MIN,dp[n][i]);
	    }
	    cout<<MIN<<endl;
	}
}

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

using namespace std;

int calc(int p,int x){
  return p*(100+x)/100;
}

int main(){

  int bfr_zeikomi,x,y;
  int ans,x1,x2;
  while(true){
    cin >> x >> y >> bfr_zeikomi;
    if(x == 0 && y == 0 && bfr_zeikomi == 0)break;
    ans = 0;
    for(int i = 1;i<bfr_zeikomi;i++)
      for(int j = 1;j<bfr_zeikomi;j++){
	if(calc(i,x) + calc(j,x) == bfr_zeikomi){
	  x1 = calc(i,y);
	  x2 = calc(j,y);
	  ans = max(ans,x1+x2);
      }
    }
    cout << ans << endl;
  }

  return 0;
}

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define all(a) (a.begin(), a.end())

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////
	
void solve() {
	int N,X;
	int x[E5]={};
	cin >> N >> X;
	for (int i = 0; i < N; ++i) {
		cin >> x[i];
		x[i] = x[i]-X;
	}

	int g = 0;
	for (int i = 0; i < N; ++i) {
		g = __gcd(g,x[i]);
	}

	cout << abs(g) << '\n';

}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
int main() {
	int n, i, j, ans,p,k,flag,flag2;
	char s[55][55], cs[55][55];
	while (1) {
		cin >> n;
		if (n == 0)
			return 0;
		for (i = 0; i < n; i++)
			cin >> s[i];
		for (i = 0; i < n; i++) {
			cs[i][0] = s[i][0];
			p = 1;
			for (j = 0; s[i][j + 1] != '\0'; j++) {
				if (s[i][j] == 'a' || s[i][j] == 'i' || s[i][j] == 'u' || s[i][j] == 'e' || s[i][j] == 'o') {
					cs[i][p] = s[i][j + 1];
					p++;
				}
			}
			cs[i][p] = '\0';
		}
		ans = 1;
		flag = 0;
		for (i = 0; i < n; i++) {
			for (j = i + 1; j < n; j++) {
				flag2 = 0;
				for (k = 0; cs[i][k] != '\0'&&cs[j][k] != '\0'; k++) {
					if (cs[i][k] != cs[j][k]) {
						if (ans < k+1)
							ans = k+1;
						flag2++;
						break;
					}
				}
				if (cs[i][k] == '\0'&&cs[j][k] == '\0')
					flag = 1;
				if (flag2 == 0 && ans < k+1)
					ans = k+1;
			}
		}
		if (flag == 1)
			cout << "-1" << endl;
		else
			cout << ans << endl;
	}
}


Measured memory_bytes: 3092