akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  V x(5); cin >> x;
  
  rep(i, 5) {
    if (x[i] == 0) {
      cout << (i+1) << "\n";
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main() {
    int N; cin >> N;
    int D[100050]; for (int i=1; i<=N; i++) cin >> D[i];

    int bucket_max = 0;
    int bucket[100050] = {};
    for (int i=1; i<=N; i++) {
        bucket_max = (D[i] > bucket_max) ? D[i] : bucket_max;
        bucket[D[i]]++;
    }

    if (!(bucket[0] == 1 && D[1] == 0)) {
        cout << 0 << endl;
        return 0;
    }

    long ans = 1;
    for (int i=1; i<=bucket_max; i++) {
        for (int k=0; k<bucket[i]; k++) {
            ans = ans * bucket[i-1] % 998244353;
        }
    }

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


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N, Y;
  scanf("%d %d", &N, &Y);
  for (int x = 0; x <= N; ++x) {
    for (int y = 0; y <= N - x; ++y) {
      int z = N - x - y;
      if (10000 * x + 5000 * y + 1000 * z == Y) {
        printf("%d %d %d\n", x, y, z);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}


Measured memory_bytes: 256
/*
 *architect034
 *NIT Silchar<36>
 */
#include<bits/stdc++.h>
using namespace std;
#define bhago   ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll   long long
#define ull unsigned long long
#define loop(i,start,end,increment)   for(ll i=start;i<=end;i+=increment)
#define ulta(i,start,end,decrement)   for(ll i=start;i>=end;i-=decrement)
#define pb   push_back
#define popb   pop_back
#define pf   push_front
#define popf   pop_front
#define mp   make_pair
#define FF   first
#define SS   second#FFFFFF
#define all(something)   something.begin(),something.end()
#define vecitr   vector<ll>::iterator
#define setitr   set<ll>::iterator
#define mapitr   map<ll,ll>::iterator
#define mod   1000000007
const int INF = 1e9 + 5;

void debug(string s)
{
	cout<<s<<"\n";
}
const int MAX = 2000007;
bool prime[MAX];
int sp[MAX];
void sieve()
{
	for (int i = 2; i < MAX; i += 2)
	{
		sp[i] = 2;//even numbers have smallest prime factor 2
	}
	for (ll i = 3; i < MAX; i += 2)
	{
		if (!prime[i])
		{
			sp[i] = i;
			for (ll j = i; (j*i) < MAX; j += 2)
			{
				if (!prime[j*i])
				{
					prime[j*i] = true;
					sp[j*i] = i;
				}
			}
		}
	}
}
ll GCD(ll a,ll b)
{
	ll c=a%b;
	while(c!=0)
	{
		a=b;
		b=c;
		c=a%b;
	}
	return b;
}
ll power(ll a,ll b)
{
	ll ans=1;
	while(b!=0)
	{
		if(b%2==1)
			ans*=a;
		a*=a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	bhago;
	ll n,wgt;
	cin>>n>>wgt;
	ll w[n+1],v[n+1];
	for(ll i=0;i<n;i++){
		cin>>w[i+1]>>v[i+1];
	}
	ll dp[n+1][wgt+1]={0};
	for(ll i=0;i<=n;i++){
		for(ll j=0;j<=wgt;j++){
			dp[i][j]=0;
		}
	}
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=wgt;j++){
			if(j>=w[i]){
				dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
			}else{
				dp[i][j]=dp[i-1][j];
			}
			
		}
	}
	cout<<dp[n][wgt];
	return 0;
}


Measured memory_bytes: 79232
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextLong();
        }
        for (int i = 0 ; i < n - k; i++) {
            if (a[i] <  a[i + k]) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }

}


Measured memory_bytes: 61696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MX=1e18;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll a;cin>>a;
    long double b;cin>>b;
    long double ans = a*b;
    ll v=ans;
    cout<<v;
}



Measured memory_bytes: 3748
if __name__ == '__main__':
	n, m, l = map(int, input().split())
	a,b,c = [], [], []
	for i in range(n):
		a.append([int(s) for s in input().split()])
		c.append([0 for k in range(l)])
	for i in range(m):
		b.append([int(s) for s in input().split()])
	
	for i in range(n):
		for k in range(l):
			ans = 0
			for j in range(m):
				ans += a[i][j] * b[j][k]	
			c[i][k] = ans
	
	for i in range(n):
		print("%d" % (c[i][0]), end= "")
		for k in range(1,l):
			print(" %d" % (c[i][k]), end="")
		print()


Measured memory_bytes: 7052
#include <iostream>
#include <cmath>
#include <iomanip>

int main() {
  int N,K;
  unsigned long long sum=0;
  std::cin >> N >> K;
  double rate_sum=0;
  unsigned long long max_cnt=0;
  for(int n=1;n<=N;n++){
    int win_cnt = std::ceil(std::log(K/(double)n)/std::log(2));
    if(n==1)max_cnt=win_cnt;
    if(n>=K)
      win_cnt = 0;
    rate_sum += std::pow(2,max_cnt-win_cnt);
  }
  std::cout << std::setprecision(10) << rate_sum/(std::pow(2,max_cnt)*N) << std::endl;
  return 0;
}


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

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

    vector<int> num(10);
    for(int i=0; i<k; i++){
        int d;
        cin >> d;
        num[d] = 1;
    }

    for(int i=n; i<100000; i++){
        int test  = i;
        int score = 0;
        while(test > 0){
            score += num[test % 10];
            test /= 10;
        }
        if(score == 0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

using namespace std;

int main()
{
    #ifdef lOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // lOCAL_EXEC
   long long int n,m,i,j,k,x,y,z;
   cin>>n>>m;
   long long int A[n+1]={0};
   deque<long long int>vt[n+1],ct[n+1];
   for(i=1;i<=m;i++){
    cin>>x>>y;
    vt[x].push_back(y);
    vt[y].push_back(x);
   }
   bool visited[n+1]={false};
   stack<long long int>st;
   y=1;
   for(i=1;i<=n;i++){
   // cout<<i<<endl;
    if(visited[i]==false){
        st.push(i);
        A[y]+=1;
        while(!st.empty()){
           x=st.top();
           visited[x]=true;
           while(!vt[x].empty()&&visited[vt[x][0]]==true){
            vt[x].pop_front();
           }
           if(vt[x].empty())
                st.pop();
           else{
            st.push(vt[x][0]);
            A[y]+=1;
           }
        }
        y+=1;
    }
 //   cout<<i<<endl;
   }
   long long int ans=0;
   for(i=1;i<=n;i++){
   // cout<<A[i]<<" ";
    ans=max(ans,A[i]);
   }
   cout<<ans;
    return 0;
}


Measured memory_bytes: 275732
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }
#define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,N) for(int i=0;i<(int)(N);i++)
#define rep1(i,N) for(int i=1;i<=(int)(N);i++)
#define fs first
#define sc second
#define eb emplace_back
#define pb eb
#define all(x) x.begin(),x.end()
template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

#ifdef LOCAL
#define show(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

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

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

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


    int n;
    cin >> n;
    using P = pair<int, int>;
    V<P> v;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (n % 2 == 0 && (i + j) == n + 1) continue;
            if (n % 2 == 1 && (i + j) == n) continue;
            v.push_back({i, j});
        }
    }

    cout << v.size() << endl;
    for (auto p: v) {
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}


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

int main() {
  char c;
  cin >> c;
  string S = "";
  
  if(c == 'a'||c == 'e'||c == 'i'||c == 'o'||c == 'u'){
    S = "vowel";
  }else{
    S = "consonant";
  }
  cout << S << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{

    int a[5];
    scanf("%d %d %d",&a[0],&a[1],&a[2]);

    if((a[0]+a[1]+a[2])>=22)
        printf("bust");
    else
        printf("win");

    printf("\n");
    return 0;
}


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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    ll h;
    cin >> h >> n;
    vector<pair<ll, ll>> vp(n);
    for(i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        vp[i] = {a, b};
    }
    vector<ll> dp(h + 100,INF);
    dp[0] = 0;
    for(i = 0; i < h; i++) {
        if(dp[i] == INF) continue;
        for(j = 0; j < n; j++) {
            ll x = min(i + vp[j].first, h);
            dp[x] = min(dp[i] + vp[j].second, dp[x]);
        }
    }
    cout << dp[h] << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	string s; cin>>s;
  if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]){
    cout<<"Bad"<<endl;
  }else{
    cout<<"Good"<<endl;
  }
	return 0;
}

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

int main(void){
    string c1,c2;cin >> c1 >> c2;
    reverse(c1.begin(), c1.end());

    if (c1 == c2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

typedef struct{
  char suit;
  int value;
}card;

card L[MAX/2+2],R[MAX/2+2];

void conq(card A[],int n,int lefhasi,int man,int righasi)
{
  int lefnum,rignum,i=0,j=0,k=0;
  lefnum=man-lefhasi;
  rignum=righasi-man;
  //int lefhai[lefnum+1],righai[rignum+1];
  for(i=0;i<lefnum;i++)
    {
      L[i]=A[lefhasi+i];
      // printf("%d\n",lefhai[lehasi+i]);
    }
  for(i=0;i<rignum;i++)
    {
      R[i]=A[man+i];
      //printf("%d\n",righai[man+i]);
    }
  L[lefnum].value=R[rignum].value=2000000000;
  i=0;
  for(k=lefhasi;k<righasi;k++)
    {
      if(L[i].value<=R[j].value)
	{
	  A[k]=L[i++];
	}
      else
	{
	  A[k]=R[j++];
	}
    }
}

void divi(card A[],int n,int lefhasi,int righasi)
{
  int man;
  if(lefhasi+1<righasi)
    {
      man=(lefhasi+righasi)/2;
      divi(A,n,lefhasi,man);
      divi(A,n,man,righasi);
      conq(A,n,lefhasi,man,righasi);
    }
}
int partition(card A[],int n,int p,int r)
{
  int i=0,j;
  card t,x;
  x=A[r];
  i=p-1;
  for (j=p;j<r;j++)
    {
      if (A[j].value<=x.value)
	{
	  i = i+1;
	  //A[i] と A[j] を交換
	  t=A[i];
	  A[i]=A[j];
	  A[j]=t;
	}
    }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

void quicksort(card A[],int n,int p,int r)
{
  int q;
  if(p<r)
    {
      q=partition(A,n,p,r);
      quicksort(A,n,p,q-1);
      quicksort(A,n,q+1,r);
    }
}

int main()
{
  int n,i,v;
  card A[MAX],B[MAX];
  char S[10];
  int stable=1;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s %d",S,&v);
      A[i].suit=B[i].suit=S[0];
      A[i].value=B[i].value=v;
    }
  divi(A,n,0,n);
  quicksort(B,n,0,n-1);
  for(i=0;i<n;i++)
    {
      if(A[i].suit!=B[i].suit)
	{
	  stable=0;
	}
    }
  if(stable==1)
    {
      printf("Stable\n");
    }
  else
    {
      printf("Not stable\n");
    }
  for(i=0;i<n;i++)
    {
      printf("%c %d\n",B[i].suit,B[i].value);
    }
  return 0;
}



Measured memory_bytes: 4128
from collections import Counter

N = int(input())
S = input()
RGB_Counter = Counter(S)
ans = RGB_Counter['R'] * RGB_Counter['G'] * RGB_Counter['B']

dum = []
d = 0
while 3 + d*2 <= N:
    for i in range(N - 2*(d+1)):
        a = S[i]
        b = S[i+d+1]
        c = S[i+2*(d+1)]
        if a != b and b != c and c != a:
            ans -= 1
    d += 1

print(ans)

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  if (n == 0) {
    cout << 0 << '\n';
    return 0;
  }

  string ans;
  while (n) {
    int r = n % 2;
    if (r < 0) {
      r += 2;
    }

    ans += '0' + r;
    n -= r;
    n /= -2;
  }

  reverse(ans.begin(), ans.end());
  cout << ans << '\n';
}

Measured memory_bytes: 3624
#include <iostream>

// ax+by=c となる整数の組(x, y)が存在するか否か
bool axbyc(int a, int b, int c)
{
	c %= (a * b);
	for (int cand_x = 0; c - a * cand_x >= 0; cand_x++) {
		if ((c - a * cand_x) % b == 0) {
			return true;
		}
	}
	return false;
}

int main(int argc, const char *argv[])
{
	const int PlaceOfCake = 4;
	const int PlaceOfDonuts = 7;

	int N;
	std::cin >> N;

	std::cout << (axbyc(PlaceOfCake, PlaceOfDonuts, N) ? "Yes" : "No")
			  << std::endl;

	return 0;
}


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

using namespace std;

using ll = long long;

bool judge(ll x) {
    string s = to_string(x);
    int n = s.size();
    for (int i = 0; i < n - 1; ++i) {
        if (abs(s[i] - s[i + 1]) > 1) return false;
    }
    return true;
}

void calc(int max_keta, vector< vector<ll> >& v) {
    if (max_keta == 1) {
        v[max_keta - 1] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        return;
    }

    calc(max_keta - 1, v);
    for (ll x : v[max_keta - 2]) {
        ll d = x % 10;
        if (d > 0) v[max_keta - 1].push_back(x * 10 + d - 1);
        if (d < 9) v[max_keta - 1].push_back(x * 10 + d + 1);
        v[max_keta - 1].push_back(x * 10 + d);
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector< vector<ll> > v(10);
    calc(10, v);
    vector<ll> v2;
    for (int i = 0; i < 10; ++i) {
        for (ll x : v[i]) v2.push_back(x);
    }
    sort(v2.begin(), v2.end());

    int n;
    cin >> n;
    cout << v2[n - 1] << "\n";
    return 0;
}

Measured memory_bytes: 4084
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
long long dp[2005][2005]={0};
struct Num{
	long long val,id;
}num[2005];
bool cmp(Num a,Num b){
	return a.val>b.val;
}
int main(){
	long long i,j,n;
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&num[i].val);
		num[i].id=i;
	}
	sort(num,num+n,cmp);
	dp[1][0]=num[0].id*num[0].val;
	dp[0][1]=(n-1-num[0].id)*num[0].val;
	for(i=2;i<=n;i++)
		for(j=0;j<=i;j++)
			dp[j][i-j]=max((j?(dp[j-1][i-j]+abs(num[i-1].id-j+1)*num[i-1].val):0),((i-j)?(dp[j][i-j-1]+abs(n-i+j-num[i-1].id)*num[i-1].val):0));
	long long ans=0;
	for(i=0;i<=n;i++)
		ans=max(ans,dp[i][n-i]);
	printf("%lld\n",ans);
}


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

int main(){
  int X,Y;
  cin >> X >> Y;
  int count = 0;
  if (X == 3 || Y == 3) count += 100000;
  if (X == 3 && Y == 3) cout << 200000;
  if (X == 2 || Y == 2) count += 200000;
  if (X == 2 && Y == 2) cout << 400000;
  if (X == 1 || Y == 1) count += 300000;
  if (X == 1 && Y == 1) cout << 1000000 << endl;
   if (!((X == 1 && Y == 1) || (X == 2 && Y == 2) || (X == 3 && Y == 3)))cout << count << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define inf 409
#define infm 100009
#define INF (ll)1e15
#define mod ((ll)1e9+7)
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;
int n;

struct brick{
	int a,b,c,d;
	brick(){}
	brick(int aa,int bb,int cc,int dd){
		a=aa,b=bb,c=cc,d=dd;
	}
}a[inf];

bool operator<(brick _1,brick _2){
	if (_1.a==_2.a){
		if (_1.b==_2.b){
			if (_1.c==_2.c){
				return _1.d<_2.d;
			}
			return _1.c<_2.c;
		}
		return _1.b<_2.b;
	}
	return _1.a<_2.a;
}

brick Nxt(brick x){
	return brick(x.b,x.c,x.d,x.a);
}

map <brick,ll> mp;

void insert(brick x,int val){
	for (int i=1;i<=4;i++){
		mp[x]+=val;
		x=Nxt(x);
	}
	return;
}

bool check(brick x){
	return mp.count(x);
}

int main(){
	rd(n)
	for (int i=1;i<=n;i++){
		rd(a[i].a) rd(a[i].b) rd(a[i].c) rd(a[i].d)
		insert(a[i],1);
	}
	ll ans=0LL;
	for (int i=1;i<=n;i++){
		insert(a[i],-1);
		for (int j=i+1;j<=n;j++){
			insert(a[j],-1);
			for (int k=0;k<4;k++){
				a[j]=Nxt(a[j]);
				brick t1,t2,t3,t4;
				t1=brick(a[i].b,a[i].a,a[j].a,a[j].d);
				t2=brick(a[i].c,a[i].b,a[j].d,a[j].c);
				t3=brick(a[i].d,a[i].c,a[j].c,a[j].b);
				t4=brick(a[i].a,a[i].d,a[j].b,a[j].a);
				if (check(t1) && check(t2) && check(t3) && check(t4)){
					ll now=1LL;
					now*=mp[t1];
					insert(t1,-1);
					now*=mp[t2];
					insert(t2,-1);
					now*=mp[t3];
					insert(t3,-1);
					now*=mp[t4];
					insert(t1,1);
					insert(t2,1);
					insert(t3,1);
					ans+=now;
				}
			}
			insert(a[j],1);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

#define int long long 

const int p = 1e9+7;


int dp[105][15], vis[105][15], h, w, k, f[15][2];

void init(){
    memset(dp, 0, sizeof dp);
    dp[h][k] = 1;
    vis[h][k] = 1;
    
    f[1][1] = f[1][0] = 1;
    for(int i = 2; i <= 8; i++) {
        f[i][1] = f[i-1][0];
        f[i][0] = (f[i-1][1] + f[i-1][0])%p;
    }
}
int cnt(int num){
    if(num<=0) return 1;
    return (f[num][0] + f[num][1]) % p;
}
int dfs(int r, int c){
    if(r > h || r < 0 || c > w || c <= 0) return 0;
    if(vis[r][c])return dp[r][c];
    vis[r][c] = 1;
    dp[r][c] = (dp[r][c] + dfs(r+1, c)   * (cnt(c-1-1) * cnt(w-c-1)%p)%p)%p;
    dp[r][c] = (dp[r][c] + dfs(r+1, c+1) * (cnt(c-1-1) * cnt(w-c-2)%p)%p)%p;
    dp[r][c] = (dp[r][c] + dfs(r+1, c-1) * (cnt(c-2-1) * cnt(w-c-1)%p)%p)%p;
    return dp[r][c];
}
signed main(){
    scanf("%lld%lld%lld", &h, &w, &k);
    init();
    printf("%lld\n", dfs(0, 1));
    return 0;
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m=map(int,input().split())
half=n//2
lst=[]
if n%2==1:
    for i in range(m):
        lst.append([half-i,half+i+1])
else:
    for i in range(m):
        if i%2==0:
            lst.append([half-i//2,half+i//2+1])
        else:
            lst.append([1+i//2,n-1-i//2])

for i in range(m):
    print(*lst[i])

# dic=defaultdict(int)
# for i in range(m):
#     tmp=lst[i]
#     dic[tmp[1]-tmp[0]]+=1
#     dic[n-tmp[1]+tmp[0]]+=1
# print(dic)


Measured memory_bytes: 81648
using System;
 
namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            var NMK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NMK[0]; var M = NMK[1]; var K = NMK[2];
            var friendship = new UnionFind(N);
            var friend = new int[N + 1];
            for (int i = 0; i < M; i++)
            {
                var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                friendship.unite(read[0], read[1]);
                friend[read[0]]++;
                friend[read[1]]++;
            }
            var suggestions = new int[N];
            for (int i = 0; i < N; i++) suggestions[i] = friendship.RootCount(i + 1) - friend[i + 1] - 1;
            for (int i = 0; i < K; i++)
            {
                var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                if (friendship.sameRoot(read[0], read[1]))
                {
                    suggestions[read[0] - 1]--;
                    suggestions[read[1] - 1]--;
                }
            }
            Console.WriteLine(string.Join(" ", suggestions));
        }
    }
    public class UnionFind
    {
        private int[] parents;
        // 同じ根に属する枝の数を格納する
        private int[] rootCount;
 
        public int RootCount(int branch)
        {
            return rootCount[root(branch)];
        }
 
        public UnionFind(int count)
        {
            parents = new int[count + 1];
            rootCount = new int[count + 1];
            for (int i = 0; i < count + 1; i++)
            {
                parents[i] = i;
                rootCount[i] = 1;
            }
        }
 
        private int root(int N)
        {
            if (parents[N] == N) return N;
            return parents[N] = root(parents[N]);
        }
 
        //木を併合する際に、枝の数も合算する
        public void unite(int X, int Y)
        {
            int rootX = root(X);
            int rootY = root(Y);
            if (rootX == rootY) return;
            rootCount[rootX] += rootCount[rootY];
            parents[rootY] = rootX;
        }
 
        public bool sameRoot(int X, int Y)
        {
            return root(X) == root(Y);
        }
    }
}

Measured memory_bytes: 20640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#define mp make_pair
#define pb push_back
#define INF 100000005
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
typedef long long int ll;

int main(){
    ll c[500005];
    ll m[500005];
    ll sum;
    int N;
    ll P,Q;
    scanf("%d %lld %lld",&N,&P,&Q);
    rep(i,N){
        scanf("%lld",c+i);
        sum+=c[i];
        m[i]=c[i]-P*(Q-i);
    }
    sort(m,m+N);
    ll ret = sum;
    rep(i,N){
        sum += P*i*2;
        sum -= m[i];
        ret=max(sum,ret);
    }
    cout<<ret<<endl;
    
}

Measured memory_bytes: 9036
//In the name of God
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second

ll n;
string s;

int main(){
    fast_io;

    cin >> s;
    n = s.size();
    for(ll i = 0; i < n; i++){
        if(s[i] == '?') s[i] = 'D';
    }
    cout << s;

    return 0;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int x,y,s{};
    in>>x>>y;
    if(x<2) s+=300000;
    else if(x<3) s+=200000;
    else if(x<4) s+=100000;
    if(y<2) s+=300000;
    else if(y<3) s+=200000;
    else if(y<4) s+=100000;
    if(x==1&&y==1) s+=400000;
    cout<<s<<endl;
}

Measured memory_bytes: 256
/*
    And I know I may end up failing too
*/




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

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int>pii;
typedef unsigned long long ull;

#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
#define pf           push_front
#define pi           acos(-1)
#define all(x)       x.begin(),x.end()
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define INF          0x3f3f3f3f

struct hash_pair
{
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);auto hash2 = hash<T2> {}(p.second);return hash1 ^ hash2;
    }
};

ll t;
ll mod=N;
ll BigMod(ll base,ll pow,ll mod)
{
    if(pow==0||base==1)return 1;
    else if(pow==1)return base;
    else if(pow%2)return BigMod(base,pow-1,mod)*base%mod;
    else {ll x=(BigMod(base,pow/2,mod)%mod);x=(x*x)%mod;return x;}
}

ll arr[100005];

int main()
{
    fast;
    ll a,b,c,d,e,f,g,i,j;
    ll n,m,k;
    cin>>n;
    f=0;
    for(i=0;i<n;i++)
    {
        cin>>a;
        f+=a;
        arr[a]++;
    }
    cin>>m;
    for(i=0;i<m;i++)
    {
        cin>>a>>b;
        f-=(arr[a]*a);
        f-=(arr[b]*b);
        arr[b]+=arr[a];
        arr[a]=0;
        f+=(arr[b]*b);
        cout<<f<<endl;
    }

    return 0;
}


Measured memory_bytes: 4396
#include<stdio.h>
#define rep(i,n) for(i=0;i<n;i++)
void swap(int*a,int*b){int t=*a;*a=*b;*b=t;}
int main(void)
{
	int n,a[100],i,j,c;
	for(;;){
		scanf("%d",&n);if(!n)break;
		c=0;
		rep(i,n)scanf("%d",a+i);
		for(i=n-1;i;i--){
			rep(j,i){
				if(a[j]>a[j+1]){swap(a+j,a+j+1);c++;}
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 0
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    int n, q;
    cin >> n;
    vector<int> S(n);
    for(auto &x : S) cin >> x;
    cin >> q;
    vector<int> T(q);
    for(auto &x : T) cin >> x;

    int cnt = 0;
    REP(i, q){
        REP(j, n){
            if(T[i] == S[j]){
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 3176
/*betaでやろう*/
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <iterator>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair
#define INT int_64
const ll INF = 1e17;
const ll NEGA=-INF; 

ll ans = 0;
int cnt=0;

int used[1001];
ll dp[1001][1001];
ll sumx,sumy,sumz;
ll sx,sy,sz;
ll a[101];
int main() 
{ 
 ll n;
 cin>>n;
 rep(i,n) cin>>a[i];
 int ans=0;
 rep(i,n-1){
     if(a[i]==a[i+1]) {
         ans++;
         a[i+1]=-1;
     }
 }
 cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int N, M, A[1001], i, k, tmp, j = 0, h = 0, ans = 0;
	scanf("%d%d", &N, &M);
	for (i=0; i < M ;i++) {
		scanf("%d%d", &tmp, &k);
		if (tmp < N) {
			A[h] = tmp;
			h++;
		} else j++;
	}
	for (i=0; i < h ;i++) {
		for (k=0; k < h ;k++) {
			if (A[k] < A[k+1] && k+1 < h) {
				tmp = A[k];
				A[k] = A[k+1];
				A[k+1] = tmp;
			} else if (A[k] > A[k-1] && k+1 == h) {
				tmp = A[k-1];
				A[k-1] = A[k];
				A[k] = tmp;
			}
		}
	}
	for (tmp=0; tmp+j+1 < M ;tmp++) {
		ans += N-A[tmp];
	}
	printf("%d\n", ans);
	return 0;
}

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

long long n, k, h, total = 0;
priority_queue<long long> hps;

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> h;
        total += h;
        hps.push(h);
    }

    while (k-- && hps.size() > 0)
    {
        total -= hps.top();
        hps.pop();
    }

    cout << total;
    cin >> n;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    string s;
    cin >> s;
    cout << (count(ALL(s), '7') ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a[10000],i,c=0;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            if(a[i]%3==0 || a[i]%5==0)
            {}
            else
            {
                c++;
            }
        }
    }
    if(c==0)
    {
        cout << "APPROVED" << endl;
    }
    else
    {
        cout << "DENIED" << endl;
    }
    return 0;

}


Measured memory_bytes: 3584
a = input()
b = int(a)
c = list(a)
t = int(a[0])
r = t+(len(a)-1)*9
#print(t,a.count("9"))
if t != 9  and a.count("9") == len(a)-1:
    r = t+(len(a)-1)*9
elif a.count("9") != len(a):
    t -= 1
    r = t+(len(a)-1)*9
if b<9:
    r = b
elif b == 9:
    r = 9
    
print(r)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
    int i, x, n;

    scanf("%d", &n);
    for (i=1; i<=n; i++) {
        x = i;
        if (x % 3 == 0) {
            printf(" %d", i);
        } else {
            while (x != 0) {
                if (x % 10 == 3) {
                    printf(" %d", i);
                    break;
                }
                x /= 10;
            }
        }   
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vint l(2*n);
    rep(i, 2*n) cin >> l[i];
    sort(all(l));

    int ans = 0;
    for (int i = 0; i < 2*n; i += 2) {
        ans += l[i];
    }

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

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

#ifdef WINT_MIN
#define __MAI
#endif

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007ll
void printbit(int u) { if (u == 0)cout << 0; else { int s = 0, k = 0; for (; 0<u; u >>= 1, k++)s = (s << 1) | (u & 1); for (; 0<k--; s >>= 1)cout << (s & 1); } }template<typename T1, typename T2>
    ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << "(" << p.first << ":" << p.second << ")"; return o; }

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

namespace {
    std::chrono::system_clock::time_point t;
    void tic() { t = TIME; }
    void toc() { fprintf(stderr, "TIME : %lldms\n", MILLISEC(TIME - t)); }
    std::chrono::system_clock::time_point tle = TIME;
#ifdef __MAI
    void safe_tle(int msec) { assert(MILLISEC(TIME - tle) < msec); }
#else
#define safe_tle(k) ;
#endif
}

#ifndef __MAI 
namespace {
    class MaiScanner {
    public:
        template<typename T>
        void input_integer(T& var) {
            var = 0;
            T sign = 1;
            int cc = getchar_unlocked();
            for (; cc<'0' || '9'<cc; cc = getchar_unlocked())
                if (cc == '-') sign = -1;
            for (; '0' <= cc&&cc <= '9'; cc = getchar_unlocked())
                var = (var << 3) + (var << 1) + cc - '0';
            var = var*sign;
        }
        void ign() { getchar_unlocked(); }
        MaiScanner& operator>>(int& var) {
            input_integer<int>(var);
            return *this;
        }
        MaiScanner& operator>>(long long& var) {
            input_integer<long long>(var);
            return *this;
        }
    };
}
MaiScanner scanner;
#else
#define scanner cin
#endif

int width, height;
int m, n;

ll aa[300010];

int main() {
    int i, j, k;
    ll x, y, a, b;

    scanner >> n;

    for (i = 0; i < 3 * n; ++i) {
        scanner >> aa[i];
        aa[i] = -aa[i];
    }

    sort(aa, aa + 3 * n);


    ll sum = 0;
    for (i = 0; i < n; ++i) {
        a = aa[i * 2];
        b = aa[i * 2 + 1];
        sum += b;
    }

    cout << -sum << endl;


    return 0;
}

Measured memory_bytes: 2560
<?php
  list($a, $b, $n) = explode(" ", trim(fgets(STDIN)));

  $x = 0;
  if($n >= $b - 1){
    $x = $b - 1;
  }else{
    $x = $n;
  }
  echo intdiv($a*$x, $b) - 8 * intdiv($x, $b);


Measured memory_bytes: 16016
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define rsort(a) sort(all(a),greater<>())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> V;
const long long MOD=1000000007;
const long long INF = 1e18;
vector <ll> dp;


void solve(long long N, long long A, long long B){
    ll ans = 0, sum = 0;
    for (ll i = 1; i <= N; i++) {
        // ll sum = i%10+i/10+i/100+i/1000;
        // sum = i/1000 + (i%1000)/100 + (i%100)/10 + (i%10);
        sum = i/10000;
        sum += i%10000 ? i%10000/1000 : 0;
        sum += i%1000 ? i%1000/100 : 0;
        sum += i%100 ? i%100/10 : 0;
        sum += i%10 ? i%10 : 0;
        if (sum >= A && sum <= B)
        {
            ans += i;
        }
        sum = 0;
    }
    cout << ans << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


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

int main(){
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());

    if(s<t)
    puts("Yes");
    else
    puts("No");
}

Measured memory_bytes: 256
N, Y = map(int,input().split())

for i in range(N+1):
  for j in range(N-i+1):
    k = N - i - j
    if(k >= 0):
      if(10000*i + 5000*j + 1000*k == Y):
        print(i, j, k)
        exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
#include <cstdio>

int main()
{
  char s[11];
  char ans[11];
  scanf("%s", s);
  for (char *p = s, *ap = ans; *p; ++p)
  {
    if (*p == 'B')
    {
      if (ap != ans)
      {
        --ap;
      }
      *ap = 0;
    }
    else
    {
      *ap++ = *p;
      *ap = 0;
    }
  }
  puts(ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

string s;

int main(void){
    
    cin >> s;
    reverse(s.begin(), s.end());
    
    string ans, temp;
    for(int i = 0; i < s.size(); ++i){
        temp.push_back(s[i]);
        string n = temp; reverse(n.begin(), n.end());
        if(n == "dream" || n == "dreamer" || n == "erase" || n == "eraser") ans += temp, temp = "";
    }
    printf("%s\n", (ans == s) ? "YES" : "NO");
    
    return 0;
}

Measured memory_bytes: 640
#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 rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<ll> g[n+1];
  rep(i, n){
    ll u,k;cin>>u>>k;
    rep(j, k){
      ll t;cin>>t;
      g[u].push_back(t);
    }
  }

  vector<ll>result(n+1);
  rep1(i, n)result[i]=-1;

  result[1]=0;

  queue<ll> q;
  q.push(1);
  while(!q.empty()){
    ll c = q.front();
    q.pop();
    for(auto to: g[c]){
      if(result[to]>=0)continue;

      result[to] = result[c]+1;
      q.push(to);
    }
  }

  rep1(i, n)cout<<i<<' '<<result[i]<<endl;

  return 0;
}



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

int main(){
  int n;
  long long a[200001] = {};
  cin >> n;

  int tmp;
  for(int i = 1;i <= n;i++){
    cin >> tmp;
    a[i] = a[i-1]+tmp;
  }

  long long ans = LLONG_MAX;
  for(int i = 1;i < n;i++){
    ans = min(ans,llabs(a[i]-(a[n]-a[i])));
  }

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



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define INF 1000000000000000000

int main(){
  int N;
  cin>>N;
  vector<ll> A(N+1);
  ll sum=0;
  for(int i=0;i<=N;i++){
    cin>>A.at(i);
    sum+=A.at(i);
  }

  vector<ll> possible(N+1,0);//深さiで子を持つ頂点の数であり得る最大の数
  bool flag=true;
  ll number=1;

  int depth=N;
  for(int i=0;i<=N;i++){
    number-=A.at(i);
    if(number<0){
      flag=false;
    }
    possible.at(i)=number;
    if(number>=INF){
      depth=i;
      break;
    }
    number<<=1;
  }

  ll ans=0;
  number=0;
  for(int i=N;i>=0;i--){
    if(i>depth){
      number+=A.at(i);
      ans+=number;
    }else{
      if(number>possible.at(i)){
        number=possible.at(i);
      }
      number+=A.at(i);
      ans+=number;
    }
  }
  if(flag){
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }
}


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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

const int N = 1000007, inf = 0x3f3f3f3f;
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;


vector<tuple<int, int, int, int>> que;
int n, m, q;
ll best = 0;
vector<int> v = {0};
void solve(int n, int down) {
	if(n == 0) {
		ll sum = 0;
		for(auto aux : que) {
			int a, b, c, d;
			tie(a, b, c, d) = aux;
			if(v[b] - v[a] == c) sum += d;
		}
		best = max(best, sum);
		return;
	}

	for(int i = down; i <= m; ++i) {
		v.pb(i);
		solve(n-1, i);
		v.pop_back();
	}
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	 cin >> n >> m >> q;
	for(int i = 0; i < q; ++i) {
		int a, b, c, d; cin >> a >> b >> c >> d;
		que.eb(a, b, c, d);
	}

	solve(n, 1);

	cout << best << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(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 unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int n, m, col[1010], cnt[2];
vector<int> G[1010];

bool is_bipartite(int v, int c){
    if(col[v] >= 0) return col[v] == c;
    col[v] = c;
    ++cnt[c];
    for(int nv: G[v]){
        if(!is_bipartite(nv, c^1)) return false;
    }
    return true;
}

void solve(){
    rep(i, n) G[i].clear();
    rep(i, m){
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    fill(col, col+n, -1);
    cnt[0] = cnt[1] = 0;
    if(!is_bipartite(0, 0)){
        printf("%d\n", 0);
        return;
    }
    set<int> S;
    rep(i, 2)if(cnt[i] % 2 == 0) S.insert(cnt[i] / 2);
    printf("%d\n", S.size());
    for(int x: S) printf("%d\n", x);
}

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


Measured memory_bytes: 3384
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
    f=[d[k]for k in p]
    if f[0]==e[0]and f[5]==e[5]:
     f=f[1:5]*2
     for k in range(4):
      if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(f())


Measured memory_bytes: 5616
/*  -*- coding: utf-8 -*-
 *
 * b.cc: D: Equal Cut
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;

/* global variables */

ll asums[MAX_N + 1];

/* subroutines */

inline ll maxll(ll a, ll b) { return (a > b) ? a : b; }
inline ll minll(ll a, ll b) { return (a < b) ? a : b; }

/* main */

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

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

  ll mind = LINF;
  for (int k = 2; k + 2 <= n; k++) {
    ll av0 = (asums[0] + asums[k]) / 2, av1 = (asums[k] + asums[n]) / 2;
    int i0 = lower_bound(asums, asums + k + 1, av0) - asums;
    int i1 = lower_bound(asums + k + 1, asums + n + 1, av1) - asums;

    for (int i = i0 - 2; i <= i0 + 2; i++)
      if (i > 0 && i < k) {
	ll b0 = asums[i] - asums[0], b1 = asums[k] - asums[i];
	ll maxb01 = maxll(b0, b1);
	ll minb01 = minll(b0, b1);
	for (int j = i1 - 2; j <= i1 + 2; j++)
	  if (j > k && j < n) {
	    ll b2 = asums[j] - asums[k], b3 = asums[n] - asums[j];
	    ll maxb23 = maxll(b2, b3);
	    ll minb23 = minll(b2, b3);
	    ll d = maxll(maxb01, maxb23) - minll(minb01, minb23);
	    if (mind > d) mind = d;
	  }
      }
  }

  printf("%lld\n", mind);
  return 0;
}


Measured memory_bytes: 1792