akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

const int INF = 1<<30;

int b;

int n;
int a[252521];
const int N = 1<<18;
pii seg[2*N];
pii qmin(int l, int r, int a, int b, int k){
  if(r<=a || b<=l)return pii(INF,INF);
  if(l<=a && b<=r)return seg[k];
  int m = (a+b)/2;
  return min(qmin(l,r,a,m,2*k+1),qmin(l,r,m,b,2*k+2));
}

ll dfs(int l, int r, int x){
  if(r==l)return 0;
  if(r-l==1)return 1;
  ll ret = 0;
  int cnt = 0;
  pii P = qmin(l,r,0,N,0);
  int v = P.first;
  int p = P.second;
  if(l<p)ret = min(ret+max(1ll,dfs(l,p,v)),1ll<<60);
  p++;
  while(p<r){
    P = qmin(p,r,0,N,0);
    if(P.first != v)break;
    int q = P.second;
    ret = min(ret+max(1ll,dfs(p,q,v)),1ll<<60);
    p = q+1;
  }
  ret = min(ret+max(1ll,dfs(p,r,v)),1ll<<60);
  int sa = v-x;

  ll a = b;
  ll c = sa;
  ll bsa = 1;
  while(c){
    if(c&1)bsa=min(bsa*a,1ll<<30);
    a=min(a*a,1ll<<30);
    c>>=1;
  }
  return (ret+bsa-1)/bsa;
}

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",a+i);
  // 1 check
  bool ok1 = true;
  REP(i,n-1)if(a[i]>=a[i+1]){
    ok1 = false; break;
  }
  if(ok1){
    puts("1");
    return 0;
  }
  // seg
  REP(i,n)seg[i+N-1] = pii(a[i],i);
  FOR(i,n,N)seg[i+N-1] = pii(INF,INF);
  FORR(i,0,N-1)seg[i] = min(seg[2*i+1],seg[2*i+2]);

  int low = 1, high = n+10;
  while(low+1<high){
    b = (low+high)/2;
    ll ret = dfs(0,n,0);
    if(ret<=1){
      high = b;
    }else{
      low = b;
    }
  }
  printf("%d\n",high);
  return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:


int main(void){
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];

	const ll sum = accumulate(begin(a),end(a),0LL);

	ll ans =  1LL << 60;

	ll cur = 0LL;
	rep(i,n){
		cur += a[i];
		if(i==n-1) break;
		ll alt = sum - cur;
		chmin(ans,abs(cur-alt));
	}


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main() {
  while (true) {
    int n, m;
    cin>>n>>m;
    if (n==0&&m==0) {
      break;
    }
    vector<int> A;
    for(int i=0;i<n;++i) {
      int a;
      cin>>a;
      A.push_back(a);
    }
    sort(A.begin(),A.end());
    int res = 0;
    for(auto it=A.begin();it!=A.end();++it) {
      auto it2 = upper_bound(it+1,A.end(),m-*it);
      if(it2-1!=it&&*it+*(it2-1)<=m)
        res=max(res,*it+*(it2-1));
    }
    if (res==0)
      cout<<"NONE"<<endl;
    else
      cout<<res<<endl;
  }
  return 0;
}



Measured memory_bytes: 3152
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt[2][300002];
	int e = 0;
	for (int i = 0; i < n; ++i) {
		cnt[0][i] = e;
		e += s[i] == 'W';
	}
	e = 0;
	for (int i = n - 1; i >= 0; --i) {
		cnt[1][i] = e;
		e += s[i] == 'E';
	}
	int ans = 1 << 30;
	for (int i = 0; i < n; ++i) {
		ans = min(ans, cnt[0][i] + cnt[1][i]);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int X;
  cin >> X;

  int ans = 1;
  for (int i = 1; i <= X; i++) {
    for (int j = 2; j <= 10; j++) {
      int n = 1;
      for (int k = 1; k <= j; k++) {
        n *= i;
      }
      if (n <= X)
        ans = max(ans, n);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end() 
#define endl "\n"
#define int long long int
#define ll long long
#define ld long double
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
const int mod = 1000000007;
const int N=200005;
const int inf=1e18;
vector<vector<int>>adj(N);


bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}

void fun(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}


signed main(){
    flash;
    fun();
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<tuple<string,int,int>> a(n);
        for(int i=0;i<n;i++){
            cin>>get<0>(a[i])>>get<1>(a[i]);
            get<1>(a[i])=100-get<1>(a[i]);
            get<2>(a[i])=i+1;
        }
        sort(all(a));
        for(int i=0;i<n;i++){
            cout<<get<2>(a[i])<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 7788
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sc second
#define st first
#define pii pair<int, int>
#define arr array
#define task "A"
#define task_check "A"

const int maxn = 3e5 + 5;
const int maxN = 1e5 + 5;
const int mod = 1e9 + 7;

using namespace std;

/// Count : 1

int n, m;
ll row[maxn], col[maxn];

int main()
{
    /*if(fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }*/
    int t;
    cin >> n >> m >> t;
    map<ll, ll>have;
    for(int i=1; i<=t; i++){
        int u, v;
        cin >> u >> v;
        row[u] ++;
        col[v] ++;
        have[u*300001 + v] ++;
    }
    ll maxx = 0;
    ll ans = 0;
    vector<int>dx, dy;
    for(int i=1; i<=n; i++){
        if(row[i] > maxx){
            maxx = row[i];
            dx.clear();
        }
        if(row[i] == maxx) dx.pb(i);
    }
    ans += maxx;
    maxx = 0;
    for(int i=1; i<=m; i++){
        if(col[i] > maxx){
            maxx = col[i];
            dy.clear();
        }
        if(col[i] == maxx) dy.pb(i);
    }
    ans += maxx;
    for(auto j : dx){
        for(auto j1 : dy){
            if(!have.count(j * 300001 + j1)){
                //cout << j <<" "<<j1<<"\n";
                cout << ans;
                return 0;
            }
        }
    }
    cout << ans-1;
}


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

int main()
{
	int n,m;
	double a,sum=0;
	bool flag=true;
	vector<double>v;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		v.push_back(a);
		sum+=a;
	}
	sort(v.begin(),v.end(),greater<int>());
	for(int i=0;i<m;i++)
	{
		if(v[i]<sum*1/(4*m))flag=false;
	}
	if(flag)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

#define int long long

const int N = 1e6 + 10;

int a[N], b[N];

signed main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] != a[i - 1]) b[++b[0]] = a[i];
	}
	int money = 1000;
	int left = 0;
	int ans = 1000;
	for (int i = 1; i <= b[0]; i++)
	{
		//big
		if (b[i] > b[i + 1] && b[i] > b[i - 1] || (i == 1 && b[i] > b[i + 1]) || (i == n && b[i] > b[i - 1]))
		{
			//sell
			if (left)
				money += left * b[i], left = 0;
		}
		if (b[i] < b[i + 1] && b[i] < b[i - 1] || (i == 1 && b[i] < b[i + 1]) || (i == n && b[i] < b[i - 1]))
		{
			if (money)
				left += money / b[i], money %= b[i];
		}
		ans = max(ans, money);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
// author -> LetsGoAc
#include "bits/stdc++.h"
using    namespace std;
typedef  long double ld;
#define  int long long
typedef  pair<int,int> pii;
#define  RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  rep(i,n) for(i=0; i <n; i++)
#define  repv(i,k,n) for(int i=k; i<=n; i++)
#define  pb push_back
#define  mp make_pair
#define  F  first
#define  S  second
#define  sz(x)  (int)x.size()
#define  all(v) v.begin(),v.end()
#define  endl '\n'
#define  deb(x) c out<<#x<<" = "<<x<<endl
#define  gcd   __gcd
#define  inf   LLONG_MAX
#define  minf  LLONG_MIN 
#define  gi  greater<int> 
#define  gpi greater<pii>  
#define  sp(n) fixed<<setprecision(n)
const int mod = (int)(1e9+7);
int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
int pct(int x)
{   return __builtin_popcountll(x);}
int  lcm(int a,int b){return a*b/gcd(a,b);}
bool is_power_2(int n){ return log2(n)==floor(log2(n));}
bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}
void db()
{   
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
void timeit()
{  
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " <<sp(5)<< 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}
int     dx []    =  {-1 , 0 , 1 , 0 ,-1,-1, 1,  1};
int     dy []    =  { 0 , 1 , 0 ,-1 ,-1, 1, 1, -1};
char    dir[]    =  {'U','R','D','L'};
/* ---------------------- ar.cpp --------------------------------- */
const int maxn = 1e6+5;
void solve(int tc)
{
    // cout<<"Case #"<<tc<<": ";
    int n,i,j,k,m,q,l,r;
    cin>>n;
    if(n>=30)
        cout<<"Yes";
    else
        cout<<"No";
}   
signed main()
{
    // ar.cpp
    RAGE;
  //  db();    
    int t=1;
    //cin>>t;
    for(int i=1; i<=t; i++)
    {
        solve(i);
    }
  //  timeit();
    return 0;
}
/*
    1. To find 2's complement , reverse all the bits after 1st set bit. (right - >left.)

*/  

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N+10, 1);
    rep(i, 2, N+1){
        for(ll j = i; j <= N; j += i){
            a[j]++;
        }
    }
    ll ans = 0;
    rep(i, 1, N+1) ans += i * a[i];
    cout << ans << endl;
    return 0;
}


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

const int M=1e9+7;

int main()
{
    int n,x,t;
    cin>>n>>x>>t;
    if(n<=x)
        cout<<t<<endl;
    else
    {
        ll ans=(ceil((double)n/x)*t);
        cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
const double EPS = 1e-15;
const double eps = 1e-15;
const int num = 15;
const double PI = acos(-1.0);
const double INF = 0x3f3f3f3f;

double T = 100;
double r = 0.99;

struct Point{
    double x,y,z;
};

double dist(Point A,Point B)
{
    return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y)+(A.z-B.z)*(A.z-B.z));
}

Point p[num],m[num];
int n;
double d[num];
double ans;

double MAX(Point t)
{
    double res=0;
    for(int i=0;i<n;i++)
        res=max(res,dist(t,p[i]));
    ans=min(ans,res);
    return res;
}

int main()
{
    srand(time(0));
    while(cin>>n)
    {
        if(n==0)
            break;
        for(int i=0;i<n;i++)
            cin>>p[i].x>>p[i].y>>p[i].z;
        double t=T;
        Point now,next;
        now.x=now.y=now.z=0;
        int pos;
        ans=1e100;
        while(t>EPS)
        {
            double dis=0;
            for(int i=0;i<n;i++)
            {
                if(dis<dist(now,p[i]))
                {
                    pos=i;
                    dis=dist(now,p[i]);
                }
            }
            next.x=now.x+(p[pos].x-now.x)/dis*t;
            next.y=now.y+(p[pos].y-now.y)/dis*t;
            next.z=now.z+(p[pos].z-now.z)/dis*t;
            double x=MAX(now)-MAX(next);
            if(x>0||exp(x/t)>(rand()%1000+1)/1000.0)
                now=next;
            t*=r;
        }
        printf("%.5f\n",ans);
    }
    return 0;
}



Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
const int INF = 1e18, MOD = 1e9 + 7;
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
signed main() {
    INCANT;
    int n, res = 0, l, r;
    int a[2222];
    cin>>n;
    rep(i, n){
        cin>>a[i];
    }
    sort(a, a + n);
    rep(i, n){
        rep(j, i + 1, n){
            res += lower_bound(a, a + n, a[i] + a[j]) - a - j - 1;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

typedef pair<int,int> ip;

int d[701][701], n, m;
vector<ip> v;
bool e[701][701];
vector<int> con[701];

int f(int cur, int k) {
	if(k==v.size()) return cur==0;
	if(d[cur][k]>=0) return d[cur][k];
	if(cur>=v[k].first && f(cur-v[k].first,k+1))
		return d[cur][k]=1;
	if(cur>=v[k].second && f(cur-v[k].second,k+1))
		return d[cur][k]=1;
	return d[cur][k]=0;
}

int col[701];

bool bfs(int s) {
	queue<int> q;
	q.push(s);
	col[s]=0;
	int c0=1, c1=0;
	while(!q.empty()) {
		int u=q.front();
		q.pop();
		for(int i=0;i<con[u].size();i++) {
			int v=con[u][i];
			if(col[v]<0) {
				col[v]=(col[u]^1);
				q.push(v);
				if(col[v]==0) c0++;
				else c1++;
			} else if(col[u]==col[v]) return false;
		}
	}
	v.push_back(ip(c0,c1));
	return true;
}

int main() {
	scanf("%d %d",&n,&m);
	while(m--) {
		int u, v;
		scanf("%d %d",&u,&v);
		e[u][v]=e[v][u]=true;
	}
	for(int i=1;i<=n;i++) {
		for(int j=i+1;j<=n;j++) {
			if(!e[i][j]) {
				con[i].push_back(j);
				con[j].push_back(i);
			}
		}
	}
	memset(col,-1,sizeof(col));
	for(int i=1;i<=n;i++) if(col[i]<0) {
		if(!bfs(i)) {
			puts("-1");
			return 0;
		}
	}
	memset(d,-1,sizeof(d));
	int res=(1<<30);
	for(int i=0;i<=n;i++) {
		if(f(i,0)) {
			res=min(res,i*(i-1)/2+(n-i)*(n-i-1)/2);
		}
	}
	printf("%d\n",res);
	return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    string S;
    cin >> S;
    
    if(S == "SUN"){
        _PR(7);
    }
    else if(S == "MON"){
        _PR(6);
    }
    else if(S == "TUE"){
        _PR(5);
    }
    else if(S == "WED"){
        _PR(4);
    }
    else if(S == "THU"){
        _PR(3);
    }
    else if(S == "FRI"){
        _PR(2);
    }
    else if(S == "SAT"){
        _PR(1);
    }


    return 0;
}

/*



*/

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int n,bit[4040],costw[2020][2020],costb[2020][2020],w[2020],b[2020],memo[2020][2020];
bool done[2020][2020];

void update(int p, int v){
	while(p<=4000){
		bit[p] += v;
		p += (p&(-p));
	}
}

int query(int p){
	int v=0;
	while(p>0){
		v += bit[p];
		p -= (p&(-p));
	}
	return v;
}

int solve(int i, int j){
	if(done[i][j]){
		return memo[i][j];
	}
	done[i][j] = true;
	if(i==n && j==n){
		memo[i][j] = 0;
	}else if(i==n){
		memo[i][j] = costb[i][j] + solve(i,j+1);
	}else if(j==n){
		memo[i][j] = costw[i][j] + solve(i+1,j);
	}else{
		memo[i][j] = min(costb[i][j]+solve(i,j+1),costw[i][j]+solve(i+1,j));
	}
	return memo[i][j];
}

int main(void){
	int i,j,a;
	char c;
	cin >> n;
	fill(bit,bit+4040,0);
	fill(done[0],done[2020],false);
	for(i=1; i<=(2*n); ++i){
		update(i,1);
		cin >> c >> a;
		if(c=='W'){
			w[a-1] = i;
		}else{
			b[a-1] = i;
		}
	}
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			costw[i][j] = query(w[i])-1;
			costb[i][j] = query(b[j])-1;
			update(b[j],-1);
		}
		costw[i][n] = query(w[i])-1;
		for(j=0; j<n; ++j){
			update(b[j],1);
		}
		update(w[i],-1);
	}
	for(j=0; j<n; ++j){
		costb[n][j] = query(b[j])-1;
		update(b[j],-1);
	}
	cout << solve(0,0) << endl;
	return 0;
}


Measured memory_bytes: 52096
/**
 * @author torith
 * @date 2018-10-24
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int G[50][50] = {};
int N,M;

int solve(int i,int j,bool * visited){
    if(i == j) return 1;
    if(visited[i]) return 0;
    visited[i] = true;
    int sum = 0;
    for (int k = 0; k < N; ++k) {
        if(G[i][k]){
            sum += solve(k,j,visited);
        }
    }
    return sum;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int a,b;
        cin >> a >> b;
        G[a-1][b-1] = 1;
        G[b-1][a-1] = 1;
    }

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            if(G[i][j]){
                bool visited[50] = {};
                if (solve(i,j,visited) == 1) ans ++;
            }
        }
    }

    cout << ans/2 << "\n";


    return 0;
}



Measured memory_bytes: 256
K=int(input())

cache = [1, 
9, 
30, 
76, 
141, 
267, 
400, 
624, 
885, 
1249, 
1590, 
2208, 
2689, 
3411, 
4248, 
5248, 
6081, 
7485, 
8530, 
10248, 
11889, 
13687, 
15228, 
17988, 
20053, 
22569, 
25242, 
28588, 
31053, 
35463, 
38284, 
42540, 
46581, 
50893, 
55362, 
61824, 
65857, 
71247, 
76884, 
84388, 
89349, 
97881, 
103342, 
111528, 
120141, 
128047, 
134580, 
146316, 
154177, 
164817, 
174438, 
185836, 
194157, 
207927, 
218812, 
233268, 
245277, 
257857, 
268182, 
288216, 
299257, 
313635, 
330204, 
347836, 
362973, 
383709, 
397042, 
416448, 
434025, 
456967, 
471948, 
499740, 
515581, 
536073, 
559758, 
583960, 
604833, 
633651, 
652216, 
683712, 
709065, 
734233, 
754734, 
793188, 
818917, 
846603, 
874512, 
909496, 
933081, 
977145, 
1006126, 
1041504, 
1073385, 
1106467, 
1138536, 
1187112, 
1215145, 
1255101, 
1295142, 
1342852, 
1373253, 
1422195, 
1453816, 
1502376, 
1553361, 
1595437, 
1629570, 
1691292, 
1726717, 
1782111, 
1827492, 
1887772, 
1925853, 
1986837, 
2033674, 
2089776, 
2145333, 
2197483, 
2246640, 
2332104, 
2379085, 
2434833, 
2490534, 
2554600, 
2609625, 
2693919, 
2742052, 
2813988, 
2875245, 
2952085, 
3003306, 
3096024, 
3157249, 
3224511, 
3306240, 
3388576, 
3444609, 
3533637, 
3591322, 
3693924, 
3767085, 
3842623, 
3912324, 
4027884, 
4102093, 
4181949, 
4270422, 
4361548, 
4427853, 
4548003, 
4616104, 
4718640, 
4812789, 
4918561, 
5003286, 
5131848, 
5205481, 
5299011, 
5392008, 
5521384, 
5610705, 
5739009, 
5818390, 
5930196, 
6052893, 
6156139, 
6239472, 
6402720, 
6493681, 
6623853, 
6741078, 
6864016, 
6953457, 
7094451, 
7215016, 
7359936, 
7475145, 
7593865, 
7689630, 
7886244, 
7984165, 
8130747, 
8253888, 
8403448, 
8523897, 
8684853, 
8802826, 
8949612, 
9105537, 
9267595, 
9376656, 
9574704, 
9686065, 
9827097, 
9997134, 
10174780, 
10290813, 
10493367, 
10611772, 
10813692, 
10962213]

print(cache[K-1])

Measured memory_bytes: 9384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>
#include <cstring>


int main() {
    long long a, v, b, w, t;
    std::cin >> a >> v >> b >> w >> t;
    if (a == b) {
        std::cout << "YES" << std::endl;
        return 0;
    }
    if (a > b) {
        a -= v*t;
        b -= w*t;
        if (a <= b) std::cout << "YES" << std::endl;
        else std::cout << "NO" << std::endl;
    }
    else {
        a += v*t;
        b += w*t;
        if (a >= b) std::cout << "YES" << std::endl;
        else std::cout << "NO" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
    using namespace std;
    long long k,t,s;
    int main() {
        cin>>k;
        t=k/50;
        s=k-t*50;
        cout<<50<<endl;
        for(int i=1 ; i<=50; i++){
            if(i<=s){
                cout<<100+t-s<<" ";
            }
            else
                cout<<49+t-s<<" ";
        }
    }

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <iomanip>
#include <malloc.h>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(int i = 0;i < n;++i)
long long dp[100][11000] = {};
int main() {
	int n, a;
	cin >> n >> a;
	dp[0][5000] = 1;
	for (int i = 0;i < n;++i) {
		int x;
		cin >> x;
		for (int q = 0;q < 10000;++q) {
			dp[i + 1][q + x-a] += dp[i][q];
			dp[i + 1][q] += dp[i][q];
		}
	}
	cout << dp[n][5000] - 1 << endl;
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#define rep(i,n)  for(int i=0; i<n; i++)
using namespace std;
int main(void){
    int a, b;
    string s;
    cin >> a >> b >> s;

    rep(i, s.size()){
        if(i == a){
            if(s[i] != '-'){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            if(s[i] == '-'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> a(n),b(k+1,0);
    rep(i,n) cin >> a.at(i);
    rep(i,k+1){
        rep(j,n){
            if (i-a.at(j)<0) break;
            if (b.at(i-a.at(j))==0){
                b.at(i)=1;
            }
        }
    }
    if (b.at(k)==1) cout << "First" << endl;
    else cout << "Second" << endl;
}


Measured memory_bytes: 640
using System;


class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);

        if((a*b)%2 == 0)
        {
            Console.WriteLine("Even");
        }
        else
        {
            Console.WriteLine("Odd");
        }
    }
}

Measured memory_bytes: 13140
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int64_t> X(N);
  vector<int64_t> Y(N);
  vector<int64_t> Z(N);
  rep(i, N) { cin >> X[i] >> Y[i] >> Z[i]; }

  vector<tuple<int, int, int>> pattern = {
      {+1, +1, +1}, {+1, +1, -1}, {+1, -1, +1}, {+1, -1, -1},
      {-1, +1, +1}, {-1, +1, -1}, {-1, -1, +1}, {-1, -1, -1}};
  int64_t answer = 0;
  for (auto& pat : pattern) {
    vector<int64_t> XYZ(N);
    rep(i, N) {
      XYZ[i] = X[i] * get<0>(pat) + Y[i] * get<1>(pat) + Z[i] * get<2>(pat);
    }
    sort(XYZ.rbegin(), XYZ.rend());
    int64_t tmp_ans = 0;
    rep(i, M) { tmp_ans += XYZ[i]; }
    answer = max(answer, tmp_ans);
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3696
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0) 
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n,m,a=0,b,c=1,d,x,y,z;
  string s,t;
  //

  // ここから
  IN2(n,x);
  Vi v(n);
  VIN(v)
  REP(i,n){
    a += v[i];
    if(a <= x) c++;
  }
  OUT(c);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c; cin >> a >> b >> c;
  if (a == b && b == c && c == a){
    cout << 1;
  }
  else if (a != b && b != c && c != a){
    cout << 3;
  }
  else{
    cout << 2;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  ll a,b,c; cin >>a >>b >>c;
  if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0){
    cout <<0 <<endl; return 0;
  }
  ll res = 1000000000000000000;
  chmin(res, a*b);
  chmin(res, b*c);
  chmin(res, c*a);
  cout <<res <<endl;
}


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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
// end of Template

int a[200010],n;
int box[200010];
vi m;
void process (int x){
    int sum = 0;
    for(int i=x;i<=n;i+=x){
        sum+=box[i];
    }
    if((sum%2) == (a[x]%2)){}
    else{box[x]=1;}
}
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=n;i>=1;i--)process(i);
    for(int i=1;i<=n;i++){
        if(box[i]>0){m.pb(i);}
    }
    cout<<m.size()<<newl;
    for(int i=0;i<m.size();i++){
        cout<<m[i];
        if(i==m.size()-1){cout<<newl;}
        else{cout<<" ";}
    }

}


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

int N, M, R;
int dist[201][201];
bool visit[8];
int ans = INF;
vector<int> r(9);

void dfs(int v, int prev, int d){

   if(v == R + 1){
      //終了
      if(ans > d) ans = d;
      return;
   }

   for ( int i =1; i <= R ; i ++) if (! visit [ i ])
   {
      visit[i]= true;
      if ( prev == -1) dfs ( v +1 ,i ,0);
      else dfs ( v +1 ,i , d + dist[r[prev]][r[i]]);
      visit[i]= false;
   }
}

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

   rep(i,R) {
       cin >> r[i+1];
   }
   rep(i,8) visit[i] = false;
   rep(i,N)rep(j,N) if(i != j)dist[i+1][j+1] = INF;
   //rの最短距離を求める
   rep(i,M){
      int a, b, c;
      cin >> a >> b >> c;
      if(dist[a][b] > c) dist[a][b] = dist[b][a] = c;
   }

   //200なのでワーシャルフロイドを使う
   rep(k,N) rep(i,N) rep(j,N) dist[i+1][j+1] = min(dist[i+1][j+1], dist[i+1][k+1] + dist[k+1][j+1]);

   dfs(1,-1,0);
   cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a,b;
  cin >> N;
  int ans=0;
  for(int i=0;i<N;i++){
    cin >> a >> b;
    ans = ans + b - a + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
matrix = []
crow = []
for i in range(3):
    row = input().split()
    for j in row:
        crow.append(int(j))
    matrix.append(crow)
    crow = []

ans = 'Yes'

test = []
for i in range(2):
    for j in range(3):
        test.append(matrix[i][j]-matrix[i+1][j])
        if len(set(test))!=1:
            ans = 'No'
    test = []
    
for j in range(2):
    for i in range(3):
        test.append(matrix[i][j]-matrix[i][j+1])
        if len(set(test))!=1:
            ans = 'No'
        test = []
        

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef vector<int> vec;
//配列の添字ズレに注意
//=に注意

int main(){
  int a,b,c,d,e; cin>>a>>b>>c>>d>>e;
  //string s; cin>>s;
  
  cout<<(15-a-b-c-d-e) <<endl;
}

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

int main() {
  int N, goal, pla = 1;
  int64_t K, KK;
  cin >> N >> K;
  KK = K;
  int arr[N];
  map<int, int> mp;
  int cnt = 0;
  int tele;
  for(int i = 0; i < N; i++){
    cin >> arr[i];
  }
  while(K > 0){
    if(!(mp.count(pla))){
      mp[pla] = cnt;
      pla = arr[pla - 1];
      cnt++;
      K--;
    }
    else{
      tele = cnt - mp[pla];
      KK = KK - mp[pla];
      KK = KK % tele;
      while(KK > 0){
        pla = arr[pla - 1];
        KK--;
      }
      break;
    }
  }
  cout << pla << endl;
  return 0;
    
}

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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int r;
cin>>r;
cout<<3*r*r<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<queue>
#include<cstring>
#include<math.h>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=1e5+5;


int main()
{
	long long n,a,b;
	cin>>n>>a>>b;
	long long ans=(n/(a+b))*a;
	if(n%(a+b)>=a) ans=ans+a;
	else ans=ans+n%(a+b);
	cout<<ans<<endl;
	return 0; 
}

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

vector<char> sieve(const int M){
    vector<char> isPrime(M);
    for(int i=2;i<M;i++) isPrime[i] = true;
    for(int i=2;i*i<M;i++){
        if(not isPrime[i]) continue;
        for(int j=i*i;j<M;j+=i){
            isPrime[j] = false;
        }
    }
    return isPrime;
}

int main (int argc, char const* argv[])
{
    int n;
    vector<char> p;
    while(cin >> n){
        int count = 0;
        p = sieve(n+1);
        for(vector<char>::iterator it = p.begin(); it != p.end() ; ++it){
            if(*it == true)
                ++count;
        }
        
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 3480
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.ArrayDeque;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        String n = sc.next();
        int l = n.length();
        if(n.charAt(l-1)=='2' || n.charAt(l-1)=='4' || n.charAt(l-1)=='5' || n.charAt(l-1)=='7' || n.charAt(l-1)=='9'){
            System.out.println("hon");
        }
        else if(n.charAt(l-1)=='0' || n.charAt(l-1)=='1' || n.charAt(l-1)=='6' || n.charAt(l-1)=='8'){
            System.out.println("pon");
        }
        else if(n.charAt(l-1)=='3'){
            System.out.println("bon");
        }
    }
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    int answer = INT_MAX;
    for (int i = -100; i <= 100; i++)
    {
        int sum_point = 0;
        for (int j = 0; j < n; j++)
        {
            if (a.at(j) != i)
            {
                sum_point += (a.at(j) - i) * (a.at(j) - i);
            }
        }
        answer = min(answer, sum_point);
    }

    cout << answer << endl;
}

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

void dif(const string& s) {
  struct Chain {int id; string s;};
  int m = 0;

  vector<string> res;

  int carry = -1;
  queue<Chain> q;
  q.push({m++, s});
  while(!q.empty()) {
    auto chain = q.front(); q.pop();

    if(~carry) {
      stringstream ss;
      ss << "join " << carry << " " << chain.id;
      res.push_back(ss.str());
      chain.s.insert(begin(chain.s), 'o');
      chain.id = m++;
      carry = -1;
    }

    auto x = count(begin(chain.s), end(chain.s), 'x');
    auto o = count(begin(chain.s), end(chain.s), 'o');
    if(x == 0) {
      while(2 < o && 2 < chain.s.size()) {
        stringstream ss;
        ss << "split " << chain.id << " " << 0;
        res.push_back(ss.str());
        chain.s.erase(0, 1);
        chain.id = (++m)++;
        --o;
      }
      continue;
    }

    while(x + 1 < o && chain.s.front() == 'o') {
      stringstream ss;
      ss << "split " << chain.id << " " << 0;
      res.push_back(ss.str());
      chain.s.erase(0, 1);
      chain.id = (++m)++;
      --o;
    }

    x = o = 0;
    for(int i = 0; i < chain.s.size() - 1; ++i) {
      if(chain.s[i] == 'o') ++o;
      if(chain.s[i] == 'x') ++x;
      if(!x || x + 1 != o) continue;
      stringstream ss;
      ss << "split " << chain.id << " " << i;
      res.push_back(ss.str());
      q.push({m + 1, chain.s.substr(i + 1)});
      chain.s.erase(i + 1);
      chain.id = m;
      m += 2;
      break;
    }

    while(chain.s.back() == 'o') {
      stringstream ss;
      ss << "split " << chain.id << " " << chain.s.size() - 2;
      res.push_back(ss.str());
      chain.s.pop_back();
      ss.str("");
      ss << "join " << m + 1 << " " << m;
      res.push_back(ss.str());
      chain.s.insert(begin(chain.s), 'o');
      chain.id = m + 2;
      m += 3;
    }

    while(chain.s.front() == 'o' && chain.s.back() == 'x') {
      stringstream ss;
      ss << "split " << chain.id << " " << 0;
      res.push_back(ss.str());
      ss.str("");
      ss << "join " << m + 1 << " " << m;
      res.push_back(ss.str());
      ss.str("");
      ss << "split " << m + 2 << " " << chain.s.size() - 3;
      res.push_back(ss.str());
      chain.s.erase(0, 1);
      chain.s.pop_back();
      chain.id = m + 3;
      m += 5;
    }

    carry = chain.id;
  }

  cout << res.size() << endl;
  for(const auto& i: res) cout << i << endl;
}

void same(string s) {
  vector<string> res;
  int id = 0;
  while(2 < s.size()) {
    if(s[0] == s[1]) break;
    stringstream ss;
    ss << "split " << id << " " << 1;
    res.push_back(ss.str());
    id += 2;
    s.erase(0, 2);
  }
  stringstream ss;
  ss << res.size();
  res.insert(begin(res), ss.str());

  if(2 < s.size()) cout << -1 << endl;
  else             for(auto& i: res) cout << i << endl;
}

void solve(const string& s) {
  auto x = count(begin(s), end(s), 'x');
  auto o = count(begin(s), end(s), 'o');

  if(x > o)  cout << -1 << endl;
  if(x == o) same(s);
  if(x < o)  dif(s);
}

int main() {
  int Q;
  cin >> Q;

  for(int i = 0; i < Q; ++i) {
    string s;
    cin >> s;

    solve(s);
  }
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    int n;
    cin >> n;
    map<string, int> m;
    int maxi = 0;
    forn(n){
        string s;
        cin >> s;
        m[s]++;
        maxi = max(maxi, m[s]);
    }
    set<string> s;
    for(auto i : m){
        if(i.ss == maxi){
            s.insert(i.ff);
        }
    }
    for(auto i : s){
        cout << i << '\n';
    }
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

Measured memory_bytes: 33280
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

answer = 0
tyokkin = -1

for dish in A:
  manzoku = B[dish-1]
  if dish - tyokkin == 1:
    manzoku += C[dish-2]
  answer += manzoku
  tyokkin = dish
print(answer)

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] strlist = str.split(" ");
		int x = Integer.parseInt(strlist[0]);
		int a = Integer.parseInt(strlist[1]);
		int b = Integer.parseInt(strlist[2]);

		String answer = "dangerous";
		if(a >= b){
			answer = "delicious";
		}else if(a >= b - x){
			answer = "safe";
		}
		System.out.println(answer);
	}
}


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

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        int n = Integer.parseInt(br.readLine());
        int area = n * n;

        System.out.println(area);
      }
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
    ll x, y;
    cin >> x >> y;
    REP(turu, x+1){
        ll kame = x - turu;
        if(turu * 2 + kame * 4 == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3620
import scala.io.StdIn._

object Main extends App {
  val Array(n, k) = readLine.split(" ").map(_.toLong)
  val as = readLine.split(" ").map(_.toInt).sorted
  val fs = readLine.split(" ").map(_.toInt).sorted.reverse
  val zip = as.zip(fs)

  def available(cost: Long): Boolean = 
    zip.foldLeft(k){case (trainings, (a, f)) => trainings - Math.max(0, a - cost / f)} >= 0

  def binSearch(min: Long, max: Long): Long = {
    if (max - min <= 1) max
    else {
      val cur = (min + max) / 2
      if (available(cur)) binSearch(min, cur) else binSearch(cur, max)
    }
  }

  println(binSearch(-1, 1000000000000L))
}

Measured memory_bytes: 129848
// Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Type
template <typename T> using P = pair<T, T>;
using ll = long long;
using ull = unsigned long long;

// Constants
const ll INF = 1e18;
const ll MOD = 1000000007;


// 辺
struct Edge {
  int to;
  ll cost;
  Edge(int to, ll cost) : to(to), cost(cost) {}
};

// ノード
struct Node {
  vector<Edge> edges;
  Node() {}
  void addEdge(int to, ll cost) {
    edges.push_back(Edge(to, cost));
  }
};

// グラフ
class Graph {
  private:
    int nodeN;
    vector<Node> graph;
  public:
    Graph(int nodeN) {
      this->nodeN = nodeN;
      for(int i = 0; i < nodeN; i++) {
        graph.push_back(Node());
      }
    }
    /**
      辺を追加する
      */
    void addEdge(int from, int to, ll cost) {
      graph[from].addEdge(to, cost);
    }
    /**
      getter
      */
    int getNodeN() {
      return this->nodeN;
    }
    vector<Node> getGraph() {
      return this->graph;
    }
};

/**
  ベルマンフォード法
  計算量: O(|V|・|E|)
  */
vector<ll> bellmanFord(Graph g, int s) {
  int n = g.getNodeN();
  vector<Node> graph = g.getGraph();

  // 距離情報初期化
  vector<ll> d(n, -INF);
  d[s] = 0;

  // 全ての辺に対して、nodeN回更新を掛ける
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      for(Edge edge : graph[j].edges) {
        if(d[edge.to] < d[j] + edge.cost) {
          d[edge.to] = d[j] + edge.cost;
          // 負閉路検出
          // nodeN回目のループで、目的地Nへのルートが更新されるなら負閉路
          if(i == n-1 && edge.to == n-1) {
            d[n-1] = -INF;
            return d;
          }
        }
      }
    }
  }
  return d;
}

int main() {
  // 入力
  int N, M;
  cin >> N >> M;
  Graph graph = Graph(N);
  for(int i = 0; i < M; i++) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--; b--;
    graph.addEdge(a, b, c);
  }

  vector<ll> d = bellmanFord(graph, 0);

  if(d[N-1] != -INF) {
    cout << d[N-1] << endl;
  } else {
    cout << "inf" << endl;
  }

  return 0;
}

Measured memory_bytes: 640