akhauriyash/Code-Regression huggingface dataset:
/*input
7 1 2
24 35 40 68 72 99 103
*/

#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <map>

using namespace std;

void dijkstra(int target, vector<vector<pair<int, int>>> &node, vector<int> &result){

	int num_node = node.size();
	vector<int> distance(num_node, INT_MAX);
	// vector<int> result(num_node, INT_MAX);
	fill(result.begin(), result.end(), INT_MAX);
	vector<int> decided;

	result[target] = 0;
	distance[target] = 0;
	decided.push_back(target);
	int min_index = target;

	while(true){

		for(auto pa:node[min_index]){
			int d = pa.second;
			distance[pa.first] = min(distance[pa.first], distance[min_index] + d);
		}
		for(auto d:decided){
			distance[d] = INT_MAX;
		}

		vector<int>::iterator min_itr = min_element(distance.begin(), distance.end());
		min_index = std::distance(distance.begin(), min_itr);

		result[min_index] = distance[min_index];
		decided.push_back(min_index);

		if(decided.size() == num_node) break;
	}

}

int main()
{
	long N, A, B;
	cin >> N >> A >> B;

	vector<long> positions(N);
	for(int i=0;i<N;i++){
		cin >> positions[i];
	}

	long result = 0;
	for(int i=0;i<N-1;i++){
		long walk = (positions[i+1] - positions[i]) * A;
		long port = B;
		long cost = min(walk, port);
		result += cost;
	}

	cout << result << endl;

	// vector<vector<pair<int, int>>> node(N);
	// for(int i=0;i<N-1;i++){
	// 	node[i].push_back(make_pair(i+1, positions[i+1] - positions[i]));
	// }
	// vector<int> result(N, -1);

	// dijkstra(0, node, result);
	// for(auto r:result){
	// 	cout << r << " ";
	// }
	// cout << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef int status;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = int(1e9);
const int MAX = 100002;

int N,M,K;
char a[MAX],b[MAX];

int main()
{
    cin>>N;
    int n = N;
    int sum = 0;
    while(n)
    {
        sum += n%10;
        n/=10;
    }
    if(N%sum==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"unicode/utf8"
)

func main() {
	var a string
	fmt.Scan(&a)
	inputs := spritString(a)

	res := "Yes"
	for i, v := range inputs {
		step := i + 1
		if step%2 == 0 {
			if v == "R" {
				res = "No"
			}
		} else {
			if v == "L" {
				res = "No"
			}
		}
	}
	fmt.Println(res)
}

func spritString(input string) (res []string) {
	for i := 0; i < utf8.RuneCountInString(input); i++ {
		res = append(res, input[i:i+1])
	}
	return
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
 
using namespace std;
 
int main(void) {
    int m;
    int n;
    while (1) {
        cin >> m >> n;
        if (m == 0 && n == 0) {
            break;
        }
 
        vector<int> v(7368792, 0);
        int base = m;
        int count = 0;
        while (1) {
            for (int i = 1; i * base < v.size(); i++) {
                v[i * base] = 1;
            }
            count++;
 
            if (count == n) {
                break; 
            }
 
            while (1) {
                if (v[base] == 0) {
                    break;
                } else {
                    base++;
                }
            }
        }
 
 
        int check = m;
        while (1) {
            if (v[check] == 0) {
                cout << check << endl;
                break;
            }
            check++;
        }
    }
    return 0;
}

Measured memory_bytes: 31880
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int N,Q;
	while(1){
		cin>>N>>Q;
		if(N==0 && Q==0)break;
		int num;
		int convenient[101];
		rep(i,101)convenient[i]=0;
		rep(i,N){
			cin>>num;
			rep(j,num){
				int good;
				cin>>good;
				convenient[good]++;
			}
		}
		int max=0;
		int day;
		rep(i,101){
			if(max<convenient[i]){
				max=convenient[i];
				day=i;
			}
		}
		if(max>=Q){
			cout<<day<<endl;
		}else{
			cout<<"0"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Edge {
  int from, to, cost;
  Edge(int a, int b, int c) {
    from = a;
    to   = b;
    cost = c;
  }
};
std::vector<Edge> node[100001];
int result[100001];

void BFS(int curr_node, int prev_col, int prev_node, int prev_path) {
  // cerr << "\033[93m" << curr_node << "\033[m" << endl;
  if (prev_path % 2 == 0) {
    result[curr_node] = prev_col;
  } else {
    if (prev_col == 0) {
      result[curr_node] = 1;
    } else {
      result[curr_node] = 0;
    }
  }
  for (auto edge : node[curr_node]) {
    if (edge.to != prev_node) {
      BFS(edge.to, result[curr_node], curr_node, edge.cost);
    }
  }
  return;
}

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

  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    node[a].push_back(Edge(a, b, c));
    node[b].push_back(Edge(b, a, c));
  }
  BFS(1, 0, 0, 0);

  for (int i = 1; i <= n; i++) {
    cout << result[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=k-n+1;i<n+k;i++)
        printf("%d ",i);
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char x[7];
	int n;
	scanf("%s",x);
	if(strcmp(x,"SUN")==0)
		printf("7\n");
	else if(strcmp(x,"SAT")==0) 
		printf("1\n");
	else if(strcmp(x,"FRI")==0) 
		printf("2\n");
	else if(strcmp(x,"THU")==0) 
		printf("3\n");
	else if(strcmp(x,"WED")==0) 
		printf("4\n");
	else if(strcmp(x,"TUE")==0) 
		printf("5\n");
	else if(strcmp(x,"MON")==0) 
		printf("6\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> g(h, vector<char>(w));
    int ans = 0;
    rep(y, h) rep(x, w)
    {
        cin >> g[y][x];
        ans += (int)(g[y][x] == '.');
    }

    queue<P> q;
    q.emplace(0, 0);
    vector<vector<int>> d(h, vector<int>(w, -1));
    d[0][0] = 0;
    while (q.size())
    {
        P n = q.front();
        q.pop();
        int ny = n.first, nx = n.second;
        if (n == P(h - 1, w - 1))
        {
            break;
        }

        if (ny > 0 && g[ny - 1][nx] == '.' && d[ny - 1][nx] < 0)
        {
            d[ny - 1][nx] = d[ny][nx] + 1;
            q.push(P(ny - 1, nx));
        }
        if (nx > 0 && g[ny][nx - 1] == '.' && d[ny][nx - 1] < 0)
        {
            d[ny][nx - 1] = d[ny][nx] + 1;
            q.push(P(ny, nx - 1));
        }
        if (ny < h - 1 && g[ny + 1][nx] == '.' && d[ny + 1][nx] < 0)
        {
            d[ny + 1][nx] = d[ny][nx] + 1;
            q.push(P(ny + 1, nx));
        }
        if (nx < w - 1 && g[ny][nx + 1] == '.' && d[ny][nx + 1] < 0)
        {
            d[ny][nx + 1] = d[ny][nx] + 1;
            q.push(P(ny, nx + 1));
        }
    }
    if (d[h - 1][w - 1] < 0)
    {
        ans = -1;
    }
    else
    {
        ans -= d[h - 1][w - 1] + 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,m,s=0,c=0,i,x;
	cin>>n>>m;
	long long a[n+1];
	for(i=0;i<n;i++)
	{
    cin>>a[i];
    s=s+a[i];
	}
	
	for(i=0;i<n;i++)
	{
		x=a[i]*4*m;
		if(x>=s)
		{
        c++;
		}
	}
	if(c>=m)
	{
		cout<<"Yes"<<endl;
	}else
	{
		cout<<"No"<<endl;
	}
	return 0;

	 
}


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

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define DEB 0
#define all(x) x.begin(), x.end()

int dp[10001],sz;
int primes[10001];
bool check[10001];

void make_prime(){
  check[0]=check[1]=true;
  for(int i=2; i*i<=10000; i++){
    if( !check[i] ){
      for(int j=i*2; j<=10000; j+=i){
	check[j] = true;
      }
    }
  }
  primes[sz++] = 2;
  for(int i=3; i<=10000; i+=2){
    if( !check[i] ){
      primes[sz++] = i;
    }
  }
}

int main(){
  int n;
  make_prime();
  
  rep(i,sz){
    int sum = primes[i];
    dp[sum]++;
    for(int j=i+1; j<sz && sum+primes[j]<=10000; j++){
      sum += primes[j];
      dp[sum]++;
    }
  }

  while(scanf("%d",&n),n){
    printf("%d\n",dp[n]);
  }
  return 0;
}

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

int dif='a'-'A';
void outU( string &s ){
  char c;
  for(unsigned int i=0;i<s.size();i++ ){
    c=s.at( i );
    if( i==0 ) c-= dif;
    cout << c;
  }
}

int main(){
  string name, type;
  string names[100];
  int nw;

  while( true ){
    cin >> name >> type;
    //    cout << name << "," << type << endl;

    if( type=="X" ) break;

    for( int i=0;i<100;i++ )names[i]="";

    nw=0;
    char c;
    for( unsigned int i=0; i<name.size();i++ ){
      c = name.at(i);
      if( c== '_' ) nw++;
      else if( c<='Z'){
	c+= dif;
	if( names[nw].size()!=0 ){
	  nw++; names[nw]="";
	}
	names[nw] += c;
      }else
	names[nw] += c;
    }
    if( c!='_' )
      nw++;

    //    cout << "\ndiv "<<name<<endl;
    // for( int i=0;i<nw;i++ )      cout << names[i] << endl;

    if( type=="D" ){
      int i;
      for( i=0;i<nw-1;i++ )
	cout << names[i] << "_" ;
      cout << names[i] << endl;
    }else{
      if( type=="U" ) // テつ湘つ嘉つづδ淌つづδ古つ陛つカテつ偲つ堙つ療δアテつづδ催つ陛δ湘つ甘つキ
	outU( names[0] );
      else
	cout << names[0];
      for( int i=1;i<nw;i++ )
	outU( names[i] );
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 0
MOD = 10**9 + 7
def pow(x,n)
  if n == 0
    1
  elsif n % 2 == 0
    pow(x*x%MOD, n/2) % MOD
  else
    x * pow(x, n-1) % MOD
  end
end
def divisors(n)
  p = []
  2.upto((n**0.5)) do |i|
    break if i > n / i
    while n % i == 0
      p << i
      n /= i
    end
  end
  p << n if n != 1
  p
end

n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
lcm = Hash.new(0)
divisors(a[0]).each do |x|
  lcm[x] += 1
end
(n-1).times do |i|
  h = Hash.new(0)
  divisors(a[i+1]).each do |x|
    h[x] += 1
    lcm[x] = h[x] if lcm[x] < h[x]
  end
end
lcmNum = lcm.inject(1){|result,(k,v)| result * pow(k,v) % MOD}
ans = 0
a.each do |x|
  ans += lcmNum * pow(x, MOD-2) % MOD
  ans %= MOD
end
puts ans

Measured memory_bytes: 16828
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,k,cnt=0;
    cin>>n>>k;
    bool b[n]={0};
    for(int i=0;i<k;i++){
    	int d;
    	cin>>d;
    	for(int j=0;j<d;j++){
    		int c;
			cin>>c;
    		b[c-1]=1;
		}
	}
	for(int i=0;i<n;i++){
		if(b[i]==0){
			cnt++;
		}
	}
	cout<<cnt;
    
//system("pause");
return 0;

}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	char a[100][100],b[100][100];
	int c=0;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)cin>>a[i][j];
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++)cin>>b[i][j];
	}
	for(int i=0;i<=n-m;i++){
		for(int j=0;j<=n-m;j++){
			for(int k=0;k<m;k++){
				for(int l=0;l<m;l++){
					if(a[i+k][j+l]!=b[k][l])c=1;
				}
			}
			if(c==0){cout<<"Yes"<<endl;return 0;}
			c=0;
		}
	}
	cout<<"No"<<endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  bool flag = true;
  if((a*b) % 2 == 0) flag = false;
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int k, t, p, mx;

int main()
{
     cin>>k>>t;
     for(int i = 0 ; i < t ; i++ )
          cin>>p, mx = max(mx, p);
     cout<<max(mx-1-(k-mx), 0)<<endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc129/tasks/abc129_b
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
// clang-format on
int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  for (auto &x : W) {
    cin >> x;
  }
  int res{INT_MAX}, left{}, right{};
  REP(i, N - 1) {
    left = accumulate(W.begin(), W.begin() + 1 + i, 0);
    right = accumulate(W.begin() + i + 1, W.end(), 0);
    res = min(res, abs(left - right));
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

ans = 1
up = None
for l, r in zip(a, a[1:]):
    if l == r:
        continue
    if l < r:
        if up is None:
            up = True
        elif not up:
            ans += 1
            up = None
    else:
        if up is None:
            up = False
        elif up:
            ans += 1
            up = None

print(ans)


Measured memory_bytes: 14252
m, d = map(int, input().split())
ans = 0
for i in range(1, m+1):
    for j in range(1, d+1):
        d1 = j%10
        d10 = (j//10)%10
        if d1 < 2 or d10 < 2: continue
        if d1*d10 == i: ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}

int main() {
  int x,a;
  cin>>x>>a;
  if(x>=a){
    cout<<10<<endl;
    return 0;
  }
  cout<<0<<endl;
}


Measured memory_bytes: 3604
N=io.read("n")
K=io.read("n")
A={}
for i=1,N do
  A[i]=io.read("n")
end
table.sort(A)
minnub=1
for i=2,N do
  if A[i]==A[i-1] then
    minnub=minnub+1
    else
    break
  end
end
res=0
if (N-minnub)%(K-1)==0 then
  res=(N-minnub)//(K-1)
  else
  res=(N-minnub)//(K-1)+1
end
print(res)

Measured memory_bytes: 2424
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	string S;
	int c = 0;
	cin >> S;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == 'o')c++;
	}
	if (c + 15 - S.size() > 7)cout << "YES";
	else cout << "NO";
}


Measured memory_bytes: 256
N,M=map(int, input().split())
edge=[list(map(int,input().split())) for i in range(M)]
inf=10**20
c=[[inf]*N for i in range(N)]
e=[[0]*N for i in range(N)]
for i,j,w in edge:
    c[i-1][j-1]=w
    c[j-1][i-1]=w
    e[i-1][j-1]=1
    e[j-1][i-1]=1
for i in range(N):
    c[i][i]=0
ans=0
def wf(c,N):
    global ans
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if c[i][j]>c[i][k]+c[k][j]:
                    if e[i][j]==1:
                        ans+=1
                        e[i][j]=e[j][i]=0
                    c[i][j]=c[i][k]+c[k][j]
wf(c,N)
print(ans)

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

namespace AtCoder200531
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            ulong a = ulong.Parse(str[0]);
            ulong b = (ulong)((double.Parse(str[1]) * 1000 + 5) / 10);


            Console.WriteLine((ulong)(a*b/100));
        }
    }
}


Measured memory_bytes: 27604
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
using namespace std;

int n,m;
string s;
int dp[20][2];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1=freopen("in","r",stdin);
    //stream2=freopen("out","w",stdout);
    if(stream1==NULL)return 0;
    //if(stream2==NULL)return 0;
#endif
    cin>>s;
    int n=(int)s.size();
    int sum=0;
    bool flag=1;
    for(int i=n-1;i>=0;i--){
      if(i==0){
        if(flag)sum+=s[i]-'0';
        else sum+=s[i]-'1';
        continue;
      }
      sum+=9;
      if(9>s[i]-'0')flag=0;
    }
    cout<<sum<<endl;
#ifdef LOCAL_DEFINE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    fclose(stream1);
    //fclose(stream2);
#endif
    return 0;
}

Measured memory_bytes: 256
use std::io;


fn main() {
    let n = read_one::<usize>();
    let ans = recur(3, n) + recur(5, n) + recur(7, n);
    println!("{}", ans);
}

fn recur(n: usize, th: usize) -> usize {
    if n > th { return 0; }
    let s = n.to_string();
    let mut ans = 1;
    if !(s.contains("3") && s.contains("5") && s.contains("7")) {
        ans = 0;
    } 
    return ans
        + recur(n * 10 + 3, th)
        + recur(n * 10 + 5, th)
        + recur(n * 10 + 7, th);
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
package main

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

func main() {
	var N int
	fmt.Scan(&N)

	var cardStr string
	sc := bufio.NewScanner(os.Stdin)
	if sc.Scan() {
		cardStr = sc.Text()
	}

	cardArray := strings.Split(cardStr, " ")
	// var sumAlice int
	// var sumBobs int
	var sumTotal int

	for i := 0; i < N; i++ {
		var tmpValue int
		var tmpIndex int
		for index, valueStr := range cardArray {
			value, _ := strconv.Atoi(valueStr)
			if tmpValue < value {
				tmpValue = value
				tmpIndex = index
			}
		}
		if i%2 == 0 {
			sumTotal += tmpValue
		} else {
			sumTotal -= tmpValue
		}
		cardArray[tmpIndex] = "-1"
	}
	fmt.Println(sumTotal)
}


Measured memory_bytes: 640
N = int(input())
cards = list(map(int, input().split()))
cards.sort(reverse=True)
alice = []
bob = []

cards_number = len(cards)
for i in range(cards_number):
    if i % 2 == 0:
        alice.append(cards[i])
    else:
        bob.append(cards[i])

difference = abs(sum(alice) - sum(bob))
print(difference)


Measured memory_bytes: 3060
N = int(input())
xyhs = [tuple(map(int, input().split())) for _ in range(N)]
xyhs.sort(key=lambda x: x[2])

# 中心座標(Cx,Cy)を全通り試す
for Cx in range(101):
    for Cy in range(101):
        x, y, h = xyhs[-1]
        H = h + abs(Cx - x) + abs(Cy - y)
        for x, y, h in reversed(xyhs[:-1]):
            H2 = h + abs(Cx - x) + abs(Cy - y)
            if h == 0:
                if H2 < H: break
            else:
                if H != H2: break
        else:
            print(Cx, Cy, H)
            exit()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;




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

    vector<int>R(n,0);
    vector<int>G(n,0);
    vector<int>B(n,0);
    ll r=0;
    ll g=0;
    ll b=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            r++;
            R[i]=r;
            G[i]=g;
            B[i]=b;
        }
        if(s[i]=='G'){
            g++;
            R[i]=r;
            G[i]=g;
            B[i]=b;
        }
        if(s[i]=='B'){
            b++;
            R[i]=r;
            G[i]=g;
            B[i]=b;
        }
    }
    ll ans=0;

    // for(int i=0;i<n;i++){
    //     cout<<G[i]<<endl;
    // }


    for(ll j=1;j<n-1;j++){
        if(s[j]=='R'){
            ans+=(G[j-1] * (B[n-1]-B[j]));
            ans+=(B[j-1] * (G[n-1]-G[j]));
            for(ll i=1;i<=min(j,n-j-1);i++){
                if((s[j-i]=='B' && s[j+i]=='G') || (s[j-i]=='G' && s[j+i]=='B')){
                    ans--;
                }
            }
        }

        if(s[j]=='G'){
            ans+=(B[j-1] * (R[n-1]-R[j]));
            // cout<<ans<<endl;
            ans+=(R[j-1] * (B[n-1]-B[j]));
            // cout<<ans<<endl;
            for(ll i=1;i<=min(j,n-j-1);i++){
                if((s[j-i]=='B' && s[j+i]=='R') || (s[j-i]=='R' && s[j+i]=='B')){
                    ans--;
                }
            }
        }

        if(s[j]=='B'){
            ans+=(R[j-1] * (G[n-1]-G[j]));
            ans+=(G[j-1] * (R[n-1]-R[j]));
            for(ll i=1;i<=min(j,n-j-1);i++){
                if((s[j-i]=='G' && s[j+i]=='R') || (s[j-i]=='R' && s[j+i]=='G')){
                    ans--;
                }
            }
        }
        // cout<<"ans="<<ans<<endl;
    }

    cout<<ans<<endl;





    return 0;
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

// https://onlinejudge.u-aizu.ac.jp/solutions/problem/DSL_2_D/review/3635072/beet/C++14
template<typename E>
struct SegmentTree {
    using H = function<E(E, E)>;
    int n, height;
    H h;
    E ei;
    vector<E> laz;

    SegmentTree(H h, E ei) : h(h), ei(ei) {}

    void init(int n_) {
        n = 1;
        height = 0;
        while (n < n_) n <<= 1, height++;
        laz.assign(2 * n, ei);
    }

    inline void eval(int k) {
        if (laz[k] == ei) return;
        laz[(k << 1) | 0] = h(laz[(k << 1) | 0], laz[k]);
        laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]);
        laz[k] = ei;
    }

    inline void thrust(int k) {
        for (int i = height; i; i--) eval(k >> i);
    }

    void update(int a, int b, E x) {
        thrust(a += n);
        thrust(b += n - 1);
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) laz[l] = h(laz[l], x), l++;
            if (r & 1) --r, laz[r] = h(laz[r], x);
        }
    }

    E get_val(int a) {
        thrust(a += n);
        return laz[a];
    }

    void set_val(int a, E x) {
        thrust(a += n);
        laz[a] = x;
    }
};


int main() {

    int n, q;
    cin >> n >> q;
    auto h = [](int a, int b) {
        (void) a;
        return b;
    };
    SegmentTree<int> st(h, INT_MAX);
    st.init(n);

    rep(i, q) {
        int query;
        cin >> query;

        if (query == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            st.update(s, t + 1, x);
        } else if (query == 1) {
            int x;
            cin >> x;
            cout << st.get_val(x) << endl;
        }

    }

}



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

using vi = vector<int>;
using vvi = vector<vi>;

int main()
{
    ios_base::sync_with_stdio(0);

    int a, b, c; cin >> a >> b >> c;

    if(c >= a && c <= b) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < a.length; ++i) {
            a[i] = sc.nextInt();
        }

        System.out.println(solve(a));

        sc.close();
    }

    static int solve(int[] a) {
        Map<Integer, Integer> valueToCount = new HashMap<>();
        for (int ai : a) {
            for (int value : new int[] { ai - 1, ai, ai + 1 }) {
                valueToCount.put(value, valueToCount.getOrDefault(value, 0) + 1);
            }
        }

        return valueToCount.values().stream().mapToInt(x -> x).max().getAsInt();
    }
}

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

using LL = long long;
const LL M = 998244353;

int main() {
  LL N, S;
  cin >> N >> S;
  vector<LL> A(N);
  for(auto& i: A) cin >> i;

  LL ans = 0;
  vector<LL> dp(S+2);
  for(auto i=0; i<N; ++i) {
    auto x = min(S+1, A[i]);
    for(auto j=S; x<=j; --j) (dp[j] += dp[j-x]) %= M;
    dp[x] += i+1;
    (ans += dp[S]) %= M;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    int K;
    cin >> K;
    queue<ll> x;
    rep(i,9){
        x.push(i+1);
    }
    ll answer;
    rep(i,K){
        answer = x.front();
        x.pop();
      	int tail = answer % 10;
        if(tail != 0){
            x.push(answer*10 + tail - 1);
        }
        x.push(10*answer + tail);
        if(tail != 9){
            x.push(answer*10 + tail + 1);
        }
    }
    cout << answer << endl;
}


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

#define endl '\n'

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

#define ff first
#define ss second

#define x first
#define y second

const int N = 200;

bool a[N][N];
int dp[N][N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  int h, w;
  scanf("%d %d ", &h, &w);

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      a[i][j] = (getchar() == '#');
    }
    getchar();
  }

  dp[h-1][w-1] = a[h-1][w-1];
  for (int i = h-1, j = w-2; j >= 0; j--) {
    dp[i][j] = dp[i][j+1] + (a[i][j] and !a[i][j+1]);
  }
  for (int i = h-2, j = w-1; i >= 0; i--) {
    dp[i][j] = dp[i+1][j] + (a[i][j] and !a[i+1][j]);
  }
  for (int i = h-2; i >= 0; i--) {
    for (int j = w-2; j >= 0; j--) {
      dp[i][j] = min(
        dp[i+1][j] + (a[i][j] and !a[i+1][j]),
        dp[i][j+1] + (a[i][j] and !a[i][j+1])
      );
    }
  }

  printf("%d\n", dp[0][0]);

  return 0;
}

Measured memory_bytes: 384
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int times = sc.nextInt();
			Set<Long> set = new HashSet<Long>();
			for (int i = 0; i<times; i++){
				int query = sc.nextInt();
				long x = sc.nextLong();
				switch (query) {
				case 0:
					set.add(x);
					System.out.println(set.size());
					break;
				case 1:
					if (set.contains(x)) {
						System.out.println(1);
					} else System.out.println(0);
					break;

				}
			}
		}
	}
}



Measured memory_bytes: 164732
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve(h: i64) -> i64 {
    if h == 1 {
        return 1;
    }
    1 + solve(h/2) * 2
}
 
fn main() {
    input! {
        h: i64
    };
    println!("{}", solve(h));
}

Measured memory_bytes: 4352
// AOJ Volume1 0217

#include <stdio.h>

int main(void)
{
    int n;
    int p, d1, d2;
    int d, max_p, max_d;
    int i;
    
    while (1){
        scanf("%d", &n);
        if (n == 0){
            break;
        }
        max_p = max_d = -1;
        for (i = 0; i < n; i++){
            scanf("%d%d%d", &p, &d1, &d2);
            
            d = d1 + d2;
            
            if (d > max_d){
                max_d = d;
                max_p = p;
            }
        }
        printf("%d %d\n", max_p, max_d);
    }
    return (0);
}

Measured memory_bytes: 600
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <stdio.h>
#include <deque>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define REV(v) for (auto itr = v.rbegin(); itr != v.rend(); itr++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a));
#define MINUS(a) memset(a,-1,sizeof(a));
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define VL(v,n) vector<ll> v(n);
#define Read_VL(v,n) vector<ll> v(n);REP(i,0,n)cin>>v[i];
#define sumV(v,n) Vl(acm,n) REP(i,0,n) acm[i] = v[i] + ( i == 0 ? 0 : acm[i - 1]);
#define EPS (1e-10)
#define INF 1000000000000LL

void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}


template<class T=ll>struct Graph{
	int n;
	vector<vector<tuple<ll,T>>>edge;
	Graph(int N=1):n(N){edge.resize(n);}
	void add(ll f,ll t,T c,bool d=false){
		edge[f].emplace_back(t,c);
		if(!d)edge[t].emplace_back(f,c);
	}
	void view(){
		REP(i,0,n)for(auto&e:edge[i])
			puta(i,"=>",get<0>(e),", cost :",get<1>(e));
	}
};

bool cmp( ll a, ll b ){
  return a>b;
}

bool length_cmp( string &a, string &b ){
  return a.size() < b.size();
}

ll StoLL( string s )
{
	ll num=0;
  REP( i, 0, s.size() ){
    num = num * 10 + ( s[i] ^ 48 );
  }
  return num;
}

ll CtoLL( char c )
{
	if( 'a' <= c && c <= 'z'){
		return (ll)( c ^ 96 ) ;
	}
	else if( 'A' <= c && c <= 'Z'){
		return (ll)( c ^ 64 );
	}
  return 0;
}

ll MOD=1000000007;
ll dx[4] = { 1, 0, -1, 0 };
ll dy[4] = { 0, 1, 0, -1 };
//I ASCII code: '0' = 48; 'A' = 65; 'a' = 97

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    SIN(s)
    ll n = s.size();
    ll ans = 0;
    ll m = 0;
    REP( i, 0, n ){
      REP( j, i, n ){
        set<char> st;
        REP(k,i,j+1){
          st.insert(s[k]);
        }
        st.erase('A');
        st.erase('G');
        st.erase('C');
        st.erase('T');
        if( st.empty() ){
          ans=fmax(ans,j-i+1);
        }
      }
    }
    puta(ans);
    return 0;
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

ll n , m , ans;
ll x[MAXX];

int main()
{
    _FastIO;
    cin >> n >> m;
    for(ll i = 0; i < m; i++){
        cin >> x[i];
    }
    sort(x , x + m);
    vector<ll> v;
    for(ll i = 1; i < m; i++){
        ans += (x[i] - x[i - 1]);
        v.push_back(x[i] - x[i - 1]);
    }
    sort(v.begin() , v.end());
    reverse(v.begin() , v.end());
    ll y = n - 1;
    if(y > (m - 1))
        y = m - 1;
    for(ll i = 0; i < y; i++){
        ans -= v[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2168
import java.lang.*;
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int result = 0;
        for(int i = 0;i<n;i++){
            int kari = i+1;
            int atai = 0;
            while(kari!=0){
                atai += (kari%10);
                kari = (int)(kari/10);
            }
            if(atai>=a&&atai<=b){
                result += i+1;
            }
        }
        System.out.println(result);
        sc.close();
    }
}

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

const long long MINUS_INF = -1LL << 60;

struct UnionFind {
    vector<long long> par; // 親ノード
    vector<long long> rank; // ランク
    vector<long long> root_size; //ノードが根のときに、何個の子要素を持っているのか。(自分を含む)
                            //親じゃない場合は-1を出力

    UnionFind(long long n = 1) {
        init(n);
    }

    void init(long long n = 1) {
        par.resize(n); rank.resize(n); root_size.resize(n);
        for (long long i = 0; i < n; ++i) par[i] = i, rank[i] = 0, root_size[i] = 1;
    }

    long long root(long long x) {
        if (par[x] == x) {
            return x;
        }
        else {
            long long r = root(par[x]);
            return par[x] = r;
        }
    }

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

    //yをxにマージ
    bool merge(long long x, long long y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        root_size[x] += root_size[y];
        root_size[y] = -1;
        return true;
    }

    long long size(long long x){
        x = root(x);
        return root_size[x];
    }
};

int main(){
    int N; cin >> N;
    long long K; cin >> K;


    vector<long long> C(N+1);
    vector<long long> P(N+1);
    for(int i=1; i<=N; ++i){
        cin >> P[i];
    }

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

    UnionFind uf = UnionFind(N+1);

    //cycle_root, cycle_point.
    map<int, long long> m;


    for(int i=1; i<=N; ++i){
        uf.merge(i, P[i]);
    }

    // rootを全更新
    for(int i=1; i<=N; ++i){
        uf.root(i);
        m[uf.root(i)] += C[P[i]];
    }

    long long ans = MINUS_INF;

    //最初に始める点
    for(int i=1; i<=N; ++i){

        //何回歩けるか
        long long rest_K = K;
        long long tmp_ans = 0;

        //サイクルが負なら一周のみ
        if(m[uf.root(i)] <= 0){
            long long cnt = min(rest_K, uf.root_size[uf.root(i)]);
            int t = P[i];
            for(int _=0; _< cnt; ++_){
                tmp_ans += C[t];
                ans = max(ans, tmp_ans);
                t = P[t];
            }
        }else{
        //正なら最後の一種になるまで動く
            long long cycle_size = uf.root_size[uf.root(i)];
            long long cycle_cnt = rest_K / cycle_size;
            long long rest = rest_K % cycle_size;

            // if(rest == 0){
            cycle_cnt -= 1;
            // }

            tmp_ans = cycle_cnt * m[uf.root(i)];
            ans = max(ans, tmp_ans);
            rest_K -= cycle_cnt * cycle_size;

            int t = P[i];
            while(rest_K){
                tmp_ans += C[t];
                ans = max(ans, tmp_ans);
                t = P[t];
                rest_K--;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3872
#include<bits/stdc++.h>
#define for_int(i,a,b) for(int i=(a);i<=(b);++i)
#define rep_int(i,a,b) for(int i=(a);i>=(b);--i)
#define for_ll(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep_ll(i,a,b) for(ll i=(a);i>=(b);--i)
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1e6+5
#define quick_pow_mod 1e9+7
#define PII pair<int,int>
const int factor_N = 1e7 + 5;
const int tree_arr_N = 1e6 + 5;
using namespace std;
//快读
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (; isdigit(c); c = getchar())
		x = x * 10 + c - 48;
	return x * f;
}
const int N = 2e5 + 5;
int n, a[N];
vector<int>b;
ll ans;
int main() {
	n = read();
	for_int(i, 1, n) a[i] = read();
	sort(a + 1, a + 1 + n, [](const int a, const int b) {
		return a > b;
		});
	for_int(i, 1, n) {
		b.push_back(a[i]);
		if (i > 1) b.push_back(a[i]);
	}
	for_int(i,0,n-2) ans +=(ll) b[i];
	cout << ans << endl;
	return 0;
}



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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

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

int main() {
    ll n;
    cin >> n;
    ll i = 1;
    while (n > 0) {
        if (i * (i + 1) / 2 >= n) {
            cout << i << endl;
            n -= i;
            i = 0;
        }
        i++;
    }

    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <sstream>
#include <iostream>
#include <cstring>
#define REP(i,x,v)for(int i=x;i<=v;i++)
#define REPD(i,x,v)for(int i=x;i>=v;i--)
#define FOR(i,v)for(int i=0;i<v;i++)
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define IN(x,y) ((y).find((x))!=(y).end())
#define LOLDBG
#ifdef LOLDBG
#define DBG(vari) cout<<#vari<<" = "<<vari<<endl;
#define DBG2(v1,v2) cout<<(v1)<<" - "<<(v2)<<endl;
#else
#define DBG(vari)
#define DBG2(v1,v2)
#endif
#define CZ(x) scanf("%d",&(x));
#define CZ2(x,y) scanf("%d%d",&(x),&(y));
#define ALL(x) (x).begin(),(x).end()
#define un(x) x.erase(unique(ALL(x)),x.end());
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
template<typename T,typename TT> ostream &operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream &operator<<(ostream &s,vector<T> t){s<<"{";FOR(i,t.size())s<<t[i]<<(i==t.size()-1?"":",");return s<<"}"<<endl; }



int main()
{
    ios_base::sync_with_stdio(0);
    int n;cin>>n;
    vector<pii> v(n);
    FOR(i,n)cin>>v[i].fi;
    FOR(i,n)cin>>v[i].se;
    int best=-1;

    FOR(msk,(1<<n))
    {
        vector<pii> p;
        FOR(i,n) if ((1<<i)&msk) p.pb(mp(v[i].se,i)); else p.pb(mp(v[i].fi,i));
        vi bits;
        FOR(i,n) bits.pb(!!((1<<i)&msk));
        sort(ALL(p));
        int bad=0;
        int sum=0;
        vi ans(n);
        REP(c,1,50)
        {
            int mn=100,mx=-100;
            vi par[2]={vi(),vi()};

            FOR(i,n) if (p[i].fi==c)
            {
                mn=min(mn,i);mx=max(mx,i);
                int bit=(bits[p[i].se]+p[i].se)%2;
                par[bit].pb(p[i].se);
            }
            if (mn<100)
            {
                vi pos[2]={vi(),vi()};
                REP(j,mn,mx) pos[j%2].pb(j);
                if (sz(pos[0])==sz(par[0]) && sz(pos[1])==sz(par[1]))
                {
                    FOR(g,2)
                    {
                        sort(ALL(pos[g]));
                        sort(ALL(par[g]));
                        FOR(l,sz(pos[g])) ans[pos[g][l]]=par[g][l];
                    }
                }
                else {bad=1;break;}
            }
            if (bad) break;
        }
        FOR(i,n)FOR(j,i) if (ans[i]<ans[j]) sum++;
        if (!bad)
        {
            if (best==-1 || sum<best)
            {
                best=sum;
                //DBG(bits);
                //DBG(p);
            }
        }
    }
    cout<<best;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

template<class T> T pow(T a, T b) {
	if (b == 0)return 1;
	if (b % 2) {
		T ret = pow(a, (b - 1) / 2);
		return ret * ret * a;
	}
	else {
		T ret = pow(a, b / 2);
		return ret * ret;
	}
}

int main() {
	init();

	int N; cin >> N;
	vector<vector<int>>vec(2, vector<int>(N));
	rep(i, 0, 2)rep(j, 0, N)cin >> vec[i][j];
	int x = 0, ans = 0;
	rep(i, 0, N) {
		x += vec[0][i];
		int y = 0;
		rep(j, i, N) {
			y += vec[1][j];
		}
		chmax(ans, x + y);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
using System;

namespace sample1
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			String str = Console.ReadLine();
			while (str != null)
			{
				String[] strs = str.Split();
				var sum = int.Parse(strs[0]) + int.Parse(strs[1]);
				Console.WriteLine((int)Math.Log10(sum) + 1);
				str = Console.ReadLine();
			}
		}
	}
}



Measured memory_bytes: 13940
using System;
using System.Collections.Generic;
class Program{
	static void Main(){
		string s=Console.ReadLine();
		char c='0';
		int ans=0,a=0,z=0,j=0;
		var hs=new Dictionary<char,int>();
		for(int i=0;i<s.Length;i++){
			if(hs.ContainsKey(s[i])){hs[s[i]]++;a++;}
			else if(s[i]!='x'){hs.Add(s[i],1);a++;}
		}
		if(a==0){goto f;}
		foreach(KeyValuePair<char,int> e in hs){
			if(e.Key!='x'&&e.Value%2==1){
				if(c=='0'){c=e.Key;}
				else{ans=-1;goto f;}
			}
		}
		char[] cr=new char[a];
		a=0;
		if(c!='0'){
			for(;z<hs[c]/2+1;j++){
				if(s[j]!='x'){
					cr[a]=s[j];
					a++;
					if(s[j]==c){z++;}
				}
			}
			a=0;
			z=j;
			for(j=s.Length-1;j>=z;j--){
				if(s[j]!='x'){
					if(cr[a]!=s[j]){ans=-1;goto f;}
					a++;
				}
			}
			s="A"+s+"A";
			for(int i=z,k=z;k>-1;i++,k--){
				while(s[i]!=s[k]){
					if(s[i]=='x'){i++;}
					else{k--;}
					ans++;
				}
			}
		}
		else{
			for(int i=0;i<s.Length;i++){
				if(s[i]!='x'){
					cr[a]=s[i];
					a++;
				}
			}
			c=cr[a/2];
			for(int i=a/2,k=a/2-1;k>-1;i++,k--){
				if(cr[i]!=cr[k]){ans=-1;goto f;}
			}
			a=0;
			for(j=0;j<s.Length;j++){
				if(s[j]==c){
					a++;
					if(hs[c]/2==a){break;}
				}
			}
			s="A"+s+"A";
			z=j+2;
			while(s[z]=='x'){z++;}
			for(int i=z,k=j+1;k>-1;i++,k--){
				while(s[i]!=s[k]){
					if(s[i]=='x'){i++;}
					else{k--;}
					ans++;
				}
			}
		}
		f:
		Console.WriteLine("{0}",ans);
	}
}

Measured memory_bytes: 13920
n = int(input())
taro = 0
hanako = 0
for x in range(0, n):
    t, h = input().split()
    if t > h:
        taro += 3
    elif t < h:
        hanako += 3
    elif t == h:
        taro += 1
        hanako += 1
print(taro, hanako)



Measured memory_bytes: 5596