akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define  ll  long long
#define NOT_FOUND_ERROR -1
#define rep(k, n)  for(int i=k; i<n;  i++)
#define rep2(k,n)  for(int j=k; j<n;  j++)
using namespace std;
int DivUp(ll a, ll b) {return (a+(b-1)/b);} /*切り上げ*/

int main(){
    int a, b;
    string s;
    cin >> a >> b;
    if(a==b){
        rep(0,a) cout << b;
        return 0;
    }
    rep(0,max(a,b)) cout << min(a,b);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int a[3];
    int i;
    int tmp;

    for (i = 0; i < 3; i++) {
        scanf("%d",&a[i]);
    }
    
    if (a[0] > a[1]){
        tmp = a[0];
        a[0] = a[1];
        a[1] = tmp;
    }
    if (a[1] > a[2]){
        tmp = a[1];
        a[1] = a[2];
        a[2] = tmp;
    }

    if (a[0] > a[1]){
        tmp = a[0];
        a[0] = a[1];
        a[1] = tmp;
    }

    printf("%d %d %d\n",a[0],a[1],a[2]);
    return 0;
}

Measured memory_bytes: 596
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int x,n;
  cin >> x >> n;
  vector<int>p(n);
  rep(i,n) cin >> p.at(i);
  rep(i,n) p.at(i) = 100+p.at(i);
  vector<int>a(210);
  rep(i,n) a.at(p.at(i))++; 
  int mi = 10000;
  int num = 0;
  x = x + 100;
  for(int i=0;i<210;i++){
    if(a.at(i)!=1){
      if(mi > min(mi,abs(x-i))){
        num = i;
      mi = min(mi,abs(x-i));
      }
    }
  }
//  cout << mi << endl;             
  cout << num - 100<< endl;
}

Measured memory_bytes: 3628
number = int(input())
x = input().split(" ")
sum = 0
max = int(x[0])
min = int(x[0])
for i in range(0, number):
    sum = sum + int(x[i])
    if max < int(x[i]):
        max = int(x[i])
    elif int(x[i]) < min:
        min = int(x[i])
print(str(min)+" "+str(max)+" "+str(sum))
    



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

using namespace std;

int main() {
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  bool ok = true;
  vector<int> v(3);
  v[0] = A;
  v[1] = B;
  v[2] = C;
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    int idx1 = S[i][0] - 'A';
    int idx2 = S[i][1] - 'A';
    if (v[idx1] == 0 and v[idx2] == 0) {
      ok = false;
      break;
    } else if (v[idx1] == 1 and v[idx2] == 1) {
      if (i < N - 1 and S[i] != S[i + 1]) {
        int n1 = S[i + 1][0] - 'A';
        int n2 = S[i + 1][1] - 'A';
        if (idx1 == n1 or idx1 == n2) {
          v[idx1]++;
          v[idx2]--;
          ans[i] = idx1;
        } else if (idx2 == n1 or idx2 == n2) {
          v[idx1]--;
          v[idx2]++;
          ans[i] = idx2;
        }
      } else {
        v[idx1]--;
        v[idx2]++;
        ans[i] = idx2;
      }
    } else if (v[idx1] > v[idx2]) {
      v[idx1]--;
      v[idx2]++;
      ans[i] = idx2;
    } else {
      v[idx1]++;
      v[idx2]--;
      ans[i] = idx1;
    }
  }
  if (!ok) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  for (int i = 0; i < N; i++) {
    if (ans[i] == 0) {
      cout << "A" << endl;
    } else if (ans[i] == 1) {
      cout << "B" << endl;
    } else {
      cout << "C" << endl;
    }
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 6692
#include <stdio.h>

int main () {
	int sLength, sLetter;
	char text[55];
	
	scanf("%d%d", &sLength, &sLetter);
	getchar();
	scanf("%s", &text);
	text [sLetter-1] += 32;
	printf("%s\n", text);
	
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x,y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x,y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define d4(x,y,z,w)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z << " | "<< #w << "--> " << w <<endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=1e9+7;
const long long maxn=30;
const long long inf=99999999999;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRand(ll l, ll r){ uniform_int_distribution<ll> uid(l, r); return uid(rng); }

void solve(){
	
	ll k;
	cin>>k;
	string s;
	cin>>s;
	ll n=s.size();
	if (n<=k){
		cout<<s<<endl;
	}
	else{
		for (int i=0;i<k;i++){
			cout<<s[i];
		}
		cout<<"...";
		cout<<endl;
	}
	
	return;
}

 
int main(){ 
    
    #ifndef ONLINE_JUDGE
	//	freopen("input.txt", "r", stdin);
    #endif
    srand(time(0)); 
    
    ios::sync_with_stdio(0);
    cin.tie(0);
 	
	//T{ solve(); }
	solve();
	
	
	return 0;
	
}

Measured memory_bytes: 3668
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;



int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    ll absMX = 0;
    int z;
    rep(i, n){
        cin >> a[i];
        absMX = max(absMX, abs(a[i]));
        if(absMX == abs(a[i]))z = i;
    }

    vector<P> p;
    rep(i, n){
        if(i == z)continue;
        p.emplace_back(z, i);
    }
    if(a[z] < 0) for(int i = n - 1; i > 0; i--)p.emplace_back(i, i - 1);
    
    else for(int i = 0; i < n - 1; i++)p.emplace_back(i, i + 1);
    cout << p.size() << endl;
    for(auto x : p)cout << x.first + 1 << " " << x.second + 1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793



int main(){
  int N, K, C; cin >> N >> K >> C;
  string S; cin >> S;
  vector<int> L, R; int prev = -inf;
  rep(i, N){
    if(S[i]=='o' && i-prev>C){
      prev = i; L.push_back(i);
    }
  }
  prev = inf;
  for(int i=N-1; i>=0; i--){
    if(S[i]=='o' && prev-i>C){
      prev = i; R.push_back(i);
    }
  }
  if(L.size()!=K || R.size()!=K){
    return 0;
  }
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());
  rep(i, K){
    if(L[i]==R[i]){
      cout << L[i]+1 << endl;
    }
  }
}

Measured memory_bytes: 3448
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]
INF = 10 ** 9

ans = INF
for i in range(1 << n):
    sm = [0] * m
    cost = 0
    for j in range(n):
        if i >> j & 1:
            cost += ca[j][0]
            for k, e in enumerate(ca[j][1:]):
                sm[k] += e

    if min(sm) >= x:
        ans = min(ans, cost)

if ans == INF:
    ans = -1

print(ans)


Measured memory_bytes: 9208
#include <bits/stdc++.h>
#include <stdio.h>
#define ll long long
#define fr(i,p,n) for(ll i=p;i<n;i++)
#define fr1(i,p,n) for(ll i=p;i>=n;i--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e9
#define precise cout << std::setprecision(12) << std::fixed;
#define endl "\n"
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    FAST
    int t=1;
    //cin>>t;
    while(t--)
    {
        int x,n;
        cin>>x>>n;
        if(n==0) {cout<<x<<endl;continue;}
        int p[n];
        pair<int,int> a[n];
        fr(i,0,n)
        {
            cin>>p[i];
            a[i].ff=abs(p[i]-x);
            a[i].ss=p[i];
        }
        sort(a,a+n);
        //fr(i,0,n) cout<<a[i].ff<<a[i].ss<<endl;
        if(a[0].ff!=0) {cout<<x<<endl;continue;}
        int ans=0;
        int cnt=0;
        bool f=0;
        fr(i,1,n)
        {
            int num=i/2+(i%2!=0);
            //cout<<num<<endl;
            if(a[i].ff==num)
            {
                cnt++;
                continue;
            }
            if(cnt%2==0) ans=x-num;
            else ans=2*x-a[i-1].ss;
            f=1;
            break;
        }
        if(f==0)
        {
            int num=n/2+(n%2!=0);
            if(cnt%2==0) ans=x-num;
            else ans=2*x-a[n-1].ss;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  int m;cin >> m;
  int a[n][2];
  rep(i,n){
    cin >> a[i][0];
    cin >> a[i][1];
  }

  int b[m][2];
  rep(i,m){
    cin >> b[i][0];
    cin >> b[i][1];
  }

  rep(i,n){
    Int count = INF;
    Int an = INF;
    Int ans = 0;
    rep(j,m){
      count = abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1]);
      //debug(count);
      if(an>count){
        an = count;
        ans = j+1;
      }
    }
  cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,i,j,k,l,mp[25][25],all[1<<16],dp[1<<16][25],x,y,z,sum,ans;
int main(){
	cin>>n>>m;
	for (i=1;i<=m;i++){
		cin>>x>>y>>z;
		x--;y--;
		sum+=z;
		mp[x][y]=mp[y][x]=z;
	}
	for (i=0;i<(1<<n);i++){
		for (j=0;j<n;j++)if ((i>>j)&1){
			for (k=j+1;k<n;k++)if ((i>>k)&1){
				all[i]+=mp[j][k];
			}
		}
	}
	memset(dp,-1,sizeof(dp));
	dp[1][0]=0;
	for (i=1;i<(1<<n);i++){
		for (j=0;j<n;j++) if ((i>>j)&1)if (dp[i][j]!=-1){
			for (k=((((1<<n)-1)^i)|(1<<j));k;k=((k-1)&((((1<<n)-1)^i)|(1<<j)))){
				dp[i|k][j]=max(dp[i|k][j],dp[i][j]+all[k]);
			}
			for (k=0;k<n;k++) if (!((i>>k)&1)) if (mp[j][k]){
				dp[i|(1<<k)][k]=max(dp[i|(1<<k)][k],dp[i][j]+mp[j][k]);
			}
		}
		/*if (i>32766){
			system("pause");
		}*/
		if ((i>>(n-1))&1) ans=max(ans,dp[i][n-1]);
		/*if (ans>1234567){
			system("pause");
		}*/
	}
	cout<<sum-ans<<endl;
	return 0;
}

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

using namespace std;

int main()
{
    int c;

    string str, str2;

    cin >> str >> str2;

    if(str[0] == str2[0])
    {
        c++;
    }

    if(str[1] == str2[1])
    {
        c++;
    }

    if(str[2] == str2[2])
    {
        c++;
    }

    cout << c << endl;

    return 0;
}

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

const int N = 200005;

int main() {
   
   set <int> s;
   s.insert(1);
   int x;
   cin >> x;
   for(int i = 2; i <= 10000; i++) {
      int val = i * i;
      while(val <= x) {
         s.insert(val);
         val *= i;
      }
   }   

   cout << *s.rbegin() << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,xa,xb;
ll md=1e9+7;
map<ll, ll> mp;
ll a[200010],b[200010];
ll ksm(ll x)
{
	if (!x) return 1;
	else if (mp[x]) return mp[x];
	else return mp[x]=(((ksm(x/2)*ksm(x/2))%md)*(x%2 ? 2 : 1))%md;
} 
ll cnt(ll x)
{
	//cout <<x<<" ##\n";
	fill(a+2,a+x+1,1);
	for (ll i=0;i<x;i++) b[i]=n-i;
	for (ll i=x;i>=2;i--)
	{
		ll st=n%i;
		//if (i<1000) cout <<i<<" "<<a[i]<<" ##\n";
		while (a[i] && st<x)
		{
			while (b[st]%i==0 && a[i]) b[st]/=i,a[i]--;
			if (!a[i]) break;
			ll t=__gcd(i,b[st]);
			a[i]--,a[i/t]++,b[st]/=t;
			st+=i;
		}
		if (a[i])
		{
			for (ll j=(ll)sqrt(i);j>1;j--)
			{
				if (i%j==0)
				{
					//cout <<i<<" "<<j<<" "<<i/j<<" ##\n";
					a[j]+=a[i],a[i/j]+=a[i],a[i]=0;
					break;
				}
			}
		}
	}
	ll r=1;
	//for (int i=2;i<=x;i++) cout <<i<<" "<<a[i]<<" ##\n";
	for (ll i=0;i<x;i++)
	{
		//cout <<i<<" "<<b[i]<<" ##\n";
		r=(r*b[i])%md;
	}
	return r;
}
int main()
{
	cin >>n>>xa>>xb;
	ll res=ksm(n)-1-cnt(xa)-cnt(xb);
	//cout <<ksm(n)-1<<" "<<cnt(xa)<<" "<<cnt(xb)<<" ##\n"; 
	while (res<0) res+=md;
	cout <<res;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long int
#define N 100000
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;
/**
        * @author :: Sawlani
        *
        */

int main()
{

    cout << fixed << setprecision(11);
     double l;
     cin >>  l;

     double ans;
     ans=(double)(l/3.0)*(l/3.0)*(l/3.0);

     cout << ans ;
     
}

Measured memory_bytes: 256
"use strict";
function body(ary){
    let ans = "";
    if (ary[0] < ary[1] && ary[1] < ary[2]){
	ans = "Yes";
    } else {
	ans = "No";
    }
    return ans;
}

(function (){
    var s = require("fs").readFileSync("/dev/stdin", "utf8");
    var ary = s.split(' ').map(Number);

    var ans=body(ary);
    
    console.log(ans);
})();


Measured memory_bytes: 15104
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef long long int ll;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll n,m,i,a,b,dp[100005],maxi;
vector<ll>v[100005];

ll dfs(ll x)
{
	dp[x]=0;
	for(ll i=0;i<v[x].size();i++)
	{
		if(dp[v[x][i]]==-1)
			dp[v[x][i]]=dfs(v[x][i]);
		if(dp[x]<1+dp[v[x][i]])
			dp[x]=1+dp[v[x][i]];
	}
	return dp[x];
}

int main()
{
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>a>>b;
		v[a].pb(b);
	}
	memset(dp,-1,sizeof(dp));
	for(i=1;i<=n;i++)
	{
		if(dp[i]==-1)
			dp[i]=dfs(i);
	}
	for(i=1;i<=n;i++)
		maxi=max(maxi,dp[i]);
	cout<<maxi;
	return 0;
}

Measured memory_bytes: 8576
let input = readLine()!
    .split(separator: " ")
    .compactMap { Int($0) }

let left = input[0] + input[1]
let right = input[2] + input[3]

if left > right {
    print("Left")
} else if left < right {
    print("Right")
} else {
    print("Balanced")
}


Measured memory_bytes: 8240
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<bool> vis(n+1,false);
	queue<pair<int,int>> q;
	q.push({n,0});
	vis[n]=true;
	while(!q.empty()){
		auto p=q.front();
		q.pop();
		int val=p.first, moves=p.second;
		if(val==0) return cout<<moves, 0;
		if(!vis[val-1]){vis[val-1]=true; q.push({val-1,moves+1});}
		for(int sub=6;val-sub>=0;sub*=6){
			if(!vis[val-sub]){
				vis[val-sub]=true;
				q.push({val-sub,moves+1});
			}
		}
		for(int sub=9;val-sub>=0; sub*=9){
			if(!vis[val-sub]){
				vis[val-sub]=true;
				q.push({val-sub,moves+1});
			}
		}
	}
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int K = s.nextInt();
		int A = s.nextInt();
		int B = s.nextInt();
		
		boolean ans = false;
		for(int i=A; i<=B; i++) {
			if(i%K == 0) {
				ans = true;
				break;
			}
		}
		
		if(ans) {System.out.println("OK");}
		else {System.out.println("NG");}

		
	}

}


Measured memory_bytes: 35704
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B;
string S;
cin>>A>>B>>S;
for(int i=0;i<A-1;i++){
    if(S[i]=='0'||S[i]=='1'||S[i]=='2'||S[i]=='3'||S[i]=='4'||S[i]=='5'||S[i]=='6'||S[i]=='7'||S[i]=='8'||S[i]=='9')continue;
    cout<<"No";
    return 0;
}
if(S[A]!='-'){
    cout<<"No";
    return 0;
}
for(int i=A+1;i<S.size();i++){
if(S[i]=='0'||S[i]=='1'||S[i]=='2'||S[i]=='3'||S[i]=='4'||S[i]=='5'||S[i]=='6'||S[i]=='7'||S[i]=='8'||S[i]=='9')continue;
cout<<"No";
return 0;

}
cout<<"Yes";
return 0;
}

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

ifstream fin("parimpar2.in");
ofstream fout("parimpar2.out"); 

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
   
    int n, k;
    cin >> n >> k;
    int ans=k;
    for(int i=0; i<n-1; ++i)
        ans*=k-1;
    cout << ans;
    return 0;
}


Measured memory_bytes: 3648
jewel, query = map(int, input().split())
t = min(jewel, query)
dq = [int(i) for i in input().split()]
ans = []

for i in range(t+1):
  for j in range(i+1):
    have = dq[:j] + dq[(jewel-i+j):]
    drop = query - len(have)

    for k in range(drop):
      if not have:
        break
      
      cand = min(have)
      if cand < 0:
        have.remove(cand)
      else:
        break
        
    ans.append(sum(have))
    
print(max(ans))

Measured memory_bytes: 3064
n, q = map(int, input().split())
s = input()
l = 0
r = n - 1
Q = [(input().split()) for i in range(q)]
Q.reverse()
for t,d in Q:
    if s[l] == t and d == "L":
        l += 1
    elif l > 0 and s[l - 1] == t and d == "R":
        l -= 1
    if s[r] == t and d == "R":
        r -= 1
    elif r < n - 1 and s[r + 1] == t and d == "L":
        r += 1
    if l > r:
        break
print(r - l + 1)


Measured memory_bytes: 39348
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map(String::toLong)
    var r = 0
    var s = 0L
    var ans = 0L
    for (l in 0..(n - 1)) {
        while (r < n && (s + a[r]) == (s xor a[r])) {
            s += a[r]
            r++
        }
        ans += r - l
        s -= a[l]
        if (l > r) r = l
    }
    println(ans)
}

Measured memory_bytes: 82752
/*
useful stl
array<ll,size> ar;         //size(),front(),back(),fill(),empty()
deque<ll> d                //push_back(),push_front(),pop_front(),pop_back()
vector<ll> v(size,val);    //push_back(),*max_element(v.begin(),v.end()),accumulate(v.begin(),v.end(),0),pop_back()
stack<ll> g;               //push(),pop(),top(),size(),empty()         LIFO
queue<ll> q;               //push(),size(),front(),back(),empty()      FIFO
priority_queue<ll> pq
*/
#include <bits/stdc++.h>
 
using namespace std;

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    char c;
    cin>>c;
    cout<<char(c+1);
    return 0;
}


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

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

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0; i<n; i++){
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  double ans=v.at(0);
  for(int i=1; i<n; i++){
    ans += v.at(i);
    ans /= 2.0;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 3e5 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r; 
}
void solve()
{
	ll x, k, d;
	cin >> x >> k >> d;
	ll a = min(abs(x) / d, k);
	k -= a;
	if(x > 0) {
		x -= a * d;
		if(k % 2) x -= d;	
	}
	else {
		x += a * d;
		if(k % 2) x += d;
	}
	x = abs(x);
	cout << x;
}
 
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main()
{
    ll n,m; cin >> n >> m;
    vector<ll> h(n); rep(i, n) cin >> h[i];
    using Graph = vector<vector<ll>>; // グラフ型
    Graph G(n); // グラフ
    rep(i,m){
        ll a,b; cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
//        g[a-1][b-1] = 1; g[b-1][a-1] = 1;
    }
    ll ans = 0;
    rep(i,n){
        bool flg=true, flg2=false;
        for(auto c : G[i]){
            flg2 = true;
            if(h[c] >= h[i]) flg=false;
        }
//        cout << flg << flg2 << endl;
        if(flg || !flg2) ans++;
    }
    cout << ans << endl;
}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ c.cpp
./a.out

サンプルのダウンロードは oj d URL
テストは oj t
コード変えたらコンパイルする
不正解ならWAが出る
*/

Measured memory_bytes: 9768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#define pi 3.14159265358979323846264338327950

int main() {
	int N, A, B; std::cin >> N >> A >> B;
	std::string s; std::cin >> s;
	int count = 0; int count_b = 0;
	for (int i{ 0 }; i < s.size(); ++i) {
		if (s[i] == 'c') {
			std::cout << "No" << std::endl;
		} else if (s[i] == 'a') {
			if (count < A + B ) {
				std::cout << "Yes" << std::endl;
				++count;
			}
			else {
				std::cout << "No" << std::endl;
			}
		} else {
			if (count < A + B && count_b < B) {
				std::cout << "Yes" << std::endl;
				++count;
				++count_b;
			}
			else {
				std::cout << "No" << std::endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3776
while True:
	n = int(raw_input())
	if n == 0: break

	else:
		list = []
		for i in range(n):
			score = int(raw_input())
			list.append(score)
		list.sort();
		list.pop(0);
		list.pop();
		x = sum(list) / (n-2)
		print x

Measured memory_bytes: 6404
import heapq
class HeapQ:
    def __init__(self, L, desc=False):
        if desc:
            L = [-l for l in L]
        self.sign = -1 if desc else 1
        self.HQ = L
        heapq.heapify(self.HQ)
    def pop(self):
        return heapq.heappop(self.HQ) * self.sign
    def push(self, x):
        heapq.heappush(self.HQ, x * self.sign)
    def get_list(self):
        return list([-hq for hq in self.HQ]) if self.sign == -1 else list(self.HQ)

n, m = map(int, input().split())
A = list(map(int, input().split()))
hq = HeapQ(A, desc=True)
for _ in range(m):
    hq.push(hq.pop() // 2)

print(sum(hq.get_list()))

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

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s;
	cin>>s;
	for(int i=s.size()-1;i>=3;i--){
		string t=s.substr(i-2,3);
		if(t=="eam"){
			t=s.substr(i-4,5);
			if(t!="dream"){
				cout<<"NO"<<endl;
				return 0;
			}
			i=i-4;
			continue;
		}
		else if(t=="mer"){
			t=s.substr(i-6,7);
			if(t!="dreamer"){
				cout<<"NO"<<endl;
				return 0;
			}
			i=i-6;
			continue;
		}
		else if(t=="ase"){
			t=s.substr(i-4,5);
			if(t!="erase"){
				cout<<"NO"<<endl;
				return 0;
			}
			i=i-4;
			continue;
		}
		else if(t=="ser"){
			t=s.substr(i-5,6);
			if(t!="eraser"){
				cout<<"NO"<<endl;
				return 0;
			}
			i=i-5;
			continue;
		}
		else{
			cout<<"NO"<<endl;
			return 0; 
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 512
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let s: Vec<char> = itr.next().unwrap().chars().collect();
    if s[2] == s[3] && s[4] == s[5] {
        println!("Yes",)
    } else {
        println!("No",)
    }
}


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

int main()
{
    int d;
    cin >> d;
    int c[26];
    for(int i = 0; i < 26; i++) cin >> c[i];
    int s[400][26];
    for(int i = 0; i < d; i++){
        for(int j = 0; j < 26; j++) cin >> s[i][j];
    }
    int ans = 0;
    int last[26];
    for(int i = 0; i < 26; i++) last[i] = -1;
    for(int i = 0; i < d; i++){
        int v;
        cin >> v;
        v--;
        ans += s[i][v];
        last[v] = i;
        for(int j = 0; j < 26; j++) ans -= c[j] * (i - last[j]);
        cout << ans << endl;
    }
}


Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<array>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, s, a) for (int i = s; i < a; i++)
#define llint long long int
using namespace std;

const int N_MAX = 505;
const int INF = 9999999;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a + b / 2;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define loop(i, a, b) for(int i = a; i < b; i++)
#define pool(i, a, b) for(int i = a; i > b; i--)
#define pb push_back

const int maxn = 1e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

const int nax =3005;
ll dp[nax][nax];

int main()
{
	int n;
	fastIO
	scanf("%d", &n);
	vector <int> a(n);
	for(int& x : a)
		scanf("%d", &x);

	for(int L = n - 1; L >= 0; L--)
	{
		for(int R = L; R < n; R++)
		{
			if(L == R)
			{
				dp[L][R] = a[R];
			}
			else
			{
				dp[L][R] = max(a[L] - dp[L + 1][R], a[R] - dp[L][R - 1]);
			}
		}
	}
	cout << dp[0][n - 1];

	return 0;
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
typedef std::vector<long> LI;

struct BIT {
   LI xs;
   long n;
   BIT(long n) : xs(n+1), n(n) {}
   long sum(long i) {
      if( i <= 0 ) return 0;
      return xs[i] + sum(i-(i&-i));
   }
   void add(long i, long x) {
      if( i > n ) return;
      xs[i] += x;
      add(i+(i&-i), x);
   }
};

struct Solver {
   void solve() {
      long n, q; std::cin >> n >> q;
      BIT bit(n);
      for(long i = 0; i < q; ++i) {
         long com, x, y;
         std::cin >> com >> x >> y;
         if( com == 0 ) {
            bit.add(x, y);
         }
         else {
            long res = bit.sum(y) - bit.sum(x-1);
            printf("%ld\n", res);
         }
      }
   }
};

int main() { std::shared_ptr<Solver>(new Solver())->solve(); }

Measured memory_bytes: 3632
program ABC165_A
  integer::A,B,K
  read(*,*)K
  read(*,*)A,B
  N=0
  do i=1,1000
     if(A<=K*i .and. K*i<=B) then
        N=1
        go to 10
     end if
     if(K*i>1000) go to 10
  end do
 10 if(N==1) then
     write(*,*)'OK'
  else
     write(*,*)'NG'
  end if
end program ABC165_A

Measured memory_bytes: 2800
#include<queue>
#include<cstdio>

using namespace std;

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

struct Dice{
	int t,s,e,w,n,b;
	Dice(int tt,int ss,int ee,int ww,int nn,int bb):t(tt),s(ss),e(ee),w(ww),n(nn),b(bb){}
	void rotx(){
		Dice tmp=*this;
		t=tmp.w;
		e=tmp.t;
		w=tmp.b;
		b=tmp.e;
	}
	void roty(){
		Dice tmp=*this;
		t=tmp.s;
		s=tmp.b;
		n=tmp.t;
		b=tmp.n;
	}
};

struct Stat{
	int x,y,cost;
	Dice dice;
	Stat(int xx,int yy,int c,Dice d):x(xx),y(yy),cost(c),dice(d){}
	bool operator<(const Stat &st)const{ return cost<st.cost; }
};

int main(){
	for(int h,w;scanf("%d%d",&h,&w),h;){
		int grid[10][10];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)	scanf("%d",grid[i]+j);
		int sx,sy,gx,gy;	scanf("%d%d%d%d",&sy,&sx,&gy,&gx);

		Dice ini(1,2,3,4,5,6);

		int cmin[10][10][7][7],ans;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)for(int t=1;t<=6;t++)for(int w=1;w<=6;w++)	cmin[i][j][t][w]=1<<30;
		cmin[sy][sx][ini.t][ini.w]=0;
		priority_queue<Stat> pq;	pq.push(Stat(sx,sy,0,ini));
		while(!pq.empty()){
			Stat a=pq.top();	pq.pop();
			int x=a.x,y=a.y,cost=-a.cost;
			Dice d=a.dice;
			if(x==gx && y==gy){ ans=cost; break; }
			if(cmin[y][x][d.t][d.w]<cost)	continue;

			for(int i=0;i<4;i++){
				int xx=x+dx[i],yy=y+dy[i];
				if(0<=xx && xx<w && 0<=yy && yy<h){
					Dice nextdice=d;
					if(i==0)		nextdice.rotx();
					else if(i==1)	nextdice.roty();
					else if(i==2)	nextdice.rotx(),nextdice.rotx(),nextdice.rotx();
					else			nextdice.roty(),nextdice.roty(),nextdice.roty();
					int nextt=nextdice.t;
					int nextw=nextdice.w;
					int nextcost=cost+nextdice.b*grid[yy][xx];
					if(nextcost<cmin[yy][xx][nextt][nextw]){
						pq.push(Stat(xx,yy,-nextcost,nextdice));
						cmin[yy][xx][nextt][nextw]=nextcost;
					}
				}
			}
		}

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

	return 0;
}

Measured memory_bytes: 868
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ;

int n ,arr[N] ;
int main(){
    cin >> n ;
    for(int i=0;i<n;++i) cin >> arr[i];
    sort(arr,arr+n);
    long double ans = arr[0] ;
    for(int i=1;i<n;++i) ans = (ans + arr[i])/2 ;
    cout << fixed << setprecision(15) << ans ;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int N;
	cin>>N;
	if(N==1)cout<<"Hello World"<<endl;
	else{
		int A,B;
		cin>>A>>B;
		cout<<A+B<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;pair<string,int> a[100];int main(){int t=0,g,i;while(cin>>a[t].x>>a[t].y)t++;sort(a,a+t);string f,b=a[0].x;cout<<b<<endl<<a[0].y;for(i=1;i<t;i++){bool n=0;f=a[i].x,g=a[i].y;if(f==b)n=1;if(n)cout<<" "<<g;else cout<<endl<<f<<endl<<g;b=f;}cout<<endl;return 0;}

Measured memory_bytes: 1228
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    S = input()
    T = input()
    count = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            count += 1
    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68536
import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long prevT = 0;
		long prevA = 0;
		for (int i = 0; i < n; i++) {
			long t = sc.nextLong();
			long a = sc.nextLong();
			if (n == 0) {
				prevT = t;
				prevA = a;
				continue;
			}
			if (prevT > t || prevA > a) {
				long byT = prevT / t;
				if (prevT % t != 0) {
					byT++;
				}
				long byA = prevA / a;
				if (prevA % a != 0) {
					byA++;
				}
				long by = Math.max(byT, byA);
				t *= by;
				a *= by;
			}
			prevT = t;
			prevA = a;
		}
		System.out.println(prevT + prevA);
	}
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    ll n,x;
    ll a[4][13]={};
    char c[4]={'S','H','C','D'};
    cin>>n;
    char cc;
    REP(i,n){
        cin>>cc>>x;
        REP(j,4){
            if(c[j]==cc)a[j][x-1]=1;
        }
    }
    REP(i,4)REP(j,13){
        if(a[i][j]==0){
            cout<<c[i]<<" "<<j+1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3092
import scala.io.StdIn.{readInt,readLine}

object Main {
  def main(args:Array[String]) = {
    val n = readInt
    val d = new Array[Int](n)
    val f = new Array[Int](n)

    val g = {
      for(i<-0 until n) yield {
        val v = readLine.split(" ").map(_.toInt)
        (for(j<-2 until 2+v(1)) yield v(j) ).toArray
      }
    }.toArray

    def scan(i:Int,cnt:Int):Int = {
      if(d(i)==0) d(i) = cnt

      if(g(i).length > 0) {
        var cnt2 = cnt
        for(j<-0 until g(i).length) {
          if(f(g(i)(j)-1)==0 && d(g(i)(j)-1)==0) {
            cnt2 = scan(g(i)(j)-1,cnt2+1)
          }
        }
        f(i) = cnt2 +1
        cnt2 +1
      } else {
        f(i) = cnt+1
        cnt+1
      }
    }

    var cnt = 1
    for(i<-0 until n) {
      if(f(i)==0) cnt = scan(i,cnt)+1
    }

    for(i<-0 until n) {
      println((i+1) + " " + d(i) + " " + f(i))
    }
  }
}

Measured memory_bytes: 44124
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = (int)1e9 + 7;
int INF = (int)2e18;

signed main() {
    int N, K;
    cin >> N >> K;
    int M = 0;
    // init
    vector<pair<int, int>> ans;
    for (int i = 2; i <= N; i++) {
        ans.emplace_back(1, i);
        ++M;
    }
    int maxK = (N - 1) * (N - 2) / 2;
    if (maxK < K) {
        cout << -1 << endl;
        return 0;
    } else {
        int subK = maxK - K;
        for (int i = 2; i <= N - 1; i++) {
            for (int j = i + 1; j <= N; j++) {
                if (subK == 0) break;
                ans.emplace_back(i, j);
                ++M;
                --subK;
            }
        }
    }
    cout << M << endl;
    for (int i = 0; i < M; i++) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf (ll)(1e18)
#define mod 1000000007

int main()
{
    int t=1;
    //cin>>t;

    while( t-- )
    {
        ll a[2],b[2];

        cin>>a[0]>>a[1]>>b[0]>>b[1];

        ll ans=-1000000000000000000;
        for( int i=0 ; i<2 ; i++ )
            for( int j=0 ; j<2 ; j++ )
            ans=max( ans, a[i]*b[j] );

        cout<<ans;

    }
    return 0;
}












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

using namespace std;

int cnt = 0;
int MOD = 1000000007;

int main(){
    unsigned long long N,A,B;
    cin >> N >> A >> B;
    
    if((B-A)%2==0){
        cout << (B-A)/2 << endl;
        return 0;
    }else{
        cout << min(A-1,N-B)+1+(B-A-1)/2 << endl;
        return 0;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 200010;

int n, q;
char s[N];
char a[N], b[N];

int work(int pos) {
  for (int i = 1; i <= q; ++i) {
    if (s[pos] == a[i]) {
      if (b[i] == 'L')
        --pos;
      else
        ++pos;
    }
    if (pos == 0 || pos == n + 1)
      return pos;
  }
  return pos;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d%d%s", &n, &q, s + 1);
  for (int i = 1; i <= q; ++i)
    scanf(" %c %c", a + i, b + i);
  int ans = n;
  int l = 0, r = n;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (work(mid) == 0)
      l = mid;
    else
      r = mid - 1;
  }
  ans -= l;
  l = 1;
  r = n + 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (work(mid) != n + 1)
      l = mid + 1;
    else
      r = mid;
  }
  ans -= n - l + 1;
  printf("%d\n", ans);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 768
n=int(input())
s=input()
mod=10**9+7
op=1
ans=1
if s[0]=="W" or s[-1]=="W":
  print(0)
else:
  for i in range(1,2*n):
    if s[i]=="B":
      if op%2==0:
        op+=1
      else:
        ans*=op
        op-=1
    else:
      if op%2==1:
        op+=1
      else:
        ans=(ans*op)%mod
        op-=1
  if op!=0:
    ans=0
  for i in range(n):
    ans=(ans*(i+1))%mod
  print(ans)



Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n;
  cin >> n;
  set<long>yaku;
  set<long>ansers;
  set<long>m1yaku;
  if(n==2)cout<<1<<endl;
  else{
    long ans = 0;
    yaku.insert(n);
    for(long i=2;i*i<=n;i++){
      if(n%i==0){
        yaku.insert(i);
        yaku.insert(n/i);
      }
    }
    yaku.insert(n);
    for(long i:yaku){
      long tmp = n;
      while(tmp%i==0)tmp/=i;
      if(tmp%i==1)ansers.insert(i);
    }

    for(long i=2;i*i<=n-1;i++){
      if((n-1)%i==0){
        m1yaku.insert(i);
        m1yaku.insert((n-1)/i);
      }
    }
    ansers.insert(n-1);
    for(long i:m1yaku){
      ansers.insert(i);
    }
    cout<<ansers.size()<<endl;
  }
}


Measured memory_bytes: 512
S=input()
ans=0
a=0
i=0
while i<len(S):
    if S[i]=='A':
        a+=1
        i+=1
    elif S[i:i+2]=='BC':
        ans+=a
        i+=2
    else:
        a=0
        i+=1
    #print(a,ans)
print(ans)


Measured memory_bytes: 40304
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int n,temp,max=0,i,j;
    char s[1000];
    int f[50]={0},q[50]={0};
    scanf("%d",&n);
    scanf("%s",s);
    for(i=0;i<n;i++)
    {
        f[s[i]-'a']=1;
        for(j=0;j<26;j++)
            q[j]=0;
        for(j=i+1;j<n;j++)
        {
            q[s[j]-'a']=1;
        }
        temp=0;
        for(j=0;j<26;j++)
        {
            if(f[j]==1&&q[j]==1)
            temp++;
        }
        if(temp>max)max=temp;
    }
    printf("%d\n",max);

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n; cin>>n;
  const ll INF = 1e18;
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  vector<vll> dp(n+1, vll(5, -INF));
  dp[0][0] = 0;
  int k = n%2+1;
  rep(i,n) repc(j,k) {
    chmax(dp[i+1][j+1], dp[i][j]);
    if((i+j)%2==0) chmax(dp[i+1][j], dp[i][j] + A[i]);
    else chmax(dp[i+1][j], dp[i][j]);
  }
  cout << dp[n][k] << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 18704
import java.util.Scanner;


public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //System.out.print("入力してください > ");
        //int    x = Integer.parseInt(scanner.nextLine());
        //int n = Integer.parseInt(scanner.nextLine());
        //String d = scanner.nextLine();
       
        //int n    =  Integer.parseInt(scanner.nextLine());
        String[] s1 =  scanner.nextLine().split(" ");
        int m1 = Integer.parseInt(s1[0]);
        int d1 = Integer.parseInt(s1[1]);
        
        String[] s2 =  scanner.nextLine().split(" ");
        int m2 = Integer.parseInt(s2[0]);
        int d2 = Integer.parseInt(s2[1]);
        
        
        if( m1 == m2){
            System.out.println(0);
        }
        else{
            System.out.println(1);
        }
        
        
        
        
        // Scannerクラスのインスタンスをクローズ
        scanner.close();
    }
    private static boolean kaeru(int a, int b,long x, int n){
        
        return kakaku(a, b, n) <= x;
    }
    private static int kakaku(int a, int b,int n){
        
        return a*n + b*keta(n);
    }
    private static int keta(int n){
        
        int keta = 1;
        double nn = n;
        while(nn >= 10){
            nn = nn/10.0;
            keta++;
        }
        return keta;
        
    }
}

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

int main(){
    int n; long long k;
    cin >> n >> k;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> num(41, 0);
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 41; j++){
            if ((a[i] >> j) & 1) num[j]++;
        }
    }
    vector<int> bi_k(41, 0);
    for (int i = 0; i < 41; i++){
        if ((k >> i) & 1) bi_k[i] = 1;
    }
    long long ans = 0;
    for (int i = 41; i >= 0; i--){
        if (bi_k[i] == 0) continue;
        vector<int> tmp_k = bi_k;
        tmp_k[i] = 0;
        for (int j = 0; j < i; j++) {
            if (num[j] * 2 >= n) tmp_k[j] = 0;
            else tmp_k[j] = 1;
        }
        long long tmp = 0;
        for (int j = 0; j < 41; j++){
            if (num[j] == 0 && tmp_k[j] == 0) continue;
            if (tmp_k[j] == 0) tmp += (long long)pow(2, j) * num[j];
            else tmp += (long long)pow(2, j) * (n - num[j]);
        }
        ans = max(ans, tmp);
    }
    long long tmp = 0;
    for (int j = 0; j < 41; j++){
        if (num[j] == 0 && bi_k[j] == 0) continue;
        if (bi_k[j] == 0) tmp += (long long)pow(2, j) * num[j];
        else tmp += (long long)pow(2, j) * (n - num[j]);
    }
    ans = max(ans, tmp);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define N 10000

int main(void){
  int i,n,j,k;
  int s[N],g[N];
  int lar,sma;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&s[i],&g[i]);
  }
  for(i=0;i<n;i++){
    if(s[i]<=5 && g[i]<=5){
      if(s[i]<g[i]){
        for(j=s[i];j<=g[i];j++){
          printf("%d",j);
          if(j!=g[i])
            printf(" ");
        }
        printf("\n");
      }else if(g[i]<s[i]){
        for(j=s[i];j>=g[i];j--){
          printf("%d",j);
          if(j!=g[i])
            printf(" ");
        }
        printf("\n");
      }
    }else{
      if(s[i]<g[i]){
        for(j=s[i];j<=g[i];j++){
          printf("%d",j);
          if(j!=g[i])
            printf(" ");
        }
        printf("\n");
      }
      if(s[i]>g[i]){
        for(j=s[i];;){
          printf("%d",j);
          if(j!=g[i])
            printf(" ");
          else
            break;
          j++;
          if(j==10){
            if(g[i]<=5){
              for(k=5;;k--){
                printf("%d",k);
                if(k!=g[i])
                  printf(" ");
                else
                  break;
              }
              break;
            }else{
              for(k=5;k>=0;k--){
                printf("%d ",k);
              }
              for(k=1;k<=g[i];k++){
                printf("%d",k);
                if(k!=g[i])
                  printf(" ");
              }
              break;
            }
          }
        }
        printf("\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(){

  char chr;

  int c=0;

  int a[26]={};
	
	while(scanf("%c",&chr) != EOF){

	  if(chr>='a'&&chr<='z')

	    a[chr-'a']++;

	  if(chr>='A'&&chr<='Z')

	    a[chr-'A']++;


	}

  int k;

  for(k=0;k<=25;k++){

    printf("%c : %d\n",'a'+k,a[k]);

  }

  return 0;

}

Measured memory_bytes: 540
#include <bits/stdc++.h>
#define N 500006
#define mo 1000000007
using namespace std;
long long T,q,n,m,t,orz,ans,cnt,p[21],a[21],bit[21];
void so(long long x,long long y,long long w)
{
	if(x>t){
		if(y!=0)return;
		if(w>0)ans+=w*(orz&1?10:1);
		return;
	}
	long long o=y%10,p=(10-o)%10;
	so(x+1,abs((y-p*a[x])/10),(x==1?w*(9-p):w*(10-p)));
}
int main()
{
	scanf("%lld",&n);m=n;p[0]=1;
	for(int i=1;i<=18;i++)p[i]=p[i-1]*10;
	for(long long i=2;i<=18;i++){
		n=m;t=i/2;orz=i;
		memset(a,0,sizeof a);
		for(long long j=1;j<i;j++)a[1]=a[1]*10+9;
		long long x=a[1];
		for(long long j=2;j<=t;j++)x/=100,a[j]=x;
		so(1,n,1);
	}
	printf("%lld\n",ans);
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int rem=n%10;
    if(rem==3)
    {
        cout<<"bon"<<endl;
        return 0;
    }
    else if(rem==0 || rem==1 || rem==6 || rem==8)
    {
        cout<<"pon"<<endl;
        return 0;
    }
    else
    {
        cout<<"hon"<<endl;
        return 0;
    }
}

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


int main()
{

    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    while(1)
    {
        c=c-b;
        if(c<=0)
        {
            cout<<"Yes";
            break;
        }
        a=a-d;
         if(a<=0)
        {
            cout<<"No";
            break;
        }
    }
   return 0;
}


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

typedef long long ll;

int main(){
    ll n;
    cin >> n;
    priority_queue<ll> que;
    for(int i=0;i<n;i++){
        ll a;
        cin >> a;
        que.push(a);
    }
    ll cnt = 0;
    while(que.top()+cnt >= n){
        ll a = que.top()+cnt;
        que.pop();
        ll x = (a-n)/n + 1;
        a -= (n+1)*x+cnt;
        que.push(a);
        cnt += x;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256