akhauriyash/Code-Regression huggingface dataset:
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Long.max;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        int n = scanInt();
        long[] a = new long[n];
        long ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = scanLong();
        }
        Arrays.sort(a);
        if (a.length == 2) {
            out.print(max(a[0], a[1]));
            return;
        }
        for (int i = n / 2 + 1; i < n; i++) {
            ans += a[i];
        }
        if (n % 2 != 0) {
            for (int i = 0; i < n / 2; i++) {
                ans += a[n - 2 - i];
            }
        } else {
            for (int i = 0; i < n / 2; i++) {
                if (i + 1 < n / 2) {
                    ans += a[n - 2 - i];
                } else {
                    ans += a[n - 1 - i];
                }
            }
        }
        out.print(ans);
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int x[n];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        ans += min((ll)a * (x[i + 1] - x[i]), (ll)b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void) {
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  if (a+b > c+d) {
    printf("Left\n");
  } else if (a+b == c+d) {
    printf("Balanced\n");
  } else {
    printf("Right\n");
  }
  return 0;
}

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

int main(){
    int n;
    int charge;
    int cnt = 0;

    int coin[] = {500, 100, 50, 10, 5, 1};

    while(cin >> n, n != 0){
        charge = 1000 - n;
        for(int i=0; i<6; i++){
            int j = 0;
            while(charge - coin[i] * j >= coin[i]){
                j++;
            }
            charge -= coin[i] * j;
            cnt += j;
        }

        cout << cnt << endl;
        cnt = 0;
    }
    return 0;
}

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

int main(){
    int i,j,k;
    int N,M;
    int ans = 1;

    cin >> N;

    vector<int> A(100001);

    for(i=0;i<N;i++)cin >> A.at(i);

    for(i=0;i<N;i++){
        ans = A.at(ans-1);
        if(ans == 2){
            cout << i+1 << endl;
            return 0;
        }
    }

    cout << "-1" << endl;

}

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

int main(){
	int n,d[4],turn;
	while(1){
		A:
		cin >> n;
		if(n==0){
			return 0;
		}
		d[3] = n/1000;
		d[2] = n/100 - d[3]*10;
		d[1] = n/10 - d[3]*100 - d[2]*10;
		d[0] = n - d[3]*1000 -d[2]*100 -d[1]*10;
		if((d[0]==d[1])&&(d[1]==d[2])&&(d[2]==d[3])){
			cout << "NA\n";
			goto A;
		}
		turn=0;
		while(n!=6174){
			d[3] = n/1000;
			d[2] = n/100 - d[3]*10;
			d[1] = n/10 - d[3]*100 - d[2]*10;
			d[0] = n - d[3]*1000 -d[2]*100 -d[1]*10;
		
			int y;
			for(int i=1;i<4;i++){
				for(int j=1;j<5-i;j++){
					if(d[j-1]>d[j]){
						y = d[j-1];
						d[j-1] = d[j];
						d[j] = y;
					}
				}
			}
		
			n = (d[3]-d[0])*999 + (d[2]-d[1])*90;

			turn++;
		}
		cout << turn <<  "\n";
	}
return 0;
}

Measured memory_bytes: 1164
n = gets.to_i
a = n.times.map{gets.to_i}

m1 = a.max
b = Marshal.load(Marshal.dump(a))
b.delete_at(a.index(m1))
m2 = b.max

(0...n).each do |i|
  if a[i] == m1
    puts m2
  else
    puts m1
  end
end

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.value);
    }

    mint inv() const {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((value += MOD - a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (value *= a.value) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    string s;
    cin >> s;
    int n = s.size();
    bool ok = true;
    auto is_palindrome = [](string s) {
        return s == string(s.rbegin(), s.rend());
    };
    // debug(s.substr(0, (n - 1) / 2));
    // debug(s.substr((n + 3) / 2 - 1, n - 1));
    ok = ok and is_palindrome(s);
    ok = ok and is_palindrome(s.substr(0, (n - 1) / 2));
    ok = ok and is_palindrome(s.substr((n + 3) / 2 - 1));

    if (ok)
        CYES;
    else
        CNO;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
from operator import itemgetter

n = int(sys.stdin.readline())
a = dict()
for i,ai in enumerate([int(x) for x in sys.stdin.readline().strip().split()]):
    a[i+1] = ai
#
for i,ai in sorted(a.items(),key=itemgetter(1)):
    print( i,end=" ")


Measured memory_bytes: 25492
#include <stdio.h>
#include <stdlib.h>
 
struct C {
  char a;
  int b;
};
 
int N;
 
int isStable(struct C b[], struct C s[]){
  int i;
 
  for(i = 0; i < N; i++){
    if(b[i].a != s[i].a)  return 0;
  }
  return 1;
}
 
void BubbleSort(struct C c[]){ //??????
  int i, j;
  struct C k;
 
  for(i = 0; i < N; i++){
    for(j = N-1; j >= i+1; j--){
      if(c[j].b < c[j-1].b){
    k = c[j];
    c[j] = c[j-1];
    c[j-1] = k;
      }
    }
  }
}
 
void SelectionSort(struct C c[]){ //?????????
  int i, j, minj;
  struct C k;
 
  for(i = 0; i < N; i++){
    minj = i;
    for(j = i; j < N; j++){
      if(c[j].b < c[minj].b)  minj = j;
    }
    k = c[i];
    c[i] = c[minj];
    c[minj] = k;
  }
}
 
int main()
{
  struct C s[36], b[36];
  char x[2];
  int i;
   
  scanf("%d", &N);
  for(i = 0; i < N; i++){
    scanf("%s", x);
    b[i].a = x[0];
    b[i].b = atoi(&x[1]);
  }
  for(i = 0; i < N; i++)  s[i] = b[i];
  BubbleSort(b);
  SelectionSort(s);
 
  for(i = 0; i < N; i++){
    printf("%c%d", b[i].a, b[i].b);
    if(i < N - 1) printf(" ");
    else printf("\n");
  }
  printf("Stable\n");
 
  for(i = 0; i < N; i++){
    printf("%c%d", s[i].a, s[i].b);
    if(i < N - 1) printf(" ");
    else printf("\n");
  }
  if(isStable(b, s)) printf("Stable\n");
  else printf("Not stable\n");
 
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for (int i = 0; i < r; i++)
#define repeq(i,r) for (int i = 0; i <= r; i++)

int main() {
  int N, A;
  cin >> N;
  rep(i,N) {
    cin >> A;
    if (A % 2 == 0 && A % 3 != 0 && A % 5 != 0) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>

int main() {
    std::string S;
    std::cin >> S;
    std::map<std::string, int> dictionary{
            {"SUN", 7}, {"MON", 6}, {"TUE", 5}, {"WED", 4}, {"THU", 3}, {"FRI", 2}, {"SAT", 1}
    };
    std::cout << dictionary[S] << std::endl;
    return 0;
}


Measured memory_bytes: 256
a, b, k = map(int, input().split())

min = [0] * k
max = [0] * k

for i in range(k):
  if a+i > b:
    break
  min[i] = a+i

for n in range(k):
  if b-n < a:
    break
  max[n] = b-n

ans = min + max
ans = set(ans)
ans = list(ans)
ans.sort()

for j in ans:
  if j == 0:
    continue
  print(j)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  double sum = 0;
  double res = 0;
  for (int i = 0; i < K - 1; i++) {
    sum += (1.0 + P[i]) / 2.0;
  }
  for (int i = K - 1; i < N; i++) {
    if (i - K >= 0) {
      sum -= (1.0 + P[i - K]) / 2.0;
    }
    sum += (P[i] + 1.0) / 2.0;
    res = max(res, sum);
  }
  cout << std::fixed;
  cout << std::setprecision(10) << res << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int check(int p1, int p2, int p3){
	if(p2 == max(p1, max(p2, p3))) return 0;
  	if(p2 == min(p1, min(p2, p3))) return 0;
  return 1;
}
 
int main(){
  int p[21] = {};
  int n, ans = 0;
  cin >> n;
  for(int i = 0; i < n; i++){
	cin >> p[i];
  }
  for(int i = 1; i < n-1; i++){
	ans += check(p[i-1], p[i], p[i+1]);
  }
  cout << ans << endl;
	return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#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 repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int a, b;
    cin >> a >> b;
    if (a<b) swap(a, b);
    int ans = max(a+a-1, a+b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    string s;
	cin >> s;
    int n = s.length();
    bool a = true;
    int kaisuu=0;
    fr(i,n){
      if(a==(s[i]=='0'))kaisuu+=1;
      if(a)a=false;
      else a=true;
    }
    cout << min(kaisuu,n-kaisuu) << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long llong;

int main(int, char**) {
  int a[9];
  for (int i = 0; i < 9; ++i) {
    cin >> a[i];
  }
  int n;
  cin >> n;
  int b[n];
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    for (int j = 0; j < 9; ++j) {
      if (a[j] == b[i])
        a[j] = 0;
    }
  }

  // Horizontal x 3
  bool found = true;
  for (int i = 0; i < 3; ++i) {
    if (a[i] != 0) {
      found = false;
      break;
    }
  }
  if (found) {
    cout << "Yes";
    return 0;
  }
  
  found = true;
  for (int i = 3; i < 6; ++i) {
    if (a[i] != 0) {
      found = false;
      break;
    }
  }
  if (found) {
    cout << "Yes";
    return 0;
  }
  
  found = true;
  for (int i = 6; i < 9; ++i) {
    if (a[i] != 0) {
      found = false;
      break;
    }
  }
  if (found) {
    cout << "Yes";
    return 0;
  }

  // Vertical x 3
  found = true;
  for (int i = 0; i < 3; ++i) {
    if (a[i * 3] != 0) {
      found = false;
      break;
    }
  }
  if (found) {
    cout << "Yes";
    return 0;
  }
  
  found = true;
  for (int i = 0; i < 3; ++i) {
    if (a[i * 3 + 1] != 0) {
      found = false;
      break;
    }
  }
  if (found) {
    cout << "Yes";
    return 0;
  }
  
  found = true;
  for (int i = 0; i < 3; ++i) {
    if (a[i * 3 + 2] != 0) {
      found = false;
      break;
    }
  }
  if (found) {
    cout << "Yes";
    return 0;
  }

  // Diagonal x 2
  found = true;
  for (int i = 0; i < 3; ++i) {
    if (a[i * 3 + i] != 0) {
      found = false;
      break;
    }
  }
  if (found) {
    cout << "Yes";
    return 0;
  }
  
  found = true;
  for (int i = 0; i < 3; ++i) {
    if (a[i * 3 + 2 - i] != 0) {
      found = false;
      break;
    }
  }
  if (found) {
    cout << "Yes";
    return 0;
  }

  cout << "No";
  return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cassert>
#include<climits>
#include<algorithm>
#include<vector>
#include<deque>
#include<map>
#include<set>
#include<sstream>
#include<cstring>

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

using namespace std;

int main() {
  int a,b;
  char c;
  cin >> a >> c >> b;
  if( c == '+' ) cout << a + b << endl;
  else if( c == '-' ) cout<<a-b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int Next[5010];
char s[5010];
void get_Next(int slen,int offset){
	int i=offset,j=-1+offset;
	Next[offset] = -1+offset;
	while (i<slen){
		if (j==-1+offset||s[i]==s[j]){
			i++,j++;
			if (s[i]!=s[j]) Next[i] = j;
			else Next[i] = Next[j];
		}
		else j = Next[j];	
	} 
}

int kmp(int slen,int offset){
	int i=0,j=offset,res=offset;
	while (i<offset&&j<slen){
		if (j==-1+offset||s[i]==s[j]){
			i++,j++;
		}
		else {
			if (j>res) res = j;
			j = Next[j];	
		}	
	}
	if (j>res) res = j;	
	return res-offset;
}

int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",&s);
	int slen = strlen(s),ans=0;
	for (int i=1;i<slen;i++){
		get_Next(slen,i);
		ans = max(kmp(slen,i),ans);	
	}
	printf("%d",ans);
	return 0;	
}

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

int main(){
    ll n, m; cin >> n >> m;
    map<ll,ll> a;
    ll ans = 0, s = 0; a[s]++;
    for(int i=0; i<n; i++){
        ll x; cin >> x;
        s = (s+x) % m;
        ans += a[s];
        a[s]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7488
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

int solve()
{
	ll n,k;cin>>n>>k;
	set<ll> s;
	rep(i,1,n+1) s.insert(i);
	rep(i,0,k)
	{
		ll d;cin>>d;
		rep(j,0,d)
		{
			ll x;cin>>x;
			s.erase(x);
		}
	}

	cout<<sz(s)<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod=998244353;

#define pb push_back
#define mp make_pair


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll t,n,k;
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
        cout<<"Yes";
    else
        cout<<"No";


    return 0;
}




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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int a,b,c,d;

    a = N / 1000;
    b = (N - 1000 * a) / 100;
    c = (N - 1000 * a - b * 100) / 10;
    d = (N - 1000 * a - b * 100) % 10;

    if (a == b && b == c){
        cout << "Yes" << endl;
    }
    else if (b == c && c ==d){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include "iostream"

using namespace std;

int main() {

	int n;
	int lpos;
	int s[100000];

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	int p = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] <= s[n - 1]) {
			int x = s[i];
			s[i] = s[p];
			s[p] = x;
			
			if (i == n - 1) {
				lpos = p;
			}

			p++;
		}
	}

	for (int i = 0; i < n; i++) {
		if (i == lpos) cout << "[" << s[i] << "]";
		else cout << s[i];
		if (i < n - 1) cout << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1548
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using intl = int64_t;
using graph = vector<vector<int> >;
int main(){
    int n;
    cin >> n;
    vector<intl> a;
    for(int i=0;i<n;i++){
        int b;
        cin >> b;
        a.push_back(b);
    }
    sort(a.begin(),a.end());

    int check=1;
    for(int i=1;i<n;i++){
        if(a[i-1]==a[i]){
            check=0;
            break;
        }
    }

    if(check){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


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

int H, W;
vector< vector<bool> > Wall;

int bfs(int sx, int sy){
    vector< vector<bool> > Vis (H+2, vector<bool> (W+2, 0));
    queue< pair<int, pair<int, int> > > Q;

    Q.push( {0, {sx, sy}} );
    // ------------------------------------
    int subMaxMoves = 0;
    while(!Q.empty()) {
        pair<int, int> coor = Q.front().second;
        int            step = Q.front().first;
        Q.pop();
        // --
        if( Vis[coor.first][coor.second] ) continue;
        Vis[coor.first][coor.second] = 1;
        //
        subMaxMoves         = max(subMaxMoves, step);
        // --
        for(int d = -1; d <= 1; d += 2) {
            if(!Wall[coor.first + d][coor.second]) {
                Q.push( {step+1, {coor.first+d, coor.second}} );
            }
            if(!Wall[coor.first][coor.second + d]) {
                Q.push( {step+1, {coor.first, coor.second+d}} );
            }
        }
    }
    //
    return subMaxMoves;
}

int main() {
    cin >> H >> W;
    Wall.resize(H+2, vector<bool> (W+2, 1));
    for(int i = 1; i <= H; i++) {
        for(int j = 1; j <= W; j++) {
            char c;
            cin >> c;
            Wall[i][j] = (c == '#');
        }
    }
    // --------------------------------------------
    int maxMoves = 0;
    for(int i = 1; i <= H; i++) {
        for(int j = 1; j <= W; j++) {
            if(!Wall[i][j]) maxMoves = max(maxMoves, bfs(i, j));
        }
    }
    //
    cout << maxMoves << endl;
    return 0;
}

Measured memory_bytes: 256
program B;
    var Q:string;
    var ans:integer;
begin
    readln(Q);
    ans:=0;
    if Q[1]=Q[length(Q)] then ans:=ans+1;
    if length(Q) mod 2=0 then ans:=ans+1;
    if ans mod 2=1 then writeln('Second') else writeln('First');
end.

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

using namespace std;

int sec[200010];
int sum[200010];

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        char c;
        cin>>c;
        sec[i]=c=='#';
    }
    for(int i=1;i<=n;i++)
    {
        sec[i]+=sec[i-1];
    }
    int ans=0x7f7f7f7f;
    for(int i=0;i<=n;i++)
    {
        ans=min(ans,sec[i]+n-i-(sec[n]-sec[i]));
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 1152
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll n;cin>>n;
    ll a[n+1];mem(a,0);
    rep(i,1,n+1)cin>>a[i];
    ll dp[n+1][3];mem(dp,0);
    rep(i,0,n+1)dp[i][0]=dp[i][1]=dp[i][2]=-INF;
    dp[1][0]=a[1];
    dp[2][1]=a[2];
    dp[3][0]=a[1]+a[3];dp[3][2]=a[3];
    rep(i,4,n+1){
        dp[i][0]=max(dp[i-2][0]+a[i],dp[i][0]);
        dp[i][1]=max({dp[i-3][0]+a[i],dp[i-2][1]+a[i],dp[i][1]});
        dp[i][2]=max({dp[i-4][0]+a[i],dp[i-3][1]+a[i],dp[i-2][2]+a[i],dp[i][2]});
    }
    if(n&1)cout<<max({dp[n][2],dp[n-1][1],dp[n-2][0]});
    else cout<<max(dp[n][1],dp[n-1][0]);
}

Measured memory_bytes: 9860
s, t = (input() for _ in range(2))
tmp = s
if tmp == t:
  print('Yes')
  exit()
if set(s) == set(t):
  for i in range(len(s)):
    tmp = tmp[-1] + tmp[:-1]
    if tmp == t:
      print('Yes')
      exit()
print('No')

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
   int a[6]; 
   cin>>a[1]>>a[2]>>a[3]>>a[4]>>a[5];
   for(int i = 1 ; i <= 5 ; i++)
   {
     if(a[i]==0)
     {
        cout<<i<<endl;
        break;
     }
   }
   return 0;
}

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

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

    int N, R;

    cin >> N >> R;

    N >= 10 ? cout << R : cout << R + 100 * (10-N);

    return 0;
}


Measured memory_bytes: 256
/***************************************************

@author: vichitr
Compiled On: 19th Mar 2020

*****************************************************/
#include<bits/stdc++.h>
#define MAX 9223372036854775807
#define endl "\n"
#define ll long long
#define int long long
#define double long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define ip pair<int, int>
#define F first
#define S second

#define loop(i,n) for(int i=0;i<n;i++)
#define loops(i,s,n) for(int i=s;i<=n;i++)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
using namespace std;

const ll MOD = 1e9+7;
const ll SZ = 107;
const ll N = 2e5+7;
// const ll M = 2e5+7;

ll pwr(ll x, ll y)
{
    ll r = 1LL;
    while(y)
    {
        if(y&1)
            r = (r * x) % MOD;
        y >>= 1;
        x = (x * x) % MOD;
    }
    return r;
}

int inv(int x)
{
    return pwr(x, MOD-2ll);
}

// int fact[N];

// int nCr(int x, int y){
//     int ans= fact[x];
//     ans *= inv(fact[y]);
//     ans %= MOD;
//     ans *= inv(fact[x-y]);
//     ans %= MOD;
//     return ans;
// }

// bool prim(int n){
//     for(int i=2;i*i<=n;i++){
//         if(n%i==0)
//             return 0;
//     }
//     return 1;
// }
bool ispal(string s){
    int n = s.size();
    for(int i=0;i<n/2;i++)
        if(s[i]!=s[n-1-i])
            return 0;
    return 1;
}

void solve()
{ 
    int n; cin>>n;
    int a[n];
    map<int, int> M;
    loop(i, n){
        cin>>a[i];
        M[a[i]]++;
    }
    int ans = 0;
    for(auto i: M)
    {
        int x = i.second;
        ans += x*(x-1)/2;
    }
    for(int i=0;i<n;i++){
        int here = ans;
        int x = M[a[i]];
        here -= x*(x-1)/2;
        x--;
        here += x*(x-1)/2;
        cout<<here<<endl;
    }
}

signed main()
{
    fast;
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("out.txt", "w", stdout);
// #endif
    int t=1;
    // cin >>t;

    // fact[0] =1;
    // for(int i=1;i<N;i++){
    //     fact[i] = fact[i-1]*i;
    //     fact[i] %= MOD;
    // }
    // int i  =1;
    while(t--){
        // int n = i++;
        solve();
        
    }
    return 0;
}

/*****************************

1
10 3
1 5 1
3 6 1
6 9 1


**************************/

Measured memory_bytes: 11136
#include<stdio.h>
long long int mini(long long int a,long long int b){
  if(a>b) return b;
  return a;
}
int main(void){
  long long int l,r,i,j,ans=1e9;
  scanf("%lld %lld",&l,&r);
  if(r-l < 2019){
    for(i=l;i<r;i++){
      for(j=i+1;j<=r;j++){
        ans = mini(ans,(i*j)%2019);
      }
    }
  }
  else ans = 0;
  printf("%lld\n",ans);
  return 0;
}

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

#define fio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i >= b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define ll long long
#define pb push_back
#define sz(v) v.size()
#define pln(a)  cout<<a;
#define rr return 0;
#define rr1 return 1;
#define vr return;
#define int long long 

void solve()
{
  string s;
  cin>>s;
  for0(i, s.length()) {
    if(s[i] == '?')
      s[i] = 'D';
  }
  
  cout<<s;
}

signed main() {

  fio;
  
  
  //tc(t) {
    solve();
    pln("\n");
  //}
  
  rr;
}

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

int main(void) 
{
  int i, j, N;
  signed int tmp, *A;
  scanf("%d", &N);

  /* 整数Ｎ個を要素に持つ配列を確保する */
  A = (int *) malloc(sizeof(int) * N);

  for (i = 0; i < N; i++) 
    scanf(" %d", &A[i]);
 
  for (i = 0; i < N - 1; i++) 
    printf("%d ", A[i]);

  printf("%d\n", A[N - 1]);
 
  /* 挿入ソート */
  for (i = 1; i < N; i++) { 
    
    tmp = A[i];
    
    /* iから始める */
    j = i;
    
    /* A[j] < A[j - 1] であれば要素を入れ替えて、jをデクリメント */
    while (A[j] < A[j - 1] && j > 0) {
      A[j]     = A[j - 1];
      A[j - 1] = tmp;
      j--;
    }
    
    for (j = 0; j < N - 1; j++) 
      printf("%d ", A[j]);
    
    printf("%d\n", A[N - 1]);
  }
  return 0;
}

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

int main()
{
	int n;
	ll m;
	cin >> n >> m;
	vector<ll> a(n);
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	vector<ll> f(1 << n), lcm(1 << n, 1);
	for (int i = 1; i < (1 << n); i++) {
		int t = i & (i - 1);
		int b = __builtin_ctz(i - t);
		lcm[i] = lcm[t];
		ll tmp = a[b] / __gcd(lcm[i], a[b]);
		if (tmp > (m + lcm[i] - 1) / lcm[i]) {
			lcm[i] = m + 1;
		}
		else {
			lcm[i] *= tmp;
		}
		f[i] = (__builtin_popcount(i) & 1 ? 1 : -1) * m / lcm[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < (1 << n); j++) {
			if ((j & (1 << i))) {
				f[j] += f[j ^ (1 << i)];
			}
		}
	}
	ld res = 0;
	for (int i = 0; i < (1 << n); i++) {
		ld x = 1;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				x *= (ld)p[j] / 100;
			}
			else {
				x *= (ld)(100 - p[j]) / 100;
			}
		}
		res += f[i] * x;
	}
	cout << fixed << setprecision(10) << res << endl;
	return 0;
}



Measured memory_bytes: 19200
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const int mod=1e9+7;
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int a[100010],v[100010],id[100010];
LL jc[100010],p[100010];
LL C(int n,int m){
    return jc[m]*powmod(jc[n],mod-2)%mod*powmod(jc[m-n],mod-2)%mod;
}
int main(){
//    freopen("C-small-attempt1.in","r",stdin);
//    freopen("output.txt","w",stdout);
    int n;
    jc[0]=1;
    for(int i=1;i<=100001;i++) jc[i]=jc[i-1]*i%mod;
    cin>>n;
    int x;
    for(int i=1;i<=n+1;i++){
        cin>>a[i];
        v[a[i]]++;
        if(v[a[i]]==2) x=i;
        else id[a[i]]=i;
    }
//    for(int i=0;i<id[a[x]];i++){
//        for(int j=0;j<=n+1-x;j++){
//            p[i+j]+=C(i,id[a[x]]-1)*C(j,n+1-x)%mod;
//            p[i+j]%=mod;
//        }
//    }
    int g=id[a[x]]-1+n+1-x;
    cout<<n<<endl;
    for(int i=2;i<=n;i++){
        LL ans=C(i,n+1);
        ans=((ans-C(i-1,g))%mod+mod)%mod;
        cout<<ans<<endl;
    }
    puts("1");
	return 0;
}
/*
*/


Measured memory_bytes: 3200
#include <iostream>
#include <string>
using namespace	std;
int main(){

  string s;
  cin>>s;
  for(int i=0,r=0;i<s.size();i++){
    if(s[i]=='*'){
      cout<<r<<endl;
      return 0;
    }
    else if(s[i]=='(') r++;
    else r--;
  }
}

Measured memory_bytes: 3200
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll H, W;
    cin >> H >> W;
    vector<string> A(H);
    REP(i, H)
    cin >> A[i];

    //予め移動した全部のマスの数を数え上げる
    ll count_all = 0;
    REP(i, H)
    REP(j, W)
    if (A[i][j] == '#')
        count_all++;

    //下に移動することを1、右に移動することを0で表現する
    REP(bf, 1 << H + W - 2)
    {
        ll cx = 0, cy = 0;
        ll current_count = count_all - 1; //初期位置は通過済み
        REP(k, H + W - 2)
        {
            //一つ下のマスに移動
            if (bf >> k & 1)
                cx++;
            //一つ右のマスに移動
            else
                cy++;

            //範囲外に出た場合はスキップ
            if (cx >= H || cy >= W)
                continue;

            //通過したかチェック
            if (A[cx][cy] == '#')
                current_count--;
        }

        //すべてのマスを通過できる移動パターンが見つかった場合
        if (current_count == 0)
        {
            cout << "Possible" << endl;
            return 0;
        }
    }

    cout << "Impossible" << endl;

    return 0;
}


Measured memory_bytes: 3092
import math
D,G = map(int,input().split())
p=[]
c=[]
for i in range(D):
    p_tmp,c_tmp = map(int,input().split())
    p.append(p_tmp)
    c.append(c_tmp)

ans = sum(p)
for i in range(2**D):
    score_tmp = 0
    ans_tmp = 0
    for j in range(D):
        if (i>>j)%2 == 1:
            score_tmp += p[j]*(j+1)*100+c[j]
            ans_tmp += p[j]

    if ans_tmp >= ans:
        continue
    elif score_tmp >= G:
        ans = ans_tmp
        continue
    else:
        for j in range(D):
            if (i>>(D-1-j))%2 == 1:
                continue
            elif score_tmp + p[D-1-j]*(D-j)*100 < G:
                break
            else:
                ans_tmp += math.ceil((G - score_tmp)/((D-j)*100))
                ans = min(ans,ans_tmp)
                break

print(ans)


Measured memory_bytes: 3188
//By Zank100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define din(t) long long t;cin>>t;
#define in(t) cin>>t;
ll mul(ll a, ll b)
{
    return(((a%mod)*(b%mod))%mod);
}
ll modexp(ll b, ll e){
	ll res = 1;
	for(; e; b = b * b % mod, e >>= 1) if(e & 1) res = res * b % mod;
	return res;
}
ll modinv(ll a){
    ll x=mod-2;
	return modexp(a,x);
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	din(t);
	cout<<t + t*t + t*t*t<<endl;
	return 0;
}


Measured memory_bytes: 3568
N = int(input())
ans = 0
yakusu = []

for i in range(1,int(N**0.5)+1):
    if N%i == 0:
        yakusu.append(i)
        if i != N//i:
            yakusu.append(N//i)
yakusu.sort()

for i in range(len(yakusu)-1):
    if yakusu[i+1] - yakusu[i] > 1:
        for m in range(yakusu[i+1], yakusu[i], -1):
           if N//m == N%m:
               ans += m 
               break

print(ans)

Measured memory_bytes: 3296
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using ll = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
     
int main() {
    ll H, N;
    cin >> H >> N;
    vector<ll> A;
    for (int i = 0; i < N; i++ ) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    if( H - accumulate( A.begin(), A.end(), 0 ) <= 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1400
from itertools import permutations
n = int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))

num = [0]*n
for i in range(n):
    num[i] = i+1

cnt = 1
for i in permutations(num):
    if P == list(i):
        a = cnt + 1
    if Q == list(i):
        b = cnt + 1
    cnt += 1
print(abs(a-b))

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

int main(){
    long N; cin>>N;
    vector<long> a(5, 0);

    char c[5] = {'M','A','R','C','H'};
    ll count = 0;
    rep(i, N){
        string S; cin>>S;
        rep(j, 5){
            if(S[0] == c[j]){
                a[j]++;
                count++;
                break;
            }
        }
    }

    ll ans = 0;
    rep(i, 5){
       FOR(j, i+1, 5){
           FOR(k, j+1, 5){
               ans += a[i]*a[j]*a[k];
           }
       }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3636
S = list(input())
T = list(input())
ans = 0

for i in range(0, len(S)):
    if (S[i] != T[i]):
        ans = 0
        break    
    else :
      if(len(S)+1 == len(T)):
        ans = 1
      elif(len(S)>=len(T)):
        ans = 2
      elif(len(S)+1 < len(T)):
        ans = 3

if(ans == 1):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9036
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int N;
string S;

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

  cin >> N;
  cin >> S;
  ll K=0;
  ll ans = 1ll;
  // Wは偶数回、Bは奇数回ひっくり返さないといけない。
  // もし自分が左側としてひっくり返すなら自分はK+1回ひっくり返される.
  // 逆に右側としてひっくり返すなら自分はK回ひっくり返される.
  rep(i, 2*N){
    if ((S[i]=='W')==(K%2==0)){
      ans*=K;
      ans%=MOD;
      K--;
      if (K<0) break;
    } else K++;
  }

  if (K !=0) {
    cout << 0 << "\n";
    return 0;
  }

  for(ll i=1; i<=N; i++){
    ans*=i;
    ans%=MOD;
  }

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 720
#include <stdio.h>

int check_size(int size)
{
	if (size <= 60) return (0);
	if (size <= 80) return (1);
	if (size <= 100) return (2);
	if (size <= 120) return (3);
	if (size <= 140) return (4);
	if (size <= 160) return (5);
	return (6);
}

int check_weight(int weight)
{
	if (weight <= 2) return (0);
	if (weight <= 5) return (1);
	if (weight <= 10) return (2);
	if (weight <= 15) return (3);
	if (weight <= 20) return (4);
	if (weight <= 25) return (5);
	return (6);
}

int main(int argc, char const *argv[])
{
	int n;

	while (scanf("%d", &n), n){
		int i, j;
		int sum = 0;

		for (i = 0; i < n; i++){
			int x, y, h, w;
			int res;

			scanf("%d%d%d%d", &x, &y, &h, &w);
			res = fmax(check_size(x + y + h), check_weight(w));
			if (res < 6) sum += 600 + res * 200;
		}

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

	return (0);
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
int main()
{
  int n, d;
  cin>>n>>d;
  
  int count  = 0;
  for(int i=0;i<n;i++)
  {
    ull a, b;
    cin>>a>>b;
    
    double temp = sqrt(a*a + b*b);
    if(temp<= d)
      count++;
  }
  cout<<count<<"\n";
    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct Point{
  double x,y;
  Point(){}
  Point(double x,double y):x(x),y(y){}
  Point operator+(Point a){return Point(x+a.x,y+a.y);}
  Point operator-(Point a){return Point(x-a.x,y-a.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}
};
typedef Point Vector;
typedef vector<Point> Polygon;
struct Segment{
  Point p1,p2;
  Segment(){}
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

struct multi{
  int po;
  Point p;
  Segment s;
  multi():po(-1){}
  multi(Point p):po(1),p(p){}
  multi(Segment s):po(0),s(s){}
};

double norm(Vector a){
  return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
  return sqrt(norm(a));
}

double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}

double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}

#define EPS (1e-10)

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>EPS) return 1;
  if(cross(a,b)<-EPS) return -1;
  if(dot(a,b)< -EPS) return 2;
  if(norm(a)<norm(b)) return -2;
  return 0;
}

Point getCrossPointLL(Line l1,Line l2){
  double a=cross(l1.p2-l1.p1,l2.p2-l2.p1);
  double b=cross(l1.p2-l1.p1,l1.p2-l2.p1);
  if(abs(a)<EPS&&abs(b)<EPS) return l2.p1;
  return l2.p1+(l2.p2-l2.p1)*(b/a);
}

Point project(Segment s,Point p){
  Vector base=s.p2-s.p1;
  double r=dot(p-s.p1,base)/norm(base);
  return s.p1+base*r;
}
Point reflect(Segment s,Point p){
  return p+(project(s,p)-p)*2.0;
}

multi ope(multi a,multi b){
  if(a.po==1&&b.po==1){
    return multi(Line(a.p,b.p));
  }
  if(a.po==0&&b.po==0){
    return multi(getCrossPointLL(a.s,b.s));
  }
  if(a.po) swap(a,b);
  return multi(reflect(a.s,b.p));
}


multi expr(string s,int &p);
multi factor(string s,int &p);
int number(string s,int &p);

multi expr(string s,int &p){
  //cout<<"e:"<<p<<endl;
  multi res=factor(s,p);
  while(p<(int)s.size()){
    if(s[p]=='@'){
      p++;
      multi tmp=factor(s,p);
      res=ope(res,tmp);
      continue;
    }
    break;
  }
  return res;
}

multi factor(string s,int &p){
  //cout<<"f:"<<p<<endl;
  multi res;
  assert(s[p]=='(');
  p++;
  if(isdigit(s[p])||s[p]=='-'){
    int x=number(s,p);
    assert(s[p]==',');
    p++;
    int y=number(s,p);
    res=multi(Point(x,y));
  }else{
    res=expr(s,p);
  }
  //cout<<"fe:"<<p<<endl;
  assert(s[p]==')');
  p++;
  return res;
}

int number(string s,int &p){
  int f=1;
  if(s[p]=='-') f=-1,p++;
  int res=0;
  while(isdigit(s[p])) res=res*10+s[p++]-'0';
  return f*res;
}

signed main(){
  string s;
  while(cin>>s,s!="#"){
    int p=0;
    multi ans=expr(s,p);
    printf("%.12f %.12f\n",ans.p.x,ans.p.y);
  }
  return 0;
}

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

int main() {
  string a, b, c, i;
  cin >> a >> b >> c;
  
  char d, e, f;
  d = a.at(0) - 32;
  e = b.at(0) - 32;
  f = c.at(0) - 32;
  
  cout << d << e << f << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

void Aa(char* a){
    for(int i=0;i<11;i++){
        if(65 <= a[i] && a[i] <=90){
            a[i] = a[i] + 32;
        }
    }
    return;
}


int main(){


    char key[11];
    char Exit[] = "END_OF_TEXT";
    int Ans = 0;

    Aa(key);

    scanf("%s",key);
    //printf("%s\n",key);


    while(1){
        char buff[1001];
        scanf("%s",buff);
        bool aa = true;

        for(int i = 0;i < 11;i++){
            if(buff[i] != Exit[i]){
                aa = false;
                break;
            }
        }
        if(aa){
            break;
        }

        
        Aa(buff);
        //printf("%s\n",buff);
        //printf("%d\n",strcmp(buff,Exit));

        if(strcmp(buff,key) == 0){
            Ans++;
        }
        
        
        //printf("%d\n",Ans);
    }
    printf("%d\n",Ans);


    return 0;
}



Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#define ll long long
#define INF 0x3f3f3f3f
#define SIS std::ios::sync_with_stdio(false)
using namespace std;

int main()
{
    SIS;
    int n;
    while(cin>>n)
    {
        vector <int> s;
        int num;
        for(int i=0;i<n;i++)
        {
            cin>>num;
            s.push_back(num);
        }
        sort(s.begin(),s.end());
        for(int i=0;i<n;i++)
            if(i==0)
                cout<<s[i];
            else
                cout<<" "<<s[i];
        cout<<endl;
    }
    return 0;
}



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

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll x;
    cin>>x;

    ll ans = 0;
    for(ll i=1;i<=100000;++i){
        if(i * 100 <= x and x <= i * 100 + 5 * i){
            ans = 1;
            break;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4700