akhauriyash/Code-Regression huggingface dataset:
n, k, *a = map(int, open(0).read().split())
a.sort()

mod = 10 ** 9 + 7

fact = [1] * (n + 1)
for i in range(1, n + 1):
    fact[i] = fact[i - 1] * i % mod


def inv(x):
    return pow(x, mod - 2, mod)


def c(n, k):
    return fact[n] * inv(fact[n - k] * fact[k] % mod) % mod


ans = 0
for i in range(k - 1, n):
    # a[i]がmax
    ans += a[i] * c(i, k - 1) % mod
a = list(reversed(a))
for i in range(k - 1, n):
    ans -= a[i] * c(i, k - 1) % mod
print((ans + mod) % mod)


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

int main() {
  int N;
  cin>>N;
  long pow=1;
  long div= 1000000007;
  for(int i=1;i<=N;i++){
    pow *=i;
    pow %=div;
  }

  cout<<pow<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};
//x以下の要素への最小index, ソートしてから使ってね
template <class T> 
int former(const vector<T> &v, T x){
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> 
int latter(const vector<T> &v, T x){
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
//素因数分解
template <class T>
map<T,T> prime_factor(T x){
    map<T,T> ans;
    for(T i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]=1;
    }
    return ans;
}
//約数列挙
template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}
//素数判定
template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

const ll inf=1e9+7;

ll mult(ll n,ll m){//n^m%infを求める
    if(m==1){
        return n%inf;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%inf;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%inf;
    }
}

typedef pair<int,int> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b<c+d){
        cout<<"Right"<<endl;
    }else if(a+b==c+d){
        cout<<"Balanced"<<endl;
    }else{
        cout<<"Left"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  int n;
  F f;
  G g;
  T ti;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int n_,F f,G g,T ti):
    f(f),g(g),ti(ti){
    init(n_);
  }
  void init(int n_){
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i>0;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  void update(int k,E a){
    k+=n;
    dat[k]=g(dat[k],a);
    while(k>0){
      k>>=1;
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
    }
  }
  inline T query(int a,int b){
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }
  int find(int a,int b,function<bool(T)> &check,int k,int l,int r){
    if(!check(dat[k])||r<=a||b<=l) return -1;
    if(k>=n) return k-n;
    int m=(l+r)>>1;
    int vl=find(a,b,check,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(a,b,check,(k<<1)|1,m,r);
  }
  int find(int a,int b,function<bool(T)> &check){
    return find(a,b,check,1,0,n);
  }
};
//END CUT HERE
signed AOJ_DSL2A(){
  int n,q;
  scanf("%d %d",&n,&q);
  auto f=[](int a,int b){return min(a,b);};
  auto g=[](int a,int b){++a;return b;};
  SegmentTree<int,int> rmq(n,f,g,INT_MAX);
  
  for(int i=0;i<q;i++){
    int c,x,y;
    scanf("%d %d %d",&c,&x,&y);
    if(c) printf("%d\n",rmq.query(x,y+1));
    else rmq.update(x,y);
  }
  return 0;
}
/*
  verified on 2018/03/04
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp
*/

signed ARC038_C(){
  Int n;
  cin>>n;
  vector<Int> c(n,0),a(n,0);
  for(Int i=1;i<n;i++) cin>>c[i]>>a[i];
  
  SegmentTree<Int, Int>::F f=[](Int a,Int b){return min(a,b);};
  SegmentTree<Int, Int>::G g=[](Int a,Int b){return max(a,b);};
  SegmentTree<Int, Int> seg(n,f,g,-1);
  
  vector<Int> dp(n);
  dp[0]=0;
  seg.update(0,0);
  for(Int i=1;i<n;i++){
    function<bool(Int)> check=[&](Int x){return x<i-c[i];};
    dp[i]=seg.find(0,n,check);
    seg.update(dp[i],i);
  }
  
  Int ans=0;
  for(Int i=1;i<n;i++)
    if(a[i]&1) ans^=dp[i];
  
  cout<<(ans?"First":"Second")<<endl;
  return 0;
}

/*
  verified on 2018/01/30
  https://beta.atcoder.jp/contests/arc038/tasks/arc038_c
*/

signed main(){
  AOJ_DSL2A();
  //ARC038_C();
  return 0;
}



Measured memory_bytes: 3848
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s, t, last;
    cin >> s;
    int i = 0;
    vector<string>ans;
    while(i < s.size())
    {
        t += s[i++];
        if(t == last)
            continue;
        last = t;
        ans.push_back(t);
        t = "";
    }
    cout << ans.size();
    return 0;
}


Measured memory_bytes: 11016
#include <iostream>
#include<cmath>
#include<set>
#include<cstdio>
#include<algorithm>
#include<utility>
using namespace std;
long long a, b, c, ans, k;
int main()
{
	cin >> a >> b >> c >> k;
	if (k % 2 == 0)ans = a - b;
	else ans = b - a;
	if (abs(ans) > 1e18)cout << "Unfair";
	else cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

template<typename T>
struct FenwickTree{
	vector<T> node;
	int n;
	int sz;
	FenwickTree(int n) :n(n) { 
		node.resize(n+1LL,0);
		sz=1;
		while(sz<node.size()) sz*=2;
	}
	T sum(int k) {
		T ret = 0;
		for (;k>0;k-=(k & -k)) ret+=node[k];
		return ret;
	}
	
	T sum(int a, int b){return sum(b)-sum(a);}//[a,b)
 
	void add(int k, T x) {
		for(;k<=n;k+=(k & -k)) node[k]+=x;
	}
};

//Compress<ll> comp(a);みたいな感じで
template <class T>
struct Compress{
    int N;
    map<T,int> idx;
    vector<T> cmp;
    Compress(vector<T> v){
        for(auto& x:v) cmp.push_back(x);
        sort(cmp.begin(),cmp.end());
        cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
        N=cmp.size();
        for(int i=0;i<N;i++) idx[cmp[i]]=i;
    }
    int id(T val){return idx[val];}//前→後
    T val(int id){return cmp[id];}//後→前
};
	

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<ll> a(n);
    FenwickTree<ll> seg(n+1);
    ll ans=0;
    rep(i,n){
        cin>>a[i];
    }
    Compress<ll> comp(a);
    rep(i,n){
        a[i]=comp.id(a[i])+1;
    }
    rep(i,n){
        ans+=seg.sum(a[i],n+1);
        seg.add(a[i],1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 21556
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var S = ReadLine();
            var l = 0;
            var r = S.Length - 1;
            var ans = 0;
            while(l<r)
            {
                if(S[l]==S[r])
                {
                    l++;
                    r--;
                }
                else if (S[l] == 'x')
                {
                    l++;
                    ans++;
                }
                else if (S[r] == 'x')
                {
                    r--;
                    ans++;
                }
                else
                {
                    WriteLine(-1);
                    return;
                }
            }
            WriteLine(ans);
        }
    }
}


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

using namespace std;

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


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

int main () {
    int H, W;
    cin >> H >> W;
    
    while (H!=0 && W!=0) {
        for (int i=0; i<H; i++) {
            for (int j=0; j<W; j++) {
                cout << "#";
            }
            cout << endl;
        }
        
        cin >> H >> W;
        cout << endl;
    }
    
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	using P = pair<int, pair<int, int>>;
	vector<P> infos(N);
	for (int i = 0; i < N; i++) cin >> infos[i].second.first >> infos[i].second.second >> infos[i].first;
	sort(infos.begin(), infos.end(), greater<P>());

	for (int cx = 0; cx <= 100; cx++) {
		for (int cy = 0; cy <= 100; cy++) {
			int H = infos[0].first + abs(infos[0].second.first - cx) + abs(infos[0].second.second - cy);
			bool IsOK = true;
			for (int i = 1; i < N; i++) {
				int HH = infos[i].first + abs(infos[i].second.first - cx) + abs(infos[i].second.second - cy);
				if (infos[i].first > 0 && H != HH) {
					IsOK = false;
					break;
				}
				if (infos[i].first == 0 && HH < H) {
					IsOK = false;
					break;
				}
			}
			if (IsOK) {
				cout << cx << " " << cy << " " << H << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        boolean[] isPrime = new boolean[55556];

        for(int i = 4; i < 55556; i+=2){
            isPrime[i] = true;
        }

        for(int i = 3; i < 55556; i+=2){
            if(!isPrime[i]){
                for(int j = i*2; j < 55556; j+=i){
                    isPrime[j] = true;
                }
            }
        }

        int n = Integer.parseInt(br.readLine());
        int count = 2; 

        System.out.print("11");
        for(int i = 13; i < 55556 && count <= n; i+=2){
            if(!isPrime[i] && i%10 == 1){
                count++;
                System.out.print(" " + i);
            }
        }


    }
}

Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
long long x,y;
long long k;
int ans;
long long gcd(long long a,long long b) {
    return b==0?a:gcd(b,a%b);
}
int main() {
	cin>>x>>y;
	k=gcd(x,y);
	for(int i=2;i<=sqrt(k);i++) 
		if(!(k%i)) {
			ans++;
			while(!(k%i)) k/=i;
		}
	if(k>1) ans++;
	cout<<++ans;
	return 0;
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	rep(i, n - 2) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			ans++;
		}
	}
	print(ans);
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	
	int N,M;
	cin>>N>>M;
	vector<int> A(N);
	vector<int> B(N);
	FDS(i,N){
		cin>>A[i]>>B[i];
	}
	
	vector<pair<int,int>> AB(N);
	FDS(i,N){
		AB[i]= make_pair(A[i],B[i]);
	}
	VSORT(AB);//pair型は前からsortされる
	ll ans=0;
	FDS(i,N){
		int buy =min(M,AB[i].second);//買う数
		
		ans+=(ll)buy*AB[i].first;
		M-=buy;
	}
	cout<<ans<<endl;
}


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

int main(){
	int n,k;cin>>n>>k;
	if(k==1 || k==2*n-1){
		cout<<"No"<<endl;
		return 0;
	}
	else{
	cout<<"Yes"<<endl;
	if(n==k){
		for(int i=1;i<=2*n-1;i++){
			cout<<i<<endl;
		}
	}
	else if (k<n){
		for(int i=n+k-2;i>=k-1;i--){
		cout<<i<<endl;}
		for(int i=n+k-1;i<=2*n-1;i++){
		cout<<i<<endl;}
		for(int i=1;i<k-1;i++){
		cout<<i<<endl;}
	}
	else{
		for(int i=k-n+2;i<=k+1;i++){
			cout<<i<<endl;
		}
		for(int i=k-n+1;i>=1;i--){
			cout<<i<<endl;
		}
		for(int i=k+2;i<=2*n-1;i++){
			cout<<i<<endl;
		}

	}
    }
}

Measured memory_bytes: 1536
n,m = map(int,input().split())
a = set([int(input()) for _ in range(m)])
dp = [0] * (n + 1)
dp[0] = 1
mod = 10**9+7
for i in range(1,n+1):
    if i in a:
        dp[i] = 0
    elif i == 1:
        dp[i] = 1
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[-1])

Measured memory_bytes: 13168
#include<cstdio>
#include<map>
using namespace std;
typedef long long ll;
int i,j,k,n,m,ff,ch,pn,ans,Fg;
ll s;
int p[3030];
map<ll,ll> S;
map<ll,int> Map;
map<ll,int>::iterator it;
void R(ll &x) {
    ff=x=0;ch=getchar();
    while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
    while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
    if (ff) x=-x;
}
bool check(int x) {
    for (int i=2;i*i<=x;i++) if (x%i==0) return 0;
    return 1;
}
ll sqrt(ll x) {
    ll l=1,r=100000,mid;
    while (l<r) {
        mid=(l+r+1)>>1;
        if (mid*mid<=x) l=mid;
        else r=mid-1;
    }
    return l;
}
int main() {
    scanf("%d",&n);
    for (i=2;i<=3000;i++) if (check(i)) p[++pn]=i;
    for (i=1;i<=n;i++) {
        R(s);
        ll a=1,b=1;
        for (j=1;j<=pn;j++) if (s%p[j]==0) {
            ll t=0;
            while (s%p[j]==0) s/=p[j],t++;
            t%=3;
            if (!t) continue;
            for (k=0;k<t;k++) a*=p[j];
            for (k=3;k>t;k--) b*=p[j];
        }
        ll t=sqrt(s);
        if (t*t==s) a*=s,b*=t;
        else {
            if (10000000000ll/b/s/s>=1) a*=s,b*=s*s;
            else {
                ans++;
                continue;
            }
        }
        if (a==1) Fg=1;
        else {
            S[a]=b;
            Map[a]++;
        }
    }
    ans+=Fg;
    for (it=Map.begin();it!=Map.end();it++) {
        ll a=(*it).first;
        ll b=S[a];
        if (Map[a]<Map[b] || (Map[a]==Map[b] && a<b)) continue;
        ans+=Map[a];
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 20864
#include <cstdio>
#include <algorithm>

const int MAX_N = 100005;
int N, K;
struct v {
  int size, val;
} vals[MAX_N];

long long getVal(int k) {
  long long tot = 0;
  for (int i = 0; i < N; ++i) {
    if ((vals[i].size & k) == vals[i].size) tot += vals[i].val;
  }
  return tot;
}

int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &vals[i].size, &vals[i].val);
  }
  long long max = 0;
  for (int i = 0; i <= 31; ++i) {
    max = std::max(max, getVal(K));
    if (K & (1 << i)) {
      K -= (1 << i);
      K |= (1 << i) - 1;
    }
  }
  printf("%lld\n", max);
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int input,s1,s2,s3,output;
    cin >> input;
    s1 = input%10;
    input /= 10;
    s2 = input%10;
    input /= 10;
    s3 = input%10;
    input /= 10;
    if (s1 == 1) output++;
    if (s2 == 1) output++;
    if (s3 == 1) output++;
    cout << output << endl;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int n, m, a = 0;
  cin >> n >> m;
  v1i v(m);
  rep(i, m) cin >> v[i];
  rep(i, m) a += v[i];
  if(a > n) cout << -1 << endl;
  else cout << n-a << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>       // printf,scanf
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>  //sort,binarySearch
#include <functional> 
#include <iomanip>    // setprecision
#include <utility>    // c+11 Array
#include <set>
#include <sstream>
#include <map>
#include <bits/stdc++.h>
#define MOD (1e+9)+7
#define PI 3.141592653589793238462643383279
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define pb(x) push_back(x)
#define debug(x) cerr << #x << " = " << x << endl;
#define debret(x) debug(x) ; return 0;

using namespace std;

int main(){

    string str;
    string ans = "";

    REP(i,3){
        cin >> str;
        ans += str[0];
    }

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


Measured memory_bytes: 384
import numpy as np
from collections import deque
# h, w = map(int,input().split())
# maze = [list(input()) for i in range(h)]
# seen = [[-1]*w for _ in range(h)]
# move = [[1,0],[-1,0],[0,1],[0,-1]]
# # start = [0,0]
# start = [2,2]
# g = [4,5]
# que = [start]
# seen[start[0]][start[1]] = 0
# que.append(start)
# while que:
#     y,x = que.pop(0)
#     if (y == g[0]) and (x == g[1]):
#         break
#     for i in range(len(move)):
#         ny,nx = y+move[i][0], x+move[i][1]
#         if (0 <= ny < h) and (0 <= nx < w):
#             if maze[ny][nx] == '.':
#                 if seen[ny][nx] == -1:
#                     seen[ny][nx] = seen[y][x]+1
#                     que.append([ny,nx])

# print(seen[])

def bfs(maze, visited, sy, sx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        y, x = queue.popleft()
        # if [y, x] == [gy, gx]:
            # return visited[y][x]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if (0<=new_y<len(maze)) and (0<=new_x<len(maze[0])):
                if maze[new_y][new_x] == "." and \
                    visited[new_y][new_x] == -1:
                    
                    visited[new_y][new_x] = visited[y][x] + 1
                    queue.append([new_y, new_x])
    return visited

h, w = map(int, input().split())
maze = [input() for i in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if (maze[i][j] == '.'):
            sy,sx = i,j
            visited = [[-1]*w for j in range(h)]
            vi = bfs(maze,visited,sy,sx)
            a = np.array(vi).flatten().max()
            ans = max(ans, a)
# sy,sx = 0,0
# visited = [[-1]*w for j in range(h)]
# r = bfs(maze, visited, sy, sx)
print(ans)


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

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define MAGIC0
mt19937 rnd(time(0)); //rnd()

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e5 + 7;
const double PI = acos(-1.);
const double EPS = 1e-8;
const int MOD = 998244353;

int main()
{
	ios_base::sync_with_stdio(0);
	int n, a, b;
	cin >> n >> a >> b;
	cout << (n - a + 1) * (n - b + 1);

	return 0;
}


Measured memory_bytes: 256
#![allow(dead_code)]
use std::io;
use std::f64;

fn main() {
    solve_d();
}

fn solve_d() {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    let n = n.trim().parse::<f64>().unwrap();

    let mut xs = String::new();
    io::stdin().read_line(&mut xs).unwrap();
    let xs: Vec<_> = xs.trim()
        .split_whitespace()
        .map(|s| s.parse::<f64>().unwrap())
        .collect();
    let mut ys = String::new();
    io::stdin().read_line(&mut ys).unwrap();
    let ys: Vec<_> = ys.trim()
        .split_whitespace()
        .map(|s| s.parse::<f64>().unwrap())
        .collect();

    let mut max = -1_f64;
    let mut sum = 0_f64;
    let mut sum2 = 0_f64;
    let mut sum3 = 0_f64;
    for i in 0..(n as usize) {
        let abs = (xs[i] - ys[i]).abs();
        if max < abs {
            max = abs;
        }
        sum += abs;
        sum2 += abs.powi(2);
        sum3 += abs.powi(3);
    }

    println!("{:.5}", sum);
    println!("{:.5}", sum2.sqrt());
    println!("{:.5}", sum3.powf(0.33333333333));
    println!("{:.5}", max);
}



Measured memory_bytes: 5172
#include<iostream>
#include<string>
#include<cmath>
#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
//#include<bitset>
#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI  r;
//	if (x < y) {
//		swap(x, y);
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x, LLI y) {
//	return x / gcd(x, y) * y;
//}

//long nCr(int n, int r) {
//	long ans = 1;
//	for (int i = n; i > n - r; i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; i++) {
//		ans = ans / i;
//	}
//	return ans;
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI cnt = 0;
	cin >> N;
	vector<LLI>vec(N);
	for (int i = 0; i < N;i++) {
		cin >> vec[i];
	}
	sort(vec.begin(), vec.end());
	if (vec[N/2] == vec[N/2 - 1]) {

	}
	else {
		cnt = vec[N / 2] - vec[N / 2 - 1];
	}
	cout << cnt << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ld,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<ll> A(N);
    ll ma=0,mi=N;
    rep(i,N) cin>>A[i];
    rep(i,N){
        maxi(ma,A[i]);
        mini(mi,A[i]);
    }
    if(ma>mi+1){ cout<< "No" <<"\n"; return;}
    if(ma==mi){
        if(ma==N-1 or (ma>=1 and ma<=N/2)){ cout<< "Yes" <<"\n"; return;}
        else{cout<< "No" <<"\n"; return;}
    }
    ll mact=0;
    ll mict=0;
    rep(i,N){
        mact+= ma==A[i];
        mict+= mi==A[i];
    }
    ma-=mict;
    if(ma>=1 and ma<=mact/2) cout<< "Yes"<<"\n";
    else cout<< "No"<<"\n";

}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<set>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

const int MX = 100005;

vector<pii> D;
string ans = "", cur = "";
int mn;

int main()
{
	int N, cnt = 0;
	scanf("%d", &N);
	while(N % 2 == 0) N /= 2;
	while(N % 5 == 0) N /= 5;
	if( N == 1 ) return !printf("1\n");
	ll m = 1;
	set<int> L;
	for(int i = 1; i <= N; i++){
		L.insert(m);
		m = m * 10 % N;
	}
	for(int c : L){
		if( (c+1) % N == 0 ) return !printf("2\n");
	}
	for(int c : L){
		if( L.find((N-c-1) % N) != L.end() ) return !printf("3\n");
	}

	int vst[MX] = {};

	vst[1] = 1;
	for(int c : L){
		for(int t = 0; t < 2; t++){
		for(int i = 0; i < N; i++){
			if( vst[i] ){
				int& d = vst[(i+c)%N];
				if( d ) d = min(d, vst[i] + 1);
				else d = vst[i]+1;
			}
		}
		}
	}
	printf("%d\n", vst[0]);
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	int n, k; cin >> n >> k;

	int c = 0;
	FOR_LT(i, 0, n) {
		int h; cin >> h;
		if (k <= h) c++;
	}

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

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

int main(int argc, const char * argv[]) {
    
    int N;
    cin >> N;
    
    int h[N],p[N];
    
    for(int i=0;i<N;i++)
    {
        cin >> h[i];
    }
    
    
    
    for(int i=0;i<N;i++)
    {
        p[h[i]-1] = i+1;
    }
    
    for(int i=0;i<N;i++)
    {
        cout << p[i] << " ";
    }
    
    cout << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main () {
	int n, d;
	scanf("%d %d", &n, &d);
	if(n % (d * 2 + 1)){
		printf("%d\n", n / (d * 2 + 1) + 1);
	}else{
		printf("%d\n", (n / (d * 2 + 1)));
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include <vector>
#include <string>
#include <set>
#include <utility>
using namespace std ;
using ll = long long ;
using vll = vector<ll> ;
using pll = pair<ll,ll> ;

int main(){
    ll a,b,m ;
    cin >> a >> b >> m ;
    vll A(a) ;
    vll B(b) ;
    ll mna = 10000000000 ;
    ll mnb = 10000000000 ;
    for(int i=0;i<a;i++){
        ll sub ; cin >> sub ;
        if(sub<mna) mna = sub ;
        A.at(i) = sub ;
    }
    for(int i=0;i<b;i++){
        ll sub ; cin >> sub ;
        if(mnb>sub) mnb = sub ;
        B.at(i) = sub ;
    }
    ll mnc = 10000000000 ;
    for(int i=0;i<m;i++){
        ll x,y,c ;
        cin >> x >> y >> c ;
        ll cost = A.at(x-1)+B.at(y-1)-c ;
        if(mnc>cost) mnc = cost ;
    }
    if(mna+mnb<mnc) mnc = mna+mnb ;
    cout << mnc << endl ;
    
}





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

int main() {
    int h, w, d;
    cin >> h >> w >> d;
    int rs[h * w + 1], cs[h * w + 1];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int a;
            cin >> a;
            rs[a] = i;
            cs[a] = j;
        }
    }
    int acc[h * w + 1];
    for (int i = 1; i <= d; i++) {
        acc[i] = 0;
    }
    for (int i = d + 1; i <= h * w; i++) {
        acc[i] = acc[i - d] + abs(rs[i] - rs[i - d]) + abs(cs[i] - cs[i - d]);
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << acc[r] - acc[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
 
typedef long long LL;
typedef pair<int, int> PII;

const int MAX = 1 << 8;

LL a[MAX];
string s;
vector<LL> b;

bool add(LL x)
{
	for(LL y: b)
		if((x ^ y) < x)
			x ^= y;
	if(x == 0)
		return false;
	for(LL& y: b)
		if((y ^ x) < y)
			y ^= x;
	b.push_back(x);
	sort(ALL(b));
	return true;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		FOR(i, 0, n)
			cin >> a[i];
		cin >> s;
		bool ans = false;
		RFOR(i, n, 0)
		{
			if(add(a[i]) && s[i] == '1')
				ans = true;
		}
		cout << ans << "\n";
		b.clear();
	}
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

int n;
vector<int> a;
int ans[100000][2];
int result;
int in;
int main(){
    cin >> n;
    rep(i,n){
        cin >> in;
        a.push_back(in);
    }

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

    for(int i=0; i<n-2; i++){
        /*
        cout << "\t";
        for(int j=0; j<a.size(); j++){
            cout << a[j] << " ";
        }
        cout << endl;
        */
        if(a[1] <= 0){
            ans[i][0] = a.back();
            ans[i][1] = a[1];
            a.back() = (a.back() - a[1]);
            a.erase(a.begin() + 1);
        }else{
            ans[i][0] = a.front();
            ans[i][1] = a[1];
            a.front() = (a.front() - a[1]);
            a.erase(a.begin() + 1);
        }
    }

        // cout << "\t";
        // for(int j=0; j<a.size(); j++){
        //     cout << a[j] << " ";
        // }
        // cout << endl;

    ans[n-2][0] = a[1];
    ans[n-2][1] = a[0];
    //cout << "a:" << ans[n-2][0] << "\tb:" << ans[n
    result = ans[n-2][0] - ans[n-2][1];

    cout << result << endl;
    for(int i=0; i<n-1; i++){
        cout << ans[i][0] << " " << ans[i][1] << endl;
    }

    return 0;
}

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

int main()
{
    char s[25];
    cin >> s;
    for(int i=0; i<19; i++){
        if(i==5 || i==13){
            cout << ' ';
        }else{
            cout << s[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;


int main(){
    ll n,v; cin >> n >> v;
    vl a(n),b(n),c(n),d(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    rep(i,n) cin >> d[i];
    vl ab,cd;
    rep(i,n){
        rep(j,n){
            ab.push_back(a[i]+b[j]);
            cd.push_back(c[i]+d[j]);
        }
    }
    sort(all(ab)), sort(all(cd));
    ll ans = 0;
    for(auto i : ab){
        ans += upper_bound(all(cd),v-i) - lower_bound(all(cd),v-i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 18844
#include <bits/stdc++.h>
#define oo int(1e9)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9) + 7;
int H, W;
vector<vector<char>> a;
vector<vector<ll>> dp;


int main() {
	cin.tie(0); ios::sync_with_stdio(0); cout.tie(0);
    cin >> H >> W;
    a.resize(H,vector<char> (W));
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++) cin >> a[i][j];
        
    dp.resize(H + 1,vector<ll> (W + 1));
    dp[1][1] = (a[0][0] != '#');
    for (int i = 1; i <= H; i++)
        for (int j = 1; j <= W; j++){
            if (a[i - 1][j - 1] == '#' || (i == 1 && j == 1)) continue;
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
        }
    cout << dp[H][W];    
	return 0;
}

Measured memory_bytes: 9088
s = gets.chomp
q = gets.to_i
queries = q.times.map { gets.split }

s1 = ''
reversed = false

queries.each do |t, f, c|
  if t == '1'
    reversed = !reversed
    next
  end

  if (f == '1' && reversed) || (f == '2' && !reversed)
    s << c
  else
    s1 << c
  end
end

if reversed
  puts s.reverse! << s1
else
  puts s1.reverse! << s
end


Measured memory_bytes: 54908
#include<iostream>
#include<string>
using namespace std;
int main (){
string s,u,t;
int a,b;
cin >> s >> t;

cin >> a>>b;

cin>>u;

if (s==u){
a--;
} else {
b--;
}

cout << a << ' ' << b << endl;



return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from networkx.utils import UnionFind
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    n,m=map(int, input().split())
    uf = UnionFind()
    for i in range(1,n+1):
        _=uf[i]
    for _ in range(m):
        a,b=map(int, input().split())
        uf.union(a, b)  # aとbをマージ
    print(len(list(uf.to_sets()))-1)
    #for group in uf.to_sets():  # すべてのグループのリストを返す
        #print(group)

if __name__ == '__main__':
    main()



Measured memory_bytes: 87140
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{BufWriter, Write};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    input!(
        a: [usize; 5],
    );

    let mut ans = 0;
    let mut sub = 0;
    for i in 0..5 {
        ans += (a[i] + 9) / 10 * 10;
        sub = max(sub, (10 - a[i] % 10) % 10);
    }
    println!("{}", ans - sub);
}

fn main() {
    let stack_size = 1 << 28;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue<int, vector<int>, greater<int> > q;
#include <map>
#include <set> //multiset set<int,greater<int>>大到小
#include <vector>// vector<int>().swap(v);清空释放内存
#include <stack>
#include <cmath> // auto &Name : STLName  Name.
#include <utility>
#include <sstream>
#include <string>//__builtin_popcount(ans);//获取某个数二进制位1的个数
#define mod 1000000007
#define mod9 998244353
#define ld long double
#define ull unsigned long long
#define db double
#define ll long long
const db eps=1e-7;
//const db pi=acos(-1);
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
#define rep(i,be,en) for (ll i=be;i<=en;i++)
#define per(i,be,en) for (int i=en;i>=be;i--)
using namespace std;
const int N=1e5+7;

int t,n,m,k,fl=0,ans=0;
int a[N],b[N];
int main() {
    scanf("%d%d",&n,&m);
    rep(i,1,n) scanf("%d",&a[i]);
    rep(i,1,m){
        scanf("%d%d",&t,&k);
        if(a[t]==a[k]){
            b[t]++;b[k]++;
        }else
        if(a[t]<a[k]){
            b[t]++;
        }else if(a[t]>a[k]){
            b[k]++;
        }
    }
    rep(i,1,n) if(b[i]==0) ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 4008
#include <limits>
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>
using namespace std;

template<typename T>
inline T dbl(T x){ return x * x; }

int main(){
  const int n = getInt();
  vector<pair<int, int> > v(n);

  REP(i,n){
    v[i].first = getInt();
    v[i].second = getInt();
  }

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

  int ans = numeric_limits<int>::max();

  REP(i,n){
    const pair<int, int> &x = v[i];
    for(int j = i + 1; j < n; j++){
      const pair<int, int> &y = v[j];
      if(dbl(y.first - x.first) >= ans) break;
      ans = min(ans, dbl(x.first - y.first) + dbl(x.second - y.second));
    }
  }

  printf("%d\n", ans);

  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 2011

typedef long long ll;
typedef long double ld;

int choose[maxn][maxn], dp[maxn][maxn], sum[maxn][maxn];

int add(int x, int y){
	return (1LL * x + y) % MOD;
}

int mult(int x, int y){
	return (1LL * x * y) % MOD;
}

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

	for(int i = 0; i < maxn; i++){
		dp[0][i] = dp[i][0] = 1;
		choose[i][0] = sum[i][0] = 1;
	}

	for(int i = 1; i < maxn; i++){
		for(int j = 1; j <= i; j++){
			choose[i][j] = add(choose[i - 1][j - 1], choose[i - 1][j]);
			sum[i][j] = add(sum[i][j - 1], choose[i][j]);
		}
	}

	for(int i = 1; i < maxn; i++){
		for(int j = 1; j < maxn; j++){
			dp[i][j] = add(dp[i - 1][j], sum[j - 1][min(i, j - 1)]);
		}
	}

	ll ans = 0;
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= min(a - i, b - 1); j++){
			ans = add(ans, mult(dp[a - i - j][j], choose[b - 1][j]));
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 46720
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int[] input = new int[n];

		String[] tmpArray = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			input[i] = Integer.parseInt(tmpArray[i]);
		}

		Arrays.sort(input);

		int border = input[n/2] - input[n/2 - 1];

		System.out.println(border);
	}

}


Measured memory_bytes: 36924
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

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

// conversion
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();
}

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

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

  lint x, y;
  cin >> x >> y;

  lint s = x, ans = 0;
  while (s <= y) {
    s *= 2;
    ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=1000005;
int n,i,j,ans,pt[N],q[N],bg,ed;
char s0[N],t[N];
int main()
{
	scanf("%d",&n);
	scanf("%s%s",s0+1,t+1);
	if(strcmp(s0+1,t+1)==0)
	{
		printf("0");
		return 0;
	}
	for(i=j=n;i>=1;--i)
	{
		j=min(j,i);
		while(j>=1&&s0[j]!=t[i])
			--j;
		if(j<1)
		{
			printf("-1");
			return 0;
		}
		pt[i]=j;
	}
	bg=1,ed=0;
	for(i=n,j=0;i>=1;--i)
	if(pt[i]!=pt[i-1])
	{
		while(bg<=ed&&q[bg]-(ed-bg+1)>=i)
			++bg;
		if(i!=pt[i])
			q[++ed]=pt[i];
		ans=max(ans,ed-bg+1);
	}
	printf("%d",ans+1);
	return 0;
}


Measured memory_bytes: 9984