akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#define ll long long
#define skip cin>>ws;
#define vll vector<ll> 
#define vb vector<bool>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define vs vector<string>
#define vvpll vector<vector<pair<ll, ll>>>
#define pb push_back
#define pob pop_back()
#define MOD (ll)(1e9 + 7)
#define test ll t; cin>>t; while(t--)

using namespace std;

void enter(vll &ar)
{
    ll n = ar.size();
    for(ll i=0;i<n;i++) cin>>ar[i];
}

void show(vll &a)
{
    ll n = a.size();
    for(ll i=0;i<n;i++) cout<<a[i]<<" ";
    cout<<"\n";
}

void SieveOfErat1sthenes(ll n, vll &pri) 
{ 
    vb prime(n+1, true); 
   
    for (ll p=2; p*p<=n; p++) 
    { 
        
        if (prime[p] == true) 
        { 
            pri.pb(p);
            
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}


struct segtree
{
    ll size;
    vector<long long> values;

    void init(ll n)
    {
        size = 1;

        while(size<=n)
        {
            size *= 2;
        }

        values.assign(2*size, 0LL);
    }

    void set(ll i, ll v, ll x, ll lx, ll rx)
    {
        if(rx-lx ==1)
        {
            values[x] = v;
            return;
        }

        ll m = (lx+rx)/2;

        if(i<m)
        {
            set(i, v, 2*x + 1, lx, m);
        }
        else
        {
            set(i, v, 2*x + 2, m, rx);
        }

        values[x] = max(values[2*x +1],  values[2*x + 2]);
    }

    void set(ll i, ll v)
    {
        set(i, v, 0, 0, size);
    }

    long long maxi(ll l, ll r, ll x, ll lx, ll rx)
    {
        if( lx >= r || rx <= l) return 0;
        if( lx >= l && rx <= r) return values[x];

        ll m = (lx + rx)/2;

        long long s1 = maxi(l, r, 2*x + 1, lx, m);
        long long s2 = maxi(l, r, 2*x + 2, m, rx);
        return max(s1, s2);
    }

    long long maxi(ll l, ll r)
    {
        return maxi(l, r, 0, 0, size);
    }

};

ll mo(ll a)
{
    return a%MOD;
}

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

    ll n;
    cin>>n;

    vll h(n), a(n);
    enter(h);
    enter(a);

    ll k = n + 1;

    segtree st;
    st.init(k);

    for(ll i=0;i<n;i++)
    {
        ll ma = st.maxi(0, h[i]);
        st.set(h[i], a[i]+ma);
    }

    ll ans = st.maxi(0, n + 1);

    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 10584
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>
#include <vector>

#define INF (int)1e8+1
#define EPS 1e-10
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cout << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
int W, H;
const int MAX_WH = 1e5;
vector<pair<int, int> > pq;

void solve() {
  // p, qをソート
  sort(all(pq));;
  int a = W + 1, b = H + 1;
  ll ans = 0;
  for (auto e : pq) {
    if (e.second == 0) {
      ans += (ll)e.first * b;
      a--;
    } else {
      ans += (ll)e.first * a;
      b--;
    }
  }

  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> W >> H;
  REP(i, W) {
    int t;
    cin >> t;
    pq.emplace_back(t, 0);
  }
  REP(i, H) {
    int t;
    cin >> t;
    pq.emplace_back(t, 1);
  }
  solve();
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    int n, m, s = 0;
    cin >> n >> m;
    vector<vector<int>> matrix(n, vector<int>(m));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> matrix[i] [j];
            s += matrix[i] [j];
        }
    }

    for (int i = 0; i < n; i++){
        int k = 0;
        for (int j = 0; j < m; j++){
            cout << matrix[i][j] << " ";
            k += matrix[i][j];
        }
        cout << k << endl;
    }

    

    for (int i = 0; i < m; i++){
        int l = 0;
        for (int j = 0; j < n; j++){
            l += matrix[j][i];
        }
        cout << l << " ";
        if (i == m-1){
            cout << s << endl;
        }
    }
}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll n, k; cin >> n >> k;
  vll a(n); rep(i, n) cin >> a[i];
  ll ans = 0, flag = 0;
  while(1)
  {
    flag++;
    ans += k;
    if(ans >= n) { fin(flag) exit(0); }
    ans--;
  }
  return;
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll factorial(ll n) {//階乗
	if (n > 0) {
		ll b = n * factorial(n - 1);
		return b;
	}
	else {
		return 1;
	}
}

ll ncr(ll n, ll r) {
	return factorial(n) / (factorial(r) * (factorial(n - r)));
}
signed main() {
	ll n, a, b, c, d;

	scnaf("%lld %lld %lld %lld %lld", &n, &a, &b, &c, &d);

	n -= 1;
	REP(i, n +  1) {
		
		ll st, cn = n - i;
		if (a - d * i + c * cn <= b && a - c * i + d * cn >= b) {
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())

mod = 10**9+7

# (2**n-1)-nCa-nCb

sum_n = pow(2, n, mod)-1
# print(sum_n)
child = 1
mother = 1

for i in range(0, a):
    child *= (n-i)
    child %= mod  # 分子

    mother *= (i+1)
    mother %= mod
# print(mother)
# mod-2はフェルマーの小定理によるchild/mother ->child*(mother**(mod-2)) -2が出てくる理由はhttps://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#3-4-fermat-%E3%81%AE%E5%B0%8F%E5%AE%9A%E7%90%86%E3%81%AB%E3%82%88%E3%82%8B%E9%80%86%E5%85%83%E8%A8%88%E7%AE%97
hate_a = child * pow(mother, mod-2, mod) % mod

child = 1
mother = 1

for i in range(0, b):
    child *= (n-i)
    child %= mod  # 分母

    mother *= (i+1)
    mother %= mod

hate_b = child * pow(mother, mod-2, mod) % mod

print((sum_n-hate_a-hate_b) % mod)


Measured memory_bytes: 8968
h,w = gets.split.map &:to_i
a = h.times.map { gets.split.map &:to_i }

pos = -> i {
  y = i / w
  x = y.even? ? i % w : w - i % w - 1
  [y,x]
}

ans = []
0.upto(h*w-2) do |i|
  y,x = pos[i]
  ny,nx = pos[i+1]

  if a[y][x].odd?
    a[y][x] -= 1
    a[ny][nx] += 1
    ans << [y+1,x+1,ny+1,nx+1].join(" ")
  end
end

puts ans.size
ans.each do |s|
  puts s
end



Measured memory_bytes: 37116
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int H, W;
    cin >> H >> W;

    int c[10][10];
    REP(i, 10) REP(j, 10) cin >> c[i][j];

    int a[10];
    REP(i, 10) a[i] = 0;
    REP(i, H) REP(j, W) {
        int tmp;
        cin >> tmp;
        if (tmp < 0) continue;
        a[tmp] += 1;
    }

    REP(k, 10) REP(i, 10) REP(j, 10){
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    }

    ll ans = 0;
    REP(i, 10) {
        ans += c[i][1] * a[i];
    }

    cout << fixed << setprecision(20);
    cout << ans << endl;

}


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

int main(){
  int a[3];
  int ans;
  cin >> a[0] >> a[1] >> a[2];

  int max=a[0];
  for(int i=1;i<3;i++){
    if(max<a[i]) max=a[i];
  }
  cout << a[0]+a[1]+a[2]-max << 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++)
#define REP(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<int>> G;
    vector<vector<int>> x(2005,vector<int>(2005));
    vector<vector<int>> y(2005,vector<int>(2005));
    rep(i,h){
        string tmp;
        cin>>tmp;
        vector<int> s;
        rep(j,w){
            if(tmp[j]=='#') s.emplace_back(0);
            else s.emplace_back(1);
        }
        G.emplace_back(s);
    }
    rep(i,h){
        rep(j,w){
            if(G[i][j]==0) x[i][j]=0;
            else if(j==0) x[i][j]=1;
            else x[i][j]=x[i][j-1]+1;
        }
    }
    rep(i,h){
        for(int j=w-2;j>=0;j--){
            if(x[i][j]==0) continue;
            if(x[i][j+1]>x[i][j]) x[i][j]=x[i][j+1];
        }
    }

    rep(j,w){
        rep(i,h){
            if(G[i][j]==0) y[i][j]=0;
            else if(i==0) y[i][j]=1;
            else y[i][j]=y[i-1][j]+1;
        }
    }

    rep(j,w){
        for(int i=h-2;i>=0;i--){
            if(y[i][j]==0) continue;
            if(y[i+1][j]>y[i][j]) y[i][j]=y[i+1][j];
        }
    }
    ll ans=0;
    rep(i,h){
        rep(j,w){
            ll tmp=x[i][j]+y[i][j]-1;
            ans=max(ans,tmp);
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 47488
# coding: utf-8
n = int(input())
h = list(map(int,input().split()))
dp = [0] * n
dp[1] = abs(h[0]-h[1])
for i in range(2, n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

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

int main(){
  
  int N;
  int i, j, k;
  cin >> N;
  vector<int> A(N);
  vector<vector<int>> x(N);
  vector<vector<int>> y(N);
  
  int _x, _y;
  for (i = 0; i < N; i++){
    cin >> A.at(i);
    for (j = 0; j < A.at(i); j++){
      
      cin >> _x >> _y;
      x.at(i).push_back(_x);
      y.at(i).push_back(_y);
    }
  }
  
  int MxNumHnstP = 0;
  //bitで全ての組み合わせをループ
  for (i = 0; i < (1 << N); i++){
    
    //ビットを抽出
    bitset<15> Kumi(i);
      
    //ビット列の本当のことを言っている人に対してのループ
    for(j = 0; j < N; j++){
      if(Kumi[j] == 1){
        
        //一人の全ての証言に対するループ
        for (k = 0; k < A.at(j); k++){
          
          //cout << (Kumi[x.at(j).at(k) - 1] != y.at(j).at(k)) << endl;
          //x.at().at() 番目の人が y.at().at() になっているかを判定（間違っていたらこのbit列は終わり）
          if (Kumi[x.at(j).at(k) - 1] != y.at(j).at(k)){goto OUT;}

        }
      }
    }
    
    //回りきったらそのbit列の1の数をMxNumHnstPとして更新
    MxNumHnstP = max(MxNumHnstP, (int) Kumi.count());      
OUT:
    continue;
  }
  cout << MxNumHnstP << endl;
}

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


int dx[]={1,-1,0, 0,-1,1,-1, 1};
int dy[]={0, 0,1,-1, 1,1,-1,-1};
char s[100][100];

int main(){
	int h,w;
	cin >> h >> w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> s[i][j];
		}
	}
	
	int cnt;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(s[i][j]=='#') continue;
			
			cnt=0;
			for(int k=0;k<8;k++){
				int dxx=i+dx[k],dyy=j+dy[k];
				if(dxx<0||dyy<0 || dxx>=h||dyy>=w) continue;
				if(s[dxx][dyy]=='#') cnt++;
			}
			s[i][j]=char(cnt+'0');
		}
	}
	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cout << s[i][j];
		}
		cout << endl;
	}
	return 0;
}

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

int main(){
  long long n;
  cin >> n;
  
  long long ans = 0, div = 10;
  while(div <= n){
    ans += n / div;
    div *= 5;
  }
  if(n %2) ans = 0;
  
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;cin>>n;
    string s;cin>>s;
    if(n >= 3200){
        cout << s << endl;
    }else{
        cout << "red" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define ll long long
#define endl "\n"
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define f first
#define s second
#define vecll vector<ll>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<ll,ll>>
#define mapllll map<ll,ll>
#define mapstrll map<string,ll>
#define mapllvecll map<ll,vecll>
#define setll set<ll>
#define fio ios_base::sync_with_stdio (false); cin.tie (NULL); cout.tie(NULL);
 
using namespace std;
 
ll const N=1e5+5;
ll const inf=1e18+5;
ll const MOD=1e9+7;
 
ll t,n,m,x,y,z,w,k;
 
int main()
{
    fio
 
    cin>>n;
 
    ll ans = 0;
    for(ll i=1;i<=n;i++)
    {
        if(i%3 == 0 || i%5 == 0)    continue;
        ans += i;
    }
    cout<<ans;
    return 0;
}

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

int main() {
    int A, B;
    int answer;
    cin >> A >> B;
    if(B > 0) {
        if((A + B) > (A * B)) answer = A + B;
        else answer = A * B;
    } else {
        if((A - B) > (A * B)) answer = A - B;
        else answer = A * B;
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

vector<long long> a;

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

  a.resize(N);
  vector<long long> indices(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    indices[i] = i;
  }

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

  long long ret = 0;
  long long sum = 0;
  for (int i = 0; i < N; ++i) {
    if (i == 0) {
      sum += a[i];
      ret = 1;
    } else {
      if (a[i] > 2 * sum) {
        sum += a[i];
        N -= ret;
      } else {
        sum += a[i];
        ++ret;
      }
    }
  }

  cout << N << endl;

  return 0;
}

Measured memory_bytes: 1792
def main():
    size = int(input())
    data = [0]*size

    n = input().split()

    for i in range(0,len(n)):
        data[i] = int(n[i])

    max = data[0]

    for i in range(1,len(data)):
       if data[i] <= max:
           max = data[i]

    min = data[0]

    for i in range(1,len(data)):
        if data[i] >= min:
            min = data[i]

    total = 0

    for num in data:
        total += num

    print("{0} {1} {2}".format(max,min,total))

if __name__ == "__main__":
    main()

Measured memory_bytes: 6680
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define int long long
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define F first
#define S second
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};


signed main(){
  int a,b;
  cin>>a>>b;
  b+=a*3;
  cout<<b/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
    #define debug(...) printf(__VA_ARGS__)
#else
    #define debug(...) (void)0
#endif
#define MP make_pair
#define PB push_back
#define LL long long
#define pii pair<int,int>

#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
//const int inf = 0x7fffffff; //beware overflow
//const LL INF = 0x7fffffffffffffff; //beware overflow
#define mem(x, y) memset(x, (y), sizeof(x) );
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
     return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
    s << "[ ";
    for (auto it : c) s << it << " ";
    s << "]";
    return s;
}
template<typename T>
ostream& operator << (ostream &o, const set<T> &st) {
    o << "{";
    for (auto it=st.begin(); it!=st.end(); it++) o << (it==st.begin() ? "" : ", ") << *it;
    return o << "}";
}
template<typename T1, typename T2>
ostream& operator << (ostream &o, const map<T1, T2> &mp) {
    o << "{";
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        o << (it==mp.begin()?"":", ") << it->fi << ":" << it->se;
    }
    o << "}";
    return o;
}
inline LL getint(){
   LL _x=0,_tmp=1; char _tc=getchar();
   while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
   if( _tc == '-' ) _tc=getchar() , _tmp = -1;
   while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
   return _x*_tmp;
}
#define maxn 100005
LL a[maxn];
LL ps[maxn];
int main() {
    int n=getint();
    for(int i=0;i<n;i++)a[i]=getint();
    sort(a, a+n);
    partial_sum(a, a+n, ps);
    int i;
    for(i=n-2;i>=0;i--) {
        if( ps[i]*2 < a[i+1] ) break;
    }
    cout << n-1-i << endl;
}



Measured memory_bytes: 1792
#include <iostream>
typedef long long int ll;
#define rep(i,k,n) for(int i=k;i<n;++i)

int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    ll a,b,c,k;
    std::cin >> a >> b >> c >> k;
    ll ans=0;
    if(a>=k){
        ans+=k*1;
    } else if(a<k){
        ans+=a*1;
        if(b>=(k-a)){
            
        } else if(b<(k-a)){
            ans+=(k-a-b)*(-1);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3636
fun powerMod(x: Int, n: Int, mod: Int): Int = when {
    n == 0 -> 1
    n % 2 == 1 -> ((powerMod(x, n - 1, mod).toLong() * x.toLong()) % mod).toInt()
    else -> {
        val tmp = (powerMod(x, n / 2, mod) % mod).toLong()
        ((tmp * tmp) % mod).toInt()
    }
}

fun main() {
    val n = readLine()!!.toInt()
    val mod = 1_000_000_000 + 7
    val res = powerMod(10, n, mod) - (powerMod(9, n, mod) + powerMod(9, n, mod) - powerMod(8, n, mod)) % mod
    println((res + mod) % mod)
}


Measured memory_bytes: 34592
#include <iostream>
using namespace std;
int n,a[10005],b[10005],i,j,Max=0,sm,ct;
int main()
{


    cin>>n;

    for (i=1;i<=n;++i)

        cin>>a[i];


    for (i=1;i<=n;++i)

        cin>>b[i];


    for (i=1;i<=n;i++)
    {
        for (j=1;j<=i;j++) sm+=a[j];
        for (j=i;j<=n;j++) sm+=b[j];
        Max=max(Max,sm);
        sm=0;
    }
    cout<<Max<<endl;
    return 0;
}


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

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef pair < int , int > pp;
//const int mod = 1e9 + 7;
const int N   = 3e3 + 3;

ll C[N][N],dp[N][N],F[N],M[N],T[N],n,mod,ans,i,j,k,t,x,p;

ll fast(ll a, ll b){
    ll t = 1;
    a = a % mod;
    for(; b ; b >>= 1){
        if(b & 1) t = t*a % mod;
        a = a*a % mod;
    }
    return t;
}

ll f(int i, int k){
    if(i == 0) return k == 0;
    if(k < 0) return 0;
    ll &r = dp[i][k];
    if(r != -1) return r;
    return r = (f(i-1,k) + f(i-1,k-1) + f(i-1,k) * k) % mod;
}

int main(){
    cin >> n >> mod;
    for(i=0;i<=n;i++)
        for(C[i][0]=j=1;j<=i;j++)
            C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;


    memset(dp , -1 , sizeof dp);
    for(i=1;i<=n;i++){
        t = fast(2,n-i);
        for(M[i]=p=j=1;j<=i;j++){
            p = p * t % mod;
            M[i] = (M[i] + f(i,j) * p) % mod;
        }
    }

    for(T[0]=2,i=1;i<=n;i++) T[i] = T[i-1] * T[i-1] % mod;
    ans = T[n];
    for(i=1;i<=n;i++){
        t = M[i] * C[n][i] % mod * T[n-i] % mod;
        if(i&1) ans -= t;
        else ans += t;
        ans = ans % mod;
    }

    cout << (ans + mod) % mod;
    return 0;
}

Measured memory_bytes: 141312
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>
#include <queue>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int digit_sum(int n) {
  int sum = 0;
  while(n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

  int N; cin>>N;
  int imin = INF;
  for(int i=1; i<N; i++) {
    int a = i;
    int b = N - a;
    int n = digit_sum(a) + digit_sum(b);
    // imin = min(imin, n);
    if(imin > n) {
      imin = n;
      // cout << "a:" << a << endl;
      // cout << "b:" << b << endl;
    }
  }

  cout << imin << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << endl;
#else
#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

void solve()
{
	int n;
	cin >> n;	

	int x = n + !(n % 2);
	vector<pii> ans;

	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j < i; ++j)
		{
			if(i + j == x)
				continue;

			//cout << i << " " << j << endl;
			ans.emplace_back(i, j);
		}
	}

	cout << ans.size() << endl;

	for(auto el: ans)
		cout << el.first << " " << el.second << endl;
}

int main(int argc, char** argv)
{
	fast_io();
	solve();

	return 0;
}


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

using namespace std;

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

class C {
	int ROWS, COLUMNS;
	vector<string> picture;

public:
	void solve()
	{
		for (int y{ 0 }; y < ROWS; y++)
		{
			for (int x{ 0 }; x < COLUMNS; x++)
			{
				if ((picture[y][x] == '#') && !dfs(x, y, true))
				{
					cout << "No" << endl;
					return;
				}
			}
		}
		cout << "Yes" << endl;
	}
	
	bool dfs(const int& x, const int& y, bool isFirstElem)
	{
		if (picture[y][x] == '.')
			return false;

		picture[y][x] = '.';

		if (!isFirstElem)
		{
			int x_visiting, y_visiting;
			for (int i{ 0 }; i < 4; i++)
			{
				x_visiting = x + dx[i];
				y_visiting = y + dy[i];
				if ((0 <= x_visiting && x_visiting < COLUMNS) && (0 <= y_visiting && y_visiting < ROWS) && picture[y_visiting][x_visiting] == '#')
					dfs(x_visiting, y_visiting, false);
			}

			return true;
		}
		else
		{
			bool flag{ false };
			int x_visiting, y_visiting;

			for (int i{ 0 }; i < 4; i++)
			{
				x_visiting = x + dx[i];
				y_visiting = y + dy[i];
				if ((0 <= x_visiting && x_visiting < COLUMNS) && (0 <= y_visiting && y_visiting < ROWS))
					flag |= dfs(x_visiting, y_visiting, false);
			}

			return flag;
		}
	}


	C()
	{
		cin >> ROWS >> COLUMNS;
		picture.resize(ROWS);

		for (int y{ 0 }; y < ROWS; y++)
		{
			cin >> picture[y];
		}
	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 20
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P; 
#define INF 100000000
const int MAX = 1000000;
const int MOD = 1000000007;

int main(){
    int n;
    string s;
    cin>>n>>s;
    int cnt=0;
    for(int i=0;i<=n-3;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') cnt++;
    }
    OUT(cnt);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

int main(){
    ll n,a,b,c;
    cin >> n >> a >> b >> c;
    string s[n];
    rep(i,n) cin >> s[i];
    char ans[n];
    rep(i,n){
        if(s[i]=="AB"){
            if(a==0&&b==0){
                cout << "No" << endl;
                return 0;
            }
            if(a==0){
                a++; b--;
                ans[i]='A';
            }else if(b==0){
                a--; b++;
                ans[i]='B';
            }else if(a==1&&b==1){
                if(i+1<n&&s[i+1]=="BC"){
                    a--; b++;
                    ans[i]='B';
                }else{
                    a++; b--;
                    ans[i]='A';
                }
            }
            else if(a<b){
                a++; b--;
                ans[i]='A';
            }else{
                a--; b++;
                ans[i]='B';
            }
        }
        if(s[i]=="AC"){
            if(a==0&&c==0){
                cout << "No" << endl;
                return 0;
            }
            if(a==0){
                a++; c--;
                ans[i]='A';
            }else if(c==0){
                a--; c++;
                ans[i]='C';
            }else if(a==1&&c==1){
                if(i+1<n&&s[i+1]=="BC"){
                    a--; c++;
                    ans[i]='C';
                }else{
                    a++; c--;
                    ans[i]='A';
                }
            }else if(a<c){
                a++; c--;
                ans[i]='A';
            }else{
                a--; c++;
                ans[i]='C';
            }
        }
        if(s[i]=="BC"){
            if(b==0&&c==0){
                cout << "No" << endl;
                return 0;
            }
            if(c==0){
                c++; b--;
                ans[i]='C';
            }else if(b==0){
                c--; b++;
                ans[i]='B';
            }else if(c==1&&b==1){
                if(i+1<n&&s[i+1]=="AC"){
                    b--; c++;
                    ans[i]='C';
                }else{
                    b++; c--;
                    ans[i]='B';
                }
            }else if(b<c){
                b++; c--;
                ans[i]='B';
            }else{
                b--; c++;
                ans[i]='C';
            }
        }
        
    }
    cout << "Yes" << endl;
    rep(i,n) cout << ans[i] << endl;
}


Measured memory_bytes: 6836
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

int n,q,p[100010],l[10010],r[10010],sum[45][100010],cnt[45][100010];
bool used[100010];
int s = 0,c = 0;

void dfs(int v){
	if(used[v]) return;
	used[v] = true;
	s += v + 1;
	c++;
	dfs(p[v]);
	sum[c][v + 1] += s;
	cnt[c][v + 1]++;
}

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

signed main(){
	cin >> n >> q;
	for(int i = 0;i < n;i++){
		cin >> p[i]; p[i]--;
	}
	for(int i = 0;i < q;i++){
		cin >> l[i] >> r[i]; l[i]--;
	}
	for(int i = 0;i < n;i++){
		if(!used[i]){
			s = c = 0;
			dfs(i);
		}
	}
	for(int i = 1;i <= 40;i++){
		for(int j = 1;j <= n;j++){
			(sum[i][j] += sum[i][j - 1]) %= MOD;
			cnt[i][j] += cnt[i][j - 1];
		}
	}
	for(int i = 0;i < q;i++){
		int cycle = 1,ans = 0;
		for(int j = 1;j <= 40;j++){
			if(cnt[j][r[i]] - cnt[j][l[i]]) cycle = cycle / gcd(cycle,j) * j;
		}
		for(int j = 1;j <= 40;j++){
			ans = (ans + (sum[j][r[i]] - sum[j][l[i]] + MOD) % MOD * (cycle / j % MOD)) % MOD;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 66672
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 1010100;
char s[N] , t[N];
int n , q[N] , l , r;

int main(){
    scanf("%d",&n);
    scanf("%s%s",s + 1,t + 1);
    if(strcmp(s + 1 , t + 1) == 0) return puts("0") , 0;
    int ans = 0;
    for(int i=n,pos=n;i>=1;--i) if(t[i] != t[i-1]){
        pos = min(i , pos);
        while(pos >= 1 && s[pos] != t[i]) --pos;
        if(pos == 0) return puts("-1") , 0;
        while(l < r && q[l] - i >= (r - l)) ++l;
        if(pos != i) q[r++] = pos , ans = max(ans , r - l);
    }
    printf("%d\n",ans + 1);
    return 0;
}


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

int main() {
  int x, y;
  cin >> x >> y;
  if (x == 4 || x == 6 || x == 9 || x == 11)
    x = 200;
  else if (x == 2)
    x = 300;
  else
    x = 100;

  if (y == 4 || y == 6 || y == 9 || y == 11)
    y = 200;
  else if (y == 2)
    y = 300;
  else
    y = 100;

  if (x == y)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
N, M, X, Y = map(int, input().split())
x = sorted(map(int, input().split()))
y = sorted(map(int, input().split()))
 
if x[-1] < y[0]:
  if Y <= x[-1] or y[0] <= X:
    print('War')
  else:
    print('No War')
else:
  print('War')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
const int S=11e5;
int n,m,nw,f[2][23][S],i,j,k,ml,ans,x,y,z,nxt[S][23];
char c[S];
int main(){
	scanf("%d%d%s",&n,&m,c);
	for(i=1;i<=n;++i){
		scanf("%s",c);
		for(j=0;j<1<<i;++j)f[0][i][j]=c[j]=='1';
	}
	for(i=0;i<S;++i)for(j=19,nxt[i][20]=20;j>=0;--j)
		nxt[i][j]=(i>>j&1)==(i>>j+1&1)?nxt[i][j+1]:j+1;
	for(i=1;i<=n;++i){
		nw^=1;
		for(j=n;j>=i;--j)memcpy(f[nw][j],f[!nw][j],4<<j);
		for(j=n;j>i;--j)for(k=0;k<1<<j;++k){
			if(x=f[!nw][j][k]){
				if(y=nxt[k][i-1],y<j)f[nw][j-(y-(i-1))][(k&((1<<i-1)-1))|(k>>y<<i-1)]+=x;
			}
			f[nw][i][k&((1<<i)-1)]+=f[nw][j][k];
		}
		for(j=(1<<i)-1;j>=0;--j)if(f[nw][i][j]>=m)ans=j,ml=i;
	}
	for(k=ml-1;k>=0;--k)putchar('0'+(ans>>k&1));puts("");
	return 0;
}

Measured memory_bytes: 198912
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;

bool v[200020];
ll d[200020];

int main(){
  ll n,k;
  cin >> n >> k;
  ll a[n];
  rep(i,n){
    cin >> a[i];
    a[i]--;
  }
  ll now=0,from=-1,len=0;
  while(k>0){
    if(v[now]){
//      cout << len-d[now] <<endl;
      k%=len-d[now];
    }
    if(k==0)break;
    v[now]=true;
    d[now]=len;
//    from=now;
    now=a[now];
    k--;
    len++;
//    cout << k << endl;
  }
  cout << now+1 << endl;
return 0;}

Measured memory_bytes: 6940
def solve(n, a):
    b = sum(a) / n
    ans = 0
    best = abs(a[0] - b)
    for i in range(n):
        c = abs(a[i] - b)
        if c < best:
            ans, best = i, c
    return ans

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

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

using namespace std;
using ll = long long;

int main() {
    ll n, k;
    cin >> n >> k;

    double p = 0;
    for (ll num_dice = 1; num_dice <= n; ++num_dice) {
        if (num_dice >= k) {
            p += 1 / (double)n;
            continue;
        }

        ll kaisu = ceil(log2((double)k/num_dice));

        p += (1 / pow(2, kaisu)) / (double)n;
    }

    cout << fixed << setprecision(10) << p << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
int main(){
    string s;
    cin >> s;
    int cnt = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '1')
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,n,count = 0,done=0;
	cin>>n;
	int d1[n],d2[n];
	for(int i=0;i<n;i++)
	{
	 cin>>d1[i]>>d2[i];
	}
	
	for(int i=0;i<n;i++)
	{
	 	if(d1[i] == d2[i])
	  	 count = count + 1 ;
	 	else
	  	 count = 0;
	  
	 	if(count == 3)
	 	{
	  	  cout<<"Yes"<<endl;
	  	  done = 1;
	  	  break;
	 	}
	  
	}
	
	if(done == 0)
	 cout<<"No"<<endl;
 return 0;
}


Measured memory_bytes: 3640
from collections import deque

deq = deque([])

q = int(input())
for i in range(q):
    op = list(map(int, input().split(' ')))
    if op[0] == 0:
        if op[1] == 0:
            deq.appendleft(op[2])
        else:
            deq.append(op[2])
    elif op[0] == 1:
        print(deq[op[1]])
    elif op[0] == 2:
        if op[1] == 0:
            deq.popleft()
        else:
            deq.pop()


Measured memory_bytes: 21936
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll n, k;
    cin >> n >> k;
    VL a(n);
    REP(i,n) a[i] = in();
    ll ok = 1e10, ng = 0;
    while (ok - ng > 1){
        ll x = (ok + ng) / 2;
        ll c = 0;
        REP(i,n){
            c += (a[i] + x - 1) / x - 1;
        }
        if (c <= k) ok = x;
        else ng = x;
    }
    cout << ok << endl;
    return 0;
}


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

int main(){
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    ll cnt = 0;
    rep(i, 0, n){
        if(i == 0 && s[i] == 'L') continue;
        if(i == n-1 && s[i] == 'R') continue;
        if(s[i] == 'R' && s[i+1] == 'R') cnt++;
        if(s[i] == 'L' && s[i-1] == 'L') cnt++;
    }
    ll rem = n - 1 - cnt;
    cerr << cnt << endl;
    if(rem >= 2*k){
        cout << cnt + 2*k << endl;
    }else{
        cout << n-1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <stack>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::stack;

int main(void) {
    string s; 
    stack<char> st; 
    char comp;
    bool check;

    while (getline(cin, s)) {
        if (s[0] == '.') {
            break;
        }
        check = true;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == '(' || s[i] == '[') {
                st.push(s[i]); 
            } else if (s[i] == ')' || s[i] == ']') {
                if (st.empty()) {
                    check = false;
                    break;
                }
                comp = st.top();   
                st.pop();
                if ((comp == '(' && s[i] == ']') || (comp == '[' && s[i] == ')')) {
                    check = false;
                    break;
                }
            }
        }
        if (! st.empty()) {
            check = false;
            while (! st.empty()) {
                st.pop(); 
            }
        }
        if (check == true) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3204
#include <iostream>
#include <iterator>
#include <queue>
#include <vector>

using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    vector<priority_queue<int>> A(n);
    int x, y, z;
    for(int i = 0; i < q; i++){
        cin >> x;
        if(x == 0){
            cin >> y >> z;
            A[y].push(z);
        }else if(x == 1){
            cin >> y;
            if(A[y].empty()){
                continue;
            }else{
                cout << A[y].top() << "\n";
            }
        }else{
            cin >> y;
            if(A[y].empty()){
                continue;
            }else{
                A[y].pop();
            }
        }
    }

    return 0;
}


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

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  
  rep(i, k){
    if(b<=a)b*=2;
    else if(c<=b)c*=2;
  }
  if(c>b&&b>a)cout << "Yes";
  else cout << "No";

  return 0;
}


Measured memory_bytes: 3592
check :: Int -> Int -> Int -> String
check a b c | a + b == c = "Yes"
            | a + c == b = "Yes"
            | b + c == a = "Yes"
            | otherwise = "No"

main = do
      n <- words <$> getLine
      let [a,b,c] = map read n :: [Int]
      putStrLn(check a b c)


Measured memory_bytes: 508
#include<stdio.h>
void yen500(int k,int x);
int main(void){
 
    int K,X;
    scanf("%d %d",&K,&X);
    yen500(K,X);
    return 0;
}
void yen500(int k,int x){
    if(500*k>=x){
        printf("Yes");
    }else{
        printf("No");
    }
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void){

	int a, c, d[20000], n=0, m;
	char b;

	while (1) {
		scanf("%d %c %d", &a, &b, &c);
		if (b == '+')
		{
			d[n] = a + c;
		}
		else if (b == '-')
		{
			d[n] = a - c;
		}
		else if (b == '*')
		{
			d[n] = a * c;
		}
		else if (b == '/')
		{
			d[n] = a / c;
		}
		else if (b == '?')
		{
			break;
		}
		n++;
	}

	for (m = 0; m < n; m++)
	{
		printf("%d\n", d[m]);
	}

	return 0;
}

Measured memory_bytes: 1856
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

ll solve(ll H) { return H == 1 ? 1 : 2 * solve(H / 2) + 1; }

int main() {
  ll H;
  cin >> H;
  cout << solve(H) << endl;
  return 0;
}


Measured memory_bytes: 3424
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, m;
	while (cin >> n >> m) {
		if (!n && !m)return 0;
		vector<int>v;
		for (int i = 0; i < n; i++)v.push_back(i + 1);
		int k = -1;
		while (v.size() != 1) {
			for (int i = 0; i < m; i++){
				k++;
				if (k == v.size())k = 0;
			}
			v.erase(v.begin() + k);
			k--;
		}
		cout << v[0] << endl;
	}
}

Measured memory_bytes: 3052
code = r"""
# distutils: language=c++
# distutils: include_dirs=/opt/atcoder-stl
from libcpp.vector cimport vector
cdef extern from *:
    ctypedef int MOD_t "998244353"
    ctypedef long long ll "long long"
cdef extern from "<atcoder/convolution>" namespace "atcoder" nogil:
    vector[int] convolution[M](vector[int] a, vector[int] b)
    #vector[long] convolution[M](vector[long] a, vector[long] b)
    #vector[ll] convolution[M](vector[ll] a, vector[ll] b)
    vector[ll] convolution_ll(vector[ll] a, vector[ll] b)
from libc.stdio cimport getchar, printf
cdef inline int read() nogil:
    cdef int b, c = 0
    while 1:
        b = getchar() - 48
        if b < 0: return c
        c = c * 10 + b
cdef int n = read(), m = read(), i
cdef vector[int] a = vector[int](n), b = vector[int](m)
for i in range(n): a[i] = read()
for i in range(m): b[i] = read()
cdef vector[int] c = convolution[MOD_t](a, b)
for i in range(n + m - 1): printf('%d ', c[i])
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('solve.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b solve.pyx')
import solve

Measured memory_bytes: 28264
#include <iostream>
#include <cmath>
#include <iomanip>
using std::string;
using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::setprecision;


int main(void){
  int n;
  double s[1500];
  double ave;
  double alpha;

  while(1){
    ave = 0;
    alpha = 0;
    cin >> n;
    if(n == 0){
      break;
    }
    for(int i=0;i < n;i++){
      cin >> s[i];
      ave += s[i];
    }

    ave /= n;
    cout << fixed;
    for(int i = 0;i < n;i++){
      alpha += (ave-s[i])*(ave-s[i]);
    }

    alpha = sqrt(alpha/n);
    cout << setprecision(10) <<  alpha << endl;
  }
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	int N;
	cin >> N;
	int a, prev, flag = 0, flag2 = true;
	cin >> prev;
	int cnt = 0;
	rep(i, N-1) {
		cin >> a;
		//cout << a << " " << prev << " " << flag << endl;
		if(flag2) {
			if(a == prev) {
				prev = a;
				continue;
			}
			if(a < prev) flag = -1;
			if(a > prev) flag = 1;
			prev = a;
			flag2 = false;
			continue;
		}
		if(flag == -1 && a > prev) {
			cnt++;
			flag2 = true;
		}
		else if (flag == 1 && a < prev) {
			cnt++;
			flag = -1;
			flag2 = true;
		}
		prev = a;
	}
	cout << cnt+1 << endl;
	

  return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
//  val l = List.fill(5)(sc.nextInt)
  val h, w = sc.nextInt
  val h2, w2 = sc.nextInt

  val ans = h * w - (h2 * w + w2 * h - h2 * w2)
  println(ans)
}

Measured memory_bytes: 25528
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=405;
int a[N],sum[N],dp[N][N];
main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    sum[0]=a[0];
    for(int i=1;i<n;i++)
        sum[i]=sum[i-1]+a[i];
    for(int i=0;i<n;i++)
        dp[i][i]=0;
    for(int v=1;v<n;v++)
    {
        for(int i=0;i<n-v;i++)
        {
            int j=i+v;
            dp[i][j]=LLONG_MAX/2;
            int tmp=sum[j]-(i>0?sum[i-1]:0);
            for(int k=i;k<j;k++)
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+tmp);
        }
    }
    printf("%lld\n",dp[0][n-1]);
    return 0;
}


Measured memory_bytes: 1536