akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int H,s[1000000];
void insert(int key)
{
  H++;
  s[H]=-1;
  heapIncreasekey(H,key);
}
 
int heapExtractMax(void)
{
  int max;
   
  if(H<1) return;
   
  max=s[1];
  s[1]=s[H];
  H--;
  maxHeapify(s,1);
   
  return max; 
}
 
void heapIncreasekey(int i,int key)
{
  int temp;
   
  if(key<s[i]) return;
 
  s[i]=key;
  while(i>1 && s[i/2]<s[i]){
    temp=s[i];
    s[i]=s[i/2];
    s[i/2]=temp;
    i=i/2;
  }
}
 
void maxHeapify(int A[],int i)
{
  int l,r,largest,temp;
 
  l = i*2;
  r = l+1;
 
 
  if(l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if( r <= H && A[r] > A[largest]) largest = r;
            
  if(largest != i){  
    temp=A[i];
    A[i]=A[largest];
    A[largest]=temp;
    maxHeapify(A, largest);
  }      
}
int main()
{
  int i,key;
  char cmd[10];
 
  while(1){
    scanf("%s",cmd); 
    if(cmd[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else if(cmd[1]=='x') printf("%d\n",heapExtractMax());
    else break;
  }
   
  return 0;
}
 

Measured memory_bytes: 4508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define infy 2e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
const int N = five;
ll dp[2][N];
int main()
{
       string s;
       cin>>s;
       if(s[2]==s[3] &&s[4]==s[5]){
              cout<<"Yes"<<endl;
       }
       else{
              cout<<"No"<<endl;
       }
}


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

signed main(){
    int N; cin >> N;
    int c2 = 0, c4 = 0;
    for(int i = 0; i < N; i++){
        int a; cin >> a;
        if(a % 4 == 0) c4++;
        else if(a % 2 == 0) c2++;
    }
    int len;
    if(c2 == 0) len = 2 * c4 + 1;
    else len = 2 * c4 + c2;
    if(len >= N) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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


using namespace std;
const int maxn=1e5+5;
inline LL quickread()
{
	LL X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}
int main()
{
    int h,w,m;
    cin>>h>>w>>m;
    set<int>  s[h+1];
    LL a[h+5];
    LL b[w+5];
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(int i=0;i<m;i++)
    {
        LL h1,w1;
        h1=quickread();
        w1=quickread();
        s[h1].insert(w1);
        a[h1]++;
        b[w1]++;
    }
    int maxtmp=0;
    set<int> set_h;
    int ans=0;
    for(int i=1;i<=h;i++)
    {
        if(a[i]>=maxtmp)
            maxtmp=a[i];
    }
    ans+=maxtmp;
    for(int i=1;i<=h;i++)
    {
        if(a[i]==maxtmp)
           set_h.insert(i);
    }
    maxtmp=0;
    set<int> set_w;
    for(int i=1;i<=w;i++)
    {
        if(b[i]>=maxtmp)
            maxtmp=b[i];
    }
    ans+=maxtmp;
    for(int i=1;i<=w;i++)
    {
        if(b[i]==maxtmp)
           set_w.insert(i);
    }
    set<int> :: iterator it=set_h.begin();
    int flag=0;
    while(it!=set_h.end())
    {
        set<int> :: iterator it2=set_w.begin();
        while(it2!=set_w.end())
        {
            if(s[*it].count(*it2)==0)
            {
                flag=1;
                break;
            }
            it2++;
        }
        if(flag)
        {
            break;
        }
        it++;
    }
    if(flag)
        cout<<ans<<endl;
    else
        cout<<ans-1<<endl;
}


Measured memory_bytes: 64428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var < (end); var++)
#define RFOR(var, begin, end) for (int var = (begin) - 1; var >= (end); var--)
#define REP(var, length) FOR(var, 0, length)
#define RREP(var, length) RFOR(var, length, 0)
#define SORT(vector) sort(vector.begin(), vector.end())

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  int n, m;
  cin >> n >> m;

  vector<int> divisor;

  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      divisor.push_back(i);
      if (i != m / i) divisor.push_back(m / i);
    }
  }

  SORT(divisor);

  RREP(i, divisor.size()) {
    if (divisor[i] <= m / n) {
      cout << divisor[i] << endl;
      return;
    }
  }

}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


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;
typedef pair<ll, ll> P;

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

int main() {
  ll h, n;
  cin >> h >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end(), greater<ll>());
  rep(i, n) {
    h -= a[i];
    if (h <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
	int n,count=0;
	int i,j,k,l;
	int judge;
	
	while(~scanf("%d",&n)){
		for(i=0;i<10;++i){
			for(j=0;j<10;++j){
				for(k=0;k<10;++k){
					for(l=0;l<10;++l){
						if((i+j+k+l)==n){
							count++;
						}
					}
				}
			}
		}
		
		printf("%d\n",count);
		count = 0;
	}
	
	return 0;
	
}

Measured memory_bytes: 0
#include <iostream>
#include <string>

using namespace std;

string whatclass(double d){ 
        string s;
        if(d <= 48){
                s = "light fly";
        }else if(d <= 51){
                s = "fly";
        }else if(d <= 54){
                s = "bantam";
        }else if(d <= 57){
                s = "feather";
        }else if(d <= 60){
                s = "light";
        }else if(d <= 64){
                s = "light welter";
        }else if(d <= 69){
                s = "welter";
        }else if(d <= 75){
                s = "light middle";
        }else if(d <= 81){
                s = "middle";
        }else if(d <= 91){
                s = "light heavy";
        }else{
                s = "heavy";
        }   
        return s;

}
int main(){
        double in; 
        while(cin >> in){
                cout << whatclass(in) << endl;
        }   
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
int main()
{
	ll n,k;
	cin>>n>>k;
	vector<ll>pf(n+2);
	ll sum=0;
	for(int i=0; i<=n; i++)
	{
		sum+=i;
		pf[i+1]=sum;
	}
	ll ans=0;
	for(int i=k; i<=n+1; i++)
	{
		ll low=pf[i];
		ll high=pf[n+1]-pf[n+1-i];
	    ans=(ans+(high-low+1))%mod;
	}
	cout<<ans;
	return 0;
	
}

Measured memory_bytes: 4728
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <utility>
#include <map>
#include <algorithm>
#include <cmath>
#include <set>
#include <unordered_set>
#include <climits>
using namespace std;
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
#define ForInt(i, n) for (int i = 0; i < (n); ++i)
#define ForLong(i, n) for (int64 i = 0; i < (n); ++i)
#define ForIntInit(i, begin, end) for (int i = (begin); i < (end); ++i)
#define ForItr(it, itBegin, itEnd) for (auto it = (itBegin); it != (itEnd); ++it)
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))



int main()
{
	int n;
	cin >> n;
	vint l(n);
	ForInt(i, n)
	{
		cin >> l[i];
	}
	sort(l.begin(), l.end());

	int64 count = 0;
	auto itAEnd = l.end() - 2;
	auto itBEnd = l.end() - 1;
	auto itEnd = l.end();
	ForItr(itA, l.begin(), itAEnd)
	{
		ForItr(itB, itA + 1, itBEnd)
		{
			count += distance(itB, lower_bound(itB, itEnd, (*itA) + (*itB))) - 1;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#abc170d
n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt=[0]*(a[-1]+1)
for x in a:
 for i in range(x,a[-1]+1,x):
  cnt[i]+=1
res=0
for x in a:
 if cnt[x]==1:
  res+=1
print(res)


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

int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	set<int> r,g,b;
	for (int i = 0; i < n; ++i)
	{
		if(s[i]=='R')
			r.insert(i);
		if(s[i]=='G')
			g.insert(i);
		if(s[i]=='B')
			b.insert(i);

	}
	ll ans = 0;
	for (auto i:r)
	{
		for(auto j:g)
		{
			ans += b.size();
			if(b.find(2*j-i)!=b.end())
				ans--;
			if(b.find(2*i-j)!=b.end())
				ans--;
			if((i+j)%2==0&&b.find(i+(j-i)/2)!=b.end())
				ans--;
		}		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3756
using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            Regex HTC = new Regex(@"^+(hi)?(hi)?(hi)?(hi)?(hi)$");
            string s = Console.ReadLine();
            if(HTC.IsMatch(s))
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<vector<pair<int, long long int>>> V(n);
  for(int i=0;i<n-1;i++) {
    int a, b;
    long long int c;
    cin >> a >> b >> c;
    a--;
    b--;
    V[a].emplace_back(make_pair(b, c));
    V[b].emplace_back(make_pair(a, c));
  }
  vector<long long int> d(n);
  vector<int> prev(n);
  auto compare = [](pair<int, long long int> ap, pair<int, long long int> bp) {
    return (ap.second > bp.second);
  };
  priority_queue<pair<int, long long int>, vector<pair<int, long long int>>, decltype(compare)> que{compare};

  int q, k;
  cin >> q >> k;
  k--;

  for(int i=0;i<n;i++) {
    if(i == k) d[i] = 0;
    else d[i] = 1e18;
    prev[i] = -1;
  }

  que.emplace(make_pair(k, d[k]));

  while(!que.empty()) {
    pair<int, long long int> p = que.top();que.pop();
    for(int i=0;i<V[p.first].size();i++) {
      long long int alt = p.second + V[p.first][i].second;
      if(d[V[p.first][i].first] > alt) {
        d[V[p.first][i].first] = alt;
        prev[V[p.first][i].first] = p.first;
        que.emplace(make_pair(V[p.first][i].first, alt));
      }
    }
  }

  for(int i=0;i<q;i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    cout << d[x] + d[y] << endl;
  }
}

Measured memory_bytes: 11504
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int s=sc.nextInt();
		int w=sc.nextInt();
		if(s<=w){
			System.out.println("unsafe");
		}else{
			System.out.println("safe");
		}
	}
}


Measured memory_bytes: 35768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll Atot[201010], Btot[201010];

int main(){
    int n,m;
    ll k;
    cin>>n>>m>>k;

    rep(i,n){
        ll a;
        cin>>a;
        Atot[i+1]=Atot[i]+a;
    }
    rep(i,m){
        ll b;
        cin>>b;
        Btot[i+1]=Btot[i]+b;
    }

    int ans=0;
    int j=m;
    rep(i,n+1){
        if(Atot[i]>k) break;

        while(Atot[i]+Btot[j]>k) j--;
        ans=max(ans,i+j);
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 6752
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

vi Z_Algorithm(string s){
	int S=s.size();
	vi A(S);
	A[0]=S;
	int i=1,j=0;
	while(i<S){
		while(i+j<S&&s[j]==s[i+j]) j++;
		A[i]=j;
		if(!j){
			i++;continue;
		}
		int k=1;
		while(i+k<S&&k+A[k]<j) A[i+k]=A[k],k++;
		i+=k;j-=k;
	}
	return A;
}

int n;
vi a,b;

int main(){
	cin>>n;
	a=b=vi(n);
	for(auto &i:a) cin>>i;
	for(auto &i:b) cin>>i;
	vi used(n,1);
	for(int j=0;j<30;j++){
		vi c(n);
		for(int k=0;k<2;k++){
			string s;
			for(int i=0;i<n;i++){
				if(((b[i]&1<<j)>0)^(k==1)) s+='1';
				else s+='0';
			}
			for(int i=0;i<n;i++){
				if(a[i]&1<<j) s+='1';
				else s+='0';
			}
			for(int i=0;i<n;i++){
				if(a[i]&1<<j) s+='1';
				else s+='0';
			}
			vi z=Z_Algorithm(s);
			for(int i=0;i<n;i++) if(z[i+n]>=n) c[i]=1;
//			cout<<s<<endl;
//			for(auto i:z) cout<<i<<' ';cout<<endl;
		}
//		for(auto i:c) cout<<i<<' ';
//		cout<<endl;
		for(int i=0;i<n;i++) used[i]&=c[i];
	}
	for(int i=0;i<n;i++) if(used[i]) cout<<i<<' '<<(a[i]^b[0])<<endl;
}

Measured memory_bytes: 7732
N, Y = map(int, input().split())

for x in range(0, N+1):
  for y in range(0, N-x+1):
    z = N - x - y
    if 0<= z <= N and 10000*x + 5000*y + 1000*z == Y:
      print(x, y, z)
      exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
//input
int X;


//processing



//dpTable
//int dp[100050];

int main(){
    cin >> X;
    if (X >= 400 && X <= 599) cout << 8 << endl;
    if (X >= 600 && X <= 799) cout << 7 << endl;
    if (X >= 800 && X <= 999) cout << 6 << endl;
    if (X >= 1000 && X <= 1199) cout << 5 << endl;
    if (X >= 1200 && X <= 1399) cout << 4 << endl;
    if (X >= 1400 && X <= 1599) cout << 3 << endl;
    if (X >= 1600 && X <= 1799) cout << 2 << endl;
    if (X >= 1800 && X <= 1999) cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>//高速化したい
#define rep(i,n)for(int i=0;i<(int)(n);i++)
int main(){
int n,m,x,c[12]={0},a[12][12]={0},y,z[12],b,d=2e9;
scanf("%d%d%d",&n,&m,&x);
rep(i,n){
scanf("%d",&c[i]);
rep(j,m){
scanf("%d",&a[i][j]);
}
}
rep(i,2){rep(j,2){rep(k,2){rep(l,2){rep(o,2){rep(p,2){rep(q,2){rep(r,2){rep(s,2){rep(t,2){rep(u,2){rep(v,2){
y=i*c[0]+j*c[1]+k*c[2]+l*c[3]+o*c[4]+p*c[5]+q*c[6]+r*c[7]+s*c[8]+t*c[9]+u*c[10]+v*c[11];
for(b=0;b<m;b++){
z[b]=i*a[0][b]+j*a[1][b]+k*a[2][b]+l*a[3][b]+o*a[4][b]+p*a[5][b]+q*a[6][b]+r*a[7][b]+s*a[8][b]+t*a[9][b]+u*a[10][b]+v*a[11][b];
if(z[b]<x)break;
}
if(b==m&&y<d)d = y;
}}}}}}}}}}}}
if(d==(int)2e9)puts("-1");
else printf("%d",d);
return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  
  sort(p.begin(), p.end());
  int ans = 0;
  rep(i, k) ans += p[i];
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define sq(a) ((a)*(a))
#define rep(i,a,b) for(long long int i=a;i<=b;i++)
#define deb(r) cout<<#r<<"="<<r<<endl;
using namespace std;
typedef long long int ll;
typedef long double llf;

int main()
{
    ll n;  cin>>n;
    string s; cin>>s;
    //deb(s);
    ll i=0,j=n-1,c=0;
    //deb(i);deb(j);
    //deb(s[i]);
    //deb(s[j]);
    while(i<j )
    {
        //deb(s);
        if(s[i]=='W' && s[j]=='R') {
            swap(s[i],s[j]);

            //deb(s);
            c++;
            i++;
        }
        if(s[i]=='R') i++;
        if(s[j]=='W') j--;

    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 3736
#include <stdio.h>

int A[100000];

int Abs(int x){
  if(x < 0) return -x;
  else return x;
}

void Do(int N){
  int i, c, C, m, n;
  long long B;
  c = 0;
  C = 0;
  m = 1e9;
  n = -1;
  for(i = 0;i < N;i++){
    scanf("%d", &A[i]);
    if(A[i] == 0) c = 1;
    if(c == 0 && A[i] < 0) C++;
    if(m > Abs(A[i])){
      m = Abs(A[i]);
      n = i;
    }
  }
  B = 0;
  if(c == 0 && C % 2 == 1){
    for(i = 0;i < N;i++){
      if(i == n) B -= Abs(A[i]);
      else B += Abs(A[i]);
    }
  }else for(i = 0;i < N;i++) B += Abs(A[i]);
  printf("%lld\n", B);
}

int main(void){
  int N;
  scanf("%d", &N);
  Do(N);
  return 0;
}


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

// 簡易UF
struct UF{
    vector<int> p, m;
    int n;

    UF(int siz){
        n = siz;
        p.resize(n, 0);
        m.resize(n, 1);
        for(int i = 0; i < n; i++)  p[i] = i;
    }

    int parent(int x){
        if(p[x] != x)   p[x] = parent(p[x]);
        return p[x];
    }

    bool same(int x, int y){
        return parent(x) == parent(y);
    }
    
    void unite(int x, int y){
        x = parent(x), y = parent(y);
        if(x == y)  return;
        m[y] += m[x];
        p[x] = y;
    }
};

int main(){
    int n;
    cin >> n;
    vector<int> x(n), y(n), xrev(n), yrev(n);
    for(int i = 0; i < n; i++)  cin >> x[i] >> y[i], xrev[--x[i]] = i, yrev[--y[i]] = i;
    set<int> s;
    UF uf(n);
    // up
    for(int i = 0; i < n; i++){
        auto it = s.lower_bound(x[yrev[i]]);
        if(it != s.begin()){
            it--;
            uf.unite(xrev[*it], yrev[i]);
        }
        s.insert(x[yrev[i]]);
    }
    s.clear();
    // down
    for(int i = n-1; i >= 0; i--){
        auto it = s.upper_bound(x[yrev[i]]);
        if(it != s.end()){
            uf.unite(xrev[*it], yrev[i]);
        }
        s.insert(x[yrev[i]]);
    }
    s.clear();
    // right
    for(int i = 0; i < n; i++){
        auto it = s.lower_bound(y[xrev[i]]);
        if(it != s.begin()){
            it--;
            uf.unite(yrev[*it], xrev[i]);
        }
        s.insert(y[xrev[i]]);
    }
    s.clear();
    // left
    for(int i = n-1; i >= 0; i--){
        auto it = s.upper_bound(y[xrev[i]]);
        if(it != s.end()){
            uf.unite(yrev[*it], xrev[i]);
        }
        s.insert(y[xrev[i]]);
    }
    for(int i = 0; i < n; i++)  cout << uf.m[uf.parent(i)] << endl;
    return 0;
}

Measured memory_bytes: 17184
#include <bits/stdc++.h>
using namespace std;
 
int main (){
  int n,m;
  cin >>n>>m;
  int a[100100];
  string b[100100];
  for(int i=1; i<=m; i++){
    cin>>a[i]>>b[i];
  }
  bool c[100100]={0};
 int  countwa=0,countac=0;
  int wa[100100]={0};
  for(int i=1;i<=m;i++){
    if(c[a[i]]==1) continue;
    else{ if(b[i]=="WA") wa[a[i]]++;
        else{ c[a[i]]=1; countac++; countwa+=wa[a[i]];}
        }
  }
cout <<countac<<" "<<countwa<<endl;
  }

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;


/*
*/

ll w,h,w_bonded=0,h_bonded=0,ans=0;
pair<ll,pair<ll,ll>> c[200010];

void init(){
	cin>>w>>h;
	rep(i,w){
		ll x;
		cin>>x;
		c[i]={x,{0,i}};
	}
	rep(i,h){
		ll x;
		cin>>x;
		c[i+w]={x,{1,i}};
	}
	sort(c,c+h+w);
}

int main(void){
	init();
	rep(i,h+w){
		if(c[i].second.first==0){
			ans+=c[i].first*(h+1-h_bonded);
			w_bonded++;
		}else{
			ans+=c[i].first*(w+1-w_bonded);
			h_bonded++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define go(u) for (int o=ft[u],v;v=E[o].t;o=E[o].n)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef double dob;
typedef pair<int,int> par;
const int N=20010,lim=20000,P=998244353,g=3,ig=(P+1)/3;
int n,m;
LL s1[N],s2[N],inv[N];
LL C(int n,int m){
	if (m<0||m>n) return 0;
	return s1[n]*s2[m]%P*s2[n-m]%P;
}
LL pw(LL x,LL k){
	LL y=1;
	while (k){
		if (k&1) y=y*x%P;
		x=x*x%P;
		k>>=1;
	}
	return y;
}
namespace po{
	LL a[N],b[N],c[N];
	void dft(LL* a,int n,int op){
		static LL r[N];
		r[0]=0;
		for (int i=0;i<n;i+=2){
			r[i]=r[i>>1]>>1;
			r[i+1]=r[i]|n>>1;
		}
		for (int i=0;i<n;i++) if (i<r[i]) swap(a[i],a[r[i]]);	
		for (int h=2;h<=n;h<<=1){
			LL wn=pw(op==1?g:ig,(P-1)/h);
			for (int i=0;i<n;i+=h){
				LL w=1;
				for (int j=i;j<i+h/2;j++){
					LL x=a[j],y=a[j+h/2];
					a[j]=(x+y*w)%P;
					a[j+h/2]=(x-y*w)%P;
					w=w*wn%P;
				}
			}
		}
		if (op==-1) for (int i=0,iv=pw(n,P-2);i<n;i++) a[i]=a[i]*iv%P;
	}
	void mul(LL* _a,LL* _b,LL* _c,int len){
		memcpy(a,_a,len*8);
		memcpy(b,_b,len*8);
		dft(a,len,1),dft(b,len,1);
		rep(i,0,len-1) c[i]=a[i]*b[i]%P;
		dft(c,len,-1);
		memcpy(_c,c,len*8);
	}
};
struct poly{
	int l;
	vector <LL> a;
	LL& operator [](int k){return a[k];}
	void set(int len){
		while (a.size()<len) a.push_back(0);
		while (l>len) a[--l]=0;
		l=len;
	}
	void operator *=(poly k){
		int len=1;
		while (len<l+k.l-1) len<<=1;
		set(len),k.set(len);
		po::mul(&a[0],&k[0],&a[0],len);
	}
}p1,p2;
void init(){
	inv[1]=1;
	rep(i,2,lim) inv[i]=inv[P%i]*(P-P/i)%P;
	s1[0]=s2[0]=1;
	rep(i,1,lim){
		s1[i]=s1[i-1]*i%P;
		s2[i]=s2[i-1]*inv[i]%P;
	}
	p1.set(n+5),p1[0]=1;
	p2.set(n+5);
	rep(i,1,n) p2[i]=s2[i+2];
}
LL tp[N];
int main(){
	scanf("%d%d",&n,&m);
	init();
	while (m--){
		rep(i,0,n) tp[i]=p1[i];
		p1*=p2;
		p1.set(n+5);
		rep(i,0,n) p1[i]=p1[i]*(i+1)%P*(i+2)%P;
		rep(i,0,n) p1[i]=(p1[i]+tp[i]*((LL)i*(i+1)/2%P+1))%P;
	}
	rep(i,0,n) p1[i]=p1[i]*s1[i]%P;
	LL ans=0;
	rep(i,0,n) ans=(ans+p1[i]*C(n,i))%P;
	ans=(ans%P+P)%P;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1928
using System;

namespace teisyutusensei
{
    class Program
    {
        static void Main(string[] args)
        {
            

            string result =null;
            bool fr = true;


            while(fr)
            {
                ////?????????????????????
                string dmmy = Console.ReadLine();

                string[] input = dmmy.Split(' ');

                int n = int.Parse(input[0]);
                int x = int.Parse(input[1]);

                if (n == 0 && x == 0)
                {
                    fr = false;
                    break;
                }

                int sum = 0;
                int count = 0;

                for (int i = 1; i <= n - 2; i++)
                {
                    for (int j = i + 1; j <= n - 1; j++)
                    {
                        for (int k = j+1 ; k <= n; k++)
                        {
                            sum = i + j + k;
                            if (sum == x)
                            {
                                count++;
                            }
                        }
                        
                    }
                    
                }
                result += count;
                result += "\n";

            }

            Console.Write(result);
            Console.ReadLine();

        }
    }

}

Measured memory_bytes: 5636
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll [[maybe_unused]] = long long;
using ull [[maybe_unused]] = unsigned long long;
using ld [[maybe_unused]] = long double;

[[maybe_unused]] static constexpr int mod = (int)1e9 + 7;
[[maybe_unused]] static constexpr int inf = 100100100;
[[maybe_unused]] static constexpr ll linf = 1e18;
[[maybe_unused]] static constexpr double eps = 1e-9;
[[maybe_unused]] static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, a) for (ll i = a; i >= 0; --i)
#define all(obj) begin(obj), end(obj)
#define rall(obj) rbegin(obj), rend(obj)
#define pb push_back
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    cout << max(A + B, max(A - B, A * B)) << endl;
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var l = Console.ReadLine().Split(' ').Select(int.Parse).OrderByDescending(s => s).ToList();

            var ans = 0;
            for (int i = 0; i < n - 2; i++)
            {
                for (int j = i + 1; j < n - 1; j++)
                {
                    var border = l[i] - l[j];
                    Func<int, bool> judge = k => border < l[k];
                    ans += judge(j + 1) ? SearchLast(judge, j + 1, n - 1) - j : 0;
                }
            }
            Console.WriteLine(ans);
        }

        public static int SearchLast(Func<int, bool> f, int min, int max)
        {
            if (f(max)) return max;
            var k = min + (max - min) / 2;

            return f(k) ? SearchLast(f, k, max - 1) : SearchLast(f, min, k);
        }
    }
}


Measured memory_bytes: 19652
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
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);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int H, W;
char board[110][110];
int dist[110][110];

signed main() {
	cin >> H >> W;
	int cnt = 0;
	for(int i=0; i<H; i++) {
		for(int j=0; j<W; j++) {
			cin >> board[i][j];
			cnt += (board[i][j] == '#');
		}
	}

	memset(dist, -1, sizeof(dist));
	dist[0][0] = 0;
	queue< pair<int, int> > que;
	que.push(make_pair(0, 0));

	while(que.size()) {
		int x, y; tie(x, y) = que.front(); que.pop();
		for(int k=0; k<4; k++) {
			int nx = x + dx[k], ny = y + dy[k];
			if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
			if(board[nx][ny] == '#') continue;
			if(dist[nx][ny] >= 0) continue;
			dist[nx][ny] = dist[x][y] + 1;
			que.push(make_pair(nx, ny));
		}
	}

	if(dist[H-1][W-1] == -1) cout << -1 << endl;
	else {
		int ans = H*W - cnt - dist[H-1][W-1] - 1;
		cout << ans << endl;
	}
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1LL << 60;

#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

long long MODPOW(long long inv,long long pow, long long mod){
    if(pow == 1) return inv % mod;
    else{
        if(pow % 2) return inv * MODPOW(inv, pow -1, mod) % mod;
        long long res = MODPOW(inv, pow/2, mod);
        return res * res % mod; 
    }
}

long long COMMOD(int a, int b){
    long long res=1; long long resinv = 1;
    for(int i = a; i>a-b; i--){
        res = res * i % MOD;
        resinv = resinv*(a-i+1) % MOD;
    }
    return res*MODPOW(resinv, MOD-2, MOD) % MOD;
}

int main() {
    int S;
    cin>>S;
    ll ans = 0;
    int count = 0;
    if(S < 3) ans = 0;
    else {    
        S -= 3;
        while(S >= 0){
            ans += COMMOD(S + count, count);
            ans %= MOD;
            count++;
            S -= 3;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int ans[100010];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int left = 0, right = 0;
    int i = 0;
    while(left < S.length()) {
        int num[2] = {};
        while(S[i] == 'R') {num[(i - left) % 2]++; i++;}
        right = i;
        while(S[i] == 'L') {num[(i - right + 1) % 2]++; i++;}
        left = i;
        ans[right - 1] = num[0];
        ans[right] = num[1];
    }
    rep(i, S.length()) {
        if(i != 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N=(int)1e5+7;

int n;

struct info
{
        int a;
        int b;
};

bool cmp(info f,info s)
{
        return f.a+f.b<s.a+s.b;
}

info v[N];

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        cin>>n;
        for(int i=1;i<=n;i++)
        {
                cin>>v[i].a>>v[i].b;
        }
        sort(v+1,v+n+1,cmp);
        ll res=0LL;
        int j=0;
        for(int i=n;i>=1;i--)
        {
                j++;
                if(j%2==1)
                {
                        res+=v[i].a;
                }
                else
                {
                        res-=v[i].b;
                }
        }
        cout<<res<<"\n";
        return 0;
}
/**

**/


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);I++) cin >> x[i];

int main(){
  char a,b ;
  cin >> a >> b;
  if(a == 'H' && b =='H')
    cout <<"H"<< endl;
  if(a == 'H' && b == 'D')
    cout <<"D"<<endl;
  if(a =='D' && b =='H')
    cout <<"D" << endl;
  if(a =='D' && b =='D')
    cout <<"H"<<endl;
}

Measured memory_bytes: 256
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: August 30 , 2019
 * 
 */

#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(i,x) for(auto (i)=0 ; (i)<(x); ++(i))
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define ef else if
#define wh while
#define el else
#define ivv(x) int x; cin>>x
#define lv(x) bint x; cin>>x
#define sv(x) string x; cin>>x
#define cv(x) char x; cin>>x
#define fv(x) float x; cin>>x
#define dv(x) double x; cin>>x
#define endl '\n'
using namespace std;






auto SOLUTION_FUNCTION( void ) ->void {
    // your solution goes here 

    ivv(x);
    puts((x==5 or x==3 or x==7)?"YES":"NO");


    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

Measured memory_bytes: 256
import math
n = int(input())
x = list(map(int,input().split()))
s = min(x)
e = max(x)
ans = 10**18
for i in range(s,e+1):
  f = 0
  for j in range(n):
    f += (x[j]-i)**2
  ans = min(ans,f)
print(ans)

Measured memory_bytes: 3064
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

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

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------


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

  string S[3];
  cin >> S[0] >> S[1] >> S[2];
  int itr[3] = {0, 0, 0};
  int turn = 0;

  while (true) {
    if (itr[turn] >= S[turn].size()) {
      cout << CHAR(turn + 'A') << endl;
      return 0;
    }

    itr[turn]++;
    turn = INT(S[turn][itr[turn] - 1] - 'a');
  }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rrep1(i,n) for(ll i=n;i>=1;i--)
#define FOR(i,a,b) for(ll i=a;i<b;i++)

const ll MOD=1000000007;
const ll INF=1000000000000000;

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

int main(){
	ll dp[100101];
	rep(i,100101) dp[i]=INF;
    ll N,K; cin>>N>>K;
	vector<ll>h(N);
	rep(i,N) cin>>h[i];
	dp[0]=0;
	rep(i,N){
		rep1(j,K){
			chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
		}
	}
	cout<<dp[N-1];
}

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

const int MN = 100005;

int N;
std::vector<int> G[MN];

int dp[MN];
void DFS(int u) {
	for (int v : G[u]) DFS(v);
	static int seq[MN];
	int t = 0;
	for (int v : G[u]) seq[++t] = dp[v];
	std::sort(seq + 1, seq + t + 1);
	for (int i = 1; i <= t; ++i) dp[u] = std::max(dp[u], seq[i] + t - i + 1);
}

int main() {
	scanf("%d", &N);
	for (int i = 2, x; i <= N; ++i) scanf("%d", &x), G[x].push_back(i);
	DFS(1);
	printf("%d\n", dp[1]);
	return 0;
}

Measured memory_bytes: 16760
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;
    if(a >= 10 || b >= 10) cout << -1 << endl;
    else cout << a*b << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int X = scan.nextInt();
			int Y = scan.nextInt();
			int Z = scan.nextInt();
			
			int t = 0;
			int s = 0;
			
			t = X;
			X =Y;
			Y = t;
			
			s = X;
			X = Z;
			Z = s;
			
			System.out.println(X);
			System.out.println(Y);
			System.out.println(Z);
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int H,W; cin>>H>>W;
  vector<string> S(H);
  rep(i,0,H) cin>>S[i];
  vii dp(H+1,vi(W+1,INF));
  dp[0][1]=0;
  rep(i,0,H){
    rep(j,0,W){
      int X=dp[i][j+1],Y=dp[i+1][j];
      if(S[i][j]=='#'){
        if(j==0||S[i][j-1]=='.') Y++;
        if(i==0||S[i-1][j]=='.') X++;
      }
      dp[i+1][j+1]=min(X,Y);
    }
  }
  cout<<dp[H][W]<<endl;
  }


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

using namespace std;

const int maxn = 1e3+10;
const int maxs = 2e4+10;

int n;
long long int dp[maxn][maxs], w[maxn], s[maxn], v[maxn], d[maxn];

bool comp(int i, int j){
	return s[i] < s[j];
}

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		scanf("%d%d%d", &w[i], &s[i], &v[i]);
		s[i] += w[i];
		d[i] = i;
	}

	sort(d, d+n, comp);

	for (int i = w[d[0]]; i < maxs; i++)
		dp[0][i] = v[d[0]];

	for (int i = 1; i < n; i++){
		for (int j = 0; j < maxs; j++){
			dp[i][j] = dp[i-1][j];
			if (w[d[i]] <= j){
				dp[i][j] = max(dp[i][j], dp[i-1][min(j-w[d[i]], s[d[i]]-w[d[i]])] + v[d[i]]);
			}
		}
	}

	cout << dp[n-1][maxs-1] << endl;
	return 0;
}


Measured memory_bytes: 157952
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		double r,S,l;
		r=sc.nextDouble();
		S=(r*r)*Math.PI;
		l=(r*2)*Math.PI;
		System.out.print(String.format("%.6f", S)+" ");
		System.out.println(String.format("%.6f", l));
		sc.close();
	}
}



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

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

    long long int ans = 0;
    for(long long int alpha=1;alpha*(alpha+1)<n;alpha++){
        if((n-alpha)%alpha==0){
            ans += (n-alpha)/alpha;
        }
    }
    cout << ans << endl;
    return 0;
}




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

int main(){
	map<string,int> m;
	m["SUN"] = 7;
	m["MON"] = 6;
	m["TUE"] = 5;
	m["WED"] = 4;
	m["THU"] = 3;
	m["FRI"] = 2;
	m["SAT"] = 1;

	string s;
	cin >> s;
	cout << m[s] << endl;
}


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

int main() {
    int n;
    cin >> n;
    int a[n];
    int count=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        count+=a[i];
    }
    int ans;
    sort(a,a+n);
    if(count%10!=0) ans=count;
    else{
        bool flag=false;
        for(int i=0;i<n;i++){
            if(a[i]%10!=0){
                ans=count-a[i];
                flag=true;
                break;
            }
        }
        if(!flag){
            ans=0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a,f;
int main(){
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a;
		if (a%3!=0&&a%5!=0&&a%2==0) f=1;
	}
	if (f==0)
		cout<<"APPROVED"<<endl;
	else
		cout<<"DENIED"<<endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
XL = N.times.map { gets.split.map(&:to_i) }

sorted = XL.sort_by { |x, l| x - l }
ans = 0
current_right = -(1 << 60)
sorted.each do |x, l|
  left = x - l
  right = x + l
  if left >= current_right
    ans += 1
    current_right = right
  elsif right < current_right
    current_right = right
  end
end
puts ans

Measured memory_bytes: 12664
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n;
    cin >> n;
    vector<li> xs(n), ys(n);
    for (int i = 0; i < n; ++i) {
        cin >> xs[i];
    }
    priority_queue<pair<li, li>> q;
    for (int i = 0; i < n; ++i) {
        cin >> ys[i];
        q.emplace(ys[i], i);
    }

    li ans = 0;
    while (not q.empty()) {
        auto t = q.top(); q.pop();
        li i = t.second;
        li v = t.first;
        if (v < xs[i]) {
            ans = -1;
            break;
        } else if (v == xs[i]) {
            continue;
        }
        li d = v - xs[i];
        li u = ys[(i + 1) % n] + ys[(i + n - 1) % n];
        if (d % u == 0) {
            ans += d / u;
            ys[i] = xs[i];
            continue;
        } else {
            li nv = v % u;
            if (nv == v) {
                ans = -1;
                break;
            }
            ans += v / u;
            ys[i] = nv;
            q.emplace(nv, i);
        }
    }

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

Measured memory_bytes: 9712
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string.h>
using namespace std;
typedef long long int llint;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b < c) {
		swap(b, c);
	}
	if (a < b) {
		swap(a, b);
	}
	if (b < c) {
		swap(b, c);
	}
	cout << a - c << endl;
	return 0;
}


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

pii field[125][125];
int c[125][125];

int dfs(int x, int y, int check){
    while(c[x][y] == 0){
        c[x][y] = check;
        int nx = field[x][y].first, ny = field[x][y].second;
        x = nx; y = ny;
    }
    if(c[x][y] == check) return 1;
    else return 0;
}

int main(){
    int n;
    while(cin >> n, n){
        rep(i, 125) rep(j, 125) c[i][j] = 0;
        rep(i, n){
            rep(j, n){
                int x, y;
                cin >> x >> y;
                field[i][j] = mp(y, x);
            }
        }
        int ans = 0;
        int check = 1;
        rep(i, n){
            rep(j, n){
                if(c[i][j] == 0){
                    ans += dfs(i, j, check);
                    check++;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1344
"""
KがAの最大公約数の倍数であれば実現可能。そうでなければ実現不可能。
"""
import sys
sys.setrecursionlimit(200000)
N,K = map(int,input().split())
A = list(map(int,input().split()))

def gcd(a,b):
    return a if b==0 else gcd(b,a%b)
if N ==1:
    g = A[0]
else:
    g = gcd(A[0],A[1])
    for i in range(2,N):
        g = gcd(g,A[2])

if K<=max(A) and K%g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 62576
#include<bits/stdc++.h>
using namespace std;
int main (){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	vector<pair<int,int>> a(n);
	for (int i=0;i<n;i++) cin>>a[i].first>>a[i].second;
	sort(a.begin(),a.end());
	int dp1[n],dp2[n];
	dp1[n-1]=a[n-1].first+a[n-1].second;
	dp2[n-1]=a[n-1].first-a[n-1].second;
	for (int i=n-2;i>=0;i--){
		dp1[i]=max(dp1[i+1],a[i].first+a[i].second);
		dp2[i]=max(dp2[i+1],a[i].first-a[i].second);
	}
	int maxi=0;
	for (int i=0;i<n-1;i++){
		int cnt=0;
		cnt=max(a[i].second-a[i].first+dp2[i+1],dp1[i+1]-a[i].first-a[i].second);
		maxi=max(maxi,cnt);
	}
	cout<<maxi;
}

Measured memory_bytes: 6360
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using ll = long long;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using namespace std;
using vl = vector<ll>;
using pll =  pair<ll,ll>;

void solve()
{   
    ll n,k;
    cin>>n>>k;
    vl h(n);
    for(int i=0;i<n;i++)
        cin>>h[i];
    sort(h.rbegin(),h.rend());
    ll sum =0;
    for(int i=k;i<n;i++){
        sum += h[i];
    }
    cout<<sum;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    solve();
    return 0;
}

Measured memory_bytes: 1792