akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){rev|=c=='-';c=Getchar();if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------------------------head--------------------------------------------------

const int inf=0x3f3f3f3f;
const int N=200005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,m,a[N],b[N];
ll c[N],K;

map<int,int> vis;

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	read(n);
	for(int i=1;i<=n;i++)
		read(a[i]),b[i]=i;
	read(m,K);
	n--;
	for(int i=1;i<=m;i++){
		int x;read(x);
		swap(b[x-1],b[x]);
	}
	for(int i=1;i<=n;i++){
		if(vis[i]) continue;
		int k=b[i],si;
		vi s(0);s.pb(i);
		vis[i]=1;
		while(k!=i) vis[k]=1,s.pb(k),k=b[k];
		si=SZ(s);
		for(int j=0;j<si;j++)
			c[s[(j-K%si+si)%si]]=a[s[j]+1]-a[s[j]];
	}
	c[0]=a[1];
	for(int i=1;i<=n;i++)
		c[i]+=c[i-1];
	for(int i=0;i<=n;i++)
		print(c[i]);
	return 0;
}

Measured memory_bytes: 7552
#include <algorithm>
#include <iostream>

using namespace std;

int main(){
    int t, n[3];
    cin >> t;
    while(t--){
        cin >> n[0] >> n[1] >> n[2];
        sort( n, n+3);
        for(int i=0;i<3;i++) n[i]*=n[i];
        if(n[2]-n[0]-n[1]) cout << "NO" <<endl;
        else cout << "YES" <<endl;
    }
    return 0;
}

Measured memory_bytes: 1168
N,K=list(map(int, input().split()))
S=list(input())
dvd=0
for i in range(N-1):
    if S[i]!=S[i+1]:
        dvd+=1
if 2*K>=dvd:
    print(N-1)
else:
    print(N-1-dvd+2*K)

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

using namespace std;

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

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (ll i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const ll inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec)is>>x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i, vec.size()) {
        if(i) os << " ";
        os << vec[i];
    }
    return os;
}

P dp[2][1000001];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, p; cin >> n >> p;
    vector<ll> X(n), Y(n);
    REP(i, n) cin >> X[i] >> Y[i];

    fill(dp[0], dp[2], P(-1,0));
    dp[0][0] = P(0, 0);
    REP(i, n) {
        fill(dp[i+1&1], dp[(i+1&1)+1], P(-1,-1));
        REP(j, p+1) {
            if (dp[i&1][j].first < 0) continue;
            // ??±????????????
            dp[i+1&1][j] = max(dp[i+1&1][j], P(dp[i&1][j].first, 0));
            // ??±??????
            ll x = max<ll>(0, X[i] - (-dp[i&1][j].second));
            ll need = max<ll>(0, Y[i] - x);
            if (j+need <= p) {
                ll nj = j+need;
                dp[i+1&1][nj] = max(dp[i+1&1][nj], P(dp[i&1][j].first+1, -need));
            }
        }
    }
    ll ans = 0;
    REP(j, p+1) {
        ans = max<ll>(ans, dp[n&1][j].first);
    }
    cout << ans << endl;
}

Measured memory_bytes: 34388
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    int N;
    cin >> N;
    set<string> st;
    for (int i=0;i<N;i++){
        string s;
        cin >> s;
        if (st.find(s) == st.end()){
            st.insert(s);
        }
    }
    cout << st.size() << "\n";

    return 0;
}

Measured memory_bytes: 19252
import java.util.Scanner;

public class Main{
	public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
      int S=sc.nextInt();
      int a=S%10;
      int b=S%100;
      int c=S%1000;
      
      if ((S-c)/1000==(c-b)/100){
      	System.out.println("Bad");
      }else if((c-b)/100==(b-a)/10){
      	System.out.println("Bad");
      }else if((b-a)/10==a){
      	System.out.println("Bad");
      }else{
        System.out.println("Good");
      }
      
    
    
    
    
    }
}

Measured memory_bytes: 21840
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n; cin >> n;
	vector<int> a(n+1);

	for (int i = 1; i < n+1; i++) {
		cin >> a[i];
	}

	LL ans = 0;
	int r = 1;

	//xorと+が同じなら普通に整数で管理しても同じ
	LL sum = a[1];

	for (int l = 0; l < n; l++) {
		if (r < l)r = l + 1;
		
		while (r+1<=n &&(sum^a[r + 1]) == (sum + a[r + 1])) {
			sum += a[r + 1];
			r++;
		}

		//数え上げなのでどんどん足す
		ans += r - l;

		sum -= a[l + 1];
	}

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
from collections import deque
import sys


sys.setrecursionlimit(100000)


class UnionFind:
    def __init__(self, size):
        self.parent = [-1] * (size + 1)  # 非負なら親ノード，負ならグループの要素数

    def root(self, x):  # root(x): xの根ノードを返す．
        if self.parent[x] < 0:
            return x
        elif self.parent[self.parent[x]] < 0:
            return self.parent[x]
        else:
            self.parent[x] = self.root(self.parent[x])  # xをxの根に直接つなぐ
            return self.parent[x]

    def merge(self, x, y):  # merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]:  # xの要素数がyの要素数より「小さい」とき入れ替える
            x, y = y, x
        self.parent[x] += self.parent[y]  # xの要素数を更新
        self.parent[y] = x  # yをxにつなぐ
        return True

    def issame(self, x, y):  # same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)

    def size(self, x):  # size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]

N,M = list(map(int, input().split(" ")))
uf = UnionFind(N)
for _ in range(M):
    x,y,_ = list(map(int, input().split(" ")))
    uf.merge(x,y)
anss = set()
for i in range(1,N+1):
    anss.add(uf.root(i))
print(len(anss))


Measured memory_bytes: 70488
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int ans = 0;
	while (N--) {
		int t; cin >> t;
		if (t < A || B <= t) ans++;
	}
	cout << ans << endl;
}


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

int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  if (x < 0) x *= -1;
  if (k <= x / d){
    cout << x - k * d << endl;
  } else {
    ll a = x - (d * (x / d));
    if (a < 0) a *= -1;
    ll b = a - d;
    if (b < 0) b *= -1;
    ll rest = k - (x / d);

    if (rest % 2 == 0) {
      cout << a << endl;
    } else {
      cout << b << endl;
    }
  }
}


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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

int main(){
    int a,b;
    string ans = "No";
    cin >> a >> b;
    if(a*b %2 == 1){
        ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int top, N[1000];

int pop(void);
void push(int);

int main()
{
  
  int x,y,i;
  char n[100];
  top = 0;
  
  while(scanf("%s",n) != EOF) {
   if(n[0] == '+') {
      x = pop();
      y = pop();
      push(x+y);
    }

    else if( n[0] == '-')  {
      y = pop();
      x = pop();
      push(x-y);
    }

    else if( n[0] == '*') {
      x = pop();
      y = pop();
      push(x*y);
    }

    else {
      push(atoi(n));
    }
    
  }
  
  printf("%d\n",pop());
  return 0;
  
}


void push(int a)
{
  N[++top] = a;
}

int pop()
{
  top--;
  return N[top+1];
}

Measured memory_bytes: 552
#include <iostream>
#include <cstring>

using namespace std;

int main(){
string s;
  int win=0;
  cin >> s;
  
  for(int i=0;i<s.length();i++){
   if(s[i]=='o'){
   win++;
   }
  }
  
 
  
  if(15-s.length()+win>=8){
  cout << "YES" <<endl;
  }
  else{
  cout << "NO" <<endl;
  }
  

}

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

#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;

int main()
{
    int a,b;
    cin >> a >> b;
    int count=1;
    int i=0;
    while(count<b){
        count+=(a-1);
        ++i;
    }
    cout << i << endl;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b >= c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int n, k, p, i, j;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%d%d", &k, &p);
    k %= p;
    if(k) printf("%d\n", k);
    else printf("%d\n", p);
  }
  return 0;
}


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

int n;

int main() {
  cin >> n;
  vector<int> h(n);
  rep (i, n) {
    cin >> h[i];
  }
  string ans = "Yes";
  for (int i = n-2; i > 0; i--) {
    if (h[i+1] < h[i]) h[i]--;
    if (h[i+1] < h[i]) ans = "No";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3780
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <cmath>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> p;
typedef vector<p> vp;
const int INF=1e9;
int n,k;
int ans=1e9+5;
int h[100005];
int main(int argc,char const* argv[])
{
  cin >> n >> k;
  for(int i=0;i<n;i++)
    {
      cin >> h[i];
    }
  sort(h,h+n);
  for(int i=0;i<n-k+1;i++)
    {
      ans=min(ans,h[i+k-1]-h[i]);
    }
  cout << ans << endl;
  return 0; 
}


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

using namespace std;

int main() {

  

  int n,m;
cin >> n >> m;
  vector<int> f(m);
  int a,b,c;
  
  for(int i = 0;i< m;i++){
    f.at(i)=0;
    }
  
  for(int i = 0;i< n;i++){
    cin >> a;
    for(int j=0;j<a;j++){
      cin >> b;
      f.at(b-1) +=1;
      }
    }
  for(int i = 0;i< m;i++){
    if(f.at(i)==n){
      c += 1;
      }
    }
  cout << c << endl;
        
        
  }



Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int A[3],tmp;
    scanf("%d %d %d",&A[0],&A[1],&A[2]);

    if(A[0] > A[1]){
        tmp = A[0];
        A[0] = A[1];
        A[1] = tmp;
    }
    if(A[1] > A[2]){
        tmp = A[1];
        A[1] = A[2];
        A[2] = tmp;
    }
    if(A[0] > A[1]){
        tmp = A[0];
        A[0] = A[1];
        A[1] = tmp;
    }

    tmp = (A[2] - A[1]) + (A[1] - A[0]);
    printf("%d",tmp);





    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
    string s,t;cin>>s>>t;
    int ans=101010;
    for(int i=0;i<=s.length()-t.length();++i){
        int cnt=0;
        for(int j=0;j<t.length();++j){
            if(s[i+j]!=t[j])cnt++;
        }
        ans=min(cnt,ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
N = int(input())
num_list = [int(item) for item in input().split()]
q = int(input())
q_list = [int(item) for item in input().split()]


deque = []
for i in range(1,2**N):
    temp_num = 0
    for j in range(N):
        if (i >> j) & 1 == 1:
            temp_num += num_list[j]
    deque.append(temp_num)

# res_list = list(deque)
for k in q_list:
    if k in deque:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 43080
#include<iostream>
using namespace std;
 
int main() {
 
  char ch;
  int n, i, s, t, rank;
  int card[4][14]={};  //??????????????????
   
  cin >> n;
 
  for(i=0; i<n; i++){
      cin >> ch >> rank;
      if(ch == 'S') card[0][rank] = 1;
      if(ch == 'H') card[1][rank] = 1;
      if(ch == 'C') card[2][rank] = 1;
      if(ch == 'D') card[3][rank] = 1;
  }
 
  for(s=0; s<4; s++){
    for(t=1; t<14; t++){
      if(card[s][t]) continue;
      if(s==0) ch = 'S';
      if(s==1) ch = 'H';
      if(s==2) ch = 'C';
      if(s==3) ch = 'D';
      cout << ch << " " << t << endl;
    }
  }
 
  return 0;
   
}

Measured memory_bytes: 3040
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#define INF 100000000000
#define N 200000
#define ll long long
using namespace std;

int main(){
    int n;
    cin>>n;
    if(n==0) cout<<"1"<<endl;
    else cout<<"0"<<endl;
}

Measured memory_bytes: 3592
/*
        FFFFFFFFFFFFFFFFFFFFFF
        F::::::::::::::::::::F
        F::::::::::::::::::::F
        FF::::::FFFFFFFFF::::F
          F:::::F       FFFFFF
          F:::::F
          F::::::FFFFFFFFFF
          F:::::::::::::::F
          F:::::::::::::::F
          F::::::FFFFFFFFFF
          F:::::F
          F:::::F
        FF:::::::FF
        F::::::::FF
        F::::::::FF
        FFFFFFFFFFF
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(...) cout<<__FUNCTION__<<":"<<__LINE__<<": ";debugger(#__VA_ARGS__, __VA_ARGS__);
template<typename arg>
void debugger(const char* varname, arg&& var) { cout<<varname<<" = "<<var<<endl; }
template<typename arg, typename... args>
void debugger(const char* varnames, arg&& var, args&&... vars) {
    const char* comma = strchr(varnames + 1, ',');
    cout.write(varnames, comma - varnames)<<" = "<<var<<" | ";
    int sz = 1; if(isspace(comma[sz])) sz++;
    debugger(comma + sz, vars...);
}
#define forr(i, s, n) for(ll i=(ll)(s); i<(ll)(n); ++i)
#define forn(i, n) forr(i, 0, n)
#define eb(n) emplace_back(n)
#define endl '\n'
#define fst first
#define snd second
using ll = long long;
using ii = pair<ll,ll>;
using vi = vector<ll>;
extern const int INF = INT_MAX - 5;
extern const ll LINF = LLONG_MAX - 5;
extern const int MOD = 1e9 + 7;
extern const int N = 2e5 + 200;
ll a,n,b;
int main() {
    cin>>n>>a>>b;
    ll sm = a + b;
    ll d = n / sm;
    ll md = n % sm;
    ll ans = (d * a) + min(a, md);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define lson l,mid,o<<1
#define rson mid+1,r,o<<1|1
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define I64 ll
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> P;
typedef pair<P, int> PII;
typedef pair<LL, int> PIII;
const LL INF = 0x3f3f3f3f;
const int N = 5e5 + 10;
const int M = 1e5 + 10;
const LL mod = 998244353;
const double PI=acos(-1);
inline LL ab(LL x){return x < 0 ? -x : x;}
inline int mm(int x, int p){return x >= p ? x - p : x < 0 ? x + p : x;}

int num[N];
int v[N];
int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) scanf("%d", &num[i]), v[i] = num[i];
    sort(v + 1, v + n + 1);
    for(int i = 1; i <= n; ++i){
        if(num[i] <= v[n >> 1]) printf("%d\n", v[(n >> 1) + 1]);
        else    printf("%d\n", v[n >> 1]);
    }
    return 0;
}
/*
13
0 1 1 3 3 0 6 6 8 9 9 9
100
R 8 8
R 8 8
W 8
W 6
R 1 9
W 6
R
*/


Measured memory_bytes: 3712
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

//O(V+E)
const int MAX_V = 101010;

int V;                 //頂点数
vector<int> G[MAX_V];  //グラフの辺
vector<int> rG[MAX_V]; //逆向きの辺
vector<int> vs;        //帰りがけ順の並び
bool used[MAX_V];      //既に調べたかどうか
int cmp[MAX_V];        //属する強連結成分のトポロジカル順序

void add_edge(int from, int to) {
  G[from].push_back(to);
  rG[to].push_back(from);
}

void dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    if (!used[G[v][i]]) dfs(G[v][i]);
  }
  vs.push_back(v);
}

void rdfs(int v, int k) {
  used[v] = true;
  cmp[v] = k;
  for (int i = 0; i < rG[v].size(); i++) {
    if (!used[rG[v][i]]) rdfs(rG[v][i], k);
  }
}

int scc() {
  memset(used, 0, sizeof(used));
  vs.clear();
  for (int v = 0; v < V; v++) {
    if (!used[v]) dfs(v);
  }
  memset(used, 0, sizeof(used));
  int k = 0;
  for (int i = vs.size() - 1; i >= 0; i--) {
    if (!used[vs[i]]) rdfs(vs[i], k++);
  }
  return k;
}

signed main() {
  int E;
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    add_edge(s, t);
  }

  int k = scc();

  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int u, v;
    cin >> u >> v;
    if (cmp[u] == cmp[v]) {
      cout << "1" << endl;
    } else {
      cout << "0" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 9116
def main():
    h, w, *ca = map(int, open(0).read().split())
    it = zip(*[iter(ca[:100])] * 10)
    *c, = map(lambda i: list(i), it)
    a = ca[100:]

    for k in range(10):
        for i in range(10):
            for j in range(10):
                c[i][j] = min(c[i][j], c[i][k] + c[k][j])

    ans = 0

    for i in a:
        if i in [-1, 1]:
            continue
        ans += c[i][1]

    print(ans)


if __name__ == '__main__':
    main()


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

void dfs(int u, int num, auto& used, const auto& g) {
    used[u] = num;
    for (int v : g[u]) {
        if (used[v]) continue;
        dfs(v, num, used, g);
    }
}
signed main() {
    int N, K, L;
    cin >> N >> K >> L;

    vector<vector<int>> G(N), H(N);
    for (int i = 0; i < K; i++) {
        int p, q;
        cin >> p >> q;
        --q, --p;
        G[p].push_back(q);
        G[q].push_back(p);
    }
    for (int i = 0; i < L; i++) {
        int r, s;
        cin >> r >> s;
        --r, --s;
        H[s].push_back(r);
        H[r].push_back(s);
    }

    int num;
    vector<int> g(N), h(N);
    num = 0;
    for (int i = 0; i < N; i++) {
        if (g[i] || !G[i].size()) continue;
        dfs(i, ++num, g, G);
    }
    num = 0;
    for (int i = 0; i < N; i++) {
        if (h[i] || !H[i].size()) continue;
        dfs(i, ++num, h, H);
    }

    //for (int x : g) cerr << x << " "; cerr << endl;
    //for (int x : h) cerr << x << " "; cerr << endl;

    map<pair<int, int>, int> m;
    for (int i = 0; i < N; i++) {
        if (g[i] && h[i]) m[{g[i], h[i]}]++;
    }

    for (int i = 0; i < N; i++) {
        int t = m[{g[i], h[i]}];
        cout << (t ? t : 1) << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 23168
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(x+r>0&&x+r<=w&&y+r>0&&y+r<=h){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
}



Measured memory_bytes: 3096
n = int(input())
h = [int(i) for i in input().split()]

if n==1:
  print("Yes")

else:
  flag = True
  for i in reversed(range(n-1)):
    if h[i]==h[i+1]+1:
      h[i] -= 1
    elif h[i]<=h[i+1]:
      h[i]=h[i]
    else:
      flag = False
      break
  if flag:
    print("Yes")
  else:
    print("No")

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int N;
    cin >> N;

    vi rate(9, 0);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (1    <= a && a < 400)  rate[0]++;
        if (400  <= a && a < 800)  rate[1]++;
        if (800  <= a && a < 1200) rate[2]++;
        if (1200 <= a && a < 1600) rate[3]++;
        if (1600 <= a && a < 2000) rate[4]++;
        if (2000 <= a && a < 2400) rate[5]++;
        if (2400 <= a && a < 2800) rate[6]++;
        if (2800 <= a && a < 3200) rate[7]++;
        if (a >= 3200) rate[8]++;
    }

    int ans=0;
    for (int i = 0; i < 8; i++) {
        if (rate[i] > 0) {
            ans++;
        }
    }
    cout << ans + (ans==0 && rate[8] > 0) << " " << ans + rate[8] << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
n=I()
dl=[]
taka=[]
aoki=[]
for i in range(n):
    a,b=IL()
    dl.append([i,a,b,a+b])
dl.sort(key=lambda x:-x[3])
t=1
ans=0
for i in range(n):
    if t==1:
        taka.append(i)
        t=-1
    else:
        aoki.append(i)
        t=1
for i in taka:
    ans+=dl[i][1]
for i in aoki:
    ans-=dl[i][2]
print(ans)

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

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

	int h;
	cin >> h;
	int ans = 1;
	int maxh = h;
	for( int i = 1; i < n; ++i )
	{
		cin >> h;
		if( maxh <= h )	ans++;
		maxh = max( maxh, h );
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner


import scala.io.StdIn._

object Main extends App {

  val Array(n,m) = readLine().split(" ").map(_.toInt)
  val A = readLine().split(" ").map(_.toInt)

  def solve() = {
    val sorted = A.sorted(Ordering[Int].reverse)
    val border = A.sum.toDouble / (4 * m)
    if(sorted(m-1) >= border) "Yes" else "No"
  }

  println(solve())

}



Measured memory_bytes: 55076
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int dpS[10005], dpW[10005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	vi p = {c, d};
	//compute the possible amounts of sugar
	memset(dpS, 0, sizeof(dpS));
	memset(dpW, 0, sizeof(dpW));
	dpS[0] = 1;
	rep(i, 2) for(int j = 0; j <= (10000 - p[i]); j++) dpS[j + p[i]] |= dpS[j];
	dpW[0] = 1;
	p = {a, b};
	rep(i, 2) for(int j = 0; j <= (10000 - (100 * p[i])); j++) dpW[j + (100 * p[i])] |= dpW[j];
	pi best = {-1, -1};
	for(int i = 100 * a; i <= f; i += 100) if(dpW[i]){
		//we pour in this much water
		int mx = e * (i / 100); //the max amount of sugar
		for(int j = mx; j >= 0; j--) if(dpS[j]){
			if((j + i) <= f){
				if((best.fi == -1) || (best.fi * i) < (j * best.se)){
					best = mp(j, i);
				}
				break;
			}
		}
	}
	cout << best.fi + best.se << " " << best.fi << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

using namespace std;

typedef long long ll;
#define INF (1<<29)
#define INFF 0x7fffffff
#define LINF (1ll<<60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'

#define MOD 1000000007

char arr[1010][1010];
ll dp[1010][1010] = {};

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

    int n, m;cin>>n>>m;
    _fi(n)_fj(m) cin>>arr[i][j];
    arr[0][0] = '#';

    dp[0][0] = 1;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            if (arr[i][j] == '#') continue;

            if (i > 0 && j > 0) {
                dp[i][j] = dp[i-1][j]+dp[i][j-1];
                dp[i][j] %= MOD;
            }
            else if (i == 0) dp[i][j] = dp[i][j-1];
            else if (j == 0) dp[i][j] = dp[i-1][j];
        }
    }

    cout << dp[n-1][m-1] << endl;

    return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define ll long long
#define MAX 100005
#define pb push_back
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;

int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}

ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}


bool prime[100005];
void seive()
{  memset(prime,true,sizeof(prime));
    for(int i=2;i*i<=100005;i++)
    {
         if(prime[i]==true) {
        for(int j=2*i;j<=(100005);j+=i)
           { prime[j]=false;}
           }

    }
}
 ll lcm(ll a, ll b)
 {
    return (a/gcd(a, b))*b;
 }
 ll fact(int n)
 {
     if(n==1) return 1;
     return n*fact(n-1);
 }
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  ll n;
  string s1,s2,s3;
  cin>>n>>s1>>s2>>s3;
  ll ans=0;
  for(int i=0;i<n;i++)
  {
      ll a1,a2,a3;
      if(s1[i]==s2[i]&&s2[i]==s3[i]) continue;
      if(s1[i]==s2[i]) ans+=1;
      else if(s2[i]==s3[i]||s1[i]==s3[i]) ans+=1;
      else ans+=2;

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007
const long long INF = 1LL<<60;


int main(){	
	int n;
	cin >> n;
	ll ans = 0;
	map<string, int> s;
	while(n--){
		string str;
		cin >> str;
		sort(str.begin(),str.end());
		ans += s[str]++;
	}
	cout << ans << endl;
	return 0;
 }

Measured memory_bytes: 11136
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value


void solve() {

	int N;
	cin >> N;
	vi L(N);
	for (int i = 0; i < N; i++) {
		cin >> L[i];
	}

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

	int sum = 0;
	for (int i = 0; i < N - 1; i++) {
		sum += L[i];
	}

	Yes(sum > L[N - 1]);

	return;

}

int main() {

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

	solve();

	return 0;

}

Measured memory_bytes: 256
N = int(input())
red = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x:x[1], reverse=True)
blue = sorted([list(map(int, input().split())) for _ in range(N)])

cnt = 0
for i in blue:
    for j in red:
        if i[0] > j[0] and i[1] > j[1]:
            cnt += 1
            red.remove(j)
            break

print(cnt)


Measured memory_bytes: 3060
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  int n, m, x, y; cin >> n >> m >> x >> y;
  vector<int> X(n), Y(m);
  loop(i,0,n) cin >> X[i];
  loop(i,0,m) cin >> Y[i];
  X.push_back(x);
  Y.push_back(y);
  sort(X.rbegin(), X.rend());
  sort(Y.begin(), Y.end());
  if (X[0] < Y[0]) cout << "No War" << endl;
  else cout << "War" << endl;
  return 0;
}


Measured memory_bytes: 3624
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type Pond struct {
	start int
	end   int
	area  int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	input := sc.Text()
	result := calcArea([]byte(input))

	areaSum := 0
	areas := []int{}
	for _, pond := range result {
		areaSum += pond.area
		areas = append(areas, pond.area)
	}
	fmt.Println(areaSum)
	areasFormatted := make([]string, len(areas)+1)
	areasFormatted[0] = strconv.Itoa(len(areas))
	for i, v := range areas {
		areasFormatted[i+1] = strconv.Itoa(v)
	}
	fmt.Println(strings.Join(areasFormatted, " "))
}

func calcArea(inputText []byte) []*Pond {
	stack := []int{}
	ponds := []*Pond{}
	for currentPos, char := range inputText {
		switch char {
		case '\\':
			stack = append(stack, currentPos)
		case '/':
			if len(stack) > 0 {
				downPos := stack[len(stack)-1]
				stack = stack[:len(stack)-1]
				area := currentPos - downPos
				mergeTargetPonds, newPonds := findAndPartitionExistingPondsFor(downPos, currentPos, ponds)
				var pond *Pond
				if len(mergeTargetPonds) > 0 {
					for _, v := range mergeTargetPonds {
						area += v.area
					}
					pond = &Pond{downPos, currentPos, area}
				} else {
					pond = &Pond{downPos, currentPos, area}
				}
				ponds = append(newPonds, pond)
			}
		case '_':
			// do nothing
		default:
			panic(fmt.Errorf("unknown char: %s", char))
		}
	}
	return ponds
}

func findAndPartitionExistingPondsFor(start int, end int, ponds []*Pond) ([]*Pond, []*Pond) {
	mergeTargetPonds := []*Pond{}
	newPonds := []*Pond{}
	for i := 0; i < len(ponds); i++ {
		if ponds[i].start > start && ponds[i].end < end {
			mergeTargetPonds = append(mergeTargetPonds, ponds[i])
		} else {
			newPonds = append(newPonds, ponds[i])
		}
	}
	return mergeTargetPonds, newPonds
}



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

int main() {
	
	int n;
	int c[200];
	
	while(cin>>n,n) {
		int a;
		rep(i, 2*n)c[i]=0;
		rep(i, n) {
			cin>>a;
			c[a-1]=1;
		}
		
		int s[] = {n,n};
		
		int f=n,p=1;
		
		while(f) {
			for(int i=0;(i<2*n)&&f;++i) {
				if(c[i]==p) {
					c[i] = -1;
					f = --s[p];
					p = !p;
				}
			}
			p=!p;
		}
		
		cout<<s[0]<<endl<<s[1]<<endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

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

    vector<vector<vector<ll>>> tbl(51,vector<vector<ll>>(51,vector<ll>(51,-LINF)));

    for(int i=0;i<=n;i++){ //i個宝石を取る 1ループ目
        for(int l=0;l<=i;l++){ //左からl個取り、 2ループ目
            ll r = i-l; //右からr=i-l取ることを考える
            vector<ll> juery(0);
            ll juerysum = 0;
            for(int k=0;k<l;k++){
                juery.push_back(v.at(k));
                juerysum+=v.at(k);
            }
            for(int k=n-1;k>=n-r;k--){
                juery.push_back(v.at(k));
                juerysum+=v.at(k);
            }
            sort(juery.begin(),juery.end());
            tbl.at(0).at(i).at(l) = juerysum;
            for(int j=1;j<=i;j++){ //j個返却することを考える
                tbl.at(j).at(i).at(l) = tbl.at(j-1).at(i).at(l) - juery.at(j-1);
            }
        }
    }
    ll ans = 0;
    for(int z = 0;z<=kk;z++){ //z回操作を行う場合を考える。zは最大kk回
        rep(i,51){
            rep(j,51){
                if(i+j==z){
                    rep(k,51) ans = max(ans,tbl[i][j][k]);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
/* Alohomora */
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        998244353
#define all(x) 	   x.begin(),x.end()	
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
void comp()
{
	ll i,j,k,n,m,x,y;
	string s;
	cin>>n>>x>>y;
	ll mat[n+1][n+1];
	fl(i,n+1) {
		fl(j,n+1) mat[i][j]=0;
	}
	fli(j,y,n+1)
	{
		mat[x][j]=j-y+1;
		mat[j][x]=j-y+1;
	}
	fli(j,1,y)
	{
		mat[x][j]=min(mat[x][y]+abs(j-y),abs(j-x));
		mat[j][x]=mat[x][j];
	}
	fli(i,1,n+1)
	{
		if(i!=x) {
			fli(j,1,n+1)
			{
				if(j!=x)
				{
					mat[i][j]=min(mat[i][x]+mat[x][j],abs(j-i));
				}
				//cout<<mat[i][j]<<" ";
			}
		}
		//cout<<endl;
	}
	map<ll,ll>m1;
	fli(i,1,n+1)
	{
		fli(j,i+1,n+1)
		{
			m1[mat[i][j]]++;
		}
	}
	fli(i,1,n)
	{
		cout<<m1[i]<<endl;
	}
}

int main()
{
    speedup;
    ll i=0,t;
    ll n;
    //cin>>t;
    t=1;
	while(t--)
    {
        comp();
    }
    return 0;
}


Measured memory_bytes: 31616
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
int pd[1010000],K,n,w[210000],bo[210000],ans[210000];
char ch[210000];
queue<int>Q;
void print(){
	for (int i=1;i<=n;i++) if (ans[i]) putchar('A'); else putchar('B');
	exit(0);
}
int main(){
	scanf("%d%d",&n,&K);
	scanf("%s",ch+1);
	for (int i=1;i<=n;i++) if (ch[i]=='A') pd[i]=1; else pd[i]=0;
	int l=1,now=0;
	for (;K;K--){
	//	cout<<"fa "<<K<<" "<<l<<endl;
	//	for (int i=1;i<=n;i++) cout<<(pd[l+i-1]^now)<<" "; cout<<endl;
		if (l>n){
			if ((n&1)&&(pd[l]^now)==1){
				for (int i=1;i<=n;i++) ans[i]=i&1;
				if (K&1) ans[1]=0;
				print();
			}
			if (n%2==0){
				for (int i=1;i<=n;i++) ans[i]=(i&1)^1;
				print();
			}
		}
		if (pd[l]==now){
			l++; pd[l+n-1]=now; now^=1;
		} else pd[l]^=1;
	}
	for (int i=1;i<=n;i++) ans[i]=pd[i+l-1]^now;
	print();
}

Measured memory_bytes: 5504
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 100;

int main() {
	int N;
	long long dp[MAX] = { 0 };

	dp[0] = 2;
	dp[1] = 1;

	cin >> N;

	for (int i = 2; i <= N; i++) {
		dp[i] = dp[i - 1] + dp[i - 2];
	}

	cout << dp[N] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <queue>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;


int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    int res = 0;

    vector <int> p(N);
    vector <int> q(N);
    vector <int> san(N);

    REP(i, N)
    {
        cin >> p[i];
        san[i] = p[i];
    }
    REP(i, N)
    {
        cin >> q[i];
    }

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

    ll cnt = 1;
    int a = 0;
    int b = 0;

    do {
        
        bool flag = true;
        for(int i = 0; i < N; ++i)
        {
            if(p[i] != san[i])
            {
                flag = false;
                break;
            }
        }
        if(flag)a = cnt;

        flag = true;
        for(int i = 0; i < N; ++i)
        {
            if(q[i] != san[i])
            {
                flag = false;
                break;
            }
        }
        if(flag)b = cnt;

        if(a != 0 && b != 0)break;
    
        ++cnt;
    } while (std::next_permutation(san.begin(), san.end()));

    res = abs(a-b);

    cout << res << endl;

    return 0;
}


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

using lint = long long;
const lint INF = 1e18;

int main() {
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<lint> s(A + 2), t(B + 2), x(Q);
    s[0] = t[0] = -INF;
    s[A + 1] = t[B + 1] = INF;
    for (int i = 1; i <= A; i++) {
        cin >> s[i];
    }
    for (int i = 1; i <= B; i++) {
        cin >> t[i];
    }
    for (int i = 0; i < Q; i++) {
        cin >> x[i];
    }

    for (int i = 0; i < Q; i++) {
        vector<lint> sp(2), tp(2);
        sp[0] = *(lower_bound(s.begin(), s.end(), x[i]) - 1);
        sp[1] = *lower_bound(s.begin(), s.end(), x[i]);
        tp[0] = *(lower_bound(t.begin(), t.end(), x[i]) - 1);
        tp[1] = *lower_bound(t.begin(), t.end(), x[i]);

        lint ans = INF;
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                ans = min(ans, min(abs(x[i] - sp[j]) + abs(sp[j] - tp[k]), abs(x[i] - tp[k]) + abs(tp[k] - sp[j])));
            }
        }

        cout << ans << endl;
    }

    return 0;
}

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

typedef struct
{
    int s;
    int c;
} num_t;

// --------------- 比較用の関数 cmp -------------------
int cmp(const void *p, const void *q)
{
    return ((num_t *)p)->s - ((num_t *)q)->s;
}

int main()
{
    /* ------- 宣言と入力 ------- */

    int N, M;

    cin >> N >> M;

    int s[M];
    int c[M];
    int ans[N];

    for (int i = 0; i < M; i++)
    {
        cin >> s[i] >> c[i];
    }

    /* ------- 計算 ------- */

    num_t lst[M];

    for (int i = 0; i < M; i++)
    {
        lst[i].s = s[i];
        lst[i].c = c[i];
    }

    qsort(lst, M, sizeof(num_t), cmp);

    for (int i = 0; i < M; i++)
    {
        if (i != 0 && lst[i - 1].s == lst[i].s && lst[i - 1].c != lst[i].c)
        {
            cout << "-1" << endl;
            return 0;
        }

        if (N > 1 && lst[i].s == 1 && lst[i].c == 0)
        {
            cout << "-1" << endl;
            return 0;
        }
    }

    for (int i = 0; i < N; i++)
    {
        ans[i] = 0;
    }
    if (N == 1)
        ans[0] = 0;
    else 
        ans[0] = 1;
    for (int i = 0; i < M; i++)
    {
        ans[lst[i].s - 1] = lst[i].c;
    }

    for (int i = 0; i < N; i++)
    {
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import sys

class UnionFind:
    def __init__(self,sz):
        self.__ranks = [1] * sz
        self.__parents = [ i for i in range(sz) ]
    def find_parent(self, x):
        if x == self.__parents[x]:
            return x
        else:
            self.__parents[x] = self.find_parent(self.__parents[x])
            return self.__parents[x]
    def same(self, x, y):
        return self.find_parent(x) == self.find_parent(y)
    def unite(self, x, y):
        px = self.find_parent(x)
        py = self.find_parent(y)
        if px == py:
            return
        if self.__ranks[px] > self.__ranks[py]:
            self.__parents[py] = px
        else:
            self.__parents[px] = py
            if self.__ranks[px] == self.__ranks[py]:
                self.__ranks[py] += 1

def main():
    n,w,h = map(int, input().split())

    uf = UnionFind(n)
    xd = {}
    yd = {}
    is_edges_slime = False
    for i in range(n):
        x,y = map(int, sys.stdin.readline().split())

        if x == 1 or x == w:
            is_edges_slime = True
        if y == 1 or y == h:
            is_edges_slime = True

        if x in xd:
            uf.unite(xd[x], i)
        else:
            xd[x] = i
        
        if y in yd:
            uf.unite(yd[y], i)
        else:
            yd[y] = i

    root = set()
    for i in range(n):
        root.add( uf.find_parent(i) )

    if len(root) == 1:
        print(n - 1)
    else:
        ans = n - len(root) # ????´?????????¨??????
        ans += len(root) - (1 if is_edges_slime else 0) # ???????????????
        ans += len(root) - 1 # ????????°???????????????
        print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 18636
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
pair<int,int> leader[300001];
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  if(s[0]=='W')
    leader[0].first=1;
  if(s[n-1]=='E')
    leader[n-1].second=1;
  for(int i=1;i<n;i++){
    if(s[i]=='W')
      leader[i].first=leader[i-1].first+1;
    else
      leader[i].first=leader[i-1].first;
  }
  for(int i=n-2;i>=0;i--){
    if(s[i]=='E')
      leader[i].second=leader[i+1].second+1;
    else
      leader[i].second=leader[i+1].second;}
  int mn=100000007;
  for(int i=0;i<n;i++){
    mn=min((leader[i].first+leader[i].second-1),mn);}
  cout<<mn;
  return 0;
}

Measured memory_bytes: 2948