akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ERotationMatching solver = new ERotationMatching();
        solver.solve(1, in, out);
        out.close();
    }

    static class ERotationMatching {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();

            if (n % 2 == 1) {
                for (int i = 0; i < m; i++) {
                    out.println(Util.join(i + 1, 2 * m - i));
                }
                return;
            }

            int i = n / 2, j = n / 2 + 1;
            while ((j - i) < n / 2 && m > 0) {
                out.println(Util.join(i, j));
                i--;
                j++;
                m--;
            }
            j++;
            while (m > 0) {
                out.println(Util.join(i, j));
                i--;
                j++;
                m--;
            }
        }

    }

    static class Util {
        public static String join(int... i) {
            StringBuilder sb = new StringBuilder();
            for (int o : i) {
                sb.append(o);
                sb.append(" ");
            }
            if (sb.length() > 0) {
                sb.deleteCharAt(sb.length() - 1);
            }
            return sb.toString();
        }

        private Util() {
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }
}



Measured memory_bytes: 46140
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define lint long int
int main(){
    lint W,H;
    cin>>W>>H;
    lint x,y;
    cin>>x>>y;
    ld S=W*H;
    cout<<fixed<<setprecision(10)<<S/2<<" ";
    if(((W%2==0)&&(W/2==x))&&((H%2==0)&&(H/2==y))){
        cout<<1<<endl;
    }
    else{
        cout<<0<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <stack>
#include <functional>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

#define _SI(arr) (sizeof(arr)/sizeof(arr[0])

int main() {
	ll N, A;
	cin >> N >> A;

	N = N % 500;

	if (A >= N)
	{
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
}

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

using namespace std;

struct Store
{
    vector<int> open;
    vector<int> profits;
};

Store ReadStore()
{
    Store store;
    store.open.resize(10);

    for (auto &o : store.open) {
        cin >> o;
    }
    return store;
}

int Bit(int num, int pos)
{
    return (num & (1 << pos)) ? 1 : 0;
}

int64_t Profit(const vector<Store> &stores, int mask)
{
    int64_t profit = 0;
    for (const auto &s : stores) {
        int matches = 0;
        for (int i = 0; i < 10; i += 1) {
            if (Bit(mask, i) == 0) {
                continue;
            }
            matches += s.open[i] ? 1 : 0;
        }
        profit += s.profits[matches];
    }
    return profit;
}

int64_t Solve(const vector<Store> &stores)
{
    int64_t res = -(1LL << 40);
    for (int i = 1; i < (1 << 10); i += 1) {
        res = max(res, Profit(stores, i));
    }
    return res;
}

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

    vector<Store> stores(n);
    for (auto &s : stores) {
        s = ReadStore();
    }

    for (auto &s : stores) {
        s.profits.resize(11);
        for (auto &p : s.profits) {
            cin >> p;
        }
    }

    auto res = Solve(stores);
    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(3 * n);
    priority_queue<int, vector<int>, greater<int>> a_front;
    priority_queue<int> a_back;
    for (int i = 0; i < 3 * n; i++) {
        cin >> a[i];
        if (i < n) {
            a_front.push(a[i]);
        }
        if (i >= 2 * n) {
            a_back.push(a[i]);
        }
    }
    //区間を[0,n+i),[n+i,3*n)と切った時の和
    vector<lint> front_sum(n + 1, 0), back_sum(n + 1, 0);
    for (int i = 0; i < n; i++) {
        front_sum[0] += a[i];
    }
    for (int i = 0; i < n; i++) {
        back_sum[n] += a[2 * n + i];
    }
    // front_sumを構築
    for (int i = 0; i < n; i++) {
        a_front.push(a[n + i]);
        front_sum[i + 1] = front_sum[i] + a[n + i] - a_front.top();
        a_front.pop();
    }
    // back_sumを構築
    for (int i = 0; i < n; i++) {
        a_back.push(a[2 * n - 1 - i]);
        back_sum[n - 1 - i] = back_sum[n - i] + a[2 * n - 1 - i] - a_back.top();
        a_back.pop();
    }
    //最大のやつを探す
    lint ans = LLONG_MIN;
    for (int i = 0; i <= n; i++) {
        ans = max(ans, front_sum[i] - back_sum[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3960
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		double a = 2 * n * Math.PI;
		System.out.println(a);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

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

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

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

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}

Measured memory_bytes: 33128
#include <bits/stdc++.h>
 
#define ll long long
#define loop(a) loopi(i,a)
#define loopi(i,a) for(int i=0; i<a; i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
 
using namespace std;
 
const int mod=1e9+7;
 
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	string str;
	cin >> str;
	int ans=0;
	while(!str.empty()){
		if(str.size()==1) break;
		if(*str.begin()!=*(str.end()-1)) ans++;
		str.erase(str.begin(),str.begin()+1);
		str.erase(str.end()-1,str.end());
	}
	cout << ans << "\n";
	return 0;
}


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

int main(){
    int m, f, r;
    while(true){
        scanf("%d %d %d", &m, &f, &r);
        if(m == -1 && f == -1 && f == -1) break;
        
        char g;
        if(m == -1 || f == -1){
            g = 'F';
        }else if(m + f >= 80){
            g = 'A';
        }else if(m + f >= 65){
            g = 'B';
        }else if(m + f >=50){
            g = 'C';
        }else if(m + f >= 30){
            if(r >= 50) g = 'C';
            else g = 'D';
        }else{
            g = 'F';
        }

        printf("%c\n", g);
    }
    return 0;
}

Measured memory_bytes: 1028
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {

			String str = br.readLine();
			StringTokenizer st = new StringTokenizer(str, " ");
			int x = Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());

			if (x == 0 && y == 0)
				break;
			if (x <= y) {
				System.out.println(x + " " + y);
			} else {
				System.out.println(y + " " + x);
			}
		}
	}

}



Measured memory_bytes: 26536
import itertools
N,M,Q = map(int,input().split())
abcd = [list(map(int,input().split())) for q in range(Q)]
print(max(sum(d for a,b,c,d in abcd if i[b-1]-i[a-1]==c) for i in itertools.combinations_with_replacement(range(M),N)))

Measured memory_bytes: 9096
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

typedef long long LL;

int main(){
    int N;
    while(cin >> N) {
        vector<LL> A(2 * N);
        REP(i, N) cin >> A[i];
        REP(i, N) A[N + i] = A[i];
        vector<LL> cum(A.size() + 1);
        REP(i, A.size()) cum[i + 1] = cum[i] + A[i];
        
        LL S = cum[N];

        LL ans = 0;
        for(int i = 0, j = 0; i < N; i++) {
            while(cum[j + 1] - cum[i] < S / 3) {
                j++;
            }
            // A[i] + ... + A[j - 1] < S / 3, 
            // A[i] + ... + A[j] >= S / 3
            for(int l = j - i - 3; l <= j - i + 3; l++) if(l >= 1 && N - l >= 2) {
                int k = i + l;
                // A[i, k) + A[k, i + N)
                int lb = 0, ub = N - l; // 
                while(ub - lb > 1) {
                    int mid = (lb + ub) / 2;
                    if(cum[k + mid] - cum[k] < S / 3) {
                        lb = mid;
                    } else {
                        ub = mid;
                    }
                }
                for(int m = lb - 3; m <= lb + 3; m++) if(m >= 1 && N - l - m >= 1) {
                    LL S1 = cum[i + l] - cum[i];
                    LL S2 = cum[i + l + m] - cum[i + l];
                    LL S3 = cum[i + N] - cum[i + l + m];
                    ans = max(ans, min({S1, S2, S3}));
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4164
import java.util.*;

@SuppressWarnings("unchecked")
class Main{
    static Scanner sc = new Scanner(System.in);

    public static void solve(int w, int h){
        int INF = Integer.MAX_VALUE/2;
        ArrayList[] list = new ArrayList[5];
        for(int i=0; i<5; i++) list[i] = new ArrayList<int[]>();

        int sx = 0, sy = 0, gx = 0, gy = 0;
        for(int i=0; i<h; i++){
            char[] line = sc.next().toCharArray();
            for(int j=0; j<w; j++){
                if(line[j]=='S'){ sx = j; sy = i;}
                if(line[j]=='G'){ gx = j; gy = i;}
                if(Character.isDigit(line[j])) list[line[j]-'1'].add(new int[]{j, i});
            }
        }

        int midx = 0, min = INF;
        for(int start=0; start<5; start++){
            int[][] dp = new int[5][];
            for(int i=1; i<=4; i++){
                int idx = (start + i) % 5;
                int before = (idx+4) % 5;
                dp[idx] = new int[list[idx].size()];
                Arrays.fill(dp[idx], INF);
                for(int j=0; j<list[idx].size(); j++){
                    int[] pos = (int[])list[idx].get(j);
                    if(i==1){
                        dp[idx][j] = Math.abs(sx - pos[0]) + Math.abs(sy - pos[1]);
                        continue;
                    }
                    for(int k=0; k<list[before].size(); k++){
                        int[] bpos = (int[])list[before].get(k);
                        int dist = dp[before][k] + Math.abs(pos[0] - bpos[0]) + Math.abs(pos[1] - bpos[1]);
                        if(i==4){
                            dist += Math.abs(gx - pos[0]) + Math.abs(gy - pos[1]);
                            if(dist<min){
                                min = dist;
                                midx = start+1;
                            }
                        }
                        dp[idx][j] = Math.min(dp[idx][j], dist);
                    }
                }
            }
        }
        if(min==INF) System.out.println("NA");
        else System.out.println(midx+" "+min);
    }

    public static void main(String[] args){
        while(true){
            int w = sc.nextInt(), h = sc.nextInt();
            if(w==0 && h==0) break;
            solve(w, h);
        }
    }
}

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

typedef long long ll;

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

    int n; cin >> n;
    vector<int> p(n);
    for(int i=0;i<n;i++) cin >> p[i];
    int ans = 0;
    for(int i=0;i<n;){
        if(p[i]==i+1 && p[i+1]==i+2){
            ans++;
            i += 2;
        }else if(p[i]==i+1){
            ans++;
            i++;
        }else i++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

  int k;
  cin>>k;

  if(k%2==0)
    cout<<k/2*k/2<<endl;
  else
    cout<<(k-1)/2*(k-(k-1)/2)<<endl;

  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <algorithm>

using namespace std;

int main(void) {
	int num, i, a, b, ans = 0;
	cin >> num;
	vector<int> ok(num, false);
	vector<pair<int, int>> x(num), y(num);	//pos, id
	vector<list<pair<int, int>>> mp(num);	//cost, to
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
	pair<int, int> p;
	for (i = 0; i < num; i++) {
		scanf("%d%d", &a, &b);
		x[i] = make_pair(a, i);
		y[i] = make_pair(b, i);
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	for (i = 0; i < num - 1; i++) {
		mp[x[i].second].push_back(make_pair(x[i + 1].first - x[i].first, x[i + 1].second));
		mp[x[i + 1].second].push_back(make_pair(x[i + 1].first - x[i].first, x[i].second));
		mp[y[i].second].push_back(make_pair(y[i + 1].first - y[i].first, y[i + 1].second));
		mp[y[i + 1].second].push_back(make_pair(y[i + 1].first - y[i].first, y[i].second));
	}
	for (auto itr = mp[0].begin(); itr != mp[0].end(); itr++)
		que.push(*itr);
	ok[0] = true;
	while (!que.empty()) {
		a = que.top().second;
		if (ok[a])
			que.pop();
		else {
			ok[a] = true;
			ans += que.top().first;
			que.pop();
			for (auto itr = mp[a].begin(); itr != mp[a].end(); itr++)
				que.push(*itr);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 18420
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(9);
  int n;
  cin>>n;
  int v[50];
  double ans=0;
  rep(i,n) cin>>v[i];
  sort(v,v+n);
  ans+=v[0];
  repi(i,1,n){
    ans+=v[i];
    ans/=2;
  }
  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 256
// キュー
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<limits.h>

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

//const int MAX_N = 100000;
const int STR_LEN = 10;

// キュー関連の定義
const int Max_Queue = 100000;
const int Queue_Error = -2147483648;

// キューの要素の構造体
typedef struct q_e
{
    // 配列の要素No.
    int id;
    // プロセス名
    char process_name[STR_LEN];
    // プロセスの時間
    int process_time;
}queue_element;

queue_element ary_queue[Max_Queue];

// キューの情報の構造体
typedef struct q_i
{
    int head;
    int tail;
}queue_info;

queue_info que_info;

void create_queue(void);
int enqueue(queue_element element);
queue_element dequeue(void);

int main(void)
{

    int N, cpu_time, total_time = 0;
    char str[STR_LEN];
    queue_element que_ele;

    // キューの初期化
    create_queue();

    scanf("%d %d", &N, &cpu_time);

    for(int i = 0; i < N; i++)
    {
    	que_ele.id = i;

        scanf("%s", &str[0]);
        strcpy(&(que_ele.process_name[0]), &str[0]);

        scanf("%s", &str[0]);
        que_ele.process_time = atoi(str);

        // キューに挿入する
        enqueue(que_ele);
    }

    // cpuの時間を割り当てる
    while( que_info.head != que_info.tail )
    {
        // キューからポップする
        que_ele = dequeue();

        if( 0 < que_ele.process_time
            && que_ele.process_time <= cpu_time )
        {
            total_time += que_ele.process_time;
            que_ele.process_time = 0;

            printf("%s %d\n", que_ele.process_name, total_time);
        }
        else
        {
            total_time += cpu_time;
            que_ele.process_time -= cpu_time;

            enqueue(que_ele);
        }
    }

    return 0;

}

// キューを作成する関数
void create_queue(void)
{
    int i;

    for(i = 0; i < Max_Queue; i++)
    {
        // キュー要素の初期化
    	ary_queue[i].id = 0;
        ary_queue[i].process_name[0] = '\0';
        ary_queue[i].process_time = 0;
    }

    que_info.head = 0;
    que_info.tail = 0;

    return;
}

// キューへプッシュする関数
int enqueue(queue_element element)
{

    if( que_info.head == ( que_info.tail + 1 ) % Max_Queue )
    {
        // キューが満杯
        return Queue_Error;
    }

    // キューに追加する
    ary_queue[que_info.tail] = element;
    que_info.tail = ( que_info.tail + 1 ) % Max_Queue;

    return 0;
}

// キューからポップする関数
queue_element dequeue(void)
{
    queue_element ret;

    if( que_info.head == que_info.tail )
    {
        // キューが空の時
        ret.id = Queue_Error;
    }
    else
    {
        // キューから取り出す
        ret = ary_queue[que_info.head];
        que_info.head = ( que_info.head + 1 ) % Max_Queue;
    }

    return ret;
}



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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K, A[105];
ll DP[105][int(1e5+5)], sum[105][int(1e5+5)];

int main(){
  cin >> N >> K;
  for (int i = 1; i <= N; i++) cin >> A[i];
  DP[0][K] = 1;
  sum[0][K] = 1;

  for (int i = 1; i <= N; i++){
    DP[i][0] = sum[i-1][A[i]];
    for (int j = 1; j <= K; j++){
      int M = min(j+A[i], K);
      DP[i][j] = (sum[i-1][M] - sum[i-1][j-1]) % MOD;
      if (DP[i][j] < 0) DP[i][j] += MOD;
    }

    sum[i][0] = DP[i][0];
    for (int j = 1; j <= K; j++){
      sum[i][j] = (sum[i][j-1] + DP[i][j]) % MOD;
    }
  }

  cout << DP[N][0] << endl;

  return 0;
}


Measured memory_bytes: 159788
#include<stdio.h>
int i,j,n,v,u,k,time,data[101][101],d[101],f[101];
void visit(int);



int main(){
  time=1;
  scanf("%d",&n);
  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      data[i][j]=0;
      d[j]=0;
      f[j]=0;
    }
  }
  for(i = 0; i < n; i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      data[u][v]=1;
    }
  }
  for(i=1;i<=n;i++){
    if(d[i]==0)visit(i);
  }
  for(i = 1;i <= n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;
}




void visit(int u){
  int v;
  
  d[u]=time++;

  
  
  for(v = 1; v <= n; v++){
    if(data[u][v]&d[v]==0)
      visit(v);
  }
  f[u]=time++;
}



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

using namespace std;
typedef long long ll;
const int N = 18;
int _w;

int n, a[1<<N], ans[1<<N];

struct Number {
	int x, id;
	Number() {}
	Number( int x, int id ):
		x(x), id(id) {}
	Number operator+( const Number &rhs ) const {
		return Number(x + rhs.x, -1);
	}
	int get() {
		return x;
	}
	bool operator<( const Number &rhs ) const {
		if( x == rhs.x ) return id < rhs.id;
		else return x > rhs.x;
	}
	bool operator==( const Number &rhs ) const {
		return x == rhs.x && id == rhs.id;
	}
};

struct Node {
	Number a, b;
	void merge( const Node &rhs ) {
		static Number tmp[4];
		tmp[0] = a;
		tmp[1] = b;
		tmp[2] = rhs.a;
		tmp[3] = rhs.b;
		sort(tmp, tmp+4);
		unique(tmp, tmp+4);
		a = tmp[0], b = tmp[1];
	}
};

Node f[1<<N];

int main() {
	_w = scanf( "%d", &n );
	for( int i = 0; i < (1<<n); ++i ) {
		_w = scanf( "%d", a+i );
		f[i].a = Number( a[i], i );
		f[i].b = Number( -1, -1 );
	}
	for( int i = 0; i < (1<<n); ++i )
		for( int j = 0; j < n; ++j )
			f[i|(1<<j)].merge( f[i] );
	for( int i = 1; i < (1<<n); ++i )
		ans[i] = (f[i].a + f[i].b).get();
	for( int i = 2; i < (1<<n); ++i )
		ans[i] = max( ans[i], ans[i-1] );
	for( int i = 1; i < (1<<n); ++i )
		printf( "%d\n", ans[i] );
	return 0;
}


Measured memory_bytes: 9216
#include <algorithm>
#include <cassert>
#include <iostream>
#include <limits>
#include <queue>
#include <vector>

#ifdef _DEBUG
#define ASSERT(x) cassert(x)
#define DLOG(x) cout << #x " " << x << endl;
#else
#define ASSERT(x)
#define DLOG(x)
#endif

using namespace std;

bool ok(vector<int>& ws, int64_t weight_limit, int count_limit) {
  size_t index = 0;
  for (int i = 0; i < count_limit; ++i) {
    for (int64_t w = 0; w + ws[index] <= weight_limit;) {
      w += ws[index++];
      if (index == ws.size()) return true;
    }
  }
  return false;
}

size_t search(vector<int>& ws, int k, size_t l, size_t r) {
  if (l >= r) return l;
  auto m = (l + r) / 2;
  if (ok(ws, m, k)) {
    return search(ws, k, l, m);
  } else {
    return search(ws, k, m + 1, r);
  }
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> ws;
  ws.reserve(n);
  for (int i = 0; i < n; ++i) {
    int wi;
    cin >> wi;
    ws.push_back(wi);
  }
  cout << search(ws, k, 0, 100'000LL * 10'000LL) << endl;
}



Measured memory_bytes: 3144
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << std::endl;
}

using namespace std;

int n;

int ch(vector<Pii> &da, int x) {
    int a = 0, b = 0, c = 1000000200;
    rip(i,n*2,0) {
        if(da[i].second < 0) a++;
        else b++;
        if(a == x) {
            c = min(c,da[i].first);
        }
        // cout << a MM b MM c MM da[i].first<< endl;
        if(b == x) {
            // cout << da[i].first - c << endl;
            return da[i].first - c + 1;
        }
    }
}

int main() {
    cin >> n;
    vector<Pii> da(n);
    rip(i,n,0) {
        cin >> da[i].first >> da[i].second;
    }
    vector<Pii> daa(n*2);
    rip(i,n,0) {
        daa[i*2] = {da[i].first, -i-1};
        daa[i*2 + 1] = {da[i].second, i+1};
    }
    sort(all(daa));
    if(n&1) {
        cout << ch(daa, n/2 + 1) << endl;
    }
    else {
        cout << ch(daa, n/2) + ch(daa, n/2+1) - 1 << endl;
    }
}

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

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n, a[100];
	cin >> n;
	REP(i, n) {
		cin >> a[i];
	}
	sort(a, a + n,std::greater<int>());
	int o = 0, e = 0;
	REP(i, n) {
		if (i % 2 == 0) {
			e += a[i];
		}
		else {
			o += a[i];
		}
	}
	cout << e - o << endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define pi 3.141592654

int main()
{
	int a, b, h, m;
	double H, M, A, val;
	scanf("%d %d %d %d", &a, &b, &h, &m);
	H=(h*360*1.00)/12+(m*360*1.00)/(12*60);
	M=(m*360*1.00)/(60);
	A=abs(H-M);
	if (A>180) A=360-A;

	A=(pi*A)/180.0;
	val=(a*a)+(b*b)-(2*a*b*cos(A));
	val=sqrt(val);
	printf("%.20lf\n", val);
	return 0;
}


Measured memory_bytes: 2584
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

#define MAX_N 200005
vector<int> pre_G[MAX_N];
vector<int> G[MAX_N];
int par_[MAX_N];
int flag_netsukigi[MAX_N];
void make_netsukigi(int r){
    rep(i,MAX_N){
        G[i].clear();
        par_[i] = 0;
        flag_netsukigi[i] = 0;
    }
    queue<int> que;
    que.push(r);
    flag_netsukigi[r] = 1;
    par_[r] = -1;

    while(que.size() > 0){
        int x = que.front();
        que.pop();
        flag_netsukigi[x] = 1;
        rep(i,pre_G[x].size()){
            if(flag_netsukigi[pre_G[x][i]] == 0){
                par_[pre_G[x][i]] = x;
                G[x].push_back(pre_G[x][i]);
                que.push(pre_G[x][i]);
            }
        }
    }
}

int n;
ll MOD;
vector<ll> dp[MAX_N];
int son[MAX_N];
ll ans[MAX_N];
ll dp2[MAX_N];

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

    rep(i,n-1){
        int a, b;
        scanf("%d%d", &a, &b);
        a--; b--; // 0-indexにするため.
        pre_G[a].push_back(b);
        pre_G[b].push_back(a);
    }

    make_netsukigi(0);

    rep(i,n) sort(G[i].begin(), G[i].end());
    rep(i,n){
        rep(j,G[i].size()) dp[i].push_back(0);
    }

    queue<int> que;
    rep(i,n){
        son[i] = G[i].size();
        if(son[i] == 0){
            que.push(i);
        }
    }

    while(que.size() > 0){
        int x = que.front();
        que.pop();
        if(x==0)break;
        ll num = 1;
        rep(i,G[x].size()){
            num *= (dp[x][i] + 1);
            num %= MOD;
        }
        int y = par_[x];
        int ite = lower_bound(G[y].begin(),G[y].end(),x) - G[y].begin();
        dp[y][ite] = num;
        son[y]--;
        if(son[y] == 0){
            que.push(y);
        }
    }

    que.push(0);

    while(que.size() > 0){
        int x = que.front();
        que.pop();
        ans[x] = dp2[x] + 1;
        rep(i,G[x].size()){
            ans[x] *= dp[x][i] + 1;
            ans[x] %= MOD;
        }
        ans[x] %= MOD;
        if(G[x].size() == 0) continue;
        int m = G[x].size();
        ll l[m], r[m];
        l[0] = dp2[x] + 1;
        srep(i,1,m) l[i] = l[i-1] * (dp[x][i-1] + 1) % MOD;
        r[m-1] = 1;
        drep(i,m-1) r[i] = r[i+1] * (dp[x][i+1] + 1) % MOD;
        rep(i,G[x].size()){
            int z = G[x][i];
            dp2[z] = l[i]*r[i]%MOD;
            que.push(z);
        }
    }

    rep(i,n) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 30648
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ExhaustiveSearch solver = new ExhaustiveSearch();
        solver.solve(1, in, out);
        out.close();
    }

    static class ExhaustiveSearch {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            int m = in.nextInt();
            HashMap<Integer, Boolean> hm = new HashMap<>();
            int[] q = new int[m];
            for (int i = 0; i < m; i++) {
                q[i] = in.nextInt();
                hm.putIfAbsent(q[i], false);
            }

            for (int i = 0; i < Math.pow(2, n); i++) {
                int cmp = 0;
                for (int j = 0; j < n; j++) if ((i & (int) Math.pow(2, j)) == (int) Math.pow(2, j)) cmp += a[j];
                if (hm.containsKey(cmp)) hm.replace(cmp, false, true);
            }

            for (int value : q) {
                out.println(hm.get(value) ? "yes" : "no");
            }

        }

    }
}




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

int main(){
	int N, M;
	cin >> N >> M;
	int a[N+1], w[N+1];
	rep(i,N+1) {
		a[i] = 0;
		w[i] = 0;
	}

	rep(i,M) {
		int p;
		string s;
		cin >> p >> s;
		if (s == "AC") {
			a[p]++;
		}
		else {
			if (a[p] > 0) continue;
			else w[p]++;
		}
	}

	int Na = 0, Nw=0;
	for (int i = 1; i <= N; i++) {
		if (a[i]>0) {
			Na++;
			Nw += w[i];
		}
	}

	cout << Na << endl;
	cout << Nw << endl;

	return 0;
}


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

int main(int argc, char const* argv[]) {
  int begin, end;
  bool tmp = true;
  while (true) {
    cin >> begin >> end;
    if (begin == 0 && end == 0) break;
    if (!tmp) cout << endl;
    if (tmp) tmp = false;

    bool flag = true;
    for (int i = begin; i <= end; i += 1) {
      if (i % 400 == 0) {
        flag = false;
        cout << i << endl;
        continue;
      }
      if (i % 4 == 0 && i % 100 != 0) {
        flag = false;
        cout << i << endl;
      }
    }
    if (flag) {
      cout << "NA" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
    int value = 700, i;
    char s[4];
    
    scanf("%s", s);
    
    for(i = 0; i<3; i++){
        if(s[i] == 'o'){
            value += 100;
        }
    }
    printf("%d\n", value);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] arr=new int[n];
		int[] arr1=new int[n];
		int count=0,flag=0;
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
			arr1[i]=sc.nextInt();
		}
		for(int i=0;i<n;i++) 
		{
				
			if(arr[i]==arr1[i])
			{
				count++;
				if(count>=3)
				{
					flag=1;
					break;
					
				}
			}
			else
			{
				count=0;
			}
			
		}
			
			
		
		if(flag==1)
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 27224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <array>
using namespace std;
typedef long long ll;

int uf[100000][2]={};

int main(int argc,char const* argv[])
{
  int n;
  cin >> n;
  vector<int> a(n,0);
  ll ans=10000000000;
  ll tmp=0;
  for(int i=0;i<n;i++)
    {
      cin >> a[i];
    }
  for(int j=-100;j<=100;j++)
    {
      tmp=0;
      for(int i=0;i<n;i++)
	{
	  tmp+=pow((j-a[i]),2);
	}
      if(tmp<=ans) ans=tmp;
    }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

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

  int sum = 0, back = 0;
  for (int i = 1; i <= n; ++i) {
    sum += 800;
    if (i % 15 == 0) back += 200;
  }

  cout << sum - back << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
import math as m

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

setrecursionlimit(10000)

def main():
	n, m = rli()
	G = [[] for i in range(n+1)]
	for _ in range(m):
		u, v = rli()
		G[u].append(v)
	ans = 0
	memo = [-1 for _ in range(n+1)]

	def longest(v):
		if memo[v] > -1:
			return memo[v]
		pathlen = 0
		for nbhr in G[v]:
			pathlen = max(pathlen, 1 + longest(nbhr))
		memo[v] = pathlen
		return pathlen

	for i in range(1, n+1):
		ans = max(ans, longest(i))

	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 133596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    char turn = 'a';
    string a, b, c;
    cin >> a >> b >> c;

    while(true){
        if(turn == 'a'){
            if(a.size() == 0){
                cout << 'A' << endl;
                return 0;
            } else {
                turn = a[0];
                a.erase(a.begin());
            }
        } else if(turn == 'b'){
            if(b.size() == 0){
                cout << 'B' << endl;
                return 0;
            } else {
                turn = b[0];
                b.erase(b.begin());
            }
        } else {
            if(c.size() == 0){
                cout << 'C' << endl;
                return 0;
            } else {
                turn = c[0];
                c.erase(c.begin());
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
H,W=map(int, input().split())
S=[]
S.append(list(['X']*(W+2)))
for h in range(H):
    S.append(['X']+list(input())+['X'])
S.append(list(['X']*(W+2)))

from collections import deque
q=deque([[1,1]])
d=[(1,0),(-1,0),(0,1),(0,-1)]
S[1][1]=0

cnt_nm=0
for h in range(H+2):
    for w in range(W+2):
        if S[h][w]=='#':
            cnt_nm+=1

while q:
    y,x = q.popleft()
#     S[y][x]='X'
    for dy,dx in d:
        if S[y+dy][x+dx]=='.':
            q.append([y+dy,x+dx])
            S[y+dy][x+dx]=S[y][x]+1

if S[H][W]=='.':
    print('-1')
else:
    print(H*W-cnt_nm-S[H][W]-1)

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

int main() {
string s,t  ;
    cin >> s>> t ;
  sort(s.begin(),s.end()) ;
  sort(t.begin(),t.end()) ;
  reverse(t.begin(),t.end()) ;

    if(s<t)  cout << "Yes" << endl;  
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

string s;
int ans;
void dfs(int idx,int num,int sum){
  if(idx == (int)s.size()) {
    ans += sum + num;
    return;
  }
  dfs(idx+1,num*10+s[idx]-'0',sum);
  if(num)dfs(idx,0,sum+num);
}

signed main(){
  cin>>s;
  dfs(0,0,0);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    int ans = a[n-1]-a[0];
    rep(i,n-1){
        ans = min(ans, k - (a[i + 1] - a[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>   //PBDS
#include <ext/pb_ds/tree_policy.hpp>       //PBDS
#define int long long int
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pi pair<int,int>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mi map<int,int>
#define PI  3.141592653589
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define f(i,x,n) for(int i=x;i<n;i++)
#define rf(i,x,n) for(int i=n-1;i>=x;i--)
#define check(x)   cerr<<#x<<" : "<<x<<endl;
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define fbo find_by_order                    //return iterator PBDS
#define ook order_of_key                     //return number :)) PBDS
#define baar exit(0)
using namespace __gnu_pbds;
using namespace std;
int powmod(int base,int exponent,int mod)
{
    int ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    return ans;
}
signed main()
{
//   #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
//   #endif
    fast
    int n;
    double d;
    cin>>n>>d;
    int cnt=0;
    f(i,0,n)
    {
    	int x,y;
    	cin>>x>>y;
    	int z=x*x;
    	int w=y*y;
    	double ans=sqrt(z+w);
    	if(ans<=d) cnt++; 
	}
	cout<<cnt;
	//cerr << "Time elapsed: " << clock() / 1000 << " ms" << endl;
    return 0;
}

Measured memory_bytes: 3784
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
vector < pair<string,int> > f_s;
int main(){
	int n,m;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		string a;
		cin>>a;
		bool flag=0;
		for(int i=0;i<f_s.size();i++)
			if(f_s[i].first==a){
				f_s[i].second++;
				flag=1;
				break;
			}
		if(!flag)
			f_s.push_back(make_pair(a,1));
	}
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		string a;
		cin>>a;
		for(int i=0;i<f_s.size();i++)
			if(f_s[i].first==a){
				f_s[i].second--;
				break;
			}
	}
	int maxn=0;
	for(int i=0;i<f_s.size();i++)
		if(f_s[i].second>maxn)
			maxn=f_s[i].second;
	printf("%d\n",maxn);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  signed long long int K,A,B;
  cin>>K>>A>>B;
  unsigned long long int bisket=1;
  for(int i=1;i<=K;i++){
    if(i>=A&&B-A>=2&&i!=K){
      i++;
      bisket+=B-A;
    }
    else bisket++;
  }
  cout<<bisket<<endl;
}

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

int main(){
  
  int N, i, a;
  cin >> N;
  vector<int> num(N);
  for(i=0; i<N; i++){
    cin>>a;
    if(a%4==0){
      num[0]++;
    }else if(a%2==0){
      num[1]++;
    }else{
      num[2]++;
    }
  }
  
  if(num[1]==0){
    if(num[0]+1>=num[2]){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    if(num[0]>=num[2]){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }    
  }
  
  return 0;
}

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

int main(){
    int N, tmp;
    double tmp2, tmp3;
    cin >> N;
    priority_queue<int, vector<int>, greater<int>> v;
    for(int i = 0; i < N; i++){
        cin >> tmp;
        v.push(tmp);
    }
    tmp2 = v.top();
    v.pop();
    for(int i = 0; i < N-1; i++){
        tmp3 = v.top();
        v.pop();
        tmp2 = (tmp2 + tmp3) / 2;
    }
    cout << tmp2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include<iomanip>
#include<sstream>
#include <fstream>
#define ll long long
#define pb push_back
#define clr(a, b) memset((a), (b), sizeof(a))
#define debugs(x) cout << "Line" << __LINE__ << "	" << #x << "=" << x << endl
#define break break
#define continue continue
#define itn int
#define endl '\n'
#define Endl endl
#define vint vector<int>
#define pii pair<int, int> 
using namespace std;

int n, k, m;
int a[200005];
void solve(int T)
{
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	sort(a + 1, a + n + 1);
	ll ans = a[n];
	int i, j;
	for (i = n - 1, j = 1; j <= (n-1) / 2; j++)
	{
		ans += 1ll * 2 * a[i--];
	}
	if (n & 1)ans -= a[i+1];
	cout << ans << endl;
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int numoftest = 1;

	//cin >> numoftest;


	for (int siven = 1; siven <= numoftest; ++siven)
		solve(siven);
	return 0;
}

/*


*/

Measured memory_bytes: 3868
class Comb0():
    # あらかじめO(k)の前計算をしておいてr<=kに対してnCrを高速に計算する
    def __init__(self, n, k=10**6, p=10**9+7):
        # num[i]=nPi
        # den[i]=(i!)^(-1)
        num, den = [1], [1]
        a, b = 1, 1
        for i in range(1, k+1):
            a = (a*(n-i+1)) % p
            b = (b*pow(i, p-2, p)) % p
            num.append(a)
            den.append(b)
        self.num = num
        self.den = den
        self.n = n
        self.p = p

    def calc(self, r):
        num, den = self.num, self.den
        if r < 0 or self.n < r:
            return 0
        return (num[r] * den[r]) % self.p


n, a, b = map(int, input().split())
p = 10**9+7
cmb = Comb0(n, k=max(a, b))
print((pow(2, n, p)-1-cmb.calc(a)-cmb.calc(b)) % p)


Measured memory_bytes: 18920
import sys
import fractions
def lcm(a, b):
    return abs(a*b) // fractions.gcd(a, b)
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=2
while a[0]%c==0:
  c=c*2
c=c//2
fail=0
for i in range(n):
  if a[i]%c!=0:
    fail=1
  if a[i]%(2*c)==0:
    fail=1
if fail==1:
  print(0)
  sys.exit()
A=1
for i in range(n):
  A=lcm(A,a[i])
print(2*m//A-2*m//(2*A))

Measured memory_bytes: 16320
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	int n=gInt();
	char[] c=new char[n];;

	void f(char top,int depth) {
		if(depth==n) {
			System.out.println(c);
			return;
		}
		for(c[depth]='a';c[depth]<=top+1;++c[depth])
			f((char)Math.max(top,c[depth]),depth+1);
	}

	void solve(){
		f((char)('a'-1),0);
	}

	public static void main(String[] A){
		new Main().solve();
	}

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	LongStream LONGS(int n){
		return LongStream.generate(this::gLong).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int t;
	Supplier<T> supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return (cur+d==to)||(d<0^cur+d<to);
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}


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

from collections import defaultdict
counter = defaultdict(int)

for k in range(1,N+1):
    temp = list(str(k))
    counter[(int(temp[0]),int(temp[-1]))] += 1

ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += counter[(i,j)]*counter[(j,i)]
print(ans)

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

int main(){
    char c;
    cin >> c;
    if (c == 'a'|| c == 'i'|| c == 'u'|| c == 'e'|| c == 'o'){
        cout << "vowel" <<endl;
    }else{
        cout << "consonant" << endl;
    }
    return 0;
}



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

int main() {
  int n; cin >>n;
  string s;
  cin>>s;
  int migi=0;
  int hidari=0;
  int count_hidari=0;
  int count_migi=0;
  vector<bool> hantei(n);
  for(int j=0;j<n;j++){
    hantei[j]=0;
  }
  for(int j=0;j<n-1;j++){
    if(s[j]=='(' && hantei[j]==false){
      for(int k=j+1;k<n;k++){
        if(s[k]==')'&&hantei[k]==false){
          hantei[j]=true;
          hantei[k]=true;
          break;
        }
      }
    }
  }
  for(int i=0;i<s.size();i++){
    if(s[i]=='('&&hantei[i]==false)count_hidari++;
    else if(s[i]==')'&&hantei[i]==false)count_migi++;
  }
  for(int j=0;j<count_hidari;j++){
    s.push_back(')');
  }      
  for(int j=0;j<count_migi;j++){
    s.insert(0,"(");
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256