akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc104_b.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S;
  cin >> S;

  int aidx = 0;
  int acnt = 0;
  int cidx = 0;
  int ccnt = 0;
  rep(i, S.size()) {
    if (S[i] == 'A') {
      aidx = i;
      acnt++;
    } else if (S[i] == 'C') {
      cidx = i;
      ccnt++;
    } else if (S[i] <= 'Z') {
      cout << "WA" << endl;
      return 0;
    }
  }

  bool ok = (aidx == 0) && (acnt == 1) && (cidx >= 2 && cidx <= S.size() - 2) &&
            (ccnt == 1);

  cout << (ok ? "AC" : "WA") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

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

void Main() {
  Cin(int, n, a, b);

  bool wina = false, winb = false;
  while (!wina && !winb) {
    if (a + 1 != b)
      a++;
    else {
      a--;
      if (a == 0) winb = true;
    }
    if (b - 1 != a)
      b--;
    else {
      b++;
      if (b == n + 1) wina = true;
    }
  }

  cout << (wina ? "Alice" : "Borys") << endl;
}

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

int main() {
  string S;
  cin >> S;

  if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

        
  

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N, M;
int p[200100];
int el[200100];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> M;
	int i;
	for (i = 1; i <= N; i++)
	{
		cin >> el[i];
		p[i] = 1;
	}
	int ans = N;
	for (i = 0; i < M; i++)
	{
		int x, y;
		cin >> x >> y;
		if (el[x] >= el[y])
		{
			ans -= p[y];
			p[y] = 0;
		}
		if (el[x] <= el[y])
		{
			ans -= p[x];
			p[x] = 0;
		}
	}
	cout << ans;
}

Measured memory_bytes: 4436
N, K = map(int, input().split())
G = [[[0, 0] for j in range(2 * K + 1)] for i in range(K + 1)]
W = 0
for i in range(N):
  x, y, c = input().split()
  X = int(x) % (2 * K)
  Y = int(y) % (2 * K)
  if X >= K:
    X = (X - K) % K
    Y = (Y - K) % (2 * K)
  G[X + 1][Y + 1][0 if c == 'W' else 1] += 1
  W += 1 if c == 'W' else 0
for i in range(1, K + 1):
  for j in range(1, 2 * K + 1):
    G[i][j][0] += G[i][j - 1][0]
    G[i][j][1] += G[i][j - 1][1]
for i in range(1, K + 1):
  for j in range(1, 2 * K + 1):
    G[i][j][0] += G[i - 1][j][0]
    G[i][j][1] += G[i - 1][j][1]
cnt = 0
for i in range(1, K + 1):
  for j in range(1, K + 1):
    w = 2 * G[i - 1][j - 1][0] + G[K][j + K - 1][0] - 2 * G[i - 1][j + K - 1][0] - G[K][j - 1][0] + G[i - 1][2 * K][0]
    b = 2 * G[i - 1][j - 1][1] + G[K][j + K - 1][1] - 2 * G[i - 1][j + K - 1][1] - G[K][j - 1][1] + G[i - 1][2 * K][1]
    cnt = max([w + (N - W - b), (W - w) + b, cnt])
print(cnt)

Measured memory_bytes: 203996
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;

static const int  MAX_INT = std::numeric_limits<int>::max();
static const long MAX_LONG = std::numeric_limits<long>::max();
static const ll   MAX_LL = std::numeric_limits<long long>::max();

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

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
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; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
    int N; cin >> N;
    vector<int> d1(N), d2(N);
    vector<bool> zoro(N);
    rep(i, N) {
        cin >> d1[i] >> d2[i];
        zoro[i] = (d1[i] == d2[i]);
    }
    int cnt = 0;
    rep(i, N) {
        if (zoro[i]) {
            cnt++;
        }
        else {
            cnt = 0;
        }
        if (cnt == 3) break;
    }

    if (cnt == 3) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

    double tmp;
    cin >> tmp;

    return 0;
}


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

int main() {
    string s;
    cin >> s;
    string e;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '0'){
            e += '0';
        }else if(s[i] == '1'){
            e += '1';
        }else{
            if(e.size() > 0){
                e.pop_back();
            }
        }
    }
    cout << e;
}

Measured memory_bytes: 256
/*
 * written by Yaqi Zhang (zhang623@wisc.edu)
 * University of Wisconsin-Madison
 * 2020
 */
#include <bits/stdc++.h>

#define INF 0x3f3f3f3f

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    for(int i = 0; i < h; ++i) cin >> grid[i];
    vector<vector<int>> left(h, vector<int>(w, 0));
    vector<vector<int>> right(h, vector<int>(w, 0));
    vector<vector<int>> up(h, vector<int>(w, 0));
    vector<vector<int>> down(h, vector<int>(w, 0));
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(grid[i][j] == '.') {
                // left
                if(j > 0 && grid[i][j - 1] == '.') left[i][j] = left[i][j - 1] + 1;

                // up
                if(i > 0 && grid[i - 1][j] == '.') up[i][j] = up[i - 1][j] + 1;
            }
        }
    }

    for(int i = h - 1; i >= 0; --i) {
        for(int j = w - 1; j >= 0; --j) {
            if(grid[i][j] == '.') {
                // right
                if(j + 1 < w && grid[i][j + 1] == '.') right[i][j] = right[i][j + 1] + 1;

                // down
                if(i + 1 < h && grid[i + 1][j] == '.') down[i][j] = down[i + 1][j] + 1;
            }
        }
    }
    int mx = 0;
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(grid[i][j] == '.') {
                mx = max(mx, 1 + left[i][j] + right[i][j] + up[i][j] + down[i][j]);
            }
        }
    }
    cout << mx << endl;
    return 0;
}



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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int N, M;
  ll L;
  cin >> N >> M >> L;
  vvl dist(N, vl(N, LINF)); // dist[from][to]
  vvl dist2(N, vl(N, LINF)); // dist[from][to]
  rep(i, N) dist[i][i] = 0; // 自分自身へは距離0
  rep(i, M) {
    int u, v;
    ll c;
    cin >> u >> v >> c;
    u--, v--;
    if (c <= L) {
      dist[u][v] = c;
      dist[v][u] = c; // 無向辺の場合は両側に入力
    }
  }
  rep(k, N) rep(i, N) rep(j, N) { // k:経由する頂点、i:始点、j:終点
    if (dist[i][j] > dist[i][k] + dist[k][j]) {
      dist[i][j] = dist[i][k] + dist[k][j];
    }
  }
  rep(i, N) rep(j, N) { // i:始点、j:終点
    if (dist[i][j] <= L) {
      dist2[i][j] = 1;
    }
  }
  rep(k, N) rep(i, N) rep(j, N) { // k:経由する頂点、i:始点、j:終点
    if (dist2[i][j] > dist2[i][k] + dist2[k][j]) {
      dist2[i][j] = dist2[i][k] + dist2[k][j];
    }
  }

  int Q;
  cin >> Q;
  rep(i, Q) {
    int s, g;
    cin >> s >> g;
    s--, g--;
    if (dist2[s][g] == LINF) {
      cout << -1 << endl;
    } else {
      cout << dist2[s][g] - 1 << endl;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    while (b <= a)
        b *= 2, k--;
    while (c <= b)
        c *= 2, k--;
    if (k < 0)
        cout << "No";
    else
        cout << "Yes";
    return 0;
}

Measured memory_bytes: 3552
#include <stdio.h>

#define N 20
#define MIN(A,B) \
  ( (A) < (B) ? (A) : (B) )
#define MAX(A,B) \
  ( (A) > (B) ? (A) : (B) )

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j;

  for ( ; ; )
  {
    int n, m;
    int mx[ N ], my[ N ], mc[ N ] = { 0 };
    int px = 10, py = 10;
    int res = 1;

    scanf ( " %d", &n );
    if ( !n ) break ;
    for ( i = 0; i < n; ++i )
    {
      scanf ( " %d %d", mx + i, my + i );
    }

    scanf ( " %d", &m );
    for ( j = 0; j < m; ++j )
    {
      char cmd;
      int dist;
      int nx, ny;

      scanf ( " %c %d", &cmd, &dist );
      nx = px + ( cmd == 'E' ? dist : 0 )
              + ( cmd == 'W' ? -dist : 0 );
      ny = py + ( cmd == 'N' ? dist : 0 )
              + ( cmd == 'S' ? -dist : 0 );
      
      for ( i = 0; i < n; ++i )
      {
        if ( mc[ i ] )  continue ;

        mc[ i ] = !!( MIN( nx, px ) <= mx[ i ] && mx[ i ] <= MAX( nx, px )
                   && MIN( ny, py ) <= my[ i ] && my[ i ] <= MAX( ny, py ) );
      }

      px = nx; py = ny;
    }

    for ( i = 0; i < n; ++i )
    {
      res = res && mc[ i ];
    }
    puts ( res ? "Yes"
               : "No" );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long 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*(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;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	string S;
	cin >> S;

	if (S.size() < 26) {
		vll v(26, 0);

		rep(i, S[i]) {
			v[S[i] - 'a'] = 1;
		}

		ll c = 0;
		rep(i, 26) {
			if (v[i] == 0) { c = i; break; }
		}

	

		char x = c + 'a';
		cout << S + x << endl;
	}

	else {
		for (ll i = 25; i>=0; i--) {
			char c = S[i];

			char d = 127;
			for (ll j = i+1; j < 26; j++) {
				if (S[j] > c) { d = min(d, S[j]); }
			}

			//cout << d << endl;

			if (d == 127) { continue; }

			else { cout << S.substr(0, i) + d << endl; return 0; }
		}

		cout << -1 << endl;
	}
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

ll N;
ll BIT[SIZE];
ll A[SIZE];
ll table[SIZE];

void add(ll loc,ll value){

	BIT[loc] += value;

	loc += loc & -loc;

	while(loc <= (N+1)){
		BIT[loc] += value;
		loc += loc & -loc;
	}
}

ll getSum(ll loc){

	ll sum = BIT[loc];

	loc -= loc & -loc;

	while(loc > 0){
		sum += BIT[loc];
		loc -= loc & -loc;
	}
	return sum;
}

int main(){

	scanf("%lld",&N);

	ll minimum = BIG_NUM,maximum = -BIG_NUM;

	for(ll i = 1; i <= N; i++){

		scanf("%lld",&A[i]);
		minimum = min(minimum,A[i]);
		maximum = max(maximum,A[i]);
	}

	ll all = N*(N+1)/2;
	ll half;
	if(all%2 == 0){

		half = all/2;
	}else{

		half = all/2+1;
	}

	ll left = minimum,right = maximum,mid = (left+right)/2;
	ll ans;

	while(left <= right){

		table[0] = 0;
		minimum = 0;

		for(ll i = 1; i <= N; i++){
			if(A[i] < mid){
				table[i] = -1;
			}else{

				table[i] = 1;
			}
			table[i] += table[i-1];
			minimum = min(minimum,table[i]);
		}

		for(ll i = 0; i <= N+1; i++)BIT[i] = 0;

		ll tmp = 0;

		//自分の左にある、自分以下の数を数える
		for(ll i = 0; i <= N; i++){

			ll loc = table[i]-minimum+1; //BITなので、最小値を1にする

			tmp += getSum(loc);
			add(loc,1);
		}

		if(tmp >= half){

			ans = mid;
			left = mid+1;
		}else{

			right = mid-1;
		}
		mid = (left+right)/2;
	}

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

	return 0;
}


Measured memory_bytes: 6144
import java.util.Scanner;

class Main {
    static final long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        long ans = 3;
        boolean tate = true;
        int start = 0;
        if (s.charAt(0) == t.charAt(0)) {
            start = 1;
        } else {
            tate = false;
            start = 2;
            ans = 6;
        }

        for (int i = start; i < n; i++) {
            char c1 = s.charAt(i);
            char c2 = t.charAt(i);
            if (tate) {
                if (c1 == c2) {
                    ans *= 2;
                    ans %= mod;
                    tate = true;
                } else {
                    ans *= 2;
                    ans %= mod;
                    i++;
                    tate = false;
                }
            } else {
                if (c1 == c2) {
                    ans *= 1;
                    tate = true;
                } else {
                    ans *= 3;
                    ans %= mod;
                    i++;
                    tate = false;
                }
            }

        }
        System.out.println(ans);
        sc.close();
    }
}


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

const int maxn = 1e5+5;
int N;
ll A[maxn];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A,A+N,greater<int>());
    ll res = 0;
    res += A[0];
    for (int i = 1; i < N-1; i++) {
        res += abs(A[i]);
    }
    res -= A[N-1];
    cout << res << '\n';
    int idx = 1;
    ll curr = A[N-1];
    for (; idx < N - 1 && A[idx] >= 0; idx++) {
        cout << A[N-1] << ' ' << A[idx] << '\n';
        A[N-1] -= A[idx];
    }
    //cerr << idx << ' ' << A[idx] << '\n';
    cout << A[0] << ' ' << A[N-1] << '\n';
    A[0] -= A[N-1];
    for (; idx < N - 1; idx++) {
        cout << A[0] << ' ' << A[idx] << '\n';
        A[0] -= A[idx];
    }
}



Measured memory_bytes: 2688
N=int(input())
i=N//3
j=N//5
k=N//15

sum3=3*i*(1+i)//2
sum5=5*j*(1+j)//2
sum15=15*k*(1+k)//2
sumall=N*(1+N)//2

ans = sumall-(sum3+sum5-sum15)
print(ans)

Measured memory_bytes: 9180
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

import org.omg.Messaging.SyncScopeHelper;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new Test_200().doIt();
	}
	class Test_200{
		void doIt() {
			int N = sc.nextInt();
			long S[] = new long[N+1];
			S[0] = 0;
			for(int i = 1;i < N+1;i++) {
				S[i] = S[i-1] + sc.nextLong();
			}
			Arrays.sort(S);
			long ans = 0;
			long cnt = 0;
			for(int i = 1;i < N+1;i++) {
				if(S[i] == S[i-1]) {
					cnt++;
					ans = ans + cnt;
				}
				else cnt = 0;
			}
			System.out.println(ans);
		}
	}
}


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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int grundy = 0;
  int n; cin >> n;
  for(int i=0; i < n; i++) {
    ll a, k; cin >> a >> k;
    int res = 0;
    while(1) {
      ll g = a / k;
      if(g == 0) break;
      ll num = a % k;
      num %= g + 1;
      if(num == 0) {
        res = g;
        break;
      }
      a = g * k + num;
      a -= g + 1;
    }
    grundy ^= res;
  }
  cout << (grundy == 0 ? "Aoki" : "Takahashi") << endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i,N){
        cin >> L[i];
    }
    sort(L.begin(), L.end());
    int max = L[N-1];
    int sum = 0;
    rep(i,N-1){
        sum += L[i];
    }
    string ans = (max >= sum)? "No" : "Yes";
    cout<< ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define lld long long int
#define ld long double
#define mpi 3.14159265358979323846
#define mod 1000000007
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string a,b,c;
	cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0] << "\n";
	return 0;
}


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

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;++i)
        cin>>a[i];

    sort(a.rbegin(),a.rend());
    ll s = a[0];
    ll mx = a[1];
    ll t =2;
    ll j = 1;
    for(int i=2;i<(int)a.size();++i)
    {
        s+= mx;
        t--;
        if(t==0)
        {
            mx = a[++j];
            t=2;
        }
    }
    cout<<s<<endl;


    return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int N;
  cin >> N;
  vector<int> a(N);
  map<int, int> m;
  REP(i, N) {
    cin >> a[i];
    if(m.count(a[i]) == 0)
      m[a[i]] = 1;
    else
      m[a[i]]++;
  }
  ll ans_sum = 0;
  for(auto i = m.begin(); i != m.end(); i++) {
    ll j = i->second;
    ans_sum += j * (j - 1) / 2;
  }
  vector<ll> ans(N, 0);
  REP(i, N) {
    ll sum = m[a[i]];
    ans[i] = ans_sum - (sum * (sum - 1) / 2 - (sum - 1) * (sum - 2) / 2);
  }
  REP(i, N) {
    cout << ans[i] << endl;
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
typedef vector<int64_t> vi;
typedef vector<vector<int64_t>> vvi;
const double pi = 3.14159265358979;

int main(){
    int n,m; cin >> n >> m;
    vvi r(n);
    for(int ix=0;ix<m;ix++){
        int a , b; cin >> a >> b; a--; b--;
        r.at(a).push_back(b); r.at(b).push_back(a);
    }
    vi dist(n,-1);
    vi sign(n,-1);
    queue<int> q;
    dist.at(0) = 0;
    q.push(0);
    while(!q.empty()){
        int v = q.front(); q.pop();
        for(int nv : r.at(v)){
            if(dist.at(nv) == -1){
                dist.at(nv) = dist.at(v)+1;
                q.push(nv);
                sign.at(nv) = v;
            }
            else if(dist.at(nv) > dist.at(v)+1){
                dist.at(nv) = dist.at(v)+1;
                sign.at(nv) = v;
            }
        }
    }
    cout << "Yes" << endl;
    for(int ix=1;ix<n;ix++) cout << sign.at(ix)+1 << endl;
}

Measured memory_bytes: 13472
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
int main()
{
    ios_base::sync_with_stdio(0);
 
	int N; cin >> N;
  	int ans = 0;
  for (int i = 0; i < N; i++)
  {
int x; cin >> x;
    if (x == ans + 1)
      ans++;
  }
  if (ans == 0) ans = N + 1;
  cout << N - ans << "\n";
}

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


int main() {
int n, k;
cin >> n >> k;
vector<int> p(n);
rep(i,n) cin >> p[i];
//配列をソート
sort(p.begin(),p.end());
int sum = 0;
for(int i = 0; i<k; i++) sum += p[i];
cout << sum << endl; 
return 0; 
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
typedef long long ll;
inline ll read() {ll x = 0;char ch = getchar(), w = 1;while(ch < '0' || ch > '9') {
if(ch == '-') w = -1;ch = getchar();}while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0';ch = getchar();
}return x * w;}
void write(ll x) {if(x < 0) putchar('-'), x = -x;if(x > 9) write(x / 10);putchar(x % 10 + '0');}
inline void writeln(ll x) {write(x);puts("");}
using namespace std;
const int N = 310;
char s[N];
int n;
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	ll m = read();
	ll ans = 0;
	for(int i = 1, j; i <= n; i = j) {
		j = i;
		while(s[i] == s[j]) ++j;
		ans += (j - i) / 2;
	}
	if(s[1] != s[n]) {
		writeln(m * ans);
		return 0;
	}
	int l = 1, r = n;
	while(s[l] == s[1]) ++l;
	while(s[r] == s[1]) --r;
	if(r == 0) {
		writeln(n * m / 2);
		return 0;
	}
/*	ans = 0;
	for(int i = l, j; i <= r; i= j) {
		j = i;
		while(s[i] == s[j]) ++j;
		ans += (j - i) / 2;
	}*/
//	printf("l=%d,r=%d,ans=%d ()%d %d %d\n", l, r,ans,(l-1)/2,(n-r)/2,(l-1+n-r)/2);
	writeln(ans * m - ((l - 1) / 2 + (n - r) / 2 - (l - 1 + n - r) / 2) * (m - 1));
//	printf("ans=%lld\n", ans);
	/*
	axaaxaaaa
	*/
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
 int n;
 scanf("%d",&n);
 int a[n],b[n],c[n-1];

 for(int i=0;i<n;i++)
 scanf("%d",&a[i]);

 for(int i=0;i<n;i++)
 scanf("%d",&b[i]);

 for(int i=0;i<n-1;i++)
 scanf("%d",&c[i]);

 int count=0;

for(int i=0;i<n;i++)
{
    count+=b[a[i]-1];


}
for(int i=1;i<n;i++)
{
    if(a[i]-1==a[i-1])
        count+=c[a[i-1]-1];
}
printf("%d",count);
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <complex>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
#define un using namespace
un std;
#define pb push_back
#define pf pop_front

#define mp make_pair

#define c0 first
#define c1 second
#define sqr(x) ((x)*(x))
#define clr(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define clr80(x) memset(x, 0x80, sizeof(x))
#define clr7F(x) memset(x, 0x7F, sizeof(x))

#define LL long long
#ifdef __unix__
#define LLD "%lld"
#else
#define LLD "%I64d"
#endif
#define pii pair<int, int>
#define pip pair<int, pii>
#define vi vector<int>
#define vpi vector<pii>
#define pq priority_queue

template<typename T>
inline bool chkmin(T &a, T b){return a > b ? a = b, 1 : 0;}
template<typename T>
inline bool chkmax(T &a, T b){return a < b ? a = b, 1 : 0;}

#define P 1000000007

#define getint(x){\
	char __next__char__;bool __nega__int__=0;\
	while(!isdigit(__next__char__=getchar())&&__next__char__!='-');\
	__next__char__=='-'?(x=0,__nega__int__=1):(x=__next__char__-48);\
	while(isdigit(__next__char__=getchar()))x=x*10+__next__char__-48;\
	if(__nega__int__)x=-x;\
}
#define getint2(x1,x2){getint(x1);getint(x2);}
#define getint3(x1,x2,x3){getint(x1);getint(x2);getint(x3);}
#define getint4(x1,x2,x3,x4){getint(x1);getint(x2);getint(x3);getint(x4);}
#define getint5(x1,x2,x3,x4,x5){getint(x1);getint(x2);getint(x3);getint(x4);getint(x5);}
#define getint6(x1,x2,x3,x4,x5,x6){getint(x1);getint(x2);getint(x3);getint(x4);getint(x5);getint(x6);}

int n;
int a[500 * 500 + 1];
int x[501];
int now[501];
void solve() {
	vector<int> s;
	s.pb(0);
	int n;
	getint(n);
	memset(a + 1, -1, 4 * n * n);
	memset(now, 0, sizeof now);
	int p = 1;
	for (int i = 1; i <= n; i++) {
		getint(x[i]);
		a[x[i]] = i;
	}
	for (int i = 1; i <= n * n; i++)
		if (a[i] != -1)
			s.pb(a[i]);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < s[i]; j++) {
			while (a[p] != -1) {
				p++;
			}
			a[p] = s[i];
		}
	}
	p = n * n;
	for (int i = n; i >= 1; i--) {
		for (int j = 0; j < n - s[i]; j++) {
			while (a[p] != -1) {
				p--;
			}
			a[p] = s[i];
		}
	}
	for (int i = 1; i <= n * n; i++) {
		if (a[i] == -1)
			while (1);
		if (now[a[i]] < a[i]) {
			now[a[i]]++;
			if (now[a[i]] == a[i]) {
				if (i != x[a[i]]) {
					puts("No");
					return;
				}
			}
		}
	}
	puts("Yes");
	for (int i = 1; i <= n * n; i++) {
		printf("%d%c", a[i], i == n * n ? '\n' : ' ');
	}
}

int main() {
	//for (int t = 50; t--; )
		solve();
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
#define LL long long
#define REP(i, a, b) for(int i = a; i <= b; ++i)
#define PER(i, a, b) for(int i = a; i >= b; --i)

inline int read() {
	int x = 0, flag = 1; char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * flag;
}

int main() {
	int a = read(), b = read();
	cout << a + (int) b / 2 << endl;
	return 0;
}
 

Measured memory_bytes: 256
def make_inv_tables(mod, n):
    # 階乗テーブル逆元の階乗テーブルの2つを作成する

    fac = [1, 1]
    ifac = [1, 1]
    inverse = [0, 1]

    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod // i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac

def cmb(n, k, mod, fac, ifac):
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod

X, Y = map(int, input().split())
total = int((X + Y) / 3)
n = X - total
if (X + Y) % 3 != 0:
    print(0)
elif X - total < 0 or Y - total < 0:
    print(0)
else:
    MOD = 10 **  9 + 7
    fac, ifac = make_inv_tables(MOD, total)
    ans = cmb(total, n, MOD, fac, ifac)
    print(ans)

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef long long ll;

const int MOD = 1000000007;

void solve() {
  ll H, ans = 0, cur = 1;
  cin >> H;
  while (H > 0) {
    H /= 2;
    ans += cur;
    cur *= 2;
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;
vector<ll> g[100005];
ll d[100005];
ll rec(ll x){
	if (d[x] != -1) {
		return d[x];
	}
	ll mx = 0;
	for (int i = 0; i < g[x].size(); i++) {
		mx = max(mx, rec(g[x][i]) + 1);
	}
	d[x] = mx;
	return mx;
}

int main() {
	ll n, m;
	cin >> n >> m;
	ll x, y;
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		x--;
		y--;
		g[x].push_back(y);
	}
	for (int i = 0; i < n; i++) {
		d[i] = -1;
	}
	ll ans;
	for (int i = 0; i < n; i++) {
		ans = max(ans, rec(i));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8576
D = gets.to_i
C = gets.chomp.split.map(&:to_i)
s = D.times.map{gets.split.map(&:to_i)}
c = Array.new(26, 0)
t = []

(0..D-1).each do |i|

  (0..25).each do |l|
    c[l] += C[l]
  end
ans = 0
boder = s[i][0]+7*c[0]

  (1..25).each do |e|
    if s[i][e]+7*c[e] >= boder
      ans = e
      boder = s[i][e]+7*c[e]
    end
  end
c[ans] = 0
puts ans+1
end


  



Measured memory_bytes: 14380
#include <stdio.h>
int main()
{
	int	n, r;
	char	c[40];
	int	i, j;

	scanf("%d", &n);
	if (n == 0) {
		printf("0\n");
	}
	else {
		j = 0;
		while (n != 0) {
			r = (n % 2)? 1: 0;
			n = (n - r) / -2;
			c[j] = '0' + r;
			j++;
		}
		for (i = j-1; 0 <= i; --i) {
			printf("%c", c[i]);
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 128
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################
n = int(input())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
b = b[::-1]
c = -1
for i in range(n):
	if a[i] == b[i]:
		c = a[i]
		break
l = 0
for i in range(n):
	if a[i] == c and b[i] == c:
		l = i
		break
r = -1
for i in range(n-1,-1,-1):
	if a[i] == c and b[i] == c:
		r = i
		break
for i in range(n):
	if a[i] != c and b[i] != c and l<=r:
		b[i] , b[l] = b[l], b[i]
		l+=1

if l <= r:
	print("No")
	exit()
print("Yes")
print(*b)











'''
# Wrap solution for more recursion depth
#submit as python3
import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)



threading.Thread(target=solve).start()
'''


Measured memory_bytes: 115092
N, M, C = map(int, input().split())
B = [int(i) for i in input().split()]
count = 0
for i in range(N):
    score = 0
    for a, b in zip(input().split(), B):
        score += int(a)*b
    if score + C > 0:
        count += 1
print(count)

Measured memory_bytes: 3060
import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

import numpy as np

def Main():
    n = read_int()
    a = np.array(read_int_list(), np.int64)
    ans = 0
    for i in range(60):
        cnt_one = np.count_nonzero(a >> i & 1)
        cnt_zero = n - cnt_one
        ans += (cnt_one * cnt_zero * (1 << i)) % MOD
        ans %= MOD
    print(ans)
    

if __name__ ==  '__main__':
    Main()

Measured memory_bytes: 68880
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  ll a,b,c,d; cin >> a >> b >> c >> d;

  ll ans = a*c;
  umax(ans, a*d);
  umax(ans, b*c);
  umax(ans, b*d);

  if(( a <= 0 && b >= 0) || ( c <= 0 && d >= 0)) umax(ans, 0LL);
  cout << ans << endl;
}


Measured memory_bytes: 3632
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int[] x = new int[n + 1];
        for (int i = 1; i <= n; ++i)
            x[i] = scanner.nextInt();
        long[][] f = new long[n + 1][2];
        f[2][0] = x[1] + x[2];
        f[2][1] = -x[1] - x[2];
        for (int i = 3; i <= n; ++i) {
            f[i][0] = Math.max(f[i - 1][0], f[i - 1][1]) + x[i];
            f[i][1] = Math.max(f[i - 1][0] - 2 * x[i - 1], f[i - 1][1] + 2 * x[i - 1]) - x[i];
        }
        writer.println(Math.max(f[n][0], f[n][1]));

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

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

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

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

Measured memory_bytes: 44952
MOD = 10 ** 9 + 7
MAX = 10 ** 6 + 1
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX

def CoMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

def COM(n, k):
   if n < k:
       return 0
   if n < 0 or k < 0:
       return 0

   return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
CoMinit()

N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

mint = 0
maxt = 0
for i in range(N):
    maxt += a[i] * COM(i, K - 1)
    mint += a[-i - 1] * COM(i, K - 1)

print((maxt - mint) % MOD)

Measured memory_bytes: 132824
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

inline LL read()
{
	char c=getchar();LL num=0;
	for(;!isdigit(c);c=getchar());
	for(;isdigit(c);c=getchar())
		num=num*10+c-'0';
	return num;
}

int main()
{
	LL l=read(),r=read();
	LL L=l,R=r;
	for(int i=60;~i;--i)
	{
		if((l>>i)^(r>>i))
		{
			l|=1ll<<i;
			int t=--i;
			for(;~t;--t) R|=1ll<<t;
			for(;~i&&!(r>>i&1);--i);
			for(;~i;--i) r|=1ll<<i;
			break;
		}
	}
	if(r>=l)
		cout<<R-L+1;
	else
		cout<<r-L+1+R-l+1;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int a[maxn], b[maxn], a1[maxn], b1[maxn];
int  v[maxn], match[maxn];
int n;
vector < int > g[maxn];
bool dfs(int x)
{
	int y;
	for(int i = 0; i < g[x].size(); i++){
		y = g[x][i];
		if(!v[y]){
			v[y] = 1;
			if(!match[y] || dfs(match[y])){
				match[y] = x;
				return true;
			}
		}
	}
	return false;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d %d", a + i, b + i);
	}
	for(int i = 1; i <= n; i++){
		scanf("%d %d", a1 + i, b1 + i);
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(a[i] < a1[j] && b[i] < b1[j]){
				g[i].push_back(j);
			}
		}
	}
//	for(int i = 1; i <= n; i++){
//		for(int j = 1; j <= n; j++){
//			printf("%d ", g[i][j]);
//		}
//		printf("\n");
//	}
	int ans = 0;
	for(int i  = 1; i <= n; i++){
		memset(v, 0, sizeof(v));
		if(dfs(i))ans++;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n;
	cin >> n;
	vector<int> a(n+1), b(n+1), c(n);
	rep(i, 1, n+1)cin >> a[i];
	rep(i, 1, n+1)cin >> b[i];
	rep(i, 1, n)cin >> c[i];
	int ans = 0;
	rep(i, 1, n+1) {
		ans += b[a[i]];
		if(i != 1 && a[i]-1 == a[i-1]) ans +=c[a[i-1]];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
s = input()
w = {}
ret = 'Yes'

for i in range(len(s)):
    if s[i] in w:
        w[s[i]] = w[s[i]] + 1
    else:
        w[s[i]] = 1

for num in w:
    if (w[num] % 2) == 1:
        ret = 'No'
        break

print(ret)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<double> c;
  rep(i, n) {
    double v;
    cin >> v;
    c.push_back(v);
  };
  rep(j, n-1) {
    set<int> s;
    sort(c.begin(), c.end());
    double x, y;
    rep(i, c.size()) {
      if(!s.count(i)) {
        x = c[i];
        s.insert(i);
        break;
      }
    }
    rep(i, c.size()) {
      if(!s.count(i)) {
        y = c[i];
        s.insert(i);
        break;
      }
    }
    vector<double> c3;
    rep(i, c.size()) {
      if(s.count(i)) continue;
      c3.push_back(c[i]);
    }
    c3.push_back((x+y)/2);
    c = c3;
  }
  cout << c[0] << endl;
  return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//namespaces
using namespace __gnu_pbds; 
using namespace std;

//MACROS
#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long 
#define For(i,s,e) for (int i=(s); i<(e); i++)
#define Fod(i,s,e) for (int i=(s); i>=(e); i--)
#define pii pair<ll,ll>
#define f first
#define s second
#define endl "\n"
#define all(container) container.begin(), container.end()
#define mp make_pair
#define int ll

//debug
#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

//Templates
template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

//globals
ll const prime1 = 304933;
ll const prime2 = 15486277;
ll const mod = 1e9+7;
ll const inf = 1e18;
ll const size_1d = 1e6 + 7;
ll const size_2d = 1e3 + 7;

//functions
ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;} 
ll gcdext(ll a,ll b,ll *x = 0, ll *y = 0){if(a == 0){*x = 0;*y = 1;return b;}ll x1,y1;ll gcd1 = gcdext(b%a,a,&x1,&y1);*x = y1 - (b/a)*x1;*y = x1;return gcd1;}
int randomize(){return (rand()%10000);} 

// CODE STARTS HERE

signed main(){
    IOS
    int a,b;cin >> a >> b;
    bool flag[4] = {0};
    flag[a] = true;
    flag[b] = true;
    for (int i = 0; i < 3; ++i)
    {
        if(!flag[i + 1]) return cout << i + 1 << endl,0;
    }

    return 0;
}

Measured memory_bytes: 256
r,c = map(int,input().split())
tbl = [list(map(int,input().split())) for _ in range(r)]
tbladd = []
for i in range(r):
    tbl[i].insert(c,sum(tbl[i]))
for i in range(c+1):
    sum = 0
    for j in range(r):
        sum += tbl[j][i]
    tbladd.insert(i,sum)
tbl.append(tbladd)
for i in range(r+1):
    for j in range(c+1):
        if j != c:
            print(tbl[i][j], end=' ')
        else:
            print(tbl[i][j], end='')
    if i != r:
        print()
    else:
        print()


Measured memory_bytes: 6228
from fractions import gcd
#操作の中で値が増えることはないため、max(a) < kだった場合は無理 
n,k = map(int, input().split())
a = list(map(int, input().split()))
gcd_a = a[0]
for i in range(n):
    gcd_a = gcd(gcd_a,a[i])
if k % gcd_a == 0 and k <= max(a):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 16280
n = int(input())
lst = sorted(list(map(int,input().split())))[::-1]
flag = 0
z = 1
if 0 in lst:
    z = 0
else:
    for i in range(n):
        z *= lst[i]
        if z>(10**18):
            print(-1)
            flag = 1
            break
if flag ==0:
  print(z)

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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

int main(){
	setIO();
	int s, w;
	cin>>s>>w;
	if(s>w) cout<<"safe\n";
	else cout<<"unsafe\n";
}

Measured memory_bytes: 3652
import fractions
z = [0,0,0]
z[0],z[1],z[2],n = map(int,input().split())
z.sort(reverse = 1)
a,b,c = z[2],z[1],z[0]
d = fractions.gcd(b,c)
b = b//d
c = c//d
#print(d)
ans = 0
x,y,z = 0,0,0
while a*x <= n:
  m = n-a*x
  if m%d > 0:
    continue
  m = m//d
  y = 0
  f = 0
  while m-b*y>= 0 and y < c:
    if (m-b*y)%c == 0:
      f = 1
      break
    y += 1
  ans += f*((m-b*y)//c//b+1)
  x += 1
print(ans)

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

int main() {
  int h, w;
  cin >> h >> w;
  char grid[h][w];
  rep(i, h) rep(j, w) cin >> grid[i][j];

  rep(i, h) rep(j, w) {
    if (grid[i][j] == '#') {
      bool flag = false;
      //上確認
      if (i != 0) {
        if (grid[i - 1][j] == '#') flag = true;
      }
      //下確認
      if (i != h - 1) {
        if (grid[i + 1][j] == '#') flag = true;
      }
      //左確認
      if (j != 0) {
        if (grid[i][j - 1] == '#') flag = true;
      }
      //右確認
      if (j != w - 1) {
        if (grid[i][j + 1] == '#') flag = true;
      }
      if (!flag) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

        typedef long long ll;
        //#define pb push_back

           int main()
         {
             int n,m; cin >> n>>m;
             if(n<10 && m<10)
             {
                 cout << n*m << '\n';
             }
             else {
                cout << -1 << '\n';
             }

         }


Measured memory_bytes: 256