akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>


using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vc=vector<char>;


struct q_t
{
	int x;
	bool operator<(const q_t& rhs) const
	{
		return x>rhs.x;
	}
};


priority_queue<q_t> que;


void push(q_t q)
{
	que.push(q);
}


int pop(q_t& q)
{
	if(que.empty()) return 0;
	q=que.top();
	que.pop();
	return 1;
}


template<typename T>
vector<vector<T> > vv_alloc(int w, int h, const T& f=T())
{
	vector<vector<T> > ret;

	ret.resize(h);
	for(auto& x : ret) x.resize(w, f);
	return ret;
}


vc input(void)
{
	vc ret;
	char buf[20+2];

	scanf("%s", buf);
	ret.resize(strlen(buf)+1);
	strcpy(&ret[0], buf);
	return ret;
}


int main(void)
{
	int n;
	vector<vc> s, sa, sz;
	vc t;
	int rank_a, rank_z;

	while(scanf("%d", &n)==1)
	{
		s.resize(n);
		for(int i=0;i<n;i++) s[i]=input();
		sa=s;
		sz=s;
		for(auto& se:sa)
			for(char& c:se)
				if(c=='?') c='a';

		for(auto& se:sz)
			for(char& c:se)
				if(c=='?') c='z';

		t=input();

		rank_a=1;
		for(auto& se:sa)
		{
			if(strcmp(&t[0], &se[0])>=0) rank_a++;
		}
		rank_z=1;
		for(auto& se:sz)
		{
			if(strcmp(&t[0], &se[0])>0) rank_z++;
		}

		for(int i=rank_z;i<rank_a;i++) printf("%d ", i);
		printf("%d\n", rank_a);
	}

	return 0;
}


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

int main() {
    int r,g,b,n;
    cin>>r>>g>>b;
    
    n=100*r+10*g+b;
    
    if(n%4==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  char n[5];
  scanf("%s", n);
  if (n[0] == n[1] && n[0] == n[2])
    printf("Yes\n");
  else if (n[1] == n[2] && n[1] == n[3])
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };


signed main() {
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<int> p(n);
  vector<int> f(n);
  REP(i, n) p[i] = 1;
  f[0] = 1;
  REP(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if(f[x] == 1) {
      p[x]--;
      p[y]++;
      f[y] = 1;
      if(p[x] == 0) {
        f[x] = 0;
      }
    }
    else {
      p[x]--;
      p[y]++;
    }
  }
  cout << accumulate(all(f), 0l) << endl;
  return 0;
}


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

using namespace std;

int r[1 << 20];

int get(int x) {
    return (r[x] < 0 ? x : r[x] = get(r[x]));
}

void join(int x, int y) {
    int rx = get(x), ry = get(y);
    if (rx == ry) return;
    r[rx] += r[ry];
    r[ry] = rx;
}

int main() {
    int n, m;
    memset(r, -1, sizeof(r));
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        join(x, y);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i)
        if (r[i] < 0) ans = max(ans, -r[i]);
    cout << ans << '\n';
    return 0;
}

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

int main(){
    string s; cin >> s;
    for(int i = 0; i < s.size(); ++i){
        if(s[i] != s[s.size() - i - 1]){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
int main() {
	int N,SL,TL;
	char S[26],T[101];
	scanf("%d",&N);
	scanf("%s",S);
	SL=strlen(S);
	int ans=0;
	for(int i=0;i<N;i++) {
		scanf("%s",T);
		TL=strlen(T);
		for(int j=0;j<TL;j++) {
			if(S[0]!=T[j]) continue;
			bool _OK=false;
			for(int k=j+1;k<TL;k++) {
				if(S[1]!=T[k]) continue;
				int span=k-j;
				bool OK=true;
				for(int l=2;l<SL;l++) {
					if((k+span*(l-1))>=TL) {OK=false;break;}
					if(S[l]!=T[k+span*(l-1)]) {OK=false;break;}
				}
				if(OK) {_OK=true;break;}
			}
			if(_OK) {ans++;break;}
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1028
#include<stdio.h>
int main(){
  int a,b,c,i,tmp;

  scanf("%d %d %d",&a,&b,&c);
  for(i=0;i<3;i++){
    if(a > b){
      tmp = a;
      a = b;
      b = tmp;
    }
    else if(b > c){
      tmp = b;
      b = c;
      c = tmp;
    }
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}



Measured memory_bytes: 2088
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	string S;
	cin >> S;
	if ((S[0] == S[1] && S[1] == S[2]) || (S[1] == S[2] && S[2] == S[3])) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1) << '\n';

    return 0;
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        int[] arr = new int[n];
        StringTokenizer st = new StringTokenizer(in.readLine());
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }
        int res = 0;
        for (int i = 1; i < n-1; i++) {
            if (arr[i] > arr[i-1] && arr[i] < arr[i+1]) {
                res++;
            } else if (arr[i] < arr[i-1] && arr[i] > arr[i+1]){
                res++;
            }
        }
        System.out.println(res);
    }

}
/*


 */

Measured memory_bytes: 24532
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
    ll x;
    cin >> x;

    for(ll i=-1e3; i<=1e3; i++){
        for(ll j=-1e3; j<=1e3; j++){
            if(i*i*i*i*i == j*j*j*j*j + x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

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

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    vec<string> grid(3);
    range(i, 0, 3) cin >> grid.at(i);
    cout << grid.at(0).at(0) << grid.at(1).at(1) << grid.at(2).at(2) << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) cerr << #OBJ << ": "; CERR(OBJ); cerr << "\n"
template <typename T, typename ...Ts> void CERR(const T &FIRST, const Ts &...REST) { CERR(FIRST); cerr << ", "; CERR(REST...); }
#define dbs(...) cerr << "(" << #__VA_ARGS__ << "): ("; CERR(__VA_ARGS__); cerr << ")\n"
#include <atcoder/all>
using namespace atcoder;

int N;

int op(int a, int b) {
	return max(a, b);
}

int e() {
	return -1;
}

void show(segtree<int, op, e> s) {
	cout << "[";
	rep(i, N) cout << s.get(i) << ", ";
	cout << "]\n";
}

int main() {
	// 1-indを0-indに直す
	int Q; cin >> N >> Q;
	vi A(N); rep(i, N) cin >> A[i];
	segtree<int, op, e> s(A);
	while (Q--) {
		int T; cin >> T;
		if (T == 1) {
			int X, V; cin >> X >> V;
			s.set(X - 1, V);

		} else if (T == 2) {
			int L, R; cin >> L >> R;
			cout << s.prod(L - 1, R) << endl;

		} else if (T == 3) {
			int X, V; cin >> X >> V;
			function<bool(int)> f = [&](int x) {
				return x < V;
			};
			cout << s.max_right<function<bool(int)>>(X - 1, f) + 1 << endl;
		}
		
		// show(s);
	}
}


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

using namespace std;

void CountTriangles(vector <int> A)
{
    int n=A.size();

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

    int c= 0;

    for( int i = n-1; i >= 1; i--)
        {
        int l = 0, r = i-1;
        while( l < r){
            if( A[l] + A[r] > A[i])
            {
                c+= r - l ;
                r--;
            }
            else
            {
                l++;
            }
        }
    }
    cout<<c<<endl;;
}


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

    vector <int> A;

    int n;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        A.push_back(x);
    }

    CountTriangles(A);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
pii dfs(vii &A,vector<bool> &F,int X){
  int ret=1,let=1;
  rep(i,0,A[X].size()){
    int Y=A[X][i];
    if(F[Y]){
      F[Y]=0;
      pii P=dfs(A,F,Y);
      ret*=P.first+P.second;
      let*=P.first;
      ret%=MOD;
      let%=MOD;
    }
  }
  return mp(ret,let);
}
signed main(){
  int N; cin>>N;
  vii A(N);
  rep(i,1,N){
    int X,Y; cin>>X>>Y;
    A[X-1].pb(Y-1);
    A[Y-1].pb(X-1);
  }
  vector<bool> F(N,1);
  F[0]=0;
  auto p=dfs(A,F,0);
  int ans=p.first+p.second;
  ans%=MOD;
  cout<<ans<<endl;
  }



Measured memory_bytes: 11264
import collections

N = int(input())
VV = list(map(int, input().split()))
v_even = VV[::2]
v_odd = VV[1::2]

e = collections.Counter(v_even).most_common() + [(0, 0)]
o = collections.Counter(v_odd).most_common() + [(0, 0)]

if (e[0][0] == o[0][0]):
    tmp1 = e[0][1] + o[1][1]
    tmp2 = e[1][1] + o[0][1]
    answer = N - max(tmp1, tmp2)
else:
    tmp = e[0][1] + o[0][1]
    answer = N - tmp

print(answer)

Measured memory_bytes: 21212
n = int(input())
s = list(input())
# EりーだーW
cnt = [0] * (n+1)
for i in range(1, n+1):
    cnt[i] += cnt[i-1]
    if s[i-1] == "E": cnt[i] += 1

ans = float("INF")
for i in range(1,n+1):
    a = ((i-1) - cnt[i-1]) + (cnt[-1] - cnt[i])
    if ans > a: ans = a
print(ans)

Measured memory_bytes: 17720
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define mii map<int,int>
#define io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main() {
	io
	int a,b;
  cin>>a>>b;
  if(b==1){
  	cout<<0;
    return 0;
  }
  int t=a;
  int ans=1;
  while(t<b){
  	t=t-1+a;
    ans++;
  }
  cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
                                print_function, unicode_literals)
import sys

n = int(input())
r = []
for i in range(n):
    r.append(int(input()))

c = sys.maxsize
ret = -sys.maxsize - 1
for j in range(n):
    ret = max([ret, r[j] - c])
    if(r[j] < c):
        c = r[j]

print(ret)

Measured memory_bytes: 15576
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
int dp[1010][1010];
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m;
    char ch;
    cin>>n>>m;
    dp[0][0] = 1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>ch;
            if((i==0&&j==0)||ch=='#') continue;
            if(i)
                dp[i][j]+=dp[i-1][j];
            if(j)
                dp[i][j]+=dp[i][j-1];
            dp[i][j]%=mod;
        }
    }
    cout<<dp[n-1][m-1];
    return 0;
}

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

int N,M;
int cost[300];
int status[3][300];

/* [syurui][rest budget] */
int memo[3][301];

int tansaku(int syurui,int rest) {
	int result,i;
	if(rest<=0)return 0;
	if(memo[syurui][rest]>0)return memo[syurui][rest]-1;
	result=0;
	for(i=0;i<N;i++) {
		if(cost[i]<=rest) {
			int nowresult;
			nowresult=status[syurui][i]+tansaku(syurui,rest-cost[i]);
			if(nowresult>result)result=nowresult;
		}
	}
	memo[syurui][rest]=result+1;
	return result;
}

int main(void) {
	char buffer[1000];
	while(fgets(buffer,sizeof(buffer),stdin)) {
		int i;
		int now,max;
		sscanf(buffer,"%d%d ",&N,&M);
		for(i=0;i<N;i++) {
			fgets(buffer,sizeof(buffer),stdin);
			fgets(buffer,sizeof(buffer),stdin);
			sscanf(buffer,"%d%d%d%d",&cost[i],
				&status[0][i],&status[1][i],&status[2][i]);
		}
		memset(memo,0,sizeof(memo));
		max=0;
		for(i=0;i<3;i++) {
			now=tansaku(i,M);
			if(now>max)max=now;
		}
		printf("%d\n",max);
	}
	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int h, n;
    cin >> h >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    vi dp(h+1, INF);
    dp[0] = 0;
    rep(i, n) rep(j, h+1) {
        if (dp[j] == INF) continue;
        dp[min(h,j+a[i])] = min(dp[min(h,j+a[i])], dp[j]+b[i]);
        dp[j] = min(dp[j], dp[j]);
    }
    cout << dp[h] << endl;
    return 0;
}


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

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

  int a, b;
  string s;
  cin >> a >> b;

  if (a > b)
  {
    for (int i = 0; i < a; i++) s += to_string(b);
    cout << s << endl;
  }
  else
  {
    for (int i = 0; i < b; i++) s += to_string(a);
    cout << s << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

const ll mod=998244353 ;
const ll MAXN=1e6+5;
const ll inf=1e17;

int main()
{
    fastio;
    int k;
    cin >> k;
    int ans = 0;
    for(int i = 1; i <= k; i++){
        for(int j = 1; j <= k; j++){
            for(int p = 1; p <= k; p++){
                int c = __gcd(i, j);
                c = __gcd(c, p);
                ans += c;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3648
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let (a, b, c): (usize, usize, usize);
    input!(a, b, c);
    if a + b + c >= 22 {
        p("bust");
    } else {
        p("win");
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 998244353;
const ll INF = 1LL << 62;

int main() {
  //
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  vl x(n);
  rep(i, n) cin >> x[i];
  rep(i, n - 1) { ans += min(a * (x[i + 1] - x[i]), b); }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int gcd(int a, int b){
	if(a%b == 0) return b;
	return gcd(b,a%b);
}

int main(){
	int a, b;
	scanf("%d %d",&a,&b);
	getchar();
	printf("%d\n",gcd(a,b));
	
	return 0;
}


Measured memory_bytes: 2112
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 100005
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

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

/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	if ((C - A) * (C - B) <= 0) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
using testimony = pair<set<int>, set<int>>;

int main() {
    string X;
    cin >> X;
    int skipped = 0;
    int num_s = 0;
    for(auto c: X) {
        if(c == 'T') {
            if(num_s > 0) {
                num_s--;
            } else {
                skipped++;
            }
        }
        if(c =='S') {
            num_s++;
        }
    }
    cout << skipped + num_s << endl;

    return 0;
}



Measured memory_bytes: 3416
from collections import defaultdict
s = input()
n = len(s)

d = defaultdict(int)
d[0] = 1
x = 0
b = 1
for i in range(n-1,-1,-1):
    x += b*int(s[i])
    x %= 2019
    d[x] += 1

    b *= 10
    b %= 2019

res = 0
for k in d:
    c = d[k]
    res += c*(c-1)//2
print(res)


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

using namespace std;

#define pb push_back

typedef long long ll;
typedef vector<ll> vll;

int n,sz[4];
ll max_w,w[111],v[111];
vll table[4];

int main()
{
	scanf("%d %lld",&n,&max_w);
	scanf("%lld %lld",&w[0],&v[0]);
	table[0].pb(v[0]);
	for(int i=1;i<n;i++) {
		scanf("%lld %lld",&w[i],&v[i]);
		if(w[i]==w[0]) table[0].pb(v[i]);
		if(w[i]==w[0]+1) table[1].pb(v[i]);
		if(w[i]==w[0]+2) table[2].pb(v[i]);
		if(w[i]==w[0]+3) table[3].pb(v[i]);
	}
	//urut dari besar ke kecil
	for(int i=0;i<4;i++) {
		sz[i] = table[i].size();
		sort(table[i].begin(),table[i].end());
		table[i].pb(0);
		reverse(table[i].begin(),table[i].end());
		for(int j=1;j<=sz[i];j++) table[i][j]+=table[i][j-1];
	}
	//find max value
	ll ans = 0;
	for(int i=0;i<=sz[0];i++) {
		for(int j=0;j<=sz[1];j++) {
			for(int k=0;k<=sz[2];k++) {
				for(int l=0;l<=sz[3];l++) {
					ll temp = (i*w[0]) + (j*(w[0]+1)) + (k*(w[0]+2)) + (l*(w[0]+3));
					if(temp<=max_w) ans = max(ans,table[0][i]+table[1][j]+table[2][k]+table[3][l]);
				}
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	int n, m, k;
	cin >> n >> m >> k;
	int i, j;
	bool flag = false;
	for (i = 0; i <= m; i++) { // i個おす
		for (j = 0; j <= n; j++) { // j個おす
			int tmp = 0;
			tmp += (i * n);
			tmp += (j * m);
			tmp -= 2 * (i * j);
			 // cout << tmp << endl;
			if (tmp == k) flag++;
		}
	}
	if (flag) cout << "Yes";
	else cout << "No";
	return 0;
}

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

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var K = cin.ReadInt;
            var l = cin.ReadIntArray(N);
            Array.Sort(l);
            Array.Reverse(l);
            var ans = l.Take(K).Sum();
            WriteLine(ans);
        }

        /*public long C(long n, long r)
        {
            if (r == 0 || r == n) return 1L;
            if (n < r) return 0L;
            long[,] Pascal = new long[n + 1, n + 1];
            Pascal[0, 0] = 1;
            for (long i = 1; i <= n; i++)
            {
                Pascal[i, 0] = 1;
                Pascal[i, i] = 1;
                for (long j = 1; j < n; j++)
                {
                    Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
                }
            }
            return Pascal[n, r];
        }*/

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 13780
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define deb(x) cout << #x << "=" << x << endl
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
int M=1e9+7,N=205001;

int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M



void solve() {
	int n,m,i,k,s=0,y;
	cin>>n;
	int a[n],b[n-1],x=0;
	rep(i,0,n) cin>>a[i];
	rep(i,1,n) b[i-1]=a[0]^a[i];
	rep(i,0,n-1) x=x^b[i];
	int f=x^a[0];
	cout<<f<<" ";
	rep(i,0,n-1) cout<<(f^b[i])<<" ";
	

	
}


signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}





Measured memory_bytes: 6736
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			int h = scanner.nextInt();
			int k = scanner.nextInt();
			if ((n | m | h | k) == 0)
				break;
			int[] ten = new int[n];
			for (int i = 0; i < n; i++)
				ten[i] = scanner.nextInt();
			Point[] p = new Point[m];
			for (int i = 0; i < m; i++) {
				int pos = scanner.nextInt() - 1;
				int y = scanner.nextInt();
				p[i] = new Point(y, pos);
			}
			Arrays.sort(p);
			for (int i = m - 1; i >= 0; i--) {
				int pos = p[i].pos;
				swap(ten, pos, pos + 1);
			}
			int sum = 0;
			for (int i = 0; i < k; i++)
				sum += ten[i];
			int[] c = new int[n];
			for (int i = 0; i < n; i++)
				c[i] = i;
			int ans = sum;
			for (int i = 0; i < m; i++) {
				int pos = p[i].pos;
				int a = c[pos];
				int b = c[pos + 1];
				swap(c, pos, pos + 1);
				if (a > b)
					swap(a, b);
				if (a < k && k <= b)
					ans = Math.min(ans, sum - ten[a] + ten[b]);
			}
			System.out.println(ans);
		}
	}

	private void swap(int a, int b) {
		int tmp = a;
		a = b;
		b = tmp;

	}

	private void swap(int[] ten, int pos, int i) {
		int tmp = ten[pos];
		ten[pos] = ten[i];
		ten[i] = tmp;
	}

	class Point implements Comparable<Point> {

		int y, pos;

		@Override
		public String toString() {
			return "Point [y=" + y + ", pos=" + pos + "]";
		}

		public Point(int y, int pos) {
			super();
			this.y = y;
			this.pos = pos;
		}

		@Override
		public int compareTo(Point o) {
			return y - o.y;
		}
	}
}

Measured memory_bytes: 83600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n;
	vector<string> s(n);
	rep(i, n) cin >> s[i];
	cin >> m;
	vector<string> t(m);
	rep(i, m) cin >> t[i];

	map<string, int> ans;

	rep(i, n) {
		ans[s[i]]++;
	}
	rep(i, m) {
		ans[t[i]]--;
	}

	int res = 0;
	for (auto& c : ans) {
		res = max(res, c.second);
	}

	dunk(res);

	return 0;
}

Measured memory_bytes: 256
//C++
//#pragma comment(linker, "/STACK:102400000,102400000")
//G++
//#define OPENSTACK
#define ONLINE_JUDGE
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cctype>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MOD = 998244353;
const int N = 1e6 + 10, M = N;//刻意开大会消耗时间.


int main()
{
    #ifdef OPENSTACK
    int size = 64 << 20; // 64MB
    char *p = (char*)malloc(size) + size;
    #if (defined _WIN64) or (defined __unix)
        __asm__("movq %0, %%rsp\n" :: "r"(p));
    #else
        __asm__("movl %0, %%esp\n" :: "r"(p));
    #endif
    #endif
    #ifndef ONLINE_JUDGE
        freopen("../put/a.input","r",stdin);
        freopen("../put/a.output","w",stdout);
    #endif
    clock_t c1 = clock();
    //coding here......

    int n, a;
    cin >> n;
    LL res = 0, num = 0;
    for(int i = 1; i <= n; i ++){
        cin >> a;
        if(a < num) res += abs(num - a);
        else num = (LL)a;
    }    
    cout << res << endl;

    //finish here......
    #ifndef ONLINE_JUDGE
        std::cerr << "Time:" << clock() - c1 << "ms" << std::endl;
    #endif
    #ifdef OPENSTACK
        exit(0);
    #else
        return 0;
    #endif
}

Measured memory_bytes: 3604
S = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
v = list(map(int, S.split(', ')))
print(v[int(input())-1])

Measured memory_bytes: 2940
k = int(input())
a, b = map(int, input().split())

tmp1 = a // k
tmp2 = b // k
amari1 = a % k
amari2 = b % k

if amari1 == 0 or amari2 == 0:
    print('OK')
elif tmp1 != tmp2:
    print('OK')
else:
    print('NG')


Measured memory_bytes: 9172
from collections import deque
n = int(input())
g = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

parent = [-1 for i in range(n)]
dist = [-1 for i in range(n)]
flag = [0 for i in range(n)]

def dfs(s):
    flag[s] = 1
    dist[s] = 0
    d = 0
    q = deque([(s, d)])

    while len(q) > 0:
        v = q.popleft()
        for i in g[v[0]]:
            if flag[i]:
                continue
            flag[i] = 1
            parent[i] = v[0]
            dist[i] = v[1] + 1
            q.append((i, v[1] + 1))

parent2 = [-1 for i in range(n)]
dist2 = [-1 for i in range(n)]
flag2 = [0 for i in range(n)]

def dfs_f(s):
    count2 = 0
    flag2[s] = 1
    dist2[s] = 0
    d = 0
    q = deque([(s, d)])

    while len(q) > 0:
        v = q.popleft()
        for i in g[v[0]]:
            if flag2[i]:
                continue
            count2 += 1
            flag2[i] = 1
            parent2[i] = v
            dist2[i] = v[1] + 1
            q.append((i, v[1] + 1))
    return count2

parent3 = [-1 for i in range(n)]
dist3 = [-1 for i in range(n)]
flag3 = [0 for i in range(n)]

def dfs_s(s):
    count3 = 0
    flag3[s] = 1
    dist3[s] = 0
    d = 0
    q = deque([(s, d)])

    while len(q) > 0:
        v = q.popleft()
        for i in g[v[0]]:
            if flag3[i]:
                continue
            count3 += 1
            flag3[i] = 1
            parent3[i] = v[0]
            dist3[i] = v[1] + 1
            q.append((i, v[1] + 1))
    return count3

dfs(0)
D = dist[n-1]

j = n-1
flag2[n-1] = 1
flag3[0] = 1
for i in range(D):
    if (D - i) >= (D+2)//2:
        flag2[j] = 1
        j = parent[j]
    else:
        flag3[j] = 1
        j = parent[j]

df = dfs_f(0)
ds = dfs_s(n-1)

if df > ds:
    print("Fennec")
else:
    print("Snuke")


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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p.at(i);
    }
    
    int count = 0;
    for (int i = 1; i < n - 1; i++) {
        if (p.at(i) > p.at(i - 1) && p.at(i) < p.at(i + 1)) {
            count++;
        } else if (p.at(i) < p.at(i - 1) && p.at(i) > p.at(i + 1)) {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 300010;
const double eps = 1e-6;

int n;
char a[N];
int w[N], e[N];

int main()
{
    scanf("%d", &n);
    scanf("%s", a + 1);
    for(int i = 1, W = 0; i <= n; i++)
    {
        w[i] = W;
        if(a[i] == 'W') W++;
    }
    for(int i = n, E = 0; i >= 1; i--)
    {
        e[i] = E;
        if(a[i] == 'E') E++;
    }

    int res = 0x3f3f3f3f;
    for(int i = 1; i <= n; i++) res = min(res, w[i] + e[i]);
    cout << res << endl;
    return 0;
}


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



int main(){
  int n;
  cin >> n;
  if (n == 0){ 
    cout << 2 << endl;
  } else if (n == 1){
    cout << 1 << endl;
  } else{ 
    vector<int64_t> l(n+1);
    l.at(0) = 2;
    l.at(1) = 1;
    for (int i = 2; i <= n; i++){
      l.at(i) = l.at(i-1) + l.at(i-2);
    }
    cout << l.at(n) << endl;
  }
}

Measured memory_bytes: 256
from math import floor,ceil,sqrt
import fractions
from collections import deque
import itertools
from collections import deque
import collections
import heapq
N=int(input())
A=list(map(int,input().split()))
A.sort()
nums={}
for i in range(N):
    if nums.get(A[i])==None:
        nums[A[i]]=1
    else:
        nums[A[i]]=nums[A[i]]+1
#print(nums)
for i in range(len(A)):
    if nums[A[i]]!=0:
        for j in range(A[i]*2,10**6+1,A[i]):
            if nums.get(j)!=None:
                nums[j]=0
    if nums[A[i]]!=1:
        nums[A[i]]=0
ans=0
for i in range(len(A)):
    if nums[A[i]]==1:
        ans=ans+1
print(ans)



Measured memory_bytes: 116872
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(11);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n, m;
  cin >> n >> m;
  int p;
  cin >> p;

  vector<vector<pil> > G(n), G2(n);
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].eb(b, p - c);
    G2[b].eb(a, 1);
  }

  vector<int> c(n);
  auto dfs = [&](auto&& dfs, int v, int be) -> void {
    c[v] = 1; // debuged, for の外
    for (pil p : G2[v]) {
      if (c[p.F]) continue; // debuged, p.F==be to c[p.F]
      dfs(dfs, p.F, v);
    }
  };
  dfs(dfs, n - 1, -1);
  // cerr << c << endl;

  vector<ll> d(n, INF);
  auto bell = [&](int s) { // O(NM)
    d[s] = 0;
    int cnt = 0;
    while (1) {
      int update = 0;
      rep(v, n) { // O(M)
        if (d[v] == INF || c[v] == 0) continue;
        for (pil p : G[v]) if (c[p.F] == 1 && chmin(d[p.F], d[v] + p.S)) update = 1;
      }
      if (update == 0) break;
      if (cnt++ == 2 * n) return 1; // 負閉路検出
    }
    return 0;
  };
  if (bell(0)) cout << -1 << endl;
  else cout << max(0LL, -d[n - 1]) << endl; // debuged, forget else
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;


int main()
{
	fast;
	cin>>n>>m;
	// cout<<(n+m-1)/m
	fs(ar,m);
	fo(i,1,m)
	n-=ar[i];
	if(n<=0)
		cout<<"Yes";
	else
		cout<<"No";
}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;



int main(){
    double l,len,ht,vol;
    cin>>l;
    len = l/3;
    ht = l - (2*len);
    vol = len*len*ht;
    cout<<fixed<<setprecision(6)<<vol;
    return 0;

}


Measured memory_bytes: 3732
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    kuri :
    while ( cin >> a >> b){
        if(cin.eof()){break;}
        c = a+b;
        if (c/1000000>=1){
            cout << "7" << endl; goto kuri;
        }
        if (c/100000>=1){
            cout << "6" << endl; goto kuri;
        }
        if (c/10000>=1){
            cout << "5" << endl; goto kuri;
        }
        if (c/1000>=1){
            cout << "4" << endl; goto kuri;
        }
        if (c/100>=1){
            cout << "3" << endl; goto kuri;
        }
        if (c/10>=1){
            cout << "2" << endl; goto kuri;
        }
        else{
            cout << "1" << endl; goto kuri;
        }


    }
}

Measured memory_bytes: 1156
#include <stdio.h>
int main(void)
{
	double height=0, high=0, low=0;
	while(scanf("%lf", &height)!=EOF)
	{
		if(high < height)
			high = height;
		if(low==0 || low > height)
			low = height;
	}
	printf("%f\n", high-low);
	return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


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

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

	vector<ll> a(N + 1);
	repn(i, N) cin >> a[i];

	ll ans = INF;

	for (ll t = -100; t <= 100; t++) {
		ll v = 0;
		repn(i, N) v += (a[i] - t)*(a[i] - t);

		ans = min(ans, v);
	}

	cout << ans;


	system("PAUSE");
}

Measured memory_bytes: 504