akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

vector<vector<int>> split(const vector<int>& vP){
    vector<vector<int>> vvNew;
    
    uint i=0;
    while(i<vP.size()){
        while(i<vP.size() && vP[i]==0){ ++i; } // pass empty
        
        vector<int> vNew;
        while(i<vP.size() && vP[i]!=0 ){ vNew.push_back( vP[i] ); ++i; } // copy
        vvNew.push_back( move(vNew) );
    }
    return vvNew;
}
vector<vector<int>> split(const vector<vector<int>>& vvP){
    vector<vector<int>> vvNew;
    for(uint vi=0; vi<vvP.size(); ++vi){
        vector<vector<int>> vvTmp = split( vvP[vi] );
        
        for(uint i=0; i<vvTmp.size(); ++i){
            if( vvTmp[i].size()==0 ){ continue; }
            vvNew.push_back( move(vvTmp[i]) );
        }
    }
    return vvNew;
}

int min(const vector<int>& vP){
    int minVal=vP[0];
    for(uint i=1; i<vP.size(); ++i){
        minVal = min(minVal, vP[i]);
    }
    return minVal;
}

int main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    
    uint N; cin >> N;
    vector<vector<int>> vvP(1, vector<int>(N));
    for(uint i=0; i<N; ++i){ cin>>vvP[0][i]; }
    
    int64 cnt=0;
    while(vvP.size()!=0){
        for(uint vi=0; vi<vvP.size(); ++vi){
            int minVal = min( vvP[vi] );
            cnt += minVal;
            
            for(uint i=0; i<vvP[vi].size(); ++i){ vvP[vi][i] -= minVal; }
        }
        
        vvP = split( vvP );
    }
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
from itertools import product
n,m  = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i, j, k in product([-1,1], repeat=3):
    ans = max(ans, sum(sorted(i*x+j*y+k*z for x,y,z in a)[::-1][:m]))
print(ans)

Measured memory_bytes: 40944
#include<cstdio>

int main(){
	int dice1[6], dice2[6], tmp[6];
	int pt[5][6] = {	{5,1,3,4,6,2}, 
				 	{0,0,0,0,0,0},
					{4,2,1,6,5,3},
					{2,6,3,4,1,5},
					{3,2,6,1,5,4}};
	int t[24] = {0,0,0,2,0,0,0,2,0,0,0,4,0,0,0,4,0,0,0,2,0,0,0,0};
	for(int i = 0; i < 6; i++){
		scanf("%d", &dice1[i]);
     }
	for(int i = 0; i < 6; i++){
		scanf("%d", &dice2[i]);
	}
	int x;
	for(int i = 0; i < 24 ; i++){
		int c = 0;
		while(!(dice1[c] - dice2[c])){
			c++;
		}
		if(c == 6){
			printf("Yes\n");
			return 0;
		}
		for(int j = 0; j < 6; j++){
			tmp[j] = dice1[j];
		}
		for(int j = 0; j < 6; j++){
			x = pt[t[i]][j];
			dice1[j] = tmp[x - 1];
		}
	}
	printf("No\n");
	return 0;
}

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

struct MaxFlow{
  struct edge{ int to,cap,rev; }; //{行先,容量,逆辺}
  vector< vector<edge> > G; //隣接リスト
  vector<bool> visited; //dfsで既に調べたかのフラグ

  void init(int n){
    G.resize(n);
    visited.resize(n);
  }

  void add_edge(int from,int to,int cap){
    G[from].push_back({to,cap,(int)G[to].size()});
    G[to].push_back({from,0,(int)G[from].size()-1});
  }

  //増加パスを探す
  int dfs(int v,int t,int f){
    if(v == t) return f;
    visited[v] = true;
    for(auto &e : G[v]){
      if(!visited[e.to] && e.cap > 0){
        int d = dfs(e.to,t,min(f,e.cap));
        if(d > 0){
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  //sからtへの最大流を求める
  int maxflow(int s,int t){
    int flow = 0;
    for(;;){
      fill(visited.begin(),visited.end(),false);
      int f = dfs(s,t,1LL<<60);
      if(f == 0) return flow;
      flow += f;
    }
  }

}flow;

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

  int V,E; cin >> V >> E;
  flow.init(V+1);
  for(int i = 0; i < E; i++){
    int u,v,c; cin >> u >> v >> c;
    flow.add_edge(u,v,c);
  }
  cout << flow.maxflow(0,V-1) << endl;

  return 0;
}



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

import static java.lang.Integer.parseInt;

/**
 * Osenbei
 * JOI 7th, Pre 5
 */
public class Main {

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

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			StringTokenizer st = new StringTokenizer(line);

			int R, C;
			R = parseInt(st.nextToken());
			C = parseInt(st.nextToken());
			if ((R | C) == 0) break;

			int[] CR = new int[C];

			for (int i = 0; i < R; i++) {
				st = new StringTokenizer(br.readLine());
				for (int j = 0; j < C; j++) {
					if (st.nextToken().equals("1")) CR[j] |= 1 << i;
				}
			}

			//solve
			int max = 0;

			for (int i = 0; i < 1 << R; i++) {
				int[] _CR = Arrays.copyOf(CR, CR.length);
				//
				int count = 0;
				for (int j = 0; j < C; j++) {
					int bits = bits(_CR[j] ^ i, R);
					count += (bits > R - bits ? bits : R - bits);
				}
				max = Math.max(max, count);
			}

			System.out.println(max);
		}
	}

	static int bits(int b, int size) {
		int ret = 0;
		for (int i = 0; i < size; i++) {
			if ((b >> i & 1) == 1) ret++;
		}
		return ret;
	}
}

Measured memory_bytes: 63880
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pf(n) printf("%d\n",n)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	int n;
	cin >> n;
	map<int, int> d;
	int mx = 0;
	int mi = 1001001;
	rep(i, n) {
		int D;
		cin >> D;
		mx = max(mx, D);
		mi = min(mi, D);
		d[D]++;
	}
	vector<int> a(mx + 1, 0);
	a[1] += d[1];
	for (int i = 2; i <= mx; i++) {
		a[i] += d[i] + a[i - 1];
	}
	int ans = 0;
	for (int i = 1; i <= mx; i++) {
		if (a[i] == n / 2) ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8312
#include<bits/stdc++.h>
#define int long long 
using namespace std;
signed main(){
  int n;
  string s[1100];
  double a[10000],sum=0;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i]>>s[i];
  }
  for(int i=0;i<n;i++){
    if(s[i]=="JPY"){
      sum+=a[i];
    }else if(s[i]=="BTC"){
      sum += a[i] * 380000.0;
    }
  }
  
  cout<<sum<<"\n";

  return(0);
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
   int S,h,m,s;
   scanf("%d",&S);
   h=S/3600;
   m=(S-h*3600)/60;
   s=(S-h*3600)-m*60;
   printf("%d:%d:%d\n",h,m,s);
   return 0;
 
}


Measured memory_bytes: 2044
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
	
int n,a;
int main(){
	long long int min=0x7fffffff;
//	scanf("%d%d",&n,&a);
	cin>>n>>a;
	if(a-n>=2019){
		printf("0");
	}else{
		for(int i=n;i<=a;i++){
			for(int j=i+1;j<=a;j++){
//				long long int sum=(i*j)%2019;
				long long int sum=((i%2019) * (j%2019) ) %2019;
	//			printf("%d",sum);
				if(sum<min){
					min=sum;
				}
			}
		}
		printf("%lld",min);
	}
	return 0;
} 
//int n,a;
//int main(){
//	long long int min=2019;
//	scanf("%d%d",&n,&a);
////	if(((n*a)%2019)!=((n%2019)*(a%2019))){
////		printf("0");
////	}else{
//	if(!(a-n>=2019)&&a>n){
//		for(int i=n;i<=a;i++){
//			for(int j=i+1;j<=a;j++){
//				long long int sum=(i*j)%2019;
//				printf("%d\n",sum);
//				if(sum<min){
//					min=sum;
//				}
//			}
//		}
//	printf("%d",min);
//	}else{
//		printf("0");
//	}
////	}
//	return 0;
//} 
//1010  2020
///1010

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    long long n, m;
    cin >> n >> m;
    vector <long long> qw (n);
    for (int i=0; i<n; ++i)
        cin >> qw[i];
    for (int i=1; i<n-m+1; ++i)
    {
        if (qw[i+m-1]>qw[i-1])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}


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

int main()
{
	int N;
	struct Pt
	{
		int x;
		int y;
		int64_t h;
	};
	struct Pt InpPt[100];
	int ansx = 0, ansy = 0;
	int64_t ansh = 0;
	int bk = 0;

	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> InpPt[i].x >> InpPt[i].y >> InpPt[i].h;
	}

	for (int x = 0; x <= 100; x++)
	{
		for (int y = 0; y <= 100; y++)
		{
			int found = 1;
			ansh = 10000000000l;
			for (int i = 0; i < N; i++)
			{
				int64_t ch = InpPt[i].h + abs(x - InpPt[i].x) + abs(y - InpPt[i].y);
				if (ch < ansh) ansh = ch;
			}

			for (int i = 0; i < N; i++)
			{
				int64_t calc_h = ansh - abs(x - InpPt[i].x) - abs(y - InpPt[i].y);
				if (calc_h < 0) calc_h = 0;
				if (calc_h != InpPt[i].h)
				{
					found = 0;
					break;
				}
			}
			if (found == 1)
			{
				ansx = x;
				ansy = y;
				bk = 1;
				break;
			}
		}
		if (bk != 0) break;
	}
	cout << ansx << " " << ansy << " " << ansh << endl;

	return(0);
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[][] sum = new long[8][n];
		for (int i = 0; i < n; i++) {
			long x = sc.nextLong();
			long y = sc.nextLong();
			long z = sc.nextLong();
			for (int j = 0; j < 8; j++) {
				long a = 0;
				if ((j >> 0) % 2 == 1) {
					a += x;
				} else {
					a -= x;
				}
				if ((j >> 1) % 2 == 1) {
					a += y;
				} else {
					a -= y;
				}
				if ((j >> 2) % 2 == 1) {
					a += z;
				} else {
					a -= z;
				}
				sum[j][i] = a;
			}
		}
		sc.close();

		for (int j = 0; j < 8; j++) {
			Arrays.parallelSort(sum[j]);
		}

		long ans = 0;
		for (int j = 0; j < 8; j++) {
			long a = 0;
			for (int i = n - m; i < n; i++) {
				a += sum[j][i];
			}
			ans = Math.max(ans, a);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 26432
T = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))


da, db = 0, 0
for i in range(2):
    da += T[i] * A[i]
    db += T[i] * B[i]

if da == db:
    print("infinity")
    exit()

x = (B[0] - A[0]) * T[0]
y = da - db

print(max(0, x // y * 2 + (0 if x % y == 0 else 1)))


Measured memory_bytes: 3064
N = int(input())
A = [int(x) for x in input().split()]

mod = 10**9 + 7

ans = sum(A) * sum(A) % mod
ans += mod - (sum([a*a for a in A]) % mod)
ans %= mod
if(ans%2==0):
    ans //= 2
else:
    ans = (ans + mod) // 2
    ans %= mod
print(ans)

Measured memory_bytes: 31424
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

  int by4 = 0;
  int by2 = 0;
  int oth = 0;
  rep(i, N) {
    int a;
    cin >> a;
    if (a % 4 == 0)
      by4++;
    else if (a % 2 == 0)
      by2++;
    else
      oth++;
  }
  if (by2 != 0) {
    if (oth <= by4) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    if (oth <= (by4 + 1)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int M, D;
	cin >> M >> D;
	
	int res = 0;
	for(int i = 1; i <= M; i++){
		for(int j = 1; j <= D; j++){
			int d0 = j % 10;
			int d1 = j / 10;

			if(d0>=2 and d1>=2 and d0*d1==i) res++;
		}
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*
import java.math.*

val pw = PrintWriter(System.out)

fun main(args: Array<String>) {
    val n = readInt()
    val x = readListOfInt()
    val sortedX = x.sorted() 
    val centerIdx = n / 2 - 1 
    val centerX = sortedX[centerIdx]

    x.forEach { cx ->
        val ans = 
            if(cx <= centerX) {
                sortedX[centerIdx+1]            
            } else {
                sortedX[centerIdx]
            }
            println(ans)

    }
    pw.flush()
}

fun inputList() = 
    readLine()!!.split(" ").map(String::toInt)

fun sum_digits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

/****** Decrared Functions ******/

// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }


fun println(value : Any) {
    pw.println(value)
}

fun gcd(a: Long, b: Long): Long = 
    if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
    if(b==0L) a else gcd(b, a % b)


Measured memory_bytes: 85060
#include <iostream>
#include <string>
using namespace std;
int main() {
    string S; cin>>S;
    bool flg=true;
    for (int i=0; i<S.length(); i++) {
        if (i%2 == 0) {
            if (S.at(i) == 'L') {
                flg=false;
                break;
            }
        } else {
            if (S.at(i) == 'R') {
                flg=false;
                break;
            }
        }
    }
    flg ? cout<<"Yes"<<endl : cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3616
import java.util.*;
public class Main {
	final int MAX = (1 << 15);
	private void doit(){
		Scanner sc = new Scanner(System.in);
		boolean [] isprime = new boolean[MAX + 1];
		Arrays.fill(isprime, true);
		isprime[0] = false;
		isprime[1] = false;
		for(int i = 0; i * i <= MAX; i++){
			if(isprime[i]){
				for(int j = i * 2; j <= MAX; j += i){
					isprime[j] = false;
				}
			}
		}
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int count = 0;
			for(int i = 2; i <= n / 2; i++){
				if(isprime[i] && isprime[n - i]){
					count++;
				}
			}
			System.out.println(count);
		}
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstdio>

using namespace std;

int main()
{
    double a, b, c;

    cin >> a >> b >> c;

    double s = a * b * sin(c/180 * M_PI) / 2;
    double l = a + b + sqrt(pow(a, 2) + pow(b, 2) - 2*a*b*cos(c/180 * M_PI));
    double h = 2*s/a;

    printf("%.8lf\n%.8lf\n%.8lf\n", s, l, h);
}



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

using namespace std;

#define PRB ""
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define EP emplace_back
#define SZ(A) (int) A.size()
#define FOR(i, l, r) for (int i = l; i <= r; i++)
#define FORD(i, r, l) for (int i = r; i >= l; i--)
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long ll;
typedef pair<int, int> ii;
typedef unsigned long long ull;

int main(){
    int n, a[111111], f[111111], res = 0;
    cin >> n;
    FOR(i, 1, n) cin >> a[i];
    f[1] = 0;
    FOR(i, 2, n)
        if (a[i] <= a[i - 1])
            f[i] = f[i - 1] + 1;
        else f[i] = 0;
    FOR(i, 1, n)
        res = max(res, f[i]);
    cout << res;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };


void solve() {
	ll n, a, b; cin >> n >> a >> b;
	ll d = n / (a + b);
	ll ans = d * a;
	ll r = n % (a + b);
	ans += min(r, a);
	cout << ans << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
const int INF = 1e9;
using namespace std;

signed main() {
    int N;
    string S;
    cin >> N >> S;
    int ans=INF;
    int w[N+10]={0},b[N+10]={0};
    rep(i,N){
        if(S[i]=='.')  {w[i+1]=w[i]+1; b[i+1]=b[i];}
        else {b[i+1]=b[i]+1; w[i+1]=w[i];}
    }
    rep(i,N+1){
        ans=min(ans,b[i]+w[N]-w[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716
#include <stdio.h>
#include <algorithm>
using namespace std;
struct A{int w,d,l,pos;A() {w=d=l=0;}}RB[105];bool operator !=(A a, A b) {return a.w*3+a.d!=b.w*3+b.d;}bool operator <(A a, A b) {return a.w*3+a.d<b.w*3+b.d;}
int main() {
    int N,i,j,l,r,a,b,ans[105];scanf("%d",&N);for (i=0,j=(N*N-N)/2;i<j;i++) {scanf("%d %d %d %d",&l,&r,&a,&b);if (a>b) RB[l].w++,RB[r].l++; else if (a==b) RB[l].d++,RB[r].d++; else RB[l].l++,RB[r].w++;}
    for (i=1;i<=N;i++) RB[i].pos=i;sort(RB+1,RB+N+1);for (l=1,j=1,i=N;i;i--) 
	if (RB[i]!=RB[i-1]) {for (r=0;r<j;r++) ans[RB[i+r].pos]=l;l+=j,j=1;} else j++;for (i=1;i<=N;i++) printf("%d\n",ans[i]);return 0;}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
int main(void){
char x[125],y[125],z[100];
int i=0,k=0,a,b;
gets(x);
while(x[i]!=' '){
 y[i]=x[i];
 i++;
};
a=atoi(y);
i++;
while(x[i]!='\0'){
 z[k]=x[i];
 k++;
 i++;
};
b=atoi(z);
printf("%d %d\n",a*b,(a+b)*2);
return 0;
};

Measured memory_bytes: 524
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var h = int.Parse(line[0]);
            var w = int.Parse(line[1]);
            if (h == 0 && w == 0) break;
            var map = new int[h, w];
            for (int i = 0; i < h; i++)
            {
                var s = Console.ReadLine().Trim();
                for (int j = 0; j < w; j++)
                    if (s[j] == '^') map[i, j] = 1;
                    else if (s[j] == '>') map[i, j] = 2;
                    else if (s[j] == 'v') map[i, j] = 3;
                    else if (s[j] == '<') map[i, j] = 4;
            }
            gowithTile(map);
        }
    }
    public static void gowithTile (int[,] map)
    {
        var h = map.GetLength(0);   var w = map.GetLength(1);
        var map2 = new int[h, w];
        var x = 0;  var y = 0;  var loop = false;
        while (true)
        {
            if (map2[x,y] == 1) { loop = true; break; }
            map2[x, y] = 1;
            if (map[x, y] == 1) x--;
            else if (map[x, y] == 2) y++;
            else if (map[x, y] == 3) x++;
            else if (map[x, y] == 4) y--;
            else break;
        }
        if (loop) Console.WriteLine("LOOP");
        else Console.WriteLine("{0} {1}", y,x);
    }
}

Measured memory_bytes: 9148
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for B - Toll Gates
	var N, M, X int
	fmt.Scanf("%d %d %d", &N, &M, &X)

	A := make(map[int]int, M)
	var temp int
	for i := 0; i < M; i++ {
		fmt.Scanf("%d", &temp)
		A[temp]++
	}

	var cost1 int
	for i := X; i < N; i++ {
		if A[i] > 0 {
			cost1++
		}
	}

	var cost2 int
	for i := X; i > 0; i-- {
		if A[i] > 0 {
			cost2++
		}
	}

	fmt.Println(math.Min(float64(cost1), float64(cost2)))
}


Measured memory_bytes: 1844
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var a = int.Parse(line[1]);
        var b = int.Parse(line[2]);
        var count = 0;
        for (int i = 0; i < n; i++)
        {
            var t = int.Parse(Console.ReadLine().Trim());
            if (t < a | t >= b) count++;
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 13140
#include <stdio.h>

int main(void) {
  int H, W;
  while(1) {
    scanf("%d %d", &H, &W);
    if (H == 0 && W ==0) break;
    int i, j;
    for (i = 0; i < H; i++) {
      for (j = 0; j < W; j++) {
        if (i == 0 || i == H - 1 || j == 0 || j == W - 1) {
          putchar('#');
        } else {
          putchar('.');
        }
      }
      putchar('\n');
    }
    putchar('\n');
  }
  return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <limits>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
 


struct PrimeNumbers {
    vector<bool> sieve;
    vector<int> prime;
    PrimeNumbers(int n) : sieve(n+1,true) {
        sieve[0] = sieve[1] = false;
        for(long long i=2; i<sieve.size(); i++) {
            if(sieve[i]) {
                prime.push_back((int)i);
                for(long long j=i*i; j<sieve.size(); j+=i) {
                    sieve[j] = false;
                }
            }
        }
    }
    bool isPrime(int n) { return sieve[n]; }
    int size(void) { return (int)prime.size(); }
    int  operator [] (int n) { return  prime[n]; }
    bool operator == (int n) { return  sieve[n]; }
    bool operator != (int n) { return !sieve[n]; }
};

int main() {

    PrimeNumbers p(3000000);
    
    int n; 
    while(cin >> n) {
        if(n==0)break;
        ll sum = 0;
        REP(i,n)sum += p[i];
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3984
// Problem : A - Station and Bus
// Contest : AtCoder Beginner Contest 158
// URL : https://atcoder.jp/contests/abc158/tasks/abc158_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int ans = 0;
    for(auto e : s)
    {
    	if(e == 'A') ans++;
    }
    if(ans > 0 && ans < 3) cout <<"Yes";
    else cout <<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {  
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 1; i <= a; i++) {
        if ((c + i * b) % a == 0) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}




Measured memory_bytes: 3600
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i:
        x, y = a[0]
        if x >= c:
            break
        if y > i:
            heapq.heapreplace(a, (x, y - i))
            i = 0
        else:
            heapq.heappop(a)
            i -= y
    heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))


Measured memory_bytes: 21548
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

void solve() {
    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No") << "\n";
}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    solve();

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases


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

inline void chmin(long long &x, long long y) {
    if (x > y) x = y;
}

struct RMQ {
    int N;
    vector<long long> seg;

    RMQ(int n) {
        N = 1 << (int)log2(n * 2 - 1);
        seg.resize(N * 2, 1e18);
    }

    void update(int k, long long v) {
        for (seg[k += N] = v; k > 1; k >>= 1) {
            seg[k >> 1] = min(seg[k], seg[k ^ 1]);
        }
    }

    long long minimum(int l, int r) {
        long long res = 1e18;
        for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
            if (l & 1) res = min(res, seg[l++]);
            if (r & 1) res = min(res, seg[--r]);
        }
        return res;
    }
};

long long dp[101010];

int main() {
    int n;
    long long T, E;
    cin >> n >> E >> T;
    vector<long long> x(n), d(n), ds(n + 1);
    for (int i = 0; i < n; i++) scanf("%lld", &x[i]);
    for (int i = 0; i < n - 1; i++) d[i] = x[i + 1] - x[i];
    for (int i = 0; i < n; i++) ds[i + 1] = ds[i] + d[i];

    fill_n(dp, 101010, 1e17);
    dp[0] = 0;

    RMQ L(n + 1), R(n + 1);
    L.update(0, 0);
    R.update(0, 0);

    for (int i = 1; i <= n; i++) {
        int ok = i;
        int ng = -1;
        while (ok - ng > 1) {
            int mid = (ok + ng) / 2;
            if (T >= 2 * (ds[i - 1] - ds[mid])) ok = mid;
            else ng = mid;
        }
        chmin(dp[i], L.minimum(ok, i) + T);
        chmin(dp[i], R.minimum(0, ok) + 2 * ds[i - 1]);
        L.update(i, dp[i]);
        R.update(i, dp[i] - 2 * ds[i]);
    }

    cout << dp[n] + E << endl;
}

Measured memory_bytes: 7552
#include <stdio.h>
int main()
{
    int n, x, i, j, k, count, tmp;
    while (scanf("%d %d", &n, &x), n + x != 0)
    {
        count = tmp = 0;
        for (i = 1; i < n - 1; i++)
        {
            for (j = i + 1; j < n; j++)
            {
                for (k = j + 1; k <= n; k++)
                {
                    if (i + j + k == x)
                        count++;
                }
            }
        }
        printf("%d\n", count);
    }
    return 0;
}



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

#include <cmath>

int main()
{
	long N, M;
	cin >> N >> M;

	/*
	for (int i = int(sqrt(M)); i > 0; i--)
	{
		if (M % i == 0)
		{
			long remainder = M / i;
			if (remainder >= N)
			{
				cout << i << endl;
				return 0;
			}
		}
	}
	*/
	/*
	for (long i = M; i > 0; i--)
	{
		if (M % i == 0)
		{
			long remainder = M / i;
			if (remainder >= N)
			{
				cout << i << endl;
				return 0;
			}
		}
	}
	*/
	int max = 1;
	for (int i = 1; i <= int(sqrt(M)); i++)
	{
		if (M % i == 0)
		{
			/*
			long remainder = M / i;
			if (remainder >= N)
			{
				cout << i << endl;
				return 0;
			}
			*/
			if (i >= N)
			{
				cout << M / i << endl;
				return 0;
			}
			else if ((i > max) && (M / i >= N))
			{
				max = i;
			}
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
P RetVec(P x, P y) { return P(x.first - y.first, x.second - y.second); }
int main() {
  int N;
  cin >> N;
  vector<P> Z(N);
  REP(i, N) cin >> Z[i].first >> Z[i].second;
  ll ans = N;
  REP(i, N) for (int j = 0; j < N; j++) {
    if (i == j) continue;
    P p = RetVec(Z[i], Z[j]);
    ll tmp = 0;
    REP(k, N) for (int l = 0; l < N; l++) {
      if (k == l) continue;
      if (RetVec(Z[k], Z[l]) == p) {
        tmp++;
      }
    }
    ans = min(ans, N - tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

ld PI = acos(-1);
int main()
{
	boost;
	ld a, b, h, m;
	cin >> a >> b >> h >> m;
	ld x = h * 60 + m;
	ld hr = 0.5 * x;
	ld min = 6.0 * m;
	ld df = abs(hr - min);
	df *=  (PI / 180.0);
	ld c = sqrt((a * a) + (b * b) - (2 * a * b * cos(df)));
	cout << fixed << setprecision(10) << c << '\n';
	
}


Measured memory_bytes: 4160
import java.util.InputMismatchException;
import java.util.Scanner;

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

		try {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int r;

			while((r = x % y) != 0) {
				x = y;
				y = r;
			}

			System.out.println(y);
		} catch(InputMismatchException ex) {
			ex.printStackTrace();
		} finally {
			sc.close();
		}
	}
}



Measured memory_bytes: 26248
#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;
	int odd = 1;
	rep(i, N) {
		int A;
		cin >> A;
		if (A % 2 == 0) odd *= 2;
	}
	cout << pow(3, N) - odd << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include<math.h>
#include<bits/stdc++.h>
#include <map>
#include <algorithm>
#include <cmath>



using namespace std;
const int INF = 1e9+7;
int solve(int h[],int n){
    int dp[n+1];
    for(int i=0;i<n+1;i++)dp[i] = INF;
    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    for(int i=2;i<n+1;i++){
        dp[i] = min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
    }
    return dp[n-1];
}

int main(){
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)cin>>h[i];
    cout<<solve(h,n)<<endl;

}


Measured memory_bytes: 4360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    for (int i=s.length()/2-1;i>=0;i--)
    {
        bool ok = true;
        // mozinonagasawositeisita
        rep(j,i) {
            if (s[j]!=s[j+i]) ok = false;
        }
        if (ok)
        {
            cout << i * 2 << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
int main(){
    fast();

/* you get what you work for not what you wish for */
    inp(n);
    inpv(a, n);
    inpv(b, n);
    inpv(c, n-1);
    ll ans = b[a[0]-1];
    for(int i=1; i<n; i++){
        ans += b[a[i]-1];
        if(a[i]==a[i-1]+1){
            ans += c[a[i-1]-1];
        }
    }
    out(ans);
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 100000 + 10;
typedef long long LL;

int n;
int a[N], dp[N];
LL sum[N];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i ++) {
        scanf("%d", &a[i]);
    }
    sort(a+1, a+1+n);
    for (int i = 1; i <= n; i ++) {
        sum[i] = sum[i-1] + a[i];
    }
    int ans = 1; dp[n] = 1;
    for (int i = n - 1; i >= 1; i --) {
        if (sum[i] * 2 >= a[i + 1]) {
            dp[i] = dp[i+1];
        }
        if (dp[i]) ans ++;
    }
    printf("%d\n", ans);

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  string Sa,Sb,Sc;
  char card;
  cin >> Sa >> Sb >> Sc;
  int a = 0,b = 0, c = 0;
  card = Sa.at(a);
  a++;
  cin >> Sa >> Sb >> Sc;
  while(1){
    switch(card){
      case 'a':
        if(Sa[a] =='\0'){
          cout << "A" <<endl;
          return 0;
        }
        else{
          card = Sa.at(a);
          a++;
        }
        break;
        
      case 'b':
        if(Sb[b] =='\0'){
          cout << "B" <<endl;
          return 0;
        }
        else{
          card = Sb.at(b);
          b++;
        }
        break;
        
      case 'c':
        if(Sc[c] =='\0'){
          cout << "C" <<endl;
          return 0;
        }
        else{
          card = Sc.at(c);
          c++;
        }
        break;
    }
  }
}
  


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

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

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end(), greater<ll>());
    ll ans = a[0];
    for(ll i = 1; i < n - 1; i++) {
        ans += a[(i + 1) / 2];
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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



int main() {
    using vi = vector<int>;
    
    int n;
    cin >> n;
    vi a(n-1);
    vector<vi> b(n+1);
    rep(i,n-1){
        cin >> a[i];
        b[a[i]].push_back(i+2);
    }

    rep(i,n){
        cout << b[i+1].size() << endl;
    }

}

Measured memory_bytes: 14876
while True:
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        break
    elif m==-1 or f==-1:
        print("F")
    elif m+f>=80:
        print("A")
    elif 80>m+f>=65:
        print("B")
    elif 65>m+f>=50:
        print("C")
    elif 50>m+f>=30:
        if r>=50:
            print("C")
        else:
            print("D")
    else:
        print("F")
 


Measured memory_bytes: 5592
#include<stdio.h>

int main()
{
    int N,R,I;
    scanf("%d %d",&N,&R);
    if(N<=100 && N>=1)
    {
        if(R<=4111 && R>=0)
        {
            if(N<=10)
            {
                I=R+100*(10-N);
                printf("%d",I);
            }
            else
                printf("%d",R);

        }
    }

        return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int ans = 0;
  
  for(int A = 1; A < N; A++){
    int x = (N-1) / A;
    if(x == A){
      ans++;
    }else if(x > A){
      ans += 2 * (x - A) + 1;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3648
char W[9],V[9];Z[8],S,N,T,P,M;main(i,j,k,l,r,d){for(;scanf("%d%d%d%s%s%d%d",&S,&N,&T,W,V,&P,&M),S;printf("%.10f\n",1-pow(1-1.0/P,N*r))){
	memset(Z,0,sizeof(Z));
	l=*W=='A'?2:1;
	d=24*60*(*W=='A'?1:7);
	if(*V=='A')for(i=0;i<l;i++)Z[i*4]=Z[i*4+1]=Z[i*4+2]=Z[i*4+3]=1;
	if(*V=='D')for(i=0;i<l;i++)Z[i*4+1]=Z[i*4+2]=1;
	if(*V=='N')for(i=0;i<l;i++)Z[i*4]=Z[i*4+3]=1;
	for(r=j=0;j<24*60;r=r>l?r:l,j++)for(k=j,l=i=0;i<M;k=(k+T)%d,i++)if(k<24*60)l+=Z[(k+S)%(48*60)/360]&Z[k/360];
}exit(0);}

Measured memory_bytes: 692
#abc132_b.py
def is_center(A,i):
    if (A[i-1]<A[i] and A[i]<A[i+1]) or (A[i-1]>A[i] and A[i]>A[i+1]):
        return True
    return False

N = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(1,N-1):
    if is_center(A,i):
        cnt+= 1
print(cnt)

Measured memory_bytes: 38256
import numpy as np
N=int(input())
lst = []
for i in range(N):
    a = int(input())
    lst.append(a)

fst = np.max(lst)
fst_idx = np.argmax(lst)
lst.remove(fst)
snd = np.max(lst)

for i in range(N):
    if i == fst_idx:
        print(snd)
    else:
        print(fst)



Measured memory_bytes: 22824
#include <cstdio>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

bool ary[31];

int main() {
	memset(ary, -1, sizeof ary);
	rep(i, 28) {
		int t;
		scanf(" %d", &t);
		ary[t] = false;
	}
	for(int i = 1; i <= 30; i++) {
		if(ary[i])
			printf("%d\n", i);
	}
	return 0;
}

Measured memory_bytes: 0
import numpy as np
WH='.'
BK='#'
x=input()
x=x.split()
H=int(x[0])
W=int(x[1])
a=[[] for i in range(H)]
num=[]
numnum=0
for i in range(H):
    x=input()
    for j in range(W):
        a[i].append(x[j])
for i in range(H):
    flag=0
    for j in range(W):
        if a[i][j]==WH:
            flag=flag+1
        else:
            flag=flag-1
    if flag==W:
        num.append(i)
        numnum=numnum+1
for i in range(numnum):
    a.pop(num[i]-i)
H=H-numnum
a_n=np.array(a)
tr=a_n.T
a=tr.tolist()
num=[]
numnum=0
num_num=0
for i in range(W):
    flag=0
    for j in range(H):
        if a[i][j]==WH:
            flag=flag+1
        else:
            flag=flag-1
    if flag==H:
        num.append(i)
        numnum=numnum+1
        flag=0
    else:
        flag=0
for i in range(numnum):
    a.pop(num[i]-i)
W=W-numnum
a_n=np.array(a)
a=a_n.T
for i in range(H):
    ans=''
    for j in range(W):
        ans=ans+a[i][j]
    print(ans)

Measured memory_bytes: 12512
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int X[100], n;
ll memo[60][60][3000];
ll rec(int i, int r, int sum) {
    if (r == 0 && sum == 0) return 1;
    if (i >= n || r < 0 || sum < 0) return 0;
    if (memo[i][r][sum] != -1) return memo[i][r][sum];
    return memo[i][r][sum] = rec(i + 1, r, sum) + rec(i + 1, r - 1, sum - X[i]);
}

int main()
{
    fill(memo[0][0], memo[59][59]+3000, -1);
    int a; cin >> n >> a;
    loop (n, i) cin >> X[i];

    ll ans = 0;
    loop (n, i) {
        ans += rec(0, i + 1, a * (i + 1));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 84608
// vim: shiftwidth=2 expandtab foldmethod=marker

// include {{{
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <utility>
#include <cstdlib>
#include <random>
// }}}

// debug(...) {{{
#ifdef LOCAL_DEBUG
#include "./debug.h"
#else
#define debug(...)
#define debugn(...)
#define debug_reset()
#endif

#include <cstdio>

template<class T>
std::string bin(int bits, const T& x) {
  char buf[bits + 1];
  buf[bits] = '\0';
  for(int i = 0; i < bits; i++) {
    if((x >> i) & 1) {
      buf[bits - i - 1] = '1';
    } else {
      buf[bits - i - 1] = '0';
    }
  }
  return std::string(buf);
}
std::string bin(int x) {
  if(x < 0) return bin(32, x);
  for(int i = 4; i < 31; i++) {
    int y = 1 << i;
    if(x < y) return bin(i, x);
  }
  return bin(32, x);
}
// }}}

// misc {{{
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

template<class T>
void sort(T& arr) {
  std::sort(arr.begin(), arr.end());
}
template<class T, class By>
void sort_by(T& arr, By by) {
  std::sort(arr.begin(), arr.end(), [by](auto l, auto r){return  by(l) < by(r); });
}

template<class T>
void reverse(T& arr) {
  std::reverse(arr.begin(), arr.end());
}

// }}}

// main {{{
void solve();
int main() {
  solve();
}
// }}}

void solve() {
  string S, T;
  cin >> S >> T;
  int ans = 0;
  rep(i, 3) {
    if(S[i] == T[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  string s; ll k;
  cin >> s >> k;
  for(int i = 0; i < k; i++){
    if(s[i] != '1'){
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans[1010][1010];
int main(){
	ll h,w,a,b;
	cin>>h>>w>>a>>b;
	for(int i=1;i<=b;i++){
		for(int j=a+1;j<=w;j++)ans[i][j]=1;
	}
	for(int i=b+1;i<=h;i++){
		for(int j=1;j<=a;j++)ans[i][j]=1;
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++)cout<<ans[i][j];
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 10544