akhauriyash/Code-Regression huggingface dataset:
/*
 *      ┌─┐       ┌─┐ + +
 *   ┌──┘ ┴───────┘ ┴──┐++
 *   │                 │
 *   │       ───       │++ + + +
 *   ███████───███████ │+
 *   │                 │+
 *   │       ─┴─       │
 *   │                 │
 *   └───┐         ┌───┘
 *       │         │
 *       │         │   + +
 *       │         │       Code is far away from bug with the animal protecting
 *       │         └──────────────┐
 *       │                        │
 *       │                        ├─┐
 *       │                        ┌─┘
 *       │                        │
 *       └─┐  ┐  ┌───────┬──┐  ┌──┘  + + + +
 *         │ ─┤ ─┤       │ ─┤ ─┤
 *         └──┴──┘       └──┴──┘  + + + +
 *                神兽保佑
 *               代码无BUG!
 */

#include<bits/stdc++.h>
using namespace std;
class IN{
public:
    template<typename T>
    IN& operator >>(T &x){read(x);return *this;}
    IN& operator >>(double &x){scanf("%lf",&x);return *this;}
    IN& operator >>(char *s){scanf("%s",s);return *this;}
    IN& operator >>(char &c){c=getchar();return *this;}
private:
    template<typename T>
    void read(T &x){
        T f=1;int c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
        while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
        x*=f;
    }
}in;
class NL{}nl;
class BK{}bk;
class OUT{
public:
    template<typename T>
    OUT& operator <<(T x){write(x);return *this;}
    OUT& operator <<(const char *s){printf("%s",s);return *this;}
    OUT& operator <<(char c){putchar(c);return *this;}
    OUT& operator <<(BK x){putchar(' ');return *this;}
    OUT& operator <<(NL x){putchar('\n');return *this;}
private:
    template<typename T>
    void write(T x){
        if(x<0)putchar('-'),x=-x;
        if(x>=10)write(x/10);
        putchar(x%10+48);
    }
}out;

#define pb(x) push_back(x)
#define fi first
#define se second
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define mem(a,x) memset(a,x,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;
/*****************************************************************************************************/
ll Pow(ll a,ll b,ll mod){ll res=1;a%=mod;while(b){if(b&1)(res*=a)%=mod;(a*=a)%=mod;b>>=1;}return res%mod;}
ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}//p为素数,a<p
ll C(ll n,ll m,ll p){ll res=1;for(ll i=1,j=n-m+1;i<=m;++i,++j){res=res*inv(i,p)%p*j%p;}return res;}
/*****************************************************************************************************/
const int N=2e5+10;
int a[N];

int main(){
    int n;
    in>>n;
    map<int,int> mp;
    rep(i,1,n){
        in>>a[i];
        mp[a[i]]++;
    }
    ll sum=0;
    for(auto x:mp)
        sum+=(ll)(x.se)*(x.se-1)/2;
    rep(i,1,n){
        ll x=mp[a[i]];
        ll ans=sum-(x*(x-1)/2);
        --x;
        if(x>=2)ans+=x*(x-1)/2;
        out<<ans<<nl;
    }
    return 0;
}


Measured memory_bytes: 8320
#define DivertaPC2019_E
#ifdef DivertaPC2019_E

#pragma comment (linker, "/STACK:256000000")
#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 BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

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

int N;
vll A, sumA;
vi zero;

int main() {
    cin >> N;
    A.resize(N);
    sumA.resize(N + 1);
    zero.resize(N + 2);
    rep(i, N) {
        cin >> A[i];
        sumA[i + 1] = sumA[i] ^ A[i];
    }
    rep(i, 1, N + 1) {
        zero[i + 1] = zero[i];
        if (sumA[i] == 0) zero[i + 1]++;
    }

    if (sumA[N] != 0) {
        vi indices(1, 0);
        rep(i, 1, N + 1) {
            if (sumA[i] == sumA[N]) indices.push_back(i);
        }

        ll dp0 = 1, dp1 = 0;
        rep(i, 0, indices.size() - 1) {
            int n_zero = zero[indices[i + 1]] - zero[indices[i]];
            ll tmp = (dp0 + dp1 * n_zero) % MOD;
            dp0 = tmp;
            dp1 = (dp1 + tmp) % MOD;
        }
        ll ans = dp0;
        write(ans);

        //vv<ll> dp = vvec(N + 1, 2, (ll)0);
        //dp[0][0] = 1;
        //rep(i, 0, N) {
        //    dp[i + 1][0] = dp[i][0];
        //    dp[i + 1][1] = dp[i][1];
        //    if (sumA[i + 1] == sumA[N]) {
        //        dp[i + 1][1] += dp[i][0];
        //        dp[i + 1][1] %= MOD;
        //    }
        //    else if (sumA[i + 1] == 0) {
        //        dp[i + 1][0] += dp[i][1];
        //        dp[i + 1][0] %= MOD;
        //    }
        //}
        //write(dp[N][0]);
    }
    else {
        rep(i, 1, N + 1) cerr << sumA[i] << " ";
        cerr << endl;

        vv<int> indices = vvec(1 << 20, 1, 0);
        rep(i, 1, N + 1) {
            indices[sumA[i]].push_back(i);
        }

        ll ans = modulo_pow(2, zero[N + 1] - 1);

        rep(x, 1, 1 << 20) {
            if (indices[x].size() < 2) continue;

            ll dp0 = 1, dp1 = 0;
            rep(i, 0, indices[x].size() - 1) {
                int n_zero = zero[indices[x][i + 1]] - zero[indices[x][i]];
                ll tmp = (dp0 + dp1 * n_zero) % MOD;
                dp0 = tmp;
                dp1 = (dp1 + tmp) % MOD;
            }

            ans += dp1;
            ans %= MOD;
        }

        write(ans);
    }
}

#endif

Measured memory_bytes: 70268
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int Q=633,MOD=1e9+7;
int f[Q][Q];
int g[Q];
int ct[Q];
int to[Q];
inline int mul(int a,int b)
{return 1LL*a*b%MOD;}
inline int add(int a,int b)
{a+=b;return a>=MOD?a-MOD:a;}
inline int sub(int a,int b)
{a-=b;return a<0?a+MOD:a;}
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1,x,y;i<=k;i++){
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);
        to[x]=y,to[y]=x;
        ++ct[x],++ct[y];
    }
    for(int i=1;i<=(n<<1);i++)
        ct[i]=ct[i-1]+(ct[i]==0);
    g[0]=1;
    int als=0;
    for(int i=2;i<=(n<<1);i+=2)
        g[i]=mul(g[i-2],i-1);
    for(int t=1;t<=(n<<1);t++)
        for(int i=1,j;(j=i+t-1)<=(n<<1);i++){
            int fl=1;
            for(int k=i;k<=j;k++)
                if(to[k]&&(to[k]<i||to[k]>j)){
                    fl=0;
                    break;
                }
            if(!fl)continue;
            f[i][j]=g[ct[j]-ct[i-1]];
            for(int k=i;k<j;k++)
                f[i][j]=sub(f[i][j],mul(f[i][k],g[ct[j]-ct[k]]));
            als=add(als,mul(f[i][j],g[(n<<1)-(k<<1)-(ct[j]-ct[i-1])]));
        }
    printf("%d",als);
    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; ++i) cin >> A[i];
    
    int res = 0;
    for(int i = 0; i < N; ++i) {
        while(i+1 < N && A[i] == A[i+1]) ++i;
        
        if(i+1 < N && A[i] < A[i+1]) {
            while(i+1 < N && A[i] <= A[i+1]) ++i;
        } else if(i+1 < N && A[i] > A[i+1]){
            while(i+1 < N && A[i] >= A[i+1]) ++i;
        }
        
        ++res;
    }
    
    cout << res << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>



int main () {
    int a, b, c;
    std::cin >> a >> b >> c;

    std::vector<int> di;
    di.push_back(a + b);
    di.push_back(b + c);
    di.push_back(c + a);

    std::cout << *std::min_element(di.begin(), di.end()) << "\n";
}

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

using namespace std;

using i64 = long long;

const i64 MOD = 998244353;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;


signed main(){
    int m;
    string s;
    cin >> m >> s;
    vector<int> v;
    int n = s.size();
    string st = "RGB";
    for(int i = 0; i < n; ++i)
        v.push_back(st.find(s[i]));
    vector<int> lrd(n, -1);
    vector<int> fl(8, 0);
    fl[0] = m;
    for(int i = 0; i < n; ++i){
        vector<pair<int,int>> t;
        for(int j = 0; j < 7; ++j)
            if(!(j & (1 << v[i])))
                t.emplace_back(__builtin_popcount(j), j);
        sort(t.begin(), t.end(), greater<>());
        for(auto& p : t){
            int j = p.second;
            if(fl[j]){
                --fl[j];
                ++fl[j | (1 << v[i])];
                lrd[i] = p.first;
                break;
            }
        }
    }

    mint ans = 1;
    vector<int> cnt(3, 0);
    for(int i = 0; i < n; ++i){
        if(lrd[i] == 0)
            ++cnt[0];
        else{
            ans *= cnt[lrd[i] - 1];
            --cnt[lrd[i] - 1];
            ++cnt[lrd[i]];
        }
    }
    assert(cnt[2] == m);
    for(int i = 0; i < m; ++i)
        ans *= i + 1;

    cout << ans << endl;
}



Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int n, m, l[100009], r[100009], ans;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; ++ i)
    {
        cin >> l[i] >> r[i];
    }
    ans = *min_element(r + 1, r + 1 + m) - *max_element(l + 1, l + 1 + m) + 1;
    cout << max(ans, 0);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A + B == C + D){
    cout << "Balanced" <<endl;
  }
  else if (A + B > C + D){
    cout << "Left" <<endl;
  }
  else{
    cout << "Right" <<endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int h = scan.nextInt();
        int n = scan.nextInt();
        int sum = 0;
        for(int i = 0; i < n; i++) {
            sum += scan.nextInt();
        }
        System.out.println(h <= sum ? "Yes" : "No");
    }
}

Measured memory_bytes: 45944
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

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

int main(){
  int N, M; cin >> N >> M;

  vector<pair<ll, ll>> AB;
  for(int i = 0; i < N; i++){
    ll a, b; cin >> a >> b;
    AB.push_back(make_pair(a,b));
  }

  sort(AB.begin(), AB.end());

  ll ans = 0;
  ll rest = M;
  for(int i = 0; i < N; i++){
    ll AT = AB[i].first;
    ll BT = AB[i].second;
    if(rest >= BT){
      ans += AT * BT;
      rest -= BT;
    } else {
      ans += AT * rest;
      rest = 0;
    }
    if(rest == 0) break;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 2420
import java.util.*;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
	    int[] number = new int[N];
	    int count = 0;

	    for(int i=0; i<N; i++){
	      number[i] = sc.nextInt();
	    }
	    for(int i=1; i<N-1; i++){
	      if((number[i-1]<=number[i])&&(number[i]<=number[i+1])){
	        count++;
	      }else if((number[i+1]<=number[i])&&(number[i]<=number[i-1])){
	        count++;
	      }
	    }
	    System.out.println(count);
	}

}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define read(a)  for(int i = 0; i < n; i++) cin >> a[i];
#define print(a)  for(int i = 0; i < n; i++) cout << a[i] << " ";
#define pb push_back
#define ins insert
#define pql priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define pqlv priority_queue<vi>
#define pqsv priority_queue<vi, vvi, greater<vi>>
#define endl '\n'

signed main() {
    int n, a, b;
    cin >> n >> a >> b;
    if(a % 2 == b % 2) {
        cout << (b - a) / 2;
    }
    else {
        int must = min({ a - 1, n - b });
        cout << must + 1 + (b - a - 1) / 2;
    }
}

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

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

  int n,q;
  int count = 0;
  cin >> n;
  int *S = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  int x;
  for (int i = 0; i < q; i++) {
    cin >> x;
    int left = 0;
    int right = n;
    int mid;
    while (left < right) {
      mid = (left + right) / 2;
      if (S[mid] == x) {
        count++;
        break;
      } else if (S[mid] < x) {
        left = mid + 1;
      } else {
        right = mid;
      }
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 1592
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

const int MOD = 1000000007;

const int MAX_N = 2000010;
long long fac[MAX_N + 1], finv[MAX_N + 1];

struct init_fac {
    long long mod_inv(long long a, long long m) {   // gcd(a, m) = 1
        long long b = m, x = 1, y = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(x -= t * y, y);
        }
        x = (x % m + m) % m;
        return x;
    }

    init_fac() {
        fac[0] = 1;
        for (int i = 1; i <= MAX_N; ++i) fac[i] = i * fac[i - 1] % MOD;
        finv[MAX_N] = mod_inv(fac[MAX_N], MOD);
        for (int i = MAX_N - 1; i >= 0; --i) finv[i] = (i + 1) * finv[i + 1] % MOD;
    }
} init_fac;

long long nPk(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fac[n] * finv[n - k] % MOD;
}

long long nCk(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return nPk(n, k) * finv[k] % MOD;
}

long long nHk(int n, int k) {
    if (n < 0 || k < 0) return 0;
    return nCk(n + k - 1, k);
}

void _main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    REP (i, min(n, k) + 1) {
        (ans += nCk(n, i) * nCk(n - 1, i) % MOD) %= MOD;
    }
    cout << ans << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("in.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("out.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 31488
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999
#define ALL(x) (x).begin(), (x).end()
#define LBi(x, n) lower_bound(ALL(x), n) - (x).begin()
#define ZIP(x) (x).erase(unique(ALL(x)), (x).end())
#define Pi pair<int, int>
#define Vi vector<int>

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

string s = "";
char ch[10];
int n, a, b, c, d, x, m[5];

int main() {
	cin >> a >> b;
	cout << (a*b % 2 ? "Odd" : "Even") << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

int solve(vector<int>s,vector<int>t,vector<int>ans,int n, int k,bool flag) {
	if (n == -1) {
		int sum=0;
		for (int i = 0; i < ans.size(); ++i) {
			sum*=10;
			sum+=ans[i];
		}
		return sum;
	}
	else {
		int nu=s[n]-t[n]-int(flag);
		if (nu>=0) {
			ans.insert(ans.begin(),nu);
			return solve(s,t,ans,n-1,k,false);
		}
		else {
			ans.insert(ans.begin(),10+nu);
			int sum=0;
			if (k) {
				sum=solve(s,t,ans,n-1,k-1,false);
			}
			 {
				sum=max(sum,solve(s,t,ans,n-1,k,true));
			}
			
			return sum;
		}
	}
}

int main()
{
	string s,t;cin>>s>>t;
	int k;cin>>k;
	while (t.size() < s.size()) {
		t="0"+t;
	}
	vector<int>sv,tv;
	for (int i = 0; i < s.size(); ++i) {
		sv.push_back(s[i]-'0');
		tv.push_back(t[i]-'0');
	}
	vector<int>aans;
	int ans=solve(sv,tv,aans,s.size()-1,k,false);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3220
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int[] n = SpRead(' ').Select(i => int.Parse(i)).ToArray();
        Console.WriteLine(n[0] + n[1]/2);
    }

}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }

}


Measured memory_bytes: 11220
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(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;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll mark[2*n];
    mark[0]=1;
    if(s[0]=='W')
    {
        cout<<0<<'\n';
        return;
    }
    for(int i=1;i<2*n;i++)
    {
        if(s[i]==s[i-1])
        {
            mark[i]=mark[i-1]*-1;
        }
        else
        {
            mark[i]=mark[i-1];
        }
    }
    ll cnt=0;
    for(int i=0;i<2*n;i++)
    {
        cnt+=mark[i];
        if(cnt<0)
        {
            cout<<0<<'\n';
            return;
        }
    }
    if(cnt!=0)
    {
        cout<<0<<'\n';
        return;
    }
    ll r=0;
    ll ans=1;
    for(int i=2*n-1;i>=0;i--)
    {
        if(mark[i]==-1)
            r++;
        else
        {
            ans*=r;
            ans%=mod;
            r--;
        }
    }
    ll mult=1;
    for(int i=1;i<=n;i++)
    {
        mult*=i;
        mult%=mod;
    }
    ans*=mult;
    ans%=mod;
    cout<<ans<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 17148
#include<iostream>
#include<cstdio>
#include<cmath>
#define EPS 1e-10
using namespace std;

int main(){
  double x1,x2,x3,xp,y1,y2,y3,yp;
  while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
    double A = sqrt(pow(x1-x2,2)+pow(y1-y2,2)),B = sqrt(pow(x2-x3,2)+pow(y2-y3,2)), C = sqrt(pow(x1-x3,2)+pow(y1-y3,2)) ;
    double s = (A+B+C)/2.0;
    double S = sqrt(s*(s-A)*(s-B)*(s-C));
 
   double A12 = sqrt(pow(x1-x2,2)+pow(y1-y2,2)),B1p =sqrt(pow(x1-xp,2)+pow(y1-yp,2)), C2p = sqrt(pow(xp-x2,2)+pow(yp-y2,2)) ;
    double s2 = (A12+B1p+C2p)/2.0;
    double S2 = sqrt(s2*(s2-A12)*(s2-B1p)*(s2-C2p));
    /*
    if(S2 == 0){
      cout << "NO" << endl;
      break;
    }
    */
    double A13 = sqrt(pow(x1-x3,2)+pow(y1-y3,2)), Cp3 = sqrt(pow(xp-x3,2)+pow(yp-y3,2));
    double s3 = (A13+B1p+Cp3)/2.0;
    double S3 =  sqrt(s3*(s3-A13)*(s3-B1p)*(s3-Cp3));
    /*
    if(s3 == 0){
      cout << "NO" << endl;
      break;
    }
    */
    double A23 = sqrt(pow(x3-x2,2)+pow(y3-y2,2));
    double s4 = (A23+C2p+Cp3)/2.0;
    double S4 =  sqrt(s4*(s4-A23)*(s4-C2p)*(s4-Cp3));
    /*
    if(S3 == 0){
      cout << "NO" << endl;
      break;
    }
    */
    double Ssum = S2+S3+S4;
    
    fabs(Ssum - S)< EPS?cout << "YES" << endl:cout << "NO" << endl;


  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 n;
  cin >> n;
  for (int x = 1; x <= 9; ++x) {
    for (int y = 1; y <= 9; ++y) {
      if (x * y == n) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  int a[8] = {};
  int b = 0;
  rep(i,n) {
    int x;
    cin >> x;
    if(x >= 3200) b++;
    else a[x/400]++;
  } 
  int ans = 0;
  rep(i,8) {
    if(a[i]) ans++;
  }
  if(ans == 0) cout << 1 << " " << ans+b << endl;
  else cout << ans << " " << ans+b << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String x = br.readLine();
		System.out.println(x.replaceAll(",", " "));
	}
}

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

int main() {
  int N, T, A;
  cin >> N >> T >> A;
  int H[1000];
  for(int i = 0; i < N; i++) cin >> H[i];
  int t = 1000 * T, a = 1000 * A;
  int ans = 0;
  int res = 600000;
  for(int i = 0; i < N; i++) {
    if (res > max(t - a, H[i] * 6) - min(t - a, H[i] * 6)) {
      res = max(t - a, H[i] * 6) - min(t - a, H[i] * 6);
      ans = i + 1;                              
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
	map< int, int> l;
	int n, a[12], c;
	bool f;
	while(1) {
		cin >> n;
		if(!n) break;
		c = 0;
		for( int i=0; i<n; i++) cin >> a[i];
		while(1) {
			l.clear(); f = false;
			for( int i=0; i<n; i++) {
				if(l.count(a[i])==0) l[a[i]] = 1;
				else l[a[i]]++;
			}
			for( int i=0; i<n; i++) {
				if(a[i]!=l[a[i]]) { 
					a[i] = l[a[i]];
					f = true;
				}
			}
			if(!f) break;
			c++;
		}
		cout << c << endl;
		for( int i=0; i<n; i++) cout << a[i] << ( i==n-1 ? "" : " " );
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int x, y;
	int n;
	int[] xs, ys;

	// JG
	int[] dx={-1, 0, 1, -1, 0, 1, -2, -2, -2, 2, 2, 2};
	int[] dy={-2, -2, -2, 2, 2, 2, -1, 0, 1, -1, 0, 1};

	void run(){
		for(;;){
			x=sc.nextInt();
			y=sc.nextInt();
			if((x|y)==0){
				break;
			}
			n=sc.nextInt();
			xs=new int[n];
			ys=new int[n];
			for(int i=0; i<n; i++){
				xs[i]=sc.nextInt();
				ys[i]=sc.nextInt();
			}
			solve();
		}
	}

	void solve(){
		boolean f=false;
		for(int i=0; i<dx.length; i++){
			f|=dfs(x+dx[i], y+dy[i], 0);
		}
		println(f?"OK":"NA");
	}

	// ¿å¤ÇkÌXvN[ÉÀÁ½Cª·é
	boolean dfs(int x, int y, int k){
		if(k==n){
			return true;
		}
		if(x<0||x>=10||y<0||y>=10){
			return false;
		}
		if(x<xs[k]-1||x>xs[k]+1||y<ys[k]-1||y>ys[k]+1){
			return false;
		}
		boolean f=false;
		for(int i=0; i<dx.length; i++){
			f|=dfs(x+dx[i], y+dy[i], k+1);
		}
		return f;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

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

int main()
{
    int n, b, f, r, v;
    int room[4][3][10] = {0};
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> b >> f >> r >> v;
        room[b - 1][f - 1][r - 1] += v;
    }
    for (int b = 0; b < 4; b++)
    {
        for (int f = 0; f < 3; f++)
        {
            for (int r = 0; r < 10; r++)
            {
                cout << " " << room[b][f][r];
            }
            cout << "\n";
        }
        if (b < 3)
        {
            cout << "####################\n";
        }
    }
}




Measured memory_bytes: 3092
#include <iostream>

#define INF 100000000

using namespace std;

int main() {

  int pasta[5],juice[5];

  int min_pasta,min_juice;


  for(int i=0;i<3;i++) cin >> pasta[i];

  for(int i=0;i<2;i++) cin >> juice[i];

  min_pasta=INF;

  for(int i=0;i<3;i++) {

    if(min_pasta>pasta[i]) min_pasta=pasta[i];

  }

  min_juice=INF;

  for(int i=0;i<2;i++) {

    if(min_juice>juice[i]) min_juice=juice[i];

  }

  cout << min_pasta+min_juice-50 << endl;

  return 0;

}

Measured memory_bytes: 0
#include<stdio.h>

int main(void) {
        int i, a, b;
        int min, max;
        long sum;
        scanf("%d\n", &a);

        max=-1000000;
        min=1000000;
        sum = 0;
        for(i=0;i<a;i++) {
                scanf("%d", &b);
                if(b < min)     min=b;
                if(b > max)     max=b;
                sum+=b;
        }
        printf("%d %d %ld\n", min, max, sum);
        return 0;

}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int r,g,b;
    cin>>r>>g>>b;
    int tmp=100*r+10*g+b;
    if (tmp%4==0) {
        cout<<"YES"<<endl;
    } else {
        cout<<"NO"<<endl;
    }
}

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

vector<string> a;
const int MOD = 1000000007;

long long dp[1010][1010]={0};

int add(long long &a, long long b){
  a += b;
  if (a >= MOD) a -= MOD;
}

int main(){
  int h, w;
  cin >> h >> w;
  a.resize(h);
  for(int i=0;i<h;i++){
    cin >> a[i];
  }
  dp[0][0] = 1;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i+1<h&&a[i+1][j]=='.'){
        add(dp[i+1][j], dp[i][j]);
      }
      if(j+1<w&&a[i][j+1]=='.'){
        add(dp[i][j+1], dp[i][j]);
      }
    }
  }
  cout << dp[h-1][w-1] << endl; 
}



Measured memory_bytes: 9216
n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]
INF = 100000


def rec(i, x, y, z):
    if i >= n:
        return abs(a - x) + abs(b - y) + abs(c - z) if x * y * z > 0 else INF

    return min(rec(i + 1, x, y, z),
               rec(i + 1, x + l[i], y, z) + (10 if x > 0 else 0),
               rec(i + 1, x, y + l[i], z) + (10 if y > 0 else 0),
               rec(i + 1, x, y, z + l[i]) + (10 if z > 0 else 0))


print(rec(0, 0, 0, 0))

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

int main() {
  int N, ans = 0;
  string S;
  
  cin >> N ;
  
  for( int i =1; i <= N; i++ ) {
    
    S = to_string(i);
    if( S.size() % 2 == 1 ) {
      
      ans++;
      
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <ctime>
#include <cctype>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int Maxx = 1e5 + 7;
const ll Inf = 1e18;
const double PI = acos(-1.0);
queue <int> qua;
map <int, int> mp;
ll a, b, c, k;

int main() {
	cin >> a >> b >> c >> k;
	if(abs(a - b) > Inf || abs(b - a) > Inf) puts("Unfair");
	if(k & 1) printf("%lld\n", b - a);
	else printf("%lld\n", a - b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h> //ABC 162_b
#define ll long long
using namespace std;
int main(){
	int n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++){
		if(i%3==0||i%5==0)
			continue;
		ans+=i;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3680
#include<stdio.h>

#define SIZE 10000

int main(void){
    int num,count=0;
    int a[SIZE];
    int b[SIZE];
    
    scanf("%d",&num);
    
    for(int i=0;i<num;i++){
        scanf("%d",&a[i]);
    }
    
	int tmp;
    scanf("%d",&tmp);
    
    for(int i=0;i<SIZE;i++){
    	if(scanf("%d",&b[i])==EOF)break;
        
        for(int j=0;j<num;j++){
            if(a[j]==b[i]){
                count++;
                break;
            }
        }
    }
    
    printf("%d\n",count);
}


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


interface Ball{
    int getRadius();
    int getPoint();
    boolean isPlaced();
    int distanceTo(Ball another);
    boolean collide(Ball another);
    String coordinate();
}
class PlacedBall implements Ball{
    int radius;
    int point;
    int x, y, z;
    public PlacedBall(int r, int p, int x, int y, int z){
        this.radius = r;
        this.point = p;
        this.x = x;
        this.y = y;
        this.z = z;
    }
    public PlacedBall(Ball b, int x, int y, int z){
        this(b.getRadius(), b.getPoint(), x,y,z);
    }

    public int getRadius(){return radius;}
    public int getPoint(){return point;}
    public boolean isPlaced(){return true;}
    public int distanceTo(Ball another){
        if(another.isPlaced()){
            return (this.x-((PlacedBall)another).x)*(this.x-((PlacedBall)another).x) +
                   (this.y-((PlacedBall)another).y)*(this.y-((PlacedBall)another).y) +
                   (this.z-((PlacedBall)another).z)*(this.z-((PlacedBall)another).z) ;
        }else return 5000000;
    }
    public boolean collide(Ball another){
        return this.distanceTo(another) >= (this.getRadius()+another.getRadius())*(this.getRadius()+another.getRadius());
    }

    public String coordinate(){
        return x+" "+y+" "+z;
    }
}
class removedBall implements Ball{
    int radius;
    int point;
    public removedBall(int r, int p){
        this.radius = r;
        this.point = p;
    }
    public removedBall(Ball b){
        this(b.getRadius(), b.getPoint());
    }

    public int getRadius(){return radius;}
    public int getPoint(){return point;}
    public boolean isPlaced(){return false;}
    public int distanceTo(Ball another){
        return 5000000;
    }
    public boolean collide(Ball another){
        return false;
    }

    public String coordinate(){
        return "-1 -1 -1";
    }
}

class PairBonus{
    int ball1, ball2;
    int distance;
    int point;
    public PairBonus(int b1Num, int b2Num, int d, int p){
        this.ball1 = b1Num;
        this.ball2 = b2Num;
        this. distance = d*d;
        this.point = p;
    }
    public boolean getBonus(Ball b1, Ball b2){
        return b1.distanceTo(b2) <= this.distance;
    }
    public boolean getBonus(Ball[] balls){
        return getBonus(balls[ball1], balls[ball2]);
    }
}

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();


        int M = (N%2==0) ? N * (N-2) / 2 : ((N-1)*(N-3)/2 + N-1);
        System.out.println(M);
        for(int i=1; i<=N; i++) for(int j=i+1; j<=N; j++){
            if(i<j && i+j!=(N/2)*2+1) System.out.println(i+" "+j);
        }

    }
}


Measured memory_bytes: 24400
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;

int r[4010], g[4010], b[4010];
int main()
{
	int N;
	string S;
	cin >> N >> S;
	for (int i = 0; i < N; i++) {
		r[i + 1] = r[i];
		g[i + 1] = g[i];
		b[i + 1] = b[i];
		if (S[i] == 'R') r[i + 1]++;
		if (S[i] == 'G') g[i + 1]++;
		if (S[i] == 'B') b[i + 1]++;
	}
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (S[i] == S[j]) continue;
			int diff = j - i;
			if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R')) {
				ans += b[N] - b[j + 1];
				if (S[min(j + diff, N)] == 'B') ans--;
			}
			else if ((S[i] == 'B' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'B')) {
				ans += r[N] - r[j + 1];
				if (S[min(j + diff, N)] == 'R') ans--;
			}
			else {
				ans += g[N] - g[j + 1];
				if (S[min(j + diff, N)] == 'G') ans--;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3680
// 
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


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

    char s;
    cin>>s;
    if('a'<=s and s<='z') cout<<"a"<<endl;
    else cout<<"A"<<endl;
    return 0;
}

Measured memory_bytes: 3600
function main(input) {
  const s = input.trim()

  const array = s.split('').reduce((a, c) => {
    a[c.charCodeAt() - 'a'.charCodeAt()]++
    return a
  }, [0, 0, 0])

  if (Math.max(...array) - Math.min(...array) >= 2) {
    console.log('NO')
  } else {
    console.log('YES')
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 32468
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef  long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define F first
#define S second
#define pi 3.141592653589793238
#define INF 1e9+5

int main()
{

	ll n;
	cin>>n;
	ll a[n];
	ll dp[n];
    for(int x=0;x<n;x++){
        cin>>a[x];
        dp[x]=INF;
	}
	dp[0]=0;
	for(int x=0;x<n;x++){
        for(int y=x+1;y<=x+2;y++){
            if(y<n){
            dp[y]=min(dp[y],dp[x]+abs(a[x]-a[y]));
            }
        }
	}
	cout<<dp[n-1];



}


Measured memory_bytes: 1792
x,y,a,b,c = map(int,input().split())
pl = list(map(int,input().split()))
ql = list(map(int,input().split()))
rl = list(map(int,input().split()))

pl = sorted(pl)
ql = sorted(ql)
rl = sorted(rl)
ansl = pl[-x:] + ql[-y:]

ansl += rl

ansl = sorted(ansl)
print(sum(ansl[-(x+y):]))



Measured memory_bytes: 114156
h, w = map(int, input().split())
a = []
for _ in range(h):
    a.append(input())
    
sharpnum = 0
for ai in a:
    sharpnum += ai.count("#")
     
                
if sharpnum == (h+w - 1):
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;

  map<int, int> m;
  for (int i = 0; i < n; i++)
  {
    int a;
    cin >> a;
    if (a % 4 == 0)
    {
      m[4]++;
    }
    else if (a % 2 == 0)
    {
      m[2] = 1;
    }
    else
    {
      m[0]++;
    }
  }

  if (m[2] + m[0] <= m[4] + 1)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;
ll dp[10][2][8];//equal?,7,5,3
ll table[] = {7,5,3};

int main(){
    cin >> s;
    rep(i,s.size()+1){
        if(i == 0)dp[i][1][0] = 1;
        else dp[i][0][0] = 1;
    }
    rep(i,s.size()){
        ll snum = s[i] - '0';
        rep(j,8){
            ll now = j;
            rep(k,3){
                ll nxt = j | (1 << k);
                dp[i+1][0][nxt] += dp[i][0][now];
                if(snum > table[k])dp[i+1][0][nxt] += dp[i][1][now];
                if(snum == table[k])dp[i+1][1][nxt] += dp[i][1][now];
            }
        }
    }
    cout << dp[s.size()][0][7] + dp[s.size()][1][7] << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var A = ReadArrayLong();
            var B = ReadArrayLong();
            var nen = new List<long>();
            var en = new List<long>();
            for (int i = 0; i < N; i++)
            {
                if (A[i] < B[i]) nen.Add(B[i] - A[i]);
                else if (A[i] > B[i]) en.Add(A[i] - B[i]);
            }
            if (nen.Count() == 0) { Console.WriteLine(0); return; }
            else if(nen.Sum()>en.Sum()) { Console.WriteLine(-1); return; }
            nen = nen.OrderByDescending(l => l).ToList();
            en = en.OrderByDescending(l => l).ToList();
            var ans = nen.Count() + 1;
            var cnt = 0;
            for (int i = 0; i < nen.Count(); i++)
            {
                var rem = nen[i];
                while (rem > 0)
                {
                    if (en[cnt] >= rem)
                    {
                        en[cnt] -= rem;
                        rem = 0;
                    }
                    else if (en[cnt] < rem)
                    {
                        rem -= en[cnt];
                        en[cnt] = 0;
                        cnt++;
                        ans++;
                    }
                }
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 34756
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<(int)c;i++)
#define print(var) cout<<var<<endl;
#define DEBUG(var) cerr<<var<<endl;
// puts("str");

const int inf = 1000000000;//10^9

int main (){
  int A,B,ans;
  cin>>A>>B;
  ans=A*B;
  print(ans);


  return 0;

}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <cstring>

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

using namespace std;

class Dice {
private:
    vector<int> num, i_num;

public:
    enum FACE {TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM}; 
    enum MOVE {TOP_TO_FRONT, TOP_TO_RIGHT, TOP_TO_LEFT, TOP_TO_BACK, FRONT_TO_LEFT, FRONT_TO_RIGHT};

    const int tb[6][4] = {
        {FRONT, TOP, BACK, BOTTOM},
        {RIGHT, TOP, LEFT, BOTTOM},
        {LEFT, TOP, RIGHT, BOTTOM},
        {BACK, TOP, FRONT, BOTTOM},
        {LEFT, FRONT, RIGHT, BACK},
        {RIGHT, FRONT, LEFT, BACK}
    };

    Dice() 
    { 
        num.assign(6, -1);
        i_num.resize(6);
        i_num = {1, 3, 5, 2, 4, 6};
    }

    Dice(int t, int f) 
    {
        num.resize(6), i_num.resize(6);
        i_num = {1, 3, 5, 2, 4, 6};
        roll(t, f);
    }

    void set_identity(vector<int> i) { num = i_num = i; }

    int top() {return num[TOP];}
    int bottom() {return num[BOTTOM];}
    int right() {return num[RIGHT];}
    int left() {return num[LEFT];}
    int front() {return num[FRONT];}
    int back() {return num[BACK];}
    int get(FACE f) { return num[f]; }

    void rotate(int move)
    {
        int tmp = num[tb[move][0]];
        rep(i, 3) num[tb[move][i]] = num[tb[move][i+1]];
        num[tb[move][3]] = tmp;
    }
    
    void roll(int t, int f)
    {
        num = i_num;

        for (int j=0; j<6; j++) {
            for (int i=0; i<4; i++) {
                if (num[0] == t && num[1] == f) return;
                rotate(FRONT_TO_RIGHT);
            }
            if (j%2) rotate(TOP_TO_FRONT);
            else rotate(TOP_TO_RIGHT);
        }
    }

    void print()
    {
        cerr << "[" << num[0] << ", " << num[FRONT] << ", " 
            << num[RIGHT] << "]" << endl;
    };
};

int main()
{
    Dice d;

    vector<int> num(6);
    rep(i, 6) cin >> num[i];
    d.set_identity(num);

    string S;
    cin >> S;

    for (char s  : S) {
        if (s == 'S') d.rotate(d.TOP_TO_FRONT);
        if (s == 'W') d.rotate(d.TOP_TO_LEFT);
        if (s == 'N') d.rotate(d.TOP_TO_BACK);
        if (s == 'E') d.rotate(d.TOP_TO_RIGHT);
    }

    cout << d.get(d.TOP) << endl;
}

Measured memory_bytes: 3216
#include <stdio.h>


int ways;

void sum(int start, int n, int x, int total, int depth)
{
	int i;

	if (depth == 0){
		if (total == x){
			ways++;
		}
		return;
	}
	
	for (i = start; i <= n; i++){
		sum(i + 1, n, x, total + i, depth - 1);
	}
	return;
}


int main(void)
{
	int n, x;

	while (1){
		scanf("%d%d", &n, &x);

		if (n == 0 && x == 0){
			break;
		}
		
		ways = 0;
		sum(1, n, x, 0, 3);
		printf("%d\n", ways);
	}
	return (0);
}



Measured memory_bytes: 2056
def is_prime(n):
    if n == 1:
        return False

    i = 2
    while True:
        if i ** 2 >= n:
            return True
        if n % i == 0:
            return False
        i += 1

x = int(input())
for i in range(x, x ** 2):
    if is_prime(i):
        print(i)
        break


Measured memory_bytes: 2940
import sys

x, n = map(int, input().split())

if n == 0:
  print(x)
  sys.exit()
  
p = list(map(int, input().split()))

sub, up = x, x

while True:
  if sub not in p:
    print(sub)
    sys.exit()
  elif up not in p:
    print(up)
    sys.exit()
  sub -= 1
  up += 1

Measured memory_bytes: 9088
from sys import stdin

n,a,b = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

point = 0
for i in range(n-1):
    if (li[i+1]-li[i])*a < b:
        point += (li[i+1]-li[i])*a
    else:
        point += b

print(point)

Measured memory_bytes: 14480
n,m = map(int,input().split())

h = list(map(int,input().split()))

is_good = [True]*n

for i in range(m):
  a,b = map(int,input().split())
  if h[a-1] > h[b-1]:
    is_good[b-1] = False
  elif h[b-1] > h[a-1]:
    is_good[a-1] = False
  else:
    is_good[a-1] = False
    is_good[b-1] = False

cnt = 0
for i in is_good:
  if i == True:
    cnt += 1

print(cnt)

Measured memory_bytes: 20120
N = int(input())
p_list = list(map(int, input().split()))

r = {}
for i in range(N):
    r[p_list[i]] = i + 1

a_list = []
b_list = []
for i in range(1, N + 1):
    a_list.append(30000 * i)
    b_list.append(30000 * (N - i) + r[i])

print(*a_list)
print(*b_list)


Measured memory_bytes: 7728
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;




int main(){
  int n;
  set <int> s;
  cin >> n;
  vector <int> a;
  REP(i,n){
    int b;
    cin >> b;
    s.insert(b);
  }
  /*
  //sort(a.begin(),a.end());
  int b = a[0],num = 1;
  for(int i = 1;i < a.size();i++){
    if(b == a[i]){
      num++;
      if(i == a.size()-1){
	if(num != 1 && num%2 == 1){
	  cout << i << num <<endl;
	  a.erase(a.begin()+i+1-num,a.begin()+i);
	}
      }
    }
    
    else{
      b = a[i];
      //cout << num << endl;
      if(num != 1 && num%2 == 1){
	a.erase(a.begin()+i-num,a.begin()+i-1);
	i = i - num+1;
      }
      else if(num != 1 && num%2 == 0){
	//cout << 1 << endl;
	a.erase(a.begin()+i-num,a.begin()+i-1);
	i = i - num+1;
      }
      
      num = 1;
    }
  }
  b = a[0];
  num = 0;
  for(int i = 1;i < a.size();i++){
    if(a[i-1] == a[i])
      num++;
  }
  if(num%2 == 1)
    num++;
  int res = a.size();
  if(a.size()%2 == 0)
    res--;
  cout << res << endl;
  */
  /*
  REP(i,a.size()){
    cout << a[i] << "  ";
    }*/
  int res = s.size();
  if(res%2 == 0)
    res--;
  cout <<res << endl;
  return 0;
}


Measured memory_bytes: 4992