akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll k = n-1;
    set<ll> st;
    for(ll i=1;i*i<=k;i++){
        if(k%i==0){
            if(i!=1) st.insert(i);
            if(i*i!=k) st.insert(k/i);
            //cerr << i << " " << (ll)(k/i) << endl;
        }
    } 
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ll t = n/i;
            while(i!=1 && t%i==0){
                if((t-1)%i == 0){
                    //cerr << i <<endl;
                    st.insert(i);
                }
                t /= i;
            }
            if(t==1){
               // cerr << i << endl;
                st.insert(i);
            }
            else{
                if(i!=1 && (t-1)%i==0){
                   // cerr << i << endl;
                    st.insert(i);
                }
            }
            ll d = n/i;
            t = n/d;
            while(d!=1 && t%d==0){
                if((t-1)%d == 0){
                   // cerr << d << endl;
                    st.insert(d);
                }
                t /= d;
            }
            if(t==1){
               // cerr << d << endl;
                st.insert(d);
            }
            else{
                if(d!=1 && (t-1)%d==0){
                    //cerr << d << endl;
                    st.insert(d);
                }
            }
        }
    }
    ll ans = st.size();
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))
col = list([i for i in range(1, N + 1)])
count = 0

for j in range(N):
    if p[j] != col[j]:
        count += 1
if count == 0 or count == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int x[SIZE],y[SIZE];
LL sqr(LL x){return x*x;}
int main(){
    int N; R(N);
    REP(i,N)R(x[i],y[i]);
    VI p(N);
    REP(i,N)p[i]=i;
    double v=0;
    do{
        REPP(i,1,N){
            v+=sqrt(sqr(x[p[i]]-x[p[i-1]])+sqr(y[p[i]]-y[p[i-1]]));
        }
    }while(next_permutation(ALL(p)));
    FOR(i,1,N)v/=i;
    W(v);
    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
/*
#define lli long long int

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

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

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

    int a,b,c,k;
    cin>>a>>b>>c>>k; int sum=0;
    sum+=(a>k)?k:a;
    k-=a;
    k-=b;
    if(k<=0) {cout << sum;return 0;}
    sum+=(c>k?-k:-c);
   	cout << sum;
   	return 0;

}


Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#include <complex>
#include <vector>
#include <set>
#include <iomanip>


using namespace std;
typedef long double ld;
typedef long long ll;
const int MAX = 60;
typedef complex<long double> Point;


namespace std {
    bool operator<(const Point &lhs, const Point &rhs) {
        return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
    }
}

struct Circle {
    Point c;
    ld r;

    vector<Point> cross(const Circle &other) {
        vector<Point> ret;
        ld dist = abs(c - other.c);
        ld rc = (dist * dist + r * r - other.r * other.r) / (2 * dist);
        ld dfr = r * r - rc * rc;
        if (abs(dfr) < 1e-6) dfr = 0.0;
        if (dfr < 0.0) {
            return ret;
        }
        ld rs = sqrt(dfr);
        Point diff = (other.c - c) / dist;
        ret.push_back(c + diff * Point{rc, rs});
        if (dfr != 0.0) {
            ret.push_back(c + diff * Point{rc, -rs});
        }
        return ret;
    }
};

const ld eps = 1e-9;
int n, k;
Circle m[MAX + 1];
int c[MAX + 1];


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    cin >> n >> k;

    vector<Point> centers;
    for (int i = 0; i < n; ++i) {
        ld xc, yc;
        cin >> xc >> yc >> c[i];
        m[i] = {Point{xc, yc}};
        centers.push_back(m[i].c);
    }

    ld hi = 1e6;
    ld lo = 0;
    for (int ii = 0; ii < 100; ++ii) {
        ld t = lo + (hi - lo) / 2;
        vector<Point> candidate(centers);

        for (int i = 0; i < n; ++i) {
            m[i].r = (ld) t / (ld) c[i];
            for (int j = i + 1; j < n; ++j) {
                m[j].r = (ld) t / (ld) c[j];
                auto ret = m[i].cross(m[j]);
                for (auto pt : ret) {
                    candidate.push_back(pt);
                }
            }
        }

        int mc = 0;
        for (auto pt : candidate) {
            int count = 0;
            for (int i = 0; i < n; ++i) {
                ld diff = abs(m[i].c - pt);
                if (diff < m[i].r + eps) {
                    ++count;
                }
            }
            mc = count;
            if (count >= k) {
                break;
            }
        }

        if (mc < k) {
            lo = t + eps;
        } else {
            hi = t;
        }
    }

    cout << lo;

    return 0;
}


Measured memory_bytes: 488
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<long long> a(n);
	rep(i, 0, n - 1)
	{
		long long x; cin >> x;
		a[i] = x - (i + 1);
	}
	sort(all(a));
	long long res = 0;
	if (n % 2 == 1)
	{
		rep(i, 0, n - 1)
		{
			res += abs(a[i] - a[n / 2]);
		}
	}
	else
	{
		long long can1 = 0, can2 = 0;
		rep(i, 0, n - 1)
		{
			can1 += abs(a[i] - a[n / 2]);
			can2 += abs(a[i] - a[n / 2 - 1]);
		}
		res = min(can1, can2);
	}
	cout << res << endl;
}

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


int r[10005],ans[10005],cnt;
vector<int> e[10005];
void dfs(int t)
{
	if (ans[t]==0) ans[t]=r[--cnt];
	else return;
	for (int i=0; i<e[t].size(); i++)
	{
		dfs(e[t][i]);
	}
}
int main()
{
	int n; cin>>n;

	for (int i=1; i<n; i++)
	{
		int x1,x2;
		cin>>x1>>x2;
		e[x1].push_back(x2);
		e[x2].push_back(x1);
	 } 
	for (int i=1; i<=n; i++) cin>>r[i];
	
	sort(r+1,r+n+1);
	
	int ans0=0;
	for (int i=1; i<n; i++) ans0+=r[i];
	cout << ans0 << endl;
	cnt=n+1;
	dfs(1);
	
	for (int i=1; i<=n; i++) cout << ans[i] << ' ';
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define M ((ll)(1e9)+7)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;

bool comp(pair<ll,ll> a,pair<ll,ll> b)
{
    if(a.S<b.S)
    return true;
    return false;
}
void solve()
{
    int n;
    cin>>n;ll c=0;
    map<pair<ll,ll>,ll> m;
    for(int i=1;i<=n;i++)
    {
        string s="";
        int te=i;
        while(te!=0)
        {
            int d=te%10;
            s=(char)(d+48)+s;
            te/=10;
        }
        ll a=(ll)s[0]-48;
        ll b=(ll)s[s.size()-1]-48;
        //cout<<a<<" "<<b<<endl;
        if(a==b)
        c++;
        m[mp(a,b)]++;
    }
    ll ans=0;
    for(ll i=1;i<=9;i++)
    {
        for(ll j=1;j<=9;j++)
        {
            //cout<<m[mp(i,j)]<<" "<<m[mp(j,i)]<<endl;
            if(m[mp(i,j)]!=0&&m[mp(j,i)]!=0){
            ll va=m[mp(i,j)]*m[mp(j,i)];
            ans+=va;}
            //cout<<va<<endl;}
        }
    }
    cout<<ans<<endl;
}
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF = 1e6+7;
const long long MOD = 1e9+7;

using namespace std;

int main(){
	
	string s;
	cin >> s;
	int cnt=0;
	int ans=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='R'){
			cnt++;
		}else{
			ans=max(ans,cnt);
			cnt=0;
		}
	}
	ans=max(ans,cnt);
	cout << ans << endl;		
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define all_white first
#define sth_is_black second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
//~ const ll inf = 1e18+5;
const ll maxn= 1e5+5;
ll n, mod;
ll mult(ll a, ll b){
	//~ ll mod = mod;
	return (a%mod*b%mod)%mod;
}
ll add(ll a, ll b){
	//~ ll mod = modd;
	return (a%mod+b%mod+mod)%mod;
}
vector<ll> adjlist[maxn];
vector<ll> children[maxn];
pi down[maxn], up[maxn];
vector<pi> downs[maxn], pre[maxn], suf[maxn];

pi merge(pi &a, pi &b){
	pi p = mp(0, 0);
	p.all_white = mult(a.all_white, b.all_white);
	p.sth_is_black = add(mult(a.all_white, b.sth_is_black), (mult(a.sth_is_black, add(b.all_white, b.sth_is_black))));
	return p;
}
pi process(pi p){
	pi g = mp(p.all_white, add(p.sth_is_black, p.all_white));
	return g;
}
void dfs_one(ll x, ll par){
	pi p = mp(1,0);
		for (auto i:adjlist[x]){
		if (i == par)continue;
		children[x].pb(i);
		dfs_one(i, x);
		//~ cout << "hi";
		p = merge(p, down[i]);
		downs[x].pb(down[i]);
	}
	down[x] = process(p);
}
void dfs_two(ll x, ll par){
	for (ll i = 0; i < children[x].size(); i++){
		pi p = mp(1, 0);
		if (i != 0){
			p = merge(p, pre[x][i-1]);
		}
		if (i != (ll)children[x].size()-1){
			p = merge(p, suf[x][i+1]);
		}
		if (x != 1)p = merge(p, up[x]);
		ll b = children[x][i];
		up[b] = process(p);
		dfs_two(b, x);
	}
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> mod;
	//~ cout << down[0].first;
	for (ll i = 0; i < n-1; i++){
		ll aa, bb;
		cin >> aa >> bb;
		adjlist[aa].push_back(bb);
		adjlist[bb].push_back(aa);
		//~ cout << "ok";
	}
	//~ for (ll i = 1; i <= n; i++){
		//~ for (auto j:adjlist[i])cout << j << ' ';
	//~ }
	//~ cout << "hi";
	dfs_one(1, 1);
	//~ cout << "beibi";
	for (ll i = 1; i <= n; i++){
		ll k = downs[i].size();
		pi p = mp(1, 0);
		for (ll j= 0; j < k; j++){
			p = merge(p, downs[i][j]);
			pre[i].pb(p);
		}
		p = {1, 0};
		for (ll j = k-1; j >= 0; j--){
			p = merge(p, downs[i][j]);
			suf[i].pb(p);
		}
		reverse(suf[i].begin(), suf[i].end());
	}
	dfs_two(1, -1);
	for (ll a = 1; a <= n; a++){
		pi p = mp(1, 0);
		if (a != 1)p = merge(p, up[a]);
		if (!children[a].empty())p = merge(p, pre[a].back());
		p = process(p);
		cout << p.second << '\n';
	}
}


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

int main() {
  int N,n,ans=0,i=10;
  cin >> N;
  n=N;
  while (N>0) {
    ans+=N%i;
    N/=i;
  }
  if (n%ans==0) {
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}




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

ll dfs(ll k, ll N, ll bits) {
    if (k > N) return 0;
    ll ret = bits == 7 ? 1 : 0;
    for (int i = 0; i < 3; ++i)
        ret += dfs(k * 10 + vector<int>{3, 5, 7}[i], N, 1<<i|bits);
    return ret;
}

int main() {
    ll N; cin >> N;
    cout << dfs(0, N, 0) << endl;
    return 0;
}


Measured memory_bytes: 3608
// Problem : A - B +/- A
// Contest : AtCoder Beginner Contest 118
// URL : https://atcoder.jp/contests/abc118/tasks/abc118_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef long double ld;

constexpr int INF = 1e9;
constexpr ll BIGINF = 1e18;
constexpr double EPS = 1e-16;
constexpr int MOD = 1e9 + 7;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

int a;
int b;

void input() {
  cin >> a >> b;
}

void solve() {
  int ans = b - a;
  
  if (b % a == 0)
    ans = a + b;
    
  cout << ans << '\n';
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve();
}


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

using namespace std;

int main()
{
    //vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};

    int N, M;
    cin >> N >> M;

    vector<int> index_list(N, 100);
    vector<int> a_list(N);
    vector<int> b_list(N);

    for(int i = 0; i < N; i ++){
        index_list[i] = i;
        cin >> a_list[i] >> b_list[i];
    }

    sort(index_list.begin(), index_list.end(), [a_list](int o1, int o2){return less<int>()(a_list[o1], a_list[o2]);});

    long charge = 0;

    for(int i = 0, cnt = 0; i < N && cnt < M; i ++){
        int index = index_list[i];
        int a = a_list[index];
        int b = b_list[index];
        int delta = min(b, M - cnt);
        cnt += delta;
        charge += 1l * delta * a;
    }

    cout << charge << endl;
}

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

int main(void){
  int h, w;
  
  while(1){
    cin >> h >> w;

    if(h == 0 && w == 0) break;
    
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(i == 0 || i == h - 1 || j == 0 || j == w - 1){
	  cout << "#";

	} else {
	  cout << ".";

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

Measured memory_bytes: 1152
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int x, a;
	cin >> x >> a;
	if (x < a) {
		cout << 0 << endl;
	} else {
		cout << 10 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    static int cnt = 0;
    private static void re(int i,int n,int v,int t,int s)
    {
        //i????????¨????????°?????°,n?????????????±?,v????´??????°???,s???????¨???°,t???????????§??§?????§????????°
        if(i==n)
        {
            for(int j=t+1; j<=9; j++)
            {
                int tempv=v+j;
                if(tempv==s)
                {
                    cnt++;
                    break;

                }
            }
        }
        else
        {
            for(int j=t+1; j<=9; j++)
            {
                int tempv = v+j;
                if(tempv<s)
                {
                    re(i+1,n,tempv,j,s);
                }
            }
        }
    }
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        while(true) {
            cnt=0;
            int n = scan.nextInt();
            int s = scan.nextInt();
            if(n==0 && s==0)
            {
                break;
            }
            re(1, n, 0, -1, s);
            System.out.println(cnt);
        }
    }
}

Measured memory_bytes: 26056
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 1e5 + 5;
int n , s;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    ll res = 0;
    cin >> n >> s;
    vector<ll> a(n + 1) , b(n + 1);
    for(int i = 1 ; i <= n ; ++i)cin >> a[i] >> b[i];
    if(a[n] < s || a[1] > s)return cout << max(abs(s - a[1]) , abs(s - a[n])) , 0;
    for(int i = 1 , j = n ; a[i] < s && a[j] > s ; ){
        res += a[j] - a[i];
        if(b[i] >= b[j]){
            while(b[i] >= b[j] && a[j] > s)b[i] += b[j--];
        }else{
            while(b[j] > b[i] && a[i] < s)b[j] += b[i++];
        }
        if(a[j] < s)res += s - a[i];
        else if(a[i] > s)res += a[j] - s;
    }
    cout << res;
}


Measured memory_bytes: 1792
#include <iostream>
 
int main (void) {
	std::string S;
	std::cin >> S;
	int cnt = 0, max = 0;
	
	for (auto c : S) {
		if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
			++cnt;
			if (max < cnt) {max = cnt;}
		} else {
			cnt = 0;
		}
	}
	
	std::cout << max;
	
	return 0;
}

Measured memory_bytes: 256
import collections
def solve(S):
    r_ix = len(S)
    while len(S):
        is_hit = False

        for word in ['dream', 'dreamer', 'erase', 'eraser']:
            l_ix = r_ix - len(word)
            if S[l_ix:r_ix] == word:
                S = S[:l_ix]
                r_ix = l_ix
                is_hit = True

        if not is_hit:
            return "NO"
                
    return "YES"


def solve2(S):
    word = ['dream', 'dreamer', 'erase', 'eraser']
    buf = []
    for ch in S:
        buf.append(ch)
    curchar = ''
    while len(buf) > 0:
        c = buf.pop()
        curchar = c + curchar
        if curchar in word:
            curchar = ''

    if curchar == '':
        return "YES"

    return "NO"

if __name__ == "__main__":
    S = input()
    print(solve(S))


Measured memory_bytes: 3572
"use strict"
function Main(input) {
  input = input.split('\n');
  let i1 = input[0].trim().split(' ').map(Number);
  let n = i1[0];
  let k = i1[1];

  let mons = input[1].trim().split(' ').map(Number);
  mons.sort((a,b) => a-b);

  let atk = 0;
  for(let i=0; i<n-k; ++i){
    atk+=mons[i];
  }
  console.log(atk);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int reduce2zero(int i);

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

	int popcount=0;
	for (int i=0;i<n;++i)
	{
		if (x[i]=='1')
		{
			++popcount;
		}
	}
	int popp=popcount+1;
	int popm=popcount-1;

	int modulop=1;
	int modulom=1;
	int sump=0;
	int summ=0;
	for (int i=n-1;i>=0;--i)
	{
		if (x[i]=='1')
		{
			sump+=modulop;
			sump%=popp;
			if (popm>0)
			{
				summ+=modulom;
				summ%=popm;
			}
		}
		modulop<<=1;
		modulop%=popp;
		if (popm>0)
		{
			modulom<<=1;
			modulom%=popm;
		}
	}
	sump%=popp;
	if (popm>0)
	{
		summ%=popm;
	}

	vector<int> after1st(n);
	modulop=1;
	modulom=1;
	for (int i=n-1;i>=0;--i)
	{
		if (x[i]=='0')
		{
			after1st[i]=(sump+modulop)%popp;
		}
		else
		{
			if (popm>0)
			{
				after1st[i]=(summ-modulom+popm)%popm;
			}
			else
			{
				after1st[i]=-1;
			}
		}
		modulop<<=1;
		modulop%=popp;
		if (popm>0)
		{
			modulom<<=1;
			modulom%=popm;
		}
	}

	for (int i=0;i<n;++i)
	{
		cout << reduce2zero(after1st[i]) << endl;
	}

}


int reduce2zero(int i)
{
	int count=1;
	if (i<0)
	{
		return 0;
	}
	while (i>0)
	{
		i=i%__builtin_popcount(i);
		++count;
	}
	return count;
}








Measured memory_bytes: 4448
from itertools import permutations

def get_int():
    return int(input())

def get_int_list():
    return list(map(int, input().split()))

while(True):
    try:
        n, a, b, c = get_int_list()
        l = [get_int() for _ in range(n)]
        ans = 1000000000000
        for take in permutations(l, n):
            #print(take)
            take = list(take)
            cnt = 0
            i = 3
            while True:
                if i >= n:
                    break
                if abs(take[2] - a) < 10:
                    break
                if take[2] > a:
                    break
                if abs(take[2] + take[i] - a) >= abs(take[2] - a):
                    break
                if take[i] <= 10:
                    break
                take[2] += take[i]
                i += 1
                cnt += 10
            cnt += abs(take[2] - a)
            #print(take[2])

            while True:
                if i >= n:
                    break
                if abs(take[1] - b) < 10:
                    break
                if take[1] > b:
                    break
                if abs(take[1] + take[i] - b) >= abs(take[1] - b):
                    break
                if take[i] <= 10:
                    break
                take[1] += take[i]
                i += 1
                cnt += 10
            cnt += abs(take[1] - b)
            #print(take[1])

            while True:
                if i >= n:
                    break
                if abs(take[0] - c) < 10:
                    break
                if take[0] > c:
                    break
                if abs(take[0] + take[i] - c) >= abs(take[0] - c):
                    break
                if take[i] <= 10:
                    break
                take[0] += take[i]
                i += 1
                cnt += 10
            cnt += abs(take[0] - c)
            #print(take[0])

            ans = min(ans, cnt)
            #if(ans == 253):
            #    print(take[0], take[1], take[2])
        print(ans)
    except EOFError:
        exit()


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int a,b,c,k; cin >> a >> b >> c >> k;
  if(a >= k) cout << k << endl;
  else if(b >= k-a) cout << a << endl;
  else cout << a - (k - a - b) << endl;
  return 0;
}


Measured memory_bytes: 3592
N = int(input())
X = input()
ans = [1 for _ in range(N)]
#original 1 count
l = X.count('1')
if l == 0:
  for _ in range(N):
    print(1)
  exit()
if l == 1:
  if X[-1] == '1':
    for _ in range(N-1):
      ans[_] = 2
  else:
    ans[-1] = 2 
  for k in range(N):
    if X[k] =='1':
      ans[k] = 0 
  for _ in range(N):
    print(ans[_])
  exit()
 
 
intN = int(X, 2)
N1 = intN %(l-1)
N0 = intN % (l+1)
 
 
start = []
if N == 1:
  if X[0] == '1':
    print(0)
    exit()
  else:
    print(1)
    exit()
else:
  s1 = 1
  s0 = 1
  for k in range(N-1, -1, -1):
    if X[k] == '1':      
      ia = (N1 - s1)%(l-1)
    else:
      ia = (N0 + s0)%(l+1)
    start.append(ia)
    s1 = s1*2%(l-1)
    s0 = s0*2%(l+1)
start = start[::-1]
 
ml = len(bin(l+1))-2
poplist = [0 for _ in range(N)]
t = 1
while t < N + 1:
  t *= 2
  for k in range(t//2, N, t):
    for j in range(t//2):
      if k+j>N-1:
        break
      poplist[k+j] += 1
"""
 
def popcount(n):
  c = 0
  n = bin(n)[2:]
  for k in range(len(n)):
    if n[k] == '1':
      c+=1
  return c
"""
for k in range(len(start)):
  for count in range(10*5):
    if start[k] == 0:
      ans[k] += count
      break
    else:
      start[k] = start[k] % poplist[start[k]]
 
for k in range(N):
  print(ans[k])

Measured memory_bytes: 119288
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, A, B, C; cin >> N >> A >> B >> C;
    vector<int> L(N); for (int &l : L) cin >> l;
    int ans = numeric_limits<int>::max();
    for (int i = 0, e = pow(4, N); i < e; i++) {
        int a[3] = {}, cost = 0, k = i;
        for (int j = 0; j < N; j++, k /= 4) {
            if (k % 4 == 3) continue;
            if (a[k % 4] != 0) cost += 10;
            a[k % 4] += L[j];
        }
        if (a[0] == 0 || a[1] == 0 || a[2] == 0) continue;
        ans = min(ans, cost + abs(a[0] - A) + abs(a[1] - B) + abs(a[2] - C));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    vector<int> v(3);
    rep(i, 0, 3) cin >> v[i];
    int K; cin >> K;
    sort(v.begin(), v.end());
    int res = v[0]+v[1]+v[2];
    rep(i, 0, K) {
      res += v[2];
      v[2] *= 2;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#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 ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

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

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;


int N, u, v;
int aoki[100000], takahashi[100000];
vector<int> adj[100000];
bool visited[100000];

void dfs_aoki(int index, int depth){
    if(visited[index]) return;
    aoki[index] = depth;
    visited[index] = true;
    for(int next : adj[index]){
        dfs_aoki(next, depth + 1);
    }
}

void dfs_takahashi(int index, int depth){
    if(visited[index]) return;
    takahashi[index] = depth;
    visited[index] = true;
    for(int next : adj[index]){
        dfs_takahashi(next, depth + 1);
    }
}


signed main(){
    cin >> N >> u >> v;
    u--; v--;
    int A, B;
    REP(i, N - 1){
        cin >> A >> B;
        A--; B--;
        adj[A].push_back(B);
        adj[B].push_back(A);
    }
    REP(i, N) visited[i] = false;
    dfs_aoki(v, 0);
    REP(i, N) visited[i] = false;
    dfs_takahashi(u, 0);
    int t = -1, a = -1;
    REP(i, N){
        if(takahashi[i] < aoki[i] && a < aoki[i]){
            a = aoki[i];
            t = takahashi[i];
        }
    }
    PRINT(a - 1);
    return 0;
}

Measured memory_bytes: 9216
#include<cstdio>
int main(){
    int N;
    scanf("%d",&N);
    for(int n = 1; n <= N; n++){
        if(n % 3 == 0){
            printf(" %d",n);
        }
        else{
            int Q = n;
            int r;
            for(int j = 1;; j++){
                r = Q % 10;
                Q = Q / 10;
                if(r == 3){
                    printf(" %d",n);
                    break;
                }
                if(Q == 0){
                    break;
                }
            }
        }
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 2676
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

// Binary Indexed Tree
template<class T>
struct BinaryIndexedTree {
	const int n;
	vector<T> v;
	BinaryIndexedTree(int n) : n(n), v(n, 0) {}
	void add(int i, T x) {
		for (; i < n; i |= i + 1)
			v[i] += x;
	}
	// [0, i)
	T sum(int i) {
		T r = 0;
		for (--i; i >= 0; i = (i & (i + 1)) - 1)
			r += v[i];
		return r;
	}
	// [l, r)
	T sum(int l, int r) {
		return sum(r) - sum(l);
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	BinaryIndexedTree<int> b(n);
	rep(_, 0, q) {
		int c, x, y; cin >> c >> x >> y;
		if (c == 0) {
			b.add(x - 1, y);
		}
		else {
			cout << b.sum(x - 1, y) << endl;
		}
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rrep1(i,n) for(ll i=n;i>=1;i--)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

int main(){
    ll N,K; cin>>N>>K;
    vector<ll> L(N);
    rep(i,N) cin>>L[i];
    sort(all(L),greater<ll>());
    ll ans=0;
    rep(i,K) ans+=L[i];
    cout<<ans;
}

Measured memory_bytes: 256
from math import *
PI = 3.1415926535898
while True:
	try:
		n = input()
		if n == 0:
			break
		res = []
		arr = []
		su = 0
		for i in range(n):
			arr.append(input())
		res.append(arr[0])
		ans = arr[0]
		for i in range(1, n):
			res.append(max(res[i-1] + arr[i], arr[i]))
			ans = max(ans, res[i])
		print ans
	except EOFError:
		break

Measured memory_bytes: 6528
// PCK 2012 Q5 --- Salary for a Plumber

#include <iostream>
#include <algorithm>
#include <functional>
#include <cstring>
using namespace std;

static const int MAX_N = 65000;

int main()
{

	long long n, MLength = 0, addLength = 0, cnt = 0, Max = 0;
	int p[MAX_N], j[MAX_N - 1];

	while( cin >> n, n ) {

		memset( p, 0, sizeof( p ) );
		memset( j, 0, sizeof( j ) );

		MLength = 0, addLength = 0, Max = 0, cnt = n - 1;

		for( int i = 0; i < n; i++ ) { cin >> p[i]; Max += p[i]; addLength += p[i]; }
		for( int i = 0; i < n - 1; i++ ) cin >> j[i];

		sort( p, p + n, greater< int >() );
		sort( j, j + n - 1, greater< int >() );

		MLength = p[0] + j[0] + p[1];

		Max = max( MLength * cnt, Max * n );

		addLength -= ( p[0] + p[1] );

		for( int i = 2; i < n; i++ ) {

			addLength += MLength;

			Max = max( addLength * cnt, Max );

			cnt--;

			addLength -= ( MLength + p[i] );
			MLength += ( p[i] + j[i - 1 ] );

		}

		cout << Max << endl;

	}

	return 0;

}

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

#define maxn 100000+5

using namespace std;

long long a[maxn],sum[maxn];
int n,k;

int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	a[0]=-0x3f3f3f3f;
	int st=0;
	for(int i=1;i<=n;i++)
		if(a[i]==0){
			st=i;
			break;
		}
	if(n==1){
		printf("%lld",abs(a[1]));
		return 0;
	}
	if(!st){
		k++,n++;
		a[n]=0;
		sort(a+1,a+1+n);
		for(int i=1;i<=n;i++)
			if(a[i]==0) st=i;
	}	
	long long ans=LLONG_MAX;
	for(int i=st;i>=1;i--)
		if(st-i+1<=k && st+k-(st-i+1)<=n)
			ans=min(ans,(a[st]-a[i])*2+a[st+k-(st-i+1)]-a[st]);
	for(int i=st;i<=n;i++)
		if(i-st+1<=k && st-k+i-st+1>0)
			ans=min(ans,(a[i]-a[st])*2+a[st]-a[st-k+i-st+1]);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }

int main() {
  int a, b;
  vector<int> c;

  cin >> a >> b;

  if (b % a == 0) {
    cout << a + b;
  } else {
    cout << b - a;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdlib.h>

using namespace std;

int main() {
    int n;
    long int x;
    cin >> n >> x;
    long int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a+n);
    long int sum = 0;
    int count = 0;
    for(int i = 0; i < n; i++) {
        if(x > sum) {
            sum += a[i];
            count++;
            if(x == sum) {
                count++;
            }
        }
    }
    cout << count-1;
    return 0;
}



Measured memory_bytes: 256
import itertools
 
def check(lis, a):
    return sum((i[3] for i in a if lis[i[1]-1]-lis[i[0]-1]==i[2]))
   
n, m, q = map(int, input().split())
a = [[int(i) for i in input().split(" ")] for j in range(q)]
ans = 0
for i in itertools.combinations_with_replacement(range(m), n):
    ans = max(ans, check(i, a))
print(ans)

Measured memory_bytes: 9104
/*
    Code by:-
  ______                                                                __          
 /      \                                                              |  \         
|  ▓▓▓▓▓▓\ ______  ______ ____  ______ ____  __    __       __  ______  \▓▓_______  
| ▓▓___\▓▓|      \|      \    \|      \    \|  \  |  \     |  \|      \|  \       \ 
 \▓▓    \  \▓▓▓▓▓▓\ ▓▓▓▓▓▓\▓▓▓▓\ ▓▓▓▓▓▓\▓▓▓▓\ ▓▓  | ▓▓      \▓▓ \▓▓▓▓▓▓\ ▓▓ ▓▓▓▓▓▓▓\
 _\▓▓▓▓▓▓\/      ▓▓ ▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ | ▓▓ ▓▓  | ▓▓     |  \/      ▓▓ ▓▓ ▓▓  | ▓▓
|  \__| ▓▓  ▓▓▓▓▓▓▓ ▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ | ▓▓ ▓▓__/ ▓▓     | ▓▓  ▓▓▓▓▓▓▓ ▓▓ ▓▓  | ▓▓
 \▓▓    ▓▓\▓▓    ▓▓ ▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ | ▓▓\▓▓    ▓▓     | ▓▓\▓▓    ▓▓ ▓▓ ▓▓  | ▓▓
  \▓▓▓▓▓▓  \▓▓▓▓▓▓▓\▓▓  \▓▓  \▓▓\▓▓  \▓▓  \▓▓_\▓▓▓▓▓▓▓__   | ▓▓ \▓▓▓▓▓▓▓\▓▓\▓▓   \▓▓
                                            |  \__| ▓▓  \__/ ▓▓                     
                                             \▓▓    ▓▓\▓▓    ▓▓                     
                                              \▓▓▓▓▓▓  \▓▓▓▓▓▓                      

*/

#include "bits/stdc++.h"
using namespace std;

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

    if(n%1000==0)
    {
        cout<<n%1000;
    }
    else
    {
        cout<<(1000-n%1000);
    }
}


Measured memory_bytes: 3588
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let A = cin.getInt(), B = cin.getInt(), T = cin.getInt();
    let ans = Math.floor(T / A) * B;
    console.log(ans);
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
ll n,m,d;
int main()
{
	scanf("%lld%lld%lld",&n,&m,&d);
	printf("%.10lf\n",(double)(m-1)*(n*2-d*2)/(n*n)/((d==0)?2:1));
	return 0;
}


Measured memory_bytes: 256
def modinv(a,m):
    return pow(a,m-2,m)

import copy

S = input()
N = len(S)
dp = [[[0,0], [0,0,0], [0,0,0,0]] for i in range(N+1)]
mod = 10**9 + 7

for i in range(N):
    dp[i+1] = copy.deepcopy(dp[i])
    if S[i] == 'A':
        dp[i+1][0][0] += 1

    elif S[i] == 'B':
        for j in range(2):
            dp[i+1][1][j] = (dp[i+1][1][j] + dp[i][0][j])%mod

    elif S[i] == 'C':
        for j in range(3):
            dp[i+1][2][j] = (dp[i+1][2][j] + dp[i][1][j])%mod

    else:
        dp[i+1][0][1] += 1
        for j in range(2):
            dp[i+1][1][j+1] = (dp[i+1][1][j+1] + dp[i][0][j])%mod
        for j in range(3):
            dp[i+1][2][j+1] = (dp[i+1][2][j+1] + dp[i][1][j])%mod

Q = S.count('?')

inv3 = modinv(3,mod)
inv9 = inv3*inv3%mod
inv27 = inv9*inv3%mod
threeQ = pow(3,Q,mod)

ans = threeQ * (dp[N][2][0] + dp[N][2][1]*inv3 + dp[N][2][2]*inv9 + dp[N][2][3]*inv27) % mod
print(ans)

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

using namespace std;

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

void print_forward(std::deque<int> const& deque)
{
	for (int i = 0; i < deque.size(); i++)
		std::cout << deque[i] <<  " ";
	std::cout << '\n';
}

void print_backwards(std::deque<int> const& deque)
{
	for (int i = deque.size() - 1; i >= 0; i--)
		std::cout << deque[i] <<  " ";
	std::cout << '\n';
}


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

    string S;cin>>S;
    deque<char> ss(S.begin(),S.end());
    int q; cin>>q;
    bool left2right=true;
    for (size_t i = 0; i < q; i++)
    {
        int t;
        cin>>t;
        if (t==1) {
            //reverse
            left2right = !left2right;
        } else{
            int f; char c; 
            cin>>f >> c;
            if (f==1) {
                //add begining
                if(left2right) {
                    ss.push_front(c);
                } else{
                    ss.push_back(c);
                }
            } else{
                // add end
                if(left2right) {
                    ss.push_back(c);
                } else {
                    ss.push_front(c);
                }
            }
        }
    }

    if(left2right) {
        for (auto &&i : ss)
        {
            cout<<i;
        }
        cout<<"\n";
    } else{
        for(auto it=ss.rbegin();it!=ss.rend();it++) {
            cout << *it;
        }
        cout<<"\n";
    }
    

    return 0;
}


Measured memory_bytes: 976
S = input()
N = len(S)
flag = 0

ans = 0
ans2 = 0
Bcount = 0
Wcount = 0
for i in range(N):
    if S[i] == 'B':
        ans2 += N - 1 - i
        Bcount += 1
for i in range(N):
    if S[i] == "W":
        Wcount += 1
        ans += i + 1
for i in range(Bcount):
    ans2 -= i
for i in range(Wcount):
    ans -= i
print(min(ans,ans2))


Measured memory_bytes: 3500
n,m=map(int,input().split())
lst=[]
for i in range(n):
    lst.append(input().split())
lst2=[]
for i in range(m):
    lst2.append(int(input()))
lst3=[]
for i in range(n):
    lst3=lst[i]
    c=0
    for i in range(m):
        c+=int(lst3[i])*lst2[i]
    print(c)


Measured memory_bytes: 6244
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int V, E;
pair<int, pair<int, int>> p[100000];


int main() {
  cin >> V >> E;
  UnionFind tree(V);

  rep(i, E) {
    int s, t, w;
    cin >> s >> t >> w;
    p[i].first = w;
    p[i].second = make_pair(s, t);
  }

  sort(p, p+E);
  int ans = 0;
  rep(i, E) {
    int s = p[i].second.first;
    int t = p[i].second.second;
    if(tree.same(s, t)) {
      continue;
    } else {
      tree.unite(s, t);
      ans += p[i].first;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4324
#include <stdio.h>
#include <math.h>

int main()
{
    int n, i;
    double s[1001], sum = 0.0, m, a = 0.0;
    
    while(1)
    {
        scanf("%d", &n);
        if(n == 0) break;
        for(i=0; i<n; i++){
            scanf("%lf", &s[i]);
            sum += s[i];
        }
        m = sum / n;
        for(i=0; i<n; i++) a += pow((s[i]-m), 2);
        a /= n;
        printf("%f\n", sqrt(a));
        sum = 0.0;
        a = 0.0;
    }
    return 0;
}

Measured memory_bytes: 664
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from copy import copy
import numpy as np
from numpy.fft import fft, ifft
from fractions import gcd


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

a, p = MAP()

print(int((a*3+p)/2))

Measured memory_bytes: 22760
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;
int n;
ll c, k, t[100500];

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

for(int i=1;i<=n;i++){
	cin >> t[i];
}
sort(t + 1, t + n + 1);
ll res = 0, cnt = 1, last = t[1];
for(int i=2;i<=n;i++){
	if(last + k >= t[i] && cnt < c){
		cnt++;
		continue;
	}
	cnt = 1;
	res++;
	last = t[i];
}
cout << res + 1;
return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
bool prime[1000000];
#define max 1000000
int main(){
	prime[1] = true;
	for(int i = 2; i * i < max; i++){
		if(!prime[i]){
			for(int j = i * i; j < max; j+=i){
				prime[j] = true;
			}
		}
	}
	int n;
	while(scanf("%d",&n) != EOF){
		int ans = 0;
		for(int i = 1; i <= n; i++){
			if(!prime[i])ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2000
import math

x = int(input())

if x == 2:
    print(2)
    exit()

def isprime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

while True:
    if isprime(x):
        print(x)
        exit()
    else:
        x += 1
print(x)


Measured memory_bytes: 9084
#include<bits/stdc++.h>
#define ll long long
const int MAX=1e+5;
using namespace std;

int H, N;
int A[MAX];
int main(){
	cin>>H>>N;
	int sum=0;
	for(int i=0; i<N; ++i){
		cin>>A[i];
		sum+=A[i];
	}
	cout<<(H<=sum?"Yes":"No");
	return 0;
}


Measured memory_bytes: 640
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = input()
d = {}
def sub(val):
    if val in d:
        return d[val]
    pc = 0
    for i in range(val.bit_length()):
        if val>>i&1:
            pc += 1
    if pc==0:
        ans = 0
    else:
        tmp = val % pc
        if tmp==0:
            ans = 1
        else:
            ans = sub(tmp) + 1
    d[val] = ans
    return ans

pc = sum(item=="1" for item in a)
val0 = 0 # pc-1
val1 = 0 # pc+1
for i in range(n):
    if a[i]=="1":
        if pc>1:
            val0 += pow(2,n-1-i,pc-1)
        val1 += pow(2,n-1-i,pc+1)
        
ans = [None]*n
# print(a)
for i in range(n):
    if a[i]=="1":
        if pc==1:
            val = 0
            ans[i] = 0
        else:
            val = (val0 - pow(2,n-1-i,pc-1))%(pc-1) #(1<<(n-1-i))
            ans[i] = sub(val) + 1
#         print(1, bin(val)[2:], pc-1)
    else:
        val = (val1 + pow(2,n-1-i,pc+1))%(pc+1) #(1<<(n-1-i))
        ans[i] = sub(val) + 1
#         print(0, bin(val)[2:], pc+1)
write("\n".join(map(str, ans)))

Measured memory_bytes: 93768
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, k: usize, a: [usize; n]);

    let check = |l: usize| {
        let mut s = 0;
        for &ai in &a {
            let t = ai / l + if ai % l == 0 { 0 } else { 1 } - 1;
            s += t
        }
        s <= k
    };

    let mut ok = 1_000_000_010;
    let mut ng = 0;
    while ok - ng > 1 {
        let m = (ok + ng) / 2;
        if check(m) {
            ok = m;
        } else {
            ng = m;
        }
    }
    println!("{}", ok);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 5436