akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>
#include <list>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
//#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;

int main(void)
{
    int X; cin >> X;
    int A = 0, B = 0;
    rep(i, 0, 1000) {
        rep(j, 0, 1000) {
            if (pow(i, 5) - pow(j, 5) == X) {
                A = i; B = j;
                break;
            }else if(pow(i, 5) + pow(j, 5) == X) {
                A = i; B = -j;
                break;
            }
        }
    }
    cout << A << " " << B << endl;

    return 0;
}


Measured memory_bytes: 4012
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 

 
 
const int INF = 10000000;

int main(){
	int n;
	while(cin>>n){
		vi v(n, 0);
		rep(i, n) cin >> v[i];
		sort(all(v));
		int s = 0, ans = 0;
		rep(i, n){
			s += v[i];
			ans += s;
		}
		cout<<ans<<endl;
	}
}

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

int main(){
    int n;
    cin>>n;
    ll ans=0;
    for(int i=1; i<=n; ++i)ans+=(ll)i*(n-i+1);
    rep(i,n-1){
        int a,b; cin>>a>>b;
        if(a>b)swap(a,b);
        ans-=(ll)a*(n-b+1);
    }
    cout<<ans<<endl;
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

// y, x
string a[1005];
int dx[]={-1, 0, 0, 1};
int dy[]={0, 1, -1, 0};
int h,w;
queue<int> q;
queue<int> nq;

bool ok(int x, int y){
  return (0<=x&&x<w&&0<=y&&y<h);
}

void solve(int x, int y) {
  for(int i=0;i<4;i++){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(ok(nx, ny)&&a[ny][nx]=='.'){
      a[ny][nx]='#';
      nq.push(nx);nq.push(ny);
    }
  }
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  cin>>h>>w;
  for(int y=0;y<h;y++){
    cin>>a[y];
  }
  for(int y=0;y<h;y++){
    for(int x=0;x<w;x++){
      if(a[y][x]=='#'){
        q.push(x);
        q.push(y);
      }
    }
  }
  int res=0;
  while(1){
    while(!q.empty()){
      int x = q.front();q.pop();
      int y = q.front();q.pop();
      solve(x, y);
    }
    if(nq.size()>0)res++;
    else break;
    swap(q, nq);
    queue<int> empty;
    swap(nq, empty);
  }
  cout<<res<<endl;
  return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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;
}

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

int N, total;
vector<int> a;

void solve() {
    cin >> N; a.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        total += a[i];
    }
    int ans = 0, avg = round(double(total) / N);
    for (int i : a) {
        // cout << i << " " << avg << "\n";
        ans += pow(i - avg, 2);
        // cout << ans << "\n";
    }
    cout << ans;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <map>
#define int long long

using namespace std;

map<int,int> mp;
int q[1234567];

signed main(){
    int n;
    scanf("%lld",&n);
    int a;
    int h=0;
    for(int i=0;i<n;i++){
        scanf("%lld",&a);
        if(!mp[a]){
            q[h++]=a;
        }
        mp[a]++;
    }
    sort(q,q+h);
    int g=-1,z=-1;
    int flag=0;
    for(int i=h-1;i>=0;i--){
        if(mp[q[i]]>=2){
            if(mp[q[i]]>=4&&flag==0){
                long long s=q[i]*q[i]*1LL;
                cout<<s<<endl;
                return 0;
            } else {
                if(flag==0){
                    g=q[i];
                    flag=1;
                } else {
                    z=q[i];
                    break;
                }
            }
        }
    }
    if(z==-1||g==-1){
        puts("0");
    } else {
        long long l = g*z*1LL;
        cout<<l<<endl;
    }
    return 0;
}


Measured memory_bytes: 7296
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String[] array = br.readLine().split(" ");
			int N = Integer.parseInt(array[0]);
			int K = Integer.parseInt(array[1]);

			int[] A = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();

			int[] map = new int[N];

			for (int a : A) {
				map[a - 1]++;
			}

			Arrays.sort(map);

			int count = 0;
			for (int i = 0; i < map.length - K; i++) {
				count += map[i];
			}

			System.out.println(count);
		}
	}
}

Measured memory_bytes: 47268
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,n;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&e);
	if(a<40){
		a=40;
	}
	if(b<40){
		b=40;
	}
	if(c<40){
		c=40;
	}
	if(d<40){
		d=40;
	}
	if(e<40){
		e=40;
	}
	n=(a+b+c+d+e)/5;
	printf("%d\n",n);
	
	return 0;
}



Measured memory_bytes: 2756
from collections import Counter
def main():
    n = int(input())
    V = list(map(int,input().split()))

    C0 = Counter(V[0:n:2])
    C1 = Counter(V[1:n:2])

    items0 = list(C0.items())
    items0.sort(key=lambda x:-x[1])
    items1 = list(C1.items())
    items1.sort(key=lambda x:-x[1])

    ans = 0
    if items0[0][0] == items1[0][0]:
        sec = n//2
        if len(items0)==1 and len(items1)==1:
            ans = n//2
        elif len(items0)==1:
            ans = items1[0][1]
        elif len(items1)==1:
            ans = items0[0][1]
        else:
            ans = n//2-items0[0][1] + n//2-max(items0[1][1],items1[1][1])
    else:
        ans = n -items0[0][1] - items1[0][1]

    print(ans)
main()

Measured memory_bytes: 103028
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll n,w;
ll dp[105][100005];

ll solve(ll W[], ll V[]){
	for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<=w;j++)
		{
			//cout<<"1"<<endl;
			if(i==0 || j==0)
			{
				dp[i][j] = 0;
				continue;
			}
			if(W[i-1]<=j)
			{
				dp[i][j] = max(V[i-1]+dp[i-1][j-W[i-1]],dp[i-1][j]);
			}
			else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	return dp[n][w];
}

int main()
{
	
	cin>>n>>w;
	
	ll W[n],V[n];
	for(ll i=0;i<n;i++)
	{
		cin>>W[i]>>V[i];
	}
	
	cout<<solve(W,V)<<endl;
	return 0;
}

Measured memory_bytes: 80128
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	int k;
	cin>>k;
	vector<int> table = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cout<<table[k-1]<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,a) REP(i,0,a)
#define REV(i,a,b) for(i=a-1;i>=b;i--)
#define rev(s) reverse(s.begin(),s.end())
#define pb push_back
#define mp make_pair
#define ord(v) sort(v.begin(),v.end());
const ll MAXN=2*1e5+10;
#define MAX 2*1e9
#define fi first
#define se second
#define pi 3.141592653589793238
#define rem 1000000007
#define eps 1e-9

int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ll n,i;
    cin>>n;
    ll h[n];
    rep(i,n)
    cin>>h[i];
    ll f[n];
    f[0]=0;
    f[1]=abs(h[0]-h[1]);
    REP(i,2,n)
    {
        f[i]=min(f[i-2]+abs(h[i]-h[i-2]),f[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<f[n-1]<<endl;
    
    
    return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

// N, E, S, W
const int dx[4] = {-1, 0,  1,  0};
const int dy[4] = { 0, 1,  0, -1};

int chr2int(char c) {
    if (c == 'W') return 0;
    if (c == 'N') return 1;
    if (c == 'E') return 2;
    return 3;
}

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

    int n;
    while (cin >> n, n) {
        vector<Pii> vp(n);
        rep(i, n) cin >> vp[i].first >> vp[i].second;
        int m;
        cin >> m;
        vector<vector<bool>> visited(21, vector<bool>(21));
        int x = 10, y = 10;
        visited[x][y] = true;
        rep(i, m) {
            char c;
            int l;
            cin >> c >> l;
            int d = chr2int(c);
            while (l--) {
                x += dx[d];
                y += dy[d];
                visited[x][y] = true;
            }
        }

        int cnt = 0;
        rep(i, n) {
            cnt += visited[vp[i].first][vp[i].second];
        }

        cout << (cnt == n ? "Yes" : "No") << endl;


    }
}

Measured memory_bytes: 3152
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<unordered_set>

using namespace std;
using ll = long long;

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    long long N;
    cin >> N;
    // 例外処理
    if(N == 1){
        std::cout << 0 << std::endl;
        return 0;
    }

    const auto &res = prime_factorize(N);
    map<ll, ll> mp;
    for (auto p : res) {
        for (int i = 0; i < p.second; ++i){
            mp[p.first]++;
        }
    }

    vector<ll> val(mp.size()), count(mp.size());
    ll cnt = 0;
    for(auto m : mp){
        val[cnt] = m.first;
        count[cnt] = m.second;
        // std::cout << val[cnt] << " " << count[cnt] << std::endl;
        cnt++;
    }

    // まずは各項残るまで責める
    ll ans = 0;
    for(int i = 0; i < mp.size(); i++){
        for(int j = 1;; j++){
            if(count[i] - j >= 0){
                ans++;
                count[i] -= j;
            }else{
                break;
            }
        }
    }

    // 残りものをかき集める
    /*
    ll tmp = 1;
    ll same = 0;
    for(int i = 0; i < mp.size(); i++){
        if(count[i] != 0){
            tmp *= count[i];
            same++;
        }
    }
    if(same == 0) tmp = 0;
    else tmp -= same;
    */

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main()
{
  char s[20000];
  int high[20000];
  int a[20000];
  int tmp[20000];
  int temp = 0;
  int count = -1;
  scanf("%s", s);
  int i, j, k, tmphigh = 0;
  int A = 0;
  for(i = 0; s[i] != '\0'; i++) {
    switch(s[i]) {
    case '\\':
      tmphigh--;
      high[i] = tmphigh;
      break;
    case '_':
      high[i] = 20000;
      break;
    case '/':
      high[i] = tmphigh;
      for(j = i-1; j >= 0; j--) {
	if(high[j] == tmphigh) {
	  //	  printf("%d\n", i - j);
	  A += i - j;
	  if (j < tmp[count]) {
	    for (k = count-1; k >=  0; k--) {
	      if (j < tmp[k]) {
		a[k] += a[count];
		a[count] = 0;
		count = k;
	      }
	    }
	    a[count] += i - j;
	    tmp[count] = j;
	    //	    printf("count = %d, a = %d\n", count, a[count]);
	  } else {
	    count++;
	    a[count] += i - j;
	    tmp[count] = j;
	    //	    printf("count = %d, a = %d\n", count, a[count]);
	  }
	  break;
	}
      }
      tmphigh++;
      break;
    }
  }
  printf("%d\n", A);
  printf("%d", count+1);
  for(i=0;i<=count;i++){
    printf(" %d", a[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 668
// A - Poor.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if ((A == B || B == C || C == A) && (A != B || B != C || C != A)) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FASTIO cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define ll long long int
#define F first
#define S second
#define pll pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vpii vector<pair<int,int> >
#define vvpii vector<vpii >
#define vpll vector<pair<ll,ll> >
#define vvpll vector<vpll >
#define pb push_back

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

struct compare {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		if ((a.S - a.F) != (b.S - b.F)) return ((a.S - a.F) > (b.S - b.F));
		else return (a.F < b.F);
	}
};
vvi edges;
vi visited, dp;
void dfs(int i) {
	visited[i] = 1;
	for (auto j : edges[i]) {
		if (visited[j] == 0) dfs(j);
		dp[i] = max(dp[i], 1 + dp[j]);
	}
}
int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	FASTIO;
	int n, m; cin >> n >> m;
	edges.resize(n + 1); visited.resize(n + 1); dp.resize(n + 1);
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		edges[u].pb(v);
	}
	for (int i = 1; i <= n; i++) {
		if (visited[i] == 0) dfs(i);
	}
	int ans = dp[0];
	for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
	cout << ans << endl;

}


Measured memory_bytes: 8576
import java.util.Scanner;

public class Main {
	char[][] map;
	int h, w;
	char c;
	
	void run() {
		Scanner scan = new Scanner(System.in);
		while (true) {
			h = scan.nextInt();
			w = scan.nextInt();
			if (w == 0 && h == 0) break;
			map = new char[h][];
			int section = 0;
			scan.nextLine();
			for (int y = 0; y < h; y++) {
				map[y] = new char[w];
				String str = scan.nextLine();
				for (int x = 0; x < w; x++) {
					map[y][x] = str.charAt(x);
				}
			}
			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					if (map[y][x] != 'x') {
						c = map[y][x];
						solve(y, x);
						section++;
					}
				}
			}
			System.out.println(section);
		}
	}
	
	void solve(int y, int x) {
		if (y < 0 || x < 0 || y >= h || x >= w || map[y][x] != c) return;
		map[y][x] = 'x';
		solve(y + 1, x);
		solve(y - 1, x);
		solve(y, x + 1);
		solve(y, x - 1);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 28540
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

ll v = 1000*100;

int main(void) {
	ll n,w; cin >> n >> w ;
	vector<ll> wei(n);
	vector<ll> val(n);
	rep(i,n) cin >> wei[i] >> val[i];
	vector<vector<ll>> dp(n,vector<ll>(v+1,INF));//dpは重さ
	dp[0][val[0]] = wei[0];
	rep2(i,1,n)rep(j,v+1){//jは価値
		dp[i][j] = min(dp[i][j],dp[i-1][j]);
		if(j-val[i]>0) dp[i][j] = min(dp[i][j],dp[i-1][j-val[i]]+wei[i]);
		if(j==val[i]) dp[i][j] = min(dp[i][j],wei[i]);
	}
	ll ans=0;
	for(int j=v; j>=0; j--){
		if(dp[n-1][j]<=w){
			ans = j;
			break;
		}
	}
/* 	rep(i,n){
		rep(j,v+1){
			if(dp[i][j]==INF) cout << "INF " ;
			else cout << dp[i][j] << " " ;
		}
		cout << endl;
	}	 */
	out(ans);
	
}




Measured memory_bytes: 79488
import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long A, long B) {
    return A < 10 && B < 10 ? A * B : -1;
} 


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long A;
    A = input.front.to!long;
    input.popFront;

    long B;
    B = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(A, B);
    else
        solve(A, B).writeln;
}


Measured memory_bytes: 256
n, a = gets.to_i, $stdin.read.split.map(&:to_i)
zero, one = a.count(0), a.count(1)
a.delete(0)
a.delete(1)
a.sort!

if zero.odd?
  if one >= 1
    w = [0] * (zero - 1) + [1, 0] + [1] * (one - 1)
  elsif a.length >= 1
    w = [0] * (zero - 1) + [a.delete_at(0), 0]
  else
    w = [0] * zero
  end
else
  w = [0] * zero + [1] * one
end
b = (a[-2..-1] == [2, 3] ? a[0...-2] + [3, 2] : a) + w

puts b

Measured memory_bytes: 2332
from collections import Counter
s = input()
def num(letter):
	return ord(letter) - 97
def let(number):
	return chr(number + 97)

ok = 0
ng = len(s)
used = [False] * 26
tmp = 0
cnt = 0
for i in range(len(s)):
	if used[num(s[i])] == False:
		used[num(s[i])] = True
		tmp += 1
	if tmp == 26:
		cnt += 1
		tmp = 0
		used = [False] * 26

prm = cnt+1

if prm == 1:
	for j in range(26):
		if used[j] == False:
			print(let(j))
			break
else:
	d = []
	used = [False] * 26
	tmp = 0
	for i in range(len(s)-1, -1, -1):
		if used[num(s[i])] == False:
			used[num(s[i])] = True
			tmp += 1
		if tmp == 26:
			tmp = 0
			used = [False] * 26
			d.append(i)
	d = d[::-1]
	#print(d)
	ans = ""
	cnt = 0
	i = 0
	skip = False
	used = [False] * 26
	for i in range(len(s)):
		if cnt < prm-1:
			if i == d[cnt]:
				for j in range(26):
					if used[j] == False:
						ans += let(j)
						break
				used = [False] * 26
				cnt += 1
				skip = True
				
		if skip:
			if s[i] == ans[-1]:
				#print(i)
				skip = False
			continue

		if used[num(s[i])] == False:
			used[num(s[i])] = True

	#print(used)
	for j in range(26):
		if used[j] == False:
			ans += let(j)
			break
	print(ans)

Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
template<class T> inline T GCD_L(T a,T b){
  T r;
  while(a){
    r=b;
    b=a;
    a=r%a;
  }
  return b;
}
int A;
int B;
int C;
int main(){
  rd(A);
  rd(B);
  rd(C);
  if(C%GCD_L(A, B)==0){
    wt_L("YES");
    wt_L('\n');
  }
  else{
    wt_L("NO");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int A, B, C;
// {
//   rd(A,B,C);
//   wt( if[C%gcd(A,B)==0, "YES", "NO"] );
// }


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

int main() {
  int A, B;
  cin >> A >> B;
  
  int ans = A + B;
  if (ans < A - B) ans = A - B;
  if (ans < A * B) ans = A * B; 
    
  cout << ans << endl;
  
}

Measured memory_bytes: 256
N = int(input())
p_list=[]
for i in range(N):
  p_list.append(int(input()))
  
p_list.sort(reverse=True)
ans=0
for i in range(N):
  if i==0:
    ans+=p_list[i]/2
  else:
    ans+=p_list[i]
    
print(int(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <complex>

using namespace std;

int n, m, ans;

void check(int r)
{
    long long g = 1LL * n * r;
    if (g <= m)
    {
        ans = max(ans, r);
    }
}

int main()
{
    cin >> n >> m;
    for (int j = 1; j * j <= m; j++)
    {
        if (m % j == 0)
        {
            check(j);
            check(m / j);
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
package main

import "fmt"

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

	wSlice := make([]string, n)
	for i := range wSlice {
		fmt.Scan(&wSlice[i])
	}

	for i := range wSlice {
		if i == 0 {
			continue
		}
		if wSlice[i][0] != wSlice[i-1][len(wSlice[i-1])-1] {
			fmt.Println("No")
			return
		}
		for j := 0; j < i; j++ {
			if wSlice[i] == wSlice[j] {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
import numpy as np


N = int(input())
B = np.array(input().split(), np.int32)
A = np.zeros_like(np.arange(N, dtype='int'))

A[0] = B[0]
A[-1] = B[-1]

for i in range(1, N-1):
    A[i] = min([B[i-1], B[i]])

print(sum(A))


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

const int mod = 1000000007;
const int inv2 = 500000004;

int sum[200010];
long long mul[200010];
int a[200010];
long long inv[200010];
int n;

struct BIT {
	long long T[200010];
	BIT() {memset(T, 0, sizeof(T));}
	void modify(int x, long long v) {
		while (x <= n) (T[x] += v) %= mod, x += x & -x;
	}
	long long query(int x) {
		long long res = 0;
		while (x) (res += T[x]) %= mod, x -= x & -x;
		return res;
	}
};

BIT T1, T2, T3, T;
int zero[200010], num[200010];

long long power(long long a, int b) {
	if (!b) return 1;
	long long tmp = power(a, b >> 1);
	return b & 1 ? tmp * tmp % mod * a % mod : tmp * tmp % mod;
}

int get_left(int x) {
	int l = 0, r = x;
	while (l < r) {
		int mid = l + r >> 1;
		if (num[mid] == num[x]) r = mid;
		else l = mid + 1;
	}
	return l;
}

int get_right(int x) {
	int l = x, r = n + 1;
	while (l < r) {
		int mid = l + r >> 1;
		if (num[mid] == num[x]) l = mid + 1;
		else r = mid;
	}
	return l;
}

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		sum[a[i]]++;
	}
	for (int i = n; i >= 1; i--) {
		sum[i] += sum[i + 1];
	}
	long long all = 1;
	mul[0] = 1;
	for (int i = 1; i <= n; i++) {
		mul[i] = sum[i] - (n - i);
		(all *= mul[i]) %= mod;
		if (mul[i] == 0) {
			printf("0\n");
			return 0;
		}
		mul[i] = power(mul[i], mod - 2) * (mul[i] - 1) % mod;
		if (mul[i]) (mul[i] *= mul[i - 1]) %= mod;
		else mul[i] = mul[i - 1], num[i] = 1;
		num[i] += num[i - 1];
		inv[i] = power(mul[i], mod - 2);
	}
	if (num[n] == n) {
		long long ans = 0;
		for (int i = n; i >= 1; i--) {
			ans += T.query(a[i] - 1);
			T.modify(a[i], 1);
		}
		printf("%lld\n", ans % mod);
		return 0;
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		int pos, sum;
		// < a[i]
		pos = get_left(a[i]);
		sum = T1.query(a[i] - 1) - T1.query(pos);
		ans += all * mul[a[i]] % mod * (T3.query(a[i] - 1) - T3.query(pos) + mod) % mod * inv2 % mod;
		// == a[i]
		sum = T1.query(a[i]) - T1.query(a[i] - 1);
		ans += all * inv2 % mod * sum % mod;
		// > a[i]
		pos = get_right(a[i]) - 1;
		sum = T1.query(n) - T1.query(a[i]);
		ans += all * sum % mod - all * inv[a[i]] % mod * (T2.query(pos) - T2.query(a[i]) + mod) % mod * inv2 % mod + mod;
		T1.modify(a[i], 1), T2.modify(a[i], mul[a[i]]), T3.modify(a[i], inv[a[i]]);
		ans %= mod;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 12032
N=int(input())
L=[0 for i in range(N)]
A=[int(input())-1  for _ in range(N)]
n=0
m=1
while L[n]!=1 and A[n]!=1:
  L[n]=1
  m+=1
  n=A[n]
if L[n]==1:
  print(-1)
else:
  print(m)

Measured memory_bytes: 7860
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::HashSet;

fn main() {
    input!{
        h: usize,
        w: usize,
        n: usize,
        v: [(usize1, usize1); n]
    }
    let mut bset = HashSet::new();
    let mut set = HashSet::new();
    for &(a, b) in &v {
        bset.insert((a, b));
        let imin = if a < 2 {
            0
        } else {
            a - 2
        };
        let imax = if a > h - 3 {
            h - 2
        } else {
            a + 1
        };
        let jmin = if b < 2 {
            0
        } else {
            b - 2
        };
        let jmax = if b > w - 3 {
            w - 2
        } else {
            b + 1
        };
        for i in imin..imax {
            for j in jmin..jmax {
                set.insert((i, j));
            }
        }
    }
    let mut ans = vec![0; 10];
    for &(x, y) in set.iter() {
        let mut c = 0;
        for i in x..x + 3 {
            for j in y..y + 3 {
                if bset.contains(&(i, j)) {
                    c += 1;
                }
            }
        }
        ans[c] += 1;
    }
    ans[0] = (h - 2) * (w - 2) - ans.iter().sum::<usize>();
    for i in 0..10 {
        println!("{}", ans[i]);
    }
}


Measured memory_bytes: 47584
import math
N=int(input())
zahyo=[list(map(int,input().split())) for i in range(N)]
ans = []
for i in range(N):
    for j in range(N):
        ans.append(math.sqrt((zahyo[i][0]-zahyo[j][0])**2+(zahyo[i][1]-zahyo[j][1])**2))
print(sum(ans)/(N))

Measured memory_bytes: 3060
n=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
  s=input()
  if s=="AC":
    ac += 1
  elif s == "WA" :
    wa +=1
  elif s == "TLE":
    tle += 1
  else :
    re +=1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<int> A(m), B(m);
  vector<vector<int>> G(n);
  rep(i, m) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    G[A[i]].push_back(B[i]);
  }
  int ans = 0;
  int sub = 0;
  map<ll, int> cnt;
  rep(i, n) {
    if(cnt[i]) {
      ans++;
      cnt.clear();
    }
    for(int ne: G[i]) cnt[ne]++;
  }
  cout << ans << "\n";
  return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  string ans = "No";
  
  if (a == b && a != c) {
    ans = "Yes";
  }
  else if (a == c && a != b) {
    ans = "Yes";
  }
  else if (b == c && b != a) {
    ans = "Yes";
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> l;
	rep(i, h) {
		string rc;
		cin >> rc;
		l.push_back(rc);
	}

	vector<vector<int>> dist(h, vector<int>(w, -1));
	dist[0][0] = 0;
	queue<pair<int,int>> q;
	q.push(pair<int,int>(0, 0));

	auto Add = [&](int y, int x, int d) {
		if (y < 0 || y >= l.size()) return;
		if (x < 0 || x >= l[y].size()) return;
		char m = l[y][x];
		if (m != '.') return;
		if (dist[y][x] == -1) {
			dist[y][x] = d;
		}
		else{
			if (dist[y][x] <= d)
			{
				return;
			}
			else
			{
				dist[y][x] = d;
			}
		}
		q.push(pair<int, int>(y, x));

	};

	while (!q.empty())
	{
		pair<int,int> now = q.front(); q.pop();
		int d = dist[now.first][now.second];
		Add(now.first - 1, now.second, d + 1);
		Add(now.first + 1, now.second, d + 1);
		Add(now.first, now.second - 1, d + 1);
		Add(now.first, now.second + 1, d + 1);
	}
	int count = dist[h - 1][w - 1] + 1;
	int ans = 0;
	rep(i, h) {
		rep(j, w) {
			if (l[i][j] == '.') {
				ans++;
			}
		}
	}
	ans -= count;
	if (count == 0) {
		ans = -1;
	}
	cout << ans << endl;

	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}

Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

using ll = long long;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(b / a, c) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int a,b,h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;    
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<String> set = new HashSet<>();
        char end = '0';
        for(int i = 0; i < n; i++){
            String w = sc.next();
            if(i != 0){
                if(set.contains(w) || end != w.charAt(0)){
                    System.out.println("No");
                    return;
                }
            }
            end = w.charAt(w.length()-1);
            set.add(w);

        }
        System.out.println("Yes");
    }
}


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


void solve(long long N){
    long ok = 1e9;
    long ng = 0;
    while(ok- ng > 1){
        long long mid = (ok+ng)/2;
        if(mid*(mid+1)/2 >= N){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    //cout<<ok<<endl;
    int cnt = 0;
    long sum = ok*(ok+1)/2;
    while(1){
       // cout<<sum<<endl;
        if(ok - cnt < 0)return;
        if(sum - N > ok - cnt){
            sum -= (ok - cnt);
            cnt++;
        }else{
            for(int i = 1;i <= ok-cnt;i++){
                if(sum - N != i)cout<<i<<endl;
            }
            return;
        }
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 384
a = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51".split(",")

k = int(input())						# 5

print(a[k-1])


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

struct T{string n; int p; };

bool operator==(const T& l, const T& r)
{
    return l.p == r.p;
}

bool operator>(const T& l, const T& r)
{
    return l.p < r.p;
}

bool operator<(const T& l, const T& r)
{
    return l.p > r.p;
}


int main()
{
    int n;
    bool fst = true;
    while(cin >> n && n) {
        if(fst) {
            fst = false;
        } else {
            cout << endl;
        }
        T v[n];
        int a, b, c;
        for(int i = 0; i < n; i++) {
            cin >> v[i].n >> a >> b >> c;
            v[i].p = a * 3 + c;
        }
        stable_sort(v, v + n);
        for(int i = 0; i < n; i++) {
            cout << v[i].n << "," << v[i].p << endl;
        }
    }
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
typedef long long ll;
using namespace std;
ll intpow(int n,int m){
    if(m==0)return 1;
    return n*intpow(n,m-1);
}
int main(){
    ll n,m;
    cin >> n >> m;
    ll cost=0;
    int cnt=0;
    map<ll,ll> memo;
    ll a,b;
    for(int i=0;i<n;i++){
        cin >> a >> b;
        if(memo.find(a) != memo.end())memo[a]+=b;
        else memo[a]=b;
    }
    auto itr=memo.begin();
    for(int i=0;i<memo.size();i++){
        if(cnt+itr->second < m){
            cnt += itr->second;
            cost += itr->first*itr->second;
        }
        else{
            cost += itr->first*(m-cnt);
            break;
        }
      itr++;
    }
    cout << cost <<endl;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
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;
}

int main()
{
    cout << fixed << setprecision(15);
    ll a, b, c;
    cin >> a >> b >> c;

    map<ll,ll> M;

    M[a]++;
    M[b]++;
    M[c]++;

    cout << M.size() << endl;
    return 0;
}

Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;

ll X[1000];
ll Z[1000];
ll Y[1000];
pll S[1000];
void _(){
    int a,b;
    cin >> a >>b;
    if(a>8 || b>8)cout <<":(";
    else cout << "Yay!";

}


int main() {
#if __MINGW32__
    freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Input.txt", "r", stdin);
    freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}








Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;

/*sortの仕方
 * ■ string s の場合
 * 昇順: sort(s.begin(), s.end())
 * 降順:  sort(s.rbegin(), s.rend())
 *
 * ■ ll a[N] の場合
 * 昇順: sort(a, a+N)
 * 降順: 不明
 */

/*ll alph2ll(char character) {
    ll x = character - 'a';
    return x;
}
*/

// ll my_gcd(ll a, ll b){
// 	return (b==0) ? a : my_gcd(b, a%b);
// }
//
// ll my_lcm(ll a, ll b){
// 	return a*b / my_gcd(a,b);
// }


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

	int A[N];
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	sort(A, A+N);

    int updown[N], downup[N];
    for(int i=0; i<N; i++){
        if(i%2 == 0){
            updown[i] = -1;
            downup[i] = 1;
            if(i!=0 && i!=N-1){
                updown[i] *= 2;
                downup[i] *= 2;
            }
        } else {
            updown[i] = 1;
            downup[i] = -1;
            if(i!=0 && i!=N-1){
                updown[i] *= 2;
                downup[i] *= 2;
            }
        }
    }

    sort(updown, updown + N);
    sort(downup, downup + N);

    ll tmp1 = 0, tmp2 = 0;
    for(int i=0; i<N; i++){
        tmp1 += (ll)A[i]*(ll)updown[i];
        tmp2 += (ll)A[i]*(ll)downup[i];
    }

    cout << max(tmp1, tmp2) << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

int main(){

  int n,q,i,j,k,C=0,m,r,l;
  int S[100000];
  int T[50000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }


    for(i=0;i<q;i++){
      r=n;
      l=0;
      while(l<r){
	m=(r+l)/2;
	if(S[m]>T[i]){ 
	  r=m;
	  continue;
	}
	  else if(S[m]<T[i]){
	    l=m+1;
	    continue;
	  }
	  else {
	  C++;
	  break;
	}
	
    }
    }
  printf("%d\n",C);
  return 0;
}



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

int dp[302][302];

int main(){
    int n;
    while(cin >> n, n != 0){
        vector<int> v;
        for(int i=0;i<n;++i){
            int w;
            cin >> w;
            v.push_back(w);
        }

        for(int i=0;i<=300;++i)
            for(int j=0;j<=300;++j)
                dp[i][j] = 0;

        for(int i=0;i<n-1;++i){
            if(abs(v[i]-v[i+1]) <= 1)
                dp[i][i+1] = 2;
        }

        for(int k=2;k<n;++k){
            for(int i=0;i<n;++i){
                if(i+k >= n)break;
                for(int j=0;j<k;++j)
                    dp[i][i+k] = max(dp[i][i+k], dp[i][i+j] + dp[i+j+1][i+k]);
                if(dp[i+1][i+k-1] == k-1 && abs(v[i]-v[i+k]) <= 1)
                    dp[i][i+k] = k + 1;
                dp[i][i+k] = max(dp[i][i+k], dp[i+1][i+k-1]);
            }
        }

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

    return 0;
}



Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  ll a,b;
  cin>>a>>b;
  ll f=0;
  for(ll i=0;i<=1000;i++)
  {
    for(ll j=0;j<=1000;j++)
    {
      ll p=(2*i)+(4*j);
      ll q=i+j;
      if(p==b&&q==a)
      {
        f=1;
        break;
      }
    }
    if(f)
      break;
  }
  if(f)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 3648
N_M = list(map(int,input().split()))
N = N_M[0]
M = N_M[1]
ans = 0

list_sum = [0] * M

for i in range(N):
    tmp = list(map(int,input().split()))
    for j in tmp[1:]:
        list_sum[j - 1] +=1
        
for i in list_sum:
    if i == N:
        ans +=1
        
print(ans)
        

Measured memory_bytes: 3060
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<iomanip>
#include<string>
using namespace std;

int gcd(long long int m,long long int n){
	while(m!=n){
		if(m>n){m=m-n;
		}
		else n=n-m;
	}
	return m;
}
int lmc(long long int m,long long int n){
return m*n/gcd(m,n);
}

int main(){
long long int a,b;
while(cin>>a>>b){
	cout<<gcd(a,b)<<" "<<lmc(a,b)<<endl;

}


}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{
	vector <int> v;
	int n,maxi=0,m=0;          
	cin>>n;
    int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=0;i<n;i++)
	{
		if(a[i]>=a[i+1])
		m=a[i];
		
		if(m>=a[i] && a[i]>=a[i+1])		
		++maxi;
		else
		{
		v.push_back(maxi); 
		maxi=0; 
	}
	if(i==n-1)
	v.push_back(--maxi);
	}
   cout<<*max_element(v.begin(),v.end());
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll n, m, d;
  cin >> n >> m >> d;
  double ans = 2;
  ans *= (double)(n-d)/n;
  ans *= (double)(m-1)/n;
  if(d == 0) ans /= 2;
  printf("%0.12f\n", ans);
}


Measured memory_bytes: 3740
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
using namespace std;

int main()
{
  vector<int> in(3);
  map<int,int> mp;

  int N, L;

  cin >> N;
  cin >> L;

  vector<string> S;
  S.resize(N);
  for(auto &s: S)
    cin >> s;

  sort(S.begin(), S.end());

  for(auto s: S)
    cout << s;
  cout << endl;

  return 0;
}


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

using namespace std;

int main(){
  int n;
  cin>>n;
  char s[200],t[200];
  for(int i=0;i<n;i++){
     cin>>s[i];
  }
  for(int i=0;i<n;i++){
     cin>>t[i];
  }
  int p=2*n;
  string st[p];
  for(int i=0;i<n;i++){
     cout<<s[i];
     cout<<t[i];
  }
  
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//char型から数値型に変換する関数（z.at(i)などに使用）
int ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
//1～10000の階乗（を1000000007で割ったあまり）を求める関数
int fact(int64_t x){
  int64_t y=1;
  for(int64_t i=1;i<=x;i++){
   y*=i;
   y%=1000000007;
  }
  return y;
}
//入力した２つの値の最小公倍数を求める関数
int64_t lcm(int64_t x,int64_t y){
   int64_t z=x*y;
  if(x<y){
    int64_t ex=x;
    x=y;
    y=ex;
  }
  int64_t r=x%y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }
  return z/y;
}
//入力した２つの値の最大公約数を求める関数は__gcd(x,y);
int main() {
int64_t n;
cin>>n;
vector<int64_t> s(n);
  int64_t ans=0;
for(int i=0;i<n;i++){
cin>>s.at(i);
  ans+=s.at(i);
}
sort(s.begin(),s.end());
  if(ans%10!=0){
    cout<<ans;
    return 0;
  }
  else{
    for(int i=0;i<n;i++){
      if(s.at(i)%10!=0){
        cout<<ans-s.at(i);
        return 0;
      }
    }
    cout<<0;
  }
}

Measured memory_bytes: 256