akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

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

bool isPrime(ll n){
  if(n<=1) return false;
  for(ll i=2; i*i<=n; i++){
    if(n%i==0) return false;
  }
  return true;
}

int main()
{
  ll a,b;
  int res=1;
  cin >> a >> b;

  ll n = gcd(a,b);
  vector<ll> v;
  for(ll i=1; i*i<=n; i++){
    if(n%i) continue;
    v.push_back(i);
    if(n/i == i) continue;
    v.push_back(n/i);
  }
  for(auto it:v){
    if(isPrime(it)) res++;
  }
  cout << res << endl;
}


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

int main()
{
	string s;
	char c;
	int q;
	int t, f;
	int cnt = 0;
	
	cin >> s;
	cin >> q;
	
	for(int i = 1; i <= q; i++)
	{
		cin >> t;
		if(t == 1)
		{
			cnt++;
		}
		if(t == 2)
		{
			cin >> f >> c;
			if(!(cnt % 2))
			{
				if(f == 1)
					s.insert(s.begin(), c);
				if(f == 2)
					s.push_back(c);
			}
			else
			{
				if(f == 1)
					s.push_back(c);
				if(f == 2)
					s.insert(s.begin(), c);
			}
		}
	}
	if(cnt % 2)
		reverse(s.begin(), s.end());
	cout << s << endl;
	
	return 0;
}

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

void Call(int N) {
	int i = 1;
	while (i <= N) {
		int x = i;
		if (i % 3 == 0) {
			cout << " " << i;
			 
		}
		else {
			do {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
			} while (2 < x);
		}
		i++;
	}
	cout << endl; 
}

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



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

public static class Program
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var inputs = Console.ReadLine().Trim().Split(' ').Select(s => int.Parse(s)).ToArray();
        var result = string.Join(" ", inputs.Select((value, index) => new Tuple<int, int>(value, index + 1)).OrderBy(p => p.Item1).Select(p => p.Item2));
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 32476
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>

//#define "limits.h"
using namespace std;




int main()
{
	int n, m;
	char s[200][20], t[200][20];
	int i, j=0, k=0,x=0,l,c=0;
	cin >> n;
	for (i = 1;i <= n;i++) {
		cin >> s[i];
	}
	cin >> m;
	for (i = 1;i <= m;i++) {
		cin >> t[i];
	}
	for (i = 1;i <= n;i++) {
		l = strlen(s[i]);
		for (j = 1;j <= n;j++) {
			if (strcmp(s[i], s[j]) == 0) { k++; }
		}
		for (j = 1;j <= m;j++) {
			if (strcmp(s[i], t[j]) == 0) { k--; }
		}
		x =(int) fmax(x, k);
		k = 0;
	}


	printf("%d\n", x);



	return 0;
}



Measured memory_bytes: 256
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

def re(n):
  if n < 2:
    return 1
  return n*re(n-1)

def c(n,r):
  return re(n)//re(n-r)//2

a,b = miinps()

ans = 0

ans += c(a,2)
ans += c(b,2)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,sum=0,i;
    cin>>n>>m;
    int a[m];
    for(i=0; i<m; i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>n)
    {
        cout<<-1;
    }
    else
    {
        cout<<n-sum;
    }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
int64_t MOD=1000000007;


int main() {

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


Measured memory_bytes: 3588
/*
        Choo Lo jo mujhe tum kabhi, kho na jaoon main raat din
    Nazaron mein tum ho basey
        Keh do jo tum ek baar, Mere ho bas tum mere
    Nazaron mein tum ho basey
*/
 
#include<bits/stdc++.h>
#include<cstdio>
 
#define deb(x) cout << #x << " -> " << x << el
#define db double
#define ll long long int
#define ull unsigned long long int
#define umap unordered_map
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define sclu(x) scanf("%llu", &x)
#define scd(x) scanf("%lf", &x)
#define pass cout<<"pass\n"
#define vi vector<int>
#define pb push_back
#define vec vector
#define el "\n"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define umap unordered_map
#define f(i,x,y) for(int i=x;i<y;++i)
#define ff(i,x,y) for(int i=x;i<=y;++i)
#define mem(x) memset(x, 0, sizeof(x))
#define mems(x,y) memset(x, y, sizeof(x))
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ppi pair<int, pii>
#define mat vector<vector<ll> > 
#define mod 1000000007
#define MAX 100005
 
using namespace std;

const int INF = 1e9 + 5;

void solve() {
	int n;
	sc(n);

	vec<int> dp(3, 0);

	for(int day = 0; day < n; ++day) {

		vi points(3);
		vi newDp(3, -INF);

		for(int p = 0; p < 3; ++p) {
			sc(points[p]);
		}

		for(int i = 0; i < 3; ++i) {
			for(int j = 0; j < 3; ++j) {
				if(i == j) continue;
				newDp[i] = max(dp[j] + points[i], newDp[i]);
			}
		}
		dp = newDp;
	}
	cout << max({dp[0], dp[1], dp[2]}) << el;
}

// 2
// 10 40 70
// 20 50 80


int main() {
    int ccc = 1;
    // sc(ccc);
    while(ccc--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   
 
 
int main(){
  ll i,j,k;
  ll result = -INF;
  ll buf = 0;
  ll buf2 = 0;
  ll buf3 = 0;
  bool judge = true;
  ll n; cin >> n;
  ll f[n][10];
  for(i=0;i<n;i++){
    for(j=0;j<10;j++){
      cin>>f[i][j];
    }
  }
  ll p[n][11];
  for(i=0;i<n;i++){
    for(j=0;j<=10;j++){
      cin>>p[i][j];
    }
  }
  vector<ll> a(10);
  for(i=1;i<(1<<10);i++){
    k=i;
    for(j=0;j<10;k/=2,j++)
      a[j]=k%2;  
    buf=0;
    for(j=0;j<n;j++){
      buf2=0;
      for(k=0;k<10;k++){
        if(a[k]==1&&f[j][k]==1){
          buf2++;
        }
      }
      buf+=p[j][buf2];
    }
    chmax(result,buf);
  }
  cout<<result<<endl;
    
      
  return 0;
}

Measured memory_bytes: 256
function Main(input){
    var xs = input.split('\n');
    //console.log(xs);
    var nums = xs[0].split(' ').map(v => parseInt(v, 10));
    //console.log(nums);
    var K = nums[1];
    var S = xs[1];
    var a = S.slice(0, K -1 );
    var b = S[K -1].toLowerCase(); 
    var c = S.slice(K);
    console.log(a+b+c);
  
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 7372
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<queue>
#include<set>
#include<string>
#include <vector>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

using namespace std;


int main(){
	int N, ans = 0;
	char S[300][300], C[300][300];

	scanf("%d", &N);
	REP(i, N){
		scanf("%s", S[i]);
	}

	REP(i, N){
		int t = 1;
		REP(j, N){
			REP(k, N){
				C[j][k] = S[j][(k + i) % N];
			}
		}
		REP(j, N){
			REP(k, N){
				if (C[j][k] != C[k][j]){
					t = 0;
				}
			}
		}
		ans += t*N;
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 512
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: i64
    }

    let ans = 180*(n-2);

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXH 1001
#define MAXW 1001
queue<pair<ll, ll> > q1;
queue<pair<ll, ll> > q2;
bool wall[MAXH][MAXW];
int main() {
    int count[MAXH][MAXW];
    int h, w, ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            
            count[i][j] = 1000000;
        }
    }
    for (int i = 1; i <= h; i++) {
        string s;
        cin >> s;
        for (int j = 1; j <= w; j++) {
            if (s[j - 1] == '#') {
                wall[i][j] = true;
            }
            else {
                wall[i][j] = false;
            }
        }
    }
    bool ok = false;
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    q1.push(make_pair(ch, cw));
    count[ch][cw] = 0;
    while (q1.size() || q2.size()) {
        pair<ll, ll> p;
        if (q1.size()) {
            p = q1.front();
            if ((p.first == dh) && (p.second == dw)) {
                ok = true;
            }
            q1.pop();
        }
        else {
            p = q2.front();
            if ((p.first == dh) && (p.second == dw)) {
                ok = true;
            }
            q2.pop();
        }
        for (int i = 0; i < 4; i++) {
            int nextx = p.first + dx[i];
            int nexty = p.second + dy[i];
            if ((1 <= nextx) && (nextx <= h) && (1 <= nexty) && (nexty <= w) && (!wall[nextx][nexty])) {
                if (count[nextx][nexty] > count[p.first][p.second]) {
                    count[nextx][nexty] = count[p.first][p.second];
                    q1.push(make_pair(nextx, nexty));
                }
            }

        }
        for (int x = -2; x <= 2; x++) {
            for (int y = -2; y <= 2; y++) {
                if (!(((x == 1) && (y == 0)) || ((x == 0) && (y == 1)) || ((x == -1) && (y == 0)) ||((x == 0) && (y == -1)) || ((x == 0)&&(y == 0)))) {
                    int nextx = p.first + x;
                    int nexty = p.second + y;
                    if ((1 <= nextx) && (nextx <= h) && (1 <= nexty) && (nexty <= w) && (!wall[nextx][nexty])) {
                        if (count[nextx][nexty] > count[p.first][p.second] + 1) {
                            count[nextx][nexty] = count[p.first][p.second] + 1;
                            q2.push(make_pair(nextx, nexty));
                        }
                    }
                }
            }
        }
    }
    if (ok) {
        cout << count[dh][dw] << endl;
    }
    else {
        cout << -1 << endl;
    }
    return 0;
}

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

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			cout << v[i][j] << "   ";
		}
		cout << endl;
	}
}


int main(){//
    int N, Q;
    cin >> N >> Q;
    //vec[i][j]: 頂点iと結ばれている頂点の数列
    vector<vector<int>> vec(N, vector<int>());
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }

    //score[i]: 頂点iの点数
    vector<ll> score(N, 0);//とりあえず指定された頂点piのみにxiを足す．
    for(int i=0; i<Q; i++){
        int p, x;
        cin >> p >> x;
        p--;
        score[p] += x;
    }

    // cout << " vec: " << endl; print_vec2(vec);
    // cout << " score: " ; print_vec(score);

    //頂点iのカウンター値は iの親ノードのカウンター値と iのscoreの和
    vector<ll> ans(N, 0);//ans[i]: 頂点iのカウンター値
    // DFSする   ( BFSの解法は下にあるよ)
    //stack.first: 注目ノード,  second: 注目ノードの親
    stack<P> st;
    st.push(P(0, -1));
    while(st.size() != 0){
        int child = st.top().first;
        int parent = st.top().second;
        ans[child] += score[child];
        st.pop();

        for(int j=0; j<vec[child].size(); j++){
            int next_c = vec[child][j];
            if(next_c == parent) continue;
            ans[next_c] += ans[child];
            st.push(P(next_c, child));
        }
    }

    
    
    // //BFSする   ACしました!
    // //q.fist: 注目ノード, q.second: 注目ノードの親
    // queue<P> q;
    // q.push(P(0, -1));
    // while(q.size() != 0){
    //     int child = q.front().first;
    //     int parent = q.front().second;
    //     ans[child] += score[child];
    //     q.pop();
    //     for(int j=0; j<vec[child].size(); j++){
    //         int next_c = vec[child][j];
    //         // cout << " cihld: " << child << "  parent: " << parent << "  next_c: " << next_c << endl;
            
    //         if(next_c == parent) continue;
    //         ans[next_c] += ans[child];
    //         q.push(P(next_c, child));

    //     }
    // }

    for(int i=0; i<N; i++){
        cout << ans[i] << endl;
    }
    
}

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

int main(){
  string S;
  cin >> S;
  
  int N = (int)S.size();
  
  int count_a = 0;
  int count_b = 0;
  
  //0文字目が0 == 偶数マスがゼロになるようにする場合count_a
  rep(i,N){
    if(i % 2 == 0){
      if(S.at(i) == '0')count_a++;
    }
    else{
      if(S.at(i) == '1')count_a++;
    }
  }
  
  //奇数マスがゼロ
  rep(i,N){
    if(i % 2 == 1){
      if(S.at(i) == '0')count_b++;
    }
    else{
      if(S.at(i) == '1')count_b++;
    }
  }
  
  cout << min(count_a,count_b) << endl;
  return 0;
  
  
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  int A,B,K;
  cin>>A>>B>>K;
  int cnt=0;
  vector<int>a;
  for(int i=1;i<=A;i++){
    if(A%i==0&&B%i==0){a.push_back(i);}
    }
  reverse(a.begin(),a.end());
  cout<<a[K-1]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)


int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> vec(n);
    rep(i,n){
        cin >> vec.at(i);
    }


    vector<ll> dp(n,INF);

    rep(i,n){
        if(i==0){
            dp.at(i) = 0;
            continue;
        }
        for(ll j = i - k; j < i; j++){
            if(j < 0) continue;
            chmin(dp.at(i), dp.at(j) + abs(vec.at(i) - vec.at(j)));
        }
    }

    cout << dp.at(n-1) << endl;
    
}


Measured memory_bytes: 1792
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto L = RD;
	auto x = cast(double)L / 3.0;

	writefln(FMT_F, x^^3);
	stdout.flush;
	debug readln;
}

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

int main(){
    ll w,h,k;
    cin>>w>>h>>k;
    ll width = w;
    ll length = h;

    ll l=0;
    ll m=w;
    ll n=0;
    ll o=h;

    ll x,y,a;
    for(ll i=0;i<k;++i){
        cin>>x>>y>>a;

        if(a==1){
            if(l==0){
                width -= x;
                l=x;
            }else if(x>l){
                width -= x-l;
                l=x;
            }
        }else if(a==2){
            if(m==w){
                width -= w-x; 
                m=x;
            }else if(x<m){
                width -= m-x;
                m=x;
            }
        }else if(a==3){
            if(n==0){
                length -= y;
                n=y;
            }else if(y>n){
                length -= y-n;
                n=y;
            }
        }else if(a==4){
            if(o==h){
                length -= h-y;
                o=y;
            }else if(y<o){
                length -= o-y;
                o=y;
            }
        }
    }

    ll sum=width*length;
    if(width<0 or length<0){
        cout<<0<<endl;
        return 0;
    }else{
        cout<<sum<<endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 256
// Volume 0 0032 Plastic Board
// 答えを見た（,の扱いがわからなかったので、、）
#include <stdio.h>
using namespace std;

int main() {
    int a, b, c = 0;
    int l = 0;
    int r = 0;

    while (scanf("%d,%d,%d", &a, &b, &c) != EOF) {
        //printf("a:%d, b:%d, c:%d, r:%d, l:%d\n", a, b, c, r, l);
        if (a*a + b*b == c*c) {
            r++;
        } else {
            if (a == b)
                l++;
        }
    }   
    printf("%d\n%d\n", r, l); 
    return 0;
}


Measured memory_bytes: 2608
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n;
lint x[15], y[15], p[15], cost_x[15][1<<15], cost_y[15][1<<15];
lint ans[16];

void rec(int cur, int S, int T){
    if(cur == n){
        lint tmp = 0;
        rep(i, n) tmp += min(cost_x[i][S], cost_y[i][T]);
        chmin(ans[__builtin_popcount(S) + __builtin_popcount(T)], tmp);
        return;
    }
    rec(cur+1, S, T);
    rec(cur+1, S|(1<<cur), T);
    rec(cur+1, S, T|(1<<cur));
}

int main(){
    scanf("%d", &n);
    rep(i, n) scanf("%lld%lld%lld", &x[i], &y[i], &p[i]);
    rep(S, 1<<n){
        rep(i, n){
            lint tmp_x = abs(x[i]) * p[i], tmp_y = abs(y[i]) * p[i];
            rep(j, n)if(S>>j & 1){
                chmin(tmp_x, abs(x[j] - x[i]) * p[i]);
                chmin(tmp_y, abs(y[j] - y[i]) * p[i]);
            }
            cost_x[i][S] = tmp_x;
            cost_y[i][S] = tmp_y;
        }
    }
    fill(ans, ans+n+1, INF);
    rec(0, 0, 0);
    rep(i, n+1) printf("%lld\n", ans[i]);
}

Measured memory_bytes: 11428
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int  n;
long long sum = 0;
long long ans1 = 0;
long long ans2 = 0;
int i, j;
int t = 1;

int main() {

	cin >> n ;

	int a[100010];

	for (i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];

		if (sum*t <= 0) {
			ans1 += abs(sum-t);
			sum = t;
		}
		t *= -1;
	}

	t = -1;
	sum = 0;

	for (i = 0; i < n; i++) {
		sum += a[i];
		if (sum*t <= 0) {
			ans2 += abs(sum - t);
			sum = t;
		}

		t *= -1;
	}
	printf("%lld\n", min(ans1, ans2));
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	long A, B;
	int keta = 0;
	long[] aCount, bCount;

	Main() {
		Scanner in = new Scanner(System.in);
		A = in.nextLong();
		B = in.nextLong();
		in.close();
		keta = Math.max(Long.toBinaryString(A).length(), Long.toBinaryString(B).length());

	}

	long[] oneCount(long val) {
		long[] result = new long[keta];
		Arrays.fill(result, 0L);
		long v = val + 1;
		long div = 2;
		long base = 1;
		for (int i = 0; i < keta; ++i) {
			long shou = Math.floorDiv(v, div);
			long mod = v % div;
			result[i] += shou * base;
			if (mod == 0) {
				// result[i] = 0;
			} else if (Math.floorDiv(div, 2) >= mod) {
				// result[i] = 0;
			} else {
				result[i] = div - mod;
			}
			div *= 2;
			base *= 2;
		}
		return result;
	}

	void calc() {
		aCount = oneCount(A - 1);
		bCount = oneCount(B);
		long result = 0;
		long base = 1;
		for (int i = 0; i < aCount.length; ++i) {
			// System.out.println(aCount[i] + ", " + bCount[i]);
			if ((aCount[i] + bCount[i]) % 2 == 1) {
				result += base;
			}
			base *= 2;
		}
		System.out.println(result);
	}

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

}

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

#define int long long
#define uint unsigned int
#define pii pair<int, int>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin()), ((c).end())

#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))

#define PW(n) (1LL << (n))

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNI(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int N;
int a[300010];
int L[300010], R[300010];

void calc(int* a, int* x) {
  priority_queue<int, vector<int>, greater<int>> que;
  x[0] = 0;
  REP(i, 3*N) {
    x[i+1] = x[i] + a[i];
    que.push(a[i]);
    if (que.size() > N) {
      x[i+1] -= que.top();
      que.pop();
    }
  }
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  REP(i, 3*N) cin >> a[i];
  calc(a, L);
  reverse(a, a+3*N);
  REP(i, 3*N) a[i] *= -1;
  calc(a, R);
  int ans = -INF;
  FOR(i, N, 2*N+1) CHMAX(ans, L[i]+R[3*N-i]);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9076
#include <stdio.h>
#include <string.h>

int stricmp(char* ch1,char* ch2){
    int ch1_length = 0,ch2_length = 0,div;
    for(int i = 0; ch1[i] != '\0';i++) ch1_length++;
    for(int i = 0; ch2[i] != '\0';i++) ch2_length++;
    if(ch1_length != ch2_length) return -1;
    for(int i = 0; ch1[i] != '\0';i++)
    {
        div = ch1[i] -ch2[i];
        if(div != 0 && div != 32 && div != -32)
            return -1;
    }
    return 0;
}

int main(int argc, const char * argv[]){
    char W[11],T[1001];
    int count = 0;
    scanf("%s", W);
    while(true){
        scanf("%s", T);
        if(strcmp("END_OF_TEXT",T) == 0) break;
        if(stricmp(T, W) == 0) count++;
    }
    printf("%d\n",count);
}



Measured memory_bytes: 2684
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(void){
    double a, b, c, d, e, f, x, y;
    while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
        x = (b*f - c*e)/(b*d - a*e);
        y = (a*f - c*d)/(a*e - b*d);
        if(x == -0) x=0;
        if(y == -0) y=0;
        cout << fixed << setprecision(3) << x << " " << y << endl;
    }
    return 0;
}
    



Measured memory_bytes: 3320
-- import Data.List
import Control.Monad
import Text.Printf

type Order = (Int,Int,Int,Int) -- [b,f,r,v]

main = do
  n <- readLn
  ss <- replicateM n getLine
  let orders = map (toOrder . (map read)) $ map words ss
  printRooms 1 1 1 orders 

newline :: IO ()
newline = putStrLn ""

isThisroom :: (Int,Int,Int) -> Order -> Bool
isThisroom (b',f',r') (b,f,r,_) = b' == b && f' == f && r' == r

printRooms :: Int -> Int -> Int -> [Order]-> IO ()
printRooms b f r orders = do
  let v = sum . map getPopulation . filter (\o -> isThisroom (b,f,r) o) $ orders
  printf " %d" v
  case (b,f,r) of
    (4,3,10) -> do {newline; return ()}
    (_,3,10) -> do {newline; putStrLn line;
                    printRooms (b + 1) 1 1 orders }
    (_,_,10) -> do {newline;
                    printRooms b (f + 1) 1 orders}
    _        ->     printRooms b f (r + 1) orders
    where line = "####################"
          
toOrder :: [Int] -> Order
toOrder [b,f,r,v] = (b,f,r,v)

getPopulation :: Order -> Int
getPopulation (_,_,_,v) = v

Measured memory_bytes: 4264
#include <cstdio>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 1000000000;
const int K_MAX = 10;

int n, k;

int tbl[11][5];
int hist[11];

void solve() {
  REP(i, 11) REP(j, 5) {
    int mod = ((i + 1) * 7 + j + 2) * 9 % 11;
    tbl[i][j] = mod;
    hist[mod]++;
  }

  // DUMP2D(tbl, 11, 5);
  // DUMP(hist, 11);

  int q = (n - 2) / 11;
  int r = (n - 2) % 11;
  int ans = hist[k] * q;
  REP(i, r) REP(j, 5) {
    if (tbl[i][j] == k) ans++;
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d%d", &n, &k);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 128
// JAI SHREE RAM
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for(int i=0;i<n;i++)
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define sec second
#define fir first
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI           3.14159265358979323846  /* pi */
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	double a, b, c, d;
	cin >> a >> b >> c >> d;
	

	while(1)
	{
		c=c-b;
		if(c<=0)
		{
			cout<<"Yes";
			break;
		}
		a=a-d;
		if(a<=0)
		{
			cout<<"No";
			break;
		}
	}


	}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    string ans="No";
    cin >> n>>m;
    bool a[n+1][n+1],b[m+1][m+1];
    for(int i=0;i<n;i++){
        string str;
        cin >> str;
        // cerr << str<< endl;
        for(int j =0;j<n;j++){
            if(str[j]=='#'){
                a[i][j] = true;
            }
            else{
                a[i][j] = false;
            }
        }
    }
    for(int i=0;i<m;i++){
        string str;
        cin >> str;
        for(int j =0;j<m;j++){
            if(str[j]=='#'){
                b[i][j] = true;
            }
            else{
                b[i][j] = false;
            }
        }
    }
    bool flag = true;
    bool finish = false;
    //i,jは左上の座標
    for(int i =0;i<n-m+1;i++){
        for(int j =0;j<n-m+1;j++){
            flag = true;
            for(int k=0;k<m;k++){
                for(int l =0;l<m;l++){
                    if(a[i+k][j+l]!=b[k][l]){
                        flag = false;
                        break;
                    }
                    if(k == m-1 && l== m-1){
                        finish = true;
                        ans = "Yes";
                    }
                }
                if(!flag){
                    break;
                }
                if(finish){
                    break;
                }
            }
            if(finish){
                break;
            }
        }
        if(finish){
            break;
        }
    }
    cout << ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int m,n,a[109],tot;

int main()
{
	cin >> n >> m;
	for(int i = 0;i<n;i++)cin >> a[i],tot += a[i];
	sort(a,a+n);
	if(a[n-m]<ceil((long double)tot/m/4))cout << "No";
	else cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll x, y;
  cin >> x >> y;

  ll cnt = 0;
  if (y == 0) {
    if (x <= 0)
      cnt = y - x;
    else {
      cnt++;
      x *= -1;
      cnt += y - x;
    }
  } else if (y > 0) {
    if (x <= -y) {
      cnt += -y - x;
      cnt++;
    } else if (x < 0) {
      cnt++;
      x *= -1;
      cnt += y - x;
    } else if (x <= y) {
      cnt += y - x;
    } else {
      cnt++;
      x *= -1;
      cnt += -y - x;
      cnt++;
    }
  } else {
    if (x <= y) {
      cnt += y - x;
    } else if (x < 0) {
      x *= -1;
      cnt++;
      cnt += -y - x;
      cnt++;
    } else if (x <= -y) {
      cnt += -y - x;
      cnt++;
    } else {  // -y < x
      cnt++;
      x *= -1;
      cnt += y - x;
    }
  }

  cout << cnt << endl;

  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    ll ans = 1;
    ll a[n];
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(j, n)
    {
        if (a[j] > 1000000000000000000 / ans)
        {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[j];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4392
#include <iostream>
#include <vector>
#include <algorithm>

struct greater
{
	template<class T>
	bool operator()(T const& a, T const& b) const { return a > b; }
};

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

	std::vector<int> data;
	for (int i = 0; i < n; i++)
	{
		int a = 0;
		std::cin >> a;
		data.push_back(a);
	}

	//ソート用に配列コピー
	std::vector<int> sorted;
	for (int i = 0; i < data.size(); i++)
		sorted.push_back(data.at(i));

	//降順にソート
	std::sort(sorted.begin(), sorted.end(), greater());

	for (int i = 0; i < n; i++)
	{
		if (data.at(i) == sorted.at(0))
			std::cout << sorted.at(1) << std::endl;
		else
			std::cout << sorted.at(0) << std::endl;;
	}

	return 0;
}


Measured memory_bytes: 3316
n=int(input())
A=tuple(map(int, input().split()))
cnt=0

def merge_sort(A,cnt):
    m=len(A)
    if m == 1:
        return A,cnt
    else:
        mid=(m+1)//2
        A1=tuple(A[:mid])
        A2=tuple(A[mid:])
        A1,cnt=merge_sort(A1,cnt)
        A2,cnt=merge_sort(A2,cnt)
        n1=len(A1)
        n2=len(A2)
        i1=0
        i2=0
        ans=[0]*(n1+n2)
        j=0
        while j < n1+n2:
            if i1 == n1:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            elif i2 == n2:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            elif A1[i1] < A2[i2]:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            else:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            j += 1
        return ans,cnt

sorted_A,cnt=merge_sort(A,0)
print(*sorted_A)
print(cnt)

            

        


Measured memory_bytes: 63444
n, x = map(int, raw_input().split())
A = map(int, raw_input().split())
ans = 0
if x < A[0]:
    ans += A[0] - x
    A[0] = x
if x < A[-1]:
    ans += A[-1] - x
    A[-1] = x
for i in xrange(1, n):
    if x - A[i-1] < A[i]:
        ans += A[i] - (x - A[i-1])
        A[i] = x - A[i-1]
print ans

Measured memory_bytes: 11340
s=input().split()
dict={}
max=""
max_num=0
max_index=""
for i in s:
    if i in dict:
        dict[i]+=1
        if max_num<dict[i]:
            max_index=i
            max_num=dict[i]
    else: dict[i]=0
    if len(i)>len(max):
        max=i
print(max_index,max)

Measured memory_bytes: 7300
x = int(input())

if x == 2:
    print(2)
    quit()
li = [2]
for i in range(3, 10**6, 2):
    for j in li:
        if i % j == 0:
            break
    else:
        if i >= x:
            print(i)
            quit()
        li.append(i)

Measured memory_bytes: 40428
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct UnionFind {
    UnionFind(int n) : p(n, -1) {}
    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }
    int size(int u) {
        return -p[root(u)];
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v];
        p[v] = u;
    }
    vector<int> p;
};

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

    int n, m;
    cin >> n >> m;

    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;

        uf.unite(x, y);
    }

    int r = 0;
    for (int i = 0; i < n; i++) {
        r += uf.p[i] < 0;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 640
// Problem : D - Chat in a Circle
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
using namespace std;
#define int         long long int
#define vi           vector<int>
#define pii          pair<int,int>
#define vpp          vector<pii>
#define mii          map<int,int>
#define pb           push_back
#define rep(i,a,bb)  for(int i=a;i<bb;i++)
#define ff           first
#define ss           second
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test         int T;cin>>T;while(T--)
#define __sort(v)    sort(v.begin(),v.end())
#define __rsort(v)   sort(v.rbegin(),v.rend())
#define setbits(x)   __builtin_popcount(x)
#define zrobits(x)   __builtin_ctzint(x)
#define endl '\n'
#define debug(x)  cerr<<"[ "<<#x<<" : "<<x<<" ]"<<endl
#define debugp(x) cerr<<"[ "<<#x<<".ff : "<<x.first<<", "<<#x<<".ss : "<<x.second<<" ]"<<endl
#define debugs(x) cerr<<"[ "; for(auto i:x) cerr<<i<<" "; cerr<<" ]"<<endl;
#define debugm(x) cerr<<"----------"<<endl; for(auto i:x) cerr<<i.ff<<":"<<i.ss<<endl; cerr<<"----------"; 
#define PI 3.14159265359
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int dxk[]={0,0,1,-1,1,1,-1,-1};
int dyk[]={1,-1,0,0,1,-1,1,-1};
const int inf = 1e+18;
const int mod = 1e+9 + 7;

void solve()
{
	int n;
	cin>>n;
	int a[n];
	rep(i,0,n)
	 cin>>a[i];
	sort(a, a+n);
	int ans = a[n-1];
	int curr = n-2;
	for(int i=n-2; i>0&&curr; i--)
	  {
	  	if(curr-2>=0){
	  		ans+=2*a[i];
	  		curr-=2;
	  	}
	  	else
	  	{
	  		ans+=a[i];
	  		curr--;
	  	}
	  }
	cout<<ans<<endl;
}

int32_t main()
{
  fast;
  //test
  solve();
  return 0;
}


Measured memory_bytes: 5172
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

const int maxn = 2e5 + 5;
int a[maxn];

int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int n = read();
    bool ok = false;
    rep(i, 1, n) {
        sf(a[i]);
        if (a[i] == 1) ok = true;
    }
    if (!ok) {
        puts("-1");
        return 0;
    }
    int t = 1;
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] == t) {
            ++t;
        }else {
            ++cnt;
        }
    }
    out(cnt);
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc169
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
            solve_abc169A();
            Console.Out.Flush();
        }

        public static void solve_abc169B()
        {
        }

        public static void solve_abc169A()
        {
            int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Console.WriteLine(ab[0] * ab[1]);
        }

        /*
            int[] test = new int[7]  {3, 5, 7, 9, 10, 11, 13};
            int[] keys = new int[9] {1, 3, 4, 5, 8, 11, 12, 13, 14};
            for (int i = 0; i < keys.Length; i++)
            {
                Console.WriteLine(binSearch(test, keys[i]));
            }
        */
        public static int binSearch(int[] a, int x)
        {
            int l = 0;
            int r = a.Length - 1;
            while (l <= r)
            {
                int mid = (l + r) / 2;
                if (a[mid] == x)
                {
                    return mid;
                }
                else if (a[mid] > x)
                {
                    r = mid - 1;
                }
                else
                {
                    l = mid + 1;
                }
            }
            return -1;
        }

        public static int binSearchLeft(int[] a, int x)
        {
            int l = 0;
            int r = a.Length - 1;
            while (l < r)
            {
                int mid = (l + r) / 2;
                if (a[mid] < x)
                {
                    l = mid + 1;
                }
                else
                {
                    r = mid;
                }
            }
            return l;
        }
    }
}

Measured memory_bytes: 28432
N,K=map(int,input().split())
Points=[[int(i) for i in input().split()] for i in range(N)]
List_x=[Points[i][0] for i in range(N)]
List_x.sort(key=lambda x:x)
List_y=[Points[i][1] for i in range(N)]
List_y.sort(key=lambda x:x)
n=0
Y=0
S=[]
for x1 in range(N-1):
  for x2 in range(x1+K-1,N):
    for y1 in range(N-1):
      for y2 in range(max([y1+K-1,Y]),N):
        for p in Points:
          if List_x[x1]<=p[0]<=List_x[x2] and List_y[y1]<=p[1]<=List_y[y2]:
            n+=1
          if n==K:
            x_delta=List_x[x2]-List_x[x1]
            y_delta=List_y[y2]-List_y[y1]
            S.append(x_delta*y_delta)
            break
        if n>=K:
          n=0
          Y=y2
          break  
        n=0
    Y=0    
print(min(S))          
          

Measured memory_bytes: 5228
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *
        
N = INT()

w = []

n = "a"

def DFS(n):
    if len(n) == N:
        w.append(n)
        return
    else:
        for i in range(len(set(n))+1):
            m = n + ascii_lowercase[i]
            DFS(m)

DFS(n)
print(*w, sep= "\n")


Measured memory_bytes: 20188
//Problem A
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=105;
ll n,x,a[N],s,u;

int main(){
    scanf("%lld%lld",&n,&x);
    for(int i=1;i<=n;i++)scanf("%lld",&a[i]),s+=a[i];
    if(s==x){printf("%lld",n);return 0;}sort(a+1,a+n+1);
    for(int i=1;i<n;i++){
        u+=a[i];
        if(x<u){printf("%lld",i-1);return 0;}
    }printf("%lld",n-1);
    return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var s = Console.ReadLine();
            string ans = string.Empty;
            for (int i = 0; i < Math.Ceiling(s.Length / 2.0); i++) ans += s[2 * i].ToString();
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 32724