akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll K,A,B;
  cin >> K >> A >> B;
  if(K<=A)
  {
    cout << K + 1 << endl;
  }
  else
  {
    if(A+2>=B)
    {
      cout << K + 1 << endl;
    }
    else
    {
      ll M = K-A-1;
      if(M%2==0)
      {
        cout << B + M/2 * (B-A) << endl;
      }
      else
      {
        cout << B + (M-1)/2 * (B-A) + 1 << endl;
      }
      
    }
    
  }
  return 0;
}


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

int main() {
  int N,K;
  cin >> N >>K;
  int S = 1;
  
  for (int i=0; i<N; i ++) {
  	if (2 * S < S + K){
    	S *= 2;
    }
    else {
    	S += K;
    }
  }
 
  cout << S;
}

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


#define int long long 


const int N = 3e5 + 7, inf = 6e5 + 7;

int t[N << 2], lzy[N << 2], up[N << 2];


void pushDown(int v, int l, int r) {
	int mid = (l + r) >> 1;
	if(up[v]) {
		t[v] = up[v];
		lzy[v * 2] = lzy[v * 2 + 1] = 0;
		up[v * 2] = up[v];
		up[v * 2 + 1] = up[v] + (mid - l + 1);
		up[v] = 0;
	}
	if(lzy[v]) {
		t[v] += lzy[v];
		lzy[v * 2] += lzy[v];
		lzy[v * 2 + 1] += lzy[v];
		lzy[v] = 0;
	}
}

void update(int v, int l, int r, int L, int R) {
	pushDown(v, l, r);
	if(l > R || r < L) return;
	if(l >= L && r <= R) {
		lzy[v]++;
		pushDown(v, l, r);
		return;
	}
	int mid = (l + r) >> 1;
	update(v * 2, l, mid, L, R);
	update(v * 2 + 1, mid + 1, r, L, R);
	t[v] = min(t[v * 2], t[v * 2 + 1]);
}


void modify(int v, int l, int r, int L, int R, int x) {

	pushDown(v, l, r);
	if(l > R || r < L) return;
	if(l >= L && r <= R) {
		lzy[v] = 0;
		up[v] = x + (l - L);
		pushDown(v, l, r);
		return;
	}
	int mid = (l + r) >> 1;
	modify(v * 2, l, mid, L, R, x);
	modify(v * 2 + 1, mid + 1, r, L, R, x);
	t[v] = min(t[v * 2], t[v * 2 + 1]);
}


int query(int v, int l, int r, int L, int R) {
	pushDown(v, l, r);
	if(l > R || r < L) return inf;
	if(l >= L && r <= R) return t[v];
	int mid = (l + r) >> 1;
	int z =  min(query(v * 2, l, mid, L, R), query(v * 2 + 1, mid + 1, r, L, R));
	t[v] = min(t[v * 2], t[v * 2 + 1]);
	return z;
}

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		int l, r; cin >> l >> r;
		if(l > 1) update(1, 1, m, 1, l - 1);
		if(r < m) update(1, 1, m, r + 1, m);
		int x = inf;
		if(l > 1) x = min(query(1, 1, m, l - 1, l - 1) + 1, x);
		modify(1, 1, m, l, r, x);
		int ans = t[1];
		if(ans > n + m) ans = -1;
		cout << ans << endl;
	}

	
	
}


Measured memory_bytes: 24040
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
	using namespace std;
const int N=100010;
char s[N];
char a[N];
int n;
bool work(){
	for (int i=2;i<n;i++) {
		if (a[i-1]=='W') {
			if (s[i-1]=='o')
				if (a[i-2]=='W') 
				a[i]='S';
				else a[i]='W';
			if (s[i-1]=='x') 
				if (a[i-2]=='S')
					a[i]='S';
				else a[i]='W';
		}
		if (a[i-1]=='S') {
			if (s[i-1]=='o')
				if (a[i-2]=='S') 
				a[i]='S';
				else a[i]='W';
			if (s[i-1]=='x') 
				if (a[i-2]=='W')
					a[i]='S';
				else a[i]='W';
		}
	}
//	cout<<a<<endl;
	for (int i=0;i<n;i++) {
		int pre=(i+n-1)%n,nxt=(i+1)%n;
		if (a[i]=='S') {
			if (s[i]=='o')
				if (a[nxt]!=a[pre]) return 0;
			if (s[i]=='x')
				if (a[nxt]==a[pre]) return 0;
				}
		if (a[i]=='W'){
			if (s[i]=='x')
				if (a[nxt]!=a[pre]) return 0;
			if (s[i]=='o')
				if (a[nxt]==a[pre]) return 0;
		}
	}
	return 1;
}
bool fd=0;
void pd(){
	if (!fd && work()) {
		cout<<a<<endl;
		fd=1;
	}
}
int main(){
	scanf("%d",&n);
	cin>>s;
	a[0]='W'; a[1]='S'; pd();
	a[0]='W'; a[1]='W'; pd();
	a[0]='S'; a[1]='S'; pd();
	a[0]='S'; a[1]='W'; pd();
	if (!fd) cout<<-1<<endl;
}

Measured memory_bytes: 512
#include<iostream>

int main(){

    while(true){
        int a, b;
        char op;
        std::cin >> a >> op >> b;
        if(op == '+'){
            std::cout << a + b << std::endl;
        }
        else if(op == '-'){
            std::cout << a - b << std::endl;
        }
        else if(op == '*'){
            std::cout << a * b << std::endl;
        }
        else if(op == '/'){
            std::cout << a / b << std::endl;
        }
        else{
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3100
#include <cstdio> 
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int maxn = 5e5 + 10;

char a[maxn];

int c[maxn][26];

int t,op,pos,l,r,len;
char v;

int lowbit(int x) {
	return x & -x;
}

void insert(int id,int x,int v) {
	for(int i = id; i <= len; i += lowbit(i)) {
		c[i][x] += v;
	}
	return ;
}

int query(int id,int x) {
	int ans = 0;
	for(int i = id; i; i -= lowbit(i)) {
		ans += c[i][x];
	}
	return ans;
}

int main(void) {
	cin >> len;
	scanf("%s",a + 1);
	for(int i = 1; i <= len; i ++) {
		int v = a[i] - 'a';
		insert(i,v,1);
	}
	cin >> t;
	while(t --) {
		cin >> op; 
		if(op == 1) {
			cin >> pos >> v;
//			cout << v << endl;
			insert(pos,a[pos] - 'a',-1);
			insert(pos,v - 'a',1);
			a[pos] = v;
		} else {
			cin >> l >> r;
			int res = 0;
			for(int i = 0; i < 26; i ++) {
				if(query(r,i) - query(l - 1,i)) res ++;
			}
			cout << res << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 51584
#include <iostream>

using namespace std;

int main(){
    int input;
    cin >> input;
    int reversed = input / 100 + (input % 10) * 100 + (input / 10) % 10 * 10;
    if(input == reversed){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int a,b;
  	cin>>a>>b;
  	cout<<(a-1)*(b-1)<<endl;
	return 0;
}


Measured memory_bytes: 256
//Solution By SlavicG
#include <bits/stdc++.h>
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int  main()
{
	int n;
	cin >> n;
	int a[n];
	int dp[n+2];
	forn(i,n)cin >> a[i];
	forn(i,n + 2)dp[i] = INT_MAX;
	dp[0] = 0;
	for(int i = 0;i<n;i++)
	{
		dp[i+1] = min(dp[i+1], dp[i] + abs(a[i] - a[i+1]));
		dp[i+2] = min(dp[i+2], dp[i] + abs(a[i] - a[i+2]));
	}
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
// C - Stones

using namespace std;

int w[200005],b[200005];

int main() {
    int N,i,cnt,ans;
    string S;

    cin >> N;
    cin >> S;

    cnt = 0;
    for (i = 0;i < N;i++) {
        if (S[i] == '#')
            cnt++;
        b[i] = cnt;
    }

    cnt = 0;
    for (i = N - 1;i >= 0;i--) {
        if (S[i] == '.')
            cnt++;
        w[i] = cnt;
    }

    ans = w[0];
    for (i = 0;i < N;i++)
        ans = min(ans,b[i] + w[i + 1]);
    
    printf("%d\n",ans);
}


Measured memory_bytes: 2180
N=int(input())
T=input()
t=[]
tmp=0
sign="R"
for i in range(len(T)):
    if sign=="R":
        if T[i]=="R":
            tmp+=1
        else:
            if t and t[-1]!="S":
                t[-1]+=tmp
                sign="S"
                tmp=1
            else:
                t.append(tmp)
                tmp=1
                sign="S"
    else:
        if T[i]=="S":
            tmp+=1
        else:
            if tmp%2==1:
                t.append("S")
            tmp=1
            sign="R"

if sign=="R":
    if t and t[-1]!="S":
        t[-1]+=tmp
        sign="S"
        tmp=1
    else:
        t.append(tmp)
        tmp=1
        sign="S"
else:
    if tmp%2==1:
        t.append("S")
    tmp=1
    sign="R"

def dance(n,music):
    if n==0:
        return [0]
    res=[-1]*3**n
    for i in range(3):
        nmusic=[]
        val=i
        for j in range(len(music)):
            if music[j]!="S":
                tmp=music[j]//3
                if val+(music[j]%3)>=3:
                    tmp+=1
                if nmusic and nmusic[-1]!="S":
                    nmusic[-1]+=tmp
                elif tmp:
                    nmusic.append(tmp)
                val+=music[j]
                val%=3
            else:
                if nmusic and nmusic[-1]=="S":
                    nmusic.pop()
                else:
                    nmusic.append("S")
                val=(-val)%3
        rres=dance(n-1,nmusic)
        for j in range(3**(n-1)):
            res[3*j+i]=3*rres[j]+val
    return res


res=dance(N,t)
print(*res)

Measured memory_bytes: 131152
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'


int main() {
	#ifdef shiven
	freopen("test.in", "r", stdin);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin >> n;
	vector<ll> pt(n), ptb(n);
	for_(i, 0, n) {
		ll a, b; cin >> a >> b;
		ptb[i] = a-b;
		pt[i] = a+b;
	}
	
	sort(pt.begin(), pt.end());
	sort(ptb.begin(), ptb.end());
	cout << max(pt[n-1]-pt[0], ptb[n-1] - ptb[0]) << endl;

	return 0;
}


Measured memory_bytes: 6352
import math
a, b, x = list(map(int,input().split()))
h = x / (a * b * 0.5)
if h > a:
    u = (a ** 2 * b - x) / (a ** 2 / 2)
    ans = math.degrees(math.atan2(u, a))
else:
    ans = math.degrees(math.atan2(b, h))
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define all(v) v.begin(),v.end()
using namespace std;

signed main(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    int q;
    cin>>q;
    rep(i,q){
        int k;
        cin>>k;
        cout<<(lower_bound(all(a),k)-a.begin())<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

string S,T;
int dp[3010][3010];

signed main(){
	cin>>S>>T;
	REP(i,S.size()){
		REP(j,T.size()){
			if(S[i]==T[j]){
				dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
			}
			dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1]);
			dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j]);
		}
	}
	string res="";
	int s=S.size(),t=T.size();
	while(s>0&&t>0){
		if(dp[s][t]==dp[s-1][t]){
			s--;
		}
		else if(dp[s][t]==dp[s][t-1]){
			t--;
		}
		else{
			res=S[s-1]+res;
			s--,t--;
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 70784
#include <stdio.h>

int main(void){
  int a,b,c,d,e;
  scanf("%d %d",&a,&b);
  c=a+a-1;
  d=a+b;
  e=b+b-1;
  printf("%d\n",max(c,d,e));
  return 0;
}

max(int c,int d,int e){
  if(c>=d&&c>=e) return c;
  if(d>c&&d>=e) return d;
  if(e>d&&e>c) return e;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

ll func(ll A, ll B) {
	if (B < A) return B;
	else return func(A, B / A) + B % A;
}

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

	//解説チラ見済み

	ll N, S;
	cin >> N >> S;

	ll kotae = -1;
	int rt = sqrt(N) + 1;
	rep1(i, rt) {
		if (func(i + 1, N) == S) {
			kotae = i + 1;
			break;
		}
	}
	if (kotae == -1) {
		for (int i = rt; i >= 1; i--) {
			if ((N - S + i) % i == 0 && i < (N - S + i) / i && S - i < (N - S + i) / i && S >= i) {
				kotae = (N - S + i) / i;
				break;
			}
		}
	}
	if (N == S) kotae = N + 1;
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int A,B,C,K;
	cin>>A>>B>>C>>K;
	int ans = 0;
	while (B<=A){
		B*=2;
		ans++;
	}
	while (C<=B){
		C*=2;
		ans++;
	}
	if (ans <=K) cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,n;
	cin>>x>>n;
	int a,f[200],q=0,w=0;
	memset(f,0,sizeof(f));
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		f[a]=1;
	}
	for(int i=x;i<=105;i++)
	{	//cout<<f[i]<<endl;
		if(f[i]==0)
		{
			
			q=i;//da
			break;
		}
	}
	for(int i=x;i>=0;i--)
	{
		if(f[i]==0)
		{
			w=i;//xiao
			break;
		}
	}
	
	//cout<<q<<w;
	
	if(q-x>=x-w)
	{
		cout<<w;
	}
	else
	{
		cout<<q;
	}
}

Measured memory_bytes: 3608
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

S = gets.chomp

N = S.length

if S == S.reverse && S[0...(N-1)/2] == S[0...(N-1)/2].reverse && S[((N+3)/2-1)..] == S[((N+3)/2-1)..].reverse
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 14332
#include<string>
using namespace std;
#include <stdio.h>
#include <limits.h>
#include "bits/stdc++.h"
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
int a, b, c, ans1, k;
int main()
{
	cin >> a >> b >> c >> k;
	if (a >= b&&a >= c) {
		ans1 = a*pow(2, k) + b + c;
	}
	else if (b > a&&b >= c) {
		ans1 = b*pow(2, k) + a + c;
	}
	else
	{
		ans1 = c*pow(2, k) + a + b;
	}
	cout << ans1;
	return 0;

}


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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
  st s;
  ci(s);
  ll a=s[0]+s[1]+s[2];
  ll b='a'+'b'+'c';
  if(a==b){
    co("Yes")
  }
  else{
    co("No")
  }
  
}

Measured memory_bytes: 256
#include<iostream>
int main()
{
    int a[5]={'\0'};
    int n = -25;
    int flg = -1111;
    for(int i=0;i<5;i++){
        std::cin>>a[i];
        if(a[i]==0 && i!=0){
            n= a[i-1]+1;
        }else if(a[i]==0 && i==0){
            flg = i;
        }
        
    }
    if(n == -25){
        n= a[flg+1]-1;
    }
    std::cout<<n<<std::endl;

    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
double solve(int a1,int a2,int a3,int n,double dp[][301][301]){
  if(a1==0&&a2==0&&a3==0)
    return 0.0;
  if(dp[a1][a2][a3]>=-1.0)
    return dp[a1][a2][a3];
  double so=0.0;
  if(a1>0)
    so+=(a1*1.0/n)*solve(a1-1,a2,a3,n,dp);
  if(a2>0)
    so+=(a2*1.0/n)*solve(a1+1,a2-1,a3,n,dp);
  if(a3>0)
    so+=(a3*1.0/n)*solve(a1,a2+1,a3-1,n,dp);
  so+=1.0;
  so*=(n*1.0)/(a1+a2+a3);
  dp[a1][a2][a3]=so;
  return so;
}
  
  int main(){
  ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
  int n;
  cin>>n;
  int x;
  int a1=0,a2=0,a3=0;
  for(int i=0;i<n;i++){
    cin>>x;
    if(x==1)
      a1++;
    else if(x==2)
      a2++;
    else
      a3++;
  }
    double dp[301][301][301];
    
    memset(dp,-10.0,sizeof(dp));
  cout<<fixed<<setprecision(8)<<solve(a1,a2,a3,n,dp)<<endl;
  return 0;
}

Measured memory_bytes: 213504
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(b-a==c-b)System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 23508
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        List<String> u = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            u.add(sc.next());
        }
        int m = sc.nextInt();
        List<String> t = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            t.add(sc.next());
        }

        boolean lock = false;
        for (int i = 0; i < m; i++) {
            String str = t.get(i);
            if (!u.contains(str)) {
                System.out.printf("Unknown %s%n", str);
                continue;
            }
            if (!lock) {
                System.out.printf("Opened by %s%n", str);
            } else {
                System.out.printf("Closed by %s%n", str);
            }
            lock = !lock;

        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}



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

int main(){
  int n;
  int d[110];
  cin>>n;
  for(int i=0; i<n; ++i)cin>>d[i];
  
  int num[110] = {0};
    for (int i = 0; i < n; ++i) {
        num[d[i]]++; 
    }
  
  int res=0;
  for(int i=1;i<=100; i++){
    if(num[i]){
      ++res;
    }
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */


/* Name of the class has to be "Main" only if the class is public. */
 public class Main
{
    
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner s=new Scanner(System.in);
        int t=s.nextInt();
      System.out.println(t*t);
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n; cin>>n;
    vector<int> d1(n);
    vector<int> d2(n);
    rep(i,n)cin>>d1[i]>>d2[i];

    int count =0;
    int nowcount =0;
    rep(i,n){
        if(d1[i]==d2[i]){
            nowcount++;
        }
        else nowcount=0;
        count =max(count,nowcount);
    }
    if(count>=3){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int n;
vector<ll> x, y;
vector<vector<int>> tree;
constexpr int INF = 1e9 + 6;

bool dfs(int v, int p = -1) {
    for (int u : tree[v]) {
        if (u == p) continue;
        if (!dfs(u, v)) return false;
    }
    // dp[k] : k以下で最小
    vector<vector<ll>> dp(tree[v].size() + 1, vector<ll>(x[v] + 1, INF));
    dp[0][0] = 0;
    ll res = INF;
    for (int i = 0; i < tree[v].size(); i++) {
        if (tree[v][i] == p) {
            dp[i + 1] = dp[i];
        }
        else {
            int u = tree[v][i];
            for (int j = 0; j <= x[v]; j++) {
                if (j - x[u] >= 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - x[u]] + y[u]);
                if (j - y[u] >= 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - y[u]] + x[u]);
            }
        }
    }
    for (int i = 0; i <= x[v]; i++) {
        res = min(res, dp[tree[v].size()][i]);
    }
    /*for (int i = 0; i <= tree[v].size(); i++) {
        for (int j = 0; j <= x[v]; j++) {
            if (dp[i][j] == INF) cout << "- ";
            else cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;*/
    if (res == INF) return false;
    y[v] = res;
    return true;
}

int main() {
    cin >> n;
    tree.resize(n);
    for (int i = 1; i < n; i++) {
        int a; cin >> a;
        tree[i].push_back(a - 1);
        tree[a - 1].push_back(i);
    }
    x.resize(n);
    y.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    if (!dfs(0)) puts("IMPOSSIBLE");
    else puts("POSSIBLE");
    /*for (int i = 0; i < n; i++) {
        cout << x[i] << " " << y[i] << endl;
    }*/
    return 0;
}

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

int k, m, n, h, w;
ll t[1 << 17], d[1 << 17];

int main()
{
    while (cin >> n >> k)
    {
        if (n == 0 && k == 0)
            return 0;
        ll ans = 0, a[n], sum = 0;
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            if (i < k)
                sum += a[i];
        }
        ans = sum;
        for (int i = k; i < n; i++)
        {
            sum -= a[i - k];
            sum += a[i];
            ans = max(ans, sum);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=55;
vector<ll> adj[N];
ll mask[N],par[N],dp[1ll<<20][N];
set<ll> st[25];
void dfs(ll src,ll pr){
    par[src]=pr;
    for(auto &v:adj[src])if(v!=pr)dfs(v,src);
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    for(ll i=0,u,v;i<n-1;i++)cin>>u>>v,adj[u].push_back(v),adj[v].push_back(u);
    dfs(1,0);
    ll m;cin>>m;
    for(ll i=0;i<m;i++){
        ll a,b;cin>>a>>b;
        while(a!=1)st[i].insert(a),a=par[a];
        while(b!=1){
            if(st[i].count(b))st[i].erase(b);
            else st[i].insert(b);
            b=par[b];
        }
    }

    for(ll i=0;i<(1ll<<m);i++)for(ll j=0;j<=n+1;j++)dp[i][j]=0;
    dp[0][1]=1;
    for(ll i=0;i<=n;i++)for(ll l=0;l<m;l++)if(st[l].count(i))mask[i]=(mask[i]|(1ll<<l));

    for(ll i=0;i<(1ll<<m);i++){
        for(ll j=2;j<=n;j++){
            dp[i][j]+=dp[i][j-1];
            ll k=i|mask[j];
            dp[k][j]+=dp[i][j-1];
        }
    }

    cout<< dp[(1ll<<m)-1][n];
}



Measured memory_bytes: 450816
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

#define MXN 105
int N;
int A[MXN], B[MXN];
int S;

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

    cin>>N;
    FOR(i,1,N-1)cin>>B[i];
    S+=B[1]+B[N-1];
    FOR(i,2,N-1)
    {
        S+=min(B[i-1],B[i]);
    }
    cout<<S<<'\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

void solve() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll x = min(a, k), y = 0, z = 0;
    k -= x;
    if (k > 0) y = min(b, k);
    k -= y;
    if (k > 0) z = min(c, k);
    cout << x - z;


}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1; 
    //cin >> T;
    while(T--) solve();
}

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

long long n, a, b;

int main(){
	scanf("%lld %lld %lld", &n, &a, &b);
	if(a % 2 == b % 2){
		printf("%lld\n", (b - a) / 2);
	}else{
		printf("%lld\n", min((a - 1), (n - b)) + 1 +  + (b - a - 1) / 2);
	}
	return 0;
}

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

int main(){
    int N;
    cin>>N;
    vector<double> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    sort(A.begin(),A.end());
    ll ans=1;
    for(int i=0;i<N-1;i++){
        if(A[i+1]<=A[i]*2){
            ans++;
        }
        else ans=1;
        A[i+1]+=A[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
A,B,C,D,E,F=map(int,input().split())


noudo=0

satomizu=0
sato=0
Flug=False

NA1=F/(A*100)
NA=int(NA1)
NB1=F/(B*100)
NB=int(NB1)
NC1=F/C
NC=int(NC1)
ND1=F/D
ND=int(ND1)
if B%A ==0:
    NB=1
if D%C ==0:
    ND=1

jyogen=E/(100+E)
for a in range(1,NA+2):
    for b in range(NB+1):
        for c in range(NC+1):
            for d in range(ND+1):
                if  noudo<=(c*C+d*D)/(100*a*A +100*b*B+c*C+d*D) and (c*C+d*D)/(100*a*A +100*b*B+c*C+d*D)<=jyogen and (100*a*A +100*b*B+c*C+d*D)<=F:
                    noudo=(c*C+d*D)/(100*a*A +100*b*B+c*C+d*D)
                    satomizu=100*a*A +100*b*B+c*C+d*D
                    sato=c*C+d*D
                    if sato/satomizu == jyogen:
                        Flug=True
                        break
    if Flug==True:
            break
print(str(satomizu)+" "+str(sato))

Measured memory_bytes: 3064
XYDs = readlines.drop(1).map{|l| x, y, d = l.split; [x.to_i, y.to_i, d]}

f = ->(e){XYDs.select{|x, y, d| d == e}.map{|a| a[0, 2]}.transpose}
(@rx, @ry), (@lx, @ly), (@ux, @uy), (@dx, @dy) = ['R', 'L', 'U', 'D'].map{|d| f[d].empty? ? [[], []] : f[d]}

def g(t)
  dx = (@ux + @dx + @rx.map{|x| x + t} + @lx.map{|x| x - t}).minmax.inject(:-).abs
  dy = (@ry + @ly + @uy.map{|y| y + t} + @dy.map{|y| y - t}).minmax.inject(:-).abs
  dx * dy
end

xys = XYDs.group_by{|x, y, d| d}.values
vs = ->(i){xys.flat_map{|a| a.map{|b| b[i]}.minmax}.combination(2).flat_map{|a, b| d = (a - b).abs; [d, d/2.0]}}
puts ([0] + vs[0] + vs[1]).uniq.map{|t| g(t)}.min

Measured memory_bytes: 96784
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define pb  push_back
#define mp make_pair
#define ll long long
#define pr pair<int, int> 
#define vpr vector<pr> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define all(n) n.begin(),n.end()
#define Test printf("Case %d: ",tc++);
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
const int mod = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 1e6 + 5;

int solve() 
{
	//happy coding

	string s;
	cin>>s;
	char  c = '7';
	bool g = false;
	for(int i=0;i<s.size();i++){
		if(s[i]=='7') g = true;
	}
	if(g){
		Yes
	}else{
		No;
	}

	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, l, r, m, i;
    vector <int> v;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        int x;
        
        scanf("%d", &x);
        
        v.push_back(x);
    }
    
    sort(v.begin(), v.end());
    
    l = -1, r = n - 1, m = (l + r) / 2;
    
    while (r - l > 1) {
        long long sum = 0;
        
        for (i = 0; i <= m; i++) sum += v[i];
        
        for (i = m + 1; i < n; i++) {
            if (sum * 2 < v[i]) break;
            
            sum += v[i];
        }
        
        if (i < n) {
            l = m;
            m = (l + r) / 2;
        } else {
            r = m;
            m = (l + r) / 2;
        }
    }
    
    printf("%d\n", n - r);
    
    return 0;
}


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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

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

const int MOD = (int) 1e9 + 7;

const int MAXN = (int) 2e5;

int n;

int c[MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= n; ++i) c[i] = read<int>();
}

inline void solve()
{
	n = unique(c + 1, c + n + 1) - c - 1;

	static int f[MAXN + 5], sum[MAXN + 5];

	f[0] = 1;
	for(int i = 0; i <= n; ++i)
	{
		(f[i] += sum[c[i]]) %= MOD;
		if(i < n) (sum[c[i + 1]] += f[i]) %= MOD;
	}

	printf("%d\n", (f[n] + MOD) % MOD);
}

int main()
{
#ifndef ONLINE_JUDGE
//	freopen("B.in", "r", stdin);
//	freopen("B.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 2560
use maplit::hashmap;
use num::{rational::Ratio, One, Signed as _};
use proconio::input;
use std::{
    fmt,
    iter::{Product, Sum},
    ops::{Add, Div, Mul, Sub},
};

fn main() {
    input! {
        n: usize,
        abs: [(i64, i64); n],
    }

    let mut zeros = 0;
    let mut horz = 0;
    let mut vert = 0;
    let mut others = hashmap!();

    for (a, b) in abs {
        match (a.signum(), b.signum()) {
            (0, 0) => zeros += 1,
            (1, 0) | (-1, 0) => horz += 1,
            (0, 1) | (0, -1) => vert += 1,
            _ => *others.entry(Ratio::new(a, b)).or_insert(0) += 1usize,
        }
    }

    let ans = others
        .iter()
        .map(|(grad, &num1)| {
            let num2 = *others.get(&-grad.recip()).unwrap_or(&0);
            if grad.is_positive() && num2 > 0 {
                ModInt::unchecked(1)
            } else {
                f(num1, num2)
            }
        })
        .product::<ModInt>()
        * f(horz, vert)
        + ModInt::unchecked(zeros)
        - ModInt::unchecked(1);
    println!("{}", ans);
}

fn f(a: usize, b: usize) -> ModInt {
    pow2(a) + pow2(b) - ModInt::unchecked(1)
}

fn pow2(exp: usize) -> ModInt {
    num::pow(ModInt::unchecked(2), exp)
}

const P: usize = 1_000_000_007;

#[derive(Clone, Copy, Debug)]
struct ModInt {
    repr: usize,
}

impl ModInt {
    fn new(val: usize) -> Self {
        Self { repr: val % P }
    }

    fn unchecked(repr: usize) -> Self {
        Self { repr }
    }
}

impl One for ModInt {
    fn one() -> Self {
        Self::unchecked(1)
    }
}

impl fmt::Display for ModInt {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt::Display::fmt(&self.repr, fmt)
    }
}

impl Add for ModInt {
    type Output = Self;

    fn add(self, rhs: Self) -> Self {
        Self::new(self.repr + rhs.repr)
    }
}

impl Sub for ModInt {
    type Output = Self;

    fn sub(self, rhs: Self) -> Self {
        Self::new(P + self.repr - rhs.repr)
    }
}

impl Mul for ModInt {
    type Output = Self;

    fn mul(self, rhs: Self) -> Self {
        Self::new(self.repr * rhs.repr)
    }
}

impl Div for ModInt {
    type Output = Self;

    fn div(self, rhs: Self) -> Self {
        self * num::pow(rhs, P - 2)
    }
}

impl Sum for ModInt {
    fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
        iter.fold(Self::unchecked(0), Add::add)
    }
}

impl Product for ModInt {
    fn product<I: Iterator<Item = Self>>(iter: I) -> Self {
        iter.fold(Self::unchecked(1), Mul::mul)
    }
}


Measured memory_bytes: 22472
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String a = sc.next();//文字取得ラーメンの具材
		String b[] = a.split("");//具材の有無を入れる配列
		int total = 700;
		
		for(int c = 0;c < 3;c++){
			if(b[c].equals("o")){
				total = total + 100;
			}
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
signed main(){
	int a,b;
	cin>>a>>b;
	b/=1000;
	b-=a;
	for(int i=0;i*9<=b&&i<=a;i++){
		for(int j=0;j*4+i*9<=b&&i+j<=a ;j++){
			if(j*4+i*9==b){
				cout<<i<<" "<<j<<" "<<a-i-j<<endl;
				return 0;
			}
		}
	}
	puts("-1 -1 -1");
	return 0;
}


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

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int r, g; cin >> r >> g;
    cout << g * 2  - r << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n ;
  cout<<(n+1)/2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 2010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    string s;
    cin >> n >> s;
    bool out = 0;
    vector<ll> a(2*n,0),index;
    ll cnt = 0;
    if (s[0] == 'W' || s[2*n-1] == 'W'){
        out = 1;
    }
    a[0]++;
    rep(i,1,2*n-1){
        if (s[i] == s[i-1]){
            a[i] = 1-a[i-1];
        }
        else{
            a[i] = a[i-1];
        }
    }
    rep(i,2*n){
        if (a[i] == 0){
            index.push_back(i);
            cnt++;
        }
    }
    //PRINT(cnt);
    if (cnt != n) out = 1;
    if (out){
        PRINT(0);
        return 0;
    }
    rep(i,2*n-1) a[i+1] += a[i];
    ll ans = 1;
    index.push_back(2*n-1);
    rep(i,n){
        ans *= a[index[i]]-i;
        ans %= MOD;
    }
    rep(i,1,n+1){
        (ans *= i)%=MOD;
    }
    PRINT(ans);
}


Measured memory_bytes: 3216
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,ans=1e9;

int f(int x){
	int res=0;
	while(x){
		res+=x%10;x/=10;
	}
	return res;
}

int main(){
	scanf("%d",&n);
	for(int i=n/2;i;--i){
		ans=min(ans,f(i)+f(n-i));
	}
	printf("%d\n",ans);
	return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int n,m; cin>>n>>m;
  if (n==m) out("Yes");
  out("No");
  

  return 0;
}


Measured memory_bytes: 256
data = input().split('/')
year = int(data[0])
month = int(data[1])
day = int(data[2])

result = 'TBD'
if year < 2019:
  result = 'Heisei'
elif year == 2019:
  if month <= 4:
    result = 'Heisei'

print(result)

Measured memory_bytes: 3060
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
c.sort()
ans = 0
for x in b:
  ans += bisect.bisect_left(a,x)*(n-bisect.bisect_right(c,x))
print(ans)

Measured memory_bytes: 23360
#090B
a,b=map(int,input().split())

ans=0

for i in range(a,b+1):
	l=[]
	r_l=[]
	temp=0#onaji
	while(i!=0):
		l.append(i%10)
		#print(l)
		i=int(i/10)
	old_l=l
	old_l=tuple(old_l)
#	print(old_l)
	l.reverse()
#	print(old_l)
	l=tuple(l)
#	print(l)
	for i in range(len(l)):
		if(l[i]!=old_l[i]):
			temp=1
			break

	if(temp==0):
		ans+=1

print(ans)






Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int A,B,C,D,E,F;
int w,s;
int ans,anss;
double maxn=-1;
int main() {
	scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
	A*=100;B*=100;
	for(int a=0;a<=F/A;a++)
		for(int b=0;b<=(F-a*A)/B;b++)
			for(int c=0;c<=(F-a*A-b*B)/C;c++)
				for(int d=0;d<=(F-a*A-b*B-c*C)/D;d++) {
					w=a*A+b*B;s=c*C+d*D;
					if(s<=w/100*E&&w+s<=F) 
						if(1.0*s/(w+s)>maxn)
							maxn=1.0*s/(w+s),ans=w+s,anss=s;
				}
	printf("%d %d\n",ans,anss);			
	return 0;
}

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

int main()
{
  int N,sum,ii,sumN;
  while(1){
    cin>>N;
    if(N==0)break;
    sum=0;
    ii=0;
    sumN=0;
    for(int i=1;i<N;++i){
      sumN+=i;
      ii+=1;
      if(sumN==N){
        sum++;
        sumN=0;
        i-=ii-1;
	ii=0;
      }
      if(sumN>N){
        sumN=0;
        i-=ii-1;
        ii=0;
      }
    }
    cout<< sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N = int(input())
A = list(map(int, input().split()))

left = [0] * (N+1)
right = [0] * (N+1)

left[0] = A[0]
for i in range(N-1):
    left[i+1] = left[i] ^ A[i+1]

right[N] = A[-1]
for i in range(N-1,0,-1):
    right[i] = right[i+1] ^ A[i-1]

ans = []
for i in range(N):
    if i-1 >= 0:
        l = left[i-1]
    else:
        l = 0
    if i+1 < N:
        r = right[i+2]
    else:
        r = 0
    ans.append(l^r)
print(*ans, sep=" ")


Measured memory_bytes: 113384
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,v[5],mi=10000000000000000,ans;
  cin >> n;
  for(int i=0;i<5;i++){
    cin >> v[i];
    mi = min(v[i],mi);
  }
  ans = (n+mi-1)/mi + 4;
  cout << ans << endl;
}


Measured memory_bytes: 256
let cnt = ref 0

let insertion_sort (a : int array) n g =
  for i = g to n - 1 do
    let v = a.(i) in
    let j = ref (i - g) in
    while !j >= 0 && a.(!j) > v do
      a.(!j+g) <- a.(!j);
      j := !j - g;
      incr cnt;
    done;
    a.(!j+g) <- v;
  done

let generate_g n =
  let g = ref [] in
  let new_g = ref 1 in
  let i = ref 1 in
  while !new_g <= n do
    g := !new_g :: !g;
    new_g := int_of_float (4.**(float_of_int !i) +. 3.*.2.**(float_of_int (!i - 1)) +. 1.);
    incr i;
  done;
  !g

let shell_sort (a : int array) n =
  cnt := 0;
  let g = generate_g n in
  List.iter (fun g -> insertion_sort a n g) g;
  g

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> read_int ()) in
  let g = shell_sort a n in
  Printf.printf "%d\n" (List.length g);
  List.iteri (fun i n -> if i <> 0 then print_string " "; print_int n) g;
  print_newline ();
  Printf.printf "%d\n" !cnt;
  Array.iter (fun n -> Printf.printf "%d\n" n) a

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

int bbq_easy(vector<int> v)
{
	int count = 0, size = v.size();
	sort(v.begin(), v.end());

	for (int i = 0; i < size && i+1 < size; i+=2) {
		count += min(v[i], v[i+1]);
	}
	return count ;
}

int main(){
	int n, x ;
	vector<int> v;
	cin >> n ;
	for (int i = 0; i < 2*n; ++i) {
		cin >> x ;
		v.push_back(x);
	}

	cout << bbq_easy(v);
	return 0;
}


Measured memory_bytes: 256