akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string s;
  cin >> s;
  int n=s.size();
  int ans=999;
  rep(i,n-2){
    int k=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    ans=min(ans,abs(753-k));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
def yumiri(L, n):
  for i in range(len(L)):
    if L[i] > n:
      return i - 1

def parunyasu(a, b, p, q):
  reans = ans
  rd1, rq1, d1, nd1, nq1, q1, _ = naobou(a, q)
  rd2, rq2, d2, nd2, nq2, q2, newans = naobou(b, p)

  if reans < newans:
    t[d1 - 1] = q1
    t[d2 - 1] = q2
    return newans
  else:
    ayaneru(rd2, rq2, d2, nd2, nq2)
    ayaneru(rd1, rq1, d1, nd1, nq1)
    return ans

def ayaneru(rd, rq, d, nd, nq):
  ZL[rd].insert(rq, d)
  del ZL[nd][nq + 1]

def naobou(d, q):
  newans = ans

  rd = t[d - 1] - 1
  rq = yumiri(ZL[rd], d)
  newans += SUMD[ZL[rd][rq] - ZL[rd][rq - 1] - 1] * c[rd]
  newans += SUMD[ZL[rd][rq + 1] - ZL[rd][rq] - 1] * c[rd]
  newans -= SUMD[ZL[rd][rq + 1] - ZL[rd][rq - 1] - 1] * c[rd] 
  del ZL[rd][rq]

  nd = q - 1
  nq = yumiri(ZL[nd], d)
  newans += SUMD[ZL[nd][nq + 1] - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[d - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[ZL[nd][nq + 1] - d - 1] * c[nd]
  ZL[nd].insert(nq + 1, d)

  newans -= s[d - 1][rd]
  newans += s[d - 1][nd]

  return rd, rq, d, nd, nq, q, ans

def rieshon():
  ans = 0
  for i in range(D):
    ans += s[i][t[i] - 1]
    for j in range(26):
      if t[i] - 1 == j:
        L[j] = 0
        ZL[j].append(i + 1)
      else:
        L[j] += 1
        ans -= L[j] * c[j]
  for i in range(26):
    ZL[i].append(D + 1)
  return ans

import time
import random
startTime = time.time()

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

L = [0] * 26
ZL = [[0] for _ in range(26)]
SUMD = [0] * (D + 1)
for i in range(1, D + 1):
  SUMD[i] = SUMD[i - 1] + i

RD = [0] * 26
t = [0] * D
for i in range(D):
  RD[0] += 1
  ma = s[i][0] + RD[0] * c[0]
  man = 0
  for j in range(1, 26):
    RD[j] += 1
    k = s[i][j] + RD[j] * c[j]
    if k > ma:
      ma = k
      man = j
  t[i] = man + 1
  RD[man] = 0

ans = rieshon()
while time.time() - startTime < 1.8:
  l = random.randrange(min(D - 1, 26)) + 1
  d = random.randrange(D - l) + 1
  p = t[d - 1]
  q = t[d + l - 1]
  if p == q: continue
  ans = parunyasu(d, d + l, p, q)

for i in range(D):
  print(t[i])


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

using namespace std;

const int max_n = 55, inf = 1000111222;

int n, x[max_n], y[max_n], used[max_n];

int solve(int p, int q) {
    memset(used, 0, sizeof(used));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (x[i] + p == x[j] && y[i] + q == y[j]) {
                used[j] = 1;
            }
        }
    }
    return n - accumulate(used, used + n, 0);
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }
    int ans = inf;
    if (n == 1) {
        ans = 1;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (i == j) {
                continue;
            }
            ans = min(ans, solve(x[j] - x[i], y[j] - y[i]));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int R;
	cin >> R;

	if (R < 1200)
	{
		cout << "ABC";
	}
	else if (R < 2800)
	{
		cout << "ARC";
	}
	else
	{
		cout << "AGC";
	}

	return 0;
}


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

int main() {
  int H,N; cin >> H >> N;
  int A = 0;
  vector<int>vec(N);
  
  for(int i = 0; i<N; i++){
    cin >> vec.at(i);
    A += vec.at(i);
  }
  
  if(A>=H) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
 
#define N 100001
 
void Partition(int A[], int p, int r){
  int x, i, j;
  int temp;
 
  x = A[r];
  i = p-1;
 
  for(j = p; j <= r-1; j++){
    if(A[j] <= x){
      i = i + 1;
      //--------exchange
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
      //----------------
    }
  }
 
  //--------exchange
  temp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = temp;
 //----------------

  //output
  for(j = 0; j <= r; j++){
    if(j == i + 1) printf("[%d]", A[j]);
    else printf("%d", A[j]);
    if(j != r) printf(" ");
  }
  printf("\n");

}
 
int main(){
  int n, i, p = 0, r;
  int A[N];
 
  //input and initialize
  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &A[i]);
  r = n - 1;
 
  Partition(A, p, r);
 
  return 0;
}

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

int dp[110][10];

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

  int h, w, k;
  cin >> h >> w >> k;

  dp[0][0] = 1;
  FOR(i, 1, 10) dp[0][i] = 0;

  rep(i, h) {
    rep(bit, 1<<w-1) {
      if (bit & (bit << 1)) continue;
      int tmp[10];
      rep(j, w) tmp[j] = dp[i][j];
      rep(j, w-1) {
        if (bit & 1<<j) {
          swap(tmp[j], tmp[j+1]);
        }
      }
      rep(j, w) {
          dp[i+1][j] = (dp[i+1][j] + tmp[j]) % mod;
      }
    }
  }
  cout << dp[h][k-1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N; string S;
  cin >> N >> S;
  for(int i = 0; i < S.size(); i++) {
    int x = ((int)S.at(i) + N);
    if(x > (int)'Z') {
      x %= (int)'Z';
    }
    if(x >= (int)'A') {
      cout << (char)x;
    } else {
      cout << char(x + (int)'A' - 1);
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ins insert
#define sz(x) (long long)x.size()
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5;
const ld pi = 3.141592653;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll INF = __LONG_LONG_MAX__;

using namespace std;

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

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int T = 1;
        //cin>>T;
        while(T--)
        {
                ll n, i, ans = 0;
                cin>>n;
                vector<ll> a(n), suff(n);
                for(i=0; i<n; i++) cin>>a[i];
                suff[n-1] = a[n-1];
                for(i=n-2; i>=0; i--) suff[i] = (suff[i+1] + a[i])%MOD;
                for(i=0; i<n-1; i++) ans = (ans + (a[i] * suff[i+1]) %MOD) %MOD;
                cout<<ans;
        }
        return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for (int i = 0; i < N - 1; ++i) {
    if (S.substr(i, 2) == "OX" || S.substr(i, 2) == "XO")
      ++ans, ++i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3348
#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int i, n, *A;
	scanf("%d", &n);
	A = malloc((n + 1) * sizeof(int));
	for (i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
	}
	for (i = 1; i <= n; i++) {
		printf("node %d: key = %d, ", i, A[i]);
		if (i / 2 > 0) printf("parent key = %d, ", A[i / 2]);
		if (i * 2 <= n) printf("left key = %d, ", A[i * 2]);
		if (i * 2 + 1 <= n) printf("right key = %d, ", A[i * 2 + 1]);
		printf("\n");
	}
	return 0;
}

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

using namespace std;
typedef vector<int> vi;
struct node{
int depth = -1;
int low;
int parent;
bool vis = false;
bool isArti = false;
vi adj;
};

vector<set<int> > biconnected;
stack<int> s;

static node g[100005];
void dfs(int u){
    if(g[u].depth == -1) g[u].depth = g[g[u].parent].depth + 1;
    g[u].low = g[u].depth;
    g[u].vis = true;
    for(int i = 0;i < g[u].adj.size();i++){
        int v = g[u].adj[i];
        if(!g[v].vis){
            g[v].parent = u;
            s.push(u);
            dfs(v);
            g[u].low = min(g[u].low,g[v].low);

            if(g[v].low >= g[u].depth){
                g[u].isArti = true;
                g[u].low = min(g[u].low,g[v].low);
                set<int> newSet;
                int nn;
                biconnected.push_back(newSet);
                do{
                    nn = s.top();
                    s.pop();
                    biconnected.back().insert(nn);
                }while(nn != u);
            }
        }
        else if(v != g[u].parent){
            g[u].low = min(g[u].low,g[v].depth);
        }
        s.push(u);
    }
}
int main()
{
    //freopen("i.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].adj.push_back(b);
        g[b].adj.push_back(a);
    }

    for(int i = 0;i < n;i++){
        if(g[i].adj.size() % 2 == 1){
            cout << "No\n";
            return 0;
        }
    }
    dfs(0);
    if(biconnected.size() >= 3){
        cout << "Yes\n";
        return 0;
    }
    else if(biconnected.size() == 2){
        if(m - n >= 3) cout << "Yes\n";
        else cout << "No\n";
    }
    else{
        if(m - n >= 3) cout << "Yes\n";
        else cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 21888
k,n = map(int, input().split())
a = list(map(int, input().split()))
max = 0
for i in range(n-1):
    if a[i+1] - a[i] >= max:
        max = a[i+1] - a[i]

if k - a[n-1] + a[0] > max:
    print(a[n-1] - a[0])
else:
    print(k - max)

Measured memory_bytes: 26444
#include<iostream>
#include<string>
#include<iomanip>

using namespace std;

#define int long long
#define MAX 110000

const long long MOD = (long long)1e9 + 7;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string L;
	int three = 1, ans = 1;
	static int sum[MAX] = {1,};
	
	cin>>L;
	
	for(int i = 0; i < L.size(); i++){
		sum[i+1] = sum[i];
		if(L[i] == '1') sum[i+1] *= 2, sum[i+1] %= MOD;
	}
	
	for(int i = L.size()-1, temp = 0; i >= 0; i--, three = 3*three%MOD){
		if(L[i] == '1')ans = (ans + (three + 1)*sum[i])%MOD;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1232
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int aPrice = sc.nextInt();
		int bPrice = sc.nextInt();
		int abPrice = sc.nextInt();
		int aPizzaCnt = sc.nextInt();
		int bPizzaCnt = sc.nextInt();
		sc.close();
		int abPizzaCnt = (aPizzaCnt > bPizzaCnt)? aPizzaCnt*2:bPizzaCnt*2;
		int defaultPrice = (aPrice*aPizzaCnt) + (bPrice*bPizzaCnt);
		int gattaiPrice = abPizzaCnt * abPrice;
		int sabunPrice = (((aPizzaCnt > bPizzaCnt)? bPizzaCnt*2:aPizzaCnt*2) * abPrice)
				+ ((aPizzaCnt > bPizzaCnt)? (aPizzaCnt-bPizzaCnt)*aPrice:
					(bPizzaCnt-aPizzaCnt)*bPrice);
		if(gattaiPrice > sabunPrice) gattaiPrice = sabunPrice;
		System.out.println((defaultPrice > gattaiPrice)?gattaiPrice:defaultPrice);
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
#define mem(i, a) memset(i, a, sizeof(i))
#define sqr(x) ((x)*(x))
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
typedef long long ll;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
// const int maxn = e + 7;
using namespace std;
int main(void){
#ifdef ljxtt
freopen("data.in", "r", stdin);
#endif
    int n; cin >> n;
    bool ans = 0;
    while(n){
        int t = n % 10;
        if(t == 7) ans = 1;
        n /= 10;
    }
    if(ans) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ff first
#define ss second
#define input(a) scanf("%lld",&a)
#define M 1000000007
#define inf 1<<30

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;

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

ll bigMod(ll base,ll power)
{
    if(power==0)
        return 1;
    ll x=bigMod(base,power/2);
    x=(x*x)%M;
    if(power&1)
        x=(x*base)%M;
    return x;
}

ll h,w,x,y,u,cnt[410*410],res;
char grid[410][410];


class dsu
{
    ll *parent;
public:
    dsu(int n)
    {
        parent=new ll[n+5];
        for(int i=0;i<=n;i++)
            parent[i]=i;
    }
    ll finrep(ll n)
    {
        if(parent[n]==n)
            return n;
        return parent[n]=finrep(parent[n]);
    }
    ll add(ll a,ll b)
    {
        ll u=finrep(a),v=finrep(b);
        if(u==v)
            return 0;
        parent[u]=v;
        return 1;
    }
    ~dsu()
    {
        delete parent;
    }
protected:
private:
};


int main()
{
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>grid[i][j];
        }
    }
    dsu d(h*w);
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(grid[i][j]=='.'){
                u=-1;
                for(int k=-1;k<2;k++){
                    for(int l=-1;l<2;l++){
                        if((k==0)^(l==0)){
                            x=i+k;
                            y=j+l;
                            if(0<=x&&x<h&&0<=y&&y<w&&grid[x][y]=='#'){
                                if(u==-1){
                                    u=x*w+y;
                                }
                                else{
                                    d.add(u,x*w+y);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(grid[i][j]=='.'){
                u=-1;
                for(int k=-1;k<2;k++){
                    for(int l=-1;l<2;l++){
                        if((k==0)^(l==0)){
                            x=i+k;
                            y=j+l;
                            if(0<=x&&x<h&&0<=y&&y<w&&grid[x][y]=='#'){
                                u=x*w+y;
                            }
                        }
                    }
                }
                if(u==-1)
                    continue;
                cnt[d.finrep(u)]++;
            }
        }
    }
    res=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(grid[i][j]=='#'){
                res+=cnt[d.finrep(i*w+j)];
            }
        }
    }
    cout<<res<<endl;
    return 0;
}



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

int main() {
	// your code goes here
	int a,b,k,i,m=0; cin >> a >> b >> k;
	for(i=min(a,b);i>=1;i--){
		if(a%i==0&&b%i==0){
			m++;
		}
		if(m==k){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  string ans;
  int egl = 3;
  int ckl = 7;
  bool prevEgg = s.find("egg") == 0;
  ans = prevEgg ? "egg" : "chicken";
  int generation = 1;
  int maxGen = 1;
  s = s.substr(prevEgg ? egl : ckl);
  while(s.size() > 0) {
    if (s.find("egg") == 0) {
      s = s.substr(egl);
      if (prevEgg) {
        generation = 1;
      }
      else {
        prevEgg = true;
        generation++;
        if (generation > maxGen) {
          maxGen = generation;
          ans = "egg";
        }
      }
    }
    else {
      s = s.substr(ckl);
      if (!prevEgg) {
        generation = 1;
      }
      else {
        prevEgg = false;
        generation++;
        if (generation > maxGen) {
          maxGen = generation;
          ans = "chicken";
        }
      }
    }
 }
  cout << ans << endl;
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  if (S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3)) cout << "Bad";
    else cout << "Good";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007; // = 10^9 + 7

void solve()
{
	ll n, k;
	cin >> n >> k;

	// (n+1)Ck + nC(k+1) + ... + (n+1)C(n+1)
	//=(n+1)C(n-k+1) + nC(n-k) + ... + (n+1)C(0)

	ll ans = 0;
	for(ll i = k; i <= n + 1; ++i)
	{
		ans = (ans + (long long)((n+1) * i) % MOD - (long long)(i * i) % MOD + 1) % MOD;
	}

	if (ans < 0)
	{
		ans += MOD;
	}

	cout << ans << endl;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const long long MOD = 1000000007;

int N;
ll A[100];

signed main(){
    cin >> N;
    REP(i, N) cin >> A[i];
    ll m = 1000;
    FOR(i, 1, N){
        if(A[i - 1] >= A[i]) continue;
        ll d = A[i] * (m / A[i - 1]);
        m %= A[i - 1];
        m += d;
    }
    PRINT(m);
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll m;
void add(ll &a, ll b)
{
    a = (a + b);
}
int main()
{
    ll n, x;
    cin >> n >> x >> m;
    set<int> s;
    vector<int> v(1e5+10);
    s.insert(x);
    v[0] = x;
    bool flag = false;
    int start = 0;
    int end = 0;
    for(int i = 1; i <= m; i++)
    {
        x = (x * x) % m;
        v[i] = x;

        if(s.find(x) != s.end())
        {
            end = i-1;
            flag = true;
            for(int j = 0; j <= i; j++)
            {
                if(v[j] == x)
                {
                    start = j;
                    break;
                }
            }
        }
        if(flag) break;
        s.insert(x);
    }
    ll ans = 0;
    for(int i = 0; i < start; i++) add(ans, v[i]);
    ll num = 0;
    for(int i = start; i <= end; i++) add(num, v[i]);
    ll dis = end - start + 1;
    ll wid = (n - start) / dis;
    add(ans, wid * num);
    for(int i = start; i < start + (n-start) % dis; i++)
    {
        add(ans, v[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5840
#include <stdio.h>
        #include <stdlib.h>
         
        int main(void)
        {
            long long n, a, b, max = 0, maxi;
            scanf("%lld%lld%lld", &n, &a, &b);
            long long h[n];
            for (int i = 0; i < n; ++i){
                 scanf("%lld", &h[i]);
                 if (max < h[i])
                    max = h[i];
            }
         
            long long del = a - b, l = 0, r = max/b + 1, t;
            while (r - l > 1){
                t = (l+r)/2;
                long long ch = t;
                for (int i = 0; i < n; ++i){
                    if (t*b < h[i]){
                        ch -= (h[i] - t*b)/del + ((h[i] - t*b)%del? 1:0);
                    }
                }
                if (ch < 0)
                    l = t;
                else
                    r = t;
            }
            printf("%lld\n", r);
            return 0;
        }

Measured memory_bytes: 896
#include<stdio.h>
#define N 100

void selection(int,int []);

int main(){

  int i,m,n[N];

  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d",&n[i]);
  }
  selection(m,n);
  return 0;
}

void selection(int m,int n[]){
  int i,j,mini=0,a=0,b=0;

  for(i=0;i<m;i++){
    mini=i;
    for(j=i;j<m;j++){
      if(n[j]<n[mini]){
	mini=j;
      }
    }
    if(n[i]!=n[mini]){ 
      b=n[i];
      n[i]=n[mini];
      n[mini]=b;
      a++;
    }
  }
  for(i=0;i<m;i++){
    printf("%d",n[i]);
    if(i<m-1){
      printf(" ");
    }
  }
  printf("\n%d\n",a);
}

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

#define fio() ios_base::sync_with_stdio(false);\
cin.tie(NULL);
#define md 1000000007
#define mem(ar,avg) memset(ar,avg,sizeof(ar))
#define pb push_back

typedef long long int lli;
typedef float fl;


int main()
{
	fio();
	int t;
	//cin >> t;
	//while (t--)
	{
		lli n, d;
		cin >> n ;

		string s;
		cin >> s;

		lli w = 0, r = 0 ;

		for (int i = 0; i < n; i++)
		{
			if (s[i] == 'W')
				w++;
		}
		for (int i = n - 1; w > 0; i--, w--)
		{
			if (s[i] == 'R')
				r++;
		}
		cout << r << endl ;
	}

}

Measured memory_bytes: 3732
#include<cstdio>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;

int n;
int xx[20],yy[20],dis[20];
LL ans[20],p[20];
void f(int t,int x)
{
	int i,j;
	LL res=0;
	int dis2[20];
	for(i=1;i<=n;i++)
	{
		dis2[i]=dis[i];
		res+=dis2[i]*p[i];
	}
	ans[t]=min(ans[t],res);
	if(x>n) return;
	for(i=1;i<=n;i++)
		dis[i]=min(dis[i],abs(xx[i]-xx[x]));
	f(t+1,x+1);
	for(i=1;i<=n;i++)
		dis[i]=min(dis2[i],abs(yy[i]-yy[x]));
	f(t+1,x+1);
	for(i=1;i<=n;i++)
		dis[i]=dis2[i];
	f(t,x+1);
}
int main()
{
	int i;
	cin>>n;
	for(i=0;i<=n;i++)
		ans[i]=1ll<<60;
	for(i=1;i<=n;i++)
	{
		cin>>xx[i]>>yy[i]>>p[i];
		dis[i]=min(abs(xx[i]),abs(yy[i]));
	}
	f(0,1);
	for(i=0;i<=n;i++)
	{
		if(ans[i]<(1ll<<60)) cout<<ans[i]<<endl;
		else cout<<0<<endl;
	}
	return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
main(){
  int i,s[50],n;
  for(i=1;i<=30;i++){
    s[i]=1;
  }
  for(i=1;i<=28;i++){
    scanf("%d",&n);
    s[n]=0;
  }
  for(i=1;i<=30;i++){
    if(s[i]==1){
      printf("%d\n",i);
    }
  }
  return 0;
}

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

int main() {
    string r, a, b;
    cin >> r >> a >> b;
    r += a;
    r += b;
    if (stoi(r) % 4 == 0) {
        cout << "YES" << endl;
    } else{
        cout << "NO" << endl;
    }
}

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


using namespace std;
using ll = long long;

const ll sz = 2e6 + 10;
ll a[sz], b[sz];

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    ll cs = 0, tmp;
    for(ll i = 0; i < n; i++) {
        cin >> tmp;
        cs += tmp;
        a[i] = cs;
    }
    cs = 0;
    for(ll i = 0; i < m; i++) {
        cin >> tmp;
        cs += tmp;
        b[i] = cs;
    }
    ll mx = 0;
    for(ll i = 0; i < n; i++) {
        if(a[i] > k) break; 
        ll cnt = 0;
        auto it = lower_bound(b, b+m, k-a[i]) - b;
        if(it == m || b[it] > k-a[i]) it--;
        cnt += it  + 1;
        cnt += (i + 1);
        mx = max(mx, cnt);
    }
    ll mxb = 0;
    for(ll i = 0; i < m; i++) {
        if(b[i] > k) break;
        auto it = lower_bound(a, a+n, k-b[i]) - a;
        ll cnt = 0;
        if(it == n || b[it] > k-b[i]) it--;
        cnt += (i + 1);
        mxb = max(mxb, cnt);
    }
    cout << max(mx, mxb) << "\n";
    



    return 0;
}



Measured memory_bytes: 6716
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	vector<ll> s,s2,s3,p;
	set<ll> p2;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		s.pb(x);
	}
	for(int i=2;i<=100000;i++){
		bool fl = true;
		for(int j=2;j*j<=i;j++){
			if(i%j==0) fl = false;
		}
		if(fl){p.pb(i);p2.insert(i*i);}
	}
	for(int i=0;i<n;i++){
		ll x = s[i];
		for(int j=0;p[j]<2200;j++){
			while( x % (p[j]*p[j]*p[j]) == 0){
				x /= p[j]*p[j]*p[j];
			}
		}
		s2.pb(x);
	}
	for(int i=0;i<s2.size();i++){
		ll x = s2[i];
		ll cp = 1;
		for(int j=0;p[j]<2200;j++){
			if( x % (p[j]*p[j]) == 0){
				cp *= p[j];
				x /= p[j]*p[j];
			}
			else if( x % p[j] == 0){
				cp *= p[j]*p[j];
				x /= p[j];
			}
		}
		if( p2.find(x) != p2.end()){
			cp *= (int)sqrt(x);
		}
		else{
			cp *= (x*x);
		}
		s3.pb(cp);
	}
	map<ll,ll> mope;
	for(int i=0;i<s2.size();i++){
		mope[ s2[i] ]++;
	}
	ll ans = 0;
	for(int i=0;i<s2.size();i++){
		//cout<<s2[i]<<" "<<mope[s2[i]]<<" "<<mope[s3[i]]<<endl;
		if( s2[i]>1 && mope[ s2[i] ] >= mope[ s3[i] ]){
			ans += mope[ s2[i] ];
			mope[s2[i]]=0;
			mope[s3[i]]=0;
		}
	}
	cout<<ans+min(mope[1],1LL)<<endl;
	return 0;
}

Measured memory_bytes: 15604
////////////////////////////////////////////    _LeMur_
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 150005;
const int inf = 1000 * 1000 * 1000;
const int mod = 998244353;

int n;
vector <int> g[N];

int a[N];
int it = 0 , pat = 0;
int answ[N];

void dfs(int v,int p){
    for(int i=0;i<(int)g[v].size();i++){
        int to = g[v][i];
        if(to == p)continue;
        dfs(to , v);
    }
    ++it;
    answ[v] = a[it];
    if(v != 1) pat += a[it];
}

int main(){
	mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        int a , b;
        scanf("%d%d",&a,&b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a + 1 , a + n + 1);
    dfs(1 , -1);
    cout << pat << endl;
    for(int i=1;i<=n;i++){
        printf("%d ",answ[i]);
    }
    cout << endl;
	return 0;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     int cnt=0;
     string str;
     cin>>str;
     for(int i=0;i<str.size();i++)
     {
         if(str[i]=='7')
            {
                cout<<"Yes"<<endl;
                cnt=10;
            return 0;
            }
     }
     if(cnt==0)
        cout<<"No"<<endl;
}


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

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

	int n;cin >> n;
	for(int i = 0; i < n; i++){
		int l[3] = {};
		for(int j = 0; j < 3; j++){
			cin >> l[j];
		}
		bool flag = false;
		for(int j = 0; j < 3; j++){
			//printf("%d %d %d",l[j]*l[j],l[(j+1)%3]*l[(j+1)%3],l[(j+2)%3]*l[(j+2)%3]);
			if(l[j]*l[j] + l[(j+1)%3]*l[(j+1)%3] == l[(j+2)%3]*l[(j+2)%3]){
				flag = true;
				break;
			}
		}
		cout << (flag?"YES":"NO") << endl;
	}

	return 0;
}



Measured memory_bytes: 3016
#include<bits/stdc++.h>
using namespace std;
int main(){
	double n;
	cin >> n;
	for(int i=1;i<=50000;i++){
		if((int)(i*1.08)==n){
			cout << i;
			return 0;
		}
	}
	cout << ":(";
	return 0;
}

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
    ll h,n;
    cin>>h>>n;
    
    ll a,su=0;
    rep(i,n){
        cin>>a;
        su+= a;
    }
    if(su>=h){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long int
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int N = 2e5 + 5;
const int oo = 1e9 + 5;
const LL ooll = (LL)1e18 + 5;
const int MOD = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l, r) uniform_int_distribution<int>(l, r)(rng)

clock_t start = clock();

int dp[N];
void solve() {
    int h, w;
    cin >> h >> w;
    set<int> st;
    multiset<int> costs;
    for (int i=1;i<=w;++i) {
        dp[i] = 0;
        st.insert(i);
        costs.insert(0);
    }
    for (int i=0;i<h;++i) {
        int a, b;
        cin >> a >> b;
        int go = oo;
        while(!st.empty()) {
            auto it = st.lower_bound(a);
            if (it == st.end() || *it > b) break;
            if (b+1 <= w) go = min(go, dp[*it] + b + 1 - *it);
            costs.erase(costs.find(dp[*it]));
            dp[*it] = oo;
            st.erase(it);
        }
        if (go < oo) {
            if (dp[b+1] < oo) {
                costs.erase(costs.find(dp[b+1]));
            } else {
                st.insert(b+1);
            }
            dp[b+1] = min(dp[b+1], go);
            costs.insert(dp[b+1]);
        }
        if (costs.empty()) {
            cout << "-1\n";
        } else {
            cout << i + *costs.begin() + 1 << '\n';
        }
    }

}

int main() {
    FASTIO;
    int T = 1;
    // cin >> T;
    for (int t=1;t<=T;++t) {
        solve();
    }
    // cerr << fixed << setprecision(10);
    // cerr << (clock() - start) / ((long double)CLOCKS_PER_SEC) << '\n';
    return 0;
} 

Measured memory_bytes: 23196
#mapってそんなに速ないんけ？
iN = int(input())
aA = [0] + [int(_) for _ in input().split()] + [0]
iAll = sum(map(lambda i :abs(aA[i+1]-aA[i]),range(iN+1)))
print("\n".join(map(str,map(lambda i:iAll - abs(aA[i-1]-aA[i]) - abs(aA[i]-aA[i+1]) + abs(aA[i-1]-aA[i+1]), range(1,iN+1)))))


Measured memory_bytes: 16192
p (1..gets.to_i).flat_map{|i|
	r = []
	p = 2
	while i > 1
		if i%p==0
			r << p
			i /= p
		else
			p += 1
		end
	end
	r
}.group_by{|x|x}.map{|k, v| v.size + 1}.reduce(1, :*) % (10**9+7)

Measured memory_bytes: 1916
#include <iostream>

using namespace std;


int main()
{
	const long MAX_N = 1000000000;
	int n;
	cin >> n;

	long long answer = 0;
	for (long long i = 1; i < n; i++)
	{
		answer += i;
	}

	cout << answer;

	return 0;

}



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

int main(){
	int n, a, b, ans = 0;
	scanf("%d %d %d", &n, &a, &b);
	for(int i=1; i<=n; i++){
		int t = i, sum = 0;
		while(t){
			sum += t%10;
			t /= 10;
		}
		if(a<=sum && sum<=b) ans += i;
	}
	printf("%d\n", ans);
	return 0;
}
		


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)


struct UnionFind {
    vector<int> par;

    UnionFind(int n): par(n, -1) {};
    
    void init(int n) { par.assign(n, -1); }

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x);
        y = root(y);

        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};



int main(){

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

    ll n, m; cin >> n >> m;
    ll a[m], b[m];
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        a[i]; b[i];
    }

    ll cnt_bridge = 0;
    rep(i_skip, m){
        UnionFind uf(n);
        uf.init(n);
        

        rep(i_edge, m){
            if(i_edge == i_skip) continue;
            uf.merge(a[i_edge], b[i_edge]);
        }

        reps(i_node, 1, n){
            if(uf.root(i_node) != uf.root(0)){
                cnt_bridge++;
                break;
            }
        }
    }

    cout << cnt_bridge << endl;

    return 0;
}

Measured memory_bytes: 256
while 1:
    n,x=map(int,input().split())
    if n==x==0:
        break
    else:
        cnt=0
        for i in range(1,n+1):
            for j in range(i,n+1):
                if i+j<x and i!=j:
                    for r in range(j,n+1):
                        if i+j+r==x and i!=j!=r:
                            cnt+=1
        print(cnt)


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

using namespace std;

int n,sum;
char s[1000];

int main(){
	scanf("%d%s",&n,s+1);
	for (int i=1;i<=n;++i) sum+=s[i]=='R';
	puts(sum>n/2?"Yes":"No");
	
	return 0;
}
			

Measured memory_bytes: 256
#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() {
  long long n;
  cin >> n;
  long long sum = 0;
  for(int i=1;i<=n;++i){
      if(i%3 !=0 && i%5 !=0){
          sum += i;
      }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <fstream>
#include <map>



int main() {
    int n;
    std::cin >> n;
    //in >> n;
    std::vector<std::vector<int>> table(2, std::vector<int> (n, 0));
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < n; ++j) {
            std::cin >> table[i][j];
            //in >> table[i][j];
        }
    }
    int max = 0;
    int cur;
    for (int i = 0; i < n; ++i) {
        cur = 0;
        for (int j = 0; j <= i; ++j) {
            cur += table[0][j];
        }
        for (int j = i; j < n; ++j) {
            cur += table[1][j];
        }
        max = std::max(max, cur);
    }

    std::cout << max;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int h, m, s;
int	main(){
	cin >> s;
	m=s/60;
	h=m/60;
	m=m-h*60;
	s=s-m*60-h*60*60;
	cout << h <<':'<< m << ':'<< s << endl;
	return 0; 
	
}



Measured memory_bytes: 3072
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

const int MAX = 100;
const int MAX_C = 51;

int Com[MAX][MAX];

void calc_com() {
  memset(Com, 0, sizeof(Com));
  Com[0][0] = 1;
  for (int i = 1; i < MAX_C; i++) {
    Com[i][0] = 1;
    for (int j = 1; j < MAX_C; j++) {
      Com[i][j] = (Com[i - 1][j - 1] + Com[i - 1][j]);
    }
  }
}

signed main() {
  int N, P;
  cin >> N >> P;

  int even = 0, odd = 0;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    if (tmp % 2 == 0) {
      even++;
    } else {
      odd++;
    }
  }

  calc_com();

  int ans = 0;
  for (int i = P; i <= odd; i += 2) {
    ans += Com[odd][i] * pow(2, even);
  }

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D,L,R;
  cin >>A>>B>>C>>D;
  L=A+B; R=C+D;
  if(L>R){
    cout<<"Left"<<endl;
  }
  if(L<R){
    cout<<"Right"<<endl;
  }
  if(L==R){
    cout<<"Balanced"<<endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>

struct Node
{
	int key;
	Node *left;
	Node *right;
	Node *parent;
};

Node *root;
Node *NIL;

Node * find(Node *u, int key)
{
	while (u != NIL && u->key != key)
	{
		if (key < u->key)u = u->left;
		else u = u->right;
	}
	return u;
}

void insert(int key)
{
	// 挿入ノードの生成
	Node *z = (Node*)malloc(sizeof(Node));
	z->key = key;
	z->left = NIL;
	z->right = NIL;

	// 挿入位置の親を探す
	Node *y = NIL;	// 挿入位置の親
	Node *x = root; // 挿入位置
	while (x != NIL)
	{
		y = x;
		if (z->key < x->key)
		{
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}

	// 挿入の実行
	z->parent = y;
	if (y == NIL)
	{
		root = z;
	}
	else
	{
		if (z->key < y->key)
		{
			y->left = z;
		}
		else
		{
			y->right = z;
		}
	}
}

void inorder(Node *u)
{
	if (u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u)
{
	if (u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

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

	int key;
	char com[10];
	for (int i = 0; i < n; i++)
	{
		scanf("%s", com);
		if (com[0] == 'i')
		{
			scanf("%d", &key);
			insert(key);
		}
		if (com[0] == 'p')
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		if (com[0] == 'f')
		{
		   	scanf("%d", &key);
			if (find(root, key) != NIL)
			{
				printf("yes\n");
			}
			else
			{
				printf("no\n");
			}
		}
	}
	return 0;
}

/*
「ALDS1_8_A_BinarySearchTree1」の main関数

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

	int key;
	char com[10];
	for (int i = 0; i < n; i++)
	{
		scanf("%s", com);
		if (com[0] == 'i')
		{
			scanf("%d", &key);
			insert(key);
		}
		if (com[0] == 'p')
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}
*/


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

int main() {
  int x, y;
  cin >> x >> y;
  for (int i=0; i<(x+1); i++){
    if ( (i*2)+(x-i)*4==y ){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

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

	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			if ((10000 * i + 5000 * j + 1000 * (n - i - j) == y) && n - i - j >= 0)
			{
				cout << i <<" "<< j<<" "<< n - i - j;
				return 0;
			}

		}
	}
	cout << "-1 -1 -1" << endl;
}

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

using namespace std;

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

    int num0 = 0, num1 = 0;
    for (char c : s) {
        if (c == '0') num0++;
        else num1++;
    }

    cout << 2 * min(num0, num1) << endl;
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

	int a, b; std::cin >> a >> b;
	std::cout << max(0, a - b * 2) << "\n";
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    REP(i, n){
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    cout << accumulate(p.begin(), p.begin() + k, 0) << endl;
    return 0;
}

Measured memory_bytes: 3236
#include <stdio.h>

#define MAX 200000

int main(void)
{
    int R[MAX], n;
    int i;
    int maxv, minv;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &R[i]);
    }

    maxv = -2000000000;
    minv = R[0];

    for (i = 1; i < n; i++) {
        maxv = maxv>R[i]-minv ? maxv : R[i]-minv;
        minv = minv<R[i] ? minv :  R[i];
    }

    printf("%d\n", maxv);
    
    return 0;
}


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

using namespace std;

void baseball(){
    bool first=false, second=false, third=false;
    int runner=0;
    int outCount=0;
    int score=0;
    string event;
    string hit = "HIT";
    string homerun = "HOMERUN";
    string out = "OUT";
    
    while(outCount !=3){
        cin >> event;
        if(event == hit){
            if(third==true) runner--,score++;
            if(second==true) third=true;
            if(first==true) second=true;
            first=true;
            runner++;
        }
        else if(event == homerun){
            score += runner+1;
            first=false, second=false, third=false;
            runner=0;
        }
        else if(event == out){
            outCount++;
        }
        
    }
    cout << score<<endl;
}


int main(){
    
    int c;
    cin >> c;
    
    for(int i=0;i<c;i++){
        
        baseball();
        
    }
    return 0;
}

Measured memory_bytes: 1220
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

print(input().count('o')*100+700)


Measured memory_bytes: 3064
import static java.util.Comparator.comparing;

import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==========================================================
    public void solve() {
    	int N = ni();
    	int K = ni();
    	int[] H = ndi(N);
    	int[] dp = new int[N+10];
    	Arrays.fill(dp, 1000000000);
    	dp[0] = 0;
    	for (int i = 0; i < N-1; i++) {
    		for (int j = 1; j <= K; j++) {
				if(i+j >= N)	break;
				dp[i+j] = Math.min(dp[i+j], dp[i] + Math.abs(H[i+j] - H[i]));
			}
		}
    	out.println(dp[N-1]);
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] nddi(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


Measured memory_bytes: 51404
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define All(obj) (obj).begin(),(obj).end()

using namespace std;


int main() {
	speed;
	int a, b;
	cin >> a >> b;
	cout << (a - 1)*(b - 1);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,M;
  cin>>N>>M;
  vector<int> A(M),B(M-1);
  for(int &i:A)cin>>i;
  sort(A.begin(),A.end());
  for(int i=0;i<M-1;i++)B[i]=A[i+1]-A[i];
  sort(B.begin(),B.end());
  int ans=0;
  for(int i=0;i+N<M;i++)ans+=B[i];
  cout<<ans<<endl;
}

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


int main(void){
  int n,k,q; cin >> n >> k >> q;
  int a[q];
  rep(i,q) cin >> a[i];
  vector<int> score(n,k-q);
  for(int i = 0; i < q; i++){
    score[a[i]-1]++;
  }
  for(int i = 0; i < n; i++){
    if(score[i] <= 0){
      cout << "No" << endl;
    }
    else cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 1408