akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    string a, b, c, ans;
    cin >> a;
    cout << a[0]<< to_string(a.size()-2) << a.back() << endl;
}


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

using namespace std;

const int Nmax = 1e5 + 1;

int n;
int a[Nmax];
int cnt;

int main(){
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    if(a[1] == 1) cnt++, a[2] = 1;
    for(int i = n; i >= 2; --i){
        if(a[i] == i && a[i-1] == i) {swap(a[i], a[i-1]); cnt++;}
        if(a[i] == i && a[i-1] != i) {swap(a[i], a[i-1]); cnt++; }
    }
    cout << cnt;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
const int N = 2e5 + 5;
#define PI acos(-1.0)
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> VI;
#define pqll_max priority_queue<ll> // max heap. push(),pop(),top(),size(),empty()
#define pqll_min priority_queue<ll,vector<ll>,greater<ll> >
#define lb(v,val)   lower_bound(v.begin(),v.end(),val) //first equal to or lower than [------------
#define ub(v,val)   upper_bound(v.begin(),v.end(),val) //first greater than ------------)
#define bs(v,x) binary_search(v.begin(),v.end(),x)
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(ll a, ll b) { if (a < b)swap(a, b); return (((a%mod) - (b%mod) + mod) % mod); }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;

signed main()
{
	fastio;
	int n;
	cin >> n;
	VI v(n);
	in(v);
	map<int, int>m;
	rep(i, n) {
		m[v[i]]++;
	}
	int tot = 0;
	for (auto i : m) {
		tot += ((i.second)*(i.second - 1)) / 2;
	}
	rep(i, n) {
		cout << tot - (m[v[i]] - 1) << endl;
	}
	


}

Measured memory_bytes: 11136
def main():
    N, C = (int(i) for i in input().split())
    D = [[int(i) for i in input().split()] for j in range(C)]
    c = [[int(i) for i in input().split()] for j in range(N)]
    base = [[((i+1)+(j+1)) % 3 for j in range(N)] for i in range(N)]
    d = [{i: 0 for i in range(1, C + 1)} for j in range(3)]
    for i in range(N):
        for j in range(N):
            d[base[i][j]][c[i][j]] += 1

    ans = 1 << 60
    from itertools import combinations, permutations
    for comb in combinations(range(1, C+1), 3):
        for p in permutations(comb):
            cur = 0
            for i in range(3):
                for k, v in d[i].items():
                    cur += D[k-1][p[i]-1] * v
            ans = min(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 46684
#include<stdio.h>                                                         
                                                                          
int main(void){                                                           
                                                                          
  int a,b,s,l;                                                            
                                                                          
  scanf("%d %d",&a,&b);                                                   
                                                                          
  s = a * b;                                                              
  l = 2 * (a + b);                                                        
                                                                          
  printf("%d %d\n",s,l);                                                    
                                                                          
  return 0;                                                               
}      

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;

int main() {

	string s;
	cin >> s;

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

	if (s[1] == s[0] && s[2] == s[3]&& s[2] != s[0])cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
#H×Wのマス目入力の周りに"."を付け加える関数
def pixel_input(H,W,border="."):
    pixel = [[border]*(W+2)] + \
    [[border] + list(input()) + [border] for _ in range(H)] + \
    [[border]*(W+2)]
    return pixel
#マス目型2次元配列を出力する関数
def pixel_print(pixel):
    for i in range(len(pixel)):
        print("".join(pixel[i]))
S=pixel_input(H,W)
T=[["?" for _ in range(W)] for _ in range(H)]

for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]=="#":
            T[i-1][j-1]="#"
        else:
            T[i-1][j-1]=str((S[i-1][j-1]+S[i-1][j]+S[i-1][j+1]+S[i][j-1]+S[i][j+1]+S[i+1][j-1]+S[i+1][j]+S[i+1][j+1]).count("#"))
pixel_print(T)

Measured memory_bytes: 3188
#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 bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
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 namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string O, E; cin >> O >> E;
    int n = O.size() + E.size();

    string res;
    rep(i, n){
        if((i + 1) % 2){
            res.push_back(O[i / 2]);
        }
        else {
            res.push_back(E[i / 2]);
        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 500005
#define mod 1000000007
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
char s[N],t[N];
int n,flag,pre[N],suf[N],ans=0;
void getfail(int *fail,char *s)
{
	fail[0]=-1;
	int j=0;
	for(int i=1;i<n;++i){
		while(j&&s[i]!=s[j])j=fail[j];
		if(s[i]==s[j])fail[i+1]=++j;
		else fail[i+1]=0;
	}
}
inline bool checkpre(int pos){return pre[pos]==0||pos%(pos-pre[pos]);}
inline bool checksuf(int pos){return suf[pos]==0||pos%(pos-suf[pos]);}
int main(){
	scanf("%s",s),n=strlen(s);
	for(int i=0;i<n;++i)t[i]=s[n-i-1];
	getfail(pre,s),getfail(suf,t),t[n]='\0';
	flag=checkpre(n)?1:2;
	bool f=true;
	for(int i=1;i<n;++i)if(s[i]!=s[i-1]){f=false;break;}
	if(f)flag=n;
	cout<<flag<<'\n';
	if(flag!=2){cout<<1;return 0;}
	for(int i=0;i<n;++i){
		int tmp=n-i-1;
		if(checkpre(i+1)&&checksuf(tmp))++ans;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

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

int main() {
	//入力
	int N;
	cin >> N;
	vector<string> s(N);
	for (int i = 0; i < N; i++) {
		cin >> s[i];
	}
	int M;
	cin >> M;
	vector<string> t(M);
	for (int i = 0; i < M; i++) {
		cin >> t[i];
	}

	//青ー赤のMAXを青ループで求める
	int point, max_point = 0;
	for (string tmp_s : s) {
		point = 0;
		for (string com_s : s) {
			if (tmp_s == com_s) {
				point++;
			}
		}
		for (string com_t : t) {
			if (tmp_s == com_t) {
				point--;
			}
		}
		if (max_point < point) {
			max_point = point;
		}
	}
	cout << max_point;


	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#define EPS (1e-10)
#define equals(a,b) (fabs(a)-fabs(b)<EPS)


using namespace std;

class Point{
public:
    double x,y;

    Point(double x=0,double y=0):x(x),y(y){}

    Point operator + (Point &p) { return Point(x+p.x,y+p.y); }
    Point operator - (Point &p) { return Point(x-p.x,y-p.y); }
    Point operator * (double a) { return Point(x*a,y*a); }
    Point operator / (double a) { return Point(x/a,y/a); }

    double abs() { return sqrt(norm()); }
    double norm() { return x*x+y*y; }

    bool operator < (const Point &p) const {
        return x!=p.x?x<p.x:y<p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
    }
};

typedef Point Vector;
///Program 16.3 表示线段的结构体
struct Segment{
    Point p1,p2;
};

///Program 16.4 表示直线的结构体
typedef Segment Line;

class Circle{
public:
    Point c;
    double r;
    Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

///Program 16.6 多边形
typedef vector<Point> Polygon;

///内积
double dot(Vector a,Vector b){
    return a.x*b.x+a.y*b.y;
}
///外积
double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double norm(Point p) { return p.x*p.x+p.y*p.y; }
double abs(Point p) { return sqrt(norm(p)); }
//double norm() { return x*x+y*y; }
int ccw(Point p0,Point p1,Point p2){
    Vector a=p1-p0;
    Vector b=p2-p0;
    if(cross(a,b)>EPS)  {//printf("COUNTER_CLOCKWISE\n");
            return 1;}///p2位于p0-->p1的逆时针方向
    if(cross(a,b)<-EPS) {//printf("CLOCKWISE\n");
        return -1;}///p2位于p0-->p1的顺时针方向
    if(dot(a,b)<-EPS)   {//printf("ONLINE_BACK\n");
        return 2;}///p2位于线段p0p1后方
    if(a.norm()<b.norm())  { //printf("ONLINE_FRONT\n");
        return -2;}///p2位于线段p0p1前方

  //  printf("ON_SEGMENT\n");///p2位于线段p0p1的中间
    return 0;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
    return (ccw(p1,p2,p3) * ccw(p1,p2,p4) <= 0&&
            ccw(p3,p4,p1) * ccw(p3,p4,p2) <= 0);
}

bool intersect(Segment s1,Segment s2){
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}


///两点之间的距离
double getDistance(Point a,Point b){
    return abs(a-b);
}

///点与直线的距离
double getDistanceLP(Line l,Point p){
    return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}

///点到线段的距离
double getDistanceSP(Segment s,Point p){
    if(dot(s.p2-s.p1,p-s.p1)<0.0)   return abs(p-s.p1);
    if(dot(s.p1-s.p2,p-s.p2)<0.0)   return abs(p-s.p2);
    return getDistanceLP(s,p);
}

///线段到线段的距离
double getDistance(Segment s1,Segment s2){
    if(intersect(s1,s2))    return 0.0;
    return min(min(getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2)),
               min(getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)));
}


int main(){
    Segment s1,s2;
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&s1.p1.x,&s1.p1.y,&s1.p2.x,&s1.p2.y,&s2.p1.x,&s2.p1.y,&s2.p2.x,&s2.p2.y);
        printf("%.10f\n",getDistance(s1,s2));
    }
    return 0;
}



Measured memory_bytes: 3236
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

int main() {
	string s;
	cin >> s;
	if (s == "SAT")cout << 1 << endl;
	else if (s == "MON")cout << 6 << endl;
	else if (s == "TUE")cout << 5 << endl;
	else if (s == "WED")cout << 4 << endl;
	else if (s == "THU")cout << 3 << endl;
	else if (s == "FRI")cout << 2 << endl;
	else cout << 7 << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector < vector<int>>edges;
void dfs(int v, vector<int>& add, vector<int>& ans, int prev) {
	add[v] += add[prev];
	for (auto u : edges[v]) {
		if (u != prev)dfs(u, add, ans, v);
	}
}
signed main(void)
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, q;
	cin >> n >> q;
	edges = vector < vector<int>>(n + 1);
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		edges[x].push_back(y);
		edges[y].push_back(x);
	}
	vector<int>add(n + 1);
	vector<int>ans(n + 1);
	for (int i = 0; i < q; i++) {
		int p, x;
		cin >> p >> x;
		add[p] += x;
	}
	dfs(1, add, ans, 0);
	for (int i = 1; i <= n; i++)cout << add[i] << " ";
	return 0;
}

Measured memory_bytes: 28928
def is_prime(n):
    # ?´???°??????
    if n == 2:
        return True
    elif n < 2 or n & 1 == 0:
        return False
    for i in range(3, int(n**0.5) + 1, 2):
        if n % i == 0:
            return False
    return True

N = int(input())
cnt = 0
for i in range(N):
    e = int(input())
    if is_prime(e):
        cnt += 1
print(cnt)

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

ll mod=1e9+7;
ll dp[100005][13];

int main(){
    string s;
    cin >> s;
    ll n=s.size();
    dp[0][0]=1;
    ll res;
    for(ll i=0;i<n;i++){
        ll c;
        if(s[i]=='?') c=-1;
        else c=s[i]-'0';
        for(ll j=0;j<10;j++){
            if(c!=-1&&c!=j) continue;
            for(ll k=0;k<13;k++){
                dp[i+1][(k*10+j)%13]+=dp[i][k];
            }
        }
        for(ll j=0;j<13;j++) dp[i+1][j]%=mod;
    }
    res=dp[n][5];
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 13936
#include<bits/stdc++.h>
using namespace std;
int n,x[1005][1005],a[1005],ans,nw[1005];
queue<int>Q;
bool iq[1005];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		for(int o=1;o<n;++o)scanf("%d",&x[i][o]);
		nw[i]=1;
	}
	int rs=0;
	for(int i=1;i<=n;++i){
		if(iq[i])continue;
		int to=x[i][nw[i]];
		if(x[to][nw[to]]==i){
			iq[i]=iq[to]=1;
			Q.push(i);
			Q.push(to);
		}
	}
	while(!Q.empty()){
		int l=0;ans++;
		while(!Q.empty()){
			a[++l]=Q.front();Q.pop();
			nw[a[l]]++;
			iq[a[l]]=0;
		}
		for(int i=1;i<=l;++i){
			if(iq[a[i]])continue;
			int to=x[a[i]][nw[a[i]]];
			if(x[to][nw[to]]==a[i]){
				iq[a[i]]=iq[to]=1;
				Q.push(a[i]);
				Q.push(to);
			}
		}
	}
	for(int i=1;i<=n;++i)if(nw[i]!=n){puts("-1");return 0;}
	printf("%d\n",ans);
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define all(c) (c).begin(), (c).end()
#define endl '\n'

ll pow(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}




int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
//      int t;
//      cin >> t;
//      while(t--){



// }


int n;

cin >> n;
int x = 0;
int arr[n];
fo(i,0,n)cin >> arr[i];
fo(i,0,n)x ^= arr[i];

fo(i,0,n){
	int res = x^arr[i];
	cout << res << ' ';
}



return 0;
}



Measured memory_bytes: 5036
// 4/3/2020 8:00:11 PM
#include <bits/stdc++.h>  
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long    
#define MOD                998244353
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"  
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             (x).begin(),(x).end() 
using namespace std ; 
// 2020-04-01
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5+20;
const int mod = 1e9+7;  
bool is(char c ){
  return c > '0' && c <= '9';
}
int tests() {
  ll s ;
  cin >> s ; 
  cout << 0 << ' ' << 0 << ' ' ;
  ll x1,y1 ;
  x1 = 1e9,y1 =1 ;
  cout << y1 << ' ' << x1 << ' ' ;
  cout << (s+x1-1)/x1 << ' ' << (x1-s%x1)%x1 << '\n';
  return 0;
} 
int main(){
    I__O ;            
    int cases = 1 ; 
    // cin >> cases ;  
    for(int  _ = 1 ; _ <= cases ; _++ ){   
    // cout << "Case #" << _ << ": ";
      tests(); 
    }
    return 0 ; 
}

// -Wall -Weptra -O2
// -pedantic -std=c++11
// -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC


Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<vector>
#include <string>
#include<queue>
#define ll long long
using namespace std;
int n;

int main()
{
	scanf("%d", &n);

	string ps, s;
	int start = 0;
	int end = n - 1;
	int mid;

	cout << "0\n";
	fflush(stdout);
	cin >> ps;
	if (ps == "Vacant") return 0;

	while (start < end) {
		mid = (start + end) >> 1;
		cout << mid << '\n';
		fflush(stdout);
		cin >> s;
		if (s == "Vacant") return 0;

		if (mid % 2) {
			if (ps == s) {
				end = mid - 1;
			}
			else start = mid + 1;
		}
		else {
			if (ps == s) {
				start = mid + 1;
			}
			else end = mid - 1;
		}
	}
	cout << start << '\n';
	fflush(stdout);
	cin >> s;
	return 0;
}

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

using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if(a == 5 and b == 5 and c == 7){
cout<<"YES"<<endl;
}
else if(a == 7 and b == 5 and c == 5){
cout<<"YES"<<endl;
}
else if(a == 5 and b ==7 and c == 5){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e7+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

int field[110][110];
int w, h, n;

int main(){
	cin >> w >> h >> n;
	REP(i, n){
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1){
			REP(j, h){
				REP(k, x){
					field[j][k] = 1;
				}
			}
		}
		else if (a == 2){
			REP(j, h){
				FOR(k, x, w){
					field[j][k] = 1;
				}
			}
		}
		else if (a == 3){
			REP(j, y){
				REP(k, w){
					field[j][k] = 1;
				}
			}
		}
		else{
			FOR(j, y, h){
				REP(k, w){
					field[j][k] = 1;
				}
			}
		}
	}
	int ans = 0;
	REP(i, h){
		REP(j, w){
			if (!field[i][j])ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int N, ans;

        int gcd(int a, int b) {
            if (a < b) {
                int tmp = a; a = b; b = tmp;
            }
            if (b == 0) {
                return a;
            } else {
                return gcd(b, a % b);
            }
        }

        void solve(InputReader in, PrintWriter out) {
            N = in.nextInt();

            for (int i = 0; i < N; ++i) {
                int a = in.nextInt();
                if (i == 0) {
                    ans = a;
                } else {
                    ans = gcd(ans, a);
                }
            }

            out.println(ans);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() { return Integer.parseInt(next()); }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; ++i) arr[i] = this.nextInt();
            return arr;
        }
    }
}


Measured memory_bytes: 35864
n = int(input())
txy = [[0, 0, 0]]
for _ in range(n):
    txy.append(list(map(int, input().split())))

for i in range(1, n + 1):
    t = txy[i][0] - txy[i-1][0]
    x = txy[i][1] - txy[i-1][1]
    y = txy[i][2] - txy[i-1][2]
    mv = abs(x) + abs(y)
    if mv > t or (mv - t) % 2 == 1:
        print("No")
        break

else:
    print("Yes")



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

int a, b, c, d;

int main()
{
  cin >> a >> b >> c >> d;
  if ((a + b) < (c + d)) {
    cout << " Right";
  } else if ((a + b) > (c + d)) {
    cout << "Left";
  } else {
    cout << "Balanced";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, M;
    string S;
    cin >> N >> M >> S;
    VEC(int) SafeSquares;
    FOR(i, 0, N + 1)
        if (S[i] == '0')
            SafeSquares.push_back(i);

    const int _Infinity = 1 << 20;
    VEC(int) Turns(N + 1, _Infinity);
    VEC(int) Next(N + 1, -1);
    Turns[N] = 0;

    FORD(i, N - 1, -1) {
        int a = i + 1, b = min(i + M, N);
        int upper = upper_bound(ALL(SafeSquares), b) - BEGIN(SafeSquares);
        int lower = lower_bound(ALL(SafeSquares), a) - BEGIN(SafeSquares);
        if (upper == lower) {
            // No safe squares reachable from here.
            continue;
        }

        // [lower - upper)
        int farthest = SafeSquares[--upper];
        Turns[i] = min(Turns[i], 1 + Turns[farthest]);
        Next[i] = farthest;
    }

    int i = 0, t = Turns[0];
    if (t >= _Infinity) {
        cout << -1 << endl;
        return 0;
    }

    VEC(int) SafeSquareDist;
    for (int square : SafeSquares)
        SafeSquareDist.push_back(Turns[square]);

    while (i < N) {
        int a = i + 1, b = min(i + M, N);
        int upper = upper_bound(ALL(SafeSquares), b) - BEGIN(SafeSquares);
        int lower = lower_bound(ALL(SafeSquares), a) - BEGIN(SafeSquares);

        // Always upper > lower.
        int j = lower;
        for (;j < upper && SafeSquareDist[j] > t - 1;j += 100);
        // j >= upper or SSD[j] <= t - 1
        if (j >= upper)
            j = upper - 1;
        while (j > lower && SafeSquareDist[j] == SafeSquareDist[j - 1])
            j--;
        cout << SafeSquares[j] - i << " ";
        i = SafeSquares[j];
        t--;
    }
    cout << endl;

    return 0;
};

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

#include <iostream>
#include <fstream>

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

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

class debug
{
public:
    typedef long long ll;
    template<typename T> void vd(vector<T> vec);
    template<typename T> void vd2(vector<vector<T>> vec);
    template<typename T> void ad(T *arr, ll n);
    template<typename T, size_t N> void ad2(T (&arr)[N], ll n);
    template<typename T> void md(T mp);
};

#endif //INCLUDE_DEBUG_HPP

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

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

template<typename T> void debug::ad(T *arr, ll n)
{
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T, size_t N> void debug::ad2(T (&arr)[N], ll n)
{
    for(int i=0; i<=N; i++) for(int j=0; j<=n; j++) cout << arr[i][j] << " ";
    cout << endl;
}

template<typename T> void debug::md(T mp)
{
    cout << "key : value" << endl;
    for(auto const& m : mp) cout << m.first << " : " << m.second << endl;
    cout << endl;
}
debug debug;

class CPoll {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n;
	    in >> n;
	    map<string, int> cnt;
	    string s;
	    for(int i=0; i<n; i++){
	        in >> s;
	        cnt[s]++;
	    }

	    int mx = 0;
	    for(auto e : cnt){
            chmax(mx, e.second);
	    }

        vector<string> res;
	    for(auto e : cnt){
	        if(mx == -1){
	            mx = e.second;
	            res.push_back(e.first);
	            continue;
	        }
	        if(mx == e.second){
	            res.push_back(e.first);
	            continue;
	        }
	    }

	    sort(res.begin(), res.end());
	    for(auto v : res){
	        out << v << endl;
	    }
	}
};


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


Measured memory_bytes: 26868
#!/usr/bin/env python3
import sys


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    A, V = IL(int)
    B, W = IL(int)
    T = IS(int)

    if V > W and abs((B - A) / (V - W)) <= T:
        print('YES')
    else:
        print('NO')

solve()


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

bool kaibun(string S) {
  int n = S.length();
  rep(i, n/2) {
    if (S[i] != S[n-i-1]) {
      return false;
    }
  }
  return true;
}

int main() {
  string S;
  cin >> S;
  int n = S.length();

  string ans = "Yes";
  if (!kaibun(S)) {
    ans = "No";
  } else if (!kaibun(S.substr(0, (n-1)/2))) {
    ans = "No";
  } else if (!kaibun(S.substr((n+3)/2-1))) {
    ans = "No";
  }

  cout << ans << endl;

}


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

def black_magic(n):
    d = {
        1: 1431655765,
        2: 858993459,
        4: 252645135,
        8: 16711935,
        16: 65535
    }
    n=(n&d[1])+((n>>1)&d[1])
    n=(n&d[2])+((n>>2)&d[2])
    n=(n&d[4])+((n>>4)&d[4])
    n=(n&d[8])+((n>>8)&d[8])
    n=(n&d[16])+((n>>16)&d[16])
    return n

while black_magic(N) - 1:
    N &= N-1
print(N)

Measured memory_bytes: 9156
N,K=map(int,input().split())
if K>(N-1)*(N-2)/2:
  print("-1")
else:
  print(int(N*(N-1)/2-K))
  for i in range(N-1):
    print("1",i+2)
  a=(N-2)*(N-1)/2-K
  if a!=0:    
    b=2
    for j in range(N-1):
      for k in range(N-j-2):
        print(2+j,3+j+k)
        a=a-1
        if a==0:
          break
      if a==0:
        break
 

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

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //-----------------------------------------
    ll N;
    cin >> N;

    map<ll, ll> m;
    vector<ll> lst;
    lst.resize(N);
    rep(i, N)
    {
        cin >> lst[i];
        m[lst[i]]++;
    }

    ll total=0;
    for(auto itr=m.begin();itr!=m.end();++itr)
    {
        total += itr->second*(itr->second-1)/2;
    }

    rep(i, lst.size())
    {
        ll n=m[lst[i]]-1;
        cout << total - n << endl;
    }

    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int cnt[1000005];
long long mod = 998244353;
int main(){
	int n;
	cin.tie(0);
	cin >> n;
	int mv = 0;
	for(int i = 0;i < n;i++){
		int x;
		cin >> x;
		if(i == 0 && x != 0){
			cout << 0;
			return 0;
		}
		if(i != 0 && x == 0){
			cout << 0;
			return 0;
		}
		cnt[x]++;
		mv = max(mv,x);
	}
	
	long long ans = 1;
	for(int i = 1;;i++){
		if(cnt[i] == 0){
			if(i == mv+1) break;
			else{
				cout << 0;
				return 0;
			}
		}
		for(int j = 0;j < cnt[i];j++){
			ans *= cnt[i-1];
			ans %= mod;
		}
	}
	cout << ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;
using ll = long long;
using ld = double;

using bint = boost::multiprecision::cpp_int;

constexpr int MOD = 1e9 + 7;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    string s;
    cin>>n>>s;
    int l=0,r=n;
    while(r>0&&s[r-1]=='W')r--;
    while(l<n&&s[l]=='R')l++;
    int cnt=0;
    while(l!=r){
        cnt++;
        s[l]='R';
        s[r-1]='W';
        while(r>0&&s[r-1]=='W')r--;
        while(l<n&&s[l]=='R')l++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3712
#include <iostream>
using namespace std;
int main(void) {
	int count = 0;
	char a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	if (a == d)
		count++;
	if (b == e)
		count++;
	if (c == f)
		count++;
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
# AtCoder Regular Contest 061  C - たくさんの数式

s=''
aa=list(input())

for i in range(2**(len(aa)-1)):

    for j in range(len(aa)):

        s+=aa[j]

        if (i>>j) & 1:

            s += "+"

    s+="+"

s+="0"

print(eval(s))

Measured memory_bytes: 4140
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b;
  cin >> a >> b;
  cout << (a + b + 1) / 2 << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstring>
using namespace std;
 
int main()
{
	int n,m,i,j,s,ma=-1;
	cin>>n;
	string a[n];
	for (i=0;i<=n-1;i++)
		cin>>a[i];
	cin>>m;
	string b[m];
	for (i=0;i<=m-1;i++)
		cin>>b[i];
	for (i=0;i<=n-1;i++)
	{
		s=0;
		for (j=0;j<=n-1;j++)
			if (a[i]==a[j]) s++;
		for (j=0;j<=m-1;j++)
			if (a[i]==b[j]) s--;
		ma=max(ma,s);
	}
	if (ma<0) ma=0;
	cout <<ma;
}

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

#define mod 1000000007

int main() {
   // freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
	long long N, a, b;
	cin >> N;
	for(a = 1;a <= 3500;a++) {
		for(b = 1;b <= 3500;b++) {
			if((4*a*b-N*b-N*a) > 0 and N*a*b % (4*a*b-N*b-N*a) == 0) {
				cout << a << " " << b << " " << N*a*b / (4*a*b-N*b-N*a);
				return 0;
			}
		}
	}

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
    i64 N, K;
    cin >> N >> K;
    cout << min(N%K, K - (N%K)) << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
#include<string.h>
//#include<time.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define max(a,b) a>b?a:b
int dp[1001][1001];
int main() {
	int w[1001], v[1001];
	int i, j, n, W,cnt=1;
	while (~fscanf(stdin, "%d", &W), W) {
		memset(dp, 0, sizeof(dp));
		fscanf(stdin, "%d", &n);
		for (i = 1; i <= n; i++) fscanf(stdin, "%d,%d", v + i, w + i);
		for (i = 1; i <= n; i++)
			for (j = 0; j <= W; j++) {
				if (w[i] > j) dp[i][j] = dp[i - 1][j];
				else dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
			}
		for (i = 0; i <= W; i++) if (dp[n][W] == dp[n][i]) break;
		fprintf(stdout, "Case %d:\n%d\n%d\n", cnt++,dp[n][W],i);
	}
	return 0;
}

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

int bucket[10]={0};

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        bucket[min(a/400, 8)]++;
    }

    int mini = 0, maxi = 0;
    for(int i=0;i<8;++i){
        if(bucket[i]){
            mini++;
            maxi++;
        }
    }

    if(mini == 0 && bucket[8])mini = 1;
    if(bucket[8])maxi += bucket[8];

    cout << mini << ' ' << maxi << endl;

    return 0;
}


Measured memory_bytes: 256
-- C "Vacation"
-- -------------
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU

-- ByteStringを用いた入力
readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

readIntPair3 :: BS.ByteString -> (Int, Int, Int)
readIntPair3 s = (a, b, c)
  where
    (a, s') = fromJust . BS.readInt $ s
    (b, s'') = fromJust . BS.readInt . BS.dropWhile isSpace $ s'
    (c, _) = fromJust . BS.readInt . BS.dropWhile isSpace $ s''

getInt :: IO Int
getInt = readInt <$> BS.getLine

getIntPair3 :: IO (Int, Int, Int)
getIntPair3 = readIntPair3 <$> BS.getLine
-- -------------

main = do
  n <- getInt
  xs <- VU.replicateM n getIntPair3
  let step (x, y, z) (a, b, c) = (a + y`max`z, b + x`max`z, c + x`max`y)
  print . (\(a, b, c) -> a `max` b `max` c) . VU.foldl' step (0, 0, 0) $ xs

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


int main() {
  int n;
  cin >> n;
  int b[200100], w[200100];
  for(int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    b[i] = b[i-1];
    w[i] = w[i-1];
    if(c=='#') b[i]++;
    else w[i]++;
  }
  int ans = 1001001001;
  for(int i = 1; i <= n; i++) {
    int cnt = b[i-1] + w[n] -w[i];
    ans = min(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

class RangeCount {
    const int ST_SIZE = (1 << 20) - 1;
    int n;
    vi data;
    vvi segtree;

    void init(int k, int l, int r) {
        if (r - l == 1) {
            segtree[k].push_back(data[l]);
        } else {
            int lch = k * 2 + 1;
            int rch = k * 2 + 2;
            init(lch, l, (l + r) / 2);
            init(rch, (l + r) / 2, r);
            segtree[k].resize(r - l);

            merge(segtree[lch].begin(), segtree[lch].end(), segtree[rch].begin(), segtree[rch].end(), segtree[k].begin());
        }
    }

    // number of x in [i, j)
    int query(int i, int j, i64 x, int k, int l, int r) {
        if (j <= l || r <= i) {
            return 0;
        }

        if (i <= l && r <= j) {
            return upper_bound(segtree[k].begin(), segtree[k].end(), x) - segtree[k].begin();
        }

        int lc = query(i, j, x, k * 2 + 1, l, (l + r) / 2);
        int rc = query(i, j, x, k * 2 + 2, (l + r) / 2, r);
        return lc + rc;
    }

public:
    RangeCount(vi v) {
        n = v.size();
        data = vi(v);
        segtree = vvi(ST_SIZE);
        init(0, 0, n);
    }

    int exact(int i, int j, i64 x) {
        return query(i, j, x, 0, 0, n) - query(i, j, x - 1, 0, 0, n);
    }

    int le(int i, int j, i64 x) {
        return query(i, j, x, 0, 0, n);
    }

    int lt(int i, int j, i64 x) {
        return query(i, j, x - 1, 0, 0, n);
    }

    int ge(int i, int j, i64 x) {
        return query(i, j, 1e18, 0, 0, n) - query(i, j, x - 1, 0, 0, n);
    }

    int gt(int i, int j, i64 x) {
        return query(i, j, 1e18, 0, 0, n) - query(i, j, x, 0, 0, n);
    }
};

int main() {
    int n;
    cin >> n;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }
    RangeCount cnt(as);
    i64 ans = 0;
    for (int i = 0; i < n; i++) {
        ans += min(cnt.gt(0, i, as[i]), cnt.gt(i + 1, n, as[i]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 47248
data=[]
ans=[]
while
    n=gets.to_f
    if n==0 then break end
    data << [n, gets.split.map(&:to_i)]
end
data.each do |e|
    n,s=e
    m=s.inject{|a,b|a+b}/n
    bunsan=s.map{|num|(num-m)**2}.inject{|a,b|a+b}/n
    ans << Math.sqrt(bunsan)
end
ans.each{|a|p a}


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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

int N, A, B, C;
int l[8];

int dfs(int pos, int a, int b, int c)
{
    if (pos == N) {
        return a * b * c > 0 ? abs(a - A) + abs(b - B) + abs(c - C) : inf;
    }

    //l[pos]を使わない
    int r1 = dfs(pos + 1, a, b, c);
    //l[pos]をAに使う
    int r2 = dfs(pos + 1, a + l[pos], b, c) + (a ? 10 : 0);
    //l[pos]をBに使う
    int r3 = dfs(pos + 1, a, b + l[pos], c) + (b ? 10 : 0);
    //l[pos]をcに使う
    int r4 = dfs(pos + 1, a, b, c + l[pos]) + (c ? 10 : 0);

    //4通りのうち最小を返す
    return min(min(r1, r2), min(r3, r4));
}

int main()
{
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++) cin >> l[i];

    cout << dfs(0, 0, 0, 0) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef pair<lli, pii> ppi;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
    }
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
const double PI = 3.141592653589793238463;
lli solve(){
    lli a, b, c;
    cin>>a>>b>>c;
    if(c-a-b <= 0){
        cout<<"No\n";
        return 0;
    }
    lli a3 = (c-a-b) * (c-a-b);
    lli a2 = 4 * a * b;
    if(a3 > a2)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}
int main(){
    fastio;
    lli t;
    // cin>>t;
    t = 1;
    while(t>0){
        t--;
        solve();
    }
    return 0;
}

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

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

    ll n; cin >> n;

    ll cnt0 = 0;
    map<ll, ll> hat;
    REP(i, n) {
        ll tmp; cin >> tmp;
        if (tmp == 0) cnt0++;
        hat[tmp]++;
    }

    bool ok = false;
    if (cnt0 == n) ok = true;
    else if (hat.size() == 2) {
        if (hat.count(0)) {
            ll cnt = 0;
            for (auto i : hat)
                if (i.first != 0) cnt = i.second;
            if (cnt0 * 2 == cnt) ok = true;
        }
    }
    else if (hat.size() == 3) {
        ll val[3];
        ll cnt[3];
        ll i = 0;
        for (auto itr : hat) {
            val[i] = itr.first;
            cnt[i] = itr.second;
            i++;
        }
        if (cnt[0] == cnt[1] && cnt[1] == cnt[2])
            if (((val[0] ^ val[1]) ^ val[2]) == 0)
                ok = true;
    }

    if (ok) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}


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

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>
#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define bits(n) __builtin_popcount(n)


void solve()
{
    unordered_map<int, int> um;
    ordered_set s;
    int n,q;
    cin >> n>>q;
    vector<int> a(n);
    for (auto &it : a)
        cin >> it;
    vector<int> ans(q);
    vector<vector<pair<int, int>>> que(n);
    for (int i = 0; i < q; i++)
    {
        int L, R;
        cin >> L >> R;
        L--;
        R--;
        que[R].push_back({L, i});
    }
    for (int i = 0; i < n; i++)
    {
        if (um.count(a[i]))
            s.erase(um[a[i]]);
        um[a[i]] = i;
        s.insert(i);
        for (auto it : que[i])
            ans[it.second] = s.size() - s.order_of_key(it.first);
    }
    for (int i = 0; i < q; i++)
        cout << ans[i] << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 72556