akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=(double)a/b;
	printf("%d\n",d);
	printf("%d\n",r);
	printf("%f\n",f);
	
	
return 0;
}

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

int main(){
  	int n=0;
	string s;
  	cin>>s;
  	
  	for(int i=0;i<4;i++){
		if(s[i]=='+'){
          n++;
        }else{
		  n-=1;
        }
    }

  	cout<<n<<endl;
}

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

#define endl "\n"
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

void header() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int h[maxn];

void solve() {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> h[i];
    sort(h + 1, h + 1 + n);
    ll sum = 0;
    for (int i = 1; i <= n - k; i++) sum += h[i];
    cout << sum << endl;
}

int main() {
    header();
    solve();
    return 0;
}


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

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int xa = min(a,k); //+1đIÔ
  k -= xa;

  int xb = min(b,k); //0đIÔ
  k -= xb;

  int xc = k;
  int ans = xa - xc;
  cout << ans << endl;


  return 0;
}


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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;cin>>n>>k;
    string s;cin>>s;
    ll uh=1;
    rep(i,n-1){
        if(s[i+1]!=s[i])uh++;
    }
    while(uh>1&&k>0){
        if(uh>2){
            uh-=2;
            k--;
        }
        else{
            uh--;
            k--;
        }
    }
    cout<<n-uh<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <queue>
using namespace std;

int main() {
	int n;
	cin >> n;
	int sumOdd = 0;

	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if (a % 2 == 1) sumOdd++;
	}
	if (sumOdd % 2 == 0)
		cout << "YES";
	else
		cout << "NO";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod=1000000007;


ll A, B, C, X, Y, res;

int main() {
	cin >> A >> B >> C >> X >> Y;
	if (C * 2 > A + B) {
		cout << A * X + B * Y << endl;
	}
	else {
		res += min(X, Y) * 2 * C;
		if (X > Y) {
			res += (X - Y)*min(C * 2, A);
		}
		else {
			res += (Y - X)*min(C * 2, B);
		}
		cout << res << endl;
	}
	return 0;
}

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

using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin>>a>>b;
    if(a%2==0 || b%2==0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int maxn = 333;
string u, v;
int dp[maxn][maxn][maxn];
int solve(int l, int r, int k){
    if(l > r) return 0;
    if(l == r) return 1;
    if(dp[l][r][k] != -1) return dp[l][r][k];
    int ans = 0;
    if(u[l] == u[r]) ans = max(ans, 2 + solve(l + 1, r - 1, k));
    ans = max(ans, solve(l+1, r, k));
    ans = max(ans, solve(l, r-1, k));
    if(k) ans = max(ans, 2 + solve(l + 1, r - 1, k - 1));
    return dp[l][r][k] = ans;
}
int main(){
    string c;
    cin >> c;
    int k;
    cin >> k;
    u = c;
    memset(dp, -1, sizeof(dp));
    cout << solve(0, c.size() - 1, k) << endl;
    return 0;
}


Measured memory_bytes: 144512
#include<stdio.h>

void maxHeapify(int*,int,int);

#define MAX 500001

int main(){
  int H,i,A[MAX];

  scanf("%d",&H);
  for(i=1;i<=H;i++)scanf("%d",&A[i]);
  
  for(i=H/2;i>=1;i--){
    maxHeapify(A,i,H);
  }
  
  for(i=1;i<=H;i++)printf(" %d",A[i]);
  printf("\n");
  return 0;
}

void maxHeapify(int *A,int i,int H){
  int l,r,largest,a,j;
  l=2*i;
  r=2*i+1;
  if(l<=H&&A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H&&A[r]>A[largest])largest=r;
    
  if(largest!=i){
    a=A[i];
    A[i]=A[largest];
    A[largest]=a;
    maxHeapify(A,largest,H);
  }
}



Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int mod = 1e9+7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint pow(int x) {
    if (!x) return 1;
    mint res = pow(x/2);
    res *= res;
    if(x%2!=0) res*=2;
    return res;
}

// nCk = n/1 * (n-1)/2 * (n-k+1)/k
mint choose(int n, int k) {
    mint x = 1, y = 1;
    rep(i, k) {
        x *= n-i;
        y *= i+1;
    }
    return x / y;
}

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

    int n, a, b; cin >> n >> a >> b;

    mint ans = pow(n) - 1;
    ans -= choose(n, a);
    ans -= choose(n, b);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> b(n, 0), s(n+1, 0);
    for (int i = 0; i < n; i++) { int a; cin >> a; b[a-1]++; }
    sort(b.begin(), b.end());
    for (int i = 0; i < n; i++) s[i+1] = b[i] + s[i];
    vector<int> f(n+1, 1<<30);
    for (int x = 1; x <= n; x++) {
        int i = lower_bound(b.begin(), b.end(), x) - b.begin();
        f[x] = n - i + s[i]/x;
    }
    for (int k = 1; k <= n; k++)
        cout << f.rend() - lower_bound(f.rbegin(), f.rend(), k) - 1 << endl;
}


Measured memory_bytes: 4352
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n;
    cin>>n;
    ll mx=0;
    ll sum=0;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        sum+=a;
        mx=max(mx,a);
    }
    cout<<sum-mx/2<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <map>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int w, n; cin >> w >> n;
	vector<int> A(w);
	iota(A.begin(), A.end(), 1);
	for (int i = 0; i < n; i++) { int a, b; char c; cin >> a >> c >> b; swap(A[a - 1], A[b - 1]); }
	for (int i = 0; i < w; i++) cout << A[i] << endl;
}

Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <stack>
#include <map>
using namespace std;

typedef vector <int> VI;
typedef vector <VI> VVI;
typedef pair <int, int> PII;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef int Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void visit(const Graph &g, int v, vector< vector<int> >& scc,
    stack<int> &S, vector<bool> &inS,
    vector<int> &low, vector<int> &num, int& time) {
        low[v] = num[v] = ++time;
        S.push(v); inS[v] = true;
        FOR(e, g[v]) {
            int w = e->dst;
            if (num[w] == 0) {
                visit(g, w, scc, S, inS, low, num, time);
                low[v] = min(low[v], low[w]);
            } else if (inS[w])
                low[v] = min(low[v], num[w]);
        }
        if (low[v] == num[v]) {
            scc.push_back(vector<int>());
            while (1) {
                int w = S.top(); S.pop(); inS[w] = false;
                scc.back().push_back(w);
                if (v == w) break;
            }
        }
}

void stronglyConnectedComponents(const Graph& g,
    vector< vector<int> >& scc) {
        const int n = g.size();
        vector<int> num(n), low(n);
        stack<int> S;
        vector<bool> inS(n);
        int time = 0;
        REP(u, n) if (num[u] == 0)
            visit(g, u, scc, S, inS, low, num, time);
}

int main() {
    int n;
    while ( cin >> n && n ) {
        Graph G(n);
        for ( int i = 0; i < n; ++ i ) {
            for ( int j = 0; j < 2; ++ j ) {
                int b, f;
                cin >> b >> f;
                G[i].push_back( Edge( i, b, f ) );
            }
        }
        VVI scc;
        int res = 1;
        stronglyConnectedComponents( G, scc );
        for ( auto it = scc.begin(); it != scc.end(); ++ it ) {
            VI V = *it;
            int m = V.size();
            int maxf = 0;
            for ( int i = 0; i < m; ++ i ) {
                for ( int j = 0; j < 2; ++ j ) {
                    maxf = max( maxf, G[V[i]][j].weight );
                }
            }
            int cnt = 0;
            for ( int i = 0; i < m; ++ i ) {
                for ( int j = 0; j < 2; ++ j ) {
                    if ( maxf == G[V[i]][j].weight ) {
                        cnt ++;
                    }
                }
            }
            res = ( res * ( cnt / 2 ) ) % 10007;
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[26];
int main() {
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		ll now=s[i]-'a';
		a[now]++;
	}
	ll ans=1;
	for(int i=0;i<26;i++){
		for(int j=i+1;j<26;j++){
			ans+=a[i]*a[j];
		}
	}
	cout <<ans;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

const ll mod=1000000007;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  ll n,t;
  cin >> n >> t;
   vpll a(n);
   rep(i,0,n) cin >> a[i].first >> a[i].second;
   sort(a.begin(),a.end());
    
  vector<vll> dp(n+1,vll(6005,0)); 
   
  ll res=0;
  rep(i,0,n) {
    rep(j,0,t) {
      if(j+a[i].first<t) dp[i+1][j+a[i].first]=max(dp[i+1][j+a[i].first],dp[i][j]+a[i].second);
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
      res=max(res,dp[i][j]+a[i].second);
    }
    }
 
   cout << res << endl;
 
}

Measured memory_bytes: 141312
N, K = map(int,input().split( ))
H = [int(i) for i in input().split( )]

H = sorted(H)
def binary_search(arr, x):
    start = 0
    end = len(arr)-1
    while(end >= start):
        mid = int(start + (end-start)/2)
        if x > arr[mid]:
            start = mid+1
        elif x < arr[mid]:
            end = mid -1
        else:
            for i in range(mid-start):
                if arr[mid-i-1] < x:
                    start = mid - i
                    break
            break
    return start
print(N - binary_search(H, K))

Measured memory_bytes: 11896
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl


/*--------------------template--------------------*/

double func(ll a, ll b) {
    return (double)(100 * b) / (a + b);
}

bool ch(string a) {
    if (a.size() % 2 == 1) {
        return false;
    }
    string s = a.substr(0, a.size() / 2);
    string t = a.substr(a.size() / 2, a.size());
    if (s == t) {
        return true;
    } else {
        return false;
    }
}


int main() {
    cin >> s;
    while (1) {
        s.pop_back();
        if (ch(s)) {
            cout << s.size() << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int A,B,C,D,E,F,tar,water,suger,answ,anss,sum,ra,rb,rc,rd;
double nd;
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
	if (A<B)  swap(A,B);
	if (C<D)  swap(C,D);
	ra=F/(A*100);
	rb=F/(B*100);
	rc=F/C;
	rd=F/D;
	for (a=0;a<=ra;a++)
	  for (b=0;b<=rb;b++)
	    for (c=0;c<=rc;c++)
	      for (d=0;d<=rd;d++)
	      {
	      	water=a*A+B*b;
	      	suger=c*C+D*d;
	      	if (!water)  continue;
	      	if (100*water+suger>F)  continue;
	      	if ((double)suger/(double)water>(double) E)  continue;
	      	double t=(double)(100*suger)/(double)(100*water+suger);
	      	if (t>nd)  nd=t,anss=suger,sum=100*water+suger;
		  }
	if (sum==0)
	  printf("%d 0",100*B);
	else 
	  printf("%d %d",sum,anss);
}

Measured memory_bytes: 128
M = 10**9+7
import sys
input = sys.stdin.readline

N,K = map(int, input().split())
A = list(map(int, input().split()))
A_ = sorted(A, reverse = True)
ans = 0
ans_ = 0
for i in range(0,N-1):
        for j in range(i+1,N):
            if A[i] > A[j]:
                ans += 1
            if A_[i] > A_[j]:
                ans_ += 1

print(((int((K*(K-1))//2)%M)*ans_+ans*K)%M)

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

using namespace std;

int main()
{
	long long n,m;
	long long scc=0;
	cin>>n>>m;
	if(n<m/2)
	{
		scc+=n;
		m-=n*2;
		scc+=m/4;
	}else{
		scc+=m/2;
	}
	cout<<scc<<endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let x = read_vec::<usize>();
    let mut pairs = vec![];
    for (i, xnum) in x.into_iter().enumerate() {
        pairs.push((xnum - 1, i));
    }
    pairs.sort();
    let mut answers = vec![];
    let mut pointer = 0;

    let mut yobi = VecDeque::new();
    for &(_, i) in pairs.iter() {
        for _ in 0..i {
            yobi.push_back(i);
        }
    }

    let mut residual = VecDeque::new();
    for (xnum, i) in pairs {
        if pointer > xnum {
            println!("No");
            return;
        }
        while pointer < xnum {
            if let Some(top) = yobi.pop_front() {
                answers.push(top);
            } else if let Some(top) = residual.pop_front() {
                answers.push(top);
            } else {
                println!("No");
                return;
            }
            pointer += 1;
        }
        if !yobi.is_empty() && yobi[0] == i {
            println!("No");
            return;
        }
        answers.push(i);
        pointer += 1;
        for _ in i + 1..n {
            residual.push_back(i);
        }
    }
    while let Some(top) = residual.pop_front() {
        answers.push(top);
        pointer += 1;
    }
    assert_eq!(pointer, n * n);
    assert_eq!(answers.len(), n * n);
    println!("Yes");
    for ans in answers {
        print!("{} ", ans + 1);
    }
    println!("");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

// ??????????????±??????????????£????????£???

int main(){
	string T, P;
	cin >> T >> P;
	long skip[10000] = {};
	// index i??§???????????£???????????¨???
	for (long i = 0; i < P.size(); i++){
		if (i == 0) skip[i] = 1;
		else {
			// j?????????????????????
			for (long j = 1; j < P.size(); j++){
				// index i - 1?????§?????§????????????
				for (long k = 0; k < i + 1; k++){
					// index i - 1?????§?????£?????????j???skip????????????
					if (j + k == i && P[k] != P[j + k]){
						skip[i] = j;
						break;
					}
					if (P[k] != P[j + k]) break; // ?¬????j????????????
				}
				if (skip[i] != 0) break;
			}
			// ????????\???????????£?????¨??????i + 1??¨??????
			if (skip[i] == 0) skip[i] = i + 1;
		}
	}
	/*
	for (long i = 0; i < P.size(); i++){
		cout << i << ": " << skip[i] << endl;
	}
	*/

	long m = 0, n = 0;
	while (m < T.size() && n < P.size()){
		if (T[m] == P[n]){
			if (n == P.size() - 1){
				// ????????????m?????????????????¨????°????index???????????????
				// cout << m - n << endl;
				printf("%d\n", m - n);
				// ???????????§?????£????????£????????????
				m = m - n + 1;
				n = 0;
			}
			else {
				m++;
				n++;
			}
		}
		else {
			// text???pattern???????????????????????¨?????£??????skip??¨????????£?????¨?????¨??????????????????????????????????????¨???????????????
			n -= skip[n];
			// ???????????????????????§???????????????
			if (n < 0){
				m++;
				n++;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1272
fn main() {
    let mut a: Vec<usize> =
        io::read_line().split_whitespace().map(|num| num.parse().unwrap()).collect();
    let n: usize = io::readln();
    let mut two = [a[0] * 8, a[1] * 4, a[2] * 2, a[3]];
    let mut one = [a[0] * 4, a[1] * 2, a[2]];
    one.sort();
    two.sort();
    let mut ans: usize = 0;
    if n > 1 {
        ans = two[0] * (n / 2);
        if n % 2 != 0 {
            ans += one[0];
        }
    } else {
        ans = one[0];
    }
    println!("{}", ans);
}

pub mod io {
    use std::io;

    pub fn read_line() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }

    pub fn readln<T: Read>() -> T {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        T::read(s.trim())
    }

    pub trait Read {
        fn read(s: &str) -> Self;
    }

    impl Read for String {
        fn read(s: &str) -> Self {
            s.to_string()
        }
    }

    impl<T: Read> Read for Vec<T> {
        fn read(s: &str) -> Self {
            s.split_whitespace().map(|w| T::read(w)).collect()
        }
    }

    macro_rules !def_read {
        ($t : ty) => {
            impl Read for $t {
                fn read(s : &str)->$t { s.parse().unwrap() }
            }
        }
    }

    macro_rules !def_read_tuple {
        ($($t : ident), *) => {
            impl<$($t : Read + Default), *> Read for ($($t), *) {
                fn read(s : &str)->Self {
                    let mut iter = s.split_whitespace();
                    ($($t::read(iter.next().unwrap())), *)
                }
            }
        };
    }

    def_read!(i32);
    def_read!(i64);
    def_read!(isize);
    def_read!(usize);
    def_read!(f32);
    def_read!(f64);
    def_read_tuple!(T0, T1);
    def_read_tuple!(T0, T1, T2);
    def_read_tuple!(T0, T1, T2, T3);
    def_read_tuple!(T0, T1, T2, T3, T4);
}

Measured memory_bytes: 4352
#include<cctype>
#include<cstdio>
#include<cstring>
#include<algorithm>

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

using namespace std;

int idx;
char s[11];
bool res;

#define ASRT if(!res) return 0

int N(){
	if(!('1'<=s[idx] && s[idx]<='9')){ res=false; ASRT; }
	int a=0;
	while(isdigit(s[idx])) a=10*a+s[idx++]-'0';
	return a;
}

int N0(){
	int a;
	if(s[idx]=='0'){
		idx++;
		a=0;
	}
	else a=N();
	ASRT;
	return a;
}

int Ex2(){
	int a=N0();
	ASRT;
	while(s[idx]=='*' || s[idx]=='/'){
		char op=s[idx++];
		int b=N0();
		ASRT;
		if(op=='/' && (b==0 || a%b!=0)){ res=false; ASRT; }

		if(op=='*') a*=b;
		if(op=='/') a/=b;
	}
	return a;
}

int Ex1(){
	int a=Ex2();
	ASRT;
	while(s[idx]=='+' || s[idx]=='-'){
		char op=s[idx++];
		int b=Ex2();
		ASRT;

		if(op=='+') a+=b;
		if(op=='-') a-=b;
	}
	return a;
}

int Eq(){
	int a=Ex1();
	ASRT;
	if(s[idx++]!='='){ res=false; ASRT; }
	int b=Ex1();
	ASRT;
	if(a!=b || s[idx]) res=false;
	return 0;
}

bool parse(){
	if(strlen(s)<=2) return true;
	idx=0;
	res=true;
	Eq();
	return res;
}

int h,w;
char B[10][11];

bool calc_no_space(){
	rep(i,h){
		int p=-1;
		rep(j,w+1){
			if(j<w && B[i][j]!='#'){
				if(p==-1) p=j;
			}
			else{
				if(p!=-1){
					rep(k,j-p) s[k]=B[i][p+k];
					s[j-p]='\0';
					if(strchr(s,'.')==0 && !parse()) return false;
					p=-1;
				}
			}
		}
	}

	rep(j,w){
		int p=-1;
		rep(i,h+1){
			if(i<h && B[i][j]!='#'){
				if(p==-1) p=i;
			}
			else{
				if(p!=-1){
					rep(k,i-p) s[k]=B[p+k][j];
					s[i-p]='\0';
					if(strchr(s,'.')==0 && !parse()) return false;
					p=-1;
				}
			}
		}
	}

	return true;
}

char key[10];
int n,qx[10],qy[10];
bool dfs(int k,bool *used){
	if(k==n) return true;

	rep(l,n) if(!used[l]) {
		used[l]=true;
		B[qy[k]][qx[k]]=key[l];

		bool ok=true;
		int x1=qx[k],x2=qx[k];
		while(x1>=0 && B[qy[k]][x1]!='#') x1--; x1++;
		while(x2< w && B[qy[k]][x2]!='#') x2++;
		rep(j,x2-x1) s[j]=B[qy[k]][x1+j];
		s[x2-x1]='\0';
		if(count(s,s+x2-x1,'.')==0 && !parse()) ok=false;

		int y1=qy[k],y2=qy[k];
		while(y1>=0 && B[y1][qx[k]]!='#') y1--; y1++;
		while(y2< h && B[y2][qx[k]]!='#') y2++;
		rep(i,y2-y1) s[i]=B[y1+i][qx[k]];
		s[y2-y1]='\0';
		if(count(s,s+y2-y1,'.')==0 && !parse()) ok=false;

		if(ok && dfs(k+1,used)) return true;

		used[l]=false;
		B[qy[k]][qx[k]]='.';
	}

	return false;
}

int main(){
	for(;scanf("%d%d",&h,&w),h;){
		rep(i,h) scanf("%s",B[i]);
		scanf("%d",&n);
		rep(i,n) scanf(" %c",key+i);

		n=0;
		rep(i,h) rep(j,w) if(B[i][j]=='.') qx[n]=j, qy[n]=i, n++;

		bool used[10]={};
		puts(calc_no_space()&&dfs(0,used)?"Yes":"No");
	}

	return 0;
}

Measured memory_bytes: 740
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<set>
 
#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
#define P pair<int,int>
#define F first
#define S second
 
using namespace std;


int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << (a * b > c * d ? a * b : c * d) << endl;
}

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

int main() {
    int n;cin>>n;
    int m = 2*n;
    int l[m];rep(i,m)cin>>l[i];
    sort(l,l+m);
    int ans = 0;
    for(int i=0;i<m;i+=2)ans+=l[i];
    cout<<ans<<endl;
	return 0;
}

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

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

    for(int i = 0; i < s.length(); i++){
        if(s[i] != 'a' && 26-(s[i]-'a') <= k){
            k -= 26-(s[i]-'a');
            s[i] = 'a';
        }
    }

    if(k > 0){
        k %= 26;
        s[s.length()-1] = (s[s.length()-1]-'a' + k)% 26 + 'a';
    }

    cout << s << endl;
    return 0;
}

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

struct StCrd
{
  string m_sMrk;
  int    m_nNum;
  int    m_nSeq;
};

void fnInput(int &rnMaxSiz, vector<StCrd> &rvoCrd)
{
  cin >> rnMaxSiz;

  rvoCrd.resize(rnMaxSiz);
  for (int i = 0; i < rnMaxSiz; i++)
  {
    cin >> rvoCrd[i].m_sMrk >> rvoCrd[i].m_nNum;
    rvoCrd[i].m_nSeq = i + 1;
  }
}

int fnPartition(vector<StCrd> &rvoCrd, int nFront, int nBack)
{
  int nMid = nFront;

  for (int i = nFront; i < nBack; i++)
    if (rvoCrd[i].m_nNum <= rvoCrd[nBack].m_nNum)
      swap(rvoCrd[nMid++], rvoCrd[i]);

  swap(rvoCrd[nMid], rvoCrd[nBack]);
  return nMid;
}

void fnQuickSort(vector<StCrd> &rvoCrd, int nFront, int nBack)
{
  if (nFront < nBack)
  {
    int nMid = fnPartition(rvoCrd, nFront, nBack);
    fnQuickSort(rvoCrd, nFront, nMid - 1);
    fnQuickSort(rvoCrd, nMid + 1, nBack);
  }
}

void fnResult(const vector<StCrd> &cnrvoCrd)
{
  bool bStable = true;
  for (int i = 0; i < cnrvoCrd.size();    )
  {
    int j = i;
    while (cnrvoCrd[i].m_nNum == cnrvoCrd[++j].m_nNum)
      if (cnrvoCrd[i].m_nSeq < cnrvoCrd[j].m_nSeq);
      else
      {
        bStable = false; 
        goto LOOP_END;
      }

    i = j;
  }

LOOP_END:
  if (bStable)  cout << "Stable" << endl;
  else          cout << "Not stable" << endl;

  for (int i = 0; i < cnrvoCrd.size(); i++)
    cout << cnrvoCrd[i].m_sMrk << " " << cnrvoCrd[i].m_nNum << endl;
}

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

  int nMaxSiz;
  vector<StCrd> voCrd;

  fnInput(nMaxSiz, voCrd);
  fnQuickSort(voCrd, 0, voCrd.size() - 1);
  fnResult(voCrd);

  return 0;
}

Measured memory_bytes: 7328
a,b,h,m=map(int,input().split())
long_t=h*30+(m/60)*30
short_t=m*6
theta=0
if long_t-short_t>=0:
  theta=long_t-short_t
else:
  theta=short_t-long_t
from math import cos,radians
cos_t=cos(radians(theta))

# c=(a**2+b**2-2*a*b*cos_t)**0.5
c=a**2+b**2-2*a*b*cos_t
print(c**0.5)

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

int	main() {
	int N;
	cin >>N;
	vector<long> A(N);
	for (int i=0; i<N; i++)
		cin >>A.at(i);
	sort(A.begin(), A.end());
	long S=0;
	for (int i=0; i<N/2; i++)
		S +=(A.at(N-1-i)-A.at(i))*2;
	S +=A.at(N/2-1)-A.at(N-N/2);
	if (1==N%2)
		S +=max(A.at(N/2+1)-A.at(N/2), A.at(N/2)-A.at(N/2-1));
	cout <<S <<endl;
	return 0;
};


Measured memory_bytes: 1024
#include <stdio.h>
int main()
{
    char a[4],b[4],c[4];
    scanf("%[^\n]",a);
    scanf(" %[^\n]",b);
    scanf(" %[^\n]",c);
    printf("%c%c%c",a[0],b[1],c[2]);
    return 0;
}


Measured memory_bytes: 128
from sys import stdin,setrecursionlimit
from math import factorial

setrecursionlimit(10 ** 7)

n = int(stdin.readline().rstrip())

li = [stdin.readline().rstrip() for i in range(n)]

name_list = [0]*5

for i in li:
    if i[0] in "MARCH":
        name_list["MARCH".index(i[0])] += 1

point = sum(1 for i in name_list if i != 0)

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))#組み合わせ

from itertools import combinations
lin = list(combinations(name_list, 3))

count = 0

for i in lin:
    if 0 not in i:
        po = 1
        for j in i:
            po *= j
        count += po
print(count)

Measured memory_bytes: 9776
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long K, N;
	cin >> K >> N;
	vector<long long>A(N);
	for (long long i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	for (long long i = 0; i < N; i++) {
		A.push_back(A.at(i) + K);
	}
	long long ans = 9e9;
	for (long long i = 0; i < N; i++) {
		if (ans > A.at(i + N - 1) - A.at(i)) ans = A.at(i + N - 1) - A.at(i);
	}
	for (long long i = 2 * N - 1; i >= N; i--) {
		if (ans > A.at(i) - A.at(i - N + 1)) ans = A.at(i) - A.at(i - N + 1	);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,j;
  double qq;
  scanf("%lf",&qq);
  n=(int)qq;
  j=(int)(100000*qq)-100000*n;
  // cout<<n<<' '<<j<<endl;
  while(n>=0){
    int nn=n;
    int ji[8]={},kyo[4]={},a=0;
    for(int i=0;i<8;i++){
      if(nn%2!=0){
	ji[i]=1;
      }else{
	ji[i]=0;
      }
      nn=nn/2;
      // cout<<nn<<endl;
    }
    if(nn){
      a=1;
    }else{
      int c=50000;
      for(int i=0;i<4;i++){
	//cout<<j<<endl;
	if((j-c)>=0){
	  kyo[i]=1;
	  j-=c;
	}else{
	  kyo[i]=0;
	}
	c/=2;
	//cout<<c<<endl;
      }
    }
    if(j){
      a=1;
    }
    if(a==0){
      for(int i=7;i>=0;i--){
	cout<<ji[i];
      }
      cout<<'.';
      for(int i=0;i<4;i++){
	cout<<kyo[i];
      }
      cout<<endl;
    }else{
      cout<<"NA"<<endl;
    }
    scanf("%lf",&qq);
    n=(int)qq;
    j=(int)(100000*qq)-100000*n;
  }
  return 0;
}



Measured memory_bytes: 3216
import fractions
N,M = map(int,input().split())
S = input(); T = input()
gcd = fractions.gcd(N,M)
N_prime = N //gcd; M_prime = M // gcd
for i in range(0,N,N_prime):
    for j in range(0,M,M_prime):
        if i * M_prime - j * N_prime == 0 and S[i] != T[j]:
            print(-1)
            exit()
print(N*M // gcd)

Measured memory_bytes: 67048
#include<iostream>
using namespace std;
int main(){
    int x,y;
    while(1){
        cin >>x >>y;
        if(x==0&y==0)break;
         
         if(x>=y){
         cout <<y<<" "<<x<<endl;
         }
         else{
         cout <<x<<" "<<y<<endl;
    }
   
    }
    return 0;
}


Measured memory_bytes: 3112
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
#define ll int
using namespace std;
const int MAXN = 100005;
int book[MAXN];
int N, M;

int n;
int a[MAXN]; 
struct tree { int l, r, dat; }t[MAXN << 2];

inline int ls(int p) { return p << 1; }
inline int rs(int p) { return ((p << 1) | 1); }

inline void build(int p, int l, int r) {
	t[p].l = l, t[p].r = r;
	if (l == r) { t[p].dat = a[l]; return ; }
	int mid = (l + r) >> 1;
	build(ls(p), l, mid);
	build(rs(p), mid + 1, r);
	t[p].dat = max(t[ls(p)].dat, t[rs(p)].dat);
}

inline void change(int p, int x, int v) {
	if (t[p].l == t[p].r) { t[p].dat = v; return ; }
	int mid = (t[p].l + t[p].r) >> 1;
	if (x <= mid) change(ls(p), x, v);
	else change(rs(p), x, v);
	t[p].dat = max(t[ls(p)].dat, t[rs(p)].dat);
}

inline int ask(int p, int l, int r) {
	if (l <= t[p].l && r >= t[p].r) return t[p].dat;
	int mid = (t[p].l + t[p].r) >> 1;
	int val = -inf;
	if (l <= mid) val = max(val, ask(ls(p), l, r));
	if (r > mid) val = max(val, ask(rs(p), l, r));
	return val;
}
struct TASK
{
	int t, v;
};
TASK task[MAXN];
bool cmp(TASK a, TASK b)
{
	if(a.v == b.v)
	{
		return a.t < b.t;
	}
	return a.v > b.v;
}
int ans;
int main()
{
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; i++)
	{
		scanf("%d%d", &task[i].t, &task[i].v);
	}
	sort(task + 1, task + 1 + N, cmp);
	for(int i=1;i<=M;i++)
	{
		a[i]=i;
	}
	build(1,1,M);
	for(int i = 1; i <= N; i++)
	{
		if(task[i].t>M)
		{
			continue;
		}
		int time = M - task[i].t + 1;
		int pos=ask(1,1,time);
		if(pos >= 1)
		{
			change(1,pos,-1);
			ans += task[i].v;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
//#include <set>
//#include <map>
//#include <ctime>
//#include <cmath>
//#include <utility>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define ii InputInteger( );
#define f for(int i=0; i<n; i++)
int InputInteger( ){ int x; cin >> x; return x; }
const int Inf = 2147483647;
const char e = '\n';

void iv( vi& p ){ for( int& x: p ) cin >> x; }
void sa( vi& p ){ sort( p.begin(), p.end() ); }
void sd( vi& p ){ sort( p.begin(), p.end(), [](int a, int b){ return a > b; } ); }
void pv( const vi& p ){ for( int x: p ) cout << x << ' '; cout << e; }

int main()
{
	ios_base::sync_with_stdio( false );
	cin.tie( nullptr );
	ll h;
	while( cin >> h )
	{
	    int n = ii;
	    ll sum = 0;
	    vector <int> a(n);
	    f
	    {
	        cin >> a[i];
	        sum += a[i];
	    }
	    if(sum >= h) cout << "Yes";
	    else cout << "No";
	    cout << e;
	}
	return 0;
}

// Kafe's Grandmaster Template 14th



Measured memory_bytes: 640
import Control.Monad
import Data.List

solve :: [(String, Int)] -> [(String, Int)] -> [Int]
solve [] _ = []
solve ((name, inc):ss) t = case lookup name t of
  Just dec -> (inc - dec) : solve ss t
  Nothing  -> inc : solve ss t

main :: IO ()
main = do
  let convert = map (\x -> (head x, length x)) . group . sort
  n <- readLn
  ss <- convert <$> replicateM n getLine
  m <- readLn
  ts <- convert <$> replicateM m getLine
  print . max 0 $ maximum $ solve ss ts


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

ll n;
vector<ll> h;
ll a,b;

bool solve(ll k){
	ll t=0;
	ll q=a-b;
	for (ll i = 0; i < h.size(); i++) {
		ll tmp=ll(h[i])-ll(k)*ll(b);
		if(tmp>0)t+=(tmp%q==0)?tmp/q:(tmp/q+1);
	}
	return k>=t;
}

int main(void)
{
	cin>>n>>a>>b;
	for (ll i = 0; i < n; i++) {
		ll t;
		cin>>t;
		h.push_back(t);
	}
	ll l=1,r=ll(1e9);
	while(l<r){
		ll mid=(l+r)/2;
		if(solve(mid)){
			r=mid;
		}
		else l=mid+1;
	}
	cout<<l<<endl;
	return 0;
}
	

Measured memory_bytes: 1400
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    switch(a)
    {
        case 0: {

                    cout<<b+b/100<<endl;
                    break;
                }
        case 1: cout<<(b+b/100)*100; break;
        case 2: cout<<(b+b/100)*100*100; break;
        default :  ;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
 
int main(){
    int n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    a--;b--;c--;d--;
    string s;
    cin>>s;
    if(c<d){
        int sum=0,tmp=0;
        for(int i=a+1;i<d;i++){
            if(s[i]=='#') tmp++;
            else{
                sum=max(sum,tmp);
                tmp=0;
            }
        }
        if(sum>=2) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }else{
        int sum=0,tmp=0;
        for(int i=a+1;i<d;i++){
            if(s[i]=='#') tmp++;
            else{
                sum=max(sum,tmp);
                tmp=0;
            }
        }
        int flag=0;
        for(int i=b;i<=d&&i<n;i++){
            if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.') flag=1;
        }
        if(sum>=2 || flag==0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
lld fac_ (lld n)
{
	lld min = MAX;
	for(lld i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			lld y = n/i;
			if (i+y-2 < min)
			{
				min = i+y-2;
			}
		}
	}
	return min;
}
int main ()
{
	FastIO
	lld n, i;
	cin >> n;
	cout << fac_(n);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                while (true) {
                        int N = sc.nextInt();
                        if (N == 0) {
                                return;
                        }
                        int WF[][] = new int[10][10];
                        for (int i = 0; i < 10; i++) {
                                for (int j = 0; j < 10; j++) {
                                        WF[i][j] = 1 << 25;
                                }
                                WF[i][i] = 0;
                        }
                        for (int i = 0; i < N; i++) {
                                int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
                                WF[a][b] = Math.min(WF[a][b], c);
                                WF[b][a] = WF[a][b];
                        }
                        for (int k = 0; k < 10; k++) {
                                for (int i = 0; i < 10; i++) {
                                        for (int j = 0; j < 10; j++) {
                                                WF[i][j] = Math.min(WF[i][j], WF[i][k] + WF[k][j]);
                                                WF[j][i] = WF[i][j];
                                        }
                                }
                        }
                        int ans = 0;
                        int minlen = 1 << 25;
                        for (int i = 0; i < 10; i++) {
                                int tmp = 0;
                                boolean f = false;
                                for (int j = 0; j < 10; j++) {
                                        if (i!=j && WF[i][j] != 1 << 25) {
                                                tmp += WF[i][j];
                                                f = true;
                                        }
                                }
                                if (f && tmp < minlen) {
                                        ans = i;
                                        minlen = tmp;
                                }
                        }
                        System.out.println(ans + " " + minlen);
                }
        }
}

Measured memory_bytes: 26384
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define	pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigint        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(aint(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 

template <typename T>
T ceil(T a, T b){ return (a+b-1)/b; }

template<typename T>
T binpow(T a, T b) {
    T res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void solve(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    stack<int> r, w;
    FOR(i, 0, n) {
        if(s[i]=='R'){
            r.push(i);
        }
    }
    for(int i=n-1;i>=0;i--) {
        if(s[i]=='W'){
            w.push(i);
        }
    }
    if(w.empty() or r.empty()){
        cout<<0<<endl;
        return;
    }
    int i=w.top(), j = r.top(), cnt=0;
    while(i<j and !r.empty() and !w.empty()) {
        i=w.top(), j = r.top();
        if(i>j){
            break;
        }
        w.pop(), r.pop();
        swap(s[i], s[j]);
        cnt++;
    }
    FOR(i, 1, n) {
        if(s[i-1]=='W' and s[i]=='R')cnt++;
    }
    cout<<cnt<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);     
    int t=1;
    //cin>>t;
    FOR(i, 1, t+1){ 
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
 
}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll M,N,K;
vector<P> G[500005];
vector<P> lis_x[100005];
vector<P> lis_y[100005];

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

    cin >> M >> N >> K;

    lis_x[1].push_back(P(1,0));

    for (ll i = 0;i < K;i++){
        ll x,y; cin >> x >> y;
        lis_x[x].push_back(P(y,i+1));
        lis_y[y].push_back(P(x,i+1));
    }

    lis_x[M].push_back(P(N,K+1));
    lis_y[N].push_back(P(M,K+1));

    for (ll i = 0;i <= M;i++){
        if(!lis_x[i].size()) continue;
        sort(lis_x[i].begin(),lis_x[i].end());
        P p = lis_x[i][0];
        for (ll j = 1;j < lis_x[i].size();j++){
            //cout << i << " " <<  p.first << endl;
            G[p.second].push_back(P(lis_x[i][j].second,lis_x[i][j].first-p.first));
            G[lis_x[i][j].second].push_back(P(p.second,lis_x[i][j].first-p.first));
            p = lis_x[i][j];
        }
        //cout << endl;
    }

    for (ll i = 0;i <= N;i++){
        if(!lis_y[i].size()) continue;
        sort(lis_y[i].begin(),lis_y[i].end());
        P p = lis_y[i][0];
        for (ll j = 1;j < lis_y[i].size();j++){
            G[p.second+(K+2)].push_back(P(lis_y[i][j].second+(K+2),lis_y[i][j].first-p.first));
            G[lis_y[i][j].second+(K+2)].push_back(P(p.second+(K+2),lis_y[i][j].first-p.first));
            p = lis_y[i][j];
        }
    }

    for (ll i = 0;i <= K+2;i++){
        if(i%(K+2)){
            G[i].push_back(P(i+K+2,1));
            G[i+K+2].push_back(P(i,1));
        }
    }

    priority_queue<P,vector<P>, greater<P>> que;
    ll dist[500005];
    //fill(dist,dist+K*2+5,ll_MAX);
    for (ll i = 0;i < 500000;i++){
        dist[i] = LLONG_MAX;
    }
    dist[0] = 0;
    que.push(P(0,0));

    while(que.size()){
        P p = que.top(); que.pop();
        ll from = p.second;
        ll sum = p.first;
        if(dist[from] < sum) continue;
        //cout << from << " " << sum << endl;
        for (ll i = 0;i < G[from].size();i++){
            ll to = G[from][i].first;
            ll cost = G[from][i].second;
            if(dist[from]+cost < dist[to]){
                dist[to] = dist[from]+cost;
                que.push(P(dist[to],to));
            }
        }
    }

    ll ans = min(dist[K+1],dist[K+1+K+2]);
    if(ans == LLONG_MAX) ans = -1;

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 68280
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		boolean OK = false;
		for(long n = 1; n <= 3500; n++) {
			for(long h = 1; h <= 3500; h++) {
				if(n * (2 * h - N) + h * (2 * n - N) <= 0) continue;
				if(n * h * N % ((long)4 * n * h - n * N - h * N) == 0) {
					System.out.println(h+" "+n+" "+(n * h * N / ((long)4 * n * h - n * N - h * N)));
					OK = true;
					break;
				}
			}
			if(OK) break;
		}
	}
}


Measured memory_bytes: 23252
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        G[a].append(b)
        G[b].append(a)
    
    red, black = list(), list()
    visited = [False] * N
    stack = [(0, True)]
    visited[0] = True
    while stack:
        v, is_red = stack.pop()
        if is_red: red.append(v)
        else: black.append(v)
        for to in G[v]:
            if visited[to]: continue
            visited[to] = True
            stack.append((to, not is_red))
    if len(red) < len(black): red, black = black, red

    ans = [0] * N
    if len(black) <= N//3:
        n3 = 3
        for v in black: ans[v], n3 = n3, n3 + 3
        n = 1
        for v in red:
            if n3 <= N: ans[v], n3 = n3, n3 + 3
            else:
                ans[v], n = n, n + 1
                if n%3 == 0: n += 1
    else:
        n1, n2, n3 = 1, 2, 3
        for v in black:
            if n1 <= N: ans[v], n1 = n1, n1 + 3
            else: ans[v], n3 = n3, n3 + 3
        for v in red:
            if n2 <= N: ans[v], n2 = n2, n2 + 3
            else: ans[v], n3 = n3, n3 + 3
    print(*ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 103500
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

int main() {
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int cnt = 0;
    rep(i, 3001) {
        rep(j, 3001) {
            int rg = r * i + g * j;
            if (rg <= n && (n - rg) % b == 0) cnt++;
        }
    }
    cout << cnt << endl;
}


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

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N+1), B(N);
    rep(i, N+1) cin >> A[i];
    rep(i, N) cin >> B[i];

    ll res = 0;
    rep (i, N) {
        ll attack = min(B[i], A[i]);
        res += attack;
        B[i] -= attack;
        attack = min(B[i], A[i+1]);
        A[i+1] -= attack;
        res += attack;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1792