akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

struct PrimeFactorization {
    vector<pair<ll, int>> factors;
    void factor(ll n) {
        int sqrt_n = (int)(sqrtl(n) + 1e-6L);
        primes.resize(0);
        isPrime.assign(sqrt_n + 1, true);
        for (int k = 2; k <= sqrt_n; ++k) {
            if (!isPrime[k]) continue;
            primes.push_back(k);
            for (int l = k * 2; l <= sqrt_n; l += k) isPrime[l] = false;
        }
        factors.resize(0);
        for (int i = 0; i < (int)primes.size() && n > 1;) {
            if (n % primes[i] == 0) {
                n /= primes[i];
                if (!factors.empty() && factors.back().first == primes[i]) factors.back().second++;
                else factors.emplace_back(primes[i], 1);
            }
            else i++;
        }
        if (n > 1) factors.emplace_back(n, 1);
    }
    pair<ll, int> operator [](int i) const { return factors[i]; }
    int size() const { return factors.size(); }
private:
    vector<int> primes;
    vector<bool> isPrime;
};

ll mpow(ll x, ll n) { ll y = 1; for (; n; n /= 2) { y = n % 2 ? y * x % MOD : y; x = x * x % MOD; } return y; }

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    PrimeFactorization pf;
    map<int, int> pfcnt;

    rep(i, N) {
        pf.factor(A[i]);
        rep(j, pf.size()) {
            pfcnt[pf[j].first] = max(pfcnt[pf[j].first], pf[j].second);
        }
    }

    ll GCD = 1;
    for (auto&& pc : pfcnt) {
        rep(i, pc.second) GCD = GCD * pc.first % MOD;
    }

    ll ans = 0;
    rep(i, N) {
        ans = (ans + GCD * mpow(A[i], MOD - 2)) % MOD;
    }
    write(ans);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=1e18,MOD=1e8+7,MAX=1e3+5;


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS
    ll a[4];
    lp(i,0,4)
        cin>>a[i];
    ll res=-1e18;
    lp(i,0,2){
        lp(j,2,4){
            res=max(res,a[i]*a[j]);
        }
    }
    cout<<res;
}

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

int main() {
 int N, A;
  cin >> N >> A;
    
  int amari = N % 500;
  int answer =  A - amari;

  if(answer >= 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int w, h, n, x[110], y[110], a[110];
    cin >> w >> h >> n;

    int left_x = 0, right_x = w, up_y = h, down_y = 0;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> a[i];
        switch(a[i]) {
            case (1):
            if (left_x < x[i]) left_x = x[i]; break;
            case (2):
            if (right_x > x[i]) right_x = x[i]; break;
            case (3):
            if (down_y < y[i]) down_y = y[i]; break;
            case (4):
            if (up_y > y[i]) up_y = y[i]; break;
        }
    }
    if (right_x - left_x > 0 && up_y - down_y > 0) {
        cout << (right_x - left_x) * (up_y - down_y) << endl;
    } else {
        cout << 0 << endl;
    }
	return 0;
}

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

int main() {
	int res=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int a;
		cin>>a;
		if(a%2==1&&i%2==1)res++;
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define EPS 1e-5

#define MAKEROT(x,y,c,s) {double r = sqrt(x*x+y*y); c = x/r; s = y/r;}
#define ROT(x,y,c,s) {double u = c*x+s*y; double v = -s*x+c*y; x = u; y = v;}
vector<double> givens(vector<vector<double> > A, vector<double> b) {
	int n = b.size();
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			double c, s;
			MAKEROT(A[i][i], A[j][i], c, s);
			ROT(b[i], b[j], c, s);
			for (int k = i; k < n; k++)
				ROT(A[i][k], A[j][k], c, s);
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = i + 1; j < n; j++)
			b[i] = b[i] - A[i][j] * b[j];
		b[i] = b[i] / A[i][i];
	}
	return b;
}

int D;
vector<double> V;

int solve()
{
	V.resize(D + 3);
	rep(i, 0, D + 3) cin >> V[i];

	rep(i, 0, D + 3) rep(j, i + 1, D + 3)
	{
		vector<vector<double> > A(D + 1, vector<double>(D + 1, 0));
		vector<double> B(D + 1, 0);

		int idx = 0;
		rep(ii, 0, D + 3)
		{
			if (ii == i) continue;
			if (ii == j) continue;
			int a = 1;
			rep(jj, 0, D + 1) A[idx][jj] = a, a *= ii;
			B[idx] = V[ii];
			idx++;
		}

		vector<double> C = givens(A, B);
		int ans = -1;
		rep(ii, 0, D + 3)
		{
			double ret = 0;
			int a = 1;
			rep(jj, 0, D + 1) ret += (double)a * C[jj], a *= ii;
			if (!(abs(ret - V[ii]) < EPS))
			{
				if(ans < 0) ans = ii;
				else ans = 100;
			}
		}
		if (ans < 0) continue;
		if (ans == 100) continue;

		return ans;
	}

	return -1;
}

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

	while (cin >> D)
	{
		if (D == 0) return 0;

		cout << solve() << endl;
	}
}

Measured memory_bytes: 3220
S = input()

flg = True

for i in range(len(S)):
  if i%2 == 0 and S[i] == 'L':
    flg = False
    break
  if i%2 == 1 and S[i] == 'R':
    flg = False
    break
    
print('Yes' if flg else 'No')
    



Measured memory_bytes: 2940
#include <stdio.h>

int main(void)
{
    int A, B;
    int sum, diff, prod;
    scanf("%d%d", &A, &B);

    sum = A + B;
    diff = A - B;
    prod = A * B;

    printf("%d\n", prod>(sum>diff ? sum:diff) ? prod:(sum>diff ? sum:diff) );


    return 0;
}


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

int main()
{
  int a;
  string s;
  cin >> a >> s;
  if (a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int x;

int main(){
	cin>>x;
	int t=x%100;
	int s=x/100;
	if((t+4)/5<=s){
		cout<<1<<endl;
	}else{
		cout<<0<<endl;
	}
	return 0;
}

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


#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
using namespace std;


void solve() {
    int n;
    double d;
    cin >> n >> d;
    int cnt=0;
    for (int i=0; i<n; i++) {
        ll x, y;
        cin >> x >> y;
        double distance=sqrt(x*x+y*y);
        if (distance<=d) cnt++;
    }
    
    cout << cnt << endl;
}

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


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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; }

const ll MRINF = 5000000000000000;

int main() {

  string S, T; cin >> S >> T;
  ll ans = 0;
  REP(i, S.length()){
    if(S[i]!=T[i])ans++;
  }
  cout << ans << endl;

  
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll res=0;
    ll l=0,r=0,Xor=0,sum=0;
    for(;r<n;r++){
        Xor^=a[r];
        sum+=a[r];
        for(;Xor!=sum;l++){
            Xor^=a[l];
            sum-=a[l];
        }
        res+=r-l+1;
        //cout<<r-l+1<<endl;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 1792
#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 v,e;
    cin>>v>>e;
    int s,t,d;
    int inf = 1<<30;
    int mat[17][17]={};
    REP(i,17)REP(j,17)mat[i][j]=-1;
    REP(i,e){
        cin>>s>>t>>d;
        mat[s][t]=d;
    }
    int dp[1<<18][17]={};
    REP(i,1<<18)REP(j,17)dp[i][j]=inf;
    dp[0][0]=0;
    for(int i=0; i< (1<<v); i++){
        for(int from=0; from<v; from++){
            for(int to=0; to<v; to++){
                if((i & 1<<to)==0 && mat[from][to]!=-1){
                    dp[i | 1<<to][to] = min(dp[i | 1<<to][to], dp[i][from]+mat[from][to]);
                }
            }
        }
    }
    if(dp[(1<<v)-1][0] == inf)cout<<"-1"<<endl;
    else cout<<dp[(1<<v)-1][0]<<endl;
}


Measured memory_bytes: 20500
#include <stdio.h>
 
int main(void)
{
    int total;
    int book[9];
    int sum;
    int i;
     
    while (1){
        scanf("%d", &total);
        if (total == 0){
            break;
        }
         
        sum = 0;
        for (i = 0; i < 9; i++){
            scanf("%d", &book[i]);
            sum += book[i];
        }
  printf("%d\n", total - sum);
    }
  
     
    return (0);
}

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

int N;

signed main(){
  
  cin>>N;
  
  int t = 0, x = 0, y = 0;
    
  for(int i=0;i<N;i++){
    
    int nt, nx, ny;
    cin>>nt>>nx>>ny;
    
    int d = abs( nx - x ) + abs( ny - y );
    
    if( nt - t < d || ( ( nt - t ) - d ) % 2 == 1 ){
      cout<<"No"<<endl;
      return 0;
    }
    
    nt = t, nx = x, ny = y;
    
  }
  
  cout<<"Yes"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
# Aizu Problem 00126: Puzzle
#
import sys, math, os, copy

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def check_puzzle(puzzle):
    marker = [[' ' for _ in range(9)] for __ in range(9)]
    # check rows:
    for r in range(9):
        row = puzzle[r]
        for k in range(1, 10):
            if row.count(k) != 1:
                for idx in [j for j in range(9) if row[j] == k]:
                    marker[r][idx] = '*'
    # check columns:
    for c in range(9):
        col = [puzzle[r][c] for r in range(9)]
        for k in range(1, 10):
            if col.count(k) != 1:
                for idx in [j for j in range(9) if col[j] == k]:
                    marker[idx][c] = '*'
    # check sub-squares:
    for rs in range(3):
        for rc in range(3):
            square = puzzle[3*rs][3*rc:3*rc+3] + puzzle[3*rs+1][3*rc:3*rc+3] + \
                     puzzle[3*rs+2][3*rc:3*rc+3]
            for k in range(1, 10):
                if square.count(k) != 1:
                    for idx in [j for j in range(9) if square[j] == k]:
                        ridx = 3 * rs + idx // 3
                        cidx = 3 * rc + idx % 3
                        marker[ridx][cidx] = '*'
            
    return marker


first = True
N = int(input())
for n in range(N):
    puzzle = [[int(_) for _ in input().split()] for __ in range(9)]
    marker = check_puzzle(puzzle)
    if first:
        first = False
    else:
        print()
    for k in range(9):
        out = ''.join([marker[k][j] + str(puzzle[k][j]) for j in range(9)])
        print(out)

Measured memory_bytes: 8160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int P=1e9+7;
inline int add(int a,int b)
{
	return (a + b)>=P?(a+b-P):(a+b);
}
inline int mul(int a,int b)
{
	return 1LL * a * b % P;
}
const int MAXN=2e3+10;
int n,m,C[MAXN][MAXN];
int calc(int x)
{
	int res=0;
	for(int i=x-1;i<=n-m;++i)
	{
		int j=n-m-i;
		int tmp=j+1;
		if(i<x-1)
			tmp=0;
		else if(x==1 && i>0)
			tmp=0;
		else if(x==1)
			tmp=j+1;
		else
			tmp=mul(tmp,C[i-1][x-2]);
		res=add(res,tmp);
	}
	res=mul(res,C[m-1][x-1]);
	return res;
}
int main()
{
	n=read(),m=read();
	C[0][0]=1;
	for(int i=1;i<=n;++i)
	{
		C[i][0]=1;
		for(int j=1;j<=i;++j)
			C[i][j]=add(C[i-1][j],C[i-1][j-1]);
	}
	for(int i=1;i<=m;++i)
		printf("%d\n",calc(i));
	return 0;
}


Measured memory_bytes: 15104
nxt = input().split()
# print(nxt)
N = int(nxt[0])
X = int(nxt[1])
T = int(nxt[2])
# print(N,X,T)
tmp = N/X - int(N/X)
if tmp == 0:
    counter = int(N/X)
else:
    counter = int(N/X) + 1
# print(counter)
print(counter * T)

Measured memory_bytes: 9108
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
  if(ch == 'A' ) return 1;
  else if(ch == 'C' ) return 2;
  else if(ch == 'G' ) return 3;
  else if(ch == 'T' ) return 4;
  else return 0;
}
long long getKey(char str[]){
  long long sum = 0 , p = 1 , i;
  for(int i = 0; i < strlen(str); i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){return key % M; }
int h2(int key){return 1 + (key % M - 1);}

int find(char str[]){
  long long key , i , h;
  key = getKey(str);
  for(i = 0; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if( strcmp(H[h],str) == 0) return 1;
    else if( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key = getKey(str);
  for(i = 0; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if( strcmp(H[h],str) == 0) return 1;
    else if( strlen(H[h]) == 0 ) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for(i = 0; i < M; i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%s %s",com, str);

    if(com[0] == 'i'){
      insert(str);
    }else{
      if( find(str) ){
        printf("yes\n");
      }else{
        printf("no\n");
      }
    }
  }
  return 0;
}



Measured memory_bytes: 16036
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
   int n;
   cin >> n;
   vector<pair<ll,ll>>  mp(n);
   rep(i,n){
      ll a,b;
      cin >> a >> b;
      mp.at(i)=make_pair(b,a);
   }
   sort(mp.begin(),mp.end());
   ll sum=0;
   bool c=true;
   rep(i,n){
      ll bb,aa;
      tie(bb,aa)=mp.at(i);
      sum+=aa;
      if(sum>bb){
         c=false;
         break;
      }
   }
   if(c)cout << "Yes" << endl;
   else cout << "No"  << endl;
}


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

int main(){
    int s,w;
    cin>>s>>w;
    if(w<s)cout<<"safe"<<endl;
    else cout<<"unsafe"<<endl;
}

Measured memory_bytes: 3624
n, m, x = map(int, input().split())
c = [0] * n
a = [[0 for _ in range(m)] for _ in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    c[i] = tmp[0]
    a[i] = tmp[1:]
ans_flag = False
ans = sum(c)
for i in range(1 << n):
    flag = [False] * n
    for j in range(n):
        if (i >> j) & 1:
            flag[j] = True
    ok = [0] * m
    cost = 0
    for k in range(n):
        if flag[k]:
            for t in range(m):
                ok[t] += a[k][t]
            cost += c[k]
        look = [False] * m
        for s in range(m):
            if ok[s] >= x:
                look[s] = True
            if all(look):
                ans = min(ans, cost)
                ans_flag = True
if ans_flag:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 68948
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AthleteProgramming2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[4];
            int[] b = new int[4];
            int hit, blow;

            string[] s1, s2;
            string str;

            while ((str = Console.ReadLine()) != null)
            {

                s1 = str.Split(' ');
                s2 = Console.ReadLine().Split(' ');

                for (int i = 0; i < 4; i++)
                {
                    a[i] = int.Parse(s1[i]);
                    b[i] = int.Parse(s2[i]);
                }

                hit = 0;
                blow = 0;

                for (int i = 0; i < 4; i++)
                {
                    if (a[i] == b[i])
                        hit++;
                    for (int j = 0; j < 4; j++)
                    {
                        if (a[i] == b[j])
                            blow++;
                    }
                }

                blow -= hit;

                Console.WriteLine("{0} {1}", hit, blow);
            }

        }

    }
}

Measured memory_bytes: 9016
n = int(input())
nums = [int(i) for i in input().split(" ")]

approved = True
for num in nums:
  if num%2 == 0:
    approved = approved & ((num%3 == 0) or (num%5 == 0))
if approved:
  print('APPROVED')
else:
  print('DENIED')
  

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

int bubblesort(int A[], int N){
   bool flag = 1;
   int count = 0;
   while(flag){
      flag = 0;
      for(int i=N-1; i>0; i--){
         if(A[i] < A[i-1]){
            int tmp = A[i];
            A[i] = A[i-1];
            A[i-1] = tmp;
            flag = 1;
            count++;
         }
      }
   }
   return count;
}

int main()
{
   int A[100];
   int N;
   cin >> N;
   for(int i=0; i<N; i++) cin >> A[i];
   int n = bubblesort(A, N);
   for(int i=0; i<N; i++){
      if(i != N-1) cout << A[i] << " ";
      else cout << A[i] << endl;
   }
   cout << n << endl;
}


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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int n;
int a[100000];

int main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    ll ans = 0, sum = 0;
    rep(i,n) {
        sum += a[i];
        if (i%2) {
            if (sum <= 0) {
                ans += 1-sum;
                sum = 1;
            }
        } else {
            if (sum >= 0) {
                ans += sum+1;
                sum = -1;
            }
        }
    }
    ll ans2 = 0, sum2 = 0;
    rep(i,n) {
        sum2 += a[i];
        if (!(i%2)) {
            if (sum2 <= 0) {
                ans2 += 1-sum2;
                sum2 = 1;
            }
        } else {
            if (sum2 >= 0) {
                ans2 += sum2+1;
                sum2 = -1;
            }
        }
    }
    cout << min(ans, ans2) << endl;
}
































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

using namespace std;

typedef long long ll;

int n, k;
ll a[1001];
ll sum[1001];
bool sign[510000][50];
int cont[60];
bool use[510000];
vector<ll> v;

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i == 0) sum[i] = a[i];
        else {
            sum[i] = sum[i - 1] + a[i];
        }
    }
    for (int i = 0; i < n; i++) {
        ll now = a[i];
        v.push_back(now);
        for (int j = i + 1; j < n; j++) {
            now += a[j];
            v.push_back(now);
        }
    }
    for (int i = 0; i < (int)v.size(); i++) {
        ll now = v[i];
        for (int j = 0; (1L << j) <= now; j++) {
            if ((1L << j) & now) {
                sign[i][j] = 1;
                cont[j]++;
            }
        }
    }
    for (int i = 0; i < (int)v.size(); i++) use[i] = 1;
    for (int i = 59; i >= 0; i--) {
        if (cont[i] < k) continue;
        for (int j = 0; j < 60; j++) cont[j] = 0;
        for (int j = 0; j < (int)v.size(); j++) {
            if (!sign[j][i]) use[j] = 0;
            if (use[j]) {
                for (int l = 0; l < 60; l++) {
                    if (v[j] & (1L << l)) cont[l]++;
                }
            }
        }
        if (cont[i] == k) break;
    }
    ll ans = 0;
    ll now = 1;
    for (int i = 0; i < 60; i++) {
        if (cont[i] >= k) ans += now;
        now <<= 1;
    }
    cout << ans << endl;
}

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

int n;

int binary_search(int l, int r, int v){
    while(r-l > 1){
        int mid = l + (r-l)/2;
        if(mid*mid >= v){
            r = mid;
        }else{
            l = mid;
        }
    }
    return r;
}

int main(void){
    cin >> n;
    for(int i = 1; i <= n; i++){
        int res = 0;
        for(int u = 2; u*u <= 2*i; u++){
            for(int v = 2; v*v <= 2*i; v++){
                if(2*i-u*u-v*v <= 0) continue;
                int w = binary_search(0, 2*i-u*u-v*v, 2*i-u*u-v*v);
                if(u*u+v*v+w*w != 2*i) continue;
                int a, b, c;
                a = u-v+w;
                b = u+v-w;
                c = -u+v+w;
                if(a < 1 || b < 1 || c < 1) continue;
                if(a%2 == 0 && b%2 == 0 && c%2 == 0){
                    res++;
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}


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

constexpr int MAX_N = 1e5+9;

int N;
vector<vector<int>> edges(MAX_N+1), costs(MAX_N+1);
int colors[MAX_N+1];

void dfs(int cur, int pre, int w) {
  colors[cur] = (w % 2 == 0) ? colors[pre] : !colors[pre];
  for (int i{}; i < edges[cur].size(); ++i) {
    int next = edges[cur][i];
    if (colors[next] >= 0) continue;
    dfs(next, cur, costs[cur][i]);
  }
}

int main() {
  fill_n(colors, MAX_N+1, -1);
  colors[0] = 0;

  cin >> N;

  for (int i{}; i < N - 1; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    edges[u].push_back(v);
    costs[u].push_back(w);
    edges[v].push_back(u);
    costs[v].push_back(w);
  }

  colors[1] = 0;
  dfs(1, 0, 0);
  for (int i{1}; i <= N; ++i) {
    cout << colors[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 12800
def pairwise_distinct():
    n = int(input())
    k = list(input().split()) #input based on n
    if not len(k) == n:
        return "==== pleas input based on n times in one line ===="
    else:
        if (len(set(k)) == len(k)):
            return "YES"
        else:
            return "NO"

print(pairwise_distinct())

Measured memory_bytes: 31056
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	int a[n+1];
	fill(a,a+(n+1),1);
	int h[n+1];
	for(int i = 0; i<n; i++)
		cin>>h[i+1];
	for(int i =0; i<m; i++)
	{
		int j,k;
		cin>>j>>k;
		if(h[j]<=h[k])
			a[j] = 0;
		if(h[k]<=h[j])
			a[k] = 0;
	}
	int ans = int(count(a,a+n+1,1))-1;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 	
	
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> v(m);
	for(int i = 0; i < m; i++) {
		cin >> v[i].first >> v[i].second;
	}
	sort(v.begin(), v.end(), [](pair<int, int> x, pair<int, int> y) 
			-> bool {return x.second < y.second;});
	int cur = 0;
	int ans = 0;
	for(int i = 0; i < m; i++) {
		if(cur <= v[i].first) {
			ans++;
			cur = v[i].second;
		}
	}
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 1024
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn gcd(a: u32, b: u32) -> u32 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

use std::cmp::{max, min};

fn main() {
    let nk: Vec<u32> = read_vec();
    let n = nk[0] as usize;
    let k = nk[1];
    let a: Vec<u32> = read_vec();
    let mut v: u32 = a[0];
    let mut mx: u32 = a[0];
    for i in 1..n {
        let tmp = a[i];
        v = gcd(max(v, tmp), min(v, tmp));
        if tmp > mx {
            mx = tmp;
        }
    }
    if k % v == 0 && mx >= k {
        println!("POSSIBLE");
    } else {
        println!("IMPOSSIBLE");
    }
}


Measured memory_bytes: 6396
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class B {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    string o, e;
	    in >> o >> e;
	    string res = "";
	    for(int i=0; i<o.length() + e.length(); i++){
            if(i%2 == 0) out << o[i/2];
            else out << e[i/2];
	    }
	    out << endl;
	}
};


int main() {
	B solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n;
    cin >> n;

    v_int x(n),y(n);

    rep(i,n) {
        cin >> x[i] >> y[i];
    }

    v_int idx(n);
    rep(i,n) { idx[i] = i; }
    
    double ans = 0;
    do {
        double dist = 0;
        rep(i,n-1) {
            int j = i+1;
            double dx = (x[idx[i]]-x[idx[j]])*(x[idx[i]]-x[idx[j]]);
            double dy = (y[idx[i]]-y[idx[j]])*(y[idx[i]]-y[idx[j]]);
            dist += sqrt(dx+dy);
        }
        ans += dist;
    } while(next_permutation(idx.begin(), idx.end()));

    rep(i,n) {
        ans /= (i+1);
    }
    printf("%.12f", ans);
    return 0;
} /*atcoder*/



Measured memory_bytes: 3756
package main

import (
	"fmt"
)

func abs(a int) int {
	if a < 0 {
		return (-1) * a
	}
	return a
}

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	if abs(a-c) <= d || abs(a-b) <= d && abs(b-c) <= d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  int xsum = 0;
  vecint a(n);
  REP(i,n) {
    cin>>a[i];
    xsum ^= a[i];
  }
  REP(i,n) {
    if(i)cout<<" ";
    cout<<(xsum^a[i]);
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3960
a=[]
b=[]

for i in range (10):
    c=int(input())
    a.append(c)
    d=sorted(a)
    
for i in range (10):
    c=int(input())
    b.append(c)
    e=sorted(b)

print(d[-1]+d[-2]+d[-3],e[-1]+e[-2]+e[-3])




Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;
const int INF = 1001001001;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

int color(int x){
    if(x < 400)     return 0;
    if(x < 800)     return 1;
    if(x < 1200)    return 2;
    if(x < 1600)    return 3;
    if(x < 2000)    return 4;
    if(x < 2400)    return 5;
    if(x < 2800)    return 6;
    if(x < 3200)    return 7;

    return 8;
}

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

    int n;
    cin >> n;
    vector<int> cnt(10, 0);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        ++cnt[color(a)];
    }
    int resmin = 0;
    for(int i = 0; i < 8; ++i){
        if(cnt[i] > 0)  ++resmin;
    }
    int resmax = 0;
    int limit = 8;
    int rest = limit - resmin;
    resmax = resmin + cnt[8];
    if(resmin == 0) resmin = 1;
    cout << resmin << " " << resmax << endl;
}

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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

#define R 1000000000

int n, s[20005], t[20005], a[20005], b[20005];

int main(){
	scanf("%d", &n);
	FI(i, 1, n) scanf("%d", &t[i]), s[t[i]] = i;
	a[1] = s[1];
	b[1] = R;
	FI(i, 2, n){
		a[i] = a[i - 1] + 1;
		b[i] = b[i - 1] - 1;
		if(s[i] < s[i - 1]) b[i] -= (s[i - 1] - s[i]);
		else a[i] += (s[i] - s[i - 1]);
	}
	FI(i, 1, n) printf("%d%c", a[i], i == n ? '\n':' ');
	FI(i, 1, n) printf("%d%c", b[i], i == n ? '\n':' ');
	return 0;
}

Measured memory_bytes: 896
<>=~$";
@HW=($`+1,$'+1);
@p=map[<>+0,0],1..$`;
@q=map[<>+0,1],1..$';
for(sort{@$a[0]-@$b[0]}@p,@q){
	$x+=@$_[0]*$HW[!@$_[1]];
	--$HW[@$_[1]]
}
print$x


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

int main() {
    string a;
    getline(cin,a);
    for (int i = 0; i < a.length(); ++i) {
        if (a[i]>=65&&a[i]<=90) a[i]+=32;
        else if (a[i]>=97&&a[i]<=122) a[i]-=32;
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 3168
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
		int m = sc.nextInt();
		int total = 0;
		if(n>0){
			total += n * (n-1) / 2;
		}
		if(m>0){
			total += m * (m-1) / 2;
		}
    System.out.println(total);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
 
#define A_MAX 1000000
#define A_MAX_HALF 500000
 
using namespace std;
 
int min_factor[A_MAX + 1];
int q[A_MAX + 1];
int a[A_MAX + 1];
vector<int> primes{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 };
int N;
 
int read_int() {
    int x = 0;
    char c = getchar_unlocked();
    do {
      x = 10 * x + c - '0';
    } while ((c = getchar_unlocked()) >= '0');
    return x;
}
 
int main() {
    for (int i = 2; i <= A_MAX_HALF; ++i) {
        if (!min_factor[i]) {
            min_factor[i] = i;
        }
        int min_factor_i = min_factor[i];
        for (int p : primes) {
            int n = i * p;
            if (n > A_MAX) {
                break;
            }
            min_factor[n] = p;
            if (p == min_factor_i) {
                q[n] = q[i];
                break;
            } else {
                q[n] = i;
            }
        }
    }
 
    char c = getchar_unlocked();
    do {
        N = 10 * N + c - '0';
    } while ((c = getchar_unlocked()) >= '0');
    for (int i = 0; i < N; ++i) {
        int A = 0;
        c = getchar_unlocked();
        do {
        	A = 10 * A + c - '0';
    	} while ((c = getchar_unlocked()) >= '0');
        ++a[A];
    }
 
    int is_pairwise_coprime = 1;
    for (int n = A_MAX; n > 1; --n) {
        int an = a[n];
        if (an) {
            if (an > 1) {
                if (an == N) {
                    printf("not coprime\n");
                    return 0;
                }
                is_pairwise_coprime = 0;
            }
            a[min_factor[n]] += an;
            a[q[n]] += an;
        }
    }
    if (is_pairwise_coprime) {
        printf("pairwise coprime\n");
    } else {
        printf("setwise coprime\n");
    }
 
    return 0;
}

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

using namespace std;

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

    int ans = 1;
    long long a, b;
    cin >> a >> b;

    if (a > b)
        swap(a, b);

    for (long long i = 2; i * i <= a; i++)
        if (a % i == 0) {
            ans += (b % i == 0);
            while (a % i == 0)
                a /= i;
        }

    ans += (a > 1 && b % a == 0);
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
s=input()
if int(s[-1]) == 2 or int(s[-1]) == 4 or int(s[-1]) == 5 or int(s[-1]) == 7 or int(s[-1]) ==9:
    print("hon")
elif int(s[-1]) == 0 or int(s[-1]) == 1 or int(s[-1]) == 6 or int(s[-1]) ==8:
    print("pon")
else:
    print("bon")


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'


int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  if (s[0] == 'W') {
    cout << 0 << endl;
    return 0;
  }
  ll stock = 1;
  char pre = 'r';
  ll ans = 1;
  for (int i = 1; i < 2*n; i++) {
    assert(pre == 'l' or pre == 'r');
    if (s[i] == s[i - 1]) {
      if (pre == 'r') {
        if (stock == 0) {
          cout << 0 << endl;
          return 0;
        }
        pre = 'l';
        ans *= stock;
        stock--;
      }
      else {
        pre = 'r';
        stock++;
      }
    }
    else {
      if (pre == 'r') {
        pre = 'r';
        stock++;
      }
      else {
        pre = 'l';
        if (stock == 0) {
          cout << 0 << endl;
          return 0;
        }
        ans *= stock;
        stock--;
      }
    }
    ans %= MOD;
  }
  rep1 (i, n) {
    ans *= i;
    ans %= MOD;
  }
  if (stock > 0) {
    cout << 0 << endl;
  }
  else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 640
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import itertools
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N, M, Q = LI()

abcd = []

all = 0
for i in range(Q):
    a, b, c, d = LI()
    a -= 1
    b -= 1
    abcd.append([a, b, c, d])
    all += d

abcd = sorted(abcd, key= lambda x:x[3], reverse= True)
ans = 0
if Q <= 2:
    for q in range(Q):
        ans += abcd[q][-1]
    print(ans)
    sys.exit()

def cal_ans(A):
    ans = 0
    for i in range(Q):
        a, b, c, d = abcd[i]
        if A[b] - A[a] == c:
            ans += d
    return ans

def n2kdigit(n, k):
    bi=''
    before = 1
    while n!=0:
        if before <= (n % k):
            # print(n)
            bi+=str(n%abs(k))
            before = n % k
            if k<0:n=-(-n//k)
            else:n=n//k
        else:
            return None
    if len(bi) < N:
        return None
    return bi
ans = 0

for i in itertools.combinations_with_replacement(range(1, M+1), N):
    # print(i)
    ans = max(ans, cal_ans(i))
print(ans)

Measured memory_bytes: 10836
#include<bits/stdc++.h>
using namespace std;
#define flb(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define mp make_pair
#define pb push_back
#define inf (long long)(1e18+1e15)
typedef pair<int,int> ii;
typedef vector <int> vi;
typedef vector <pair<int,int> > vii;
typedef vector <vector <int> > vvi;

int main()
{
    int n;
    cin>>n;
    map <int,int> m;
    flb(i,0,n-1)
    {
        int x;
        cin>>x;
        m[x]++;
    }
    flb(i,1,n+1)
    {
        cout<<m[i]<<endl;
    }
}


Measured memory_bytes: 13004
//>> OI Solution Info <<//
// Version: 2
// State: Progress
// Problem: Eating Symbols Hard
// ID: AtCoder ARC099D
// Time: ---
// Timeline:
//   --- ~ --- Initialize
// Review:
//   ---
//>> End <<//
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define y0 y_0
#define y1 y_1
#define yn y_n
#include <assert.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

inline int fpow(int x,int y,int mod){
	if(y==0)return 1;
	long long res=fpow(x,y/2,mod);
	(res*=res)%=mod;
	return y%2==0?int(res):int(res*x%mod);
}

static const int Mult=4;
static const int Mod=1000000007;
static const int Advance[4]={113,113113,233,23333333};
static const int Offset=250005;

struct Hash{
	int a[4];
	static int pow[4][500010];
	
	Hash(){
		for(int i=0;i<Mult;i++)a[i]=0;
	}
	
	bool operator==(const Hash& r)const{
		for(int i=0;i<Mult;i++)if(a[i]!=r.a[i])return false;
		return true;
	}
	
	bool operator<(const Hash& r)const{
		for(int i=0;i<Mult;i++)if(a[i]!=r.a[i])return a[i]<r.a[i];
		return false;
	}
	
	Hash operator-(const Hash& r)const{
		Hash res;
		for(int i=0;i<Mult;i++)res.a[i]=(a[i]+Mod-r.a[i])%Mod;
		return res;
	}
	
	void inc(int pos,int x){
		x=(x+Mod)%Mod;
		for(int i=0;i<Mult;i++){
			(a[i]+=int((long long)pow[i][pos+Offset]*x%Mod))%=Mod;
			assert(a[i]>=0);
		}
	}
	
	void shift(int x){
		for(int i=0;i<Mult;i++){
			a[i]=int((long long)a[i]*pow[i][x+Offset]%Mod);
			assert(a[i]>=0);
		}
	}
	
	static void init(){
		for(int i=0;i<Mult;i++){
			int inv=fpow(Advance[i],Mod-2,Mod);
			pow[i][Offset]=1;
			for(int j=Offset-1;j>=0;j--)pow[i][j]=int((long long)pow[i][j+1]*inv%Mod);
			for(int j=Offset+1;j<500010;j++)pow[i][j]=int((long long)pow[i][j-1]*Advance[i]%Mod);
			for(int j=0;j<500010;j++)assert(pow[i][j]>=0);
		}
	}
};
int Hash::pow[4][500010];

int n;
char s[250005];
Hash all;

/*
Hash eval(int l,int r){
	int p=0;
	Hash res;
	for(int i=r;i>=l;i--){
		if(s[i]=='+')res.inc(0,1);
		else if(s[i]=='-')res.inc(0,-1);
		else if(s[i]=='<')res.shift(-1);
		else if(s[i]=='>')res.shift(1);
	}
	return res;
}
*/

long long solve(int l,int r){
	if(l==r){
		Hash curr;
		if(s[l]=='+')curr.inc(0,1);
		else if(s[l]=='-')curr.inc(0,-1);
		return curr==all?1:0;
	}
	
	long long res=0;
	int mid=(l+r)/2;
	
	Hash right;
	int p=0;
	map<Hash,int> cnt;
	for(int i=mid+1;i<=r;i++){
		if(s[i]=='+')right.inc(p,1);
		else if(s[i]=='-')right.inc(p,-1);
		else if(s[i]=='<')p--;
		else if(s[i]=='>')p++;
		cnt[right]++;
	}
	
	Hash left;
	p=0;
	for(int i=mid;i>=l;i--){
		if(s[i]=='+')left.inc(0,1);
		else if(s[i]=='-')left.inc(0,-1);
		else if(s[i]=='<'){
			left.shift(-1);
			p--;
		}
		else if(s[i]=='>'){
			left.shift(1);
			p++;
		}
		Hash curr=all-left;
		curr.shift(-p);
		res+=cnt[curr];
	}
	
//	printf("%d [%d] %d => %lld\n",l,mid,r,res);
	
	res+=solve(l,mid);
	res+=solve(mid+1,r);
	return res;
}

int main(){
	Hash::init();
	scanf("%d %s",&n,s);
	
	int p=0;
	for(int i=0;i<n;i++){
		if(s[i]=='+')all.inc(p,1);
		else if(s[i]=='-')all.inc(p,-1);
		else if(s[i]=='<')p--;
		else if(s[i]=='>')p++;
	}
	
	printf("%lld\n",solve(0,n-1));
	return 0;
}


Measured memory_bytes: 39552
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long K = sc.nextLong();

        if(K<=A){
            System.out.println(A-K +" "+ B);    
        }else if(K>A && K<=A+B){
			System.out.println("0 " + (B-(K-A)));
        }else{
			System.out.println("0 0");            
        }
    }
}


Measured memory_bytes: 23252