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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


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


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

    while(true){
      cin >> n;
      if(n==0) break;
      vector<pair<double,string>> array;
      rep(i,n){
        string l;
        cin >> l;
        double p,a,b,c,d,s,e,f,m;
        cin >> p >> a >> b >> c >> d >> e >> f >> s >> m;
        double calc = ((f*m*s)-p)/((a+b+c+d+e) + (d+e)*(m-1));
        //cout << calc << endl;
        array.push_back(make_pair( calc , l ));
      }
      sort(all(array),greater<pair<double,string>>());
      vector<string> ans;
      map<double,vector<string>> mp;
      rep(i,n){
        //out << array[i].second << endl;
        mp[array[i].first].push_back(array[i].second);
      }
      rep(i,n){
        if(mp[array[i].first].empty() == false){
          sort(all(mp[array[i].first]));
          rep(j,mp[array[i].first].size()) cout << mp[array[i].first][j] << endl;
          mp[array[i].first].clear();
        }
      }

      cout << '#' << endl;
    }
    return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long int lli;
const long long int MaxN=200005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli arr[MaxN];
	void solve(){
		lli N,i,j,sum=0,res=0;
		cin>>N;
		for(i=0;i<N;i++){
			cin>>arr[i];
			sum+=arr[i];
		}
		sort(arr,arr+N);
		arr[N]=0;
		for(i=N-1;i>=0;i--){
			if(sum*2>=arr[i+1]){
				res+=1;
				//cout<<i+1<<" "<<arr[i]<<" "<<sum<<"\n";
			}
			else {
				break;
			}	
			sum-=arr[i];
		}
		cout<<res;
	}
int main(){
	cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

int p5(int n){
    return (n*n*n*n*n);
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x;
    cin>>x;
    rep(i,-130,130){
        rep(j,-130,130){
            if(p5(i) - p5(j) == x){cout<<i<<' '<<j;return 0;}
        }
    }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
ll mod = 1e9 + 7;

template <class T> struct Matrix {
    vector<vector<T>> A;
    Matrix(int n, int m) : A(n, vector<T>(m)) {}
    Matrix(int n) : A(n, vector<T>(n)) {}
    int size() {
        return A.size();
    }
    inline vector<T> &operator[](int i) {
        return A[i];
    }
};
template <class T> Matrix<T> operator*(Matrix<T> A, Matrix<T> B) {
    Matrix<T> R(A.size(), B[0].size());
    for (int i = 0; i < A.size(); ++i)
        for (int j = 0; j < B[0].size(); ++j)
            for (int k = 0; k < B.size(); ++k)
                R[i][j] = (R[i][j] + A[i][k] * B[k][j]) % mod;
    return R;
}
template <class T> Matrix<T> power(Matrix<T> X, ll n) {
    Matrix<T> R(X.size());
    for (int i = 0; i < X.size(); i++)
        R[i][i] = 1;
    while (n > 0) {
        if (n & 1)
            R = R * X;
        X = X * X;
        n >>= 1;
    }
    return R;
}

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

    ll n, k;
    cin >> n >> k;
    Matrix<ll> a(n);
    rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];
    a = power(a, k);
    ll ans = 0;
    rep(i, 0, n) rep(j, 0, n) ans = (ans + a[i][j]) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>

int main(void){
int i,j,m,n,mn;
scanf("%d%d",&n,&m);
mn=m*n;
int a[mn],b[n]={0},c[m]={0},d=0;
for (i=0;i<mn;i++){
	scanf("%d",&a[i]);
};
for(i=0;i<n;i++){
	for(j=0;j<m;j++){
		b[i]=b[i]+a[i*m+j];
	};
};
for(i=0;i<m;i++){
	for(j=0;j<n;j++){
		c[i]=c[i]+a[j*m+i];
	};
};
for(i=0;i<n;i++){
	d=d+b[i];
}
for(i=0;i<n;i++){
	for(j=0;j<m;j++){
		printf("%d ",a[i*m+j]);
	};
	printf("%d\n",b[i]);
};
for(i=0;i<m;i++){
	printf("%d ",c[i]);
};
printf("%d\n",d);


return 0;
}

Measured memory_bytes: 2676
import scala.io.Source.stdin

object Main {
  def main(args:Array[String]) = {
    val list = stdin.getLines.map { s=>
      val w = s.split(" ")
      (w(0),w(1).toInt)
    }.toList.groupBy(_._1).toArray.sortBy(_._1)

    list.foreach { l =>
      println(l._1)
      println(l._2.map(_._2).sorted.mkString(" "))
    }
  }
}

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

int main() {
    char ch;

    while (true) {
        scanf("%c", &ch);

        if (isalpha(ch)) {
            if (islower(ch)) {
                printf("%c", toupper(ch));
            } else {
                printf("%c", tolower(ch));
            }
        } else {
            printf("%c", ch);
        }

        if (ch == '\n') {
            break;
        }
    }

    return 0;
}


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


int main(){
    int counta=0;
    string S,T;
    cin>>S>>T;
    for(int i=0;i<S.size();i++){
        if(S.at(i)!=T.at(i)){
            counta++;
        }
    }
    cout<<counta<<endl;
}

Measured memory_bytes: 3912
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

int main() {
    int a, b, c, d;
    string s;
    cin >> s;
    a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
    char op1, op2, op3;
    if (a + b + c + d == 7) op1 = '+', op2 = '+', op3 = '+';
    else if (a + b + c - d == 7) op1 = '+', op2 = '+', op3 = '-';
    else if (a + b - c + d == 7) op1 = '+', op2 = '-', op3 = '+';
    else if (a + b - c - d == 7) op1 = '+', op2 = '-', op3 = '-';
    else if (a - b + c + d == 7) op1 = '-', op2 = '+', op3 = '+';
    else if (a - b + c - d == 7) op1 = '-', op2 = '+', op3 = '-';
    else if (a - b - c + d == 7) op1 = '-', op2 = '-', op3 = '+';
    else if (a - b - c - d == 7) op1 = '-', op2 = '-', op3 = '-';
    printf("%d%c%d%c%d%c%d=7\n", a, op1, b, op2, c, op3, d);
}

Measured memory_bytes: 256
#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() {
  string s;
  cin >> s;
  string t;
  int n = s.size();
  int m = (n-1)/2;
  rep(i,m) {
    string u;
    u += s.at(i);
    t += u;
  }
  bool ok = true;
  rep(i,m) if(t.at(i)!=t.at(m-1-i)) ok = false;
  if(ok) {
    string v;
    rep(i,m) {
      string w;
      w += s.at(i+m+1);
      v += w;
    }
    reverse(v.begin(), v.end());
    if(t==v) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_c() {
	ll n, m;
	ll x;
	ll a;
	string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;
	
	cin >> n;
	string tmp;
	vector<map<char, ll>> sm(n);
	rep(i, n) {
		cin >> tmp;
		rep(j, tmp.size()) {
			++sm[i][tmp[j]];
		}
	}

	V cnt(sm[0].size(), INF);
	ll idx = 0;
	for (auto itr : sm[0]) {
		rep(i, n) {
			cnt[idx] = min(cnt[idx], sm[i][itr.first]);
		}
		rep(i, cnt[idx]) {
			s_ans += itr.first;
		}
		idx++;
	}

	sort(ALL(s_ans));

	cout << s_ans << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(15);

	solve_abc_c();

	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main() {
  int a,b,c,d,k;
  c = 0;
  d = 0;
  scanf("%d %d", &a, &b);
  for(int i = 0; i < 1000000000; i++) {
    c = a - i;
    d = b - i;
    if (c<0){
      c = -1 * c;
    }
    if (d<0) {
      d = -1 * d;
    }
    if (c == d) {
      k = i;
      printf("%d", k);
      return 0;
      break;
    }
  }
  printf("IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 128
abcd = input()
def dfs(i, s, sum):
    if i == 3:
        if sum == 7:
            print(s + '=7')
            exit()
    else:
        dfs(i+1, s + '+' + abcd[i+1], sum + int(abcd[i+1]))
        dfs(i+1, s + '-' + abcd[i+1], sum - int(abcd[i+1]))
dfs(0, abcd[0], int(abcd[0]))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int dp[2000][5000];
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int N, M;
  cin >> N >> M;
  memset(dp, INF, sizeof(dp));
  vector<int> a(M), b(M), c(M);
  REP(i, M) {
    cin >> a[i] >> b[i];
    REP(j, b[i]) {
      int t;
      cin >> t, t--;
      c[i] += 1 << t;
    }
  }
  REP(i, 2000) REP(j, 5000) dp[i][j] = INF;
  dp[0][0] = 0;
  REP(i, M) {
    REP(j, 1 << N) {
      chmin(dp[i + 1][j], dp[i][j]);
      int n = j | c[i];
      chmin(dp[i + 1][n], dp[i][j] + a[i]);
    }
  }
  cout << (dp[M][(1 << N) - 1] == INF ? -1 : dp[M][(1 << N) - 1]) << endl;
}

Measured memory_bytes: 42700
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define output(x) cout<<x<<endl;
typedef long long int ll;



int main()
{
	ll  i, j, k, l, m, sum, flag,ans,W,H,N;
	sum = 0;
	flag = 0;
	cin >> N;
	vector<ll>A(N);
	REP(i, 0, N) {
		cin >> A[i];
	}
	j = 1;
	sum += A[0] - 1;
	REP(i, 1, N) {
		if (A[i] == j + 1) {
			j++;
		}
		else {
			sum += (A[i] - 1) / (j + 1);
		}
	}
	output(sum);

	return 0;
}



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

void solve(){
string n;
	cin>>n;
   int len = n.size();
   char c = n[len-1];
   if(c=='2'||c=='4'||c=='5'||c=='7'||c=='9')
   	cout<<"hon\n";
   else if(c=='3')
   	cout<<"bon\n";
   else
   	cout<<"pon\n";
}
int main(){
	solve();
}

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

using namespace std;
using ll = long long int;

int main(void){

    ll h, w;
    cin >> h >> w;
    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }

    cout << (h*w+2-1) / 2 << endl;

    return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

ll MOD = 1e9+7;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vector<pii> arr (2*N);
	F0R(i, N) {
		int x; cin >> x;
		arr[i] = {x, 0};
	}
	F0R(i, N) {
		int x; cin >> x;
		arr[i+N] = {x, 1};
	}
	sort(arr.begin(), arr.end());
	vi pick (2);
	ll ans = 1;
	for (pii x : arr) {
		if (pick[1-x.second] == 0) {
			pick[x.second]++;
		} else {
			ans *= pick[1-x.second]--; ans %= MOD;
		}
	}
	print(ans);
}

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

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> a(A);
    vector<ll> b(B);
    vector<ll> c(C);
    for(int i=0;i<A;i++){
        cin >> a[i];
    }
    for(int i=0;i<B;i++){
        cin >> b[i];
    }
    for(int i=0;i<C;i++){
        cin >> c[i];
    }
    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());
    sort(c.begin(), c.end(), greater<ll>());
    ll total = 0;
    for(int i=0;i<X;i++){
        total += a[i];
    }
    for(int i=0;i<Y;i++){
        total += b[i];
    }
    int ea = X-1;
    int eb = Y-1;
    for(int i=0;i<C;i++){
        if(ea>=0 && eb>=0){
            if(a[ea]<b[eb]){
                if(c[i] > a[ea]){
                    total += c[i] - a[ea];
                    ea--;
                }
            }else{
                if(c[i] > b[eb]){
                    total += c[i] - b[eb];
                    eb--;
                }
            }
        }else if(ea >= 0 && c[i] > a[ea]){
            total += c[i] - a[ea];
            ea--;
        }else if(eb >= 0 && c[i] > b[eb]){
            total += c[i] - b[eb];
            eb--;
        }
        // total %= 1000000000 + 7;
    }
    cout << total << endl;

    return 0;
}


Measured memory_bytes: 2688
#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
#define int long long

int sumL[100010];
int sumR[100010];

int ansL[2][100010];
int ansR[2][100010];

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, C;
    cin >> N >> C;
    int x[100010], v[100010];
    rep(i, N) cin >> x[i] >> v[i];
    rep(i, N) {
        sumL[i + 1] += sumL[i] + v[i];
        sumR[i + 1] += sumR[i] + v[N - i - 1];
    }
    rep(i, N) {
        ansL[0][i + 1] = max(ansL[0][i], sumL[i + 1] - x[i]);
        ansL[1][i + 1] = max(ansL[1][i], sumL[i + 1] - x[i] * 2);
        ansR[0][i + 1] = max(ansR[0][i], sumR[i + 1] - (C - x[N - i - 1]));
        ansR[1][i + 1] = max(ansR[1][i], sumR[i + 1] - (C - x[N - i - 1]) * 2);
    }
    int ans = 0;
    // rep(i, N + 1) cout << ansL[0][i] << " ";
    // cout << endl;
    // rep(i, N + 1) cout << ansR[0][i] << " ";
    // cout << endl;

    rep(i, N + 1) {
        ans = max(ans, ansL[0][i] + ansR[1][N - i]);
        ans = max(ans, ansL[1][i] + ansR[0][N - i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9876
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<int> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

template<typename T1, typename T2>
bool pairCompare(const pair<T1, T2> &firstElof,
                 const pair<T1, T2> &secondElof) {
    return firstElof.second > secondElof.second;
}

int mapMaxValue(std::map<ll, int> m) {
    int max = 0;
    for (std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++) {
        if (max < it->second) max = it->second;
    }
    return max;
}

int main(void) {
    int n;
    string s;
    cin >> n >> s;

    int right_count = 0, left_count = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '(') {
            left_count++;
        } else {
            if (left_count > 0) left_count--;
            else right_count++;
        }
    }

    string ans = "";

    for (int i = 0; i < right_count; i++) {
        ans += "(";
    }
    ans += s;
    for (int i = 0; i < left_count; i++) {
        ans += ")";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> G(N);
    for (ll i = 0; i < M; ++i) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<ll> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<ll> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0);

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        ll v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (ll nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    cerr << dist[N-1] << endl;

    if (dist[N-1] <= 2 && dist[N-1] != -1) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }


    return 0;
}

Measured memory_bytes: 18196
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int straight(int[]);

int main() {

	int ans, h[5];

	while(scanf("%d,%d,%d,%d,%d", &h[0], &h[1], &h[2], &h[3], &h[4])!=EOF) {
		ans=0;
		for(int i=0; i<4; i++) {
			for(int j=i+1; j<5; j++) {
				if(h[i]==h[j])
					ans++;
			}
		}
		switch(ans) {
			case 1:
				cout << "one pair" << endl;
				break;
			case 2:
				cout << "two pair" << endl;
				break;
			case 3:
				cout << "three card" << endl;
				break;
			case 4:
				cout << "full house" << endl;
				break;
			case 6:
				cout << "four card" << endl;
				break;
			default:
				if(straight(h))
					cout << "straight" << endl;
				else
					cout << "null" << endl;
		}
	}
	
	return 0;

}

int straight(int h[5]) {
	
	sort(h, h+5);
	for(int i=0; i<9; i++) {
		if(h[0]==i&&h[1]==i+1&&h[2]==i+2&&h[3]==i+3&&h[4]==i+4||h[0]==1&&h[1]==10&&h[2]==11&&h[3]==12&&h[4]==13)
			return 1;
	}

	return 0;

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define N 1000000
int main()
{
   ll a,b;
   cin>>a>>b;
   cout<<max({a+b,a-b,a*b});
}     
     
     

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#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>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = 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;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    ll A, B, C, K; cin >> A >> B >> C >> K;
    if(A >= K) cout << K << endl;
    else if(A < K and A + B >= K) cout << A << endl;
    else cout << A - (K - (A + B)) << endl;
    return 0;
}


Measured memory_bytes: 3636
n = int(input())

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

S = num2alpha(n)
A = S.lower()
print(A)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }
signed main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int max = 0;
    int x = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'I') {
            x++;
        } else {
            x--;
        }
        if (x > max) {
            max = x;
        }
    }
    cout << max << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)

using namespace std;

template<class Abel> struct WeightedUnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    WeightedUnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n+1, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main(){
  int n, m;
  cin>>n>>m;
  
  WeightedUnionFind<int> wuf(n);
  
  rep(i,m){
    int l,r,d;
    cin>>l>>r>>d;
    if(!wuf.issame(l, r)){
      wuf.merge(l, r, d);
    }else{
      if(d != wuf.diff(l,r)){
        cout<<"No";
        return 0;
      }
    }
  }
  cout<<"Yes";

  return 0;
}



Measured memory_bytes: 1408
from itertools import accumulate

N, K = map(int, input().split())
P = map(int, input().split())
acc_P = list(accumulate(P))
ans = (acc_P[K-1] + K) / 2

for i in range(N-K):
    ans = max(ans, (acc_P[i+K] - acc_P[i] + K) / 2)

print(ans)

Measured memory_bytes: 25152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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 n,k; cin>>n>>k;
    ll res=n%k;
    cout<<min(res, k-res)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n";
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return 1;}return 0;}

int k,n;

bool comp(const pair<ll,ll>& l,const pair<ll,ll>& r){
    if(l.first==r.first)return l.second<r.second;
    else return l.first>r.first;
}

int main(){
    cin >> n >> k;
    vector<ll> t(n);
    vector<ll> d(n);
    REP(i,n){
        cin >> t[i] >> d[i];
        t[i]--;
    }
    vector<pair<ll,ll>> p(n);
    REP(i,n){
        p[i].first = d[i];
        p[i].second = t[i];
    }
    sort(all(p),comp);
    vector<int> u(n,0);
    vector<int> v(n,0);
    ll temp = 0;
    ll x=0;
    REP(i,k){
        temp+=p[i].first;
        if(u[p[i].second]==0)x++;
        u[p[i].second]++;
    }
    ll res = temp+x*x;
    int cnt = 1;
    FOR(i, k, n){
        if(u[p[i].second]==0){
            while(cnt<=k){
                if(u[p[k-cnt].second]>1){
                    temp-=p[k-cnt].first;
                    temp+=p[i].first;
                    x++;
                    chmax(res,temp+x*x);
                    u[p[k-cnt].second]--;
                    u[p[i].second]++;
                    cnt++;
                    break;
                }else{
                    cnt++;
                }
            }
        }
    }
    put(res);
    return 0;
}


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

using namespace std;

int n, x, a[110];

int main(){
    scanf("%d %d", &n, &x);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n);

    int cnt = 0;
    for(int i = 1; i <= n; i++)
        if(a[i] <= x) x -= a[i], cnt++;
    if(cnt == n && x) cnt--;
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
X=[0 for i in range(10**5+1)]
Q=int(input())
sum_=sum(A)
for i in range(N):
    X[A[i]]+=1
for i in range(Q):
    B,C=map(int,input().split())
    sum_+=X[B]*(C-B)
    X[C]+=X[B]
    X[B]=0
    print(sum_)

Measured memory_bytes: 90592
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A, B;
	cin >> A >> B;
	int ans = 0;
	rep(i, A, B + 1)
	{
		if (i % 10 == (i / 10000) % 10 && (i / 10) % 10 == (i / 1000) % 10)
		{
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define min(a, b) ((a) < (b)? (a):(b))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(typeof(n) i=(a); i<(n); i++)

int main() {
	int N, D, X;
	cin >> N;
	cin >> D >> X;
	int ans = 0;
	rep(i, N) {
	    int a; cin >> a;
	    for(int d=1; d<=D; d+=a) ans++;
	}
	cout << ans+X << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int x[100][100];
int main() {
	int n; cin >> n;
	if (n == 2) { cout << "-1" << endl; return 0; }
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - 1; j++) {
			x[i][j] = (i + j + 1) % n + 1;
		}
	}
	if (n % 2 == 0) {
		for (int i = 0; i < n / 2; i++) {
			for (int j = 0; j < n - 2; j += 2) {
				swap(x[i][j], x[i][j + 1]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - 1; j++) {
			if (j)cout << ' ';
			cout << x[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val yens = parseList(sc, n)
    val sum = yens.sum()
    println(sum)
}


private fun parseList(scanner: Scanner, length: Int): List<Float> {
    return (0 until length).map {
        val value = scanner.nextFloat()
        val unit = scanner.next()
        if (unit == "BTC") {
            return@map value * 380000
        }
        return@map value
    }
}

Measured memory_bytes: 31908
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
vector<int> par(1000000);//それぞれの頂点の親,最大値をsizeにする
vector<int> dis(1000000);//ランク
vector<int> si(1000000);
int n;
class union_find{
  public:
  void init(){
    for(int i = 0;i < n;i++){
      par[i] = i;//最初、親は自分自身とする
      dis[i] = 0;
      si[i] = 1;
    }
  }
  //木の根を求める
  int root(int x){
    if(par[x] == x){
      return x;
    }
    else{
      return par[x] = root(par[x]);
    }
  }
  //xとyが同じ集合に属すか否か
  bool same(int x,int y){
    //cout << x << " " << y << endl;
    return (root(x) == root(y));
  }
  //xとyの属する集合を併合
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x == y){
      //si[x] = 0;
      return;
    }
    if(dis[x] < dis[y]){
      par[x] = y;
      si[x] = 0;
    }
    else{
      par[y] = x;
      if(dis[x] == dis[y])dis[x]++;
      si[y] = 0;
    }
  }
};

//union_find tree;
//tree.init() //これで初期化
//tree.unite(a,b) //aとbのグループを併合
//tree.same(a,b) //aとbが同じグループか(trueかfalse)

int main(){
  ll m;
  cin >> n >> m;
  union_find tree;
  tree.init();
  for(int i = 0;i < m;i++){
    ll x,y,z;
    cin >> x >> y >> z;
    x--,y--;
    tree.unite(x,y);
    //cout << x << " " << y << endl;
  }
  ll res = 0;
  //vector<bool> seen(n);
  for(int i = 0;i < n;i++){
    if(si[i] != 0)res++;
    //cout << si[i] << " ";
  }
  //cout << endl;
  cout << res << endl;
}

Measured memory_bytes: 14740
import java.util.Scanner;

public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        
        boolean flag = false;
        if(a < b) {
            for(int i = a; i <= b; i ++) {
                if(i == c) {
                    flag = true;
                    break;
                }
            }
        } else {
            for(int i = b; i <= a; i ++) {
                if(i == c) {
                    flag = true;
                    break;
                }
            }
        }
        String str = flag ? "Yes" : "No";
        System.out.println(str);
    }
}

Measured memory_bytes: 21716
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{
		int N = Int32.Parse(Console.ReadLine());

		int[] t = new int[N+1];
		int[] x = new int[N+1];
		int[] y = new int[N+1];
		for(int i = 1; i <= N; i++)
		{
			string[] args = Console.ReadLine().Split(' ');
			t[i] = Int32.Parse(args[0]);
			x[i] = Int32.Parse(args[1]);
			y[i] = Int32.Parse(args[2]);
		}

		bool enable = true;
		for(int i = 1; i <= N; i++)
		{
			int tSpan = t[i] - t[i-1];
			int d = Math.Abs(x[i] - x[i-1]) + Math.Abs(y[i] - y[i-1]);
			if((tSpan < d) || ((tSpan -d) % 2) == 1)
			{
				enable = false;
				break;
			}
		}
	
		Console.WriteLine(enable ? "Yes" : "No");
	}
}





Measured memory_bytes: 16196
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>

std::string s;
std::vector<int> v, l, r;
int ans;

int main(){
	std::cin >> s;
	int t = 0, u = 0;
	for(int i=0; i<s.size(); ++i){
		if(s[i] == '0' + t){
			++u;
		}else{
			v.push_back(u);
			t = s[i] - '0';
			u = 1;
		}
	}
	v.push_back(u);
	l = r = v;
	for(int i=1; i<v.size(); ++i){
		l[i] += l[i-1];
		r[v.size()-i-1] += r[v.size()-i];
	}
//	for(int i=0; i<v.size(); ++i) printf("%d %d %d\n", v[i], l[i], r[i]);
	ans = std::min(l[v.size()-1], r[0]);
	for(int i=0; i<v.size()-1; ++i)
		ans = std::min(ans, std::max(l[i], r[i+1]));
	printf("%d\n", ans);
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int ans[10001];

int main(void){
	int n;
	scanf("%d",&n);
	int cnt=0;
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++){
			for(int k=1;k<=100;k++){
				int val=i*i+j*j+k*k;
				val+=i*j+j*k+k*i;
				if(val<=n){
					ans[val]++;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 3756
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

K, X = get_ints

puts (X - K + 1).step(X + K - 1).map { _1 }.join(' ')


Measured memory_bytes: 14496
n, k = map(int, input().split())
h = list(map(int, input().split()))

def chmin(a, b):
    if a > b: return b
    else: return a

dp = [float('inf')] * (n + k)
dp[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            dp[i + j] = chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
print(dp[n - 1])

Measured memory_bytes: 84888
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();        
        int X = r.i();
        print((X-3)*(X-5)*(X-7) == 0, "YES", "NO");
    }
    static void print(Object o){
        System.out.println(o.toString());
    }
    static void print(boolean b, String s1, String s2){
        System.out.println(b ? s1 : s2);
    }
    static int max(int[] ii){
        int max = ii[0];
        for(int i : ii) if(max < i) max = i;
        return max;
    }
    static int min(int[] ii){
        int min = ii[0];
        for(int i : ii) if(i < min) min = i;
        return min;
    }
    static long max(long[] ll){
        long max = ll[0];
        for(long l : ll) if(max < l) max = l;     
        return max;
    }
    static long min(long[] ll){
        long min = ll[0];
        for(long l : ll) if(l < min) min = l;
        return min;
    }
    static double max(double[] dd){
        double max = dd[0];
        for(double d : dd) if(max < d) max = d;
        return max;
    }
    static double min(double[] dd){
        double min = dd[0];
        for(double d : dd) if(d < min) min = d;
        return min;
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return readLine().split(" ");
        }
        int i() throws IOException{
            return Integer.parseInt(readLine());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        int[] ii(int N) throws IOException{
            int[] ii = new int[N];
            for(int j = 0; j < N; j++) ii[j] = i();
            return ii;
        }
        long l() throws IOException{
            return Long.parseLong(readLine());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
        long[] ll(int N) throws IOException{
            long[] ll = new long[N];
            for(int j = 0; j < N; j++) ll[j] = i();            
            return ll;
        }
    }
}

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

int N, Q;
std::vector<int> edges[200000];
int64_t num[200000];

void dfs(int i, int p){
  for (int j: edges[i]) if (j != p){
    num[j] += num[i];
    dfs(j, i);
  }
}

int main(){
  std::cin >> N >> Q;
  for (int i = 0; i < N - 1; i++){
    int a, b;
    std::cin >> a >> b;
    edges[a-1].push_back(b-1);
    edges[b-1].push_back(a-1);
  }
  for (int i = 0; i < Q; i++){
    int p, x;
    std::cin >> p >> x;
    num[p-1] += x;
  }
  
  dfs(0, -1);
  for (int i = 0; i < N; i++){
    std::cout << num[i] << " \n"[i == N-1];
  }
  return 0;
}

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

int main() {
  
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long x1, x2, x3, x4;
  
  x1 = a * c;
  x2 = a * d;
  x3 = b * c;
  x4 = b * d;
  
  long long ans;
  
  ans = max(max(x1, x2), max(x3, x4));
  
  cout << ans << endl;

}

Measured memory_bytes: 3628
#include <stdio.h>
int main(void){
	int i , j , t , data[10];
	for(i = 0 ;  i < 10 ; i++){
		scanf("%d ",&data[i]);
	}
	for( i = 0 ; i < 9 ; i++){
		for( j = 0 ; j < 9-i ; j++){
			if(data[j] < data[j+1]){
			t = data[j];
			data[j] = data[j+1];
			data[j+1] = t;
			}
		}
	}
	for(i = 0 ; i < 3 ; i++){
		printf("%d\n",data[i]);
	}
	return 0;
}

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

struct edge{
    int index,x,y;
};

struct node{
    int cost,u,v;
};

bool comp(node a1,node a2){
    return a1.cost < a2.cost;
}

bool compx(edge e1,edge e2){
    return e1.x < e2.x;
}

bool compy(edge e1,edge e2){
    return e1.y < e2.y;
}

struct UnionFind{

    vector<int> par;
    vector<int> sizes;

    UnionFind(int n):par(n),sizes(n,1){
        for(int i=0;i<n;i++){
            par[i]=i;
        }
    }
    
    int find(int x) { //xの根を得る
        if (x == par[x]) return x;
        return par[x] = find(par[x]); //根を張り替えながら再帰的に根ノードを探す
    }

    void unite(int x, int y) { //xとyの集合を併合
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sizes[find(x)];
    }
};

int main(){
    int N; cin >> N;
    UnionFind uf(N);
    edge ex[N];
    edge ey[N];
    for(int i=0;i<N;i++){
        int x,y; cin >> x >> y;
        ex[i]={i,x,y};
        ey[i]={i,x,y};
    }
    sort(ex,ex+N,compx);
    sort(ey,ey+N,compy);
    vector<node> ans;
    for(int i=0;i<N-1;i++){
        ans.push_back({abs(ex[i+1].x-ex[i].x),ex[i].index,ex[i+1].index});
        ans.push_back({abs(ey[i+1].y-ey[i].y),ey[i].index,ey[i+1].index});
    }
    sort(ans.begin(),ans.end(),comp);
    long long res=0;
    for(int i=0;i<ans.size();i++){
        //cout << ans[i].cost << endl;
        if(!uf.same(ans[i].u,ans[i].v)){
            uf.unite(ans[i].u,ans[i].v);
            res+=ans[i].cost;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 8052
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define mp(a, b) make_pair((a),(b))
#define bs(n) ((ull)1<<(ull)n)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;
constexpr double eps = 0.000000001;


int dp[100][100], dq[100][100], h, w;
vector<string> m;

int rec(int y, int x) {
    if (y == h && x == w) return 0;
    if (dq[y][x] == 0) {
        dp[y][x] = INT32_MAX;
        dq[y][x] = 1;
        auto t = [&y, &x](int y1, int x1) {
            dp[y][x] = min(dp[y][x], rec(y1, x1) + (m[y][x] == '.' && m[y1][x1] == '#' ? 1 : 0));
        };
        if (y < h)t(y + 1, x);
        if (x < w)t(y, x + 1);
    }
    return dp[y][x];
}

int main() {
    cin >> h >> w;
    m.resize(h);
    h--;
    w--;
    for (auto &e:m)cin >> e;
    int t = m[0][0] == '#' ? 1 : 0;
    cout << rec(0, 0) + t << endl;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    int n;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        SortedMap<Integer, Integer> counts = new TreeMap<>(Collections.reverseOrder());
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (!counts.containsKey(a)) {
                counts.put(a, 1);
            } else {
                counts.put(a, counts.get(a) + 1);
            }
        }
        int first = 0;
        int second = 0;
        for (Map.Entry<Integer, Integer> entry : counts.entrySet()) {
            int value = entry.getValue();
            if (value >= 4) {
                if (first == 0) {
                    first = entry.getKey();
                }
                second = entry.getKey();
                break;
            } else if (value >= 2) {
                if (first == 0) {
                    first = entry.getKey();
                } else {
                    second = entry.getKey();
                    break;
                }
            }
        }
        System.out.println((long)first * second);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 46024
N = int(raw_input())
V = map(int, raw_input().split(' '))

sorted_V = [N-i-1 for i in range(N)]

sorted_V.sort(reverse=True,key=lambda x: V[x])
lowest = N

uses = [0 for i in range(N)]

last = V[sorted_V[0]]

for ind, val in enumerate(sorted_V):
	if ind != N - 1 and V[sorted_V[ind]] == V[sorted_V[ind + 1]]:
		continue

	lowest = min(lowest, val)
	spots = ind + 1

	if ind == N - 1:
		individual_removals = last
		last = 0
	else:
		individual_removals = last - V[sorted_V[ind + 1]]
		last = V[sorted_V[ind + 1]]

	full_removals = individual_removals * spots
	uses[lowest] += full_removals

for i in uses:
	print i

Measured memory_bytes: 15548