akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

//const ll mod = 1000000007;

int main() {
    int s,w;
    cin >> s >> w;
    string ans = s <= w ? "unsafe" : "safe";
    cout << ans << endl;
}

Measured memory_bytes: 3572
import java.io.IOException
import java.lang.NumberFormatException
import java.lang.StringBuilder
import kotlin.math.max
import kotlin.math.pow

object AMain{
    fun solve(){
        val n = nextInt()
        val k = nextInt()
        val p = IntArray(n){ nextInt()}

        p.sort()
        var ans = 0
        for(i in 0 until k){
            ans += p[i]
        }
        println(ans)
    }





    // Scanner based on uwi-san's Java code
    val stream = System.`in`
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0

    fun hasNextByte(): Boolean{
        if(ptr < buflen){
            return true
        }else{
            ptr = 0
            try{
                buflen = stream.read(buffer)
            }catch (e: IOException){
                e.printStackTrace()
            }
            if(buflen <= 0){
                return false
            }
        }
        return true
    }

    fun readByte() =
        if(hasNextByte()) buffer[ptr++]
        else -1

    fun isPrintableChar(c: Byte) = c in 33..126

    fun hasNext(): Boolean{
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++
        return hasNextByte()
    }

    fun next(): String{
        if(!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while(isPrintableChar(b)){
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun nextLong(): Long{
        if(!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if(b == '-'.toByte()){
            minus = true
            b = readByte()
        }
        if(b !in '0'.toByte()..'9'.toByte())
            throw NumberFormatException()
        while(true){
            if(b in '0'.toByte()..'9'.toByte()){
                n *= 10
                n += b - '0'.toByte()
            }else if(!isPrintableChar(b)){
                return if(minus) -n else n
            }else{
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextInt(): Int{
        val n1 = nextLong()
        if(n1 !in Int.MIN_VALUE..Int.MAX_VALUE)
            throw NumberFormatException()
        return n1.toInt()
    }

    fun NextDouble() = next().toDouble()
}

fun main(){
    AMain.solve()
}



Measured memory_bytes: 36872
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int k,n;
	cin>>n>>k;
	vector<int> a;
	for(int i=0;i<n;++i){
		int val;
		cin>>val;
		a.push_back(val);
	}
	int ans = 0;
	sort(a.begin(),a.end());
	for(int i=0;i<k;++i){
		ans += a[i];
	}
	cout<<ans<<'\n';
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  int sum = 0;
  for (int i = 0; i < N - 1; i++) {
    sum += A.at(i);
  }
  
  if (sum > A.at(N-1)) {
    cout << "Yes" <<endl;
  }
  else {
    cout << "No" <<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << (x) << std::endl
constexpr int INF = 1 << 30;

struct CostGraph
{
    using T = int;
    CostGraph(int V) : V(V), edge(V) {}
    void addEdge(const int i, const int j, const int c)
    {
        edge[i].push_back(Edge{i, j, c});
    }
    struct Edge
    {
        int from;
        int to;
        int cost;
    };
    int V;
    std::vector<std::vector<Edge>> edge;
};

std::vector<int> Dijkstra(const CostGraph& g, const int s)
{
    std::vector<int> d(g.V, INF);
    using P = std::pair<int, int>;
    std::priority_queue<P, std::vector<P>, std::greater<P>> q;
    d[s] = 0, q.push({0, s});
    while (not q.empty()) {
        const auto p = q.top();
        const int cost = p.first, v = p.second;
        q.pop();
        if (d[v] < cost) { continue; }
        for (const auto& e : g.edge[v]) {
            if (d[e.to] <= d[v] + e.cost) { continue; }
            d[e.to] = d[v] + e.cost, q.push({d[e.to], e.to});
        }
    }
    return d;
}

int main()
{
    int N;
    std::cin >> N;

    std::vector<std::vector<int>> a(26);
    for (int i = 0; i < N; i++) {
        std::string s;
        std::cin >> s;
        const int ind = s.front() - 'a';
        a[ind].push_back(i);
    }
    CostGraph g(N);
    for (int i = 0; i < N - 1; i++) { g.addEdge(i, i + 1, 1); }
    for (int i = 0; i < 26; i++) {
        const int sz = a[i].size();
        for (int j = 0; j < sz - 1; j++) {
            g.addEdge(a[i][j], a[i][j + 1], 0);
        }
    }
    const auto d = Dijkstra(g, 0);
    std::cout << d[N - 1] + 1 << std::endl;
    return 0;
}



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

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

int L;
vector<P> G[30]; // const, to
vector<bool> op; // T: x2, F: +1
int s,t,now,e;

void gen_op(int num){
	if(num == 2) return;
	if(num%2 != 0){
		gen_op(num-1);
		op.push_back(false);
	}else{
		gen_op(num/2);
		op.push_back(true);	
	}
	return;
}

void make_graph(){
	for (int i = 0;i < op.size();i++){
		if(op[i]){
			for (int j = s;j < t;j++){
				for (int k = 0;k < G[j].size();k++){
					G[j][k].first *= 2;
				}
			}
			G[t].push_back(P(0,t+1));
			G[t].push_back(P(1,t+1));
			t++;
			e += 2;
			now *= 2;
		}else{
			G[s].push_back(P(now,t));
			now += 1;
			e++;
		}
	}
}

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

	cin >> L;

	G[1].push_back(P(0,2));
	G[1].push_back(P(1,2));
	s = 1;
	t = 2;
	now = 2;
	e = 2;

	gen_op(L);
	make_graph();

	cout << t << " " << e << endl;

	for (int i = s;i < t;i++){
		for (int j = 0;j < G[i].size();j++){
			cout << i << " " << G[i][j].second << " " << G[i][j].first << endl;
		}
	}

	return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
void trace(int A[], int N){
    for (int i = 0; i < N; i++){
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

/* バブルソート */
int bubbleSort(int A[], int N){
    int flag, j, temp, count;
    flag = 1;
    count = 0;
    while(flag){
        flag = 0;
        for (j = 1; j < N; j++){
            if (A[j] < A[j - 1]){
                temp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = temp;
                flag = 1;
                count += 1;
            }
        }
    }
    return count;
}

int main() {
    int N, i, count;
    int A[100];
    
    scanf("%d", &N);
    for (i = 0; i < N; i++) scanf("%d", &A[i]);
    count = bubbleSort(A, N);
    trace(A, N);
    printf("%d\n", count);

    return 0;
}



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

int main(){
	int b[5];
	while (cin >> b[0], b[0]) {
		int a[4]{};
		a[b[0]] = true;
		for (int i = 1; i < 5; i++) {
			cin >> b[i]; a[b[i]] = true;
		}
		int cnt = 0;
		for (int i = 1; i <= 3; i++)if (a[i])cnt++;
		if (cnt == 1 || cnt == 3) {
			rep(i, 5)puts("3");
			continue;
		}
		int m; for (int i = 1; i <= 3; i++)if (!a[i])m = i;
		int k;
		switch (m) {
		case 1:k = 2; break;
		case 2:k = 3; break;
		case 3:k = 1; break;
		}
		rep(i, 5) {
			if (b[i] == k)puts("1");
			else puts("2");
		}
	}
	return 0;
}

Measured memory_bytes: 2964
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll a[225816];

int main(void){
	int n,i=0;
	ll m=INFLL,ans=0ll;
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> a[i];
	}
	std::sort(a,a+n,std::greater<ll>()); i = 0;
	ans += a[i];
	n-=2; ++i;
	while(true){
		if(n){
			--n;
			ans += a[i];
		}else{
			break;
		}
		if(n){
			--n;
			ans += a[i];
		}else{
			break;
		}
		++i;
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 5144
#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; }

// ガウスの消去法（Gauss elimination）
// O(n^3)
// 
// Verified:
//   http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2488795

using Num = double;
using Vec = vector<Num>;
using Mat = vector<Vec>;
const Num EPS = 1e-5; // 誤差
pair<bool, Vec> gaussianElimination(Mat A, Vec b) {
	const int n = A.size(), m = A[0].size();
	int ci = 0, cj = 0;
	while (ci < n && cj < m) {
		// A[ci][cj] が最大になるように
		for (int i = ci + 1; i < n; i++) {
			if (abs(A[i][cj]) > abs(A[ci][cj])) {
				A[i].swap(A[ci]);
				swap(b[i], b[ci]);
			}
		}
		if (abs(A[ci][cj]) > 0) {
			// 係数を 1 に
			Num d = A[ci][cj];
			for (int j = 0; j < m; j++)
				A[ci][j] /= d;
			b[ci] /= d;
			// 前進消去（forward elimination）
			for (int i = ci + 1; i < n; i++) {
				Num k = A[i][cj];
				for (int j = 0; j < m; j++)
					A[i][j] -= k * A[ci][j];
				b[i] -= k * b[ci];
			}
			ci++;
		}
		cj++;
	}
	// 0 != b[i] だったら不能
	for (int i = ci; i < n; i++)
		if (abs(b[i]) > EPS)
			return make_pair(false, Vec());
	// 不定
	if (ci < m || cj < m)
		return make_pair(true, Vec());
	// 後退代入（back substitution）
	for (int j = m - 1; j >= 0; j--)
		for (int i = 0; i < j; i++)
			b[i] -= b[j] * A[i][j];
	return make_pair(true, b);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int d; cin >> d;) {
		if (d == 0)break;
		vector<double> v(d + 3); rep(i, 0, d + 3) {
			cin >> v[i];
		}
		double c = v[0];
		int ok = 0;
		int ans = 0;
		rep(k, 1, d + 3) {
			Mat A(d + 1, Vec(d));
			Vec b(d + 1);
			int ci = 0;
			rep(i, 1, d + 3) {
				if (i == k)continue;
				double x = i;
				rep(j, 0, d) {
					A[ci][j] = x;
					x *= i;
				}
				b[ci] = v[i] - c;
				ci++;
			}
			dump(A, b);
			auto res = gaussianElimination(A, b);
			if (res.first) {
				ok++;
				ans = k;
			}
		}
		dump(ok, ans);
		if (ok == 1) {
			cout << ans << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	return 0;
}


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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator*(long long y,const mint& m){ return m*y; }

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

	mint dp[2][301][300]; // dp[頂点 0 を含む強連結成分のサイズ][新たに訪れた部分のサイズ] = 場合の数
	dp[0][1][0]=1;
	int cur=0,next=1;
	rep(t,m){
		rep(i,n+1) rep(j,n) dp[next][i][j]=0;

		for(int i=1;i<=t+1;i++) rep(j,n-i+1) if(dp[cur][i][j].to_int()!=0) {
			dp[next][i+j][0]+=i*dp[cur][i][j];       // 0 を含む強連結成分に移動
			dp[next][i][j]+=j*dp[cur][i][j];         // 新たに訪れた j 個の頂点のうちのどれかに移動
			dp[next][i][j+1]+=(n-i-j)*dp[cur][i][j]; // 未到達の頂点に移動
		}
		swap(cur,next);
	}
	printf("%d\n",dp[cur][n][0].to_int());

	return 0;
}


Measured memory_bytes: 896
using System;

namespace Integral
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string input = Console.ReadLine();
                if (input == null)
                {
                    break;
                }

                long temp = int.Parse(input);

                
                long ans = 0;

                for (long i = 1; i < 600 / temp; ++i)
                {
                    ans += (long)Math.Pow(i*temp, 2) * temp;

                }

                Console.WriteLine(ans);
            }
        }
    }
}



Measured memory_bytes: 15920
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=2e5+10;
const ll MOD=10;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
int N;
int A[MAXN];
int x[MAXN];
void solve()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    int xum=0,xum1=0;
    for(int u=1;u<=N;u++){
        cin>>A[u];
        xum=xum^A[u];
        if(u>1)xum1=xum1^A[u];
    }
    cout<<xum1;
    for(int u=2;u<=N;u++){
        cout<<" "<<(xum^A[u]);
    }
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

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

int main(){
  int n;
  cin >> n;
 vector<int> h(n);
 int c = 0, max = 0;
 for(int i = 0; i < n; i++){
   cin >> h[i];
   if(i == 0) continue;

   if(h[i-1] >= h[i]){
     c++;
     if(c > max) max = c;
   } else {
     c = 0;
   }
 }
 cout << max << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N,H,W;
    cin >> N>>H>>W;
    ll x,y;
    ll ans = 0;
    rep(i,N){
        cin >> x>>y;
        if(x >= H && y >= W)ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var x = long.Parse(Console.ReadLine());

        long k500 = x / 500;

        var amari = x - (k500 * 500);
        var k5 = amari / 5;

        Console.WriteLine((k500 * 1000) + (k5 * 5));
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
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;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

vector<ll> ans;

void dfs(ll now, int d) {
    ans.emplace_back(now);
    if(d == 10) {
        return;
    }
    int r = now % 10;
    for(int i = max(0, r - 1); i <= min(9, r + 1); i++) {
        dfs(now * 10 + i, d + 1);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;
    cin >> k;
    for(int i = 1; i < 10; i++) {
        dfs(i, 1);
    }
    sort(ALL(ans));
    cout << ans[--k] << endl;
}

Measured memory_bytes: 2548
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N;
	cin >> N;


	string ret = "?";
	rep1(i, N) {
		ret += ' ';
		ret += to_string(i);
	}
	cout << ret << endl;

	string T;
	cin >> T;

	string S;
	S = T;
	string NS;
	if (S == "Red") NS = "Blue";
	else NS = "Red";

	int L = 0;
	int R = N;
	while (L + 1 < R) {
		int M = (L + R) / 2;
		ret = "?";
		rep1(i, M) {
			ret += ' ';
			ret += to_string(i);
		}
		for (int i = M + 1; i <= N; i++) {
			ret += ' ';
			ret += to_string(N + i);
		}
		cout << ret << endl;
		cin >> T;
		if (S == T) R = M;
		else L = M;
	}

	string C[200] = {};
	C[R] = S;
	C[N + R] = NS;

	rep1(j, N) {
		if (j != R) {
			ret = "?";
			rep1(i, R - 1) {
				ret += ' ';
				ret += to_string(i);
			}
			ret += ' ';
			if (j < R) ret += to_string(N + j);
			else ret += to_string(j);

			for (int i = R + 1; i <= N; i++) {
				ret += ' ';
				ret += to_string(N + i);
			}
			cout << ret << endl;
			cin >> T;
			if(S == T){
				if (j < R) C[N + j] = S;
				else C[j] = S;
			}
			else {
				if (j < R) C[N + j] = T;
				else C[j] = T;
			}
		}
	}
	rep1(j, N) {
		if (j != R) {
			ret = "?";
			rep1(i, R - 1) {
				ret += ' ';
				ret += to_string(N + i);
			}
			ret += ' ';
			if (j < R) ret += to_string(j);
			else ret += to_string(N + j);

			for (int i = R + 1; i <= N; i++) {
				ret += ' ';
				ret += to_string(i);
			}
			cout << ret << endl;
			cin >> T;
			if (S == T) {
				if (j < R) C[j] = S;
				else C[N + j] = S;
			}
			else {
				if (j < R) C[j] = T;
				else C[N + j] = T;
			}
		}
	}


	ret = "! ";
	rep1(i, 2 * N) {
		if (C[i] == "Red") ret += 'R';
		else ret += 'B';
	}
	cout << ret << endl;

	Would you please return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

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

	int64 N, M;
	cin >> N >> M;
	vector<int64> last(N, -1);
	REP(i, M) {
		int64 e;
		cin >> e;
		last[e-1] = i;
	}
	vector<PLL> ord(N);
	REP(i, N) {
		ord[i] = PLL(-last[i], i);
	}
	sort(all(ord));
	REP(i, N) {
		cout << ord[i].sc+1 << endl;
	}
}



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

int main(){
	long long int n,tol=0,cnt=0,an;
	cin >> n;
	long long int a[n];
	for(int i=0;i<n;i++) {cin >> a[i]; tol+=a[i];}
	for(int i=0;i<n;i++)
	{
		if(abs(cnt*2-tol)>abs(cnt*2-tol+2*a[i]))
		{
			cnt+=a[i]; 
		}
		else break;
	}
	an=abs(tol-2*cnt);
	cout << an;
	return 0;
	
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> a(N); for(auto& in:a) cin >> in;
    
    
    cout << 2*N-1 << endl;
     ll id = -1;
    ll maxa = -1;
    bool f = false;
    for(int i = 0; i < N;i++){
        if(abs(a[i]) > maxa){
            maxa = abs(a[i]);
            f = (a[i] >= 0)?true:false;
            id = i+1;
        }
    }
    for(int i = 1; i <= N; i++){
        cout << id << " " << i << endl;
    }
    if(f){
        for(int i = 1; i < N;i++){
            cout << i << " " << i + 1 << endl;
        }
    }else{
        for(int i = (int)N; i > 1; i--){
            cout << i << " " << i - 1 << endl;
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve<ll>();
//    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
#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 = (int)(1e9) + 7;
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 (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	int A, B; cin >> A >> B;
	int C; cin >> C;
	vector<int> D(N); rep(i, 0, N) { cin >> D[i]; }
	sort(all(D)); reverse(all(D));
	dump(D);
	int cal = C;
	rep(i, 0, N) {
		if ((cal + D[i]) / (A + (i + 1)*B) >= cal / (A + i*B)) {
			cal += D[i];
		}
		else {
			cout << cal / (A + i*B) << endl;
			break;
		}
	}
	return 0;
}

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

//???????????????????¢????

int IsStable(int N, vector<string>Sort_v1, vector<string>Sort_v2){

	for (int i = 0; i < N - 1; i++){
		for (int j = i + 1; j < N - 1; j++){
			for (int a = 0; a < N - 1; a++)
				for (int b = a+1; b < N - 1; b++){

					if (Sort_v1[i][1] == Sort_v1[j][1] &&
						Sort_v1[i] == Sort_v2[b] &&
						Sort_v1[j] == Sort_v2[a]){

						return 0;

					}
						
				}

		}

	}


	return 1;

}


//??????????????¨?????????????????????
void BubbleSort(int N, vector<string> Sort){
	string v;
	int flag = 1;
	
	//???????¢??????¨?????????
	vector<string> Sort_v1;
	for (int j = 0; j < N; j++){
		Sort_v1.push_back(Sort[j]);
	}

	
	while (flag){
		flag = 0;
		for (int j = N - 1; j>0; j--){
			if (Sort[j][1] < Sort[j - 1][1]){
				v = Sort[j];
				Sort[j] = Sort[j - 1];
				Sort[j - 1] = v;

				flag = 1;
			}
			
		}
	}//while?????????
	for (int k = 0; k < N; k++){
		cout << Sort[k];
		if (k != N - 1)cout << " ";
	}cout << endl;


	
	if (IsStable(N, Sort_v1, Sort) == 1)cout << "Stable" << endl;
	else if (IsStable(N, Sort_v1, Sort) == 0){ cout << "Not stable" << endl; }
	

}

//??????????????¨??????????????????
//???????????????
//???????????????????´???????????°?????????¢?´¢???????????????????????????????´???¨??????????????¢?????´?????????
void SelectionSort(int N, vector <string> Sort){

	int min;
	string v;

	//???????¢??????¨?????????
	vector<string> Sort_v1;
	for (int j = 0; j < N; j++){
		Sort_v1.push_back(Sort[j]);
	}


	for (int i = 0; i < N - 1; i++){
		min = i;
		for (int j = i + 1; j < N; j++){
			if (Sort[min][1] > Sort[j][1]){
				min = j;
			}

		}

		if (min != i){
			v = Sort[min];
			Sort[min] = Sort[i];
			Sort[i] = v;
		}

	}

	for (int k = 0; k < N; k++){
		cout << Sort[k];
		if (k != N - 1)cout << " ";
	}cout << endl;

	if (IsStable(N, Sort_v1, Sort) == 1)cout << "Stable" << endl;
	else if (IsStable(N, Sort_v1, Sort) == 0){ cout << "Not stable" << endl; }

}






int main(){

	int N;
	string sort;
	cin >> N;
	vector <string> Sort;
	
	for (int i = 0; i < N; i++){
		cin >> sort;
		Sort.push_back(sort);
	}

	
	BubbleSort(N, Sort);
	
	SelectionSort(N, Sort);

	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
using namespace std;
int main(void) {
	int N,R,G,B,cnt,k;
	cnt = 0;

	cin >> R >> G >> B >> N;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			k = (N - i*R - j*G);
			if (k>=0&&k%B==0) {
				cnt++;
			}
		}
	}
	cout << cnt;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n=0 , i, m = 100000;
	scanf("%d",&n);
	for(i=0;i<n;i++) {
		m = m*1.05;
		if ( (m%1000) > 0 ) {
			m = m - (m%1000) +1000;
		}
	}
	printf("%d\n",m);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto &e : v) cin >> e;
  sort(begin(v), end(v));
  double r = v.front();
  for (auto e : v) r = (r + e) / 2.0;
  cout << fixed << setprecision(6) << r << endl;
}


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

using namespace std;

int main(){
    int N;
    int napW;

    cin >> N;
    cin >> napW;

    vector<int> w(N);
    vector<long long> v(N);

    vector<vector<long long>>  dp(N+1,vector<long long>(napW+1,0));



    for (int i = 0; i <N ; ++i) {
        cin >> w[i];
        cin >> v[i];
    }



    for (int i = 0; i <N; ++i) {
        for (int W = 0; W <= napW ; ++W) {
            if(W - w[i] >= 0){
                dp[i+1][W] = max(dp[i][W],dp[i][W-w[i]] + v[i]);
            }else{
                dp[i+1][W] = dp[i][W];
            }
        }
    }

    cout << dp[N][napW] <<endl;


}



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

int main(){
    int n;
    cin>>n;
    if((n/100)>12||n/100==0){
        if(n%100>0&&n%100<13){
            cout<<"YYMM"<<endl;
        }
        else{
            cout<<"NA"<<endl;
        }
    }
    else{
         if(n%100>0&&n%100<13){
            cout<<"AMBIGUOUS"<<endl;
        }
        else{
            cout<<"MMYY"<<endl;
        }
    }
   return 0;
}

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


int main() {
	int n, m;
	int a[100], b[100], c[100] = {};
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		c[a[i]]++; c[b[i]]++;
	}
	for (int i = 1; i <= n; i++)cout << c[i] << endl;;
}

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

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
map<int, int> ans;
void f(int n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i != 0) continue;
        while (n % i == 0) {
            n /= i;
            ans[i]++;
        }
    }
    if (n != 1) ans[n]++;
}

// 約数列挙 O(√n)
vector<int> divisor(int n){
    vector<int> res;
    for(int i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

map<int, int> prime_factor(int n) {
    map<int, int> res;
    for (int i = 2; i * i <= n; i++) {
        while (n % 1 == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main() {
    int N;
    cin >> N;
    int res = 0;
    rep(i, 1, N+1) {
        if (i % 2 == 0) continue;
        if (divisor(i).size() == 8) ++res;
    }
    cout << res << endl;
    return 0;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

struct edge
{
    int to; ll cost;
    edge(int to, ll cost) : to(to), cost(cost) {}
};

vector<ll> dijkstra(const vector<vector<edge>> &g, int s)
{
    using P = pair<ll, int>;

    priority_queue<P, vector<P>, greater<P>> q;
    vector<ll> dist(g.size(), linf);

    dist[s] = 0; q.emplace(0, s);
    while (!q.empty()) {
        auto [d, now] = q.top(); q.pop();
        if (dist[now] < d) continue;
        for (auto &e: g[now]) {
            if (dist[e.to] > d + e.cost) {
                dist[e.to] = d + e.cost;
                q.emplace(dist[e.to], e.to);
            }
        }
    }
    return move(dist);
}

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

    int n, m, s; cin >> n >> m >> s;
    const int mx = 5000;
    vector<vector<edge>> g(n * (mx + 1));
    
    for (int i = 0; i < m; i++) {
        int u, v, a, b; cin >> u >> v >> a >> b;
        u--, v--;
        for (int j = mx; j >= a; j--) {
            g[j + u * (mx + 1)].emplace_back((j - a) + v * (mx + 1), b);
            g[j + v * (mx + 1)].emplace_back((j - a) + u * (mx + 1), b);
        }
    }
    for (int i = 0; i < n; i++) {
        int c, d; cin >> c >> d;
        for (int j = 0; j + c <= mx; j++) g[j + i * (mx + 1)].emplace_back((j + c) + i * (mx + 1), d);
    }

    auto dist = dijkstra(g, min(s, mx));
    for (int i = 1; i < n; i++) {
        ll ans = linf;
        for (int j = 0; j <= mx; j++) ans = min(ans, dist[j + i * (mx + 1)]);
        cout << ans << endl;
    }
    return 0;
}


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

int main () {
  int A , B , C , D;
  cin >> A >> B >> C >> D;
  int left , right;
  left = A + B;
  right = C + D;
  
  if (left > right) cout << "Left" << endl;
  if (left == right) cout << "Balanced" << endl;
  if (left < right) cout << "Right" << endl;
  
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
for i in range(n) :
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v

    for j in range(n):
        if j == n - 1 :
            print(A[j])
        else:
            print(str(A[j]) + " ", end="")


Measured memory_bytes: 5980
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main()
{
    ll h, w;
    int n;
    cin >> h >> w >> n;
    map<P, bool> mp;
    ll a[100005], b[100005];
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        mp[P(a[i], b[i])] = true;
    }
    ll ans[10]{0};
    for(int i = 0; i < n; i++){
        for(int x = max(a[i] - 2, 0ll); x + 2 < min(a[i] + 3, h); x++){
            for(int y = max(b[i] - 2, 0ll); y + 2 < min(b[i] + 3, w); y++){
                int c = 0;
                for(int u = x; u < x + 3; u++){
                    for(int v = y; v < y + 3; v++){
                        if(mp[P(u, v)]) c++;
                    }
                }
                ans[c]++;
            }
        }
    }
    ans[0] = (h - 2) * (w - 2);
    for(int i = 1; i < 10; i++){
        ans[i] /= i;
        ans[0] -= ans[i];
    }
    for(int i = 0; i < 10; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 161416
#include <bits/stdc++.h>
#define rp(i,n) for(ll i=0; i<n; i++)
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
using G=vector<vector<int>>;
using PP=pair<ll,pair<ll,ll>>;
using tlll=tuple<ll,ll,ll>;
const ll INF=1ll<<50;
ll n,m,s;
ll maxa;
ll dp[53][2510];
vector<vector<PP>> graph(53);
vector<pair<ll,ll>> changetime(53);
int main(){
    cin >> n >> m >> s;
    rp(i,m){
        ll u,v,a,b;
        cin >> u >> v >> a >> b;
        maxa=max(maxa,a);
        graph[u].push_back(mp(v,mp(a,b)));
        graph[v].push_back(mp(u,mp(a,b)));
    }
    if(s>maxa*n) s=maxa*n;
    rp(i,n){
        ll c,d;
        cin >> c >> d;
        changetime[i+1]=mp(c,d);
    }
    rp(i,53){
        rp(j,2510){
            dp[i][j]=INF;
        }
    }
    dp[1][s]=0;
    priority_queue<tlll,vector<tlll>,greater<tlll>> dij;
    dij.push(mt(0,1,s));
    while(!dij.empty()){
        tlll t=dij.top(); dij.pop();
        int ctr=0;
        ll time=get<0>(t);
        ll i=get<1>(t);
        ll j=get<2>(t);
        if(dp[i][j]<=time&&(i!=1||j!=s)) continue;
        dp[i][j]=time;
        for(ll c=j-1; c>=0; c--){
            if(dp[i][c]>time) dp[i][c]=time;
            else break;
        }
        while(j<=maxa*n){
            if(ctr>0){
                if(dp[i][j]>dp[i][j-changetime[i].first]+changetime[i].second)
                dp[i][j]=dp[i][j-changetime[i].first]+changetime[i].second;
                else break;
            }
            for(auto pp : graph[i]){
                if(j>=pp.second.first)
                dij.push(mt(dp[i][j]+pp.second.second,pp.first,j-pp.second.first));
            }
            ctr++;
            j+=changetime[i].first;
        }
    }
    for(int i=2; i<=n; i++){
        ll ans=1ll<<51;
        rp(j,maxa*n){
            ans=min(ans,dp[i][j]);
        }
        cout << ans << endl;
    }
    return 0;
}

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

#define N 30001

int n, integer_s[N]={10};
char s[N];

int search(int i, int *cnt, int *iPass){
  if(i==3){
//    printf("%d %d %d %d\n",iPass[0], iPass[1], iPass[2], iPass[3]);
    *cnt = *cnt+1;
  }
  else{
    for(int k=0; k<=9; k++){ 
      for(int j=iPass[i]+1; j<n; j++){ 
//        printf("%d\n",integer_s[j]);
        if(integer_s[j]==k){
          iPass[i+1] = j;
          search(i+1, cnt, iPass);
          break;
        }
      }
    }
  }
  return 0;
}

int main(){
  int cnt=0, iPass[4]={-1}; 
  char sTmp;
  // iPass[0]=-1, iPass[1]:1桁目の格納場所 ,iPass[2]:２桁目の格納場所, iPass[3]:3桁目の格納場所
  scanf("%d %s", &n, s);
//  for(int a=0;a<n;a++){
//    printf("%c\n",s[a]);
//    printf("%d\n",atoi(&s[a]));
//  }
  for(int i=0; i<n; i++){
    sTmp = s[i];
    integer_s[i] = atoi(&sTmp);
//    printf("%d ",integer_s[i]);
  }

  search(0, &cnt, iPass);
  printf("%d",cnt);
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
const int NN = 1e6+10;
typedef long long ll;

ll n;
int arr[NN];
int main(){
    // freopen("test.in","r",stdin);
    cin>>n;
    for(int i = 0;i<n;i++) scanf("%d",&arr[i]);
    arr[0]--;
    bool tag = 1;
    for(int i = 1;i<n;i++){
        if(arr[i] > arr[i-1]) arr[i]--;
        else if(arr[i] == arr[i-1]) continue;
        else{
            tag = 0;
            break;
        }
    }
    if(tag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 640
(* O((max n m)^2) *)
open List;;
let n = read_int () in
let ss = Array.to_list @@ Array.init n @@ fun _ -> read_line () in
let m = read_int () in
let ts = Array.to_list @@ Array.init m @@ fun _ -> read_line () in
let f s = (length @@ filter ((=) s) ss) - (length @@ filter ((=) s) ts) in
map f ss |> fold_left max 0 |> Printf.printf "%d\n"

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
 
int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
   ll ans= n*(n-1);
  if(ans==0)
    ans=0;
  else
    ans=ans/2;
 
    cout<<ans;
}

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

MOD = 1000000007


def combination(n, r):
    r = min(r, n - r)

    num = 1
    den = 1

    for i in range(1, r + 1):
        num = (num * (n + 1 - i)) % MOD
        den = (den * i) % MOD

    return num * pow(den, MOD - 2, MOD) % MOD


def func(a, n, p):
    bi = str(format(n, "b"))
    res = 1

    for i in range(len(bi)):
        res = (res * res) % p
        if bi[i] == "1":
            res = (res * a) % p

    return res


s = func(2, n, MOD) - 1
xa = combination(n, a)
xb = combination(n, b)

p = (s - xa - xb) % MOD

if p < 0:
    print(p + MOD)
else:
    print(p)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

int n, q;
lint a[100010];

bool check(int mid, int x){
    if(2*mid-n+1 < 0) return false;
    return abs(a[2*mid-n+1] - x) <= abs(a[mid] - x);
}

int main(){
    scanf("%d%d", &n, &q);
    lint asum[n+1], evsum[(n+1)/2+1];
    asum[0] = evsum[0] = 0;
    rep(i, n){
        scanf("%d", &a[i]);
        asum[i+1] = asum[i] + a[i];
        if(i%2 == 0) evsum[i/2+1] = evsum[i/2] + a[i];
    }
    rep(i, q){
        int x;
        scanf("%d", &x);
        int ok = n-1;
        int ng = 0;
        while(ok - ng > 1){
            int mid = (ok + ng) / 2;
            if(check(mid, x)) ok = mid;
            else ng = mid;
        }
        lint score = asum[n] - asum[ok];
        int m = 2*ok-n-1;
        if(m >= 0){
            if(m%2 == 0) score += evsum[m/2+1];
            else score += asum[m+1] - evsum[m/2+1];
        }
        printf("%lld\n", score);
    }
}

Measured memory_bytes: 3712
import fractions

ABCD = list(map(int, input().split()))

A = ABCD[0]
B = ABCD[1]
C = ABCD[2]
D = ABCD[3]


# def lcm(x, y):
#     return (x * y) // fractions.gcd(x, y)


def floor(a, b):
  # return int((a - a%b)/b)
  return a//b
def gcd(a, b):
  while b != 0:
      a, b = b, a % b
  return a
def lcm(a, b):
  return floor((a * b), gcd(a, b))

firstC = floor((A-1),C)
firstD = floor((A-1),D)
firstCD = floor((A-1),lcm(C,D))

# if A%lcm(C,D) ==0 and firstCD > 0:
#     firstCD -= 1

endC = floor(B,C)
endD = floor(B,D)
endCD = floor(B,lcm(C,D))

End = B-endC-firstD + endCD
First = (A-1) - firstC - firstD + firstCD



thereC = endC - firstC
thereD = endD - firstD
thereCD = endCD - firstCD

NoP = thereC+thereD - thereCD

# print(thereC)
# print(thereD)
# print(thereCD)
# print(NoP)
print((B-A+1)-NoP)
# print(End-First)









Measured memory_bytes: 5076
#include<bits/stdc++.h>
#define M 200005
#define ll long long
#define P 1000000007
using namespace std;
int n;
int col[M],nw[M];
ll dp[M],res[M];//i结尾方案(必取) 前缀 上个位置  
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&col[i]);
	int sz=0;
	for(int i=1;i<=n;i++) 
		if(col[i]!=col[i-1]) nw[++sz]=col[i];
	for(int i=1;i<=sz;i++){
		dp[i]=res[nw[i]];
		res[nw[i]]=(res[nw[i]]+dp[i-1]+1)%P;
		dp[i]=(dp[i]+dp[i-1])%P;
	}
	printf("%lld\n",(dp[sz]+1)%P);
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
const int MAX_N = int(1e5)+10;
const int INF = int(1e9);

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

int N;
// int a[MAX_N], b[MAX_N], c[MAX_N];
int A[MAX_N][3]; //a,b,cをまとめる

// dp[i][j]: i-1日目までの幸福度の和のmax (ただしi-1日目にjを行う)
int dp[MAX_N][3];

int main()
{
  cin >> N;
  // REP(i,0,N) cin >> a[i] >> b[i] >> c[i];
  REP(i,0,N) cin >> A[i][0] >> A[i][1] >> A[i][2];

  REP(j,0,3) dp[0][j] = 0;

  REP(i,0,N) {
    REP(j,0,3) {
      dp[i+1][j] = -INF; // init
      REP(k,0,3) {
        // i日目にjを行う．i-1日目にはkを行った．
        if (j != k) chmax(dp[i+1][j], dp[i][k] + A[i][j]);
      }
    }
  }

  int ans = -INF;
  REP(j,0,3) chmax(ans, dp[N][j]);
  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int H,W;
    while(true){
        cin >> H >> W;
        if(H==0 && W==0) break;
        for(int h=1;h<=H;h++){
            for(int w=1;w<=W;w++){
                cout << ((1<h && h<H && 1<w && w<W)?'.':'#');
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3084
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a<b) swap(a,b);
    if(a<c) swap(a,c);
    a=a*10+b+c;
    printf("%d\n",a);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

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

	rep(i, 0, s.size()) {
		if (s[i] == s[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		else if (i != s.size() - 1 && s[i] == s[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

void solve(){
  int a, b; cin >> a >> b;
  int x = 1, sum = 0;
  while(x < b){
    x += a - 1;
    sum++;
  }
  cout << sum << endl;
  return;
}

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


Measured memory_bytes: 256
N, x = gets.strip.split(/ /).collect{|n| n.to_i}
as = gets.strip.split(/ /).collect{|n| n.to_i}


as = as.sort

count = 0

a_get = []
a_zero = []

as.each{|a|
	if a <= x
		count += 1
		x -= a
		a_get << a
	else
		a_zero << a
	end
}

if x > 0
	a_get.each{|a|
		a_zero.each{|b|
			if a + x == b
				x = 0
				break
			end
		}
		if x == 0
			break
		end
	}
end

if x > 0 && count > 0 && a_zero.length == 0
	count -= 1
end

puts count




Measured memory_bytes: 3836
#include <iostream>
#define ll long long
using namespace std;

ll mod=1000000007;
const int SIZE=210000;
ll fac[SIZE], finv[SIZE], inv[SIZE];
void COMinit(ll m){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2; i<SIZE; ++i){
        fac[i]=(fac[i-1]*i)%m;
        inv[i]=m-(inv[m%i]*(m/i))%m;
        finv[i]=(finv[i-1]*inv[i])%m;
    }
}
ll COM(int n, int k, ll m){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return (fac[n]*((finv[k]*finv[n-k])%m))%m;
}

ll modpow(ll a, ll b, ll m){
    ll res=1, p=0, now=a%m;
    b %= (m-1);
    for(int i=0; b>p; ++i){
        if(b&((ll) 1<<i)){
            res=(res*now)%m;
            p |= ((ll) 1<<i);
        }
        now=(now*now)%m;
    }
    return res;
}
ll modinv(ll a, ll m){
    return modpow(a, m-2, m);
}
ll moddiv(ll a, ll b, ll m){
    return (a*modinv(b, m))%m;
}

int main() {
	int B, W;
	cin >> B >> W;
	ll hh=1, ww=0, bb=0;
	COMinit(mod);
	for(int i=0; i<B+W; ++i){
		ll ans=(bb*2)%mod;
		ans=(ans+hh+mod*2-ww-bb)%mod;
		cout << moddiv(ans, hh*2, mod) << endl;
		hh=(hh*2)%mod;
		ww=(ww*2+COM(i, B-1, mod))%mod;
		bb=(bb*2+COM(i, W-1, mod))%mod;
	}
	return 0;
}

Measured memory_bytes: 7168
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    s = input()

    mask1 = ""
    mask2 = ""

    for i in range(len(s)):
        mask1 += str(0 ^ i%2)
        mask2 += str(1 ^ i%2)

    cnt1 = 0
    cnt2 = 0
    for i in range(len(s)):
        if s[i] == mask1[i]:
            cnt1 += 1
        if s[i] == mask2[i]:
            cnt2 += 1
    print(min(cnt1, cnt2))

main()


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
int main() {
  int w, h, x, y, c, ans;
  string l;
  vector<string> M0, M1;
  queue< vector<int> > que;
  while (cin >> w >> h, w) {
    getline(cin, l);
    for (int i = 0; i < 2*h-1; ++i) {
      getline(cin, l);
      if (i%2) M1.push_back(l);
      else M0.push_back(l);
    }
    vector<int> p(3,0);
    vector< vector<bool> > maze(h, vector<bool>(w, false));
    maze[0][0] = true;
    que.push(p);
    ans = 0;
    while (que.size() > 0) {
      x = que.front()[0];
      y = que.front()[1];
      c = que.front()[2];
      que.pop();
      if (x == w-1 && y == h-1) {
	ans = c+1;
	break;
      } else if (c > 900) break;
      ++c;
      if (x > 0 && M0[y][2*(x-1)+1] == '0' && (!maze[y][x-1])) {
	p = {x-1,y,c};
	que.push(p);
	maze[y][x-1] = true;
      }
      if (x < w - 1 && M0[y][2*x+1] == '0' && (!maze[y][x+1])) {
	p = {x+1,y,c};
	que.push(p);
	maze[y][x+1] = true;
      }
      if (y > 0 && M1[y-1][2*x] == '0' && (!maze[y-1][x])) {
	p = {x,y-1,c};
	que.push(p);
	maze[y-1][x] = true;
      }
      if (y < h - 1 && M1[y][2*x] == '0' && (!maze[y+1][x])) {
	p = {x,y+1,c};
	que.push(p);
	maze[y+1][x] = true;
      }
    }
    while (que.size() > 0) que.pop();
    while (M1.size() > 0) M1.pop_back();
    while (M0.size() > 0) M0.pop_back();
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3192