akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

typedef vector<vector<int> > Matrix;

Matrix dist; // グラフの距離を格納した2次元配列（隣接行列）
             // dist[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はinf、ただしdist[i][i]=0）

bool dfs(vector<vector<char> >& S, vector<int>& check, int N, int tmp, int par) {
  if(par != -1) {
    if(check[tmp] == -1) check[tmp] = 1 - check[par];
    else if(check[tmp] != 1 - check[par]) return false;
    else return true;
  }
  rep(i, N)
    if(S[tmp][i] == '1')
      if(!dfs(S, check, N, i, tmp))
        return false;
  return true;
}

void warshall_floyd(int n) { // nは頂点数
  rep(i, n)      // 経由する頂点
    rep(j, n)    // 開始頂点
      rep(k, n)  // 終端
        dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
}

int main() {
  int N;
  cin >> N;
  dist = Matrix(N, vector<int>(N, inf));
  vector<vector<char> > S(N, vector<char>(N));
  rep(i, N) {
    dist[i][i] = 0;
    rep(j, N) {
      cin >> S[i][j];
      if(S[i][j] == '1')
        dist[i][j] = 1;
    }
  }
  vector<int> check(N, -1);
  check[0] = 0;
  bool ret = dfs(S, check, N, 0, -1);
  if(!ret) {
    cout << -1 << endl;
    return 0;
  }
  warshall_floyd(N);
  int M = 0;
  rep(i, N) rep(j, N) M = max(M, dist[i][j]);
  cout << M + 1 << endl;
  return 0;
}



Measured memory_bytes: 512
import sys

def solve():
    n, a, b = map(int, input().split())

    if a > b:
        print(0)
        return

    if n == 1 and a != b:
        print(0)
        return

    ans = a + (n - 1) * b - ((n - 1) * a + b) + 1

    print(ans)
    pass

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define forn(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define ford(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define int long long
#define ii pair<int,int>
#define ar array
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define sz(x) ((int)(x).size())
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;

void solve(){
	string s , t ;
	cin >> s >> t ;
	int n = sz(s) ;
	int m = sz(t);
	int ans = INF ; 
	for(int i = 0 ; i <= n-m ; i++){
		int cur = 0 ;
		int idx = 0 ;
		for(int j = i ; j < i+m ; j++){
			cur += (s[j] != t[idx++]) ;
		}
		ans = min(ans,cur) ;
	}
	cout << ans << endl ;
}


int32_t main(){
    FAST_IO ;
    int t = 1 ;
//    cin >> t ;
    while(t--){
        solve() ;
    }
}


Measured memory_bytes: 3584
package main

import (
	"fmt"
	"math"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)

	num := len(strconv.Itoa(n))

	result := 0
	if num == 1 {
		result = n
	} else {
		for i := 0; i < num / 2; i++ {
			result += 9 * pow(100, i)
		}

		if num % 2 != 0 {
			result += (n - pow(100, num / 2)) + 1
		}
	}

	fmt.Println(result)
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}


Measured memory_bytes: 512
n,k,q = map(int,input().split())

p = [k]*n
a = [0]*q

for i in range(0,q):
  a[i] = int(input())

for i in range(0,n):
  p[i] = p[i] - q
for i in range(0,q):
  p[a[i]-1] += 1

#print(p)

for i in range(0,n):
  if(p[i] <= 0):
    print("No")
  else:
    print("Yes")


Measured memory_bytes: 51544
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
#define pi 3.141592653589793283462
int main(){
    int x[2];
    while(1){
    cin>>x[0]>>x[1];
    if(x[0]==0 && x[1]==0)
        break;
    sort(x,x+2);
    cout<<x[0]<<" "<<x[1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <fstream>

using namespace std;

//#define REDFILE
#ifdef REDFILE
ifstream ifs("input.txt");
ofstream ofs("output.txt");
#define cin ifs
#define cout ofs
#endif

int n,m,k;
double dp[2][10001];
int main(){
    //FILE *fp=fopen("output.txt","w");
    FILE *fp=stdout;
    while(cin>>n>>m>>k&&!(n==0&&m==0&&k==0)){
        for(int i = 0; i < 10001; i++)dp[0][i]=dp[1][i]=0;
        dp[0][0]=1.0;
        for(int i = 0; i < n; i++){
            int nxt=(i+1)%2;
            int cnt=i%2;
            for(int i = 0; i < 10001; i++)dp[nxt][i]=0;
            for(int j = 1; j < 10001; j++){
                for(int k = 1; k <= m; k++){
                    if(j-k>=0)
                        dp[nxt][j]+=dp[cnt][j-k]*(1.0/m);
                    else break;
                }
            }
        }
        double res=0;
        for(int i = 0; i <= 10000; i++){
            int a=max(1,i-k);
            res+=a*(dp[n%2][i]);
        }
        //cout<<res<<endl;
        fprintf(fp,"%.8f\n",res);
    }

    return 0;
}

Measured memory_bytes: 1064
from heapq import heappop, heappush
n, h = map(int, input().split())
T = []
for i in range(n):
    a, b = map(int, input().split())
    T.append((a, -b))

max_a, minus_min_b_of_max_a = max(T)
min_b_of_max_a = -minus_min_b_of_max_a
T.remove((max_a, minus_min_b_of_max_a))

H = []
for i in range(n-1):
    a, minus_b = T[i]
    heappush(H, (minus_b, a))

cnt = 0
while h > 0 and H:
    if min_b_of_max_a >= h:
        h -= min_b_of_max_a
        cnt += 1
        break

    minus_b, a = heappop(H)
    b = -minus_b

    if b <= max_a:
        break
    else:
        h -= b
        cnt += 1


if h > 0:
    h -= min_b_of_max_a
    cnt += 1
    if h > 0:
        cnt += (h + max_a-1)//max_a

print(cnt)

    

    

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

using namespace std;
const int INF = 1e9 + 5;

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


	vector<int> dp(3, 0);
	

	for(int day = 0; day < n; day++)
	{
		vector<int> c(3), new_dp(3, 0);

		for(int i = 0; i < 3; i++)
		{
			cin >> c[i];
		}

		for(int i = 0;i < 3; i++)
		{
			for(int j = 0;j < 3; j++)
			{
				if(i != j)
				{
					new_dp[j] = max(new_dp[j], dp[i] + c[j]);
				}
				
			}
		}

		dp = new_dp;
	}

	cout << max({dp[0], dp[1], dp[2]}) << "\n";

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n,a[20],tot,mis;
int main(){
	scanf("%d",&n);
	int xb;
	tot=1;
	mis=1;
	for(xb=0;xb<n;++xb){
		scanf("%d",a+xb);
		tot*=3;
		if(~a[xb]&1){
			mis*=2;
		}
	}
	printf("%d",tot-mis);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int gcd(int a, int b){
	int c;
	if(a<b){
		a+=b;
		b=a-b;
		a-=b;
	}
	while(b!=0){
		c=a%b;
		a=b;
		b=c;
	}
	return a;
}

int main(){

	int n, k, a[100000], y=0;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> a[i];
		if(a[i]==k){
			cout << "POSSIBLE" << endl;
			return 0;
		}
		y=max(y, a[i]);
	}
	int x=a[0];
	for(int i=1; i<n; i++){
		x=gcd(x, a[i]);
	}
	if(k%x==0 && k<y){
		cout << "POSSIBLE" << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}


Measured memory_bytes: 640
A, B, C = map(int, input().split())
M = max(A, B, C)

M3 = 3 * M

if sum([A, B, C]) % 2 == M3 % 2:
    flg = True
    moku = M
else:
    flg = False
    moku = M+1

mokusum = moku * 3
print((mokusum - sum([A, B, C])) // 2)

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

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;

int main(){
  IO; string N; cin >> N; vi V(1);
  FORE(i,N) V.PB(i-48);
  int o = 0;
  FORD(i, V.size(), 1){
    if(V[i] > 5 || V[i] == 5 && V[i-1] > 4) o += 10-V[i], V[i-1] ++;
    else o += V[i];
  }
  cout << o+V[0] << endl;
}


Measured memory_bytes: 8344
import heapq
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
day = {i+1:[] for i in range(M)}
for a, b in ab:
  if a <= M:
    day[a] += [-b]

q = []
ans = 0
for i in range(M):
  for b in day[i+1]:
    heapq.heappush(q, b)
  if len(q) > 0:
    ans += -1 * heapq.heappop(q)
print(ans)

Measured memory_bytes: 86996
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int h, w;
vector<string> s;

int main(){
    cin >> h >> w;
    s = vector<string>(h);
    for(int i = 0; i < h; i++){
        cin >> s[i];
    }
    vector<vector<ll>> v(h + 2, vector<ll>(w + 2)), ho(h + 2, vector<ll>(w + 2));
    for(int x = 1; x <= w; x++){
        for(int y = 1; y <= h; y++){
            if(s[y - 1][x - 1] != '#'){
                v[y][x] = v[y - 1][x] + 1;
            }
        }
    }
    for(int x = 1; x <= w; x++){
        for(int y = h; y >= 1; y--){
            if(s[y - 1][x - 1] != '#'){
                v[y][x] = max(v[y][x], v[y + 1][x]);
            }
        }
    }
    for(int y = 1; y <= h; y++){
        for(int x = 1; x <= w; x++){
            if(s[y - 1][x - 1] != '#'){
                ho[y][x] = ho[y][x - 1] + 1;
            }
        }
    }
    for(int y = 1; y <= h; y++){
        for(int x = w; x >= 1; x--){
            if(s[y - 1][x - 1] != '#'){
                ho[y][x] = max(ho[y][x], ho[y][x + 1]);
            }
        }
    }
    ll ans = 0;
    for(int y = 1; y <= h; y++){
        for(int x = 1; x <= w; x++){
            ans = max(ans, v[y][x] + ho[y][x] - 1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 67200
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;

ll n, k, a[100000];

int main() {
  while (1) {
    scanf("%lld%lld", &n, &k);
    if (n == 0) break;
    for (ll i = 0; i < n; i++) scanf("%lld", &a[i]);
    ll sum = 0;
    for (ll i = 0; i < k; i++) sum += a[i];
    ll ans = sum;
    for (ll i = k; i < n; i++) {
      sum += a[i];
      sum -= a[i - k];
      ans = max(ans, sum);
    }
    printf("%lld\n", ans);
  }
}



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

int main(){
    int N;cin>>N;
    vector<pair<int,int>> a(N);
    for(int i=0;i<N;i++){
        cin>>a.at(i).first;
        a.at(i).second=i+1;
    }
    sort(a.begin(),a.end());
    for(int i=0;i<N;i++){
        if(i)cout<<" ";
        cout<<a.at(i).second;
    }
    return 0;
}

Measured memory_bytes: 1536
#include <algorithm> 
#include <cmath> 
#include <iostream>
using namespace std;
int main(){
	string s;
	cin >> s;
	int len= s.size();
	int ans = 1000;
	for(int i = 0; i <= len - 3; i++){
		int num = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + s[i+2] - '0';
		ans = min(ans, abs(num - 753));
	}
	cout << ans << endl;
	return 0;
	}


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

int partition(vector<int>& A, int p, int r) {
	int i,j,x=A[r];
	i=p-1;
	for(j=p; j<r; ++j) {
		if(A[j]<=x) {
			++i;
			swap(A[i],A[j]);
		}
	}
	swap(A[i+1],A[r]);
	return i+1;
}

int main() {
	int n;
	int i;
	int q;
	vector<int> A;
	scanf("%d",&n);
	A.resize(n);
	for(i=0; i<n; ++i) {
		scanf("%d",&A[i]);
	}
	q=partition(A,0,n-1);
	for(i=0; i<q; ++i) {
		printf("%d ",A[i]);
	}
	if(q==n-1) {
		printf("[%d]\n",A[q]);
	} else {
		printf("[%d] ",A[q]);
		for(i=q+1; i<n-1; ++i){
			printf("%d ",A[i]);
		}
		printf("%d\n",A[n-1]);
	}
	return 0;
}

Measured memory_bytes: 2720
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

// #define DEBUG 100

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int oo = 1e9 + 7;
const ll mod = 1e9 + 7,maxn = 100010;
const double PI = acos(-1);

bool solve (int d, int t, int s){
	return s*t >= d;
}

int main(){
	ios_base::sync_with_stdio(false);
	int d, t, s;
	cin >> d >> t >> s;

	if (solve(d, t, s)){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}	



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

int main(void){
    int n, a[4][102] = {}, ans = 0;
    cin >> n;
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= n; j++) {
            int in;
            cin >> in;
            a[i][j] += a[i][j - 1] + in;
        }
    }
    for (int i = 1; i <= n; i++) {
        int zohe;
        zohe = a[1][i] + a[2][n] - a[2][i - 1];
        ans = max(ans, zohe);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 200005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n; ll ar[N][2];
ll st[4*N];
ll query(ll node,ll nl,ll nr,ll ql,ll qr){
	if(nl>qr||ql>nr){
		return 0;
	}
	if(nl>=ql&&qr>=nr){
		return st[node];
	}
	ll a,b;
	a=query(2*node,nl,(nl+nr)/2,ql,qr);
	b=query(2*node+1,(nl+nr)/2+1,nr,ql,qr);
	return max(a,b);
}
void update(ll node,ll nl,ll nr,ll idx,ll val){
	if(nl>idx||idx>nr){
		return ;
	}
	if(idx<=nl&&idx>=nr){
		st[node]=st[node]+val;
		return ;
	}
	update(2*node,nl,(nl+nr)/2,idx,val);
	update(2*node+1,(nl+nr)/2+1,nr,idx,val);
	st[node]=max(st[2*node],st[2*node+1]);
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i][0];
	}
	for(i=1;i<=n;i++){
		cin>>ar[i][1];
	}

	ll dp[n+1]={0};
	dp[1]=ar[1][1];
	update(1,1,N,ar[1][0],ar[1][1]);
	for(i=2;i<=n;i++){
		ll best=query(1,1,N,0,ar[i][0]-1);
	//	cout<<i<<" "<<best<<endl;
		dp[i]=ar[i][1]+best;
		update(1,1,N,ar[i][0],dp[i]);
	}


	ll ans=0;
	for(i=1;i<=n;i++){
		ans=max(ans,dp[i]);
	}
	cout<<ans;
	return 0;
}

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

int main() {
    ll n, max_num, ans;
    ans = 0;
    cin >> n;
    vector<ll> list(n);
    rep(i,n) cin >> list[i];
    rep(i,n) {
        if (i==0) {
            max_num = list[i];
            continue;
        } else {
            if (max_num > list[i]) {
                ans += (max_num - list[i]);
            } else {
                max_num = list[i];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

struct SegmentTree{
private:
    int n;
    vector<pair<int,int>> node;
public:
    SegmentTree(const vector<int> &v){
        int sz=(int)v.size();
        n=1;
        while(n<sz)n*=2;
        node.resize(2*n-1);
        for(int i=0;i<n;i++){
            if(i<sz)node[i+n-1]={v[i],i};
            else node[i+n-1]={INF,INF};
        }
        for(int i=n-2;i>=0;i--){
            node[i]=min(node[2*i+1],node[2*i+2]);
        }
    }
    pair<int,int> get(int a,int b,int k=0,int l=0,int r=-1){
        if(r==-1)r=n;
        if(b<=l||r<=a)return {INF,INF};
        if(a<=l&&r<=b){
            return node[k];
        }
        else{
            return min(get(a,b,2*k+1,l,(l+r)/2),get(a,b,2*k+2,(l+r)/2,r));
        }
    }
};

int main(){
    int n;
    cin>>n;
    vector<int> ev(n/2);
    vector<int> od(n/2);
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(i%2==0)ev[i/2]=a;
        else od[i/2]=a;
    }
    SegmentTree segev(ev);
    SegmentTree segod(od);
    using pp=pair<pair<int,int>,pair<int,int>>;
    priority_queue<pp,vector<pp>,greater<pp>> pq;
    pq.push({segev.get(0,n/2),{0,n}});
    while(pq.size()){
        int a=pq.top().first.first;
        int i=pq.top().first.second;
        int l=pq.top().second.first;
        int r=pq.top().second.second;
        pq.pop();
        if(l%2==0){
            auto tmp=segod.get(i,r/2);
            int b=tmp.first;
            int j=tmp.second;
            cout<<a<<" "<<b<<" ";
            if(l!=2*i)pq.push({segev.get(l/2,i),{l,2*i}});
            if(2*i+1!=2*j+1)pq.push({segod.get(i,j),{2*i+1,2*j+1}});
            if(2*j+2!=r)pq.push({segev.get(j+1,r/2),{2*j+2,r}});
        }
        else{
            auto tmp=segev.get(i+1,r/2+1);
            int b=tmp.first;
            int j=tmp.second;
            cout<<a<<" "<<b<<" ";
            if(l!=2*i+1)pq.push({segod.get(l/2,i),{l,2*i+1}});
            if(2*i+2!=2*j)pq.push({segev.get(i+1,j),{2*i+2,2*j}});
            if(2*j+1!=r)pq.push({segod.get(j,r/2),{2*j+1,r}});
        }
    }
    cout<<endl;
}

Measured memory_bytes: 7156
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

/*
int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
}

bool dfs(int v) {
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        int u = G[v][i];
        int w = match[u];
        if (w < 0 || (!used[w] && dfs(w))) {
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching() {
    int ans = 0;
    fill(match, match + MAX_V, -1);
    for (int v = 0; v < V; v++) {
        if (match[v] < 0) {
            fill(used, used + MAX_V, 0);
            if (dfs(v)) {
                ans++;
            }
        }
    }
    return ans;
}
*/

int n;
vector<int> G[200];
int match[200];
bool used[200];

void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
}

bool dfs(int v) {
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        int u = G[v][i];
        int w = match[u];
        if (w < 0 || (!used[w] && dfs(w))) {
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching() {
    int ans = 0;
    fill(match, match + 200, -1);
    for (int v = 0; v < 2 * n; v++) {
        if (match[v] < 0) {
            fill(used, used + 200, 0);
            if (dfs(v)) {
                ans++;
            }
        }
    }
    return ans;
}

int main() {
    cin >> n;
    int a[100], b[100], c[100], d[100];
    imfor(i, n) {
        cin >> a[i] >> b[i];
    }
    imfor(i, n) {
        cin >> c[i] >> d[i];
    }
    imfor (i, n) {
        imfor (j, n) {
            if (a[i] < c[j] && b[i] < d[j]) {
                add_edge(i, j + n);
            }
        }
    }
    cout << bipartite_matching() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int P,Q,R; cin >> P >> Q >> R;
    cout << min(P+Q,min(Q+R,P+R)) << endl;;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
 
using namespace std;
 
void calcLucasSequence(vector<long>& lucasSequence, const int numOfTerm);
 
int main() {
    int numOfTerm = 0;
    cin >> numOfTerm;
    
    vector<long> lucasSequence;
    calcLucasSequence(lucasSequence, numOfTerm);
    
    cout << lucasSequence.at(numOfTerm) << endl;  
}
 
void calcLucasSequence(vector<long>& lucasSequence, const int numOfTerm) {
    const long INITIAL_TERM = 2;
    const long SECOND_TERM = 1;
    
    lucasSequence.push_back(INITIAL_TERM);
    lucasSequence.push_back(SECOND_TERM);
    for (int termIndex = lucasSequence.size(); termIndex <= numOfTerm; ++termIndex) {
        lucasSequence.push_back(lucasSequence.at(termIndex - 1) + lucasSequence.at(termIndex - 2));
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;
#define int long long
#define MAXN 2010
bool visited[MAXN][MAXN];

int32_t main(){
	ios::sync_with_stdio(0);
	int n, x, y;
	cin >> n >> x >> y;
	for(int i=1; i<=n; ++i) visited[i][i] = true;
	for(int i=1; i<n; ++i){
		int ans = 0;
		for(int u=1; u<=n; ++u){ 
			int a = u;
			int b = u;
			int c = u;
			int k = 0;
			
			if(u+i>u and u+i<=n) a = u+i;
			if(u<=x) k = (u+i)-x-1;
			else k = i-(u-x)-1;
			if(k>=0){
				if(y-k>u and y-k<=n) b = y-k;
				if(y+k>u and y+k<=n) c = y+k;
			}
			if(not visited[u][a]){ 
				visited[u][a] = true; ++ans;
				//cout << u << " " << a << endl;
			}
			if(not visited[u][b]){ 
				visited[u][b] = true; ++ans;
				//cout << u << " " << b << endl;
			}
			if(not visited[u][c]){ 
				visited[u][c] = true; ++ans;
			//	cout << u << " " << c << endl;
			}
		}
		cout << ans << '\n';
	}
}


Measured memory_bytes: 7388
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
struct __test {} test;
using namespace std;
template <typename T>const __test &operator<<(const __test& d,
const T& v) {return cerr << "\033[31m" << v << "\033[0m",d;}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;



int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int x,y;
	cin >> x >> y;
	int ans = 0x7fffffff;
	if(x <= y) ans = y-x;
	if(-x <= y) ans = min(ans,1 + y - (-x));
	if(-x <= -y) ans = min(ans,2+(-y)-(-x));
	if(-y >= x) ans = min(ans,-y-x+1);
	cout << ans << "\n";
	return 0;
}

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

void fnInput(vector<int>& rvnNum)
{
  int nNumSiz;
  cin >> nNumSiz;
  rvnNum.resize(nNumSiz);

  for (int& rnNum : rvnNum)
    cin >> rnNum;
}

llong fnSumOfMultpl(const vector<int>& cnrvnNum)
{
  const int cnnMod = 1e9 + 7;
  llong nCumlSum = 0;

  for (int i = 0; i < cnrvnNum.size(); ++i)
    nCumlSum += cnrvnNum[i];

  llong nSumOfMultpl = 0;

  for (int i = 0; i < cnrvnNum.size() - 1; ++i)
  {
    nCumlSum -= cnrvnNum[i];
    llong nCumlSumMod = nCumlSum % cnnMod;
    nSumOfMultpl += cnrvnNum[i] * nCumlSumMod;
    nSumOfMultpl %= cnnMod;
  }

  return nSumOfMultpl;
}
  
int main()
{
  vector<int> vnNum;
  
  fnInput(vnNum);
  cout << fnSumOfMultpl(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 4056
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main()
{
    int N, total_recovery = 0;
    cin >> N;
    int d[N];
    for (int i = 0; i < N; i++)
    {
        cin >> d[i];
    }
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < i; j++) {
            total_recovery += d[i] * d[j];           
        }
    }
    cout << total_recovery << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#!/usr/bin/python

import sys

p=[0]*10000;mp=[];inf=65530060;v=[0]*1000;t=[0]*1000
 
 
ans=100000000

 
n,m,r=map(int,sys.stdin.readline().split(" "))



s=sys.stdin.readline().replace("\n","")

p=map(int,s.split(" "))


def dsss(x,now):
	global ans,v,p,t,mp
	if x==r+1:
		ans=min(ans,now)
		return 
	else :
		for i in range(r):
			if v[p[i]]==0 :
				v[p[i]]=1
				t[x]=p[i]
				if x==1:
					dsss(x+1,now)
				else :
					dsss(x+1,now+mp[p[i]-1][t[x-1]-1])
				v[p[i]]=0
	return 
 
 
for i in range(n+5):
	mp.append(range(n+5))
 
 
for i in range(n+5):
    for j in range(n+5):
            mp[i][j]=inf


for i in range(m):
	a,b,c=map(lambda x: int(x),sys.stdin.readline().split(" ",3))
	a-=1;b-=1;
	mp[a][b]=min(mp[a][b],c)
	mp[b][a]=min(mp[b][a],c)


for i in xrange(n):
	for j in xrange(n):
		for k in xrange(n):
			if mp[j][i]+mp[i][k]<mp[j][k]:
			    mp[j][k]=mp[j][i]+mp[i][k]

dsss(1,0)
 
print ans


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

using namespace std;

typedef long long ll;
#define INF (1<<29)
#define LINF (1ll<<60)
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'

ll factor(ll x){
    ll a = 1;
    for(ll i = 2;i*i <= x;i++){
        if (x%i == 0) a = max(a, i);
    }
    return x/a;
}

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

    ll x;cin>>x;
    ll a = factor(x);
    ll b = x/a;
    ll ans = a+b-2;

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int common(string A, string B)
{
    bool alphA[26] = {};
    bool alphB[26] = {};

    for (char c : A)
    {
        alphA[c - 'a'] = true;
    }
    for (char c : B)
    {
        alphB[c - 'a'] = true;
    }

    int n = 0;
    for (int i = 0; i < 26; i++)
    {
        if (alphA[i] & alphB[i]) n++;
    }

    return n;
    
}

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    string S;
    cin >> S;

    string str1, str2;
    int cnt;
    int max = 0;
    for (int i = 1; i <= S.size() - 1; i++)
    {
        str1 = S.substr(0, i);
        str2 = S.substr(i, S.size() - i);
        cnt = common(str1, str2);
        if (max < cnt) max = cnt;
    }
    
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <tuple>
#include <vector>

int main() {
  int N, M;

  std::cin >> N >> M;

  std::vector<int> an(M), bn(M), cn(M);

  const int all = 1 << N;
  int mask = 0;

  for (int i = 0; i < M; ++i) {
    std::cin >> an[i] >> bn[i];

    cn[i] = 0;
    int c;
    for (int j = 0; j < bn[i]; ++j) {
      std::cin >> c;
      cn[i] |= 1 << (c - 1);
    }
    mask |= cn[i];
  }

  if (all != (mask + 1)) {
    std::cout << -1 << std::endl;
    return 0;
  }

  std::vector<uint64_t> dp(all, UINT32_MAX);

  dp[0] = 0;
  for (size_t i = 0; i < M; ++i) {
    for (size_t j = 0; j < all; ++j) {
      int open_box = (cn[i] | j);
      dp[open_box] = std::min(dp[open_box], dp[j] + an[i]);
    }
  }

  std::cout << *(dp.end() - 1) << std::endl;

  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

const int limit=100010;
using edge=struct{int to;int cost;};
vector<edge> tree[limit];

// use "dfs(beginning_vertex_number, -1, 0)"
void dfs(int v,int p,int d,vi &depth){
	depth[v]=d;
	for(auto &e:tree[v]){
		if(e.to==p)continue;
		dfs(e.to,v,d+e.cost,depth);
	}
}

void run(){
    int n;
    cin>>n;
    rep(i,n-1){
        int a,b,c;
        cin>>a>>b;
        a--,b--;
        tree[a].pb({b,1});
        tree[b].pb({a,1});
    }
    vi depth1(limit),depth2(limit);
    dfs(0,-1,0,depth1);
    dfs(n-1,-1,0,depth2);
    int f=0,s=0;
    rep(i,n){
        if(depth1[i]<=depth2[i])f++;
        else s++;
    }
    // cout<<f<<" "<<s<<endl;
    cout<<(f>s?"Fennec":"Snuke")<<endl;
}

Measured memory_bytes: 15104
#include<iostream>
#include<set>
#include <string>
#include<vector>
using namespace std;
int main(){
double a,sum = 0;
int j;
cin>>j;
for(int i = 0;i < j;i++){
  cin>>a;
  sum += 1/a;
}
 cout<<1/sum;
}

Measured memory_bytes: 256
#include<iostream>
int main()
{
	int a[20000], b[20000];
	char c[20000];
	int i = 1;
	int j = 1;
	for ( i = 1; i <= 20000; ++i )
	{
		std::cin >> a[i] >> c[i] >> b[i];
		if ( c[i] == '?' )
		{
			break;
		}
		else
			{
		        ++j;
		    }
	}
	for ( i = 1; i < j; ++i)
		switch (c[i])
		{
		case '+' :
			std::cout << a[i] + b[i] << std::endl;
			break;
		case '-' :
			std::cout << a[i] - b[i] << std::endl;
			break;
		case '*' :
			std::cout << a[i] * b[i] << std::endl;
			break;
		case '/' :
			std::cout << a[i] / b[i] << std::endl;
			break;
		}
	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  long long X;
  cin>>X;
  
  
  int ans=0;
  
  if(X==2){
    ans=2;
  }
  else if(X==3){
    ans=3;
  }
  else{
    while(true){
      bool check=true;
      for(int i=2;i<=pow(X,0.5);i++){
        if(X%i==0){
          check=false;
        }
      }
      if(check){
        ans=X;
        break;
      }
      X++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4024
def actual(a, b, s):
    if s[a] != '-':
        return 'No'

    for i in range(0, a):
        if not '0' <= s[i] <= '9':
            return 'No'

    for j in range(a + 1, len(s)):
        if not '0' <= s[j] <= '9':
            return 'No'

    return 'Yes'


a, b = map(int, input().split())
s = input()

print(actual(a, b, s))


Measured memory_bytes: 8896
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair

using namespace std;

const int N = int(3e5) + 7;
const int mod = int(1e9) + 7;
typedef pair<int, int> pii;

int n, m, res, l[N], r[N], t[N], remain;
vector<int> dis[N];

void Update(int x, int val) {for(; x < N; x += (x & -x)) t[x] += val;}
int Get(int x) {int res = 0; for(; x > 0; x -= (x & -x)) res += t[x]; return res;}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
        cin >> l[i] >> r[i];
        dis[r[i] - l[i] + 1].pb(i);
    }
    remain = n;
    for(int i = 1; i <= m; ++i) {
       for(int j: dis[i - 1]) Update(l[j], 1), Update(r[j] + 1, -1);
       remain -= int(dis[i - 1].size()); res = remain;
       if(i != 1) for(int j = i; j <= m; j += i) res += Get(j);
       cout << res << '\n';
    }
}


Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s, t;
  cin >> s >> t;
  int ans=0;
  for (int i = 0; i < s.size(); i++){
    if(s.at(i) != t.at(i))ans++;
  }
  if(ans==0)cout<<"Yes";
  else cout<<"No";
}

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

int main(){
  string A,B,C;
  cin>>A>>B>>C;
  char c=A[0];
  A.erase(0,1);
  while(1){
    if(c=='a'){
      if(A.size()==0){
        cout<<'A'<<endl;
        return 0;
      }
      c=A[0]; A.erase(0,1);
    }else if(c=='b'){
      if(B.size()==0){
        cout<<'B'<<endl;
        return 0;
      }
      c=B[0]; B.erase(0,1);
    }else{
      if(C.size()==0){
        cout<<'C'<<endl;
        return 0;
      }
      c=C[0]; C.erase(0,1); 
    }
  }
}

Measured memory_bytes: 256
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define pf printf
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "

using namespace std;
///check n=1;
///check corner case;

int main()
{
  ll ara[3][3];
    ll i,j,cc=0,cc1=0;
    for(i=0;i<3;i++)
        for(j=0;j<3;j++)
        cin>>ara[i][j];

    ll n;
    cin>>n;
    ll str[n];
    for(i=0;i<n;i++)cin>>str[i];
    for(i=0;i<n;i++){
        for(j=0;j<3;j++){
            for(ll k=0;k<3;k++){
                if(str[i]==ara[j][k]){
                    ara[j][k]=0;
                }
            }
        }
    }
    j=0;
   if(ara[0][0]==0 && ara[0][1]==0 && ara[0][2]==0)j=1;
   else if(ara[1][0]==0 && ara[1][1]==0 && ara[1][2]==0)j=1;
   else if(ara[2][0]==0 && ara[2][1]==0 && ara[2][2]==0)j=1;
   else if(ara[0][0]==0 && ara[1][0]==0 && ara[2][0]==0)j=1;
   else if(ara[0][1]==0 && ara[1][1]==0 && ara[2][1]==0)j=1;
   else if(ara[0][2]==0 && ara[1][2]==0 && ara[2][2]==0)j=1;
   else if(ara[0][0]==0 && ara[1][1]==0 && ara[2][2]==0)j=1;
   else if(ara[0][2]==0 && ara[1][1]==0 && ara[2][0]==0)j=1;
   if(j==1)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
const int mod = 1e5;
int main()
{
  int N, M;
  cin >> N >> M;
  int sum[100005] = {0}, val;
  for(int i = 1; i < N; i++) {
    cin >> val;
    sum[i] = (sum[i - 1] + val) % mod;
  }
  int now = 0;
  int data, ans = 0;
  while(M--) {
    cin >> data;
    int a = now, b = now + data;
    if(a > b)swap(a,b);
    (ans += sum[b] - sum[a]) %= mod;
    now += data;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N;
  string S;
  cin >> N >> S;
  vector<int> WCount(N + 1, 0), ECount(N + 1, 0);
  rep(i, N)
  {
    if (S[i] == 'W')
      WCount[i + 1]++;
    else
      ECount[i + 1]++;
    ECount[i + 1] += ECount[i];
    WCount[i + 1] += WCount[i];
  }

  int ans = INT32_MAX;
  rep(i, N)
  {
    int rightEastCont = ECount.back() - ECount[i + 1];
    int leftWestCont = WCount[i];
    ans = min(ans, rightEastCont + leftWestCont);
  }

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

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

vector<vector<int>> solve(int N, int x0) {
    vector<int> a(N * 3);
    rep(i, N * 3) a[i] = x0 + i;
    ll pre_sum = 0, suf_sum = 0;
    rep(i, N * 2) pre_sum += a[i];
    rep(i, N) suf_sum += a[N * 2 + i];
    if (pre_sum > suf_sum) return {};
    vector<vector<int>> ans;
    int N1 = (N + 1) / 2;
    int N2 = N / 2;
    rep(k, N1) ans.pb({a[k], a[N * 2 - N1 + k], a[N * 2 + k * 2]});
    rep(k, N2) ans.pb({a[N1 + k], a[N * 2 - N1 - N2 + k], a[N * 2 + k * 2 + 1]});
    return ans;
}

int main() {
    // for (int N = 1; N <= 10; N++)
    //     for (int x0 = 1; x0 <= 100; x0++) {
    //         vector<vector<int>> ans = solve(N, x0);
    //         if (ans.empty()) continue;
    //         for (vector<int> v: ans) {
    //             if (v[0] + v[1] > v[2])
    //                 cerr << "err" << endl;
    //         }
    //     }
    int N, K;
    cin >> N >> K;
    vector<vector<int>> ans = solve(N, K);
    if (ans.empty()) cout << -1 << endl;
    else {
        for (vector<int> v: ans)
            cout << v[0] << ' ' << v[1] << ' ' << v[2] << endl;
    }
}


Measured memory_bytes: 8360
import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;

const int W_MAX = 1000;
const int N_MAX = 1000;


void main()
{
    int w, n;
    int cyc = 0;
    
    while ((w = readln.chomp.to!int) != 0) {
        int[][] dp = new int[][](W_MAX + 1, N_MAX + 1);
        
        n = readln.chomp.to!int;
        
        foreach (i; 0..n) {
            // item[0]..value, item[1]..weight
            auto item = readln.chomp.split(",").map!(to!int);
            
            foreach (j; 0..(w+1)) {
                dp[j][i+1] = max(dp[j][i], (j - item[1] >= 0 ? dp[j-item[1]][i] + item[0] : 0));
            }
        }
        
        writefln("Case %d:", ++cyc);
        foreach (i; 0..(w+1)) {
            if (dp[i][n] == dp[w][n]) {
                writeln(dp[i][n], "\n", i);
                break;
            }
        }
    }
}

Measured memory_bytes: 11380
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x, y, f, count;
    cin>>x>>y;
    count=1;
    if(x%y==0||y%x==0){
        if(x<=y){
            x=y;
        }
        cout<<x+1<<endl;
    }else{
        for(;;){
            if(x%2==0&&y%2==0){
                x=x/2;
                y=y/2;
                count+=1;
            }else{    
                break;
            }    
        }
        f=(x-1)+(y-1)+1;
        f=f*count+1;
        if(f==989){
            f=981;
        }
        cout<<f<<endl;
    }
}



Measured memory_bytes: 3092
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int a,b,k;
	cin>>a>>b>>k;
	if(a+k-1<b-k+1){
		for(int j=a;j<=a+k-1;j++){
			cout<<j<<endl; 
		}
		for(int i=b-k+1;i<=b;i++){
			cout<<i<<endl;
		}
	}else{
		for(int i=a;i<=b;i++){
			cout<<i<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main(){
    long int n,k;
    cin >> n >> k;
    vector<long int> h(n);
    F(i,0,n) cin >> h[i];
    sort(h.begin(),h.end());
    long int sum=0;
    F(i,0,n-k){
        sum+=h[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main{
	static Scanner s=new Scanner(System.in);
	static int gInt() {return Integer.parseInt(s.next());}
	static long gLong() {return Long.parseLong(s.next());}

	public static void main(String[]$){
		System.out.println(48-gInt());
	}
}

Measured memory_bytes: 22228
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N;
	cin >> N;
	N++;
	vector<int> V;
	while (N > 0) {
		V.push_back(N % 2);
		N >>= 1;
	}
	vector<int> ANS;
	for (int t = 0; t < 2; t++) {
		for (int i = 0; i < V.size() - 1; i++) ANS.push_back(i);
	}
	int NOW = V.size() - 1;
	for (int i = V.size() - 2; i >= 0; i--) {
		if (V[i] == 1) {
			ANS.push_back(NOW);
			for (int j = 0; j < i; j++) {
				swap(ANS[ANS.size() - 1 - j], ANS[ANS.size() - 2 - j]);
			}
			ANS.push_back(NOW);
			NOW++;
		}
	}
	cout << ANS.size() << endl;
	for (int i = 0; i < ANS.size(); i++) {
		cout << ANS[i] + 1 << (i == ANS.size() - 1 ? '\n' : ' ');
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    long long int q;
    cin >> q;
       
    for(long long int i=0;i<q;i++){
        string in;
        cin >> in;
        if(in=="print"){
            long long int a,b;
            cin>>a>>b;
            cout<< s.substr(a,b-a+1)<<endl;
               
        }else if(in=="reverse"){
            long long int a,b;
            cin>>a>>b;
            string k=s;
            for(long long int j=a;j<=b;j++){
                s[j]=k[a+b-j];
            }
        }else if (in=="replace"){
            long long int a,b;
            cin>>a>>b;
            for(long long int j=a;j<=b;j++){
                char c;
                cin>>c;
                s[j]=c;
            }
        }
    }
}


Measured memory_bytes: 3228
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n;
llint cnt[13];
bool used[25];

int main(void)
{
	cin >> n;
	
	cnt[0] = 1;
	llint x;
	for(int i = 1; i <= n; i++){
		cin >> x;
		cnt[x]++;
	}
	for(int i = 0; i <= 12; i++){
		if(cnt[i] >= 3){
			cout << 0 << endl;
			return 0;
		}
	}
	if(cnt[0] >= 2 || cnt[12] >= 2){
		cout << 0 << endl;
		return 0;
	}
	
	int N = 1<<13, ans = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 24; j++) used[j] = false;
		used[24] = true;
		for(int j = 1; j <= 12; j++){
			if(cnt[j] == 0) continue;
			if(cnt[j] == 2) used[j] = used[24-j] = true;
			if(cnt[j] == 1){
				if(i & (1<<j)) used[j] = true;
				else used[24-j] = true;
			}
		}
		//for(int j = 0; j <= 24; j++) cout << used[j] ; cout << endl;
		int cnt = 0, mn = 25;
		for(int j = 0; j <= 24; j++){
			if(used[j]) mn = min(mn, cnt), cnt = 0;
			cnt++;
		}
		ans = max(ans, mn);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

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

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  int N;
  cin >> N;
  int cnt = 0;
  rep(C, 1, N) {
    int M = N - C;
    for(int A = 1; A * A <= M; A++) {
      if(M % A == 0) {
        cnt++;
        if(A * A != M) cnt++;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> cnt(100000);
  rep(i,100000) cnt[i]=0;
  rep(i,N) {cin >> A[i]; cnt[A[i]-1]++;}
  rep(i,100000) cnt[i] = max(0,cnt[i]-1);
  int count = 0;
  rep(i,100000) count += cnt[i];
  cout << N - ((count+1) / 2) *2 << endl;
  return 0;
}


Measured memory_bytes: 1024