akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    REP(i, 1, 10) {
        REP(j, 1, 10) {
            if (i * j == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n,m,e[200][200];

int main()
{
	while(cin>>n,n)
	{
		map<string,int> id;
		rep(i,2*n)rep(j,2*n)e[i][j]=inf;
		
		string u1,u2,t; m=0;
		rep(i,n)
		{
			cin>>t>>u1>>t>>t>>u2;
			if(!id.count(u1))id[u1]=m++;
			if(!id.count(u2))id[u2]=m++;
			e[id[u1]][id[u2]]=atoi(t.substr(3).c_str());
			e[id[u2]][id[u1]]=-e[id[u1]][id[u2]];
		}
		rep(k,m)rep(i,m)rep(j,m)e[i][j]=min(e[i][j],e[i][k]+e[k][j]);
		bool f=0;
		rep(i,m)if(e[i][i]!=inf&&e[i][i]!=0)f=1;
		puts(f?"No":"Yes");
	}
	return 0;
}

Measured memory_bytes: 1084
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 21

int H, W;
char S[SIZE][SIZE];

int bfs(int sy, int sx) {
  queue<pair<int,int>> que1, que2;
  bool visited[SIZE][SIZE] = {};

  que1.push({sy, sx});

  int res = 0;

  for (int i=0; que1.size(); i++) {
    while(que1.size()) {
      auto p = que1.front();
      que1.pop();

      int y = p.first;
      int x = p.second;

      if (S[y][x] == '#') continue;
      if (visited[y][x]) continue;
      visited[y][x] = true;

      res = max(res, i);

      if (y > 0) que2.push({y-1, x});
      if (x > 0) que2.push({y, x-1});
      if (y < H-1) que2.push({y+1, x});
      if (x < W-1) que2.push({y, x+1});
    }

    swap(que1, que2);
  }

  return res;
}

int main() {

  scanf("%d%d", &H, &W);

  for (int i=0; i<H; i++)
    scanf("%s", S[i]);

  int ans = 0;

  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (S[i][j] == '#') continue;
      debug(bfs(i, j));
      ans = max(ans, bfs(i, j));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys


def main():
    input = sys.stdin.buffer.readline
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    for a in a_list:
        n -= a
        if n < 0:
            break
    print(n if n >= 0 else -1)


if __name__ == '__main__':
    main()


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

using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');

int main() {
  ll n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<math.h>
#define INF 100000001

int xy[101][101];
int p[101];


int z(int a,int b){
  int i;
  int Min=INF;
  int num=b-a;
  for(i=0;i<num;i++){
    Min=fmin(Min,xy[a][a+i]+xy[a+i+1][b]+p[a-1]*p[a+i]*p[b]);
  }
  return Min;
}



int main(){
  int i,j,k,l,m,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&p[i],&m);
  }
  p[n]=m;
  
  for(i=1;i<=n;i++){
    xy[i][i]=0;
  }

  for(i=1;i<n;i++){
    xy[i][i+1]=p[i-1]*p[i]*p[i+1];
  }
  
  for(j=0;j<=n-3;j++){
    for(i=3+j;i<=n;i++){
      xy[i-2-j][i]=z(i-2-j,i);
    }
  }
  printf("%d\n",xy[1][n]);

  return 0;
}



Measured memory_bytes: 2104
def main():
    n = int(input())
    A = input()
    B = input()
    C = input()
    count = 0
    for i in range(n):
        a = A[i]
        b = B[i]
        c = C[i]
        if a == b == c:
            continue
        elif a == b or b == c or c == a:
            count += 1
        else:
            count += 2
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll a,b,c;
  cin >> a >> b >> c;
  ll x=min(c,b);
  c-=x;
  b-=x;
  ll ans=x*2;
  ans+=b;
  x=min(a,c);
  c-=x;
  a-=x;
  ans+=x;
  if(c) ans++;
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
package main

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

func main() {
	a := []string{}
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	n, _ := strconv.Atoi(strings.Split(sc.Text(), " ")[0])
	for i := 0; i < n; i++ {
		sc.Scan()
		a = append(a, sc.Text())
	}
	sort.Strings(a)
	fmt.Println(strings.Join(a, ""))
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    string s;
    cin >> s;
    string S[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    rep(i,7) {
        if (s != S[i]) continue;
        cout << 7-i << endl;
    }
    return 0;
}


Measured memory_bytes: 3552
//Volume1-0103
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//initialization
		int    out,
		       runner,
		       score;
		String s;

        //input
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while(n-- > 0){
        	out    = 0;
        	runner = 0;
        	score  = 0;
        	while(out != 3){
            	s = sc.next();

            	//calculation
            	if(s.equals("HIT")){
            		if   (runner == 3){score++; }
            		else              {runner++;}
           		}
            	if(s.equals("OUT")){out++;}
            	if(s.equals("HOMERUN")){
            		score += runner + 1;
            		runner = 0;
            	}
        	}

        	//output
        	System.out.println(score);
        }
	}
}

Measured memory_bytes: 15356
#include <iostream>

using namespace std;

int main(){
    int n, s[13] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, h[13] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, c[13] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, d[13] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
    string a;
    int b;
    
    cin >> n;
    
    for(int i=0;i<n;i++){
        cin >> a >> b;
        if(a=="S"){
            s[b-1] = 0;
        }
        else if(a=="H"){
            h[b-1] = 0;
        }
        else if(a=="C"){
            c[b-1] = 0;
        }
        else{
            d[b-1] = 0;
        }
    }
    
    for(int j=0;j<13;j++){
        if(s[j]==1){
            cout << "S " << j+1 << endl;
        }
    }
    
    for(int j=0;j<13;j++){
        if(h[j]==1){
            cout << "H " << j+1 << endl;
        }
    }
    
    for(int j=0;j<13;j++){
        if(c[j]==1){
            cout << "C " << j+1  << endl;
        }
    }
    
    for(int j=0;j<13;j++){
        if(d[j]==1){
            cout << "D " << j+1 << endl;
        }
    }
}


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

int main(void) {

    vector<int> H;
    vector<int> field;
    int N, M;
    cin >> N >> M;

    H.reserve(N + 1);
    field.reserve(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> H[i];
    }

    for (int i = 1; i <= M; i++) {
        int a, b;
        cin >> a >> b;

        field[a] = max(field[a], H[b]);
        field[b] = max(field[b], H[a]);
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += H[i] > field[i];
    }

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

Measured memory_bytes: 4192
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;


int main(){
 int h,w; cin>>h>>w;
 char masu[h][w];
 bool hb[h]; REP(i,h)hb[i]=false;
 bool wb[w]; REP(i,w)wb[i]=false;
 REP(i,h)REP(j,w)cin>>masu[i][j];

 REP(i,h){
     bool check=true;
     REP(j,w){
         if(masu[i][j]=='#')check=false;
     }
     if(check)hb[i]=true;//trueならその行は白行
 }
 REP(j,w){
     bool check=true;
     REP(i,h){
         if(masu[i][j]=='#')check=false;
     }
  if(check)wb[j]=true;
 }

 REP(i,h){
     REP(j,w){
         if(hb[i]!=true&&wb[j]!=true)cout<<masu[i][j];
     }
     if(hb[i]!=true)cout<<endl;
 }
 
}


Measured memory_bytes: 256
//二分图 
#include<cstdio> 
#include<iostream> 
#include<map> 
#include<vector> 
#include<algorithm> 
#include<cstring>
using namespace std; 
#define MAXN 205 
int N; 
struct node{ 
    int x,y; 
}; 
node a[2*MAXN];
vector<int>G[MAXN];
int ma[2*MAXN];
bool vis[2*MAXN];
bool dfs(int u)
{
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i];
		if(vis[v]) continue;
		vis[v]=1;
		if(ma[v]==0||dfs(ma[v]))
		{
			ma[u]=v;
			ma[v]=u;
			return true;
		}
	}
	return false;
}
int main() 
{ 
    scanf("%d",&N); 
    for(int i=1;i<=2*N;i++) 
    	scanf("%d %d",&a[i].x,&a[i].y);
    for(int i=1;i<=N;i++)
		for(int j=N+1;j<=2*N;j++)
		if(a[i].x<a[j].x&&a[i].y<a[j].y)
		{
			G[i].push_back(j);
			G[j].push_back(i);
		}
	int ans=0;
	for(int i=1;i<=N;i++)
	{
		memset(vis,0,sizeof(vis));
		if(dfs(i))
			ans++;
	}
	printf("%d\n",ans);
}
 



Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;
struct UF
{
	vector<int>v;
	UF():v(100,-1){};
	int R(int x){return v[x]<0?x:v[x]=R(v[x]);}
	int U(int x,int y)
	{
		x=R(x);
		y=R(y);
		if(x-y)
		{
			if(v[x]<v[y])swap(x,y);
			v[y]+=v[x];
			v[x]=y;
		}
		return x-y;
	}
};
double F(double x){return x*x;}
struct S{double d;int a,b;S(double d,int a,int b):d(d),a(a),b(b){}bool operator<(const S&s)const{return d<s.d;}};
int main()
{
	int n,i,j;
	double x[100],y[100],z[100],r[100],d,res;
	while(scanf("%d",&n),n)
	{
		vector<S>v;
		UF uf;
		for(i=0;i<n;++i)scanf("%lf%lf%lf%lf",x+i,y+i,z+i,r+i);
		for(i=0;i<n;++i)for(j=i+1;j<n;++j)
		{
			d=sqrt(F(x[i]-x[j])+F(y[i]-y[j])+F(z[i]-z[j]))-r[i]-r[j];
			if(d<0)uf.U(i,j);
			else v.push_back(S(d,i,j));
		}
		sort(v.begin(),v.end());
		res=0;
		for(i=0;i<v.size();++i)
		{
			S s=v[i];
			if(uf.U(s.a,s.b))res+=s.d;
		}
		printf("%.3f\n",res);
	}
	return 0;
}

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

#define MAX 100005
#define NIL -1

struct node{
  int p;
  int l;
  int r;
};

struct node T[MAX];
int D[MAX];//深さ

void print(int u){
  int i,c;

  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p==NIL) printf("root, ");
  else if(T[u].l == NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i){
      printf(", ");
    }
    printf("%d",c);
  }
  printf("]\n");
}

void rec(int u,int p){
  D[u]=p;
  if(T[u].r!=NIL) rec(T[u].r,p);
  if(T[u].l!=NIL) rec(T[u].l,p+1);
}

int main(){
  int n,i,j,v,d,c,l,r;


  scanf("%d",&n);
  for(i=0;i<n;i++)
    T[i].l=T[i].r=T[i].p=NIL;

  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }

  for(i=0;i<n;i++){
    if(T[i].p == NIL) r = i;
  }

  rec(r,0);

  for(i=0;i<n;i++) print(i);

  return 0;
}





Measured memory_bytes: 6416
import sys
input=sys.stdin.readline
n=int(input())
sp=[]
sn=[]
for i in range(n):
    s=input().rstrip()
    m=0
    temp=0
    for j in s:
        if j=='(':
            temp+=1
        else:
            temp-=1
        m=min(m,temp)
    m=-m
    if temp>=0:
        sp.append((m,temp))
    else:
        sn.append((m+temp,-temp))
sp.sort()
sn.sort()
vp=0
for i in sp:
    if vp-i[0]<0:
        print('No')
        sys.exit()
    else:
        vp+=i[1]
vn=0
for i in sn:
    if vn-i[0]<0:
        print('No')
        sys.exit()
    else:
        vn+=i[1]
if vp==vn:
    print('Yes')
else:
    print('No')


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

int main(){
  int N;
  cin >> N;
  int S,E;
  int C = 0;
  
  for (int i = 0; i < N; i++){
    cin >> S >> E;
    C += E - S + 1;
  }
  
  cout << C << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a)-1)
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}
const int N=3e3+5;
vector<int> niz(N);
int n;
vector<vector<ll> > dp(N,vector<ll>(N,-1));
ll calc(int l,int r)
{
    if(l>r)
        return 0;
    if(dp[l][r]!=-1)
        return dp[l][r];
    int po=l+n-1-r;
    if(po%2==0)
    {
        return dp[l][r]=max(calc(l+1,r)+niz[l],calc(l,r-1)+niz[r]);
    }
    return dp[l][r]=min(calc(l+1,r)-niz[l],calc(l,r-1)-niz[r]);
}
int main()
{
    scanf("%i",&n);
    for(int i=0;i<n;i++)
        cin >> niz[i];
    printf("%lld\n",calc(0,n-1));
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int q;
  cin >> q;
  rep(i,q){
      int k;
      cin >> k;
      ll a=0,m=0,l=0,ans=0;
      rep(i,n){
          if (s[i]=='D') a++;
          if (s[i]=='M'){
              m++;
              l+=a;
          }
          if (s[i]=='C') ans+=l;
          if (i+1-k>=0){
              if (s[i+1-k]=='D'){
                  a--;
                  l-=m;
              }
              if (s[i+1-k]=='M'){
                  m--;
              }
          }
      }
      cout << ans << endl;
  }
}


Measured memory_bytes: 1412
import scala.io.StdIn.{readLine,readInt}

object Main {

  def main(args: Array[String]) = {
    readInt
    val l = readLine.split(" ").map(_.toInt)
    printf("%d %d %d\n",l.min,l.max,l.foldLeft(0.toLong)(_+_))
  }
}

Measured memory_bytes: 49316
#include <iostream>

using namespace std;

int main() {
    
    int N;
    cin >> N;
    
    int sum = 0; 
    int res = 0;
    int div = N;

    while(div >= 1) {
        res = div % 10;
        div = div / 10;
        sum += res;
    }
    
    sum += div;
    
    if(N % sum == 0) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

Measured memory_bytes: 256
N = gets.to_i 
S = gets.strip.split('')

A = [{"o" => 2, "x" => 1, :c => "S"},
     {"o" => 1, "x" => 2, :c => "S"},
     {"o" => 3, "x" => 0, :c => "W"},
     {"o" => 0, "x" => 3, :c => "W"}]
     
def automato(ini)
  state = ini
  line = ""
  S.each do |xo| 
    line << A[state][:c]
    state = A[state][xo]
  end
  state == ini ? line : ""
end

flag = false 
(0..3).each do |ini|
  ans = automato(ini)
  if ans != ""
    puts ans
    flag = true 
    break 
  end
end
puts "-1" if flag == false 

Measured memory_bytes: 7548
class UnionFind():
  def __init__(self,n):
    self.n=n
    self.root=[-1]*(n+1)
    self.rnk=[0]*(n+1)
  def Find_Root(self,x):
    if self.root[x]<0:
      return x
    else:
      self.root[x]=self.Find_Root(self.root[x])
      return self.root[x]
  def Unite(self,x,y):
    x=self.Find_Root(x)
    y=self.Find_Root(y)
    if x==y:
      return 
    elif self.rnk[x]>self.rnk[y]:
      self.root[x]+=self.root[y]
      self.root[y]=x
    else:
      self.root[y]+=self.root[x]
      self.root[x]=y
      if self.rnk[x]==self.rnk[y]:
        self.rnk[y]+=1
  def isSameGroup(self,x,y):
    return self.Find_Root(x)==self.Find_Root(y)
  def Count(self,x):
    return -self.root[self.Find_Root(x)]
N,M=map(int,input().split())
uf=UnionFind(N)
AB=[]
for i in range(M):
  AB.append(list(map(int,input().split())))
ans=[0]*M
ans[M-1]=(N*(N-1))//2
for i in range(M-2,-1,-1):
  if uf.isSameGroup(AB[i+1][0],AB[i+1][1]):
    ans[i]=ans[i+1]
  else:
    n1=uf.Count(AB[i+1][0])
    n2=uf.Count(AB[i+1][1])
    ans[i]=ans[i+1]-n1*n2
  uf.Unite(AB[i+1][0],AB[i+1][1])
for i in range(M):
  print(ans[i])

Measured memory_bytes: 34216
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    string S;
    cin >> S;
    int N = S.length();
    int eve=0, odd=0;
    REP(i, N){
        if(i%2){
            odd += S[i]=='1';
        }else{
            eve += S[i]=='1';
        }
    }
    cout << min(odd+((N+1)/2-eve), eve+(N/2-odd)) << el;
}



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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;


int main(){
  ll N;
  cin >> N;
  ll beki = 26;
  int keta= 1;
  while(N > beki){
    N-= beki;
    keta++;
    beki*=26;
  }

  string ans;
  N--;
  REP(i, keta){
    ans += N%26 + 'a';
    N /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;

  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

using namespace std;

const int MOD = 1e9+7;

int main(){
  long long n,m,sx=0,sy=0,a,b;

  scanf("%lld%lld",&n,&m);
  vector<int> x(n);
  vector<int> y(m);
  a = n - 1;
  b = m - 1;
  REP(i,n) scanf("%d",&x[i]);
  REP(i,m) scanf("%d",&y[i]);

  REP(i,n){
    sx += (2*i-a)*x[i];
    sx %= MOD;
  }
  REP(i,m){
    sy += (2*i-b)*y[i];
    sy %= MOD;
  }

  a = sx * sy;
  printf("%lld\n",a%MOD);
  return 0;
}


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


ll mod = 1e9+7;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}

ll modconv(ll n, ll k){
	ll res = 1;
	for (ll i = n; i >= n-k+1; i--) res = res * i % mod;
	for (ll i = 1; i <= k; i++) res = res * modinv(i) % mod;
	return res;
}

int main(){
    ll N, M, K;
    cin >> N >> M >> K;
    
    ll ans = 0;
    ll t = modconv(N*M-2, K-2);
    ans += N*N %mod *M %mod *(M-1) %mod *(M+1)%mod*modinv(6)%mod*t%mod;
    ans += M*M %mod *N %mod *(N-1) %mod *(N+1)%mod*modinv(6)%mod*t%mod;
    cout << ans%mod << endl;
    return 0;
}

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 int ll;

int main() {
  char a, b; cin >> a >> b;
  int a2 = a - '0';
  int b2 = b - '0';
  string a3 =  "", b3 = "";
  rep(i, b2) a3 += a;
  rep(i, a2) b3 += b;
  cout << min(a3, b3);
  return 0;
}

Measured memory_bytes: 256
import sys
path=[list(map(int,e.split(',')))for e in sys.stdin]
for i in range(1,len(path)):
    for j in range(len(path[i])):
        if len(path[i])>len(path[i-1]):
            start=0 if j<1 else j-1
            path[i][j]+=max(path[i-1][~-j*(j>0):j+1])
        else:
            path[i][j]+=max(path[i-1][j:j+2])
print(path[-1][-1])


Measured memory_bytes: 5616
n = int(input())
a = list(map(int,input().split()))
num = [0]*9
for i in range(n):
    if a[i] < 400:
        num[0] += 1
    elif a[i] < 800:
        num[1] += 1
    elif a[i] < 1200:
        num[2] += 1
    elif a[i] < 1600:
        num[3] += 1
    elif a[i] < 2000:
        num[4] += 1
    elif a[i] < 2400:
        num[5] += 1
    elif a[i] < 2800:
        num[6] += 1
    elif a[i] < 3200:
        num[7] += 1
    else:
        num[8] += 1
ans = 0
for i in range(8):
    if num[i] != 0:
        ans += 1
print(max(ans,1), ans + num[-1])



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

string S;

int main() {
  cin >> S;

  int counter = 0;

  for (int i = 0; i < (S.length() / 2); i++) {
    if (S[i] != S[S.length() - i - 1]) {
      counter++;
    }
  }

  cout << counter << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

vector<ll> A;
ll ans = 0;

void cal(ll from , ll to , ll h){
	if (from == to){
		ans += A[from]-h;
		return ;
	}

	ll min_num = 1000;
	ll min_idx_from = -1;


	for(ll i = from; i <= to; i++){
		if(A[i] < min_num){
			min_num = A[i];
			min_idx_from = i;
		}
	}

	ll min_idx_to = min_idx_from;
	for(ll i = min_idx_from; i<= to; i++){
		if(A[i] == A[min_idx_from]) min_idx_to = min_idx_from;
		else break;
	}

	if(from != min_idx_from) cal(from, min_idx_from-1, min_num);
	ans += (min_num - h);
	if(to != min_idx_to) cal(min_idx_to+1, to, min_num);
}

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

	ll N;


	cin >> N;
	rep(i, N){
		ll inp;
		cin >> inp;
		A.pb(inp);
	}

	cal(0, N-1, 0);

	cout << ans << endl;


	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


Measured memory_bytes: 384
# coding: utf-8
yama=[0 for i in range(int(input()))]
t=list(map(int,input().split()))
a=list(map(int,input().split()))

check=0
for i in range(len(yama)):
    if check!=t[i]:
        check=t[i]
        yama[i]=check
    else:
        yama[i]=-check
check=0
for i in range(len(yama)):
    if yama[len(yama)-i-1]>0 and yama[len(yama)-i-1]>a[len(yama)-i-1]:
        print(0)
        exit()
    if check!=a[len(yama)-i-1]:
        check=a[len(yama)-i-1]
        if yama[len(yama)-i-1]>0 and yama[len(yama)-i-1]>check:
            print(0)
            exit()
        yama[len(yama)-i-1]=check
    else:
        if yama[len(yama)-i-1]<0:
            yama[len(yama)-i-1]=max(-check,yama[len(yama)-i-1])

x=1
for i in yama:
    if i<0:
        x=(x*-i)%1000000007

print(x)


Measured memory_bytes: 19964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//clock_t begin = clock();
	int h, n;
	cin >> h >> n;
	vector<pi>v(n + 1);
	for (int i = 0; i < n; i++) {
		cin >> v[i].fi >> v[i].se;
	}
	vector<ll>dp(h + 1, 1e9);
	dp[h] = 0;
	for (int i = h; i >= 0; i--) {
		for (int j = 0; j < n; j++) {
			int can = v[j].fi;
			int by = v[j].se;
			if (i - can <= 0)
				dp[0] = min(dp[0], dp[i] + by);
			else
				dp[i - can] = min(dp[i - can], dp[i] + by);
		}
	}
	cout << dp[0] << endl;
	//clock_t end = clock();
	//cerr << "Time run: " << (float)(end - begin) / CLOCKS_PER_SEC << " s" << endl;
}

Measured memory_bytes: 3720
N, K = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

E = [0] * N
for i in range(N):
  E[i] = (1+p[i])/2

e = sum(E[:K])
ans = e
for i in range(1, N-K+1):
  e = e - E[i-1] + E[i+K-1]
  if ans < e:
    ans = e
    
print(ans)


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

int main(){
    int n;
    cin >> n;
    int num;
    int odd=0, m2=0, m4=0;
    
    for(int i=0; i<n; i++){
        cin >> num;
        if(num%2==1) odd++;
        else if(num%4==0) m4++;
        else m2++;
    }
    if(m2==0) m4++;
    if(m4>=odd) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
long double pi=3.14159265358979323846L;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
void nckinit(ll n,ll md){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=md;
  }
  gya[n]=gyaku(kai[n],md);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=md;
  }
  gya[0]=1;
}
ll nck(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  ret*=gya[k];
  ret%=md;
  return ret;
}
ll npk(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,m;cin>>n>>m;
    ll u=1000000000001,d=0;
    while(u-d>1){
        ll mid=(u+d)/2;
        if(m<2*mid){
            u=mid;
            continue;
        }
        ll t=m-2*mid;
        ll nn=n+t/2;
        if(nn>=mid)d=mid;
        else u=mid;
    }
    cout<<d<<endl;
}



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

int main(){
    string s, t;    cin >> s >> t;
    string ans = "No";
    int tc = t.size();
    for(int i=0; i<tc; i++){
      string tmp = t.substr(i, tc-i);
      tmp += t.substr(0, i);
      if(tmp==s) ans = "Yes";  
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
// Why am I so dumb? :c
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e5 + 5;

struct person {
	int a, b, c;

	person() {
		a = b = c = 0;
	}

	const bool operator <(person &other) {
		return a - b > other.a - other.b;
	}
};

ll pref[MAXN], suff[MAXN];

person arr[MAXN];

int cnt[3], n;

ll ans;

void solve() {
	for (int i = 0; i < 3; ++i) {
		scanf("%d", &cnt[i]);
		n += cnt[i];
	}

	for (int i = 1; i <= n; ++i) {
		scanf("%d %d %d", &arr[i].a, &arr[i].b, &arr[i].c);
	}

	sort(arr + 1, arr + n + 1);

	for (int i = 1; i <= n; ++i) {
		arr[i].a -= arr[i].c;
		arr[i].b -= arr[i].c;
	}

	multiset<int> S;
	ll cur = 0;

	for (int i = 1; i <= n; ++i) {
		pref[i] = pref[i - 1] + arr[i].a;
		S.insert(arr[i].a);

		if (S.size() > cnt[0]) {
			pref[i] -= *S.begin();
			S.erase(S.begin());
		}
	}

	S.clear();

	for (int i = n; i > 0; --i) {
		suff[i] = suff[i + 1] + arr[i].b;
		S.insert(arr[i].b);

		if (S.size() > cnt[1]) {
			suff[i] -= *S.begin();
			S.erase(S.begin());
		}
	}

	ans = -(ll)1e15;

	for (int p = cnt[0]; p + cnt[1] <= n; ++p) {
		ans = max(ans, pref[p] + suff[p + 1]);	
	}

	for (int i = 1; i <= n; ++i) {
		ans += arr[i].c; 
	}

	printf("%lld\n", ans);
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 7424
#ABC139-E League
"""
全試合を頂点として、試合の順序を、先にやる試合→後にやる試合
で辺を張る。この時、後にやる試合の入次数を保持する。
入次数が0である試合は、それより前にやる試合が無いと言えるので、そのような試合から行っていく。
その頂点から出ている辺の入次数を-1する。
これを繰り返した結果、全試合(n(n-1)/2)が行えていればかかった日数を、
そうでないなら-1を出力する。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
edge = [[] for _ in range(2*(10**6))] #桁ずらしで管理。
dim_in = [-1]*(2*(10**6)) #-1のままなら、使われなかったことになる
dig = 10**3
for i in range(n):
    lst1 = list(map(int,readline().split()))
    fr = None
    for j in lst1:
        go = max(i,j-1) + min(i,j-1)*dig
        if fr != None:
            if dim_in[fr] < 0:
                dim_in[fr] = 0
            if dim_in[go] < 0:
                dim_in[go] = 0
            edge[fr].append(go)
            dim_in[go] += 1
        fr = go

#初日に行える試合を求める
can_game = []
count = 0
for idx,i in enumerate(dim_in):
    if i == 0:
        count += 1
        can_game.append(idx)

day = 0
while len(can_game) > 0:
    next_game = []
    for i in can_game:
        for j in edge[i]:
            dim_in[j] -= 1
            if dim_in[j] == 0:
                count += 1
                next_game.append(j)
    can_game = next_game
    day += 1

if count >= n*(n-1)//2:
    print(day)
else:
    print(-1)

Measured memory_bytes: 157608
#include <iostream>
 
int main()
{
  int N, A, B, sum = 0;
  std::cin >> N >> A >> B;
  
  for(int i = 1; i <= N; i++)
  {
    int digit_num_sum = 0;
    for(int digit_num = i; digit_num > 0; digit_num = digit_num / 10)
    {
      digit_num_sum += digit_num % 10;
    }
    
    if(digit_num_sum >= A && digit_num_sum <= B)
    {
      sum += i;
    }
  }
  
  std::cout << sum;
  return 0;
}

Measured memory_bytes: 3168
#import<bits/stdc++.h>
using namespace std;
pair<long,long>p[1<<18];
long I,A,n,r,b,d,t,i;
main()
{
    d=I=b=1e9;
    for(cin>>n; i<n; i++)
    {
        cin>>p[i].first>>p[i].second;
        if(p[i].first>p[i].second)
            swap(p[i].first,p[i].second);
        I=min(I,p[i].first),A=max(A,p[i].second),r=max(r,p[i].first),b=min(b,p[i].second);
    }
    i=~0;
    sort(p,p+n);
    t=(r-I)*(A-b);
    b=p[1+i].first,r=p[n+i].first;
    for(t=min(t,(A-I)*(r-b)); ++i<n; t=min(t,(A-I)*(r-b)))
        b=min(min(p[i].second,i-n+1?p[1+i].first:A),d),d=min(d,p[i].second),r=max(r,p[i].second);
    cout<<t;
}


Measured memory_bytes: 4352
while True:
    H, W = map(int,input().split())
    if H + W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j) % 2 == 0:
                print('#',end='')
                
            else:
                print('.',end='')
                
        print()
    print()


Measured memory_bytes: 7004
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		if(A%2 == 0 || B%2 == 0 || C%2 == 0){
			Console.WriteLine(0);
			return;
		}
		
		Console.WriteLine( new long[]{A*B,B*C,C*A}.Min() ); 
		
	}
	long A,B,C;
	public Sol(){
		var d = rla();
		A = d[0]; B = d[1]; C = d[2];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 2904
#include <iostream>
#include <cstdio>
#include <cmath>
#include <complex>
using namespace std;

typedef complex<double> P;

#define x real()
#define y imag()

double isIntersect(P p1, P p2,P p3,P p4 ){
  return (((p1.x - p2.x)*(p3.y - p1.y)+(p1.y-p2.y)*(p1.x-p3.x))*((p1.x - p2.x)*(p4.y - p1.y)+(p1.y-p2.y)*(p1.x-p4.x)));
}

int main(){
  double xa,ya,xb,yb,xc,yc,xd,yd;
  char e;
  while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF ){

    P a(xa , ya);
    P b(xb , yb);
    P c(xc , yc);
    P d(xd , yd);

    if(isIntersect(a,c,b,d) > 0.0 || isIntersect(b,d,a,c) > 0.0){
      cout << "NO" <<endl;
    }else cout << "YES" << endl; 


}
  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-5
#define M 200010
#define fi first
#define se second
#define pb push_back
#define LL long long
#define MOD 1000000007
#define pii pair<int,int>
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
inline int read(){char ch=getchar();int x=0,f=1;while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
inline LL llread(){char ch=getchar();LL x=0,f=1;while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
int a[M],ans,b[M],c[M];
int n,m;
inline bool check(int x){
	int tot=0;
	rep(i,x,n)b[++tot]=a[i]-m;
	int i1=1,i2=1;
	rep(i,1,n){
		if(i1<=x-1&&i2<=tot){
			if(a[i1]<b[i2])c[i]=a[i1],++i1;
			else c[i]=b[i2],++i2;
		}
		else if(i1==x){
			c[i]=b[i2],++i2;
		}
		else c[i]=a[i1],++i1;
	}
	ans=0;
	rep(i,1,n/2){
		int x=c[i]+c[n-i+1];
		if(x<0)return false;
		ans=max(ans,x);
	}
	return true;
}
int main() {
	//freopen("a.in","r",stdin);
	n=read()*2,m=read();
	rep(i,1,n)a[i]=read();
	sort(a+1,a+n+1);
	int l=1,r=n+1,t=0;
	//check(6);
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid))r=(t=mid)-1;
		else l=mid+1; 
	}
	check(t);
	//cerr<<t<<endl;
	printf("%d\n",ans);
}



Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=a;i<=b;++i)
using namespace std;

const int maxn=1e5+10;
int s[maxn];

void Init(int n)
{
	For(i,1,9)
		s[i]=i;
	For(i,10,n)
	{
		int k=i,sum=0;
		while(k)
		{
			sum+=s[k%10];
			k/=10;
		}
		s[i]=sum;
	}
}

int main()
{
	Init(maxn-5);
	int n,ans=0x3f3f3f3f;
	scanf("%d",&n);
	For(i,1,n/2+1)
		ans=min(ans,s[i]+s[n-i]);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include<cstring>
using namespace std;
int mincost(int **dp,int n){
    int costs[n][3];
    memset(costs,0,sizeof(costs));
    costs[0][0] = dp[0][0];
    costs[0][1] = dp[0][1];
    costs[0][2] = dp[0][2];
    for(int i=1;i<n;i++){
        costs[i][0] = dp[i][0] + max(costs[i-1][1],costs[i-1][2]);
        costs[i][1] = dp[i][1] + max(costs[i-1][0],costs[i-1][2]);
        costs[i][2] = dp[i][2] + max(costs[i-1][1],costs[i-1][0]);
    }
    return max(costs[n-1][0],max(costs[n-1][1],costs[n-1][2]));
}
int main() {
    int n;
    cin>>n;
    int **dp=new int*[n];
    for(int i=0;i<n;i++) dp[i] = new int[3];
    for(int i=0;i<n;i++){
        cin>>dp[i][0]>>dp[i][1]>>dp[i][2];
    }
    cout<<mincost(dp,n)<<endl;
}


Measured memory_bytes: 8636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using treap = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
    {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
    {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
    {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T> ostream& operator<<(ostream& s, set<T> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T> ostream& operator<<(ostream& s, multiset<T> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
    #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
    #define dump(...)
    #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(nullptr); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
    int n; cin >> n;
    vector<int> ans(n);
    REP (i, n) {
        int x; cin >> x;
        ans[x - 1] = i;
    }
    REP (i, n) cout << ans[i] + 1 << " ";
    cout << endl;
}


Measured memory_bytes: 1664
N, P = list(map(int,input().split()))


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


fct = factorize(P)
ans = 1
for i,n in fct:
    ans *= i**(n//N)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	ll x;
	cin >> x;
	ll ans = x / 11 * 2, tmp = x % 11;
	if (tmp > 6)
		ans += 2;
	else if (tmp > 0)
		ans++;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n, k;
    cin >> n >> k;

    vector<int> vec(n);
    int res = 0;
    for (int i = 0; i < n; i++) {
        int height;
        cin >> height;
        if (height >= k) ++res;
    }

    cout << res << endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////
bool check(string S) {
	int len = S.length();
	for (int i = 0; i < len / 2; ++i) {
		if (S[i] != S[len - 1 - i]) {
			return false;
		}
	}
	return true;
}
void solve() {
	string str;
	cin >> str;
	int N = str.length();
	if (check(str) && check(str.substr(0, N / 2)) && check(str.substr())) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
using namespace std;
#define ll long long
int main(){
	int A,B;
    cin >> A >> B;
    cout << B+max(0,10-A)*100;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int heights[N];
  for(int i = 0; i < N; ++i){
    cin >> heights[i];
  }
  int a = abs(heights[1] - heights[0]), b = abs(heights[2] - heights[0]), ans = a;
  for (int i = 1; i < N - 1; ++i){
    if (i % 2 == 1){
      b = min(b, a + abs(heights[i] - heights[i+1]));
      if (i != N-2){
        a = a + abs(heights[i] - heights[i+2]);
      }
      else{
        ans = b;
      }
    }
    else{
      a = min(a, b + abs(heights[i] - heights[i+1]));
      if (i != N-2){
        b = b + abs(heights[i] - heights[i+2]);
      }
      else{
        ans = a;
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 4004
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#include <iostream>
#define ll long long int
#define cases int t; cin >> t; while (t--)
#define fir for (ll i = 0; i < n; i++)
#define fira for (ll i = 0; i < n; i++) cin >> a[i]
#define firan ll n; cin >> n; ll a[n]; fira;
#define pb push_back
using namespace std;

int main()
{
    int a[3], n = 3;
    fira;
    sort(a, a+n);
    cout << a[2]*10 + a[0] + a[1] << endl;
    return 0;
}

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

int main() {
    string x;
    string y;
    cin >> x;
    cin >> y;
    int co = 0;
    for(int i = 0; i < 3 ; ++i){
        if(x[i]==y[i]){
            co +=1;
        }
    }
    cout << co;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int n;
vector<int> v[110000];
vector<int> w[110000];
bool visited[110000];

set<int> stx;
set<int> sty;

long long ans;

void dfs(int i)
{
  if (visited[i]) return;
  visited[i] = true;
  int cnt = 0;
  for (int y: v[i]) {
    sty.insert(y);
    for (int x: w[y]) {
      stx.insert(x);
      dfs(x);
    }
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    w[y].push_back(x);
  }
  
  for (int i = 1; i <= 100000; i++) {
    dfs(i);
    ans += stx.size() * sty.size();
    stx.clear();
    sty.clear();
  }
  ans -= n;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 15232