akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 1000000001
void mergesort(int *,int ,int );
void merge(int *,int ,int ,int );
int count=0,n,Left[250001],Right[250001],i;

int main(void){
  int S[500000];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);
  mergesort(S,0,n);

  for(i=0;i<n;i++){
    printf("%d",S[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n%d\n",count);
  return 0;
}
void mergesort(int *S,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(S,left,mid);
    mergesort(S,mid,right);
    merge(S,left,mid,right);
  }
}
void merge(int *S,int left,int mid,int right){
  int n1=mid-left,n2=right-mid,j,k;
  for(i=0;i<n1;i++)
    Left[i]=S[left+i];//not include mid
  for(i=0;i<n2;i++)
    Right[i]=S[mid+i];//include mid
  Left[n1]=MAX;
  Right[n2]=MAX;
  for(i=0,j=0,k=left;k<right;k++){
    if(Left[j]>Right[i])S[k]=Right[i++];
    else S[k]=Left[j++];
  }
  count+=right-left;
}


Measured memory_bytes: 5628
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int main()
{
    string w, a;
    int p = 0;
    cin >> w;
    for(int j = 0; j < w.size(); j++)
        {
            int k = 0;
    for(int i = 0; i < w.size(); i++)
        {
            if(w[j] == w[i])
                k++;
        }
        if(k % 2 == 1)
            p++;
            }
        if(p == 0)
            cout << "Yes";
        else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
const long long llnrm=LLONG_MAX;
const int nrm=INT_MAX;
const int nrn=INT_MIN;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int ans,n;
string s;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>s;
    for(int i=0;i<s.size();i++) if(s[i]=='1') ans++;
    cout<<ans<<endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a;
  rep(i, n) {
    int x;
    cin >> x;
    a.push_back(x);
  }

  int tmp = 1;
  int ans = 0;
  bool ok = false;

  rep(i, n) {
    if (a[i] != tmp) {
      ans++;
      continue;
    } else {
      ok = true;
      tmp++;
    }
  }

  if (ok) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  };
  return 0;
}

Measured memory_bytes: 1400
#coding utf-8
DG = input().split()
D = int(DG[0])
G = int(DG[1])
p = [0 for i in range(D)]
c = [0 for i in range(D)]
for i in range(D):
  pc = input().split()
  p[i] = int(pc[0])
  c[i] = int(pc[1])

x = 2**D
ans = 10000
for i in range(x):
  Gt = 0
  tmp = 0
  y = bin(i)[2:]
  y ="0"*(D-len(y))+y
  for j in range(D):
    if y[j:j+1] =="1":
      Gt +=(j+1)*p[j]*100 +c[j]
      tmp += p[j]
  if G>Gt:
    for j in reversed(range(0,D)):
      if G<=Gt:
        break
      if y[j:j+1] =="0":
        for k in range(p[j]):
          Gt += (j+1)*100
          tmp +=1
          if G <=Gt:
            break
  if tmp<ans and G<=Gt:
    ans = tmp
  
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	ll k;
	string s;

	cin >> s >> k;

	if (s[0] == '1' && k == 1) {
		cout << 1 << endl;
	}
	else if (s[0] == '1' && k >= 2) {

		int num = -1;

		for (int i = 0; i < k; i++) {
			if (s[i] != '1') {
				num = s[i] - '0';
				break;
			}
		}

		if (num == -1) {
			cout << 1 << endl;
		}
		else {
			cout << num << endl;
		}
		
	}
	else {
		cout << s[0] << endl;
	}



	return 0;
}

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

int main () 
{
    int A, B, K;
    
    std::cin >> A >> B >> K;
    
    int length = B - A +1;
    
    for (int i = A; i <= B; i++) 
    {
        if (i - A + 1 <= K) std::cout << i << std::endl;
        else if (length - K < i - A + 1 ) std::cout << i << std::endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
vector<int> v;
void putv(){
	for(int i=0;i<v.size();i++){
		if(v[i]==-1)cout<<"[";
		if(v[i]==-2)cout<<"]";
		if(v[i]==0)cout<<" ";
		if(v[i]>0)cout<<v[i];
	}
	cout<<endl;
}
int DFS(int x){
	vector<int> lis;
	int pnt=x,cnt=0;
	while(true){
		pnt++;
		if(v[pnt]==-2)break;
		if(v[pnt]==-1)lis.push_back(DFS(pnt));
		if(v[pnt]>0)cnt++;
	}
	v[x]=0,v[pnt]=0;
	if(cnt==1){
		//cout<<"%";
		return v[pnt-1]/2+1;
	}cnt=0;
	
	//cout<<"#"<<x<<" ";
	//for(int i=0;i<lis.size();i++)cout<<lis[i]<<" ";cout<<endl;
	//putv();
	
	sort(lis.begin(),lis.end());
	for(int i=0;i<=lis.size()/2;i++)cnt+=lis[i];
	//cout<<"&"<<cnt<<endl;
	return cnt;
}
int main(){
	int n;cin>>n;string s;
	
	while(n--){
		cin>>s;v.clear();
		int cnt=0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='[')v.push_back(-1);
			if(s[i]==']'){
				if(cnt>0)v.push_back(cnt);
				v.push_back(-2);cnt=0;
			}
			if(s[i]>='0'&&s[i]<='9'){
				cnt*=10;cnt+=s[i]-'0';
			}
		}
		//putv();
		cout<<DFS(0)<<endl;
		//putv();
	}
	return 0;
}

Measured memory_bytes: 3184
/**
 * Created by hiroqn on 13/10/06.
 */
var fs = require('fs'),
    length = fs.fstatSync(process.stdin.fd).size,
    buffer = new Buffer(length),
    bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
    input = buffer.toString('utf8', 0, bytesRead).split('\n');

var CODE_A = 'A'.charCodeAt(0),
    CODE_Z = 'Z'.charCodeAt(0),
    CODE_a = 'a'.charCodeAt(0),
    CODE_z = 'z'.charCodeAt(0),
    DIFF = CODE_Z - CODE_a;

function solve(n, kList, str) {
  var k = 0, code, result = '';
  for (var i = 0, l = str.length; i < l; i++) {
    code = str.charCodeAt(i);
    if (CODE_A <= code && code <= CODE_Z) {
      code -= CODE_A;// 0->A,25->Z
    } else {
      code = code - CODE_a + 26;
    }
//    console.log(code)
    if (code < kList[k]) {
      code = code + 52 - kList[k];
    } else {
      code -= kList[k];
    }
    if (code < 26) {
      result += String.fromCharCode(code + CODE_A);
    } else {
      result += String.fromCharCode(code - 26 + CODE_a);
    }
//    code -= kList[k];
    k++;
    k %= n;

  }
  return result;
}

while (input[0] !== '0') {
  var nKeys = input.shift() - 0,
      keyList = input.shift().split(' ').map(function (i) {
        return i - 0;
      }),
      str = input.shift();
  console.log(solve(nKeys, keyList, str));
}

Measured memory_bytes: 9548
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int a,b;
    cin>>a>>b;
    if(a<=8&&b<=8) cout<<"Yay!"<<endl;
    else cout<<":("<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		long X = in.nextLong();
		long Y = in.nextLong();
		int counter = 0;
		
		for(long i=X; i<=Y; i*=2) {
			counter += 1;
		}
		System.out.println(counter);
	}

}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
int sum[300000], w[300000];
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\Users\Joeon\Desktop\IN.txt", "r", stdin);
//		freopen("C:\Users\Joeon\Desktop\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, fmax = -1, at;
	cin>>n>>k;
	rep(i, 0, n) cin>>w[i];
	rep(i, 0, k) sum[0] += w[i];
	hrp(i, 1, n-k) sum[i] = sum[i-1]-w[i-1]+w[i+k-1];
	hrp(i, 0, n-k) if (sum[i] > fmax) fmax = sum[i], at = i;
	double ans = 0.0;
	rep(i, at, at+k) hrp(j, 1, w[i]) ans += 1.0*j/w[i];
	printf("%.9lf\n", ans);
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

Measured memory_bytes: 3840
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
    [n, k] <- map (fst . fromJust . B.readInteger) . B.words <$> B.getLine
    pos <- replicateM (fromIntegral n) ((\[a,b]->(a,b)) . map (fst . fromJust . B.readInteger) . B.words <$> B.getLine)
    print . minimum $ concatMap
        (\(p,p')-> [(fst p'-fst p)*(snd p'-snd p)|innerPoints pos p p' >= k])
        [((x,y), (x',y'))|x<-map fst pos, x'<-map fst pos, y<-map snd pos, y'<- map snd pos, x<=x', y<=y'] 
    
innerPoints :: [(Integer, Integer)] -> (Integer, Integer) -> (Integer, Integer) -> Integer
innerPoints pos (x,y) (x',y') = sum . map (\x->if x then 1 else 0) $ flip map pos
    (\(x'',y'')->x<=x'' && x''<=x' && y<=y'' && y''<=y')


Measured memory_bytes: 2428
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

#define INF 1000000001
#define LINF 1000000000000000001

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

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

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

int n, m, a[1001], b[1001], c[1001], dp[101][101];
bool d[1001] = {0};
vector<P> v[101];

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i] >> c[i];
		v[a[i]].push_back(P(b[i], c[i]));
		v[b[i]].push_back(P(a[i], c[i]));
	}
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			dp[i][j] = INF;
			if(i == j)
				dp[i][j] = 0;
		}
	}
	
	for(int i = 1; i <= n; i++){
		queue<int> q;
		q.push(i);
		while(q.size()){
			int p = q.front();
			q.pop();
			for(int j = 0; j < v[p].size(); j++){
				if(dp[i][v[p][j].first] > dp[i][p] + v[p][j].second){
					dp[i][v[p][j].first] = dp[i][p] + v[p][j].second;
					q.push(v[p][j].first);
				}
			}
		}
	}
	int cnt = 0;
	for(int i = 0; i < m; i++){
		if(dp[a[i]][b[i]] < c[i] && dp[b[i]][a[i]] < c[i])
			cnt++;
	}
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	int W,H,x,y,r;
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	if(x >= r && y >= r && (H - r) >= y && (W - r) >= x)
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
} 


Measured memory_bytes: 2144
#include<bits/stdc++.h>
#define line cout<<endl;
#define space cout<<" ";
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI 3.141592653589793238
typedef long long int ll;

using namespace std;

const int N = 1e9+7;

vector<ll> v(100005);
ll dp[100005];

ll findans(ll n)
{
    if(n<0)
    {
        return INT_MAX;
    }
    if(n==0)
    {
        return 0;
    }

    if(dp[n]!=-1)
    {
        return dp[n];
    }

    return dp[n] =  min(abs(v[n-2]-v[n])+findans(n-2),abs(v[n-1]-v[n])+findans(n-1));

}

void solve()
{
    memset(dp,-1,sizeof(dp));
    ll n;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }

    ll ans = findans(n-1);
    cout<<ans;

}


int main()
{
   ll t;
   t = 1;
  // cin>>t;

   while(t--)
   {
       solve();
       cout<<endl;
   }




}













Measured memory_bytes: 9496
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_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(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n, a, x, y, cnt, mx = -INF;
    bool flag;
    vector<pair<int, int>> said[22];
    cin>>n;
    rep(i, n) {
        cin>>a;
        while(a--) {
            cin>>x>>y;
            x--;
            said[i].push_back({x, y});
        }
    }
    rep(i, pow(2, n)) {
        int peop = i;
        flag = true;
        rep(j, n) {
            if((peop >> j) & 1) {
                each(p, said[j]) {
                    if((peop >> p.first & 1) != p.second) {
                        flag = false;
                    }
                }
                
            }
        }
        if(flag) {
            cnt = 0;
            while(peop > 0) {
                if(peop & 1) cnt++;
                peop >>= 1;
            }
            chmax(mx, cnt);
        }
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int N = 0,A[100],i = 0,j = 0,k = 0,l = 0,m = 0,flag = 0;

  scanf("%d",&N);

  for(i = 0;i < N;i++)
    {
      scanf("%d",&A[i]);
    }
  while(j < N-1)
    {
    for(k = N-1;k >= j+1;--k)
      {
	if(A[k] < A[k-1])
	  {
	    l  = A[k-1];
	    A[k-1] = A[k];
	    A[k] = l;
	    flag += 1;
	  }
      }
    ++j;
    }
  for(m = 0;m < N;m++)
    {
      if(m == N-1)
	{
	  printf("%d\n",A[m]);
	}
      else if(m < N-1)
	{
      printf("%d ",A[m]);
	}
    }
  printf("%d\n",flag);
  return 0;
}



Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		double N = stdIn.nextDouble();
		double ans = 0;
		if(N % 2 == 0){
			ans = 0.5;
		}
		else{
			ans = (N + 1) / 2 / N;
		}
		System.out.printf("%.10f",ans);

		stdIn.close();
	}
}


Measured memory_bytes: 37608
n, k = gets.split.map(&:to_i)
s = gets.chomp.chars

first = 1
while first < n && k > 0
    if s[first - 1] != s[first] then
        last = first
        while last < n - 1
            if s[last] == s[first] && s[last + 1] == s[first - 1] then
                break
            end
            last += 1
        end
        for i in first.upto(last)
            if s[i] == 'L' then
                s[i] = 'R'
            else
                s[i] = 'L'
            end
        end
        k -= 1
    end
    first += 1
end

count = 0
for i in 1.upto(n - 1)
    if s[i - 1] != s[i] then
        count += 1
    end
end

puts n - 1 - count


Measured memory_bytes: 11772
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
char c1[3],c2[3];
REP(i,3) cin >> c1[i];
REP(j,3) cin >> c2[j];
int flg = -1;
REP(i,3) {
  if(c1[i] != c2[2-i]) flg++;
}
if(flg==-1) {
  cout << "YES" << endl;
} else {
  cout << "NO" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n;cin>>n;
    vin a(n);
    rep(i,n)cin>>a[i];
    int sum=0;
    rep(i,n)sum+=a[i]-1;
    cout<<sum<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {


	final int MOD = 1000000007;


	public static void main(String[] args) {

		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

		int n = sc.nextInt();
//		int k = sc.nextInt();

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

		String s = String.valueOf(n);
		String[] strArray = s.split("");

		for(int i=0; i < s.length(); i++) {
			if(strArray[i].equals("7")) {
				f = true;
			}
		}


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

		if(f) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

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

Measured memory_bytes: 35792
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int a,b;
    scanf("%d%d", &a, &b);
    if(a<=0 && b>=0) {
        printf("Zero\n"); return 0;
    }
    if(a>0) {
        printf("Positive\n"); return 0;
    }
    if((b-a+1)%2) {
        printf("Negative\n");
    }
    else {
        printf("Positive\n");
    }

    return 0;
}


Measured memory_bytes: 128
n = int(input())
v_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
ans = 0

for i in range(n):
    if v_list[i] - c_list[i] > 0:
        ans += v_list[i] - c_list[i]

print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class Program
	{
		static long mod = 1000000007;   // 10^9 + 7

		static void Main(string[] args)
		{
			int N = int.Parse(Console.ReadLine());
			double[] vs = Console.ReadLine().Split().Select(double.Parse).ToArray();

			PriorityQueue<double> queue = new PriorityQueue<double>();
			foreach (var item in vs) {
				queue.Enqueue(item);
			}

			while (queue.Count > 1) {
				double x = queue.Dequeue();
				double y = queue.Dequeue();
				double a = (x + y) / 2;
				queue.Enqueue(a);
			}

			Console.WriteLine(queue.Peek());
		}
	}

	#region 優先度付きキュー

	public class PriorityQueue<T> where T : IComparable
	{
		private readonly List<T> _Heap;
		private readonly Comparison<T> _Compare;

		public int Count { get { return _Heap.Count; } }

		public PriorityQueue() : this(false) { }
		public PriorityQueue(bool reverse)
		{
			_Heap = new List<T>();
			if (!reverse) {
				_Compare = Comparer<T>.Default.Compare;
			} else {
				_Compare = (T x, T y) => Comparer<T>.Default.Compare(y, x);
			}
		}

		public void Enqueue(T item)
		{
			_Heap.Add(item);
			int i = _Heap.Count - 1;
			while (i > 0) {
				int p = (i - 1) / 2;
				if (_Compare(_Heap[p], item) <= 0) {
					break;
				}
				_Heap[i] = _Heap[p];
				i = p;
			}
			_Heap[i] = item;
		}

		public T Dequeue()
		{
			int size = _Heap.Count - 1;
			T ret = _Heap[0];
			T x = _Heap[size];
			int i = 0;
			while (i * 2 + 1 < size) {
				var a = i * 2 + 1;
				var b = i * 2 + 2;
				if (b < size && _Compare(_Heap[b], _Heap[a]) < 0) {
					a = b;
				}
				if (_Compare(_Heap[a], x) >= 0) {
					break;
				}
				_Heap[i] = _Heap[a];
				i = a;
			}
			_Heap[i] = x;
			_Heap.RemoveAt(size);
			return ret;
		}

		public T Peek()
		{
			return _Heap[0];
		}

		public void Clear()
		{
			_Heap.Clear();
		}

		public List<T>.Enumerator GetEnumerator()
		{
			return _Heap.GetEnumerator();
		}

		public override string ToString()
		{
			return string.Join(" ", _Heap);
		}
	}

	#endregion

}


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

typedef long long ll;
const ll INF = 1LL<<60, MOD = 1e9 + 7;
const ll dx[] = {1,0,-1,0};
const ll dy[] = {0,1,0,-1};
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()
#define m_p make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,maxn=0,idx,second=0;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n){
        if(maxn < a[i]){
            maxn = a[i];
            idx = i;
        }
    }
    rep(i,n){
        if(i==idx) continue;
        second = max(second,a[i]);
    }
    rep(i,n){
        if(i != idx) cout << maxn << endl;
        else cout << second << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
S = input()
T = input()

tran = [i for i in range(97,123)]

for i in range(len(S)) :
    Si = ord(S[i])-97
    Ti = ord(T[i])-97
    if tran[Si] == Ti :
        continue
    elif tran[Si] > 90 :
        tran[Si] = Ti
    else :
        print("No")
        exit()

if len(set(tran)) == len(tran) :
    print("Yes")
else :
    print("No")



Measured memory_bytes: 3632
class UnionFind:
    def __init__(self, n):
        self.p = [-1]*n
        # union by rank
        self.r = [1]*n
 
    def find(self, x):
        if self.p[x] < 0:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]
 
    def union(self, x, y):
        rx, ry = self.find(x), self.find(y)
 
        if rx != ry:
            if self.r[rx] > self.r[ry]:
                rx, ry = ry, rx
            if self.r[rx] == self.r[ry]:
                self.r[ry] += 1
            self.p[ry] += self.p[rx]
            self.p[rx] = ry
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def count_member(self, x):
        return -self.p[self.find(x)]

n,m,k=map(int,input().split())
uf=UnionFind(n)
ab,cd=[],[]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    ab.append((a,b))
    uf.union(a,b)

for i in range(k):
    c,d=map(int,input().split())
    c-=1
    d-=1
    cd.append((c,d))

ans=[]
for i in range(n):
    t=uf.count_member(i)-1
    ans.append(t)

for a,b in ab:
    if uf.same(a,b):
        ans[a]-=1
        ans[b]-=1

for c,d in cd:
    if uf.same(c,d):
        ans[c]-=1
        ans[d]-=1
print(*ans)

Measured memory_bytes: 37912
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int K, N;
  cin >> K >> N;
  if(K % 2 == 0){
    cout << K/2 << ' ';
    REP(i,N - 1){
      cout << K;
      if(i != N - 1) cout << ' ';
    }
    cout << endl;
  }else{ // K is odd
    vector<int> a(N,(K+1)/2);
    int m = N/2;
    while(m-- > 0){
      if(a[a.size() - 1] == 1){
        a.pop_back();
      }else{
        a[a.size() - 1]--;
        while(a.size() < N){
          a.push_back(K);
        }
      }
    }
    REP(i,a.size()){
      if(i) cout << ' ';
      cout << a[i];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

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

    int count[N];
    for(int i = 0; i < N; i++)
    {
        count[i] = 0;
    }
    
    for(int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        count[a-1]++;
        count[b-1]++;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int b[100010];
int main()
{
	int k,n;
	cin>>k>>n;
	if(n==1)
	{
		cout<<0<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(int i=1;i<n;i++)
	{
		b[i]=a[i+1]-a[i];
	}
	sort(b+1,b+n);
	int sum=0;
	for(int i=1;i<=n-1-(k-1);i++)
	{
		sum+=b[i];
	} 
	cout<<sum<<endl;
	
}

Measured memory_bytes: 1024
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse = True)

v = sum(a)
x = 1 / (4 * m)
v = v * x

c = 0
for i in range(n):
    if a[i] < v:
        break
    else:
        c += 1

    if c == m:
        break

if c < m:
    print('No')
else:
    print('Yes')

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

typedef long long ll;

ll f(string s){
    string s1,s2,s3;
    s1 = s.substr(0,2);
    s2 = s.substr(3,2);
    s3 = s.substr(6,2);

    int hh = stoi(s1)*3600;
    int mm = stoi(s2)*60;
    int ss = stoi(s3)*1;

    return hh+mm+ss;
}

const int mx=23*3600+59*60+59;

void solve(int n){
    vector<int> v(mx+10,0);
    for(ll i=0;i<n;i++){
        string s1,s2;
        cin >> s1 >> s2;
        ll s=f(s1);
        ll t=f(s2);
        v[s]++;
        v[t]--;
    }
    for(int i=1;i<mx+10;i++){
        v[i] = v[i] + v[i-1];
    }
    int ans = 0;
    for(int i=0;i<mx+10;i++){
        ans = max(ans,v[i]);
    }
    cout << ans << endl;
}

int main(){
    int n;
    while(cin>>n){
        if(n==0) break;
        solve(n);
    }
}

Measured memory_bytes: 3500
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
using namespace std;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) ((x)&1)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define mem(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for (int i=(a); i<=(b); ++i)
#define per(i,a,b) for (int i=(a); i>=(b); --i)
#define rep_it(it,x) for (__typeof((x).begin()) it=(x).begin(); it!=(x).end(); it++)
#define ____ puts("\n_______________\n\n")
#define debug(x) ____; cout<< #x << " => " << (x) << endl
#define debug_pair(x) cout<<"\n{ "<<(x).fir<<" , "<<(x).sec<<" }\n"
#define debug_arr(x,n) ____; cout<<#x<<":\n"; rep(i,0,n) cout<<#x<<"["<<(i)<<"] => "<<x[i]<<endl
#define debug_arr2(x,n,m) ____; cout<<#x<<":\n"; rep(i,0,n) rep(j,0,m) cout<<#x<<"["<<(i)<<"]["<<(j)<<"]= "<<x[i][j]<<((j==m)?"\n\n":"    ")
#define debug_set(x) ____; cout<<#x<<": \n"; rep_it(it,x) cout<<(*it)<<" "; cout<<endl
#define debug_map(x) ____; cout<<#x<<": \n"; rep_it(it,x) debug_pair(*it)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const ll ooo=9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
//const int _p = 1000 * 1000 * 1000 + 7;
const int _p=1000003;
const int N=301005;
const double PI=acos(-1.0);
const double eps=1e-9;
int o(int x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

string st[55];
int n,m;
int addx[]={-1,-1,-1,0,1,1,1,0};
int addy[]={-1,0,1,1,1,0,-1,-1};

int main() {
    //file_put();

    scanf("%d%d",&n,&m);
    rep(i,1,n) {
        cin>>st[i];
        st[i]=' '+st[i]+' ';
    }
    st[0]=st[n+1]="";
    rep(i,1,100) st[0]+=' ';
    rep(i,1,100) st[n+1]+=' ';
    rep(i,1,n)
        rep(j,1,m){
            if (st[i][j]=='#') continue;
            int num=0;
            rep(k,0,7) num+=(st[i+addx[k]][j+addy[k]]=='#');
            st[i][j]=(num+48);
        }
    rep(i,1,n){
        rep(j,1,m) printf("%c",st[i][j]);
        printf("\n");
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int  main()
{    
   int k;
   string  s;
   cin>>k>>s;
   int l=s.length();
   if(l<=k)
     {
     	cout<<s<<endl;
	 }
	 else
	 {
	 	cout<<s.substr(0,k)<<"..."<<endl;
	 }
	 return 0;
}

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

typedef long long LL;
const int N = 1e5 + 10;

int n, a, b, D;
int x[N], y[N], id[N], deg[N];
int cov[N], fa[N];

inline int mabs(int x) {return x >= 0 ? x : - x;}

inline int getf(int x) {
  return fa[x] == x ? x : fa[x] = getf(fa[x]);
}

inline bool cmp(int a, int b) {
  if (x[a] != x[b]) return x[a] < x[b];
  return y[a] < y[b];
}

inline void BuildGraph1() {
  sort(id + 1, id + n + 1, cmp);
  for (int i = 1, l = 1, r = 1; i <= n; i ++) {
    if (x[id[l]] != x[id[i]] - D) {
      while (l <= n && x[id[l]] < x[id[i]] - D) l ++;
      if (x[id[l]] != x[id[i]] - D) continue;
    }
    while (l <= n && x[id[l]] == x[id[i]] - D && y[id[l]] < y[id[i]] - D) l ++;
    if (r < l) r = l;
    while (r <= n && x[id[r]] == x[id[i]] - D && y[id[r]] <= y[id[i]] + D) r ++;
    if (l < r) {
      cov[l] ++;
      cov[r - 1] --;
      fa[getf(id[i])] = getf(id[l]);
      deg[id[i]] += r - l;
    }
  }
  for (int i = 1; i <= n; i ++) {
    cov[i] += cov[i - 1];
    if (cov[i]) fa[getf(id[i])] = getf(id[i + 1]);
  }
}

inline void BuildGraph2() {
  memset(cov, 0, sizeof cov);
  sort(id + 1, id + n + 1, cmp);
  for (int i = 1, l = 1, r = 1; i <= n; i ++) {
    if (x[id[l]] != x[id[i]] - D) {
      while (l <= n && x[id[l]] < x[id[i]] - D) l ++;
      if (x[id[l]] != x[id[i]] - D) continue;
    }
    while (l <= n && x[id[l]] == x[id[i]] - D && y[id[l]] <= y[id[i]] - D) l ++;
    if (r < l) r = l;
    while (r <= n && x[id[r]] == x[id[i]] - D && y[id[r]] < y[id[i]] + D) r ++;
    if (l < r) {
      cov[l] ++;
      cov[r - 1] --;
      fa[getf(id[i])] = getf(id[l]);
      deg[id[i]] += r - l;
    }
  }
  for (int i = 1; i <= n; i ++) {
    cov[i] += cov[i - 1];
    if (cov[i]) fa[getf(id[i])] = getf(id[i + 1]);
  }
}

int main() {
  scanf("%d%d%d", &n, &a, &b);
  for (int i = 1, X, Y; i <= n; i ++) {
    scanf("%d%d", &X, &Y);
    x[i] = X + Y;
    y[i] = Y - X;
    id[i] = i;
    fa[i] = i;
  }
  D = max(mabs(x[a] - x[b]), mabs(y[a] - y[b]));
  BuildGraph1();
  for (int i = 1; i <= n; i ++) {
    id[i] = i;
    swap(x[i], y[i]);
  }
  BuildGraph2();
  int F = getf(a);
  LL ans = 0;
  for (int i = 1; i <= n; i ++)
    if (getf(i) == F) ans += deg[i];
  printf("%lld\n", ans);
  return 0;
}
//***if this code fails, replace int with long long


Measured memory_bytes: 2816
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		int[] cards = new int[2*n];
		
		for(int i = 0; i < 2*n ; i++){
			cards[i] = i+1;
		}

		int m = Integer.parseInt(br.readLine());

		for(int i = 0; i < m; i++){
			int mode = Integer.parseInt(br.readLine());
			
			if(mode == 0){
				cards = riffleShuffle(cards);
			}
			
			else {
				cards = shuffle(cards, mode);
			}
		}
		
		for(int i = 0; i < 2*n; i++){
			System.out.println(cards[i]);
		}
	}
	
	public static int[] shuffle(int[] origin, int k){
		int[] result = new int[origin.length];
		int n = origin.length;
		
		for(int i = 0; i < k; i++){
			//System.out.println("origin "+origin[i]);
			result[n - k + i] = origin[i];
		}
		
		for(int i = 0; i <= n - k - 1; i++){
			result[i] = origin[i + k];
		}
		
		return result;
	}
	
	public static int[] riffleShuffle(int[] origin){
		int n = origin.length / 2;
		
		int[] result = new int[origin.length];
		for(int i = 0; i < n; i++){
			result[i*2] = origin[i];
			result[i*2+1] = origin[n+i];
		}
		
		return result;
	}

}

Measured memory_bytes: 26096
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int dp[60][2][2][2] = {};
long long L, R;

void add(int &x, int y) {
    x = (x + y) % MOD;
}

bool bit(long long X, int i) {
    return (X >> i & 1);
}

int f(int pos, int x, int y, int s) {
    if(pos == -1) return 1;
    if(dp[pos][x][y][s] != -1) return dp[pos][x][y][s];

    int ret = 0;
    if(x || !bit(L, pos)) add(ret, f(pos - 1, x, (bit(R, pos) ? 1 : y), s));
    if((x || !bit(L, pos)) && (y || bit(R, pos)) && s) add(ret, f(pos - 1, x, y, s));
    if(y || bit(R, pos)) add(ret, f(pos - 1, (!bit(L, pos) ? 1 : x), y, 1));

    dp[pos][x][y][s] = ret;
    return ret;
}

int main() {
    cin >> L >> R;

    memset(dp, -1, sizeof(dp));
    cout << f(59, 0, 0, 0) << endl;
}

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


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors


divisor = []
for i in range(1, N + 1):
    divisor.append(make_divisors(i))
B = [0]*N
rs = [0]*N
for i in range(N - 1, -1, -1):
    if rs[i] != A[i]:
        B[i] = 1
        for j in divisor[i]:
            rs[j-1] = 1 - rs[j-1]

print(sum(B))
for i in range(N):
    if B[i] == 1:
        print(i+1)

Measured memory_bytes: 111848
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_SIZE_MAX		3000										// 最大サイズ
#define D_ICNT_MAX		3											// 行内最大アイテム数

// 内部変数
static FILE *szpFpI;												// 入力
static int si2Itm[D_SIZE_MAX][D_SIZE_MAX];							// アイテム
static long long sl3Val[D_SIZE_MAX][D_SIZE_MAX][D_ICNT_MAX + 1];	// 価値
static int siRow, siCol;											// 行・列

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 最大値 - 取得
long long
fGetMaxL(
	long long plVal1			// <I> 値１
	, long long plVal2			// <I> 値２
)
{
	if (plVal1 > plVal2) {
		return plVal1;
	}
	else {
		return plVal2;
	}
}

// 実行メイン
int
fMain(
)
{
	int i, j, k;
	char lc1Buf[1024];

	// データ - 初期化
	memset(si2Itm, 0, sizeof(si2Itm));
	memset(sl3Val, 0, sizeof(sl3Val));

	// 行・列・アイテム数 - 取得
	int liICnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d%d", &siRow, &siCol, &liICnt);

	// アイテム - 取得
	for (i = 0; i < liICnt; i++) {
		int liRow, liCol, liVal;
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d%d", &liRow, &liCol, &liVal);
		si2Itm[liRow - 1][liCol - 1] = liVal;
	}

	// 価値 - セット
	for (i = 0; i < siRow; i++) {
		for (j = 0; j < siCol; j++) {

			// アイテム - 取得
			if (si2Itm[i][j] > 0) {
				for (k = D_ICNT_MAX - 1; k >= 0; k--) {
					sl3Val[i][j][k + 1] = fGetMaxL(sl3Val[i][j][k + 1], sl3Val[i][j][k] + (long long)si2Itm[i][j]);
				}
			}

			// 右へ
			if (j < siCol - 1) {
				for (k = 0; k <= D_ICNT_MAX; k++) {
					sl3Val[i][j + 1][k] = fGetMaxL(sl3Val[i][j + 1][k], sl3Val[i][j][k]);
				}
			}

			// 下へ
			if (i < siRow - 1) {
				for (k = 0; k <= D_ICNT_MAX; k++) {
					sl3Val[i + 1][j][0] = fGetMaxL(sl3Val[i + 1][j][0], sl3Val[i][j][k]);
				}
			}
		}
	}

	// 最大値 - 取得
	long long llMax = 0;
	for (i = 0; i <= D_ICNT_MAX; i++) {
		llMax = fGetMaxL(llMax, sl3Val[siRow - 1][siCol - 1][i]);
	}

	// 出力
	sprintf(lc1Buf, "%lld\n", llMax);
	fOutLine(lc1Buf);

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}


Measured memory_bytes: 318176
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n;
  cin>>n;

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  sort(all(p));
  reverse(all(p));

  ll ans=p[0];
  for(int i=2;i<n;i++){
    ans+=p[i/2];
  }

  cout << ans << endl;

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    string S; cin >> S;
    int n = S.size();
    if(n % 2 != 0){
        cout << "No" << endl;
        return 0;
    }
    bool ans = true;
    rep(i,n){
        if(i % 2 == 0){
            if(S[i] != 'h') ans = false;
        }else{
            if(S[i] != 'i') ans = false;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static String f(char[] s, int i, String ans, int sum) {
        if (i == 4 && sum == 7) return ans + "=7";
        else if (i == 4) return "";
        String ans1 = f(s, i + 1, ans + "-" + s[i], sum - Integer.parseInt(s[i] + ""));
        String ans2 = f(s, i + 1, ans + "+" + s[i], sum + Integer.parseInt(s[i] + ""));
        if (ans1.length() >= ans2.length()) return ans1;
        return ans2;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        char s[] = scan.next().toCharArray();
        System.out.println(f(s, 1, s[0] + "", Integer.parseInt(s[0] + "")));
    }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    rep(i, n/2){
        if(s[i] == s[n-i-1]){
            continue;
        }
        else{
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}


Measured memory_bytes: 256
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; cin>>___T; for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6+10;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9+7;
void add(int &a,int b) {a+=b; if(a>=mod) a-=mod;}
void dec(int &a,int b) {a-=b; if(a<0) a+=mod;}
int main()
{
    string s;
    cin >> s;
    puts(s[2]==s[3]&&s[4]==s[5]?"Yes":"No");
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL

int main(){
  ll N, M;
  cin >> N >> M;
  priority_queue<Pll, vector<Pll>, greater<Pll>> que;
  for(int i = 0; i < M; i++){
    ll a, b;
    cin >> a >> b;
    que.push(Pll(a, b-1));
  }
  ll ans = 0;
  ll left = -1;
  ll right = INF;
  while(!que.empty()){
    ll a = que.top().first, b = que.top().second;
    que.pop();
    chmax(left, a);
    chmin(right, b);
    if(right < left){
      ans++;
      left = a;
      right = b;
    }
  }
  ans++;
  cout << ans << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const int vx[]={1,0,-1,0}, vy[]={0,1,0,-1};
const ll LINF=1e18;
const ld PI=abs(acos(-1));

int main(){
	int n,a,b; cin >> n >> a >> b; a += b;
	string s; cin >> s;
	
	int c = 0, j = 0;
	REP(i,0,s.size()){
		if(s[i] == 'b') j++;
		if(c == a) cout << "No" << endl;
		else if(s[i] == 'a') cout << "Yes" << endl, c++;
		else if(s[i] == 'b' and j <= b) cout << "Yes" << endl, c++;
		else cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 896
A,B,C,X,Y = gets.split.map(&:to_i)

c = C * 2
a = A < c ? A : c
b = B < c ? B : c
x,y = X,Y
a,b,x,y = b,a,y,x if X < Y

if c <= A+B || b == c
  puts y * c + (x - y) * a
elsif a == c
  puts x * c + (y - x) * b
else
  puts y * b + x * a
end


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	
	string s;
	cin >> s;

	int ans=0, now=0;
	rep(i,3){
		if(s[i]=='R'){
			now++;
			chmax(ans,now);
		}
		else{
			now = 0;
		}
	}

	cout << ans << endl;

}

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

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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

string day[]{"SUN","MON","TUE","WED","THU","FRI","SAT"};

int main(){
	string s;cin>>s;
	rep(i,7){
		if(day[i]==s){
			cout<<7-i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    int H,W;
    cin >> H >> W;
    char S[H][W];
    rep(i,H) cin >> S[i];
    rep(i,H){
        rep(j,W) cout << S[i][j];
        cout << endl;
        rep(j,W) cout << S[i][j];
        cout << endl;
    }
}

Measured memory_bytes: 256